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 "StoryModeController.h" |
---|
30 | |
---|
31 | #include "core/CoreIncludes.h" |
---|
32 | #include "core/command/ConsoleCommandIncludes.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 | |
---|
40 | namespace orxonox |
---|
41 | { |
---|
42 | extern const std::string __CC_fire_name = "fire"; |
---|
43 | extern const std::string __CC_suicide_name = "suicide"; |
---|
44 | |
---|
45 | SetConsoleCommand("StoryModeController", "moveFrontBack", &StoryModeController::moveFrontBack ).addShortcut().setAsInputCommand(); |
---|
46 | SetConsoleCommand("StoryModeController", "moveRightLeft", &StoryModeController::moveRightLeft ).addShortcut().setAsInputCommand(); |
---|
47 | SetConsoleCommand("StoryModeController", "moveUpDown", &StoryModeController::moveUpDown ).addShortcut().setAsInputCommand(); |
---|
48 | SetConsoleCommand("StoryModeController", "myposition", &StoryModeController::myposition ).addShortcut(); |
---|
49 | |
---|
50 | RegisterUnloadableClass(StoryModeController); |
---|
51 | |
---|
52 | StoryModeController* StoryModeController::localController_s = nullptr; |
---|
53 | |
---|
54 | StoryModeController::StoryModeController(Context* context) : FormationController(context) |
---|
55 | { |
---|
56 | RegisterObject(StoryModeController); |
---|
57 | |
---|
58 | this->controlPaused_ = false; |
---|
59 | StoryModeController::localController_s = this; |
---|
60 | } |
---|
61 | |
---|
62 | StoryModeController::~StoryModeController() |
---|
63 | { |
---|
64 | if (StoryModeController::localController_s) |
---|
65 | { |
---|
66 | StoryModeController::localController_s->removeFromFormation(); |
---|
67 | } |
---|
68 | StoryModeController::localController_s = nullptr; |
---|
69 | } |
---|
70 | |
---|
71 | void StoryModeController::tick(float dt) |
---|
72 | { |
---|
73 | if (GameMode::playsSound() && StoryModeController::localController_s && StoryModeController::localController_s->controllableEntity_) |
---|
74 | { |
---|
75 | Camera* camera = StoryModeController::localController_s->controllableEntity_->getCamera(); |
---|
76 | if (!camera) |
---|
77 | orxout(internal_warning) << "StoryModeController, Warning: Using a ControllableEntity without Camera" << endl; |
---|
78 | } |
---|
79 | |
---|
80 | // commandslaves when Master of a formation |
---|
81 | if (StoryModeController::localController_s && StoryModeController::localController_s->state_==MASTER && FormationController::slaves_.size() > 0) |
---|
82 | { |
---|
83 | if (StoryModeController::localController_s->formationMode_ != ATTACK) |
---|
84 | StoryModeController::localController_s->commandSlaves(); |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | void StoryModeController::moveFrontBack(const Vector2& value) |
---|
89 | { |
---|
90 | if (StoryModeController::localController_s) |
---|
91 | StoryModeController::localController_s->frontback(value); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | void StoryModeController::moveRightLeft(const Vector2& value) |
---|
96 | { |
---|
97 | if (StoryModeController::localController_s && StoryModeController::localController_s->controllableEntity_) |
---|
98 | StoryModeController::localController_s->controllableEntity_->moveRightLeft(value); |
---|
99 | } |
---|
100 | |
---|
101 | void StoryModeController::moveUpDown(const Vector2& value) |
---|
102 | { |
---|
103 | if (StoryModeController::localController_s && StoryModeController::localController_s->controllableEntity_) |
---|
104 | StoryModeController::localController_s->controllableEntity_->moveUpDown(value); |
---|
105 | } |
---|
106 | |
---|
107 | void StoryModeController::fire(unsigned int firemode) |
---|
108 | { |
---|
109 | if (StoryModeController::localController_s) |
---|
110 | StoryModeController::localController_s->doFire(firemode); |
---|
111 | } |
---|
112 | |
---|
113 | void StoryModeController::doFire(unsigned int firemode) |
---|
114 | { |
---|
115 | if (StoryModeController::localController_s && StoryModeController::localController_s->controllableEntity_) |
---|
116 | { |
---|
117 | StoryModeController::localController_s->controllableEntity_->fire(firemode); |
---|
118 | //if human fires, set slaves free. See FormationController::forceFreeSlaves() |
---|
119 | if (StoryModeController::localController_s->state_==MASTER && StoryModeController::localController_s->formationMode_ == NORMAL) |
---|
120 | { |
---|
121 | StoryModeController::localController_s->forceFreeSlaves(); |
---|
122 | } |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | void StoryModeController::myposition() |
---|
128 | { |
---|
129 | if (StoryModeController::localController_s && StoryModeController::localController_s->controllableEntity_) |
---|
130 | { |
---|
131 | const Vector3& position = StoryModeController::localController_s->controllableEntity_->getPosition(); |
---|
132 | const Quaternion& orientation = StoryModeController::localController_s->controllableEntity_->getOrientation(); |
---|
133 | |
---|
134 | orxout(message) << "position=\"" << position.x << ", " << position.y << ", " << position.z << "\" " |
---|
135 | << "orientation=\"" << orientation.w << ", " << orientation.x << ", " << orientation.y << ", " << orientation.z << "\"" << endl; |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | Pawn* StoryModeController::getLocalControllerEntityAsPawn() |
---|
141 | { |
---|
142 | if (StoryModeController::localController_s) |
---|
143 | return orxonox_cast<Pawn*>(StoryModeController::localController_s->getControllableEntity()); |
---|
144 | else |
---|
145 | return nullptr; |
---|
146 | } |
---|
147 | |
---|
148 | void StoryModeController::pauseControl() |
---|
149 | { |
---|
150 | if (StoryModeController::localController_s) |
---|
151 | StoryModeController::localController_s->doPauseControl(); |
---|
152 | } |
---|
153 | |
---|
154 | void NewStoryModeController::doPauseControl() |
---|
155 | { |
---|
156 | this->controlPaused_ = true; |
---|
157 | this->hideOverlays(); |
---|
158 | } |
---|
159 | } |
---|