Changeset 10847 for code/branches/campaignHS15/src/orxonox
- Timestamp:
- Nov 24, 2015, 11:54:47 AM (9 years ago)
- Location:
- code/branches/campaignHS15/src/orxonox
- Files:
-
- 6 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 } -
code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc
r10844 r10847 27 27 */ 28 28 29 #include "Action Point.h"29 #include "Actionpoint.h" 30 30 31 31 #include "core/CoreIncludes.h" … … 34 34 namespace orxonox 35 35 { 36 RegisterClass(Action Point);36 RegisterClass(Actionpoint); 37 37 38 Action Point::ActionPoint(Context* context) : StaticEntity(context)38 Actionpoint::Actionpoint(Context* context) : StaticEntity(context) 39 39 { 40 RegisterObject(Action Point);40 RegisterObject(Actionpoint); 41 41 42 42 } 43 43 //usage: 44 44 // <DivisionController team=12> 45 // < actionpoints>46 // <Action Point position="12,34,56" action="FIGHT" enemy="enemyName" />, position irrelevant47 // <Action Point position="12,34,56" action="PROTECT" protect="protectName" />, position irrelevant48 // <Action Point position="12,34,56" action="FLY" />, position relevant: makes ship fly to the position of ActionPoint49 // </ actionpoints>45 // <Actionpoints> 46 // <Actionpoint position="12,34,56" action="FIGHT" enemy="enemyName" />, position irrelevant 47 // <Actionpoint position="12,34,56" action="PROTECT" protect="protectName" />, position irrelevant 48 // <Actionpoint position="12,34,56" action="FLY" />, position relevant: makes ship fly to the position of Actionpoint 49 // </Actionpoints> 50 50 // </DivisonController> 51 51 //DivisionController will firstly fight enemy that it will find by name "enemyName", if finds nothing or when beats enemy, … … 56 56 //another usage: 57 57 // <DivisionController team=12> 58 // < actionpoints>59 // <Action Point position="12,34,56" action="PROTECT" protectMe=true />, position irrelevant60 // <Action Point position="12,34,56" action="FIGHT" fightAll=true />, position irrelevant61 // </ actionpoints>58 // <Actionpoints> 59 // <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />, position irrelevant 60 // <Actionpoint position="12,34,56" action="FIGHT" fightAll=true />, position irrelevant 61 // </Actionpoints> 62 62 // </DivisonController> 63 63 //DivisionController will protect the first NewHumanController it finds, when it dies or if no controller found, 64 64 //it will fight closest enemies one after another 65 void Action Point::XMLPort(Element& xmlelement, XMLPort::Mode mode)65 void Actionpoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) 66 66 { 67 SUPER(Action Point, XMLPort, xmlelement, mode);67 SUPER(Actionpoint, XMLPort, xmlelement, mode); 68 68 69 XMLPortParam( Action Point, "action", setActionXML, getActionXML, xmlelement, mode );70 XMLPortParam( Action Point, "protect", setProtectXML, getProtectXML, xmlelement, mode );71 XMLPortParam( Action Point, "enemy", setEnemyXML, getEnemyXML, xmlelement, mode );72 XMLPortParam( Action Point, "protectMe", setProtectMeXML, getProtectMeXML, xmlelement, mode ).defaultValues(false);73 XMLPortParam( Action Point, "fightAll", setFightAllXML, getFightAllXML, xmlelement, mode ).defaultValues(false);69 XMLPortParam( Actionpoint, "action", setActionXML, getActionXML, xmlelement, mode ); 70 XMLPortParam( Actionpoint, "protect", setProtectXML, getProtectXML, xmlelement, mode ); 71 XMLPortParam( Actionpoint, "enemy", setEnemyXML, getEnemyXML, xmlelement, mode ); 72 XMLPortParam( Actionpoint, "protectMe", setProtectMeXML, getProtectMeXML, xmlelement, mode ).defaultValues(false); 73 XMLPortParam( Actionpoint, "fightAll", setFightAllXML, getFightAllXML, xmlelement, mode ).defaultValues(false); 74 74 75 75 } 76 void Action Point::setActionXML( std::string val)76 void Actionpoint::setActionXML( std::string val) 77 77 { 78 78 this->actionName_ = getUppercase( val ); 79 orxout(internal_error) << "action = " << this->actionName_ << endl; 79 80 } 80 81 81 std::string Action Point::getActionXML()82 std::string Actionpoint::getActionXML() 82 83 { 83 84 return this->actionName_; 84 85 } 85 void Action Point::setProtectXML( std::string val)86 void Actionpoint::setProtectXML( std::string val) 86 87 { 87 88 this->protectName_ = getUppercase( val ); 88 89 } 89 90 90 std::string Action Point::getProtectXML()91 std::string Actionpoint::getProtectXML() 91 92 { 92 93 return this->protectName_; 93 94 } 94 void Action Point::setEnemyXML( std::string val)95 void Actionpoint::setEnemyXML( std::string val) 95 96 { 96 97 this->enemyName_ = getUppercase( val ); 97 98 } 98 99 99 std::string Action Point::getEnemyXML()100 std::string Actionpoint::getEnemyXML() 100 101 { 101 102 return this->enemyName_; 102 103 } 103 104 void ActionPoint::setTargetPosition(const Vector3& target) 104 void Actionpoint::setProtect( ControllableEntity* protect) 105 { 106 this->protect_ = protect; 107 } 108 ControllableEntity* Actionpoint::getProtect() 109 { 110 return this->protect_; 111 } 112 void Actionpoint::setEnemy( ControllableEntity* enemy) 113 { 114 this->enemy_ = enemy; 115 } 116 ControllableEntity* Actionpoint::getEnemy() 117 { 118 return this->enemy_; 119 } 120 void Actionpoint::setTargetPosition(const Vector3& target) 105 121 { 106 122 this->targetPosition_ = target; 107 123 } 108 Vector3 Action Point::getTargetPosition ()124 Vector3 Actionpoint::getTargetPosition () 109 125 { 110 126 return this->targetPosition_; -
code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
r10844 r10847 33 33 */ 34 34 35 #ifndef _Action Point_H__36 #define _Action Point_H__35 #ifndef _Actionpoint_H__ 36 #define _Actionpoint_H__ 37 37 38 38 #include "OrxonoxPrereqs.h" … … 45 45 { 46 46 47 class _OrxonoxExport Action Point : public StaticEntity47 class _OrxonoxExport Actionpoint : public StaticEntity 48 48 { 49 49 public: 50 Action Point(Context* context);51 virtual ~Action Point() {}50 Actionpoint(Context* context); 51 virtual ~Actionpoint() {} 52 52 53 53 //----[XML data]---- … … 87 87 //----[/FightAll data]---- 88 88 //----[/XML data]---- 89 89 void setProtect( ControllableEntity* protect); 90 ControllableEntity* getProtect(); 91 void setEnemy( ControllableEntity* enemy); 92 ControllableEntity* getEnemy(); 90 93 //----["Waypoints" data]---- 91 94 void setTargetPosition(const Vector3& target); … … 98 101 std::string protectName_; 99 102 std::string enemyName_; 103 WeakPtr<ControllableEntity> protect_; 104 WeakPtr<ControllableEntity> enemy_; 105 100 106 bool protectMe_; 101 107 bool fightAll_; … … 104 110 } 105 111 106 #endif /* _Action Point_H__ */112 #endif /* _Actionpoint_H__ */ -
code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt
r10843 r10847 12 12 SpawnPoint.cc 13 13 TeamSpawnPoint.cc 14 Action Point.cc14 Actionpoint.cc 15 15 ) 16 16
Note: See TracChangeset
for help on using the changeset viewer.