Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8928


Ignore:
Timestamp:
Nov 9, 2011, 4:11:12 PM (13 years ago)
Author:
eceline
Message:

some changes for multiplayer-version

Location:
code/branches/spaceraceTwo/src/modules/gametypes
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc

    r8921 r8928  
    3636#include "SpaceRace.h"
    3737
     38
    3839namespace orxonox
    3940{
     
    6061              //  this->nextcheckpoints_[i]->destroy();
    6162        }
    62         nextcheckpoints_.clear();
     63       //nextcheckpoints_.destroy;
    6364    }
    6465
     
    6970        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    7071        assert(gametype);
    71         if (this->getCheckpointIndex() == gametype->getCheckpointsReached())
    72             this->setRadarVisibility(true);
    73         else
    74             this->setRadarVisibility(false);
     72        this->setRadarVisibility(false);
     73        Vector3 v =Vector3(0,0,0);
     74        int j=0;
     75        for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
     76        {
     77                j=gametype->getCheckpointReached(it->first);
     78                RaceCheckPoint* r=SpaceRaceManager::getCheckpoint(j);
     79                v=r->getNextcheckpoint();
     80                for(int i=1;i<4;i++){
     81                if (this->getCheckpointIndex() == v[i])
     82                 this->setRadarVisibility(true);
     83                 }
     84        }     
    7585    }
    7686
     
    8292        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
    8393        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
    84     //XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const std::vector<int>&);
     94    XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&);
    8595    }
    8696
    87     void RaceCheckPoint::triggered(bool bIsTriggered)
     97
     98
     99    void RaceCheckPoint::triggered(bool bIsTriggered, PlayerInfo* player)
    88100    {
    89101        DistanceTrigger::triggered(bIsTriggered);
    90102
    91103        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    92         if (gametype && this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
     104        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointReached(player) && bIsTriggered)
    93105        {
    94106            gametype->clock_.capture();
     
    103115            else
    104116            {
    105                 gametype->newCheckpointReached();
     117                gametype->newCheckpointReached(this);
    106118                this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
    107119            }
  • code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h

    r8915 r8928  
    5050            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5151            virtual void tick(float dt);
     52        inline void setCheckpointIndex(int checkpointIndex)
     53                { this->bCheckpointIndex_ = checkpointIndex; }
     54            inline int getCheckpointIndex()
     55                { return this->bCheckpointIndex_; }
    5256
    53             protected:
    54             virtual void triggered(bool bIsTriggered);
     57        inline void setNextcheckpoint(const Vector3& checkpoints)
     58                {this->nextcheckpoints_=checkpoints;}
     59            inline void setNextcheckpoint(float x, float y, float z)
     60                { this->setNextcheckpoint(Vector3(x, y, z)); }
     61           inline const Vector3& getNextcheckpoint() const
     62                {return this->nextcheckpoints_;}
     63        protected:
     64            virtual void triggered(bool bIsTriggered, PlayerInfo* player);
    5565            inline void setLast(bool isLast)
    5666                { this->bIsLast_ = isLast; }
     
    5868                { return this->bIsLast_; }
    5969           
    60         inline void setCheckpointIndex(int checkpointIndex)
    61                 { this->bCheckpointIndex_ = checkpointIndex; }
    62             inline int getCheckpointIndex()
    63                 { return this->bCheckpointIndex_; }
     70       
     71               
    6472
    65         inline void setNextcheckpoint(std::vector<int> checkpoints)
    66                 { this->nextcheckpoints_ = checkpoints; }
    67             inline std::vector<int> getNextcheckpoint()
    68                 { return this->nextcheckpoints_; }
    6973            virtual void setTimelimit(float timeLimit);
    7074            inline float getTimeLimit()
     
    7882            float bTimeLimit_; //The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses.
    7983
    80         std::vector<int> nextcheckpoints_; //the indexes of the next check points
     84       
     85        Vector3 nextcheckpoints_; //the indexes of the next check points
    8186     
    8287    };
  • code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc

    r8915 r8928  
    4545    {
    4646        RegisterObject(SpaceRace);
    47         this->checkpointsReached_ = 0;
     47        //this->checkpointsReached_ = 0;
    4848        this->bTimeIsUp_ = false;
    4949        this->numberOfBots_ = 0;
    5050        this->cantMove_=false;
     51       
     52       
    5153    }
    5254   
     
    6567            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    6668            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
    67                         + "You didn't reach the check point " + multi_cast<std::string>(this->checkpointsReached_+1)
    68                         + " before the time limit. You lose!";
     69                        + "You didn't reach the check point  before the time limit. You lose!";
    6970            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    7071            ChatManager::message(message);
     
    138139       
    139140
    140     void SpaceRace::newCheckpointReached()
     141    void SpaceRace::newCheckpointReached(RaceCheckPoint* p)
    141142    {
    142         this->checkpointsReached_++;
     143        this->checkpointReached_=p->getCheckpointIndex();
    143144        this->clock_.capture();
    144145        int s = this->clock_.getSeconds();
    145146        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    146         const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
     147        const std::string& message = "Checkpoint " + multi_cast<std::string>(p)
    147148                        + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
    148149                        + " seconds.";
    149150        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    150151        ChatManager::message(message);
     152       
     153       
    151154    }
     155   
     156     int SpaceRace::getCheckpointReached(PlayerInfo* player){
     157        return this->currentCheckpoint_[player];
     158}
    152159
     160void SpaceRace::playerEntered(PlayerInfo* player){
     161        this->currentCheckpoint_[player]=1;
     162        this->playersAlive_++;
     163    }
     164   
     165        bool SpaceRace::playerLeft(PlayerInfo* player){
     166                 bool valid_player = true;
     167        if (valid_player)
     168        {
     169            this->playersAlive_--;
     170        }
     171
     172        return valid_player;
     173        }
    153174}
  • code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h

    r8911 r8928  
    5959            virtual void end();
    6060               
    61             virtual void newCheckpointReached();
     61            virtual void newCheckpointReached(RaceCheckPoint* p);
    6262
    63             inline void setCheckpointsReached(int n)
    64                 { this->checkpointsReached_ = n;}
    65             inline int getCheckpointsReached()
    66                 { return this->checkpointsReached_; }
     63            inline void setCheckpointReached(int n)
     64                { this->checkpointReached_ = n;}
     65            inline int getCheckpointReached()
     66                { return this->checkpointReached_; }
     67               
    6768            inline void timeIsUp()
    6869                { this->bTimeIsUp_ = true;}
    6970        void tick(float dt);
     71
     72        int getCheckpointReached(PlayerInfo* player);
     73
     74         
    7075        protected:
    71                
     76                virtual void playerEntered(PlayerInfo* player); //!< Initializes values.
     77                 virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables.
    7278        private:
    7379        float maxSpeedBack_; float maxSpeedFront_; float maxSpeedLeftRight_; float maxSpeedUpDown_;
    7480        bool cantMove_;
    75             int checkpointsReached_; //The current number of check points reached by the player.
     81            int checkpointReached_; //The number of the last check point reached by each player.
    7682            std::set<float> scores_; //The times of the players are saved in a set.
    7783            bool bTimeIsUp_; //True if one of the check points is reached too late.
    7884            Clock clock_; //The clock starts running at the beginning of the game. It is used to give the time at each check point, the give the time at the end of the game, and to stop the game if a check point is reached too late.
     85
     86                std::map<PlayerInfo*, int> currentCheckpoint_;
     87                int playersAlive_;
     88
     89       
    7990    };
    8091}
  • code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc

    r8915 r8928  
    8585   
    8686   
     87   
     88   
     89   
     90    }
    8791
    88    
    8992
    90 }
  • code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h

    r8915 r8928  
    6161            void addCheckpoint(RaceCheckPoint* checkpoint);
    6262            RaceCheckPoint* getCheckpoint(unsigned int index) const;
     63               
     64               
    6365
    6466        void tick(float dt);
     
    6668               
    6769        private:
    68         std::vector<RaceCheckPoint*> checkpoints_;
     70                std::vector<RaceCheckPoint*> checkpoints_;
     71               
     72               
     73               
    6974 };
    7075}
Note: See TracChangeset for help on using the changeset viewer.