- Timestamp:
- Nov 22, 2015, 5:06:38 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10805 r10826 35 35 RegisterClass(WingmanController); 36 36 37 37 //CommonController contains all common functionality of AI Controllers 38 38 WingmanController::WingmanController(Context* context) : CommonController(context) 39 39 { … … 42 42 this->myLeader_ = 0; 43 43 this->rank_ = Rank::WINGMAN; 44 45 44 } 46 45 … … 49 48 50 49 } 51 // void WingmanController::chooseManeuver() 52 // { 53 // if (this->maneuverType_ == ManeuverType::NONE) 54 // switch (this->maneuverType_ ) 55 // { 56 // case ManeuverType::NONE: 57 // { 50 51 void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 52 { 53 SUPER(WingmanController, XMLPort, xmlelement, mode); 58 54 59 // break; 60 // } 61 // case ManeuverType::NEUTRAL: 62 // { 63 64 // break; 65 // } 66 // case ManeuverType::OFFENSIVE: 67 // { 68 69 // break; 70 // } 71 // case ManeuverType::DEFENSIVE: 72 // { 73 74 // break; 75 // } 76 // } 77 // if (!this->myWingman_) 78 // return; 79 // Vector3* targetRelativePositionOfWingman; 80 // switch (this->formationMode_){ 81 // case FormationMode::WALL: 82 // { 83 // targetRelativePositionOfWingman = new Vector3 (-400, 0, 0); 84 // break; 85 // } 86 // case FormationMode::FINGER4: 87 // { 88 // targetRelativePositionOfWingman = new Vector3 (-400, 0, -200); 89 // break; 90 // } 91 // case FormationMode::VEE: 92 // { 93 // break; 94 // } 95 // case FormationMode::DIAMOND: 96 // { 97 // targetRelativePositionOfWingman = new Vector3 (400, -200, 0); 98 // break; 99 // } 100 // } 101 // Quaternion orient = this->getControllableEntity()->getWorldOrientation(); 102 103 // Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 104 // (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); 105 106 // myWingman_->setTargetOrientation(orient); 107 // myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); 108 109 // } 110 55 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 56 } 57 58 //----in tick, move (or look) and shoot---- 111 59 void WingmanController::tick(float dt) 112 60 { … … 129 77 } 130 78 79 //----action for hard calculations---- 131 80 void WingmanController::action() 132 81 { 82 //----If no leader, find one---- 133 83 if (!this->myLeader_) 134 84 { … … 136 86 this->myLeader_ = newLeader; 137 87 if (newLeader) 138 orxout(internal_error) << "new Leader set" << endl; 88 { 89 //orxout(internal_error) << "new Leader set" << endl; 90 } 91 //----If no leader found, attack someone---- 92 //----TODO: find closest enemy---- 139 93 else 140 94 { 141 if (!this->target_){ 95 if ( !this->hasTarget() || this->action_ != Action::FIGHT ) 96 { 142 97 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 143 98 { 144 if ( this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())99 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) ) 145 100 continue; 146 101 this->setAction(Action::FIGHT, (*itP)); … … 149 104 } 150 105 } 151 152 106 } 107 //----If have leader, he will deal with logic---- 153 108 else 154 109 { 155 110 156 111 } 157 112 113 114 //----action was set to fight---- 158 115 if (this->action_ == Action::FIGHT) 159 116 { 117 //----choose where to go---- 160 118 this->maneuver(); 119 //----fire if you can---- 161 120 this->bShooting_ = this->canFire(); 162 if (this->target_)163 {164 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();165 if (diffVector.length() > 5000)166 {167 168 }169 }170 121 } 122 //----action was set to fly, leader handles the logic---- 171 123 else if (this->action_ == Action::FLY) 172 124 { 173 125 174 126 } 127 //----TODO: implement protect---- 175 128 else if (this->action_ == Action::PROTECT) 176 129 { … … 182 135 183 136 184 137 //----POST: closest leader that is ready to take a new wingman is returned---- 185 138 CommonController* WingmanController::findNewLeader() 186 139 { … … 189 142 return 0; 190 143 144 //----vars for finding the closest leader---- 191 145 CommonController* closestLeader = 0; 192 146 float minDistance = std::numeric_limits<float>::infinity(); … … 194 148 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 195 149 { 196 // 0ptr?150 //----0ptr or not a leader or dead?---- 197 151 if (!it || 198 152 (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) || 199 153 !(it->getControllableEntity())) 200 154 continue; 201 //same team? 202 if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) 155 156 //----same team?---- 157 if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity()) ) 203 158 continue; 204 //is equal to this? 205 if (it->getControllableEntity() == this->getControllableEntity()) 206 continue; 207 208 float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 159 160 //----check distance---- 161 float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity()); 209 162 if (distance < minDistance && !(it->hasWingman())) 210 163 { … … 216 169 if (closestLeader) 217 170 { 171 //----Racing conditions---- 218 172 if (closestLeader->setWingman(this)) 219 173 return closestLeader; … … 222 176 } 223 177 224 void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)225 {226 SUPER(WingmanController, XMLPort, xmlelement, mode);227 228 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);229 }230 178 231 179
Note: See TracChangeset
for help on using the changeset viewer.