Crossfire Server, Trunk
map.h
Go to the documentation of this file.
1 
6 /*
7  * The mapstruct is allocated each time a new map is opened.
8  * It contains pointers (very indirectly) to all objects on the map.
9  */
10 
11 #ifndef MAP_H
12 #define MAP_H
13 
14 /* We set this size - this is to make magic map work properly on
15  * tiled maps. There is no requirement that this matches the
16  * tiled maps size - it just seemed like a reasonable value.
17  * Magic map code now always starts out putting the player in the
18  * center of the map - this makes the most sense when dealing
19  * with tiled maps.
20  * We also figure out the magicmap color to use as we process the
21  * spaces - this is more efficient as we already have up to date
22  * map pointers.
23  */
24 #define MAGIC_MAP_SIZE 50
25 #define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2
26 
27 /* This correspondes to the map layers in the map2 protocol.
28  * The MAP_LAYER_... correspond to what goes on what layer -
29  * this removes the need for hardcoding, and also makes sure
30  * we don't overstep the number of layers.
31  */
32 #define MAP_LAYERS 10
33 
34 extern const char *const map_layer_name[MAP_LAYERS];
35 
40 #define MAP_LAYER_FLOOR 0
41 #define MAP_LAYER_NO_PICK1 1
42 #define MAP_LAYER_NO_PICK2 2
43 #define MAP_LAYER_ITEM1 3
44 #define MAP_LAYER_ITEM2 4
45 #define MAP_LAYER_ITEM3 5
46 #define MAP_LAYER_LIVING1 6
47 #define MAP_LAYER_LIVING2 7
48 #define MAP_LAYER_FLY1 8
49 #define MAP_LAYER_FLY2 9
51 
52 
57 #define MAP_TYPE_LEGACY 1
58 #define MAP_TYPE_DEFAULT 2
59 #define MAP_TYPE_CHOICE 3
62 #define MAP_WHEN_RESET(m) ((m)->reset_time)
63 
64 #define MAP_RESET_TIMEOUT(m) ((m)->reset_timeout)
65 #define MAP_DIFFICULTY(m) ((m)->difficulty)
66 #define MAP_TIMEOUT(m) ((m)->timeout)
67 #define MAP_SWAP_TIME(m) ((m)->swap_time)
68 #define MAP_OUTDOORS(m) ((m)->outdoor)
69 
71 #define MAP_DARKNESS(m) (m)->darkness
72 
74 #define MAP_WIDTH(m) (m)->width
75 
76 #define MAP_HEIGHT(m) (m)->height
77 
78 #define MAP_SIZE(m) map_size(m)
79 
81 #define MAP_ENTER_X(m) (m)->enter_x
82 
83 #define MAP_ENTER_Y(m) (m)->enter_y
84 
85 #define MAP_NOSMOOTH(m) (m)->nosmooth
86 
92 #define MAP_FLUSH 0x1
93 #define MAP_PLAYER_UNIQUE 0x2
94 #define MAP_NO_DIFFICULTY 0x4
95 #define MAP_STYLE 0x8
96 #define MAP_OVERLAY 0x10
98 
99 
107 #define SAVE_FLAG_SAVE_UNPAID 1
108 #define SAVE_FLAG_NO_REMOVE 2
110 
111 
117 #define SAVE_MODE_NORMAL 0
118 #define SAVE_MODE_INPLACE 1
119 #define SAVE_MODE_OVERLAY 2
121 
122 
127 #define MAP_IN_MEMORY 1
128 #define MAP_SWAPPED 2
129 #define MAP_LOADING 3
130 #define MAP_SAVING 4
132 
133 
140 #define SAVE_ERROR_OK 0
141 #define SAVE_ERROR_RCREATION -1
142 #define SAVE_ERROR_UCREATION -2
143 #define SAVE_ERROR_WRITE -3
144 #define SAVE_ERROR_NO_PATH -4
145 #define SAVE_ERROR_URENAME -5
146 #define SAVE_ERROR_CLOSE -6
147 /* -7 (no longer used) */
148 #define SAVE_ERROR_NOT_IN_MEMORY -10
149 #define SAVE_ERROR_PLAYER -11
151 
152 /* GET_MAP_FLAGS really shouldn't be used very often - get_map_flags should
153  * really be used, as it is multi tile aware. However, there are some cases
154  * where it is known the map is not tiled or the values are known
155  * consistent (eg, op->map, op->x, op->y)
156  */
158 #define GET_MAP_FLAGS(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].flags)
159 
160 #define SET_MAP_FLAGS(M, X, Y, C) ((M)->spaces[(X)+(M)->width*(Y)].flags = C)
161 
163 #define GET_MAP_LIGHT(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].light)
164 
165 #define SET_MAP_LIGHT(M, X, Y, L) ((M)->spaces[(X)+(M)->width*(Y)].light = L)
166 
167 #define GET_MAP_PLAYER(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].pl)
168 #define SET_MAP_PLAYER(M, X, Y, C) ((M)->spaces[(X)+(M)->width*(Y)].pl = C)
169 
171 #define GET_MAP_OB(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].bottom)
172 
173 #define GET_MAP_TOP(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].top)
174 
176 #define SET_MAP_OB(M, X, Y, tmp) ((M)->spaces[(X)+(M)->width*(Y)].bottom = (tmp))
177 
178 #define SET_MAP_TOP(M, X, Y, tmp) ((M)->spaces[(X)+(M)->width*(Y)].top = (tmp))
179 
181 #define SET_MAP_FACE_OBJ(M, X, Y, C, L) ((M)->spaces[(X)+(M)->width*(Y)].faces_obj[L] = C)
182 
183 #define GET_MAP_FACE_OBJ(M, X, Y, L) ((M)->spaces[(X)+(M)->width*(Y)].faces_obj[L])
184 
188 #define GET_MAP_FACE_OBJS(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].faces_obj)
189 
191 #define GET_MAP_MOVE_BLOCK(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].move_block)
192 
193 #define SET_MAP_MOVE_BLOCK(M, X, Y, C) ((M)->spaces[(X)+(M)->width*(Y)].move_block = C)
194 
196 #define GET_MAP_MOVE_SLOW(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].move_slow)
197 
198 #define SET_MAP_MOVE_SLOW(M, X, Y, C) ((M)->spaces[(X)+(M)->width*(Y)].move_slow = C)
199 
201 #define GET_MAP_MOVE_ON(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].move_on)
202 
203 #define SET_MAP_MOVE_ON(M, X, Y, C) ((M)->spaces[(X)+(M)->width*(Y)].move_on = C)
204 
206 #define GET_MAP_MOVE_OFF(M, X, Y) ((M)->spaces[(X)+(M)->width*(Y)].move_off)
207 
208 #define SET_MAP_MOVE_OFF(M, X, Y, C) ((M)->spaces[(X)+(M)->width*(Y)].move_off = C)
209 
216 #define OUT_OF_REAL_MAP(M, X, Y) ((X) < 0 || (Y) < 0 || (X) >= (M)->width || (Y) >= (M)->height)
217 
225 #define P_BLOCKSVIEW 0x01
226 #define P_NO_MAGIC 0x02
228 /* AB_NO_PASS is used for arch_blocked() return value. It needs
229  * to be here to make sure the bits don't match with anything.
230  * Changed name to have AB_ prefix just to make sure no one
231  * is using the P_NO_PASS. AB_.. should only be used for
232  * arch_blocked and functions that examine the return value.
233  */
234 #define AB_NO_PASS 0x04
235 #define P_PLAYER 0x08
236 #define P_IS_ALIVE 0x10
237 #define P_NO_CLERIC 0x20
238 #define P_NEED_UPDATE 0x40
239 #define P_NO_ERROR 0x80
242 /* The following two values are not stored in the MapLook flags, but instead
243  * used in the get_map_flags value - that function is used to return
244  * the flag value, as well as other conditions - using a more general
245  * function that does more of the work can hopefully be used to replace
246  * lots of duplicate checks currently in the code.
247  */
248 #define P_OUT_OF_MAP 0x100
249 #define P_NEW_MAP 0x200
251 
252 
255 struct MapSpace {
256  object *bottom;
257  object *top;
259  uint8_t flags;
260  int8_t light;
265  object *pl;
266 };
267 
273 struct region {
274  char *name;
280  char *longname;
282  char *msg;
283  uint32_t counter;
284  int8_t fallback;
286  char *jailmap;
287  int16_t jailx, jaily;
288 };
289 
294 struct shopitems {
295  const char *name;
296  const char *name_pl;
297  int typenum;
298  int8_t strength;
300  int index;
301 };
302 
314 struct mapstruct {
316  char *tmpname;
317  char *name;
318  struct region *region;
321  uint32_t reset_time;
322  uint32_t reset_timeout;
324  uint32_t fixed_resettime:1;
327  uint32_t unique:1;
328  uint32_t is_template:1;
329  uint32_t nosmooth:1;
330  uint32_t outdoor:1;
331  int32_t timeout;
332  int32_t swap_time;
333  uint16_t difficulty;
334  int16_t players;
335  uint32_t in_memory;
336  uint8_t darkness;
337  uint16_t width, height;
338  int16_t enter_x, enter_y;
347  char *shoprace;
348  double shopgreed;
349  uint64_t shopmin;
350  uint64_t shopmax;
351  char *msg;
352  char *maplore;
353  char *tile_path[4];
355  char path[HUGE_BUF];
358 };
359 
370 struct rv_vector {
371  unsigned int distance;
374  int direction;
375  object *part;
376 };
377 
378 uint32_t map_size(mapstruct *m);
379 
380 #endif /* MAP_H */
mapstruct::shopgreed
double shopgreed
Definition: map.h:348
mapstruct::tile_path
char * tile_path[4]
Definition: map.h:353
shopitems::strength
int8_t strength
Definition: map.h:298
mapstruct::region
struct region * region
Definition: map.h:318
mapstruct::difficulty
uint16_t difficulty
Definition: map.h:333
MapSpace::move_block
MoveType move_block
Definition: map.h:261
region::fallback
int8_t fallback
Definition: map.h:284
mapstruct::outdoor
uint32_t outdoor
Definition: map.h:330
map_layer_name
const char *const map_layer_name[MAP_LAYERS]
Definition: map.cpp:45
mapstruct::shopmin
uint64_t shopmin
Definition: map.h:349
mapstruct::buttons
oblinkpt * buttons
Definition: map.h:344
MapSpace
Definition: map.h:255
mapstruct::players
int16_t players
Definition: map.h:334
mapstruct::tmpname
char * tmpname
Definition: map.h:316
MoveType
unsigned char MoveType
Definition: define.h:417
shopitems::index
int index
Definition: map.h:300
mapstruct::height
uint16_t height
Definition: map.h:337
MAP_LAYERS
#define MAP_LAYERS
Definition: map.h:32
mapstruct::swap_time
int32_t swap_time
Definition: map.h:332
oblinkpt
Definition: object.h:460
region::name
char * name
Definition: map.h:274
MapSpace::light
int8_t light
Definition: map.h:260
rv_vector::part
object * part
Definition: map.h:375
mapstruct::is_template
uint32_t is_template
Definition: map.h:328
mapstruct::path
char path[HUGE_BUF]
Definition: map.h:355
HUGE_BUF
#define HUGE_BUF
Definition: define.h:37
mapstruct::width
uint16_t width
Definition: map.h:337
region::longname
char * longname
Definition: map.h:280
rv_vector::distance_y
int distance_y
Definition: map.h:373
mapstruct::shopitems
struct shopitems * shopitems
Definition: map.h:346
m
static event_registration m
Definition: citylife.cpp:425
rv_vector::distance_x
int distance_x
Definition: map.h:372
mapstruct::shoprace
char * shoprace
Definition: map.h:347
region::parent
region * parent
Definition: map.h:275
region::msg
char * msg
Definition: map.h:282
region::jailmap
char * jailmap
Definition: map.h:286
shopitems::name_pl
const char * name_pl
Definition: map.h:296
MapSpace::top
object * top
Definition: map.h:257
mapstruct::reset_group
sstring reset_group
Definition: map.h:326
mapstruct::last_reset_time
long last_reset_time
Definition: map.h:356
mapstruct::maplore
char * maplore
Definition: map.h:352
shopitems::typenum
int typenum
Definition: map.h:297
mapstruct::shopmax
uint64_t shopmax
Definition: map.h:350
MapSpace::move_slow
MoveType move_slow
Definition: map.h:262
MapSpace::pl
object * pl
Definition: map.h:265
region
Definition: map.h:273
MapSpace::faces_obj
object * faces_obj[MAP_LAYERS]
Definition: map.h:258
MapSpace::flags
uint8_t flags
Definition: map.h:259
mapstruct::background_music
char * background_music
Definition: map.h:357
shopitems::name
const char * name
Definition: map.h:295
mapstruct::reset_timeout
uint32_t reset_timeout
Definition: map.h:322
mapstruct
Definition: map.h:314
sstring
const typedef char * sstring
Definition: sstring.h:2
mapstruct::nosmooth
uint32_t nosmooth
Definition: map.h:329
mapstruct::name
char * name
Definition: map.h:317
mapstruct::enter_x
int16_t enter_x
Definition: map.h:338
mapstruct::in_memory
uint32_t in_memory
Definition: map.h:335
rv_vector
Definition: map.h:370
shopitems
Definition: map.h:294
mapstruct::timeout
int32_t timeout
Definition: map.h:331
mapstruct::tile_map
mapstruct * tile_map[4]
Definition: map.h:354
mapstruct::spaces
MapSpace * spaces
Definition: map.h:345
mapstruct::msg
char * msg
Definition: map.h:351
region::counter
uint32_t counter
Definition: map.h:283
MapSpace::bottom
object * bottom
Definition: map.h:256
map_size
uint32_t map_size(mapstruct *m)
Definition: map.cpp:798
mapstruct::enter_y
int16_t enter_y
Definition: map.h:338
mapstruct::unique
uint32_t unique
Definition: map.h:327
mapstruct::next
mapstruct * next
Definition: map.h:315
mapstruct::reset_time
uint32_t reset_time
Definition: map.h:321
mapstruct::darkness
uint8_t darkness
Definition: map.h:336
MapSpace::move_off
MoveType move_off
Definition: map.h:264
rv_vector::direction
int direction
Definition: map.h:374
mapstruct::fixed_resettime
uint32_t fixed_resettime
Definition: map.h:324
rv_vector::distance
unsigned int distance
Definition: map.h:371
MapSpace::move_on
MoveType move_on
Definition: map.h:263
region::jaily
int16_t jaily
Definition: map.h:287
region::jailx
int16_t jailx
Definition: map.h:287