Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9262 for code/trunk


Ignore:
Timestamp:
Jun 2, 2012, 11:08:21 PM (12 years ago)
Author:
landauf
Message:

fixed bug in SpaceRaceManager - it used the wrong index to identify Checkpoints (the order in which they appear in the XML file instead of RaceCheckPoint::getCheckpointIndex())
+ some more cleanup

Location:
code/trunk/src/modules/gametypes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/gametypes/RaceCheckPoint.h

    r9260 r9262  
    5656            inline void setNextcheckpoint(const Vector3& checkpoints)
    5757                { this->nextcheckpoints_ = checkpoints; }
    58             inline void setNextcheckpoint(float x, float y, float z)
    59                 { this->setNextcheckpoint(Vector3(x, y, z)); }
    6058            inline const Vector3& getNextcheckpoint() const
    6159                { return this->nextcheckpoints_; }
  • code/trunk/src/modules/gametypes/SpaceRace.cc

    r9261 r9262  
    7878        SUPER(SpaceRace,tick,dt);
    7979
     80        // spawn the players already when the countdown starts, but deactivate their engines
    8081        if (this->isStartCountdownRunning() && !this->cantMove_)
    8182        {
     
    8788        }
    8889
     90        // activate the engines again if the countdown ends
    8991        if (!this->isStartCountdownRunning() && this->cantMove_)
    9092        {
     
    104106        int index = checkpoint->getCheckpointIndex();
    105107        this->checkpointReached_[player] = index;
     108
    106109        this->clock_.capture();
    107110        int s = this->clock_.getSeconds();
    108111        int ms = this->clock_.getMilliseconds() % 1000;
    109         const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
     112
     113        const std::string& message = "Checkpoint " + multi_cast<std::string>(index + 1)
    110114            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
    111115        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
  • code/trunk/src/modules/gametypes/SpaceRace.h

    r9261 r9262  
    6161            virtual void end();
    6262
    63             virtual void newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player);
    64 
    65             inline void setCheckpointReached(int index, PlayerInfo* player)
    66                 { this->checkpointReached_[player] = index;}
     63            void newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player);
    6764            inline int getCheckpointReached(PlayerInfo* player)
    6865                { return this->checkpointReached_[player]; }
     
    8178
    8279        private:
    83             bool cantMove_;
     80            bool cantMove_;                                ///< Helper variable, used to stall the engines before the race starts.
    8481            std::map<PlayerInfo*, int> checkpointReached_; ///< The number of the last check point reached by each player.
    8582            bool bTimeIsUp_;                               ///< True if one of the check points is reached too late.
  • code/trunk/src/modules/gametypes/SpaceRaceManager.cc

    r9260 r9262  
    9494    }
    9595
    96     int SpaceRaceManager::getIndex(RaceCheckPoint* checkpoint)
     96    /**
     97        @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex).
     98    */
     99    RaceCheckPoint* SpaceRaceManager::findCheckpoint(int index) const
    97100    {
    98101        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    99             if (this->checkpoints_[i] == checkpoint)
    100                 return i;
    101 
    102         return -1;
     102            if (this->checkpoints_[i]->getCheckpointIndex() == index)
     103                return this->checkpoints_[i];
     104        return 0;
    103105    }
    104106
     
    113115        if (index > -1)
    114116        {
    115             Vector3 v = this->getCheckpoint(index)->getNextcheckpoint();
     117            Vector3 v = this->findCheckpoint(index)->getNextcheckpoint();
    116118
    117             if (this->getCheckpoint(v.x) == check)
     119            if (this->findCheckpoint(v.x) == check)
    118120            {
    119121                reachedValidCheckpoint = true;
    120122            }
    121             if (this->getCheckpoint(v.y) == check)
     123            if (this->findCheckpoint(v.y) == check)
    122124            {
    123125                reachedValidCheckpoint = true;
    124126            }
    125             if (this->getCheckpoint(v.z) == check)
     127            if (this->findCheckpoint(v.z) == check)
    126128            {
    127129                reachedValidCheckpoint = true;
     
    130132        else
    131133        {
    132             reachedValidCheckpoint = (this->getIndex(check) == 0);
     134            reachedValidCheckpoint = (check->getCheckpointIndex() == 0);
    133135        }
    134136
     
    147149                        {
    148150                if (index > -1)
    149                     this->setRadVis(player, false);
     151                    this->setRadarVisibility(player, false);
    150152                else
    151                     this->getCheckpoint(0)->setRadarVisibility(false);
     153                    this->findCheckpoint(0)->setRadarVisibility(false);
    152154
    153155                gametype->newCheckpointReached(check, player);
    154                 this->setRadVis(player, true);
     156                this->setRadarVisibility(player, true);
    155157            }
    156158        }
     
    159161    }
    160162
    161     void SpaceRaceManager::setRadVis(PlayerInfo* player, bool bVisible)
     163    void SpaceRaceManager::setRadarVisibility(PlayerInfo* player, bool bVisible)
    162164    {
    163165        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    164166        assert(gametype);
    165167        int index = gametype->getCheckpointReached(player);
    166         Vector3 v = this->getCheckpoint(index)->getNextcheckpoint();
     168        Vector3 v = this->findCheckpoint(index)->getNextcheckpoint();
    167169
    168170        if (v.x > -1)
    169171        {
    170             this->getCheckpoint(v.x)->setRadarVisibility(bVisible);
    171             this->getCheckpoint(v.x)->settingsChanged();
     172            this->findCheckpoint(v.x)->setRadarVisibility(bVisible);
     173            this->findCheckpoint(v.x)->settingsChanged();
    172174        }
    173175        if (v.y > -1)
    174176        {
    175             this->getCheckpoint(v.y)->setRadarVisibility(bVisible);
    176             this->getCheckpoint(v.y)->settingsChanged();
     177            this->findCheckpoint(v.y)->setRadarVisibility(bVisible);
     178            this->findCheckpoint(v.y)->settingsChanged();
    177179        }
    178180        if (v.z > -1)
    179181        {
    180             this->getCheckpoint(v.z)->setRadarVisibility(bVisible);
    181             this->getCheckpoint(v.z)->settingsChanged();
     182            this->findCheckpoint(v.z)->setRadarVisibility(bVisible);
     183            this->findCheckpoint(v.z)->settingsChanged();
    182184        }
    183185    }
  • code/trunk/src/modules/gametypes/SpaceRaceManager.h

    r9260 r9262  
    6262            void addCheckpoint(RaceCheckPoint* checkpoint);
    6363            RaceCheckPoint* getCheckpoint(unsigned int index) const;
    64             int getIndex(RaceCheckPoint* checkpoint);
     64
     65            RaceCheckPoint* findCheckpoint(int index) const;
    6566
    6667            void checkpointReached(RaceCheckPoint* check, PlayerInfo* player);
     
    6970
    7071        protected:
    71             void setRadVis(PlayerInfo* player, bool bVisible); ///< sets RadarVisibility of the checkpoints the player can reach.
     72            void setRadarVisibility(PlayerInfo* player, bool bVisible); ///< sets RadarVisibility of the checkpoints the player can reach.
    7273
    7374        private:
Note: See TracChangeset for help on using the changeset viewer.