Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7163 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

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