Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/controllers/HumanController.cc @ 7862

Last change on this file since 7862 was 7862, checked in by landauf, 13 years ago

added feature to Spectator which changes the keybind mode of the fire command to OnPress if the player controls a Spectator. changes mode back to OnHold if the player stops control of the Spectator (e.g. spawns) by using a helper function.

This avoids accidentally firing the weapons right after spawn.

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