Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2012merge/src/orxonox/gametypes/Dynamicmatch.cc @ 9339

Last change on this file since 9339 was 9339, checked in by jo, 12 years ago

Found reason why players are not always detected correctly: numberOfPlayers only count players that have been added before the gametype started.

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