Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 31, 2015, 5:31:23 PM (9 years ago)
Author:
landauf
Message:

replaced tabs with spaces. no changes in code.

Location:
code/branches/presentationFS14/src/modules/objects/controllers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationFS14/src/modules/objects/controllers/TeamTargetProxy.cc

    r10072 r10215  
    3333namespace orxonox
    3434{
    35         RegisterClass(TeamTargetProxy);
     35    RegisterClass(TeamTargetProxy);
    3636
    3737   /**
     
    4242       The context
    4343    */
    44         TeamTargetProxy::TeamTargetProxy(Context* context) : FormationController(context)
    45         {
    46                 RegisterObject(TeamTargetProxy);
     44    TeamTargetProxy::TeamTargetProxy(Context* context) : FormationController(context)
     45    {
     46        RegisterObject(TeamTargetProxy);
    4747
    48                 this->once_ = false;
    49         }
     48        this->once_ = false;
     49    }
    5050
    5151    /**
     
    5353        Destructor. Nothing to see here.
    5454     */
    55         TeamTargetProxy::~TeamTargetProxy()
    56         {
    57         }
     55    TeamTargetProxy::~TeamTargetProxy()
     56    {
     57    }
    5858
    5959    /**
     
    6363        That's all there is.
    6464    */
    65         void TeamTargetProxy::tick(float dt)
    66         {
    67             if (!this->isActive() || !this->getControllableEntity())
    68                 return;
     65    void TeamTargetProxy::tick(float dt)
     66    {
     67        if (!this->isActive() || !this->getControllableEntity())
     68            return;
    6969
    7070        ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent());
     
    102102            }
    103103        }
    104         }
     104    }
    105105}
  • code/branches/presentationFS14/src/modules/objects/controllers/TeamTargetProxy.h

    r10072 r10215  
    3535 namespace orxonox
    3636 {
    37         /**
    38                 @brief
    39                 A controller, that just copies the team and the target of a parent for itself and it's controllable entity.
     37    /**
     38        @brief
     39        A controller, that just copies the team and the target of a parent for itself and it's controllable entity.
    4040
    41                 Useful for following (and similar) situations: (-> means attached to)
    42                         turret (rotates) -> some kind of turret base (looks nice) -> spaceship (flies around)
    43                         The turret has a controller that wants to copy the spaceship's target and team. In this case it doesn't work though,
    44                         because the turret isn't directly attached to the spaceship. Here's where this controller comes in. Drawback: the base
    45                         has to be controllable and ticks every second (performance?)
    46         */
    47         class _OrxonoxExport TeamTargetProxy : public FormationController, public Tickable
    48         {
    49                 public:
    50                         TeamTargetProxy(Context* context);
    51                         virtual ~TeamTargetProxy();
     41        Useful for following (and similar) situations: (-> means attached to)
     42            turret (rotates) -> some kind of turret base (looks nice) -> spaceship (flies around)
     43            The turret has a controller that wants to copy the spaceship's target and team. In this case it doesn't work though,
     44            because the turret isn't directly attached to the spaceship. Here's where this controller comes in. Drawback: the base
     45            has to be controllable and ticks every second (performance?)
     46    */
     47    class _OrxonoxExport TeamTargetProxy : public FormationController, public Tickable
     48    {
     49        public:
     50            TeamTargetProxy(Context* context);
     51            virtual ~TeamTargetProxy();
    5252
    53                         virtual void tick(float dt);
     53            virtual void tick(float dt);
    5454
    55                 private:
    56                         bool once_; //!< Flag for executing code in the tick function only once.
    57         };
     55        private:
     56            bool once_; //!< Flag for executing code in the tick function only once.
     57    };
    5858 }
    5959
  • code/branches/presentationFS14/src/modules/objects/controllers/TurretController.cc

    r10072 r10215  
    3333 namespace orxonox
    3434 {
    35         RegisterClass(TurretController);
     35    RegisterClass(TurretController);
    3636
    3737    /**
     
    4242        The context
    4343    */
    44         TurretController::TurretController(Context* context) : ArtificialController(context)
    45         {
    46                 RegisterObject(TurretController);
    47 
    48                 this->once_ = false;
    49 
    50         }
     44    TurretController::TurretController(Context* context) : ArtificialController(context)
     45    {
     46        RegisterObject(TurretController);
     47
     48        this->once_ = false;
     49
     50    }
    5151
    5252    /**
     
    5454        Destructor. Nothing to see here.
    5555    */
    56         TurretController::~TurretController()
    57         {
    58 
    59         }
     56    TurretController::~TurretController()
     57    {
     58
     59    }
    6060
    6161    /**
     
    6969        The function that scores the pawns.
    7070    */
    71         void TurretController::searchTarget()
    72         {
     71    void TurretController::searchTarget()
     72    {
    7373        Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
    7474
     
    7676        if(this->target_ && turret->isInRange(target_) != -1.f && !FormationController::sameTeam(turret, this->target_, this->getGametype()))
    7777        {
    78                 return;
     78            return;
    7979        }
    8080        else
    8181        {
    82                 this->forgetTarget();
    83                 turret->setTarget(0);
     82            this->forgetTarget();
     83            turret->setTarget(0);
    8484        }
    8585
     
    8888        if(parent)
    8989        {
    90                 Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
    91                 if(parenttarget && turret->isInRange(parenttarget))
    92                 {
    93                         this->setTarget(parenttarget);
    94                         turret->setTarget(parenttarget);
    95                         return;
    96                 }
     90            Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
     91            if(parenttarget && turret->isInRange(parenttarget))
     92            {
     93                this->setTarget(parenttarget);
     94                turret->setTarget(parenttarget);
     95                return;
     96            }
    9797        }
    9898
     
    101101        Pawn* minScorePawn = 0;
    102102
    103                 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)     
    104         {
    105                 Pawn* entity = orxonox_cast<Pawn*>(*it);
     103        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
     104        {
     105            Pawn* entity = orxonox_cast<Pawn*>(*it);
    106106            if (!entity || FormationController::sameTeam(this->getControllableEntity(), entity, this->getGametype()))
    107                 continue;
     107                continue;
    108108            tempScore = turret->isInRange(entity);
    109109            if(tempScore != -1.f)
    110110            {
    111                 if(tempScore < minScore)
    112                 {
    113                         minScore = tempScore;
    114                         minScorePawn = entity;
    115                 }
    116             }
    117         }
     111                if(tempScore < minScore)
     112                {
     113                    minScore = tempScore;
     114                    minScorePawn = entity;
     115                }
     116            }
     117        }
    118118        this->setTarget(minScorePawn);
    119119        turret->setTarget(minScorePawn);
    120         }
     120    }
    121121
    122122    /**
     
    124124        Tests, if the turret is looking at the target, with a specified tolerance
    125125
    126                 This uses the world position as opposed to the local position in the old version.
    127 
    128                 @param angle
    129                 The tolerance, in radians
     126        This uses the world position as opposed to the local position in the old version.
     127
     128        @param angle
     129        The tolerance, in radians
    130130    */
    131131    bool TurretController::isLookingAtTargetNew(float angle) const
     
    140140        The more health and distance a pawn has, the higher the score. This means lower equals better.
    141141
    142                 @param pawn
    143                 The pawn to score
    144 
    145                 @param distance
    146                 The distance. Can be squared or normed, doesn't matter as long as all are treated the same.
     142        @param pawn
     143        The pawn to score
     144
     145        @param distance
     146        The distance. Can be squared or normed, doesn't matter as long as all are treated the same.
    147147    */   
    148         float TurretController::targetScore(Pawn* pawn, float distance) const
    149         {
    150                 return pawn->getHealth()/pawn->getMaxHealth() + distance;
    151         }
    152 
    153     /**
    154         @brief
    155         Does all the controlling of the turret.
    156 
    157         If the turret has a parent, copies the team from there, if it's not already set.
    158         Other actions are: Search a target. If a target has been found, aim and shoot at it.
    159     */
    160         void TurretController::tick(float dt)
    161         {
    162             if (!this->isActive() || !this->getControllableEntity())
    163                 return;
     148    float TurretController::targetScore(Pawn* pawn, float distance) const
     149    {
     150        return pawn->getHealth()/pawn->getMaxHealth() + distance;
     151    }
     152
     153    /**
     154        @brief
     155        Does all the controlling of the turret.
     156
     157        If the turret has a parent, copies the team from there, if it's not already set.
     158        Other actions are: Search a target. If a target has been found, aim and shoot at it.
     159    */
     160    void TurretController::tick(float dt)
     161    {
     162        if (!this->isActive() || !this->getControllableEntity())
     163            return;
    164164
    165165
     
    171171
    172172        if(!this->once_)
    173                 this->once_ = true;
     173            this->once_ = true;
    174174     
    175175        //Teams aren't set immediately, after creation, so we have to check every tick...
     
    188188        }
    189189
    190                 this->searchTarget();
    191                 if(this->target_)
    192                 {
    193                         Turret* turret = orxonox_cast<Turret*> (this->getControllableEntity());
    194                         this->aimAtTarget();
    195                         turret->aimAtPosition(target_->getWorldPosition());
    196                         if(this->isLookingAtTargetNew(Degree(5).valueRadians()))
    197                         {
    198                                 this->getControllableEntity()->fire(0);
    199                         }
    200                 }
    201         }
     190        this->searchTarget();
     191        if(this->target_)
     192        {
     193            Turret* turret = orxonox_cast<Turret*> (this->getControllableEntity());
     194            this->aimAtTarget();
     195            turret->aimAtPosition(target_->getWorldPosition());
     196            if(this->isLookingAtTargetNew(Degree(5).valueRadians()))
     197            {
     198                this->getControllableEntity()->fire(0);
     199            }
     200        }
     201    }
    202202 }
  • code/branches/presentationFS14/src/modules/objects/controllers/TurretController.h

    r10072 r10215  
    3939 namespace orxonox
    4040 {
    41         /**
    42                 @brief
    43                 Controller for turrets. Chooses a target, and makes the turret aim/shoot at it.
     41    /**
     42        @brief
     43        Controller for turrets. Chooses a target, and makes the turret aim/shoot at it.
    4444
    45                 The controllableEntity gets casted to Turret, so this controller won't work for anything else.
    46         */
    47         class _OrxonoxExport TurretController : public ArtificialController, public Tickable
    48         {
    49                 public:
    50                         TurretController(Context* context);
    51                         virtual ~TurretController();
     45        The controllableEntity gets casted to Turret, so this controller won't work for anything else.
     46    */
     47    class _OrxonoxExport TurretController : public ArtificialController, public Tickable
     48    {
     49        public:
     50            TurretController(Context* context);
     51            virtual ~TurretController();
    5252
    53                         virtual void tick(float dt);
     53            virtual void tick(float dt);
    5454
    55                 private:
     55        private:
    5656
    57                         void searchTarget();
    58                         bool isLookingAtTargetNew(float angle) const;
    59                         float targetScore(Pawn* pawn, float distance) const;
     57            void searchTarget();
     58            bool isLookingAtTargetNew(float angle) const;
     59            float targetScore(Pawn* pawn, float distance) const;
    6060
    61                         bool once_; //!< Flag for executing code in the tick function only once.
    62         };
     61            bool once_; //!< Flag for executing code in the tick function only once.
     62    };
    6363 }
    6464
Note: See TracChangeset for help on using the changeset viewer.