Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10877


Ignore:
Timestamp:
Nov 27, 2015, 4:42:14 PM (8 years ago)
Author:
gania
Message:

CommonController now has static methods only. Replace with a namespace?

Location:
code/branches/campaignHS15
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/data/levels/AITest.oxw

    r10875 r10877  
    261261    -->
    262262<!-- HERE ENDS DEMO FOR FORMATIONS -->
    263    
    264    
     263    <!--
     264    <SpaceShip position="2000, 2000, 2000" lookat="0,0,0" team=1 name="ss2">
     265      <templates>
     266        <Template link=spaceshipassff />
     267      </templates>
     268      <controller>
     269        <DivisionController team=1 formationMode="finger4">
     270         
     271        </DivisionController>
     272      </controller>
     273    </SpaceShip>
    265274   
    266 
     275 -->
    267276  </Scene>
    268277</Level>
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10875 r10877  
    3131#include "core/XMLPort.h"
    3232#include <algorithm>
     33#include "worldentities/Actionpoint.h"
    3334
    3435
     
    3839    RegisterClass(ActionpointController);
    3940
    40     //CommonController contains all common functionality of AI Controllers
    4141    ActionpointController::ActionpointController(Context* context) : FightingController(context)
    4242    {
    43               this->bInLoop_ = false;
     43        this->bInLoop_ = false;
    4444        this->bLoop_ = false;
    4545        this->bEndLoop_ = false;
     
    4848        this->action_ = Action::NONE;
    4949        this->squaredaccuracy_ = 2500;
    50 
     50        this->bFirstTick_ = true;
    5151
    5252        RegisterObject(ActionpointController);
     
    559559        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
    560560        {
    561             if ( (this->target_ && this->distance (this->getControllableEntity(), this->target_) > this->attackRange_)
     561            if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
    562562                || !this->target_ )
    563563            {
    564564                Pawn* newTarget = this->closestTarget();
    565565                if ( newTarget &&
    566                     this->distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
     566                    CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
    567567                        <= this->attackRange_ )
    568568                {
    569                     Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO, false };
     569                    Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, false };
    570570                    this->parsedActionpoints_.push_back(p);
    571571                    this->executeActionpoint();
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10871 r10877  
    3131
    3232#include "controllers/FightingController.h"
    33 
     33#include "tools/Timer.h"
     34#include "tools/interfaces/Tickable.h"
    3435
    3536namespace orxonox
     
    5152    } ;
    5253
    53     class _OrxonoxExport ActionpointController : public FightingController
     54    class _OrxonoxExport ActionpointController : public FightingController, public Tickable
    5455    {
    5556        public:
     
    7475            void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
    7576
    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; }
    7885
    7986        protected:
     
    106113                void moveBackToTop();
    107114            //----[Actionpoint methods]----         
    108            
     115                bool bFirstTick_;
     116
    109117        private:
    110118           
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc

    r10875 r10877  
    2727 */
    2828#include "controllers/CommonController.h"
    29 #include "core/XMLPort.h"
    3029
    3130//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
    3236#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"
    4137
    4238namespace orxonox
     
    4440
    4541    RegisterClass( CommonController );
    46     const float SPEED = 0.9f/0.02f;
    47     const float ROTATEFACTOR = 1.0f/0.02f;
    4842
    49  
    5043    CommonController::CommonController( Context* context ): Controller( context )
    5144    {
    52         this->bFirstTick_ = true;
    53        
    5445        RegisterObject( CommonController );
    55 
    5646    }
    5747    CommonController::~CommonController()
     
    5949       
    6050    }
    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" methods
    74     bool CommonController::setWingman ( CommonController* wingman )
    75     { return false; }
    76     bool CommonController::hasWingman()
    77     { return true; }
    7851
    7952    float CommonController::randomInRange( float a, float b )
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

    r10875 r10877  
    3232
    3333#include "controllers/Controller.h"
     34#include <limits>
     35
    3436#include "worldentities/ControllableEntity.h"
    3537#include "worldentities/pawns/Pawn.h"
    3638
    37 #include "tools/Timer.h"
    38 #include "tools/interfaces/Tickable.h"
    39 #include <limits>
    40 #include "worldentities/Actionpoint.h"
    4139
    4240namespace orxonox
    4341{
    44     class _OrxonoxExport CommonController : public Controller, public Tickable
     42    class _OrxonoxExport CommonController : public Controller
    4543    {
    4644
    4745        public:
     46            static const float ACTION_INTERVAL = 1.0f;
     47
    4848            static const float hardcoded_projectile_speed = 750;
    49             static const float ACTION_INTERVAL = 1.0f;
    5049
    5150            CommonController(Context* context);
    5251            virtual ~CommonController();
    5352
    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);
    6554            static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
    6655            static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
    6756            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 ) ;           
    7558    };
    7659}
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10869 r10877  
    4949    DivisionController::~DivisionController()
    5050    {
    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         // }
    6651        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
    6752        {
     
    11297    }
    11398   
    114     bool DivisionController::setWingman(CommonController* cwingman)
     99    bool DivisionController::setWingman(ActionpointController* wingman)
    115100    {
    116101
    117         WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
     102        WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);
    118103        if (!this->myWingman_)
    119104        {
    120             this->myWingman_ = wingman;
     105            this->myWingman_ = newWingman;
    121106            return true;
    122107        }
     
    126111        }
    127112    }
    128     bool DivisionController::setFollower(LeaderController* myFollower)
     113    bool DivisionController::setFollower(ActionpointController* myFollower)
    129114    {
    130          if (!this->myFollower_)
     115        LeaderController* newFollower = orxonox_cast<LeaderController*> (myFollower);
     116        if (!this->myFollower_)
    131117        {
    132             this->myFollower_ = myFollower;
     118            this->myFollower_ = newFollower;
    133119            return true;
    134120        }
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h

    r10869 r10877  
    5252
    5353            //----[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);
    5656                virtual bool hasWingman();
    5757                virtual bool hasFollower();
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10875 r10877  
    126126        Vector3 diffUnit = diffVector/diffLength;
    127127
    128         bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
     128        bool bTargetIsLookingAtThis = CommonController::isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
    129129       
    130130        //too far? well, come closer then
     
    167167    {
    168168        float factorX = 0, factorY = 0, factorZ = 0;
    169         float rand = randomInRange (0, 1);
     169        float rand = CommonController::randomInRange (0, 1);
    170170   
    171171        if (rand <= 0.5)
     
    173173        else
    174174        { factorX = -1; }
    175         rand = randomInRange (0, 1);
     175        rand = CommonController::randomInRange (0, 1);
    176176        if (rand <= 0.5)
    177177        { factorY = 1; }
    178178        else
    179179        { factorY = -1; }
    180         rand = randomInRange (0, 1);
     180        rand = CommonController::randomInRange (0, 1);
    181181        if (rand <= 0.5)
    182182        { factorZ = 1; }
     
    186186        Vector3 target = ( diffUnit )* 8000.0f;
    187187        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 )
    191191        );
    192192        Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
     
    245245        if ( !this->getControllableEntity()  || !this->target_ )
    246246            return false;
    247         return this->isLooking(this->getControllableEntity(), this->getTarget(), angle);
     247        return CommonController::isLooking(this->getControllableEntity(), this->getTarget(), angle);
    248248    }
    249249        void FightingController::setClosestTarget()
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.h

    r10871 r10877  
    3535namespace orxonox
    3636{
    37 
    38    
    39 
    4037    class _OrxonoxExport FightingController : public FlyingController
    4138    {
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc

    r10875 r10877  
    4545
    4646    }
     47
    4748    void FlyingController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
    4849    {
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h

    r10875 r10877  
    3535namespace orxonox
    3636{   
    37     const float SPEED = 0.9f/0.02f;
    38     const float ROTATEFACTOR = 0.6f/0.02f;
    3937    namespace FormationMode
    4038    {
     
    4543    }
    4644
    47    
    48 
    4945    class _OrxonoxExport FlyingController : public CommonController
    5046    {
    5147
    5248        public:
     49            static const float SPEED = 0.9f/0.02f;
     50            static const float ROTATEFACTOR = 0.6f/0.02f;
     51 
    5352            FlyingController(Context* context);
    5453            virtual ~FlyingController();
  • code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h

    r10864 r10877  
    4747                virtual void tick(float dt);
    4848
    49             //----[pseudo virtual methods]----
    50                 virtual bool setFollower(LeaderController* myFollower)
    51                     { return false; }
    52                 virtual bool hasFollower()
    53                     { return true; }
    54             //----[/pseudo virtual methods]----
    5549
    5650
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10875 r10877  
    315315        return 0;
    316316    }
    317     bool SectionController::setWingman(CommonController* cwingman)
    318     {
    319         WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
     317    bool SectionController::setWingman(ActionpointController* wingman)
     318    {
     319        WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);
    320320
    321321        if (!this->myWingman_)
    322322        {
    323             this->myWingman_ = wingman;
     323            this->myWingman_ = newWingman;
    324324            return true;
    325325        }
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.h

    r10869 r10877  
    5353                LeaderController* findNewDivisionLeader();
    5454
    55                 virtual bool setWingman(CommonController* cwingman);
     55                virtual bool setWingman(ActionpointController* wingman);
    5656                virtual bool hasWingman();
    5757
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10875 r10877  
    111111        if (!this->myLeader_)
    112112        {
    113             ActionpointController* newLeader = orxonox_cast<ActionpointController*> (findNewLeader());
     113            ActionpointController* newLeader = (findNewLeader());
    114114            this->myLeader_ = newLeader;
    115115           
     
    219219    }
    220220    //----POST: closest leader that is ready to take a new wingman is returned----
    221     CommonController* WingmanController::findNewLeader()
     221    ActionpointController* WingmanController::findNewLeader()
    222222    {
    223223
     
    226226
    227227        //----vars for finding the closest leader----
    228         CommonController* closestLeader = 0;
     228        ActionpointController* closestLeader = 0;
    229229        float minDistance =  std::numeric_limits<float>::infinity();
    230230        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)
    232233        {
    233234            //----0ptr or not a leader or dead?----
     
    253254        {
    254255            //----Racing conditions----
    255             if (closestLeader->setWingman(orxonox_cast<CommonController*>(this)))
     256            if (closestLeader->setWingman(orxonox_cast<ActionpointController*>(this)))
     257            {
    256258                return closestLeader;
    257         }
     259            }
     260
     261        }
     262
    258263        return 0;
    259264    }
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h

    r10869 r10877  
    5252
    5353            //----[own functions]----
    54                CommonController* findNewLeader();
     54               ActionpointController* findNewLeader();
    5555            //----[/own functions]----
    5656
Note: See TracChangeset for help on using the changeset viewer.