1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002-2005 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002-2005 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
21 | * <http://www.gnu.org/licenses/>. |
21 | * |
22 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
24 | */ |
24 | |
25 | |
25 | /* |
26 | /* |
26 | * The maptile is allocated each time a new map is opened. |
27 | * The maptile is allocated each time a new map is opened. |
… | |
… | |
55 | // tile map index - toggling the lowest bit reverses direction |
56 | // tile map index - toggling the lowest bit reverses direction |
56 | enum |
57 | enum |
57 | { |
58 | { |
58 | TILE_NORTH, |
59 | TILE_NORTH, |
59 | TILE_SOUTH, |
60 | TILE_SOUTH, |
60 | TILE_EAST , |
|
|
61 | TILE_WEST, |
61 | TILE_WEST, |
|
|
62 | TILE_EAST, |
62 | TILE_UP, |
63 | TILE_UP, |
63 | TILE_DOWN, |
64 | TILE_DOWN, |
64 | TILE_NUM |
65 | TILE_NUM |
65 | }; |
66 | }; |
66 | |
67 | |
… | |
… | |
157 | void update_ (); |
158 | void update_ (); |
158 | MTH void update () |
159 | MTH void update () |
159 | { |
160 | { |
160 | // we take advantage of the fact that 0x80 is the sign bit |
161 | // we take advantage of the fact that 0x80 is the sign bit |
161 | // to generate more efficient code on many cpus |
162 | // to generate more efficient code on many cpus |
162 | assert (sint8 (P_UPTODATE) < 0); |
163 | //assert (sint8 (P_UPTODATE) < 0); |
163 | assert (sint8 (-1 & ~P_UPTODATE) >= 0); |
164 | //assert (sint8 (-1 & ~P_UPTODATE) >= 0); |
164 | |
165 | |
165 | if (expect_false (sint8 (flags_) >= 0)) |
166 | if (expect_false (sint8 (flags_) >= 0)) |
166 | update_ (); |
167 | update_ (); |
167 | |
168 | |
168 | // must be true by now (gcc seems content with only the second test) |
169 | // must be true by now (gcc seems content with only the second test) |
169 | assume (sint8 (flags_) < 0); |
170 | ecb_assume (sint8 (flags_) < 0); |
170 | assume (flags_ & P_UPTODATE); |
171 | ecb_assume (flags_ & P_UPTODATE); |
171 | } |
172 | } |
172 | |
173 | |
173 | MTH uint8 flags () |
174 | MTH uint8 flags () |
174 | { |
175 | { |
175 | update (); |
176 | update (); |
… | |
… | |
204 | update (); |
205 | update (); |
205 | return items_; |
206 | return items_; |
206 | } |
207 | } |
207 | |
208 | |
208 | // return the item volume on this mapspace in cm³ |
209 | // return the item volume on this mapspace in cm³ |
209 | MTH uint64 volume () |
210 | MTH volume_t volume () |
210 | { |
211 | { |
211 | update (); |
212 | update (); |
212 | return volume_ * 1024; |
213 | return volume_ * 1024; |
213 | } |
214 | } |
214 | |
215 | |
… | |
… | |
249 | struct shopitems : zero_initialised |
250 | struct shopitems : zero_initialised |
250 | { |
251 | { |
251 | const char *name; /* name of the item in question, null if it is the default item */ |
252 | const char *name; /* name of the item in question, null if it is the default item */ |
252 | const char *name_pl; /* plural name */ |
253 | const char *name_pl; /* plural name */ |
253 | int typenum; /* itemtype number we need to match 0 if it is the default price */ |
254 | int typenum; /* itemtype number we need to match 0 if it is the default price */ |
254 | sint8 strength; /* the degree of specialisation the shop has in this item, |
255 | sint8 strength; /* the degree of specialisation the shop has in this item, |
255 | * as a percentage from -100 to 100 */ |
256 | * as a percentage from -100 to 100 */ |
256 | int index; /* being the size of the shopitems array. */ |
257 | int index; /* being the size of the shopitems array. */ |
257 | }; |
258 | }; |
258 | |
259 | |
259 | // map I/O, what to load/save |
260 | // map I/O, what to load/save |
… | |
… | |
261 | IO_HEADER = 0x01, // the "arch map" pseudo object |
262 | IO_HEADER = 0x01, // the "arch map" pseudo object |
262 | IO_OBJECTS = 0x02, // the non-unique objects |
263 | IO_OBJECTS = 0x02, // the non-unique objects |
263 | IO_UNIQUES = 0x04, // unique objects |
264 | IO_UNIQUES = 0x04, // unique objects |
264 | }; |
265 | }; |
265 | |
266 | |
266 | /* In general, code should always use the macros |
267 | /* In general, code should always use the macros |
267 | * above (or functions in map.c) to access many of the |
268 | * above (or functions in map.c) to access many of the |
268 | * values in the map structure. Failure to do this will |
269 | * values in the map structure. Failure to do this will |
269 | * almost certainly break various features. You may think |
270 | * almost certainly break various features. You may think |
270 | * it is safe to look at width and height values directly |
271 | * it is safe to look at width and height values directly |
271 | * (or even through the macros), but doing so will completely |
272 | * (or even through the macros), but doing so will completely |
272 | * break map tiling. |
273 | * break map tiling. |
… | |
… | |
280 | region_ptr *regionmap; /* index to region */ |
281 | region_ptr *regionmap; /* index to region */ |
281 | |
282 | |
282 | tstamp ACC (RW, last_access); /* last time this map was accessed somehow */ |
283 | tstamp ACC (RW, last_access); /* last time this map was accessed somehow */ |
283 | |
284 | |
284 | shstr ACC (RW, name); /* Name of map as given by its creator */ |
285 | shstr ACC (RW, name); /* Name of map as given by its creator */ |
285 | region_ptr ACC (RW, default_region); /* What jurisdiction in the game world this map is ruled by |
286 | region_ptr ACC (RW, default_region); /* What jurisdiction in the game world this map is ruled by |
286 | * points to the struct containing all the properties of |
287 | * points to the struct containing all the properties of |
287 | * the region */ |
288 | * the region */ |
288 | double ACC (RW, reset_time); |
289 | double ACC (RW, reset_time); |
289 | uint32 ACC (RW, reset_timeout); /* How many seconds must elapse before this map |
290 | uint32 ACC (RW, reset_timeout); /* How many seconds must elapse before this map |
290 | * should be reset |
291 | * should be reset |
291 | */ |
292 | */ |
… | |
… | |
320 | shstr ACC (RW, msg); /* Message map creator may have left */ |
321 | shstr ACC (RW, msg); /* Message map creator may have left */ |
321 | shstr ACC (RW, maplore); /* Map lore information */ |
322 | shstr ACC (RW, maplore); /* Map lore information */ |
322 | shstr ACC (RW, tile_path[TILE_NUM]); /* path to adjoining maps */ |
323 | shstr ACC (RW, tile_path[TILE_NUM]); /* path to adjoining maps */ |
323 | maptile *ACC (RW, tile_map[TILE_NUM]); /* Next map, linked list */ |
324 | maptile *ACC (RW, tile_map[TILE_NUM]); /* Next map, linked list */ |
324 | shstr ACC (RW, path); /* Filename of the map */ |
325 | shstr ACC (RW, path); /* Filename of the map */ |
325 | uint64 ACC (RW, max_volume); // maximum volume for all items on a mapspace |
326 | volume_t ACC (RW, max_volume); // maximum volume for all items on a mapspace |
326 | int ACC (RW, max_items); // maximum number of items on a mapspace |
327 | int ACC (RW, max_items); // maximum number of items on a mapspace |
327 | |
328 | |
328 | //-GPL |
329 | //-GPL |
329 | |
330 | |
330 | physics_queue pq[PHYSICS_QUEUES]; |
331 | physics_queue pq[PHYSICS_QUEUES]; |
331 | MTH void queue_physics (object *ob, int after = 0); |
332 | MTH void queue_physics (object *ob, int after = 0); |
332 | MTH void queue_physics_at (int x, int y); |
333 | MTH void queue_physics_at (int x, int y); |
333 | MTH void post_load_physics (); |
|
|
334 | MTH int run_physics (tick_t tick, int max_objects); |
334 | MTH int run_physics (tick_t tick, int max_objects); |
|
|
335 | MTH void activate_physics (); |
335 | |
336 | |
336 | // the maptile:: is neccessary here for the perl interface to work |
337 | // the maptile:: is neccessary here for the perl interface to work |
337 | MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const |
338 | MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const |
338 | { |
339 | { |
339 | return clamp (outdoor ? darkness + outside : darkness, 0, MAX_DARKNESS); |
340 | return clamp (outdoor ? darkness + outside : darkness, 0, MAX_DARKNESS); |
340 | } |
341 | } |
341 | |
342 | |
342 | static void adjust_daylight (); |
343 | static void adjust_daylight (); |
343 | |
344 | |
344 | MTH void activate (); |
345 | MTH void activate (); |
345 | MTH void activate_physics (); |
|
|
346 | MTH void deactivate (); |
346 | MTH void deactivate (); |
347 | |
347 | |
348 | // allocates all (empty) mapspace |
348 | // allocates all (empty) mapspace |
349 | MTH void alloc (); |
349 | MTH void alloc (); |
350 | // deallocates the mapspaces (and destroys all objects) |
350 | // deallocates the mapspaces (and destroys all objects) |
… | |
… | |
528 | return *this; |
528 | return *this; |
529 | } |
529 | } |
530 | |
530 | |
531 | mapxy &move (int dir) |
531 | mapxy &move (int dir) |
532 | { |
532 | { |
533 | return move (freearr_x [dir], freearr_y [dir]); |
533 | return move (DIRX (dir), DIRY (dir)); |
534 | } |
534 | } |
535 | |
535 | |
536 | operator void *() const { return (void *)m; } |
536 | operator void *() const { return (void *)m; } |
537 | mapxy &operator =(const object *op) |
537 | mapxy &operator =(const object *op) |
538 | { |
538 | { |
… | |
… | |
601 | } \ |
601 | } \ |
602 | } |
602 | } |
603 | |
603 | |
604 | extern dynbuf mapwalk_buf; // can be used in simple non-recursive situations |
604 | extern dynbuf mapwalk_buf; // can be used in simple non-recursive situations |
605 | |
605 | |
|
|
606 | // special "grave" map used to store all removed objects |
|
|
607 | // till they can be destroyed - saves a lot of checks in the rest |
|
|
608 | // of the code |
|
|
609 | struct freed_map |
|
|
610 | : maptile |
|
|
611 | { |
|
|
612 | freed_map () |
|
|
613 | : maptile (3, 3) |
|
|
614 | { |
|
|
615 | path = "<freed objects map>"; |
|
|
616 | name = "/internal/freed_objects_map"; |
|
|
617 | no_drop = 1; |
|
|
618 | no_reset = 1; |
|
|
619 | |
|
|
620 | state = MAP_ACTIVE; |
|
|
621 | } |
|
|
622 | |
|
|
623 | ~freed_map () |
|
|
624 | { |
|
|
625 | destroy (); |
|
|
626 | } |
|
|
627 | }; |
|
|
628 | |
|
|
629 | // initialised in common/shstr.C, due to shstr usage we need defined |
|
|
630 | // initialisation order! |
|
|
631 | extern struct freed_map freed_map; // freed objects are moved here to avoid crashes |
|
|
632 | |
606 | // loop over every space in the given maprect, |
633 | // loop over every space in the given maprect, |
607 | // setting m, nx, ny to the map and -coordinate and dx, dy to the offset relative to dx0,dy0 |
634 | // setting m, nx, ny to the map and -coordinate and dx, dy to the offset relative to dx0,dy0 |
608 | // the iterator code must be a single statement following this macro call, similar to "if" |
635 | // the iterator code must be a single statement following this macro call, similar to "if" |
609 | // "continue" will skip to the next space |
636 | // "continue" will skip to the next space |
610 | #define rect_mapwalk(rect,dx0,dy0) \ |
637 | #define rect_mapwalk(rect,dx0,dy0) \ |