Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8043 was 7863, checked in by landauf, 14 years ago

disabled suicide for Spectator

  • Property svn:eol-style set to native
File size: 10.6 KB
RevLine 
[2072]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"
[7284]32#include "core/command/ConsoleCommand.h"
[5735]33#include "worldentities/ControllableEntity.h"
34#include "worldentities/pawns/Pawn.h"
35#include "gametypes/Gametype.h"
36#include "infos/PlayerInfo.h"
[5929]37#include "Radar.h"
38#include "Scene.h"
[2072]39
40namespace orxonox
41{
[7862]42    extern const std::string __CC_fire_name = "fire";
[7863]43    extern const std::string __CC_suicide_name = "suicide";
[7862]44
[7284]45    SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
46    SetConsoleCommand("HumanController", "moveRightLeft",          &HumanController::moveRightLeft ).addShortcut().setAsInputCommand();
47    SetConsoleCommand("HumanController", "moveUpDown",             &HumanController::moveUpDown    ).addShortcut().setAsInputCommand();
48    SetConsoleCommand("HumanController", "rotateYaw",              &HumanController::rotateYaw     ).addShortcut().setAsInputCommand();
49    SetConsoleCommand("HumanController", "rotatePitch",            &HumanController::rotatePitch   ).addShortcut().setAsInputCommand();
50    SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
[7862]51    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
[7284]52    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
53    SetConsoleCommand("HumanController", "boost",                  &HumanController::boost         ).addShortcut().keybindMode(KeybindMode::OnHold);
54    SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
55    SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
56    SetConsoleCommand("HumanController", "mouseLook",              &HumanController::mouseLook     ).addShortcut();
[7863]57    SetConsoleCommand("HumanController", __CC_suicide_name,        &HumanController::suicide       ).addShortcut();
[7284]58    SetConsoleCommand("HumanController", "toggleGodMode",          &HumanController::toggleGodMode ).addShortcut();
59    SetConsoleCommand("HumanController", "addBots",                &HumanController::addBots       ).addShortcut().defaultValues(1);
60    SetConsoleCommand("HumanController", "killBots",               &HumanController::killBots      ).addShortcut().defaultValues(0);
61    SetConsoleCommand("HumanController", "cycleNavigationFocus",   &HumanController::cycleNavigationFocus).addShortcut();
62    SetConsoleCommand("HumanController", "releaseNavigationFocus", &HumanController::releaseNavigationFocus).addShortcut();
[2072]63
64    CreateUnloadableFactory(HumanController);
65
66    HumanController* HumanController::localController_s = 0;
67
68    HumanController::HumanController(BaseObject* creator) : Controller(creator)
69    {
70        RegisterObject(HumanController);
71
[6417]72        controlPaused_ = false;
73
[2072]74        HumanController::localController_s = this;
75    }
76
77    HumanController::~HumanController()
78    {
79        HumanController::localController_s = 0;
80    }
81
[5929]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();
[6417]87            if (!camera)
[5929]88                COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
89        }
90    }
91
[2072]92    void HumanController::moveFrontBack(const Vector2& value)
93    {
[6417]94        if (HumanController::localController_s)
95            HumanController::localController_s->frontback(value);
96    }
97
98    void HumanController::frontback(const Vector2& value)
99    {
[2072]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
[6417]116    void HumanController::yaw(const Vector2& value)
[2072]117    {
118        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
119            HumanController::localController_s->controllableEntity_->rotateYaw(value);
120    }
121
[6417]122    void HumanController::pitch(const Vector2& value)
[2072]123    {
124        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
125            HumanController::localController_s->controllableEntity_->rotatePitch(value);
126    }
127
[6417]128    void HumanController::rotateYaw(const Vector2& value)
129    {
130        if (HumanController::localController_s)
131            HumanController::localController_s->yaw(value);
132    }
133
134    void HumanController::rotatePitch(const Vector2& value)
135    {
136        if (HumanController::localController_s)
137            HumanController::localController_s->pitch(value);
138    }
139
[2072]140    void HumanController::rotateRoll(const Vector2& value)
141    {
142        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
143            HumanController::localController_s->controllableEntity_->rotateRoll(value);
144    }
145
[3053]146    void HumanController::fire(unsigned int firemode)
[2072]147    {
[6417]148        if (HumanController::localController_s)
149            HumanController::localController_s->doFire(firemode);
150    }
151
152    void HumanController::doFire(unsigned int firemode)
153    {
[2072]154        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
[3053]155            HumanController::localController_s->controllableEntity_->fire(firemode);
[2072]156    }
157
[3053]158    void HumanController::reload()
[2072]159    {
160        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
[3053]161            HumanController::localController_s->controllableEntity_->reload();
[2072]162    }
163
[2662]164    void HumanController::boost()
165    {
166        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
167            HumanController::localController_s->controllableEntity_->boost();
168    }
169
[2072]170    void HumanController::greet()
171    {
172        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
173            HumanController::localController_s->controllableEntity_->greet();
174    }
175
176    void HumanController::switchCamera()
177    {
178        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
179            HumanController::localController_s->controllableEntity_->switchCamera();
180    }
[2662]181
182    void HumanController::mouseLook()
183    {
184        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
185            HumanController::localController_s->controllableEntity_->mouseLook();
186    }
187
188    void HumanController::suicide()
189    {
190        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
191        {
[3325]192            Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
[2662]193            if (pawn)
194                pawn->kill();
[2872]195            else if (HumanController::localController_s->player_)
[3038]196                HumanController::localController_s->player_->stopControl();
[2662]197        }
198    }
199
[6417]200    void HumanController::toggleGodMode()
201    {
202        HumanController::getLocalControllerSingleton()->setGodMode( !HumanController::getLocalControllerSingleton()->getGodMode() );
203    }
204
[2662]205    void HumanController::addBots(unsigned int amount)
206    {
207        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
208            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
209    }
210
211    void HumanController::killBots(unsigned int amount)
212    {
213        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
214            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
215    }
216
[3196]217    Pawn* HumanController::getLocalControllerEntityAsPawn()
218    {
219        if (HumanController::localController_s)
[3325]220            return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity());
[3196]221        else
222            return NULL;
223    }
[5929]224
225    void HumanController::cycleNavigationFocus()
226    {
227        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
228            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
229    }
230
231    void HumanController::releaseNavigationFocus()
232    {
233        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
234            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
235    }
[6417]236
237    void HumanController::pauseControl()
238    {
239        if (HumanController::localController_s)
240            HumanController::localController_s->doPauseControl();
241    }
242
243    void HumanController::resumeControl()
244    {
245        if (HumanController::localController_s)
246            HumanController::localController_s->doResumeControl();
247    }
[2072]248}
Note: See TracBrowser for help on using the repository browser.