Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.cc @ 2428

Last change on this file since 2428 was 2428, checked in by landauf, 15 years ago
  • Moved some variables from Gametype to GametypeInfo (Gametype exists only on the Server while GametypeInfo is synchronized)
  • Created a new HUD-element, GametypeStatus, based on GametypeInfo (the same effect was formerly achieved by using a hack in Spectator and a TextOverlay)
  • HumanController creates a HUD (additionally to the SpaceShips HUD) which includes GametypeStatus and ChatOverlay and even more in the future
  • Property svn:eol-style set to native
File size: 5.4 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 "OrxonoxStableHeaders.h"
30#include "Spectator.h"
31
32#include "core/CoreIncludes.h"
33#include "core/ConfigValueIncludes.h"
34#include "core/Core.h"
35#include "objects/worldentities/Model.h"
36#include "objects/Scene.h"
37#include "objects/infos/PlayerInfo.h"
38#include "objects/gametypes/Gametype.h"
39#include "tools/BillboardSet.h"
40#include "overlays/OverlayText.h"
41#include "overlays/OverlayGroup.h"
42#include "util/Convert.h"
43
44namespace orxonox
45{
46    CreateFactory(Spectator);
47
48    Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
49    {
50        RegisterObject(Spectator);
51
52        this->speed_ = 200;
53        this->rotationSpeed_ = 3;
54
55        this->yaw_ = 0;
56        this->pitch_ = 0;
57        this->roll_ = 0;
58        this->setHudTemplate("spectatorhud");
59
60        this->setDestroyWhenPlayerLeft(true);
61
62        this->greetingFlare_ = new BillboardSet();
63        this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 0, 0), 1);
64        if (this->greetingFlare_->getBillboardSet())
65            this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
66        this->greetingFlare_->setVisible(false);
67        this->bGreetingFlareVisible_ = false;
68        this->bGreeting_ = false;
69
70        this->setConfigValues();
71        this->registerVariables();
72    }
73
74    Spectator::~Spectator()
75    {
76        if (this->isInitialized())
77        {
78            if (this->greetingFlare_)
79            {
80                if (this->greetingFlare_->getBillboardSet())
81                    this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
82                delete this->greetingFlare_;
83            }
84        }
85    }
86
87    void Spectator::setConfigValues()
88    {
89        SetConfigValue(speed_, 200.0f);
90        SetConfigValue(rotationSpeed_, 3.0f);
91    }
92
93    void Spectator::registerVariables()
94    {
95        REGISTERDATA(this->bGreetingFlareVisible_, direction::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
96        REGISTERDATA(this->bGreeting_,             direction::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
97    }
98
99    void Spectator::changedGreeting()
100    {
101        this->bGreetingFlareVisible_ = this->bGreeting_;
102        this->changedFlareVisibility();
103    }
104
105    void Spectator::changedFlareVisibility()
106    {
107        this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
108    }
109
110    void Spectator::tick(float dt)
111    {
112        if (this->hasLocalController())
113        {
114            Vector3 velocity = this->getVelocity();
115            velocity.normalise();
116            this->setVelocity(velocity * this->speed_);
117
118            this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
119            this->pitch(Radian(this->pitch_ * this->rotationSpeed_));
120            this->roll(Radian(this->roll_ * this->rotationSpeed_));
121
122            this->yaw_ = this->pitch_ = this->roll_ = 0;
123        }
124
125        SUPER(Spectator, tick, dt);
126
127        if (this->hasLocalController())
128        {
129            this->setVelocity(Vector3::ZERO);
130        }
131    }
132
133    void Spectator::setPlayer(PlayerInfo* player)
134    {
135        ControllableEntity::setPlayer(player);
136
137//        this->setObjectMode(direction::toclient);
138    }
139
140    void Spectator::startLocalHumanControl()
141    {
142        ControllableEntity::startLocalHumanControl();
143    }
144
145    void Spectator::moveFrontBack(const Vector2& value)
146    {
147        this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);
148    }
149
150    void Spectator::moveRightLeft(const Vector2& value)
151    {
152        this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);
153    }
154
155    void Spectator::moveUpDown(const Vector2& value)
156    {
157        this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);
158    }
159
160    void Spectator::rotateYaw(const Vector2& value)
161    {
162        this->yaw_ = value.y;
163    }
164
165    void Spectator::rotatePitch(const Vector2& value)
166    {
167        this->pitch_ = value.y;
168    }
169
170    void Spectator::rotateRoll(const Vector2& value)
171    {
172        this->roll_ = value.y;
173    }
174
175    void Spectator::fire()
176    {
177        if (this->getPlayer())
178            this->getPlayer()->setReadyToSpawn(true);
179    }
180
181    void Spectator::greet()
182    {
183        this->bGreeting_ = !this->bGreeting_;
184
185        if (Core::isMaster())
186        {
187            this->bGreetingFlareVisible_ = this->bGreeting_;
188            this->changedFlareVisibility();
189        }
190    }
191}
Note: See TracBrowser for help on using the repository browser.