Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2912 was 2912, checked in by landauf, 15 years ago

Several small adjustments in the weaponsystem (like additional const keyword, includes moved from .h to .cc where possible, …)

Firemode is now an unsigned int instead of an Enum. Instead of "fire" and "altFire" use "fire 0" and "fire 1"

  • Property svn:eol-style set to native
File size: 7.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 "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#include "objects/infos/PlayerInfo.h"
38
39namespace orxonox
40{
41    SetConsoleCommand(HumanController, moveFrontBack, true).setAsInputCommand();
42    SetConsoleCommand(HumanController, moveRightLeft, true).setAsInputCommand();
43    SetConsoleCommand(HumanController, moveUpDown,    true).setAsInputCommand();
44    SetConsoleCommand(HumanController, rotateYaw,     true).setAsInputCommand();
45    SetConsoleCommand(HumanController, rotatePitch,   true).setAsInputCommand();
46    SetConsoleCommand(HumanController, rotateRoll,    true).setAsInputCommand();
47    SetConsoleCommand(HumanController, fire,          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, mouseLook,     true);
53    SetConsoleCommand(HumanController, suicide,       true);
54    SetConsoleCommand(HumanController, addBots,       true).defaultValues(1);
55    SetConsoleCommand(HumanController, killBots,      true).defaultValues(0);
56    SetConsoleCommand(HumanController, dropItems,     true);
57
58    CreateUnloadableFactory(HumanController);
59
60    HumanController* HumanController::localController_s = 0;
61
62    HumanController::HumanController(BaseObject* creator) : Controller(creator)
63    {
64        RegisterObject(HumanController);
65
66        HumanController::localController_s = this;
67    }
68
69    HumanController::~HumanController()
70    {
71        HumanController::localController_s = 0;
72    }
73
74    void HumanController::moveFrontBack(const Vector2& value)
75    {
76        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
77            HumanController::localController_s->controllableEntity_->moveFrontBack(value);
78    }
79
80    void HumanController::moveRightLeft(const Vector2& value)
81    {
82        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
83            HumanController::localController_s->controllableEntity_->moveRightLeft(value);
84    }
85
86    void HumanController::moveUpDown(const Vector2& value)
87    {
88        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
89            HumanController::localController_s->controllableEntity_->moveUpDown(value);
90    }
91
92    void HumanController::rotateYaw(const Vector2& value)
93    {
94        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
95            HumanController::localController_s->controllableEntity_->rotateYaw(value);
96    }
97
98    void HumanController::rotatePitch(const Vector2& value)
99    {
100        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
101            HumanController::localController_s->controllableEntity_->rotatePitch(value);
102    }
103
104    void HumanController::rotateRoll(const Vector2& value)
105    {
106        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
107            HumanController::localController_s->controllableEntity_->rotateRoll(value);
108    }
109
110    void HumanController::fire(unsigned int firemode)
111    {
112        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
113            HumanController::localController_s->controllableEntity_->fire(firemode);
114    }
115
116    void HumanController::boost()
117    {
118        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
119            HumanController::localController_s->controllableEntity_->boost();
120    }
121
122    void HumanController::greet()
123    {
124        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
125            HumanController::localController_s->controllableEntity_->greet();
126    }
127
128    void HumanController::use()
129    {
130        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
131            HumanController::localController_s->controllableEntity_->use();
132    }
133
134    void HumanController::switchCamera()
135    {
136        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
137            HumanController::localController_s->controllableEntity_->switchCamera();
138    }
139
140    void HumanController::mouseLook()
141    {
142        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
143            HumanController::localController_s->controllableEntity_->mouseLook();
144    }
145
146    void HumanController::suicide()
147    {
148        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
149        {
150            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
151            if (pawn)
152                pawn->kill();
153            else if (HumanController::localController_s->player_)
154                HumanController::localController_s->player_->stopControl(HumanController::localController_s->controllableEntity_);
155        }
156    }
157
158    void HumanController::addBots(unsigned int amount)
159    {
160        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
161            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
162    }
163
164    void HumanController::killBots(unsigned int amount)
165    {
166        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
167            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
168    }
169
170    void HumanController::dropItems()
171    {
172        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
173            HumanController::localController_s->controllableEntity_->dropItems();
174    }
175}
Note: See TracBrowser for help on using the repository browser.