Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/unity_build/src/orxonox/gametypes/Dynamicmatch.cc @ 8674

Last change on this file since 8674 was 8674, checked in by rgrieder, 13 years ago

Reduced some header file dependencies in tools:

  • moved Timer::setTimer() to source file
  • Property svn:eol-style set to native
File size: 30.4 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/*
34short gaming manual:
35There are three different parties a player can belong to: victim, chaser or killer
36Every 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.
37In order to win you have to earn as much points as possible:
38- as victim by escaping the chasers
39- as chaser by shooting the victim
40- as killer by killing the chasers
41
42
43What you shouldn't do is shooting at players of your own party. By doing so your score will decrease.
44P.S: If you don't want to be a victim: Get rid of your part by shooting a chaser.
45*/
46#include "Dynamicmatch.h"
47
48#include "util/Convert.h"
49#include "core/CoreIncludes.h"
50#include "core/command/Executor.h"
51#include "network/Host.h"
52#include "infos/PlayerInfo.h"
53#include "worldentities/pawns/Pawn.h"
54#include "worldentities/pawns/SpaceShip.h"
55#include "core/ConfigValueIncludes.h"
56#include "interfaces/TeamColourable.h"
57#include "items/Engine.h"
58#include "tools/Timer.h"
59#include "worldentities/TeamSpawnPoint.h"
60
61namespace orxonox
62{
63    CreateUnloadableFactory(Dynamicmatch);
64
65    Dynamicmatch::Dynamicmatch(BaseObject* creator) : Gametype(creator)
66    {
67        RegisterObject(Dynamicmatch);
68        this->gameTime_ = 180;
69        this->setConfigValues();
70        this->chaser=0;
71        this->piggy=1;
72        this->killer=2;
73        this->notEnoughPigs=false;
74        this->notEnoughKillers=false;
75        this->notEnoughChasers=false;
76        this->gameEnded_ =false;
77        this->timesequence_ = static_cast<int>(this->gameTime_);
78        this->friendlyfire=true;
79        this->numberOf[chaser]=0;
80        this->numberOf[piggy]=0;
81        this->numberOf[killer]=0;
82        this->tutorial=true;
83        this->pointsPerTime=0.0f;
84        this->setHUDTemplate("DynamicmatchHUD");
85    }
86
87    void Dynamicmatch::setConfigValues()
88    {
89        SetConfigValue(gameTime_, 180);
90        SetConfigValue(friendlyfire, true);
91        SetConfigValue(tutorial, true);
92        static ColourValue colours[] =
93        {
94            ColourValue(1.0f, 0.3f, 0.3f),  //chasercolour
95            ColourValue(0.3f, 0.3f, 1.0f),  //piggycolour
96            ColourValue(0.3f, 1.0f, 0.3f)   //killercolour  what about black: 0.0f, 0.0f, 0.0f
97
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 = dynamic_cast<SpaceShip*>(victim);
154                if (spaceship && spaceship->getEngine())
155                {
156                    spaceship->getEngine()->setSpeedFactor(5);
157                    WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine());
158                    ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
159                    executor->setDefaultValue(0, ptr);
160                    new Timer(10, false, executor, true);
161                }
162            }
163
164            //Case: notEnoughKillers: party change
165            else if (notEnoughKillers)
166            {
167                numberOf[source]--; //decrease numberof originator's party
168                playerParty_[originator->getPlayer()]=killer; //originator's new party: killer
169                setPlayerColour(originator->getPlayer()); //originator colour
170                numberOf[killer]++; //party switch: number of players is not affected (decrease and increase)
171
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                          this->gtinfo_->sendStaticMessage("Take the chasers down.",it3->first->getClientID(),partyColours_[chaser]);
179                          this->gtinfo_->sendFadingMessage("You're now a killer.",it3->first->getClientID());
180                     }
181                }
182                evaluatePlayerParties(); //check if the party change has to trigger futher party changes
183            }
184            //Case: notEnoughChasers: party change
185            else if (notEnoughChasers)
186            {
187                numberOf[target]--; //decrease numberof victims's party
188                playerParty_[victim->getPlayer()]=chaser; //victim's new party: chaser
189                setPlayerColour(victim->getPlayer()); //victim colour
190                numberOf[chaser]++; //party switch: number of players is not affected (decrease and increase)
191
192                if(tutorial) //announce party switch
193                {
194                     std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer());
195                     if (it3 != this->players_.end())
196                     {
197                          if (numberOf[killer]>0)
198                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it3->first->getClientID(),partyColours_[piggy]);
199
200                          else
201                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it3->first->getClientID(),partyColours_[piggy]);
202                          this->gtinfo_->sendFadingMessage("You're now a chaser.",it3->first->getClientID());
203                     }
204                }
205                evaluatePlayerParties(); //check if the party change has to trigger futher party changes
206            }
207
208            //Case: chaser vs. killer
209            else if ((source == killer && target == chaser)||(target == killer && source == chaser ))
210            {
211                return true;
212            }
213
214            //Case: a chaser hits piggy
215            else if ((source==chaser)&&(target==piggy))
216            {
217                std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
218                if (it != this->players_.end())
219                    {
220                        it->second.frags_++;
221                    }
222            }
223            //Case: piggy hits chaser
224            else if (source==piggy&&target==chaser)
225            {
226                //partyswitch: victim bcomes piggy and the originator(piggy) becomes chaser
227                playerParty_[victim->getPlayer()]=piggy;
228                playerParty_[originator->getPlayer()]=chaser;
229
230                //party switch -> colour switch
231                setPlayerColour(victim->getPlayer()); //victim colour
232                setPlayerColour(originator->getPlayer());//originator colour
233
234                //Announce pary switch
235                if(tutorial)
236                {
237                     std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
238                     if (it != this->players_.end())
239                     {
240                          if (numberOf[killer]>0)
241                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(), partyColours_[piggy]);
242                          else
243                              this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
244                          this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
245                     }
246                     std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer());
247                     if (it2 != this->players_.end())
248                     {
249                          this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it2->first->getClientID(),partyColours_[chaser]);
250                          this->gtinfo_->sendFadingMessage("You're now a victim.",it2->first->getClientID());
251                     }
252                }
253                //Give new pig boost
254                SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
255                if (spaceship && spaceship->getEngine())
256                {
257                    spaceship->getEngine()->setSpeedFactor(5);
258                    WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine());
259                    ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
260                    executor->setDefaultValue(0, ptr);
261                    new Timer(10, false, executor, true);
262                }
263
264            }
265            // killer vs piggy
266            else if (source==killer &&target==piggy) //party and colour switch
267            {
268            playerParty_[victim->getPlayer()]=killer;
269            playerParty_[originator->getPlayer()]=piggy;
270
271            setPlayerColour(victim->getPlayer()); //victim colour
272            setPlayerColour(originator->getPlayer()); //originator colour
273
274            if(tutorial) //Announce pary switch
275            {
276                 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
277                 if (it != this->players_.end())
278                 {
279                      this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]);
280                      this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
281                 }
282                 std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer());
283                 if (it2 != this->players_.end())
284                 {
285                      this->gtinfo_->sendStaticMessage("Take the chasers down.",it2->first->getClientID(),partyColours_[chaser]);
286                      this->gtinfo_->sendFadingMessage("You're now a killer.",it2->first->getClientID());
287                 }
288                }
289            }
290            //Case: friendly fire
291            else if (friendlyfire && (source == target))
292            {
293                std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
294                if (it != this->players_.end())
295                    {
296                        it->second.frags_--;
297                    }
298            }
299        }// from far far away not to be removed!
300        return false; //default: no damage
301    }
302
303
304
305    bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator)
306    {
307        //killers can kill chasers and killers can be killed by chasers
308        if ((playerParty_[originator->getPlayer()] == killer && playerParty_[victim->getPlayer()] == chaser)||(playerParty_[victim->getPlayer()] == killer &&
309        playerParty_[originator->getPlayer()] == chaser ))
310        {
311            if (playerParty_[originator->getPlayer()] == killer) //reward the killer
312            {
313                std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
314                if (it != this->players_.end())
315                {
316                    it->second.frags_+=20; //value must be tested
317                }
318            }
319        return true;
320        }
321        else return false;
322    }
323
324    void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring
325    {
326        if (!player)
327            return;
328
329        Dynamicmatch::setPlayerColour(player); //Set playercolour
330        evaluatePlayerParties();
331    }
332
333    void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction
334    {
335        if (!player)// only for safety
336            return;
337        playerParty_[player]=chaser; //Set playerparty
338        numberOf[chaser]++;
339        Gametype::playerEntered(player);
340        const std::string& message6 = player->getName() + " entered the game";
341        COUT(0) << message6 << std::endl;
342        Host::Broadcast(message6);
343    }
344
345    bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction
346    {
347        bool valid_player = Gametype::playerLeft(player);
348        if (valid_player)
349        {
350            switch (playerParty_[player])
351            {
352            case 0: numberOf[chaser]--; break;
353            case 1: numberOf[piggy]--; break;
354            case 2: numberOf[killer]--; break;
355            }
356            const std::string& message = player->getName() + " left the game";
357            COUT(0) << message << std::endl;
358            Host::Broadcast(message);
359            //remove player from map
360            playerParty_.erase (player);
361            //adjust player parties
362            evaluatePlayerParties();
363        }
364
365        return valid_player;
366    }
367
368
369    void Dynamicmatch::tick(float dt)
370    {
371        SUPER(Dynamicmatch, tick, dt);
372
373        if (this->hasStarted() && !gameEnded_)
374        {   pointsPerTime =pointsPerTime + dt;
375            gameTime_ = gameTime_ - dt;
376            if (pointsPerTime > 2.0f)//hard coded!! should be changed
377            {
378                pointsPerTime=0.0f;
379                rewardPig();
380            }
381            if (gameTime_<= 0)
382            {
383                this->gameEnded_ = true;
384                this->end();
385            }
386            if ( gameTime_ <= timesequence_ && gameTime_ > 0)
387            {
388                const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
389
390                this->gtinfo_->sendAnnounceMessage(message);
391
392                if (timesequence_ >= 30 && timesequence_ <= 60)
393                {
394                    timesequence_ = timesequence_ - 10;
395                }
396                else if (timesequence_ <= 30)
397                {
398                    timesequence_ = timesequence_ - 5;
399                }
400                else
401                {
402                    timesequence_ = timesequence_ - 30;
403                }
404            }
405        }
406    }
407
408    void Dynamicmatch::rewardPig()
409    {
410        for (std::map< PlayerInfo*, int >::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) //durch alle Spieler iterieren und alle piggys finden
411        {
412            if (it->second==piggy)
413            {
414                 //Spieler mit der Pig-party frags++
415                 std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(it->first);// still not sure if right syntax
416                 if (it2 != this->players_.end())
417                 {
418                     it2->second.frags_++;
419                 }
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 = dynamic_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 (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
433                {
434                    if ((*it)->isA(Class(TeamColourable)))
435                    {
436                        TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
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+this->getNumberOfPlayers()/6) > numberOf[piggy])
447        {
448            notEnoughPigs=true;
449            if (tutorial) // Announce selectionphase
450            {
451             for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
452                {
453                    if (!it->first)//in order to catch nullpointer
454                        continue;
455                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
456                        continue;
457                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->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 (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
467                  {
468                       if (!it->first)//in order to catch nullpointer
469                           continue;
470                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
471                           continue;
472                       else if (it->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.",it->first->getClientID(),partyColours_[piggy]);
476                           else
477                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
478                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
479                       }
480                       else if (it->second==piggy)
481                       {
482                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]);
483                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
484                       }
485                       else if (it->second==killer)
486                       {
487                           this->gtinfo_->sendStaticMessage("Take the chasers down.",it->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 (getNumberOfPlayers()/4 > numberOf[killer])
496        {
497            notEnoughKillers=true;
498            if (tutorial) // Announce selectionphase
499            {
500             for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
501                {
502                    if (!it->first)//in order to catch nullpointer
503                        continue;
504                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
505                        continue;
506                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->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 (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
516                  {
517                       if (!it->first)
518                           continue;
519                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
520                           continue;
521                       else if (it->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.",it->first->getClientID(),partyColours_[piggy]);
525                           else
526                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
527                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
528                       }
529                       else if (it->second==piggy)
530                       {
531                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[piggy]);
532                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
533                       }
534                       else if (it->second==killer)
535                       {
536                           this->gtinfo_->sendStaticMessage("Take the chasers down.",it->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 (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
551                {
552                    if (!it->first)//in order to catch nullpointer
553                        continue;
554                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
555                        continue;
556                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->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 (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
566                  {
567                       if (!it->first)
568                           continue;
569                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
570                           continue;
571                       else if (it->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.",it->first->getClientID(),partyColours_[piggy]);
575                           else
576                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
577                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
578                       }
579                       else if (it->second==piggy)
580                       {
581                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]);
582                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
583                       }
584                       else if (it->second==killer)
585                       {
586                           this->gtinfo_->sendStaticMessage("Take the chasers down.",it->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(WeakPtr<Engine>* ptr)// helper function
601    {
602        if (*ptr)
603        {
604            (*ptr)->setSpeedFactor(1.0f);
605        }
606        delete ptr;
607    }
608
609    bool Dynamicmatch::playerChangedName(PlayerInfo* player) //standardfunction
610    {
611        bool valid_player = Gametype::playerChangedName(player);
612        if (valid_player)
613        {
614            const std::string& message = player->getOldName() + " changed name to " + player->getName();
615            COUT(0) << message << std::endl;
616            Host::Broadcast(message);
617        }
618
619        return valid_player;
620    }
621
622    void Dynamicmatch::start()
623    {
624        Gametype::start();
625        if(!tutorial)
626        {
627            std::string message("Dynamicmatch started!");
628            COUT(0) << message << std::endl;
629            Host::Broadcast(message);
630        }
631        else if(tutorial) // Announce selectionphase
632        {
633            for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
634            {
635                if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
636                    continue;
637                this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->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        COUT(0) << message << std::endl;
646        Host::Broadcast(message);
647        callInstructions_.setTimer(10, false, createExecutor(createFunctor(&Dynamicmatch::furtherInstructions, this)));
648    }
649
650    void Dynamicmatch::furtherInstructions()
651    {
652        std::string message("After 3 Minutes the game is over.");
653        COUT(0) << message << std::endl;
654        Host::Broadcast(message);
655    }*/
656    void Dynamicmatch::end()
657    {
658        Gametype::end();
659
660        std::string message("Time out. Press F2 to see the points you scored.");
661        COUT(0) << message << std::endl;
662        Host::Broadcast(message);
663    }
664    SpawnPoint* Dynamicmatch::getBestSpawnPoint(PlayerInfo* player) const
665    {
666        int desiredTeamNr = -1;
667        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
668        if (it_player != this->playerParty_.end())
669            desiredTeamNr = it_player->second;
670
671        // Only use spawnpoints of the own team (or non-team-spawnpoints)
672        std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_;
673        for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
674        {
675            if ((*it)->isA(Class(TeamSpawnPoint)))
676            {
677                TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it);
678                if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)//getTeamNumber!!
679                {
680                    teamSpawnPoints.erase(it++);
681                    continue;
682                }
683            }
684
685            ++it;
686        }
687
688        if (teamSpawnPoints.size() > 0)
689        {
690            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
691            unsigned int index = 0;
692            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
693            {
694                if (index == randomspawn)
695                    return (*it);
696
697                ++index;
698            }
699        }
700
701        return 0;
702    }
703
704}
Note: See TracBrowser for help on using the repository browser.