- Timestamp:
- Dec 7, 2015, 8:34:20 AM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10915 r10923 92 92 <!-- HERE STARTS DEMO FOR THE ACTIONPOINTS. 93 93 P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped --> 94 <!--94 95 95 <Model mesh="cube.mesh" scale=8 position="0,0,0" /> 96 96 … … 153 153 </templates> 154 154 </SpaceShip> 155 -->155 156 156 157 157 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS --> 158 158 <!-- HERE STARTS DEMO FOR FIGHTING --> 159 159 <!-- 160 160 161 161 <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="d1sd1"> … … 196 196 </controller> 197 197 </SpaceShip> 198 <SpaceShip position="-5000, 1500, -1000" lookat="0,0,0" team=0 name="d1s1d1">199 <templates>200 <Template link=spaceshipassff />201 </templates>202 <controller>203 <DivisionController team=0 formationMode="WALL">204 205 </DivisionController>206 </controller>207 </SpaceShip>208 <SpaceShip position="-5000, 1900, -1000" lookat="0,0,0" team=0 name="d1s1s1">209 <templates>210 <Template link=spaceshipassff />211 </templates>212 <controller>213 <SectionController team=0>214 </SectionController>215 </controller>216 </SpaceShip>217 <SpaceShip position="-5000, 2100, -1000" lookat="0,0,0" team=0 name="d1s1w1">218 <templates>219 <Template link=spaceshipassff />220 </templates>221 <controller>222 <WingmanController team=0>223 </WingmanController>224 </controller>225 </SpaceShip>226 <SpaceShip position="-5000, 2400, -1000" lookat="0,0,0" team=0 name="d1s1w2">227 <templates>228 <Template link=spaceshipassff />229 </templates>230 <controller>231 <WingmanController team=0>232 </WingmanController>233 </controller>234 </SpaceShip>235 198 236 199 <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1 name="d2sd1"> … … 271 234 </controller> 272 235 </SpaceShip> 273 <SpaceShip position="1000, -1500, 1000" lookat="0,0,0" team=1 name="d2s1d1"> 274 <templates> 275 <Template link=spaceshipassff /> 276 </templates> 277 <controller> 278 <DivisionController team=1 formationMode="WALL"> 279 280 </DivisionController> 281 </controller> 282 </SpaceShip> 283 <SpaceShip position="1000, -1900, 1000" lookat="0,0,0" team=1 name="d2s1s1"> 284 <templates> 285 <Template link=spaceshipassff /> 286 </templates> 287 <controller> 288 <SectionController team=1> 289 </SectionController> 290 </controller> 291 </SpaceShip> 292 <SpaceShip position="1000, -2100, 1000" lookat="0,0,0" team=1 name="d2s1w1"> 293 <templates> 294 <Template link=spaceshipassff /> 295 </templates> 296 <controller> 297 <WingmanController team=1> 298 </WingmanController> 299 </controller> 300 </SpaceShip> 301 <SpaceShip position="1000, -2400, 1000" lookat="0,0,0" team=1 name="d2s1w2"> 302 <templates> 303 <Template link=spaceshipassff /> 304 </templates> 305 <controller> 306 <WingmanController team=1> 307 </WingmanController> 308 </controller> 309 </SpaceShip> 310 236 --> 311 237 <!-- HERE ENDS DEMO FOR FIGHTING --> 312 238 <!-- HERE STARTS DEMO FOR FORMATIONS --> -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10915 r10923 40 40 ActionpointController::ActionpointController(Context* context) : FightingController(context) 41 41 { 42 this->ticks_ = 0; 42 43 this->bPatrolling_ = false; 43 44 this->actionCounter_ = 0; 44 this->maneuverCounter_ = 0; 45 45 this->bInLoop_ = false; 46 46 this->bLoop_ = false; … … 49 49 parsedActionpoints_.clear(); 50 50 actionpoints_.clear(); 51 healthSpawners_.clear(); 52 damageSpawners_.clear(); 53 speedSpawners_.clear(); 51 54 52 this->bTakenOver_ = false; 55 53 this->action_ = Action::NONE; … … 96 94 parsedActionpoints_.clear(); 97 95 actionpoints_.clear(); 98 healthSpawners_.clear();99 damageSpawners_.clear();100 speedSpawners_.clear();96 ActionpointController::nextActionpointControllerId_--; 97 if (ActionpointController::nextActionpointControllerId_ < 0) 98 ActionpointController::nextActionpointControllerId_ = 0; 101 99 } 102 100 void ActionpointController::tick(float dt) 103 101 { 104 if (!this->getControllableEntity()) 105 return; 102 if (!this || !this->getControllableEntity()) 103 return; 104 ++this->ticks_; 105 // orxout (internal_error) << "this id = " << this->actionpointControllerId_ << endl; 106 if (ActionpointController::sTicks_ < this->ticks_) 107 { 108 // orxout (internal_error) << "total id's = " << ActionpointController::nextActionpointControllerId_ << endl; 109 ++ActionpointController::sTicks_; 110 } 111 112 if (this->ticks_ == 1) 113 { 114 115 this->actionpointControllerId_ = ActionpointController::nextActionpointControllerId_++; 116 std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end()); 117 std::reverse(actionpoints_.begin(), actionpoints_.end()); 118 if (this->parsedActionpoints_.empty()) 119 { 120 this->action_ = Action::FIGHTALL; 121 } 122 } 123 if (this->ticks_ == 1) 124 { 125 this->timeOffset_ = 0.0f; 126 this->bActionCalled_ = false; 127 128 this->bFirstTick_ = false; 129 } 130 /* if (ActionpointController::sTicks_ % (ActionpointController::nextActionpointControllerId_+1) != this->actionpointControllerId_) 131 { 132 return; 133 }*/ 134 if (!this || !this->getControllableEntity()) 135 return; 136 137 if (this->bHasTargetPosition_) 138 { 139 this->moveToTargetPosition(dt); 140 } 141 else if (this->bLookAtTarget_) 142 { 143 this->lookAtTarget(dt); 144 } 145 if (this->bShooting_) 146 { 147 this->doFire(); 148 } 149 150 if (!this || !this->getControllableEntity()) 151 return; 152 106 153 if (stop_) 107 154 return; 108 if (this->timeout_ > 0 && this->bFiredRocket_) 109 { 110 this->timeout_ -= dt; 111 } 112 if (this->bStartedDodging_) 113 { 114 this->timeDodged_ += dt; 115 if (this->timeDodged_ > 4.0f) 116 { 117 this->bStartedDodging_ = false; 118 this->timeDodged_ = 0; 119 } 120 } 121 maneuverCounter_ += dt; 122 if (maneuverCounter_ > 6.0f) 123 maneuverCounter_ = 0; 155 124 156 this->timeOffset_ += dt; 125 157 if (this->timeOffset_ >= 2.4f) … … 127 159 if (timeout_ <= 0) 128 160 this->bFiredRocket_ = false; 129 130 if (this->bHasTargetPosition_) 131 { 132 this->moveToTargetPosition(dt); 133 } 134 else if (this->bLookAtTarget_) 135 { 136 this->lookAtTarget(dt); 137 } 138 139 if (!this->getControllableEntity()) 140 return; 141 if (this->bShooting_) 142 { 143 this->doFire(); 144 } 145 if (this->bFirstTick_) 146 { 147 std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end()); 148 std::reverse(actionpoints_.begin(), actionpoints_.end()); 149 if (this->parsedActionpoints_.empty()) 150 { 151 this->action_ = Action::FIGHTALL; 152 } 153 } 154 if (this->bFirstTick_) 155 { 156 this->timeOffset_ = 0.0f; 157 this->bActionCalled_ = false; 158 setSpawners(); 159 // orxout(internal_error) << "health spawners size = " << this->healthSpawners_.size() << 160 // ", damage spawners size = " << this->damageSpawners_.size() << 161 // ", speed spawners size = " << this->speedSpawners_.size() << endl; 162 this->bFirstTick_ = false; 163 } 164 if (!this->getControllableEntity()) 165 return; 161 if (!this || !this->getControllableEntity()) 162 return; 163 164 if (!this || !this->getControllableEntity()) 165 return; 166 if (this->timeout_ > 0 && this->bFiredRocket_) 167 { 168 this->timeout_ -= dt; 169 } 170 if (this->bStartedDodging_) 171 { 172 this->timeDodged_ += dt; 173 } 174 maneuverCounter_ += dt; 175 166 176 //maneuver every 0.25 sec -> 167 if (this->hasTarget() && 168 ((this->timeOffset_ >= 0.4f && this->timeOffset_ < 0.8f) || 169 (this->timeOffset_ >= 1.2f && this->timeOffset_ < 1.6f) || 170 (this->timeOffset_ >= 1.8f && this->timeOffset_ < 2.0f) || 171 (this->timeOffset_ >= 2.2f && this->timeOffset_ < 2.4f)) && !this->bManeuverCalled_) 172 { 173 this->bManeuverCalled_ = true; 177 int step = 5; 178 if (this->hasTarget() && ActionpointController::sTicks_ % 100 == step * (this->actionpointControllerId_) + 3) 179 { 180 if (maneuverCounter_ > 6.0f) 181 maneuverCounter_ = 0; 182 if (this->bStartedDodging_ && this->timeDodged_ > 4.0f) 183 { 184 this->bStartedDodging_ = false; 185 this->timeDodged_ = 0; 186 } 174 187 this->maneuver(); 188 } 189 if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1) 190 { 191 this->action(); 192 } 193 if (!this || !this->getControllableEntity()) 194 return; 195 196 if (!this || !this->getControllableEntity()) 197 return; 198 if (this->hasTarget() && ActionpointController::sTicks_ % 100 == step * (this->actionpointControllerId_)) 199 { 175 200 this->bShooting_ = this->canFire(); 176 }177 if ((this->timeOffset_ >= 0.0f && this->timeOffset_ < 0.4f) ||178 (this->timeOffset_ >= 0.8f && this->timeOffset_ < 1.2f) ||179 (this->timeOffset_ >= 1.6f && this->timeOffset_ < 1.8f) ||180 (this->timeOffset_ >= 2.0f && this->timeOffset_ < 2.2f))181 this->bManeuverCalled_ = false; 201 202 } 203 if (!this || !this->getControllableEntity()) 204 return; 205 206 182 207 SUPER(ActionpointController, tick, dt); 183 208 } … … 195 220 this->startAttackingEnemiesThatAreClose(); 196 221 } 222 if (!this || !this->getControllableEntity()) 223 return; 224 197 225 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; 198 226 this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth(); 227 if (!this || !this->getControllableEntity()) 228 return; 199 229 200 230 // if (this->actionCounter_ % 2 == 0) … … 202 232 if (this->action_ == Action::NONE || this->bTakenOver_) 203 233 { 204 // Point point = closestPickup(PickupType::HEALTH);205 // if (point.action != Action::NONE)206 // {207 // orxout(internal_error) << "found health" << endl;208 // this->parsedActionpoints_.push_back(point);209 // }210 211 234 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_) 212 235 { … … 218 241 // this->action(); 219 242 } 243 if (!this || !this->getControllableEntity()) 244 return; 245 220 246 //Action fightall -> fight till nobody alive 221 247 if (this->action_ == Action::FIGHTALL) … … 307 333 } 308 334 309 // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());310 // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)311 // {312 // //----choose where to go----313 // this->maneuver();314 // }315 // else316 // {317 // this->dodgeTowards(healthPosition);318 // }319 // //----fire if you can----320 // this->bShooting_ = this->canFire();321 322 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;323 335 324 336 } … … 402 414 { 403 415 case Action::FIGHT: 404 { return "FIGHT"; break;}416 { return "FIGHT"; } 405 417 case Action::FLY: 406 { return "FLY"; break;}418 { return "FLY"; } 407 419 case Action::PROTECT: 408 { return "PROTECT"; break;}420 { return "PROTECT"; } 409 421 case Action::NONE: 410 { return "NONE"; break;}422 { return "NONE"; } 411 423 case Action::FIGHTALL: 412 { return "FIGHTALL"; break;}424 { return "FIGHTALL"; } 413 425 case Action::ATTACK: 414 { return "ATTACK"; break;}426 { return "ATTACK"; } 415 427 default: 416 428 return "NONE"; … … 462 474 void ActionpointController::executeActionpoint() 463 475 { 476 if (!this || !this->getControllableEntity()) 477 return; 478 464 479 Point p; 465 480 if (this->bLoop_ && !loopActionpoints_.empty()) … … 478 493 else 479 494 { 495 if (!this || !this->getControllableEntity()) 496 return; 497 480 498 this->setTarget(0); 481 499 this->setTargetPosition(this->getControllableEntity()->getWorldPosition()); … … 520 538 case Action::PROTECT: 521 539 { 522 540 if (!this || !this->getControllableEntity()) 541 return; 542 523 543 std::string protectName = p.name; 524 544 if (protectName == "reservedKeyword:human") … … 583 603 void ActionpointController::stayNearProtect() 584 604 { 605 if (!this || !this->getControllableEntity()) 606 return; 607 585 608 Vector3 targetRelativePosition(0, 300, 300); 586 609 if (!this->getProtect()) … … 665 688 Pawn* ActionpointController::closestTarget() 666 689 { 667 if (!this ->getControllableEntity())690 if (!this || !this->getControllableEntity()) 668 691 return 0; 669 692 … … 691 714 void ActionpointController::startAttackingEnemiesThatAreClose() 692 715 { 716 if (!this || !this->getControllableEntity()) 717 return; 718 693 719 //if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) 694 720 { … … 700 726 <= this->attackRange_ ) 701 727 { 728 if (!this || !this->getControllableEntity()) 729 return; 702 730 this->setTarget(newTarget); 703 731 if (this->bLoop_ && !this->bPatrolling_) … … 718 746 } 719 747 } 720 Vector3 ActionpointController::bestHealthPickup(float searchRadius) 721 { 722 723 //1000000/distance^2 * 1/index+1 724 float maxUse = 0; 725 float tempUse = -1; 726 int index = 0; 727 float distance = 0; 728 Vector3 bestPosition = this->getControllableEntity()->getWorldPosition(); 729 730 for (std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it=healthSpawners_.begin(); it!=healthSpawners_.end(); ++it) 731 { 732 distance = (this->getControllableEntity()->getWorldPosition() - (*it).second.first->getWorldPosition()).length(); 733 if (distance < this->tolerance_ || !(*it).second.second) 734 { 735 (*it).second.second = false; 736 continue; 737 } 738 if (distance > searchRadius) 739 continue; 740 index = (*it).first; 741 tempUse = 1000000*1/(1+distance*distance) * 1/((index/2.0f)+1); 742 if (tempUse > maxUse) 743 { 744 bestPosition = (*it).second.first->getWorldPosition(); 745 maxUse = tempUse; 746 } 747 } 748 //std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it = this->healthSpawners_.find(index); 749 //P.S. check if it == ... .end() 750 //orxout (internal_error) << "best position = " << bestPosition << endl; 751 return bestPosition; 752 } 753 void ActionpointController::setSpawners() 754 { 755 std::vector<std::string> damagePickups; 756 std::vector<std::string> healthPickups; 757 std::vector<std::string> speedPickups; 758 int index = 0; 759 760 761 damagePickups.push_back("largedamageboostpickup"); 762 damagePickups.push_back("dronepickup"); 763 damagePickups.push_back("mediumdamageboostpickup"); 764 damagePickups.push_back("smalldamageboostpickup"); 765 766 healthPickups.push_back("triplehealthspeedinvisibilitypickup"); 767 healthPickups.push_back("crazyhealthpickup"); 768 healthPickups.push_back("hugehealthpickup"); 769 healthPickups.push_back("hugeshieldpickup"); 770 healthPickups.push_back("hugeinvisiblepickup"); 771 healthPickups.push_back("hugeshrinkpickup"); 772 healthPickups.push_back("mediumhealthpickup"); 773 healthPickups.push_back("mediumshieldpickup"); 774 healthPickups.push_back("mediuminvisiblepickup"); 775 healthPickups.push_back("mediumshrinkpickup"); 776 healthPickups.push_back("smallhealthpickup"); 777 healthPickups.push_back("smallshieldpickup"); 778 healthPickups.push_back("smallinvisiblepickup"); 779 healthPickups.push_back("smallshrinkpickup"); 780 781 speedPickups.push_back("triplehealthspeedinvisibilitypickup"); 782 speedPickups.push_back("hugespeedpickup"); 783 speedPickups.push_back("smalljumppickup"); 784 speedPickups.push_back("mediumspeedpickup"); 785 speedPickups.push_back("smallspeedpickup"); 786 787 788 789 for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it; ++it) 790 { 791 if ((*it)->getIdentifier()->getName() != "PickupSpawner") 792 continue; 793 PickupSpawner* spawner = static_cast<PickupSpawner*>(*it); 794 std::string name = spawner->getPickupTemplateName(); 795 //float distance = ((*it)->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length(); 796 // if (distance < 50.0f) 797 // continue; 798 for (unsigned int i = 0; i < healthPickups.size(); ++i) 799 { 800 if (name == healthPickups.at(i)) 801 { 802 index = i; 803 this->healthSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true))); 804 break; 805 } 806 } 807 for (unsigned int i = 0; i < damagePickups.size(); ++i) 808 { 809 if (name == damagePickups.at(i)) 810 { 811 //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1); 812 index = i; 813 this->damageSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true))); 814 break; 815 } 816 } 817 for (unsigned int i = 0; i < speedPickups.size(); ++i) 818 { 819 if (name == speedPickups.at(i)) 820 { 821 //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1); 822 index = i; 823 this->speedSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true))); 824 break; 825 } 826 } 827 // if (tempUse > maxUse) 828 // { 829 // Point p = { Action::FLY, "", (*it)->getWorldPosition(), false }; 830 // maxUse = tempUse; 831 // maxPoint = p; 832 // } 833 // else 834 // { 835 // tempUse = -1; 836 // continue; 837 // } 838 // orxout(internal_error) << "resp time = " << static_cast<PickupSpawner*>(*it)->getRespawnTime() << endl; 839 } 840 } 841 } 748 int ActionpointController::nextActionpointControllerId_ = 0; 749 int ActionpointController::sTicks_ = 0; 750 } -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
r10915 r10923 35 35 #include "../modules/pickup/PickupSpawner.h" 36 36 #include <map> 37 38 37 39 38 … … 246 245 bool bFirstTick_; 247 246 248 void setSpawners();247 /* void setSpawners(); 249 248 Vector3 bestHealthPickup (float searchRadius); 250 249 // Point closestPickup(PickupType::Value pickupType); … … 252 251 std::multimap <int, std::pair<PickupSpawner*, bool> > damageSpawners_; 253 252 std::multimap <int, std::pair<PickupSpawner*, bool> > speedSpawners_; 254 253 */ 255 254 float timeOffset_; 256 255 bool bActionCalled_; … … 262 261 bool bDefaultPatrol_; 263 262 bool stop_; 263 static int sTicks_; 264 static int nextActionpointControllerId_; 265 int actionpointControllerId_; 266 int ticks_; 267 264 268 265 269 private: -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10915 r10923 68 68 return; 69 69 SUPER(DivisionController, tick, dt); 70 if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_)70 /*if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_) 71 71 { 72 72 this->action(); … … 76 76 { 77 77 this->bActionCalled_ = false; 78 } 78 }*/ 79 79 80 80 -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10906 r10923 63 63 void FightingController::lookAtTarget(float dt) 64 64 { 65 if (!this || !this->getControllableEntity()) 66 return; 65 67 ControllableEntity* entity = this->getControllableEntity(); 66 68 if ( !entity ) … … 126 128 float diffLength = diffVector.length(); 127 129 Vector3 diffUnit = diffVector/diffLength; 128 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f) 129 || this->deltaHp < 0; 130 131 if (!this || !this->getControllableEntity()) 132 return; 130 133 131 134 //too far? well, come closer then … … 139 142 } 140 143 else 141 { 144 { 145 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f) 146 || this->deltaHp < 0; 142 147 this->bKeepFormation_ = false; 148 149 if (!this || !this->getControllableEntity()) 150 return; 143 151 // if (this->actionCounter_ % 3 == 0) 144 152 if (maneuverCounter_ <= 1.2) … … 173 181 } 174 182 } 175 /*//too close? How do u expect to dodge anything? Just attack! 176 else if (diffLength < 1000) 177 { 178 this->bKeepFormation_ = false; 179 180 //at this point, just look and shoot 181 if (diffLength < 1000) 182 { 183 this->stopMoving(); 184 this->startLookingAtTarget(); 185 186 } 187 else 188 { 189 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 300.0f); 190 } 191 } 192 //Good distance? Check if target looks at us. It doesn't? Go hunt! 193 else if (!bTargetIsLookingAtThis) 194 { 195 this->bKeepFormation_ = false; 196 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f); 197 } 198 //That's unfortunate, he is looking and probably shooting... try to dodge what we can... 199 else 200 { 201 this->bKeepFormation_ = false; 202 if (maneuverCounter_ == 0) 203 { 204 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f); 205 return; 206 } 207 if (this->actionCounter_ % 3 == 0) 208 dodge(thisPosition, diffLength, diffUnit); 209 }*/ 210 } 211 void FightingController::dodgeTowards (Vector3& position) 212 { 213 Vector3 thisPosition = this->getControllableEntity()->getPosition(); 214 Vector3 diff = (position - thisPosition); 215 float diffLength = diff.length(); 216 Vector3 diffUnit = diff/diffLength; 217 float factor = 300.0f; 218 if (diffLength < 300) 219 { 220 this->setTargetPosition(position); 221 return; 222 } 223 else if (diffLength < 600) 224 factor = 400.0f; 225 else if (diffLength < 1000) 226 factor = 700.0f; 227 else 228 factor = 1000.0f; 229 float x = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 230 float y = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 231 float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y); 232 this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * factor); 233 // orxout(internal_error) << "Dodging towards " << Vector3(x,y,z) << endl; 234 this->boostControl(); 235 } 183 } 184 236 185 void FightingController::dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit) 237 186 { … … 257 206 { 258 207 //no target? why fire? 259 if (!this->target_ )208 if (!this->target_ || !this->getControllableEntity()) 260 209 return false; 261 210 Vector3 newPositionOfTarget = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), … … 274 223 float FightingController::squaredDistanceToTarget() const 275 224 { 276 if (!this ->getControllableEntity())225 if (!this || !this->getControllableEntity()) 277 226 return 0; 278 227 if (!this->target_ || !this->getControllableEntity()) … … 294 243 Pawn* FightingController::closestTarget() const 295 244 { 296 if (!this ->getControllableEntity())245 if (!this || !this->getControllableEntity()) 297 246 return 0; 298 247 -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
r10888 r10923 24 24 25 25 * Co-authors: 26 * Dominik Solenicki26 * ... 27 27 * 28 28 */ … … 46 46 FlyingController::~FlyingController() 47 47 { 48 49 48 } 50 49 … … 76 75 { 77 76 case FormationMode::WALL: 78 { return "WALL"; break;}77 { return "WALL"; } 79 78 case FormationMode::FINGER4: 80 { return "FINGER4"; break;}79 { return "FINGER4"; } 81 80 case FormationMode::DIAMOND: 82 { return "DIAMOND"; break;}81 { return "DIAMOND"; } 83 82 default: 84 return "DIAMOND"; break;83 return "DIAMOND"; 85 84 } 86 85 } … … 89 88 this->bHasTargetPosition_ = false; 90 89 } 91 void FlyingController::moveToPosition(const Vector3& target, float dt) 92 { 90 void FlyingController::moveToPosition(const Vector3& targetPosition, float dt) 91 { 92 if (!this->getControllableEntity()) 93 return; 93 94 ControllableEntity* entity = this->getControllableEntity(); 94 95 95 float distance = ( target - entity->getPosition() ).length();96 float distance = ( targetPosition - entity->getPosition() ).length(); 96 97 97 98 if ( distance >= this->tolerance_ ) … … 101 102 entity->getOrientation() * WorldEntity::FRONT, 102 103 entity->getOrientation() * WorldEntity::UP, 103 target );104 targetPosition ); 104 105 float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f ); 105 106 float rotateY = clamp( coord.y * 10, -1.0f, 1.0f ); … … 107 108 entity->rotatePitch( ROTATEFACTOR * rotateY * dt ); 108 109 109 if (distance > this->tolerance_*1.5f || (rotateX > -0.0 1 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))110 if (distance > this->tolerance_*1.5f || (rotateX > -0.03 && rotateX < 0.03 && rotateY > -0.03 && rotateY < 0.03)) 110 111 entity->moveFrontBack( SPEED * dt ); 111 112 copyTargetOrientation(dt); … … 123 124 void FlyingController::copyOrientation(const Quaternion& orient, float dt) 124 125 { 125 // inspired by126 //copied from 126 127 //http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Quaternion+and+Rotation+Primer&structure=Tutorials#Q._How_can_I_make_my_objects_rotate_smoothly_You_mentioned_slerp_etc_ 127 128 //how can I make my objects rotate smoothly? 128 129 if (!this->getControllableEntity()) 130 return; 129 131 Quaternion myOrient = this->getControllableEntity()->getOrientation(); 130 132 this->rotationProgress_ += dt; … … 137 139 else 138 140 { 139 140 Quaternion delta = Quaternion::Slerp(rotationProgress_, myOrient, orient, true); 141 Quaternion deltaOrientation = Quaternion::Slerp(rotationProgress_, myOrient, orient, true); 141 142 142 //rotate roll builds a Quaternion in roll method of WorldEntity, then it sets orientation. 143 //it is faster just to set orientation, plus that way there is no need in calculating the roll angle. 144 //On the downside, however, ship might also yaw and pitch, but this effect is neglectable, as we only call 145 //copyOrientation after we move our ship, thus it doesn't affect ships's flying direction too much. 146 //If you don't like the code style, you are welcomed to uncomment the code below 147 //and comment out setOrientation part, it will work just fine, but it will also be a tiny bit slower. 148 //P.S. apperantly it did affect ship's direction and did so way too much. 149 Matrix3 orientMatrix, myMatrix; 150 151 delta.ToRotationMatrix(orientMatrix); 143 Matrix3 deltaMatrix, myMatrix; 144 145 deltaOrientation.ToRotationMatrix(deltaMatrix); 152 146 myOrient.ToRotationMatrix (myMatrix); 153 147 154 Radian yRad, pRad, rRad, yMy, pMy, rMy; 155 orientMatrix.ToEulerAnglesYXZ(yRad, pRad, rRad); 156 myMatrix.ToEulerAnglesYXZ (yMy, pMy, rMy); 157 158 this->getControllableEntity()->rotateRoll ((rRad.valueRadians() - rMy.valueRadians())*ROTATEFACTOR*dt); 159 // this->getControllableEntity()->setOrientation(delta); 160 } 161 162 163 } 164 //change log: increased precision, increased rotation speed 148 Radian yawDelta, pitchDelta, rollDelta, yawMy, pitchMy, rollMy; 149 deltaMatrix.ToEulerAnglesYXZ(yawDelta, pitchDelta, rollDelta); 150 myMatrix.ToEulerAnglesYXZ (yawMy, pitchMy, rollMy); 151 152 if (!this->getControllableEntity()) 153 return; 154 this->getControllableEntity()->rotateRoll ((rollDelta.valueRadians() - rollMy.valueRadians())*ROTATEFACTOR*dt); 155 } 156 } 157 165 158 void FlyingController::copyTargetOrientation(float dt) 166 159 { 167 160 if (bHasTargetOrientation_) 168 161 { 169 copyOrientation(targetOrientation_, dt);162 this->copyOrientation(targetOrientation_, dt); 170 163 } 171 164 } … … 186 179 { 187 180 if (target) 188 setTargetOrientation(target->getOrientation());181 this->setTargetOrientation(target->getOrientation()); 189 182 } 190 183 void FlyingController::boostControl() 191 184 { 185 if (!this->getControllableEntity()) 186 return; 192 187 SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity()); 193 188 if(ship == NULL) return; … … 221 216 + (orient* (targetRelativePosition))); 222 217 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function. 223 if ( this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)218 if (static_cast<int>(rnd(1.0f) * 100) % 3 == 0) 224 219 this->setTargetOrientation (orient); 225 220 this->setTargetPosition (targetAbsolutePosition); -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
r10898 r10923 85 85 virtual void boostControl(); 86 86 void keepFormation (const ControllableEntity* leaderEntity, Vector3& targetRelativePosition); 87 87 88 FormationMode::Value formationMode_; 88 89 89 float rotationProgress_; 90 int actionCounter_; 90 float rotationProgress_; //<! for slerp 91 91 bool bHasTargetPosition_; 92 92 Vector3 targetPosition_; -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10915 r10923 74 74 75 75 SUPER(SectionController, tick, dt); 76 if (this->timeOffset_ > 0.8f && this->timeOffset_ <= 1.6f && !this->bActionCalled_)76 /*if (this->timeOffset_ > 0.8f && this->timeOffset_ <= 1.6f && !this->bActionCalled_) 77 77 { 78 78 this->action(); … … 82 82 { 83 83 this->bActionCalled_ = false; 84 } 84 }*/ 85 85 86 86 } … … 97 97 this->myDivisionLeader_ = newDivisionLeader; 98 98 //spread copyOrientation called equally among the division 99 if (this->myDivisionLeader_) 100 { 101 this->actionCounter_ = 5; 102 } 99 103 100 } 104 101 //----If have leader---- … … 156 153 } 157 154 158 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;159 155 } 160 156 … … 166 162 //----If division leader fights, cover him by fighting emenies close to his target---- 167 163 Action::Value action = this->myDivisionLeader_->getAction(); 168 169 Pawn* target; 164 170 165 if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK) 171 166 { 167 Pawn* target; 172 168 //----if he has a target---- 173 169 if (this->myDivisionLeader_->hasTarget()) … … 177 173 !( this->hasTarget() && this->getTarget() != this->myDivisionLeader_->getTarget() ) ) 178 174 { 179 180 175 bool foundTarget = false; 181 176 //----new target should be close to division's target---- -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10915 r10923 70 70 if (!this->myLeader_) 71 71 { 72 if (this->actionTime_ == 2.0f)72 /*if (this->actionTime_ == 2.0f) 73 73 { 74 74 if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_) … … 93 93 this->bActionCalled_ = false; 94 94 } 95 } 95 }*/ 96 96 } 97 97 else 98 98 { 99 if (this->timeOffset_ >= this->actionTime_ && this->timeOffset_ <= this->actionTime_ + 0.4f && !this->bActionCalled_)99 /* if (this->timeOffset_ >= this->actionTime_ && this->timeOffset_ <= this->actionTime_ + 0.4f && !this->bActionCalled_) 100 100 { 101 101 this->action(); … … 105 105 { 106 106 this->bActionCalled_ = false; 107 } 107 }*/ 108 108 } 109 109 … … 114 114 void WingmanController::action() 115 115 { 116 116 if (!this || !this->getControllableEntity()) 117 return; 117 118 //----If no leader, find one---- 118 119 if (!this->myLeader_) … … 122 123 if (this->myLeader_) 123 124 { 124 //spread copyOrientation called equally among the division 125 if (this->myLeader_->getIdentifier()->getName() == "SectionController") 126 this->actionCounter_ = 1; 127 else 128 this->actionCounter_ = 4; 125 129 126 } 130 127 } … … 137 134 { 138 135 ActionpointController::action(); 136 if (!this || !this->getControllableEntity()) 137 return; 138 139 139 } 140 140 else if (this->myLeader_) … … 170 170 } 171 171 } 172 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;173 172 } 174 173
Note: See TracChangeset
for help on using the changeset viewer.