- Timestamp:
- Dec 16, 2008, 6:01:13 PM (17 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
-
code/branches/presentation/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2371 r2485 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 39 #include "objects/weaponSystem/WeaponSystem.h" 40 #include "objects/worldentities/ParticleSpawner.h" 41 #include "objects/worldentities/ExplosionChunk.h" 38 42 39 43 namespace orxonox … … 45 49 RegisterObject(Pawn); 46 50 47 this->bAlive_ = false; 51 PawnManager::touch(); 52 53 this->bAlive_ = true; 48 54 49 55 this->health_ = 0; … … 53 59 this->lastHitOriginator_ = 0; 54 60 this->weaponSystem_ = 0; 61 62 this->spawnparticleduration_ = 3.0f; 55 63 56 64 /* … … 62 70 */ 63 71 72 this->setRadarObjectColour(ColourValue::Red); 73 this->setRadarObjectShape(RadarViewable::Dot); 74 64 75 this->registerVariables(); 65 76 } … … 67 78 Pawn::~Pawn() 68 79 { 80 if (this->isInitialized()) 81 { 82 for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it) 83 it->destroyedPawn(this); 84 } 69 85 } 70 86 … … 73 89 SUPER(Pawn, XMLPort, xmlelement, mode); 74 90 75 XMLPortParam(Pawn, "health", setHealth, getHeal ht, xmlelement, mode).defaultValues(100);91 XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100); 76 92 XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200); 77 93 XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100); 94 XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); 95 XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); 96 XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7); 78 97 } 79 98 80 99 void Pawn::registerVariables() 81 100 { 82 registerVariable(this->bAlive_, variableDirection::toclient); 83 registerVariable(this->health_, variableDirection::toclient); 101 registerVariable(this->bAlive_, variableDirection::toclient); 102 registerVariable(this->health_, variableDirection::toclient); 103 registerVariable(this->initialHealth_, variableDirection::toclient); 84 104 } 85 105 … … 119 139 } 120 140 121 void Pawn::spawn ()141 void Pawn::spawneffect() 122 142 { 123 143 // play spawn effect 144 if (this->spawnparticlesource_ != "") 145 { 146 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 147 effect->setPosition(this->getPosition()); 148 effect->setOrientation(this->getOrientation()); 149 effect->setDestroyAfterLife(true); 150 effect->setSource(this->spawnparticlesource_); 151 effect->setLifetime(this->spawnparticleduration_); 152 } 124 153 } 125 154 126 155 void Pawn::death() 127 156 { 157 // Set bAlive_ to false and wait for PawnManager to do the destruction 128 158 this->bAlive_ = false; 159 160 this->setDestroyWhenPlayerLeft(false); 161 129 162 if (this->getGametype()) 130 163 this->getGametype()->pawnKilled(this, this->lastHitOriginator_); 164 131 165 if (this->getPlayer()) 132 166 this->getPlayer()->stopControl(this); 133 167 134 delete this; 135 168 if (Core::isMaster()) 169 this->deatheffect(); 170 } 171 172 void Pawn::deatheffect() 173 { 136 174 // play death effect 175 { 176 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 177 effect->setPosition(this->getPosition()); 178 effect->setOrientation(this->getOrientation()); 179 effect->setDestroyAfterLife(true); 180 effect->setSource("Orxonox/explosion2b"); 181 effect->setLifetime(4.0f); 182 } 183 { 184 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 185 effect->setPosition(this->getPosition()); 186 effect->setOrientation(this->getOrientation()); 187 effect->setDestroyAfterLife(true); 188 effect->setSource("Orxonox/smoke6"); 189 effect->setLifetime(4.0f); 190 } 191 { 192 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 193 effect->setPosition(this->getPosition()); 194 effect->setOrientation(this->getOrientation()); 195 effect->setDestroyAfterLife(true); 196 effect->setSource("Orxonox/sparks"); 197 effect->setLifetime(4.0f); 198 } 199 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) 200 { 201 ExplosionChunk* chunk = new ExplosionChunk(this->getCreator()); 202 chunk->setPosition(this->getPosition()); 203 204 } 137 205 } 138 206 … … 146 214 { 147 215 this->setHealth(this->initialHealth_); 148 this->spawn(); 216 if (Core::isMaster()) 217 this->spawneffect(); 218 } 219 220 /////////////////// 221 // Pawn Listener // 222 /////////////////// 223 PawnListener::PawnListener() 224 { 225 RegisterRootObject(PawnListener); 149 226 } 150 227 }
Note: See TracChangeset
for help on using the changeset viewer.