Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

replaced tabs with spaces. no changes in code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 }
Note: See TracChangeset for help on using the changeset viewer.