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 | * Michael Wirth |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "NewHumanController.h" |
---|
30 | |
---|
31 | #include "core/input/InputManager.h" |
---|
32 | #include "core/input/InputState.h" |
---|
33 | |
---|
34 | #include "core/CoreIncludes.h" |
---|
35 | #include "core/ConsoleCommand.h" |
---|
36 | #include "worldentities/ControllableEntity.h" |
---|
37 | #include "worldentities/pawns/Pawn.h" |
---|
38 | #include "gametypes/Gametype.h" |
---|
39 | #include "infos/PlayerInfo.h" |
---|
40 | #include "overlays/Map.h" |
---|
41 | #include "graphics/Camera.h" |
---|
42 | #include "sound/SoundManager.h" |
---|
43 | #include "Radar.h" |
---|
44 | #include "Scene.h" |
---|
45 | |
---|
46 | namespace orxonox |
---|
47 | { |
---|
48 | SetConsoleCommand(NewHumanController, moveFrontBack, true).setAsInputCommand(); |
---|
49 | SetConsoleCommand(NewHumanController, moveRightLeft, true).setAsInputCommand(); |
---|
50 | SetConsoleCommand(NewHumanController, moveUpDown, true).setAsInputCommand(); |
---|
51 | SetConsoleCommand(NewHumanController, rotateYaw, true).setAsInputCommand(); |
---|
52 | SetConsoleCommand(NewHumanController, rotatePitch, true).setAsInputCommand(); |
---|
53 | SetConsoleCommand(NewHumanController, rotateRoll, true).setAsInputCommand(); |
---|
54 | SetConsoleCommand(NewHumanController, fire, true).keybindMode(KeybindMode::OnHold); |
---|
55 | SetConsoleCommand(NewHumanController, reload, true); |
---|
56 | SetConsoleCommand(NewHumanController, boost, true).keybindMode(KeybindMode::OnHold); |
---|
57 | SetConsoleCommand(NewHumanController, greet, true); |
---|
58 | SetConsoleCommand(NewHumanController, switchCamera, true); |
---|
59 | SetConsoleCommand(NewHumanController, mouseLook, true); |
---|
60 | SetConsoleCommand(NewHumanController, suicide, true); |
---|
61 | SetConsoleCommand(NewHumanController, addBots, true).defaultValues(1); |
---|
62 | SetConsoleCommand(NewHumanController, killBots, true).defaultValues(0); |
---|
63 | SetConsoleCommand(NewHumanController, dropItems, true); |
---|
64 | SetConsoleCommand(NewHumanController, useItem, true); |
---|
65 | SetConsoleCommand(NewHumanController, cycleNavigationFocus, true); |
---|
66 | SetConsoleCommand(NewHumanController, releaseNavigationFocus, true); |
---|
67 | |
---|
68 | CreateUnloadableFactory(NewHumanController); |
---|
69 | |
---|
70 | NewHumanController* NewHumanController::localController_s = 0; |
---|
71 | |
---|
72 | NewHumanController::NewHumanController(BaseObject* creator) : HumanController(creator) |
---|
73 | { |
---|
74 | RegisterObject(NewHumanController); |
---|
75 | |
---|
76 | NewHumanController::localController_s = this; |
---|
77 | |
---|
78 | gameInputState_ = InputManager::getInstance().createInputState("humansteering", true, true); |
---|
79 | gameInputState_->setMouseHandler(this); |
---|
80 | gameInputState_->setMouseMode(MouseMode::Exclusive); |
---|
81 | } |
---|
82 | |
---|
83 | NewHumanController::~NewHumanController() |
---|
84 | { |
---|
85 | NewHumanController::localController_s = 0; |
---|
86 | |
---|
87 | if( this->isInitialized() ) |
---|
88 | { |
---|
89 | gameInputState_->setHandler(0); |
---|
90 | InputManager::getInstance().destroyState("humansteering"); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | void NewHumanController::tick(float dt) |
---|
95 | { |
---|
96 | if (GameMode::playsSound() && NewHumanController::localController_s && NewHumanController::localController_s->controllableEntity_) |
---|
97 | { |
---|
98 | // Update sound listener |
---|
99 | Camera* camera = NewHumanController::localController_s->controllableEntity_->getCamera(); |
---|
100 | if (camera) |
---|
101 | { |
---|
102 | SoundManager::getInstance().setListenerPosition(camera->getWorldPosition()); |
---|
103 | SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation()); |
---|
104 | } |
---|
105 | else |
---|
106 | COUT(3) << "NewHumanController, Warning: Using a ControllableEntity without Camera" << std::endl; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | void NewHumanController::startControl() { |
---|
111 | //gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler()); |
---|
112 | //KeyBinderManager::getInstance().setToDefault(); |
---|
113 | |
---|
114 | InputManager::getInstance().enterState("humansteering"); |
---|
115 | std::cout << "started control" << endl; |
---|
116 | } |
---|
117 | |
---|
118 | void NewHumanController::stopControl() { |
---|
119 | InputManager::getInstance().leaveState("humansteering"); |
---|
120 | std::cout << "stopped control" << endl; |
---|
121 | } |
---|
122 | |
---|
123 | void NewHumanController::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) |
---|
124 | { |
---|
125 | std::cout << "X: " << static_cast<float>(abs.x) << " Y: " << static_cast<float>(abs.y) << endl; |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|