Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/gametypes/UnderAttack.cc @ 3104

Last change on this file since 3104 was 3104, checked in by landauf, 15 years ago

Added two new HUD-elements for TeamBaseMatch and UnderAttack

  • Property svn:eol-style set to native
File size: 5.9 KB
RevLine 
[2933]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:
[3020]23 *      Matthias Mock
[2933]24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "UnderAttack.h"
31
32#include "core/CoreIncludes.h"
33#include "core/ConfigValueIncludes.h"
[2971]34#include "util/Convert.h"
[3020]35#include "network/Host.h"
[2933]36
[3020]37#include "objects/worldentities/pawns/Destroyer.h"
[3099]38#include "objects/infos/PlayerInfo.h"
[3020]39
[2933]40namespace orxonox
41{
42    CreateUnloadableFactory(UnderAttack);
43
44    UnderAttack::UnderAttack(BaseObject* creator) : TeamDeathmatch(creator)
45    {
46        RegisterObject(UnderAttack);
[3057]47        this->gameTime_ = 180;
[2933]48        this->teams_ = 2;
49        this->destroyer_ = 0;
50        this->gameEnded_ = false;
51
[3104]52        this->setHUDTemplate("UnderAttackHUD");
53
[2933]54        this->setConfigValues();
[2971]55        this->timesequence_ = (int) this->gameTime_;
[2933]56    }
57
[2952]58    void UnderAttack::setConfigValues()
59    {
[3057]60        SetConfigValue(gameTime_, 180);
[2952]61    }
62
[2933]63    void UnderAttack::addDestroyer(Destroyer* destroyer)
64    {
65        this->destroyer_ = destroyer;
66    }
67
68
69    void UnderAttack::destroyedPawn(Pawn* pawn)
70    {
71        if (pawn == this->destroyer_)
72        {
[2952]73            this->end(); //end gametype
74            std::string message = "Ship destroyed! Team 0 has won!";
75            COUT(0) << message << std::endl;
76            Host::Broadcast(message);
[2971]77            this->gameEnded_ = true;
[3099]78
79            for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
80            {
81                if (it->first->getClientID() == CLIENTID_UNKNOWN)
82                    continue;
83
84                if (it->second == 0)
85                    this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
86                else
87                    this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
88            }
[2933]89        }
90    }
91
92    bool UnderAttack::allowPawnHit(Pawn* victim, Pawn* originator)
93    {
94        if (victim == this->destroyer_)
95        {
96            if (originator && originator->getPlayer() && !gameEnded_)
97            {
98                if (this->getTeam(originator->getPlayer()) == 0)
99                    return true;
100                else
101                    return false;
102            }
103
104            return false;
105        }
106
107        return TeamDeathmatch::allowPawnHit(victim, originator);
108    }
109
110    bool UnderAttack::allowPawnDamage(Pawn* victim, Pawn* originator)
111    {
112        if (victim == this->destroyer_)
113        {
114            if (originator && originator->getPlayer() && !gameEnded_)
115            {
116                if (this->getTeam(originator->getPlayer()) == 0)
117                    return true;
118                else
119                    return false;
120            }
121
122            return false;
123        }
124
125        return TeamDeathmatch::allowPawnDamage(victim, originator);
126    }
127
128    bool UnderAttack::allowPawnDeath(Pawn* victim, Pawn* originator)
129    {
130        if (victim == this->destroyer_)
131        {
132            if (originator && originator->getPlayer() && !gameEnded_)
133            {
134                if (this->getTeam(originator->getPlayer()) == 0)
135                    return true;
136                else
137                    return false;
138            }
139
140            return false;
141        }
142
143        return TeamDeathmatch::allowPawnDeath(victim, originator);
144    }
[2971]145
146
[2933]147    void UnderAttack::tick(float dt)
148    {
[2935]149        SUPER(UnderAttack, tick, dt);
150
[2971]151        if (this->hasStarted() && !gameEnded_)
[2933]152        {
[2935]153            gameTime_ = gameTime_ - dt;
[2971]154            if (gameTime_<= 0)
[2935]155            {
[2971]156                this->gameEnded_ = true;
[2952]157                this->end();
158                std::string message = "Time is up! Team 1 has won!";
159                COUT(0) << message << std::endl;
160                Host::Broadcast(message);
[3099]161
162                for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
163                {
164                    if (it->first->getClientID() == CLIENTID_UNKNOWN)
165                        continue;
166
167                    if (it->second == 1)
168                        this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
169                    else
170                        this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
171                }
[2935]172            }
[2971]173
174             //prints gametime
[3099]175            if ( gameTime_ <= timesequence_ && gameTime_ > 0)
[2971]176            {
[3099]177                std::string message = convertToString(timesequence_) + " seconds left!";
178/*
[2971]179                COUT(0) << message << std::endl;
180                Host::Broadcast(message);
[3099]181*/
182                this->gtinfo_.sendAnnounceMessage(message);
183
[2971]184                if (timesequence_ >= 30 && timesequence_ <= 60)
185                {
186                    timesequence_ = timesequence_ - 10;
187                }
188                else if (timesequence_ <= 30)
189                {
190                    timesequence_ = timesequence_ - 5;
191                }
192                else
193                {
194                    timesequence_ = timesequence_ - 30;
195                }
196            }
[2933]197        }
198    }
199}
Note: See TracBrowser for help on using the repository browser.