Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10968


Ignore:
Timestamp:
Dec 11, 2015, 3:16:48 PM (8 years ago)
Author:
gania
Message:

a little clean up

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

Legend:

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

    r10958 r10968  
    5353        this->bDefaultPatrol_ = true;
    5454        this->bDefaultFightAll_ = true;
    55         this->stop_ = false;
    5655        RegisterObject(ActionpointController);
    5756
     
    7574    void ActionpointController::tick(float dt)
    7675    {
    77         if (!this || !this->getControllableEntity() || !this->isActive() || this->stop_)
     76        if (!this || !this->getControllableEntity() || !this->isActive())
    7877            return;
    7978
     
    733732        if (!this || !this->getControllableEntity())
    734733            return;
    735 
    736         //if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
    737         {
    738             if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
    739             {
    740                 if (!this || !this->getControllableEntity())
    741                     return;
    742                 Pawn* newTarget = this->closestTarget();
    743                 if ( newTarget &&
    744                     CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
    745                         <= this->attackRange_ )
    746                 {
    747                     if (!this || !this->getControllableEntity())
    748                         return;
    749                     this->setTarget(newTarget);
    750                     if (this->bLoop_ && !this->bPatrolling_)
    751                     {
    752                         Point p = { Action::FIGHT, "", Vector3::ZERO, true };
    753                         this->loopActionpoints_.push_back(p);
    754                     }
    755                     else if (!this->bPatrolling_)
    756                     {
    757                         //orxout (internal_error) << "found new target " << CommonController::getName(newTarget) <<endl;
    758                         Point p = { Action::FIGHT, "", Vector3::ZERO, false };
    759                         this->parsedActionpoints_.push_back(p);
    760                     }
    761                     this->bPatrolling_ = true;
    762                     this->executeActionpoint();
    763                 }
     734       
     735        if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
     736        {
     737            if (!this || !this->getControllableEntity())
     738                return;
     739            Pawn* newTarget = this->closestTarget();
     740            if ( newTarget &&
     741                CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
     742                    <= this->attackRange_ )
     743            {
     744                if (!this || !this->getControllableEntity())
     745                    return;
     746                this->setTarget(newTarget);
     747                if (this->bLoop_ && !this->bPatrolling_)
     748                {
     749                    Point p = { Action::FIGHT, "", Vector3::ZERO, true };
     750                    this->loopActionpoints_.push_back(p);
     751                }
     752                else if (!this->bPatrolling_)
     753                {
     754                    Point p = { Action::FIGHT, "", Vector3::ZERO, false };
     755                    this->parsedActionpoints_.push_back(p);
     756                }
     757                this->bPatrolling_ = true;
     758                this->executeActionpoint();
    764759            }
    765760        }
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10955 r10968  
    216216                std::vector<Point > parsedActionpoints_;//<! actionpoints as they are stored here after being parsed from XML
    217217                std::vector<Point > loopActionpoints_;  //<! actionpoints that are to be looped
    218                 bool bInLoop_;
     218                bool bInLoop_;                          //<! variable for addActionpoint method
    219219                bool bLoop_;                            //<! is state machine looping?
    220                 bool bEndLoop_;                   
     220                bool bEndLoop_;                         //<! variable for addActionpoint method
    221221                bool bTakenOver_;                       //<! are actionpoints taken over from the leader when he died? if yes, top actionpoint
    222222                                                        //<! is to be executed for the state machine to start working
     
    250250            //----[Actionpoint methods]----         
    251251
    252                 bool bDefaultFightAll_;
    253 
    254                 bool bPatrolling_;
    255                 bool bDefaultPatrol_;
    256                 bool stop_;
     252                bool bDefaultFightAll_;     //<! if true, when no action set, this will fight all
     253
     254                bool bPatrolling_;        //<! true if current action_ is FIGHT because this found enemies that are close, need this to correctly go back to looping if was looping
     255                bool bDefaultPatrol_;       //<! if true, this will look out for enemies that are close if this is just flying or doing nothing
    257256                unsigned int ticks_;     //<! local tick counter           
    258 
    259257    };
    260258}
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc

    r10953 r10968  
    2323 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
     
    7373    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
    7474    {
    75         //uncomment following code if functions stops working due to being a hack
    76         /*if (!entity1 || !entity2)
    77             return false;
    78         return entity1->getTeam() == entity2->getTeam();*/
     75       
    7976        if (!entity1 || !entity2)
    8077            return false;
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

    r10955 r10968  
    2323 *      Gani Aliguzhinov
    2424 *   Co-authors:
    25  *      Dominik Solenicki
     25 *      ...
    2626 *
    2727 */
     
    4949            CommonController(Context* context);
    5050            virtual ~CommonController();
    51             static float randomInRange(float a, float b);
    52             static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2);
     51            static float randomInRange(float a, float b);   //<! returns random number from a to b
     52            static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2);    //<! returns distance between arguments
    5353            static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
    54             static bool isLooking(const ControllableEntity* entityThatLooks, const ControllableEntity* entityBeingLookedAt, float angle ) ;
    55             static std::string getName(const Pawn* entity ) ;           
     54            static bool isLooking(const ControllableEntity* entityThatLooks, const ControllableEntity* entityBeingLookedAt, float angle) ;
     55            static std::string getName(const Pawn* entity) ;           
    5656    };
    5757}
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10953 r10968  
    7979        if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
    8080        {
     81            //when this dies, its follower will execute all its actionpoints, if follower dies before this, wingman will do this
    8182            if (this->myFollower_)
    8283            {
  • code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc

    r10958 r10968  
    3838    {
    3939        RegisterObject(MasterController);
    40         // orxout(internal_error) << "MasterController was created" << endl;
    41 
    4240        this->controllers_.clear();
    4341        this->numberOfTicksPassedSinceLastActionCall_ = 0;
     
    5048        this->controllers_.clear();
    5149    }
     50    /*HACK*/
     51    //the whole idea is a hack
    5252    void MasterController::tick(float dt)
    5353    {   
     
    5555            return; 
    5656        ++this->ticks_;
    57         //orxout(internal_error) << "Tick = " << this->ticks_ << endl;
    5857        if (this->ticks_ == 1)
    5958        {
     
    6665                this->controllers_.push_back(*it);
    6766            }
    68             //orxout(internal_error) << "I got " << this->controllers_.size() << " controllers" << endl;
    6967        }
    7068        else
    7169        {
    72 
    7370            if (this->controllers_.empty())
    7471                return;
     
    8784            if (this->numberOfTicksPassedSinceLastActionCall_ > 0)
    8885            {
    89                 //call maneuver for current index
    9086                if (this->numberOfTicksPassedSinceLastActionCall_ == 3)
    9187                {
     88                    //check if 0ptr
    9289                    if (!this->controllers_.at(this->indexOfCurrentController_))
    9390                    {
     
    9592                        return;
    9693                    }
    97                     //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
     94                    //call maneuver for current index
    9895                    this->controllers_.at(this->indexOfCurrentController_)->maneuver();
    9996                }
    10097                else if (this->numberOfTicksPassedSinceLastActionCall_ == 6)
    10198                {
    102                     //call canFire for current index
     99                    //check if 0ptr
    103100                    if (!this->controllers_.at(this->indexOfCurrentController_))
    104101                    {
     
    106103                        return;
    107104                    }
    108                     //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
     105                    //call canFire for current index
    109106                    this->controllers_.at(this->indexOfCurrentController_)->bShooting_ = this->controllers_.at(this->indexOfCurrentController_)->canFire();   
    110107                }
     
    113110            else
    114111            {
    115                 //call action for current index
     112                //check if 0ptr
    116113                if (!this->controllers_.at(this->indexOfCurrentController_))
    117114                {
     
    119116                    return;
    120117                }
    121                 //orxout (internal_error) << "Executing action of Controller # " << this->indexOfCurrentController_ << endl;
    122                 this->controllers_.at(this->indexOfCurrentController_)->action();   
     118                //call action for current index
     119                this->controllers_.at(this->indexOfCurrentController_)->action();   
     120                 
    123121                //bCopyOrientation makes ship oscillate like crazy if set to true all the time.s
    124122                this->controllers_.at(this->indexOfCurrentController_)->bCopyOrientation_ = this->ticks_ % 3 == 0;
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10946 r10968  
    8484
    8585            this->myDivisionLeader_ = newDivisionLeader;
    86             //spread copyOrientation called equally among the division
    87 
    8886        }
    8987        //----If have leader----
     
    111109            {
    112110                this->keepFormation();
    113                 //orxout (internal_error) << "Keeping formation" << endl;
    114 
    115111            }
    116112            else if (!this->myDivisionLeader_->bKeepFormation_)
     
    162158                            foundTarget = true;
    163159                            target =  (*itP);
    164                             //orxout(internal_error) << "Found target" << endl;
    165160                            break;
    166161                        }
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.h

    r10955 r10968  
    6666        protected:       
    6767            //----action must only be managed by this----     
    68                 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
     68                virtual void action(); //<! action() is called in regular intervals by MasterController managing the bot's behaviour.
    6969                Vector3 getFormationPosition ();
    7070                void keepFormation();
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10953 r10968  
    9999        else if (this->myLeader_)
    100100        {
    101             if (this->myLeader_->bKeepFormation_ || !(this->myLeader_->getAction() == Action::FIGHT || this->myLeader_->getAction() == Action::FIGHTALL
     101            if (this->myLeader_->bKeepFormation_ || !(this->myLeader_->getAction() == Action::FIGHT
     102                || this->myLeader_->getAction() == Action::FIGHTALL
    102103                || this->myLeader_->getAction() == Action::ATTACK))
    103104            {
     
    148149        else
    149150        {
    150 
    151151            switch (this->formationMode_){
    152152                case FormationMode::WALL:
     
    215215        {
    216216            //----Racing conditions----
     217            /*TODO: racing condition check is wrong and redundant, as there is no multithreading here, ticks get called one after another,
     218            so it can be simplified to a check of whether leader got a wingman*/
    217219            if (closestLeader->setWingman(orxonox_cast<ActionpointController*>(this)))
    218220            {
    219                 if (closestLeader->getIdentifier()->getName() == "SectionController")
    220                 {
    221                     this->actionTime_ = 1.6f;
    222                 }
    223                 else
    224                 {
    225                     this->actionTime_ = 2.0f;
    226                 }
    227221                return closestLeader;
    228222            }
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h

    r10955 r10968  
    7373                WeakPtr<ActionpointController> myLeader_;
    7474                bool bFirstAction_;
    75                 float actionTime_;
    7675
    7776
Note: See TracChangeset for help on using the changeset viewer.