Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged libraries2 back to trunk

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