- Timestamp:
- Oct 30, 2015, 12:08:30 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10719 r10722 29 29 #include "WingmanController.h" 30 30 31 #include "core/CoreIncludes.h"32 33 #include "core/XMLPort.h"34 #include "core/command/ConsoleCommandIncludes.h"35 36 #include "worldentities/ControllableEntity.h"37 #include "worldentities/pawns/Pawn.h"38 31 39 32 namespace orxonox … … 51 44 WingmanController::~WingmanController() 52 45 { 53 } 54 55 /* void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 56 { 57 SUPER(WingmanController, XMLPort, xmlelement, mode); 58 59 XMLPortParam(WingmanController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f); 60 XMLPortObject(WingmanController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); 61 }*/ 46 if (this->myLeader_) 47 this->myLeader_->myWingman_ = 0; 48 } 49 62 50 CommonController* WingmanController::findNewLeader() 63 51 { 64 52 65 53 if (!this->getControllableEntity()) 66 return NULL; 67 68 69 //go through all pawns 54 return 0; 55 56 CommonController* closestLeader = 0; 57 float minDistance = std::numeric_limits<float>::infinity(); 58 70 59 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 71 60 { 61 //0ptr? 62 if (!it || !it->isLeader() || !(it->getControllableEntity())) 63 continue; 72 64 //same team? 73 if ( (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))65 if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) 74 66 continue; 75 67 //is equal to this? … … 79 71 80 72 81 //nullptr? 82 if (!it || !it->isLeader()) 83 continue; 73 84 74 85 75 float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 86 87 // is pawn in range? 76 if (distance < minDistance && !(it->hasWingman())) 77 { 78 closestLeader = *it; 79 minDistance = distance; 80 } 81 /*// is pawn in range? 88 82 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 89 83 { … … 91 85 if (it->setWingman(this)) 92 86 return *it; 93 } 94 } 95 return NULL; 96 } 87 }*/ 88 } 89 if (closestLeader) 90 { 91 if (closestLeader->setWingman(this)) 92 return closestLeader; 93 } 94 return 0; 95 } 96 97 97 void WingmanController::action() 98 98 { 99 99 //this->target_ = this->sectionTarget_; 100 if (! myLeader_)100 if (!this->myLeader_) 101 101 { 102 102 CommonController* newLeader = findNewLeader(); 103 myLeader_ = newLeader;104 /*if (newLeader)103 this->myLeader_ = newLeader; 104 if (newLeader) 105 105 orxout(internal_error) << "new Leader set" << endl; 106 106 else 107 orxout(internal_error) << " nullleader" << endl;108 */ 107 orxout(internal_error) << "0 leader" << endl; 108 109 109 } 110 110 else 111 111 { 112 112 113 //orxout(internal_error) << "already have a Leader" << endl; 113 114
Note: See TracChangeset
for help on using the changeset viewer.