Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8727 was 8727, checked in by dafrick, 13 years ago

Cleaning up in SpaceShip and Engine. Fixed several bugs.
Kicked localLinearAcceleration, primaryThrust and auxiliaryThrust out of the SpaceShip, since it wasn't used anymore.
Moved the trail lights back a bit.
Added some documentation to SpaceShip and Engine.
SpeedPickup is working again, will need some further tuning.

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