Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/controllers/HumanController.cc @ 2462

Last change on this file since 2462 was 2462, checked in by landauf, 15 years ago
  • fixed a small speedbar-initialization problem
  • added new console-commands:
    • pause
    • suicide
    • addBots [number]
    • killBots [number]
  • Property svn:eol-style set to native
File size: 6.7 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 "OrxonoxStableHeaders.h"
30#include "HumanController.h"
31
32#include "core/CoreIncludes.h"
33#include "core/ConsoleCommand.h"
34#include "objects/worldentities/ControllableEntity.h"
35#include "objects/worldentities/pawns/Pawn.h"
36#include "objects/gametypes/Gametype.h"
37
38namespace orxonox
39{
40    SetConsoleCommand(HumanController, moveFrontBack, true).setAsInputCommand();
41    SetConsoleCommand(HumanController, moveRightLeft, true).setAsInputCommand();
42    SetConsoleCommand(HumanController, moveUpDown,    true).setAsInputCommand();
43    SetConsoleCommand(HumanController, rotateYaw,     true).setAsInputCommand();
44    SetConsoleCommand(HumanController, rotatePitch,   true).setAsInputCommand();
45    SetConsoleCommand(HumanController, rotateRoll,    true).setAsInputCommand();
46    SetConsoleCommand(HumanController, fire,          true).keybindMode(KeybindMode::OnHold);
47    SetConsoleCommand(HumanController, altFire,       true).keybindMode(KeybindMode::OnHold);
48    SetConsoleCommand(HumanController, boost,         true).keybindMode(KeybindMode::OnHold);
49    SetConsoleCommand(HumanController, greet,         true);
50    SetConsoleCommand(HumanController, use,           true);
51    SetConsoleCommand(HumanController, switchCamera,  true);
52    SetConsoleCommand(HumanController, suicide,       true);
53    SetConsoleCommand(HumanController, addBots,       true).defaultValues(1);
54    SetConsoleCommand(HumanController, killBots,      true).defaultValues(0);
55
56    CreateUnloadableFactory(HumanController);
57
58    HumanController* HumanController::localController_s = 0;
59
60    HumanController::HumanController(BaseObject* creator) : Controller(creator)
61    {
62        RegisterObject(HumanController);
63
64        HumanController::localController_s = this;
65    }
66
67    HumanController::~HumanController()
68    {
69        HumanController::localController_s = 0;
70    }
71
72    void HumanController::moveFrontBack(const Vector2& value)
73    {
74        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
75            HumanController::localController_s->controllableEntity_->moveFrontBack(value);
76    }
77
78    void HumanController::moveRightLeft(const Vector2& value)
79    {
80        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
81            HumanController::localController_s->controllableEntity_->moveRightLeft(value);
82    }
83
84    void HumanController::moveUpDown(const Vector2& value)
85    {
86        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
87            HumanController::localController_s->controllableEntity_->moveUpDown(value);
88    }
89
90    void HumanController::rotateYaw(const Vector2& value)
91    {
92        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
93            HumanController::localController_s->controllableEntity_->rotateYaw(value);
94    }
95
96    void HumanController::rotatePitch(const Vector2& value)
97    {
98        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
99            HumanController::localController_s->controllableEntity_->rotatePitch(value);
100    }
101
102    void HumanController::rotateRoll(const Vector2& value)
103    {
104        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
105            HumanController::localController_s->controllableEntity_->rotateRoll(value);
106    }
107
108    void HumanController::fire()
109    {
110        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
111            HumanController::localController_s->controllableEntity_->fire();
112    }
113
114    void HumanController::altFire()
115    {
116        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
117            HumanController::localController_s->controllableEntity_->altFire();
118    }
119
120    void HumanController::boost()
121    {
122        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
123            HumanController::localController_s->controllableEntity_->boost();
124    }
125
126    void HumanController::greet()
127    {
128        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
129            HumanController::localController_s->controllableEntity_->greet();
130    }
131
132    void HumanController::use()
133    {
134        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
135            HumanController::localController_s->controllableEntity_->use();
136    }
137
138    void HumanController::switchCamera()
139    {
140        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
141            HumanController::localController_s->controllableEntity_->switchCamera();
142    }
143
144    void HumanController::suicide()
145    {
146        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
147        {
148            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
149            if (pawn)
150                pawn->kill();
151        }
152    }
153
154    void HumanController::addBots(unsigned int amount)
155    {
156        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
157            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
158    }
159
160    void HumanController::killBots(unsigned int amount)
161    {
162        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
163            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
164    }
165}
Note: See TracBrowser for help on using the repository browser.