Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/gametypes/Dynamicmatch.cc @ 11099

Last change on this file since 11099 was 11099, checked in by muemart, 8 years ago

Fix loads of doxygen warnings and other documentation issues

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