Changeset 10847 for code/branches/campaignHS15/src/orxonox/controllers
- Timestamp:
- Nov 24, 2015, 11:54:47 AM (9 years ago)
- Location:
- code/branches/campaignHS15/src/orxonox/controllers
- Files:
-
- 3 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() -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10843 r10847 39 39 #include "tools/interfaces/Tickable.h" 40 40 #include <limits> 41 41 #include "worldentities/Actionpoint.h" 42 42 43 43 namespace orxonox … … 63 63 enum Value 64 64 { 65 FLY, FIGHT, PROTECT65 NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK 66 66 }; 67 67 } … … 111 111 ControllableEntity* getProtect (); 112 112 //----[/Protect data]---- 113 //----[Actionpoint data]---- 114 void addActionpoint(WorldEntity* waypoint); 115 WorldEntity* getActionpoint(unsigned int index) const; 116 //----[/Actionpoint data]---- 113 117 //----[/XML data]---- 114 118 … … 134 138 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt); 135 139 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; 140 static std::string getName( ControllableEntity* entity ) ; 136 141 137 142 float squaredDistanceToTarget() const; … … 166 171 void doFire(); 167 172 void setClosestTarget(); 173 ControllableEntity* closestTarget(); 168 174 169 175 bool bShooting_; … … 177 183 Quaternion targetOrientation_; 178 184 179 Vector3 destination_; 180 bool bHasDestination; 185 181 186 //----[/where-to-fly information]---- 182 187 //----[protect information]---- … … 185 190 //----[who-to-kill information]---- 186 191 WeakPtr<ControllableEntity> target_; 187 WeakPtr<ControllableEntity> enemy_; 188 192 189 193 bool bHasPositionOfTarget_; 190 194 Vector3 positionOfTarget_; … … 193 197 //----[/who-to-kill information]---- 194 198 199 //----[Actionpoint information]---- 200 std::vector<WeakPtr<WorldEntity> > actionpoints_; 201 float squaredaccuracy_; 202 <tuple<Action::Value ,std::string ,Vector3 > > currentActionpoint_; 203 std::vector<tuple<Action::Value ,std::string ,Vector3 > > parsedActionpoints_; 204 //----[/Actionpoint information]---- 195 205 //----["Private" variables]---- 196 206 FormationMode::Value formationMode_; … … 198 208 std::string protectName_; 199 209 Action::Value action_; 210 int attackRange_; 211 200 212 //----[/"Private" variables]---- 201 213 }; -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10843 r10847 76 76 77 77 78 if (this->action_ == Action::FIGHT) 78 /* if (this->target_) 79 { 80 if (CommonController::distance (this->getControllableEntity(), newTarget) < 81 CommonController::distance (this->getControllableEntity(), target_)) 82 { 83 Actionpoint* ap = new Actionpoint(this->getContext()); 84 ap->setPosition (0, 0, 0); 85 ap->setActionXML ("FIGHT"); 86 //ap->setEnemyXML(CommonController::getName(newTarget)); 87 this->addActionpoint (ap); 88 } 89 90 }*/ 91 //----Whatever ship is doing, if there are targets close to it and its own target is far away, fight them---- 92 //analog to attack move 93 if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) 94 { 95 if ((this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) || 96 !this->target_) 97 { 98 ControllableEntity* newTarget = this->closestTarget(); 99 if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 100 { 101 this->backupAction(); 102 this->setAction (Action::FIGHT, newTarget); 103 } 104 } 105 } 106 //action is NONE whenever ships finishes current action, 107 //if it was fighting before because enemies were close, resume what it was doing 108 //otherwise try to execute next action 109 if (this->action_ == Action::NONE) 110 { 111 if (this->bBackuped_) 112 { 113 this->restoreAction(); 114 } else if (!this->actionpoints_.empty()) 115 { 116 this->popAction(); 117 } 118 } 119 if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL) 79 120 { 80 121 if (!this->hasTarget()) 81 122 { 82 123 //----find a target---- 83 this->setClosestTarget(); 84 } 85 else 124 if (this->action_ == Action::FIGHT) 125 { 126 ControllableEntity* newTarget = this->closestTarget(); 127 if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 128 { 129 this->setAction (Action::FIGHT, newTarget); 130 } 131 else 132 { 133 this->setAction (Action::NONE); 134 } 135 } 136 else if (this->action_ == Action::FIGHTALL) 137 { 138 this->setClosestTarget(); 139 } 140 141 } 142 else if (this->hasTarget()) 86 143 { 87 144 //----fly in formation if far enough---- 88 145 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 89 if (diffVector.length() > 3000)146 if (diffVector.length() > this->attackRange_) 90 147 { 91 148 this->setTargetPositionOfWingman(); … … 131 188 this->setProtect (static_cast<ControllableEntity*>(*itP)); 132 189 } 190 } 191 if (!this->getProtect()) 192 { 193 this->setAction (Action::NONE); 133 194 } 134 195 }
Note: See TracChangeset
for help on using the changeset viewer.