[Orxonox-commit 1969] r6686 - in code/branches/dynamicmatch/src/orxonox: controllers gametypes

jo at orxonox.net jo at orxonox.net
Mon Apr 12 14:52:46 CEST 2010


Author: jo
Date: 2010-04-12 14:52:45 +0200 (Mon, 12 Apr 2010)
New Revision: 6686

Modified:
   code/branches/dynamicmatch/src/orxonox/controllers/ArtificialController.cc
   code/branches/dynamicmatch/src/orxonox/gametypes/CMakeLists.txt
   code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.cc
   code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.h
Log:
first version- not playable yet

Modified: code/branches/dynamicmatch/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/dynamicmatch/src/orxonox/controllers/ArtificialController.cc	2010-04-12 12:21:39 UTC (rev 6685)
+++ code/branches/dynamicmatch/src/orxonox/controllers/ArtificialController.cc	2010-04-12 12:52:45 UTC (rev 6686)
@@ -33,8 +33,10 @@
 #include "worldentities/pawns/Pawn.h"
 #include "worldentities/pawns/TeamBaseMatchBase.h"
 #include "gametypes/TeamDeathmatch.h"
+#include "gametypes/Dynamicmatch.h"
 #include "controllers/WaypointPatrolController.h"
 
+
 namespace orxonox
 {
     ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
@@ -243,7 +245,16 @@
                     team2 = -1;
             }
         }
+	Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
+        if (dynamic)
+        {
+            if (entity1->getPlayer())
+                team1 = dynamic->getParty(entity1->getPlayer());
 
-        return (team1 == team2 && team1 != -1);
-    }
+            if (entity2->getPlayer())
+                team2 = dynamic->getParty(entity2->getPlayer());
+        }
+
+        return (team1 == team2 && team1 != -1)&&(!dynamic->onlyChasers); //returns false if players are in the same party and there is a victim
+    }								//-> if there is no victim or the AI-Player is not in the same team the AI attacks
 }

Modified: code/branches/dynamicmatch/src/orxonox/gametypes/CMakeLists.txt
===================================================================
--- code/branches/dynamicmatch/src/orxonox/gametypes/CMakeLists.txt	2010-04-12 12:21:39 UTC (rev 6685)
+++ code/branches/dynamicmatch/src/orxonox/gametypes/CMakeLists.txt	2010-04-12 12:52:45 UTC (rev 6686)
@@ -5,4 +5,5 @@
   TeamBaseMatch.cc
   UnderAttack.cc
   Asteroids.cc
+  Dynamicmatch.cc
 )

Modified: code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.cc
===================================================================
--- code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.cc	2010-04-12 12:21:39 UTC (rev 6685)
+++ code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.cc	2010-04-12 12:52:45 UTC (rev 6686)
@@ -28,11 +28,15 @@
 
 #include "Dynamicmatch.h"
 
+#include "util/Convert.h"
 #include "core/CoreIncludes.h"
 #include "network/Host.h"
 #include "infos/PlayerInfo.h"
 #include "worldentities/pawns/Pawn.h"
+#include "core/ConfigValueIncludes.h"
+#include "interfaces/TeamColourable.h"
 
+//toDO: maybe the has entered the game function is not enough... look at TeamDeathmath
 namespace orxonox
 {
     CreateUnloadableFactory(Dynamicmatch);
@@ -40,94 +44,197 @@
     Dynamicmatch::Dynamicmatch(BaseObject* creator) : Gametype(creator)
     {
         RegisterObject(Dynamicmatch);
-	   this->scoreTimer_.setTimer(10, true, createExecutor(createFunctor(&Dynamicmatch::winPoints, this)));//bad
-           this->outputTimer_.setTimer(10, true, createExecutor(createFunctor(&Dynamicmatch::showPoints, this)));//bad
-	   for (int player=0; player<50; player++) { this->pointsScored[player]=0;}//
-        
+	this->gameTime_ = 180;
+	this->setConfigValues();
+        this->chaser=0;
+	this->piggy=1;
+	this->onlyChasers=true;
+	this->gameEnded_ =false;
+	this->timesequence_ = static_cast<int>(this->gameTime_);
+	this->friendlyfire=true;
     }
 
-bool Gametype::allowPawnDamage(Pawn* victim, Pawn* originator)//
-    {
-        return false;
-    }
+void Dynamicmatch::setPlayerColour(PlayerInfo* player) // not sure if this is the right place - helper function
+{
+	std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
+        //if (it_player != this->playerParty_.end() && it_player->second >= 0 && it_player->second < static_cast<int>(this->partyColours_.size()))
+        // all players are the same colour at the beginning!!
+            Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity());
+            if (pawn)
+            {
+                pawn->setRadarObjectColour(this->partyColours_[it_player->second]); //does this work? //what about playerParty_[it_player] instead of it_player->second
 
-bool Gametype::allowPawnDeath(Pawn* victim, Pawn* originator)//
-    {
-        return false;
-    }
+                std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
+                for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
+                {
+                    if ((*it)->isA(Class(TeamColourable)))//not sure if this works
+                    {
+                        TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
+                        tc->setTeamColour(this->partyColours_[it_player->second]);
+                    }
+                }
+            }
+}
 
-void Dynamicmatch::winPoints() // Points scored for each player
-    {
-	/* Points: for each hit of the victim - is it possible to destinguish different weapontypes (1pt per hit)
-		the victim scores points during the duration of the victim state (1p per second)
-	*/
 
+int Dynamicmatch::getParty(PlayerInfo* player) // helper function for ArtificialController
+{
+return this->playerParty_[player];
+}
 
 
-        /*int amountControlled = 0;
-        int amountControlled2 = 0;
 
-        for (std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.begin(); it != this->bases_.end(); ++it)
+void Dynamicmatch::setConfigValues()
+    {
+        SetConfigValue(gameTime_, 180);//just for test cases
+	SetConfigValue(friendlyfire, true);
+	static ColourValue colours[] =
         {
-            if((*it)->getState() == BaseState::ControlTeam1)
-            {
-                amountControlled++;
-            }
-            if((*it)->getState() == BaseState::ControlTeam2)
-            {
-                amountControlled2++;
-            }
-        }
+	    ColourValue(0.3f, 0.3f, 1.0f),
+            ColourValue(1.0f, 0.3f, 0.3f)
+            
+        };
+        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
 
-        this->addTeamPoints(0, (amountControlled * 30));
-        this->addTeamPoints(1, (amountControlled2 * 30));
-	*/
+        SetConfigValue(partyColours_, defaultcolours);
     }
 
+bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)//
+    {	
 
+        if (victim && victim->getPlayer())
+        { 	//TODO: evtl. ->getPlayer() zugriffe auslagern fuer mehr uebersicht
+		//Case: 1. onlyChasers==false und victim ist chaser
+		if ((!onlyChasers)&&(playerParty_[originator->getPlayer()]==chaser)) {
+			std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
+                    if (it != this->players_.end())
+                    {
+                        it->second.frags_++;
+                    }
+		}
+		//Case 2: onlyChasers==false und victim ist piggy
+		else if ((!onlyChasers)&&(playerParty_[originator->getPlayer()]==piggy)){
+			//partyswitch: victim bcomes piggy and the orginator(piggy) becomes chaser
+			playerParty_[victim->getPlayer()]=piggy;
+			playerParty_[originator->getPlayer()]=chaser;
+			//announce
+			const std::string& messageVictim = victim->getPlayer()->getName() + " is victim";
+        		COUT(0) << messageVictim << std::endl;
+			Host::Broadcast(messageVictim);
+		//party switch -> colour switch
+		
+		setPlayerColour(victim->getPlayer()); //victim colour
+		setPlayerColour(originator->getPlayer());//orginator colour
+		}
+		//Case 3: there are only chasers -> new piggy is needed
+		else if (onlyChasers){
+			//Rollenzuweisung victim wird piggy
+			playerParty_[victim->getPlayer()]=piggy;
+			onlyChasers=false;
+			setPlayerColour(victim->getPlayer()); //victim colour
+		std::string message("First victim.");
+        	COUT(0) << message << std::endl;
+		Host::Broadcast(message);
+		}
+		else if (friendlyfire)
+		{
+		std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
+		 if (it != this->players_.end())
+                    {
+                        it->second.frags_--;
+                    }
+		}
+        }
+		
+	return false;
+    }
 
-    void Dynamicmatch::start()
+        
+    
+
+bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator)//
     {
+        return false;
+    }
+
+void Dynamicmatch::start() 
+    {	
         Gametype::start();
 
-        std::string message("The match has started!");
+        std::string message("Don't be a victim!");
         COUT(0) << message << std::endl;
         Host::Broadcast(message);
+	
     }
 
     void Dynamicmatch::end()
     {
         Gametype::end();
 
-        std::string message("The match has ended.");
+        std::string message("Time out. Press F2 to see the soreboard");
         COUT(0) << message << std::endl;
         Host::Broadcast(message);
+	/*for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
+                {
+                    if (it->first->getClientID() == CLIENTID_UNKNOWN)
+                        continue;
+
+                    if (it->second == 1)
+                        this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
+                    else
+                        this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+                }*/
     }
 
-    void Dynamicmatch::playerEntered(PlayerInfo* player)
+    
+void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn)
     {
+        if (!player)
+            return;
+	playerParty_[player]=chaser;//playerparty
+	// Set the playercolour
+ 	Dynamicmatch::setPlayerColour(player);
+
+	
+    }
+
+    void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction + party + colouring
+    {
+
+	if (!player)// only for safety
+            return;
+
         Gametype::playerEntered(player);
-
+	
+	//playerParty_[player]=chaser;//playerparty
+	
+        // Set the playercolour
+        //Dynamicmatch::setPlayerColour(player);
+	
+	
         const std::string& message = player->getName() + " entered the game";
         COUT(0) << message << std::endl;
         Host::Broadcast(message);
     }
 
-    bool Dynamicmatch::playerLeft(PlayerInfo* player)
+    bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction
     {
         bool valid_player = Gametype::playerLeft(player);
-
+	
+	
         if (valid_player)
         {
             const std::string& message = player->getName() + " left the game";
             COUT(0) << message << std::endl;
             Host::Broadcast(message);
+		//remove player from map
+	     playerParty_.erase (player);  
         }
 
         return valid_player;
     }
 
-    bool Dynamicmatch::playerChangedName(PlayerInfo* player)
+    bool Dynamicmatch::playerChangedName(PlayerInfo* player) //standardfunction
     {
         bool valid_player = Gametype::playerChangedName(player);
 
@@ -141,37 +248,39 @@
         return valid_player;
     }
 
-    void Dynamicmatch::pawnKilled(Pawn* victim, Pawn* killer)
+    
+
+ void Dynamicmatch::tick(float dt)
     {
-        if (victim && victim->getPlayer())
+        SUPER(Dynamicmatch, tick, dt);//TODO - was bedeutet diese Zeile
+
+        if (this->hasStarted() && !gameEnded_)
         {
-            std::string message;
-            if (killer)
+            gameTime_ = gameTime_ - dt;
+            if (gameTime_<= 0)
             {
-                if (killer->getPlayer())
-                    message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
-                else
-                    message = victim->getPlayer()->getName() + " was killed";
+                this->gameEnded_ = true;
+                this->end();        
             }
-            else
-                message = victim->getPlayer()->getName() + " died";
+		if ( gameTime_ <= timesequence_ && gameTime_ > 0)
+            {
+                const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
 
-            COUT(0) << message << std::endl;
-            Host::Broadcast(message);
-        }
+                this->gtinfo_->sendAnnounceMessage(message);
 
-        Gametype::pawnKilled(victim, killer);
+                if (timesequence_ >= 30 && timesequence_ <= 60)
+                {
+                    timesequence_ = timesequence_ - 10;
+                }
+                else if (timesequence_ <= 30)
+                {
+                    timesequence_ = timesequence_ - 5;
+                }
+                else
+                {
+                    timesequence_ = timesequence_ - 30;
+                }
+            }
+	}
     }
-
-    void Dynamicmatch::playerScored(PlayerInfo* player)
-    {
-        Gametype::playerScored(player);
-
-        if (player)
-        {
-            const std::string& message = player->getName() + " scores!";
-            COUT(0) << message << std::endl;
-            Host::Broadcast(message);
-        }
-    }
 }

Modified: code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.h
===================================================================
--- code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.h	2010-04-12 12:21:39 UTC (rev 6685)
+++ code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.h	2010-04-12 12:52:45 UTC (rev 6686)
@@ -29,6 +29,8 @@
 #ifndef _Dynamicmatch_H__
 #define _Dynamicmatch_H__
 
+#include <map>
+#include <vector>
 #include "OrxonoxPrereqs.h"
 #include "Gametype.h"
 #include "tools/Timer.h"
@@ -40,27 +42,38 @@
         public:
             Dynamicmatch(BaseObject* creator);
             virtual ~Dynamicmatch() {}
-
-		virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
-            	virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
+		
+		bool onlyChasers;
+		int getParty(PlayerInfo* player);
+		void setPlayerColour(PlayerInfo* player);//own function
+		void setConfigValues();//done
+		virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0); //ok - score function and management of parties
+            	virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0); //ok - simple
             virtual void start();
 
 		  
-            virtual void end();
+            virtual void end(); //Wie geht das mit der Punkteausgabe? frags als Schnittstelle ausreichend?
             virtual void playerEntered(PlayerInfo* player);
-            virtual bool playerLeft(PlayerInfo* player);
-            virtual bool playerChangedName(PlayerInfo* player);
-
-            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
-            virtual void playerScored(PlayerInfo* player);
-		  virtual void showPoints();
-
+		virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);//is used to initialize the player's party and colour
+            virtual bool playerLeft(PlayerInfo* player);//ToDo: extract the player's party record - done?
+            virtual bool playerChangedName(PlayerInfo* player);//unchanged
+	
+            
+		void tick (float dt);// used to end the game
+		
+		//inline const ColourValue& getPlayerColour(int teamnr) const
+                //{ return this->partyColours_[teamnr]; }
+		
 		protected:
-		  //points for each player
-		  int pointsScored[50];//sorry hard coded - each player should be able to score
-		  void winPoints();
-		  Timer outputTimer_;
-		  Timer scoreTimer_;      //?
+		  //the two different parties
+		  int chaser;
+		  int piggy;
+		  std::map< PlayerInfo*, int > playerParty_; //player's parties are recorded here
+		  std::vector<ColourValue> partyColours_; //aus TeamDeathmatch		  
+		bool friendlyfire; //goal: player can switch it on/off
+		float gameTime_;   // from UnderAttack
+		bool gameEnded_; // true if game is over
+		int timesequence_; //used for countdown
     };
 }
 




More information about the Orxonox-commit mailing list