[Orxonox-commit 4692] r9363 - code/branches/release2012/src/orxonox/gametypes

jo at orxonox.net jo at orxonox.net
Sun Sep 2 18:45:41 CEST 2012


Author: jo
Date: 2012-09-02 18:45:40 +0200 (Sun, 02 Sep 2012)
New Revision: 9363

Modified:
   code/branches/release2012/src/orxonox/gametypes/LastTeamStanding.cc
   code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.cc
   code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.h
   code/branches/release2012/src/orxonox/gametypes/TeamGametype.cc
   code/branches/release2012/src/orxonox/gametypes/TeamGametype.h
Log:
Teamdeathmatch ends if a certain number of opponents have been killed. (friendlyfire is not concerned)

Modified: code/branches/release2012/src/orxonox/gametypes/LastTeamStanding.cc
===================================================================
--- code/branches/release2012/src/orxonox/gametypes/LastTeamStanding.cc	2012-09-02 11:58:43 UTC (rev 9362)
+++ code/branches/release2012/src/orxonox/gametypes/LastTeamStanding.cc	2012-09-02 16:45:40 UTC (rev 9363)
@@ -241,17 +241,10 @@
                 {
                     party = it2->second;
                 }
-                //if (party < 0) return; //if search failed
+                if (party < 0) return; //if search failed
                 //victory message to all team members, loose message to everyone else
-                for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)
-                {
-                  if (it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
-                        continue;
-                    if (it3->second == party)
-                        {this->gtinfo_->sendAnnounceMessage("You have won the match!", it3->first->getClientID());}
-                    else
-                        {this->gtinfo_->sendAnnounceMessage("You have lost the match!", it3->first->getClientID());}
-                }
+                this->announceTeamWin(party);
+
                 return;
             }
         }

Modified: code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.cc
===================================================================
--- code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.cc	2012-09-02 11:58:43 UTC (rev 9362)
+++ code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.cc	2012-09-02 16:45:40 UTC (rev 9363)
@@ -32,6 +32,7 @@
 #include "chat/ChatManager.h"
 #include "infos/PlayerInfo.h"
 #include "worldentities/pawns/Pawn.h"
+#include "core/ConfigValueIncludes.h"
 
 namespace orxonox
 {
@@ -40,8 +41,15 @@
     TeamDeathmatch::TeamDeathmatch(BaseObject* creator) : TeamGametype(creator)
     {
         RegisterObject(TeamDeathmatch);
+
+        this->setConfigValues();
     }
 
+    void TeamDeathmatch::setConfigValues()
+    {
+        SetConfigValue(maxScore_, 10);
+    }
+
     void TeamDeathmatch::start()
     {
         TeamGametype::start();
@@ -56,6 +64,21 @@
 
         std::string message("The match has ended.");
         ChatManager::message(message);
+        
+        //find team that won the match
+        int winnerTeam = 0;
+        int highestScore = 0;
+        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+        {
+            if ( this->getTeamScore(it->first) > highestScore )
+            {
+                winnerTeam = this->getTeam(it->first);
+                highestScore = this->getTeamScore(it->first);
+            }
+        }
+
+        //announce win
+        this->announceTeamWin(winnerTeam);
     }
 
     void TeamDeathmatch::playerEntered(PlayerInfo* player)
@@ -99,7 +122,11 @@
             if (killer)
             {
                 if (killer->getPlayer())
+                {
                     message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
+                    if(this->isExactlyA(Class(TeamDeathmatch)) && (this->getTeamScore(killer->getPlayer()) >= (this->maxScore_ -1)) )
+                        this->end();
+                }
                 else
                     message = victim->getPlayer()->getName() + " was killed";
             }
@@ -108,7 +135,6 @@
 
             ChatManager::message(message);
         }
-
         Gametype::pawnKilled(victim, killer);
     }
 
@@ -120,6 +146,7 @@
         {
             const std::string& message = player->getName() + " scores!";
             ChatManager::message(message);
+
         }
     }
 

Modified: code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.h
===================================================================
--- code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.h	2012-09-02 11:58:43 UTC (rev 9362)
+++ code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.h	2012-09-02 16:45:40 UTC (rev 9363)
@@ -40,6 +40,7 @@
             TeamDeathmatch(BaseObject* creator);
             virtual ~TeamDeathmatch() {}
 
+            void setConfigValues();
             virtual void start();
             virtual void end();
             virtual void playerEntered(PlayerInfo* player);
@@ -48,6 +49,8 @@
 
             virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
             virtual void playerScored(PlayerInfo* player, int score = 1);
+       protected:
+            int maxScore_; 
     };
 }
 

Modified: code/branches/release2012/src/orxonox/gametypes/TeamGametype.cc
===================================================================
--- code/branches/release2012/src/orxonox/gametypes/TeamGametype.cc	2012-09-02 11:58:43 UTC (rev 9362)
+++ code/branches/release2012/src/orxonox/gametypes/TeamGametype.cc	2012-09-02 16:45:40 UTC (rev 9363)
@@ -172,6 +172,21 @@
         return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator || this->allowFriendlyFire_);
     }
 
+    int TeamGametype::getTeamScore(PlayerInfo* player)
+    {
+        int teamscore = 0;
+        if(!player || this->getTeam(player) == -1)
+            return 0;
+        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+        {
+            if ( this->getTeam(it->first) ==  this->getTeam(player) )
+            {
+                teamscore += it->second.frags_;
+            }
+        }
+        return teamscore;
+    }
+
     SpawnPoint* TeamGametype::getBestSpawnPoint(PlayerInfo* player) const
     {
         int desiredTeamNr = -1;
@@ -335,4 +350,21 @@
          }
     }
 
+    void TeamGametype::announceTeamWin(int winnerTeam)
+    {
+        for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)
+        {
+            if (it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
+                continue;
+            if (it3->second == winnerTeam)
+            {
+                this->gtinfo_->sendAnnounceMessage("Your team has won the match!", it3->first->getClientID());
+            }
+            else
+            {
+                this->gtinfo_->sendAnnounceMessage("Your team has lost the match!", it3->first->getClientID());
+            }
+        }   
+    }
+
 }

Modified: code/branches/release2012/src/orxonox/gametypes/TeamGametype.h
===================================================================
--- code/branches/release2012/src/orxonox/gametypes/TeamGametype.h	2012-09-02 11:58:43 UTC (rev 9362)
+++ code/branches/release2012/src/orxonox/gametypes/TeamGametype.h	2012-09-02 16:45:40 UTC (rev 9363)
@@ -61,7 +61,9 @@
 
             inline const ColourValue& getTeamColour(int teamnr) const
                 { return this->teamcolours_[teamnr]; }
+            int getTeamScore(PlayerInfo* player);
 
+
         protected:
             virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
             bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
@@ -76,6 +78,8 @@
             void setTeamColour(PlayerInfo* player, Pawn* pawn);
             void setDefaultObjectColour(Pawn* pawn);
             void colourPawn(Pawn* pawn, int teamNr);
+            void announceTeamWin(int winnerTeam);
+
     };
 }
 




More information about the Orxonox-commit mailing list