Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/orxonox/gametypes/Dynamicmatch.cc @ 7076

Last change on this file since 7076 was 7076, checked in by landauf, 14 years ago

removed some tabs in Dynamicmatch and ScreenshotManager

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