Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Merged unity_build branch back to trunk.

Features:

  • Implemented fully automatic build units to speed up compilation if requested
  • Added DOUT macro for quick debug output
  • Activated text colouring in the POSIX IOConsole
  • DeclareToluaInterface is not necessary anymore

Improvements:

  • Output levels now change appropriately when switch back and forth from dev mode
  • Log level for the file output is now also correct during startup
  • Removed some header file dependencies in core and tools to speed up compilation

no more file for command line options

  • Improved util::tribool by adapting some concepts from boost::tribool

Regressions:

  • It is not possible anymore to specify command line arguments in an extra file because we've got config values for that purpose.
  • Property svn:eol-style set to native
File size: 30.2 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                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 = dynamic_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                std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
279                if (it != this->players_.end())
280                    {
281                        it->second.frags_--;
282                    }
283            }
284        }// from far far away not to be removed!
285        return false; //default: no damage
286    }
287
288
289
290    bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator)
291    {
292        //killers can kill chasers and killers can be killed by chasers
293        if ((playerParty_[originator->getPlayer()] == killer && playerParty_[victim->getPlayer()] == chaser)||(playerParty_[victim->getPlayer()] == killer &&
294        playerParty_[originator->getPlayer()] == chaser ))
295        {
296            if (playerParty_[originator->getPlayer()] == killer) //reward the killer
297            {
298                std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
299                if (it != this->players_.end())
300                {
301                    it->second.frags_+=20; //value must be tested
302                }
303            }
304        return true;
305        }
306        else return false;
307    }
308
309    /**
310    @brief
311        Grant the piggy a boost.
312    @param spaceship
313        The SpaceShip to give the boost.
314    */
315    void Dynamicmatch::grantPigBoost(SpaceShip* spaceship)
316    {
317        // Give pig boost
318        if (spaceship)
319        {
320            spaceship->addSpeedFactor(5);
321            WeakPtr<SpaceShip>* ptr = new WeakPtr<SpaceShip>(spaceship);
322            ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
323            executor->setDefaultValue(0, ptr);
324            new Timer(10, false, executor, true);
325        }
326    }
327
328    void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring
329    {
330        if (!player)
331            return;
332
333        Dynamicmatch::setPlayerColour(player); //Set playercolour
334        evaluatePlayerParties();
335    }
336
337    void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction
338    {
339        if (!player)// only for safety
340            return;
341        playerParty_[player]=chaser; //Set playerparty
342        numberOf[chaser]++;
343        Gametype::playerEntered(player);
344        const std::string& message6 = player->getName() + " entered the game";
345        COUT(0) << message6 << std::endl;
346        Host::Broadcast(message6);
347    }
348
349    bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction
350    {
351        bool valid_player = Gametype::playerLeft(player);
352        if (valid_player)
353        {
354            switch (playerParty_[player])
355            {
356            case 0: numberOf[chaser]--; break;
357            case 1: numberOf[piggy]--; break;
358            case 2: numberOf[killer]--; break;
359            }
360            const std::string& message = player->getName() + " left the game";
361            COUT(0) << message << std::endl;
362            Host::Broadcast(message);
363            //remove player from map
364            playerParty_.erase (player);
365            //adjust player parties
366            evaluatePlayerParties();
367        }
368
369        return valid_player;
370    }
371
372
373    void Dynamicmatch::tick(float dt)
374    {
375        SUPER(Dynamicmatch, tick, dt);
376
377        if (this->hasStarted() && !gameEnded_)
378        {   pointsPerTime =pointsPerTime + dt;
379            gameTime_ = gameTime_ - dt;
380            if (pointsPerTime > 2.0f)//hard coded!! should be changed
381            {
382                pointsPerTime=0.0f;
383                rewardPig();
384            }
385            if (gameTime_<= 0)
386            {
387                this->gameEnded_ = true;
388                this->end();
389            }
390            if ( gameTime_ <= timesequence_ && gameTime_ > 0)
391            {
392                const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
393
394                this->gtinfo_->sendAnnounceMessage(message);
395
396                if (timesequence_ >= 30 && timesequence_ <= 60)
397                {
398                    timesequence_ = timesequence_ - 10;
399                }
400                else if (timesequence_ <= 30)
401                {
402                    timesequence_ = timesequence_ - 5;
403                }
404                else
405                {
406                    timesequence_ = timesequence_ - 30;
407                }
408            }
409        }
410    }
411
412    void Dynamicmatch::rewardPig()
413    {
414        for (std::map< PlayerInfo*, int >::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) //durch alle Spieler iterieren und alle piggys finden
415        {
416            if (it->second==piggy)
417            {
418                 //Spieler mit der Pig-party frags++
419                 std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(it->first);// still not sure if right syntax
420                 if (it2 != this->players_.end())
421                 {
422                     it2->second.frags_++;
423                 }
424            }
425        }
426    }
427    void Dynamicmatch::setPlayerColour(PlayerInfo* player) // sets a player's colour
428    {
429        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
430        Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity());
431            if (pawn)
432            {
433                pawn->setRadarObjectColour(this->partyColours_[it_player->second]);
434
435                std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
436                for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
437                {
438                    if ((*it)->isA(Class(TeamColourable)))
439                    {
440                        TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
441                        tc->setTeamColour(this->partyColours_[it_player->second]);
442                    }
443                }
444            }
445    }
446
447    void Dynamicmatch::evaluatePlayerParties() //manages the notEnough booleans (here the percentage of special players is implemented)
448    {
449        //pigs: 1 + every 6th player is a pig
450        if ( (1+this->getNumberOfPlayers()/6) > numberOf[piggy])
451        {
452            notEnoughPigs=true;
453            if (tutorial) // Announce selectionphase
454            {
455             for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
456                {
457                    if (!it->first)//in order to catch nullpointer
458                        continue;
459                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
460                        continue;
461                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
462                }
463            }
464        }
465        else
466        {
467             notEnoughPigs=false;
468             if(tutorial&&(!notEnoughKillers)&&(!notEnoughChasers)) //Selection phase over
469             {
470                  for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
471                  {
472                       if (!it->first)//in order to catch nullpointer
473                           continue;
474                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
475                           continue;
476                       else if (it->second==chaser)
477                       {
478                           if (numberOf[killer]>0)
479                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]);
480                           else
481                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
482                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
483                       }
484                       else if (it->second==piggy)
485                       {
486                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]);
487                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
488                       }
489                       else if (it->second==killer)
490                       {
491                           this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[chaser]);
492                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
493                       }
494                  }
495
496             }
497        }
498        //killers: every 4th player is a killer
499        if (getNumberOfPlayers()/4 > numberOf[killer])
500        {
501            notEnoughKillers=true;
502            if (tutorial) // Announce selectionphase
503            {
504             for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
505                {
506                    if (!it->first)//in order to catch nullpointer
507                        continue;
508                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
509                        continue;
510                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
511                }
512            }
513        }
514        else
515        {
516            notEnoughKillers=false;
517            if(tutorial&&(!notEnoughPigs)&&(!notEnoughChasers)) //Selection phase over
518             {
519                  for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
520                  {
521                       if (!it->first)
522                           continue;
523                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
524                           continue;
525                       else if (it->second==chaser)
526                       {
527                           if (numberOf[killer]>0)
528                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]);
529                           else
530                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
531                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
532                       }
533                       else if (it->second==piggy)
534                       {
535                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[piggy]);
536                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
537                       }
538                       else if (it->second==killer)
539                       {
540                           this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[piggy]);
541                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
542                       }
543                  }
544
545             }
546
547        }
548        //chasers: there are more chasers than killers + pigs
549        if (numberOf[piggy]+numberOf[killer] > numberOf[chaser])
550        {
551            notEnoughChasers=true;
552            if (tutorial) // Announce selectionphase
553            {
554             for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
555                {
556                    if (!it->first)//in order to catch nullpointer
557                        continue;
558                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
559                        continue;
560                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
561                }
562            }
563        }
564        else
565        {
566             notEnoughChasers=false;
567             if(tutorial&&(!notEnoughPigs)&&(!notEnoughKillers)) //Selection phase over
568             {
569                  for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
570                  {
571                       if (!it->first)
572                           continue;
573                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
574                           continue;
575                       else if (it->second==chaser)
576                       {
577                           if (numberOf[killer]>0)
578                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]);
579                           else
580                               this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]);
581                           //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID());
582                       }
583                       else if (it->second==piggy)
584                       {
585                           this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]);
586                           //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID());
587                       }
588                       else if (it->second==killer)
589                       {
590                           this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[chaser]);
591                           //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID());
592                       }
593                  }
594
595             }
596        }
597    }
598
599    int Dynamicmatch::getParty(PlayerInfo* player) // helper function for ArtificialController
600    {
601        return this->playerParty_[player];
602    }
603
604    void Dynamicmatch::resetSpeedFactor(WeakPtr<SpaceShip>* ptr)// helper function
605    {
606        if (*ptr)
607        {
608            (*ptr)->addSpeedFactor(1.0f/5.0f);
609        }
610        delete ptr;
611    }
612
613    bool Dynamicmatch::playerChangedName(PlayerInfo* player) //standardfunction
614    {
615        bool valid_player = Gametype::playerChangedName(player);
616        if (valid_player)
617        {
618            const std::string& message = player->getOldName() + " changed name to " + player->getName();
619            COUT(0) << message << std::endl;
620            Host::Broadcast(message);
621        }
622
623        return valid_player;
624    }
625
626    void Dynamicmatch::start()
627    {
628        Gametype::start();
629        if(!tutorial)
630        {
631            std::string message("Dynamicmatch started!");
632            COUT(0) << message << std::endl;
633            Host::Broadcast(message);
634        }
635        else if(tutorial) // Announce selectionphase
636        {
637            for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
638            {
639                if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
640                    continue;
641                this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
642            }
643        }
644    }
645
646    /*void Dynamicmatch::instructions()
647    {
648        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!");
649        COUT(0) << message << std::endl;
650        Host::Broadcast(message);
651        callInstructions_.setTimer(10, false, createExecutor(createFunctor(&Dynamicmatch::furtherInstructions, this)));
652    }
653
654    void Dynamicmatch::furtherInstructions()
655    {
656        std::string message("After 3 Minutes the game is over.");
657        COUT(0) << message << std::endl;
658        Host::Broadcast(message);
659    }*/
660    void Dynamicmatch::end()
661    {
662        Gametype::end();
663
664        std::string message("Time out. Press F2 to see the points you scored.");
665        COUT(0) << message << std::endl;
666        Host::Broadcast(message);
667    }
668    SpawnPoint* Dynamicmatch::getBestSpawnPoint(PlayerInfo* player) const
669    {
670        int desiredTeamNr = -1;
671        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
672        if (it_player != this->playerParty_.end())
673            desiredTeamNr = it_player->second;
674
675        // Only use spawnpoints of the own team (or non-team-spawnpoints)
676        std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_;
677        for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
678        {
679            if ((*it)->isA(Class(TeamSpawnPoint)))
680            {
681                TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it);
682                if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)//getTeamNumber!!
683                {
684                    teamSpawnPoints.erase(it++);
685                    continue;
686                }
687            }
688
689            ++it;
690        }
691
692        if (teamSpawnPoints.size() > 0)
693        {
694            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
695            unsigned int index = 0;
696            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
697            {
698                if (index == randomspawn)
699                    return (*it);
700
701                ++index;
702            }
703        }
704
705        return 0;
706    }
707
708}
Note: See TracBrowser for help on using the repository browser.