Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.cc @ 6987

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

additional infomassages, improved level

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