[Orxonox-commit 4772] r9441 - code/branches/Racingbot/src/modules/gametypes
purgham at orxonox.net
purgham at orxonox.net
Mon Nov 12 16:13:27 CET 2012
Author: purgham
Date: 2012-11-12 16:13:27 +0100 (Mon, 12 Nov 2012)
New Revision: 9441
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
Log:
BUG 12.11.2012 Error if create Bots after start
Modified: code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc 2012-11-12 13:54:11 UTC (rev 9440)
+++ code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc 2012-11-12 15:13:27 UTC (rev 9441)
@@ -42,12 +42,11 @@
{
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);
@@ -61,6 +60,10 @@
this->bIsLast_ = false;
this->timeLimit_ = 0;
//this->players_ = vector<PlayerInfo*>();
+
+ myPosition_= this->getPosition();
+ orxout(user_status) << "test" << std::endl;
+
}
RaceCheckPoint::~RaceCheckPoint()
@@ -86,7 +89,7 @@
{
ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator);
if (entity)
- this->players_.push_back(entity->getPlayer());
+ this->players_.push_back(entity->getPlayer());
}
}
Modified: code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h 2012-11-12 13:54:11 UTC (rev 9440)
+++ code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h 2012-11-12 15:13:27 UTC (rev 9441)
@@ -103,6 +103,7 @@
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
+ Vector3 myPosition_;
};
}
Modified: code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc 2012-11-12 13:54:11 UTC (rev 9440)
+++ code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc 2012-11-12 15:13:27 UTC (rev 9441)
@@ -22,14 +22,19 @@
* Created on: Oct 8, 2012
* Author: purgham
*/
-
+ /**
+ * Conventions:
+ * -first Checkpoint has index 0
+ *
+ */
#include <gametypes/SpaceRaceController.h>
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
#include "gametypes/SpaceRaceManager.h"
-// WEnn RAcer nach start erstellt wird fehler in Tick
-// Fuer beide Spieler wird next point angezeigt
+
+
+
namespace orxonox
{
CreateFactory(SpaceRaceController);
@@ -49,8 +54,15 @@
}
OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
+ //OrxAssert(1==2, "Orxassert test");
checkpoints_=checkpoints;
staticRacePoints_ = findStaticCheckpoints(checkpoints);
+ for (int i=0; true; i++){
+ if(checkpoints_[i]->getCheckpointIndex()==0){
+ nextRaceCheckpoint_=checkpoints_[i];
+ break;
+ }
+ }
}
@@ -65,12 +77,11 @@
RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint)
{
- int distances[] =
- { -1, -1, -1};
+ int distances[] ={ -1, -1, -1};
int temp_i = 0;
for (std::set<int>::iterator it =raceCheckpoint->getNextCheckpoints().begin(); it!= raceCheckpoint->getNextCheckpoints().end(); ++it)
{
- distances[temp_i] = recCalculateDistance(raceCheckpoint,this->getControllableEntity()->getPosition());
+ distances[temp_i] = recCalculateDistance(raceCheckpoint, this->getControllableEntity()->getPosition());
temp_i++;
}
if (distances[0] > distances[1] && distances[1] != -1)
@@ -118,6 +129,7 @@
int SpaceRaceController::recCalculateDistance(RaceCheckPoint* currentCheckPoint, Vector3 currentPosition)
{
+ orxout()<< "rec Aufruf" << endl;
// if ( staticCheckPoint was reached)
if (std::find(staticRacePoints_.begin(), staticRacePoints_.end(),currentCheckPoint) != staticRacePoints_.end())
{
@@ -126,10 +138,22 @@
else
{
int minimum = std::numeric_limits<int>::max();
+ int temp=0;
for (std::set<int>::iterator it = currentCheckPoint->getNextCheckpoints().begin(); it!= currentCheckPoint->getNextCheckpoints().end(); ++it)
- {
- minimum= std::min(minimum,(int) (currentPosition- currentCheckPoint->getPosition()).length() + recCalculateDistance(checkpoints_[(*it)], currentCheckPoint->getPosition()));
- }//TODO: fix cast
+ { //temp++;
+ WorldEntity* ttt= dynamic_cast<WorldEntity*> (currentCheckPoint);
+ OrxAssert(!(ttt==NULL), "WorldEntity null");
+ OrxAssert(!(ttt->getNode()==NULL), "Node of WorldEntity is null");
+
+ //orxout()<< temp <<endl;
+ //if(temp==1){orxout()<<currentCheckPoint << " == null? => "<<(currentCheckPoint==NULL)<<currentPosition<<endl;}
+ Vector3 t=(currentPosition- ttt->getPosition()); //TODO: Find Crash Reason. Why can't currentCheck access node.
+ int tt=static_cast<int>(t.length());
+ //OrxAssert(!currentCheckPoint.empty(), "currentCheckPoint == null");
+ //OrxAssert(!(it == currentCheckPoint->getNextCheckpoints().end()), "it is null");
+ minimum= std::min(minimum, tt+ recCalculateDistance(checkpoints_[(*it)], currentCheckPoint->getPosition()));
+ // minimum of distanz from 'currentPosition' to the next static Checkpoint
+ }//Error tritt manchmal auf
return minimum;
}
}
@@ -203,7 +227,7 @@
}
void SpaceRaceController::tick(float dt)
{
- if (this->getControllableEntity() == NULL || this->getControllableEntity()->getPlayer() == NULL ){orxout()<<this->getControllableEntity()<<endl; return;}
+ if (this->getControllableEntity() == NULL || this->getControllableEntity()->getPlayer() == NULL ){orxout()<<this->getControllableEntity()<< " in tick"<<endl; return;}
if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer()))
{//Checkpoint erreicht
currentRaceCheckpoint_=nextRaceCheckpoint_;
Modified: code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h 2012-11-12 13:54:11 UTC (rev 9440)
+++ code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h 2012-11-12 15:13:27 UTC (rev 9441)
@@ -39,8 +39,8 @@
{
private:
std::vector<RaceCheckPoint*> staticRacePoints_;
- RaceCheckPoint* nextRaceCheckpoint_;
- RaceCheckPoint* currentRaceCheckpoint_;
+ RaceCheckPoint* nextRaceCheckpoint_; // checkpoint that should be reached
+ RaceCheckPoint* currentRaceCheckpoint_; // last checkPoint (already reached)
std::vector<RaceCheckPoint*> checkpoints_;
int lastDistance;
More information about the Orxonox-commit
mailing list