Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11_v3/src/orxonox/gametypes/Dynamicmatch.cc @ 11054

Last change on this file since 11054 was 11054, checked in by landauf, 8 years ago

merged branch cpp11_v2 into cpp11_v3

  • Property svn:eol-style set to native
File size: 29.5 KB
RevLine 
[6586]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Johannes Ritz
24 *   Co-authors:
25 *      ...
26 *
27 */
[6921]28//TODO:
[6812]29//pig punkte vergeben pro Zeit!
30//killerfarbe schwarz; evtl. eigenes Raumfahrzeug;
31//Low; Codeoptimierung und Dokumentation
[6586]32
[9348]33/**
34@brief
35    Short Gaming Manual:
36    There are three different parties a player can belong to: victim, chaser or killer
37    Every player starts as chaser. As long as there are not enough victims and killers, you can change your and other player's parties by shooting them.
38    In order to win you have to earn as much points as possible:
39    - as victim by escaping the chasers
40    - as chaser by shooting the victim
41    - as killer by killing the chasers
[6812]42
43
[9348]44    What you shouldn't do is shooting at players of your own party. By doing so your score will decrease.
45    P.S: If you don't want to be a victim: Get rid of your part by shooting a chaser.
[6812]46*/
[6586]47#include "Dynamicmatch.h"
48
[6686]49#include "util/Convert.h"
[6586]50#include "core/CoreIncludes.h"
[8729]51#include "core/command/Executor.h"
[8858]52#include "chat/ChatManager.h"
[6586]53#include "infos/PlayerInfo.h"
54#include "worldentities/pawns/Pawn.h"
[6697]55#include "worldentities/pawns/SpaceShip.h"
[9667]56#include "core/config/ConfigValueIncludes.h"
[6686]57#include "interfaces/TeamColourable.h"
[6697]58#include "items/Engine.h"
59#include "tools/Timer.h"
[6848]60#include "worldentities/TeamSpawnPoint.h"
[6697]61
[6586]62namespace orxonox
63{
[9667]64    RegisterUnloadableClass(Dynamicmatch);
[6586]65
[9667]66    Dynamicmatch::Dynamicmatch(Context* context) : Gametype(context)
[6586]67    {
68        RegisterObject(Dynamicmatch);
[6812]69        this->gameTime_ = 180;
70        this->setConfigValues();
[6686]71        this->chaser=0;
[6812]72        this->piggy=1;
73        this->killer=2;
74        this->notEnoughPigs=false;
75        this->notEnoughKillers=false;
76        this->notEnoughChasers=false;
77        this->gameEnded_ =false;
78        this->timesequence_ = static_cast<int>(this->gameTime_);
79        this->friendlyfire=true;
80        this->numberOf[chaser]=0;
81        this->numberOf[piggy]=0;
82        this->numberOf[killer]=0;
83        this->tutorial=true;
[9348]84        this->pointsPerTime=1.0f;
[6921]85        this->setHUDTemplate("DynamicmatchHUD");
[6586]86    }
87
[11052]88    Dynamicmatch::~Dynamicmatch()
89    {
90        for (std::set<Timer*>::iterator it = this->piggyTimers_.begin(); it != this->piggyTimers_.end(); ++it)
91            delete (*it);
92    }
93
[6697]94    void Dynamicmatch::setConfigValues()
95    {
[6812]96        SetConfigValue(gameTime_, 180);
97        SetConfigValue(friendlyfire, true);
98        SetConfigValue(tutorial, true);
99        static ColourValue colours[] =
[6697]100        {
[7076]101            ColourValue(1.0f, 0.3f, 0.3f),  //chasercolour
102            ColourValue(0.3f, 0.3f, 1.0f),  //piggycolour
103            ColourValue(0.3f, 1.0f, 0.3f)   //killercolour  what about black: 0.0f, 0.0f, 0.0f
[6697]104        };
105        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
106
107        SetConfigValue(partyColours_, defaultcolours);
108    }
109
[6848]110    bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)
[7162]111    {
112        //TODO: static and fading message for the "human" player's
[6812]113        if (!originator||!victim)
[6921]114            return false;
[6959]115        if (!originator->getPlayer()||!victim->getPlayer())
[6921]116            return false;
[6812]117        if (victim && victim->getPlayer()) //&& originator && originator->getPlayer() ??
118        {
[9348]119            int target = playerParty_[victim->getPlayer()];
120            int source = playerParty_[originator->getPlayer()];
[6812]121
122            //Case: Not Enough Pigs: party change (= party management)
123            if (notEnoughPigs)
[6686]124            {
[7076]125                numberOf[target]--; //decrease numberof victims's party
126                playerParty_[victim->getPlayer()]=piggy; //victim's new party: pig
127                setPlayerColour(victim->getPlayer()); //victim's new colour
128                numberOf[piggy]++; //party switch: number of players is not affected (decrease and increase)
[7062]129
[7076]130                    if(tutorial) //announce party switch
[6921]131                    {
132                         std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer());
133                         if (it2 != this->players_.end())
134                         {
[7062]135                              this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it2->first->getClientID(), partyColours_[chaser]);
[6987]136                              this->gtinfo_->sendFadingMessage("You're now a victim.",it2->first->getClientID());
[6921]137                         }
138                    }
[7076]139                    if (notEnoughKillers) //reward the originator
[6686]140                    {
[7076]141                        numberOf[source]--; //decrease numberof originator's party
142                        playerParty_[originator->getPlayer()]=killer; //originator's new party: killer
143                        setPlayerColour(originator->getPlayer()); //originator's new colour
[6812]144                        numberOf[killer]++;
[7063]145
[7076]146                        if(tutorial) //announce party switch
[6921]147                        {
148                             std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer());
149                             if (it3 != this->players_.end())
150                             {
[7062]151                                  this->gtinfo_->sendStaticMessage("Take the chasers down.",it3->first->getClientID(), partyColours_[chaser]);
[6987]152                                  this->gtinfo_->sendFadingMessage("You're now a killer.",it3->first->getClientID());
[6921]153                             }
154                        }
[6686]155                    }
[7076]156                evaluatePlayerParties(); //check if the party change has to trigger futher party changes
157
[6812]158                //Give new pig boost
[9348]159                SpaceShip* spaceship = orxonox_cast<SpaceShip*>(victim);
[8727]160                this->grantPigBoost(spaceship);
[6686]161            }
[6586]162
[6812]163            //Case: notEnoughKillers: party change
164            else if (notEnoughKillers)
165            {
[7076]166                numberOf[source]--; //decrease numberof originator's party
167                playerParty_[originator->getPlayer()]=killer; //originator's new party: killer
168                setPlayerColour(originator->getPlayer()); //originator colour
169                numberOf[killer]++; //party switch: number of players is not affected (decrease and increase)
[7062]170
[7063]171
[7076]172                if(tutorial) //announce party switch
[6921]173                {
174                     std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer());
175                     if (it3 != this->players_.end())
176                     {
[7062]177                          this->gtinfo_->sendStaticMessage("Take the chasers down.",it3->first->getClientID(),partyColours_[chaser]);
[6987]178                          this->gtinfo_->sendFadingMessage("You're now a killer.",it3->first->getClientID());
[6921]179                     }
180                }
[7076]181                evaluatePlayerParties(); //check if the party change has to trigger futher party changes
[6812]182            }
183            //Case: notEnoughChasers: party change
184            else if (notEnoughChasers)
185            {
[7076]186                numberOf[target]--; //decrease numberof victims's party
187                playerParty_[victim->getPlayer()]=chaser; //victim's new party: chaser
188                setPlayerColour(victim->getPlayer()); //victim colour
189                numberOf[chaser]++; //party switch: number of players is not affected (decrease and increase)
[7062]190
[7076]191                if(tutorial) //announce party switch
[6921]192                {
193                     std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer());
194                     if (it3 != this->players_.end())
195                     {
196                          if (numberOf[killer]>0)
[7062]197                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it3->first->getClientID(),partyColours_[piggy]);
[7076]198
[6921]199                          else
[7062]200                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it3->first->getClientID(),partyColours_[piggy]);
[6987]201                          this->gtinfo_->sendFadingMessage("You're now a chaser.",it3->first->getClientID());
[6921]202                     }
203                }
[7076]204                evaluatePlayerParties(); //check if the party change has to trigger futher party changes
[6812]205            }
[6586]206
[6812]207            //Case: chaser vs. killer
208            else if ((source == killer && target == chaser)||(target == killer && source == chaser ))
209            {
210                return true;
211            }
[6586]212
[6812]213            //Case: a chaser hits piggy
214            else if ((source==chaser)&&(target==piggy))
215            {
216                std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
217                if (it != this->players_.end())
[6686]218                    {
219                        it->second.frags_++;
220                    }
[6812]221            }
222            //Case: piggy hits chaser
223            else if (source==piggy&&target==chaser)
224            {
225                //partyswitch: victim bcomes piggy and the originator(piggy) becomes chaser
226                playerParty_[victim->getPlayer()]=piggy;
227                playerParty_[originator->getPlayer()]=chaser;
[6697]228
[7076]229                //party switch -> colour switch
[6812]230                setPlayerColour(victim->getPlayer()); //victim colour
231                setPlayerColour(originator->getPlayer());//originator colour
[7076]232
[6921]233                //Announce pary switch
234                if(tutorial)
235                {
236                     std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
237                     if (it != this->players_.end())
[7076]238                     {
[6921]239                          if (numberOf[killer]>0)
[7062]240                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(), partyColours_[piggy]);
[6921]241                          else
[7062]242                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
[6987]243                          this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
[6921]244                     }
245                     std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer());
246                     if (it2 != this->players_.end())
247                     {
[7062]248                          this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it2->first->getClientID(),partyColours_[chaser]);
[6987]249                          this->gtinfo_->sendFadingMessage("You're now a victim.",it2->first->getClientID());
[6921]250                     }
251                }
[6812]252                //Give new pig boost
[9348]253                SpaceShip* spaceship = orxonox_cast<SpaceShip*>(victim);
[8727]254                this->grantPigBoost(spaceship);
[6812]255            }
[6848]256            // killer vs piggy
[7076]257            else if (source==killer &&target==piggy) //party and colour switch
[6812]258            {
259            playerParty_[victim->getPlayer()]=killer;
260            playerParty_[originator->getPlayer()]=piggy;
[6697]261
[7076]262            setPlayerColour(victim->getPlayer()); //victim colour
263            setPlayerColour(originator->getPlayer()); //originator colour
[7062]264
[6921]265            if(tutorial) //Announce pary switch
266            {
267                 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
268                 if (it != this->players_.end())
269                 {
[7062]270                      this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]);
[6987]271                      this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
[6921]272                 }
273                 std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer());
274                 if (it2 != this->players_.end())
275                 {
[7062]276                      this->gtinfo_->sendStaticMessage("Take the chasers down.",it2->first->getClientID(),partyColours_[chaser]);
[6987]277                      this->gtinfo_->sendFadingMessage("You're now a killer.",it2->first->getClientID());
[6921]278                 }
279                }
[6812]280            }
281            //Case: friendly fire
282            else if (friendlyfire && (source == target))
283            {
[9945]284                this->playerScored(originator->getPlayer(), -1);
[6812]285            }
[9348]286        }
[6812]287        return false; //default: no damage
[6686]288    }
[6586]289
[6686]290
291
[6812]292    bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator)
[7076]293    {
[6812]294        //killers can kill chasers and killers can be killed by chasers
295        if ((playerParty_[originator->getPlayer()] == killer && playerParty_[victim->getPlayer()] == chaser)||(playerParty_[victim->getPlayer()] == killer &&
296        playerParty_[originator->getPlayer()] == chaser ))
297        {
[7076]298            if (playerParty_[originator->getPlayer()] == killer) //reward the killer
[6812]299            {
[9945]300                this->playerScored(originator->getPlayer(), 25);
[6812]301            }
[9348]302            return true;
[6812]303        }
304        else return false;
[6586]305    }
[7076]306
[8727]307    /**
308    @brief
[9348]309        Grant the victim a boost.
[8727]310    @param spaceship
311        The SpaceShip to give the boost.
312    */
313    void Dynamicmatch::grantPigBoost(SpaceShip* spaceship)
[8706]314    {
[9348]315        // Give victim boost
[8706]316        if (spaceship)
317        {
[8727]318            spaceship->addSpeedFactor(5);
[8706]319            ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
[11052]320            Timer* timer = new Timer(10, false, executor);
321            executor->setDefaultValue(0, spaceship); // TODO: use WeakPtr because spaceship can be destroyed in the meantime
322            executor->setDefaultValue(1, timer);
323            this->piggyTimers_.insert(timer);
[8706]324        }
325    }
326
[6812]327    void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring
[6586]328    {
[6686]329        if (!player)
330            return;
[7076]331
332        Dynamicmatch::setPlayerColour(player); //Set playercolour
[6812]333        evaluatePlayerParties();
[6686]334    }
335
[6692]336    void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction
[6686]337    {
[6812]338        if (!player)// only for safety
[6686]339            return;
[7076]340        playerParty_[player]=chaser; //Set playerparty
[6848]341        numberOf[chaser]++;
[6586]342        Gametype::playerEntered(player);
[8858]343        const std::string& message = player->getName() + " entered the game";
344        ChatManager::message(message);
[6586]345    }
346
[6686]347    bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction
[6586]348    {
349        bool valid_player = Gametype::playerLeft(player);
350        if (valid_player)
351        {
[6812]352            switch (playerParty_[player])
353            {
354            case 0: numberOf[chaser]--; break;
355            case 1: numberOf[piggy]--; break;
356            case 2: numberOf[killer]--; break;
357            }
[6586]358            const std::string& message = player->getName() + " left the game";
[8858]359            ChatManager::message(message);
[7076]360            //remove player from map
[6812]361            playerParty_.erase (player);
[7076]362            //adjust player parties
[6812]363            evaluatePlayerParties();
[6586]364        }
365
366        return valid_player;
367    }
368
369
[6812]370    void Dynamicmatch::tick(float dt)
[6586]371    {
[6848]372        SUPER(Dynamicmatch, tick, dt);
[6686]373
374        if (this->hasStarted() && !gameEnded_)
[9348]375        {
376            pointsPerTime = pointsPerTime + dt; //increase points
377            gameTime_ = gameTime_ - dt; // decrease game time
378            if (pointsPerTime > 2.0f) //hard coded points for victim! should be changed
[6812]379            {
[9348]380                pointsPerTime = 0.0f;
[6921]381                rewardPig();
[6812]382            }
[6686]383            if (gameTime_<= 0)
[6586]384            {
[6686]385                this->gameEnded_ = true;
[7076]386                this->end();
[6586]387            }
[7076]388            if ( gameTime_ <= timesequence_ && gameTime_ > 0)
[6686]389            {
390                const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
[6586]391
[6686]392                this->gtinfo_->sendAnnounceMessage(message);
[6586]393
[6686]394                if (timesequence_ >= 30 && timesequence_ <= 60)
395                {
396                    timesequence_ = timesequence_ - 10;
397                }
398                else if (timesequence_ <= 30)
399                {
400                    timesequence_ = timesequence_ - 5;
401                }
402                else
403                {
404                    timesequence_ = timesequence_ - 30;
405                }
406            }
[7076]407        }
[6586]408    }
[6812]409
[9348]410/**
411    @brief The reward function is called every 2 seconds via the tick function and makes the victim score points.
412*/
[6812]413    void Dynamicmatch::rewardPig()
414    {
[11054]415        for (const auto& mapEntry : this->playerParty_) //durch alle Spieler iterieren und alle piggys finden
[6921]416        {
[11054]417            if (mapEntry.second==piggy)//Spieler mit der Pig-party frags++
[6921]418            {
[11054]419                 this->playerScored(mapEntry.first);
[6921]420            }
421        }
[6812]422    }
[7062]423    void Dynamicmatch::setPlayerColour(PlayerInfo* player) // sets a player's colour
[6812]424    {
425        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
[9348]426        Pawn* pawn = orxonox_cast<Pawn*>(player->getControllableEntity());
[6812]427            if (pawn)
428            {
[6921]429                pawn->setRadarObjectColour(this->partyColours_[it_player->second]);
[6812]430
431                std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
[11054]432                for (WorldEntity* pawnAttachment : pawnAttachments)
[6812]433                {
[11054]434                    if (pawnAttachment->isA(Class(TeamColourable)))
[6812]435                    {
[11054]436                        TeamColourable* tc = orxonox_cast<TeamColourable*>(pawnAttachment);
[6812]437                        tc->setTeamColour(this->partyColours_[it_player->second]);
438                    }
439                }
440            }
[7076]441    }
[6812]442
443    void Dynamicmatch::evaluatePlayerParties() //manages the notEnough booleans (here the percentage of special players is implemented)
444    {
445        //pigs: 1 + every 6th player is a pig
[9348]446        if ( (1 + getPlayerCount()/6) > numberOf[piggy])
[6921]447        {
448            notEnoughPigs=true;
449            if (tutorial) // Announce selectionphase
450            {
[11054]451             for (const auto& mapEntry : this->playerParty_)
[6921]452                {
[11054]453                    if (!mapEntry.first)//in order to catch nullpointer
[6921]454                        continue;
[11054]455                    if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[6921]456                        continue;
[11054]457                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",mapEntry.first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
[6921]458                }
459            }
460        }
461        else
462        {
463             notEnoughPigs=false;
464             if(tutorial&&(!notEnoughKillers)&&(!notEnoughChasers)) //Selection phase over
465             {
[11054]466                  for (const auto& mapEntry : this->playerParty_)
[6921]467                  {
[11054]468                       if (!mapEntry.first)//in order to catch nullpointer
[6921]469                           continue;
[11054]470                       if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[6921]471                           continue;
[11054]472                       else if (mapEntry.second==chaser)
[6921]473                       {
474                           if (numberOf[killer]>0)
[11054]475                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",mapEntry.first->getClientID(),partyColours_[piggy]);
[6921]476                           else
[11054]477                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",mapEntry.first->getClientID(),partyColours_[piggy]);
[6987]478                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
[6921]479                       }
[11054]480                       else if (mapEntry.second==piggy)
[6987]481                       {
[11054]482                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",mapEntry.first->getClientID(),partyColours_[chaser]);
[6987]483                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
484                       }
[11054]485                       else if (mapEntry.second==killer)
[6987]486                       {
[11054]487                           this->gtinfo_->sendStaticMessage("Take the chasers down.",mapEntry.first->getClientID(),partyColours_[chaser]);
[6987]488                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
489                       }
[6921]490                  }
[7076]491
[6921]492             }
493        }
[6812]494        //killers: every 4th player is a killer
[9348]495        if ( static_cast<unsigned int>(getPlayerCount()/4) > numberOf[killer])
[6921]496        {
497            notEnoughKillers=true;
498            if (tutorial) // Announce selectionphase
499            {
[11054]500             for (const auto& mapEntry : this->playerParty_)
[6921]501                {
[11054]502                    if (!mapEntry.first)//in order to catch nullpointer
[6921]503                        continue;
[11054]504                    if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[6921]505                        continue;
[11054]506                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",mapEntry.first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
[6921]507                }
508            }
509        }
510        else
511        {
512            notEnoughKillers=false;
513            if(tutorial&&(!notEnoughPigs)&&(!notEnoughChasers)) //Selection phase over
514             {
[11054]515                  for (const auto& mapEntry : this->playerParty_)
[6921]516                  {
[11054]517                       if (!mapEntry.first)
[6921]518                           continue;
[11054]519                       if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[6921]520                           continue;
[11054]521                       else if (mapEntry.second==chaser)
[6921]522                       {
523                           if (numberOf[killer]>0)
[11054]524                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",mapEntry.first->getClientID(),partyColours_[piggy]);
[6921]525                           else
[11054]526                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",mapEntry.first->getClientID(),partyColours_[piggy]);
[6987]527                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
[6921]528                       }
[11054]529                       else if (mapEntry.second==piggy)
[6987]530                       {
[11054]531                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",mapEntry.first->getClientID(),partyColours_[piggy]);
[6987]532                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
533                       }
[11054]534                       else if (mapEntry.second==killer)
[6987]535                       {
[11054]536                           this->gtinfo_->sendStaticMessage("Take the chasers down.",mapEntry.first->getClientID(),partyColours_[piggy]);
[6987]537                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
538                       }
[6921]539                  }
[7076]540
[6921]541             }
[7076]542
[6921]543        }
[6812]544        //chasers: there are more chasers than killers + pigs
[6921]545        if (numberOf[piggy]+numberOf[killer] > numberOf[chaser])
546        {
547            notEnoughChasers=true;
548            if (tutorial) // Announce selectionphase
549            {
[11054]550             for (const auto& mapEntry : this->playerParty_)
[6921]551                {
[11054]552                    if (!mapEntry.first)//in order to catch nullpointer
[6921]553                        continue;
[11054]554                    if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[6921]555                        continue;
[11054]556                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",mapEntry.first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
[6921]557                }
558            }
559        }
560        else
561        {
562             notEnoughChasers=false;
563             if(tutorial&&(!notEnoughPigs)&&(!notEnoughKillers)) //Selection phase over
564             {
[11054]565                  for (const auto& mapEntry : this->playerParty_)
[6921]566                  {
[11054]567                       if (!mapEntry.first)
[6921]568                           continue;
[11054]569                       if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[6921]570                           continue;
[11054]571                       else if (mapEntry.second==chaser)
[6921]572                       {
573                           if (numberOf[killer]>0)
[11054]574                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",mapEntry.first->getClientID(),partyColours_[piggy]);
[6921]575                           else
[11054]576                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",mapEntry.first->getClientID(),partyColours_[piggy]);
[6987]577                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
[6921]578                       }
[11054]579                       else if (mapEntry.second==piggy)
[6987]580                       {
[11054]581                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",mapEntry.first->getClientID(),partyColours_[chaser]);
[6987]582                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
583                       }
[11054]584                       else if (mapEntry.second==killer)
[6987]585                       {
[11054]586                           this->gtinfo_->sendStaticMessage("Take the chasers down.",mapEntry.first->getClientID(),partyColours_[chaser]);
[6987]587                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
588                       }
[6921]589                  }
[7076]590
[6921]591             }
[7076]592        }
[6812]593    }
594
595    int Dynamicmatch::getParty(PlayerInfo* player) // helper function for ArtificialController
596    {
597        return this->playerParty_[player];
598    }
599
[11052]600    void Dynamicmatch::resetSpeedFactor(SpaceShip* spaceship, Timer* timer)// helper function
[6812]601    {
[10624]602        if (spaceship)
[6812]603        {
[10624]604            spaceship->addSpeedFactor(1.0f/5.0f);
[6812]605        }
[11052]606
607        this->piggyTimers_.erase(timer);
608        delete timer;
[6812]609    }
610
611    bool Dynamicmatch::playerChangedName(PlayerInfo* player) //standardfunction
612    {
613        bool valid_player = Gametype::playerChangedName(player);
614        if (valid_player)
615        {
616            const std::string& message = player->getOldName() + " changed name to " + player->getName();
[8858]617            ChatManager::message(message);
[6812]618        }
619
620        return valid_player;
621    }
622
[7076]623    void Dynamicmatch::start()
624    {
[6812]625        Gametype::start();
626        if(!tutorial)
627        {
[6921]628            std::string message("Dynamicmatch started!");
[8858]629            ChatManager::message(message);
[6812]630        }
[6921]631        else if(tutorial) // Announce selectionphase
[6812]632        {
[11054]633            for (const auto& mapEntry : this->playerParty_)
[6921]634            {
[11054]635                if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[6921]636                    continue;
[11054]637                this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",mapEntry.first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
[6921]638            }
[6812]639        }
[7076]640    }
[6812]641
[6921]642    /*void Dynamicmatch::instructions()
[6812]643    {
644        std::string message("Earn points:\n\n\n\tIf you're red: Chase the blue player!\n\n\tIf you're blue shoot at a red player or hide.\n\n\tIf you're green: You've got the licence to kill red players!");
[8858]645        ChatManager::message(message);
[6812]646        callInstructions_.setTimer(10, false, createExecutor(createFunctor(&Dynamicmatch::furtherInstructions, this)));
647    }
648
649    void Dynamicmatch::furtherInstructions()
650    {
651        std::string message("After 3 Minutes the game is over.");
[8858]652        ChatManager::message(message);
[6921]653    }*/
[6812]654    void Dynamicmatch::end()
655    {
656        Gametype::end();
657
658        std::string message("Time out. Press F2 to see the points you scored.");
[8858]659        ChatManager::message(message);
[6812]660    }
[6848]661    SpawnPoint* Dynamicmatch::getBestSpawnPoint(PlayerInfo* player) const
662    {
663        int desiredTeamNr = -1;
664        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
665        if (it_player != this->playerParty_.end())
666            desiredTeamNr = it_player->second;
[6812]667
[6848]668        // Only use spawnpoints of the own team (or non-team-spawnpoints)
669        std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_;
670        for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
671        {
672            if ((*it)->isA(Class(TeamSpawnPoint)))
673            {
674                TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it);
675                if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)//getTeamNumber!!
676                {
677                    teamSpawnPoints.erase(it++);
678                    continue;
679                }
680            }
681
682            ++it;
683        }
684
685        if (teamSpawnPoints.size() > 0)
686        {
687            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
688            unsigned int index = 0;
[11054]689            for (SpawnPoint* teamSpawnPoint : teamSpawnPoints)
[6848]690            {
691                if (index == randomspawn)
[11054]692                    return teamSpawnPoint;
[6848]693
694                ++index;
695            }
696        }
697
[11054]698        return nullptr;
[6848]699    }
700
[6586]701}
Note: See TracBrowser for help on using the repository browser.