Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/fps/src/orxonox/controllers/HumanController.cc @ 7073

Last change on this file since 7073 was 6866, checked in by freicy, 15 years ago

commit by cyrill

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