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_NWN2_MODULE_H
26 #define ENGINES_NWN2_MODULE_H
27 
28 #include <vector>
29 #include <list>
30 #include <map>
31 #include <set>
32 
33 #include "src/common/ptrmap.h"
34 #include "src/common/ustring.h"
35 #include "src/common/changeid.h"
36 
37 #include "src/aurora/ifofile.h"
38 
40 
41 #include "src/events/types.h"
42 
45 
46 namespace Engines {
47 
48 class Console;
49 
50 namespace NWN2 {
51 
52 class Area;
53 class Creature;
54 
55 class Module : public NWN2::Object, public NWN2::ObjectContainer {
56 public:
57  Module(::Engines::Console &console);
58  ~Module();
59 
60  // .--- Module management
62  bool isLoaded() const;
64  bool isRunning() const;
65  // '---
66 
67  // .--- Information about the current module
69  const Aurora::IFOFile &getIFO() const;
70 
72  const Common::UString &getName() const;
74  const Common::UString &getDescription() const;
75  // '---
76 
77  // .--- Elements of the current module
81  Creature *getPC();
82  // '---
83 
84  void delayScript(const Common::UString &script,
85  const Aurora::NWScript::ScriptState &state,
87  uint32 delay);
88 
89  // .--- PC management
91  void movePC(const Common::UString &area);
93  void movePC(float x, float y, float z);
95  void movePC(const Common::UString &area, float x, float y, float z);
97  void movePC(Area *area, float x, float y, float z);
99  void movedPC();
100  // '---
101 
102  // .--- Static utility methods
103  static Common::UString getName(const Common::UString &module);
104  static Common::UString getDescription(const Common::UString &module);
105  // '---
106 
107  // .--- Module main loop (called by the Campaign class)
109  void clear();
110 
112  void load(const Common::UString &module);
114  void exit();
115 
117  void enter(Creature &pc, bool isNewCampaign = true);
119  void leave();
120 
122  void addEvent(const Events::Event &event);
124  void processEventQueue();
125  // '---
126 
127 private:
128  enum ActionType {
131  };
132 
133  struct Action {
135 
137 
141 
143 
144  bool operator<(const Action &s) const;
145  };
146 
148 
149  typedef std::list<Events::Event> EventQueue;
150  typedef std::multiset<Action> ActionQueue;
151 
152 
154 
155  bool _hasModule;
156  bool _running;
157  bool _exit;
158 
163 
165  std::vector<Common::ChangeID> _resHAKs;
166 
168 
171 
175 
176  bool _ranPCSpawn;
177 
179 
182 
183 
184  // .--- Unloading
185  void unload();
186 
187  void unloadModule();
188  void unloadPC();
189  void unloadTLK();
190  void unloadHAKs();
191  void unloadAreas();
192  // '---
193 
194  // .--- Loading
195  void checkXPs();
196  void checkHAKs();
197 
198  void loadTLK();
199  void loadHAKs();
200  void loadAreas();
201  // '---
202 
203  void enterArea();
204 
206  void loadModule(const Common::UString &module);
208  void changeModule(const Common::UString &module);
210  void replaceModule();
211 
212  void handleEvents();
213 
214  void handleActions();
215 };
216 
217 } // End of namespace NWN2
218 
219 } // End of namespace Engines
220 
221 #endif // ENGINES_NWN2_MODULE_H
Basic event types.
Creature * _pc
The player character we use.
Definition: module.h:170
void unloadHAKs()
Unload the HAKs required by the module.
Definition: module.cpp:381
EventQueue _eventQueue
Definition: module.h:180
Module(::Engines::Console &console)
Definition: module.cpp:58
std::list< Events::Event > EventQueue
Definition: module.h:149
bool isLoaded() const
Is a module currently loaded and ready to run?
Definition: module.cpp:82
A map storing pointer to objects, with automatic deletion.
A class holding an UTF-8 string.
Definition: ustring.h:48
void leave()
Leave the running module, quitting it.
Definition: module.cpp:235
An area in Neverwinter Nights 2, holding all objects, room tiles and terrain within, as well as general area properties like the current background music and ambient sounds.
Definition: area.h:65
bool _ranPCSpawn
Did we run the PC spawn script?
Definition: module.h:176
void delayScript(const Common::UString &script, const Aurora::NWScript::ScriptState &state, Aurora::NWScript::Object *owner, Aurora::NWScript::Object *triggerer, uint32 delay)
Definition: module.cpp:496
void addEvent(const Events::Event &event)
Add a single event for consideration into the event queue.
Definition: module.cpp:244
void loadAreas()
Load the areas.
Definition: module.cpp:389
void processEventQueue()
Process the current event queue.
Definition: module.cpp:248
void unloadModule()
Unload the module.
Definition: module.cpp:344
std::vector< Common::ChangeID > _resHAKs
Resources added by the HAKs of the module.
Definition: module.h:165
Common::UString script
Definition: module.h:136
An object within a NWN2 area.
Definition: object.h:58
Aurora::NWScript::ObjectReference triggerer
Definition: module.h:140
void load(const Common::UString &module)
Load a module.
Definition: module.cpp:90
void loadModule(const Common::UString &module)
Load the actual module.
Definition: module.cpp:102
Area * _currentArea
The current area.
Definition: module.h:174
SDL_Event Event
Definition: types.h:42
bool operator<(const Action &s) const
Definition: module.cpp:53
const Common::UString & getName() const
Return the module&#39;s name.
Definition: module.cpp:488
std::multiset< Action > ActionQueue
Definition: module.h:150
Aurora::NWScript::ScriptState state
Definition: module.h:138
A container of Neverwinter Nights 2 objects.
Loader for the module.ifo file.
Helper class to represent an undoable change.
An IFO (module information) file, describing global module properties in many Aurora games...
Definition: ifofile.h:69
void loadHAKs()
Load the HAKs required by the module.
Definition: module.cpp:372
void unload()
Unload the whole shebang.
Definition: module.cpp:336
bool _exit
Should we exit the module?
Definition: module.h:157
void exit()
Exit the currently running module.
Common::UString _newArea
The new area to enter.
Definition: module.h:173
void unloadTLK()
Unload the TLK used by the module.
Definition: module.cpp:368
Common::UString _newModule
The module we should change to.
Definition: module.h:178
void movePC(const Common::UString &area)
Move the player character to this area.
Definition: module.cpp:428
virtual void enter()
The cursor entered the object.
Definition: object.cpp:169
void replaceModule()
Actually replace the currently running module.
Definition: module.cpp:161
void clear()
Clear the whole context.
Definition: module.cpp:70
Unicode string handling.
Common::PtrMap< Common::UString, Area > AreaMap
Definition: module.h:147
Common::ChangeID _resTLK
Resources added for the custom TLK.
Definition: module.h:162
Reference to an NWScript object.
void loadTLK()
Load the TLK used by the module.
Definition: module.cpp:361
Aurora::IFOFile _ifo
The module&#39;s IFO.
Definition: module.h:167
void unloadPC()
Unload the PC.
Definition: module.cpp:418
A class representing an undoable change.
Definition: changeid.h:35
uint32_t uint32
Definition: types.h:204
AreaMap _areas
The areas in the current module.
Definition: module.h:172
Area * getCurrentArea()
Return the area the PC is currently in.
Definition: module.cpp:74
void unloadAreas()
Unload the areas.
Definition: module.cpp:411
An object in a Neverwinter Nights 2 area.
bool _running
Are we currently running a module?
Definition: module.h:156
bool isRunning() const
Is a module currently running?
Definition: module.cpp:86
::Engines::Console * _console
Definition: module.h:153
ActionQueue _delayedActions
Definition: module.h:181
bool _hasModule
Do we have a module?
Definition: module.h:155
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:78
void checkHAKs()
Do we have all HAKs needed for the module?
Definition: module.cpp:149
const Aurora::IFOFile & getIFO() const
Return the IFO of the currently loaded module.
Definition: module.cpp:484
Common::ChangeID _resModule
Resources added by the module.
Definition: module.h:160
Aurora::NWScript::ObjectReference owner
Definition: module.h:139
void checkXPs()
Do we have all expansions needed for the module?
Definition: module.cpp:135
void changeModule(const Common::UString &module)
Schedule a change to a new module.
Definition: module.cpp:157
const Common::UString & getDescription() const
Return the module&#39;s description.
Definition: module.cpp:492
void movedPC()
Notify the module that the PC was moved.
Definition: module.cpp:468
void enterArea()
Enter a new area.
Definition: module.cpp:262