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.29 by root, Wed Dec 20 09:14:22 2006 UTC vs.
Revision 1.38 by root, Wed Dec 27 09:28:01 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
99 * really be used, as it is multi tile aware. However, there are some cases 63 * really be used, as it is multi tile aware. However, there are some cases
100 * where it is known the map is not tiled or the values are known 64 * where it is known the map is not tiled or the values are known
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 SET_MAP_FLAGS(M,X,Y,C) (M)->at((X),(Y)).flags = (C)
106#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
107#define SET_MAP_LIGHT(M,X,Y,L) (M)->at((X),(Y)).light = (L)
108#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
109#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
110#define SET_MAP_OB(M,X,Y,tmp) (M)->at((X),(Y)).bottom = (tmp)
111#define SET_MAP_TOP(M,X,Y,tmp) (M)->at((X),(Y)).top = (tmp)
112#define SET_MAP_FACE(M,X,Y,C,L) (M)->at((X),(Y)).faces[L] = (C)
113#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]
114#define SET_MAP_FACE_OBJ(M,X,Y,C,L) (M)->at((X),(Y)).faces_obj[L] = (C)
115#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]
116#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
117#define SET_MAP_MOVE_BLOCK(M,X,Y,C) (M)->at((X),(Y)).move_block = (C)
118#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
119#define SET_MAP_MOVE_SLOW(M,X,Y,C) (M)->at((X),(Y)).move_slow = (C)
120#define GET_MAP_MOVE_ON(M,X,Y) (M)->at((X),(Y)).move_on 76#define GET_MAP_MOVE_ON(M,X,Y) (M)->at((X),(Y)).move_on
121#define SET_MAP_MOVE_ON(M,X,Y,C) (M)->at((X),(Y)).move_on = (C)
122#define GET_MAP_MOVE_OFF(M,X,Y) (M)->at((X),(Y)).move_off 77#define GET_MAP_MOVE_OFF(M,X,Y) (M)->at((X),(Y)).move_off
123#define SET_MAP_MOVE_OFF(M,X,Y,C) (M)->at((X),(Y)).move_off = (C)
124 78
125/* You should really know what you are doing before using this - you 79/* You should really know what you are doing before using this - you
126 * should almost always be using out_of_map instead, which takes into account 80 * should almost always be using out_of_map instead, which takes into account
127 * map tiling. 81 * map tiling.
128 */ 82 */
139 * such as: bombs, potion usage, alchemy, spells 93 * such as: bombs, potion usage, alchemy, spells
140 * this was introduced to make shops safer 94 * this was introduced to make shops safer
141 * but is useful in other situations */ 95 * but is useful in other situations */
142#define P_IS_ALIVE 0x10 /* something alive is on this space */ 96#define P_IS_ALIVE 0x10 /* something alive is on this space */
143#define P_NO_CLERIC 0x20 /* no clerical spells cast here */ 97#define P_NO_CLERIC 0x20 /* no clerical spells cast here */
98
144#define P_NEED_UPDATE 0x40 /* this space is out of date */ 99#define P_NEED_UPDATE 0x80 /* this space is out of date */
145#define P_NO_ERROR 0x80 /* Purely temporary - if set, update_position
146 * does not complain if the flags are different.
147 */
148 100
149/* The following two values are not stored in the MapLook flags, but instead 101/* The following two values are not stored in the MapLook flags, but instead
150 * used in the get_map_flags value - that function is used to return 102 * used in the get_map_flags value - that function is used to return
151 * the flag value, as well as other conditions - using a more general 103 * the flag value, as well as other conditions - using a more general
152 * function that does more of the work can hopefully be used to replace 104 * function that does more of the work can hopefully be used to replace
167 * 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
168 * to extend information about a space. 120 * to extend information about a space.
169 */ 121 */
170struct mapspace 122struct mapspace
171{ 123{
172 object *bottom; /* lowest object on this space */ 124 object *bot, *top; /* lowest/highest object on this space */
173 object *top; /* Highest object on this space */
174 New_Face *faces[MAP_LAYERS]; /* faces for the 3 layers */ 125 New_Face *faces[MAP_LAYERS]; /* faces for the 3 layers */
175 object *faces_obj[MAP_LAYERS]; /* face objects for the 3 layers */ 126 object *faces_obj[MAP_LAYERS];/* face objects for the 3 layers */
176 uint8 flags; /* flags about this space (see the P_ values above) */ 127 uint8 flags_; /* flags about this space (see the P_ values above) */
177 sint8 light; /* How much light this space provides */ 128 sint8 light; /* How much light this space provides */
178 uint8 move_block; /* What movement types this space blocks */ 129 MoveType move_block; /* What movement types this space blocks */
179 uint8 move_slow; /* What movement types this space slows */ 130 MoveType move_slow; /* What movement types this space slows */
180 uint8 move_on; /* What movement types are activated */ 131 MoveType move_on; /* What movement types are activated */
181 uint8 move_off; /* What movement types are activated */ 132 MoveType move_off; /* What movement types are activated */
133
134 void update_ ();
135 void update ()
136 {
137 if (flags_ & P_NEED_UPDATE)
138 update_ ();
139 }
140
141 uint8 flags ()
142 {
143 update ();
144 return flags_;
145 }
146
147 // maybe only inline quick flags_ checking?
148 object *player ()
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
153 if (flags () & P_PLAYER)
154 for (object *op = top; op; op = op->below)
155 if (op->type == PLAYER)
156 return op;
157
158 return 0;
159 }
182}; 160};
183 161
184/* 162/*
185 * this is an overlay structure of the whole world. It exists as a simple 163 * this is an overlay structure of the whole world. It exists as a simple
186 * high level map, which doesn't contain the full data of the underlying map. 164 * high level map, which doesn't contain the full data of the underlying map.
252 * almost certainly break various features. You may think 230 * almost certainly break various features. You may think
253 * it is safe to look at width and height values directly 231 * it is safe to look at width and height values directly
254 * (or even through the macros), but doing so will completely 232 * (or even through the macros), but doing so will completely
255 * break map tiling. 233 * break map tiling.
256 */ 234 */
257ACC_CLASS (maptile) 235INTERFACE_CLASS (maptile)
258struct maptile : zero_initialised, attachable<maptile> 236struct maptile : zero_initialised, attachable
259{ 237{
260 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. */
261 struct mapspace *spaces; /* Array of spaces on this map */ 239 struct mapspace *spaces; /* Array of spaces on this map */
262 240
263 maptile *ACC (RW, next); /* Next map, linked list */ 241 maptile *ACC (RW, next); /* Next map, linked list */
293 sint16 ACC (RW, pressure); /* barometric pressure (mb) */ 271 sint16 ACC (RW, pressure); /* barometric pressure (mb) */
294 sint8 ACC (RW, humid); /* humitidy of this tile */ 272 sint8 ACC (RW, humid); /* humitidy of this tile */
295 sint8 ACC (RW, windspeed); /* windspeed of this tile */ 273 sint8 ACC (RW, windspeed); /* windspeed of this tile */
296 sint8 ACC (RW, winddir); /* direction of wind */ 274 sint8 ACC (RW, winddir); /* direction of wind */
297 sint8 ACC (RW, sky); /* sky conditions */ 275 sint8 ACC (RW, sky); /* sky conditions */
298 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 */
299 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 */
300 char *ACC (RO, shoprace); /* the preffered race of the local shopkeeper */ 278 char *ACC (RO, shoprace); /* the preffered race of the local shopkeeper */
301 double ACC (RW, shopgreed); /* how much our shopkeeper overcharges */ 279 double ACC (RW, shopgreed); /* how much our shopkeeper overcharges */
302 sint64 ACC (RW, shopmin); /* minimum price a shop will trade for */ 280 sint64 ACC (RW, shopmin); /* minimum price a shop will trade for */
303 sint64 ACC (RW, shopmax); /* maximum price a shop will offer */ 281 sint64 ACC (RW, shopmax); /* maximum price a shop will offer */
306 char *tile_path[4]; /* path to adjoining maps */ 284 char *tile_path[4]; /* path to adjoining maps */
307 maptile *tile_map[4]; /* Next map, linked list */ 285 maptile *tile_map[4]; /* Next map, linked list */
308 char ACC (RW, path)[HUGE_BUF]; /* Filename of the map */ 286 char ACC (RW, path)[HUGE_BUF]; /* Filename of the map */
309 287
310 maptile (); 288 maptile ();
289 ~maptile ();
290 void do_destroy ();
291 void gather_callbacks (AV *&callbacks, event_type event) const;
292
311 void allocate (); 293 MTH void allocate ();
294 MTH int size () const { return width * height; }
312 295
296 MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0);
297
313 mapspace const &at (uint32 x, uint32 y) const { return spaces [x + width * y]; } 298 mapspace const &at (uint32 x, uint32 y) const { return spaces [x * height + y]; }
314 mapspace &at (uint32 x, uint32 y) { return spaces [x + width * y]; } 299 mapspace &at (uint32 x, uint32 y) { return spaces [x * height + y]; }
315}; 300};
301
302#define for_all_maps(var) for (maptile *var = first_map; var; var = var->next)
316 303
317/* This is used by get_rangevector to determine where the other 304/* This is used by get_rangevector to determine where the other
318 * creature is. get_rangevector takes into account map tiling, 305 * creature is. get_rangevector takes into account map tiling,
319 * so you just can not look the the map coordinates and get the 306 * so you just can not look the the map coordinates and get the
320 * righte value. distance_x/y are distance away, which 307 * righte value. distance_x/y are distance away, which
330 int distance_y; 317 int distance_y;
331 int direction; 318 int direction;
332 object *part; 319 object *part;
333}; 320};
334 321
322inline mapspace &
323object::ms () const
324{
325 return map->at (x, y);
326}
327
335#endif 328#endif
336 329

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines