- Timestamp:
- Dec 16, 2008, 6:01:13 PM (16 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 7 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 } -
code/branches/presentation/src/orxonox/objects/worldentities/pawns/Pawn.h
r2098 r2485 33 33 34 34 #include "objects/worldentities/ControllableEntity.h" 35 #include "objects/RadarViewable.h" 35 36 36 37 namespace orxonox 37 38 { 38 class _OrxonoxExport Pawn : public ControllableEntity 39 class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable 39 40 { 40 41 public: … … 54 55 inline void removeHealth(float health) 55 56 { this->setHealth(this->health_ - health); } 56 inline float getHeal ht() const57 inline float getHealth() const 57 58 { return this->health_; } 58 59 … … 78 79 virtual void postSpawn(); 79 80 81 inline const WorldEntity* getWorldEntity() const 82 { return (WorldEntity*)this; } 83 84 inline void setSpawnParticleSource(const std::string& source) 85 { this->spawnparticlesource_ = source; } 86 inline const std::string& getSpawnParticleSource() const 87 { return this->spawnparticlesource_; } 88 89 inline void setSpawnParticleDuration(float duration) 90 { this->spawnparticleduration_ = duration; } 91 inline float getSpawnParticleDuration() const 92 { return this->spawnparticleduration_; } 93 94 inline void setExplosionChunks(unsigned int chunks) 95 { this->numexplosionchunks_ = chunks; } 96 inline unsigned int getExplosionChunks() const 97 { return this->numexplosionchunks_; } 98 80 99 protected: 81 virtual void spawn();82 100 virtual void death(); 101 virtual void deatheffect(); 102 virtual void spawneffect(); 83 103 84 104 bool bAlive_; … … 91 111 92 112 WeaponSystem* weaponSystem_; 113 114 std::string spawnparticlesource_; 115 float spawnparticleduration_; 116 unsigned int numexplosionchunks_; 117 }; 118 119 class _OrxonoxExport PawnListener : public OrxonoxClass 120 { 121 friend class Pawn; 122 123 public: 124 PawnListener(); 125 virtual ~PawnListener() {} 126 127 protected: 128 virtual void destroyedPawn(Pawn* pawn) = 0; 93 129 }; 94 130 } -
code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2475 r2485 36 36 #include "core/CoreIncludes.h" 37 37 #include "core/ConfigValueIncludes.h" 38 #include "core/Template.h" 38 39 #include "core/XMLPort.h" 40 #include "objects/items/Engine.h" 39 41 40 42 namespace orxonox … … 53 55 this->localLinearAcceleration_.setValue(0, 0, 0); 54 56 this->localAngularAcceleration_.setValue(0, 0, 0); 57 this->bBoost_ = false; 58 this->steering_ = Vector3::ZERO; 59 this->engine_ = 0; 60 55 61 56 62 this->bInvertYAxis_ = false; … … 70 76 SpaceShip::~SpaceShip() 71 77 { 78 if (this->isInitialized() && this->engine_) 79 delete this->engine_; 72 80 } 73 81 … … 76 84 SUPER(SpaceShip, XMLPort, xmlelement, mode); 77 85 86 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 78 87 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 79 88 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); … … 109 118 SUPER(SpaceShip, tick, dt); 110 119 111 if (this-> isLocallyControlled())120 if (this->hasLocalController()) 112 121 { 113 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 114 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 115 if (this->localLinearAcceleration_.z() > 0) 116 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 117 else 118 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 119 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 120 this->localLinearAcceleration_.setValue(0, 0, 0); 122 if (!this->isInMouseLook()) 123 { 124 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 125 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 126 if (this->localLinearAcceleration_.z() > 0) 127 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 128 else 129 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 130 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 131 this->localLinearAcceleration_.setValue(0, 0, 0); 132 } 121 133 122 134 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; … … 129 141 { 130 142 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 143 this->steering_.z = -value.x; 131 144 } 132 145 … … 134 147 { 135 148 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 149 this->steering_.x = value.x; 136 150 } 137 151 … … 139 153 { 140 154 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 155 this->steering_.y = value.x; 141 156 } 142 157 … … 144 159 { 145 160 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); 161 162 Pawn::rotateYaw(value); 146 163 } 147 164 … … 149 166 { 150 167 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); 168 169 Pawn::rotatePitch(value); 151 170 } 152 171 … … 154 173 { 155 174 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 175 176 Pawn::rotateRoll(value); 156 177 } 157 178 … … 159 180 { 160 181 } 182 183 void SpaceShip::boost() 184 { 185 this->bBoost_ = true; 186 } 187 188 void SpaceShip::loadEngineTemplate() 189 { 190 if (this->enginetemplate_ != "") 191 { 192 Template* temp = Template::getTemplate(this->enginetemplate_); 193 194 if (temp) 195 { 196 Identifier* identifier = temp->getBaseclassIdentifier(); 197 198 if (identifier) 199 { 200 BaseObject* object = identifier->fabricate(this); 201 this->engine_ = dynamic_cast<Engine*>(object); 202 203 if (this->engine_) 204 { 205 this->engine_->addTemplate(temp); 206 this->engine_->addToSpaceShip(this); 207 } 208 else 209 { 210 delete object; 211 } 212 } 213 } 214 } 215 } 216 217 void SpaceShip::setEngine(Engine* engine) 218 { 219 this->engine_ = engine; 220 if (engine && engine->getShip() != this) 221 engine->addToSpaceShip(this); 222 } 161 223 } -
code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.h
r2459 r2485 58 58 59 59 virtual void fire(); 60 virtual void boost(); 61 62 void setEngine(Engine* engine); 63 inline Engine* getEngine() const 64 { return this->engine_; } 65 66 inline void setSteeringDirection(const Vector3& direction) 67 { this->steering_ = direction; } 68 inline const Vector3& getSteeringDirection() const 69 { return this->steering_; } 70 71 inline void setBoost(bool bBoost) 72 { this->bBoost_ = bBoost; } 73 inline bool getBoost() const 74 { return this->bBoost_; } 75 76 inline void setEngineTemplate(const std::string& temp) 77 { this->enginetemplate_ = temp; this->loadEngineTemplate(); } 78 inline const std::string& getEngineTemplate() const 79 { return this->enginetemplate_; } 60 80 61 81 protected: 62 82 bool bInvertYAxis_; 63 83 84 bool bBoost_; 85 Vector3 steering_; 64 86 float primaryThrust_; 65 87 float auxilaryThrust_; … … 71 93 private: 72 94 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 95 96 private: 97 void loadEngineTemplate(); 98 99 std::string enginetemplate_; 100 Engine* engine_; 73 101 }; 74 102 } -
code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2480 r2485 33 33 34 34 #include "core/CoreIncludes.h" 35 #include "core/ConfigValueIncludes.h" 35 36 #include "core/Core.h" 36 37 #include "objects/worldentities/Model.h" … … 51 52 RegisterObject(Spectator); 52 53 53 this->speed_ = 100; 54 this->rotationGain_ = 3; 54 this->speed_ = 200; 55 55 56 56 this->yaw_ = 0; … … 59 59 this->localVelocity_ = Vector3::ZERO; 60 60 this->setHudTemplate("spectatorhud"); 61 this-> hudmode_ = 0;61 this->greetingFlare_ = 0; 62 62 63 63 this->setDestroyWhenPlayerLeft(true); 64 64 65 if ( Core::showsGraphics())66 65 if (Core::showsGraphics()) 66 { 67 67 this->greetingFlare_ = new BillboardSet(); 68 68 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); … … 71 71 this->greetingFlare_->setVisible(false); 72 72 } 73 else 74 this->greetingFlare_ = 0; 73 75 74 this->bGreetingFlareVisible_ = false; 76 75 this->bGreeting_ = false; 77 76 77 this->setConfigValues(); 78 78 this->registerVariables(); 79 79 } … … 87 87 if (this->greetingFlare_->getBillboardSet()) 88 88 this->detachOgreObject(this->greetingFlare_->getBillboardSet()); 89 89 90 delete this->greetingFlare_; 90 91 } … … 92 93 } 93 94 95 void Spectator::setConfigValues() 96 { 97 SetConfigValue(speed_, 200.0f); 98 } 99 94 100 void Spectator::registerVariables() 95 101 { 96 102 registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); 97 103 registerVariable(this->bGreeting_, variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); 98 registerVariable(this->hudmode_, variableDirection::toclient);99 104 } 100 105 … … 107 112 void Spectator::changedFlareVisibility() 108 113 { 109 if ( this->greetingFlare_ ) 114 if ( this->greetingFlare_ ) 110 115 this->greetingFlare_->setVisible(this->bGreetingFlareVisible_); 111 116 } … … 113 118 void Spectator::tick(float dt) 114 119 { 115 this->updateHUD(); 116 117 if (this->isLocallyControlled()) 120 if (this->hasLocalController()) 118 121 { 119 122 float localSpeedSquared = this->localVelocity_.squaredLength(); … … 132 135 this->localVelocity_.z = 0; 133 136 134 this->yaw (Radian(this->yaw_ * this->rotationGain_)); 135 this->pitch(Radian(this->pitch_ * this->rotationGain_)); 136 this->roll (Radian(this->roll_ * this->rotationGain_)); 137 if (!this->isInMouseLook()) 138 { 139 this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed())); 140 this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed())); 141 this->roll(Radian(this->roll_ * this->getMouseLookSpeed())); 142 } 137 143 138 144 this->yaw_ = this->pitch_ = this->roll_ = 0; … … 146 152 ControllableEntity::setPlayer(player); 147 153 148 // this->setObjectMode(direction::toclient); 149 } 150 151 void Spectator::startLocalControl() 152 { 153 ControllableEntity::startLocalControl(); 154 // if (this->isLocallyControlled()) 155 // this->testmesh_->setVisible(false); 154 // this->setObjectMode(objectDirection::toclient); 155 } 156 157 void Spectator::startLocalHumanControl() 158 { 159 ControllableEntity::startLocalHumanControl(); 156 160 } 157 161 … … 174 178 { 175 179 this->yaw_ += value.y; 180 181 ControllableEntity::rotateYaw(value); 176 182 } 177 183 … … 179 185 { 180 186 this->pitch_ += value.y; 187 188 ControllableEntity::rotatePitch(value); 181 189 } 182 190 … … 184 192 { 185 193 this->roll_ += value.y; 194 195 ControllableEntity::rotateRoll(value); 186 196 } 187 197 … … 202 212 } 203 213 } 204 205 void Spectator::updateHUD()206 {207 // <hack>208 if (Core::isMaster())209 {210 if (this->getPlayer() && this->getGametype())211 {212 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())213 {214 if (!this->getPlayer()->isReadyToSpawn())215 this->hudmode_ = 0;216 else217 this->hudmode_ = 1;218 }219 else if (!this->getGametype()->hasEnded())220 {221 if (this->getGametype()->isStartCountdownRunning())222 this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());223 else224 this->hudmode_ = 3;225 }226 else227 this->hudmode_ = 4;228 }229 else230 return;231 }232 233 if (this->getHUD())234 {235 std::string text;236 int hudmode = this->hudmode_ % 10;237 238 switch (hudmode)239 {240 case 0:241 text = "Press [Fire] to start the match";242 break;243 case 1:244 text = "Waiting for other players";245 break;246 case 2:247 text = convertToString((this->hudmode_ - 2) / 10);248 break;249 case 3:250 text = "Press [Fire] to respawn";251 break;252 case 4:253 text = "Game has ended";254 break;255 default:;256 }257 258 std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();259 for (; it != this->getHUD()->getOverlays().end(); ++it)260 {261 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")262 {263 OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);264 if (overlay)265 overlay->setCaption(text);266 break;267 }268 }269 }270 // </hack>271 }272 214 } -
code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.h
r2459 r2485 42 42 virtual ~Spectator(); 43 43 44 void setConfigValues(); 44 45 void registerVariables(); 45 46 virtual void tick(float dt); 46 47 47 48 virtual void setPlayer(PlayerInfo* player); 48 virtual void startLocal Control();49 virtual void startLocalHumanControl(); 49 50 50 51 virtual void moveFrontBack(const Vector2& value); … … 62 63 void changedGreeting(); 63 64 void changedFlareVisibility(); 64 void updateHUD();65 65 66 66 BillboardSet* greetingFlare_; … … 69 69 70 70 float speed_; 71 float rotationGain_;72 71 73 72 float yaw_; … … 76 75 77 76 Vector3 localVelocity_; 78 79 int hudmode_;80 77 }; 81 78 }
Note: See TracChangeset
for help on using the changeset viewer.