Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 7, 2015, 10:24:20 PM (9 years ago)
Author:
gania
Message:

cleaned up a bit

Location:
code/branches/campaignHS15/src/orxonox/controllers
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10953 r10955  
    7878            return;
    7979
     80        //count ticks, ticks_ is unsigned, so overflow is not a problem
    8081        ++this->ticks_;
    8182        if (this->ticks_ == 1)
    8283        {
     84            //those vectors are in reversed order after being set by XML.
    8385            std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
    8486            std::reverse(actionpoints_.begin(), actionpoints_.end());
    85             if (this->parsedActionpoints_.empty())
    86             {
    87                 this->action_ = Action::FIGHTALL;
    88             }
    89         }
    90 
    91         if (!this || !this->getControllableEntity())
    92             return;
     87        }
     88
     89        if (!this || !this->getControllableEntity())
     90            return;
     91        //fly
     92        if (this->bHasTargetPosition_)
     93        {
     94            this->moveToTargetPosition(dt);
     95        }//or just rotate
     96        else if (this->bLookAtTarget_)
     97        {
     98            this->lookAtTarget(dt);
     99        }
    93100       
    94         if (this->bHasTargetPosition_)
    95         {
    96             this->moveToTargetPosition(dt);
    97         }
    98         else if (this->bLookAtTarget_)
    99         {
    100             this->lookAtTarget(dt);
    101         }
    102        
    103 
    104         if (!this || !this->getControllableEntity())
    105             return;
    106 
     101
     102        if (!this || !this->getControllableEntity())
     103            return;
     104        //don't fire rocket each tick
    107105        if (timeout_ <= 0)
    108106        {   
     
    116114        if (!this || !this->getControllableEntity())
    117115            return;
    118 
     116        //sometimes dodge, sometimes attack
    119117        if (this->ticks_ % 80 <= 10)
    120118        {
     
    128126        if (!this || !this->getControllableEntity())
    129127            return;
     128        //fire if you can
     129        if (this->bShooting_)
     130        {
     131            this->doFire();
     132        }
     133        SUPER(ActionpointController, tick, dt);
     134    }
    130135     
    131         if (this->bShooting_)
    132         {
    133             this->doFire();
    134         }
    135         SUPER(ActionpointController, tick, dt);
    136     }
    137      
    138 
     136    /**
     137    @brief
     138        action() manages the state machine.
     139    */
    139140
    140141    void ActionpointController::action()
     
    143144            return;
    144145
     146        //deltaHp is used to know if this got attacked
    145147        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
    146148        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
     149
     150        //look out for enemies
    147151        if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE))
    148152        {
     
    155159        if (this->action_ == Action::NONE || this->bTakenOver_)
    156160        {
     161            //if default behaviour is fighting all, push it onto the stack
    157162            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
    158163            {
     
    296301
    297302    }
     303    /**
     304    @brief
     305        if action is protect, this follows protect_ and fights enemies that are close
     306    */
    298307    void ActionpointController::setProtect (ControllableEntity* protect)
    299308    {
     
    306315        return this->protect_;
    307316    }
     317    //XML method
    308318    void ActionpointController::addActionpoint(WorldEntity* actionpoint)
    309319    {
     
    360370            this->actionpoints_.push_back(actionpoint);
    361371    }
     372    //XML method
    362373    WorldEntity* ActionpointController::getActionpoint(unsigned int index) const
    363374    {
     
    367378            return 0;
    368379    }
    369 
     380    //XML method
    370381    Action::Value ActionpointController::getAction ()
    371382    {
    372383        return this->action_;
    373384    }
     385    //XML method
    374386    std::string ActionpointController::getActionName()
    375387    {
     
    393405        }
    394406    }
     407    //XML method
    395408    void ActionpointController::setAction (Action::Value action)
    396409    {
    397410        this->action_ = action;
    398411    }
     412    //set action and target/protect
    399413    void ActionpointController::setAction (Action::Value action, ControllableEntity* target)
    400414    {
     
    413427        }
    414428    }
     429    //set action and target position
    415430    void ActionpointController::setAction (Action::Value action, const Vector3& target)
    416431    {
     
    423438        }
    424439    }
     440    //set action and target position and orientation
    425441    void ActionpointController::setAction (Action::Value action, const Vector3& target,  const Quaternion& orient )
    426442    {
     
    590606    }
    591607
    592    
     608    //calculate where in world coordinates this ship has to be, so that it keeps distance to protect_, and fly there
    593609    void ActionpointController::stayNearProtect()
    594610    {
     
    612628        this->setTargetOrientation(this->getProtect()->getWorldOrientation());
    613629    }
     630    //remove current point from the stack
    614631    void ActionpointController::nextActionpoint()
    615632    {
     
    638655        this->bHasTargetPosition_ = false;
    639656    }
     657    //if looping, instead of erasing point, move it to the top (back is what gets executed, so it's kinda reversed stack)
    640658    void ActionpointController::moveBackToTop()
    641659    {
     
    649667        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
    650668    }
     669    //POST: moves all consecutive points that are in loop to the loop stack
    651670    void ActionpointController::fillLoop()
    652671    {
     
    667686        }
    668687    }
    669    
     688    //copy other ship's stacks so that if it dies, this can finish that ship's actions
    670689    void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
    671690    {
     
    679698        this->bTakenOver_ = true;
    680699    }
     700    //attack closest target
    681701    void ActionpointController::setClosestTarget()
    682702    {
    683703        this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) );
    684704    }
     705    //find closest target
    685706    Pawn* ActionpointController::closestTarget()
    686707    {
     
    711732        return 0; 
    712733    }
     734    //push action FIGHT to the stack and set target to the closest enemy
    713735    void ActionpointController::startAttackingEnemiesThatAreClose()
    714736    {
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10953 r10955  
    6161        In XML one has to attack Actionpoints in order to achieve any complex behaviour, but in Controller all actionpoints are effectively
    6262        being stored in an array of type Point::Value.
     63    @note
     64        ActionpointController will not work, if there is no MasterController in the level!
    6365    */
    6466    namespace Action
     
    9395            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);         
    9496               
    95             virtual void tick(float dt);
     97            /**
     98            @brief
     99                tick is called every tick by Game (?).
     100                In tick ship flies and fires.
     101            */
     102            virtual void tick(float dt);   
    96103            /**
    97104            @brief
     
    175182
    176183            virtual void stayNearProtect();
    177             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
     184            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. Only gets called by MasterController
    178185            virtual void takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b);
    179186
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

    r10953 r10955  
    4949            CommonController(Context* context);
    5050            virtual ~CommonController();
    51             virtual void action(){}; //<! action() is called in regular intervals managing the bot's behaviour.
    5251            static float randomInRange(float a, float b);
    5352            static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2);
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h

    r10915 r10955  
    3636namespace orxonox
    3737{
     38    /**
     39        @note
     40        ActionpointController will not work, if there is no MasterController in the level!
     41    */
    3842    class _OrxonoxExport DivisionController : public ActionpointController
    3943    {
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.h

    r10953 r10955  
    3939        FightingController stores all the fighting methods and member variables of AI.
    4040        Main methods here are maneuver() and dodge().
     41   
     42    @note
     43        ActionpointController will not work, if there is no MasterController in the level!
    4144    */
    4245    class _OrxonoxExport FightingController : public FlyingController
     
    5962            bool bShooting_;
    6063            bool canFire(); //<! check if target_ is in radius and if this is looking at target_
    61 
     64            virtual void action(){};//<! action() is called in regular intervals managing the bot's behaviour. Only gets called by MasterController, is implemented in ActionpointController
    6265        protected:
    6366            void setTarget(ControllableEntity* target); //set a target to shoot at
  • code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc

    r10954 r10955  
    5858        if (this->ticks_ == 1)
    5959        {
     60            //fill the vector in the first tick
    6061            for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
    6162            {
     
    6970        else
    7071        {
     72
    7173            if (this->controllers_.empty())
    7274                return;
    7375
     76            //iterate over vecotr with the index, keep index in boundaries
    7477            if (this->indexOfCurrentController_ >= this->controllers_.size())
    7578            {
    7679                this->indexOfCurrentController_ = 0;
    7780            }
     81            //each 9 ticks index is incremented
    7882            if (this->numberOfTicksPassedSinceLastActionCall_ >= 9)
    7983            {
     
    8387            if (this->numberOfTicksPassedSinceLastActionCall_ > 0)
    8488            {
     89                //call maneuver for current index
    8590                if (this->numberOfTicksPassedSinceLastActionCall_ == 3)
    8691                {
     
    95100                else if (this->numberOfTicksPassedSinceLastActionCall_ == 6)
    96101                {
     102                    //call canFire for current index
    97103                    if (!this->controllers_.at(this->indexOfCurrentController_))
    98104                    {
     
    107113            else
    108114            {
     115                //call action for current index
    109116                if (!this->controllers_.at(this->indexOfCurrentController_))
    110117                {
  • code/branches/campaignHS15/src/orxonox/controllers/MasterController.h

    r10954 r10955  
    3737namespace orxonox
    3838{
     39    /**
     40    @brief
     41      calles action(), maneuver() and canFire() methods of all the ActionpointControllers in level.
     42      Only one instance of MasterController is to be placed in level.
     43      If no MasterController is initialized, none of ActionpointControllers will work.
     44      Example:
     45      <Pawn position = "100000, 100000, 100000">
     46        <controller>
     47          <MasterController>
     48          </MasterController>
     49        </controller>
     50      </Pawn>
     51    */
    3952    class _OrxonoxExport MasterController : public FightingController, public Tickable
    4053    {
     
    5467         
    5568        private:
    56             std::vector<WeakPtr<FightingController> > controllers_;
    57             size_t indexOfCurrentController_;
     69            std::vector<WeakPtr<FightingController> > controllers_;  //<! vector of controllers, which action(), canFire() and maneuver() methods are to be called
     70            size_t indexOfCurrentController_;                        //<! index of current controller
    5871            unsigned int numberOfTicksPassedSinceLastActionCall_;
    59             unsigned int ticks_;     //<! local tick counter           
     72            unsigned int ticks_;                                     //<! local tick counter           
    6073
    6174    };
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.h

    r10935 r10955  
    3535namespace orxonox
    3636{
     37    /**
     38        @note
     39        ActionpointController will not work, if there is no MasterController in the level!
     40    */
    3741    class _OrxonoxExport SectionController : public ActionpointController
    3842    {
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h

    r10935 r10955  
    3636namespace orxonox
    3737{
     38    /**
     39        @note
     40        ActionpointController will not work, if there is no MasterController in the level!
     41    */
    3842    class _OrxonoxExport WingmanController : public ActionpointController
    3943    {
Note: See TracChangeset for help on using the changeset viewer.