Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/controllers/HumanController.cc @ 8887

Last change on this file since 8887 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
  • Property svn:eol-style set to native
File size: 12.8 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"
[7284]32#include "core/command/ConsoleCommand.h"
[5735]33#include "worldentities/ControllableEntity.h"
34#include "worldentities/pawns/Pawn.h"
35#include "gametypes/Gametype.h"
36#include "infos/PlayerInfo.h"
[5929]37#include "Radar.h"
38#include "Scene.h"
[2072]39
40namespace orxonox
41{
[7862]42    extern const std::string __CC_fire_name = "fire";
[7863]43    extern const std::string __CC_suicide_name = "suicide";
[8706]44    const std::string __CC_boost_name = "boost";
[7862]45
[7284]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();
[7862]52    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
[7284]53    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
[8706]54    SetConsoleCommand("HumanController", __CC_boost_name,          &HumanController::keepBoost     ).addShortcut().keybindMode(KeybindMode::OnHold);
[7284]55    SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
56    SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
57    SetConsoleCommand("HumanController", "mouseLook",              &HumanController::mouseLook     ).addShortcut();
[7863]58    SetConsoleCommand("HumanController", __CC_suicide_name,        &HumanController::suicide       ).addShortcut();
[7284]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();
[8079]64    SetConsoleCommand("HumanController", "myposition",             &HumanController::myposition    ).addShortcut();
[2072]65
66    CreateUnloadableFactory(HumanController);
67
68    HumanController* HumanController::localController_s = 0;
[8706]69    /*static*/ const float HumanController::BOOSTING_TIME = 0.1f;
[2072]70
71    HumanController::HumanController(BaseObject* creator) : Controller(creator)
72    {
73        RegisterObject(HumanController);
74
[8706]75        this->controlPaused_ = false;
76        this->boosting_ = false;
77        this->boosting_ = false;
[6417]78
[2072]79        HumanController::localController_s = this;
[8706]80        this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
81        this->boostingTimeout_.stopTimer();
[2072]82    }
83
84    HumanController::~HumanController()
85    {
86        HumanController::localController_s = 0;
87    }
88
[5929]89    void HumanController::tick(float dt)
90    {
91        if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_)
92        {
93            Camera* camera = HumanController::localController_s->controllableEntity_->getCamera();
[6417]94            if (!camera)
[8858]95                orxout(internal_warning) << "HumanController, Warning: Using a ControllableEntity without Camera" << endl;
[5929]96        }
97    }
98
[2072]99    void HumanController::moveFrontBack(const Vector2& value)
100    {
[6417]101        if (HumanController::localController_s)
102            HumanController::localController_s->frontback(value);
103    }
104
105    void HumanController::frontback(const Vector2& value)
106    {
[2072]107        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
108            HumanController::localController_s->controllableEntity_->moveFrontBack(value);
109    }
110
111    void HumanController::moveRightLeft(const Vector2& value)
112    {
113        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
114            HumanController::localController_s->controllableEntity_->moveRightLeft(value);
115    }
116
117    void HumanController::moveUpDown(const Vector2& value)
118    {
119        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
120            HumanController::localController_s->controllableEntity_->moveUpDown(value);
121    }
122
[6417]123    void HumanController::yaw(const Vector2& value)
[2072]124    {
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    {
131        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
132            HumanController::localController_s->controllableEntity_->rotatePitch(value);
133    }
134
[6417]135    void HumanController::rotateYaw(const Vector2& value)
136    {
137        if (HumanController::localController_s)
138            HumanController::localController_s->yaw(value);
139    }
140
141    void HumanController::rotatePitch(const Vector2& value)
142    {
143        if (HumanController::localController_s)
144            HumanController::localController_s->pitch(value);
145    }
146
[2072]147    void HumanController::rotateRoll(const Vector2& value)
148    {
149        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
150            HumanController::localController_s->controllableEntity_->rotateRoll(value);
151    }
152
[3053]153    void HumanController::fire(unsigned int firemode)
[2072]154    {
[6417]155        if (HumanController::localController_s)
156            HumanController::localController_s->doFire(firemode);
157    }
158
159    void HumanController::doFire(unsigned int firemode)
160    {
[2072]161        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
[3053]162            HumanController::localController_s->controllableEntity_->fire(firemode);
[2072]163    }
164
[3053]165    void HumanController::reload()
[2072]166    {
167        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
[3053]168            HumanController::localController_s->controllableEntity_->reload();
[2072]169    }
170
[8706]171    /**
172    @brief
173        Static method,keeps boosting.
174    */
175    /*static*/ void HumanController::keepBoost()
[2662]176    {
177        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
[8706]178            HumanController::localController_s->keepBoosting();
[2662]179    }
[8706]180   
181    /**
182    @brief
183        Starts, or keeps the boosting mode.
184        Resets the boosting timeout and ells the ControllableEntity to boost (or not boost anymore).
185    */
186    void HumanController::keepBoosting(void)
187    {
188        if(this->boostingTimeout_.isActive())
189        {
190            this->boostingTimeout_.stopTimer();
191            this->boostingTimeout_.startTimer();
192        }
193        else
194        {
195            this->boosting_ = true;
196            this->boostingTimeout_.startTimer();
197           
198            this->controllableEntity_->boost(this->boosting_);
[8858]199//            orxout() << "Start boosting" << endl;
[8706]200        }
201    }
[2662]202
[8706]203    /**
204    @brief
205        Terminates the boosting mode.
206    */
207    void HumanController::terminateBoosting(void)
208    {
209        this->boosting_ = false;
210        this->boostingTimeout_.stopTimer();
211
212        this->controllableEntity_->boost(this->boosting_);
[8858]213//        orxout() << "Stop boosting" << endl;
[8706]214    }
215
[2072]216    void HumanController::greet()
217    {
218        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
219            HumanController::localController_s->controllableEntity_->greet();
220    }
221
222    void HumanController::switchCamera()
223    {
224        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
225            HumanController::localController_s->controllableEntity_->switchCamera();
226    }
[2662]227
228    void HumanController::mouseLook()
229    {
230        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
231            HumanController::localController_s->controllableEntity_->mouseLook();
232    }
233
234    void HumanController::suicide()
235    {
236        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
237        {
[3325]238            Pawn* pawn = orxonox_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
[2662]239            if (pawn)
240                pawn->kill();
[2872]241            else if (HumanController::localController_s->player_)
[3038]242                HumanController::localController_s->player_->stopControl();
[2662]243        }
244    }
245
[6417]246    void HumanController::toggleGodMode()
247    {
[8079]248        if (HumanController::localController_s)
249            HumanController::localController_s->setGodMode(!HumanController::localController_s->getGodMode());
[6417]250    }
251
[8079]252    void HumanController::myposition()
253    {
254        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
255        {
256            const Vector3& position = HumanController::localController_s->controllableEntity_->getPosition();
257            const Quaternion& orientation = HumanController::localController_s->controllableEntity_->getOrientation();
258
[8858]259            orxout(message) << "position=\"" << position.x << ", " << position.y << ", " << position.z << "\" "
260                            << "orientation=\"" << orientation.w << ", " << orientation.x << ", " << orientation.y << ", " << orientation.z << "\"" << endl;
[8079]261        }
262    }
263
[2662]264    void HumanController::addBots(unsigned int amount)
265    {
266        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
267            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
268    }
269
270    void HumanController::killBots(unsigned int amount)
271    {
272        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
273            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
274    }
275
[3196]276    Pawn* HumanController::getLocalControllerEntityAsPawn()
277    {
278        if (HumanController::localController_s)
[3325]279            return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity());
[3196]280        else
281            return NULL;
282    }
[5929]283
284    void HumanController::cycleNavigationFocus()
285    {
286        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
287            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
288    }
289
290    void HumanController::releaseNavigationFocus()
291    {
292        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
293            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
294    }
[6417]295
296    void HumanController::pauseControl()
297    {
298        if (HumanController::localController_s)
299            HumanController::localController_s->doPauseControl();
300    }
301
302    void HumanController::resumeControl()
303    {
304        if (HumanController::localController_s)
305            HumanController::localController_s->doResumeControl();
306    }
[2072]307}
Note: See TracBrowser for help on using the repository browser.