Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9019 was 9016, checked in by jo, 12 years ago

Merging presentation2011 branch to trunk. Please check for possible bugs.

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