Atrinik Server 2.5
Defines | Functions | Variables
server/map.c File Reference
#include <global.h>
#include <loader.h>

Go to the source code of this file.

Defines

#define DEBUG_OLDFLAGS   1

Functions

static void load_objects (mapstruct *m, FILE *fp, int mapflags)
static void save_objects (mapstruct *m, FILE *fp, FILE *fp2)
static void allocate_map (mapstruct *m)
static void free_all_objects (mapstruct *m)
static mapstructload_and_link_tiled_map (mapstruct *orig_map, int tile_num)
static int relative_tile_position_rec (mapstruct *map1, mapstruct *map2, int *x, int *y, uint32 id, int level)
static int relative_tile_position (mapstruct *map1, mapstruct *map2, int *x, int *y)
mapstructhas_been_loaded_sh (shstr *name)
char * create_pathname (const char *name)
static char * create_items_path (shstr *s)
int check_path (const char *name, int prepend_dir)
char * normalize_path (const char *src, const char *dst, char *path)
void dump_map (mapstruct *m)
void dump_all_maps ()
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 blocks_cleric (mapstruct *m, int x, int y)
int blocked (object *op, mapstruct *m, int x, int y, int terrain)
int blocked_link (object *op, int xoff, int yoff)
int blocked_link_2 (object *op, mapstruct *map, int x, int y)
int blocked_tile (object *op, mapstruct *m, int x, int y)
int arch_blocked (archetype *at, object *op, mapstruct *m, int x, int y)
void set_map_darkness (mapstruct *m, int value)
mapstructget_linked_map ()
mapstructget_empty_map (int sizex, int sizey)
mapstructload_original_map (const char *filename, int flags)
static mapstructload_temporary_map (mapstruct *m)
static void delete_unique_items (mapstruct *m)
static void load_unique_objects (mapstruct *m)
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, int flags)
void clean_tmp_map (mapstruct *m)
void free_all_maps ()
void update_position (mapstruct *m, int x, int y)
void set_map_reset_time (mapstruct *map)
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 x1, int y1, 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)
void SockList_AddMapName (SockList *sl, object *pl, mapstruct *map, object *map_info)
void SockList_AddMapMusic (SockList *sl, object *pl, mapstruct *map, object *map_info)
void SockList_AddMapWeather (SockList *sl, object *pl, mapstruct *map, object *map_info)

Variables

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

Detailed Description

Map related functions.

Definition in file map.c.


Function Documentation

static void allocate_map ( mapstruct m) [static]

This basically allocates the dynamic array of spaces for the map.

Parameters:
mMap to allocate spaces for.

Definition at line 1447 of file map.c.

int arch_blocked ( 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.
Return values:
0No block.
-1Out of map.
otherBlocking flags from blocked().

Definition at line 907 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 656 of file map.c.

int blocked_link ( object op,
int  xoff,
int  yoff 
)

Returns true if the given coordinate is blocked except by the object passed is not blocking. This is used with multipart monsters - if we want to see if a 2x2 monster can move 1 space to the left, we don't want its own area to block it from moving there.

Parameters:
opThe monster object.
xoffX position offset.
yoffY position offset.
Returns:
0 if the space to check is not blocked by anything other than the monster, return value of blocked() otherwise.

Definition at line 733 of file map.c.

int blocked_link_2 ( object op,
mapstruct map,
int  x,
int  y 
)

Same as blocked_link(), but using an absolute coordinate (map, x, y).

Parameters:
opThe monster object.
mapThe map.
xX coordinate on the map.
yY coordinate on the map.
Returns:
0 if the space to check is not blocked by anything other than the monster, return value of blocked() otherwise.
Todo:
This function should really be combined with the above to reduce code duplication.

Definition at line 796 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 854 of file map.c.

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

Check if clerical spells do not work on given coordinates on the given map.

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

Definition at line 636 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 619 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 601 of file map.c.

int check_path ( const char *  name,
int  prepend_dir 
)

This function checks if a file with the given path exists.

It tries out all the compression suffixes listed in the uncomp array.

Parameters:
nameName of the file to check.
prepend_dirIf set, then we call create_pathname(), which prepends libdir and mapdir. Otherwise, we assume the name given is fully complete.
Returns:
-1 if it fails, otherwise the mode of the file.

Definition at line 384 of file map.c.

void clean_tmp_map ( mapstruct m)

Remove the temporary file used by the map.

Parameters:
mMap.

Definition at line 2134 of file map.c.

static char* create_items_path ( shstr s) [static]

This makes absolute path to the itemfile where unique objects will be saved.

Converts '/' to '@'.

Parameters:
sPath of the map for the items.
Returns:
The absolute path.

Definition at line 346 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 323 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 1988 of file map.c.

static void delete_unique_items ( mapstruct m) [static]

Goes through a map and removes any unique items on the map.

Parameters:
mThe map to go through.

Definition at line 1659 of file map.c.

void dump_all_maps ( )

Prints out debug information about all maps.

This basically just goes through all the maps and calls dump_map() on each one.

Definition at line 561 of file map.c.

void dump_map ( mapstruct m)

Prints out debug-information about a map.

Parameters:
mMap to dump.

Definition at line 535 of file map.c.

void free_all_maps ( )

Free all allocated maps.

Definition at line 2146 of file map.c.

static void free_all_objects ( mapstruct m) [static]

Remove and free all objects in the given map.

Parameters:
mThe map.

Definition at line 1882 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 1920 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 1478 of file map.c.

mapstruct* get_linked_map ( )

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

Returns:
The new map structure.

Definition at line 1410 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 2362 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 2556 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. + any flags accepted by get_rangevector_from_mapcoords() below.

Returns TRUE if successful, or FALSE otherwise.

Todo:
Document.

Definition at line 2760 of file map.c.

int get_rangevector_from_mapcoords ( mapstruct map1,
int  x1,
int  y1,
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 2821 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 290 of file map.c.

static mapstruct* load_and_link_tiled_map ( mapstruct orig_map,
int  tile_num 
) [inline, static]

Try loading the connected map tile with the given number.

Parameters:
orig_mapBase map.
tile_numTile number to connect to.
Returns:
NULL if loading or tiling fails, loaded neighbor map otherwise.

Definition at line 56 of file map.c.

static void load_objects ( mapstruct m,
FILE *  fp,
int  mapflags 
) [static]

Loads (and parses) the objects into a given map from the specified file pointer.

Parameters:
mMap being loaded.
fpFile to read from.
mapflagsThe same as we get with load_original_map().

Definition at line 957 of file map.c.

mapstruct* load_original_map ( const char *  filename,
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 1502 of file map.c.

static mapstruct* load_temporary_map ( mapstruct m) [static]

Loads a map, which has been loaded earlier, from file.

Parameters:
mMap we want to reload.
Returns:
The map object we load into (this can change from the passed option if we can't find the original map).

Definition at line 1584 of file map.c.

static void load_unique_objects ( mapstruct m) [static]

Loads unique objects from file(s) into the map which is in memory.

Parameters:
mThe map to load unique items into.

Definition at line 1697 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 1751 of file map.c.

char* normalize_path ( const char *  src,
const char *  dst,
char *  path 
)

Make path absolute and remove ".." and "." entries.

path will become a normalized (absolute) version of the path in dst, with all relative path references (".." and "." - parent directory and same directory) resolved (path will not contain any ".." or "." elements, even if dst did).

If dst was not already absolute, the directory part of src will be used as the base path and dst will be added to it.

Parameters:
srcAlready normalized file name for finding absolute path.
dstPath to normalize. Should be either an absolute path or a path relative to src.
pathBuffer for normalized path.
Returns:
Pointer to path.

Definition at line 463 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 2917 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 2936 of file map.c.

mapstruct* ready_map_name ( const char *  name,
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 2039 of file map.c.

static int relative_tile_position ( mapstruct map1,
mapstruct map2,
int *  x,
int *  y 
) [static]

Find the distance between two map tiles on a tiled map.

The distance from the topleft (0, 0) corner of map1 to the topleft corner of map2 will be added to x and y.

This function does not work well with asymmetrically tiled maps.

It will also (naturally) perform bad on very large tilesets such as the world map as it may need to load all tiles into memory before finding a path between two tiles.

We probably want to handle the world map as a special case, considering that all tiles are of equal size, and that we might be able to parse their coordinates from their names...

Parameters:
map1
map2
x
y
Returns:
1 if the two tiles are part of the same map, 0 otherwise.

Definition at line 185 of file map.c.

static int relative_tile_position_rec ( mapstruct map1,
mapstruct map2,
int *  x,
int *  y,
uint32  id,
int  level 
) [static]

Recursive part of the relative_tile_position() function.

Parameters:
map1
map2
x
y
id
levelRecursion level.
Returns:
Todo:
A bidirectional breadth-first search would be more efficient.

Definition at line 80 of file map.c.

static void save_objects ( mapstruct m,
FILE *  fp,
FILE *  fp2 
) [static]

This saves all the objects on the map in a non destructive fashion.

Parameters:
mMap to save.
fpFile where regular objects are saved.
fp2File to save unique objects.

Definition at line 1129 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 1396 of file map.c.

void set_map_reset_time ( mapstruct map)

Updates the map's timeout.

Parameters:
mapMap to update.

Definition at line 2334 of file map.c.

void SockList_AddMapMusic ( SockList sl,
object pl,
mapstruct map,
object map_info 
)

Add map music to a SockList instance.

Parameters:
slThe SockList instance.
plOptional player object this is being done for; will be used to check which format the player's client can accept.
mapMap to add music of.
map_infoMap information object -- if not NULL and the object holds map music, it will be used to override the actual map's music.

Definition at line 2994 of file map.c.

void SockList_AddMapName ( SockList sl,
object pl,
mapstruct map,
object map_info 
)

Add map name to a SockList instance.

Parameters:
slThe SockList instance.
plOptional player object this is being done for; will be used to check which format the player's client can accept.
mapMap to add name of.
map_infoMap information object -- if not NULL and the object holds map name, it will be used to override the actual map's name.

Definition at line 2978 of file map.c.

void SockList_AddMapWeather ( SockList sl,
object pl,
mapstruct map,
object map_info 
)

Add map weather to a SockList instance.

Parameters:
slThe SockList instance.
plOptional player object this is being done for; will be used to check whether the player's client can receive weather data.
mapMap to add weather of.
map_infoMap information object -- if not NULL and the object holds map weather, it will be used to override the actual map's weather.

Definition at line 3008 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 2173 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 584 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 2956 of file map.c.


Variable Documentation

int global_darkness_table[MAX_DARKNESS+1]
Initial value:
{
    0, 20, 40, 80, 160, 320, 640, 1280
}

Definition at line 33 of file map.c.

int map_tiled_reverse[TILED_MAPS]
Initial value:
{
    2, 3, 0, 1, 6, 7, 4, 5
}

To get the reverse direction for all 8 tiled map index

Definition at line 39 of file map.c.