Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/orxonox/controllers/HumanController.cc @ 6191

Last change on this file since 6191 was 6191, checked in by rgrieder, 14 years ago

Moved sound listener to the active camera and fixed the ambient distance trigger (now acts on cameras and we only have one in a Scene so far).

  • Property svn:eol-style set to native
File size: 10.1 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, addBots,       true).defaultValues(1);
57    SetConsoleCommand(HumanController, killBots,      true).defaultValues(0);
58    SetConsoleCommand(HumanController, dropItems,     true);
59    SetConsoleCommand(HumanController, useItem,       true);
60    SetConsoleCommand(HumanController, cycleNavigationFocus,   true);
61    SetConsoleCommand(HumanController, releaseNavigationFocus, true);
62
63    CreateUnloadableFactory(HumanController);
64
65    HumanController* HumanController::localController_s = 0;
66
67    HumanController::HumanController(BaseObject* creator) : Controller(creator)
68    {
69        RegisterObject(HumanController);
70
71        HumanController::localController_s = this;
72    }
73
74    HumanController::~HumanController()
75    {
76        HumanController::localController_s = 0;
77    }
78
79    void HumanController::tick(float dt)
80    {
81        if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_)
82        {
83            Camera* camera = HumanController::localController_s->controllableEntity_->getCamera();
84            if (!camera)
85                COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
86        }
87    }
88
89    void HumanController::moveFrontBack(const Vector2& value)
90    {
91        if (HumanController::localController_s)
92            HumanController::localController_s->frontback(value);
93    }
94
95    void HumanController::frontback(const Vector2& value)
96    {
97        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
98            HumanController::localController_s->controllableEntity_->moveFrontBack(value);
99    }
100
101    void HumanController::moveRightLeft(const Vector2& value)
102    {
103        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
104            HumanController::localController_s->controllableEntity_->moveRightLeft(value);
105    }
106
107    void HumanController::moveUpDown(const Vector2& value)
108    {
109        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
110            HumanController::localController_s->controllableEntity_->moveUpDown(value);
111    }
112
113    void HumanController::yaw(const Vector2& value)
114    {
115        //Hack to enable mouselook in map
116        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
117        {
118            Map::getSingletonPtr()->rotateYaw(value);
119            return;
120        }
121        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
122            HumanController::localController_s->controllableEntity_->rotateYaw(value);
123    }
124
125    void HumanController::pitch(const Vector2& value)
126    {
127        //Hack to enable mouselook in map
128        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
129        {
130            Map::getSingletonPtr()->rotatePitch(value);
131            return;
132        }
133        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
134            HumanController::localController_s->controllableEntity_->rotatePitch(value);
135    }
136
137    void HumanController::rotateYaw(const Vector2& value)
138    {
139        if (HumanController::localController_s)
140            HumanController::localController_s->yaw(value);
141    }
142
143    void HumanController::rotatePitch(const Vector2& value)
144    {
145        if (HumanController::localController_s)
146            HumanController::localController_s->pitch(value);
147    }
148
149    void HumanController::rotateRoll(const Vector2& value)
150    {
151        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
152            HumanController::localController_s->controllableEntity_->rotateRoll(value);
153    }
154
155    void HumanController::fire(unsigned int firemode)
156    {
157        if (HumanController::localController_s)
158            HumanController::localController_s->doFire(firemode);
159    }
160
161    void HumanController::doFire(unsigned int firemode)
162    {
163        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
164            HumanController::localController_s->controllableEntity_->fire(firemode);
165    }
166
167    void HumanController::reload()
168    {
169        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
170            HumanController::localController_s->controllableEntity_->reload();
171    }
172
173    void HumanController::boost()
174    {
175        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
176            HumanController::localController_s->controllableEntity_->boost();
177    }
178
179    void HumanController::greet()
180    {
181        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
182            HumanController::localController_s->controllableEntity_->greet();
183    }
184
185    void HumanController::switchCamera()
186    {
187        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
188            HumanController::localController_s->controllableEntity_->switchCamera();
189    }
190
191    void HumanController::mouseLook()
192    {
193        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
194            HumanController::localController_s->controllableEntity_->mouseLook();
195    }
196
197    void HumanController::suicide()
198    {
199        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
200        {
201            Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
202            if (pawn)
203                pawn->kill();
204            else if (HumanController::localController_s->player_)
205                HumanController::localController_s->player_->stopControl();
206        }
207    }
208
209    void HumanController::useItem()
210    {
211        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
212            HumanController::localController_s->controllableEntity_->useItem();
213    }
214
215    void HumanController::addBots(unsigned int amount)
216    {
217        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
218            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
219    }
220
221    void HumanController::killBots(unsigned int amount)
222    {
223        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
224            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
225    }
226
227    void HumanController::dropItems()
228    {
229        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
230            HumanController::localController_s->controllableEntity_->dropItems();
231    }
232
233    Pawn* HumanController::getLocalControllerEntityAsPawn()
234    {
235        if (HumanController::localController_s)
236            return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity());
237        else
238            return NULL;
239    }
240
241    void HumanController::cycleNavigationFocus()
242    {
243        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
244            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
245    }
246
247    void HumanController::releaseNavigationFocus()
248    {
249        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
250            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
251    }
252}
Note: See TracBrowser for help on using the repository browser.