Changeset 11071 for code/trunk/src/orxonox/items/MultiStateEngine.cc
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (8 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
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
Note: See TracChangeset
for help on using the changeset viewer.