Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/map/src/orxonox/worldentities/pawns/Spectator.cc @ 12037

Last change on this file since 12037 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • Property svn:eol-style set to native
File size: 5.8 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 "Spectator.h"
30
31#include "core/CoreIncludes.h"
32#include "core/ConfigValueIncludes.h"
33#include "core/GameMode.h"
34
35#include "tools/BillboardSet.h"
36#include "Scene.h"
37#include "infos/PlayerInfo.h"
38
39namespace orxonox
40{
41    CreateFactory(Spectator);
42
43    Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
44    {
45        RegisterObject(Spectator);
46
47        this->speed_ = 200;
48
49        this->yaw_ = 0;
50        this->pitch_ = 0;
51        this->roll_ = 0;
52        this->localVelocity_ = Vector3::ZERO;
53        this->setHudTemplate("spectatorhud");
54        this->greetingFlare_ = 0;
55
56        this->setDestroyWhenPlayerLeft(true);
57
58        if (GameMode::showsGraphics())
59        {
60            this->greetingFlare_ = new BillboardSet();
61            this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0f, 1.0f, 0.8f), Vector3(0, 20, 0), 1);
62            if (this->greetingFlare_->getBillboardSet())
63                this->attachOgreObject(this->greetingFlare_->getBillboardSet());
64            this->greetingFlare_->setVisible(false);
65        }
66
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->detachOgreObject(this->greetingFlare_->getBillboardSet());
82
83                delete this->greetingFlare_;
84            }
85        }
86    }
87
88    void Spectator::setConfigValues()
89    {
90        SetConfigValue(speed_, 200.0f);
91    }
92
93    void Spectator::registerVariables()
94    {
95        registerVariable(this->bGreetingFlareVisible_, VariableDirection::ToClient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
96        registerVariable(this->bGreeting_,             VariableDirection::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        if (this->greetingFlare_)
108            this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
109    }
110
111    void Spectator::tick(float dt)
112    {
113        if (this->hasLocalController())
114        {
115            float localSpeedSquared = this->localVelocity_.squaredLength();
116            float localSpeed;
117            if (localSpeedSquared > 1.0)
118                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
119            else
120                localSpeed = this->speed_;
121
122            this->localVelocity_.x *= localSpeed;
123            this->localVelocity_.y *= localSpeed;
124            this->localVelocity_.z *= localSpeed;
125            this->setVelocity(this->getOrientation() * this->localVelocity_);
126            this->localVelocity_.x = 0;
127            this->localVelocity_.y = 0;
128            this->localVelocity_.z = 0;
129
130            if (!this->isInMouseLook())
131            {
132                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()));
133                this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
134                this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
135            }
136
137            this->yaw_ = this->pitch_ = this->roll_ = 0;
138        }
139
140        SUPER(Spectator, tick, dt);
141    }
142
143    void Spectator::setPlayer(PlayerInfo* player)
144    {
145        ControllableEntity::setPlayer(player);
146
147//        this->setSyncMode(ObjectDirection::ToClient);
148    }
149
150    void Spectator::startLocalHumanControl()
151    {
152        ControllableEntity::startLocalHumanControl();
153    }
154
155    void Spectator::moveFrontBack(const Vector2& value)
156    {
157        this->localVelocity_.z -= value.x;
158    }
159
160    void Spectator::moveRightLeft(const Vector2& value)
161    {
162        this->localVelocity_.x += value.x;
163    }
164
165    void Spectator::moveUpDown(const Vector2& value)
166    {
167        this->localVelocity_.y += value.x;
168    }
169
170    void Spectator::rotateYaw(const Vector2& value)
171    {
172        this->yaw_ += value.y;
173
174        ControllableEntity::rotateYaw(value);
175    }
176
177    void Spectator::rotatePitch(const Vector2& value)
178    {
179        this->pitch_ += value.y;
180
181        ControllableEntity::rotatePitch(value);
182    }
183
184    void Spectator::rotateRoll(const Vector2& value)
185    {
186        this->roll_ += value.y;
187
188        ControllableEntity::rotateRoll(value);
189    }
190
191    void Spectator::fired(unsigned int firemode)
192    {
193        if (this->getPlayer())
194            this->getPlayer()->setReadyToSpawn(true);
195    }
196
197    void Spectator::greet()
198    {
199        this->bGreeting_ = !this->bGreeting_;
200
201        if (GameMode::isMaster())
202        {
203            this->bGreetingFlareVisible_ = this->bGreeting_;
204            this->changedFlareVisibility();
205        }
206    }
207}
Note: See TracBrowser for help on using the repository browser.