Changeset 2662 for code/trunk/src/orxonox/objects/worldentities/pawns
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 7 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 } -
code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.h
r2098 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "objects/pickup/ShipEquipment.h" 34 34 #include "objects/worldentities/ControllableEntity.h" 35 #include "objects/RadarViewable.h" 36 #include "objects/weaponSystem/WeaponSystem.h" 35 37 36 38 namespace orxonox 37 39 { 38 class _OrxonoxExport Pawn : public ControllableEntity 40 class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable 39 41 { 40 42 public: … … 54 56 inline void removeHealth(float health) 55 57 { this->setHealth(this->health_ - health); } 56 inline float getHeal ht() const58 inline float getHealth() const 57 59 { return this->health_; } 58 60 … … 74 76 virtual void kill(); 75 77 76 virtual void fire(); 77 78 virtual void fire(WeaponMode::Enum fireMode); 78 79 virtual void postSpawn(); 79 80 81 void setWeaponSlot(WeaponSlot * wSlot); 82 WeaponSlot * getWeaponSlot(unsigned int index) const; 83 void setWeaponPack(WeaponPack * wPack); 84 WeaponPack * getWeaponPack(unsigned int firemode) const; 85 void setWeaponSet(WeaponSet * wSet); 86 WeaponSet * getWeaponSet(unsigned int index) const; 87 88 inline const WorldEntity* getWorldEntity() const 89 { return const_cast<Pawn*>(this); } 90 91 inline void setSpawnParticleSource(const std::string& source) 92 { this->spawnparticlesource_ = source; } 93 inline const std::string& getSpawnParticleSource() const 94 { return this->spawnparticlesource_; } 95 96 inline void setSpawnParticleDuration(float duration) 97 { this->spawnparticleduration_ = duration; } 98 inline float getSpawnParticleDuration() const 99 { return this->spawnparticleduration_; } 100 101 inline void setExplosionChunks(unsigned int chunks) 102 { this->numexplosionchunks_ = chunks; } 103 inline unsigned int getExplosionChunks() const 104 { return this->numexplosionchunks_; } 105 106 inline ShipEquipment& getPickUp() 107 {return this->pickUp;} 108 109 virtual void dropItems(); 110 80 111 protected: 81 virtual void spawn();82 112 virtual void death(); 113 virtual void deatheffect(); 114 virtual void spawneffect(); 83 115 116 ShipEquipment pickUp; 84 117 bool bAlive_; 118 85 119 86 120 float health_; … … 91 125 92 126 WeaponSystem* weaponSystem_; 127 unsigned int fire_; 128 unsigned int firehack_; 129 130 std::string spawnparticlesource_; 131 float spawnparticleduration_; 132 unsigned int numexplosionchunks_; 133 }; 134 135 class _OrxonoxExport PawnListener : virtual public OrxonoxClass 136 { 137 friend class Pawn; 138 139 public: 140 PawnListener(); 141 virtual ~PawnListener() {} 142 143 protected: 144 virtual void destroyedPawn(Pawn* pawn) = 0; 93 145 }; 94 146 } -
code/trunk/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2171 r2662 30 30 #include "SpaceShip.h" 31 31 32 #include "BulletDynamics/Dynamics/btRigidBody.h" 33 34 #include "util/Math.h" 35 #include "util/Exception.h" 32 36 #include "core/CoreIncludes.h" 33 37 #include "core/ConfigValueIncludes.h" 38 #include "core/Template.h" 34 39 #include "core/XMLPort.h" 35 #include " util/Math.h"40 #include "objects/items/Engine.h" 36 41 37 42 namespace orxonox 38 43 { 44 const float orientationGain = 100; 39 45 CreateFactory(SpaceShip); 40 46 … … 43 49 RegisterObject(SpaceShip); 44 50 45 this->zeroDegree_ = 0; 46 47 this->maxSpeed_ = 0; 48 this->maxSecondarySpeed_ = 0; 49 this->maxRotation_ = 0; 50 this->translationAcceleration_ = 0; 51 this->rotationAcceleration_ = 0; 52 this->translationDamping_ = 0; 53 54 this->yawRotation_ = 0; 55 this->pitchRotation_ = 0; 56 this->rollRotation_ = 0; 51 this->primaryThrust_ = 100; 52 this->auxilaryThrust_ = 30; 53 this->rotationThrust_ = 10; 54 55 this->localLinearAcceleration_.setValue(0, 0, 0); 56 this->localAngularAcceleration_.setValue(0, 0, 0); 57 this->bBoost_ = false; 58 this->bPermanentBoost_ = false; 59 this->steering_ = Vector3::ZERO; 60 this->engine_ = 0; 61 57 62 58 63 this->bInvertYAxis_ = false; 59 64 60 65 this->setDestroyWhenPlayerLeft(true); 66 67 // SpaceShip is always a physical object per default 68 // Be aware of this call: The collision type legality check will not reach derived classes! 69 this->setCollisionType(WorldEntity::Dynamic); 70 // Get notification about collisions 71 this->enableCollisionCallback(); 61 72 62 73 this->setConfigValues(); … … 66 77 SpaceShip::~SpaceShip() 67 78 { 79 if (this->isInitialized() && this->engine_) 80 delete this->engine_; 68 81 } 69 82 … … 72 85 SUPER(SpaceShip, XMLPort, xmlelement, mode); 73 86 74 XMLPortParam(SpaceShip, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode); 75 XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode); 76 XMLPortParam(SpaceShip, "maxrotation", setMaxRotation, getMaxRotation, xmlelement, mode); 77 XMLPortParam(SpaceShip, "transacc", setTransAcc, getTransAcc, xmlelement, mode); 78 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 79 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); 87 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 88 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 89 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); 90 XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode); 80 91 } 81 92 82 93 void SpaceShip::registerVariables() 83 94 { 84 REGISTERDATA(this->maxSpeed_, direction::toclient); 85 REGISTERDATA(this->maxSecondarySpeed_, direction::toclient); 86 REGISTERDATA(this->maxRotation_, direction::toclient); 87 REGISTERDATA(this->translationAcceleration_, direction::toclient); 88 REGISTERDATA(this->rotationAcceleration_, direction::toclient); 89 REGISTERDATA(this->translationDamping_, direction::toclient); 95 registerVariable(this->primaryThrust_, variableDirection::toclient); 96 registerVariable(this->auxilaryThrust_, variableDirection::toclient); 97 registerVariable(this->rotationThrust_, variableDirection::toclient); 90 98 } 91 99 … … 95 103 } 96 104 105 bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const 106 { 107 if (type != WorldEntity::Dynamic) 108 { 109 CCOUT(1) << "Error: Cannot tell a SpaceShip not to be dynamic! Ignoring." << std::endl; 110 assert(false); // Only in debug mode 111 return false; 112 } 113 else 114 return true; 115 } 116 97 117 void SpaceShip::tick(float dt) 98 118 { 99 if (this->isLocallyControlled()) 119 SUPER(SpaceShip, tick, dt); 120 121 if (this->hasLocalController()) 100 122 { 101 // ##################################### 102 // ############# STEERING ############## 103 // ##################################### 104 105 Vector3 velocity = this->getVelocity(); 106 if (velocity.x > this->maxSecondarySpeed_) 107 velocity.x = this->maxSecondarySpeed_; 108 if (velocity.x < -this->maxSecondarySpeed_) 109 velocity.x = -this->maxSecondarySpeed_; 110 if (velocity.y > this->maxSecondarySpeed_) 111 velocity.y = this->maxSecondarySpeed_; 112 if (velocity.y < -this->maxSecondarySpeed_) 113 velocity.y = -this->maxSecondarySpeed_; 114 if (velocity.z > this->maxSecondarySpeed_) 115 velocity.z = this->maxSecondarySpeed_; 116 if (velocity.z < -this->maxSpeed_) 117 velocity.z = -this->maxSpeed_; 118 119 // normalize velocity and acceleration 120 for (size_t dimension = 0; dimension < 3; ++dimension) 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 */ 133 if (!this->isInMouseLook()) 121 134 { 122 if (this->acceleration_[dimension] == 0) 135 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 136 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 137 this->localAngularAcceleration_.setValue(0, 0, 0); 138 } 139 } 140 } 141 142 void SpaceShip::moveFrontBack(const Vector2& value) 143 { 144 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 145 this->steering_.z = -value.x; 146 } 147 148 void SpaceShip::moveRightLeft(const Vector2& value) 149 { 150 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 151 this->steering_.x = value.x; 152 } 153 154 void SpaceShip::moveUpDown(const Vector2& value) 155 { 156 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 157 this->steering_.y = value.x; 158 } 159 160 void SpaceShip::rotateYaw(const Vector2& value) 161 { 162 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x); 163 164 Pawn::rotateYaw(value); 165 } 166 167 void SpaceShip::rotatePitch(const Vector2& value) 168 { 169 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); 170 171 Pawn::rotatePitch(value); 172 } 173 174 void SpaceShip::rotateRoll(const Vector2& value) 175 { 176 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 177 178 Pawn::rotateRoll(value); 179 } 180 181 void SpaceShip::fire() 182 { 183 } 184 185 void SpaceShip::boost() 186 { 187 this->bBoost_ = true; 188 } 189 190 void SpaceShip::loadEngineTemplate() 191 { 192 if (this->enginetemplate_ != "") 193 { 194 Template* temp = Template::getTemplate(this->enginetemplate_); 195 196 if (temp) 197 { 198 Identifier* identifier = temp->getBaseclassIdentifier(); 199 200 if (identifier) 123 201 { 124 if (velocity[dimension] > 0) 202 BaseObject* object = identifier->fabricate(this); 203 this->engine_ = dynamic_cast<Engine*>(object); 204 205 if (this->engine_) 125 206 { 126 velocity[dimension] -= (this->translationDamping_ * dt); 127 if (velocity[dimension] < 0) 128 velocity[dimension] = 0; 207 this->engine_->addTemplate(temp); 208 this->engine_->addToSpaceShip(this); 129 209 } 130 else if (velocity[dimension] < 0)210 else 131 211 { 132 velocity[dimension] += (this->translationDamping_ * dt); 133 if (velocity[dimension] > 0) 134 velocity[dimension] = 0; 212 delete object; 135 213 } 136 214 } 137 215 } 138 139 this->setVelocity(velocity);140 216 } 141 142 143 SUPER(SpaceShip, tick, dt); 144 145 146 if (this->isLocallyControlled()) 147 { 148 this->yaw(this->yawRotation_ * dt); 149 if (this->bInvertYAxis_) 150 this->pitch(Degree(-this->pitchRotation_ * dt)); 151 else 152 this->pitch(Degree( this->pitchRotation_ * dt)); 153 this->roll(this->rollRotation_ * dt); 154 155 this->acceleration_.x = 0; 156 this->acceleration_.y = 0; 157 this->acceleration_.z = 0; 158 159 this->yawRotation_ = this->zeroDegree_; 160 this->pitchRotation_ = this->zeroDegree_; 161 this->rollRotation_ = this->zeroDegree_; 162 } 163 } 164 165 void SpaceShip::moveFrontBack(const Vector2& value) 166 { 167 this->acceleration_.z = -this->translationAcceleration_ * value.x; 168 } 169 170 void SpaceShip::moveRightLeft(const Vector2& value) 171 { 172 this->acceleration_.x = this->translationAcceleration_ * value.x; 173 } 174 175 void SpaceShip::moveUpDown(const Vector2& value) 176 { 177 this->acceleration_.y = this->translationAcceleration_ * value.x; 178 } 179 180 void SpaceShip::rotateYaw(const Vector2& value) 181 { 182 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 183 if (temp > this->maxRotation_) 184 temp = this->maxRotation_; 185 if (temp < -this->maxRotation_) 186 temp = -this->maxRotation_; 187 this->yawRotation_ = Degree(temp); 188 } 189 190 void SpaceShip::rotatePitch(const Vector2& value) 191 { 192 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 193 if (temp > this->maxRotation_) 194 temp = this->maxRotation_; 195 if (temp < -this->maxRotation_) 196 temp = -this->maxRotation_; 197 this->pitchRotation_ = Degree(temp); 198 } 199 200 void SpaceShip::rotateRoll(const Vector2& value) 201 { 202 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 203 if (temp > this->maxRotation_) 204 temp = this->maxRotation_; 205 if (temp < -this->maxRotation_) 206 temp = -this->maxRotation_; 207 this->rollRotation_ = Degree(temp); 208 } 209 210 void SpaceShip::fire() 211 { 217 } 218 219 void SpaceShip::setEngine(Engine* engine) 220 { 221 this->engine_ = engine; 222 if (engine && engine->getShip() != this) 223 engine->addToSpaceShip(this); 212 224 } 213 225 } -
code/trunk/src/orxonox/objects/worldentities/pawns/SpaceShip.h
r2087 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "LinearMath/btVector3.h" 35 34 36 #include "Pawn.h" 35 37 … … 56 58 57 59 virtual void fire(); 60 virtual void boost(); 58 61 59 void setMaxSpeed(float value) 60 { this->maxSpeed_ = value; } 61 void setMaxSecondarySpeed(float value) 62 { this->maxSecondarySpeed_ = value; } 63 void setMaxRotation(const Degree& value) 64 { this->maxRotation_ = value; } 65 void setTransAcc(float value) 66 { this->translationAcceleration_ = value; } 67 void setRotAcc(const Degree& value) 68 { this->rotationAcceleration_ = value; } 69 void setTransDamp(float value) 70 { this->translationDamping_ = value; } 62 void setEngine(Engine* engine); 63 inline Engine* getEngine() const 64 { return this->engine_; } 71 65 72 inline float getMaxSpeed() const 73 { return this->maxSpeed_; } 74 inline float getMaxSecondarySpeed() const 75 { return this->maxSecondarySpeed_; } 76 inline float getMaxRotation() const 77 { return this->maxRotation_.valueDegrees(); } 78 inline float getTransAcc() const 79 { return this->translationAcceleration_; } 80 inline float getRotAcc() const 81 { return this->rotationAcceleration_.valueDegrees(); } 82 inline float getTransDamp() const 83 { return this->translationDamping_; } 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_; } 80 81 inline void setPermanentBoost(bool bPermanent) 82 { this->bPermanentBoost_ = bPermanent; } 83 inline bool getPermanentBoost() const 84 { return this->bPermanentBoost_; } 84 85 85 86 protected: 86 87 bool bInvertYAxis_; 87 88 88 float maxSpeed_; 89 float maxSecondarySpeed_; 90 float translationAcceleration_; 91 float translationDamping_; 89 bool bBoost_; 90 bool bPermanentBoost_; 91 Vector3 steering_; 92 float primaryThrust_; 93 float auxilaryThrust_; 94 float rotationThrust_; 95 btVector3 localLinearAcceleration_; 96 btVector3 localAngularAcceleration_; 92 97 93 Degree maxRotation_;94 Degree rotationAcceleration_;98 private: 99 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 95 100 96 Degree zeroDegree_; 97 Degree pitchRotation_; 98 Degree yawRotation_; 99 Degree rollRotation_; 101 private: 102 void loadEngineTemplate(); 103 104 std::string enginetemplate_; 105 Engine* engine_; 100 106 }; 101 107 } -
code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2171 r2662 30 30 #include "Spectator.h" 31 31 32 #include <OgreBillboardSet.h> 33 32 34 #include "core/CoreIncludes.h" 35 #include "core/ConfigValueIncludes.h" 33 36 #include "core/Core.h" 34 37 #include "objects/worldentities/Model.h" … … 49 52 RegisterObject(Spectator); 50 53 51 this->speed_ = 100; 52 this->rotationSpeed_ = 3; 54 this->speed_ = 200; 53 55 54 56 this->yaw_ = 0; 55 57 this->pitch_ = 0; 56 58 this->roll_ = 0; 59 this->localVelocity_ = Vector3::ZERO; 57 60 this->setHudTemplate("spectatorhud"); 58 this-> hudmode_ = 0;61 this->greetingFlare_ = 0; 59 62 60 63 this->setDestroyWhenPlayerLeft(true); 61 64 62 this->greetingFlare_ = new BillboardSet(); 63 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 64 if (this->greetingFlare_->getBillboardSet()) 65 this->getNode()->attachObject(this->greetingFlare_->getBillboardSet()); 66 this->greetingFlare_->setVisible(false); 65 if (Core::showsGraphics()) 66 { 67 this->greetingFlare_ = new BillboardSet(); 68 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 69 if (this->greetingFlare_->getBillboardSet()) 70 this->attachOgreObject(this->greetingFlare_->getBillboardSet()); 71 this->greetingFlare_->setVisible(false); 72 } 73 67 74 this->bGreetingFlareVisible_ = false; 68 75 this->bGreeting_ = false; 69 76 77 this->setConfigValues(); 70 78 this->registerVariables(); 71 79 } … … 78 86 { 79 87 if (this->greetingFlare_->getBillboardSet()) 80 this->getNode()->detachObject(this->greetingFlare_->getBillboardSet()); 88 this->detachOgreObject(this->greetingFlare_->getBillboardSet()); 89 81 90 delete this->greetingFlare_; 82 91 } … … 84 93 } 85 94 95 void Spectator::setConfigValues() 96 { 97 SetConfigValue(speed_, 200.0f); 98 } 99 86 100 void Spectator::registerVariables() 87 101 { 88 REGISTERDATA(this->bGreetingFlareVisible_, direction::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); 89 REGISTERDATA(this->bGreeting_, direction::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); 90 REGISTERDATA(this->hudmode_, direction::toclient); 102 registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); 103 registerVariable(this->bGreeting_, variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); 91 104 } 92 105 … … 99 112 void Spectator::changedFlareVisibility() 100 113 { 101 this->greetingFlare_->setVisible(this->bGreetingFlareVisible_); 114 if ( this->greetingFlare_ ) 115 this->greetingFlare_->setVisible(this->bGreetingFlareVisible_); 102 116 } 103 117 104 118 void Spectator::tick(float dt) 105 119 { 106 this->updateHUD(); 107 108 if (this->isLocallyControlled()) 109 { 110 Vector3 velocity = this->getVelocity(); 111 velocity.normalise(); 112 this->setVelocity(velocity * this->speed_); 113 114 this->yaw(Radian(this->yaw_ * this->rotationSpeed_)); 115 this->pitch(Radian(this->pitch_ * this->rotationSpeed_)); 116 this->roll(Radian(this->roll_ * this->rotationSpeed_)); 120 if (this->hasLocalController()) 121 { 122 float localSpeedSquared = this->localVelocity_.squaredLength(); 123 float localSpeed; 124 if (localSpeedSquared > 1.0) 125 localSpeed = this->speed_ / sqrtf(localSpeedSquared); 126 else 127 localSpeed = this->speed_; 128 129 this->localVelocity_.x *= localSpeed; 130 this->localVelocity_.y *= localSpeed; 131 this->localVelocity_.z *= localSpeed; 132 this->setVelocity(this->getOrientation() * this->localVelocity_); 133 this->localVelocity_.x = 0; 134 this->localVelocity_.y = 0; 135 this->localVelocity_.z = 0; 136 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 } 117 143 118 144 this->yaw_ = this->pitch_ = this->roll_ = 0; … … 120 146 121 147 SUPER(Spectator, tick, dt); 122 123 if (this->isLocallyControlled())124 {125 this->setVelocity(Vector3::ZERO);126 }127 148 } 128 149 … … 131 152 ControllableEntity::setPlayer(player); 132 153 133 // this->setObjectMode(direction::toclient); 134 } 135 136 void Spectator::startLocalControl() 137 { 138 ControllableEntity::startLocalControl(); 139 // if (this->isLocallyControlled()) 140 // this->testmesh_->setVisible(false); 154 // this->setObjectMode(objectDirection::toclient); 155 } 156 157 void Spectator::startLocalHumanControl() 158 { 159 ControllableEntity::startLocalHumanControl(); 141 160 } 142 161 143 162 void Spectator::moveFrontBack(const Vector2& value) 144 163 { 145 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);164 this->localVelocity_.z -= value.x; 146 165 } 147 166 148 167 void Spectator::moveRightLeft(const Vector2& value) 149 168 { 150 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);169 this->localVelocity_.x += value.x; 151 170 } 152 171 153 172 void Spectator::moveUpDown(const Vector2& value) 154 173 { 155 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);174 this->localVelocity_.y += value.x; 156 175 } 157 176 158 177 void Spectator::rotateYaw(const Vector2& value) 159 178 { 160 this->yaw_ = value.y; 179 this->yaw_ -= value.y; 180 181 ControllableEntity::rotateYaw(value); 161 182 } 162 183 163 184 void Spectator::rotatePitch(const Vector2& value) 164 185 { 165 this->pitch_ = value.y; 186 this->pitch_ += value.y; 187 188 ControllableEntity::rotatePitch(value); 166 189 } 167 190 168 191 void Spectator::rotateRoll(const Vector2& value) 169 192 { 170 this->roll_ = value.y; 171 } 172 173 void Spectator::fire() 193 this->roll_ += value.y; 194 195 ControllableEntity::rotateRoll(value); 196 } 197 198 void Spectator::fire(WeaponMode::Enum fireMode) 174 199 { 175 200 if (this->getPlayer()) … … 187 212 } 188 213 } 189 190 void Spectator::updateHUD()191 {192 // <hack>193 if (Core::isMaster())194 {195 if (this->getPlayer() && this->getGametype())196 {197 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())198 {199 if (!this->getPlayer()->isReadyToSpawn())200 this->hudmode_ = 0;201 else202 this->hudmode_ = 1;203 }204 else if (!this->getGametype()->hasEnded())205 {206 if (this->getGametype()->isStartCountdownRunning())207 this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());208 else209 this->hudmode_ = 3;210 }211 else212 this->hudmode_ = 4;213 }214 else215 return;216 }217 218 if (this->getHUD())219 {220 std::string text;221 int hudmode = this->hudmode_ % 10;222 223 switch (hudmode)224 {225 case 0:226 text = "Press [Fire] to start the match";227 break;228 case 1:229 text = "Waiting for other players";230 break;231 case 2:232 text = convertToString((this->hudmode_ - 2) / 10);233 break;234 case 3:235 text = "Press [Fire] to respawn";236 break;237 case 4:238 text = "Game has ended";239 break;240 default:;241 }242 243 std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();244 for (; it != this->getHUD()->getOverlays().end(); ++it)245 {246 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")247 {248 OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);249 if (overlay)250 overlay->setCaption(text);251 break;252 }253 }254 }255 // </hack>256 }257 214 } -
code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.h
r2087 r2662 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); … … 56 57 virtual void rotateRoll(const Vector2& value); 57 58 58 virtual void fire( );59 virtual void fire(WeaponMode::Enum fireMode); 59 60 virtual void greet(); 60 61 … … 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 rotationSpeed_;72 71 73 72 float yaw_; … … 75 74 float roll_; 76 75 77 int hudmode_;76 Vector3 localVelocity_; 78 77 }; 79 78 }
Note: See TracChangeset
for help on using the changeset viewer.