Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/overlays/hud/GametypeStatus.cc @ 8178

Last change on this file since 8178 was 8178, checked in by jo, 13 years ago

Merged lastmastanding3 into trunk. There's an xml parsing error that only appeared after merging. The level seems to load properly though.

  • Property svn:eol-style set to native
File size: 4.0 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "GametypeStatus.h"
30
31#include "util/Convert.h"
32#include "core/CoreIncludes.h"
33#include "core/command/ConsoleCommand.h"
34#include "infos/GametypeInfo.h"
35#include "infos/PlayerInfo.h"
36#include "worldentities/ControllableEntity.h"
37#include "worldentities/pawns/Spectator.h"
38//#include "gametypes/Gametype.h"
39
40namespace orxonox
41{
42    CreateFactory(GametypeStatus);
43
44    static const std::string __CC_GametypeStatus_name = "GametypeStatus";
45    static const std::string __CC_displayCaption_name = "displayCaption";
46
47    SetConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name, &GametypeStatus::setDisplayCaption);
48
49    GametypeStatus::GametypeStatus(BaseObject* creator) : OverlayText(creator)
50    {
51        RegisterObject(GametypeStatus);
52
53        //this->game_ = 0;
54        this->owner_ = 0;
55        this->bNoCaption_ = false;
56        //this->bForcedSpawn_ = false;
57
58        ModifyConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name).setObject(this);
59    }
60
61    GametypeStatus::~GametypeStatus()
62    {
63        ModifyConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name).setObject(0);
64    }
65
66    void GametypeStatus::tick(float dt)
67    {
68        SUPER(GametypeStatus, tick, dt);
69
70        if (this->owner_ && this->owner_->getGametypeInfo() && this->owner_->getControllableEntity())
71        {
72            //if (this->game_)
73            //    this->bForcedSpawn_ = this->game_->getForceSpawn();
74            //else
75            //    this->bForcedSpawn_ = false;
76
77            const GametypeInfo* gtinfo = this->owner_->getGametypeInfo();
78            ControllableEntity* ce = this->owner_->getControllableEntity();
79
80            if (this->bNoCaption_) // No captions are displayed.
81            {
82                this->setCaption("");
83                return;
84            }
85
86            if (!gtinfo->hasStarted() && !gtinfo->isStartCountdownRunning())
87            {
88                if (!this->owner_->isReadyToSpawn())
89                    this->setCaption("Press [Fire] to start the match");
90                else
91                    this->setCaption("Waiting for other players");
92            }
93            else if (!gtinfo->hasEnded())
94            {
95                if (gtinfo->isStartCountdownRunning())
96                    this->setCaption(multi_cast<std::string>(static_cast<int>(ceil(gtinfo->getStartCountdown()))));
97                else if (ce->isA(Class(Spectator))/*&&(!bForcedSpawn_)*/)
98                    this->setCaption("Press [Fire] to respawn");
99                else
100                    this->setCaption("");
101            }
102            else
103                this->setCaption("Game has ended");
104        }
105    }
106
107
108    void GametypeStatus::changedOwner()
109    {
110        SUPER(GametypeStatus, changedOwner);
111        //this->game_ = orxonox_cast<Gametype*>(this->getOwner());
112        this->owner_ = orxonox_cast<PlayerInfo*>(this->getOwner());
113    }
114
115    /**
116    @brief
117        Sets whether the gametype status is displayed.
118    @param bValue
119        If true captions are displayed, if false, not.
120    */
121    void GametypeStatus::setDisplayCaption(bool bValue)
122    {
123        this->bNoCaption_ = !bValue;
124    }
125
126}
Note: See TracBrowser for help on using the repository browser.