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 
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
59 #define MAP_TYPE_LEGACY 1
60 #define MAP_TYPE_DEFAULT 2
61 #define MAP_TYPE_CHOICE 3
65 #define MAP_WHEN_RESET(m) ((m)->reset_time)
66 
67 #define MAP_RESET_TIMEOUT(m) ((m)->reset_timeout)
68 #define MAP_DIFFICULTY(m) ((m)->difficulty)
69 #define MAP_TIMEOUT(m) ((m)->timeout)
70 #define MAP_OUTDOORS(m) ((m)->outdoor)
71 
73 #define MAP_DARKNESS(m) (m)->darkness
74 
76 #define MAP_WIDTH(m) (m)->width
77 
78 #define MAP_HEIGHT(m) (m)->height
79 
80 #define MAP_SIZE(m) map_size(m)
81 
83 #define MAP_ENTER_X(m) (m)->enter_x
84 
85 #define MAP_ENTER_Y(m) (m)->enter_y
86 
87 #define MAP_NOSMOOTH(m) (m)->nosmooth
88 
94 #define MAP_FLUSH 0x1
95 #define MAP_PLAYER_UNIQUE 0x2
96 #define MAP_NO_DIFFICULTY 0x4
97 #define MAP_STYLE 0x8
98 #define MAP_OVERLAY 0x10
109 #define SAVE_FLAG_SAVE_UNPAID 1
110 #define SAVE_FLAG_NO_REMOVE 2
119 #define SAVE_MODE_NORMAL 0
120 #define SAVE_MODE_INPLACE 1
121 #define SAVE_MODE_OVERLAY 2
129 #define MAP_IN_MEMORY 1
130 #define MAP_SWAPPED 2
131 #define MAP_LOADING 3
132 #define MAP_SAVING 4
142 #define SAVE_ERROR_OK 0
143 #define SAVE_ERROR_RCREATION -1
144 #define SAVE_ERROR_UCREATION -2
145 #define SAVE_ERROR_WRITE -3
146 #define SAVE_ERROR_NO_PATH -4
147 #define SAVE_ERROR_URENAME -5
148 #define SAVE_ERROR_CLOSE -6
149 /* -7 (no longer used) */
150 #define SAVE_ERROR_NOT_IN_MEMORY -10
151 #define SAVE_ERROR_PLAYER -11
154 /* GET_MAP_FLAGS really shouldn't be used very often - get_map_flags should
155  * really be used, as it is multi tile aware. However, there are some cases
156  * where it is known the map is not tiled or the values are known
157  * consistent (eg, op->map, op->x, op->y)
158  */
159 
160 #define GET_MAP_FLAGS(M, X, Y) (map_space(M, X, Y)->flags)
161 
162 #define SET_MAP_FLAGS(M, X, Y, C) (map_space(M, X, Y)->flags = C)
163 
165 #define GET_MAP_LIGHT(M, X, Y) (map_space(M, X, Y)->light)
166 
167 #define SET_MAP_LIGHT(M, X, Y, L) (map_space(M, X, Y)->light = L)
168 
169 #define GET_MAP_PLAYER(M, X, Y) (map_space(M, X, Y)->pl)
170 #define SET_MAP_PLAYER(M, X, Y, C) (map_space(M, X, Y)->pl = C)
171 
173 #define GET_MAP_OB(M, X, Y) (map_space(M, X, Y)->bottom)
174 
175 #define GET_MAP_TOP(M, X, Y) (map_space(M, X, Y)->top)
176 
178 #define SET_MAP_OB(M, X, Y, tmp) (map_space(M, X, Y)->bottom = (tmp))
179 
180 #define SET_MAP_TOP(M, X, Y, tmp) (map_space(M, X, Y)->top = (tmp))
181 
183 #define SET_MAP_FACE_OBJ(M, X, Y, C, L) (map_space(M, X, Y)->faces_obj[L] = C)
184 
185 #define GET_MAP_FACE_OBJ(M, X, Y, L) (map_space(M, X, Y)->faces_obj[L])
186 
190 #define GET_MAP_FACE_OBJS(M, X, Y) (map_space(M, X, Y)->faces_obj)
191 
192 extern bool ob_move_block(object *ob1, object *ob2);
193 
195 #define GET_MAP_MOVE_BLOCK(M, X, Y) (map_space(M, X, Y)->move_block)
196 
197 #define SET_MAP_MOVE_BLOCK(M, X, Y, C) (map_space(M, X, Y)->move_block = C)
198 
200 #define GET_MAP_MOVE_SLOW(M, X, Y) (map_space(M, X, Y)->move_slow)
201 
202 #define SET_MAP_MOVE_SLOW(M, X, Y, C) (map_space(M, X, Y)->move_slow = C)
203 
205 #define GET_MAP_MOVE_ON(M, X, Y) (map_space(M, X, Y)->move_on)
206 
207 #define SET_MAP_MOVE_ON(M, X, Y, C) (map_space(M, X, Y)->move_on = C)
208 
210 #define GET_MAP_MOVE_OFF(M, X, Y) (map_space(M, X, Y)->move_off)
211 
212 #define SET_MAP_MOVE_OFF(M, X, Y, C) (map_space(M, X, Y)->move_off = C)
213 
220 #define OUT_OF_REAL_MAP(M, X, Y) ((X) < 0 || (Y) < 0 || (X) >= (M)->width || (Y) >= (M)->height)
221 
229 #define P_BLOCKSVIEW 0x01
230 #define P_NO_MAGIC 0x02
232 /* AB_NO_PASS is used for arch_blocked() return value. It needs
233  * to be here to make sure the bits don't match with anything.
234  * Changed name to have AB_ prefix just to make sure no one
235  * is using the P_NO_PASS. AB_.. should only be used for
236  * arch_blocked and functions that examine the return value.
237  */
238 #define AB_NO_PASS 0x04
239 #define P_PLAYER 0x08
240 #define P_IS_ALIVE 0x10
241 #define P_NO_CLERIC 0x20
242 #define P_NEED_UPDATE 0x40
243 #define P_NO_ERROR 0x80
246 /* The following two values are not stored in the MapLook flags, but instead
247  * used in the get_map_flags value - that function is used to return
248  * the flag value, as well as other conditions - using a more general
249  * function that does more of the work can hopefully be used to replace
250  * lots of duplicate checks currently in the code.
251  */
252 #define P_OUT_OF_MAP 0x100
253 #define P_NEW_MAP 0x200
259 struct MapSpace {
260  object *bottom;
261  object *top;
262  object *faces_obj[MAP_LAYERS];
263  uint8_t flags;
264  int8_t light;
269  object *pl;
270 };
271 
277 struct region {
278  char *name;
284  char *longname;
286  char *msg;
287  uint32_t counter;
288  int8_t fallback;
290  char *jailmap;
291  int16_t jailx, jaily;
292 };
293 
298 struct shopitems {
299  const char *name;
300  const char *name_pl;
301  int typenum;
302  int8_t strength;
304  int index;
305 };
306 
318 struct mapstruct {
320  char *tmpname;
321  char *name;
322  struct region *region;
325  uint32_t reset_time;
326  uint32_t reset_timeout;
328  uint32_t fixed_resettime:1;
331  uint32_t unique:1;
332  uint32_t is_template:1;
333  uint32_t nosmooth:1;
334  uint32_t outdoor:1;
335  int32_t timeout;
336  uint16_t difficulty;
337  int16_t players;
338  uint32_t in_memory;
339  uint8_t darkness;
340  uint16_t width, height;
341  int16_t enter_x, enter_y;
350  char *shoprace;
351  double shopgreed;
352  uint64_t shopmin;
353  uint64_t shopmax;
354  char *msg;
355  char *maplore;
356  char *tile_path[4];
358  char path[HUGE_BUF];
361 };
362 
373 struct rv_vector {
374  unsigned int distance;
377  int direction;
378  object *part;
379 };
380 
381 uint32_t map_size(mapstruct *m);
382 
383 extern bool map_path_unique(const char *name);
384 
385 extern MapSpace *map_space(const mapstruct *m, int x, int y);
386 
387 extern void map_reset_swap(mapstruct *m);
388 
389 extern int map_light_on(mapstruct *m, int x, int y);
390 
391 extern bool coords_in_shop(mapstruct *map, int x, int y);
392 
396 extern bool shop_contains(object *ob);
397 
398 #endif /* MAP_H */
mapstruct::shopgreed
double shopgreed
How much our shopkeeper overcharges.
Definition: map.h:351
mapstruct::tile_path
char * tile_path[4]
Path to adjoining maps.
Definition: map.h:356
MapSpace::move_on
MoveType move_on
What movement types are activated.
Definition: map.h:267
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:302
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:322
MapSpace::light
int8_t light
How much light this space provides.
Definition: map.h:264
mapstruct::difficulty
uint16_t difficulty
What level the player should be to play here.
Definition: map.h:336
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:288
mapstruct::outdoor
uint32_t outdoor
True if an outdoor map.
Definition: map.h:334
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:352
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:2729
mapstruct::buttons
oblinkpt * buttons
Linked list of linked lists of buttons.
Definition: map.h:347
mapstruct::players
int16_t players
How many players are on this level right now.
Definition: map.h:337
mapstruct::tmpname
char * tmpname
Name of temporary file.
Definition: map.h:320
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:2756
MapSpace::move_off
MoveType move_off
What movement types are activated.
Definition: map.h:268
MoveType
unsigned char MoveType
Typdef here to define type large enough to hold bitmask of all movement types.
Definition: define.h:409
shopitems::index
int index
Being the size of the shopitems array.
Definition: map.h:304
mapstruct::height
uint16_t height
Width and height of map.
Definition: map.h:340
map_reset_swap
void map_reset_swap(mapstruct *m)
Call this when an in-memory map is used or referenced.
Definition: map.cpp:1759
MAP_LAYERS
#define MAP_LAYERS
This correspondes to the map layers in the map2 protocol.
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:278
rv_vector::part
object * part
Part we found.
Definition: map.h:378
mapstruct::is_template
uint32_t is_template
If set, this is a template map.
Definition: map.h:332
mapstruct::path
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:358
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:340
MapSpace::bottom
object * bottom
Lowest object on this space.
Definition: map.h:260
region::longname
char * longname
Official title of the region, this might be defined to be the same as name.
Definition: map.h:284
rv_vector::distance_y
int distance_y
Y delta.
Definition: map.h:376
mapstruct::shopitems
struct shopitems * shopitems
List of item-types the map's shop will trade in.
Definition: map.h:349
m
static event_registration m
Definition: citylife.cpp:424
rv_vector::distance_x
int distance_x
X delta.
Definition: map.h:375
shop_contains
bool shop_contains(object *ob)
Check if an object is in a shop.
Definition: map.cpp:2763
MapSpace::top
object * top
Highest object on this space.
Definition: map.h:261
mapstruct::shoprace
char * shoprace
The preffered race of the local shopkeeper.
Definition: map.h:350
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:279
map_space
MapSpace * map_space(const mapstruct *m, int x, int y)
Definition: map.cpp:2717
region::msg
char * msg
The description of the region.
Definition: map.h:286
region::jailmap
char * jailmap
Where a player that is arrested in this region should be imprisoned.
Definition: map.h:290
shopitems::name_pl
const char * name_pl
Plural name.
Definition: map.h:300
mapstruct::reset_group
sstring reset_group
For reset purpose, all maps in the same group reset at the same time.
Definition: map.h:330
MapSpace
This structure contains all information related to one map square.
Definition: map.h:259
mapstruct::last_reset_time
long last_reset_time
A timestamp of the last original map loading.
Definition: map.h:359
mapstruct::maplore
char * maplore
Map lore information.
Definition: map.h:355
shopitems::typenum
int typenum
Itemtype number we need to match, -1 if it is the default price.
Definition: map.h:301
mapstruct::shopmax
uint64_t shopmax
MMaximum price a shop will offer.
Definition: map.h:353
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:2713
region
This is a game region.
Definition: map.h:277
MapSpace::move_block
MoveType move_block
What movement types this space blocks.
Definition: map.h:265
mapstruct::background_music
char * background_music
Background music to use for this map.
Definition: map.h:360
shopitems::name
const char * name
Name of the item in question, null if it is the default item.
Definition: map.h:299
mapstruct::reset_timeout
uint32_t reset_timeout
How many seconds must elapse before this map should be reset.
Definition: map.h:326
mapstruct
This is a game-map.
Definition: map.h:318
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:333
MapSpace::flags
uint8_t flags
Flags about this space (see the P_ values above).
Definition: map.h:263
mapstruct::name
char * name
Name of map as given by its creator.
Definition: map.h:321
mapstruct::enter_x
int16_t enter_x
Definition: map.h:341
mapstruct::in_memory
uint32_t in_memory
Combination of IN_MEMORY_xxx flags.
Definition: map.h:338
rv_vector
This is used by get_rangevector to determine where the other creature is.
Definition: map.h:373
shopitems
Shop-related information for a map.
Definition: map.h:298
mapstruct::timeout
int32_t timeout
Swapout is set to this.
Definition: map.h:335
MapSpace::pl
object * pl
Player who is on this space, may be NULL.
Definition: map.h:269
mapstruct::tile_map
mapstruct * tile_map[4]
Adjoining maps.
Definition: map.h:357
mapstruct::spaces
MapSpace * spaces
Array of spaces on this map.
Definition: map.h:348
mapstruct::msg
char * msg
Message map creator may have left.
Definition: map.h:354
region::counter
uint32_t counter
A generic counter for holding temporary data.
Definition: map.h:287
map_size
uint32_t map_size(mapstruct *m)
Calculate map size without intermediate sign extension.
Definition: map.cpp:808
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:341
mapstruct::unique
uint32_t unique
If set, this is a per player unique map.
Definition: map.h:331
mapstruct::next
mapstruct * next
Next map, linked list.
Definition: map.h:319
mapstruct::reset_time
uint32_t reset_time
Server time when map gets reset, seconds since epoch.
Definition: map.h:325
mapstruct::darkness
uint8_t darkness
Indicates level of darkness of map.
Definition: map.h:339
rv_vector::direction
int direction
General direction to the targer.
Definition: map.h:377
mapstruct::fixed_resettime
uint32_t fixed_resettime
If true, reset time is not affected by players entering/exiting map.
Definition: map.h:328
rv_vector::distance
unsigned int distance
Distance, in squares.
Definition: map.h:374
MapSpace::move_slow
MoveType move_slow
What movement types this space slows.
Definition: map.h:266
region::jaily
int16_t jaily
The coodinates in jailmap to which the player should be sent.
Definition: map.h:291
region::jailx
int16_t jailx
Definition: map.h:291