Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc @ 11071

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 4.3 KB
RevLine 
[2825]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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "TeamDeathmatch.h"
30
31#include "core/CoreIncludes.h"
[9348]32#include "chat/ChatManager.h"
33#include "infos/PlayerInfo.h"
[5735]34#include "worldentities/pawns/Pawn.h"
[9941]35#include "core/config/ConfigValueIncludes.h"
[2825]36
37namespace orxonox
38{
[9667]39    RegisterUnloadableClass(TeamDeathmatch);
[2825]40
[9667]41    TeamDeathmatch::TeamDeathmatch(Context* context) : TeamGametype(context)
[2825]42    {
43        RegisterObject(TeamDeathmatch);
[9941]44
45        this->setConfigValues();
[9348]46    }
[2825]47
[9941]48    void TeamDeathmatch::setConfigValues()
49    {
50        SetConfigValue(maxScore_, 10);
51    }
52
[9348]53    void TeamDeathmatch::start()
54    {
55        TeamGametype::start();
[2825]56
[9348]57        std::string message("The match has started!");
58        ChatManager::message(message);
[2825]59    }
60
[9348]61    void TeamDeathmatch::end()
[2825]62    {
[9348]63        TeamGametype::end();
[2825]64
[9348]65        std::string message("The match has ended.");
66        ChatManager::message(message);
[9941]67       
68        //find team that won the match
69        int winnerTeam = 0;
70        int highestScore = 0;
[11071]71        for (const auto& mapEntry : this->players_)
[9941]72        {
[11071]73            if ( this->getTeamScore(mapEntry.first) > highestScore )
[9941]74            {
[11071]75                winnerTeam = this->getTeam(mapEntry.first);
76                highestScore = this->getTeamScore(mapEntry.first);
[9941]77            }
78        }
79
80        //announce win
81        this->announceTeamWin(winnerTeam);
[2825]82    }
83
84    void TeamDeathmatch::playerEntered(PlayerInfo* player)
85    {
[9348]86        TeamGametype::playerEntered(player);
[2825]87
[9348]88        const std::string& message = player->getName() + " entered the game";
89        ChatManager::message(message);
[2825]90    }
91
92    bool TeamDeathmatch::playerLeft(PlayerInfo* player)
93    {
[9348]94        bool valid_player = TeamGametype::playerLeft(player);
[2825]95
96        if (valid_player)
[9348]97        {
98            const std::string& message = player->getName() + " left the game";
99            ChatManager::message(message);
100        }
[2825]101
102        return valid_player;
103    }
[9348]104    bool TeamDeathmatch::playerChangedName(PlayerInfo* player)
[2825]105    {
[9348]106        bool valid_player = TeamGametype::playerChangedName(player);
[2825]107
[9348]108        if (valid_player)
109        {
110            const std::string& message = player->getOldName() + " changed name to " + player->getName();
111            ChatManager::message(message);
112        }
[2825]113
[9348]114        return valid_player;
[2825]115    }
116
[9348]117    void TeamDeathmatch::pawnKilled(Pawn* victim, Pawn* killer)
[2825]118    {
[9348]119        if (victim && victim->getPlayer())
[2825]120        {
[9348]121            std::string message;
122            if (killer)
[2825]123            {
[9348]124                if (killer->getPlayer())
[9941]125                {
[9348]126                    message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
[9941]127                    if(this->isExactlyA(Class(TeamDeathmatch)) && (this->getTeamScore(killer->getPlayer()) >= (this->maxScore_ -1)) )
128                        this->end();
129                }
[9348]130                else
131                    message = victim->getPlayer()->getName() + " was killed";
[2825]132            }
[9348]133            else
134                message = victim->getPlayer()->getName() + " died";
[2825]135
[9348]136            ChatManager::message(message);
[2825]137        }
138
[9348]139        Gametype::pawnKilled(victim, killer);
[2825]140    }
141
[9348]142    void TeamDeathmatch::playerScored(PlayerInfo* player, int score)
[2825]143    {
[9348]144        TeamGametype::playerScored(player, score);
[2825]145
[9348]146        if (player)
[2825]147        {
[9348]148            const std::string& message = player->getName() + " scores!";
149            ChatManager::message(message);
[2825]150        }
151    }
152
153}
Note: See TracBrowser for help on using the repository browser.