[Orxonox-commit 4257] r8928 - code/branches/spaceraceTwo/src/modules/gametypes

eceline at orxonox.net eceline at orxonox.net
Wed Nov 9 16:11:12 CET 2011


Author: eceline
Date: 2011-11-09 16:11:12 +0100 (Wed, 09 Nov 2011)
New Revision: 8928

Modified:
   code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc
   code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h
   code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc
   code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h
   code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc
   code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h
Log:
some changes for multiplayer-version

Modified: code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc	2011-11-09 13:42:04 UTC (rev 8927)
+++ code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc	2011-11-09 15:11:12 UTC (rev 8928)
@@ -35,6 +35,7 @@
 
 #include "SpaceRace.h"
 
+
 namespace orxonox
 {
     CreateFactory(RaceCheckPoint);
@@ -59,7 +60,7 @@
             //for (size_t i = 0; i < this->nextcheckpoints_.size(); ++i)
               //  this->nextcheckpoints_[i]->destroy();
         }
-        nextcheckpoints_.clear();
+       //nextcheckpoints_.destroy;
     }
 
     void RaceCheckPoint::tick(float dt)
@@ -68,10 +69,19 @@
 
         SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
         assert(gametype);
-        if (this->getCheckpointIndex() == gametype->getCheckpointsReached())
-            this->setRadarVisibility(true);
-        else
-            this->setRadarVisibility(false);
+        this->setRadarVisibility(false);
+        Vector3 v =Vector3(0,0,0);
+        int j=0;
+        for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
+        {
+        	j=gametype->getCheckpointReached(it->first);
+        	RaceCheckPoint* r=SpaceRaceManager::getCheckpoint(j);
+        	v=r->getNextcheckpoint();
+        	for(int i=1;i<4;i++){
+        	if (this->getCheckpointIndex() == v[i])
+           	 this->setRadarVisibility(true);
+           	 }
+        }     
     }
 
     void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -81,15 +91,17 @@
         XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
         XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
         XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
-    //XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const std::vector<int>&);
+    XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&);
     }
 
-    void RaceCheckPoint::triggered(bool bIsTriggered)
+
+
+    void RaceCheckPoint::triggered(bool bIsTriggered, PlayerInfo* player)
     {
         DistanceTrigger::triggered(bIsTriggered);
 
         SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
-        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
+        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointReached(player) && bIsTriggered)
         {
             gametype->clock_.capture();
             float time = gametype->clock_.getSecondsPrecise();
@@ -102,7 +114,7 @@
                 gametype->end();
             else
             {
-                gametype->newCheckpointReached();
+                gametype->newCheckpointReached(this);
                 this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
             }
         }

Modified: code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h	2011-11-09 13:42:04 UTC (rev 8927)
+++ code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.h	2011-11-09 15:11:12 UTC (rev 8928)
@@ -49,23 +49,27 @@
 
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             virtual void tick(float dt);
+	inline void setCheckpointIndex(int checkpointIndex)
+                { this->bCheckpointIndex_ = checkpointIndex; }
+            inline int getCheckpointIndex()
+                { return this->bCheckpointIndex_; }
 
-            protected:
-            virtual void triggered(bool bIsTriggered);
+	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_;}
+        protected:
+            virtual void triggered(bool bIsTriggered, PlayerInfo* player);
             inline void setLast(bool isLast)
                 { this->bIsLast_ = isLast; }
             inline bool getLast()
                 { return this->bIsLast_; }
             
-	inline void setCheckpointIndex(int checkpointIndex)
-                { this->bCheckpointIndex_ = checkpointIndex; }
-            inline int getCheckpointIndex()
-                { return this->bCheckpointIndex_; }
+	
+            	
 
-	inline void setNextcheckpoint(std::vector<int> checkpoints)
-                { this->nextcheckpoints_ = checkpoints; }
-            inline std::vector<int> getNextcheckpoint()
-                { return this->nextcheckpoints_; }
             virtual void setTimelimit(float timeLimit);
             inline float getTimeLimit()
                 { return this->bTimeLimit_;}
@@ -77,7 +81,8 @@
             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.
 
-	std::vector<int> nextcheckpoints_; //the indexes of the next check points
+	
+	Vector3 nextcheckpoints_; //the indexes of the next check points
       
     };
 }

Modified: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc	2011-11-09 13:42:04 UTC (rev 8927)
+++ code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc	2011-11-09 15:11:12 UTC (rev 8928)
@@ -44,10 +44,12 @@
     SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator)
     {
         RegisterObject(SpaceRace);
-        this->checkpointsReached_ = 0;
+        //this->checkpointsReached_ = 0;
         this->bTimeIsUp_ = false;
         this->numberOfBots_ = 0;
         this->cantMove_=false;
+        
+       
     }
     
   // void SpaceRace::SetConfigValues(){
@@ -64,8 +66,7 @@
             int s = this->clock_.getSeconds();
             int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
             const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
-                        + "You didn't reach the check point " + multi_cast<std::string>(this->checkpointsReached_+1)
-                        + " before the time limit. You lose!";
+                        + "You didn't reach the check point  before the time limit. You lose!";
             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
             ChatManager::message(message);
         }
@@ -137,17 +138,37 @@
 	
 	
 
-    void SpaceRace::newCheckpointReached()
+    void SpaceRace::newCheckpointReached(RaceCheckPoint* p)
     {
-        this->checkpointsReached_++;
+        this->checkpointReached_=p->getCheckpointIndex();
         this->clock_.capture();
         int s = this->clock_.getSeconds();
         int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
-        const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
+        const std::string& message = "Checkpoint " + multi_cast<std::string>(p)
                         + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
                         + " seconds.";
         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
         ChatManager::message(message);
+        
+       
     }
+    
+     int SpaceRace::getCheckpointReached(PlayerInfo* player){
+    	return this->currentCheckpoint_[player];
+}
 
+void SpaceRace::playerEntered(PlayerInfo* player){
+    	this->currentCheckpoint_[player]=1;
+    	this->playersAlive_++;
+    }
+    
+	bool SpaceRace::playerLeft(PlayerInfo* player){
+		 bool valid_player = true;
+        if (valid_player)
+        {
+            this->playersAlive_--;
+        }
+
+        return valid_player;
+	}
 }

Modified: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h	2011-11-09 13:42:04 UTC (rev 8927)
+++ code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.h	2011-11-09 15:11:12 UTC (rev 8928)
@@ -58,24 +58,35 @@
             virtual void start();
             virtual void end();
 		
-            virtual void newCheckpointReached();
+            virtual void newCheckpointReached(RaceCheckPoint* p);
 
-            inline void setCheckpointsReached(int n)
-                { this->checkpointsReached_ = n;}
-            inline int getCheckpointsReached()
-                { return this->checkpointsReached_; }
+            inline void setCheckpointReached(int n)
+                { this->checkpointReached_ = n;}
+            inline int getCheckpointReached()
+                { return this->checkpointReached_; }
+		
             inline void timeIsUp()
                 { this->bTimeIsUp_ = true;}
 	void tick(float dt);
+
+	int getCheckpointReached(PlayerInfo* player);
+
+	 
         protected:
-		
+		virtual void playerEntered(PlayerInfo* player); //!< Initializes values.
+		 virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables.
         private:
 	float maxSpeedBack_; float maxSpeedFront_; float maxSpeedLeftRight_; float maxSpeedUpDown_; 
 	bool cantMove_;
-            int checkpointsReached_; //The current number of check points reached by the player.
+            int checkpointReached_; //The number of the last check point reached by each player.
             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.
+
+		std::map<PlayerInfo*, int> currentCheckpoint_;
+		int playersAlive_;
+
+	
     };
 }
 

Modified: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc	2011-11-09 13:42:04 UTC (rev 8927)
+++ code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.cc	2011-11-09 15:11:12 UTC (rev 8928)
@@ -84,7 +84,9 @@
      
     
     
-
     
+   
+    
+    }
 
-}
+

Modified: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h
===================================================================
--- code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h	2011-11-09 13:42:04 UTC (rev 8927)
+++ code/branches/spaceraceTwo/src/modules/gametypes/SpaceRaceManager.h	2011-11-09 15:11:12 UTC (rev 8928)
@@ -60,12 +60,17 @@
 
             void addCheckpoint(RaceCheckPoint* checkpoint);
             RaceCheckPoint* getCheckpoint(unsigned int index) const;
+		
+		
 
 	void tick(float dt);
         protected:
 		
         private:
-	std::vector<RaceCheckPoint*> checkpoints_;
+		std::vector<RaceCheckPoint*> checkpoints_;
+ 		
+		
+		
  };
 }
 




More information about the Orxonox-commit mailing list