/
module.h
324 lines (251 loc) · 9.21 KB
/
module.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file
* The context needed to run a Star Wars: Knights of the Old Republic module.
*/
#ifndef ENGINES_KOTOR_MODULE_H
#define ENGINES_KOTOR_MODULE_H
#include <list>
#include <set>
#include "src/common/scopedptr.h"
#include "src/common/ustring.h"
#include "src/common/changeid.h"
#include "src/common/configman.h"
#include "src/aurora/ifofile.h"
#include "src/aurora/nwscript/objectref.h"
#include "src/graphics/aurora/fadequad.h"
#include "src/events/types.h"
#include "src/engines/kotor/objectcontainer.h"
#include "src/engines/kotor/object.h"
#include "src/engines/kotor/savedgame.h"
namespace Engines {
class Console;
namespace KotOR {
class Area;
class Creature;
class IngameGUI;
class DialogGUI;
class PartySelectionGUI;
class Module : public KotOR::Object, public KotOR::ObjectContainer {
public:
Module(::Engines::Console &console);
~Module();
/** Clear the whole context. */
void clear();
// .--- Module management
/** Is a module currently loaded and ready to run? */
bool isLoaded() const;
/** Is a module currently running? */
bool isRunning() const;
/** Load a module. */
void load(const Common::UString &module, const Common::UString &entryLocation = "",
ObjectType entryLocationType = kObjectTypeAll);
/** Load texture pack used by the module. */
void loadTexturePack();
/** Use this character as the player character. */
void usePC(Creature *pc);
/** Exit the currently running module. */
void exit();
// '---
// .--- Information about the current module
/** Return the IFO of the currently loaded module. */
const Aurora::IFOFile &getIFO() const;
/** Return the module's name. */
const Common::UString &getName() const;
// '---
// .--- Elements of the current module
/** Return the area the PC is currently in. */
Area *getCurrentArea();
/** Return the currently playing PC. */
Creature *getPC();
/** Return the fade quad. */
Graphics::Aurora::FadeQuad &getFadeQuad();
// '---
// .--- Interact with the current module
/** Show the ingame main menu. */
void showMenu();
// '---
void delayScript(const Common::UString &script,
const Aurora::NWScript::ScriptState &state,
Aurora::NWScript::Object *owner, Aurora::NWScript::Object *triggerer,
uint32 delay);
// .--- PC management
/** Move the player character to this position within the current area. */
void movePC(float x, float y, float z);
/** Move the player character to this object within this area. */
void movePC(const Common::UString &module, const Common::UString &object, ObjectType type = kObjectTypeAll);
/** Notify the module that the PC was moved. */
void movedPC();
// '---
// .--- Party Management
/** Get the count of party members. */
size_t getPartyMemberCount();
/** Add a creature to the party. */
void addToParty(Creature *creature);
/** Check if the specified creature is a party member. */
bool isObjectPartyMember(Creature *creature);
/** Show the party selection GUI. */
void showPartySelectionGUI(const Common::UString &exitScript, int forceNPC1 = -1, int forceNPC2 = -1);
/** Add available party member by template. */
void addAvailablePartyMember(int slot, const Common::UString &templ);
// '---
// .--- Gui management
/** Set the return string for the 'Return to Ebon Hawk' button. */
void setReturnStrref(uint32 id);
/** Set the string for the return dialog */
void setReturnQueryStrref(uint32 id);
/** Enable or disable the 'Return to Ebon Hawk' button. */
void setReturnEnabled(bool enabled);
// '---
// .--- Global values
/** Set a global boolean. */
void setGlobalBoolean(const Common::UString &id, bool value);
/** Get a global boolean. */
bool getGlobalBoolean(const Common::UString &id) const;
/** Get a global number. */
void setGlobalNumber(const Common::UString &id, int value);
/** Set a global number. */
int getGlobalNumber(const Common::UString &id) const;
// '---
// .--- Static utility methods
static Common::UString getName(const Common::UString &module);
// '---
// .--- Module main loop (called by the Game class)
/** Enter the loaded module, starting it. */
void enter();
/** Leave the running module, quitting it. */
void leave();
/** Open the inventory of a container. */
void clickObject(Object *object);
/** Add a single event for consideration into the event queue. */
void addEvent(const Events::Event &event);
/** Process the current event queue. */
void processEventQueue();
// '---
void toggleFreeRoamCamera();
void toggleWalkmesh();
void toggleTriggers();
void loadSavedGame(SavedGame *save);
void startConversation(const Common::UString &name, Aurora::NWScript::Object *owner = 0);
void playAnimationOnActiveObject(const Common::UString &baseAnim,
const Common::UString &headAnim);
void addItemToActiveObject(const Common::UString &item, int count);
private:
enum ActionType {
kActionNone = 0,
kActionScript = 1
};
struct Action {
ActionType type;
Common::UString script;
Aurora::NWScript::ScriptState state;
Aurora::NWScript::ObjectReference owner;
Aurora::NWScript::ObjectReference triggerer;
uint32 timestamp;
bool operator<(const Action &s) const;
};
typedef std::list<Events::Event> EventQueue;
typedef std::multiset<Action> ActionQueue;
::Engines::Console *_console;
bool _hasModule; ///< Do we have a module?
bool _running; ///< Are we currently running a module?
/** Resources added by the current module. */
std::list<Common::ChangeID> _resources;
/** The current module's IFO. */
Aurora::IFOFile _ifo;
Common::ScopedPtr<Creature> _pc; ///< The player character we use.
/** The current texture pack. */
int _currentTexturePack;
/** Resources added by the current texture pack. */
Common::ChangeID _textures;
bool _exit; ///< Should we exit the module?
Common::UString _module; ///< The current module's name.
Common::UString _newModule; ///< The module we should change to.
/** The tag of the object in the start location for this module. */
Common::UString _entryLocation;
/** The type(s) of the object in the start location for this module. */
ObjectType _entryLocationType;
Common::ScopedPtr<Area> _area; ///< The current module's area.
Common::ScopedPtr<Graphics::Aurora::FadeQuad> _fade;
Common::ScopedPtr<IngameGUI> _ingame; ///< The ingame ui.
Common::ScopedPtr<DialogGUI> _dialog; ///< Conversation/cutscene GUI.
Common::ScopedPtr<PartySelectionGUI> _partySelection;
// .--- Global values
std::map<Common::UString, bool> _globalBooleans;
std::map<Common::UString, int> _globalNumbers;
// '---
// .--- Party
std::list<Creature *> _party;
std::map<int, Common::UString> _availableParty;
// '---
EventQueue _eventQueue;
ActionQueue _delayedActions;
bool _freeCamEnabled;
uint32 _prevTimestamp;
float _frameTime;
float _forwardBtnPressed;
float _backwardsBtnPressed;
bool _pcRunning;
bool _pcPositionLoaded;
bool _inDialog;
float _cameraHeight;
// .--- Unloading
/** Unload the whole shebang.
*
* @param completeUnload Also unload the PC and texture packs.
* true: completely quit the module
* false: the PC can be transferred to a new module.
*/
void unload(bool completeUnload = true);
void unloadResources();
void unloadPC();
void unloadIFO();
void unloadArea();
void unloadTexturePack();
// '---
// .--- Loading
void load();
void loadResources();
void loadIFO();
void loadArea();
// '---
/** Load the actual module. */
void loadModule(const Common::UString &module, const Common::UString &entryLocation,
ObjectType entryLocationType);
/** Schedule a change to a new module. */
void changeModule(const Common::UString &module, const Common::UString &entryLocation,
ObjectType entryLocationType);
/** Actually replace the currently running module. */
void replaceModule();
bool getObjectLocation(const Common::UString &object, ObjectType location,
float &entryX, float &entryY, float &entryZ, float &entryAngle);
bool getEntryObjectLocation(float &entryX, float &entryY, float &entryZ, float &entryAngle);
void getEntryIFOLocation(float &entryX, float &entryY, float &entryZ, float &entryAngle);
void enterArea();
void leaveArea();
void handleEvents();
void handleActions();
void handlePCMovement();
void stopCameraMovement();
void stopPCMovement();
};
} // End of namespace KotOR
} // End of namespace Engines
#endif // ENGINES_KOTOR_MODULE_H