Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 6.7 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"
[9667]33#include "core/config/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{
[9941]40    const int attacker_ = 0; // teamnumber of the attacking team
41    const int defender_ = 1; // defender's teamnumber
42
[9667]43    RegisterUnloadableClass(UnderAttack);
[2933]44
[9667]45    UnderAttack::UnderAttack(Context* context) : TeamDeathmatch(context)
[2933]46    {
47        RegisterObject(UnderAttack);
[3057]48        this->gameTime_ = 180;
[2933]49        this->teams_ = 2;
[11071]50        this->destroyer_ = nullptr;
[5929]51        this->destroyer_.setCallback(createFunctor(&UnderAttack::killedDestroyer, this));
[2933]52        this->gameEnded_ = false;
53
54        this->setConfigValues();
[3301]55        this->timesequence_ = static_cast<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
[5929]69    void UnderAttack::killedDestroyer()
[2933]70    {
[5929]71        this->end(); //end gametype
[6417]72        std::string message("Ship destroyed! Team 0 has won!");
[8858]73        ChatManager::message(message);
[5929]74        this->gameEnded_ = true;
75
[11071]76        for (const auto& mapEntry : this->teamnumbers_)
[2933]77        {
[11071]78            if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[5929]79                continue;
[3099]80
[11071]81            if (mapEntry.second == attacker_)
82                this->gtinfo_->sendAnnounceMessage("You have won the match!", mapEntry.first->getClientID());
[5929]83            else
[11071]84                this->gtinfo_->sendAnnounceMessage("You have lost the match!", mapEntry.first->getClientID());
[2933]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    }
[2971]141
142
[2933]143    void UnderAttack::tick(float dt)
144    {
[2935]145        SUPER(UnderAttack, tick, dt);
146
[2971]147        if (this->hasStarted() && !gameEnded_)
[2933]148        {
[2935]149            gameTime_ = gameTime_ - dt;
[2971]150            if (gameTime_<= 0)
[2935]151            {
[2971]152                this->gameEnded_ = true;
[2952]153                this->end();
[6417]154                std::string message("Time is up! Team 1 has won!");
[8858]155                ChatManager::message(message);
[3099]156
[11071]157                for (const auto& mapEntry : this->teamnumbers_)
[3099]158                {
[11071]159                    if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
[3099]160                        continue;
161
[11071]162                    if (mapEntry.second == 1)
163                        this->gtinfo_->sendAnnounceMessage("You have won the match!", mapEntry.first->getClientID());
[3099]164                    else
[11071]165                        this->gtinfo_->sendAnnounceMessage("You have lost the match!", mapEntry.first->getClientID());
[3099]166                }
[2935]167            }
[2971]168
169             //prints gametime
[3099]170            if ( gameTime_ <= timesequence_ && gameTime_ > 0)
[2971]171            {
[6417]172                const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
[3099]173/*
[8858]174                ChatManager::message(message);
[3099]175*/
[5929]176                this->gtinfo_->sendAnnounceMessage(message);
[3099]177
[2971]178                if (timesequence_ >= 30 && timesequence_ <= 60)
179                {
180                    timesequence_ = timesequence_ - 10;
181                }
182                else if (timesequence_ <= 30)
183                {
184                    timesequence_ = timesequence_ - 5;
185                }
186                else
187                {
188                    timesequence_ = timesequence_ - 30;
189                }
190            }
[2933]191        }
192    }
[9941]193
194    void UnderAttack::playerEntered(PlayerInfo* player)
195    {
196        if (!player)
197            return;
198        TeamDeathmatch::playerEntered(player);
199        this->setTransporterHealth();
200    }
201
202    void UnderAttack::setTransporterHealth()
203    {
[11071]204        if (this->destroyer_ != nullptr)
[9941]205        {
206            //Calculation: Each attacker deals about 3500 damage. A human attacker deals 1500 damage additionally.
207            //Each defender prevents 500 damage. If human 2000 damage will be additionally be prevented.
208            //TODO: use gametime and the damage dealt so far in order to calculate the transporter's life more precisely
209            float health = this->getTeamSize(attacker_)*2000.0f + this->getHumansInTeam(attacker_)*3000.0f - this->getTeamSize(defender_)*500.0f - this->getHumansInTeam(defender_)*2000.0f ;
210            this->destroyer_->setHealth(std::max(health, 5000.0f)); //the destoyer should have at least 5000.0f life.
211        }
212    }
213
214
[2933]215}
Note: See TracBrowser for help on using the repository browser.