Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 29.5 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//TODO:
29//pig punkte vergeben pro Zeit!
30//killerfarbe schwarz; evtl. eigenes Raumfahrzeug;
31//Low; Codeoptimierung und Dokumentation
32
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
42
43
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.
46*/
47#include "Dynamicmatch.h"
48
49#include "util/Convert.h"
50#include "core/CoreIncludes.h"
51#include "core/command/Executor.h"
52#include "chat/ChatManager.h"
53#include "infos/PlayerInfo.h"
54#include "worldentities/pawns/Pawn.h"
55#include "worldentities/pawns/SpaceShip.h"
56#include "core/config/ConfigValueIncludes.h"
57#include "interfaces/TeamColourable.h"
58#include "items/Engine.h"
59#include "tools/Timer.h"
60#include "worldentities/TeamSpawnPoint.h"
61
62namespace orxonox
63{
64    RegisterUnloadableClass(Dynamicmatch);
65
66    Dynamicmatch::Dynamicmatch(Context* context) : Gametype(context)
67    {
68        RegisterObject(Dynamicmatch);
69        this->gameTime_ = 180;
70        this->setConfigValues();
71        this->chaser=0;
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;
84        this->pointsPerTime=1.0f;
85        this->setHUDTemplate("DynamicmatchHUD");
86    }
87
88    Dynamicmatch::~Dynamicmatch()
89    {
90        for (Timer* timer : this->piggyTimers_)
91            delete timer;
92    }
93
94    void Dynamicmatch::setConfigValues()
95    {
96        SetConfigValue(gameTime_, 180);
97        SetConfigValue(friendlyfire, true);
98        SetConfigValue(tutorial, true);
99        static ColourValue colours[] =
100        {
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
104        };
105        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
106
107        SetConfigValue(partyColours_, defaultcolours);
108    }
109
110    bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)
111    {
112        //TODO: static and fading message for the "human" player's
113        if (!originator||!victim)
114            return false;
115        if (!originator->getPlayer()||!victim->getPlayer())
116            return false;
117        if (victim && victim->getPlayer()) //&& originator && originator->getPlayer() ??
118        {
119            int target = playerParty_[victim->getPlayer()];
120            int source = playerParty_[originator->getPlayer()];
121
122            //Case: Not Enough Pigs: party change (= party management)
123            if (notEnoughPigs)
124            {
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)
129
130                    if(tutorial) //announce party switch
131                    {
132                         std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer());
133                         if (it2 != this->players_.end())
134                         {
135                              this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it2->first->getClientID(), partyColours_[chaser]);
136                              this->gtinfo_->sendFadingMessage("You're now a victim.",it2->first->getClientID());
137                         }
138                    }
139                    if (notEnoughKillers) //reward the originator
140                    {
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
144                        numberOf[killer]++;
145
146                        if(tutorial) //announce party switch
147                        {
148                             std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer());
149                             if (it3 != this->players_.end())
150                             {
151                                  this->gtinfo_->sendStaticMessage("Take the chasers down.",it3->first->getClientID(), partyColours_[chaser]);
152                                  this->gtinfo_->sendFadingMessage("You're now a killer.",it3->first->getClientID());
153                             }
154                        }
155                    }
156                evaluatePlayerParties(); //check if the party change has to trigger futher party changes
157
158                //Give new pig boost
159                SpaceShip* spaceship = orxonox_cast<SpaceShip*>(victim);
160                this->grantPigBoost(spaceship);
161            }
162
163            //Case: notEnoughKillers: party change
164            else if (notEnoughKillers)
165            {
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)
170
171
172                if(tutorial) //announce party switch
173                {
174                     std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer());
175                     if (it3 != this->players_.end())
176                     {
177                          this->gtinfo_->sendStaticMessage("Take the chasers down.",it3->first->getClientID(),partyColours_[chaser]);
178                          this->gtinfo_->sendFadingMessage("You're now a killer.",it3->first->getClientID());
179                     }
180                }
181                evaluatePlayerParties(); //check if the party change has to trigger futher party changes
182            }
183            //Case: notEnoughChasers: party change
184            else if (notEnoughChasers)
185            {
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)
190
191                if(tutorial) //announce party switch
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)
197                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it3->first->getClientID(),partyColours_[piggy]);
198
199                          else
200                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it3->first->getClientID(),partyColours_[piggy]);
201                          this->gtinfo_->sendFadingMessage("You're now a chaser.",it3->first->getClientID());
202                     }
203                }
204                evaluatePlayerParties(); //check if the party change has to trigger futher party changes
205            }
206
207            //Case: chaser vs. killer
208            else if ((source == killer && target == chaser)||(target == killer && source == chaser ))
209            {
210                return true;
211            }
212
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())
218                    {
219                        it->second.frags_++;
220                    }
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;
228
229                //party switch -> colour switch
230                setPlayerColour(victim->getPlayer()); //victim colour
231                setPlayerColour(originator->getPlayer());//originator colour
232
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())
238                     {
239                          if (numberOf[killer]>0)
240                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(), partyColours_[piggy]);
241                          else
242                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
243                          this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
244                     }
245                     std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer());
246                     if (it2 != this->players_.end())
247                     {
248                          this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it2->first->getClientID(),partyColours_[chaser]);
249                          this->gtinfo_->sendFadingMessage("You're now a victim.",it2->first->getClientID());
250                     }
251                }
252                //Give new pig boost
253                SpaceShip* spaceship = orxonox_cast<SpaceShip*>(victim);
254                this->grantPigBoost(spaceship);
255            }
256            // killer vs piggy
257            else if (source==killer &&target==piggy) //party and colour switch
258            {
259            playerParty_[victim->getPlayer()]=killer;
260            playerParty_[originator->getPlayer()]=piggy;
261
262            setPlayerColour(victim->getPlayer()); //victim colour
263            setPlayerColour(originator->getPlayer()); //originator colour
264
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                 {
270                      this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]);
271                      this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
272                 }
273                 std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer());
274                 if (it2 != this->players_.end())
275                 {
276                      this->gtinfo_->sendStaticMessage("Take the chasers down.",it2->first->getClientID(),partyColours_[chaser]);
277                      this->gtinfo_->sendFadingMessage("You're now a killer.",it2->first->getClientID());
278                 }
279                }
280            }
281            //Case: friendly fire
282            else if (friendlyfire && (source == target))
283            {
284                this->playerScored(originator->getPlayer(), -1);
285            }
286        }
287        return false; //default: no damage
288    }
289
290
291
292    bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator)
293    {
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        {
298            if (playerParty_[originator->getPlayer()] == killer) //reward the killer
299            {
300                this->playerScored(originator->getPlayer(), 25);
301            }
302            return true;
303        }
304        else return false;
305    }
306
307    /**
308    @brief
309        Grant the victim a boost.
310    @param spaceship
311        The SpaceShip to give the boost.
312    */
313    void Dynamicmatch::grantPigBoost(SpaceShip* spaceship)
314    {
315        // Give victim boost
316        if (spaceship)
317        {
318            spaceship->addSpeedFactor(5);
319            ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
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);
324        }
325    }
326
327    void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring
328    {
329        if (!player)
330            return;
331
332        Dynamicmatch::setPlayerColour(player); //Set playercolour
333        evaluatePlayerParties();
334    }
335
336    void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction
337    {
338        if (!player)// only for safety
339            return;
340        playerParty_[player]=chaser; //Set playerparty
341        numberOf[chaser]++;
342        Gametype::playerEntered(player);
343        const std::string& message = player->getName() + " entered the game";
344        ChatManager::message(message);
345    }
346
347    bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction
348    {
349        bool valid_player = Gametype::playerLeft(player);
350        if (valid_player)
351        {
352            switch (playerParty_[player])
353            {
354            case 0: numberOf[chaser]--; break;
355            case 1: numberOf[piggy]--; break;
356            case 2: numberOf[killer]--; break;
357            }
358            const std::string& message = player->getName() + " left the game";
359            ChatManager::message(message);
360            //remove player from map
361            playerParty_.erase (player);
362            //adjust player parties
363            evaluatePlayerParties();
364        }
365
366        return valid_player;
367    }
368
369
370    void Dynamicmatch::tick(float dt)
371    {
372        SUPER(Dynamicmatch, tick, dt);
373
374        if (this->hasStarted() && !gameEnded_)
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
379            {
380                pointsPerTime = 0.0f;
381                rewardPig();
382            }
383            if (gameTime_<= 0)
384            {
385                this->gameEnded_ = true;
386                this->end();
387            }
388            if ( gameTime_ <= timesequence_ && gameTime_ > 0)
389            {
390                const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
391
392                this->gtinfo_->sendAnnounceMessage(message);
393
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            }
407        }
408    }
409
410/**
411    @brief The reward function is called every 2 seconds via the tick function and makes the victim score points.
412*/
413    void Dynamicmatch::rewardPig()
414    {
415        for (const auto& mapEntry : this->playerParty_) //durch alle Spieler iterieren und alle piggys finden
416        {
417            if (mapEntry.second==piggy)//Spieler mit der Pig-party frags++
418            {
419                 this->playerScored(mapEntry.first);
420            }
421        }
422    }
423    void Dynamicmatch::setPlayerColour(PlayerInfo* player) // sets a player's colour
424    {
425        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
426        Pawn* pawn = orxonox_cast<Pawn*>(player->getControllableEntity());
427            if (pawn)
428            {
429                pawn->setRadarObjectColour(this->partyColours_[it_player->second]);
430
431                std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
432                for (WorldEntity* pawnAttachment : pawnAttachments)
433                {
434                    if (pawnAttachment->isA(Class(TeamColourable)))
435                    {
436                        TeamColourable* tc = orxonox_cast<TeamColourable*>(pawnAttachment);
437                        tc->setTeamColour(this->partyColours_[it_player->second]);
438                    }
439                }
440            }
441    }
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
446        if ( (1 + getPlayerCount()/6) > numberOf[piggy])
447        {
448            notEnoughPigs=true;
449            if (tutorial) // Announce selectionphase
450            {
451             for (const auto& mapEntry : this->playerParty_)
452                {
453                    if (!mapEntry.first)//in order to catch nullpointer
454                        continue;
455                    if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
456                        continue;
457                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",mapEntry.first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
458                }
459            }
460        }
461        else
462        {
463             notEnoughPigs=false;
464             if(tutorial&&(!notEnoughKillers)&&(!notEnoughChasers)) //Selection phase over
465             {
466                  for (const auto& mapEntry : this->playerParty_)
467                  {
468                       if (!mapEntry.first)//in order to catch nullpointer
469                           continue;
470                       if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
471                           continue;
472                       else if (mapEntry.second==chaser)
473                       {
474                           if (numberOf[killer]>0)
475                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",mapEntry.first->getClientID(),partyColours_[piggy]);
476                           else
477                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",mapEntry.first->getClientID(),partyColours_[piggy]);
478                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
479                       }
480                       else if (mapEntry.second==piggy)
481                       {
482                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",mapEntry.first->getClientID(),partyColours_[chaser]);
483                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
484                       }
485                       else if (mapEntry.second==killer)
486                       {
487                           this->gtinfo_->sendStaticMessage("Take the chasers down.",mapEntry.first->getClientID(),partyColours_[chaser]);
488                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
489                       }
490                  }
491
492             }
493        }
494        //killers: every 4th player is a killer
495        if ( static_cast<unsigned int>(getPlayerCount()/4) > numberOf[killer])
496        {
497            notEnoughKillers=true;
498            if (tutorial) // Announce selectionphase
499            {
500             for (const auto& mapEntry : this->playerParty_)
501                {
502                    if (!mapEntry.first)//in order to catch nullpointer
503                        continue;
504                    if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
505                        continue;
506                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",mapEntry.first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
507                }
508            }
509        }
510        else
511        {
512            notEnoughKillers=false;
513            if(tutorial&&(!notEnoughPigs)&&(!notEnoughChasers)) //Selection phase over
514             {
515                  for (const auto& mapEntry : this->playerParty_)
516                  {
517                       if (!mapEntry.first)
518                           continue;
519                       if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
520                           continue;
521                       else if (mapEntry.second==chaser)
522                       {
523                           if (numberOf[killer]>0)
524                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",mapEntry.first->getClientID(),partyColours_[piggy]);
525                           else
526                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",mapEntry.first->getClientID(),partyColours_[piggy]);
527                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
528                       }
529                       else if (mapEntry.second==piggy)
530                       {
531                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",mapEntry.first->getClientID(),partyColours_[piggy]);
532                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
533                       }
534                       else if (mapEntry.second==killer)
535                       {
536                           this->gtinfo_->sendStaticMessage("Take the chasers down.",mapEntry.first->getClientID(),partyColours_[piggy]);
537                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
538                       }
539                  }
540
541             }
542
543        }
544        //chasers: there are more chasers than killers + pigs
545        if (numberOf[piggy]+numberOf[killer] > numberOf[chaser])
546        {
547            notEnoughChasers=true;
548            if (tutorial) // Announce selectionphase
549            {
550             for (const auto& mapEntry : this->playerParty_)
551                {
552                    if (!mapEntry.first)//in order to catch nullpointer
553                        continue;
554                    if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
555                        continue;
556                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",mapEntry.first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
557                }
558            }
559        }
560        else
561        {
562             notEnoughChasers=false;
563             if(tutorial&&(!notEnoughPigs)&&(!notEnoughKillers)) //Selection phase over
564             {
565                  for (const auto& mapEntry : this->playerParty_)
566                  {
567                       if (!mapEntry.first)
568                           continue;
569                       if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
570                           continue;
571                       else if (mapEntry.second==chaser)
572                       {
573                           if (numberOf[killer]>0)
574                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",mapEntry.first->getClientID(),partyColours_[piggy]);
575                           else
576                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",mapEntry.first->getClientID(),partyColours_[piggy]);
577                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
578                       }
579                       else if (mapEntry.second==piggy)
580                       {
581                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",mapEntry.first->getClientID(),partyColours_[chaser]);
582                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
583                       }
584                       else if (mapEntry.second==killer)
585                       {
586                           this->gtinfo_->sendStaticMessage("Take the chasers down.",mapEntry.first->getClientID(),partyColours_[chaser]);
587                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
588                       }
589                  }
590
591             }
592        }
593    }
594
595    int Dynamicmatch::getParty(PlayerInfo* player) // helper function for ArtificialController
596    {
597        return this->playerParty_[player];
598    }
599
600    void Dynamicmatch::resetSpeedFactor(SpaceShip* spaceship, Timer* timer)// helper function
601    {
602        if (spaceship)
603        {
604            spaceship->addSpeedFactor(1.0f/5.0f);
605        }
606
607        this->piggyTimers_.erase(timer);
608        delete timer;
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();
617            ChatManager::message(message);
618        }
619
620        return valid_player;
621    }
622
623    void Dynamicmatch::start()
624    {
625        Gametype::start();
626        if(!tutorial)
627        {
628            std::string message("Dynamicmatch started!");
629            ChatManager::message(message);
630        }
631        else if(tutorial) // Announce selectionphase
632        {
633            for (const auto& mapEntry : this->playerParty_)
634            {
635                if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
636                    continue;
637                this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",mapEntry.first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
638            }
639        }
640    }
641
642    /*void Dynamicmatch::instructions()
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!");
645        ChatManager::message(message);
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.");
652        ChatManager::message(message);
653    }*/
654    void Dynamicmatch::end()
655    {
656        Gametype::end();
657
658        std::string message("Time out. Press F2 to see the points you scored.");
659        ChatManager::message(message);
660    }
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;
667
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;
689            for (SpawnPoint* teamSpawnPoint : teamSpawnPoints)
690            {
691                if (index == randomspawn)
692                    return teamSpawnPoint;
693
694                ++index;
695            }
696        }
697
698        return nullptr;
699    }
700
701}
Note: See TracBrowser for help on using the repository browser.