Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/controllers/HumanController.cc @ 7768

Last change on this file since 7768 was 7533, checked in by dafrick, 14 years ago

Documenting in pickups module.
Cleaning up in PickupManager.
Removed some obsolete functions in HumanController and ControllableEntity, which were remenants of the old pickups module.
Fixed a bug.

  • Property svn:eol-style set to native
File size: 10.5 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/command/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 "Radar.h"
38#include "Scene.h"
39
40namespace orxonox
41{
42    SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
43    SetConsoleCommand("HumanController", "moveRightLeft",          &HumanController::moveRightLeft ).addShortcut().setAsInputCommand();
44    SetConsoleCommand("HumanController", "moveUpDown",             &HumanController::moveUpDown    ).addShortcut().setAsInputCommand();
45    SetConsoleCommand("HumanController", "rotateYaw",              &HumanController::rotateYaw     ).addShortcut().setAsInputCommand();
46    SetConsoleCommand("HumanController", "rotatePitch",            &HumanController::rotatePitch   ).addShortcut().setAsInputCommand();
47    SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
48    SetConsoleCommand("HumanController", "fire",                   &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
49    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
50    SetConsoleCommand("HumanController", "boost",                  &HumanController::boost         ).addShortcut().keybindMode(KeybindMode::OnHold);
51    SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
52    SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
53    SetConsoleCommand("HumanController", "mouseLook",              &HumanController::mouseLook     ).addShortcut();
54    SetConsoleCommand("HumanController", "suicide",                &HumanController::suicide       ).addShortcut();
55    SetConsoleCommand("HumanController", "toggleGodMode",          &HumanController::toggleGodMode ).addShortcut();
56    SetConsoleCommand("HumanController", "addBots",                &HumanController::addBots       ).addShortcut().defaultValues(1);
57    SetConsoleCommand("HumanController", "killBots",               &HumanController::killBots      ).addShortcut().defaultValues(0);
58    SetConsoleCommand("HumanController", "cycleNavigationFocus",   &HumanController::cycleNavigationFocus).addShortcut();
59    SetConsoleCommand("HumanController", "releaseNavigationFocus", &HumanController::releaseNavigationFocus).addShortcut();
60
61    CreateUnloadableFactory(HumanController);
62
63    HumanController* HumanController::localController_s = 0;
64
65    HumanController::HumanController(BaseObject* creator) : Controller(creator)
66    {
67        RegisterObject(HumanController);
68
69        controlPaused_ = false;
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        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
116            HumanController::localController_s->controllableEntity_->rotateYaw(value);
117    }
118
119    void HumanController::pitch(const Vector2& value)
120    {
121        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
122            HumanController::localController_s->controllableEntity_->rotatePitch(value);
123    }
124
125    void HumanController::rotateYaw(const Vector2& value)
126    {
127        if (HumanController::localController_s)
128            HumanController::localController_s->yaw(value);
129    }
130
131    void HumanController::rotatePitch(const Vector2& value)
132    {
133        if (HumanController::localController_s)
134            HumanController::localController_s->pitch(value);
135    }
136
137    void HumanController::rotateRoll(const Vector2& value)
138    {
139        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
140            HumanController::localController_s->controllableEntity_->rotateRoll(value);
141    }
142
143    void HumanController::fire(unsigned int firemode)
144    {
145        if (HumanController::localController_s)
146            HumanController::localController_s->doFire(firemode);
147    }
148
149    void HumanController::doFire(unsigned int firemode)
150    {
151        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
152            HumanController::localController_s->controllableEntity_->fire(firemode);
153    }
154
155    void HumanController::reload()
156    {
157        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
158            HumanController::localController_s->controllableEntity_->reload();
159    }
160
161    void HumanController::boost()
162    {
163        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
164            HumanController::localController_s->controllableEntity_->boost();
165    }
166
167    void HumanController::greet()
168    {
169        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
170            HumanController::localController_s->controllableEntity_->greet();
171    }
172
173    void HumanController::switchCamera()
174    {
175        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
176            HumanController::localController_s->controllableEntity_->switchCamera();
177    }
178
179    void HumanController::mouseLook()
180    {
181        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
182            HumanController::localController_s->controllableEntity_->mouseLook();
183    }
184
185    void HumanController::suicide()
186    {
187        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
188        {
189            Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
190            if (pawn)
191                pawn->kill();
192            else if (HumanController::localController_s->player_)
193                HumanController::localController_s->player_->stopControl();
194        }
195    }
196
197    void HumanController::toggleGodMode()
198    {
199        HumanController::getLocalControllerSingleton()->setGodMode( !HumanController::getLocalControllerSingleton()->getGodMode() );
200    }
201
202    void HumanController::addBots(unsigned int amount)
203    {
204        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
205            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
206    }
207
208    void HumanController::killBots(unsigned int amount)
209    {
210        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
211            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
212    }
213
214    Pawn* HumanController::getLocalControllerEntityAsPawn()
215    {
216        if (HumanController::localController_s)
217            return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity());
218        else
219            return NULL;
220    }
221
222    void HumanController::cycleNavigationFocus()
223    {
224        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
225            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
226    }
227
228    void HumanController::releaseNavigationFocus()
229    {
230        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
231            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
232    }
233
234    void HumanController::pauseControl()
235    {
236        if (HumanController::localController_s)
237            HumanController::localController_s->doPauseControl();
238    }
239
240    void HumanController::resumeControl()
241    {
242        if (HumanController::localController_s)
243            HumanController::localController_s->doResumeControl();
244    }
245}
Note: See TracBrowser for help on using the repository browser.