Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapons/src/orxonox/controllers/HumanController.cc @ 8430

Last change on this file since 8430 was 8079, checked in by landauf, 14 years ago

merged usability branch back to trunk

incomplete summary of the changes in this branch:

  • enhanced keyboard navigation in GUIs
  • implemented new graphics menu and changeable window size at runtime
  • added developer mode
  • HUD shows if game is paused, game pauses if ingame menu is opened
  • removed a few obsolete commands and hid some that are more for internal use
  • numpad works in console and gui
  • faster loading of level info
  • enhanced usage of compositors (Shader class)
  • improved camera handling, configurable FOV and aspect ratio
  • Property svn:eol-style set to native
File size: 11.4 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    extern const std::string __CC_suicide_name = "suicide";
44
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();
51    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
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();
57    SetConsoleCommand("HumanController", __CC_suicide_name,        &HumanController::suicide       ).addShortcut();
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();
63    SetConsoleCommand("HumanController", "myposition",             &HumanController::myposition    ).addShortcut();
64
65    CreateUnloadableFactory(HumanController);
66
67    HumanController* HumanController::localController_s = 0;
68
69    HumanController::HumanController(BaseObject* creator) : Controller(creator)
70    {
71        RegisterObject(HumanController);
72
73        controlPaused_ = false;
74
75        HumanController::localController_s = this;
76    }
77
78    HumanController::~HumanController()
79    {
80        HumanController::localController_s = 0;
81    }
82
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();
88            if (!camera)
89                COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
90        }
91    }
92
93    void HumanController::moveFrontBack(const Vector2& value)
94    {
95        if (HumanController::localController_s)
96            HumanController::localController_s->frontback(value);
97    }
98
99    void HumanController::frontback(const Vector2& value)
100    {
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
117    void HumanController::yaw(const Vector2& value)
118    {
119        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
120            HumanController::localController_s->controllableEntity_->rotateYaw(value);
121    }
122
123    void HumanController::pitch(const Vector2& value)
124    {
125        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
126            HumanController::localController_s->controllableEntity_->rotatePitch(value);
127    }
128
129    void HumanController::rotateYaw(const Vector2& value)
130    {
131        if (HumanController::localController_s)
132            HumanController::localController_s->yaw(value);
133    }
134
135    void HumanController::rotatePitch(const Vector2& value)
136    {
137        if (HumanController::localController_s)
138            HumanController::localController_s->pitch(value);
139    }
140
141    void HumanController::rotateRoll(const Vector2& value)
142    {
143        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
144            HumanController::localController_s->controllableEntity_->rotateRoll(value);
145    }
146
147    void HumanController::fire(unsigned int firemode)
148    {
149        if (HumanController::localController_s)
150            HumanController::localController_s->doFire(firemode);
151    }
152
153    void HumanController::doFire(unsigned int firemode)
154    {
155        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
156            HumanController::localController_s->controllableEntity_->fire(firemode);
157    }
158
159    void HumanController::reload()
160    {
161        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
162            HumanController::localController_s->controllableEntity_->reload();
163    }
164
165    void HumanController::boost()
166    {
167        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
168            HumanController::localController_s->controllableEntity_->boost();
169    }
170
171    void HumanController::greet()
172    {
173        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
174            HumanController::localController_s->controllableEntity_->greet();
175    }
176
177    void HumanController::switchCamera()
178    {
179        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
180            HumanController::localController_s->controllableEntity_->switchCamera();
181    }
182
183    void HumanController::mouseLook()
184    {
185        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
186            HumanController::localController_s->controllableEntity_->mouseLook();
187    }
188
189    void HumanController::suicide()
190    {
191        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
192        {
193            Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
194            if (pawn)
195                pawn->kill();
196            else if (HumanController::localController_s->player_)
197                HumanController::localController_s->player_->stopControl();
198        }
199    }
200
201    void HumanController::toggleGodMode()
202    {
203        if (HumanController::localController_s)
204            HumanController::localController_s->setGodMode(!HumanController::localController_s->getGodMode());
205    }
206
207    void HumanController::myposition()
208    {
209        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
210        {
211            const Vector3& position = HumanController::localController_s->controllableEntity_->getPosition();
212            const Quaternion& orientation = HumanController::localController_s->controllableEntity_->getOrientation();
213
214            COUT(0) << "position=\"" << position.x << ", " << position.y << ", " << position.z << "\" ";
215            COUT(0) << "orientation=\"" << orientation.w << ", " << orientation.x << ", " << orientation.y << ", " << orientation.z << "\"" << std::endl;
216        }
217    }
218
219    void HumanController::addBots(unsigned int amount)
220    {
221        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
222            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
223    }
224
225    void HumanController::killBots(unsigned int amount)
226    {
227        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
228            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
229    }
230
231    Pawn* HumanController::getLocalControllerEntityAsPawn()
232    {
233        if (HumanController::localController_s)
234            return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity());
235        else
236            return NULL;
237    }
238
239    void HumanController::cycleNavigationFocus()
240    {
241        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
242            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
243    }
244
245    void HumanController::releaseNavigationFocus()
246    {
247        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
248            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
249    }
250
251    void HumanController::pauseControl()
252    {
253        if (HumanController::localController_s)
254            HumanController::localController_s->doPauseControl();
255    }
256
257    void HumanController::resumeControl()
258    {
259        if (HumanController::localController_s)
260            HumanController::localController_s->doResumeControl();
261    }
262}
Note: See TracBrowser for help on using the repository browser.