Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/controllers/HumanController.cc @ 5813

Last change on this file since 5813 was 5813, checked in by rgrieder, 15 years ago

Moved Radar Management from GSLevel to Scene.

  • Property svn:eol-style set to native
File size: 9.0 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::moveFrontBack(const Vector2& value)
80    {
81        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
82            HumanController::localController_s->controllableEntity_->moveFrontBack(value);
83    }
84
85    void HumanController::moveRightLeft(const Vector2& value)
86    {
87        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
88            HumanController::localController_s->controllableEntity_->moveRightLeft(value);
89    }
90
91    void HumanController::moveUpDown(const Vector2& value)
92    {
93        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
94            HumanController::localController_s->controllableEntity_->moveUpDown(value);
95    }
96
97    void HumanController::rotateYaw(const Vector2& value)
98    {
99        //Hack to enable mouselook in map
100        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
101        {
102            Map::getSingletonPtr()->rotateYaw(value);
103            return;
104        }
105        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
106            HumanController::localController_s->controllableEntity_->rotateYaw(value);
107    }
108
109    void HumanController::rotatePitch(const Vector2& value)
110    {
111        //Hack to enable mouselook in map
112        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
113        {
114            Map::getSingletonPtr()->rotatePitch(value);
115            return;
116        }
117        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
118            HumanController::localController_s->controllableEntity_->rotatePitch(value);
119    }
120
121    void HumanController::rotateRoll(const Vector2& value)
122    {
123        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
124            HumanController::localController_s->controllableEntity_->rotateRoll(value);
125    }
126
127    void HumanController::fire(unsigned int firemode)
128    {
129        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
130            HumanController::localController_s->controllableEntity_->fire(firemode);
131    }
132
133    void HumanController::reload()
134    {
135        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
136            HumanController::localController_s->controllableEntity_->reload();
137    }
138
139    void HumanController::boost()
140    {
141        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
142            HumanController::localController_s->controllableEntity_->boost();
143    }
144
145    void HumanController::greet()
146    {
147        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
148            HumanController::localController_s->controllableEntity_->greet();
149    }
150
151    void HumanController::switchCamera()
152    {
153        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
154            HumanController::localController_s->controllableEntity_->switchCamera();
155    }
156
157    void HumanController::mouseLook()
158    {
159        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
160            HumanController::localController_s->controllableEntity_->mouseLook();
161    }
162
163    void HumanController::suicide()
164    {
165        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
166        {
167            Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
168            if (pawn)
169                pawn->kill();
170            else if (HumanController::localController_s->player_)
171                HumanController::localController_s->player_->stopControl();
172        }
173    }
174
175    void HumanController::useItem()
176    {
177        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
178            HumanController::localController_s->controllableEntity_->useItem();
179    }
180
181    void HumanController::addBots(unsigned int amount)
182    {
183        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
184            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
185    }
186
187    void HumanController::killBots(unsigned int amount)
188    {
189        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
190            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
191    }
192
193    void HumanController::dropItems()
194    {
195        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
196            HumanController::localController_s->controllableEntity_->dropItems();
197    }
198
199    Pawn* HumanController::getLocalControllerEntityAsPawn()
200    {
201        if (HumanController::localController_s)
202            return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity());
203        else
204            return NULL;
205    }
206
207    void HumanController::cycleNavigationFocus()
208    {
209        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
210            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
211    }
212
213    void HumanController::releaseNavigationFocus()
214    {
215        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
216            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
217    }
218}
Note: See TracBrowser for help on using the repository browser.