[Orxonox-commit 4743] r9412 - code/branches/Racingbot/src/modules/gametypes
purgham at orxonox.net
purgham at orxonox.net
Mon Oct 22 17:05:14 CEST 2012
Author: purgham
Date: 2012-10-22 17:05:14 +0200 (Mon, 22 Oct 2012)
New Revision: 9412
Modified:
code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc
code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h
code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.cc
code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.h
Log:
Made SpaceRace-Mode usable for more then 1 Spaceship
Modified: code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc 2012-10-22 14:19:20 UTC (rev 9411)
+++ code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc 2012-10-22 15:05:14 UTC (rev 9412)
@@ -42,11 +42,12 @@
{
CreateFactory(RaceCheckPoint);
- RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
+ RaceCheckPoint::RaceCheckPoint(BaseObject* creator) :
+ DistanceMultiTrigger(creator), RadarViewable(creator,
+ static_cast<WorldEntity*> (this))
{
- RegisterObject(RaceCheckPoint);
-
- this->setDistance(100);
+ RegisterObject(RaceCheckPoint)
+; this->setDistance(100);
this->setBeaconMode("off");
this->setBroadcast(false);
this->setSimultaneousTriggerers(100);
@@ -59,13 +60,13 @@
this->checkpointIndex_ = 0;
this->bIsLast_ = false;
this->timeLimit_ = 0;
- this->player_ = NULL;
+ //this->players_ = vector<PlayerInfo*>();
}
+ RaceCheckPoint::~RaceCheckPoint()
+ {
- RaceCheckPoint::~RaceCheckPoint()
- {
- }
+ }
void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
@@ -85,7 +86,7 @@
{
ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator);
if (entity)
- this->player_ = entity->getPlayer();
+ this->players_.push_back(entity->getPlayer());
}
}
@@ -94,8 +95,8 @@
this->timeLimit_ = timeLimit;
if (this->timeLimit_ != 0)
{
- std::string message = "You have " + multi_cast<std::string>(this->timeLimit_)
- + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
+ std::string message = "You have " + multi_cast<std::string>(this->timeLimit_)
+ + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message);
ChatManager::message(message);
}
@@ -106,13 +107,43 @@
this->nextCheckpoints_.clear();
if (checkpoints.x > -1)
- this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5));
+ this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5));
if (checkpoints.y > -1)
- this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
+ this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
if (checkpoints.z > -1)
- this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
+ this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
}
+ PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const
+ {
+ if (players_.size() > 0)
+ {
+ for (int i = 0; i < players_.size(); i++)
+ {
+ if (this->players_[i]->getClientID() == clientID)
+ {
+ return players_[i];
+ }
+ }
+ }
+ return NULL;
+ }
+
+ bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const
+ {
+ if (players_.size() > 0)
+ {
+ for (int i = 0; i < players_.size(); i++)
+ {
+ if (this->players_[i] == player)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const
{
Vector3 checkpoints = Vector3(-1, -1, -1);
Modified: code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h 2012-10-22 14:19:20 UTC (rev 9411)
+++ code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h 2012-10-22 15:05:14 UTC (rev 9412)
@@ -36,11 +36,12 @@
namespace orxonox
{
/**
- @brief
- The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
- Don't forget to control the indexes of your check points and to set one last check point
- */
- class _GametypesExport RaceCheckPoint : public DistanceMultiTrigger, public RadarViewable
+ @brief
+ The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
+ Don't forget to control the indexes of your check points and to set one last check point
+ */
+ class _GametypesExport RaceCheckPoint: public DistanceMultiTrigger,
+ public RadarViewable
{
public:
RaceCheckPoint(BaseObject* creator);
@@ -49,41 +50,59 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
inline void setCheckpointIndex(int checkpointIndex)
- { this->checkpointIndex_ = checkpointIndex; }
+ {
+ this->checkpointIndex_ = checkpointIndex;
+ }
inline int getCheckpointIndex() const
- { return this->checkpointIndex_; }
+ {
+ return this->checkpointIndex_;
+ }
void setNextCheckpointsAsVector3(const Vector3& checkpoints);
Vector3 getNextCheckpointsAsVector3() const;
const std::set<int>& getNextCheckpoints() const
- { return this->nextCheckpoints_; }
+ {
+ return this->nextCheckpoints_;
+ }
inline void setLast(bool isLast)
- { this->bIsLast_ = isLast; }
+ {
+ this->bIsLast_ = isLast;
+ }
inline bool isLast() const
- { return this->bIsLast_; }
+ {
+ return this->bIsLast_;
+ }
virtual void setTimelimit(float timeLimit);
inline float getTimeLimit() const
- { return this->timeLimit_; }
+ {
+ return this->timeLimit_;
+ }
- inline PlayerInfo* getPlayer() const
- { return this->player_; }
+ PlayerInfo* getPlayer(unsigned int clientID) const;
+
+ bool playerWasHere(PlayerInfo* ) const;
+
inline void resetPlayer()
- { this->player_ = NULL; }
+ {
+ this->players_.clear();
+ }
protected:
virtual void fire(bool bIsTriggered, BaseObject* originator);
inline const WorldEntity* getWorldEntity() const
- { return this; }
+ {
+ return this;
+ }
private:
- int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0
+ int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0
std::set<int> nextCheckpoints_; ///< the indexes of the next check points
- 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.
- 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.
- PlayerInfo* player_; ///< The player that reached the checkpoint
+ 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.
+ 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.
+ std::vector<PlayerInfo*> players_; ///< The player that reached the checkpoint
};
}
Modified: code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc 2012-10-22 14:19:20 UTC (rev 9411)
+++ code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc 2012-10-22 15:05:14 UTC (rev 9412)
@@ -1,6 +1,24 @@
/*
- * SpaceRaceController.cc
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
*
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
* Created on: Oct 8, 2012
* Author: purgham
*/
@@ -8,6 +26,7 @@
#include <gametypes/SpaceRaceController.h>
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
+#include "gametypes/SpaceRaceManager.h"
// Von SpaceRaceManager points einlesen
@@ -16,18 +35,46 @@
namespace orxonox
{
+ /*
+ * Idea: Find static Point (checkpoints the spaceship has to reach)
+ */
SpaceRaceController::SpaceRaceController(BaseObject* creator): ArtificialController(creator)
{
- std::vector<RaceCheckPoint*> wayOptions = NULL;
- std::vector<RaceCheckPoint*> wayChosen = new std::vector<RaceCheckPoint*>();
+ std::vector<RaceCheckPoint*> checkpoints;
// TODO Auto-generated constructor stub
for (ObjectList<SpaceRaceManager >::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)
- wayOptions=it->getAllCheckpoints();
+ checkpoints=it->getAllCheckpoints();
+ //OrxAssert(checkpoints, "No Checkpoints in Level");
}
+/*
+RaceCheckPoint* SpaceRaceController::nextPoint(){
+ return NULL;
+}*/
+std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(std::vector<RaceCheckPoint*> allCheckpoints){
+ std::map< RaceCheckPoint*, int> * zaehler= new std::map< RaceCheckPoint*, int>(); // counts how many times the checkpoit was reached for simulation
+ for (unsigned int i=0; i<allCheckpoints.size() ; i++){
+ zaehler->insert ( std::pair<RaceCheckPoint*,int>(allCheckpoints[i], 0));
+ }
+ rekSimulationCheckpointsReached(zaehler->begin()->first, & allCheckpoints, zaehler);
+ //Werte auslesen und statische Checkpoints bestimmen
+ delete zaehler;
+
+}
+
+void SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::vector<RaceCheckPoint*>* checkpoints, std::map< RaceCheckPoint*, int>* zaehler){
+ zaehler->at(currentCheckpoint)++;
+ if(!currentCheckpoint->isLast()){
+ for( std::set<int>::iterator it=currentCheckpoint->getNextCheckpoints().begin(); it != currentCheckpoint->getNextCheckpoints().end(); ++it){
+ rekSimulationCheckpointsReached( (*checkpoints)[(*it)], checkpoints, zaehler);
+ }
+ }
+}
+
+
SpaceRaceController::~SpaceRaceController()
{
// TODO Auto-generated destructor stub
Modified: code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h 2012-10-22 14:19:20 UTC (rev 9411)
+++ code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h 2012-10-22 15:05:14 UTC (rev 9412)
@@ -1,6 +1,25 @@
/*
- * SpaceRaceController.h
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
*
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
* Created on: Oct 8, 2012
* Author: purgham
*/
@@ -11,16 +30,20 @@
#include "gametypes/GametypesPrereqs.h"
#include "controllers/ArtificialController.h"
#include "gametypes/Gametype.h"
+#include "gametypes/RaceCheckPoint.h"
-
namespace orxonox
{
class _GametypesExport SpaceRaceController : public ArtificialController, public Tickable
{
- private:
+ private:/*
vector<RaceCheckPoint*> lastRaceCheckpoint;
- vector<RaceCheckPoint*> nextRaceCheckpoint;
+ vector<RaceCheckPoint*> nextRaceCheckpoint;*/
+ //RaceCheckPoint* nextPoint();
+ std::vector<RaceCheckPoint*> findStaticCheckpoints(std::vector<RaceCheckPoint*>);
+ std::vector<RaceCheckPoint*> staticCheckpoints();
+ void rekSimulationCheckpointsReached(RaceCheckPoint* , std::vector<RaceCheckPoint*>* checkpoints, std::map< RaceCheckPoint*, int>*);
public:
SpaceRaceController(BaseObject* creator);
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
Modified: code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.cc
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.cc 2012-10-22 14:19:20 UTC (rev 9411)
+++ code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.cc 2012-10-22 15:05:14 UTC (rev 9412)
@@ -37,30 +37,32 @@
#include "util/Convert.h"
#include "util/Math.h"
-
-
namespace orxonox
{
CreateFactory(SpaceRaceManager);
- SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : BaseObject(creator)
+ SpaceRaceManager::SpaceRaceManager(BaseObject* creator) :
+ BaseObject(creator)
{
- RegisterObject(SpaceRaceManager);
-
+ RegisterObject(SpaceRaceManager)
+; this->race_ = orxonox_cast<SpaceRace*>(this->getGametype().get());
+ assert(race_);
+ //amountOfPlayers=(race_->getPlayers()).size();
this->firstcheckpointvisible_ = false;
+ this->players_ = this->race_->getPlayers();
}
SpaceRaceManager::~SpaceRaceManager()
{
for (size_t i = 0; i < this->checkpoints_.size(); ++i)
- this->checkpoints_[i]->destroy();
+ this->checkpoints_[i]->destroy();
}
void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(SpaceRaceManager, XMLPort, xmlelement, mode);
- XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode);
+ XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode);
}
void SpaceRaceManager::tick(float dt)
@@ -73,11 +75,15 @@
this->firstcheckpointvisible_ = true;
}
- for (size_t i = 0; i < this->checkpoints_.size(); ++i)
+ for ( std::map< PlayerInfo*, Player>::iterator it = players_.begin(); it != players_.end(); ++it)
{
- if (this->checkpoints_[i]->getPlayer() != NULL)
- this->checkpointReached(this->checkpoints_[i], this->checkpoints_[i]->getPlayer());
+ for (size_t i = 0; i < this->checkpoints_.size(); ++i)
+ {
+ if (this->checkpoints_[i]->playerWasHere(it->first))
+ this->checkpointReached(this->checkpoints_[i], it->first /*this->checkpoints_[i]->getPlayer()*/);
+ }
}
+
}
void SpaceRaceManager::addCheckpoint(RaceCheckPoint* checkpoint)
@@ -88,35 +94,36 @@
RaceCheckPoint* SpaceRaceManager::getCheckpoint(unsigned int index) const
{
if (index < this->checkpoints_.size())
- return this->checkpoints_[index];
+ return this->checkpoints_[index];
else
- return 0;
+ return 0;
}
- std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints(){
+ std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints()
+ {
return checkpoints_;
}
/**
- @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex).
- */
+ @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex).
+ */
RaceCheckPoint* SpaceRaceManager::findCheckpoint(int index) const
{
for (size_t i = 0; i < this->checkpoints_.size(); ++i)
- if (this->checkpoints_[i]->getCheckpointIndex() == index)
- return this->checkpoints_[i];
+ if (this->checkpoints_[i]->getCheckpointIndex() == index)
+ return this->checkpoints_[i];
return 0;
}
bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const
{
- if (oldCheckpoint)
+ if (oldCheckpoint != NULL)
{
// the player already visited an old checkpoint; see which checkpoints are possible now
const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints();
for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it)
- if (this->findCheckpoint(*it) == newCheckpoint)
- return true;
+ if (this->findCheckpoint(*it) == newCheckpoint)
+ return true;
return false;
}
else
@@ -131,9 +138,9 @@
SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
assert(gametype);
if (!gametype)
- return;
+ return;
- RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player);
+ RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); // returns the last from player reached checkpoint
if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player))
{
@@ -159,7 +166,7 @@
}
}
- newCheckpoint->resetPlayer();
+ // newCheckpoint->resetPlayer(); loescht playerpointer TODO: check if problems occur
}
void SpaceRaceManager::updateRadarVisibility(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint) const
@@ -168,7 +175,7 @@
{
const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints();
for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it)
- this->findCheckpoint(*it)->setRadarVisibility(false);
+ this->findCheckpoint(*it)->setRadarVisibility(false);
}
if (newCheckpoint)
@@ -177,7 +184,7 @@
const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints();
for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it)
- this->findCheckpoint(*it)->setRadarVisibility(true);
+ this->findCheckpoint(*it)->setRadarVisibility(true);
}
}
}
Modified: code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.h
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.h 2012-10-22 14:19:20 UTC (rev 9411)
+++ code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.h 2012-10-22 15:05:14 UTC (rev 9412)
@@ -77,6 +77,9 @@
private:
std::vector<RaceCheckPoint*> checkpoints_;
bool firstcheckpointvisible_; ///< true if the first check point is visible.
+ SpaceRace* race_; // needed to get the players
+ //int amountOfPlayers;
+ std::map<PlayerInfo*, Player> players_;
};
}
More information about the Orxonox-commit
mailing list