Changeset 10058 for code/branches/modularships/src/orxonox/items
- Timestamp:
- May 15, 2014, 3:53:11 PM (11 years ago)
- Location:
- code/branches/modularships/src/orxonox/items
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
r10055 r10058 83 83 void PartDestructionEvent::execute() 84 84 { 85 orxout() << "Executing PartDestructionEvent " << this->getName() << endl;86 87 85 // Do not execute if this event is invalid 88 86 if(!isValid()) … … 109 107 this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate())); 110 108 break; 109 case rotationthrust: 110 this->parent_->getParent()->setRotationThrust(operate(this->parent_->getParent()->getRotationThrust())); 111 break; 111 112 default: 112 113 break; … … 120 121 switch (this->targetParam_) { 121 122 case null: 122 for(unsigned int i = 0; i < this->parent_->getParent()->getEngineList().size(); i++) // FIXME: (noep) segfault on .size() 123 { 124 if(this->parent_->getParent()->getEngine(i)->getName() == this->targetName_) 125 { 126 orxout() << "engine found" << endl; 127 this->parent_->getParent()->removeEngine(this->parent_->getParent()->getEngine(i)); 128 break; 129 } 130 } 123 this->parent_->getParent()->removeEngine(this->parent_->getParent()->getEngineByName(targetName_)); 131 124 break; 132 125 case boostfactor: 133 for(unsigned int i = 0; i < this->parent_->getParent()->getEngineList().size(); i++) 134 { 135 if(this->parent_->getParent()->getEngine(i)->getName() == this->targetName_) 136 this->parent_->getParent()->getEngine(i)->setBoostFactor(operate(this->parent_->getParent()->getEngine(i)->getBoostFactor())); 137 break; 138 } 126 this->parent_->getParent()->getEngineByName(targetName_)->setBoostFactor(operate(this->parent_->getParent()->getEngineByName(targetName_)->getBoostFactor())); 127 break; 128 case speedfront: 129 this->parent_->getParent()->getEngineByName(targetName_)->setMaxSpeedFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getMaxSpeedFront())); 130 break; 131 case accelerationfront: 132 this->parent_->getParent()->getEngineByName(targetName_)->setAccelerationFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getAccelerationFront())); 133 break; 134 default: 135 break; 136 } 137 this->setValid(false); 138 return; 139 } 140 141 if (this->targetType_ == "part") 142 { 143 switch (this->targetParam_) { 144 case null: 145 this->parent_->getParent()->getShipPartByName(targetName_)->setEventExecution(false); 146 this->parent_->getParent()->killShipPart(targetName_); 139 147 break; 140 148 default: … … 159 167 void PartDestructionEvent::setTargetType(std::string type) 160 168 { 161 if ((type == "ship") || (type == "engine") || (type == "weapon") )169 if ((type == "ship") || (type == "engine") || (type == "weapon") || (type == "part")) 162 170 { 163 171 this->targetType_ = type; … … 166 174 167 175 // Error, if invalid target-type was entered. 168 orxout(internal_warning) << "\"" << type << "\" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon " << endl;176 orxout(internal_warning) << "\"" << type << "\" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon part" << endl; 169 177 this->setValid(false); 170 178 return; … … 229 237 // weapon: 230 238 231 // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate 239 // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate rotationthrust 232 240 if (this->targetType_ == "ship") 233 241 { … … 247 255 return; 248 256 } 249 250 orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate boostpower boostpowerrate" << endl; 257 if (param == "rotationthrust") 258 { 259 this->targetParam_ = rotationthrust; 260 return; 261 } 262 263 orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate boostpower boostpowerrate rotationthrust" << endl; 264 return; 265 } 266 267 if (this->targetType_ == "part") 268 { 269 if (param == "NULL") 270 { 271 this->targetParam_ = null; 272 return; 273 } 274 275 orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"part\". Valid types are: NULL (set operation to \"destroy\")" << endl; 251 276 return; 252 277 } … … 265 290 { 266 291 // * + - destroy 267 if ((operation == "*") || (operation == "+") || (operation == "-") || (operation == " destroy"))292 if ((operation == "*") || (operation == "+") || (operation == "-") || (operation == "set") || (operation == "destroy")) 268 293 { 269 294 this->operation_ = operation; … … 271 296 } 272 297 this->operation_ = "NULL"; 273 orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - destroy" << endl;298 orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - set destroy" << endl; 274 299 } 275 300 … … 292 317 The value which should be modified 293 318 @return 294 Returns the product / sum / difference of input and configured value, or 0 if the operation is "destroy" 319 Returns the product / sum / difference of input and configured value, 320 the configured value if the operation is "set", 321 or 0 if the operation is "destroy" 295 322 */ 296 323 float PartDestructionEvent::operate(float input) … … 302 329 if (this->operation_ == "-") 303 330 return input - this->value_; 331 if (this->operation_ == "set") 332 return this->value_; 304 333 if (this->operation_ == "destroy") 305 334 { -
code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
r10055 r10058 90 90 boostpower, // Amount of available boost 91 91 boostpowerrate, // Recharge-rate of boost 92 rotationthrust, 92 93 boostfactor, 93 94 speedfront, -
code/branches/modularships/src/orxonox/items/ShipPart.cc
r10055 r10058 52 52 RegisterObject(ShipPart); 53 53 this->setAlive(true); 54 this->setEventExecution(true); 54 55 } 55 56 … … 103 104 this->setAlive(false); 104 105 105 // Execute all destruction events 106 for (unsigned int i = 0; i < this->eventList_.size(); i++) 107 { 108 orxout() << "executing" << endl; 109 this->getDestructionEvent(i)->execute(); 106 if(eventExecution_) 107 { 108 // Execute all destruction events 109 for (unsigned int i = 0; i < this->eventList_.size(); i++) 110 { 111 this->getDestructionEvent(i)->execute(); 112 } 110 113 } 111 114 -
code/branches/modularships/src/orxonox/items/ShipPart.h
r10055 r10058 78 78 { return this->alive_; } 79 79 80 inline void setEventExecution(bool var) 81 { this->eventExecution_ = var; } 82 inline bool isEventExecution() 83 { return this->eventExecution_; } 84 80 85 virtual void setHealth(float health); 81 86 inline void addHealth(float health) … … 114 119 115 120 bool alive_; 121 bool eventExecution_; 116 122 117 123
Note: See TracChangeset
for help on using the changeset viewer.