- Timestamp:
- Oct 29, 2015, 11:53:45 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10709 r10717 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" 31 38 32 39 namespace orxonox … … 34 41 35 42 RegisterClass(WingmanController); 36 37 WingmanController::WingmanController(Context* context) : Controller(context) 43 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000; 44 45 WingmanController::WingmanController(Context* context) : CommonController(context) 38 46 { 39 47 RegisterObject(WingmanController); … … 52 60 XMLPortObject(WingmanController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); 53 61 }*/ 62 CommonController* WingmanController::findNewLeader() 63 { 64 65 if (!this->getControllableEntity()) 66 return NULL; 67 68 69 //go through all pawns 70 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 71 { 72 73 //same team? 74 if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam())) 75 continue; 76 77 //Does it have a Controller? 78 Controller* controller = 0; 79 80 if (it->getController()) 81 controller = it->getController(); 82 else if (it->getXMLController()) 83 controller = it->getXMLController(); 84 85 if (!controller) 86 continue; 87 88 //is equal to this? 89 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 90 continue; 91 92 93 CommonController* newLeader = orxonox_cast<CommonController*>(controller); 94 95 //nullptr? 96 if (!newLeader || !newLeader->isLeader()) 97 continue; 98 99 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 100 101 // is pawn in range? 102 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 103 { 104 105 if (newLeader->setWingman(this)) 106 return newLeader; 107 } 108 } 109 return NULL; 110 } 111 bool WingmanController::isLeader() 112 { 113 return false; 114 } 54 115 void WingmanController::action() 55 116 { 56 117 //this->target_ = this->sectionTarget_; 118 if (!myLeader_) 119 { 120 CommonController* newLeader = findNewLeader(); 121 myLeader_ = newLeader; 122 orxout(internal_error) << "new Leader set" << endl; 123 } 57 124 } 58 125 59 126 void WingmanController::tick(float dt) 60 {/* 127 { 128 //------------------------------------------------------- 129 /*//collect data for AI behaviour 130 Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0); 131 Vector3* meanOfAlliesPtr = new Vector3(0.0,0.0,0.0); 132 Vector3 meanOfAllies = *meanOfAlliesPtr; 133 Vector3 meanOfEnemies = *meanOfEnemiesPtr; 134 135 136 for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it) 137 { 138 139 Gametype* gt=this->getGametype(); 140 if (!gt) 141 { 142 gt=it->getGametype(); 143 } 144 if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt)) 145 { 146 enemies_.push_back(*it); 147 } 148 else { 149 allies_.push_back(*it); 150 } 151 } 152 if (enemies_.size() != 0 && allies_.size() != 0){ 153 for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it) 154 meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition(); 155 156 meanOfEnemies /= enemies_.size(); 157 158 for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it) 159 meanOfAllies += (*it)->getControllableEntity()->getWorldPosition(); 160 161 meanOfAllies /= allies_.size(); 162 163 //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl; 164 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl; 165 orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl; 166 orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl; 167 }*/ 168 /* 61 169 if (!this->isActive()) 62 170 return; … … 83 191 }*/ 84 192 //orxout(internal_error) << "I am " << this << endl; 193 194 /* void FormationController::setDesiredPositionOfSlaves() 195 { 196 if (this->state_ != MASTER) 197 return; 198 switch (this->formationMode_){ 199 case ATTACK: 200 { 201 float i = 0; 202 for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 203 { 204 (*it)->desiredRelativePosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0); 205 i++; 206 } 207 break; 208 } 209 case NORMAL: 210 { 211 break; 212 } 213 case DEFEND: 214 { 215 break; 216 } 217 } 218 219 }*/ 85 220 86 221 SUPER(WingmanController, tick, dt);
Note: See TracChangeset
for help on using the changeset viewer.