Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 7, 2015, 8:42:03 PM (9 years ago)
Author:
gania
Message:

converted hack to a legal class

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

Legend:

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

    r10946 r10953  
    3232#include <algorithm>
    3333#include "worldentities/Actionpoint.h"
    34 
    3534namespace orxonox
    3635{
     
    4039    ActionpointController::ActionpointController(Context* context) : FightingController(context)
    4140    {
    42         this->actionpointControllerId_ = 0;
    43         ActionpointController::sTicks_ = 0;
    44         ActionpointController::nextActionpointControllerId_ = 0;
    4541        this->ticks_ = 0;
    4642        this->bPatrolling_ = false;
     
    7571        parsedActionpoints_.clear();
    7672        actionpoints_.clear();
    77         this->actionpointControllerId_ = 0;
    7873
    7974    }
     
    8277        if (!this || !this->getControllableEntity() || !this->isActive() || this->stop_)
    8378            return;
     79
    8480        ++this->ticks_;
    85         // orxout (internal_error) << "this id = " << this->actionpointControllerId_ << endl;
    86         if (ActionpointController::sTicks_ < this->ticks_)
    87         {
    88             // orxout (internal_error) << "total id's = " << ActionpointController::nextActionpointControllerId_ << endl;
    89             ++ActionpointController::sTicks_;
    90         }
    91 
    92         if (!this || !this->getControllableEntity())
    93             return;
    94 
    95         if (ActionpointController::sTicks_ == 1)
    96         {
    97 
    98             this->actionpointControllerId_ = ActionpointController::nextActionpointControllerId_++;
     81        if (this->ticks_ == 1)
     82        {
    9983            std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
    10084            std::reverse(actionpoints_.begin(), actionpoints_.end());
     
    10387                this->action_ = Action::FIGHTALL;
    10488            }
    105             //orxout (internal_error) << "first tick was called by id = " << this->actionpointControllerId_ << ", total = " << ActionpointController::nextActionpointControllerId_ << endl;
    10689        }
    10790
     
    11396            this->moveToTargetPosition(dt);
    11497        }
    115         if (!this || !this->getControllableEntity())
    116             return;
    11798        else if (this->bLookAtTarget_)
    11899        {
     
    125106
    126107        if (timeout_ <= 0)
     108        {   
    127109            this->bFiredRocket_ = false;
    128        
    129 
    130         if (!this || !this->getControllableEntity())
    131             return;
    132         if (this->timeout_ > 0 && this->bFiredRocket_)
     110        }
     111        else if (this->bFiredRocket_)
    133112        {
    134113            --this->timeout_;
    135114        }
    136    
    137 
    138         if (!this || !this->getControllableEntity())
    139             return;
    140         //maneuver every 0.25 sec ->
    141         int step =  4;
    142         if (ActionpointController::sTicks_ % 100 <= 10)
     115
     116        if (!this || !this->getControllableEntity())
     117            return;
     118
     119        if (this->ticks_ % 80 <= 10)
    143120        {
    144121            this->bDodge_ = false;
     
    148125            this->bDodge_ = true;
    149126        }
    150         if (!this || !this->getControllableEntity())
    151             return;
    152         if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1)
    153         {
    154             //orxout (internal_error) << "Team " << this->getControllableEntity()->getTeam() << (this->hasTarget() ? ", got " : ", don't have") << " target" << endl;
    155             this->action();
    156         }
    157 
    158 
    159         if (!this || !this->getControllableEntity())
    160             return;
    161        /* orxout (internal_error) << "id = " << this->actionpointControllerId_ << ", in total # ids = " << ActionpointController::nextActionpointControllerId_
    162         << ", I " << (this->hasTarget() ? "have" : "don't have") << " a target, my team is " << this->getControllableEntity()->getTeam() << endl;
    163        */ if (this->hasTarget() &&  ActionpointController::sTicks_ % (ActionpointController::nextActionpointControllerId_ + 1) == (this->actionpointControllerId_))
    164         {
    165 
    166          
    167             if (!this || !this->getControllableEntity())
    168                 return;
    169             this->maneuver();
    170             if (!this || !this->getControllableEntity())
    171                 return;
    172             this->bShooting_ = this->canFire();
    173 
    174             if (!this || !this->getControllableEntity())
    175                 return;
    176 
    177             if (this->bShooting_)
    178             {
    179                 this->doFire();
    180             }
    181             if (!this || !this->getControllableEntity())
    182                 return;
    183             this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
    184             this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
    185         }
    186        
    187 
     127
     128        if (!this || !this->getControllableEntity())
     129            return;
     130     
     131        if (this->bShooting_)
     132        {
     133            this->doFire();
     134        }
    188135        SUPER(ActionpointController, tick, dt);
    189136    }
     
    193140    void ActionpointController::action()
    194141    {
    195         if (!this || !this->getControllableEntity())
    196             return;
    197 
     142        if (!this || !this->getControllableEntity() || !this->isActive())
     143            return;
     144
     145        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
     146        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
    198147        if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE))
    199148        {
     
    798747        }
    799748    }
    800     unsigned int ActionpointController::nextActionpointControllerId_ = 0;
    801     unsigned int ActionpointController::sTicks_ = 0;
    802749}   
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10946 r10953  
    3535#include "../modules/pickup/PickupSpawner.h"
    3636#include <map>
     37
     38#include <boost/shared_ptr.hpp>
    3739
    3840
     
    246248                bool bDefaultPatrol_;
    247249                bool stop_;
    248                 static unsigned int sTicks_;    //<! a hack? I don't want action() and maneuver() to be called multiple times in a tick, so I keep
    249                                                 //<! track of ticks and if current tick is "assigned" to this object, than I call maneuver()/action()
    250                 static unsigned int nextActionpointControllerId_;    //<! if level has 16 ActionpointControllers, than this variable equals to 17 after first tick
    251                 unsigned int actionpointControllerId_;   //<! integer from 0 to nextActionpointControllerId_, different for every ActionpointController in level
    252250                unsigned int ticks_;     //<! local tick counter           
     251
    253252    };
    254253}
  • code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt

    r10886 r10953  
    1818  FlyingController.cc
    1919  FightingController.cc
     20  MasterController.cc
    2021)
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc

    r10946 r10953  
    4040
    4141    RegisterClass(CommonController);
    42 
    4342    CommonController::CommonController(Context* context): Controller(context)
    4443    {
     
    9392        if (controller)
    9493        {
     94            if (controller->getIdentifier()->getName() == "MasterController")
     95                return true;
    9596            CommonController* ac = orxonox_cast<CommonController*>(controller);
    9697            if (ac)
     
    104105        if (controller)
    105106        {
     107            if (controller->getIdentifier()->getName() == "MasterController")
     108                return true;
    106109            CommonController* ac = orxonox_cast<CommonController*>(controller);
    107110            if (ac)
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

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

    r10946 r10953  
    6565        if (!this->isActive())
    6666            return;   
     67       
    6768        SUPER(DivisionController, tick, dt);
    6869       
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10935 r10953  
    143143        else
    144144        {   
    145             bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
     145            bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f)
    146146                || this->deltaHp < 0;
    147147            this->bKeepFormation_ = false;
     
    220220        }
    221221
    222         return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 10.0f);
     222        return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);
    223223    }
    224224
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.h

    r10934 r10953  
    5555                { return this->target_; }
    5656            bool bKeepFormation_;   //even if action_ == FIGHT, you might still want to keep formation if far enough form the target
    57            
     57            virtual void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on
     58                             //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_.
     59            bool bShooting_;
     60            bool canFire(); //<! check if target_ is in radius and if this is looking at target_
     61
    5862        protected:
    5963            void setTarget(ControllableEntity* target); //set a target to shoot at
     
    6569            void lookAtTarget(float dt);    //<! rotate yourself towards target
    6670
    67             void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on
    68                              //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_.
    6971            void dodge(const Vector3& thisPosition, float diffLength,  Vector3& diffUnit); //<! choose a random Vector3 perpendicular to the difference vector between
    7072                                                                        //<! this and target_ plus or minus some amount in difference vector direction,
    7173                                                                        //<! depending on whether it is better to close up or survive.
    7274            void dodgeTowards (Vector3& position);  //fly towards position and awoid being hit
    73             bool canFire(); //<! check if target_ is in radius and if this is looking at target_
    7475            void doFire();  //<! choose weapon, set aim at target_ and fire
    7576            WeakPtr<ControllableEntity> target_;
     
    8485            bool bDodge_;
    8586            int attackRange_;
    86             bool bShooting_;
    8787            bool bLookAtTarget_;
    8888            float deltaHp;
  • code/branches/campaignHS15/src/orxonox/controllers/FormationController.cc

    r10834 r10953  
    970970        if (controller)
    971971        {
     972            if (controller->getIdentifier()->getName() == "MasterController")
     973                return true;
    972974            FormationController* ac = orxonox_cast<FormationController*>(controller);
    973975            if (ac)
     
    981983        if (controller)
    982984        {
     985            if (controller->getIdentifier()->getName() == "MasterController")
     986                return true;
    983987            FormationController* ac = orxonox_cast<FormationController*>(controller);
    984988            if (ac)
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10946 r10953  
    9595        if (!this->myLeader_)
    9696        {
    97            ActionpointController::action();
    98             if (!this || !this->getControllableEntity())
    99                 return;
    100 
     97            ActionpointController::action();
    10198        }
    10299        else if (this->myLeader_)
Note: See TracChangeset for help on using the changeset viewer.