Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gameimmersion/src/orxonox/controllers/HumanController.cc @ 8541

Last change on this file since 8541 was 8541, checked in by dboehi, 13 years ago

Changed boost to start on key press and stop on key release

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