Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8706 was 8706, checked in by dafrick, 13 years ago

Merging presentation branch back into trunk.
There are many new features and also a lot of other changes and bugfixes, if you want to know, digg through the svn log.
Not everything is yet working as it should, but it should be fairly stable. If you habe any bug reports, just send me an email.

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