ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/map.h
(Generate patch)

Comparing deliantra/server/include/map.h (file contents):
Revision 1.98 by root, Sun Aug 17 22:46:26 2008 UTC vs.
Revision 1.116 by root, Thu Nov 5 15:57:15 2009 UTC

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
47#define MAGIC_MAP_SIZE 50 50#define MAGIC_MAP_SIZE 50
48#define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2 51#define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2
49 52
50#define MAP_LAYERS 3 53#define MAP_LAYERS 3
51 54
55// tile map index
56enum {
57 TILE_UP = 0,
58 TILE_RIGHT = 1,
59 TILE_DOWN = 2,
60 TILE_LEFT = 3,
61};
62
52/* Values for in_memory below */ 63/* Values for in_memory below */
53enum { 64enum {
54 MAP_ACTIVE, 65 MAP_ACTIVE,
55 MAP_INACTIVE, // not used atm. 66 MAP_INACTIVE, // not used atm.
56 MAP_SWAPPED, 67 MAP_SWAPPED,
63 * where it is known the map is not tiled or the values are known 74 * where it is known the map is not tiled or the values are known
64 * consistent (eg, op->map, op->x, op->y) 75 * consistent (eg, op->map, op->x, op->y)
65 */ 76 */
66// all those macros are herewith declared legacy 77// all those macros are herewith declared legacy
67#define GET_MAP_FLAGS(M,X,Y) (M)->at((X),(Y)).flags () 78#define GET_MAP_FLAGS(M,X,Y) (M)->at((X),(Y)).flags ()
68#define GET_MAP_LIGHT(M,X,Y) (M)->at((X),(Y)).light
69#define GET_MAP_OB(M,X,Y) (M)->at((X),(Y)).bot 79#define GET_MAP_OB(M,X,Y) (M)->at((X),(Y)).bot
70#define GET_MAP_TOP(M,X,Y) (M)->at((X),(Y)).top 80#define GET_MAP_TOP(M,X,Y) (M)->at((X),(Y)).top
71#define GET_MAP_FACE_OBJ(M,X,Y,L) (M)->at((X),(Y)).faces_obj[L] 81#define GET_MAP_FACE_OBJ(M,X,Y,L) (M)->at((X),(Y)).faces_obj[L]
72#define GET_MAP_MOVE_BLOCK(M,X,Y) (M)->at((X),(Y)).move_block 82#define GET_MAP_MOVE_BLOCK(M,X,Y) (M)->at((X),(Y)).move_block
73#define GET_MAP_MOVE_SLOW(M,X,Y) (M)->at((X),(Y)).move_slow 83#define GET_MAP_MOVE_SLOW(M,X,Y) (M)->at((X),(Y)).move_slow
100 * used in the get_map_flags value - that function is used to return 110 * used in the get_map_flags value - that function is used to return
101 * the flag value, as well as other conditions - using a more general 111 * the flag value, as well as other conditions - using a more general
102 * function that does more of the work can hopefully be used to replace 112 * function that does more of the work can hopefully be used to replace
103 * lots of duplicate checks currently in the code. 113 * lots of duplicate checks currently in the code.
104 */ 114 */
105#define P_OUT_OF_MAP 0x10000 /* This space is outside the map */ 115#define P_OUT_OF_MAP 0x10000 /* This space is outside the map */
106#define P_NEW_MAP 0x20000 116#define P_NEW_MAP 0x20000 /* Coordinates passed result in a new tiled map */
107 /* Coordinates passed result in a new tiled map */
108 117
109/* Instead of having numerous arrays that have information on a 118/* Instead of having numerous arrays that have information on a
110 * particular space (was map, floor, floor2, map_ob), 119 * particular space (was map, floor, floor2, map_ob),
111 * have this structure take care of that information. 120 * have this structure take care of that information.
112 * This puts it all in one place, and should also make it easier 121 * This puts it all in one place, and should also make it easier
116struct mapspace 125struct mapspace
117{ 126{
118 object *ACC (RW, bot); 127 object *ACC (RW, bot);
119 object *ACC (RW, top); /* lowest/highest object on this space */ 128 object *ACC (RW, top); /* lowest/highest object on this space */
120 object *ACC (RW, faces_obj[MAP_LAYERS]);/* face objects for the 3 layers */ 129 object *ACC (RW, faces_obj[MAP_LAYERS]);/* face objects for the 3 layers */
130 uint32_t smell; // the last count a player was seen here, or 0
131 static uint32_t smellcount; // global smell counter
121 uint8 flags_; /* flags about this space (see the P_ values above) */ 132 uint8 flags_; /* flags about this space (see the P_ values above) */
122 sint8 ACC (RW, light); /* How much light this space provides */ 133 sint8 ACC (RW, light); /* How much light this space provides */
123 MoveType ACC (RW, move_block); /* What movement types this space blocks */ 134 MoveType ACC (RW, move_block); /* What movement types this space blocks */
124 MoveType ACC (RW, move_slow); /* What movement types this space slows */ 135 MoveType ACC (RW, move_slow); /* What movement types this space slows */
125 MoveType ACC (RW, move_on); /* What movement types are activated */ 136 MoveType ACC (RW, move_on); /* What movement types are activated */
126 MoveType ACC (RW, move_off); /* What movement types are activated */ 137 MoveType ACC (RW, move_off); /* What movement types are activated */
127 138
139//-GPL
140
128 void update_ (); 141 void update_ ();
129 MTH void update () 142 MTH void update ()
130 { 143 {
131 if (!(flags_ & P_UPTODATE)) 144 if (expect_false (!(flags_ & P_UPTODATE)))
132 update_ (); 145 update_ ();
133 } 146 }
134 147
135 MTH uint8 flags () 148 MTH uint8 flags ()
136 { 149 {
137 update (); 150 update ();
138 return flags_; 151 return flags_;
152 }
153
154 MTH void invalidate ()
155 {
156 flags_ = 0;
139 } 157 }
140 158
141 MTH object *player () 159 MTH object *player ()
142 { 160 {
143 object *op; 161 object *op;
162 bool blocks (object *op) const 180 bool blocks (object *op) const
163 { 181 {
164 return blocks (op->move_type); 182 return blocks (op->move_type);
165 } 183 }
166}; 184};
185
186// a rectangular area of a map
187struct maprect
188{
189 maptile *m;
190 int x0, y0;
191 int x1, y1;
192 int dx, dy; // offset to go from local coordinates to original tile */
193};
194
195//+GPL
167 196
168struct shopitems : zero_initialised 197struct shopitems : zero_initialised
169{ 198{
170 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 */
171 const char *name_pl; /* plural name */ 200 const char *name_pl; /* plural name */
223 252
224 bool ACC (RW, per_player); 253 bool ACC (RW, per_player);
225 bool ACC (RW, per_party); 254 bool ACC (RW, per_party);
226 bool ACC (RW, outdoor); /* True if an outdoor map */ 255 bool ACC (RW, outdoor); /* True if an outdoor map */
227 bool ACC (RW, no_drop); /* avoid auto-dropping (on death) anything on this map */ 256 bool ACC (RW, no_drop); /* avoid auto-dropping (on death) anything on this map */
228 uint8 ACC (RW, darkness); /* indicates level of darkness of map */ 257 sint8 ACC (RW, darkness); /* indicates level of darkness of map */
258 static sint8 outdoor_darkness; /* the global darkness level outside */
229 259
230 uint16 ACC (RW, enter_x); /* enter_x and enter_y are default entrance location */ 260 uint16 ACC (RW, enter_x); /* enter_x and enter_y are default entrance location */
231 uint16 ACC (RW, enter_y); /* on the map if none are set in the exit */ 261 uint16 ACC (RW, enter_y); /* on the map if none are set in the exit */
232 oblinkpt *buttons; /* Linked list of linked lists of buttons */ 262 oblinkpt *buttons; /* Linked list of linked lists of buttons */
233 sint16 ACC (RW, temp); /* base temperature of this tile (F) */ 263 sint16 ACC (RW, temp); /* base temperature of this tile (F) */
248 maptile *ACC (RW, tile_map[4]); /* Next map, linked list */ 278 maptile *ACC (RW, tile_map[4]); /* Next map, linked list */
249 shstr ACC (RW, path); /* Filename of the map */ 279 shstr ACC (RW, path); /* Filename of the map */
250 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
251 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
252 282
283//-GPL
284
285 // the maptile:: is neccessary here for the perl interface to work
286 MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const
287 {
288 return clamp (outdoor ? darkness + outside : darkness, 0, MAX_DARKNESS);
289 }
290
291 static void adjust_daylight ();
292
253 MTH void activate (); 293 MTH void activate ();
254 MTH void deactivate (); 294 MTH void deactivate ();
255 295
256 // allocates all (empty) mapspace 296 // allocates all (empty) mapspace
257 MTH void alloc (); 297 MTH void alloc ();
260 300
261 MTH void fix_auto_apply (); 301 MTH void fix_auto_apply ();
262 MTH void do_decay_objects (); 302 MTH void do_decay_objects ();
263 MTH void update_buttons (); 303 MTH void update_buttons ();
264 MTH int change_map_light (int change); 304 MTH int change_map_light (int change);
265 static void change_all_map_light (int change); //PERL
266 MTH void set_darkness_map ();
267 MTH int estimate_difficulty () const; 305 MTH int estimate_difficulty () const;
268 306
269 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);
270 313
271 // set the given flag on all objects in the map 314 // set the given flag on all objects in the map
272 MTH void set_object_flag (int flag, int value = 1); 315 MTH void set_object_flag (int flag, int value = 1);
273 MTH void post_load_original (); 316 MTH void post_load_original ();
274 317
307 350
308 MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0); 351 MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0);
309 352
310 MTH void touch () { last_access = runtime; } 353 MTH void touch () { last_access = runtime; }
311 354
312 MTH bool tile_available (int dir, bool load = true); 355 MTH maptile *tile_available (int dir, bool load = true);
313 356
314 // find the map that is at coordinate x|y relative to this map 357 // find the map that is at coordinate x|y relative to this map
315 // TODO: need a better way than passing by reference 358 // TODO: need a better way than passing by reference
316 // TODO: make perl interface 359 // TODO: make perl interface
317 maptile *xy_find (sint16 &x, sint16 &y); 360 maptile *xy_find (sint16 &x, sint16 &y);
334 static maptile *find_async (const char *path, maptile *original = 0, bool load = true);//PERL 377 static maptile *find_async (const char *path, maptile *original = 0, bool load = true);//PERL
335 static maptile *find_sync (const char *path, maptile *original = 0);//PERL 378 static maptile *find_sync (const char *path, maptile *original = 0);//PERL
336 static maptile *find_style_sync (const char *dir, const char *file = 0);//PERL 379 static maptile *find_style_sync (const char *dir, const char *file = 0);//PERL
337 object *pick_random_object (rand_gen &gen = rndm) const; 380 object *pick_random_object (rand_gen &gen = rndm) const;
338 381
339 mapspace const &at (uint32 x, uint32 y) const { return spaces [x * height + y]; } 382 mapspace &at (uint32 x, uint32 y) const { return spaces [x * height + y]; }
340 mapspace &at (uint32 x, uint32 y) { return spaces [x * height + y]; } 383
384 // return an array of maprects corresponding
385 // to the given rectangular area. the last rect will have
386 // a 0 map pointer.
387 // the array will be stored in a static memory area,
388 // so recursion is not atm. supported
389 maprect *split_to_tiles (int x0, int y0, int x1, int y1);
341}; 390};
391
392//+GPL
342 393
343/* This is used by get_rangevector to determine where the other 394/* This is used by get_rangevector to determine where the other
344 * creature is. get_rangevector takes into account map tiling, 395 * creature is. get_rangevector takes into account map tiling,
345 * 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
346 * righte value. distance_x/y are distance away, which 397 * righte value. distance_x/y are distance away, which
363// and so on. 414// and so on.
364int get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny); 415int get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny);
365int out_of_map (maptile *m, int x, int y); 416int out_of_map (maptile *m, int x, int y);
366maptile *get_map_from_coord (maptile *m, sint16 *x, sint16 *y); 417maptile *get_map_from_coord (maptile *m, sint16 *x, sint16 *y);
367void get_rangevector (object *op1, object *op2, rv_vector *retval, int flags); 418void get_rangevector (object *op1, object *op2, rv_vector *retval, int flags);
368void get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags); 419void get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags = 0 /*unused*/);
369int on_same_map (const object *op1, const object *op2); 420int on_same_map (const object *op1, const object *op2);
370int adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy); 421int adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy);
371 422
372// 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
373static inline bool 424static inline bool
378 (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))
379 || !(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);
380} 431}
381// comaptibility cruft end 432// comaptibility cruft end
382 433
434//-GPL
435
383inline mapspace & 436inline mapspace &
384object::ms () const 437object::ms () const
385{ 438{
386 return map->at (x, y); 439 return map->at (x, y);
387} 440}
448 y = pos.y; 501 y = pos.y;
449 502
450 return pos; 503 return pos;
451} 504}
452 505
506// iterate over a rectangular area relative to op
507// can be used as a single statement, but both iterate macros
508// invocations must not be followed by a ";"
509// see common/los.C for usage example
510// the walk will be ordered, outer loop x, inner loop y
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
513#define ordered_mapwalk_begin(op,dx0,dy0,dx1,dy1) \
514 for (int dx = (dx0); dx <= (dx1); ++dx) \
515 { \
516 sint16 nx, ny; \
517 maptile *m = 0; \
518 \
519 for (int dy = (dy0); dy <= (dy1); ++dy) \
520 { \
521 /* check to see if we can simply go one down quickly, */ \
522 /* if not, do it the slow way */ \
523 if (!m || ++ny >= m->height) \
524 { \
525 nx = (op)->x + dx; ny = (op)->y + dy; m = (op)->map; \
526 \
527 if (!xy_normalise (m, nx, ny)) \
528 m = 0; \
529 }
530
531#define ordered_mapwalk_end \
532 } \
533 }
534
535// loop over every space in the given maprect,
536// setting m, nx, ny to the map and -coordinate and dx, dy to the offset relative to dx0,dy0
537// the iterator code must be a single statement following this macro call, similar to "if"
538// "continue" will skip to the next space
539#define rect_mapwalk(rect,dx0,dy0) \
540 statementvar (maptile *, m, (rect)->m) \
541 for (int nx = (rect)->x0; nx < (rect)->x1; ++nx) \
542 for (int ny = (rect)->y0; ny < (rect)->y1; ++ny) \
543 statementvar (int, dx, nx + (rect)->dx - (dx0)) \
544 statementvar (int, dy, ny + (rect)->dy - (dy0))
545
546// same as ordered_mapwalk, but the walk will not follow any particular
547// order (unorded), but is likely faster.
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
550#define unordered_mapwalk_at(map,ox,oy,dx0,dy0,dx1,dy1) \
551 for (maprect *r_e_c_t = (map)->split_to_tiles ( \
552 (ox) + (dx0) , (oy) + (dy0) , \
553 (ox) + (dx1) + 1, (oy) + (dy1) + 1); \
554 r_e_c_t->m; \
555 ++r_e_c_t) \
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)
560
453#endif 561#endif
454 562

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines