Changeset 11071 for code/trunk/src/orxonox/items
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/items/Engine.cc
r9667 r11071 50 50 RegisterObject(Engine); 51 51 52 this->ship_ = 0;52 this->ship_ = nullptr; 53 53 this->shipID_ = OBJECTID_UNKNOWN; 54 54 this->relativePosition_ = Vector3::ZERO; … … 136 136 void Engine::networkcallback_shipID() 137 137 { 138 this->ship_ = 0;138 this->ship_ = nullptr; 139 139 140 140 if (this->shipID_ != OBJECTID_UNKNOWN) … … 155 155 void Engine::run(float dt) 156 156 { 157 if (this->ship_ == NULL)157 if (this->ship_ == nullptr) 158 158 { 159 159 if (this->shipID_ != 0) … … 161 161 this->networkcallback_shipID(); 162 162 163 if (this->ship_ == NULL)163 if (this->ship_ == nullptr) 164 164 return; 165 165 } -
code/trunk/src/orxonox/items/Engine.h
r9667 r11071 59 59 virtual ~Engine(); 60 60 61 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;61 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 62 62 void setConfigValues(); 63 63 … … 67 67 /** 68 68 @brief Get the SpaceShip this Engine is mounted on. 69 @return Returns a pointer to the SpaceShip. NULLif it isn't mounted on any ship.69 @return Returns a pointer to the SpaceShip. nullptr if it isn't mounted on any ship. 70 70 */ 71 71 inline SpaceShip* getShip() const -
code/trunk/src/orxonox/items/MultiStateEngine.cc
r9939 r11071 67 67 else 68 68 { 69 this->defEngineSndBoost_ = 0;70 this->defEngineSndNormal_ = 0;71 this->lua_ = 0;69 this->defEngineSndBoost_ = nullptr; 70 this->defEngineSndNormal_ = nullptr; 71 this->lua_ = nullptr; 72 72 } 73 73 this->state_ = 0; … … 85 85 { 86 86 // We have no ship, so the effects are not attached and won't be destroyed automatically 87 for ( std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)88 for ( std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2)89 (*it2)->destroy();87 for (EffectContainer* container : this->effectContainers_) 88 for (WorldEntity* effect : container->getEffects()) 89 effect->destroy(); 90 90 if (this->defEngineSndNormal_) 91 91 this->defEngineSndNormal_->destroy(); … … 124 124 this->state_ = 0; 125 125 if (this->getShip()->isBoosting() && forward) 126 this->state_ = Boost;126 this->state_ = EngineState::Boost; 127 127 else if (forward && !this->state_) // this->state_ == Boost 128 this->state_ = Normal;128 this->state_ = EngineState::Normal; 129 129 else if (direction.z > 0.0 && velocity.z < 0.0) 130 this->state_ = Brake;130 this->state_ = EngineState::Brake; 131 131 else 132 this->state_ = Idle;133 134 if (this->state_ == Idle && this->getSpeedAdd() > 0)135 this->state_ = Normal;132 this->state_ = EngineState::Idle; 133 134 if (this->state_ == EngineState::Idle && this->getSpeedAdd() > 0) 135 this->state_ = EngineState::Normal; 136 136 } 137 137 … … 141 141 142 142 float pitch = velocity.length(); 143 if (this->state_ & Normal)143 if (this->state_ & EngineState::Normal) 144 144 defEngineSndNormal_->setPitch(clamp(pitch/MAX_VELOCITY_NORMAL + 1, 0.5f, 2.0f)); 145 if (this->state_ & Boost)145 if (this->state_ & EngineState::Boost) 146 146 defEngineSndBoost_->setPitch(clamp(pitch/MAX_VELOCITY_BOOST + 1, 0.5f, 2.0f)); 147 147 148 if (changes & Idle)149 { 150 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Idle);148 if (changes & EngineState::Idle) 149 { 150 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Idle); 151 151 lua_setglobal(this->lua_->getInternalLuaState(), "idle"); 152 152 } 153 if (changes & Normal)154 { 155 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Normal);153 if (changes & EngineState::Normal) 154 { 155 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Normal); 156 156 lua_setglobal(this->lua_->getInternalLuaState(), "normal"); 157 if (this->state_ & Normal)157 if (this->state_ & EngineState::Normal) 158 158 defEngineSndNormal_->play(); 159 159 else 160 160 defEngineSndNormal_->stop(); 161 161 } 162 if (changes & Brake)163 { 164 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Brake);162 if (changes & EngineState::Brake) 163 { 164 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Brake); 165 165 lua_setglobal(this->lua_->getInternalLuaState(), "brake"); 166 166 } 167 if (changes & Boost)168 { 169 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Boost);167 if (changes & EngineState::Boost) 168 { 169 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Boost); 170 170 lua_setglobal(this->lua_->getInternalLuaState(), "boost"); 171 if (this->state_ & Boost)171 if (this->state_ & EngineState::Boost) 172 172 defEngineSndBoost_->play(); 173 173 else … … 178 178 179 179 // Update all effect conditions 180 for ( std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)181 (*it)->updateCondition();180 for (EffectContainer* container : this->effectContainers_) 181 container->updateCondition(); 182 182 } 183 183 } … … 198 198 this->getShip()->attach(defEngineSndBoost_); 199 199 200 for ( std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)201 for ( std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsEnd(); ++it2)202 this->getShip()->attach( *it2);203 } 204 205 void MultiStateEngine::addEffectContainer(EffectContainer* effect)206 { 207 if ( effect == NULL)200 for (EffectContainer* container : this->effectContainers_) 201 for (WorldEntity* effect : container->getEffects()) 202 this->getShip()->attach(effect); 203 } 204 205 void MultiStateEngine::addEffectContainer(EffectContainer* container) 206 { 207 if (container == nullptr) 208 208 return; 209 effect->setLuaState(this->lua_, 'f' + multi_cast<std::string>(this->effectContainers_.size()));210 this->effectContainers_.push_back( effect);209 container->setLuaState(this->lua_, 'f' + multi_cast<std::string>(this->effectContainers_.size())); 210 this->effectContainers_.push_back(container); 211 211 if (this->getShip()) 212 212 { 213 for ( std::vector<WorldEntity*>::const_iterator it = effect->getEffectsBegin(); it != effect->getEffectsBegin(); ++it)214 this->getShip()->attach( *it);213 for (WorldEntity* effect : container->getEffects()) 214 this->getShip()->attach(effect); 215 215 } 216 216 } … … 219 219 { 220 220 unsigned int i = 0; 221 for ( std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)221 for (EffectContainer* effectContainer : this->effectContainers_) 222 222 { 223 223 if (i == index) 224 return (*it); 225 } 226 return NULL; 224 return effectContainer; 225 i++; 226 } 227 return nullptr; 227 228 } 228 229 -
code/trunk/src/orxonox/items/MultiStateEngine.h
r9667 r11071 41 41 { 42 42 public: 43 enumEngineState43 struct EngineState 44 44 { 45 Idle = 1,46 Normal = 2,47 Brake = 4,48 Boost = 845 static constexpr int Idle = 1; 46 static constexpr int Normal = 2; 47 static constexpr int Brake = 4; 48 static constexpr int Boost = 8; 49 49 }; 50 50 … … 52 52 virtual ~MultiStateEngine(); 53 53 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 55 55 56 virtual void run(float dt) ;56 virtual void run(float dt) override; 57 57 58 virtual void addToSpaceShip(SpaceShip* ship) ;58 virtual void addToSpaceShip(SpaceShip* ship) override; 59 59 60 60 void addEffectContainer(EffectContainer* effect); -
code/trunk/src/orxonox/items/PartDestructionEvent.cc
r10262 r11071 98 98 { 99 99 switch (this->targetParam_) { 100 case shieldhealth:100 case TargetParam::shieldhealth: 101 101 this->parent_->getParent()->setShieldHealth(operate(this->parent_->getParent()->getShieldHealth())); 102 102 break; 103 case boostpower:103 case TargetParam::boostpower: 104 104 this->parent_->getParent()->setInitialBoostPower(operate(this->parent_->getParent()->getInitialBoostPower())); 105 105 break; 106 case boostpowerrate:106 case TargetParam::boostpowerrate: 107 107 this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate())); 108 108 break; 109 case rotationthrust:109 case TargetParam::rotationthrust: 110 110 this->parent_->getParent()->setRotationThrust(operate(this->parent_->getParent()->getRotationThrust())); 111 111 break; … … 120 120 { 121 121 switch (this->targetParam_) { 122 case null:122 case TargetParam::null: 123 123 this->parent_->getParent()->getEngineByName(targetName_)->destroy(); 124 124 break; 125 case boostfactor:125 case TargetParam::boostfactor: 126 126 this->parent_->getParent()->getEngineByName(targetName_)->setBoostFactor(operate(this->parent_->getParent()->getEngineByName(targetName_)->getBoostFactor())); 127 127 break; 128 case speedfront:128 case TargetParam::speedfront: 129 129 this->parent_->getParent()->getEngineByName(targetName_)->setMaxSpeedFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getMaxSpeedFront())); 130 130 break; 131 case accelerationfront:131 case TargetParam::accelerationfront: 132 132 this->parent_->getParent()->getEngineByName(targetName_)->setAccelerationFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getAccelerationFront())); 133 133 break; … … 142 142 { 143 143 switch (this->targetParam_) { 144 case null:144 case TargetParam::null: 145 145 if (!this->parent_->getParent()->getShipPartByName(targetName_)) 146 146 return; … … 214 214 if (param == "NULL") 215 215 { 216 this->targetParam_ = null;216 this->targetParam_ = TargetParam::null; 217 217 return; 218 218 } 219 219 if (param == "boostfactor") 220 220 { 221 this->targetParam_ = boostfactor;221 this->targetParam_ = TargetParam::boostfactor; 222 222 return; 223 223 } 224 224 if (param == "speedfront") 225 225 { 226 this->targetParam_ = speedfront;226 this->targetParam_ = TargetParam::speedfront; 227 227 return; 228 228 } 229 229 if (param == "accelerationfront") 230 230 { 231 this->targetParam_ = accelerationfront;231 this->targetParam_ = TargetParam::accelerationfront; 232 232 return; 233 233 } … … 244 244 if (param == "shieldhealth") 245 245 { 246 this->targetParam_ = shieldhealth;246 this->targetParam_ = TargetParam::shieldhealth; 247 247 return; 248 248 } 249 249 if (param == "boostpower") 250 250 { 251 this->targetParam_ = boostpower;251 this->targetParam_ = TargetParam::boostpower; 252 252 return; 253 253 } 254 254 if (param == "boostpowerrate") 255 255 { 256 this->targetParam_ = boostpowerrate;256 this->targetParam_ = TargetParam::boostpowerrate; 257 257 return; 258 258 } 259 259 if (param == "rotationthrust") 260 260 { 261 this->targetParam_ = rotationthrust;261 this->targetParam_ = TargetParam::rotationthrust; 262 262 return; 263 263 } … … 271 271 if (param == "NULL") 272 272 { 273 this->targetParam_ = null;273 this->targetParam_ = TargetParam::null; 274 274 return; 275 275 } -
code/trunk/src/orxonox/items/PartDestructionEvent.h
r10262 r11071 82 82 List of all allowed parameters. 83 83 */ 84 enum TargetParam84 enum class TargetParam 85 85 { 86 86 shieldhealth, … … 100 100 virtual ~PartDestructionEvent(); 101 101 102 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;102 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 103 103 104 104 void execute(); -
code/trunk/src/orxonox/items/ShipPart.cc
r11052 r11071 49 49 50 50 ShipPart::ShipPart(Context* context) 51 : Item(context), parent_( NULL)51 : Item(context), parent_(nullptr) 52 52 { 53 53 RegisterObject(ShipPart); … … 121 121 void ShipPart::addEntity(StaticEntity* entity) 122 122 { 123 OrxAssert(entity != NULL, "The Entity cannot be NULL.");123 OrxAssert(entity != nullptr, "The Entity cannot be nullptr."); 124 124 this->entityList_.push_back(entity); 125 125 } … … 129 129 Get the i-th StaticEntity of the ShipPart. 130 130 @return 131 Returns a pointer to the i-the StaticEntity. NULLif there is no StaticEntity with that index.131 Returns a pointer to the i-the StaticEntity. nullptr if there is no StaticEntity with that index. 132 132 */ 133 133 StaticEntity* ShipPart::getEntity(unsigned int index) 134 134 { 135 135 if(this->entityList_.size() >= index) 136 return NULL;136 return nullptr; 137 137 else 138 138 return this->entityList_[index]; … … 142 142 @brief 143 143 Check whether the ShipPart has a particular Entity. 144 @param engine144 @param search 145 145 A pointer to the Entity to be checked. 146 146 */ 147 bool ShipPart::hasEntity(StaticEntity* entity) const148 { 149 for( unsigned int i = 0; i < this->entityList_.size(); i++)150 { 151 if( this->entityList_[i] == entity)147 bool ShipPart::hasEntity(StaticEntity* search) const 148 { 149 for(StaticEntity* entity : this->entityList_) 150 { 151 if(entity == search) 152 152 return true; 153 153 } … … 163 163 void ShipPart::addDestructionEvent(PartDestructionEvent* event) 164 164 { 165 OrxAssert(event != NULL, "The PartDestructionEvent cannot be NULL.");165 OrxAssert(event != nullptr, "The PartDestructionEvent cannot be nullptr."); 166 166 event->setParent(this); 167 167 this->eventList_.push_back(event); … … 172 172 Get the i-th PartDestructionEvent of the ShipPart. 173 173 @return 174 Returns a pointer to the i-the PartDestructionEvent. NULLif there is no PartDestructionEvent with that index.174 Returns a pointer to the i-the PartDestructionEvent. nullptr if there is no PartDestructionEvent with that index. 175 175 */ 176 176 PartDestructionEvent* ShipPart::getDestructionEvent(unsigned int index) 177 177 { 178 178 if(this->eventList_.size() <= index) 179 return NULL;179 return nullptr; 180 180 else 181 181 return this->eventList_[index]; 182 182 } 183 183 184 void ShipPart::setDamageAbsorption(float value)185 {186 this->damageAbsorption_ = value;187 }188 189 184 void ShipPart::setParent(ModularSpaceShip* ship) 190 185 { 191 186 this->parent_ = ship; 192 }193 194 /**195 @brief196 Sets the health of the ShipPart.197 */198 void ShipPart::setHealth(float health)199 {200 this->health_ = health;201 187 } 202 188 -
code/trunk/src/orxonox/items/ShipPart.h
r10624 r11071 47 47 virtual ~ShipPart(); 48 48 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 50 50 51 51 virtual void handleHit(float damage, float healthdamage, float shielddamage, Pawn* originator); … … 64 64 PartDestructionEvent* getDestructionEvent(unsigned int index); 65 65 66 virtual void setDamageAbsorption(float value); 67 inline float getDamageAbsorption() 66 inline void setDamageAbsorption(float value) 67 { this->damageAbsorption_ = value; } 68 inline float getDamageAbsorption() const 68 69 { return this->damageAbsorption_; } 69 70 70 71 void setParent(ModularSpaceShip* ship); 71 inline ModularSpaceShip* getParent() 72 inline ModularSpaceShip* getParent() const 72 73 { return this->parent_; } 73 74 74 75 inline void setEventExecution(bool var) 75 76 { this->eventExecution_ = var; } 76 inline bool isEventExecution() 77 inline bool isEventExecution() const 77 78 { return this->eventExecution_; } 78 79 79 virtual void setHealth(float health); 80 inline void setHealth(float health) 81 { this->health_ = health; } 80 82 inline void addHealth(float health) 81 83 { this->setHealth(this->health_ + health); }
Note: See TracChangeset
for help on using the changeset viewer.