- Timestamp:
- Nov 24, 2015, 11:54:47 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10843 r10847 60 60 this->action_ = Action::FLY; 61 61 this->stopLookingAtTarget(); 62 62 this->attackRange_ = 2500; 63 63 RegisterObject( CommonController ); 64 64 } … … 69 69 //orxout(internal_error) << "I died, my Rank is " << rank_ << endl; 70 70 } 71 71 void CommonController::backupAction() 72 { 73 this->actionpoints_.push_back (this->currentActionpoint_); 74 } 75 void CommonController::restoreAction() 76 { 77 this->currentActionpoint_ = this->actionpoints_.back(); 78 this->actionpoints_.pop_back(); 79 } 80 void CommonController::popAction() 81 { 82 this->currentActionpoint_ = actionpoints_.back(); 83 actionpoints_.pop_back(); 84 } 85 72 86 void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode ) 73 87 { 74 88 SUPER( CommonController, XMLPort, xmlelement, mode ); 75 89 XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode ); 76 XMLPortParam( CommonController, "action", setActionXML, getActionXML, xmlelement, mode );77 XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML, xmlelement, mode );90 //XMLPortParam( CommonController, "action", setActionXML, getActionXML, xmlelement, mode ); 91 //XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML, xmlelement, mode ); 78 92 //XMLPortParam ( CommonController, "enemy", setEnemyXML, getEnemyXML, xmlelement, mode ); 93 XMLPortObject(CommonController, WorldEntity, "actionpoints", addActionpoint, getActionpoint, xmlelement, mode); 94 79 95 } 80 96 void CommonController::setProtectXML( std::string val ) … … 104 120 if (!this->getProtect()) 105 121 return "noProtectWasSet"; 106 return this->getProtect()->getName(); 107 } 108 122 return CommonController::getName (this->getProtect()); 123 } 124 std::string CommonController::getName(ControllableEntity* entity) 125 { 126 std::string name = entity->getName(); 127 if (name == "") 128 { 129 const void * address = static_cast<const void*>(entity); 130 std::stringstream ss; 131 ss << address; 132 name = ss.str(); 133 } 134 return name; 135 136 } 109 137 void CommonController::setProtect (ControllableEntity* protect) 110 138 { … … 126 154 else if ( valUpper == "PROTECT" ) 127 155 value = Action::PROTECT; 156 else if ( valUpper == "NONE" ) 157 value = Action::NONE; 158 else if ( valUpper == "FIGHTALL" ) 159 value = Action::FIGHTALL; 160 else if ( valUpper == "ATTACK" ) 161 value = Action::ATTACK; 128 162 else 129 163 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." ); … … 149 183 break; 150 184 } 185 case Action::NONE: 186 { 187 return "NONE"; 188 break; 189 } 190 case Action::FIGHTALL: 191 { 192 return "FIGHTALL"; 193 break; 194 } 195 case Action::ATTACK: 196 { 197 return "ATTACK"; 198 break; 199 } 151 200 default: 152 return " FIGHT";201 return "NONE"; 153 202 break; 154 203 } … … 237 286 238 287 } 288 void CommonController::addActionpoint(WorldEntity* actionpoint) 289 { 290 std::string actionName; 291 Vector3 position; 292 std::string targetName; 293 this->actionpoints_.push_back(actionpoint); 294 if (static_cast<Actionpoint*> (actionpoint)) 295 { 296 Actionpoint* ap = static_cast<Actionpoint*> (actionpoint); 297 actionName = ap->getActionXML(); 298 targetName = ap->get 299 Action::Value value; 300 301 if ( valUpper == "FIGHT" ) 302 { 303 value = Action::FIGHT; 304 305 } 306 else if ( valUpper == "FLY" ) 307 { 308 value = Action::FLY; 309 310 } 311 else if ( valUpper == "PROTECT" ) 312 { 313 value = Action::PROTECT; 314 315 } 316 else if ( valUpper == "NONE" ) 317 { 318 value = Action::NONE; 319 320 } 321 else if ( valUpper == "FIGHTALL" ) 322 { 323 value = Action::FIGHTALL; 324 325 } 326 else if ( valUpper == "ATTACK" ) 327 { 328 value = Action::ATTACK; 329 330 } 331 else 332 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." ); 333 this->setAction( value ); 334 } 335 else 336 { 337 actionName = "FLY"; 338 } 339 340 } 341 342 WorldEntity* CommonController::getActionpoint(unsigned int index) const 343 { 344 if (index < this->actionpoints_.size()) 345 return this->actionpoints_[index]; 346 else 347 return 0; 348 } 239 349 void CommonController::setClosestTarget() 240 350 { 351 this->setTarget (closestTarget()); 352 } 353 ControllableEntity* CommonController::closestTarget() 354 { 241 355 if (!this->getControllableEntity()) 242 return ;356 return 0; 243 357 244 358 Pawn* closestTarget = 0; … … 259 373 if (closestTarget) 260 374 { 261 (this)->setTarget(static_cast<ControllableEntity*>(closestTarget)); 262 } 375 return static_cast<ControllableEntity*>(closestTarget); 376 } 377 return 0; 263 378 } 264 379 void CommonController::maneuver()
Note: See TracChangeset
for help on using the changeset viewer.