Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

With additional tutorial messages in order to explain how the gametype works

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