Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 2, 2012, 10:34:48 PM (12 years ago)
Author:
landauf
Message:

cleaned up new SpaceRace classes (no functional code-changes):

  • formatting
  • naming of variables, arguments, functions
  • unused and duplicate code
  • public member variables
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/gametypes/SpaceRaceManager.cc

    r9016 r9260  
    2121 *
    2222 *   Author:
    23  *     Celine Eggenberger
     23 *      Celine Eggenberger
    2424 *   Co-authors:
    2525 *      ...
     
    4747    {
    4848        RegisterObject(SpaceRaceManager);
    49          
    50         this->firstcheckpointvisible_=false;
    51          
     49
     50        this->firstcheckpointvisible_ = false;
    5251    }
    5352
    5453    SpaceRaceManager::~SpaceRaceManager()
    5554    {
    56         if (this->isInitialized())
     55        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
     56            this->checkpoints_[i]->destroy();
     57    }
     58
     59    void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     60    {
     61        SUPER(SpaceRaceManager, XMLPort, xmlelement, mode);
     62
     63        XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint,  xmlelement, mode);
     64    }
     65
     66    void SpaceRaceManager::tick(float dt)
     67    {
     68        SUPER(SpaceRaceManager,tick,dt);
     69
     70        if (this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_)
    5771        {
    58             for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    59                 this->checkpoints_[i]->destroy();
     72            this->checkpoints_[0]->setRadarVisibility(true);
     73            this->firstcheckpointvisible_ = true;
     74        }
     75
     76        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
     77        {
     78            if (this->checkpoints_[i]->getPlayer() != NULL)
     79                this->checkpointReached(this->checkpoints_[i], this->checkpoints_[i]->getPlayer());
    6080        }
    6181    }
    62    
     82
    6383    void SpaceRaceManager::addCheckpoint(RaceCheckPoint* checkpoint)
    6484    {
     
    7393            return 0;
    7494    }
    75    
    76     int SpaceRaceManager::getIndex(RaceCheckPoint* r)
     95
     96    int SpaceRaceManager::getIndex(RaceCheckPoint* checkpoint)
    7797    {
    7898        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    79             if (this->checkpoints_[i]==r) {return i;}
    80            
     99            if (this->checkpoints_[i] == checkpoint)
     100                return i;
     101
    81102        return -1;
    82103    }
    83    
    84     void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    85     {
    86         SUPER(SpaceRaceManager, XMLPort, xmlelement, mode);
    87104
    88        
    89         XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint,  xmlelement, mode);
    90     }
    91    
    92     void SpaceRaceManager::tick(float dt)
    93     {
    94         SUPER(SpaceRaceManager,tick,dt);
    95      
    96         if(this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_)
    97         {
    98             this->checkpoints_[0]->setRadarVisibility(true);
    99             this->firstcheckpointvisible_=true;
    100         }
    101          
    102         for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    103         {
    104             if(this->checkpoints_[i]->reached_!=NULL)
    105                 this->checkpointReached(this->checkpoints_[i],this->checkpoints_[i]->reached_);
    106         }
    107     }
    108    
    109    
    110105    void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player)
    111106    {
    112107        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    113108        assert(gametype);
    114        
    115         bool b =false;   
    116            
    117         int index=gametype->getCheckpointReached(player);
    118         Vector3 v=Vector3 (-1,-1,-1);
    119         if (index>-1)
     109
     110        bool reachedValidCheckpoint = false;
     111
     112        int index = gametype->getCheckpointReached(player);
     113        if (index > -1)
    120114        {
    121             RaceCheckPoint* tmp= this->getCheckpoint(index);
    122             v= tmp->getNextcheckpoint();
    123        
     115            Vector3 v = this->getCheckpoint(index)->getNextcheckpoint();
     116
    124117            if (this->getCheckpoint(v.x) == check)
    125118            {
    126                 b = true;
    127             }   
    128        
     119                reachedValidCheckpoint = true;
     120            }
    129121            if (this->getCheckpoint(v.y) == check)
    130122            {
    131                 b = true;
    132             }   
     123                reachedValidCheckpoint = true;
     124            }
    133125            if (this->getCheckpoint(v.z) == check)
    134126            {
    135                 b = true;
    136             }   
     127                reachedValidCheckpoint = true;
     128            }
    137129        }
    138130        else
    139131        {
    140             b = (this->getIndex(check) == 0);
     132            reachedValidCheckpoint = (this->getIndex(check) == 0);
    141133        }
    142            
    143         if (gametype && b)
     134
     135        if (gametype && reachedValidCheckpoint)
    144136        {
    145             gametype->clock_.capture();
    146             float time = gametype->clock_.getSecondsPrecise();
    147             if (check->getTimeLimit()!=0 && time > check->getTimeLimit())
     137            gametype->getClock().capture();
     138            float time = gametype->getClock().getSecondsPrecise();
     139            if (check->getTimeLimit() != 0 && time > check->getTimeLimit())
    148140            {
    149                 gametype->timeIsUp();
     141                gametype->setTimeIsUp();
    150142                gametype->end();
    151143            }
    152             else if (check->getLast())
     144            else if (check->isLast())
    153145                gametype->end();
    154146            else
    155                                 {
    156                 if (index > -1)this->setRadVis(player,false);
    157                         else this->getCheckpoint(0)->setRadarVisibility(false);
    158                 gametype->newCheckpointReached(check,player);
    159                
    160                
     147                        {
     148                if (index > -1)
     149                    this->setRadVis(player, false);
     150                else
     151                    this->getCheckpoint(0)->setRadarVisibility(false);
     152
     153                gametype->newCheckpointReached(check, player);
    161154                this->setRadVis(player, true);
    162155            }
    163156        }
    164         check->reached_=NULL;
     157
     158        check->resetPlayer();
    165159    }
    166    
    167     void SpaceRaceManager::setRadVis(PlayerInfo* player, bool b)
     160
     161    void SpaceRaceManager::setRadVis(PlayerInfo* player, bool bVisible)
    168162    {
    169163        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    170164        assert(gametype);
    171165        int index = gametype->getCheckpointReached(player);
    172         Vector3 v = Vector3(-1,-1,-1);
    173         RaceCheckPoint* tmp = this->getCheckpoint(index);
    174         v = tmp->getNextcheckpoint();
    175    
    176         if(v.x > -1)
     166        Vector3 v = this->getCheckpoint(index)->getNextcheckpoint();
     167
     168        if (v.x > -1)
    177169        {
    178             this->getCheckpoint(v.x)->setRadarVisibility(b);
     170            this->getCheckpoint(v.x)->setRadarVisibility(bVisible);
    179171            this->getCheckpoint(v.x)->settingsChanged();
    180172        }
    181         if(v.y > -1)
     173        if (v.y > -1)
    182174        {
    183             this->getCheckpoint(v.y)->setRadarVisibility(b);
     175            this->getCheckpoint(v.y)->setRadarVisibility(bVisible);
    184176            this->getCheckpoint(v.y)->settingsChanged();
    185177        }
    186         if(v.z > -1)
     178        if (v.z > -1)
    187179        {
    188             this->getCheckpoint(v.z)->setRadarVisibility(b);
    189            this->getCheckpoint(v.z)->settingsChanged();
     180            this->getCheckpoint(v.z)->setRadarVisibility(bVisible);
     181            this->getCheckpoint(v.z)->settingsChanged();
    190182        }
    191        
    192        
    193183    }
    194    
    195184}
Note: See TracChangeset for help on using the changeset viewer.