… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002-2005,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002-2005,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* |
25 | /* |
… | |
… | |
28 | |
29 | |
29 | #ifndef MAP_H |
30 | #ifndef MAP_H |
30 | #define MAP_H |
31 | #define MAP_H |
31 | |
32 | |
32 | #include <tr1/unordered_map> |
33 | #include <tr1/unordered_map> |
|
|
34 | |
|
|
35 | //+GPL |
33 | |
36 | |
34 | #include "region.h" |
37 | #include "region.h" |
35 | #include "cfperl.h" |
38 | #include "cfperl.h" |
36 | |
39 | |
37 | /* We set this size - this is to make magic map work properly on |
40 | /* We set this size - this is to make magic map work properly on |
… | |
… | |
131 | MoveType ACC (RW, move_block); /* What movement types this space blocks */ |
134 | MoveType ACC (RW, move_block); /* What movement types this space blocks */ |
132 | MoveType ACC (RW, move_slow); /* What movement types this space slows */ |
135 | MoveType ACC (RW, move_slow); /* What movement types this space slows */ |
133 | MoveType ACC (RW, move_on); /* What movement types are activated */ |
136 | MoveType ACC (RW, move_on); /* What movement types are activated */ |
134 | MoveType ACC (RW, move_off); /* What movement types are activated */ |
137 | MoveType ACC (RW, move_off); /* What movement types are activated */ |
135 | |
138 | |
|
|
139 | //-GPL |
|
|
140 | |
136 | void update_ (); |
141 | void update_ (); |
137 | MTH void update () |
142 | MTH void update () |
138 | { |
143 | { |
139 | if (!(flags_ & P_UPTODATE)) |
144 | if (expect_false (!(flags_ & P_UPTODATE))) |
140 | update_ (); |
145 | update_ (); |
141 | } |
146 | } |
142 | |
147 | |
143 | MTH uint8 flags () |
148 | MTH uint8 flags () |
144 | { |
149 | { |
… | |
… | |
184 | maptile *m; |
189 | maptile *m; |
185 | int x0, y0; |
190 | int x0, y0; |
186 | int x1, y1; |
191 | int x1, y1; |
187 | int dx, dy; // offset to go from local coordinates to original tile */ |
192 | int dx, dy; // offset to go from local coordinates to original tile */ |
188 | }; |
193 | }; |
|
|
194 | |
|
|
195 | //+GPL |
189 | |
196 | |
190 | struct shopitems : zero_initialised |
197 | struct shopitems : zero_initialised |
191 | { |
198 | { |
192 | const char *name; /* name of the item in question, null if it is the default item */ |
199 | const char *name; /* name of the item in question, null if it is the default item */ |
193 | const char *name_pl; /* plural name */ |
200 | const char *name_pl; /* plural name */ |
… | |
… | |
271 | maptile *ACC (RW, tile_map[4]); /* Next map, linked list */ |
278 | maptile *ACC (RW, tile_map[4]); /* Next map, linked list */ |
272 | shstr ACC (RW, path); /* Filename of the map */ |
279 | shstr ACC (RW, path); /* Filename of the map */ |
273 | int ACC (RW, max_nrof); // maximum nrof of any single item on a mapspace |
280 | int ACC (RW, max_nrof); // maximum nrof of any single item on a mapspace |
274 | uint64 ACC (RW, max_volume); // maximum volume for all items on a mapspace |
281 | uint64 ACC (RW, max_volume); // maximum volume for all items on a mapspace |
275 | |
282 | |
|
|
283 | //-GPL |
|
|
284 | |
276 | // the maptile:: is neccessary here for the perl interface to work |
285 | // the maptile:: is neccessary here for the perl interface to work |
277 | MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const |
286 | MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const |
278 | { |
287 | { |
279 | return clamp (outdoor ? darkness + outside : darkness, 0, MAX_DARKNESS); |
288 | return clamp (outdoor ? darkness + outside : darkness, 0, MAX_DARKNESS); |
280 | } |
289 | } |
… | |
… | |
294 | MTH void update_buttons (); |
303 | MTH void update_buttons (); |
295 | MTH int change_map_light (int change); |
304 | MTH int change_map_light (int change); |
296 | MTH int estimate_difficulty () const; |
305 | MTH int estimate_difficulty () const; |
297 | |
306 | |
298 | MTH void play_sound (faceidx sound, int x, int y) const; |
307 | MTH void play_sound (faceidx sound, int x, int y) const; |
|
|
308 | MTH void say_msg (const char *msg, int x, int y) const; |
|
|
309 | |
|
|
310 | // connected links |
|
|
311 | oblinkpt *find_link (shstr_tmp id); |
|
|
312 | MTH void trigger (shstr_tmp id, int state = 1, object *activator = 0, object *originator = 0); |
299 | |
313 | |
300 | // set the given flag on all objects in the map |
314 | // set the given flag on all objects in the map |
301 | MTH void set_object_flag (int flag, int value = 1); |
315 | MTH void set_object_flag (int flag, int value = 1); |
302 | MTH void post_load_original (); |
316 | MTH void post_load_original (); |
303 | |
317 | |
… | |
… | |
372 | // a 0 map pointer. |
386 | // a 0 map pointer. |
373 | // the array will be stored in a static memory area, |
387 | // the array will be stored in a static memory area, |
374 | // so recursion is not atm. supported |
388 | // so recursion is not atm. supported |
375 | maprect *split_to_tiles (int x0, int y0, int x1, int y1); |
389 | maprect *split_to_tiles (int x0, int y0, int x1, int y1); |
376 | }; |
390 | }; |
|
|
391 | |
|
|
392 | //+GPL |
377 | |
393 | |
378 | /* This is used by get_rangevector to determine where the other |
394 | /* This is used by get_rangevector to determine where the other |
379 | * creature is. get_rangevector takes into account map tiling, |
395 | * creature is. get_rangevector takes into account map tiling, |
380 | * so you just can not look the the map coordinates and get the |
396 | * so you just can not look the the map coordinates and get the |
381 | * righte value. distance_x/y are distance away, which |
397 | * righte value. distance_x/y are distance away, which |
… | |
… | |
398 | // and so on. |
414 | // and so on. |
399 | int get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny); |
415 | int get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny); |
400 | int out_of_map (maptile *m, int x, int y); |
416 | int out_of_map (maptile *m, int x, int y); |
401 | maptile *get_map_from_coord (maptile *m, sint16 *x, sint16 *y); |
417 | maptile *get_map_from_coord (maptile *m, sint16 *x, sint16 *y); |
402 | void get_rangevector (object *op1, object *op2, rv_vector *retval, int flags); |
418 | void get_rangevector (object *op1, object *op2, rv_vector *retval, int flags); |
403 | void get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags); |
419 | void get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags = 0 /*unused*/); |
404 | int on_same_map (const object *op1, const object *op2); |
420 | int on_same_map (const object *op1, const object *op2); |
405 | int adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy); |
421 | int adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy); |
406 | |
422 | |
407 | // adjust map, x and y for tiled maps and return true if the position is valid at all |
423 | // adjust map, x and y for tiled maps and return true if the position is valid at all |
408 | static inline bool |
424 | static inline bool |
… | |
… | |
413 | (IN_RANGE_EXC (x, 0, map->width) && IN_RANGE_EXC (y, 0, map->height)) |
429 | (IN_RANGE_EXC (x, 0, map->width) && IN_RANGE_EXC (y, 0, map->height)) |
414 | || !(get_map_flags (map, &map, x, y, &x, &y) & P_OUT_OF_MAP); |
430 | || !(get_map_flags (map, &map, x, y, &x, &y) & P_OUT_OF_MAP); |
415 | } |
431 | } |
416 | // comaptibility cruft end |
432 | // comaptibility cruft end |
417 | |
433 | |
|
|
434 | //-GPL |
|
|
435 | |
418 | inline mapspace & |
436 | inline mapspace & |
419 | object::ms () const |
437 | object::ms () const |
420 | { |
438 | { |
421 | return map->at (x, y); |
439 | return map->at (x, y); |
422 | } |
440 | } |
… | |
… | |
489 | // can be used as a single statement, but both iterate macros |
507 | // can be used as a single statement, but both iterate macros |
490 | // invocations must not be followed by a ";" |
508 | // invocations must not be followed by a ";" |
491 | // see common/los.C for usage example |
509 | // see common/los.C for usage example |
492 | // the walk will be ordered, outer loop x, inner loop y |
510 | // the walk will be ordered, outer loop x, inner loop y |
493 | // m will be set to the map (or 0), nx, ny to the map coord, dx, dy to the offset relative to op |
511 | // m will be set to the map (or 0), nx, ny to the map coord, dx, dy to the offset relative to op |
|
|
512 | // "continue" will skip to the next space |
494 | #define ordered_mapwalk_begin(op,dx0,dy0,dx1,dy1) \ |
513 | #define ordered_mapwalk_begin(op,dx0,dy0,dx1,dy1) \ |
495 | for (int dx = (dx0); dx <= (dx1); ++dx) \ |
514 | for (int dx = (dx0); dx <= (dx1); ++dx) \ |
496 | { \ |
515 | { \ |
497 | sint16 nx, ny; \ |
516 | sint16 nx, ny; \ |
498 | maptile *m = 0; \ |
517 | maptile *m = 0; \ |
… | |
… | |
512 | #define ordered_mapwalk_end \ |
531 | #define ordered_mapwalk_end \ |
513 | } \ |
532 | } \ |
514 | } |
533 | } |
515 | |
534 | |
516 | // loop over every space in the given maprect, |
535 | // loop over every space in the given maprect, |
517 | // setting m, nx, ny to the map and -coordinate and dx, dy to the offste relative to dx0,dy0 |
536 | // setting m, nx, ny to the map and -coordinate and dx, dy to the offset relative to dx0,dy0 |
518 | // the iterator code must be a single statement following this macro call, similar to "if" |
537 | // the iterator code must be a single statement following this macro call, similar to "if" |
|
|
538 | // "continue" will skip to the next space |
519 | #define rect_mapwalk(rect,dx0,dy0) \ |
539 | #define rect_mapwalk(rect,dx0,dy0) \ |
520 | statementvar (maptile *, m, (rect)->m) \ |
540 | statementvar (maptile *, m, (rect)->m) \ |
521 | for (int nx = (rect)->x0; nx < (rect)->x1; ++nx) \ |
541 | for (int nx = (rect)->x0; nx < (rect)->x1; ++nx) \ |
522 | for (int ny = (rect)->y0; ny < (rect)->y1; ++ny) \ |
542 | for (int ny = (rect)->y0; ny < (rect)->y1; ++ny) \ |
523 | statementvar (int, dx, nx + (rect)->dx - (dx0)) \ |
543 | statementvar (int, dx, nx + (rect)->dx - (dx0)) \ |
524 | statementvar (int, dy, ny + (rect)->dy - (dy0)) |
544 | statementvar (int, dy, ny + (rect)->dy - (dy0)) |
525 | |
545 | |
526 | // same as above, but the walk will not follow any particular |
546 | // same as ordered_mapwalk, but the walk will not follow any particular |
527 | // order (unorded), but is likely faster. |
547 | // order (unorded), but is likely faster. |
528 | // m will be set to the map (never 0!), nx, ny to the map coord, dx, dy to the offset relative to op |
548 | // m will be set to the map (never 0!), nx, ny to the map coord, dx, dy to the offset relative to op |
|
|
549 | // "continue" will skip to the next space |
529 | #define unordered_mapwalk(op,dx0,dy0,dx1,dy1) \ |
550 | #define unordered_mapwalk_at(map,ox,oy,dx0,dy0,dx1,dy1) \ |
530 | for (maprect *r_e_c_t = (op)->map->split_to_tiles ( \ |
551 | for (maprect *r_e_c_t = (map)->split_to_tiles ( \ |
531 | (op)->x + (dx0) , (op)->y + (dy0) , \ |
552 | (ox) + (dx0) , (oy) + (dy0) , \ |
532 | (op)->x + (dx1) + 1, (op)->y + (dy1) + 1); \ |
553 | (ox) + (dx1) + 1, (oy) + (dy1) + 1); \ |
533 | r_e_c_t->m; \ |
554 | r_e_c_t->m; \ |
534 | ++r_e_c_t) \ |
555 | ++r_e_c_t) \ |
535 | rect_mapwalk (r_e_c_t, (op)->x, (op)->y) |
556 | rect_mapwalk (r_e_c_t, (ox), (oy)) |
|
|
557 | |
|
|
558 | #define unordered_mapwalk(op,dx0,dy0,dx1,dy1) \ |
|
|
559 | unordered_mapwalk_at (op->map, op->x, op->y, dx0, dy0, dx1, dy1) |
536 | |
560 | |
537 | #endif |
561 | #endif |
538 | |
562 | |