Atrinik Server  4.0
Data Structures | Macros | Typedefs | Functions | Variables
map.h File Reference
#include <decls.h>

Go to the source code of this file.

Data Structures

struct  MapSpace_s
 
struct  region_struct
 
struct  map_event
 
struct  map_exit
 
struct  mapdef
 
struct  rv_vector_s
 

Macros

#define MAX_DARKNESS   7
 
#define MAP_PLAYER_MAP   1
 
#define LAYER_SYS   0
 
#define LAYER_FLOOR   1
 
#define LAYER_FMASK   2
 
#define LAYER_ITEM   3
 
#define LAYER_ITEM2   4
 
#define LAYER_WALL   5
 
#define LAYER_LIVING   6
 
#define LAYER_EFFECT   7
 
#define NUM_LAYERS   7
 
#define NUM_SUB_LAYERS   7
 
#define NUM_REAL_LAYERS   (NUM_LAYERS * NUM_SUB_LAYERS)
 
#define MAP_WHEN_RESET(m)   ((m)->reset_time)
 
#define MAP_RESET_TIMEOUT(m)   ((m)->reset_timeout)
 
#define MAP_DIFFICULTY(m)   ((m)->difficulty)
 
#define MAP_TIMEOUT(m)   ((m)->timeout)
 
#define MAP_SWAP_TIME(m)   ((m)->swap_time)
 
#define MAP_OUTDOORS(m)   ((m)->map_flags & MAP_FLAG_OUTDOOR)
 
#define MAP_UNIQUE(m)   ((m)->map_flags & MAP_FLAG_UNIQUE)
 
#define MAP_FIXED_RESETTIME(m)   ((m)->map_flags & MAP_FLAG_FIXED_RTIME)
 
#define MAP_NOSAVE(m)   ((m)->map_flags & MAP_FLAG_NO_SAVE)
 
#define MAP_NOMAGIC(m)   ((m)->map_flags & MAP_FLAG_NOMAGIC)
 
#define MAP_HEIGHT_DIFF(m)   ((m)->map_flags & MAP_FLAG_HEIGHT_DIFF)
 
#define MAP_NOHARM(m)   ((m)->map_flags & MAP_FLAG_NOHARM)
 
#define MAP_NOSUMMON(m)   ((m)->map_flags & MAP_FLAG_NOSUMMON)
 
#define MAP_FIXEDLOGIN(m)   ((m)->map_flags & MAP_FLAG_FIXED_LOGIN)
 
#define MAP_PLAYER_NO_SAVE(m)   ((m)->map_flags & MAP_FLAG_PLAYER_NO_SAVE)
 
#define MAP_PVP(m)   ((m)->map_flags & MAP_FLAG_PVP)
 
#define MAP_DARKNESS(m)   (m)->darkness
 
#define MAP_WIDTH(m)   (m)->width
 
#define MAP_HEIGHT(m)   (m)->height
 
#define MAP_SIZE(m)   ((m)->width * (m)->height)
 
#define MAP_ENTER_X(m)   (m)->enter_x
 
#define MAP_ENTER_Y(m)   (m)->enter_y
 
#define MAP_FLUSH   1
 
#define MAP_PLAYER_UNIQUE   2
 
#define MAP_BLOCK   4
 
#define MAP_STYLE   8
 
#define MAP_ARTIFACT   16
 
#define MAP_NAME_SHARED   32
 
#define MAP_ORIGINAL   64
 
#define MAP_NO_DYNAMIC   128
 
#define MAP_IN_MEMORY   1
 
#define MAP_SWAPPED   2
 
#define MAP_LOADING   3
 
#define MAP_SAVING   4
 
#define GET_MAP_SPACE_PTR(M_, X_, Y_)   (&((M_)->spaces[(X_) + (M_)->width * (Y_)]))
 
#define GET_MAP_SPACE_FIRST(M_)   ((M_)->first)
 
#define GET_MAP_SPACE_LAST(M_)   ((M_)->last)
 
#define GET_MAP_SPACE_LAYER(M_, L_, SL_)   ((M_)->layer[NUM_LAYERS * (SL_) + (L_) -1])
 
#define SET_MAP_SPACE_FIRST(M_, O_)   ((M_)->first = (O_))
 
#define SET_MAP_SPACE_LAST(M_, O_)   ((M_)->last = (O_))
 
#define SET_MAP_SPACE_LAYER(M_, L_, SL_, O_)   ((M_)->layer[NUM_LAYERS * (SL_) + (L_) -1] = (O_))
 
#define GET_MAP_UPDATE_COUNTER(M, X, Y)   ((M)->spaces[(X) + (M)->width * (Y)].update_tile)
 
#define INC_MAP_UPDATE_COUNTER(M, X, Y)   ((M)->spaces[((X) + (M)->width * (Y))].update_tile++)
 
#define GET_MAP_MOVE_FLAGS(M, X, Y)   ((M)->spaces[(X) + (M)->width * (Y)].move_flags)
 
#define SET_MAP_MOVE_FLAGS(M, X, Y, C)   ((M)->spaces[(X) + (M)->width * (Y)].move_flags = C)
 
#define GET_MAP_FLAGS(M, X, Y)   ((M)->spaces[(X) + (M)->width * (Y)].flags)
 
#define SET_MAP_FLAGS(M, X, Y, C)   ((M)->spaces[(X) + (M)->width * (Y)].flags = C)
 
#define GET_MAP_LIGHT(M, X, Y)   ((M)->spaces[(X) + (M)->width * (Y)].light_value)
 
#define SET_MAP_LIGHT(M, X, Y, L)   ((M)->spaces[(X) + (M)->width * (Y)].light_value = L)
 
#define GET_MAP_OB(M, X, Y)   ((M)->spaces[(X) + (M)->width * (Y)].first)
 
#define GET_MAP_OB_LAST(M, X, Y)   ((M)->spaces[(X) + (M)->width * (Y)].last)
 
#define GET_MAP_OB_LAYER(_M_, _X_, _Y_, _Z_, _SL_)   ((_M_)->spaces[(_X_) + (_M_)->width * (_Y_)].layer[NUM_LAYERS * (_SL_) + (_Z_) -1])
 
#define SET_MAP_DAMAGE(M, X, Y, SUB_LAYER, tmp)   ((M)->spaces[(X) + (M)->width * (Y)].last_damage[(SUB_LAYER)] = (int16_t) (tmp))
 
#define GET_MAP_DAMAGE(M, X, Y, SUB_LAYER)   ((M)->spaces[(X) + (M)->width * (Y)].last_damage[(SUB_LAYER)])
 
#define SET_MAP_RTAG(M, X, Y, SUB_LAYER, tmp)   ((M)->spaces[(X) + (M)->width * (Y)].round_tag[(SUB_LAYER)] = (uint32_t) (tmp))
 
#define GET_MAP_RTAG(M, X, Y, SUB_LAYER)   ((M)->spaces[(X) + (M)->width * (Y)].round_tag[(SUB_LAYER)])
 
#define GET_BOTTOM_MAP_OB(O)   ((O)->map ? GET_MAP_OB((O)->map, (O)->x, (O)->y) : NULL)
 
#define OUT_OF_MAP(M, X, Y)   ((X) < 0 || (Y) < 0 || (X) >= (M)->width || (Y) >= (M)->height)
 
#define P_BLOCKSVIEW   0x01
 
#define P_NO_MAGIC   0x02
 
#define P_NO_PASS   0x04
 
#define P_IS_PLAYER   0x08
 
#define P_IS_MONSTER   0x10
 
#define P_IS_EXIT   0x20
 
#define P_PLAYER_ONLY   0x40
 
#define P_DOOR_CLOSED   0x80
 
#define P_CHECK_INV   0x100
 
#define P_NO_PVP   0x200
 
#define P_PASS_THRU   0x400
 
#define P_WALK_ON   0x1000
 
#define P_WALK_OFF   0x2000
 
#define P_FLY_OFF   0x4000
 
#define P_FLY_ON   0x8000
 
#define P_MAGIC_MIRROR   0x10000
 
#define P_OUTDOOR   0x20000
 
#define P_OUT_OF_MAP   0x4000000
 
#define P_NEED_UPDATE   0x40000000
 
#define P_NO_TERRAIN   0x80000000
 
#define MSP_EXTRA_NO_HARM   1
 
#define MSP_EXTRA_NO_PVP   2
 
#define MSP_EXTRA_NO_MAGIC   4
 
#define MSP_EXTRA_IS_BUILDING   8
 
#define MSP_EXTRA_IS_BALCONY   16
 
#define MSP_EXTRA_IS_OVERLOOK   32
 
#define MAP_FLAG_OUTDOOR   1
 
#define MAP_FLAG_UNIQUE   2
 
#define MAP_FLAG_FIXED_RTIME   4
 
#define MAP_FLAG_NOMAGIC   8
 
#define MAP_FLAG_HEIGHT_DIFF   16
 
#define MAP_FLAG_NOHARM   32
 
#define MAP_FLAG_NOSUMMON   64
 
#define MAP_FLAG_FIXED_LOGIN   128
 
#define MAP_FLAG_PLAYER_NO_SAVE   256
 
#define MAP_FLAG_UNUSED2   1024
 
#define MAP_FLAG_UNUSED3   2048
 
#define MAP_FLAG_PVP   4096
 
#define MAP_FLAG_NO_SAVE   8192
 
#define MAP_DEFAULT_DARKNESS   0
 
#define MAP_TILE_IS_SAME_LEVEL(_m, _z)
 
#define MAP_TILES_WALK_INTERNAL(_m, _fnc,...)
 
#define MAP_TILES_WALK_START(_m, _fnc,...)
 
#define MAP_TILES_WALK_RETVAL   __ret
 
#define MAP_TILES_WALK_END   }
 
#define RV_MANHATTAN_DISTANCE   0x00
 
#define RV_EUCLIDIAN_DISTANCE   0x01
 
#define RV_DIAGONAL_DISTANCE   0x02
 
#define RV_NO_DISTANCE   (RV_EUCLIDIAN_DISTANCE | RV_DIAGONAL_DISTANCE)
 
#define RV_IGNORE_MULTIPART   0x04
 
#define RV_RECURSIVE_SEARCH   0x08
 
#define RV_NO_LOAD   0x10
 
#define NORTH   1
 
#define NORTHEAST   2
 
#define EAST   3
 
#define SOUTHEAST   4
 
#define SOUTH   5
 
#define SOUTHWEST   6
 
#define WEST   7
 
#define NORTHWEST   8
 
#define NUM_DIRECTION   8
 
#define OBJECT_IS_HIDDEN(pl, ob)   (HAS_EVENT((ob), EVENT_ASK_SHOW) && trigger_event(EVENT_ASK_SHOW, (pl), (ob), NULL, NULL, 0, 0, 0, 0) == 1)
 
#define MAP_BUILDING_DARKNESS_WALL   4
 
#define MAP_BUILDING_DARKNESS   3
 

Typedefs

typedef struct MapSpace_s MapSpace
 
typedef struct region_struct region_struct
 
typedef struct map_event map_event
 
typedef struct map_exit map_exit_t
 
typedef struct mapdef mapstruct
 
typedef struct rv_vector_s rv_vector
 

Functions

void map_init (void)
 
mapstructhas_been_loaded_sh (shstr *name)
 
char * create_pathname (const char *name)
 
int wall (mapstruct *m, int x, int y)
 
int blocks_view (mapstruct *m, int x, int y)
 
int blocks_magic (mapstruct *m, int x, int y)
 
int blocked (object *op, mapstruct *m, int x, int y, int terrain)
 
int blocked_tile (object *op, mapstruct *m, int x, int y)
 
int arch_blocked (struct archetype *at, object *op, mapstruct *m, int x, int y)
 
void set_map_darkness (mapstruct *m, int value)
 
mapstructget_linked_map (void)
 
mapstructget_empty_map (int sizex, int sizey)
 
void map_set_tile (mapstruct *m, int tile, const char *pathname)
 
mapstructload_original_map (const char *filename, mapstruct *originator, int flags)
 
int new_save_map (mapstruct *m, int flag)
 
void free_map (mapstruct *m, int flag)
 
void delete_map (mapstruct *m)
 
mapstructready_map_name (const char *name, mapstruct *originator, int flags)
 
void clean_tmp_map (mapstruct *m)
 
void free_all_maps (void)
 
void update_position (mapstruct *m, int x, int y)
 
void set_map_reset_time (mapstruct *map)
 
mapstructget_map_from_tiled (mapstruct *m, int tiled)
 
mapstructget_map_from_coord (mapstruct *m, int *x, int *y)
 
mapstructget_map_from_coord2 (mapstruct *m, int *x, int *y)
 
int get_rangevector (object *op1, object *op2, rv_vector *retval, int flags)
 
int get_rangevector_from_mapcoords (mapstruct *map1, int x, int y, mapstruct *map2, int x2, int y2, rv_vector *retval, int flags)
 
int on_same_map (object *op1, object *op2)
 
int players_on_map (mapstruct *m)
 
int wall_blocked (mapstruct *m, int x, int y)
 
int map_get_darkness (mapstruct *m, int x, int y, object **mirror)
 
int map_path_isabs (const char *path)
 
char * map_get_path (mapstruct *m, const char *path, uint8_t unique, const char *name)
 
mapstructmap_force_reset (mapstruct *m)
 
void map_redraw (mapstruct *m, int x, int y, int layer, int sub_layer)
 
objectmap_find_arch (mapstruct *m, int x, int y, archetype_t *at)
 
objectmap_find_type (mapstruct *m, int x, int y, uint8_t type)
 
int map_free_spot (mapstruct *m, int x, int y, int start, int stop, archetype_t *at, object *op)
 
int map_free_spot_first (mapstruct *m, int x, int y, archetype_t *at, object *op)
 

Variables

int global_darkness_table [MAX_DARKNESS+1]
 
int map_tiled_reverse [TILED_NUM]
 

Detailed Description

The mapstruct is allocated each time a new map is opened. It contains pointers (very indirectly) to all objects on the map.

Definition in file map.h.

Macro Definition Documentation

#define MAP_BUILDING_DARKNESS   3

Darkness of building interiors.

Definition at line 866 of file map.h.

#define MAP_BUILDING_DARKNESS_WALL   4

Maximum darkness of building walls.

Definition at line 862 of file map.h.

#define MAP_PLAYER_MAP   1

For exit objects: this is a player unique map

Definition at line 40 of file map.h.

#define MAP_TILE_IS_SAME_LEVEL (   _m,
  _z 
)
Value:
((_m)->coords[2] + (_z) >= (_m)->level_min && \
(_m)->coords[2] + (_z) <= (_m)->level_max)

Checks if the specified map level offset is part of the map.

Parameters
_mMap.
_zLevel offset.

Definition at line 696 of file map.h.

#define MAP_TILES_WALK_END   }

Ends map tile walking block.

Definition at line 766 of file map.h.

#define MAP_TILES_WALK_INTERNAL (   _m,
  _fnc,
  ... 
)
Value:
if (__ret == 0) { \
__ret = (_fnc)((_m), (_m), ##__VA_ARGS__); \
} \
\
for (__idx = 0; __ret == 0 && __idx < TILED_NUM_DIR; __idx++) { \
if ((_m)->tile_map[__idx] == NULL || \
(_m)->tile_map[__idx]->in_memory != MAP_IN_MEMORY) { \
continue; \
} \
\
__ret = (_fnc)((_m)->tile_map[__idx], (_m), ##__VA_ARGS__); \
}
#define TILED_NUM_DIR
Definition: global.h:210
#define MAP_IN_MEMORY
Definition: map.h:170

Definition at line 700 of file map.h.

#define MAP_TILES_WALK_RETVAL   __ret

Acquires the return value from the user-supplied function.

Definition at line 761 of file map.h.

#define MAP_TILES_WALK_START (   _m,
  _fnc,
  ... 
)
Value:
{ \
int __ret, __idx, __tile_id, __z; \
mapstruct *__tile; \
\
__ret = 0; \
\
if ((_m)->in_memory == MAP_IN_MEMORY) { \
MAP_TILES_WALK_INTERNAL(_m, _fnc, ##__VA_ARGS__); \
} \
\
for (__tile_id = TILED_UP; \
__ret == 0 && __tile_id <= TILED_DOWN; \
__tile_id++) { \
for (__tile = (_m)->tile_map[__tile_id], \
__z = __tile_id == TILED_UP ? 1 : -1; \
__ret == 0 && __tile != NULL && \
__tile->in_memory == MAP_IN_MEMORY && \
__tile = __tile->tile_map[__tile_id], \
__z += __tile_id == TILED_UP ? 1 : -1) { \
MAP_TILES_WALK_INTERNAL(__tile, _fnc, ##__VA_ARGS__); \
} \
}
#define MAP_IN_MEMORY
Definition: map.h:170
struct mapdef mapstruct
#define TILED_UP
Definition: global.h:203
#define MAP_TILE_IS_SAME_LEVEL(_m, _z)
Definition: map.h:696
#define TILED_DOWN
Definition: global.h:205

Walks all the tiled maps, including up/down maps that are on the same level as the specified map, including the direction-based tiled maps of those up/down maps.

Parameters
_mThe map to walk.
_fncFunction to apply to each map. This should have 'int' return value, which indicates whether to keep going or not. Non-zero return value will stop the walk, and can be retrieved with MAP_TILES_WALK_RETVAL. Two arguments are automatically supplied to the function: the first one is the tiled map, and the second one is either whatever map was supplied through the _m parameter, or a map that is tiled up/down to that map. This means that you can use the second 'map' parameter to do things like non-recursive distance calculation (since you need the specific map level for that, but you can still re-use the X/Y map tile coordinates).
...Additional arguments supplied to the function.

Definition at line 733 of file map.h.

#define MAX_DARKNESS   7

Number of darkness level. Add +1 for "total dark"

Definition at line 37 of file map.h.

#define NUM_LAYERS   7

The number of object layers.

Definition at line 67 of file map.h.

#define NUM_REAL_LAYERS   (NUM_LAYERS * NUM_SUB_LAYERS)

Effective number of all the visible layers.

Definition at line 75 of file map.h.

#define NUM_SUB_LAYERS   7

Number of sub-layers.

Definition at line 71 of file map.h.

#define OBJECT_IS_HIDDEN (   pl,
  ob 
)    (HAS_EVENT((ob), EVENT_ASK_SHOW) && trigger_event(EVENT_ASK_SHOW, (pl), (ob), NULL, NULL, 0, 0, 0, 0) == 1)

Check if 'pl' cannot see 'ob' due to it being hidden by plugin.

Definition at line 857 of file map.h.

#define OUT_OF_MAP (   M,
  X,
 
)    ((X) < 0 || (Y) < 0 || (X) >= (M)->width || (Y) >= (M)->height)

You should really know what you are doing before using this - you should almost always be using get_map_from_coord() instead, which takes into account map tiling.

Definition at line 240 of file map.h.

Typedef Documentation

typedef struct map_event map_event

A single map event, holding a pointer to map event object on map.

typedef struct MapSpace_s MapSpace

Single tile on a map

typedef struct mapdef mapstruct

In general, code should always use the macros above (or functions in map.c) to access many of the values in the map structure. Failure to do this will almost certainly break various features.

You may think it is safe to look at width and height values directly (or even through the macros), but doing so will completely break map tiling.

typedef struct region_struct region_struct

This is a game region.

Each map is in a given region of the game world and links to a region definition.

typedef struct rv_vector_s rv_vector

This is used by get_rangevector() to determine where the other creature is.

Function Documentation

int arch_blocked ( struct archetype at,
object op,
mapstruct m,
int  x,
int  y 
)

Check if an archetype can fit to a position.

Parameters
atArchetype to check.
opObject. If not NULL, will check for terrain as well.
mMap.
xX position.
yY position.
Returns
0 if the space to check is not blocked, return value of blocked() otherwise.

Definition at line 728 of file map.c.

int blocked ( object op,
mapstruct m,
int  x,
int  y,
int  terrain 
)

Check if specified object cannot move onto x, y on the given map and terrain.

Parameters
opObject.
mThe map.
xX coordinate.
yY coordinate.
terrainTerrain type.
Returns
0 if not blocked by anything, combination of Map look flags otherwise.

Definition at line 598 of file map.c.

int blocked_tile ( object op,
mapstruct m,
int  x,
int  y 
)

This is used for any action which needs to browse through the objects of the tile node, for special objects like inventory checkers.

Parameters
opObject trying to move to map at x, y.
mMap we want to check.
xX position to check for.
yY position to check for.
Returns
1 if the tile is blocked, 0 otherwise.

Definition at line 676 of file map.c.

int blocks_magic ( mapstruct m,
int  x,
int  y 
)

Check if given coordinates on the given map block magic.

Parameters
mMap.
xX position on the map.
yY position on the map.
Returns
1 if the given location blocks magic.

Definition at line 529 of file map.c.

int blocks_view ( mapstruct m,
int  x,
int  y 
)

Check if it's impossible to see through the given coordinate on the given map.

Parameters
mMap.
xX position on the map.
yY position on the map.
Returns
1 if the given location blocks view.

Definition at line 507 of file map.c.

void clean_tmp_map ( mapstruct m)

Remove the temporary file used by the map.

Parameters
mMap.

Definition at line 1662 of file map.c.

char* create_pathname ( const char *  name)

Makes a path absolute outside the world of Atrinik.

In other words, it prepends LIBDIR/MAPDIR/ to the given path and returns the pointer to a static array containing the result.

Parameters
namePath of the map.
Returns
The full path.

Definition at line 422 of file map.c.

void delete_map ( mapstruct m)

Deletes all the data on the map (freeing pointers) and then removes this map from the global linked list of maps.

Parameters
mThe map to delete.

Definition at line 1555 of file map.c.

void free_all_maps ( void  )

Free all allocated maps.

Definition at line 1677 of file map.c.

void free_map ( mapstruct m,
int  flag 
)

Frees everything allocated by the given map structure.

Don't free tmpname - our caller is left to do that.

Parameters
mMap to free.
flagIf set, free all objects on the map.

Definition at line 1493 of file map.c.

mapstruct* get_empty_map ( int  sizex,
int  sizey 
)

Creates and returns a map of the specified size.

Used in random maps code.

Parameters
sizexX size of the map.
sizeyY size of the map.
Returns
The new map structure.

Definition at line 985 of file map.c.

mapstruct* get_linked_map ( void  )

Allocates, initializes, and returns a pointer to a mapstruct.

Returns
The new map structure.

Definition at line 948 of file map.c.

mapstruct* get_map_from_coord ( mapstruct m,
int *  x,
int *  y 
)

Get real coordinates from map.

Return NULL if no map is valid (coordinates out of bounds and no tiled map), otherwise it returns the map the coordinates are really on, and updates x and y to be the localized coordinates.

Parameters
mMap to consider.
[out]xWill contain the real X position that was checked.
[out]yWill contain the real Y position that was checked.
Returns
Map that is at specified location. Will be NULL if not on any map.

Definition at line 1869 of file map.c.

mapstruct* get_map_from_coord2 ( mapstruct m,
int *  x,
int *  y 
)

Same as get_map_from_coord(), but this version doesn't load tiled maps into memory, if they are not already.

Parameters
mMap to consider.
[out]xWill contain the real X position that was checked. If coordinates are not in a map this is set to 0, or to -1 if there is a tiled map but it's not loaded.
[out]yWill contain the real Y position that was checked.
Returns
Map that is at specified location. Will be NULL if not on any map.

Definition at line 2000 of file map.c.

mapstruct* get_map_from_tiled ( mapstruct m,
int  tiled 
)

Get tiled map, loading it if necessary.

Parameters
mMap.
tiledTile ID to get.
Returns
Tiled map on success, NULL on failure.

Definition at line 1838 of file map.c.

int get_rangevector ( object op1,
object op2,
rv_vector retval,
int  flags 
)

This is used by get_player to determine where the other creature is. get_rangevector takes into account map tiling, so you just can not look the the map coordinates and get the right value. distance_x/y are distance away, which can be negative. direction is the crossfire direction scheme that the creature should head. part is the part of the monster that is closest.

get_rangevector looks at op1 and op2, and fills in the structure for op1 to get to op2. We already trust that the caller has verified that the two objects are at least on adjacent maps. If not, results are not likely to be what is desired. if the objects are not on maps, results are also likely to be unexpected

Flags: 0x1 is don't translate for closest body part. 0x2 is do recursive search on adjacent tiles.

Returns TRUE if successful, or FALSE otherwise.

Todo:
Document.

Definition at line 2238 of file map.c.

int get_rangevector_from_mapcoords ( mapstruct map1,
int  x,
int  y,
mapstruct map2,
int  x2,
int  y2,
rv_vector retval,
int  flags 
)

This is the base for get_rangevector above, but can more generally compute the rangvector between any two points on any maps.

The part field of the rangevector is always set to NULL by this function. (Since we don't actually know about any objects)

If the function fails (because of the maps being separate), it will return FALSE and the vector is not otherwise touched. Otherwise it will return TRUE.

Calculates manhattan distance (dx+dy) per default. (fast)

  • Flags: 0x4 - calculate euclidean (straight line) distance (slow) 0x8 - calculate diagonal (max(dx + dy)) distance (fast) 0x8|0x04 - don't calculate distance (or direction) (fastest)
    Todo:
    Document.

Definition at line 2297 of file map.c.

mapstruct* has_been_loaded_sh ( shstr *  name)

Check whether a specified map has been loaded already. Returns the mapstruct which has a name matching the given argument.

Parameters
nameShared string of the map path name.
Returns
mapstruct which has a name matching the given argument, NULL if no such map.

Definition at line 389 of file map.c.

mapstruct* load_original_map ( const char *  filename,
mapstruct originator,
int  flags 
)

Opens the file "filename" and reads information about the map from the given file, and stores it in a newly allocated mapstruct.

Parameters
filenameMap path.
flagsOne of (or combination of):
  • MAP_PLAYER_UNIQUE: We don't do any name changes.
  • MAP_BLOCK: We block on this load. This happens in all cases, no matter if this flag is set or not.
  • MAP_STYLE: Style map - don't add active objects, don't add to server managed map list.
Returns
The loaded map structure, NULL on failure.

Definition at line 1055 of file map.c.

object* map_find_arch ( mapstruct m,
int  x,
int  y,
archetype_t at 
)

Searches for any object with a matching archetype at the given map and coordinates.

Parameters
mMap.
xX coordinate on map.
yY coordinate on map.
atArchetype to look for.
Returns
First matching object, or NULL if none matches.

Definition at line 2856 of file map.c.

object* map_find_type ( mapstruct m,
int  x,
int  y,
uint8_t  type 
)

Searches for any object with a matching type at the given map and coordinates.

Parameters
mMap.
xX coordinate on map.
yY coordinate on map.
typeType to find.
Returns
First matching object, or NULL if none matches.

Definition at line 2891 of file map.c.

mapstruct* map_force_reset ( mapstruct m)

Force the reset of a map, removing any players on it, swapping it out and reloading it.

Parameters
mMap to reset.
Returns
Reset map on success, NULL on failure.

Definition at line 2691 of file map.c.

int map_free_spot ( mapstruct m,
int  x,
int  y,
int  start,
int  stop,
archetype_t at,
object op 
)

Will search for a spot at the given map and coordinates which will be able to contain the given archetype, and returns a random choice among the alternatives found (if any).

'start' and 'stop' specify how many squares to search (see the freearr_x/freearr_y definitions); 1-9 would search the 8 immediately adjacent tiles.

Note
This only checks to see if there is space for the head of the object - if it is a multi-part object, this should be called for all pieces.
Parameters
mMap to search on.
xX coordinate.
yY coordinate.
startStarting index in the freearr_x/freearr_y arrays; at least 0, and less than SIZEOFFREE.
stopLast index in the freearr_x/freearr_y arrays; at least 0, less than SIZEOFFREE and greater than 'start'.
atArchetype to use for blocking checks.
opObject to use for blocking checks; can be NULL.
Returns
An index usable in the freearr_x/freearr_y arrays, -1 if there is no usable spot.

Definition at line 2942 of file map.c.

int map_free_spot_first ( mapstruct m,
int  x,
int  y,
archetype_t at,
object op 
)

Works like map_free_spot(), but it will search maximum possible number of squares (SIZEOFFREE3).

It will return the first available spot, not a random choice.

Parameters
mMap to search on.
xX coordinate.
yY coordinate.
atArchetype to use for blocking checks.
opObject to use for blocking checks; can be NULL.
Returns
An index usable in the freearr_x/freearr_y arrays, -1 if there is no usable spot.

Definition at line 3009 of file map.c.

void map_init ( void  )

Initialize map-related code.

Definition at line 148 of file map.c.

void map_redraw ( mapstruct m,
int  x,
int  y,
int  layer,
int  sub_layer 
)

Force redrawing of all objects on the specified tile, for all players that can see it.

Parameters
mMap.
xX coordinate.
yY coordinate.
layerLayer to redraw, -1 for all.
sub_layerSub-layer to redraw, -1 for all.
Warning
This is a costly function, and should only be called sparingly, and only if it's really necessary. Do not EVER call it from code that is called very often (combat code for example).

Definition at line 2824 of file map.c.

int new_save_map ( mapstruct m,
int  flag 
)

Saves a map to file. If flag is set, it is saved into the same file it was (originally) loaded from. Otherwise a temporary filename will be generated, and the file will be stored there. The temporary filename will be stored in the mapstructure. If the map is unique, we also save to the filename in the map (this should have been updated when first loaded).

Parameters
mThe map to save.
flagSave flag.
Returns

Definition at line 1363 of file map.c.

int on_same_map ( object op1,
object op2 
)

Checks whether two objects are on the same map, taking map tiling into account.

Parameters
op1First object to check for.
op2Second object to check against the first.
Returns
1 if both objects are on same map, 0 otherwise.

Definition at line 2414 of file map.c.

int players_on_map ( mapstruct m)

Count the players on a map, using the local map player list.

Parameters
mThe map.
Returns
Number of players on this map.

Definition at line 2455 of file map.c.

mapstruct* ready_map_name ( const char *  name,
mapstruct originator,
int  flags 
)

Makes sure the given map is loaded and swapped in.

Parameters
namePath name of the map.
flagsPossible flags:
  • MAP_FLUSH: Flush the map - always load from the map directory, and don't do unique items or the like.
    • MAP_PLAYER_UNIQUE: This is an unique map for each player. Don't do any more name translation on it.
Returns
Pointer to the given map.

Definition at line 1584 of file map.c.

void set_map_darkness ( mapstruct m,
int  value 
)

Sets darkness for map, both light_value and darkness.

Takes care of checking the passed value.

Parameters
mPointer to the map's structure.
valueThe darkness value.

Definition at line 933 of file map.c.

void set_map_reset_time ( mapstruct map)

Updates the map's timeout.

Parameters
mapMap to update.

Definition at line 1814 of file map.c.

void update_position ( mapstruct m,
int  x,
int  y 
)

This function updates various attributes about a specific space on the map (what it looks like, whether it blocks magic, has a living creatures, prevents people from passing through, etc).

Parameters
mMap to update.
xX position on the given map.
yY position on the given map.

Definition at line 1706 of file map.c.

int wall ( mapstruct m,
int  x,
int  y 
)

Check if there is a wall on specified map at x, y.

Caller should check for P_PASS_THRU in the return value to see if it can cross here.

The P_PLAYER_ONLY flag here is analyzed without checking the caller type. That is possible because player movement related functions should always used blocked().

Parameters
mMap we're checking for.
xX position where to check.
yY position where to check.
Returns
1 if a wall is present at the given location.

Definition at line 486 of file map.c.

int wall_blocked ( mapstruct m,
int  x,
int  y 
)

Returns true if square x, y has P_NO_PASS set, which is true for walls and doors but not monsters.

Parameters
mMap to check for
xX coordinate to check for
yY coordinate to check for
Returns
Non zero if blocked, 0 otherwise.

Definition at line 2479 of file map.c.

Variable Documentation

int map_tiled_reverse[TILED_NUM]

Used to get the reverse direction for all the tiled maps.

For example: TILED_NORTH -> TILED_SOUTH

Definition at line 52 of file map.c.