Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 18, 2011, 2:35:02 PM (13 years ago)
Author:
jo
Message:

Merged SpaceraceTwo. Old racelevel does not work anymore.

Location:
code/branches/presentation2011
Files:
12 edited
3 copied

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2011

  • code/branches/presentation2011/src/modules/gametypes/CMakeLists.txt

    r8706 r8998  
    22  SpaceRace.cc
    33  RaceCheckPoint.cc
     4  SpaceRaceManager.cc
    45)
    56
  • code/branches/presentation2011/src/modules/gametypes/RaceCheckPoint.cc

    r8858 r8998  
    3434#include "chat/ChatManager.h"
    3535
     36#include <infos/PlayerInfo.h>
     37#include <worldentities/ControllableEntity.h>
     38
    3639#include "SpaceRace.h"
    3740
     
    3942{
    4043    CreateFactory(RaceCheckPoint);
     44   
     45     
    4146
    42     RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
     47    RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
    4348    {
    4449        RegisterObject(RaceCheckPoint);
    45 
    46         this->bCheckpointIndex_ = 0;
    47         this->bIsLast_ = false;
     50        this->setDistance(100);
     51        this->setBeaconMode("off");
     52        this->setBroadcast(false);
     53        this->setSimultaneousTriggerers(100);
    4854        this->bTimeLimit_ = 0;
    4955
     
    5157        this->setRadarObjectShape(RadarViewable::Triangle);
    5258        this->setRadarVisibility(false);
     59        this->settingsChanged();
     60        this->reached_=NULL;
     61     
    5362    }
     63   
    5464
    55     RaceCheckPoint::~RaceCheckPoint()
    56     {
    57     }
     65   RaceCheckPoint::~RaceCheckPoint()
     66   {
     67   
     68   }
    5869
    5970    void RaceCheckPoint::tick(float dt)
     
    6374        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    6475        assert(gametype);
    65         if (this->getCheckpointIndex() == gametype->getCheckpointsReached())
    66             this->setRadarVisibility(true);
    67         else
    68             this->setRadarVisibility(false);
    6976    }
    7077
     
    7279    {
    7380        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
    74 
     81        Vector3 v= Vector3(0,0,0);
    7582        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
    7683        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
    7784        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
     85    XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&).defaultValues(v);
    7886    }
    7987
    80     void RaceCheckPoint::triggered(bool bIsTriggered)
     88    void RaceCheckPoint::fire(bool bIsTriggered,BaseObject* player)
    8189    {
    82         DistanceTrigger::triggered(bIsTriggered);
    83 
     90        DistanceMultiTrigger::fire((bool)bIsTriggered,player);
     91       
    8492        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    85         if (gametype && 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             {
    91                 gametype->timeIsUp();
    92                 gametype->end();
    93             }
    94             else if (this->getLast())
    95                 gametype->end();
    96             else
    97             {
    98                 gametype->newCheckpointReached();
    99                 this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
    100             }
    101         }
     93        assert(gametype);
     94        ControllableEntity* entity = (ControllableEntity*) player;
     95     
     96        PlayerInfo* player2 = entity->getPlayer();
     97     
     98        if(bIsTriggered)
     99            this->reached_=player2;
    102100    }
    103101
     
    108106        {
    109107            SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
     108            assert(gametype);
    110109            if (gametype)
    111110            {
  • code/branches/presentation2011/src/modules/gametypes/RaceCheckPoint.h

    r8767 r8998  
    3232#include "gametypes/GametypesPrereqs.h"
    3333
    34 #include "objects/triggers/DistanceTrigger.h"
     34
     35
     36#include "objects/triggers/DistanceMultiTrigger.h"
    3537#include "interfaces/RadarViewable.h"
    3638
     
    4042    @brief
    4143        The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
    42         !!! Don't forget to control the indexes of your check points and to set one last check point!!!
     44         Don't forget to control the indexes of your check points and to set one last check point
    4345    */
    44     class _GametypesExport RaceCheckPoint : public DistanceTrigger, public RadarViewable
     46    class _GametypesExport RaceCheckPoint : public DistanceMultiTrigger, public RadarViewable
    4547    {
    4648        public:
     
    5052            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5153            virtual void tick(float dt);
     54            inline void setCheckpointIndex(int checkpointIndex)
     55                { this->bCheckpointIndex_ = checkpointIndex; }
     56            inline int getCheckpointIndex()
     57                { return this->bCheckpointIndex_; }
    5258
    53             protected:
    54             virtual void triggered(bool bIsTriggered);
     59            inline void setNextcheckpoint(const Vector3& checkpoints)
     60                { this->nextcheckpoints_=checkpoints; }
     61            inline void setNextcheckpoint(float x, float y, float z)
     62                { this->setNextcheckpoint(Vector3(x, y, z)); }
     63            inline const Vector3& getNextcheckpoint() const
     64                { return this->nextcheckpoints_; }
    5565            inline void setLast(bool isLast)
    5666                { this->bIsLast_ = isLast; }
    5767            inline bool getLast()
    5868                { return this->bIsLast_; }
    59             inline void setCheckpointIndex(int checkpointIndex)
    60                 { this->bCheckpointIndex_ = checkpointIndex; }
    61             inline int getCheckpointIndex()
    62                 { return this->bCheckpointIndex_; }
     69
     70            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.
     71            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.
     72            PlayerInfo* reached_;
     73               
     74            inline float getTimeLimit()
     75                { return this->bTimeLimit_; }
     76   
     77        protected:
     78            virtual void fire(bool bIsTriggered,BaseObject* player);
    6379            virtual void setTimelimit(float timeLimit);
    64             inline float getTimeLimit()
    65                 { return this->bTimeLimit_;}
     80           
    6681            inline const WorldEntity* getWorldEntity() const
    6782                { return this; }
    6883
    6984        private:
    70             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.
    71             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.
    72             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.
    73      
     85            int bCheckpointIndex_; //The index of this check point. The race starts with the check point with the index 0
     86            Vector3 nextcheckpoints_; //the indexes of the next check points
     87           
    7488    };
    7589}
  • code/branches/presentation2011/src/modules/gametypes/SpaceRace.cc

    r8858 r8998  
    2929#include "SpaceRace.h"
    3030
     31
     32#include "items/Engine.h"
     33
    3134#include "core/CoreIncludes.h"
    3235#include "chat/ChatManager.h"
    3336#include "util/Convert.h"
    3437#include "util/Math.h"
     38
     39#include "items/Engine.h"
    3540
    3641namespace orxonox
     
    4146    {
    4247        RegisterObject(SpaceRace);
    43         this->checkpointsReached_ = 0;
     48       
    4449        this->bTimeIsUp_ = false;
    4550        this->numberOfBots_ = 0;
     51        this->cantMove_=false;
     52       
    4653    }
     54       
     55   
     56  // void SpaceRace::SetConfigValues(){
     57    //SUPER(Gametype,setConfigValues);
     58    //this->Gametype::SetConfigValue(initialStartCountdown_, 3.0f);}
    4759
    4860    void SpaceRace::end()
     
    5668            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    5769            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
    58                         + "You didn't reach the check point " + multi_cast<std::string>(this->checkpointsReached_+1)
    59                         + " before the time limit. You lose!";
     70                        + "You didn't reach the check point  before the time limit. You lose!";
    6071            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    6172            ChatManager::message(message);
     
    7081            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    7182            ChatManager::message(message);
    72 /*
     83
    7384            float time = this->clock_.getSecondsPrecise();
    7485            this->scores_.insert(time);
    7586            std::set<float>::iterator it;
    76             for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
    77                 orxout(level::message) << multi_cast<std::string>(*it) << endl;
    78 */
     87           
     88
    7989        }
    8090    }
     
    8292    void SpaceRace::start()
    8393    {
    84         Gametype::start();
    8594
    86         std::string message("The match has started! Reach the check points as quickly as possible!");
     95        this->spawnPlayersIfRequested();
     96        Gametype::checkStart();
     97        this->cantMove_=true;
     98       
     99        for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
     100        {
     101            it->setActive(false);
     102           
     103        }
     104        this->addBots(this->numberOfBots_);
     105    }
     106   
     107    void SpaceRace::tick(float dt)
     108    {
     109        SUPER(SpaceRace,tick,dt);
     110   
     111        if(!this->isStartCountdownRunning() && this->cantMove_)
     112        {
     113            for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
     114            {
     115                it->setActive(true);
     116               
     117            }
     118            this->cantMove_= false;
     119           
     120            std::string message("The match has started! Reach the check points as quickly as possible!");
     121            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     122            ChatManager::message(message);           
     123        }
     124   
     125    }
     126
     127   
     128   
     129    void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl)
     130    {
     131        this->checkpointReached_[pl]=index;
     132        this->clock_.capture();
     133        int s = this->clock_.getSeconds();
     134        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
     135        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.
    87138        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    88139        ChatManager::message(message);
    89140    }
    90 
    91     void SpaceRace::newCheckpointReached()
    92     {
    93         this->checkpointsReached_++;
     141   
     142    void SpaceRace::newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl)
     143    {   
     144        int index = p->getCheckpointIndex();
     145        this->checkpointReached_[pl]=index;
    94146        this->clock_.capture();
    95147        int s = this->clock_.getSeconds();
    96148        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    97         const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
    98                         + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
    99                         + " seconds.";
     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.";
    100152        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    101153        ChatManager::message(message);
    102154    }
     155       
     156   
     157    void SpaceRace::playerEntered(PlayerInfo* player)
     158    {
     159        Gametype::playerEntered(player);
     160   
     161        this->checkpointReached_[player]=-1;
     162        //this->playersAlive_++;
     163    }
     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        //}
    103173
     174       // return valid_player;
     175    }
     176   
     177    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
     178    {
     179        return false;
     180    }
     181
     182    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
     183    {
     184        return false;
     185    }
     186
     187    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
     188    {
     189        return false;
     190    }
    104191}
  • code/branches/presentation2011/src/modules/gametypes/SpaceRace.h

    r8767 r8998  
    3434#include <set>
    3535#include <string>
     36# include <vector>
    3637
    3738#include <util/Clock.h>
     
    3940#include "gametypes/Gametype.h"
    4041
    41 #include "RaceCheckPoint.h"
     42#include "SpaceRaceManager.h"
    4243
    4344namespace orxonox
     
    5051    {
    5152        friend class RaceCheckPoint;
     53       
    5254
    5355        public:
     
    5860            virtual void end();
    5961
    60             virtual void newCheckpointReached();
     62            virtual void newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl);
     63            virtual void newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl);
    6164
    62             inline void setCheckpointsReached(int n)
    63                 { this->checkpointsReached_ = n;}
    64             inline int getCheckpointsReached()
    65                 { return this->checkpointsReached_; }
     65            inline void setCheckpointReached(int n, PlayerInfo* p)
     66                { this->checkpointReached_[p] = n;}
     67            inline int getCheckpointReached(PlayerInfo* p)
     68                { return this->checkpointReached_[p]; }
     69
    6670            inline void timeIsUp()
    6771                { this->bTimeIsUp_ = true;}
     72            void tick(float dt);
     73            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.
    6874
     75
     76            bool allowPawnHit(Pawn* victim, Pawn* originator);
     77
     78            bool allowPawnDamage(Pawn* victim, Pawn* originator);
     79
     80            bool allowPawnDeath(Pawn* victim, Pawn* originator);
    6981        protected:
    70 
     82            virtual void playerEntered(PlayerInfo* player); //!< Initializes values.
     83            virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables.
    7184        private:
    72             int checkpointsReached_; //The current number of check points reached by the player.
     85            bool cantMove_;
     86            std::map<PlayerInfo*, int>checkpointReached_; //The number of the last check point reached by each player.
    7387            std::set<float> scores_; //The times of the players are saved in a set.
    7488            bool bTimeIsUp_; //True if one of the check points is reached too late.
    75             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.
     89           
     90            int playersAlive_;
    7691    };
    7792}
  • code/branches/presentation2011/src/modules/objects/triggers/DistanceMultiTrigger.h

    r8706 r8998  
    9191    @ingroup MultiTrigger
    9292    */
    93     class _ObjectsExport DistanceMultiTrigger : public MultiTrigger
     93    class _ObjectsExport DistanceMultiTrigger : public MultiTrigger 
    9494    {
    9595
  • code/branches/presentation2011/src/modules/objects/triggers/MultiTrigger.h

    r8457 r8998  
    157157            bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object.
    158158
    159             void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an Event for the given status and originator and fires it.
     159            virtual void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an Event for the given status and originator and fires it.
    160160            void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
    161161
  • code/branches/presentation2011/src/orxonox/gametypes/Gametype.cc

    r8980 r8998  
    8585        this->dedicatedKillBots_ = createConsoleCommand( "dedicatedKillBots", createExecutor( createFunctor(&Gametype::killBots, this) ) );
    8686        /* HACK HACK HACK */
    87         //this->numberOfPlayers_ = 0;
    8887    }
    8988
     
    124123        if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted())
    125124            this->gtinfo_->countdownStartCountdown(dt);
    126 
     125                       
    127126        if (!this->gtinfo_->hasStarted())
    128127        {
     
    132131                if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
    133132                    this->gtinfo_->playerReadyToSpawn(it->first);
    134             }
    135 
     133                   
     134               
     135            }
    136136            this->checkStart();
    137137        }
     
    144144    void Gametype::start()
    145145    {
     146         
    146147        this->addBots(this->numberOfBots_);
    147148
     
    149150
    150151        this->spawnPlayersIfRequested();
     152       
     153       
    151154    }
    152155
     
    377380                {
    378381                    this->gtinfo_->stopStartCountdown();
    379                     this->gtinfo_->setStartCountdown(0.0f);;
     382                    this->gtinfo_->setStartCountdown(0.0f);
    380383                    this->start();
    381384                }
     
    398401                            hashumanplayers = true;
    399402                    }
     403                         
    400404                    if (allplayersready && hashumanplayers)
    401405                    {
     
    409413                }
    410414            }
     415           
    411416        }
    412417    }
  • code/branches/presentation2011/src/orxonox/gametypes/Gametype.h

    r8980 r8998  
    155155              { return this->gtinfo_->getNumberOfPlayers(); }
    156156
     157       
     158
    157159        protected:
    158160            virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
  • code/branches/presentation2011/src/orxonox/infos/GametypeInfo.cc

    r8858 r8998  
    7171        this->bStarted_ = false;
    7272        this->bEnded_ = false;
    73         this->startCountdown_ = 0.0f;
     73        this->startCountdown_ = 10.0f;
    7474        this->bStartCountdownRunning_ = false;
    75         this->counter_ = 0;
     75        this->counter_ = 10;
    7676        this->spawned_ = false;
    7777        this->readyToSpawn_ = false;
     
    164164    {
    165165        if(this->bStarted_)
    166             return;
     166           { return;}
    167167       
    168168        this->bStarted_ = true;
    169169        this->changedStarted();
     170       
     171       
    170172    }
    171173
  • code/branches/presentation2011/src/orxonox/infos/PlayerInfo.cc

    r8988 r8998  
    5858
    5959        this->registerVariables();
     60       
    6061    }
    6162
Note: See TracChangeset for help on using the changeset viewer.