xoreos  0.0.5
module.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef ENGINES_KOTOR_MODULE_H
26 #define ENGINES_KOTOR_MODULE_H
27 
28 #include <list>
29 #include <set>
30 
31 #include "src/common/scopedptr.h"
32 #include "src/common/ustring.h"
33 #include "src/common/changeid.h"
34 #include "src/common/configman.h"
35 
36 #include "src/aurora/ifofile.h"
37 
39 
41 
42 #include "src/events/types.h"
43 
47 
48 namespace Engines {
49 
50 class Console;
51 
52 namespace KotOR {
53 
54 class Area;
55 class Creature;
56 class IngameGUI;
57 class DialogGUI;
58 class PartySelectionGUI;
59 
61 public:
62  Module(::Engines::Console &console);
63  ~Module();
64 
66  void clear();
67 
68  // .--- Module management
70  bool isLoaded() const;
72  bool isRunning() const;
73 
75  void load(const Common::UString &module, const Common::UString &entryLocation = "",
76  ObjectType entryLocationType = kObjectTypeAll);
78  void loadTexturePack();
80  void usePC(Creature *pc);
82  void exit();
83  // '---
84 
85  // .--- Information about the current module
87  const Aurora::IFOFile &getIFO() const;
88 
90  const Common::UString &getName() const;
91  // '---
92 
93  // .--- Elements of the current module
97  Creature *getPC();
100  // '---
101 
102  // .--- Interact with the current module
104  void showMenu();
105  // '---
106 
107  void delayScript(const Common::UString &script,
108  const Aurora::NWScript::ScriptState &state,
110  uint32 delay);
111 
112  // .--- PC management
114  void movePC(float x, float y, float z);
116  void movePC(const Common::UString &module, const Common::UString &object, ObjectType type = kObjectTypeAll);
118  void movedPC();
119  // '---
120 
121  // .--- Party Management
123  size_t getPartyMemberCount();
125  void addToParty(Creature *creature);
127  bool isObjectPartyMember(Creature *creature);
129  Creature *getPartyMember(int index);
131  void switchPlayerCharacter(int npc);
133  void showPartySelectionGUI(int forceNPC1, int forceNPC2);
135  void addAvailablePartyMember(int slot, const Common::UString &templ);
137  bool isAvailableCreature(int slot);
138  // '---
139 
140  // .--- Gui management
142  void setReturnStrref(uint32 id);
144  void setReturnQueryStrref(uint32 id);
146  void setReturnEnabled(bool enabled);
147  // '---
148 
149  // .--- Global values
151  void setGlobalBoolean(const Common::UString &id, bool value);
153  bool getGlobalBoolean(const Common::UString &id) const;
155  void setGlobalNumber(const Common::UString &id, int value);
157  int getGlobalNumber(const Common::UString &id) const;
158  // '---
159 
160  // .--- Static utility methods
161  static Common::UString getName(const Common::UString &module);
162  // '---
163 
164  // .--- Module main loop (called by the Game class)
166  void enter();
168  void leave();
169 
171  void clickObject(Object *object);
172 
174  void addEvent(const Events::Event &event);
176  void processEventQueue();
177  // '---
178 
179  void toggleFreeRoamCamera();
180  void toggleWalkmesh();
181  void toggleTriggers();
182  void loadSavedGame(SavedGame *save);
183  void startConversation(const Common::UString &name, Aurora::NWScript::Object *owner = 0);
184 
185  void playAnimationOnActiveObject(const Common::UString &baseAnim,
186  const Common::UString &headAnim);
187 
188  void addItemToActiveObject(const Common::UString &item, int count);
189 
190 private:
191  enum ActionType {
194  };
195 
196  struct Action {
198 
200 
204 
206 
207  bool operator<(const Action &s) const;
208  };
209 
210  typedef std::list<Events::Event> EventQueue;
211  typedef std::multiset<Action> ActionQueue;
212 
213 
215 
216  bool _hasModule;
217  bool _running;
218 
220  std::list<Common::ChangeID> _resources;
221 
224 
226 
231 
232  bool _exit;
233 
236 
241 
243 
245 
247 
249 
251 
252  // .--- Global values
253  std::map<Common::UString, bool> _globalBooleans;
254  std::map<Common::UString, int> _globalNumbers;
255  // '---
256 
257  // .--- Party
258  std::list<Creature *> _party;
259  std::map<int, Common::UString> _availableParty;
260  // '---
261 
264 
267  float _frameTime;
272  bool _inDialog;
274 
275 
276  // .--- Unloading
283  void unload(bool completeUnload = true);
284 
285  void unloadResources();
286  void unloadPC();
287  void unloadIFO();
288  void unloadArea();
289  void unloadTexturePack();
290  // '---
291 
292  // .--- Loading
293  void load();
294 
295  void loadResources();
296  void loadIFO();
297  void loadArea();
298  // '---
299 
301  void loadModule(const Common::UString &module, const Common::UString &entryLocation,
302  ObjectType entryLocationType);
304  void changeModule(const Common::UString &module, const Common::UString &entryLocation,
305  ObjectType entryLocationType);
307  void replaceModule();
308 
309  bool getObjectLocation(const Common::UString &object, ObjectType location,
310  float &entryX, float &entryY, float &entryZ, float &entryAngle);
311  bool getEntryObjectLocation(float &entryX, float &entryY, float &entryZ, float &entryAngle);
312  void getEntryIFOLocation(float &entryX, float &entryY, float &entryZ, float &entryAngle);
313 
314  void enterArea();
315  void leaveArea();
316 
317  void handleEvents();
318 
319  void handleActions();
320  void handlePCMovement();
321 
322  void stopCameraMovement();
323  void stopPCMovement();
324 };
325 
326 } // End of namespace KotOR
327 
328 } // End of namespace Engines
329 
330 #endif // ENGINES_KOTOR_MODULE_H
The Quad to handle one color fades.
Basic event types.
void addToParty(Creature *creature)
Add a creature to the party.
Definition: module.cpp:740
void delayScript(const Common::UString &script, const Aurora::NWScript::ScriptState &state, Aurora::NWScript::Object *owner, Aurora::NWScript::Object *triggerer, uint32 delay)
Definition: module.cpp:911
std::map< Common::UString, int > _globalNumbers
Definition: module.h:254
void setGlobalNumber(const Common::UString &id, int value)
Get a global number.
Definition: module.cpp:887
void loadSavedGame(SavedGame *save)
Definition: module.cpp:977
A class holding an UTF-8 string.
Definition: ustring.h:48
Common::UString _module
The current module&#39;s name.
Definition: module.h:234
std::list< Common::ChangeID > _resources
Resources added by the current module.
Definition: module.h:220
void enter()
Enter the loaded module, starting it.
Definition: module.cpp:365
The global config manager.
void addItemToActiveObject(const Common::UString &item, int count)
Definition: module.cpp:1031
bool isRunning() const
Is a module currently running?
Definition: module.cpp:193
bool _running
Are we currently running a module?
Definition: module.h:217
bool operator<(const Action &s) const
Definition: module.cpp:70
Module(::Engines::Console &console)
Definition: module.cpp:75
ObjectType
Object type, matches the bitfield in nwscript.nss.
Definition: types.h:33
void processEventQueue()
Process the current event queue.
Definition: module.cpp:529
void setReturnQueryStrref(uint32 id)
Set the string for the return dialog.
Definition: module.cpp:867
void showMenu()
Show the ingame main menu.
Definition: module.cpp:201
std::multiset< Action > ActionQueue
Definition: module.h:211
std::list< Events::Event > EventQueue
Definition: module.h:210
Common::UString _entryLocation
The tag of the object in the start location for this module.
Definition: module.h:238
std::list< Creature * > _party
Definition: module.h:258
A simple scoped smart pointer template.
SDL_Event Event
Definition: types.h:42
void changeModule(const Common::UString &module, const Common::UString &entryLocation, ObjectType entryLocationType)
Schedule a change to a new module.
Definition: module.cpp:338
const Aurora::IFOFile & getIFO() const
Return the IFO of the currently loaded module.
Definition: module.cpp:899
void setReturnStrref(uint32 id)
Set the return string for the &#39;Return to Ebon Hawk&#39; button.
Definition: module.cpp:863
EventQueue _eventQueue
Definition: module.h:262
std::map< Common::UString, bool > _globalBooleans
Definition: module.h:253
void loadModule(const Common::UString &module, const Common::UString &entryLocation, ObjectType entryLocationType)
Load the actual module.
Definition: module.cpp:124
Common::ChangeID _textures
Resources added by the current texture pack.
Definition: module.h:230
Aurora::NWScript::ObjectReference triggerer
Definition: module.h:203
void replaceModule()
Actually replace the currently running module.
Definition: module.cpp:347
void toggleFreeRoamCamera()
Definition: module.cpp:963
Loader for the module.ifo file.
Common::UString script
Definition: module.h:199
Common::ScopedPtr< DialogGUI > _dialog
Conversation/cutscene GUI.
Definition: module.h:248
void switchPlayerCharacter(int npc)
Switch the player character.
Definition: module.cpp:773
Helper class to represent an undoable change.
A container of Star Wars: Knights of the Old Republic objects.
An IFO (module information) file, describing global module properties in many Aurora games...
Definition: ifofile.h:69
Common::ScopedPtr< Graphics::Aurora::FadeQuad > _fade
Definition: module.h:244
Aurora::NWScript::ScriptState state
Definition: module.h:201
const Common::UString & getName() const
Return the module&#39;s name.
Definition: module.cpp:903
ObjectType _entryLocationType
The type(s) of the object in the start location for this module.
Definition: module.h:240
void unload(bool completeUnload=true)
Unload the whole shebang.
Definition: module.cpp:280
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
Aurora::NWScript::ObjectReference owner
Definition: module.h:202
An area in Star Wars: Knights of the Old Republic, holding all objects and rooms within, as well as general area properties like the current background music and ambient sounds.
Definition: area.h:65
void startConversation(const Common::UString &name, Aurora::NWScript::Object *owner=0)
Definition: module.cpp:987
Graphics::Aurora::FadeQuad & getFadeQuad()
Return the fade quad.
Definition: module.cpp:185
Aurora::IFOFile _ifo
The current module&#39;s IFO.
Definition: module.h:223
void getEntryIFOLocation(float &entryX, float &entryY, float &entryZ, float &entryAngle)
Definition: module.cpp:456
void setReturnEnabled(bool enabled)
Enable or disable the &#39;Return to Ebon Hawk&#39; button.
Definition: module.cpp:871
void addEvent(const Events::Event &event)
Add a single event for consideration into the event queue.
Definition: module.cpp:525
Unicode string handling.
bool getEntryObjectLocation(float &entryX, float &entryY, float &entryZ, float &entryAngle)
Definition: module.cpp:452
void movePC(float x, float y, float z)
Move the player character to this position within the current area.
Definition: module.cpp:695
void addAvailablePartyMember(int slot, const Common::UString &templ)
Add available party member by template.
Definition: module.cpp:851
void clear()
Clear the whole context.
Definition: module.cpp:106
Reference to an NWScript object.
void loadTexturePack()
Load texture pack used by the module.
Definition: module.cpp:260
std::map< int, Common::UString > _availableParty
Definition: module.h:259
bool isAvailableCreature(int slot)
Check if there is a party member available for this id.
Definition: module.cpp:859
Common::ScopedPtr< IngameGUI > _ingame
The ingame ui.
Definition: module.h:246
A class representing an undoable change.
Definition: changeid.h:35
bool getGlobalBoolean(const Common::UString &id) const
Get a global boolean.
Definition: module.cpp:879
uint32_t uint32
Definition: types.h:204
void playAnimationOnActiveObject(const Common::UString &baseAnim, const Common::UString &headAnim)
Definition: module.cpp:1014
void setGlobalBoolean(const Common::UString &id, bool value)
Set a global boolean.
Definition: module.cpp:875
bool isLoaded() const
Is a module currently loaded and ready to run?
Definition: module.cpp:189
bool _hasModule
Do we have a module?
Definition: module.h:216
An object in a Star Wars: Knights of the Old Republic area.
void usePC(Creature *pc)
Use this character as the player character.
Definition: module.cpp:177
float _forwardBtnPressed
Definition: module.h:268
bool isObjectPartyMember(Creature *creature)
Check if the specified creature is a party member.
Definition: module.cpp:760
Common::ScopedPtr< PartySelectionGUI > _partySelection
Definition: module.h:250
ActionQueue _delayedActions
Definition: module.h:263
Common::UString _newModule
The module we should change to.
Definition: module.h:235
Area * getCurrentArea()
Return the area the PC is currently in.
Definition: module.cpp:907
Creature * getPartyMember(int index)
Get a party member by index.
Definition: module.cpp:764
int getGlobalNumber(const Common::UString &id) const
Set a global number.
Definition: module.cpp:891
bool _exit
Should we exit the module?
Definition: module.h:232
void movedPC()
Notify the module that the PC was moved.
Definition: module.cpp:716
void leave()
Leave the running module, quitting it.
Definition: module.cpp:465
void clickObject(Object *object)
Open the inventory of a container.
Definition: module.cpp:498
Common::ScopedPtr< Creature > _pc
The player character we use.
Definition: module.h:225
::Engines::Console * _console
Definition: module.h:214
Common::ScopedPtr< Area > _area
The current module&#39;s area.
Definition: module.h:242
Creation and loading of KotOR saved games.
bool getObjectLocation(const Common::UString &object, ObjectType location, float &entryX, float &entryY, float &entryZ, float &entryAngle)
Definition: module.cpp:425
void showPartySelectionGUI(int forceNPC1, int forceNPC2)
Show the party selection GUI.
Definition: module.cpp:802
void exit()
Exit the currently running module.
Definition: module.cpp:197
size_t getPartyMemberCount()
Get the count of party members.
Definition: module.cpp:736
int _currentTexturePack
The current texture pack.
Definition: module.h:228
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:181
float _backwardsBtnPressed
Definition: module.h:269