Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/gametypes/UnderAttack.cc @ 5829

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

replaced most occurrences of setObject(o) in combination with createFunctor(f) with the more convenient createFunctor(f, o)

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