[Orxonox-commit 4839] r9508 - code/branches/Racingbot/src/modules/gametypes

purgham at orxonox.net purgham at orxonox.net
Tue Dec 11 18:13:19 CET 2012


Author: purgham
Date: 2012-12-11 18:13:18 +0100 (Tue, 11 Dec 2012)
New Revision: 9508

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
Log:
still not working!

Modified: code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc	2012-12-10 16:37:23 UTC (rev 9507)
+++ code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc	2012-12-11 17:13:18 UTC (rev 9508)
@@ -64,6 +64,7 @@
         myPosition_= this->getPosition(); //eingefuegt
         //orxout(user_status) << "test" << std::endl;
 
+
     }
 
     RaceCheckPoint::~RaceCheckPoint()
@@ -105,6 +106,30 @@
         }
     }
 
+    //Must not be called before setNextCheckpointsAsVector3 at least once has been called
+    void RaceCheckPoint::setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints){
+        std::set<int> lastcheckpoints=this->nextCheckpoints_;
+        nextCheckpoints_.clear();
+        std::set<int>::iterator it = lastcheckpoints.begin();
+        if(checkpoints.x<-1){
+            virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.x,(*it)));
+            it++;
+        }
+        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly
+
+        if(checkpoints.y<-1){
+                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.y,(*it)));
+                    it++;
+        }
+        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
+
+        if(checkpoints.z<-1){
+                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.z,(*it)));
+                    it++;
+        }
+        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
+    }
+
     void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints)
     {
         this->nextCheckpoints_.clear();
@@ -147,8 +172,31 @@
         return false;
     }
 
-    Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const
+    Vector3 RaceCheckPoint::getNextCheckpointsAsVector3()
     {
+        Vector3 checkpoints = getVirtualNextCheckpointsAsVector3();
+        int j[3];
+        j[0]=changeVirtualToRealCheckPoint(checkpoints.x);
+        j[1]=changeVirtualToRealCheckPoint(checkpoints.y);
+        j[2]=changeVirtualToRealCheckPoint(checkpoints.z);
+
+
+        return Vector3(j[0],j[1],j[2]);
+
+
+    }
+
+    int RaceCheckPoint::changeVirtualToRealCheckPoint(int checkpointID) {
+        int temp=checkpointID;
+        while(temp<-1){
+            temp = this->virtualToRealCheckPoints_[temp];
+        }
+        return temp;
+    }
+
+
+    Vector3 RaceCheckPoint::getVirtualNextCheckpointsAsVector3() const
+    {
         Vector3 checkpoints = Vector3(-1, -1, -1);
 
         size_t count = 0;

Modified: code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h	2012-12-10 16:37:23 UTC (rev 9507)
+++ code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h	2012-12-11 17:13:18 UTC (rev 9508)
@@ -59,12 +59,24 @@
             }
 
             void setNextCheckpointsAsVector3(const Vector3& checkpoints);
-            Vector3 getNextCheckpointsAsVector3() const;
-            const std::set<int>& getNextCheckpoints() const
+            Vector3 getNextCheckpointsAsVector3();
+            Vector3 getVirtualNextCheckpointsAsVector3() const;
+            void setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints);
+            int changeVirtualToRealCheckPoint(int);
+
+            const std::set<int>& getVirtualNextCheckpoints() const
             {
                 return this->nextCheckpoints_;
             }
-
+            std::set<int> getNextCheckpoints()
+            {
+                std::set<int> temp;
+                std::set<int> temp2=getVirtualNextCheckpoints();
+                for (std::set<int>::iterator it = temp2.begin(); it!=temp2.end(); ++it){
+                    temp.insert(changeVirtualToRealCheckPoint((*it)));
+                }
+                return temp;
+            }
             inline void setLast(bool isLast)
             {
                 this->bIsLast_ = isLast;
@@ -90,6 +102,7 @@
             }
 
         protected:
+
             virtual void fire(bool bIsTriggered, BaseObject* originator);
 
             inline const WorldEntity* getWorldEntity() const
@@ -98,12 +111,14 @@
             }
 
         private:
+
             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.
             std::vector<PlayerInfo*> players_; ///< The player that reached the checkpoint
             Vector3 myPosition_;
+            std::map<int,int> virtualToRealCheckPoints_; // if virtualChepoint was inserted the original can be reconstructed
     };
 }
 

Modified: code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
===================================================================
--- code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc	2012-12-10 16:37:23 UTC (rev 9507)
+++ code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc	2012-12-11 17:13:18 UTC (rev 9508)
@@ -53,8 +53,10 @@
     SpaceRaceController::SpaceRaceController(BaseObject* creator) :
         ArtificialController(creator)
     {
-        RegisterObject(SpaceRaceController)
-;        std::vector<RaceCheckPoint*> checkpoints;
+        RegisterObject(SpaceRaceController);
+        std::vector<RaceCheckPoint*> checkpoints;
+
+        virtualCheckPointIndex=-2;
         for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it)
         {
             checkpoints = it->getAllCheckpoints();
@@ -63,11 +65,11 @@
 
         OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
         checkpoints_=checkpoints;
+
         for( std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it!=checkpoints.end(); ++it)
         {
             std::set<int> nextCheckPoints = ((*it)->getNextCheckpoints());
             if(!nextCheckPoints.empty()) {
-                orxout() << "yay" << endl;
                 for (std::set<int>::iterator numb = nextCheckPoints.begin(); numb!=nextCheckPoints.end(); numb++) {
                     RaceCheckPoint* point2 = findCheckpoint((*numb));
 
@@ -79,16 +81,13 @@
         staticRacePoints_ = findStaticCheckpoints(checkpoints);
         // initialisation of currentRaceCheckpoint_
         currentRaceCheckpoint_ = NULL;
-        /*
-         // find first Checkpoint
-         for (int i=0; true; i++){
-         if(checkpoints_[i]->getCheckpointIndex()==0){
-         nextRaceCheckpoint_=checkpoints_[i];
-         break;
-         }
-         }*/
 
-        virtualCheckPointIndex=-2;
+        int i;
+        for (i=-2; findCheckpoint(i)!= NULL; i--){
+            continue;
+        }
+        orxout()<<"Die ANzahl der virtuellen CP betraegt: "<< (-i)-2<<endl;
+
     }
 
     //------------------------------
@@ -108,8 +107,7 @@
      */
     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)
+        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));
@@ -139,24 +137,20 @@
 
         if (currentCheckpoint->isLast())
         {// last point reached
-            orxout() << "last one" << endl;
+
             (*zaehler)[currentCheckpoint] += 1;
             return 1; // 1 Way form the last point to this one
         }
         else
         {
             int numberOfWays = 0; // counts number of ways from this Point to the last point
-            for (std::set<int>::iterator it = currentCheckpoint->getNextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it)
+            for (std::set<int>::iterator it = currentCheckpoint->getVirtualNextCheckpoints().begin(); it!= currentCheckpoint->getVirtualNextCheckpoints().end(); ++it)
             {
                 if(currentCheckpoint==findCheckpoint(*it)){
                     orxout() << currentCheckpoint->getCheckpointIndex()<<endl;
                     continue;
                 }
-                for (std::set<int>::iterator a = currentCheckpoint->getNextCheckpoints().begin(); a!= currentCheckpoint->getNextCheckpoints().end(); ++a){
-                    orxout() << "Nextcheckpoints: "<<(*a) << endl;
-                }
-                orxout() << "currentCheck; " << currentCheckpoint->getCheckpointIndex() << "findCheck; " << findCheckpoint(*it)->getCheckpointIndex() << endl;
-                numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
+               numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
             }
             (*zaehler)[currentCheckpoint] += numberOfWays;
             return numberOfWays; // returns the number of ways from this point to the last one
@@ -184,7 +178,7 @@
         int distances[] =
         {   -1, -1, -1};
         int temp_i = 0;
-        for (std::set<int>::iterator it =raceCheckpoint->getNextCheckpoints().begin(); it!= raceCheckpoint->getNextCheckpoints().end(); ++it)
+        for (std::set<int>::iterator it =raceCheckpoint->getVirtualNextCheckpoints().begin(); it!= raceCheckpoint->getVirtualNextCheckpoints().end(); ++it)
         {
             distances[temp_i] = recCalculateDistance(findCheckpoint(*it), this->getControllableEntity()->getPosition());
             temp_i++;
@@ -193,11 +187,11 @@
         {
             if (distances[2] < distances[1] && distances[2] != -1)
             {
-                return findCheckpoint(*raceCheckpoint->getNextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2]
+                return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2]
             }
             else
             {
-                std::set<int>::iterator temp = raceCheckpoint->getNextCheckpoints().begin();
+                std::set<int>::iterator temp = raceCheckpoint->getVirtualNextCheckpoints().begin();
                 return findCheckpoint(*(++temp)); // return [1]
             }
         }
@@ -205,11 +199,11 @@
         {
             if (distances[2] < distances[0] && distances[2] != -1)
             {
-                return findCheckpoint(*raceCheckpoint->getNextCheckpoints().end()); // return [2]
+                return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().end()); // return [2]
             }
             else
             {
-                return findCheckpoint(*raceCheckpoint->getNextCheckpoints().begin()); // return [0]
+                return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().begin()); // return [0]
             }
         }
     }
@@ -228,7 +222,7 @@
         else
         {
             int minimum = std::numeric_limits<int>::max();
-            for (std::set<int>::iterator it = currentCheckPoint->getNextCheckpoints().begin(); it!= currentCheckPoint->getNextCheckpoints().end(); ++it)
+            for (std::set<int>::iterator it = currentCheckPoint->getVirtualNextCheckpoints().begin(); it!= currentCheckPoint->getVirtualNextCheckpoints().end(); ++it)
             {
                 int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length());
 
@@ -249,7 +243,7 @@
         {
             return nextRaceCheckpoint_;
         }
-        if ((currentRaceCheckpoint_->getNextCheckpoints()).size() == 1) // no Adjust possible
+        if ((currentRaceCheckpoint_->getVirtualNextCheckpoints()).size() == 1) // no Adjust possible
 
         {
             return nextRaceCheckpoint_;
@@ -274,18 +268,19 @@
         for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it){
             newTempRaceCheckPoint = new RaceCheckPoint((*it));
         }
+        newTempRaceCheckPoint->setVisible(false);
         newTempRaceCheckPoint->setPosition(virtualCheckPointPosition);
         newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex);
         newTempRaceCheckPoint->setLast(false);
-        newTempRaceCheckPoint->setNextCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));
+        newTempRaceCheckPoint->setNextVirtualCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));
 
-        Vector3 temp = previousCheckpoint->getNextCheckpointsAsVector3();
+        Vector3 temp = previousCheckpoint->getVirtualNextCheckpointsAsVector3();
         checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint);
         int positionInNextCheckPoint;
         for (int i = 0; i <3; i++)
         {
-            if(previousCheckpoint->getNextCheckpointsAsVector3()[i]==indexFollowingCheckPoint)
-            positionInNextCheckPoint=i;
+            if(previousCheckpoint->getVirtualNextCheckpointsAsVector3()[i] == indexFollowingCheckPoint)
+                positionInNextCheckPoint=i;
         }
         switch(positionInNextCheckPoint)
         {
@@ -293,9 +288,13 @@
             case 1: temp.y=virtualCheckPointIndex; break;
             case 2: temp.z=virtualCheckPointIndex; break;
         }
-        previousCheckpoint->setNextCheckpointsAsVector3(temp);
+        previousCheckpoint->setNextVirtualCheckpointsAsVector3(temp); //Existiert internes Problem bei negativen index fueer next Checkpoint
         virtualCheckPointIndex--;
-        OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
+        //OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
+        /*orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<", following:"<<indexFollowingCheckPoint<<" :       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
+        temp=previousCheckpoint->getNextCheckpointsAsVector3();
+        orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<":       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
+        orxout()<<endl;*/
         return newTempRaceCheckPoint;
     }
 
@@ -314,28 +313,31 @@
         //FOR virtual Checkpoints
         if(nextRaceCheckpoint_->getCheckpointIndex() < 0)
         {
-            if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 30)
+            if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 200)
             {
                 currentRaceCheckpoint_=nextRaceCheckpoint_;
                 nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
                 lastPositionSpaceship=this->getControllableEntity()->getPosition();
+                orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
             }
         }
 
         if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer()))
         {//Checkpoint erreicht
+
             currentRaceCheckpoint_=nextRaceCheckpoint_;
             OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined");
             nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
             lastPositionSpaceship=this->getControllableEntity()->getPosition();
+            orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
         }
         else if ((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt > ADJUSTDISTANCE)
         {
             nextRaceCheckpoint_ = adjustNextPoint();
             lastPositionSpaceship=this->getControllableEntity()->getPosition();
         }
-        //TODO: korrigieren!
 
+        // Abmessung fuer MINDISTANCE gut;
         else if((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt< MINDISTANCE )
         {
             this->moveToPosition(Vector3(rnd()*100,rnd()*100,rnd()*100));




More information about the Orxonox-commit mailing list