Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/bigships/src/orxonox/controllers/HumanController.cc @ 8592

Last change on this file since 8592 was 8426, checked in by decryphe, 14 years ago
  • Moved handling of blur effect from Engine.cc to SpaceShip.cc.
  • Implemented handling of multiple engines per SpaceShip, so that in future it would be possible to turn single engines on/off individually (for example if one gets destroyed on a big ship).
  • Updated some pointers accessing the single Engine of a SpaceShip to ask the SpaceShip itself instead for data.
  • Property svn:eol-style set to native
File size: 12.2 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    const std::string __CC_boost_name = "boost";
45
46    SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
47    SetConsoleCommand("HumanController", "moveRightLeft",          &HumanController::moveRightLeft ).addShortcut().setAsInputCommand();
48    SetConsoleCommand("HumanController", "moveUpDown",             &HumanController::moveUpDown    ).addShortcut().setAsInputCommand();
49    SetConsoleCommand("HumanController", "rotateYaw",              &HumanController::rotateYaw     ).addShortcut().setAsInputCommand();
50    SetConsoleCommand("HumanController", "rotatePitch",            &HumanController::rotatePitch   ).addShortcut().setAsInputCommand();
51    SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
52    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
53    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
54    SetConsoleCommand("HumanController", __CC_boost_name,          &HumanController::toggleBoost   ).addShortcut().keybindMode(KeybindMode::OnPress);
55    SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
56    SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
57    SetConsoleCommand("HumanController", "mouseLook",              &HumanController::mouseLook     ).addShortcut();
58    SetConsoleCommand("HumanController", __CC_suicide_name,        &HumanController::suicide       ).addShortcut();
59    SetConsoleCommand("HumanController", "toggleGodMode",          &HumanController::toggleGodMode ).addShortcut();
60    SetConsoleCommand("HumanController", "addBots",                &HumanController::addBots       ).addShortcut().defaultValues(1);
61    SetConsoleCommand("HumanController", "killBots",               &HumanController::killBots      ).addShortcut().defaultValues(0);
62    SetConsoleCommand("HumanController", "cycleNavigationFocus",   &HumanController::cycleNavigationFocus).addShortcut();
63    SetConsoleCommand("HumanController", "releaseNavigationFocus", &HumanController::releaseNavigationFocus).addShortcut();
64    SetConsoleCommand("HumanController", "myposition",             &HumanController::myposition    ).addShortcut();
65
66    CreateUnloadableFactory(HumanController);
67
68    HumanController* HumanController::localController_s = 0;
69
70    HumanController::HumanController(BaseObject* creator) : Controller(creator)
71    {
72        RegisterObject(HumanController);
73
74        controlPaused_ = false;
75        this->boosting_ = false;
76
77        HumanController::localController_s = this;
78    }
79
80    HumanController::~HumanController()
81    {
82        HumanController::localController_s = 0;
83    }
84
85    void HumanController::tick(float dt)
86    {
87        if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_)
88        {
89            Camera* camera = HumanController::localController_s->controllableEntity_->getCamera();
90            if (!camera)
91                COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
92        }
93    }
94
95    void HumanController::moveFrontBack(const Vector2& value)
96    {
97        if (HumanController::localController_s)
98            HumanController::localController_s->frontback(value);
99    }
100
101    void HumanController::frontback(const Vector2& value)
102    {
103        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
104            HumanController::localController_s->controllableEntity_->moveFrontBack(value);
105    }
106
107    void HumanController::moveRightLeft(const Vector2& value)
108    {
109        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
110            HumanController::localController_s->controllableEntity_->moveRightLeft(value);
111    }
112
113    void HumanController::moveUpDown(const Vector2& value)
114    {
115        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
116            HumanController::localController_s->controllableEntity_->moveUpDown(value);
117    }
118
119    void HumanController::yaw(const Vector2& value)
120    {
121        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
122            HumanController::localController_s->controllableEntity_->rotateYaw(value);
123    }
124
125    void HumanController::pitch(const Vector2& value)
126    {
127        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
128            HumanController::localController_s->controllableEntity_->rotatePitch(value);
129    }
130
131    void HumanController::rotateYaw(const Vector2& value)
132    {
133        if (HumanController::localController_s)
134            HumanController::localController_s->yaw(value);
135    }
136
137    void HumanController::rotatePitch(const Vector2& value)
138    {
139        if (HumanController::localController_s)
140            HumanController::localController_s->pitch(value);
141    }
142
143    void HumanController::rotateRoll(const Vector2& value)
144    {
145        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
146            HumanController::localController_s->controllableEntity_->rotateRoll(value);
147    }
148
149    void HumanController::fire(unsigned int firemode)
150    {
151        if (HumanController::localController_s)
152            HumanController::localController_s->doFire(firemode);
153    }
154
155    void HumanController::doFire(unsigned int firemode)
156    {
157        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
158            HumanController::localController_s->controllableEntity_->fire(firemode);
159    }
160
161    void HumanController::reload()
162    {
163        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
164            HumanController::localController_s->controllableEntity_->reload();
165    }
166
167    /**
168    @brief
169        Static method,toggles boosting.
170    */
171    /*static*/ void HumanController::toggleBoost()
172    {
173        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
174            HumanController::localController_s->toggleBoosting();
175    }
176   
177    /**
178    @brief
179        Toggles the boosting mode.
180        Changes the keybind mode of the boost console command and tells the ControllableEntity to boost (or not boost anymore).
181    */
182    void HumanController::toggleBoosting(void)
183    {
184        this->boosting_ = !this->boosting_;
185       
186        // The keybind mode of the boosting console command is onRelease if in boosting mode and onPress of not in boosting mode.
187        if(this->boosting_)
188            ModifyConsoleCommand(__CC_boost_name).keybindMode(KeybindMode::OnRelease);
189        else
190            ModifyConsoleCommand(__CC_boost_name).keybindMode(KeybindMode::OnPress);
191
192        this->controllableEntity_->boost(this->boosting_);
193    }
194
195    void HumanController::greet()
196    {
197        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
198            HumanController::localController_s->controllableEntity_->greet();
199    }
200
201    void HumanController::switchCamera()
202    {
203        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
204            HumanController::localController_s->controllableEntity_->switchCamera();
205    }
206
207    void HumanController::mouseLook()
208    {
209        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
210            HumanController::localController_s->controllableEntity_->mouseLook();
211    }
212
213    void HumanController::suicide()
214    {
215        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
216        {
217            Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
218            if (pawn)
219                pawn->kill();
220            else if (HumanController::localController_s->player_)
221                HumanController::localController_s->player_->stopControl();
222        }
223    }
224
225    void HumanController::toggleGodMode()
226    {
227        if (HumanController::localController_s)
228            HumanController::localController_s->setGodMode(!HumanController::localController_s->getGodMode());
229    }
230
231    void HumanController::myposition()
232    {
233        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
234        {
235            const Vector3& position = HumanController::localController_s->controllableEntity_->getPosition();
236            const Quaternion& orientation = HumanController::localController_s->controllableEntity_->getOrientation();
237
238            COUT(0) << "position=\"" << position.x << ", " << position.y << ", " << position.z << "\" ";
239            COUT(0) << "orientation=\"" << orientation.w << ", " << orientation.x << ", " << orientation.y << ", " << orientation.z << "\"" << std::endl;
240        }
241    }
242
243    void HumanController::addBots(unsigned int amount)
244    {
245        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
246            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
247    }
248
249    void HumanController::killBots(unsigned int amount)
250    {
251        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
252            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
253    }
254
255    Pawn* HumanController::getLocalControllerEntityAsPawn()
256    {
257        if (HumanController::localController_s)
258            return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity());
259        else
260            return NULL;
261    }
262
263    void HumanController::cycleNavigationFocus()
264    {
265        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
266            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
267    }
268
269    void HumanController::releaseNavigationFocus()
270    {
271        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
272            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
273    }
274
275    void HumanController::pauseControl()
276    {
277        if (HumanController::localController_s)
278            HumanController::localController_s->doPauseControl();
279    }
280
281    void HumanController::resumeControl()
282    {
283        if (HumanController::localController_s)
284            HumanController::localController_s->doResumeControl();
285    }
286}
Note: See TracBrowser for help on using the repository browser.