Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10586 for code


Ignore:
Timestamp:
Sep 15, 2015, 2:20:34 PM (9 years ago)
Author:
fvultier
Message:

Removed unuses classes and templates. The enemies move now along a path defined in the XML level file and no more along a static hard coded path.

Location:
code/branches/towerdefenseFabien
Files:
4 added
9 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/towerdefenseFabien/data/levels/towerDefense.oxw

    r10258 r10586  
    1515  include("towerdefenseHUD.oxo")
    1616  include("templates/lodInformation.oxt")
    17 ?>
    18 
    19 <?lua
     17  include("includes/weaponSettingsTurret.oxi")
    2018  include("templates/spaceshipAssff.oxt")
    21   include("templates/spaceshipPirate.oxt")
    22   include("templates/tower.oxt")
    23   include("templates/enemytowerdefense.oxt")
    2419  include("templates/standardTurret.oxt")
    2520?>
    2621
    27 <!-- Specify the position of the camera -->
    28 <Template name=centerpointmarkcamera defaults=0>
    29   <Pawn team=1>
     22<Template name=selectercameras defaults=0>
     23  <TowerDefenseSelecter>
    3024    <camerapositions>
    31       <CameraPosition position="0,0,1500"/>
     25      <CameraPosition position="0,0,1300" lookat="0,0,0" absolute=true drag=true mouselook=true/>
    3226    </camerapositions>
    33   </Pawn>
    34 </Template>
    35 
    36 <!-- Loads a mesh to mark the center-->
    37 <Template name=centerpointmark>
    38   <Pawn team=1 camerapositiontemplate=centerpointmarkcamera>
     27  </TowerDefenseSelecter>
     28</Template>
     29
     30<Template name=selectertemplate>
     31  <TowerDefenseSelecter team=0 camerapositiontemplate=selectercameras>
    3932    <attached>
    40       <Model position="0,0,0" mesh="cylinder.mesh" scale3D="1,1,1" /> <!-- the camera is attached to this -->
     33      <Model position="0,0,0" pitch=90 mesh="TD_Selection.mesh" scale=25/>
    4134    </attached>
    42   </Pawn>
    43 </Template>
    44 
    45 
    46 <!-- Template for a tower   EDIT: new towertemplate is included with "templates/tower" -->
    47 <!--Template name=towertemplate>
    48   <Tower>
     35  </TowerDefenseSelecter>
     36</Template>
     37
     38<Template name=tower1template>
     39  <TowerDefenseTower
     40  explosionchunks=6
     41  reloadrate=10
     42  reloadwaittime=5
     43  collisionType="none"
     44  pitch="0"
     45  yaw="0"
     46  roll="0"
     47  maxPitch=360
     48  maxYaw=360
     49  maxAttackRadius=1000
     50  minAttackRadius=0
     51  team=0
     52  >
     53    <controller>
     54       <TurretController team = 0/>
     55    </controller>
     56    <weaponslots>
     57      <WeaponSlot position="0,0,0" />
     58    </weaponslots>
     59    <weaponsets>
     60      <WeaponSet firemode=0 />
     61    </weaponsets>
     62    <weapons>
     63      <WeaponPack>
     64        <links>
     65          <DefaultWeaponmodeLink firemode=0 weaponmode=0 />
     66        </links>
     67        <Weapon>
     68          <HsW01 mode=0 munitionpershot=0 muzzleoffset="0,0,-30" damage=2 shielddamage=1 material="Flares/point_lensflare" delay=0/>
     69        </Weapon>
     70      </WeaponPack>
     71    </weapons>
     72  </TowerDefenseTower>
     73</Template>
     74
     75<Template name=tower2template>
     76  <TowerDefenseTower
     77  explosionchunks=6
     78  reloadrate=10
     79  reloadwaittime=5
     80  collisionType="none"
     81  pitch="0"
     82  yaw="0"
     83  roll="0"
     84  maxPitch=360
     85  maxYaw=360
     86  maxAttackRadius=1000
     87  minAttackRadius=0
     88  team=0
     89  >
     90    <controller>
     91       <TurretController team = 0/>
     92    </controller>
     93    <weaponslots>
     94      <WeaponSlot position="0,0,0" />
     95    </weaponslots>
     96    <weaponsets>
     97      <WeaponSet firemode=0 />
     98    </weaponsets>
     99    <weapons>
     100      <WeaponPack>
     101        <links>
     102          <DefaultWeaponmodeLink firemode=0 weaponmode=0 />
     103        </links>
     104        <Weapon>         
     105          <LightningGun mode=0 munitionpershot=0 muzzleoffset="0,0,-30" damage=2 shielddamage=4 />
     106        </Weapon>
     107      </WeaponPack>
     108    </weapons>
    49109    <attached>
    50       <Model position="0,0,0" scale=0.25 mesh="Tower_ME.mesh" />
     110      <Backlight position="0,-100,0" scale=2.0 colour="0.4, 0.0, 1.0" width=10 length=500 lifetime=0.3 elements=20 trailmaterial="Trail/backlighttrail" material="Examples/Flare" loop=1 />
     111    </attached>   
     112  </TowerDefenseTower>
     113</Template>
     114
     115<Template name=tower3template>
     116  <TowerDefenseTower
     117  explosionchunks=6
     118  reloadrate=10
     119  reloadwaittime=5
     120  collisionType="none"
     121  pitch="0"
     122  yaw="0"
     123  roll="0"
     124  maxPitch=360
     125  maxYaw=360
     126  maxAttackRadius=1000
     127  minAttackRadius=0
     128  team=0
     129  >
     130    <controller>
     131       <TurretController team = 0/>
     132    </controller>
     133    <weaponslots>
     134      <WeaponSlot position="0,0,0" />
     135    </weaponslots>
     136    <weaponsets>
     137      <WeaponSet firemode=0 />
     138    </weaponsets>
     139    <weapons>
     140      <WeaponPack>
     141        <links>
     142          <DefaultWeaponmodeLink firemode=0 weaponmode=0 />
     143        </links>
     144        <Weapon>
     145          <EnergyDrink mode=0 munitionpershot=0 muzzleoffset="0,0,-30" damage=2 shielddamage=4 />
     146        </Weapon>
     147      </WeaponPack>
     148    </weapons>
     149  </TowerDefenseTower>
     150</Template>
     151
     152<Template name=tower4template>
     153  <TowerDefenseTower
     154  explosionchunks=6
     155  reloadrate=10
     156  reloadwaittime=5
     157  collisionType="none"
     158  pitch="0"
     159  yaw="0"
     160  roll="0"
     161  maxPitch=360
     162  maxYaw=360
     163  maxAttackRadius=1000
     164  minAttackRadius=0
     165  team=0
     166  >
     167    <controller>
     168       <TurretController team = 0/>
     169    </controller>
     170    <weaponslots>
     171      <WeaponSlot position="0,0,0" />
     172    </weaponslots>
     173    <weaponsets>
     174      <WeaponSet firemode=0 />
     175    </weaponsets>
     176    <weapons>
     177      <WeaponPack>
     178        <links>
     179          <DefaultWeaponmodeLink firemode=0 weaponmode=0 />
     180        </links>
     181        <Weapon>
     182          <FusionFire mode=0 munitionpershot=0 muzzleoffset="0,0,-30" damage=2 shielddamage=4 /> 
     183        </Weapon>
     184      </WeaponPack>
     185    </weapons>
     186      <attached>
     187      <ParticleSpawner position="0,-100,0" source="Orxonox/sparks" lifetime=3.0 autostart=1 loop=1 />
    51188    </attached>
    52   </Tower>
    53 </Template-->
    54 
    55 
    56 
    57 
     189  </TowerDefenseTower>
     190</Template>
     191
     192<Template name=tower5template>
     193  <TowerDefenseTower
     194  explosionchunks=6
     195  reloadrate=10
     196  reloadwaittime=5
     197  collisionType="none"
     198  pitch="0"
     199  yaw="0"
     200  roll="0"
     201  maxPitch=360
     202  maxYaw=360
     203  maxAttackRadius=1000
     204  minAttackRadius=0
     205  team=0
     206  >
     207    <controller>
     208       <TurretController team = 0/>
     209    </controller>
     210    <weaponslots>
     211      <WeaponSlot position="0,0,0" />
     212    </weaponslots>
     213    <weaponsets>
     214      <WeaponSet firemode=0 />
     215    </weaponsets>
     216    <weapons>
     217      <WeaponPack>
     218        <links>
     219          <DefaultWeaponmodeLink firemode=0 weaponmode=0 />
     220        </links>
     221        <Weapon>
     222          <LaserFire mode=0 munitionpershot=0 muzzleoffset="0,0,-30" damage=2 shielddamage=4 /> 
     223        </Weapon>
     224      </WeaponPack>
     225    </weapons>
     226  </TowerDefenseTower>
     227</Template>
     228
     229<Template name=enemytowerdefense1>
     230  <TowerDefenseEnemy
     231   hudtemplate            = spaceshiphud
     232   camerapositiontemplate = spaceshipassffcameras
     233   spawnparticlesource    = "Orxonox/fairytwirl"
     234   spawnparticleduration  = 3
     235   explosionchunks        = 6
     236
     237   health            = 1
     238   maxhealth         = 2
     239   initialhealth     = 1
     240
     241   shieldhealth        = 30
     242   initialshieldhealth = 30
     243   maxshieldhealth     = 50
     244   shieldabsorption    = 0.8
     245   reloadrate          = 1
     246   reloadwaittime      = 1
     247
     248   primaryThrust     = 100
     249   auxilaryThrust    = 30
     250   rotationThrust    = 50
     251
     252   lift = 1;
     253   stallSpeed = 220;
     254
     255   boostPower            = 15
     256   boostPowerRate        = 1
     257   boostRate             = 5
     258   boostCooldownDuration = 10
     259
     260   shakeFrequency = 15
     261   shakeAmplitude = 9
     262
     263   collisionType     = "dynamic"
     264   mass              = 100
     265   linearDamping     = 0.7
     266   angularDamping    = 0.9999999
     267
     268   explosionSound = "sounds/Explosion2.ogg"   
     269  >
     270
     271    <engines>
     272      <MultiStateEngine position=" 7.6, 0, 6" template=spaceshipassffengine />
     273      <MultiStateEngine position="-7.6, 0, 0" template=spaceshipassffengine />
     274    </engines>
     275    <attached>
     276      <Model position="0,0,0" yaw=90 pitch=90 roll=0 scale=4 mesh="assff.mesh" />
     277      <BlinkingBillboard position="17,-1.5,0" material="Examples/Flare" colour="1.0, 0.5, 0.3" amplitude=0.1 frequency=0.5 quadratic=1 />
     278      <BlinkingBillboard position="-17,-1.5,0" material="Examples/Flare" colour="0.5, 1.0, 0.3" amplitude=0.1 frequency=0.5 phase=180 quadratic=1 />
     279    </attached>
     280    <collisionShapes>
     281      <BoxCollisionShape position="0,0,0"      halfExtents="10, 3, 5" />
     282      <BoxCollisionShape position="13,-1.3,0"  halfExtents="3, 1, 2" />
     283      <BoxCollisionShape position="-13,-1.3,0" halfExtents="3, 1, 2" />
     284      <BoxCollisionShape position="0,0,7"      halfExtents="3, 2, 2" />
     285      <BoxCollisionShape position="0,0.1,-11"  halfExtents="2.2, 1.8, 6" />
     286      <BoxCollisionShape position="0,0.1,-19"  halfExtents="1.4, 1, 2" />
     287    </collisionShapes>
     288    <controller>
     289      <WaypointController accuracy=60>
     290      </WaypointController>
     291    </controller>
     292  </TowerDefenseEnemy>
     293</Template>
     294
     295<Template name=enemytowerdefense2>
     296  <TowerDefenseEnemy
     297   hudtemplate            = spaceshiphud
     298   camerapositiontemplate = spaceshipassffcameras
     299   spawnparticlesource    = "Orxonox/fairytwirl"
     300   spawnparticleduration  = 3
     301   explosionchunks        = 6
     302
     303   health            = 100
     304   maxhealth         = 200
     305   initialhealth     = 100
     306
     307   shieldhealth        = 30
     308   initialshieldhealth = 30
     309   maxshieldhealth     = 50
     310   shieldabsorption    = 0.8
     311   reloadrate          = 1
     312   reloadwaittime      = 1
     313
     314   primaryThrust     = 100
     315   auxilaryThrust    = 30
     316   rotationThrust    = 50
     317
     318   lift = 1;
     319   stallSpeed = 220;
     320
     321   boostPower            = 15
     322   boostPowerRate        = 1
     323   boostRate             = 5
     324   boostCooldownDuration = 10
     325
     326   shakeFrequency = 15
     327   shakeAmplitude = 9
     328
     329   collisionType     = "dynamic"
     330   mass              = 100
     331   linearDamping     = 0.7
     332   angularDamping    = 0.9999999
     333
     334   explosionSound = "sounds/Explosion2.ogg"
     335  >
     336
     337    <engines>
     338      <Engine position=" 0, 0, 0"
     339        boostfactor    = 2
     340        speedfront     = 150
     341        speedback      =  50
     342        speedleftright =  50
     343        speedupdown    =  50         
     344        accelerationfront     = 500
     345        accelerationbrake     = 500
     346        accelerationback      =  125
     347        accelerationleftright =  125
     348        accelerationupdown    =  125
     349      />
     350    </engines>
     351    <attached>
     352      <Model position="0,0,0" yaw=0 pitch=0 roll=0 scale=2.5 mesh="JumpEnemy3.mesh" />
     353    </attached>
     354    <collisionShapes>
     355      <BoxCollisionShape position="0,0,0"      halfExtents="10, 3, 5" />
     356      <BoxCollisionShape position="13,-1.3,0"  halfExtents="3, 1, 2" />
     357      <BoxCollisionShape position="-13,-1.3,0" halfExtents="3, 1, 2" />
     358      <BoxCollisionShape position="0,0,7"      halfExtents="3, 2, 2" />
     359      <BoxCollisionShape position="0,0.1,-11"  halfExtents="2.2, 1.8, 6" />
     360      <BoxCollisionShape position="0,0.1,-19"  halfExtents="1.4, 1, 2" />
     361    </collisionShapes>
     362    <controller>
     363      <WaypointController accuracy=60>
     364      </WaypointController>
     365    </controller>   
     366  </TowerDefenseEnemy>
     367</Template>
     368
     369<Template name=enemytowerdefense3>
     370  <TowerDefenseEnemy
     371   hudtemplate            = spaceshiphud
     372   camerapositiontemplate = spaceshipassffcameras
     373   spawnparticlesource    = "Orxonox/fairytwirl"
     374   spawnparticleduration  = 3
     375   explosionchunks        = 6
     376
     377   health            = 100
     378   maxhealth         = 200
     379   initialhealth     = 100
     380   
     381   shieldhealth        = 30
     382   initialshieldhealth = 30
     383   maxshieldhealth     = 50
     384   shieldabsorption    = 0.8
     385   reloadrate          = 1
     386   reloadwaittime      = 1
     387
     388   primaryThrust     = 100
     389   auxilaryThrust    = 30
     390   rotationThrust    = 50
     391
     392   lift = 1;
     393   stallSpeed = 220;
     394
     395   boostPower            = 15
     396   boostPowerRate        = 1
     397   boostRate             = 5
     398   boostCooldownDuration = 10
     399
     400   shakeFrequency = 15
     401   shakeAmplitude = 9
     402
     403   collisionType     = "dynamic"
     404   mass              = 100
     405   linearDamping     = 0.7
     406   angularDamping    = 0.9999999
     407
     408   explosionSound = "sounds/Explosion2.ogg"
     409  >
     410
     411    <engines>
     412      <Engine position=" 0, 0, 0"
     413        boostfactor    = 2
     414        speedfront     = 150
     415        speedback      =  50
     416        speedleftright =  50
     417        speedupdown    =  50         
     418        accelerationfront     = 500
     419        accelerationbrake     = 500
     420        accelerationback      =  125
     421        accelerationleftright =  125
     422        accelerationupdown    =  125
     423      />
     424    </engines>
     425    <attached>
     426      <Model position="0,0,0" yaw=0 pitch=0 roll=0 scale=2.5 mesh="JumpEnemy4.mesh" />
     427    </attached>
     428    <collisionShapes>
     429      <BoxCollisionShape position="0,0,0"      halfExtents="10, 3, 5" />
     430      <BoxCollisionShape position="13,-1.3,0"  halfExtents="3, 1, 2" />
     431      <BoxCollisionShape position="-13,-1.3,0" halfExtents="3, 1, 2" />
     432      <BoxCollisionShape position="0,0,7"      halfExtents="3, 2, 2" />
     433      <BoxCollisionShape position="0,0.1,-11"  halfExtents="2.2, 1.8, 6" />
     434      <BoxCollisionShape position="0,0.1,-19"  halfExtents="1.4, 1, 2" />
     435    </collisionShapes>
     436    <controller>
     437      <WaypointController accuracy=60>
     438      </WaypointController>
     439    </controller>   
     440  </TowerDefenseEnemy>
     441</Template>
    58442
    59443<Level gametype = "TowerDefense">
     
    71455    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
    72456
    73     <!-- Spawns the camera, attached to a crate -->
    74     <SpawnPoint team=1 position="0,0,0" spawnclass=Pawn pawndesign=centerpointmark />
    75     <!--TeamSpawnPoint team=1 position="-7,7,4" direction="-1,0,0" roll=90 yaw=0 spawnclass=SpaceShip pawndesign=spaceshipassff /-->
    76 
    77     <!--SpawnPoint team=1 position="0,0,10" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff  /-->
    78     <!--SpawnPoint team=0 position="0,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /-->
    79 
    80 
    81 
    82 
    83     <!--invisible entity to attach towers to, since playfield is static and towers are dynamic-->
    84     <StaticEntity team =1 position=0,0,0>
    85 
    86         <attached>
    87             <Model position="-50,-50,0" mesh="Playfield_ME.mesh" scale=80 />
    88             <!-- Base -->
    89             <Model position="500,700,100" mesh="sphere.mesh" scale=80 />
    90             <!--Model position="0,0,0" mesh="crate.mesh" scale3D="3,3,3" /--> <!-- Only temporary needed to help align the collisionshape -->
    91             <!-- This was used to mark the playfield, let's let it be here for now -->
    92             <!--Model position="-8,8,0" mesh="crate.mesh" scale3D="0.3,0.3,0.3" /-->
    93             <!--Model position="-8,-8,0" mesh="crate.mesh" scale3D="0.3,0.3,0.3" /-->
    94             <!--Model position="8,-8,0" mesh="crate.mesh" scale3D="0.3,0.3,0.3" /-->
    95             <!--Model position="8,8,0" mesh="crate.mesh" scale3D="0.3,0.3,0.3" /-->
    96         </attached>
    97         <collisionShapes> <!-- The collisionshape forbids other worldentities that have a collisionShape to fly through it.
    98 
    99                                TODO: Find correct size for the collisionshape; since a collisionShape is invisible
    100                                I added the crate wich currently has the same dimensions as the collisionshape.
    101                                You have to adjust the crate's scale3D as well as the collisionshape's halfExtens to
    102                                find the proper shape. -->
    103            <BoxCollisionShape position="0,0,0" halfExtents="400,400,100" />
    104         </collisionShapes>
    105     </StaticEntity>
    106 
    107 
    108 
     457    <SpawnPoint team=0 position="0,0,0"/>
     458
     459    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_S1.mesh" scale=25/>
     460    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_S2.mesh" scale=25/>
     461    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_S3.mesh" scale=25/>
     462    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_S4.mesh" scale=25/>
     463    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_S5.mesh" scale=25/>
     464    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_T1.mesh" scale=25/>
     465    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_T2.mesh" scale=25/>
     466    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_T3.mesh" scale=25/>
     467    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_T4.mesh" scale=25/>
     468    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_T5.mesh" scale=25/>
     469    <Model position="0,0,-1000" pitch=90 lodLevel=1 mesh="TD_F1.mesh" scale=25/>
    109470
    110471    <!-- PlayField -->
    111472    <TowerDefenseCenterpoint
    112473    name=towerdefensecenter
     474    selecterTemplate=selectertemplate
     475    tower1Template=tower1template
     476    tower2Template=tower2template
     477    tower3Template=tower3template
     478    tower4Template=tower4template
     479    tower5Template=tower5template
     480    tower1Cost=100
     481    tower2Cost=100
     482    tower3Cost=100
     483    tower4Cost=100
     484    tower5Cost=100
     485    fields="F1F1F1R1I1I1I1I1O1F1F1F1F1F1F1F1
     486            F1F1F1I2F1F1F1F1F1F1F1F1F1F1F1F1
     487            F1F1F1I2F1F1F1F1F1F1F1F1F1F1F1F1
     488            F1F1F1I2F1F1F1F1F1F1F1F1F1F1F1F1
     489            F1F1F1I2F1F1F1F1F1F1F1F1F1F1F1F1
     490            F1F1F1I2F1F1F1F1F1F1F1F1F1F1F1F1
     491            F1F1F1R2I3I3I3I3L3F1F1F1F1F1F1F1
     492            F1F1F1F1F1F1F1F1I2F1F1F1F1F1F1F1
     493            F1F1F1F1F1F1F1F1I2F1F1F1F1F1F1F1
     494            X1I1I1I1R0F1F1F1I2F1F1F1F1F1F1F1
     495            F1F1F1F1I0F1F1F1I2F1F1F1F1F1F1F1
     496            F1F1F1F1I0F1F1F1I2F1F1F1F1F1F1F1
     497            F1F1F1F1L1I1I1I1L2F1F1F1F1F1F1F1
     498            F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1
     499            F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1
     500            F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1"
    113501    width=16
    114502    height=16
    115503    tileScale=100
    116     towerTemplate=tower
    117504    position="0,0,0"
    118505    direction="0,0,0"
    119506    collisionType=dynamic
    120507    mass=100000
    121     team=1
    122     />
     508    >
     509      <camerapositions>
     510        <CameraPosition position="0,0,1400" lookat="0,0,0" absolute=true />
     511      </camerapositions>   
     512    </TowerDefenseCenterpoint>
    123513
    124514  </Scene>
  • code/branches/towerdefenseFabien/src/modules/towerdefense/CMakeLists.txt

    r10258 r10586  
    22  TowerDefense.cc
    33  TowerDefenseTower.cc
    4   TowerTurret.cc
    54  TowerDefenseCenterpoint.cc
    65  TowerDefenseHUDController.cc
     
    87  TDCoordinate.cc
    98  TowerDefenseEnemy.cc
    10 
     9  TowerDefenseSelecter.cc
     10  TowerDefenseField.cc
     11  TDCoordinate.cc
    1112)
    1213
     
    1718    orxonox
    1819    overlays
     20    objects
    1921  SOURCE_FILES ${TOWERDEFENSE_SRC_FILES}
    2022)
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TDCoordinate.cc

    r10258 r10586  
    88namespace orxonox
    99{
    10     //RegisterClass(TDCoordinate);
    11 
    1210    /**
    1311    @brief
    14         Constructor. Registers and initializes the object.
     12        Constructor. Sets the default coordinates: (0,0)
    1513    */
    1614    TDCoordinate::TDCoordinate()
    1715    {
    18         //RegisterObject(TDCoordinate);
    19         x=0;
    20         y=0;
    21 
     16        Set(0,0);
    2217    }
    2318
    2419    TDCoordinate::TDCoordinate(int x, int y)
    25     {
    26         this->x=x;
    27         this->y=y;
     20    {       
     21        Set(x,y);
     22    }
     23
     24    void TDCoordinate::Set(int x, int y)
     25    {       
     26        if (x < 0)
     27        {
     28            _x = 0;
     29        }
     30        else if (x > 15)
     31        {
     32            _x = 15;
     33        }
     34        else
     35        {
     36            _x = x;
     37        }
     38
     39        if (y < 0)
     40        {
     41            _y = 0;
     42        }
     43        else if (y > 15)
     44        {
     45            _y = 15;
     46        }
     47        else
     48        {
     49            _y = y;
     50        }
     51    }
     52
     53    int TDCoordinate::GetX()
     54    {       
     55        return _x;
     56    }
     57
     58    int TDCoordinate::GetY()
     59    {       
     60        return _y;
    2861    }
    2962
     
    3467
    3568        Vector3 *coord = new Vector3();
    36         coord->x= (x-8) * tileScale;
    37         coord->y= (y-8) * tileScale;
    38         coord->z=100;
     69        coord->x= (_x-8) * tileScale;
     70        coord->y= (_y-8) * tileScale;
     71        coord->z=0;
    3972
    4073        return *coord;
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TDCoordinate.h

    r10258 r10586  
    1313//Class to save the Coordinates in a class instead of struct
    1414//Convert 2d coordinates to 3d in order to set waypoints
    15     class _TowerDefenseExport TDCoordinate : public OrxonoxClass
     15    class _TowerDefenseExport TDCoordinate
    1616    {
    1717        public:
    18             int x;
    19             int y;
     18            TDCoordinate();
     19            TDCoordinate(int x, int y);
     20            virtual ~TDCoordinate() {};
     21            virtual void Set(int x, int y);
     22            virtual int GetX();
     23            virtual int GetY();
     24            virtual Vector3 get3dcoordinate();
    2025
    21             TDCoordinate();
    22 
    23             Vector3 get3dcoordinate();
    24 
    25             virtual ~TDCoordinate() {};
    26 
    27             TDCoordinate(int x, int y);
     26        private:
     27            int _x;
     28            int _y;
    2829    };
    2930
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefense.cc

    r10258 r10586  
    3737 *
    3838 *
    39  *
    4039 *TIPP: Eclipse hilft euch schnell auf bereits vorhanden Funktionen zuzugreifen:
    4140 * einfach "this->" eingeben und kurz warten. Dann tauch eine Liste mit Vorschlägen auf. Wenn ihr jetzt weiter
     
    7675#include "TowerDefenseTower.h"
    7776#include "TowerDefenseCenterpoint.h"
    78 //#include "TDCoordinate.h"
    79 #include "TowerTurret.h"
    8077#include "worldentities/SpawnPoint.h"
    81 #include "worldentities/pawns/Pawn.h"
    82 #include "worldentities/pawns/SpaceShip.h"
    8378#include "controllers/WaypointController.h"
    8479#include "graphics/Model.h"
     
    8984#include "core/command/ConsoleCommand.h"
    9085
     86
    9187namespace orxonox
    9288{
     89    static const std::string __CC_addTower_name  = "addTower";
     90    static const std::string __CC_upgradeTower_name = "upgradeTower";
     91
     92    SetConsoleCommand("TowerDefense", __CC_addTower_name,  &TowerDefense::addTower ).addShortcut().defaultValues(1);
     93    SetConsoleCommand("TowerDefense", __CC_upgradeTower_name, &TowerDefense::upgradeTower).addShortcut().defaultValues(0);
     94
    9395    RegisterUnloadableClass(TowerDefense);
    9496
    95     TowerDefense::TowerDefense(Context* context) : Deathmatch(context)
     97    TowerDefense::TowerDefense(Context* context) : TeamDeathmatch(context)
    9698    {
    9799        RegisterObject(TowerDefense);
    98 /*
    99         for (int i=0; i < 16 ; i++){
    100             for (int j = 0; j< 16 ; j++){
    101                 towermatrix[i][j] = NULL;
    102             }
    103         }*/
    104 
     100
     101        selecter = NULL;
     102        this->player_ = NULL;       
    105103        this->setHUDTemplate("TowerDefenseHUD");
     104        this->nextwaveTimer_.setTimer(10, false, createExecutor(createFunctor(&TowerDefense::nextwave, this)));
     105        this->nextwaveTimer_.stopTimer();
     106        this->waves_ = 0;
     107        this->time = 0;
     108        this->credit_ = 0;
     109        this->lifes_ = 0;
    106110
    107111        //this->stats_ = new TowerDefensePlayerStats();
    108112
    109         /* Temporary hack to allow the player to add towers and upgrade them */
    110         this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) );
    111         this->dedicatedUpgradeTower_ = createConsoleCommand( "upgradeTower", createExecutor( createFunctor(&TowerDefense::upgradeTower, this) ) );
     113        ModifyConsoleCommand(__CC_addTower_name).setObject(this);
     114        ModifyConsoleCommand(__CC_upgradeTower_name).setObject(this);
    112115    }
    113116
    114117    TowerDefense::~TowerDefense()
    115     {
    116         /* Part of a temporary hack to allow the player to add towers */
     118    {        /* Part of a temporary hack to allow the player to add towers */
    117119        if (this->isInitialized())
    118120        {
    119             if( this->dedicatedAddTower_ )
    120                 delete this->dedicatedAddTower_;
     121            ModifyConsoleCommand(__CC_addTower_name).setObject(NULL);
     122            ModifyConsoleCommand(__CC_upgradeTower_name).setObject(NULL);
    121123        }
    122124    }
     
    124126    void TowerDefense::setCenterpoint(TowerDefenseCenterpoint *centerpoint)
    125127    {
    126         orxout() << "Centerpoint now setting..." << endl;
    127128        this->center_ = centerpoint;
    128         orxout() << "Centerpoint now set..." << endl;
    129129    }
    130130
    131131    void TowerDefense::start()
    132     {
    133 
    134         Deathmatch::start();
    135 
    136 // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path
    137         for (int i=0; i < 16 ; i++){
    138             for (int j = 0; j< 16 ; j++){
    139                 towermatrix[i][j] = false;
    140             }
    141         }
    142 
    143         for (int k=0; k<3; k++)
    144             towermatrix[1][k]=true;
    145         for (int l=1; l<11; l++)
    146             towermatrix[l][3]=true;
    147         for (int m=3; m<12; m++)
    148             towermatrix[10][m]=true;
    149         for (int n=10; n<14; n++)
    150             towermatrix[n][11]=true;
    151         for (int o=13; o<16; o++)
    152             towermatrix[13][o]=true;
     132    {       
     133        if (center_ != NULL) // There needs to be a TowerDefenseCenterpoint, i.e. the area the game takes place.
     134        {
     135            if (selecter == NULL)
     136            {
     137                selecter = new TowerDefenseSelecter(this->center_->getContext());               
     138            }
     139            selecter->addTemplate(center_->getSelecterTemplate());
     140            center_->attach(selecter);
     141        }
     142        else // If no centerpoint was specified, an error is thrown and the level is exited.
     143        {
     144            orxout(internal_error) << "Jump: No Centerpoint specified." << endl;
     145            return;
     146        }
     147
     148        enemies_.clear();
     149
     150        createFields();
     151
     152        TeamDeathmatch::start();
     153
     154        // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path
     155       
    153156
    154157        //set initial credits, lifes and WaveNumber
    155         this->setCredit(200);
    156         this->setLifes(50);
     158        this->setCredit(1000);
     159        this->setLifes(100);
    157160        this->setWaveNumber(0);
    158         time=0.0;
    159 
    160         //adds initial towers
    161         for (int i=0; i <7; i++){
    162             addTower(i+3,4);
    163         }/*
    164         for (int j=0; j < 7; j++){
    165             addTower(9,j+5);
    166         }*/
     161        time = 0.0;
    167162    }
    168163
    169164    // Generates a TowerDefenseEnemy. Uses Template "enemytowerdefense". Sets position at first waypoint of path.
    170     void TowerDefense::addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr){
    171 
     165    void TowerDefense::addTowerDefenseEnemy(int templatenr)
     166    {
     167        orxout() << "addTowerDefenseEnemy" << endl;
    172168
    173169        TowerDefenseEnemy* en1 = new TowerDefenseEnemy(this->center_->getContext());
     
    185181            en1->setScale(2);
    186182            en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
    187             //  en1->setShieldHealth(en1->getShield() = this->getWaveNumber()*2))
    188183            break;
    189184
     
    193188            en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
    194189            break;
    195         }
    196 
    197         en1->getController();
    198         en1->setPosition(path.at(0)->get3dcoordinate());
    199         TowerDefenseEnemyvector.push_back(en1);
    200 
    201         for(unsigned int i = 0; i < path.size(); ++i)
    202         {
    203             en1->addWaypoint((path.at(i)));
    204         }
     190        }       
     191
     192        en1->setTeam(2);
     193
     194        //orxonox::WeakPtr<WaypointController> controller = new WaypointController(this->center_->getContext());
     195        //controller->setControllableEntity(en1);
     196        //en1->setController(controller);
     197
     198        WaypointController* controller = (WaypointController*)(en1->getXMLController());
     199
     200        if (controller != NULL && waypoints_.size() > 1)
     201        {
     202            en1->setPosition(waypoints_.at(0)->getPosition());
     203            en1->setOrientation(Vector3(0,0,10), Degree(0));
     204            en1->setDirection(Vector3(0,1,0));
     205            en1->lookAt(waypoints_.at(1)->getPosition());
     206
     207            for (unsigned int i = 0; i < waypoints_.size(); ++ i)
     208            {
     209                orxonox::WeakPtr<MovableEntity> waypoint = new MovableEntity(this->center_->getContext());
     210                waypoint->setPosition(waypoints_.at(i)->getPosition());
     211                controller->addWaypoint(waypoints_.at(i));
     212            }
     213        }
     214
     215        enemies_.push_back(en1);
    205216    }
    206217
     
    209220    {
    210221
    211         Deathmatch::end();
     222        TeamDeathmatch::end();
    212223        ChatManager::message("Match is over! Gameover!");
    213224
    214225    }
    215226
     227    void TowerDefense::spawnPlayer(PlayerInfo* player)
     228    {
     229        assert(player);
     230        player_ = player;
     231
     232        orxout() << "spawnPlayer" << endl;
     233
     234        if (selecter->getPlayer() == NULL)
     235        {
     236            player_->startControl(selecter);
     237            players_[player].state_ = PlayerState::Alive;
     238        }
     239    }
     240
     241    /**
     242    @brief
     243        Get the player.
     244    @return
     245        Returns a pointer to the player. If there is no player, NULL is returned.
     246    */
     247    PlayerInfo* TowerDefense::getPlayer(void) const
     248    {
     249        return this->player_;
     250    }
     251
    216252    //not working yet
    217     void TowerDefense::upgradeTower(int x,int y)
    218     {/*
    219         const int upgradeCost = 20;
    220 
    221         if (!this->hasEnoughCreditForTower(upgradeCost))
    222         {
    223             orxout() << "not enough credit: " << (this->getCredit()) << " available, " << upgradeCost << " needed.";
    224             return;
    225         }
    226 
    227         if (towermatrix [x][y] == NULL)
    228         {
    229             orxout() << "no tower on this position" << endl;
    230             return;
    231         }
    232 
    233         else
    234         {
    235             (towermatrix [x][y])->upgradeTower();
    236         }*/
     253    void TowerDefense::addTower(int x,int y)
     254    {
     255        TDCoordinate* coord = new TDCoordinate(x,y);
     256        x = coord->GetX();
     257        y = coord->GetY();
     258
     259        int cost = center_->getTowerCost(1);
     260
     261        if (fields_[x][y]->isFree() == true && getCredit() >= cost)
     262        {
     263            payCredit(cost);
     264            fields_[x][y]->createTower(1);
     265        }
    237266    }
    238267
    239268    /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret")
    240269    so towers have ability if the turrets
    241 
    242270    */
    243     void TowerDefense::addTower(int x, int y)
    244     {
    245         const int towerCost = 20;
    246 
    247         if (!this->hasEnoughCreditForTower(towerCost))
    248         {
    249             orxout() << "not enough credit: " << (this->getCredit()) << " available, " << towerCost << " needed.";
     271
     272    void TowerDefense::upgradeTower(int x, int y)
     273    {   
     274        TDCoordinate* coord = new TDCoordinate(x,y);
     275        x = coord->GetX();
     276        y = coord->GetY();     
     277
     278        int cost = center_->getTowerCost(fields_[x][y]->getUpgrade() + 1);
     279
     280        if (fields_[x][y]->isFree() == false && fields_[x][y]->canUpgrade() == true && getCredit() >= cost)
     281        {
     282            payCredit(cost);
     283            fields_[x][y]->upgrade();
     284        }
     285    }   
     286
     287    void TowerDefense::tick(float dt)
     288    {
     289        //orxout() << "tick1" << endl;
     290        SUPER(TowerDefense, tick, dt);
     291        //orxout() << "tick2" << endl;
     292
     293        if (hasStarted() == false || player_ == NULL)
     294        {
    250295            return;
    251296        }
    252 
    253         if (towermatrix [x][y]==true)
    254         {
    255             orxout() << "not possible to put tower here!!" << endl;
    256             return;
    257         }
    258 
    259 /*
    260         unsigned int width = this->center_->getWidth();
    261         unsigned int height = this->center_->getHeight();
    262 */
    263 
    264         int tileScale = (int) this->center_->getTileScale();
    265 
    266         if (x > 15 || y > 15 || x < 0 || y < 0)
    267         {
    268             //Hard coded: TODO: let this depend on the centerpoint's height, width and fieldsize (fieldsize doesn't exist yet)
    269             orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl;
    270             return;
    271         }
    272 
    273         orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
    274 
    275        //Reduce credit
    276         this->buyTower(towerCost);
    277         towermatrix [x][y]=true;
    278 
    279         //Creates tower
    280         TowerDefenseTower* towernew = new TowerDefenseTower(this->center_->getContext());
    281         towernew->addTemplate("towerturret");
    282         towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 75);
    283         towernew->setGame(this);
    284     }
    285 
    286     bool TowerDefense::hasEnoughCreditForTower(int towerCost)
    287     {
    288         return ((this->getCredit()) >= towerCost);
    289     }
    290 
    291 
    292     bool TowerDefense::hasEnoughCreditForUpgrade()
    293     {
    294         return true;
    295     }
    296 
    297  
    298     void TowerDefense::tick(float dt)
    299     {
    300         SUPER(TowerDefense, tick, dt);
    301         time +=dt;
    302 
    303         TDCoordinate* coord1 = new TDCoordinate(1,1);
    304         std::vector<TDCoordinate*> path;
    305         path.push_back(coord1);
    306         if(time>1 && TowerDefenseEnemyvector.size() < 30)
     297        time += dt;       
     298
     299        //build/upgrade tower at selecter position
     300        if (selecter != NULL && selecter->buildTower_ == true)
     301        {
     302            selecter->buildTower_ = false;
     303
     304            if (getField(selecter->selectedPos_)->canUpgrade() == true)
     305            {
     306                upgradeTower(selecter->selectedPos_->GetX(), selecter->selectedPos_->GetY());
     307            }
     308            else
     309            {
     310                addTower(selecter->selectedPos_->GetX(), selecter->selectedPos_->GetY());
     311            }           
     312        }
     313
     314        if (time >= 1.3 * enemies_.size() && enemies_.size() < 10)
    307315        {
    308316            //adds different types of enemys depending on the WaveNumber
    309             addTowerDefenseEnemy(path, this->getWaveNumber() % 3 +1 );
    310             time = time-1;
    311         }
    312 
    313         Vector3* endpoint = new Vector3(500, 700, 150);
     317            addTowerDefenseEnemy(this->getWaveNumber() % 3 +1 );
     318        }
     319
    314320        //if ships are at the end they get destroyed
    315         for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i)
    316         {
    317             if(TowerDefenseEnemyvector.at(i) != NULL && TowerDefenseEnemyvector.at(i)->isAlive())
    318             {
    319                 //destroys enemys at the end of teh path and reduces the life by 1. no credits gifted
    320 
    321                 Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition();
    322                 float distance = ship.distance(*endpoint);
    323 
    324                 if(distance <50){
    325                     TowerDefenseEnemyvector.at(i)->destroy();
    326                     this->reduceLifes(1);
    327                     this->buyTower(1);
    328                     if (this->getLifes()==0)
    329                     {
    330                         this->end();
    331                     }
     321
     322        std::vector<orxonox::WeakPtr<TowerDefenseEnemy> >::iterator itBegin = enemies_.begin();
     323        std::vector<orxonox::WeakPtr<TowerDefenseEnemy> >::iterator it = itBegin;
     324        std::vector<orxonox::WeakPtr<TowerDefenseEnemy> >::iterator itEnd = enemies_.end();
     325
     326        while(it != itEnd)
     327        {
     328            //destroys enemys at the end of the path and reduces the life by 1. No credits gifted
     329            Vector3 ship = (*it)->getRVWorldPosition();
     330            float distance = ship.distance(endpoint_);
     331            if(distance < 50)
     332            {
     333                std::vector<orxonox::WeakPtr<TowerDefenseEnemy> >::iterator itTemp = it;
     334                ++ it;
     335                orxout() << "enemy deleted" << endl;               
     336                enemies_.erase(itTemp);
     337                (*itTemp)->destroy();
     338                this->reduceLifes(1);
     339                if (this->getLifes() == 0)
     340                {
     341                    this->end();
    332342                }
    333343            }
    334         }
    335         //goes thorugh vector to see if an enemy is still alive. if not next wave is launched
    336         int count= 0;
    337         for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i)
    338         {
    339             if(TowerDefenseEnemyvector.at(i)!= NULL)
    340             {
    341                 ++count;
    342             }
    343         }
    344 
    345         if(count== 0)
    346         {
    347             time2 +=dt;
    348             if(time2 > 10)
    349             {
    350                 TowerDefenseEnemyvector.clear();
    351                 this->nextwave();
    352                 time=0;
    353                 time2=0;
    354             }
    355         }
    356 
    357 
    358     }
    359 
    360     // Function to test if we can add waypoints using code only. Doesn't work yet
    361 
    362     // THE PROBLEM: WaypointController's getControllableEntity() returns null, so it won't track. How do we get the controlableEntity to NOT BE NULL???
    363     /*
    364     void TowerDefense::addWaypointsAndFirstEnemy()
    365     {
    366         SpaceShip *newShip = new SpaceShip(this->center_);
    367         newShip->addTemplate("spaceshipassff");
    368 
    369         WaypointController *newController = new WaypointController(newShip);
    370         newController->setAccuracy(3);
    371 
    372         Model *wayPoint1 = new Model(newController);
    373         wayPoint1->setMeshSource("crate.mesh");
    374         wayPoint1->setPosition(7,-7,5);
    375         wayPoint1->setScale(0.2);
    376 
    377         Model *wayPoint2 = new Model(newController);
    378         wayPoint2->setMeshSource("crate.mesh");
    379         wayPoint2->setPosition(7,7,5);
    380         wayPoint2->setScale(0.2);
    381 
    382         newController->addWaypoint(wayPoint1);
    383         newController->addWaypoint(wayPoint2);
    384 
    385         // The following line causes the game to crash
    386 
    387         newShip->setController(newController);
    388 //        newController -> getPlayer() -> startControl(newShip);
    389         newShip->setPosition(-7,-7,5);
    390         newShip->setScale(0.1);
    391         //newShip->addSpeed(1);
    392 
    393 
    394 
    395 //      this->center_->attach(newShip);
    396     }
    397     */
     344            else
     345            {
     346                ++ it;
     347            }
     348        }       
     349
     350        if (enemies_.size() == 0 && !this->nextwaveTimer_.isActive())
     351        {
     352            this->nextwaveTimer_.startTimer();
     353        }
     354    }
     355
     356    void TowerDefense::createFields()
     357    {
     358        assert(center_);
     359        TDCoordinate coord(0,0);
     360        TDCoordinate startCoord(0,0);
     361
     362        std::string fields = center_->getFields();
     363        int pos = 0;
     364        for (int j = 15; j >= 0; --j)
     365        {
     366            for (int i = 0; i < 16; ++i)
     367            {
     368                coord.Set(i,j);
     369                fields_[i][j] = new TowerDefenseField(center_->getContext());
     370                fields_[i][j]->setCenterpoint(center_);
     371                center_->attach(fields_[i][j]);
     372                fields_[i][j]->setPosition(coord.get3dcoordinate());               
     373                fields_[i][j]->create(fields.at(pos), fields.at(pos+1));           
     374                pos += 2;
     375                if (fields_[i][j]->getType() == START)
     376                {
     377                    startCoord.Set(i,j);
     378                    waypoints_.push_back(fields_[i][j]);
     379                }
     380            }
     381        }
     382
     383        //Place waypoints along the street for the waypoint controllers of the enemies
     384        TDCoordinate* thisCoord = &startCoord;
     385        TDCoordinate* nextCoord;
     386        while ((nextCoord = getNextStreetCoord(thisCoord)) != NULL)
     387        {
     388            waypoints_.push_back(fields_[nextCoord->GetX()][nextCoord->GetY()]);           
     389            thisCoord = nextCoord;
     390            endpoint_ = nextCoord->get3dcoordinate();
     391        }
     392
     393    }
     394
     395    TDCoordinate* TowerDefense::getNextStreetCoord(TDCoordinate* thisCoord)
     396    {       
     397        TowerDefenseField* thisField = fields_[thisCoord->GetX()][thisCoord->GetY()];
     398        TDCoordinate* nextCoord = new TDCoordinate(0,0);
     399
     400        if (thisField->getType() != STREET && thisField->getType() != START)
     401        {
     402            return NULL;
     403        }
     404
     405        if (thisField->getAngle() == 0)
     406        {
     407            nextCoord->Set(thisCoord->GetX(), thisCoord->GetY() - 1);
     408        }
     409        else if (thisField->getAngle() == 1)
     410        {
     411            nextCoord->Set(thisCoord->GetX() + 1, thisCoord->GetY());
     412        }
     413        else if (thisField->getAngle() == 2)
     414        {
     415            nextCoord->Set(thisCoord->GetX(), thisCoord->GetY() + 1);
     416        }
     417        else if (thisField->getAngle() == 3)
     418        {
     419            nextCoord->Set(thisCoord->GetX() - 1, thisCoord->GetY());
     420        }
     421
     422        if (thisCoord->GetX() != nextCoord->GetX() || thisCoord->GetY() != nextCoord->GetY())
     423        {
     424            return nextCoord;
     425        }
     426
     427        return NULL;
     428    }
     429
    398430    /*
    399431    void TowerDefense::playerEntered(PlayerInfo* player)
    400432    {
    401         Deathmatch::playerEntered(player);
     433        TeamDeathmatch::playerEntered(player);
    402434
    403435        const std::string& message = player->getName() + " entered the game";
     
    407439    bool TowerDefense::playerLeft(PlayerInfo* player)
    408440    {
    409         bool valid_player = Deathmatch::playerLeft(player);
     441        bool valid_player = TeamDeathmatch::playerLeft(player);
    410442
    411443        if (valid_player)
     
    437469        }
    438470
    439         Deathmatch::pawnKilled(victim, killer);
     471        TeamDeathmatch::pawnKilled(victim, killer);
    440472    }
    441473
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefense.h

    r10258 r10586  
    3838#define _TowerDefense_H__
    3939#include "TDCoordinate.h"
     40#include "TowerDefenseSelecter.h"
    4041#include "towerdefense/TowerDefensePrereqs.h"
    41 #include "gametypes/Deathmatch.h"
     42#include "gametypes/TeamDeathmatch.h"
    4243#include "TowerDefenseEnemy.h"
    4344#include "util/Output.h"
    44 #include "core/object/WeakPtr.h"
     45#include "TowerDefenseField.h"
    4546
    4647namespace orxonox
    4748{
    48     class _TowerDefenseExport TowerDefense : public Deathmatch
     49    class _TowerDefenseExport TowerDefense : public TeamDeathmatch
    4950    {
    5051    public:
    5152        TowerDefense(Context* context);
    52         virtual ~TowerDefense();
    53 
    54         std::vector<orxonox::WeakPtr<TowerDefenseEnemy> > TowerDefenseEnemyvector;
    55         bool towermatrix[16][16];
    56         void addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr);
     53        virtual ~TowerDefense();       
     54        void addTowerDefenseEnemy(int templatenr);
    5755        virtual void start(); //<! The function is called when the gametype starts
    5856        virtual void end();
    5957        virtual void tick(float dt);
    60         //virtual void playerEntered(PlayerInfo* player);
    61         //virtual bool playerLeft(PlayerInfo* player);
    62         //Player Stats (set,get, reduce)
     58        virtual void spawnPlayer(PlayerInfo* player);
     59        PlayerInfo* getPlayer(void) const;
    6360        int getCredit(){ return this->credit_; }
     61        void payCredit(int pay){ this->credit_ -= pay; }
    6462        int getLifes(){ return this->lifes_; }
    6563        int getWaveNumber(){ return this->waves_; }
     
    6967        void buyTower(int cost){ credit_ -= cost;}
    7068        void addCredit(int credit) { credit_+=credit; }
    71         void nextwave(){ waves_++;}
     69        void nextwave(){ enemies_.clear(); waves_++; time=0;}
    7270        int reduceLifes(int NumberofLifes){ return lifes_-=NumberofLifes; }
     71        TowerDefenseField* getField(TDCoordinate* coord){ return fields_[coord->GetX()][coord->GetY()]; }
     72        /*  Called by TowerDefenseCenterpoint upon game start
     73            The centerpoint is used to create towers
     74        */
     75        void setCenterpoint(TowerDefenseCenterpoint* centerpoint);       
     76        /* Adds a tower at x, y in the playfield */
     77        void addTower(int x, int y);
     78        void upgradeTower(int x, int y);
     79        virtual TDCoordinate* getNextStreetCoord(TDCoordinate*);
    7380
    7481        //virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
    7582        //virtual void playerScored(PlayerInfo* player, int score);
    7683
    77 
    78         /*  Called by TowerDefenseCenterpoint upon game start
    79             The centerpoint is used to create towers
    80         */
    81         void setCenterpoint(TowerDefenseCenterpoint *centerpoint);
    82 
    83         /* Adds a tower at x, y in the playfield */
    84         void addTower(int x, int y);
    85 
    86         void upgradeTower(int x, int y);
    87         /* Part of a temporary hack to allow the player to add towers */
    88         ConsoleCommand* dedicatedAddTower_;
    89         ConsoleCommand* dedicatedUpgradeTower_;
     84        TowerDefenseSelecter* selecter;       
    9085
    9186        //TODO: void spawnNewWave()
     
    9388        //      or spawn a new wave when the old wave has been killed           (event driven)
    9489
    95 
    9690    private:
    97         TowerDefenseCenterpoint *center_;
    98         float time;
    99         float time2;
     91        orxonox::WeakPtr<TowerDefenseCenterpoint> center_;
     92        PlayerInfo* player_;
     93        float time;       
    10094        int credit_;
    10195        int waves_;
    10296        int lifes_;
     97        Timer nextwaveTimer_;
     98        std::vector<orxonox::WeakPtr<TowerDefenseEnemy> > enemies_;
     99        TowerDefenseField* fields_[16][16];
     100        std::vector<orxonox::WeakPtr<TowerDefenseField> > waypoints_;
     101        Vector3 endpoint_;
    103102
    104         /* handles stats */
    105         bool hasEnoughCreditForTower(int towerCost);
    106         bool hasEnoughCreditForUpgrade();
    107 
    108 
    109 
    110         std::vector<TowerTurret*> towers_;
     103        void createFields();
    111104    };
    112105}
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefenseCenterpoint.cc

    r9667 r10586  
    5353        this->width_ = 15;
    5454        this->height_ = 15;
    55         this->towerTemplate_ = "";
    5655
    5756        //this->setCollisionType(Static);
     
    7271        XMLPortParam(TowerDefenseCenterpoint, "height", setHeight, getHeight, xmlelement, mode);
    7372        XMLPortParam(TowerDefenseCenterpoint, "tileScale", setTileScale, getTileScale, xmlelement, mode);
    74         XMLPortParam(TowerDefenseCenterpoint, "towerTemplate", setTowerTemplate, getTowerTemplate, xmlelement, mode);
     73        XMLPortParam(TowerDefenseCenterpoint, "selecterTemplate", setSelecterTemplate, getSelecterTemplate, xmlelement, mode);
     74        XMLPortParam(TowerDefenseCenterpoint, "tower1Template", setTower1Template, getTower1Template, xmlelement, mode);
     75        XMLPortParam(TowerDefenseCenterpoint, "tower2Template", setTower2Template, getTower2Template, xmlelement, mode);
     76        XMLPortParam(TowerDefenseCenterpoint, "tower3Template", setTower3Template, getTower3Template, xmlelement, mode);
     77        XMLPortParam(TowerDefenseCenterpoint, "tower4Template", setTower4Template, getTower4Template, xmlelement, mode);
     78        XMLPortParam(TowerDefenseCenterpoint, "tower5Template", setTower5Template, getTower5Template, xmlelement, mode);
     79        XMLPortParam(TowerDefenseCenterpoint, "fields", setFields, getFields, xmlelement, mode);
     80        XMLPortParam(TowerDefenseCenterpoint, "tower1Cost", setTower1Cost, getTower1Cost, xmlelement, mode);
     81        XMLPortParam(TowerDefenseCenterpoint, "tower2Cost", setTower2Cost, getTower2Cost, xmlelement, mode);
     82        XMLPortParam(TowerDefenseCenterpoint, "tower3Cost", setTower3Cost, getTower3Cost, xmlelement, mode);
     83        XMLPortParam(TowerDefenseCenterpoint, "tower4Cost", setTower4Cost, getTower4Cost, xmlelement, mode);
     84        XMLPortParam(TowerDefenseCenterpoint, "tower5Cost", setTower5Cost, getTower5Cost, xmlelement, mode);
    7585
    7686        //TODO: add XMLPortObject(TowerDefenseCenterpoint, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
     
    107117        }
    108118    }
     119
     120    /**
     121    @brief
     122        Removes all blanks, tabs and returns from the string passed.
     123    */
     124    void TowerDefenseCenterpoint::trimString(std::string* str)
     125    {
     126        std::string* trimmed = new std::string("");
     127        int length = str->size();
     128        char temp;
     129        for (int i = 0; i < length; ++ i)
     130        {
     131            temp = str->at(i);
     132            if (temp != ' ' && temp != '\t' && temp != '\n')
     133            {
     134                trimmed->push_back(temp);
     135            }
     136        }
     137
     138        *str = *trimmed;
     139    }
     140
     141    const int TowerDefenseCenterpoint::getTowerCost(int upgrade) const
     142    {
     143        return towerCosts_[(upgrade%5)];
     144    }
    109145}
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefenseCenterpoint.h

    r9667 r10586  
    4141#include <string>
    4242#include <util/Math.h>
    43 
     43#include "TowerDefenseTower.h"
    4444#include "worldentities/MobileEntity.h"
    4545
     
    6060            void setWidth(unsigned int width)
    6161                { this->width_ = width; }
    62 
    6362            unsigned int getWidth(void) const
    6463                { return this->width_; }
    65 
    6664            void setHeight(unsigned int height)
    6765                { this->height_ = height; }
    68 
    6966            unsigned int getHeight(void) const
    7067                { return this->height_; }
     68            void setFields(const std::string& newFields)
     69                { this->fields_ = newFields; trimString(&fields_); }
     70            const std::string& getFields() const
     71                { return this->fields_; }                   
     72            void setSelecterTemplate(const std::string& newTemplate)
     73                { this->selecterTemplate_ = newTemplate; }
     74            const std::string& getSelecterTemplate() const
     75                { return this->selecterTemplate_; }   
     76
     77            void setTower1Template(const std::string& newTemplate)
     78                { this->towerTemplates_[0] = newTemplate;}
     79            const std::string& getTower1Template() const
     80                { return this->towerTemplates_[0]; } 
     81            void setTower2Template(const std::string& newTemplate)
     82                { this->towerTemplates_[1] = newTemplate; }
     83            const std::string& getTower2Template() const
     84                { return this->towerTemplates_[1]; }
     85            void setTower3Template(const std::string& newTemplate)
     86                { this->towerTemplates_[2] = newTemplate; }
     87            const std::string& getTower3Template() const
     88                { return this->towerTemplates_[2]; }
     89            void setTower4Template(const std::string& newTemplate)
     90                { this->towerTemplates_[3] = newTemplate; }
     91            const std::string& getTower4Template() const
     92                { return this->towerTemplates_[3]; }
     93            void setTower5Template(const std::string& newTemplate)
     94                { this->towerTemplates_[4] = newTemplate; }
     95            const std::string& getTower5Template() const
     96                { return this->towerTemplates_[4]; } 
     97
     98            void setTower1Cost(const int& newCost)
     99                { this->towerCosts_[0] = newCost;}
     100            const int& getTower1Cost() const
     101                { return this->towerCosts_[0]; } 
     102            void setTower2Cost(const int& newCost)
     103                { this->towerCosts_[1] = newCost; }
     104            const int& getTower2Cost() const
     105                { return this->towerCosts_[1]; }
     106            void setTower3Cost(const int& newCost)
     107                { this->towerCosts_[2] = newCost; }
     108            const int& getTower3Cost() const
     109                { return this->towerCosts_[2]; }
     110            void setTower4Cost(const int& newCost)
     111                { this->towerCosts_[3] = newCost; }
     112            const int& getTower4Cost() const
     113                { return this->towerCosts_[3]; }
     114            void setTower5Cost(const int& newCost)
     115                { this->towerCosts_[4] = newCost; }
     116            const int& getTower5Cost() const
     117                { return this->towerCosts_[4]; }
     118
     119            const int getTowerCost(int upgrade) const;
     120                                           
    71121
    72122            /**
     
    79129                { return this->tileScale_; }
    80130
    81             /**
    82             @brief Set the template for the towers.
    83             @param template The template name to be applied to each tower.
    84             */
    85             void setTowerTemplate(const std::string& templateName)
    86                 { this->towerTemplate_ = templateName; }
    87 
    88             const std::string& getTowerTemplate(void) const
    89                 { return this->towerTemplate_; }
    90 
    91131        private:
    92132            void checkGametype();
    93 
     133            void trimString(std::string*);
     134            std::string selecterTemplate_;
     135            std::string towerTemplates_[5];
     136            int towerCosts_[5];
     137            std::string fields_;
    94138            unsigned int width_;
    95139            unsigned int height_;
    96140            unsigned int tileScale_;
    97 
    98             std::string towerTemplate_;
    99141    };
    100142}
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefenseEnemy.cc

    r10258 r10586  
    3030        //needed to keep track of the PlayerStats coded in TowerDefense.h
    3131        this->td = orxonox_cast<TowerDefense*>(this->getGametype().get());
    32         once_=false;
    33 
    34     }
    35     //add credit if enemy is destroyed
    36     TowerDefenseEnemy::~TowerDefenseEnemy(){
    37         //this->td->addCredit(1);
     32        once_ = false;
    3833    }
    3934
    40     void TowerDefenseEnemy::addWaypoint(TDCoordinate* coord)
     35    TowerDefenseEnemy::~TowerDefenseEnemy()
    4136    {
    42         this->Waypointsvector_.push_back(coord);
     37        orxout() << "TowerDefenseEnemy::~TowerDefenseEnemy" << endl;
    4338    }
    4439
    45 
    4640    void TowerDefenseEnemy::tick(float dt)
    47     {
     41    {   
     42        //orxout() << "TDE tick1" << endl;
    4843        SUPER(TowerDefenseEnemy, tick, dt);
     44        //orxout() << "TDE tick2" << endl;
    4945    }
    5046
     
    6157    void TowerDefenseEnemy::damage(float damage, float healthdamage, float shielddamage, Pawn* originator)
    6258    {
     59        orxout() << "TowerDefenseEnemy::damage" << endl;
    6360        Pawn::damage(damage, healthdamage, shielddamage, originator);
    6461        if (getGame() && once_ == false && getHealth() <= 0)
     
    6865        }
    6966    }
    70 /*
    71     void TowerDefenseEnemy::popWaypoint()
    72     {
    73         if(Waypointsvector_.size()>0)
    74             Waypointsvector_.pop_back();
    75     }
    76 
    77     TDCoordinate TowerDefenseEnemy::peekWaypoint()
    78     {
    79         if(Waypointsvector_.size()<=0){
    80             TDCoordinate* coord = TDCoordinate(-1,-1);
    81             return coord;
    82         }else{
    83             return Waypointsvector_.at(Waypointsvector_.size()-1);
    84 
    85         }
    86 
    87 
    88     }
    89 */
    90 
    9167}
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefenseEnemy.h

    r10258 r10586  
    3939
    4040        virtual void tick(float dt);
    41         void addWaypoint(TDCoordinate* coord);
    42         void popWaypoint();
    43         TDCoordinate peekWaypoint();
    44 
    4541        virtual void damage(float damage, float healthdamage, float shielddamage, Pawn* originator);
    46 
    4742
    4843    private:
     
    5146        TowerDefense* td;
    5247        bool once_;
    53         std::vector<TDCoordinate*> Waypointsvector_;
    54 
    5548    };
    5649
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefenseTower.cc

    r10258 r10586  
    2222        Constructor. Registers and initializes the object.
    2323    */
    24     TowerDefenseTower::TowerDefenseTower(Context* context) : Pawn(context)
     24    TowerDefenseTower::TowerDefenseTower(Context* context) : Turret(context)
    2525    {
    2626        RegisterObject(TowerDefenseTower);
    27 
    28         this->setCollisionType(WorldEntity::Dynamic);
    29         upgrade = 0;
     27        game_ =NULL;
     28        this->setCollisionType(WorldEntity::None);
     29        upgrade = 1;
    3030
    3131        //this->removeAllEngines();
     
    3838    }
    3939
     40    /*
    4041    void TowerDefenseTower::setOrientation(const Quaternion& orientation)
    4142    {
     
    5354    {
    5455    }
     56    */
    5557
    5658    bool TowerDefenseTower::upgradeTower()
    5759    {
    58         if(upgrade < 3)
     60        if(upgrade < 5)
    5961        {
    6062            upgrade++;
    6163            float reloadrate = getReloadRate();
    6264            float reloadwaittime = getReloadWaitTime();
    63             this->setDamageMultiplier(5000);
    64 
     65            this->setDamageMultiplier((upgrade+1)*2);
     66            //this->setRotationThrust(2*this->getRotationThrust());
    6567            reloadrate = 0.5f*reloadrate;
    6668            reloadwaittime = 0.5f*reloadwaittime;
    6769            setReloadRate(reloadrate);
    6870            setReloadWaitTime(reloadwaittime);
    69             this->addTemplate("towerturret1");
     71            //this->addTemplate("towerturret1");
    7072        }
    7173        else
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefenseTower.h

    r10258 r10586  
    1919
    2020#include "towerdefense/TowerDefensePrereqs.h"
    21 #include "worldentities/pawns/SpaceShip.h"
     21#include "objects/Turret.h"
    2222
    2323
    2424namespace orxonox
    2525{
    26     class _TowerDefenseExport TowerDefenseTower : public Pawn
     26    class _TowerDefenseExport TowerDefenseTower : public Turret
    2727    {
    2828    public:
     
    3737
    3838        // Overriding these to stop TowerDefenseTowers from spasing out
    39         void setOrientation(const Quaternion& orientation);
    40         virtual void rotateYaw(const Vector2& value);
    41         virtual void rotatePitch(const Vector2& value);
    42         virtual void rotateRoll(const Vector2& value);
     39        //void setOrientation(const Quaternion& orientation);
     40        //virtual void rotateYaw(const Vector2& value);
     41        //virtual void rotatePitch(const Vector2& value);
     42        //virtual void rotateRoll(const Vector2& value);
    4343        virtual bool upgradeTower();
    4444
Note: See TracChangeset for help on using the changeset viewer.