Changeset 10854
- Timestamp:
- Nov 25, 2015, 12:07:22 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10851 r10854 67 67 </templates> 68 68 <controller> 69 <DivisionController team=0 >69 <DivisionController team=0 formationMode="finger4"> 70 70 <actionpoints> 71 <Actionpoint position=" -1000,750,-500" action="FLY" />71 <Actionpoint position="0,0,0" action="FLY" /> 72 72 <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" /> 73 73 <Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" /> … … 76 76 </controller> 77 77 </SpaceShip> 78 <SpaceShip position="-2000, 1800, -1000" lookat="0,0,0" team=0> 79 <templates> 80 <Template link=spaceshipassff /> 81 </templates> 82 <controller> 83 <WingmanController team=0> 84 </WingmanController> 85 </controller> 86 </SpaceShip> 87 <SpaceShip position="-2000, 2100, -1000" lookat="0,0,0" team=0> 88 <templates> 89 <Template link=spaceshipassff /> 90 </templates> 91 <controller> 92 <WingmanController team=0> 93 </WingmanController> 94 </controller> 95 </SpaceShip> 96 <SpaceShip position="-2000, 2400, -1000" lookat="0,0,0" team=0> 78 <SpaceShip position="-2000, 1900, -1000" lookat="0,0,0" team=0> 97 79 <templates> 98 80 <Template link=spaceshipassff /> -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10851 r10854 65 65 this->squaredaccuracy_ = 10000; 66 66 this->bFirstTick_ = true; 67 this->tolerance_ = 65;67 this->tolerance_ = 50; 68 68 this->action_ = Action::NONE; 69 69 this->stopLookingAtTarget(); … … 73 73 CommonController::~CommonController() 74 74 { 75 for (size_t i = 0; i < this->actionpoints_.size(); ++i) 76 { 77 if(this->actionpoints_[i]) 78 this->actionpoints_[i]->destroy(); 79 } 80 this->parsedActionpoints_.clear(); 81 this->actionpoints_.clear(); 75 82 76 } 83 77 void CommonController::tick(float dt) … … 492 486 } 493 487 } 494 if (distance > 200 || (rotateX > -0.1 && rotateX < 0.1 && rotateY > -0.1 && rotateY < 0.1))488 if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01)) 495 489 this->getControllableEntity() ->moveFrontBack( SPEED * dt ); 496 490 } … … 746 740 return 0; 747 741 } 748 boolCommonController::startAttackingEnemiesThatAreClose()742 void CommonController::startAttackingEnemiesThatAreClose() 749 743 { 750 744 if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) … … 761 755 this->parsedActionpoints_.push_back(p); 762 756 this->executeActionpoint(); 763 return true; 764 } 765 } 766 } 767 return false; 757 } 758 } 759 } 768 760 } 769 761 … … 783 775 { 784 776 case Action::FIGHT: 785 { 777 { 778 std::string targetName = this->parsedActionpoints_.back().name; 779 if (targetName == "") 780 { 781 break; 782 } 783 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 784 { 785 if (CommonController::getName(*itP) == targetName) 786 { 787 this->setTarget (static_cast<ControllableEntity*>(*itP)); 788 } 789 } 786 790 break; 787 791 } … … 851 855 } 852 856 } 857 void CommonController::stayNearProtect() 858 { 859 Vector3* targetRelativePosition; 860 targetRelativePosition = new Vector3 (0, 300, 300); 861 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 862 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition))); 863 this->setTargetPosition(targetAbsolutePosition); 864 } 853 865 void CommonController::nextActionpoint() 854 866 { … … 859 871 this->setAction(Action::NONE); 860 872 } 873 void CommonController::action() 874 { 875 this->startAttackingEnemiesThatAreClose(); 876 //No action -> pop one from stack 877 if (this->action_ == Action::NONE) 878 { 879 this->executeActionpoint(); 880 } 881 //Action fightall -> fight till nobody alive 882 if (this->action_ == Action::FIGHTALL) 883 { 884 if (!this->hasTarget()) 885 { 886 //----find a target---- 887 ControllableEntity* newTarget = this->closestTarget(); 888 if (newTarget) 889 { 890 this->setAction (Action::FIGHTALL, newTarget); 891 } 892 else 893 { 894 this->nextActionpoint(); 895 return; 896 } 897 } 898 else if (this->hasTarget()) 899 { 900 901 } 902 } 903 //Action fight -> fight as long as enemies in range 904 else if (this->action_ == Action::FIGHT) 905 { 906 if (!this->hasTarget()) 907 { 908 //----find a target---- 909 ControllableEntity* newTarget = this->closestTarget(); 910 if (newTarget && 911 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 912 { 913 this->setAction (Action::FIGHT, newTarget); 914 } 915 else 916 { 917 this->nextActionpoint(); 918 return; 919 } 920 } 921 else if (this->hasTarget()) 922 { 923 //----fly in formation if far enough---- 924 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 925 926 if (diffVector.length() > this->attackRange_) 927 { 928 ControllableEntity* newTarget = this->closestTarget(); 929 930 if (newTarget && 931 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 932 { 933 this->setAction (Action::FIGHT, newTarget); 934 } 935 else 936 { 937 this->nextActionpoint(); 938 return; 939 } 940 } 941 } 942 } 943 else if (this->action_ == Action::FLY) 944 { 945 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 946 { 947 this->nextActionpoint(); 948 return; 949 } 950 } 951 else if (this->action_ == Action::PROTECT) 952 { 953 if (!this->getProtect()) 954 { 955 this->nextActionpoint(); 956 return; 957 } 958 this->stayNearProtect(); 959 } 960 else if (this->action_ == Action::ATTACK) 961 { 962 if (!this->hasTarget()) 963 { 964 this->nextActionpoint(); 965 return; 966 } 967 } 968 if (this->hasTarget()) 969 { 970 //----choose where to go---- 971 this->maneuver(); 972 //----fire if you can---- 973 this->bShooting_ = this->canFire(); 974 } 975 } 861 976 } -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10851 r10854 41 41 #include <algorithm> 42 42 #include "worldentities/Actionpoint.h" 43 #include "worldentities/pawns/SpaceShip.h" 43 44 44 45 namespace orxonox … … 133 134 //----[/Helper methods]---- 134 135 135 //----[Actionpoint information]---- 136 137 std::vector<WeakPtr<WorldEntity> > actionpoints_; 138 float squaredaccuracy_; 139 std::vector<Point > parsedActionpoints_; 140 141 //----[/Actionpoint information]---- 142 //----[Actionpoint methods]---- 143 void executeActionpoint(); 144 void nextActionpoint(); 145 //----[Actionpoint methods]---- 136 137 virtual void stayNearProtect(); 138 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 139 146 140 protected: 147 141 //----[Flying methods]---- … … 180 174 void setClosestTarget(); 181 175 Pawn* closestTarget(); 182 boolstartAttackingEnemiesThatAreClose();176 void startAttackingEnemiesThatAreClose(); 183 177 //----[/Fighting methods]---- 184 178 … … 203 197 //----[/who-to-kill information]---- 204 198 205 199 //----[Actionpoint information]---- 200 201 std::vector<WeakPtr<WorldEntity> > actionpoints_; 202 float squaredaccuracy_; 203 std::vector<Point > parsedActionpoints_; 204 205 //----[/Actionpoint information]---- 206 //----[Actionpoint methods]---- 207 void executeActionpoint(); 208 void nextActionpoint(); 209 //----[Actionpoint methods]---- 206 210 //----["Private" variables]---- 207 211 FormationMode::Value formationMode_; -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10851 r10854 50 50 DivisionController::~DivisionController() 51 51 { 52 if (this->myFollower_) 53 { 54 this->myFollower_->takeActionpoints(this->parsedActionpoints_); 55 } 56 for (size_t i = 0; i < this->actionpoints_.size(); ++i) 57 { 58 if(this->actionpoints_[i]) 59 this->actionpoints_[i]->destroy(); 60 } 61 this->parsedActionpoints_.clear(); 62 this->actionpoints_.clear(); 52 63 } 53 64 … … 65 76 } 66 77 void DivisionController::action() 67 { 68 if (this->startAttackingEnemiesThatAreClose()) 69 { 70 Point p = { Action::FIGHT, "", Vector3::ZERO }; 71 72 if (this->myWingman_) 73 { 74 this->myWingman_->parsedActionpoints_.push_back(p); 75 } 76 if (this->myFollower_) 77 { 78 this->myFollower_->parsedActionpoints_.push_back(p); 79 } 80 } 81 82 if (this->action_ == Action::NONE) 83 { 84 this->executeActionpoint(); 85 } 86 if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL) 87 { 88 if (!this->hasTarget()) 89 { 90 //----find a target---- 91 ControllableEntity* newTarget = this->closestTarget(); 92 if (this->action_ == Action::FIGHT) 93 { 94 if (newTarget && 95 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 96 { 97 this->setAction (Action::FIGHT, newTarget); 98 } 99 else 100 { 101 this->nextActionpoint(); 102 if (this->myWingman_) 103 { 104 this->myWingman_->nextActionpoint(); 105 } 106 if (this->myFollower_) 107 { 108 this->myFollower_->nextActionpoint(); 109 } 110 return; 111 } 112 } 113 else if (this->action_ == Action::FIGHTALL) 114 { 115 if (newTarget && newTarget->getController()) 116 { 117 this->setAction (Action::FIGHTALL, newTarget); 118 } 119 else 120 { 121 this->nextActionpoint(); 122 if (this->myWingman_) 123 { 124 this->myWingman_->nextActionpoint(); 125 } 126 if (this->myFollower_) 127 { 128 this->myFollower_->nextActionpoint(); 129 } 130 return; 131 } 132 } 133 134 } 135 else if (this->hasTarget()) 136 { 137 //----fly in formation if far enough---- 138 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 139 140 if (diffVector.length() > this->attackRange_) 141 { 142 if (this->action_ == Action::FIGHT) 143 { 144 this->nextActionpoint(); 145 if (this->myWingman_) 146 { 147 this->myWingman_->nextActionpoint(); 148 } 149 if (this->myFollower_) 150 { 151 this->myFollower_->nextActionpoint(); 152 } 153 return; 154 } 155 else 156 { 157 this->setTargetPositionOfWingman(); 158 this->setTargetPositionOfFollower(); 159 } 160 } 161 else 162 { 163 //----wingmans shall support the fire of their leaders---- 164 if (this->myWingman_) 165 { 166 this->myWingman_->setAction (Action::FIGHT, this->target_); 167 } 168 if (this->myFollower_) 169 { 170 this->myFollower_->setAction (Action::FIGHT); 171 } 172 } 173 } 174 } 175 else if (this->action_ == Action::FLY) 176 { 177 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 178 { 179 this->nextActionpoint(); 180 if (this->myWingman_) 181 { 182 this->myWingman_->nextActionpoint(); 183 } 184 if (this->myFollower_) 185 { 186 this->myFollower_->nextActionpoint(); 187 } 188 return; 189 } 190 this->setTargetPositionOfWingman(); 191 this->setTargetPositionOfFollower(); 192 } 193 else if (this->action_ == Action::PROTECT) 194 { 195 if (!this->getProtect()) 196 { 197 this->nextActionpoint(); 198 if (this->myWingman_) 199 { 200 this->myWingman_->nextActionpoint(); 201 } 202 if (this->myFollower_) 203 { 204 this->myFollower_->nextActionpoint(); 205 } 206 return; 207 } 208 209 Vector3* targetRelativePosition; 210 211 targetRelativePosition = new Vector3 (0, 300, 300); 212 213 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 214 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition))); 215 this->setTargetPosition(targetAbsolutePosition); 216 217 this->setTargetPositionOfWingman(); 218 this->setTargetPositionOfFollower(); 219 220 } 221 else if (this->action_ == Action::ATTACK) 222 { 223 if (!this->hasTarget()) 224 { 225 this->nextActionpoint(); 226 if (this->myWingman_) 227 { 228 this->myWingman_->nextActionpoint(); 229 } 230 if (this->myFollower_) 231 { 232 this->myFollower_->nextActionpoint(); 233 } 234 return; 235 } 236 //----fly in formation if far enough---- 237 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 238 if (diffVector.length() > this->attackRange_) 239 { 240 this->setTargetPositionOfWingman(); 241 this->setTargetPositionOfFollower(); 242 } 243 else 244 { 245 //----wingmans shall support the fire of their leaders---- 246 if (this->myWingman_) 247 { 248 this->myWingman_->setAction (Action::FIGHT, this->target_); 249 } 250 if (this->myFollower_) 251 { 252 this->myFollower_->setAction (Action::FIGHT); 253 } 254 } 255 } 256 if (this->hasTarget()) 257 { 258 //----choose where to go---- 259 this->maneuver(); 260 //----fire if you can---- 261 this->bShooting_ = this->canFire(); 262 } 78 { 79 CommonController::action(); 80 263 81 } 264 82 void DivisionController::stayNearProtect() 83 { 84 CommonController::stayNearProtect(); 85 } 265 86 void DivisionController::setTargetPositionOfWingman() 266 87 { … … 294 115 295 116 } 296 void DivisionController::setTargetPositionOfFollower() 297 { 298 if (!this->myFollower_) 299 return; 300 this->myFollower_->setFormationMode(this->formationMode_); 301 302 Vector3* targetRelativePositionOfFollower; 303 switch (this->formationMode_){ 304 case FormationMode::WALL: 305 { 306 targetRelativePositionOfFollower = new Vector3 (-400, 0, 0); 307 break; 308 } 309 case FormationMode::FINGER4: 310 { 311 targetRelativePositionOfFollower = new Vector3 (-400, 0, 200); 312 break; 313 } 314 315 case FormationMode::DIAMOND: 316 { 317 targetRelativePositionOfFollower = new Vector3 (-400, 0, 200); 318 break; 319 } 320 } 321 Quaternion orient = this->getControllableEntity()->getWorldOrientation(); 322 323 Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + 324 (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower))); 325 326 myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient ); 327 } 117 328 118 bool DivisionController::setWingman(CommonController* cwingman) 329 119 { -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
r10843 r10854 58 58 59 59 void setTargetPositionOfWingman(); 60 void setTargetPositionOfFollower();60 61 61 //----[/own functions]---- 62 virtual void stayNearProtect(); 62 63 63 64 protected: 64 65 //----action must only be managed by this---- 65 66 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 66 67 67 68 private: 68 69 //----private variables----- -
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc
r10843 r10854 51 51 { 52 52 } 53 void LeaderController::takeActionpoints (std::vector<Point > vector) 54 { 55 this->parsedActionpoints_ = vector; 56 this->setAction (Action::NONE); 57 this->setTarget(0); 58 this->setTargetPosition (this->getControllableEntity()->getWorldPosition()); 59 orxout(internal_error) << "Top action is " << this->parsedActionpoints_.back().action << endl; 60 } 53 61 54 62 -
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
r10843 r10854 53 53 { return true; } 54 54 //----[/pseudo virtual methods]---- 55 55 virtual void takeActionpoints (std::vector<Point > vector); 56 56 57 57 -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10851 r10854 51 51 SectionController::~SectionController() 52 52 { 53 53 for (size_t i = 0; i < this->actionpoints_.size(); ++i) 54 { 55 if(this->actionpoints_[i]) 56 this->actionpoints_[i]->destroy(); 57 } 58 this->parsedActionpoints_.clear(); 59 this->actionpoints_.clear(); 54 60 } 55 61 void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 86 92 if (!myDivisionLeader_) 87 93 { 88 if (this->startAttackingEnemiesThatAreClose()) 89 { 90 Point p = { Action::FIGHT, "", Vector3::ZERO }; 91 92 if (this->myWingman_) 94 CommonController::action(); 95 } 96 else if (myDivisionLeader_) 97 { 98 switch (myDivisionLeader_->getAction()) 99 { 100 // case Action::FLY: 101 // { 102 // // Vector3 targetRelativePosition = getFormationPosition(); 103 // // Quaternion orient = 104 // // this->myDivisionLeader_->getControllableEntity()->getWorldOrientation(); 105 // // Vector3 targetAbsolutePosition = 106 // // ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) + 107 // // (orient* (targetRelativePosition))); 108 // // this->setAction (Action::FLY, targetAbsolutePosition, orient); 109 // break; 110 // } 111 // case Action::FIGHT: 112 // { 113 114 // // this->setAction (Action::FLY, targetAbsolutePosition, orient); 115 // break; 116 // } 117 default: 93 118 { 94 this->myWingman_->parsedActionpoints_.push_back(p); 119 ControllableEntity* myEntity = this->getControllableEntity(); 120 Vector3 myPosition = myEntity->getWorldPosition(); 121 if (!this->myDivisionLeader_) 122 { 123 return; 124 } 125 ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity(); 126 Quaternion orient = leaderEntity->getWorldOrientation(); 127 Vector3 leaderPosition = leaderEntity->getWorldPosition(); 128 129 Vector3 targetRelativePosition = getFormationPosition(); 130 if (!this->myDivisionLeader_) 131 { 132 return; 133 } 134 Vector3 targetAbsolutePosition = 135 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5) 136 + (orient* (targetRelativePosition))); 137 138 this->setAction (Action::FLY, targetAbsolutePosition, orient); 139 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f) 140 { 141 this->boostControl(); 142 } 143 else 144 { 145 this->getControllableEntity()->boost(false); 146 } 95 147 } 96 148 } 97 if (this->action_ == Action::NONE) 98 { 99 this->executeActionpoint(); 100 } 101 if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL) 102 { 103 if (!this->hasTarget()) 104 { 105 //----find a target---- 106 ControllableEntity* newTarget = this->closestTarget(); 107 if (this->action_ == Action::FIGHT) 108 { 109 if (newTarget && 110 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 111 { 112 this->setAction (Action::FIGHT, newTarget); 113 } 114 else 115 { 116 this->nextActionpoint(); 117 if (this->myWingman_) 118 { 119 this->myWingman_->nextActionpoint(); 120 } 121 122 return; 123 } 124 } 125 else if (this->action_ == Action::FIGHTALL) 126 { 127 if (newTarget && newTarget->getController()) 128 { 129 this->setAction (Action::FIGHTALL, newTarget); 130 } 131 else 132 { 133 this->nextActionpoint(); 134 if (this->myWingman_) 135 { 136 this->myWingman_->nextActionpoint(); 137 } 138 return; 139 } 140 } 141 142 } 143 else if (this->hasTarget()) 144 { 145 //----fly in formation if far enough---- 146 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 147 148 if (diffVector.length() > this->attackRange_) 149 { 150 if (this->action_ == Action::FIGHT) 151 { 152 this->nextActionpoint(); 153 if (this->myWingman_) 154 { 155 this->myWingman_->nextActionpoint(); 156 } 157 return; 158 } 159 else 160 { 161 this->setTargetPositionOfWingman(); 162 } 163 } 164 else 165 { 166 //----wingmans shall support the fire of their leaders---- 167 if (this->myWingman_) 168 { 169 this->myWingman_->setAction (Action::FIGHT, this->target_); 170 } 171 172 } 173 } 174 } 175 else if (this->action_ == Action::FLY) 176 { 177 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 178 { 179 this->nextActionpoint(); 180 if (this->myWingman_) 181 { 182 this->myWingman_->nextActionpoint(); 183 } 184 return; 185 } 186 this->setTargetPositionOfWingman(); 187 } 188 else if (this->action_ == Action::PROTECT) 189 { 190 if (!this->getProtect()) 191 { 192 this->nextActionpoint(); 193 if (this->myWingman_) 194 { 195 this->myWingman_->nextActionpoint(); 196 } 197 return; 198 } 199 200 Vector3* targetRelativePosition; 201 202 targetRelativePosition = new Vector3 (0, 300, 300); 149 } 203 150 204 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 205 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition))); 206 this->setTargetPosition(targetAbsolutePosition); 207 208 this->setTargetPositionOfWingman(); 209 210 } 211 else if (this->action_ == Action::ATTACK) 212 { 213 if (!this->hasTarget()) 214 { 215 this->nextActionpoint(); 216 if (this->myWingman_) 217 { 218 this->myWingman_->nextActionpoint(); 219 } 220 return; 221 } 222 //----fly in formation if far enough---- 223 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 224 if (diffVector.length() > this->attackRange_) 225 { 226 this->setTargetPositionOfWingman(); 227 } 228 else 229 { 230 //----wingmans shall support the fire of their leaders---- 231 if (this->myWingman_) 232 { 233 this->myWingman_->setAction (Action::FIGHT, this->target_); 234 } 235 236 } 237 } 238 if (this->hasTarget()) 239 { 240 //----choose where to go---- 241 this->maneuver(); 242 //----fire if you can---- 243 this->bShooting_ = this->canFire(); 244 } 245 } 246 //----If have leader---- 247 else 248 { 249 //----action was set to fight---- 250 if (this->action_ == Action::FIGHT) 251 { 252 if (!this->hasTarget()) 253 { 254 this->chooseTarget(); 255 } 256 else 257 { 258 //----fly in formation if far enough---- 259 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 260 if (diffVector.length() > this->attackRange_) 261 { 262 this->setTargetPositionOfWingman(); 263 } 264 else 265 { 266 //----wingmans shall support the fire of their leaders---- 267 if (this->myWingman_) 268 { 269 this->myWingman_->setAction (Action::FIGHT, this->target_); 270 } 271 } 272 } 273 if (this->hasTarget()) 274 { 275 //----choose where to go---- 276 this->maneuver(); 277 //----fire if you can---- 278 this->bShooting_ = this->canFire(); 279 } 280 } 281 282 //----action was set to fly---- 283 else if (this->action_ == Action::FLY) 284 { 285 this->setTargetPositionOfWingman(); 286 Pawn* newTarget = this->closestTarget(); 287 if ( newTarget && this->distance (this->getControllableEntity(), 288 static_cast<ControllableEntity*>(newTarget)) <= this->attackRange_ ) 289 { 290 this->setAction (Action::FIGHT, static_cast<ControllableEntity*>(newTarget)); 291 } 292 } 293 } 294 if (this->bFirstAction_ && this->myDivisionLeader_) 295 { 296 this->parsedActionpoints_ = this->myDivisionLeader_->parsedActionpoints_; 297 this->bFirstAction_ = false; 151 } 152 153 void SectionController::boostControl() 154 { 155 SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity()); 156 if(ship == NULL) return; 157 if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost 158 { 159 160 this->getControllableEntity()->boost(true); 161 } 162 else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost 163 { 164 this->getControllableEntity()->boost(false); 298 165 } 299 166 } … … 303 170 { 304 171 //----If division leader fights, cover him by fighting emenies close to his target---- 305 if (this->myDivisionLeader_->getAction() == Action::FIGHT) 172 Action::Value action = this->myDivisionLeader_->getAction(); 173 174 Pawn* target; 175 if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK) 306 176 { 307 177 //----if he has a target---- … … 327 197 { 328 198 foundTarget = true; 329 t his->setAction(Action::FIGHT, (*itP));199 target = (*itP); 330 200 //orxout(internal_error) << "Found target" << endl; 331 201 break; … … 335 205 if (!foundTarget) 336 206 { 337 t his->setAction(Action::FIGHT,this->myDivisionLeader_->getTarget());207 target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget()); 338 208 } 339 209 } … … 341 211 else 342 212 { 343 t his->setAction(Action::FIGHT,this->myDivisionLeader_->getTarget());213 target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget()); 344 214 } 345 215 } … … 349 219 350 220 } 221 this->setAction (Action::FIGHT, orxonox_cast<ControllableEntity*>(target)); 222 } 223 else 224 { 351 225 } 226 } 227 Vector3 SectionController::getFormationPosition () 228 { 229 this->setFormationMode( this->myDivisionLeader_->getFormationMode() ); 230 Vector3* targetRelativePosition; 231 switch (this->formationMode_){ 232 case FormationMode::WALL: 233 { 234 targetRelativePosition = new Vector3 (-400, 0, 0); 235 break; 236 } 237 case FormationMode::FINGER4: 238 { 239 targetRelativePosition = new Vector3 (-400, 0, 200); 240 break; 241 } 242 243 case FormationMode::DIAMOND: 244 { 245 targetRelativePosition = new Vector3 (-400, 0, 200); 246 break; 247 } 248 } 249 return *targetRelativePosition; 352 250 } 353 251 -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
r10851 r10854 63 63 //----action must only be managed by this---- 64 64 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 65 65 Vector3 getFormationPosition (); 66 void boostControl(); 66 67 private: 67 68 //----private variables----- 68 69 Timer actionTimer_; //<! Regularly calls action(). 69 70 bool bFirstAction_; 70 71 71 72 72 73 }; -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10851 r10854 48 48 WingmanController::~WingmanController() 49 49 { 50 50 for (size_t i = 0; i < this->actionpoints_.size(); ++i) 51 { 52 if(this->actionpoints_[i]) 53 this->actionpoints_[i]->destroy(); 54 } 55 this->parsedActionpoints_.clear(); 56 this->actionpoints_.clear(); 51 57 } 52 58 … … 86 92 if (!this->myLeader_) 87 93 { 88 bool b = this->startAttackingEnemiesThatAreClose(); 94 CommonController::action(); 95 } 96 else if (this->myLeader_) 97 { 89 98 90 if (this->action_ == Action::NONE)91 {92 this->executeActionpoint();93 }94 if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)95 {96 if (!this->hasTarget())97 {98 //----find a target----99 ControllableEntity* newTarget = this->closestTarget();100 if (this->action_ == Action::FIGHT)101 {102 if (newTarget &&103 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)104 {105 this->setAction (Action::FIGHT, newTarget);106 }107 else108 {109 this->nextActionpoint();110 return;111 }112 }113 else if (this->action_ == Action::FIGHTALL)114 {115 if (newTarget && newTarget->getController())116 {117 this->setAction (Action::FIGHTALL, newTarget);118 }119 else120 {121 this->nextActionpoint();122 return;123 }124 }125 126 }127 else if (this->hasTarget())128 {129 //----fly in formation if far enough----130 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();131 132 if (diffVector.length() > this->attackRange_)133 {134 if (this->action_ == Action::FIGHT)135 {136 this->nextActionpoint();137 return;138 }139 }140 }141 }142 else if (this->action_ == Action::FLY)143 {144 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)145 {146 this->nextActionpoint();147 return;148 }149 }150 else if (this->action_ == Action::PROTECT)151 {152 if (!this->getProtect())153 {154 this->nextActionpoint();155 return;156 }157 158 Vector3* targetRelativePosition;159 160 targetRelativePosition = new Vector3 (0, 300, 300);161 162 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +163 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));164 this->setTargetPosition(targetAbsolutePosition);165 166 167 }168 else if (this->action_ == Action::ATTACK)169 {170 if (!this->hasTarget())171 {172 this->nextActionpoint();173 return;174 }175 176 }177 if (this->hasTarget())178 {179 //----choose where to go----180 this->maneuver();181 //----fire if you can----182 this->bShooting_ = this->canFire();183 }184 99 } 185 else 186 { 187 //----action was set to fight---- 188 if (this->action_ == Action::FIGHT) 189 { 190 //----If no leader found, attack someone---- 191 if (!this->hasTarget()) 192 { 193 this->setClosestTarget(); 194 } 195 if (this->hasTarget()) 196 { 197 //----choose where to go---- 198 this->maneuver(); 199 //----fire if you can---- 200 this->bShooting_ = this->canFire(); 201 } 202 } 203 //----action was set to fly, leader handles the logic---- 204 else if (this->action_ == Action::FLY) 205 { 206 207 } 208 } 209 if (this->bFirstAction_ && this->myLeader_) 210 { 211 this->parsedActionpoints_ = this->myLeader_->parsedActionpoints_; 212 this->bFirstAction_ = false; 213 } 100 214 101 } 215 102
Note: See TracChangeset
for help on using the changeset viewer.