Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/SuperOrxoBros_HS18/src/orxonox/gametypes/TeamDeathmatch.cc @ 12175

Last change on this file since 12175 was 12175, checked in by siramesh, 5 years ago

Super Orxo Bros (Sidharth Ramesh, Nisa Balta, Jeff Ren)

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