Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 19, 2013, 10:25:42 AM (12 years ago)
Author:
jo
Message:

Merging presentationHS12 back to the trunk.

Location:
code/trunk
Files:
8 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/gametypes/CMakeLists.txt

    r9016 r9526  
    55  OldSpaceRace.cc
    66  OldRaceCheckPoint.cc
     7  SpaceRaceBot.cc
     8  SpaceRaceController.cc
    79)
    810
  • code/trunk/src/modules/gametypes/GametypesPrereqs.h

    r9016 r9526  
    6767    class SpaceRace;
    6868    class OldSpaceRace;
     69    class SpaceRaceManager;
     70    class SpaceRaceBot;
     71    class SpaceRaceController;
    6972}
    7073
  • code/trunk/src/modules/gametypes/RaceCheckPoint.cc

    r9348 r9526  
    4343    CreateFactory(RaceCheckPoint);
    4444
    45     RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
     45    RaceCheckPoint::RaceCheckPoint(BaseObject* creator) : DistanceMultiTrigger(creator),
     46            RadarViewable(creator, static_cast<WorldEntity*> (this))
    4647    {
    4748        RegisterObject(RaceCheckPoint);
    48 
    4949        this->setDistance(100);
    5050        this->setBeaconMode("off");
     
    6060        this->bIsLast_ = false;
    6161        this->timeLimit_ = 0;
    62         this->player_ = NULL;
    63     }
    64 
    65 
    66    RaceCheckPoint::~RaceCheckPoint()
    67    {
    68    }
     62        //this->players_ = vector<PlayerInfo*>();
     63
     64        myPosition_= this->getPosition(); //eingefuegt
     65        //orxout(user_status) << "test" << std::endl;
     66    }
     67
     68    RaceCheckPoint::~RaceCheckPoint()
     69    {
     70
     71    }
    6972
    7073    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     
    8689            ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator);
    8790            if (entity)
    88                 this->player_ = entity->getPlayer();
     91                this->players_.push_back(entity->getPlayer());
    8992        }
    9093    }
     
    9598        if (this->timeLimit_ != 0)
    9699        {
    97             std::string message =  "You have " + multi_cast<std::string>(this->timeLimit_)
    98                         + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
     100            std::string message = "You have " + multi_cast<std::string>(this->timeLimit_)
     101            + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
    99102            this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message);
    100103            ChatManager::message(message);
     
    102105    }
    103106
     107    //Must not be called before setNextCheckpointsAsVector3 at least once has been called
     108    void RaceCheckPoint::setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints){
     109        /*std::set<int> lastcheckpoints=this->nextCheckpoints_;
     110        nextCheckpoints_.clear();
     111        std::set<int>::iterator it = lastcheckpoints.begin();
     112        if(checkpoints.x<-1){
     113            virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.x,(*it)));
     114            it++;
     115        }
     116        if(checkpoints.x!=-1)
     117            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly
     118
     119        if(checkpoints.y<-1){
     120                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.y,(*it)));
     121                    it++;
     122        }
     123        if(checkpoints.y!=-1)
     124            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
     125
     126        if(checkpoints.z<-1){
     127                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.z,(*it)));
     128                    it++;
     129        }
     130        if(checkpoints.z!=-1)
     131            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));*/
     132        nextCheckpointsVirtual_.clear();
     133        if(checkpoints.x!=-1)
     134            nextCheckpointsVirtual_.insert(checkpoints.x);
     135        if(checkpoints.y!=-1)
     136                nextCheckpointsVirtual_.insert(checkpoints.y);
     137        if(checkpoints.z!=-1)
     138                nextCheckpointsVirtual_.insert(checkpoints.z);
     139    }
     140
    104141    void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints)
    105142    {
     
    107144
    108145        if (checkpoints.x > -1)
    109             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5));
     146        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly
    110147        if (checkpoints.y > -1)
    111             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
     148        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
    112149        if (checkpoints.z > -1)
    113             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
    114     }
    115 
    116     Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const
     150        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
     151
     152        this->nextCheckpointsVirtual_=nextCheckpoints_;
     153    }
     154
     155    PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const
     156    {
     157        if (players_.size() > 0)
     158        {
     159            for (int i = 0; i < players_.size(); i++)
     160            {
     161                if (this->players_[i]->getClientID() == clientID)
     162                {
     163                    return players_[i];
     164                }
     165            }
     166        }
     167        return NULL;
     168    }
     169
     170    bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const
     171    {
     172        if (players_.size() > 0)
     173        {
     174            for (int i = 0; i < players_.size(); i++)
     175            {
     176                if (this->players_[i] == player)
     177                {
     178                    return true;
     179                }
     180            }
     181        }
     182        return false;
     183    }
     184
     185    Vector3 RaceCheckPoint::getNextCheckpointsAsVector3()
     186    {
     187        Vector3 checkpoints(-1,-1,-1); int count=0;
     188        for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ ){
     189            switch (count)
     190                        {
     191                            case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
     192                            case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
     193                            case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
     194                        }
     195                        ++count;
     196        }
     197        return checkpoints;
     198        //= getVirtualNextCheckpointsAsVector3();
     199        int j[3];
     200        j[0]=changeVirtualToRealCheckPoint(checkpoints.x);
     201        j[1]=changeVirtualToRealCheckPoint(checkpoints.y);
     202        j[2]=changeVirtualToRealCheckPoint(checkpoints.z);
     203
     204
     205        return Vector3(j[0],j[1],j[2]);
     206
     207
     208    }
     209
     210    int RaceCheckPoint::changeVirtualToRealCheckPoint(int checkpointID) {
     211        int temp=checkpointID;
     212        while(temp<-1){
     213            temp = this->virtualToRealCheckPoints_[temp];
     214        }
     215        return temp;
     216    }
     217
     218
     219    Vector3 RaceCheckPoint::getVirtualNextCheckpointsAsVector3() const
    117220    {
    118221        Vector3 checkpoints = Vector3(-1, -1, -1);
    119222
    120223        size_t count = 0;
    121         for (std::set<int>::iterator it = this->nextCheckpoints_.begin(); it != this->nextCheckpoints_.end(); ++it)
     224        for (std::set<int>::iterator it = this->nextCheckpointsVirtual_.begin(); it != this->nextCheckpointsVirtual_.end(); ++it)
    122225        {
    123226            switch (count)
  • code/trunk/src/modules/gametypes/RaceCheckPoint.h

    r9263 r9526  
    3737{
    3838    /**
    39     @brief
    40         The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
    41         Don't forget to control the indexes of your check points and to set one last check point
    42     */
    43     class _GametypesExport RaceCheckPoint : public DistanceMultiTrigger, public RadarViewable
     39     @brief
     40     The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
     41     Don't forget to control the indexes of your check points and to set one last check point
     42     */
     43    class _GametypesExport RaceCheckPoint: public DistanceMultiTrigger,
     44            public RadarViewable
    4445    {
    4546        public:
     
    5051
    5152            inline void setCheckpointIndex(int checkpointIndex)
    52                 { this->checkpointIndex_ = checkpointIndex; }
     53            {
     54                this->checkpointIndex_ = checkpointIndex;
     55            }
    5356            inline int getCheckpointIndex() const
    54                 { return this->checkpointIndex_; }
     57            {
     58                return this->checkpointIndex_;
     59            }
    5560
    5661            void setNextCheckpointsAsVector3(const Vector3& checkpoints);
    57             Vector3 getNextCheckpointsAsVector3() const;
    58             const std::set<int>& getNextCheckpoints() const
    59                 { return this->nextCheckpoints_; }
     62            Vector3 getNextCheckpointsAsVector3();
     63            Vector3 getVirtualNextCheckpointsAsVector3() const;
     64            void setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints);
     65            int changeVirtualToRealCheckPoint(int);
    6066
     67            const std::set<int>& getVirtualNextCheckpoints() const
     68            {
     69                return this->nextCheckpointsVirtual_;
     70            }
     71
     72            const std::set<int>& getNextCheckpoints()
     73            {
     74                return nextCheckpoints_;
     75                std::set<int> temp;
     76                std::set<int> temp2=getVirtualNextCheckpoints();
     77                for (std::set<int>::iterator it = temp2.begin(); it!=temp2.end(); ++it){
     78                    temp.insert(changeVirtualToRealCheckPoint((*it)));
     79                }
     80                return temp;
     81            }
    6182            inline void setLast(bool isLast)
    62                 { this->bIsLast_ = isLast; }
     83            {
     84                this->bIsLast_ = isLast;
     85            }
    6386            inline bool isLast() const
    64                 { return this->bIsLast_; }
     87            {
     88                return this->bIsLast_;
     89            }
    6590
    6691            virtual void setTimelimit(float timeLimit);
    6792            inline float getTimeLimit() const
    68                 { return this->timeLimit_; }
     93            {
     94                return this->timeLimit_;
     95            }
    6996
    70             inline PlayerInfo* getPlayer() const
    71                 { return this->player_; }
     97            PlayerInfo* getPlayer(unsigned int clientID) const;
     98
     99            bool playerWasHere(PlayerInfo* ) const;
     100
    72101            inline void resetPlayer()
    73                 { this->player_ = NULL; }
     102            {
     103                this->players_.clear();
     104            }
    74105
    75106        protected:
     107
    76108            virtual void fire(bool bIsTriggered, BaseObject* originator);
    77109
    78110            inline const WorldEntity* getWorldEntity() const
    79                 { return this; }
     111            {
     112                return this;
     113            }
    80114
    81115        private:
    82             int checkpointIndex_;           ///< The index of this check point. The race starts with the check point with the index 0
     116
     117            int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0
    83118            std::set<int> nextCheckpoints_; ///< the indexes of the next check points
    84             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.
    85             float timeLimit_;               ///< 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.
    86             PlayerInfo* player_;            ///< The player that reached the checkpoint
     119            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.
     120            float timeLimit_; ///< 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.
     121            std::vector<PlayerInfo*> players_; ///< The player that reached the checkpoint
     122            Vector3 myPosition_;
     123            std::set<int>  nextCheckpointsVirtual_;
     124            std::map<int,int> virtualToRealCheckPoints_; // if virtualChepoint was inserted the original can be reconstructed
    87125    };
    88126}
  • code/trunk/src/modules/gametypes/SpaceRace.cc

    r9348 r9526  
    3535#include "util/Convert.h"
    3636#include "util/Math.h"
    37 
     37#include "SpaceRaceBot.h"
    3838#include "items/Engine.h"
    3939
     
    4646        RegisterObject(SpaceRace);
    4747
     48        this->botclass_ = Class(SpaceRaceBot);//ClassByString("")
    4849        this->cantMove_ = false;
    4950        this->bTimeIsUp_ = false;
  • code/trunk/src/modules/gametypes/SpaceRaceManager.cc

    r9348 r9526  
    3838#include "util/Math.h"
    3939
    40 
    41 
    4240namespace orxonox
    4341{
    4442    CreateFactory(SpaceRaceManager);
    4543
    46     SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : BaseObject(creator)
     44    SpaceRaceManager::SpaceRaceManager(BaseObject* creator) :
     45        BaseObject(creator)
    4746    {
    4847        RegisterObject(SpaceRaceManager);
    49 
     48        this->race_ = orxonox_cast<SpaceRace*>(this->getGametype().get());
     49        assert(race_);
     50        //amountOfPlayers=(race_->getPlayers()).size();
    5051        this->firstcheckpointvisible_ = false;
    5152    }
     
    5455    {
    5556        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    56             this->checkpoints_[i]->destroy();
     57        this->checkpoints_[i]->destroy();
    5758    }
    5859
     
    6162        SUPER(SpaceRaceManager, XMLPort, xmlelement, mode);
    6263
    63         XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint,  xmlelement, mode);
     64        XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode);
    6465    }
    6566
     
    6768    {
    6869        SUPER(SpaceRaceManager,tick,dt);
     70
     71        this->players_ = this->race_->getPlayers();
    6972
    7073        if (this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_)
     
    7477        }
    7578
    76         for (size_t i = 0; i < this->checkpoints_.size(); ++i)
     79        for ( std::map< PlayerInfo*, Player>::iterator it = players_.begin(); it != players_.end(); ++it)
    7780        {
    78             if (this->checkpoints_[i]->getPlayer() != NULL)
    79                 this->checkpointReached(this->checkpoints_[i], this->checkpoints_[i]->getPlayer());
     81
     82            for (size_t i = 0; i < this->checkpoints_.size(); ++i)
     83            {
     84                if (this->checkpoints_[i]->playerWasHere(it->first)){
     85                this->checkpointReached(this->checkpoints_[i], it->first /*this->checkpoints_[i]->getPlayer()*/);
     86                }
     87            }
    8088        }
     89
    8190    }
    8291
     
    8998    {
    9099        if (index < this->checkpoints_.size())
    91             return this->checkpoints_[index];
     100        return this->checkpoints_[index];
    92101        else
    93             return 0;
     102        return 0;
     103    }
     104
     105    std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints()
     106    {
     107        return checkpoints_;
    94108    }
    95109
    96110    /**
    97         @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex).
    98     */
     111     @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex).
     112     */
    99113    RaceCheckPoint* SpaceRaceManager::findCheckpoint(int index) const
    100114    {
    101115        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    102             if (this->checkpoints_[i]->getCheckpointIndex() == index)
    103                 return this->checkpoints_[i];
     116        if (this->checkpoints_[i]->getCheckpointIndex() == index)
     117        return this->checkpoints_[i];
    104118        return 0;
    105119    }
     
    107121    bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const
    108122    {
    109         if (oldCheckpoint)
     123        if (oldCheckpoint != NULL)
    110124        {
    111125            // the player already visited an old checkpoint; see which checkpoints are possible now
    112126            const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints();
    113127            for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it)
    114                 if (this->findCheckpoint(*it) == newCheckpoint)
    115                     return true;
     128            if (this->findCheckpoint(*it) == newCheckpoint)
     129            return true;
    116130            return false;
    117131        }
     
    128142        assert(gametype);
    129143        if (!gametype)
    130             return;
     144        return;
    131145
    132         RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player);
     146        RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); // returns the last from player reached checkpoint
    133147
    134148        if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player))
     
    152166                // adjust the radarvisibility
    153167                gametype->newCheckpointReached(newCheckpoint, player);
    154                 this->updateRadarVisibility(oldCheckpoint, newCheckpoint);
     168                if(player->isHumanPlayer())
     169                    this->updateRadarVisibility(oldCheckpoint, newCheckpoint);
    155170            }
    156171        }
    157172
    158         newCheckpoint->resetPlayer();
     173        // newCheckpoint->resetPlayer(); loescht playerpointer TODO: check if problems occur
    159174    }
    160175
     
    165180            const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints();
    166181            for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it)
    167                 this->findCheckpoint(*it)->setRadarVisibility(false);
     182            this->findCheckpoint(*it)->setRadarVisibility(false);
    168183        }
    169184
     
    174189            const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints();
    175190            for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it)
    176                 this->findCheckpoint(*it)->setRadarVisibility(true);
     191            this->findCheckpoint(*it)->setRadarVisibility(true);
    177192        }
    178193    }
  • code/trunk/src/modules/gametypes/SpaceRaceManager.h

    r9348 r9526  
    6767            void checkpointReached(RaceCheckPoint* newCheckpoint, PlayerInfo* player);
    6868
     69            std::vector<RaceCheckPoint*> getAllCheckpoints();
     70
    6971            void tick(float dt);
    7072
     
    7678            std::vector<RaceCheckPoint*> checkpoints_;
    7779            bool firstcheckpointvisible_; ///< true if the first check point is visible.
     80            SpaceRace* race_; // needed to get the players
     81            //int amountOfPlayers;
     82            std::map<PlayerInfo*, Player> players_;
    7883    };
    7984}
Note: See TracChangeset for help on using the changeset viewer.