Changeset 10055 for code/branches/modularships/src/orxonox/items
- Timestamp:
- May 14, 2014, 8:25:08 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
r10053 r10055 38 38 #include "worldentities/pawns/Pawn.h" 39 39 #include "worldentities/pawns/ModularSpaceShip.h" 40 #include "items/Engine.h" 40 41 #include "gametypes/Gametype.h" 42 #include "chat/ChatManager.h" 41 43 42 44 … … 63 65 XMLPortParam(PartDestructionEvent, "targetType", setTargetType, getTargetType, xmlelement, mode).defaultValues("NULL"); 64 66 XMLPortParam(PartDestructionEvent, "targetName", setTargetName, getTargetName, xmlelement, mode).defaultValues("NULL"); 67 XMLPortParam(PartDestructionEvent, "operation", setOperation, getOperation, xmlelement, mode).defaultValues("NULL"); 65 68 XMLPortParam(PartDestructionEvent, "targetParam", setTargetParam, getTargetParam, xmlelement, mode).defaultValues("NULL"); 66 XMLPortParam(PartDestructionEvent, "operation", setOperation, getOperation, xmlelement, mode).defaultValues("NULL");67 69 XMLPortParam(PartDestructionEvent, "value", setEventValue, getEventValue, xmlelement, mode).defaultValues(0); 70 XMLPortParam(PartDestructionEvent, "message", setMessage, getMessage, xmlelement, mode).defaultValues("NULL"); 68 71 69 72 /* … … 74 77 } 75 78 79 /** 80 @brief 81 Executes this event. 82 */ 76 83 void PartDestructionEvent::execute() 77 84 { 85 orxout() << "Executing PartDestructionEvent " << this->getName() << endl; 86 78 87 // Do not execute if this event is invalid 79 88 if(!isValid()) … … 83 92 } 84 93 94 // Output the destruction-message to the chat 95 if(this->message_ != "NULL") 96 ChatManager::message(this->message_); 97 98 // Modify parameters as configured for all cases 85 99 if (this->targetType_ == "ship") 86 100 { … … 89 103 this->parent_->getParent()->setShieldHealth(operate(this->parent_->getParent()->getShieldHealth())); 90 104 break; 105 case boostpower: 106 this->parent_->getParent()->setInitialBoostPower(operate(this->parent_->getParent()->getInitialBoostPower())); 107 break; 108 case boostpowerrate: 109 this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate())); 110 break; 91 111 default: 92 112 break; … … 95 115 return; 96 116 } 117 118 if (this->targetType_ == "engine") 119 { 120 switch (this->targetParam_) { 121 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 } 131 break; 132 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 } 139 break; 140 default: 141 break; 142 } 143 this->setValid(false); 144 return; 145 } 97 146 } 98 147 … … 102 151 } 103 152 153 /** 154 @brief 155 Set type of the target 156 @param param 157 The desired target-type as string. Valid target-types: ship engine weapon 158 */ 104 159 void PartDestructionEvent::setTargetType(std::string type) 105 160 { 106 // ship engine weapon107 161 if ((type == "ship") || (type == "engine") || (type == "weapon")) 108 162 { … … 129 183 } 130 184 185 /** 186 @brief 187 Set the operation to be applied. 188 @param param 189 The desired parameter as string. Valid parameters: c.f. @ref orxnox::PartDestructionEvent::TargetParam 190 */ 131 191 void PartDestructionEvent::setTargetParam(std::string param) 132 192 { 193 // A target-type needs to be defined in order to choose a parameter. 133 194 if (this->targetType_ == "NULL") 134 195 { … … 138 199 } 139 200 140 // ship: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate 141 142 // engine: 201 // engine: NULL boostfactor speedfront accelerationfront 202 if (this->targetType_ == "engine") 203 { 204 if (param == "NULL") 205 { 206 this->targetParam_ = null; 207 return; 208 } 209 if (param == "boostfactor") 210 { 211 this->targetParam_ = boostfactor; 212 return; 213 } 214 if (param == "speedfront") 215 { 216 this->targetParam_ = speedfront; 217 return; 218 } 219 if (param == "accelerationfront") 220 { 221 this->targetParam_ = accelerationfront; 222 return; 223 } 224 225 orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"engine\". Valid types are: boostfactor speedfront accelerationfront" << endl; 226 return; 227 } 143 228 144 229 // weapon: 145 230 231 // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate 146 232 if (this->targetType_ == "ship") 147 233 { … … 151 237 return; 152 238 } 153 154 orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate" << endl; 239 if (param == "boostpower") 240 { 241 this->targetParam_ = boostpower; 242 return; 243 } 244 if (param == "boostpowerrate") 245 { 246 this->targetParam_ = boostpowerrate; 247 return; 248 } 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; 155 251 return; 156 252 } … … 160 256 } 161 257 258 /** 259 @brief 260 Set the operation to be applied. 261 @param operation 262 The desired operator as string. Valid operators: * + - destroy 263 */ 162 264 void PartDestructionEvent::setOperation(std::string operation) 163 265 { … … 172 274 } 173 275 276 /** 277 @brief 278 Set the message to be shown upon execution of the vent. 279 @param msg 280 The desired message as string. 281 */ 282 void PartDestructionEvent::setMessage(std::string msg) 283 { 284 this->message_ = msg; 285 } 286 287 288 /** 289 @brief 290 Apply the configured operation and value to an input. 291 @param input 292 The value which should be modified 293 @return 294 Returns the product / sum / difference of input and configured value, or 0 if the operation is "destroy" 295 */ 174 296 float PartDestructionEvent::operate(float input) 175 297 { … … 187 309 } 188 310 311 /** 312 @brief 313 Sets the value applied with the chosen operation. 314 @param value 315 The value as float. 316 */ 189 317 void PartDestructionEvent::setEventValue(float value) 190 318 { -
code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
r10053 r10055 38 38 namespace orxonox // tolua_export 39 39 { // tolua_export 40 /** 41 @brief 42 In order to assign attached entities to a ShipPart, a ShipPart with the same name as the corresponding entity needs to be created in the <parts> tag. 43 Here is a (primitive) example of a ModularSpaceShip with ShipParts and PartDestructionEvents defined in XML: 44 @code 45 <ModularSpaceShip 46 ... 47 > 48 <attached> 49 <StaticEntity name="generator" . . . /> 50 <StaticEntity name="tail" . . . /> 51 </attached> 52 <parts> 53 <ShipPart name="generator" . . . > 54 <destructionevents> 55 <PartDestructionEvent targetType="ship" targetParam="boostpowerrate" operation="-" value="0.5" message="Your boost-regeneration is reduced!" /> 56 </destructionevents> 57 </ShipPart> 58 <ShipPart name="tail" . . . > 59 <destructionevents> 60 <PartDestructionEvent ... /> 61 </destructionevents> 62 </ShipPart> 63 </parts> 64 <engines> 65 <Engine /> 66 <Engine /> 67 </engines> 68 </ModularSpaceShip> 69 @endcode 70 71 @author 72 Fabian 'x3n' Landau, Noe Pedrazzini 73 */ 40 74 class _OrxonoxExport PartDestructionEvent // tolua_export 41 75 : public Item … … 44 78 public: 45 79 80 /** 81 @brief 82 List of all allowed parameters. 83 */ 46 84 enum TargetParam 47 85 { … … 50 88 shieldabsorption, 51 89 shieldrechargerate, 90 boostpower, // Amount of available boost 91 boostpowerrate, // Recharge-rate of boost 92 boostfactor, 93 speedfront, 94 accelerationfront, 52 95 null 53 96 }; … … 85 128 { return this->operation_; } 86 129 130 void setMessage(std::string msg); 131 inline std::string getMessage() 132 { return this->message_; } 133 87 134 float operate(float input); 88 135 … … 95 142 private: 96 143 97 ShipPart* parent_; 98 bool valid_; 144 ShipPart* parent_; //!< Pointer to the ShipPart this event belongs to 145 bool valid_; //!< Whether this event is valid or not. 99 146 100 std::string targetType_; 101 std::string targetName_; 102 TargetParam targetParam_; 103 std::string operation_; 147 std::string targetType_; //!< The type of the target. (ship weapon engine) 148 std::string targetName_; //!< The name of the target. 149 TargetParam targetParam_; //!< The parameter to be modified 150 std::string operation_; //!< The operation to be applied 151 float value_; //!< The value used to do the operation 152 std::string message_; //!< The message which is shown in chat when the event is executed. 104 153 105 float value_;106 154 107 155 -
code/branches/modularships/src/orxonox/items/ShipPart.cc
r10053 r10055 90 90 } 91 91 92 /** 93 @brief 94 Is called when the ShipPart dies. 95 Executes PartDestructionEvents. 96 Tells the ModularSpaceShip to remove this ShipPart. 97 */ 92 98 void ShipPart::death() 93 99 { -
code/branches/modularships/src/orxonox/items/ShipPart.h
r10053 r10055 102 102 protected: 103 103 ModularSpaceShip* parent_; 104 unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on.104 unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on. 105 105 106 106 float damageAbsorption_; … … 110 110 111 111 private: 112 std::vector<StaticEntity*> entityList_; // list of all entities which belong to this part112 std::vector<StaticEntity*> entityList_; // List of all entities which belong to this part 113 113 std::vector<PartDestructionEvent*> eventList_; // The list of all PartDestructionEvent assigned to this ShipPart. 114 114
Note: See TracChangeset
for help on using the changeset viewer.