- Timestamp:
- Nov 29, 2015, 12:14:43 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10885 r10886 59 59 { 60 60 SUPER(WingmanController, XMLPort, xmlelement, mode); 61 62 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);63 61 } 64 62 … … 67 65 { 68 66 if (!this->isActive()) 69 return; 70 if (this->myLeader_ && this->myLeader_->getAction() != Action::FIGHT && this->myLeader_->getAction() != 71 Action::FIGHTALL && this->myLeader_->getAction() != Action::ATTACK) 72 { 73 } 67 return; 74 68 75 69 SUPER(WingmanController, tick, dt); … … 108 102 || this->myLeader_->getAction() == Action::ATTACK)) 109 103 { 110 ControllableEntity* myEntity = this->getControllableEntity(); 111 Vector3 myPosition = myEntity->getWorldPosition(); 112 if (!this->myLeader_) 113 { 114 return; 115 } 116 ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity(); 117 Quaternion orient = leaderEntity->getWorldOrientation(); 118 Vector3 leaderPosition = leaderEntity->getWorldPosition(); 119 Vector3 targetRelativePosition = getFormationPosition(); 120 if (!this->myLeader_) 121 { 122 return; 123 } 124 Vector3 targetAbsolutePosition = 125 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5) 126 + (orient* (targetRelativePosition))); 127 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function. 128 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_) 129 this->setAction (Action::FLY, targetAbsolutePosition, orient); 130 else 131 this->setAction (Action::FLY, targetAbsolutePosition); 132 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f) 133 { 134 this->boostControl(); 135 } 136 else 137 { 138 this->getControllableEntity()->boost(false); 139 } 140 } 141 else 142 { 143 switch (this->myLeader_->getAction()) 144 { 145 case Action::FIGHT: 146 { 147 if (!this->hasTarget()) 148 { 149 this->setTarget(this->myLeader_->getTarget()); 150 } 151 break; 152 } 153 case Action::FIGHTALL: 154 { 155 if (!this->hasTarget()) 156 { 157 this->setTarget(this->myLeader_->getTarget()); 158 } 159 break; 160 } 161 case Action::ATTACK: 162 { 163 if (!this->hasTarget()) 164 { 165 this->setTarget(this->myLeader_->getTarget()); 166 } 167 break; 168 } 169 default: 170 { 171 172 } 104 this->keepFormation(); 105 } 106 else if (!this->myLeader_->bKeepFormation_) 107 { 108 if (!this->hasTarget()) 109 { 110 this->setTarget(this->myLeader_->getTarget()); 173 111 } 174 112 if (this->hasTarget()) … … 180 118 } 181 119 } 182 183 184 120 } 185 121 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ; … … 236 172 delete targetRelativePosition; 237 173 return result; 174 } 175 void WingmanController::keepFormation() 176 { 177 this->bKeepFormation_ = true; 178 ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity(); 179 Vector3 targetRelativePosition = this->getFormationPosition(); 180 if (!leaderEntity) 181 return; 182 FlyingController::keepFormation (leaderEntity, targetRelativePosition); 238 183 } 239 184 //----POST: closest leader that is ready to take a new wingman is returned---- … … 268 213 minDistance = distance; 269 214 } 270 271 215 } 272 216 if (closestLeader) … … 277 221 return closestLeader; 278 222 } 279 280 } 281 223 } 282 224 return 0; 283 225 } 284 226 285 286 287 288 227 }
Note: See TracChangeset
for help on using the changeset viewer.