- Timestamp:
- Feb 14, 2009, 10:17:35 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2171 r2662 30 30 #include "Pawn.h" 31 31 32 #include "core/Core.h" 32 33 #include "core/CoreIncludes.h" 33 34 #include "core/XMLPort.h" 34 35 #include "util/Math.h" 36 #include "PawnManager.h" 35 37 #include "objects/infos/PlayerInfo.h" 36 38 #include "objects/gametypes/Gametype.h" 37 #include "objects/weaponSystem/WeaponSystem.h" 39 #include "objects/worldentities/ParticleSpawner.h" 40 #include "objects/worldentities/ExplosionChunk.h" 38 41 39 42 namespace orxonox … … 45 48 RegisterObject(Pawn); 46 49 47 this->bAlive_ = false; 50 PawnManager::touch(); 51 this->bAlive_ = true; 52 this->fire_ = 0x0; 53 this->firehack_ = 0x0; 48 54 49 55 this->health_ = 0; … … 52 58 53 59 this->lastHitOriginator_ = 0; 54 this->weaponSystem_ = 0; 55 56 /* 57 //WeaponSystem 58 weaponSystem_ = new WeaponSystem(); 59 WeaponSet * weaponSet1 = new WeaponSet(1); 60 this->weaponSystem_->attachWeaponSet(weaponSet1); 61 this->weaponSystem_->getWeaponSetPointer(0)->getWeaponSlotPointer(0)->setAmmoType(true); 62 */ 60 61 this->spawnparticleduration_ = 3.0f; 62 63 this->getPickUp().setPlayer(this); 64 65 if (Core::isMaster()) 66 { 67 this->weaponSystem_ = new WeaponSystem(this); 68 this->weaponSystem_->setParentPawn(this); 69 } 70 else 71 this->weaponSystem_ = 0; 72 73 this->setRadarObjectColour(ColourValue::Red); 74 this->setRadarObjectShape(RadarViewable::Dot); 63 75 64 76 this->registerVariables(); … … 67 79 Pawn::~Pawn() 68 80 { 81 if (this->isInitialized()) 82 { 83 for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it) 84 it->destroyedPawn(this); 85 86 if (this->weaponSystem_) 87 delete this->weaponSystem_; 88 } 69 89 } 70 90 … … 73 93 SUPER(Pawn, XMLPort, xmlelement, mode); 74 94 75 XMLPortParam(Pawn, "health", setHealth, getHeal ht, xmlelement, mode).defaultValues(100);95 XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100); 76 96 XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200); 77 97 XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100); 98 XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); 99 XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); 100 XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7); 101 102 XMLPortObject(Pawn, WeaponSlot, "weaponslots", setWeaponSlot, getWeaponSlot, xmlelement, mode); 103 XMLPortObject(Pawn, WeaponSet, "weaponsets", setWeaponSet, getWeaponSet, xmlelement, mode); 104 XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode); 78 105 } 79 106 80 107 void Pawn::registerVariables() 81 108 { 82 REGISTERDATA(this->bAlive_, direction::toclient); 83 REGISTERDATA(this->health_, direction::toclient); 109 registerVariable(this->bAlive_, variableDirection::toclient); 110 registerVariable(this->health_, variableDirection::toclient); 111 registerVariable(this->initialHealth_, variableDirection::toclient); 112 registerVariable(this->fire_, variableDirection::toserver); 84 113 } 85 114 … … 87 116 { 88 117 SUPER(Pawn, tick, dt); 118 119 if (this->weaponSystem_) 120 { 121 if (this->fire_ & WeaponMode::fire) 122 this->weaponSystem_->fire(WeaponMode::fire); 123 if (this->fire_ & WeaponMode::altFire) 124 this->weaponSystem_->fire(WeaponMode::altFire); 125 if (this->fire_ & WeaponMode::altFire2) 126 this->weaponSystem_->fire(WeaponMode::altFire2); 127 } 128 this->fire_ = this->firehack_; 129 this->firehack_ = 0x0; 89 130 90 131 if (this->health_ <= 0) … … 119 160 } 120 161 121 void Pawn::spawn ()162 void Pawn::spawneffect() 122 163 { 123 164 // play spawn effect 165 if (this->spawnparticlesource_ != "") 166 { 167 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 168 effect->setPosition(this->getPosition()); 169 effect->setOrientation(this->getOrientation()); 170 effect->setDestroyAfterLife(true); 171 effect->setSource(this->spawnparticlesource_); 172 effect->setLifetime(this->spawnparticleduration_); 173 } 124 174 } 125 175 126 176 void Pawn::death() 127 177 { 178 // Set bAlive_ to false and wait for PawnManager to do the destruction 128 179 this->bAlive_ = false; 180 181 this->setDestroyWhenPlayerLeft(false); 182 129 183 if (this->getGametype()) 130 184 this->getGametype()->pawnKilled(this, this->lastHitOriginator_); 185 131 186 if (this->getPlayer()) 132 187 this->getPlayer()->stopControl(this); 133 188 134 delete this; 135 189 if (Core::isMaster()) 190 this->deatheffect(); 191 } 192 193 void Pawn::deatheffect() 194 { 136 195 // play death effect 137 } 138 139 void Pawn::fire() 140 { 141 if (this->weaponSystem_) 142 this->weaponSystem_->fire(); 196 { 197 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 198 effect->setPosition(this->getPosition()); 199 effect->setOrientation(this->getOrientation()); 200 effect->setDestroyAfterLife(true); 201 effect->setSource("Orxonox/explosion2b"); 202 effect->setLifetime(4.0f); 203 } 204 { 205 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 206 effect->setPosition(this->getPosition()); 207 effect->setOrientation(this->getOrientation()); 208 effect->setDestroyAfterLife(true); 209 effect->setSource("Orxonox/smoke6"); 210 effect->setLifetime(4.0f); 211 } 212 { 213 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 214 effect->setPosition(this->getPosition()); 215 effect->setOrientation(this->getOrientation()); 216 effect->setDestroyAfterLife(true); 217 effect->setSource("Orxonox/sparks"); 218 effect->setLifetime(4.0f); 219 } 220 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) 221 { 222 ExplosionChunk* chunk = new ExplosionChunk(this->getCreator()); 223 chunk->setPosition(this->getPosition()); 224 225 } 226 } 227 228 void Pawn::fire(WeaponMode::Enum fireMode) 229 { 230 this->firehack_ |= fireMode; 143 231 } 144 232 … … 146 234 { 147 235 this->setHealth(this->initialHealth_); 148 this->spawn(); 236 if (Core::isMaster()) 237 this->spawneffect(); 238 } 239 240 void Pawn::dropItems() 241 { 242 pickUp.eraseAll(); 243 } 244 245 void Pawn::setWeaponSlot(WeaponSlot * wSlot) 246 { 247 this->attach(wSlot); 248 if (this->weaponSystem_) 249 this->weaponSystem_->attachWeaponSlot(wSlot); 250 } 251 252 WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const 253 { 254 if (this->weaponSystem_) 255 return this->weaponSystem_->getWeaponSlotPointer(index); 256 else 257 return 0; 258 } 259 260 void Pawn::setWeaponPack(WeaponPack * wPack) 261 { 262 if (this->weaponSystem_) 263 { 264 wPack->setParentWeaponSystem(this->weaponSystem_); 265 wPack->setParentWeaponSystemToAllWeapons(this->weaponSystem_); 266 this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() ); 267 wPack->attachNeededMunitionToAllWeapons(); 268 } 269 } 270 271 WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const 272 { 273 if (this->weaponSystem_) 274 return this->weaponSystem_->getWeaponPackPointer(firemode); 275 else 276 return 0; 277 } 278 279 void Pawn::setWeaponSet(WeaponSet * wSet) 280 { 281 if (this->weaponSystem_) 282 this->weaponSystem_->attachWeaponSet(wSet); 283 } 284 285 WeaponSet * Pawn::getWeaponSet(unsigned int index) const 286 { 287 if (this->weaponSystem_) 288 return this->weaponSystem_->getWeaponSetPointer(index); 289 else 290 return 0; 291 } 292 293 294 /////////////////// 295 // Pawn Listener // 296 /////////////////// 297 PawnListener::PawnListener() 298 { 299 RegisterRootObject(PawnListener); 149 300 } 150 301 }
Note: See TracChangeset
for help on using the changeset viewer.