Changeset 10888 for code/branches
- Timestamp:
- Nov 29, 2015, 6:36:21 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10886 r10888 18 18 include("templates/spaceshipRing.oxt") 19 19 include("templates/spaceshipSwallow.oxt") 20 include("templates/pickupRepresentationTemplates.oxt") 20 21 ?> 22 21 23 22 24 <Level> … … 30 32 skybox = "Orxonox/Starbox" 31 33 > 32 34 <?lua 35 include("includes/pickups.oxi") 36 ?> 33 37 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> 34 <TeamSpawnPoint team= 0 position="3000, -1500, 1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />38 <TeamSpawnPoint team=1 position="1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff /> 35 39 40 <!-- 41 <PickupSpawner pickup=largedamageboostpickup position="0,0,0" triggerDistance="20" respawnTime="30" maxSpawnedItems="10" /> 42 <PickupSpawner pickup=crazyhealthpickup position="0,0,0" triggerDistance="50" respawnTime="30" maxSpawnedItems="10" /> 43 <PickupSpawner pickup=hugeshieldpickup position="4000,4500, 4500" triggerDistance="10" respawnTime="5" maxSpawnedItems="10" /> 44 <PickupSpawner pickup=smalljumppickup position="6500,6500, 6000" triggerDistance="20" respawnTime="10" maxSpawnedItems="99" /> 45 <PickupSpawner pickup=largedamageboostpickup position="9500,9500, 9500" triggerDistance="20" respawnTime="30" maxSpawnedItems="10" /> 46 <PickupSpawner pickup=largedamageboostpickup position="13000,13000,13000" triggerDistance="10" respawnTime="30" maxSpawnedItems="10" /> 47 --> 36 48 <!-- HERE STARTS DEMO FOR THE "WAYPOINTS" --> 37 49 <!-- 50 <SpaceShip position="-1500, -1500, -1500" lookat="0,0,0" team=0 name="ss1"> 51 <templates> 52 <Template link=spaceshipassff /> 53 </templates> 54 <controller> 55 <DivisionController team=0 formationMode="finger4"> 56 <actionpoints> 57 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-600" /> 58 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-1000" /> 59 <Model mesh="cube.mesh" scale=8 position="400,2000,-1000" /> 60 <Model mesh="cube.mesh" scale=8 position="400,2000,-600" /> 61 </actionpoints> 62 </DivisionController> 63 </controller> 64 </SpaceShip> 65 --> 66 <!-- those two are same --> 67 68 <!-- 38 69 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-600" /> 39 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-800" /> 40 <Model mesh="cube.mesh" scale=8 position="200,2000,-800" /> 41 <Model mesh="cube.mesh" scale=8 position="200,2000,-600" /> 42 <Model mesh="cube.mesh" scale=8 position="0,0,0" /> 43 70 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-1000" /> 71 <Model mesh="cube.mesh" scale=8 position="400,2000,-1000" /> 72 <Model mesh="cube.mesh" scale=8 position="400,2000,-600" /> 44 73 <SpaceShip position="-1500, 1500, -1000" lookat="0,0,0" team=0 name="ss1"> 45 74 <templates> … … 50 79 <actionpoints> 51 80 <Actionpoint position=" 0,2000,-600" action="FLY" loopStart=true/> 52 <Actionpoint position=" 0,2000,- 800" action="FLY" />53 <Actionpoint position=" 200,2000,-800" action="FLY" />54 <Actionpoint position=" 200,2000,-600" action="FLY" loopEnd=true />81 <Actionpoint position=" 0,2000,-1000" action="FLY" /> 82 <Actionpoint position="400,2000,-1000" action="FLY" /> 83 <Actionpoint position="400,2000,-600" action="FLY" loopEnd=true /> 55 84 </actionpoints> 56 85 </DivisionController> 57 86 </controller> 58 </SpaceShip> 59 -->87 </SpaceShip> --> 88 60 89 <!-- HERE ENDS DEMO FOR THE "WAYPOINTS" --> 61 90 62 91 <!-- HERE STARTS DEMO FOR THE ACTIONPOINTS. 63 92 P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped --> 64 93 <!-- 65 94 <Model mesh="cube.mesh" scale=8 position="0,0,0" /> 66 95 … … 124 153 </SpaceShip> 125 154 126 155 --> 127 156 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS --> 128 157 <!-- HERE STARTS DEMO FOR FIGHTING --> 129 <!-- 158 159 130 160 <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="ss2"> 131 161 <templates> … … 242 272 </controller> 243 273 </SpaceShip> 244 --> 274 245 275 246 276 <!-- HERE ENDS DEMO FOR FIGHTING --> -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10886 r10888 32 32 #include <algorithm> 33 33 #include "worldentities/Actionpoint.h" 34 35 36 34 namespace orxonox 37 35 { … … 45 43 this->bLoop_ = false; 46 44 this->bEndLoop_ = false; 47 this->parsedActionpoints_.clear(); 45 loopActionpoints_.clear(); 46 parsedActionpoints_.clear(); 47 actionpoints_.clear(); 48 healthSpawners_.clear(); 49 damageSpawners_.clear(); 50 speedSpawners_.clear(); 48 51 this->bTakenOver_ = false; 49 52 this->action_ = Action::NONE; … … 64 67 parsedActionpoints_.clear(); 65 68 actionpoints_.clear(); 69 healthSpawners_.clear(); 70 damageSpawners_.clear(); 71 speedSpawners_.clear(); 66 72 } 67 73 void ActionpointController::tick(float dt) … … 97 103 } 98 104 if (this->bFirstTick_) 99 { 105 { 106 setSpawners(); 107 // orxout(internal_error) << "health spawners size = " << this->healthSpawners_.size() << 108 // ", damage spawners size = " << this->damageSpawners_.size() << 109 // ", speed spawners size = " << this->speedSpawners_.size() << endl; 100 110 this->bFirstTick_ = false; 101 111 } … … 109 119 if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity())) 110 120 return; 121 111 122 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; 112 123 this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth(); … … 116 127 if (this->action_ == Action::NONE || this->bTakenOver_) 117 128 { 129 // Point point = closestPickup(PickupType::HEALTH); 130 // if (point.action != Action::NONE) 131 // { 132 // orxout(internal_error) << "found health" << endl; 133 // this->parsedActionpoints_.push_back(point); 134 // } 118 135 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()) 119 136 { … … 142 159 { 143 160 this->action(); 144 } 161 } 162 else 163 { 164 } 145 165 } 146 166 } … … 214 234 if (this->hasTarget()) 215 235 { 216 //----choose where to go----217 236 this->maneuver(); 218 //----fire if you can---- 219 this->bShooting_ = this->canFire(); 237 this->bShooting_ = this->canFire(); 238 // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length()); 239 // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_) 240 // { 241 // //----choose where to go---- 242 // this->maneuver(); 243 // } 244 // else 245 // { 246 // this->dodgeTowards(healthPosition); 247 // } 248 // //----fire if you can---- 249 // this->bShooting_ = this->canFire(); 220 250 } 221 251 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ; 252 222 253 } 223 254 void ActionpointController::setProtect (ControllableEntity* protect) … … 236 267 bool inLoop = false; 237 268 Point p; 238 if ( static_cast<Actionpoint*> (actionpoint))239 { 240 Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);269 if (actionpoint->getIdentifier()->getName() == "Actionpoint") 270 { 271 Actionpoint* ap = orxonox_cast<Actionpoint*> (actionpoint); 241 272 actionName = ap->getActionXML(); 242 273 targetName = ap->getName(); … … 277 308 else 278 309 { 310 inLoop = true; 279 311 p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition(); p.inLoop = inLoop; 280 312 } … … 290 322 } 291 323 292 324 Action::Value ActionpointController::getAction () 293 325 { 294 326 return this->action_; … … 593 625 <= this->attackRange_ ) 594 626 { 595 Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, false }; 596 this->parsedActionpoints_.push_back(p); 627 if (this->bLoop_) 628 { 629 Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, true }; 630 this->loopActionpoints_.push_back(p); 631 } 632 else 633 { 634 Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, false }; 635 this->parsedActionpoints_.push_back(p); 636 } 597 637 this->executeActionpoint(); 598 638 } … … 600 640 } 601 641 } 642 Vector3 ActionpointController::bestHealthPickup(float searchRadius) 643 { 644 645 //1000000/distance^2 * 1/index+1 646 float maxUse = 0; 647 float tempUse = -1; 648 int index = 0; 649 float distance = 0; 650 Vector3 bestPosition = this->getControllableEntity()->getWorldPosition(); 651 652 for (std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it=healthSpawners_.begin(); it!=healthSpawners_.end(); ++it) 653 { 654 distance = (this->getControllableEntity()->getWorldPosition() - (*it).second.first->getWorldPosition()).length(); 655 if (distance < this->tolerance_ || !(*it).second.second) 656 { 657 (*it).second.second = false; 658 continue; 659 } 660 if (distance > searchRadius) 661 continue; 662 index = (*it).first; 663 tempUse = 1000000*1/(1+distance*distance) * 1/((index/2.0f)+1); 664 if (tempUse > maxUse) 665 { 666 bestPosition = (*it).second.first->getWorldPosition(); 667 maxUse = tempUse; 668 } 669 } 670 //std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it = this->healthSpawners_.find(index); 671 //P.S. check if it == ... .end() 672 //orxout (internal_error) << "best position = " << bestPosition << endl; 673 return bestPosition; 674 } 675 void ActionpointController::setSpawners() 676 { 677 std::vector<std::string> damagePickups; 678 std::vector<std::string> healthPickups; 679 std::vector<std::string> speedPickups; 680 int index = 0; 681 682 683 damagePickups.push_back("largedamageboostpickup"); 684 damagePickups.push_back("dronepickup"); 685 damagePickups.push_back("mediumdamageboostpickup"); 686 damagePickups.push_back("smalldamageboostpickup"); 687 688 healthPickups.push_back("triplehealthspeedinvisibilitypickup"); 689 healthPickups.push_back("crazyhealthpickup"); 690 healthPickups.push_back("hugehealthpickup"); 691 healthPickups.push_back("hugeshieldpickup"); 692 healthPickups.push_back("hugeinvisiblepickup"); 693 healthPickups.push_back("hugeshrinkpickup"); 694 healthPickups.push_back("mediumhealthpickup"); 695 healthPickups.push_back("mediumshieldpickup"); 696 healthPickups.push_back("mediuminvisiblepickup"); 697 healthPickups.push_back("mediumshrinkpickup"); 698 healthPickups.push_back("smallhealthpickup"); 699 healthPickups.push_back("smallshieldpickup"); 700 healthPickups.push_back("smallinvisiblepickup"); 701 healthPickups.push_back("smallshrinkpickup"); 702 703 speedPickups.push_back("triplehealthspeedinvisibilitypickup"); 704 speedPickups.push_back("hugespeedpickup"); 705 speedPickups.push_back("smalljumppickup"); 706 speedPickups.push_back("mediumspeedpickup"); 707 speedPickups.push_back("smallspeedpickup"); 708 709 710 711 for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it; ++it) 712 { 713 if ((*it)->getIdentifier()->getName() != "PickupSpawner") 714 continue; 715 PickupSpawner* spawner = static_cast<PickupSpawner*>(*it); 716 std::string name = spawner->getPickupTemplateName(); 717 //float distance = ((*it)->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length(); 718 // if (distance < 50.0f) 719 // continue; 720 for (unsigned int i = 0; i < healthPickups.size(); ++i) 721 { 722 if (name == healthPickups.at(i)) 723 { 724 index = i; 725 this->healthSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true))); 726 break; 727 } 728 } 729 for (unsigned int i = 0; i < damagePickups.size(); ++i) 730 { 731 if (name == damagePickups.at(i)) 732 { 733 //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1); 734 index = i; 735 this->damageSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true))); 736 break; 737 } 738 } 739 for (unsigned int i = 0; i < speedPickups.size(); ++i) 740 { 741 if (name == speedPickups.at(i)) 742 { 743 //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1); 744 index = i; 745 this->speedSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true))); 746 break; 747 } 748 } 749 // if (tempUse > maxUse) 750 // { 751 // Point p = { Action::FLY, "", (*it)->getWorldPosition(), false }; 752 // maxUse = tempUse; 753 // maxPoint = p; 754 // } 755 // else 756 // { 757 // tempUse = -1; 758 // continue; 759 // } 760 // orxout(internal_error) << "resp time = " << static_cast<PickupSpawner*>(*it)->getRespawnTime() << endl; 761 } 762 } 602 763 } -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
r10885 r10888 33 33 #include "tools/Timer.h" 34 34 #include "tools/interfaces/Tickable.h" 35 #include "../modules/pickup/PickupSpawner.h" 36 #include <map> 35 37 36 38 namespace orxonox … … 51 53 bool inLoop; 52 54 } ; 55 namespace PickupType 56 { 57 enum Value 58 { 59 NONE, DAMAGE, HEALTH, SPEED, PORTAL 60 }; 61 } 53 62 54 63 class _OrxonoxExport ActionpointController : public FightingController, public Tickable … … 118 127 bool bFirstTick_; 119 128 129 void setSpawners(); 130 Vector3 bestHealthPickup (float searchRadius); 131 // Point closestPickup(PickupType::Value pickupType); 132 std::multimap <int, std::pair<PickupSpawner*, bool> > healthSpawners_; 133 std::multimap <int, std::pair<PickupSpawner*, bool> > damageSpawners_; 134 std::multimap <int, std::pair<PickupSpawner*, bool> > speedSpawners_; 135 120 136 private: 121 137 -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10886 r10888 172 172 } 173 173 } 174 174 void FightingController::dodgeTowards (Vector3& position) 175 { 176 Vector3 thisPosition = this->getControllableEntity()->getPosition(); 177 Vector3 diff = (position - thisPosition); 178 float diffLength = diff.length(); 179 Vector3 diffUnit = diff/diffLength; 180 float factor = 300.0f; 181 if (diffLength < 300) 182 { 183 this->setTargetPosition(position); 184 return; 185 } 186 else if (diffLength < 600) 187 factor = 400.0f; 188 else if (diffLength < 1000) 189 factor = 700.0f; 190 else 191 factor = 1000.0f; 192 float x = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 193 float y = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 194 float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y); 195 this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * factor); 196 // orxout(internal_error) << "Dodging towards " << Vector3(x,y,z) << endl; 197 this->boostControl(); 198 } 175 199 void FightingController::dodge(const Vector3& thisPosition, Vector3& diffUnit) 176 200 { … … 179 203 float x = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 180 204 float y = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 181 float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);205 float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y); 182 206 this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : diffUnit * 100.0f)); 183 207 this->boostControl(); -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
r10886 r10888 62 62 void maneuver(); 63 63 void dodge(const Vector3& thisPosition, Vector3& diffUnit); 64 void dodgeTowards (Vector3& position); 64 65 bool canFire(); 65 66 void doFire(); -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
r10886 r10888 42 42 this->rotationProgress_ = 0; 43 43 this->spread_ = 200; 44 this->tolerance_ = 100;44 this->tolerance_ = 80; 45 45 } 46 46 FlyingController::~FlyingController() -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10886 r10888 126 126 { 127 127 this->maneuver(); 128 this->bShooting_ = this->canFire(); 128 this->bShooting_ = this->canFire(); 129 // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length()); 130 // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_) 131 // { 132 // //----choose where to go---- 133 // this->maneuver(); 134 // } 135 // else 136 // { 137 // this->dodgeTowards(healthPosition); 138 // } 139 // //----fire if you can---- 140 // this->bShooting_ = this->canFire(); 129 141 } 130 142 } -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10886 r10888 112 112 if (this->hasTarget()) 113 113 { 114 //----choose where to go----115 114 this->maneuver(); 116 //----fire if you can---- 117 this->bShooting_ = this->canFire(); 115 this->bShooting_ = this->canFire(); 116 // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length()); 117 // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_) 118 // { 119 // //----choose where to go---- 120 // this->maneuver(); 121 // } 122 // else 123 // { 124 // this->dodgeTowards(healthPosition); 125 // } 126 // //----fire if you can---- 127 // this->bShooting_ = this->canFire(); 118 128 } 119 129 } -
code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h
r10885 r10888 90 90 </SpaceShip> 91 91 92 One can also use other Worldentities instead of Actionpoints just like Waypoints, but those points 93 will be included in loop. 92 94 For more information read descriptions of the methods. 93 95 */
Note: See TracChangeset
for help on using the changeset viewer.