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.30 by root, Wed Dec 20 11:36:39 2006 UTC vs.
Revision 1.39 by root, Wed Dec 27 13:13:47 2006 UTC

30#define MAP_H 30#define MAP_H
31 31
32#include "cfperl.h" 32#include "cfperl.h"
33 33
34/* We set this size - this is to make magic map work properly on 34/* We set this size - this is to make magic map work properly on
35 * tiled maps. There is no requirement that this matches the 35 * tiled maps. There is no requirement that this matches the
36 * tiled maps size - it just seemed like a reasonable value. 36 * tiled maps size - it just seemed like a reasonable value.
37 * Magic map code now always starts out putting the player in the 37 * Magic map code now always starts out putting the player in the
38 * center of the map - this makes the most sense when dealing 38 * center of the map - this makes the most sense when dealing
39 * with tiled maps. 39 * with tiled maps.
40 * We also figure out the magicmap color to use as we process the 40 * We also figure out the magicmap color to use as we process the
42 * map pointers. 42 * map pointers.
43 */ 43 */
44#define MAGIC_MAP_SIZE 50 44#define MAGIC_MAP_SIZE 50
45#define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2 45#define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2
46 46
47#define MAP_LAYERS 4 47#define MAP_LAYERS 3
48
49/* This is when the map will reset */
50#define MAP_WHEN_RESET(m) ((m)->reset_time)
51
52#define MAP_RESET_TIMEOUT(m) ((m)->reset_timeout)
53#define MAP_DIFFICULTY(m) ((m)->difficulty)
54#define MAP_TIMEOUT(m) ((m)->timeout)
55#define MAP_SWAP_TIME(m) ((m)->swap_time)
56#define MAP_OUTDOORS(m) ((m)->outdoor)
57
58/* mape darkness used to enforce the MAX_DARKNESS value.
59 * but IMO, if it is beyond max value, that should be fixed
60 * on the map or in the code.
61 */
62#define MAP_DARKNESS(m) (m)->darkness
63
64#define MAP_WIDTH(m) (m)->width
65#define MAP_HEIGHT(m) (m)->height
66
67/* Convenient function - total number of spaces is used
68 * in many places.
69 */
70#define MAP_SIZE(m) ((m)->width * (m)->height)
71
72#define MAP_ENTER_X(m) (m)->enter_x
73#define MAP_ENTER_Y(m) (m)->enter_y
74
75#define MAP_TEMP(m) (m)->temp
76#define MAP_PRESSURE(m) (m)->pressure
77#define MAP_HUMID(m) (m)->humid
78#define MAP_WINDSPEED(m) (m)->windspeed
79#define MAP_WINDDIRECTION(m) (m)->winddir
80#define MAP_SKYCOND(m) (m)->sky
81#define MAP_WORLDPARTX(m) (m)->wpartx
82#define MAP_WORLDPARTY(m) (m)->wparty
83#define MAP_NOSMOOTH(m) (m)->nosmooth
84 48
85/* options passed to ready_map_name and load_original_map */ 49/* options passed to ready_map_name and load_original_map */
86#define MAP_FLUSH 0x1 50#define MAP_FLUSH 0x01
87#define MAP_PLAYER_UNIQUE 0x2 51#define MAP_PLAYER_UNIQUE 0x02
88#define MAP_BLOCK 0x4 52#define MAP_BLOCK 0x04
89#define MAP_STYLE 0x8 53#define MAP_STYLE 0x08
90#define MAP_OVERLAY 0x10 54#define MAP_OVERLAY 0x10
91 55
92/* Values for in_memory below. Should probably be an enumerations */ 56/* Values for in_memory below. Should probably be an enumerations */
93#define MAP_IN_MEMORY 1 57#define MAP_IN_MEMORY 1
94#define MAP_SWAPPED 2 58#define MAP_SWAPPED 2
101 * consistent (eg, op->map, op->x, op->y) 65 * consistent (eg, op->map, op->x, op->y)
102 */ 66 */
103// all those macros are herewith declared legacy 67// all those macros are herewith declared legacy
104#define GET_MAP_FLAGS(M,X,Y) (M)->at((X),(Y)).flags () 68#define GET_MAP_FLAGS(M,X,Y) (M)->at((X),(Y)).flags ()
105#define GET_MAP_LIGHT(M,X,Y) (M)->at((X),(Y)).light 69#define GET_MAP_LIGHT(M,X,Y) (M)->at((X),(Y)).light
106#define GET_MAP_OB(M,X,Y) (M)->at((X),(Y)).bottom 70#define GET_MAP_OB(M,X,Y) (M)->at((X),(Y)).bot
107#define GET_MAP_TOP(M,X,Y) (M)->at((X),(Y)).top 71#define GET_MAP_TOP(M,X,Y) (M)->at((X),(Y)).top
108#define GET_MAP_FACE(M,X,Y,L) (M)->at((X),(Y)).faces[L] 72#define GET_MAP_FACE(M,X,Y,L) (M)->at((X),(Y)).faces[L]
109#define GET_MAP_FACE_OBJ(M,X,Y,L) (M)->at((X),(Y)).faces_obj[L] 73#define GET_MAP_FACE_OBJ(M,X,Y,L) (M)->at((X),(Y)).faces_obj[L]
110#define GET_MAP_MOVE_BLOCK(M,X,Y) (M)->at((X),(Y)).move_block 74#define GET_MAP_MOVE_BLOCK(M,X,Y) (M)->at((X),(Y)).move_block
111#define GET_MAP_MOVE_SLOW(M,X,Y) (M)->at((X),(Y)).move_slow 75#define GET_MAP_MOVE_SLOW(M,X,Y) (M)->at((X),(Y)).move_slow
155 * This puts it all in one place, and should also make it easier 119 * This puts it all in one place, and should also make it easier
156 * to extend information about a space. 120 * to extend information about a space.
157 */ 121 */
158struct mapspace 122struct mapspace
159{ 123{
160 object *bottom; /* lowest object on this space */ 124 object *bot, *top; /* lowest/highest object on this space */
161 object *top; /* Highest object on this space */
162 New_Face *faces[MAP_LAYERS]; /* faces for the 3 layers */ 125 New_Face *faces[MAP_LAYERS]; /* faces for the 3 layers */
163 object *faces_obj[MAP_LAYERS];/* face objects for the 3 layers */ 126 object *faces_obj[MAP_LAYERS];/* face objects for the 3 layers */
164 uint8 flags_; /* flags about this space (see the P_ values above) */ 127 uint8 flags_; /* flags about this space (see the P_ values above) */
165 sint8 light; /* How much light this space provides */ 128 sint8 light; /* How much light this space provides */
166 MoveType move_block; /* What movement types this space blocks */ 129 MoveType move_block; /* What movement types this space blocks */
182 } 145 }
183 146
184 // maybe only inline quick flags_ checking? 147 // maybe only inline quick flags_ checking?
185 object *player () 148 object *player ()
186 { 149 {
150 // search from the top, because players are usually on top
151 // make usually == always and this non-amortized O(1)
152 // could gte rid of P_PLAYER, too, then
187 if (flags () & P_PLAYER) 153 if (flags () & P_PLAYER)
188 for (object *op = bottom; op; op = op->above) 154 for (object *op = top; op; op = op->below)
189 if (op->type == PLAYER) 155 if (op->type == PLAYER)
190 return op; 156 return op;
191 157
192 return 0; 158 return 0;
193 } 159 }
264 * almost certainly break various features. You may think 230 * almost certainly break various features. You may think
265 * it is safe to look at width and height values directly 231 * it is safe to look at width and height values directly
266 * (or even through the macros), but doing so will completely 232 * (or even through the macros), but doing so will completely
267 * break map tiling. 233 * break map tiling.
268 */ 234 */
269ACC_CLASS (maptile) 235INTERFACE_CLASS (maptile)
270struct maptile : zero_initialised, attachable<maptile> 236struct maptile : zero_initialised, attachable
271{ 237{
272 sint32 ACC (RO, width), ACC (RO, height); /* Width and height of map. */ 238 sint32 ACC (RO, width), ACC (RO, height); /* Width and height of map. */
273 struct mapspace *spaces; /* Array of spaces on this map */ 239 struct mapspace *spaces; /* Array of spaces on this map */
274 240
275 maptile *ACC (RW, next); /* Next map, linked list */ 241 maptile *ACC (RW, next); /* Next map, linked list */
305 sint16 ACC (RW, pressure); /* barometric pressure (mb) */ 271 sint16 ACC (RW, pressure); /* barometric pressure (mb) */
306 sint8 ACC (RW, humid); /* humitidy of this tile */ 272 sint8 ACC (RW, humid); /* humitidy of this tile */
307 sint8 ACC (RW, windspeed); /* windspeed of this tile */ 273 sint8 ACC (RW, windspeed); /* windspeed of this tile */
308 sint8 ACC (RW, winddir); /* direction of wind */ 274 sint8 ACC (RW, winddir); /* direction of wind */
309 sint8 ACC (RW, sky); /* sky conditions */ 275 sint8 ACC (RW, sky); /* sky conditions */
310 int ACC (RW, wpartx), ACC (RW, wparty); /*Highly fasten conversion between worldmap and weathermap */ 276 int ACC (RW, worldpartx), ACC (RW, worldparty); /*Highly fasten conversion between worldmap and weathermap */
311 struct shopitems *shopitems; /* a semi-colon seperated list of item-types the map's shop will trade in */ 277 struct shopitems *shopitems; /* a semi-colon seperated list of item-types the map's shop will trade in */
312 char *ACC (RO, shoprace); /* the preffered race of the local shopkeeper */ 278 char *ACC (RO, shoprace); /* the preffered race of the local shopkeeper */
313 double ACC (RW, shopgreed); /* how much our shopkeeper overcharges */ 279 double ACC (RW, shopgreed); /* how much our shopkeeper overcharges */
314 sint64 ACC (RW, shopmin); /* minimum price a shop will trade for */ 280 sint64 ACC (RW, shopmin); /* minimum price a shop will trade for */
315 sint64 ACC (RW, shopmax); /* maximum price a shop will offer */ 281 sint64 ACC (RW, shopmax); /* maximum price a shop will offer */
318 char *tile_path[4]; /* path to adjoining maps */ 284 char *tile_path[4]; /* path to adjoining maps */
319 maptile *tile_map[4]; /* Next map, linked list */ 285 maptile *tile_map[4]; /* Next map, linked list */
320 char ACC (RW, path)[HUGE_BUF]; /* Filename of the map */ 286 char ACC (RW, path)[HUGE_BUF]; /* Filename of the map */
321 287
322 maptile (); 288 maptile ();
289 ~maptile ();
290 void do_destroy ();
291 void gather_callbacks (AV *&callbacks, event_type event) const;
292
323 void allocate (); 293 MTH void allocate ();
294 MTH int size () const { return width * height; }
324 295
296 MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0);
297
298 MTH void link ();
299 MTH void unlink ();
300
325 mapspace const &at (uint32 x, uint32 y) const { return spaces [x + width * y]; } 301 mapspace const &at (uint32 x, uint32 y) const { return spaces [x * height + y]; }
326 mapspace &at (uint32 x, uint32 y) { return spaces [x + width * y]; } 302 mapspace &at (uint32 x, uint32 y) { return spaces [x * height + y]; }
327}; 303};
304
305#define for_all_maps(var) for (maptile *var = first_map; var; var = var->next)
328 306
329/* This is used by get_rangevector to determine where the other 307/* This is used by get_rangevector to determine where the other
330 * creature is. get_rangevector takes into account map tiling, 308 * creature is. get_rangevector takes into account map tiling,
331 * so you just can not look the the map coordinates and get the 309 * so you just can not look the the map coordinates and get the
332 * righte value. distance_x/y are distance away, which 310 * righte value. distance_x/y are distance away, which
342 int distance_y; 320 int distance_y;
343 int direction; 321 int direction;
344 object *part; 322 object *part;
345}; 323};
346 324
325inline mapspace &
326object::ms () const
327{
328 return map->at (x, y);
329}
330
347#endif 331#endif
348 332

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines