ScummVM API documentation
world.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA8_WORLD_WORLD_H
23 #define ULTIMA8_WORLD_WORLD_H
24 
25 // the main world class.
26 
27 // Current ideas on how to store the game world: (-wjp)
28 
29 // World contains Map objects. All Map objects are initialized when
30 // starting/loading a game.
31 
32 // Each Map permanently contains the nonfixed objects in that map,
33 // ( These objects don't have to be assigned object IDs here, I think )
34 
35 // When a Map is loaded, it loads the fixed objects from disk.
36 // All objects in the active map will also have to be assigned object IDs.
37 // NB: This has to happen in such a way that when a game is loaded the IDs can
38 // be reproduced exactly. (Since running usecode scripts can contain objIDs)
39 // The first N objIDs will probably be reserved from NPCs (and inventories?)
40 // After that, for example, the fixed objects could be loaded (in disk-order),
41 // followed by assigning IDs to the (already loaded) dynamic items.
42 // (in basic depth-first order, I would guess)
43 
44 // NPCs will also have to be stored somewhere. We could keep them in Map #0
45 // like the original.
46 // Q: Is the avatar's inventory stored in npcdata?
47 // Q: Is the number of objIDs reserved for npcdata fixed?
48 
49 // World also has to have the necessary save/load functions. (Which will
50 // mostly consist of calls to the save/load functions of the Map objects.)
51 
52 // Fixed objects could be kept cached in for better performance, or
53 // swapped out for memory.
54 
55 // A clear/reset function would also be useful. (All singletons that store
56 // game data need this, actually.)
57 
58 #include "ultima/ultima8/misc/common_types.h"
59 #include "ultima/ultima8/usecode/intrinsics.h"
60 #include "ultima/shared/std/containers.h"
61 
62 namespace Ultima {
63 namespace Ultima8 {
64 
65 class Map;
66 class CurrentMap;
67 class Actor;
68 class MainActor;
69 class Flex;
70 class Item;
71 
72 class World {
73 public:
74  World();
75  ~World();
76 
77  static World *get_instance() {
78  return _world;
79  }
80 
82  void clear();
83 
85  void reset();
86 
88  void initMaps();
89 
91  void loadNonFixed(Common::SeekableReadStream *rs); // delete ds afterwards
92 
95 
98  return _currentMap;
99  }
100 
104  bool switchMap(uint32 newmap);
105 
107  void etherealPush(ObjId objid) {
108  _ethereal.push_front(objid);
109  }
110 
112  bool etherealEmpty() const {
113  return _ethereal.empty();
114  }
115 
117  ObjId etherealPeek() const {
118  return _ethereal.front();
119  }
120 
122  void etherealRemove(ObjId objid) {
123  _ethereal.remove(objid);
124  }
125 
127  void worldStats() const;
128 
130  void saveMaps(Common::WriteStream *ws);
131 
133  bool loadMaps(Common::ReadStream *rs, uint32 version);
134 
136  void save(Common::WriteStream *ws);
137 
139  bool load(Common::ReadStream *rs, uint32 version);
140 
141  bool isAlertActive() const {
142  return _alertActive;
143  }
144 
145  void setAlertActive(bool active);
146 
147  uint8 getGameDifficulty() const {
148  return _difficulty;
149  }
150 
151  void setGameDifficulty(uint8 difficulty);
152 
153  uint16 getControlledNPCNum() const {
154  return _controlledNPCNum;
155  }
156  void setControlledNPCNum(uint16 num);
157 
158  uint32 getVargasShield() const {
159  return _vargasShield;
160  }
161  void setVargasShield(uint32 val) {
162  _vargasShield = val;
163  }
164 
165  INTRINSIC(I_getAlertActive); // for Crusader
166  INTRINSIC(I_setAlertActive); // for Crusader
167  INTRINSIC(I_clrAlertActive); // for Crusader
168  INTRINSIC(I_gameDifficulty); // for Crusader
169  INTRINSIC(I_getControlledNPCNum); // for Crusader
170  INTRINSIC(I_setControlledNPCNum); // for Crusader
171  INTRINSIC(I_resetVargasShield); // for Crusader: No Remorse
172 
173 private:
174 
175  void setAlertActiveRemorse(bool active);
176  void setAlertActiveRegret(bool active);
177 
178  static World *_world;
179 
180  Std::vector<Map *> _maps;
181  CurrentMap *_currentMap;
182 
183  Std::list<ObjId> _ethereal;
184 
185  bool _alertActive;
186  uint8 _difficulty;
187  uint16 _controlledNPCNum;
188 
193  uint32 _vargasShield;
194 
195 };
196 
197 } // End of namespace Ultima8
198 } // End of namespace Ultima
199 
200 #endif
void reset()
reset the world (clear everything and re-initialize maps)
void loadNonFixed(Common::SeekableReadStream *rs)
load U8&#39;s nonfixed.dat into the Maps
Definition: stream.h:77
CurrentMap * getCurrentMap() const
get the CurrentMap
Definition: world.h:97
bool switchMap(uint32 newmap)
Definition: stream.h:745
void saveMaps(Common::WriteStream *ws)
save the Maps in World.
void push_front(const t_T &element)
Definition: list.h:135
void clear()
clear the world (maps, currentmap, ethereal items)
Definition: detection.h:27
Definition: world.h:72
bool etherealEmpty() const
check if the ethereal void is empty
Definition: world.h:112
void worldStats() const
output some statistics about the world
void initMaps()
create (empty) maps, currentmap
void remove(const t_T &val)
Definition: list.h:125
t_T & front()
Definition: list.h:157
Definition: stream.h:385
bool load(Common::ReadStream *rs, uint32 version)
load World data
void etherealRemove(ObjId objid)
remove an item from the ethereal void
Definition: world.h:122
void loadItemCachNPCData(Common::SeekableReadStream *itemcach, Common::SeekableReadStream *npcdata)
load U8&#39;s itemcach.dat, npcdata.dat into the world
Definition: current_map.h:44
bool empty() const
Definition: list.h:219
bool loadMaps(Common::ReadStream *rs, uint32 version)
load Maps
Definition: containers.h:38
ObjId etherealPeek() const
return (but don&#39;t remove) the top item from the ethereal void
Definition: world.h:117
void etherealPush(ObjId objid)
push an item onto the ethereal void
Definition: world.h:107
void save(Common::WriteStream *ws)
save the rest of the World data (ethereal items, current map number).