Crossfire Server, Trunk  1.75.0
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_OUTDOORS(m) ((m)->outdoor)
68 
70 #define MAP_DARKNESS(m) (m)->darkness
71 
73 #define MAP_WIDTH(m) (m)->width
74 
75 #define MAP_HEIGHT(m) (m)->height
76 
77 #define MAP_SIZE(m) map_size(m)
78 
80 #define MAP_ENTER_X(m) (m)->enter_x
81 
82 #define MAP_ENTER_Y(m) (m)->enter_y
83 
84 #define MAP_NOSMOOTH(m) (m)->nosmooth
85 
91 #define MAP_FLUSH 0x1
92 #define MAP_PLAYER_UNIQUE 0x2
93 #define MAP_NO_DIFFICULTY 0x4
94 #define MAP_STYLE 0x8
95 #define MAP_OVERLAY 0x10
97 
98 
106 #define SAVE_FLAG_SAVE_UNPAID 1
107 #define SAVE_FLAG_NO_REMOVE 2
109 
110 
116 #define SAVE_MODE_NORMAL 0
117 #define SAVE_MODE_INPLACE 1
118 #define SAVE_MODE_OVERLAY 2
120 
121 
126 #define MAP_IN_MEMORY 1
127 #define MAP_SWAPPED 2
128 #define MAP_LOADING 3
129 #define MAP_SAVING 4
131 
132 
139 #define SAVE_ERROR_OK 0
140 #define SAVE_ERROR_RCREATION -1
141 #define SAVE_ERROR_UCREATION -2
142 #define SAVE_ERROR_WRITE -3
143 #define SAVE_ERROR_NO_PATH -4
144 #define SAVE_ERROR_URENAME -5
145 #define SAVE_ERROR_CLOSE -6
146 /* -7 (no longer used) */
147 #define SAVE_ERROR_NOT_IN_MEMORY -10
148 #define SAVE_ERROR_PLAYER -11
150 
151 /* GET_MAP_FLAGS really shouldn't be used very often - get_map_flags should
152  * really be used, as it is multi tile aware. However, there are some cases
153  * where it is known the map is not tiled or the values are known
154  * consistent (eg, op->map, op->x, op->y)
155  */
157 #define GET_MAP_FLAGS(M, X, Y) (map_space(M, X, Y)->flags)
158 
159 #define SET_MAP_FLAGS(M, X, Y, C) (map_space(M, X, Y)->flags = C)
160 
162 #define GET_MAP_LIGHT(M, X, Y) (map_space(M, X, Y)->light)
163 
164 #define SET_MAP_LIGHT(M, X, Y, L) (map_space(M, X, Y)->light = L)
165 
166 #define GET_MAP_PLAYER(M, X, Y) (map_space(M, X, Y)->pl)
167 #define SET_MAP_PLAYER(M, X, Y, C) (map_space(M, X, Y)->pl = C)
168 
170 #define GET_MAP_OB(M, X, Y) (map_space(M, X, Y)->bottom)
171 
172 #define GET_MAP_TOP(M, X, Y) (map_space(M, X, Y)->top)
173 
175 #define SET_MAP_OB(M, X, Y, tmp) (map_space(M, X, Y)->bottom = (tmp))
176 
177 #define SET_MAP_TOP(M, X, Y, tmp) (map_space(M, X, Y)->top = (tmp))
178 
180 #define SET_MAP_FACE_OBJ(M, X, Y, C, L) (map_space(M, X, Y)->faces_obj[L] = C)
181 
182 #define GET_MAP_FACE_OBJ(M, X, Y, L) (map_space(M, X, Y)->faces_obj[L])
183 
187 #define GET_MAP_FACE_OBJS(M, X, Y) (map_space(M, X, Y)->faces_obj)
188 
189 extern bool ob_move_block(object *ob1, object *ob2);
190 
192 #define GET_MAP_MOVE_BLOCK(M, X, Y) (map_space(M, X, Y)->move_block)
193 
194 #define SET_MAP_MOVE_BLOCK(M, X, Y, C) (map_space(M, X, Y)->move_block = C)
195 
197 #define GET_MAP_MOVE_SLOW(M, X, Y) (map_space(M, X, Y)->move_slow)
198 
199 #define SET_MAP_MOVE_SLOW(M, X, Y, C) (map_space(M, X, Y)->move_slow = C)
200 
202 #define GET_MAP_MOVE_ON(M, X, Y) (map_space(M, X, Y)->move_on)
203 
204 #define SET_MAP_MOVE_ON(M, X, Y, C) (map_space(M, X, Y)->move_on = C)
205 
207 #define GET_MAP_MOVE_OFF(M, X, Y) (map_space(M, X, Y)->move_off)
208 
209 #define SET_MAP_MOVE_OFF(M, X, Y, C) (map_space(M, X, Y)->move_off = C)
210 
217 #define OUT_OF_REAL_MAP(M, X, Y) ((X) < 0 || (Y) < 0 || (X) >= (M)->width || (Y) >= (M)->height)
218 
226 #define P_BLOCKSVIEW 0x01
227 #define P_NO_MAGIC 0x02
229 /* AB_NO_PASS is used for arch_blocked() return value. It needs
230  * to be here to make sure the bits don't match with anything.
231  * Changed name to have AB_ prefix just to make sure no one
232  * is using the P_NO_PASS. AB_.. should only be used for
233  * arch_blocked and functions that examine the return value.
234  */
235 #define AB_NO_PASS 0x04
236 #define P_PLAYER 0x08
237 #define P_IS_ALIVE 0x10
238 #define P_NO_CLERIC 0x20
239 #define P_NEED_UPDATE 0x40
240 #define P_NO_ERROR 0x80
243 /* The following two values are not stored in the MapLook flags, but instead
244  * used in the get_map_flags value - that function is used to return
245  * the flag value, as well as other conditions - using a more general
246  * function that does more of the work can hopefully be used to replace
247  * lots of duplicate checks currently in the code.
248  */
249 #define P_OUT_OF_MAP 0x100
250 #define P_NEW_MAP 0x200
252 
253 
256 struct MapSpace {
257  object *bottom;
258  object *top;
260  uint8_t flags;
261  int8_t light;
266  object *pl;
267 };
268 
274 struct region {
275  char *name;
281  char *longname;
283  char *msg;
284  uint32_t counter;
285  int8_t fallback;
287  char *jailmap;
288  int16_t jailx, jaily;
289 };
290 
295 struct shopitems {
296  const char *name;
297  const char *name_pl;
298  int typenum;
299  int8_t strength;
301  int index;
302 };
303 
315 struct mapstruct {
317  char *tmpname;
318  char *name;
319  struct region *region;
322  uint32_t reset_time;
323  uint32_t reset_timeout;
325  uint32_t fixed_resettime:1;
328  uint32_t unique:1;
329  uint32_t is_template:1;
330  uint32_t nosmooth:1;
331  uint32_t outdoor:1;
332  int32_t timeout;
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 extern bool map_path_unique(const char *name);
381 
382 extern MapSpace *map_space(const mapstruct *m, int x, int y);
383 
384 extern void map_reset_swap(mapstruct *m);
385 
386 extern int map_light_on(mapstruct *m, int x, int y);
387 
388 extern bool coords_in_shop(mapstruct *map, int x, int y);
389 
393 extern bool shop_contains(object *ob);
394 
395 #endif /* MAP_H */
mapstruct::shopgreed
double shopgreed
How much our shopkeeper overcharges.
Definition: map.h:348
mapstruct::tile_path
char * tile_path[4]
Path to adjoining maps.
Definition: map.h:353
MapSpace::move_on
MoveType move_on
What movement types are activated.
Definition: map.h:264
shopitems::strength
int8_t strength
The degree of specialisation the shop has in this item, as a percentage from -100 to 100.
Definition: map.h:299
ob_move_block
bool ob_move_block(object *ob1, object *ob2)
Basic macro to see if ob2 blocks ob1 from moving onto this space.
Definition: map.cpp:327
mapstruct::region
struct region * region
What jurisdiction in the game world this map is ruled by points to the struct containing all the prop...
Definition: map.h:319
MapSpace::light
int8_t light
How much light this space provides.
Definition: map.h:261
mapstruct::difficulty
uint16_t difficulty
What level the player should be to play here.
Definition: map.h:333
region::fallback
int8_t fallback
Whether, in the event of a region not existing, this should be the one we fall back on as the default...
Definition: map.h:285
mapstruct::outdoor
uint32_t outdoor
True if an outdoor map.
Definition: map.h:331
map_layer_name
const char *const map_layer_name[MAP_LAYERS]
These correspond to the layer names in map.h - since some of the types can be on multiple layers,...
Definition: map.cpp:46
mapstruct::shopmin
uint64_t shopmin
Minimum price a shop will trade for.
Definition: map.h:349
map_light_on
int map_light_on(mapstruct *m, int x, int y)
Return the light level at position (X, Y) on map M.
Definition: map.cpp:2730
mapstruct::buttons
oblinkpt * buttons
Linked list of linked lists of buttons.
Definition: map.h:344
mapstruct::players
int16_t players
How many players are on this level right now.
Definition: map.h:334
mapstruct::tmpname
char * tmpname
Name of temporary file.
Definition: map.h:317
coords_in_shop
bool coords_in_shop(mapstruct *map, int x, int y)
Check if the given map coordinates are in a shop.
Definition: map.cpp:2757
MapSpace::move_off
MoveType move_off
What movement types are activated.
Definition: map.h:265
MoveType
unsigned char MoveType
Typdef here to define type large enough to hold bitmask of all movement types.
Definition: define.h:417
shopitems::index
int index
Being the size of the shopitems array.
Definition: map.h:301
mapstruct::height
uint16_t height
Width and height of map.
Definition: map.h:337
map_reset_swap
void map_reset_swap(mapstruct *m)
Call this when an in-memory map is used or referenced.
Definition: map.cpp:1760
MAP_LAYERS
#define MAP_LAYERS
Definition: map.h:32
oblinkpt
Used to link together several object links.
Definition: object.h:469
region::name
char * name
Shortend name of the region as maps refer to it.
Definition: map.h:275
rv_vector::part
object * part
Part we found.
Definition: map.h:375
mapstruct::is_template
uint32_t is_template
If set, this is a template map.
Definition: map.h:329
mapstruct::path
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:355
HUGE_BUF
#define HUGE_BUF
Used for messages - some can be quite long.
Definition: define.h:37
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
mapstruct::width
uint16_t width
Definition: map.h:337
MapSpace::bottom
object * bottom
Lowest object on this space.
Definition: map.h:257
region::longname
char * longname
Official title of the region, this might be defined to be the same as name.
Definition: map.h:281
rv_vector::distance_y
int distance_y
Y delta.
Definition: map.h:373
mapstruct::shopitems
struct shopitems * shopitems
List of item-types the map's shop will trade in.
Definition: map.h:346
m
static event_registration m
Definition: citylife.cpp:424
rv_vector::distance_x
int distance_x
X delta.
Definition: map.h:372
shop_contains
bool shop_contains(object *ob)
Check if an object is in a shop.
Definition: map.cpp:2764
MapSpace::top
object * top
Highest object on this space.
Definition: map.h:258
mapstruct::shoprace
char * shoprace
The preffered race of the local shopkeeper.
Definition: map.h:347
region::parent
region * parent
Pointer to the region that is a parent of the current region, if a value isn't defined in the current...
Definition: map.h:276
map_space
MapSpace * map_space(const mapstruct *m, int x, int y)
Definition: map.cpp:2718
region::msg
char * msg
The description of the region.
Definition: map.h:283
region::jailmap
char * jailmap
Where a player that is arrested in this region should be imprisoned.
Definition: map.h:287
shopitems::name_pl
const char * name_pl
Plural name.
Definition: map.h:297
mapstruct::reset_group
sstring reset_group
For reset purpose, all maps in the same group reset at the same time.
Definition: map.h:327
MapSpace
This structure contains all information related to one map square.
Definition: map.h:256
mapstruct::last_reset_time
long last_reset_time
A timestamp of the last original map loading.
Definition: map.h:356
mapstruct::maplore
char * maplore
Map lore information.
Definition: map.h:352
shopitems::typenum
int typenum
Itemtype number we need to match, -1 if it is the default price.
Definition: map.h:298
mapstruct::shopmax
uint64_t shopmax
MMaximum price a shop will offer.
Definition: map.h:350
map_path_unique
bool map_path_unique(const char *name)
Return true if the given map path leads to a unique map.
Definition: map.cpp:2714
region
This is a game region.
Definition: map.h:274
MapSpace::move_block
MoveType move_block
What movement types this space blocks.
Definition: map.h:262
mapstruct::background_music
char * background_music
Background music to use for this map.
Definition: map.h:357
shopitems::name
const char * name
Name of the item in question, null if it is the default item.
Definition: map.h:296
mapstruct::reset_timeout
uint32_t reset_timeout
How many seconds must elapse before this map should be reset.
Definition: map.h:323
mapstruct
This is a game-map.
Definition: map.h:315
sstring
const typedef char * sstring
Definition: sstring.h:2
mapstruct::nosmooth
uint32_t nosmooth
If set the content of this map has smoothlevel=0 forced.
Definition: map.h:330
MapSpace::flags
uint8_t flags
Flags about this space (see the P_ values above).
Definition: map.h:260
mapstruct::name
char * name
Name of map as given by its creator.
Definition: map.h:318
mapstruct::enter_x
int16_t enter_x
Definition: map.h:338
mapstruct::in_memory
uint32_t in_memory
Combination of IN_MEMORY_xxx flags.
Definition: map.h:335
rv_vector
This is used by get_rangevector to determine where the other creature is.
Definition: map.h:370
shopitems
Shop-related information for a map.
Definition: map.h:295
mapstruct::timeout
int32_t timeout
Swapout is set to this.
Definition: map.h:332
MapSpace::pl
object * pl
Player who is on this space, may be NULL.
Definition: map.h:266
mapstruct::tile_map
mapstruct * tile_map[4]
Adjoining maps.
Definition: map.h:354
mapstruct::spaces
MapSpace * spaces
Array of spaces on this map.
Definition: map.h:345
mapstruct::msg
char * msg
Message map creator may have left.
Definition: map.h:351
region::counter
uint32_t counter
A generic counter for holding temporary data.
Definition: map.h:284
map_size
uint32_t map_size(mapstruct *m)
Calculate map size without intermediate sign extension.
Definition: map.cpp:808
MapSpace::faces_obj
object * faces_obj[MAP_LAYERS]
Face objects for the layers.
Definition: map.h:259
mapstruct::enter_y
int16_t enter_y
Enter_x and enter_y are default entrance coordinates to use for a map such that when an exit specifie...
Definition: map.h:338
mapstruct::unique
uint32_t unique
If set, this is a per player unique map.
Definition: map.h:328
mapstruct::next
mapstruct * next
Next map, linked list.
Definition: map.h:316
mapstruct::reset_time
uint32_t reset_time
Server time when map gets reset, seconds since epoch.
Definition: map.h:322
mapstruct::darkness
uint8_t darkness
Indicates level of darkness of map.
Definition: map.h:336
rv_vector::direction
int direction
General direction to the targer.
Definition: map.h:374
mapstruct::fixed_resettime
uint32_t fixed_resettime
If true, reset time is not affected by players entering/exiting map.
Definition: map.h:325
rv_vector::distance
unsigned int distance
Distance, in squares.
Definition: map.h:371
MapSpace::move_slow
MoveType move_slow
What movement types this space slows.
Definition: map.h:263
region::jaily
int16_t jaily
The coodinates in jailmap to which the player should be sent.
Definition: map.h:288
region::jailx
int16_t jailx
Definition: map.h:288