[Orxonox-commit 4591] r9262 - code/trunk/src/modules/gametypes
landauf at orxonox.net
landauf at orxonox.net
Sat Jun 2 23:08:21 CEST 2012
Author: landauf
Date: 2012-06-02 23:08:21 +0200 (Sat, 02 Jun 2012)
New Revision: 9262
Modified:
code/trunk/src/modules/gametypes/RaceCheckPoint.h
code/trunk/src/modules/gametypes/SpaceRace.cc
code/trunk/src/modules/gametypes/SpaceRace.h
code/trunk/src/modules/gametypes/SpaceRaceManager.cc
code/trunk/src/modules/gametypes/SpaceRaceManager.h
Log:
fixed bug in SpaceRaceManager - it used the wrong index to identify Checkpoints (the order in which they appear in the XML file instead of RaceCheckPoint::getCheckpointIndex())
+ some more cleanup
Modified: code/trunk/src/modules/gametypes/RaceCheckPoint.h
===================================================================
--- code/trunk/src/modules/gametypes/RaceCheckPoint.h 2012-06-02 20:46:25 UTC (rev 9261)
+++ code/trunk/src/modules/gametypes/RaceCheckPoint.h 2012-06-02 21:08:21 UTC (rev 9262)
@@ -55,8 +55,6 @@
inline void setNextcheckpoint(const Vector3& checkpoints)
{ this->nextcheckpoints_ = checkpoints; }
- inline void setNextcheckpoint(float x, float y, float z)
- { this->setNextcheckpoint(Vector3(x, y, z)); }
inline const Vector3& getNextcheckpoint() const
{ return this->nextcheckpoints_; }
Modified: code/trunk/src/modules/gametypes/SpaceRace.cc
===================================================================
--- code/trunk/src/modules/gametypes/SpaceRace.cc 2012-06-02 20:46:25 UTC (rev 9261)
+++ code/trunk/src/modules/gametypes/SpaceRace.cc 2012-06-02 21:08:21 UTC (rev 9262)
@@ -77,6 +77,7 @@
{
SUPER(SpaceRace,tick,dt);
+ // spawn the players already when the countdown starts, but deactivate their engines
if (this->isStartCountdownRunning() && !this->cantMove_)
{
this->spawnPlayersIfRequested();
@@ -86,6 +87,7 @@
it->setActive(false);
}
+ // activate the engines again if the countdown ends
if (!this->isStartCountdownRunning() && this->cantMove_)
{
for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
@@ -103,10 +105,12 @@
{
int index = checkpoint->getCheckpointIndex();
this->checkpointReached_[player] = index;
+
this->clock_.capture();
int s = this->clock_.getSeconds();
int ms = this->clock_.getMilliseconds() % 1000;
- const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
+
+ const std::string& message = "Checkpoint " + multi_cast<std::string>(index + 1)
+ " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
ChatManager::message(message);
Modified: code/trunk/src/modules/gametypes/SpaceRace.h
===================================================================
--- code/trunk/src/modules/gametypes/SpaceRace.h 2012-06-02 20:46:25 UTC (rev 9261)
+++ code/trunk/src/modules/gametypes/SpaceRace.h 2012-06-02 21:08:21 UTC (rev 9262)
@@ -60,10 +60,7 @@
virtual void end();
- virtual void newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player);
-
- inline void setCheckpointReached(int index, PlayerInfo* player)
- { this->checkpointReached_[player] = index;}
+ void newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player);
inline int getCheckpointReached(PlayerInfo* player)
{ return this->checkpointReached_[player]; }
@@ -80,7 +77,7 @@
virtual void playerEntered(PlayerInfo* player); ///< Initializes values.
private:
- bool cantMove_;
+ bool cantMove_; ///< Helper variable, used to stall the engines before the race starts.
std::map<PlayerInfo*, int> checkpointReached_; ///< The number of the last check point reached by each player.
bool bTimeIsUp_; ///< True if one of the check points is reached too late.
Modified: code/trunk/src/modules/gametypes/SpaceRaceManager.cc
===================================================================
--- code/trunk/src/modules/gametypes/SpaceRaceManager.cc 2012-06-02 20:46:25 UTC (rev 9261)
+++ code/trunk/src/modules/gametypes/SpaceRaceManager.cc 2012-06-02 21:08:21 UTC (rev 9262)
@@ -93,13 +93,15 @@
return 0;
}
- int SpaceRaceManager::getIndex(RaceCheckPoint* checkpoint)
+ /**
+ @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] == checkpoint)
- return i;
-
- return -1;
+ if (this->checkpoints_[i]->getCheckpointIndex() == index)
+ return this->checkpoints_[i];
+ return 0;
}
void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player)
@@ -112,24 +114,24 @@
int index = gametype->getCheckpointReached(player);
if (index > -1)
{
- Vector3 v = this->getCheckpoint(index)->getNextcheckpoint();
+ Vector3 v = this->findCheckpoint(index)->getNextcheckpoint();
- if (this->getCheckpoint(v.x) == check)
+ if (this->findCheckpoint(v.x) == check)
{
reachedValidCheckpoint = true;
}
- if (this->getCheckpoint(v.y) == check)
+ if (this->findCheckpoint(v.y) == check)
{
reachedValidCheckpoint = true;
}
- if (this->getCheckpoint(v.z) == check)
+ if (this->findCheckpoint(v.z) == check)
{
reachedValidCheckpoint = true;
}
}
else
{
- reachedValidCheckpoint = (this->getIndex(check) == 0);
+ reachedValidCheckpoint = (check->getCheckpointIndex() == 0);
}
if (gametype && reachedValidCheckpoint)
@@ -146,39 +148,39 @@
else
{
if (index > -1)
- this->setRadVis(player, false);
+ this->setRadarVisibility(player, false);
else
- this->getCheckpoint(0)->setRadarVisibility(false);
+ this->findCheckpoint(0)->setRadarVisibility(false);
gametype->newCheckpointReached(check, player);
- this->setRadVis(player, true);
+ this->setRadarVisibility(player, true);
}
}
check->resetPlayer();
}
- void SpaceRaceManager::setRadVis(PlayerInfo* player, bool bVisible)
+ void SpaceRaceManager::setRadarVisibility(PlayerInfo* player, bool bVisible)
{
SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
assert(gametype);
int index = gametype->getCheckpointReached(player);
- Vector3 v = this->getCheckpoint(index)->getNextcheckpoint();
+ Vector3 v = this->findCheckpoint(index)->getNextcheckpoint();
if (v.x > -1)
{
- this->getCheckpoint(v.x)->setRadarVisibility(bVisible);
- this->getCheckpoint(v.x)->settingsChanged();
+ this->findCheckpoint(v.x)->setRadarVisibility(bVisible);
+ this->findCheckpoint(v.x)->settingsChanged();
}
if (v.y > -1)
{
- this->getCheckpoint(v.y)->setRadarVisibility(bVisible);
- this->getCheckpoint(v.y)->settingsChanged();
+ this->findCheckpoint(v.y)->setRadarVisibility(bVisible);
+ this->findCheckpoint(v.y)->settingsChanged();
}
if (v.z > -1)
{
- this->getCheckpoint(v.z)->setRadarVisibility(bVisible);
- this->getCheckpoint(v.z)->settingsChanged();
+ this->findCheckpoint(v.z)->setRadarVisibility(bVisible);
+ this->findCheckpoint(v.z)->settingsChanged();
}
}
}
Modified: code/trunk/src/modules/gametypes/SpaceRaceManager.h
===================================================================
--- code/trunk/src/modules/gametypes/SpaceRaceManager.h 2012-06-02 20:46:25 UTC (rev 9261)
+++ code/trunk/src/modules/gametypes/SpaceRaceManager.h 2012-06-02 21:08:21 UTC (rev 9262)
@@ -61,14 +61,15 @@
void addCheckpoint(RaceCheckPoint* checkpoint);
RaceCheckPoint* getCheckpoint(unsigned int index) const;
- int getIndex(RaceCheckPoint* checkpoint);
+ RaceCheckPoint* findCheckpoint(int index) const;
+
void checkpointReached(RaceCheckPoint* check, PlayerInfo* player);
void tick(float dt);
protected:
- void setRadVis(PlayerInfo* player, bool bVisible); ///< sets RadarVisibility of the checkpoints the player can reach.
+ void setRadarVisibility(PlayerInfo* player, bool bVisible); ///< sets RadarVisibility of the checkpoints the player can reach.
private:
std::vector<RaceCheckPoint*> checkpoints_;
More information about the Orxonox-commit
mailing list