Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9412


Ignore:
Timestamp:
Oct 22, 2012, 5:05:14 PM (12 years ago)
Author:
purgham
Message:

Made SpaceRace-Mode usable for more then 1 Spaceship

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

Legend:

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

    r9348 r9412  
    4343    CreateFactory(RaceCheckPoint);
    4444
    45     RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
     45    RaceCheckPoint::RaceCheckPoint(BaseObject* creator) :
     46        DistanceMultiTrigger(creator), RadarViewable(creator,
     47                static_cast<WorldEntity*> (this))
    4648    {
    47         RegisterObject(RaceCheckPoint);
    48 
    49         this->setDistance(100);
     49        RegisterObject(RaceCheckPoint)
     50;        this->setDistance(100);
    5051        this->setBeaconMode("off");
    5152        this->setBroadcast(false);
     
    6061        this->bIsLast_ = false;
    6162        this->timeLimit_ = 0;
    62         this->player_ = NULL;
     63        //this->players_ = vector<PlayerInfo*>();
    6364    }
    6465
     66    RaceCheckPoint::~RaceCheckPoint()
     67    {
    6568
    66    RaceCheckPoint::~RaceCheckPoint()
    67    {
    68    }
     69    }
    6970
    7071    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     
    8687            ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator);
    8788            if (entity)
    88                 this->player_ = entity->getPlayer();
     89            this->players_.push_back(entity->getPlayer());
    8990        }
    9091    }
     
    9596        if (this->timeLimit_ != 0)
    9697        {
    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);
     98            std::string message = "You have " + multi_cast<std::string>(this->timeLimit_)
     99            + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
    99100            this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message);
    100101            ChatManager::message(message);
     
    107108
    108109        if (checkpoints.x > -1)
    109             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5));
     110        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5));
    110111        if (checkpoints.y > -1)
    111             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
     112        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
    112113        if (checkpoints.z > -1)
    113             this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
     114        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
     115    }
     116
     117    PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const
     118    {
     119        if (players_.size() > 0)
     120        {
     121            for (int i = 0; i < players_.size(); i++)
     122            {
     123                if (this->players_[i]->getClientID() == clientID)
     124                {
     125                    return players_[i];
     126                }
     127            }
     128        }
     129        return NULL;
     130    }
     131
     132    bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const
     133    {
     134        if (players_.size() > 0)
     135        {
     136            for (int i = 0; i < players_.size(); i++)
     137            {
     138                if (this->players_[i] == player)
     139                {
     140                    return true;
     141                }
     142            }
     143        }
     144        return false;
    114145    }
    115146
  • code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h

    r9263 r9412  
    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);
    5762            Vector3 getNextCheckpointsAsVector3() const;
    5863            const std::set<int>& getNextCheckpoints() const
    59                 { return this->nextCheckpoints_; }
     64            {
     65                return this->nextCheckpoints_;
     66            }
    6067
    6168            inline void setLast(bool isLast)
    62                 { this->bIsLast_ = isLast; }
     69            {
     70                this->bIsLast_ = isLast;
     71            }
    6372            inline bool isLast() const
    64                 { return this->bIsLast_; }
     73            {
     74                return this->bIsLast_;
     75            }
    6576
    6677            virtual void setTimelimit(float timeLimit);
    6778            inline float getTimeLimit() const
    68                 { return this->timeLimit_; }
     79            {
     80                return this->timeLimit_;
     81            }
    6982
    70             inline PlayerInfo* getPlayer() const
    71                 { return this->player_; }
     83            PlayerInfo* getPlayer(unsigned int clientID) const;
     84
     85            bool playerWasHere(PlayerInfo* ) const;
     86
    7287            inline void resetPlayer()
    73                 { this->player_ = NULL; }
     88            {
     89                this->players_.clear();
     90            }
    7491
    7592        protected:
     
    7794
    7895            inline const WorldEntity* getWorldEntity() const
    79                 { return this; }
     96            {
     97                return this;
     98            }
    8099
    81100        private:
    82             int checkpointIndex_;           ///< The index of this check point. The race starts with the check point with the index 0
     101            int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0
    83102            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
     103            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.
     104            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.
     105            std::vector<PlayerInfo*> players_; ///< The player that reached the checkpoint
    87106    };
    88107}
  • code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc

    r9399 r9412  
    11/*
    2  * SpaceRaceController.cc
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    321 *
    422 *  Created on: Oct 8, 2012
     
    927#include "core/CoreIncludes.h"
    1028#include "core/XMLPort.h"
     29#include "gametypes/SpaceRaceManager.h"
    1130
    1231
     
    1736{
    1837
     38    /*
     39     * Idea: Find static Point (checkpoints the spaceship has to reach)
     40     */
    1941SpaceRaceController::SpaceRaceController(BaseObject* creator): ArtificialController(creator)
    2042{
    2143
    22     std::vector<RaceCheckPoint*> wayOptions = NULL;
    23     std::vector<RaceCheckPoint*> wayChosen = new std::vector<RaceCheckPoint*>();
     44    std::vector<RaceCheckPoint*> checkpoints;
    2445    // TODO Auto-generated constructor stub
    2546    for (ObjectList<SpaceRaceManager >::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)
    26         wayOptions=it->getAllCheckpoints();
     47        checkpoints=it->getAllCheckpoints();
     48    //OrxAssert(checkpoints, "No Checkpoints in Level");
    2749
    2850
    2951}
     52/*
     53RaceCheckPoint* SpaceRaceController::nextPoint(){
     54    return NULL;
     55}*/
     56
     57std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(std::vector<RaceCheckPoint*> allCheckpoints){
     58    std::map< RaceCheckPoint*, int> * zaehler= new std::map< RaceCheckPoint*, int>(); // counts how many times the checkpoit was reached for simulation
     59    for (unsigned int i=0; i<allCheckpoints.size() ; i++){
     60        zaehler->insert ( std::pair<RaceCheckPoint*,int>(allCheckpoints[i], 0));
     61    }
     62    rekSimulationCheckpointsReached(zaehler->begin()->first, & allCheckpoints, zaehler);
     63    //Werte auslesen und statische Checkpoints bestimmen
     64    delete zaehler;
     65
     66}
     67
     68void SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::vector<RaceCheckPoint*>* checkpoints, std::map< RaceCheckPoint*, int>* zaehler){
     69    zaehler->at(currentCheckpoint)++;
     70    if(!currentCheckpoint->isLast()){
     71        for( std::set<int>::iterator it=currentCheckpoint->getNextCheckpoints().begin(); it != currentCheckpoint->getNextCheckpoints().end(); ++it){
     72            rekSimulationCheckpointsReached( (*checkpoints)[(*it)], checkpoints, zaehler);
     73        }
     74    }
     75}
     76
    3077
    3178SpaceRaceController::~SpaceRaceController()
  • code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h

    r9399 r9412  
    11/*
    2  * SpaceRaceController.h
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
    322 *
    423 *  Created on: Oct 8, 2012
     
    1231#include "controllers/ArtificialController.h"
    1332#include "gametypes/Gametype.h"
    14 
     33#include "gametypes/RaceCheckPoint.h"
    1534
    1635
     
    1938    class _GametypesExport SpaceRaceController : public ArtificialController, public Tickable
    2039    {
    21         private:
     40        private:/*
    2241            vector<RaceCheckPoint*> lastRaceCheckpoint;
    23             vector<RaceCheckPoint*> nextRaceCheckpoint;
     42            vector<RaceCheckPoint*> nextRaceCheckpoint;*/
     43            //RaceCheckPoint* nextPoint();
     44            std::vector<RaceCheckPoint*> findStaticCheckpoints(std::vector<RaceCheckPoint*>);
     45            std::vector<RaceCheckPoint*> staticCheckpoints();
     46            void rekSimulationCheckpointsReached(RaceCheckPoint* , std::vector<RaceCheckPoint*>* checkpoints, std::map< RaceCheckPoint*, int>*);
    2447        public:
    2548          SpaceRaceController(BaseObject* creator);
  • code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.cc

    r9399 r9412  
    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    {
    48         RegisterObject(SpaceRaceManager);
    49 
     47        RegisterObject(SpaceRaceManager)
     48;        this->race_ = orxonox_cast<SpaceRace*>(this->getGametype().get());
     49        assert(race_);
     50        //amountOfPlayers=(race_->getPlayers()).size();
    5051        this->firstcheckpointvisible_ = false;
     52        this->players_ = this->race_->getPlayers();
    5153    }
    5254
     
    5456    {
    5557        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    56             this->checkpoints_[i]->destroy();
     58        this->checkpoints_[i]->destroy();
    5759    }
    5860
     
    6163        SUPER(SpaceRaceManager, XMLPort, xmlelement, mode);
    6264
    63         XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint,  xmlelement, mode);
     65        XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode);
    6466    }
    6567
     
    7476        }
    7577
    76         for (size_t i = 0; i < this->checkpoints_.size(); ++i)
     78        for ( std::map< PlayerInfo*, Player>::iterator it = players_.begin(); it != players_.end(); ++it)
    7779        {
    78             if (this->checkpoints_[i]->getPlayer() != NULL)
    79                 this->checkpointReached(this->checkpoints_[i], this->checkpoints_[i]->getPlayer());
     80            for (size_t i = 0; i < this->checkpoints_.size(); ++i)
     81            {
     82                if (this->checkpoints_[i]->playerWasHere(it->first))
     83                this->checkpointReached(this->checkpoints_[i], it->first /*this->checkpoints_[i]->getPlayer()*/);
     84            }
    8085        }
     86
    8187    }
    8288
     
    8995    {
    9096        if (index < this->checkpoints_.size())
    91             return this->checkpoints_[index];
     97        return this->checkpoints_[index];
    9298        else
    93             return 0;
     99        return 0;
    94100    }
    95101
    96     std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints(){
     102    std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints()
     103    {
    97104        return checkpoints_;
    98105    }
    99106
    100107    /**
    101         @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex).
    102     */
     108     @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex).
     109     */
    103110    RaceCheckPoint* SpaceRaceManager::findCheckpoint(int index) const
    104111    {
    105112        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    106             if (this->checkpoints_[i]->getCheckpointIndex() == index)
    107                 return this->checkpoints_[i];
     113        if (this->checkpoints_[i]->getCheckpointIndex() == index)
     114        return this->checkpoints_[i];
    108115        return 0;
    109116    }
     
    111118    bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const
    112119    {
    113         if (oldCheckpoint)
     120        if (oldCheckpoint != NULL)
    114121        {
    115122            // the player already visited an old checkpoint; see which checkpoints are possible now
    116123            const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints();
    117124            for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it)
    118                 if (this->findCheckpoint(*it) == newCheckpoint)
    119                     return true;
     125            if (this->findCheckpoint(*it) == newCheckpoint)
     126            return true;
    120127            return false;
    121128        }
     
    132139        assert(gametype);
    133140        if (!gametype)
    134             return;
     141        return;
    135142
    136         RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player);
     143        RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); // returns the last from player reached checkpoint
    137144
    138145        if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player))
     
    160167        }
    161168
    162         newCheckpoint->resetPlayer();
     169        // newCheckpoint->resetPlayer(); loescht playerpointer TODO: check if problems occur
    163170    }
    164171
     
    169176            const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints();
    170177            for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it)
    171                 this->findCheckpoint(*it)->setRadarVisibility(false);
     178            this->findCheckpoint(*it)->setRadarVisibility(false);
    172179        }
    173180
     
    178185            const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints();
    179186            for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it)
    180                 this->findCheckpoint(*it)->setRadarVisibility(true);
     187            this->findCheckpoint(*it)->setRadarVisibility(true);
    181188        }
    182189    }
  • code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.h

    r9399 r9412  
    7878            std::vector<RaceCheckPoint*> checkpoints_;
    7979            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_;
    8083    };
    8184}
Note: See TracChangeset for help on using the changeset viewer.