Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 27, 2011, 11:01:24 PM (14 years ago)
Author:
dafrick
Message:

Cleanup.

Location:
code/branches/spacerace/src/modules/gametypes
Files:
4 edited

Legend:

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

    r8617 r8630  
    3838    CreateFactory(RaceCheckPoint);
    3939   
    40     RaceCheckPoint::RaceCheckPoint(BaseObject* creator):
    41         DistanceTrigger(creator),
    42         RadarViewable(creator, static_cast<WorldEntity*>(this))
     40    RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
    4341    {
    44         RegisterObject(RaceCheckPoint);
    45        
    46         this->bCheckpointIndex_ = 0;
    47         this->bIsLast_ = false;
    48         this->bTimeLimit_ = 0;
    49        
    50         this->setRadarObjectColour(ColourValue::Blue);
     42        RegisterObject(RaceCheckPoint);
     43
     44        this->bCheckpointIndex_ = 0;
     45        this->bIsLast_ = false;
     46        this->bTimeLimit_ = 0;
     47
     48        this->setRadarObjectColour(ColourValue::Blue);
    5149        this->setRadarObjectShape(RadarViewable::Triangle);
    5250        this->setRadarVisibility(false);
     
    5957    void RaceCheckPoint::tick(float dt)
    6058    {
    61         Trigger::tick(dt);
    62        
    63         SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    64         if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) this->setRadarVisibility(true);
    65         else  this->setRadarVisibility(false);
     59        SUPER(RaceCheckPoint, tick, dt);
     60
     61        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
     62        if (this->getCheckpointIndex() == gametype->getCheckpointsReached())
     63            this->setRadarVisibility(true);
     64        else
     65            this->setRadarVisibility(false);
    6666    }
    6767
     
    6969    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7070    {
    71         SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
    72        
    73         XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
    74         XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
    75         XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
     71        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
     72
     73        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
     74        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
     75        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
    7676    }
    7777   
    7878    void RaceCheckPoint::triggered(bool bIsTriggered)
    7979    {
    80         DistanceTrigger::triggered(bIsTriggered);
    81        
    82         SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    83         if (gametype)
    84         {
    85             if (this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
    86             {
    87                 gametype->clock_->capture();
    88                 float time = gametype->clock_->getSecondsPrecise();
    89                 if (this->bTimeLimit_!=0 && time > this->bTimeLimit_) {
    90                   gametype->timeIsUp();
    91                   gametype->end();
    92                 }
    93                 else if (this->getLast())
    94                 {
    95                   gametype->end();
    96                 }
    97                 else
    98                 {
    99                   gametype->newCheckpointReached();
    100                   this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
    101                 }
    102             }
    103         }
     80        DistanceTrigger::triggered(bIsTriggered);
     81
     82        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
     83        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
     84        {
     85            gametype->clock_.capture();
     86            float time = gametype->clock_.getSecondsPrecise();
     87            if (this->bTimeLimit_!=0 && time > this->bTimeLimit_)
     88            {
     89                gametype->timeIsUp();
     90                gametype->end();
     91            }
     92            else if (this->getLast())
     93                gametype->end();
     94            else
     95            {
     96                gametype->newCheckpointReached();
     97                this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
     98            }
     99        }
    104100    }
    105101   
    106102    void RaceCheckPoint::setTimelimit(float timeLimit)
    107             {
    108               this->bTimeLimit_ = timeLimit;
    109               if (this->bTimeLimit_ != 0)
    110               {
    111                   SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    112                   if (gametype)
    113                   {
    114                      const std::string& message =  "\nYou have " + multi_cast<std::string>(this->bTimeLimit_)
    115                                                    + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1) + "\n\n";
    116                      COUT(0) << message;
    117                      const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
    118                   }
    119               }
    120             }
     103    {
     104        this->bTimeLimit_ = timeLimit;
     105        if (this->bTimeLimit_ != 0)
     106        {
     107            SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
     108            if (gametype)
     109            {
     110                const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
     111                            + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1) + "\n";
     112                COUT(3) << message;
     113                const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
     114            }
     115        }
     116    }
    121117   
    122118}
  • code/branches/spacerace/src/modules/gametypes/RaceCheckPoint.h

    r8616 r8630  
    3434#include "objects/triggers/DistanceTrigger.h"
    3535#include "interfaces/RadarViewable.h"
    36 #include <boost/concept_check.hpp>
     36//#include <boost/concept_check.hpp>
    3737
    3838namespace orxonox
     
    4040  /**
    4141  @brief
    42   The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
    43   !!! Don't forget to controll the indexes of your check points and to set one last check point!!!
     42    The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
     43    !!! Don't forget to control the indexes of your check points and to set one last check point!!!
    4444  */
    4545    class _ObjectsExport RaceCheckPoint : public DistanceTrigger, public RadarViewable
    4646    {
    47     public:
    48         RaceCheckPoint(BaseObject* creator);
    49         virtual ~RaceCheckPoint();
    50        
    51         virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    52         virtual void tick(float dt);
    53        
    54     protected:
    55         virtual void triggered(bool bIsTriggered);
    56         inline void setLast(bool isLast)
    57             { this->bIsLast_ = isLast; }
    58         inline bool getLast()
    59             { return this->bIsLast_; }
    60         inline void setCheckpointIndex(int checkpointIndex)
    61             { this->bCheckpointIndex_ = checkpointIndex; }
    62         inline int getCheckpointIndex()
    63             { return this->bCheckpointIndex_; }
    64         virtual void setTimelimit(float timeLimit);
    65         inline float getTimeLimit()
    66             { return this->bTimeLimit_;}
    67         inline const WorldEntity* getWorldEntity() const
    68             { return this; }
    69        
    70     private:
    71         int bCheckpointIndex_; //The index of this check point. This value will be compared with the number of check points reached in the level. The check points must be indexed in ascending order beginning from zero and without any jumps between the indexes.
    72         bool bIsLast_; //True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level.
    73         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.
     47        public:
     48            RaceCheckPoint(BaseObject* creator);
     49            virtual ~RaceCheckPoint();
     50
     51            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     52            virtual void tick(float dt);
     53
     54            protected:
     55            virtual void triggered(bool bIsTriggered);
     56            inline void setLast(bool isLast)
     57                { this->bIsLast_ = isLast; }
     58            inline bool getLast()
     59                { return this->bIsLast_; }
     60            inline void setCheckpointIndex(int checkpointIndex)
     61                { this->bCheckpointIndex_ = checkpointIndex; }
     62            inline int getCheckpointIndex()
     63                { return this->bCheckpointIndex_; }
     64            virtual void setTimelimit(float timeLimit);
     65            inline float getTimeLimit()
     66                { return this->bTimeLimit_;}
     67            inline const WorldEntity* getWorldEntity() const
     68                { return this; }
     69
     70        private:
     71            int bCheckpointIndex_; //The index of this check point. This value will be compared with the number of check points reached in the level. The check points must be indexed in ascending order beginning from zero and without any jumps between the indexes.
     72            bool bIsLast_; //True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level.
     73            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.
    7474     
    7575    };
    7676}
    7777
    78 #endif
     78#endif /* _RaceCheckPoint_H__ */
  • code/branches/spacerace/src/modules/gametypes/SpaceRace.cc

    r8624 r8630  
    4141    SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator)
    4242    {
    43         RegisterObject(SpaceRace);
    44         this->bCheckpointsReached_ = 0;
    45         this->bTimeIsUp_ = false;
    46         this->numberOfBots_ = 0;
    47     }
    48    
    49     void SpaceRace::tick(float dt)
    50     {
    51         Gametype::tick(dt);
     43        RegisterObject(SpaceRace);
     44        this->bCheckpointsReached_ = 0;
     45        this->bTimeIsUp_ = false;
     46        this->numberOfBots_ = 0;
    5247    }
    5348   
    5449    void SpaceRace::end()
    5550    {
    56         Gametype::end();
    57         if (this->bTimeIsUp_) {
    58             this->clock_->capture();
    59             int s = this->clock_->getSeconds();
    60             int ms = this->clock_->getMilliseconds()-1000*s;
    61             const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
    62                                          + "You didn't reach the check point " + multi_cast<std::string>(this->bCheckpointsReached_+1)
    63                                          + " before the time limit. You lose!\n";
    64             COUT(0) << message;
    65             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    66             Host::Broadcast(message);
    67         }
    68         else {
    69             this->clock_->capture();
    70             int s = this->clock_->getSeconds();
    71             int ms = this->clock_->getMilliseconds()-1000*s;
    72             const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
    73                                           + "." + multi_cast<std::string>(ms) + " seconds.\n";
    74             COUT(0) << message << std::endl;
    75             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    76             Host::Broadcast(message);
    77             float time = this->clock_->getSecondsPrecise();
    78             this->scores_.insert(time);
    79             std::set<float>::iterator it;
    80             for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
    81             COUT(0) <<  multi_cast<std::string>(*it) << std::endl;
    82         }
     51        this->Gametype::end();
     52         
     53        if (this->bTimeIsUp_)
     54        {
     55            this->clock_.capture();
     56            int s = this->clock_.getSeconds();
     57            int ms = this->clock_.getMilliseconds()-1000*s;
     58            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
     59                        + "You didn't reach the check point " + multi_cast<std::string>(this->bCheckpointsReached_+1)
     60                        + " before the time limit. You lose!";
     61            COUT(3) << message;
     62            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     63            Host::Broadcast(message);
     64        }
     65        else
     66        {
     67            this->clock_.capture();
     68            int s = this->clock_.getSeconds();
     69            int ms = this->clock_.getMilliseconds()-1000*s;
     70            const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
     71                        + "." + multi_cast<std::string>(ms) + " seconds.";
     72            COUT(3) << message << std::endl;
     73            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     74            Host::Broadcast(message);
     75            float time = this->clock_.getSecondsPrecise();
     76            this->scores_.insert(time);
     77            std::set<float>::iterator it;
     78            for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
     79            COUT(3) <<  multi_cast<std::string>(*it) << std::endl;
     80        }
    8381    }
    8482
    8583    void SpaceRace::start()
    8684    {
    87         Gametype::start();
    88        
    89         clock_= new Clock();
    90         std::string message("The match has started! Reach the check points as quickly as possible!");
    91         COUT(0) << message << std::endl;
     85        Gametype::start();
     86
     87        std::string message("The match has started! Reach the check points as quickly as possible!");
     88        COUT(3) << message << std::endl;
    9289        Host::Broadcast(message);
    9390    }
     
    9592    void SpaceRace::newCheckpointReached()
    9693    {
    97         this->bCheckpointsReached_++;
    98         this->clock_->capture();
    99         int s = this->clock_->getSeconds();
    100         int ms = this->clock_->getMilliseconds()-1000*s;
    101         const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
    102                                       + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
    103                                       + " seconds.\n";
    104         COUT(0) << message << std::endl;
    105         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    106         Host::Broadcast(message);
     94        this->bCheckpointsReached_++;
     95        this->clock_.capture();
     96        int s = this->clock_.getSeconds();
     97        int ms = this->clock_.getMilliseconds()-1000*s;
     98        const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
     99                        + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
     100                        + " seconds.\n";
     101        COUT(3) << message;
     102        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     103        Host::Broadcast(message);
    107104    }
    108105
  • code/branches/spacerace/src/modules/gametypes/SpaceRace.h

    r8616 r8630  
    4242  /**
    4343  @brief
    44   The SpaceRace class enables the creation of a space race level, where the player has to reach check points in a given order.
     44    The SpaceRace class enables the creation of a space race level, where the player has to reach check points in a given order.
    4545  */
    4646    class _OrxonoxExport SpaceRace : public Gametype
    4747    {
    48         public:
    49             SpaceRace(BaseObject* creator);
    50             virtual ~SpaceRace() {}
    51            
    52             virtual void tick(float dt);
    53            
    54             virtual void start();
    55             virtual void end();
    56            
    57             virtual void newCheckpointReached();
    58            
    59             inline void setCheckpointsReached(int n)
    60                 { this->bCheckpointsReached_ = n;}
    61             inline int getCheckpointsReached()
    62                 { return this->bCheckpointsReached_; }
    63             inline void timeIsUp()
    64                 { this->bTimeIsUp_ = true;}
    65             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.
    66         protected:
    67            
    68         private:
    69             int bCheckpointsReached_; //The current number of check points reached by the player.
    70             std::set<float> scores_; //The times of the players are saved in a set.
    71             bool bTimeIsUp_; //True if one of the check points is reached too late.
     48        friend class RaceCheckPoint;
     49       
     50        public:
     51            SpaceRace(BaseObject* creator);
     52            virtual ~SpaceRace() {}
     53
     54            virtual void start();
     55                virtual void end();
     56
     57            virtual void newCheckpointReached();
     58
     59            inline void setCheckpointsReached(int n)
     60            { this->bCheckpointsReached_ = n;}
     61            inline int getCheckpointsReached()
     62            { return this->bCheckpointsReached_; }
     63            inline void timeIsUp()
     64            { this->bTimeIsUp_ = true;}
     65
     66        protected:
     67
     68        private:
     69            int bCheckpointsReached_; //The current number of check points reached by the player.
     70            std::set<float> scores_; //The times of the players are saved in a set.
     71            bool bTimeIsUp_; //True if one of the check points is reached too late.
     72            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.
    7273    };
    7374}
    7475
    75 #endif
     76#endif /* _SpaceRace_H__ */
Note: See TracChangeset for help on using the changeset viewer.