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/SpaceRace.cc

    r9016 r9260  
    2929#include "SpaceRace.h"
    3030
    31 
    3231#include "items/Engine.h"
    3332
     
    4645    {
    4746        RegisterObject(SpaceRace);
    48        
     47
     48        this->cantMove_ = false;
    4949        this->bTimeIsUp_ = false;
    50         this->numberOfBots_ = 0;
    51         this->cantMove_=false;
    52        
    5350    }
    54        
    55    
    56   // void SpaceRace::SetConfigValues(){
    57     //SUPER(Gametype,setConfigValues);
    58     //this->Gametype::SetConfigValue(initialStartCountdown_, 3.0f);}
    5951
    6052    void SpaceRace::end()
     
    6254        this->Gametype::end();
    6355
     56        this->clock_.capture();
     57        int s = this->clock_.getSeconds();
     58        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
     59        std::string message;
     60
    6461        if (this->bTimeIsUp_)
    6562        {
    66             this->clock_.capture();
    67             int s = this->clock_.getSeconds();
    68             int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    69             const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
     63            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
    7064                        + "You didn't reach the check point  before the time limit. You lose!";
    71             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    72             ChatManager::message(message);
    7365        }
    7466        else
    7567        {
    76             this->clock_.capture();
    77             int s = this->clock_.getSeconds();
    78             int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    79             const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
     68            message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
    8069                        + "." + multi_cast<std::string>(ms) + " seconds.";
    81             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    82             ChatManager::message(message);
     70        }
    8371
    84             float time = this->clock_.getSecondsPrecise();
    85             this->scores_.insert(time);
    86             std::set<float>::iterator it;
    87            
    88 
    89         }
     72        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     73        ChatManager::message(message);
    9074    }
    9175
    9276    void SpaceRace::start()
    9377    {
     78        this->spawnPlayersIfRequested();
     79        Gametype::checkStart();
     80        this->cantMove_ = true;
    9481
    95         this->spawnPlayersIfRequested();
    96         Gametype::checkStart();
    97         this->cantMove_=true;
    98        
    99         for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
    100         {
     82        for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
    10183            it->setActive(false);
    102            
    103         }
    104         this->addBots(this->numberOfBots_);
     84
     85        this->addBots(this->numberOfBots_);
    10586    }
    106    
     87
    10788    void SpaceRace::tick(float dt)
    10889    {
    10990        SUPER(SpaceRace,tick,dt);
    110    
    111         if(!this->isStartCountdownRunning() && this->cantMove_)
     91
     92        if (!this->isStartCountdownRunning() && this->cantMove_)
    11293        {
    113             for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
    114             {
     94            for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
    11595                it->setActive(true);
    116                
    117             }
     96
    11897            this->cantMove_= false;
    119            
    120             std::string message("The match has started! Reach the check points as quickly as possible!");
     98
     99            std::string message = "The match has started! Reach the check points as quickly as possible!";
    121100            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    122             ChatManager::message(message);           
     101            ChatManager::message(message);
    123102        }
    124    
    125103    }
    126104
    127    
    128    
    129     void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl)
     105    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
    130106    {
    131         this->checkpointReached_[pl]=index;
     107        int index = checkpoint->getCheckpointIndex();
     108        this->checkpointReached_[player] = index;
    132109        this->clock_.capture();
    133110        int s = this->clock_.getSeconds();
    134         int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
     111        int ms = this->clock_.getMilliseconds() % 1000;
    135112        const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
    136             + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
    137             + " seconds.";// Message is too long for a normal screen.
     113            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
    138114        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    139115        ChatManager::message(message);
    140116    }
    141    
    142     void SpaceRace::newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl)
    143     {   
    144         int index = p->getCheckpointIndex();
    145         this->checkpointReached_[pl]=index;
    146         this->clock_.capture();
    147         int s = this->clock_.getSeconds();
    148         int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    149         const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
    150             + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
    151             + " seconds.";
    152         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    153         ChatManager::message(message);
    154     }
    155        
    156    
     117
    157118    void SpaceRace::playerEntered(PlayerInfo* player)
    158119    {
    159120        Gametype::playerEntered(player);
    160    
    161         this->checkpointReached_[player]=-1;
    162         //this->playersAlive_++;
     121
     122        this->checkpointReached_[player] = -1;
    163123    }
    164    
    165     bool SpaceRace::playerLeft(PlayerInfo* player)
    166     {
    167         return Gametype::playerLeft(player);
    168         // bool valid_player = true;
    169         //if (valid_player)
    170        // {
    171         //    this->playersAlive_--;
    172         //}
    173124
    174        // return valid_player;
    175     }
    176    
    177125    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
    178126    {
Note: See TracChangeset for help on using the changeset viewer.