Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9363 for code/branches


Ignore:
Timestamp:
Sep 2, 2012, 6:45:40 PM (12 years ago)
Author:
jo
Message:

Teamdeathmatch ends if a certain number of opponents have been killed. (friendlyfire is not concerned)

Location:
code/branches/release2012/src/orxonox/gametypes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/release2012/src/orxonox/gametypes/LastTeamStanding.cc

    r9348 r9363  
    242242                    party = it2->second;
    243243                }
    244                 //if (party < 0) return; //if search failed
     244                if (party < 0) return; //if search failed
    245245                //victory message to all team members, loose message to everyone else
    246                 for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)
    247                 {
    248                   if (it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    249                         continue;
    250                     if (it3->second == party)
    251                         {this->gtinfo_->sendAnnounceMessage("You have won the match!", it3->first->getClientID());}
    252                     else
    253                         {this->gtinfo_->sendAnnounceMessage("You have lost the match!", it3->first->getClientID());}
    254                 }
     246                this->announceTeamWin(party);
     247
    255248                return;
    256249            }
  • code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.cc

    r9348 r9363  
    3333#include "infos/PlayerInfo.h"
    3434#include "worldentities/pawns/Pawn.h"
     35#include "core/ConfigValueIncludes.h"
    3536
    3637namespace orxonox
     
    4142    {
    4243        RegisterObject(TeamDeathmatch);
     44
     45        this->setConfigValues();
     46    }
     47
     48    void TeamDeathmatch::setConfigValues()
     49    {
     50        SetConfigValue(maxScore_, 10);
    4351    }
    4452
     
    5765        std::string message("The match has ended.");
    5866        ChatManager::message(message);
     67       
     68        //find team that won the match
     69        int winnerTeam = 0;
     70        int highestScore = 0;
     71        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     72        {
     73            if ( this->getTeamScore(it->first) > highestScore )
     74            {
     75                winnerTeam = this->getTeam(it->first);
     76                highestScore = this->getTeamScore(it->first);
     77            }
     78        }
     79
     80        //announce win
     81        this->announceTeamWin(winnerTeam);
    5982    }
    6083
     
    100123            {
    101124                if (killer->getPlayer())
     125                {
    102126                    message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
     127                    if(this->isExactlyA(Class(TeamDeathmatch)) && (this->getTeamScore(killer->getPlayer()) >= (this->maxScore_ -1)) )
     128                        this->end();
     129                }
    103130                else
    104131                    message = victim->getPlayer()->getName() + " was killed";
     
    109136            ChatManager::message(message);
    110137        }
    111 
    112138        Gametype::pawnKilled(victim, killer);
    113139    }
     
    121147            const std::string& message = player->getName() + " scores!";
    122148            ChatManager::message(message);
     149
    123150        }
    124151    }
  • code/branches/release2012/src/orxonox/gametypes/TeamDeathmatch.h

    r9348 r9363  
    4141            virtual ~TeamDeathmatch() {}
    4242
     43            void setConfigValues();
    4344            virtual void start();
    4445            virtual void end();
     
    4950            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
    5051            virtual void playerScored(PlayerInfo* player, int score = 1);
     52       protected:
     53            int maxScore_;
    5154    };
    5255}
  • code/branches/release2012/src/orxonox/gametypes/TeamGametype.cc

    r9348 r9363  
    173173    }
    174174
     175    int TeamGametype::getTeamScore(PlayerInfo* player)
     176    {
     177        int teamscore = 0;
     178        if(!player || this->getTeam(player) == -1)
     179            return 0;
     180        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     181        {
     182            if ( this->getTeam(it->first) ==  this->getTeam(player) )
     183            {
     184                teamscore += it->second.frags_;
     185            }
     186        }
     187        return teamscore;
     188    }
     189
    175190    SpawnPoint* TeamGametype::getBestSpawnPoint(PlayerInfo* player) const
    176191    {
     
    336351    }
    337352
     353    void TeamGametype::announceTeamWin(int winnerTeam)
     354    {
     355        for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)
     356        {
     357            if (it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
     358                continue;
     359            if (it3->second == winnerTeam)
     360            {
     361                this->gtinfo_->sendAnnounceMessage("Your team has won the match!", it3->first->getClientID());
     362            }
     363            else
     364            {
     365                this->gtinfo_->sendAnnounceMessage("Your team has lost the match!", it3->first->getClientID());
     366            }
     367        }   
     368    }
     369
    338370}
  • code/branches/release2012/src/orxonox/gametypes/TeamGametype.h

    r9348 r9363  
    6262            inline const ColourValue& getTeamColour(int teamnr) const
    6363                { return this->teamcolours_[teamnr]; }
     64            int getTeamScore(PlayerInfo* player);
     65
    6466
    6567        protected:
     
    7779            void setDefaultObjectColour(Pawn* pawn);
    7880            void colourPawn(Pawn* pawn, int teamNr);
     81            void announceTeamWin(int winnerTeam);
     82
    7983    };
    8084}
Note: See TracChangeset for help on using the changeset viewer.