Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc @ 2955

Last change on this file since 2955 was 2896, checked in by landauf, 16 years ago

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

  • Property svn:eol-style set to native
File size: 6.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 "OrxonoxStableHeaders.h"
30#include "Spectator.h"
31
32#include <OgreBillboardSet.h>
33
34#include "core/CoreIncludes.h"
35#include "core/ConfigValueIncludes.h"
36#include "core/GameMode.h"
37#include "objects/worldentities/Model.h"
38#include "objects/Scene.h"
39#include "objects/infos/PlayerInfo.h"
40#include "objects/gametypes/Gametype.h"
41#include "tools/BillboardSet.h"
42#include "overlays/OverlayText.h"
43#include "overlays/OverlayGroup.h"
44#include "util/Convert.h"
45
46namespace orxonox
47{
48    CreateFactory(Spectator);
49
50    Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
51    {
52        RegisterObject(Spectator);
53
54        this->speed_ = 200;
55
56        this->yaw_ = 0;
57        this->pitch_ = 0;
58        this->roll_ = 0;
59        this->localVelocity_ = Vector3::ZERO;
60        this->setHudTemplate("spectatorhud");
61        this->greetingFlare_ = 0;
62
63        this->setDestroyWhenPlayerLeft(true);
64
65        if (GameMode::showsGraphics())
66        {
67            this->greetingFlare_ = new BillboardSet();
68            this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
69            if (this->greetingFlare_->getBillboardSet())
70                this->attachOgreObject(this->greetingFlare_->getBillboardSet());
71            this->greetingFlare_->setVisible(false);
72        }
73
74        this->bGreetingFlareVisible_ = false;
75        this->bGreeting_ = false;
76
77        this->setConfigValues();
78        this->registerVariables();
79    }
80
81    Spectator::~Spectator()
82    {
83        if (this->isInitialized())
84        {
85            if (this->greetingFlare_)
86            {
87                if (this->greetingFlare_->getBillboardSet())
88                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
89
90                delete this->greetingFlare_;
91            }
92        }
93    }
94
95    void Spectator::setConfigValues()
96    {
97        SetConfigValue(speed_, 200.0f);
98    }
99
100    void Spectator::registerVariables()
101    {
102        registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
103        registerVariable(this->bGreeting_,             variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
104    }
105
106    void Spectator::changedGreeting()
107    {
108        this->bGreetingFlareVisible_ = this->bGreeting_;
109        this->changedFlareVisibility();
110    }
111
112    void Spectator::changedFlareVisibility()
113    {
114        if ( this->greetingFlare_ )
115            this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
116    }
117
118    void Spectator::tick(float dt)
119    {
120        if (this->hasLocalController())
121        {
122            float localSpeedSquared = this->localVelocity_.squaredLength();
123            float localSpeed;
124            if (localSpeedSquared > 1.0)
125                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
126            else
127                localSpeed = this->speed_;
128
129            this->localVelocity_.x *= localSpeed;
130            this->localVelocity_.y *= localSpeed;
131            this->localVelocity_.z *= localSpeed;
132            this->setVelocity(this->getOrientation() * this->localVelocity_);
133            this->localVelocity_.x = 0;
134            this->localVelocity_.y = 0;
135            this->localVelocity_.z = 0;
136
137            if (!this->isInMouseLook())
138            {
139                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()));
140                this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
141                this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
142            }
143
144            this->yaw_ = this->pitch_ = this->roll_ = 0;
145        }
146
147        SUPER(Spectator, tick, dt);
148    }
149
150    void Spectator::setPlayer(PlayerInfo* player)
151    {
152        ControllableEntity::setPlayer(player);
153
154//        this->setObjectMode(objectDirection::toclient);
155    }
156
157    void Spectator::startLocalHumanControl()
158    {
159        ControllableEntity::startLocalHumanControl();
160    }
161
162    void Spectator::moveFrontBack(const Vector2& value)
163    {
164        this->localVelocity_.z -= value.x;
165    }
166
167    void Spectator::moveRightLeft(const Vector2& value)
168    {
169        this->localVelocity_.x += value.x;
170    }
171
172    void Spectator::moveUpDown(const Vector2& value)
173    {
174        this->localVelocity_.y += value.x;
175    }
176
177    void Spectator::rotateYaw(const Vector2& value)
178    {
179        this->yaw_ -= value.y;
180
181        ControllableEntity::rotateYaw(value);
182    }
183
184    void Spectator::rotatePitch(const Vector2& value)
185    {
186        this->pitch_ += value.y;
187
188        ControllableEntity::rotatePitch(value);
189    }
190
191    void Spectator::rotateRoll(const Vector2& value)
192    {
193        this->roll_ += value.y;
194
195        ControllableEntity::rotateRoll(value);
196    }
197
198    void Spectator::fire(WeaponMode::Enum fireMode)
199    {
200        if (this->getPlayer())
201            this->getPlayer()->setReadyToSpawn(true);
202    }
203
204    void Spectator::greet()
205    {
206        this->bGreeting_ = !this->bGreeting_;
207
208        if (GameMode::isMaster())
209        {
210            this->bGreetingFlareVisible_ = this->bGreeting_;
211            this->changedFlareVisibility();
212        }
213    }
214}
Note: See TracBrowser for help on using the repository browser.