Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/png/src/orxonox/controllers/HumanController.cc @ 7082

Last change on this file since 7082 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: 10.7 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 "HumanController.h"
30
31#include "core/CoreIncludes.h"
32#include "core/ConsoleCommand.h"
33#include "worldentities/ControllableEntity.h"
34#include "worldentities/pawns/Pawn.h"
35#include "gametypes/Gametype.h"
36#include "infos/PlayerInfo.h"
37#include "overlays/Map.h"
38#include "Radar.h"
39#include "Scene.h"
40
41namespace orxonox
42{
43    SetConsoleCommand(HumanController, moveFrontBack, true).setAsInputCommand();
44    SetConsoleCommand(HumanController, moveRightLeft, true).setAsInputCommand();
45    SetConsoleCommand(HumanController, moveUpDown,    true).setAsInputCommand();
46    SetConsoleCommand(HumanController, rotateYaw,     true).setAsInputCommand();
47    SetConsoleCommand(HumanController, rotatePitch,   true).setAsInputCommand();
48    SetConsoleCommand(HumanController, rotateRoll,    true).setAsInputCommand();
49    SetConsoleCommand(HumanController, fire,          true).keybindMode(KeybindMode::OnHold);
50    SetConsoleCommand(HumanController, reload,        true);
51    SetConsoleCommand(HumanController, boost,         true).keybindMode(KeybindMode::OnHold);
52    SetConsoleCommand(HumanController, greet,         true);
53    SetConsoleCommand(HumanController, switchCamera,  true);
54    SetConsoleCommand(HumanController, mouseLook,     true);
55    SetConsoleCommand(HumanController, suicide,       true);
56    SetConsoleCommand(HumanController, toggleGodMode, true);
57    SetConsoleCommand(HumanController, addBots,       true).defaultValues(1);
58    SetConsoleCommand(HumanController, killBots,      true).defaultValues(0);
59    SetConsoleCommand(HumanController, dropItems,     true);
60    SetConsoleCommand(HumanController, useItem,       true);
61    SetConsoleCommand(HumanController, cycleNavigationFocus,   true);
62    SetConsoleCommand(HumanController, releaseNavigationFocus, true);
63
64    CreateUnloadableFactory(HumanController);
65
66    HumanController* HumanController::localController_s = 0;
67
68    HumanController::HumanController(BaseObject* creator) : Controller(creator)
69    {
70        RegisterObject(HumanController);
71
72        controlPaused_ = false;
73
74        HumanController::localController_s = this;
75    }
76
77    HumanController::~HumanController()
78    {
79        HumanController::localController_s = 0;
80    }
81
82    void HumanController::tick(float dt)
83    {
84        if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_)
85        {
86            Camera* camera = HumanController::localController_s->controllableEntity_->getCamera();
87            if (!camera)
88                COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
89        }
90    }
91
92    void HumanController::moveFrontBack(const Vector2& value)
93    {
94        if (HumanController::localController_s)
95            HumanController::localController_s->frontback(value);
96    }
97
98    void HumanController::frontback(const Vector2& value)
99    {
100        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
101            HumanController::localController_s->controllableEntity_->moveFrontBack(value);
102    }
103
104    void HumanController::moveRightLeft(const Vector2& value)
105    {
106        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
107            HumanController::localController_s->controllableEntity_->moveRightLeft(value);
108    }
109
110    void HumanController::moveUpDown(const Vector2& value)
111    {
112        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
113            HumanController::localController_s->controllableEntity_->moveUpDown(value);
114    }
115
116    void HumanController::yaw(const Vector2& value)
117    {
118        //Hack to enable mouselook in map
119        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
120        {
121            Map::getSingletonPtr()->rotateYaw(value);
122            return;
123        }
124        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
125            HumanController::localController_s->controllableEntity_->rotateYaw(value);
126    }
127
128    void HumanController::pitch(const Vector2& value)
129    {
130        //Hack to enable mouselook in map
131        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
132        {
133            Map::getSingletonPtr()->rotatePitch(value);
134            return;
135        }
136        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
137            HumanController::localController_s->controllableEntity_->rotatePitch(value);
138    }
139
140    void HumanController::rotateYaw(const Vector2& value)
141    {
142        if (HumanController::localController_s)
143            HumanController::localController_s->yaw(value);
144    }
145
146    void HumanController::rotatePitch(const Vector2& value)
147    {
148        if (HumanController::localController_s)
149            HumanController::localController_s->pitch(value);
150    }
151
152    void HumanController::rotateRoll(const Vector2& value)
153    {
154        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
155            HumanController::localController_s->controllableEntity_->rotateRoll(value);
156    }
157
158    void HumanController::fire(unsigned int firemode)
159    {
160        if (HumanController::localController_s)
161            HumanController::localController_s->doFire(firemode);
162    }
163
164    void HumanController::doFire(unsigned int firemode)
165    {
166        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
167            HumanController::localController_s->controllableEntity_->fire(firemode);
168    }
169
170    void HumanController::reload()
171    {
172        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
173            HumanController::localController_s->controllableEntity_->reload();
174    }
175
176    void HumanController::boost()
177    {
178        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
179            HumanController::localController_s->controllableEntity_->boost();
180    }
181
182    void HumanController::greet()
183    {
184        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
185            HumanController::localController_s->controllableEntity_->greet();
186    }
187
188    void HumanController::switchCamera()
189    {
190        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
191            HumanController::localController_s->controllableEntity_->switchCamera();
192    }
193
194    void HumanController::mouseLook()
195    {
196        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
197            HumanController::localController_s->controllableEntity_->mouseLook();
198    }
199
200    void HumanController::suicide()
201    {
202        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
203        {
204            Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
205            if (pawn)
206                pawn->kill();
207            else if (HumanController::localController_s->player_)
208                HumanController::localController_s->player_->stopControl();
209        }
210    }
211
212    void HumanController::toggleGodMode()
213    {
214        HumanController::getLocalControllerSingleton()->setGodMode( !HumanController::getLocalControllerSingleton()->getGodMode() );
215    }
216
217    void HumanController::useItem()
218    {
219        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
220            HumanController::localController_s->controllableEntity_->useItem();
221    }
222
223    void HumanController::addBots(unsigned int amount)
224    {
225        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
226            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
227    }
228
229    void HumanController::killBots(unsigned int amount)
230    {
231        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
232            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
233    }
234
235    void HumanController::dropItems()
236    {
237        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
238            HumanController::localController_s->controllableEntity_->dropItems();
239    }
240
241    Pawn* HumanController::getLocalControllerEntityAsPawn()
242    {
243        if (HumanController::localController_s)
244            return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity());
245        else
246            return NULL;
247    }
248
249    void HumanController::cycleNavigationFocus()
250    {
251        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
252            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
253    }
254
255    void HumanController::releaseNavigationFocus()
256    {
257        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
258            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
259    }
260
261    void HumanController::pauseControl()
262    {
263        if (HumanController::localController_s)
264            HumanController::localController_s->doPauseControl();
265    }
266
267    void HumanController::resumeControl()
268    {
269        if (HumanController::localController_s)
270            HumanController::localController_s->doResumeControl();
271    }
272}
Note: See TracBrowser for help on using the repository browser.