Index: code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc	(revision 8954)
+++ code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc	(revision 8959)
@@ -33,4 +33,6 @@
 #include "core/XMLPort.h"
 #include "chat/ChatManager.h"
+
+#include <infos/PlayerInfo.h>
 
 #include "SpaceRace.h"
@@ -51,6 +53,6 @@
 	
            
-        this->bCheckpointIndex_ = 0;
-        //this->bIsLast_ = false;
+       
+        
         this->bTimeLimit_ = 0;
         this->isVisible_=true;
@@ -60,4 +62,5 @@
         this->setRadarVisibility(true);
     
+    	this->reached_=NULL;
     //this->addTarget("WorldEntity");
     
@@ -71,6 +74,6 @@
     	 if (this->isInitialized())
         {
-            //for (size_t i = 0; i < 3; ++i)
-            //   this->nextcheckpoints_[i]->destroy();
+           for (size_t i = 0; i < this->next_.size(); ++i)
+                this->next_[i]->destroy();
         }
        //nextcheckpoints_.destroy;
@@ -121,19 +124,49 @@
     	DistanceMultiTrigger::fire((bool)bIsTriggered,player);
         
-   //SUPER(RaceCheckPoint,fire,bIsTriggered,player);
-		
-
-        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
+       SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
         assert(gametype);
         
-        	 PlayerInfo* player2 = (PlayerInfo*)player;
-        assert(player2);
-        	//DistanceMultiTrigger::fire(bIsTriggered,player);
+       
+        
+       // BaseObject b=*player;
+       //  PlayerInfo* p = orxonox_cast<PlayerInfo*,Player>(player);
+        //assert(player);
+       //PlayerInfo* player3=((PlayerInfo*) player);
+       Player* player3=((Player*) player);
+      
+      PlayerInfo* player2=( PlayerInfo*) player;
+       
+       for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
+        {
+          unsigned int clientid1=0, clientid2=0,clientid3=0;
+          if(it->first !=NULL)clientid1 = it->first->getClientID();
+          
+          if(player3 != NULL && player3->info_ != NULL)clientid2 =         player3->info_->getClientID();
+          if(player2 != NULL )clientid3 =         player2->getClientID();
+          orxout()<<clientid1<<endl;orxout()<<clientid2<<endl;orxout()<<clientid3<<endl;
+        orxout()<<"for"<<endl;if(clientid1==clientid2) {orxout()<<"player"<<endl; player2=it->first;}if((it->first)==player2) {orxout()<<"player2"<<endl; }}
+        
+        // PlayerInfo* player2 = orxonox_cast<PlayerInfo*>(player);
+       // assert(player);
+        //gametype->newCheckpointReached(this,player);
+        //if(bIsTriggered)this->reached_=player2;
+        
+        /* for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
+        {if(gametype->getCheckpointReached(it->first)==-1) orxout()<<"index -1"<<endl;if(player2==it->first)orxout()<<"e"<<endl;}
+        if(gametype->getCheckpointReached(player2)==-1) orxout()<<"my index -1"<<endl;
+   orxout()<<gametype->getCheckpointReached(player2)<<endl;
+         
         	
+        	RaceCheckPoint* check=gametype->getCheckpointReached(player2);
         	
+        bool b =false;	
+        for(int i=0;i<3;i++){
+        
+        if (check->getNext[i]==this){
+        	b=true;}
+        }	
+       
         	
-       
-        	
-        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointReached(player2) && bIsTriggered)
+        if (gametype && b && bIsTriggered)
         {
             gametype->clock_.capture();
@@ -147,9 +180,14 @@
                 gametype->end();
             else
+            	gametype->newCheckpointReached(this,player2)
             {
-                gametype->newCheckpointReached(this,player2);
+                
                 this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
             }
-        }
+        }*/
+  
+		
+
+      
     }
 
Index: code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h	(revision 8954)
+++ code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h	(revision 8959)
@@ -32,4 +32,6 @@
 #include "gametypes/GametypesPrereqs.h"
 
+
+
 #include "objects/triggers/DistanceMultiTrigger.h"
 #include "interfaces/RadarViewable.h"
@@ -62,15 +64,20 @@
 		{return this->nextcheckpoints_;}
 
+	inline void setNext(int index,RaceCheckPoint* p)
+		{this->next_[index]=p;}
+ inline void setLast(bool isLast)
+                { this->bIsLast_ = isLast; }
+            inline bool getLast()
+                { return this->bIsLast_; }
+            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 bTimeLimit_; //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* reached_;
+            	
 	inline void setV(bool b)
 		{this->isVisible_ = b;}
         protected:
             virtual void fire(bool bIsTriggered,BaseObject* player);
-            inline void setLast(bool isLast)
-                { this->bIsLast_ = isLast; }
-            inline bool getLast()
-                { return this->bIsLast_; }
-            
+           
 	
-            	
 
             virtual void setTimelimit(float timeLimit);
@@ -82,12 +89,12 @@
         private:
             int bCheckpointIndex_; //The index of this check point. This value will be compared with the number of check points reached in the level. The check points must be indexed in ascending order beginning from zero and without any jumps between the indexes.
-            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 bTimeLimit_; //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.
-
+            
 	
 	Vector3 nextcheckpoints_; //the indexes of the next check points
 
 	bool isVisible_;
-      
+
+	
+      std::vector<RaceCheckPoint*> next_;
     };
 }
Index: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc	(revision 8954)
+++ code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc	(revision 8959)
@@ -29,4 +29,6 @@
 #include "SpaceRace.h"
 
+//#include "SpaceRaceManager.h"
+
 #include "items/Engine.h"
 
@@ -54,5 +56,5 @@
         
        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
-        {this->checkpointReached_[it->first]=0;}
+        {this->checkpointReached_[it->first]=-1;}
         
         
@@ -140,10 +142,11 @@
       
     }
-     
-    
-    }
-
-	void SpaceRace::setV(SpaceRaceManager* m){
-		/*Vector3 v =Vector3(0,0,0);
+    // for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+      //  {if(this->getCheckpointReached(it->first)==-1) orxout()<<"index -1"<<endl;}
+   
+    }
+
+	void SpaceRace::setV(SpaceRaceManager* m){/*
+		Vector3 v =Vector3(0,0,0);
         int j=0;
         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
@@ -161,5 +164,5 @@
 
     void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl)
-    {
+    {/*
         this->checkpointReached_[pl]=index;
         this->clock_.capture();
@@ -171,5 +174,5 @@
         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
         ChatManager::message(message);
-        
+       */ 
        
     }
@@ -194,5 +197,6 @@
 void SpaceRace::playerEntered(PlayerInfo* player){
 	Gametype::playerEntered(player);
-    	//this->checkpointReached_[player]=0;
+	
+    	this->checkpointReached_[player]=-1;
     	//this->playersAlive_++;
     }
Index: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h	(revision 8954)
+++ code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h	(revision 8959)
@@ -73,4 +73,5 @@
                 { this->bTimeIsUp_ = true;}
 	void tick(float dt);
+Clock clock_; //The clock starts running at the beginning of the game. It is used to give the time at each check point, the give the time at the end of the game, and to stop the game if a check point is reached too late.
 
 
@@ -85,6 +86,5 @@
             std::set<float> scores_; //The times of the players are saved in a set.
             bool bTimeIsUp_; //True if one of the check points is reached too late.
-            Clock clock_; //The clock starts running at the beginning of the game. It is used to give the time at each check point, the give the time at the end of the game, and to stop the game if a check point is reached too late.
-
+            
 		
 		int playersAlive_;
Index: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc	(revision 8954)
+++ code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc	(revision 8959)
@@ -46,4 +46,6 @@
         RegisterObject(SpaceRaceManager);
          
+         for (size_t i = 0; i < this->checkpoints_.size(); ++i)
+                this->setNext(this->checkpoints_[i]);
           
     }
@@ -71,4 +73,15 @@
     }
     
+    int SpaceRaceManager::getIndex(RaceCheckPoint* r) 
+    {
+        
+        	 for (size_t i = 0; i < this->checkpoints_.size(); ++i)
+                if (this->checkpoints_[i]==r){return i;}
+           
+          
+        
+            return -1;
+    }
+    
      void SpaceRaceManager::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
@@ -85,8 +98,72 @@
      gametype->setV(this);
          
+         
+    	 for (size_t i = 0; i < this->checkpoints_.size(); ++i){
+                if(this->checkpoints_[i]->reached_!=NULL)
+                this->checkpointReached(this->checkpoints_[i],this->checkpoints_[i]->reached_);
+          
+     }
+    }
+    
+    
+    void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player){
+    	 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
+        assert(gametype);
+        
+        //if(gametype->getCheckpointReached(player)==-1) {orxout()<<"index -1"<<endl;}
+   
+        	 bool b =false;	
+        	//DistanceMultiTrigger::fire(bIsTriggered,player);
+        	int index=gametype->getCheckpointReached(player);
+        	if (index>-1){
+        	RaceCheckPoint* tmp= this->getCheckpoint(index);
+        	Vector3 v= tmp->getNextcheckpoint();
+       
+       // orxout()<<"index not -1"<<endl;
+        if (this->getCheckpoint(v.x)==check){
+        	b=true;
+        }	
+       
+       if (this->getCheckpoint(v.y)==check){
+        	b=true;
+        }	
+       if (this->getCheckpoint(v.z)==check){
+        	b=true;
+        }	}
+        else{b=(this->getIndex(check)==0);}
+        	
+        if (gametype && b)
+        {
+            gametype->clock_.capture();
+            float time = gametype->clock_.getSecondsPrecise();
+            if (check->bTimeLimit_!=0 && time > check->bTimeLimit_)
+            {
+                gametype->timeIsUp();
+                gametype->end();
+            }
+            else if (check->getLast())
+                gametype->end();
+            else
+            {
+                gametype->newCheckpointReached(check,player);
+                check->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
+            }
+        }
+    	check->reached_=NULL;
+    }
+    
+    
+    
+    void SpaceRaceManager::setNext(RaceCheckPoint* check){
     	
-     
+    	Vector3 v=check->getNextcheckpoint();
+    		check->setNext(0,this->getCheckpoint(v.x));
+    	check->setNext(1,this->getCheckpoint(v.y));
+    	check->setNext(2,this->getCheckpoint(v.z));
+    	}
+    
+    
     }
-}
 
 
+
Index: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h	(revision 8954)
+++ code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h	(revision 8959)
@@ -58,9 +58,11 @@
 
            void XMLPort(Element& xmlelement, XMLPort::Mode mode); 
-
+		int getIndex(RaceCheckPoint* r);
             void addCheckpoint(RaceCheckPoint* checkpoint);
             RaceCheckPoint* getCheckpoint(unsigned int index) const;
 		
+	void checkpointReached(RaceCheckPoint* check, PlayerInfo* player);
 		
+	void setNext(RaceCheckPoint* check);
 
 	void tick(float dt);
