Changeset 10877 for code/branches/campaignHS15/src/orxonox
- Timestamp:
- Nov 27, 2015, 4:42:14 PM (9 years ago)
- Location:
- code/branches/campaignHS15/src/orxonox/controllers
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10875 r10877 31 31 #include "core/XMLPort.h" 32 32 #include <algorithm> 33 #include "worldentities/Actionpoint.h" 33 34 34 35 … … 38 39 RegisterClass(ActionpointController); 39 40 40 //CommonController contains all common functionality of AI Controllers41 41 ActionpointController::ActionpointController(Context* context) : FightingController(context) 42 42 { 43 43 this->bInLoop_ = false; 44 44 this->bLoop_ = false; 45 45 this->bEndLoop_ = false; … … 48 48 this->action_ = Action::NONE; 49 49 this->squaredaccuracy_ = 2500; 50 50 this->bFirstTick_ = true; 51 51 52 52 RegisterObject(ActionpointController); … … 559 559 if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) 560 560 { 561 if ( (this->target_ && this->distance (this->getControllableEntity(), this->target_) > this->attackRange_)561 if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) 562 562 || !this->target_ ) 563 563 { 564 564 Pawn* newTarget = this->closestTarget(); 565 565 if ( newTarget && 566 this->distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))566 CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget)) 567 567 <= this->attackRange_ ) 568 568 { 569 Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO, false };569 Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, false }; 570 570 this->parsedActionpoints_.push_back(p); 571 571 this->executeActionpoint(); -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
r10871 r10877 31 31 32 32 #include "controllers/FightingController.h" 33 33 #include "tools/Timer.h" 34 #include "tools/interfaces/Tickable.h" 34 35 35 36 namespace orxonox … … 51 52 } ; 52 53 53 class _OrxonoxExport ActionpointController : public FightingController 54 class _OrxonoxExport ActionpointController : public FightingController, public Tickable 54 55 { 55 56 public: … … 74 75 void setAction (Action::Value action, const Vector3& target, const Quaternion& orient ); 75 76 76 77 77 virtual bool setWingman(ActionpointController* wingman) 78 { return false; } 79 virtual bool hasWingman() 80 { return true; } 81 virtual bool setFollower(ActionpointController* myFollower) 82 { return false; } 83 virtual bool hasFollower() 84 { return true; } 78 85 79 86 protected: … … 106 113 void moveBackToTop(); 107 114 //----[Actionpoint methods]---- 108 115 bool bFirstTick_; 116 109 117 private: 110 118 -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10875 r10877 27 27 */ 28 28 #include "controllers/CommonController.h" 29 #include "core/XMLPort.h"30 29 31 30 //stuff for sameTeam function 31 #include "gametypes/TeamDeathmatch.h" 32 #include "gametypes/Gametype.h" 33 #include "controllers/DroneController.h" 34 #include "gametypes/Dynamicmatch.h" 35 32 36 #include "worldentities/pawns/TeamBaseMatchBase.h" 33 #include "gametypes/TeamDeathmatch.h"34 #include "gametypes/Dynamicmatch.h"35 #include "gametypes/Mission.h"36 #include "gametypes/Gametype.h"37 #include "controllers/WaypointPatrolController.h"38 #include "controllers/NewHumanController.h"39 #include "controllers/DroneController.h"40 #include "util/Math.h"41 37 42 38 namespace orxonox … … 44 40 45 41 RegisterClass( CommonController ); 46 const float SPEED = 0.9f/0.02f;47 const float ROTATEFACTOR = 1.0f/0.02f;48 42 49 50 43 CommonController::CommonController( Context* context ): Controller( context ) 51 44 { 52 this->bFirstTick_ = true;53 54 45 RegisterObject( CommonController ); 55 56 46 } 57 47 CommonController::~CommonController() … … 59 49 60 50 } 61 void CommonController::tick(float dt)62 {63 64 SUPER(CommonController, tick, dt);65 }66 67 68 void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )69 {70 SUPER( CommonController, XMLPort, xmlelement, mode );71 }72 73 //"Virtual" methods74 bool CommonController::setWingman ( CommonController* wingman )75 { return false; }76 bool CommonController::hasWingman()77 { return true; }78 51 79 52 float CommonController::randomInRange( float a, float b ) -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10875 r10877 32 32 33 33 #include "controllers/Controller.h" 34 #include <limits> 35 34 36 #include "worldentities/ControllableEntity.h" 35 37 #include "worldentities/pawns/Pawn.h" 36 38 37 #include "tools/Timer.h"38 #include "tools/interfaces/Tickable.h"39 #include <limits>40 #include "worldentities/Actionpoint.h"41 39 42 40 namespace orxonox 43 41 { 44 class _OrxonoxExport CommonController : public Controller , public Tickable42 class _OrxonoxExport CommonController : public Controller 45 43 { 46 44 47 45 public: 46 static const float ACTION_INTERVAL = 1.0f; 47 48 48 static const float hardcoded_projectile_speed = 750; 49 static const float ACTION_INTERVAL = 1.0f;50 49 51 50 CommonController(Context* context); 52 51 virtual ~CommonController(); 53 52 54 virtual void tick(float dt); 55 56 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 57 58 59 60 virtual bool setWingman(CommonController* wingman); 61 virtual bool hasWingman(); 62 63 64 float randomInRange(float a, float b); 53 static float randomInRange(float a, float b); 65 54 static float distance(ControllableEntity* entity1, ControllableEntity* entity2); 66 55 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt); 67 56 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; 68 static std::string getName( Pawn* entity ) ; 69 70 protected: 71 72 bool bFirstTick_; 73 74 57 static std::string getName( Pawn* entity ) ; 75 58 }; 76 59 } -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10869 r10877 49 49 DivisionController::~DivisionController() 50 50 { 51 // if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))52 // {53 // if (this->myFollower_)54 // {55 // this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);56 // if (this->myWingman_)57 // {58 // this->myWingman_->setAction(Action::FIGHTALL);59 // }60 // }61 // else if (this->myWingman_)62 // {63 // this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);64 // }65 // }66 51 for (size_t i = 0; i < this->actionpoints_.size(); ++i) 67 52 { … … 112 97 } 113 98 114 bool DivisionController::setWingman( CommonController* cwingman)99 bool DivisionController::setWingman(ActionpointController* wingman) 115 100 { 116 101 117 W eakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);102 WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman); 118 103 if (!this->myWingman_) 119 104 { 120 this->myWingman_ = wingman;105 this->myWingman_ = newWingman; 121 106 return true; 122 107 } … … 126 111 } 127 112 } 128 bool DivisionController::setFollower( LeaderController* myFollower)113 bool DivisionController::setFollower(ActionpointController* myFollower) 129 114 { 130 if (!this->myFollower_) 115 LeaderController* newFollower = orxonox_cast<LeaderController*> (myFollower); 116 if (!this->myFollower_) 131 117 { 132 this->myFollower_ = myFollower;118 this->myFollower_ = newFollower; 133 119 return true; 134 120 } -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
r10869 r10877 52 52 53 53 //----[own functions]---- 54 virtual bool setFollower( LeaderController* myFollower);55 virtual bool setWingman( CommonController* cwingman);54 virtual bool setFollower(ActionpointController* myFollower); 55 virtual bool setWingman(ActionpointController* wingman); 56 56 virtual bool hasWingman(); 57 57 virtual bool hasFollower(); -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10875 r10877 126 126 Vector3 diffUnit = diffVector/diffLength; 127 127 128 bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );128 bool bTargetIsLookingAtThis = CommonController::isLooking ( this->target_, getControllableEntity(), math::pi/10.0f ); 129 129 130 130 //too far? well, come closer then … … 167 167 { 168 168 float factorX = 0, factorY = 0, factorZ = 0; 169 float rand = randomInRange (0, 1);169 float rand = CommonController::randomInRange (0, 1); 170 170 171 171 if (rand <= 0.5) … … 173 173 else 174 174 { factorX = -1; } 175 rand = randomInRange (0, 1);175 rand = CommonController::randomInRange (0, 1); 176 176 if (rand <= 0.5) 177 177 { factorY = 1; } 178 178 else 179 179 { factorY = -1; } 180 rand = randomInRange (0, 1);180 rand = CommonController::randomInRange (0, 1); 181 181 if (rand <= 0.5) 182 182 { factorZ = 1; } … … 186 186 Vector3 target = ( diffUnit )* 8000.0f; 187 187 Vector3* randVector = new Vector3( 188 factorX * randomInRange( 10000, 40000 ),189 factorY * randomInRange( 10000, 40000 ),190 factorZ * randomInRange( 10000, 40000 )188 factorX * CommonController::randomInRange( 10000, 40000 ), 189 factorY * CommonController::randomInRange( 10000, 40000 ), 190 factorZ * CommonController::randomInRange( 10000, 40000 ) 191 191 ); 192 192 Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit; … … 245 245 if ( !this->getControllableEntity() || !this->target_ ) 246 246 return false; 247 return this->isLooking(this->getControllableEntity(), this->getTarget(), angle);247 return CommonController::isLooking(this->getControllableEntity(), this->getTarget(), angle); 248 248 } 249 249 void FightingController::setClosestTarget() -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
r10871 r10877 35 35 namespace orxonox 36 36 { 37 38 39 40 37 class _OrxonoxExport FightingController : public FlyingController 41 38 { -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
r10875 r10877 45 45 46 46 } 47 47 48 void FlyingController::XMLPort( Element& xmlelement, XMLPort::Mode mode ) 48 49 { -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
r10875 r10877 35 35 namespace orxonox 36 36 { 37 const float SPEED = 0.9f/0.02f;38 const float ROTATEFACTOR = 0.6f/0.02f;39 37 namespace FormationMode 40 38 { … … 45 43 } 46 44 47 48 49 45 class _OrxonoxExport FlyingController : public CommonController 50 46 { 51 47 52 48 public: 49 static const float SPEED = 0.9f/0.02f; 50 static const float ROTATEFACTOR = 0.6f/0.02f; 51 53 52 FlyingController(Context* context); 54 53 virtual ~FlyingController(); -
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
r10864 r10877 47 47 virtual void tick(float dt); 48 48 49 //----[pseudo virtual methods]----50 virtual bool setFollower(LeaderController* myFollower)51 { return false; }52 virtual bool hasFollower()53 { return true; }54 //----[/pseudo virtual methods]----55 49 56 50 -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10875 r10877 315 315 return 0; 316 316 } 317 bool SectionController::setWingman( CommonController* cwingman)318 { 319 W eakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);317 bool SectionController::setWingman(ActionpointController* wingman) 318 { 319 WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman); 320 320 321 321 if (!this->myWingman_) 322 322 { 323 this->myWingman_ = wingman;323 this->myWingman_ = newWingman; 324 324 return true; 325 325 } -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
r10869 r10877 53 53 LeaderController* findNewDivisionLeader(); 54 54 55 virtual bool setWingman( CommonController* cwingman);55 virtual bool setWingman(ActionpointController* wingman); 56 56 virtual bool hasWingman(); 57 57 -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10875 r10877 111 111 if (!this->myLeader_) 112 112 { 113 ActionpointController* newLeader = orxonox_cast<ActionpointController*>(findNewLeader());113 ActionpointController* newLeader = (findNewLeader()); 114 114 this->myLeader_ = newLeader; 115 115 … … 219 219 } 220 220 //----POST: closest leader that is ready to take a new wingman is returned---- 221 CommonController* WingmanController::findNewLeader()221 ActionpointController* WingmanController::findNewLeader() 222 222 { 223 223 … … 226 226 227 227 //----vars for finding the closest leader---- 228 CommonController* closestLeader = 0;228 ActionpointController* closestLeader = 0; 229 229 float minDistance = std::numeric_limits<float>::infinity(); 230 230 Gametype* gt = this->getGametype(); 231 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 231 232 for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it) 232 233 { 233 234 //----0ptr or not a leader or dead?---- … … 253 254 { 254 255 //----Racing conditions---- 255 if (closestLeader->setWingman(orxonox_cast<CommonController*>(this))) 256 if (closestLeader->setWingman(orxonox_cast<ActionpointController*>(this))) 257 { 256 258 return closestLeader; 257 } 259 } 260 261 } 262 258 263 return 0; 259 264 } -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
r10869 r10877 52 52 53 53 //----[own functions]---- 54 CommonController* findNewLeader();54 ActionpointController* findNewLeader(); 55 55 //----[/own functions]---- 56 56
Note: See TracChangeset
for help on using the changeset viewer.