Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

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