… | |
… | |
26 | * It contains pointers (very indirectly) to all objects on the map. |
26 | * It contains pointers (very indirectly) to all objects on the map. |
27 | */ |
27 | */ |
28 | |
28 | |
29 | #ifndef MAP_H |
29 | #ifndef MAP_H |
30 | #define MAP_H |
30 | #define MAP_H |
|
|
31 | |
|
|
32 | #include <tr1/unordered_map> |
31 | |
33 | |
32 | #include "cfperl.h" |
34 | #include "cfperl.h" |
33 | |
35 | |
34 | /* We set this size - this is to make magic map work properly on |
36 | /* We set this size - this is to make magic map work properly on |
35 | * tiled maps. There is no requirement that this matches the |
37 | * tiled maps. There is no requirement that this matches the |
… | |
… | |
155 | if (op->type == PLAYER) |
157 | if (op->type == PLAYER) |
156 | return op; |
158 | return op; |
157 | |
159 | |
158 | return 0; |
160 | return 0; |
159 | } |
161 | } |
160 | }; |
|
|
161 | |
|
|
162 | /* |
|
|
163 | * this is an overlay structure of the whole world. It exists as a simple |
|
|
164 | * high level map, which doesn't contain the full data of the underlying map. |
|
|
165 | * in this map, only things such as weather are recorded. By doing so, we |
|
|
166 | * can keep the entire world parameters in memory, and act as a whole on |
|
|
167 | * them at once. We can then, in a separate loop, update the actual world |
|
|
168 | * with the new values we have assigned. |
|
|
169 | */ |
|
|
170 | |
|
|
171 | struct weathermap_t |
|
|
172 | { |
|
|
173 | sint16 temp; /* base temperature of this tile (F) */ |
|
|
174 | sint16 pressure; /* barometric pressure (mb) */ |
|
|
175 | sint8 humid; /* humitidy of this tile */ |
|
|
176 | sint8 windspeed; /* windspeed of this tile */ |
|
|
177 | sint8 winddir; /* direction of wind */ |
|
|
178 | sint8 sky; /* sky conditions */ |
|
|
179 | sint32 avgelev; /* average elevation */ |
|
|
180 | uint32 rainfall; /* cumulative rainfall */ |
|
|
181 | uint8 darkness; /* indicates level of darkness of map */ |
|
|
182 | uint8 water; /* 0-100 percentage of water tiles */ |
|
|
183 | /*Dynamic parts */ |
|
|
184 | sint16 realtemp; /* temperature at a given calculation step for this tile */ |
|
|
185 | }; |
162 | }; |
186 | |
163 | |
187 | /* |
164 | /* |
188 | * Each map is in a given region of the game world and links to a region definiton, so |
165 | * Each map is in a given region of the game world and links to a region definiton, so |
189 | * they have to appear here in the headers, before the mapdef |
166 | * they have to appear here in the headers, before the mapdef |
… | |
… | |
222 | sint8 strength; /* the degree of specialisation the shop has in this item, |
199 | sint8 strength; /* the degree of specialisation the shop has in this item, |
223 | * as a percentage from -100 to 100 */ |
200 | * as a percentage from -100 to 100 */ |
224 | int index; /* being the size of the shopitems array. */ |
201 | int index; /* being the size of the shopitems array. */ |
225 | }; |
202 | }; |
226 | |
203 | |
|
|
204 | // map I/O, what to load/save |
|
|
205 | enum { |
|
|
206 | IO_HEADER = 0x01, // the "arch map" pseudo object |
|
|
207 | IO_OBJECTS = 0x02, // the non-unique objects |
|
|
208 | IO_UNIQUES = 0x04, // unique objects |
|
|
209 | }; |
|
|
210 | |
227 | /* In general, code should always use the macros |
211 | /* In general, code should always use the macros |
228 | * above (or functions in map.c) to access many of the |
212 | * above (or functions in map.c) to access many of the |
229 | * values in the map structure. Failure to do this will |
213 | * values in the map structure. Failure to do this will |
230 | * almost certainly break various features. You may think |
214 | * almost certainly break various features. You may think |
231 | * it is safe to look at width and height values directly |
215 | * it is safe to look at width and height values directly |
… | |
… | |
233 | * break map tiling. |
217 | * break map tiling. |
234 | */ |
218 | */ |
235 | INTERFACE_CLASS (maptile) |
219 | INTERFACE_CLASS (maptile) |
236 | struct maptile : zero_initialised, attachable |
220 | struct maptile : zero_initialised, attachable |
237 | { |
221 | { |
238 | sint32 ACC (RO, width), ACC (RO, height); /* Width and height of map. */ |
222 | sint32 ACC (RW, width), ACC (RW, height); /* Width and height of map. */ |
239 | struct mapspace *spaces; /* Array of spaces on this map */ |
223 | struct mapspace *spaces; /* Array of spaces on this map */ |
240 | |
224 | |
241 | maptile *ACC (RW, next); /* Next map, linked list */ |
225 | tstamp ACC (RW, last_access); /* last time this map was accessed somehow */ |
242 | char *ACC (RO, tmpname); /* Name of temporary file */ |
226 | |
243 | char *ACC (RO, name); /* Name of map as given by its creator */ |
227 | shstr ACC (RW, name); /* Name of map as given by its creator */ |
244 | struct region *ACC (RW, region); /* What jurisdiction in the game world this map is ruled by |
228 | struct region *ACC (RW, region); /* What jurisdiction in the game world this map is ruled by |
245 | * points to the struct containing all the properties of |
229 | * points to the struct containing all the properties of |
246 | * the region */ |
230 | * the region */ |
247 | uint32 ACC (RW, reset_time); /* when this map should reset */ |
231 | double ACC (RW, reset_time); |
248 | uint32 ACC (RW, reset_timeout); /* How many seconds must elapse before this map |
232 | uint32 ACC (RW, reset_timeout); /* How many seconds must elapse before this map |
249 | * should be reset |
233 | * should be reset |
250 | */ |
234 | */ |
251 | bool ACC (RW, fixed_resettime); /* if true, reset time is not affected by |
235 | bool ACC (RW, fixed_resettime); /* if true, reset time is not affected by |
252 | * players entering/exiting map |
236 | * players entering/exiting map |
253 | */ |
237 | */ |
254 | bool ACC (RW, unique); /* if set, this is a per player unique map */ |
|
|
255 | bool ACC (RW, templatemap); /* if set, this is a template map */ |
|
|
256 | bool ACC (RW, nosmooth); /* if set the content of this map has smoothlevel=0 forced */ |
|
|
257 | sint32 ACC (RW, timeout); /* swapout is set to this */ |
238 | sint32 ACC (RW, timeout); /* swapout is set to this */ |
258 | sint32 ACC (RW, swap_time); /* When it reaches 0, the map will be swapped out */ |
239 | sint32 ACC (RW, swap_time); /* When it reaches 0, the map will be swapped out */ |
259 | uint32 ACC (RW, in_memory); /* If not true, the map has been freed and must |
240 | uint32 ACC (RW, in_memory); /* If not true, the map has been freed and must |
260 | * be loaded before used. The map,omap and map_ob |
241 | * be loaded before used. The map,omap and map_ob |
261 | * arrays will be allocated when the map is loaded */ |
242 | * arrays will be allocated when the map is loaded */ |
262 | sint16 ACC (RW, players); /* How many players are on this level right now */ |
243 | sint16 ACC (RW, players); /* How many players are on this map right now */ |
263 | uint16 ACC (RW, difficulty); /* What level the player should be to play here */ |
244 | uint16 ACC (RW, difficulty); /* What level the player should be to play here */ |
264 | |
245 | |
|
|
246 | bool ACC (RW, per_player); |
|
|
247 | bool ACC (RW, per_party); |
|
|
248 | bool ACC (RW, outdoor); /* True if an outdoor map */ |
265 | uint8 ACC (RW, darkness); /* indicates level of darkness of map */ |
249 | uint8 ACC (RW, darkness); /* indicates level of darkness of map */ |
|
|
250 | |
266 | uint16 ACC (RW, enter_x); /* enter_x and enter_y are default entrance location */ |
251 | uint16 ACC (RW, enter_x); /* enter_x and enter_y are default entrance location */ |
267 | uint16 ACC (RW, enter_y); /* on the map if none are set in the exit */ |
252 | uint16 ACC (RW, enter_y); /* on the map if none are set in the exit */ |
268 | bool ACC (RW, outdoor); /* True if an outdoor map */ |
|
|
269 | oblinkpt *buttons; /* Linked list of linked lists of buttons */ |
253 | oblinkpt *buttons; /* Linked list of linked lists of buttons */ |
270 | sint16 ACC (RW, temp); /* base temperature of this tile (F) */ |
254 | sint16 ACC (RW, temp); /* base temperature of this tile (F) */ |
271 | sint16 ACC (RW, pressure); /* barometric pressure (mb) */ |
255 | sint16 ACC (RW, pressure); /* barometric pressure (mb) */ |
272 | sint8 ACC (RW, humid); /* humitidy of this tile */ |
256 | sint8 ACC (RW, humid); /* humitidy of this tile */ |
273 | sint8 ACC (RW, windspeed); /* windspeed of this tile */ |
257 | sint8 ACC (RW, windspeed); /* windspeed of this tile */ |
274 | sint8 ACC (RW, winddir); /* direction of wind */ |
258 | sint8 ACC (RW, winddir); /* direction of wind */ |
275 | sint8 ACC (RW, sky); /* sky conditions */ |
259 | sint8 ACC (RW, sky); /* sky conditions */ |
276 | int ACC (RW, worldpartx), ACC (RW, worldparty); /*Highly fasten conversion between worldmap and weathermap */ |
260 | int ACC (RW, worldpartx), ACC (RW, worldparty); /*Highly fasten conversion between worldmap and weathermap */ |
277 | struct shopitems *shopitems; /* a semi-colon seperated list of item-types the map's shop will trade in */ |
261 | struct shopitems *shopitems; /* a semi-colon seperated list of item-types the map's shop will trade in */ |
278 | char *ACC (RO, shoprace); /* the preffered race of the local shopkeeper */ |
262 | shstr ACC (RW, shoprace); /* the preffered race of the local shopkeeper */ |
279 | double ACC (RW, shopgreed); /* how much our shopkeeper overcharges */ |
263 | double ACC (RW, shopgreed); /* how much our shopkeeper overcharges */ |
280 | sint64 ACC (RW, shopmin); /* minimum price a shop will trade for */ |
264 | sint64 ACC (RW, shopmin); /* minimum price a shop will trade for */ |
281 | sint64 ACC (RW, shopmax); /* maximum price a shop will offer */ |
265 | sint64 ACC (RW, shopmax); /* maximum price a shop will offer */ |
282 | char *ACC (RO, msg); /* Message map creator may have left */ |
266 | shstr ACC (RW, msg); /* Message map creator may have left */ |
283 | char *ACC (RO, maplore); /* Map lore information */ |
267 | shstr ACC (RW, maplore); /* Map lore information */ |
284 | char *tile_path[4]; /* path to adjoining maps */ |
268 | shstr ACC (RW, tile_path[4]); /* path to adjoining maps */ |
285 | maptile *tile_map[4]; /* Next map, linked list */ |
269 | maptile *ACC (RW, tile_map[4]); /* Next map, linked list */ |
286 | char ACC (RW, path)[HUGE_BUF]; /* Filename of the map */ |
270 | shstr ACC (RW, path); /* Filename of the map */ |
|
|
271 | |
|
|
272 | // /* |
|
|
273 | // * Makes sure the given map is loaded and swapped in. |
|
|
274 | // * name is path name of the map. |
|
|
275 | // * flags meaning: |
|
|
276 | // * 0x1 (MAP_FLUSH): flush the map - always load from the map directory, |
|
|
277 | // * and don't do unique items or the like. |
|
|
278 | // * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
|
|
279 | // * dont do any more name translation on it. |
|
|
280 | // * |
|
|
281 | // * Returns a pointer to the given map. |
|
|
282 | // */ |
|
|
283 | // static maptile *ready (const char *name, int flags); |
|
|
284 | |
|
|
285 | MTH void activate (); |
|
|
286 | MTH void deactivate (); |
|
|
287 | |
|
|
288 | // allocates all (empty) mapspace |
|
|
289 | MTH void alloc (); |
|
|
290 | // deallocates the mapspaces (and destroys all objects) |
|
|
291 | MTH void clear (); |
|
|
292 | |
|
|
293 | MTH void fix_auto_apply (); |
|
|
294 | MTH void decay_objects (); |
|
|
295 | MTH void update_buttons (); |
|
|
296 | MTH int change_map_light (int change); |
|
|
297 | static void change_all_map_light (int change); //PERL |
|
|
298 | MTH void set_darkness_map (); |
|
|
299 | MTH int estimate_difficulty () const; |
|
|
300 | |
|
|
301 | MTH void link_multipart_objects (); |
|
|
302 | MTH void clear_unique_items (); |
|
|
303 | |
|
|
304 | MTH void clear_header (); |
|
|
305 | MTH void clear_links_to (maptile *m); |
|
|
306 | |
|
|
307 | // loas the header pseudo-object |
|
|
308 | bool load_header (object_thawer &thawer); |
|
|
309 | MTH bool load_header (const char *path); |
|
|
310 | |
|
|
311 | // load objects into the map |
|
|
312 | bool load_objects (object_thawer &thawer); |
|
|
313 | MTH bool load_objects (const char *path, bool skip_header = true); |
|
|
314 | |
|
|
315 | // save objects into the given file (uses IO_ flags) |
|
|
316 | bool save_objects (object_freezer &freezer, int flags); |
|
|
317 | MTH bool save_objects (const char *path, int flags); |
|
|
318 | |
|
|
319 | // save the header pseudo object _only_ |
|
|
320 | bool save_header (object_freezer &freezer); |
|
|
321 | MTH bool save_header (const char *path); |
287 | |
322 | |
288 | maptile (); |
323 | maptile (); |
|
|
324 | maptile (int w, int h); |
289 | ~maptile (); |
325 | ~maptile (); |
|
|
326 | |
290 | void do_destroy (); |
327 | void do_destroy (); |
291 | void gather_callbacks (AV *&callbacks, event_type event) const; |
328 | void gather_callbacks (AV *&callbacks, event_type event) const; |
292 | |
329 | |
293 | MTH void allocate (); |
|
|
294 | MTH int size () const { return width * height; } |
330 | MTH int size () const { return width * height; } |
295 | |
331 | |
296 | MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0); |
332 | MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0); |
297 | |
333 | |
298 | MTH void link (); |
334 | static maptile *find_map (const char *path, maptile *origin);//PERL |
299 | MTH void unlink (); |
335 | |
|
|
336 | // load a map relative to this one |
|
|
337 | maptile *find_map (const char *path) |
|
|
338 | { |
|
|
339 | return find_map (path, this); |
|
|
340 | } |
|
|
341 | |
|
|
342 | // customise this map for the given player |
|
|
343 | // might return this or a completely new map |
|
|
344 | maptile *customise_for (object *op); |
|
|
345 | |
|
|
346 | // make sure the map is loaded |
|
|
347 | MTH bool load () |
|
|
348 | { |
|
|
349 | if (in_memory != MAP_IN_MEMORY) |
|
|
350 | do_load (); |
|
|
351 | |
|
|
352 | return spaces; |
|
|
353 | } |
|
|
354 | |
|
|
355 | static void emergency_save (); |
300 | |
356 | |
301 | mapspace const &at (uint32 x, uint32 y) const { return spaces [x * height + y]; } |
357 | mapspace const &at (uint32 x, uint32 y) const { return spaces [x * height + y]; } |
302 | mapspace &at (uint32 x, uint32 y) { return spaces [x * height + y]; } |
358 | mapspace &at (uint32 x, uint32 y) { return spaces [x * height + y]; } |
303 | }; |
|
|
304 | |
359 | |
305 | #define for_all_maps(var) for (maptile *var = first_map; var; var = var->next) |
360 | private: |
|
|
361 | void do_load ();//PERL |
|
|
362 | }; |
306 | |
363 | |
307 | /* This is used by get_rangevector to determine where the other |
364 | /* This is used by get_rangevector to determine where the other |
308 | * creature is. get_rangevector takes into account map tiling, |
365 | * creature is. get_rangevector takes into account map tiling, |
309 | * so you just can not look the the map coordinates and get the |
366 | * so you just can not look the the map coordinates and get the |
310 | * righte value. distance_x/y are distance away, which |
367 | * righte value. distance_x/y are distance away, which |