Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

cleaned up a bit

File:
1 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    {
Note: See TracChangeset for help on using the changeset viewer.