Changeset 9412 for code/branches/Racingbot
- Timestamp:
- Oct 22, 2012, 5:05:14 PM (12 years ago)
- Location:
- code/branches/Racingbot/src/modules/gametypes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc
r9348 r9412 43 43 CreateFactory(RaceCheckPoint); 44 44 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)) 46 48 { 47 RegisterObject(RaceCheckPoint); 48 49 this->setDistance(100); 49 RegisterObject(RaceCheckPoint) 50 ; this->setDistance(100); 50 51 this->setBeaconMode("off"); 51 52 this->setBroadcast(false); … … 60 61 this->bIsLast_ = false; 61 62 this->timeLimit_ = 0; 62 this->player_ = NULL;63 //this->players_ = vector<PlayerInfo*>(); 63 64 } 64 65 66 RaceCheckPoint::~RaceCheckPoint() 67 { 65 68 66 RaceCheckPoint::~RaceCheckPoint() 67 { 68 } 69 } 69 70 70 71 void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 86 87 ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator); 87 88 if (entity) 88 this->player_ = entity->getPlayer();89 this->players_.push_back(entity->getPlayer()); 89 90 } 90 91 } … … 95 96 if (this->timeLimit_ != 0) 96 97 { 97 std::string message = 98 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); 99 100 this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message); 100 101 ChatManager::message(message); … … 107 108 108 109 if (checkpoints.x > -1) 109 110 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); 110 111 if (checkpoints.y > -1) 111 112 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5)); 112 113 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; 114 145 } 115 146 -
code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h
r9263 r9412 37 37 { 38 38 /** 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 44 45 { 45 46 public: … … 50 51 51 52 inline void setCheckpointIndex(int checkpointIndex) 52 { this->checkpointIndex_ = checkpointIndex; } 53 { 54 this->checkpointIndex_ = checkpointIndex; 55 } 53 56 inline int getCheckpointIndex() const 54 { return this->checkpointIndex_; } 57 { 58 return this->checkpointIndex_; 59 } 55 60 56 61 void setNextCheckpointsAsVector3(const Vector3& checkpoints); 57 62 Vector3 getNextCheckpointsAsVector3() const; 58 63 const std::set<int>& getNextCheckpoints() const 59 { return this->nextCheckpoints_; } 64 { 65 return this->nextCheckpoints_; 66 } 60 67 61 68 inline void setLast(bool isLast) 62 { this->bIsLast_ = isLast; } 69 { 70 this->bIsLast_ = isLast; 71 } 63 72 inline bool isLast() const 64 { return this->bIsLast_; } 73 { 74 return this->bIsLast_; 75 } 65 76 66 77 virtual void setTimelimit(float timeLimit); 67 78 inline float getTimeLimit() const 68 { return this->timeLimit_; } 79 { 80 return this->timeLimit_; 81 } 69 82 70 inline PlayerInfo* getPlayer() const 71 { return this->player_; } 83 PlayerInfo* getPlayer(unsigned int clientID) const; 84 85 bool playerWasHere(PlayerInfo* ) const; 86 72 87 inline void resetPlayer() 73 { this->player_ = NULL; } 88 { 89 this->players_.clear(); 90 } 74 91 75 92 protected: … … 77 94 78 95 inline const WorldEntity* getWorldEntity() const 79 { return this; } 96 { 97 return this; 98 } 80 99 81 100 private: 82 int checkpointIndex_; 101 int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0 83 102 std::set<int> nextCheckpoints_; ///< the indexes of the next check points 84 bool bIsLast_; 85 float timeLimit_; 86 PlayerInfo* player_;///< The player that reached the checkpoint103 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 87 106 }; 88 107 } -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
r9399 r9412 1 1 /* 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. 3 21 * 4 22 * Created on: Oct 8, 2012 … … 9 27 #include "core/CoreIncludes.h" 10 28 #include "core/XMLPort.h" 29 #include "gametypes/SpaceRaceManager.h" 11 30 12 31 … … 17 36 { 18 37 38 /* 39 * Idea: Find static Point (checkpoints the spaceship has to reach) 40 */ 19 41 SpaceRaceController::SpaceRaceController(BaseObject* creator): ArtificialController(creator) 20 42 { 21 43 22 std::vector<RaceCheckPoint*> wayOptions = NULL; 23 std::vector<RaceCheckPoint*> wayChosen = new std::vector<RaceCheckPoint*>(); 44 std::vector<RaceCheckPoint*> checkpoints; 24 45 // TODO Auto-generated constructor stub 25 46 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"); 27 49 28 50 29 51 } 52 /* 53 RaceCheckPoint* SpaceRaceController::nextPoint(){ 54 return NULL; 55 }*/ 56 57 std::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 68 void 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 30 77 31 78 SpaceRaceController::~SpaceRaceController() -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h
r9399 r9412 1 1 /* 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 * 3 22 * 4 23 * Created on: Oct 8, 2012 … … 12 31 #include "controllers/ArtificialController.h" 13 32 #include "gametypes/Gametype.h" 14 33 #include "gametypes/RaceCheckPoint.h" 15 34 16 35 … … 19 38 class _GametypesExport SpaceRaceController : public ArtificialController, public Tickable 20 39 { 21 private: 40 private:/* 22 41 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>*); 24 47 public: 25 48 SpaceRaceController(BaseObject* creator); -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.cc
r9399 r9412 38 38 #include "util/Math.h" 39 39 40 41 42 40 namespace orxonox 43 41 { 44 42 CreateFactory(SpaceRaceManager); 45 43 46 SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : BaseObject(creator) 44 SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : 45 BaseObject(creator) 47 46 { 48 RegisterObject(SpaceRaceManager); 49 47 RegisterObject(SpaceRaceManager) 48 ; this->race_ = orxonox_cast<SpaceRace*>(this->getGametype().get()); 49 assert(race_); 50 //amountOfPlayers=(race_->getPlayers()).size(); 50 51 this->firstcheckpointvisible_ = false; 52 this->players_ = this->race_->getPlayers(); 51 53 } 52 54 … … 54 56 { 55 57 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 56 58 this->checkpoints_[i]->destroy(); 57 59 } 58 60 … … 61 63 SUPER(SpaceRaceManager, XMLPort, xmlelement, mode); 62 64 63 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, 65 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode); 64 66 } 65 67 … … 74 76 } 75 77 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) 77 79 { 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 } 80 85 } 86 81 87 } 82 88 … … 89 95 { 90 96 if (index < this->checkpoints_.size()) 91 97 return this->checkpoints_[index]; 92 98 else 93 99 return 0; 94 100 } 95 101 96 std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints(){ 102 std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints() 103 { 97 104 return checkpoints_; 98 105 } 99 106 100 107 /** 101 102 */108 @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex). 109 */ 103 110 RaceCheckPoint* SpaceRaceManager::findCheckpoint(int index) const 104 111 { 105 112 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 106 107 113 if (this->checkpoints_[i]->getCheckpointIndex() == index) 114 return this->checkpoints_[i]; 108 115 return 0; 109 116 } … … 111 118 bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const 112 119 { 113 if (oldCheckpoint )120 if (oldCheckpoint != NULL) 114 121 { 115 122 // the player already visited an old checkpoint; see which checkpoints are possible now 116 123 const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints(); 117 124 for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it) 118 119 125 if (this->findCheckpoint(*it) == newCheckpoint) 126 return true; 120 127 return false; 121 128 } … … 132 139 assert(gametype); 133 140 if (!gametype) 134 141 return; 135 142 136 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); 143 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); // returns the last from player reached checkpoint 137 144 138 145 if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player)) … … 160 167 } 161 168 162 newCheckpoint->resetPlayer();169 // newCheckpoint->resetPlayer(); loescht playerpointer TODO: check if problems occur 163 170 } 164 171 … … 169 176 const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints(); 170 177 for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it) 171 178 this->findCheckpoint(*it)->setRadarVisibility(false); 172 179 } 173 180 … … 178 185 const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints(); 179 186 for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it) 180 187 this->findCheckpoint(*it)->setRadarVisibility(true); 181 188 } 182 189 } -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.h
r9399 r9412 78 78 std::vector<RaceCheckPoint*> checkpoints_; 79 79 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_; 80 83 }; 81 84 }
Note: See TracChangeset
for help on using the changeset viewer.