- Timestamp:
- Oct 29, 2015, 8:02:23 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
r10718 r10719 41 41 RegisterClass(LeaderController); 42 42 43 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;44 43 45 44 LeaderController::LeaderController(Context* context) : CommonController(context) … … 47 46 48 47 RegisterObject(LeaderController); 49 bIsDivisionLeader_ = false;50 48 51 49 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this))); … … 57 55 } 58 56 59 LeaderController* LeaderController::findNewDivisionLeader() 60 { 61 62 if (!this->getControllableEntity()) 63 return NULL; 64 65 66 //go through all pawns 67 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 68 { 69 70 //same team? 71 if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam())) 72 continue; 73 74 //Does it have a Controller? 75 Controller* controller = 0; 76 77 if (it->getController()) 78 controller = it->getController(); 79 else if (it->getXMLController()) 80 controller = it->getXMLController(); 81 82 if (!controller) 83 continue; 84 85 //is equal to this? 86 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 87 continue; 88 89 90 LeaderController* newLeader = orxonox_cast<LeaderController*>(controller); 91 92 //nullptr or not DivisionController? 93 if (!newLeader || !newLeader->bIsDivisionLeader_) 94 continue; 95 96 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 97 98 // is pawn in range? 99 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 100 { 101 102 if (newLeader->setFollower(this)) 103 return newLeader; 104 } 105 } 106 return NULL; 107 108 } 109 void LeaderController::action() 110 { 111 //this->target_ = this->sectionTarget_; 112 if (!myDivisionLeader_) 113 { 114 LeaderController* newDivisionLeader = findNewDivisionLeader(); 115 myDivisionLeader_ = newDivisionLeader; 116 orxout(internal_error) << "new DivisionLeader set" << endl; 117 } 118 } 119 /* 120 Wingmen and Leaders attack target_, which is a member variable of their classes. 121 Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless 122 Wingman covers Leader's rear. 123 Leader's target_ must always equal sectionTarget_. 124 if section has a target, its Leader shoots at it, but doesn't follow. 125 Every section is a part of division. Division consisting of one Section is still a division. 126 Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController. 127 Division leader ONLY can follow target_ while in formation flight. 128 If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint. 129 Division Leader's sectionTarget_ must equal divisionTarget_, 130 but the other section, that is not a leading section, can attack any target that is near divisonTarget_ 131 132 */ 133 void LeaderController::tick(float dt) 134 {/* 135 if (!this->isActive()) 136 return; 137 138 //--------------------------Stay in division-------------------------- 139 this->keepDivisionTick();*/ 140 /*keepDivisionTick(){ 141 if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){ 142 Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) + 143 (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); 144 this->moveToPosition (desiredAbsolutePosition); 145 } 146 } 147 */ 148 /*//If ordered to attack -> follow target and shoot 149 if (this->bAttackOrder_) 150 { 151 152 } 153 //If ordered to move -> move to a target Point 154 155 //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. 156 //(Section shoots same target, Boss's section shoots another target) 157 { 158 159 }*/ 160 161 orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl; 162 163 SUPER(LeaderController, tick, dt); 164 } 165 bool LeaderController::setWingman(WingmanController* wingman) 166 { 167 if (!this->myWingman_) 168 { 169 this->myWingman_ = wingman; 170 return true; 171 } 172 else 173 { 174 return false; 175 } 176 } 177 bool LeaderController::isLeader() 178 { 179 return true; 180 } 57 181 58 //**********************************************NEW 182 59 /* void LeaderController::defaultBehaviour(float maxrand)
Note: See TracChangeset
for help on using the changeset viewer.