Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7062 was 7062, checked in by jo, 14 years ago

coloured messages, different spaceships in one level, with bug

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