Crossfire Server, Trunk  R20513
Data Structures | Macros | Typedefs | Functions | Variables
map.c File Reference

Map-related functions. More...

#include "global.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "sproto.h"
#include "loader.h"
#include "output_file.h"
#include "path.h"
Include dependency graph for map.c:

Go to the source code of this file.

Data Structures

struct  Map_Layer_Info
 Information about a layer. More...
 

Macros

#define TEMP_EXT   ".savefile"
 

Typedefs

typedef struct Map_Layer_Info Map_Layer_Info
 Information about a layer. More...
 

Functions

static void add_face_layer (int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility)
 This function is used for things that can have multiple layers - NO_PICK, ITEM, LIVING, FLYING. More...
 
static int adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy)
 Return whether map2 is adjacent to map1. More...
 
static void allocate_map (mapstruct *m)
 This basically allocates the dynamic array of spaces for the map. More...
 
int blocked_link (object *ob, mapstruct *m, int sx, int sy)
 Returns true if the given coordinate is blocked except by the object passed is not blocking. More...
 
int calculate_difficulty (mapstruct *m)
 This routine is supposed to find out the difficulty of the map. More...
 
int change_map_light (mapstruct *m, int change)
 Used to change map light level (darkness) up or down. More...
 
int check_path (const char *name, int prepend_dir)
 This function checks if a file with the given path exists. More...
 
void clean_object (object *op)
 Remove and free all objects in the inventory of the given object. More...
 
void clean_tmp_map (mapstruct *m)
 Removse the temporary file used by the map. More...
 
static void create_items_path (const char *s, char *buf, size_t size)
 This makes absolute path to the itemfile where unique objects will be saved. More...
 
void create_overlay_pathname (const char *name, char *buf, size_t size)
 Same as create_pathname(), but for the overlay maps. More...
 
char * create_pathname (const char *name, char *buf, size_t size)
 Get the full path to a map file. More...
 
void create_template_pathname (const char *name, char *buf, size_t size)
 same as create_pathname(), but for the template maps. More...
 
void delete_map (mapstruct *m)
 Frees the map, including the mapstruct. More...
 
static void delete_unique_items (mapstruct *m)
 This goes through map 'm' and removes any unique items on the map. More...
 
void dump_all_maps (void)
 Prints out debug-information about all maps. More...
 
void dump_map (const mapstruct *m)
 Prints out debug-information about a map. More...
 
void fix_container (object *container)
 When the map is loaded, load_object() does not actually insert objects into inventory, but just links them. More...
 
static void fix_container_multipart (object *container)
 Go through all the objects in a container (recursively) looking for objects whose arch says they are multipart yet according to the info we have, they only have the head (as would be expected when they are saved). More...
 
void free_all_maps (void)
 Frees all allocated maps. More...
 
static void free_all_objects (mapstruct *m)
 Remove and free all objects in the given map. More...
 
void free_map (mapstruct *m)
 Frees everything allocated by the given mapstructure. More...
 
mapstructget_empty_map (int sizex, int sizey)
 Creates and returns a map of the specific size. More...
 
mapstructget_linked_map (void)
 Allocates, initialises, and returns a pointer to a mapstruct. More...
 
int get_map_flags (mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
 This rolls up wall, blocks_magic, blocks_view, etc, all into one function that just returns a P_. More...
 
mapstructget_map_from_coord (mapstruct *m, int16_t *x, int16_t *y)
 This is basically the same as out_of_map above(), but instead we return NULL if no map is valid (coordinates out of bounds and no tiled map), otherwise it returns the map as that the coordinates are really on, and updates x and y to be the localized coordinates. More...
 
int get_rangevector (object *op1, const object *op2, rv_vector *retval, int flags)
 From map.c This is used by get_player to determine where the other creature is. More...
 
int get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector *retval, int flags)
 This is basically the same as get_rangevector() above, but instead of the first parameter being an object, it instead is the map and x,y coordinates - this is used for path to player - since the object is not infact moving but we are trying to traverse the path, we need this. More...
 
mapstructhas_been_loaded (const char *name)
 Checks whether map has been loaded. More...
 
static void link_multipart_objects (mapstruct *m)
 Go through all the objects on the map looking for objects whose arch says they are multipart yet according to the info we have, they only have the head (as would be expected when they are saved). More...
 
static mapstructload_and_link_tiled_map (mapstruct *orig_map, int tile_num)
 This updates the orig_map->tile_map[tile_num] value after loading the map. More...
 
static int load_map_header (FILE *fp, mapstruct *m)
 This loads the header information of the map. More...
 
static void load_objects (mapstruct *m, FILE *fp, int mapflags)
 Loads (and parses) the objects into a given map from the specified file pointer. More...
 
static int load_overlay_map (const char *filename, mapstruct *m)
 Loads an overlay for a map, which has been loaded earlier, from file. More...
 
static int load_temporary_map (mapstruct *m)
 Loads a map, which has been loaded earlier, from file. More...
 
static void load_unique_objects (mapstruct *m)
 Loads unique objects from file(s) into the map which is in memory. More...
 
objectmap_find_by_flag (mapstruct *map, int x, int y, int flag)
 Finds an object in a map tile by flag number. More...
 
const char * map_get_path (const object *item)
 Return the map path on which the specified item is. More...
 
void map_remove_unique_files (const mapstruct *map)
 Remove files containing the map's unique items. More...
 
uint32_t map_size (mapstruct *m)
 Calculate map size without intermediate sign extension. More...
 
mapstructmapfile_load (const char *map, int flags)
 Opens the file "filename" and reads information about the map from the given file, and stores it in a newly allocated mapstruct. More...
 
int ob_blocked (const object *ob, mapstruct *m, int16_t x, int16_t y)
 Returns true if the given object can't fit in the given spot. More...
 
int on_same_map (const object *op1, const object *op2)
 Checks whether 2 objects are on the same map or not. More...
 
int out_of_map (mapstruct *m, int x, int y)
 this returns TRUE if the coordinates (x,y) are out of map m. More...
 
static shopitemsparse_shop_string (const char *input_string, const mapstruct *map)
 Takes a string from a map definition and outputs a pointer to the array of shopitems corresponding to that string. More...
 
static void print_shop_string (mapstruct *m, char *output_string, int size)
 Opposite of parse string(), this puts the string that was originally fed in to the map (or something equivilent) into output_string. More...
 
mapstructready_map_name (const char *name, int flags)
 Makes sure the given map is loaded and swapped in. More...
 
int save_map (mapstruct *m, int flag)
 Saves a map to file. More...
 
static int save_objects (mapstruct *m, FILE *fp, FILE *fp2, int flag)
 This saves all the objects on the map in a non destructive fashion. More...
 
void set_map_reset_time (mapstruct *map)
 Updates the map's timeout. More...
 
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) More...
 

Variables

static const Map_Layer_Info map_layer_info [MAP_LAYERS]
 the ob->map_layer holds the low layer. More...
 
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, names are duplicated to correspond to that layer. More...
 
int nrofallocobjects
 How many OBs allocated (free + used) More...
 
int nroffreeobjects
 How many OBs allocated and free (free) More...
 

Detailed Description

Map-related functions.

Definition in file map.c.

Macro Definition Documentation

#define TEMP_EXT   ".savefile"

Referenced by save_map().

Typedef Documentation

Information about a layer.

Function Documentation

static void add_face_layer ( int  low_layer,
int  high_layer,
object ob,
object layers[],
int  honor_visibility 
)
inlinestatic

This function is used for things that can have multiple layers - NO_PICK, ITEM, LIVING, FLYING.

Basically, we want to store in the empty spot, and if both full, store highest visiblity objects. Since update_position() goes from bottom to top order, if the new object is equal to existing we take the new object since it is higher in the stack.

Parameters
low_layerlower bounds to check (inclusive).
high_layerupper bounds to check (inclusive).
obobject to add to the layer.
layerslayers to change.
honor_visibilityif it is set to 0,then we do a pure stacking logic - this is used for the no pick layer, since stacking ordering there is basically fixed - don't want to re-order walls, pentagrams, etc.

Definition at line 2050 of file map.c.

References obj::face, Map_Layer_Info::high_layer, and new_face_struct::visibility.

Referenced by update_position().

Here is the caller graph for this function:

static int adjacent_map ( const mapstruct map1,
const mapstruct map2,
int *  dx,
int *  dy 
)
static

Return whether map2 is adjacent to map1.

If so, store the distance from map1 to map2 in dx/dy.

Parameters
map1
map2maps to consider.
dx
dydistance. Must not be NULL. Not altered if returns 0.
Returns
1 if maps are adjacent, 0 else.

Definition at line 2439 of file map.c.

References MAP_HEIGHT, MAP_WIDTH, and mapdef::tile_map.

Referenced by get_rangevector(), get_rangevector_from_mapcoord(), and on_same_map().

Here is the caller graph for this function:

static void allocate_map ( mapstruct m)
static

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

Parameters
mmap to check.
Note
will never fail, since it calls fatal() if memory allocation failure.

Definition at line 844 of file map.c.

References fatal(), mapdef::in_memory, llevError, LOG(), MAP_IN_MEMORY, map_size(), OUT_OF_MEMORY, mapdef::path, and mapdef::spaces.

Referenced by get_empty_map(), load_temporary_map(), and mapfile_load().

Here is the call graph for this function:

Here is the caller graph for this function:

int blocked_link ( object ob,
mapstruct m,
int  sx,
int  sy 
)

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
obobject we ignore. Must not be NULL.
mmap we're considering.
sx
sytarget coordinates
Returns
TRUE if the space is blocked by something other than ob.
Note
the coordinates & map passed in should have been updated for tiling by the caller.

Definition at line 346 of file map.c.

References CHECK_INV, check_inv_recursive(), DOOR, draw_ext_info(), FLAG_ALIVE, FLAG_WIZ, MapSpace::flags, FOR_MAP_FINISH, FOR_MAP_PREPARE, GET_MAP_MOVE_BLOCK, HEAD, llevError, LOG(), obj::move_type, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_NOKEY, NDI_NAVY, NDI_UNIQUE, OB_MOVE_BLOCK, OB_TYPE_MOVE_BLOCK, OUT_OF_REAL_MAP, P_IS_ALIVE, PLAYER, QUERY_FLAG, mapdef::spaces, TRANSPORT, obj::type, and mapdef::width.

Referenced by move_ob(), and path_to_player().

Here is the call graph for this function:

Here is the caller graph for this function:

int calculate_difficulty ( mapstruct m)

This routine is supposed to find out the difficulty of the map.

Difficulty does not have a lot to do with character level, but does have a lot to do with treasure on the map.

Difficulty can now be set by the map creature. If the value stored in the map is zero, then use this routine. Maps should really have a difficulty set than using this function - human calculation is much better than this functions guesswork.

Parameters
mmap for which to compute difficulty.
Returns
difficulty of the map.

Definition at line 1913 of file map.c.

References archt::clone, liv::exp, FLAG_GENERATOR, FLAG_MONSTER, FOR_MAP_FINISH, FOR_MAP_PREPARE, GENERATE_TYPE, get_archetype_by_type_subtype(), level_exp(), MAP_DIFFICULTY, MAP_HEIGHT, MAP_WIDTH, QUERY_FLAG, and obj::stats.

Referenced by cfapi_map_get_map_property(), generate_random_map(), and mapfile_load().

Here is the call graph for this function:

Here is the caller graph for this function:

int change_map_light ( mapstruct m,
int  change 
)

Used to change map light level (darkness) up or down.

It should now be possible to change a value by more than 1.

Move this from los.c to map.c since this is more related to maps than los. postive values make it darker, negative make it brighter

Will inform players on the map.

Parameters
mmap to change.
changedelta of light.
Returns
TRUE if light changed, FALSE else.

Definition at line 1995 of file map.c.

References mapdef::darkness, ext_info_map(), MAX_DARKNESS, MSG_SUBTYPE_NONE, MSG_TYPE_MISC, NDI_BLACK, and update_all_map_los().

Referenced by cast_change_map_lightlevel(), cfapi_map_change_light(), dawn_to_dusk(), and set_darkness_map().

Here is the call graph for this function:

Here is the caller graph for this function:

int check_path ( const char *  name,
int  prepend_dir 
)

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

Parameters
namemap path to check.
prepend_dirIf set, then we call create_pathname (which prepends libdir & mapdir). Otherwise, we assume the name given is fully complete.
Returns
-1 if it fails, otherwise the mode of the file is returned.
Note
Only the editor actually cares about the writablity of this - the rest of the code only cares that the file is readable. when the editor goes away, the call to stat should probably be replaced by an access instead (similar to the windows one, but that seems to be missing the prepend_dir processing

Definition at line 203 of file map.c.

References create_pathname(), MAX_BUF, S_IRGRP, S_IROTH, S_IRUSR, S_ISREG, S_IWGRP, S_IWOTH, S_IWUSR, and snprintf.

Referenced by cfapi_system_check_path(), check_login(), and load_map_header().

Here is the call graph for this function:

Here is the caller graph for this function:

void clean_object ( object op)

Remove and free all objects in the inventory of the given object.

Parameters
opobject to clean.
Todo:
move to common/object.c ?

Definition at line 1631 of file map.c.

References clean_object(), FLAG_IS_LINKED, FOR_INV_FINISH, FOR_INV_PREPARE, object_free_drop_inventory(), object_remove(), QUERY_FLAG, and remove_button_link().

Referenced by cfapi_object_clean_object(), clean_object(), delete_unique_items(), and free_all_objects().

Here is the call graph for this function:

Here is the caller graph for this function:

void clean_tmp_map ( mapstruct m)

Removse the temporary file used by the map.

Parameters
mmap, which mustn't be NULL but can have no temporary file set.

Definition at line 1954 of file map.c.

References mapdef::tmpname, and unlink.

Referenced by clean_tmp_files(), flush_old_maps(), and ready_map_name().

Here is the caller graph for this function:

static void create_items_path ( const char *  s,
char *  buf,
size_t  size 
)
static

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

Converts '/' to '@'. I think it's essier maintain files than full directory structure, but if this is problem it can be changed.

Parameters
spath of the map for the item.
bufbuffer that will contain path. Must not be NULL.
sizebuffer's length.

Definition at line 168 of file map.c.

References Settings::localdir, settings, snprintf, and Settings::uniquedir.

Referenced by load_unique_objects(), map_remove_unique_files(), and save_map().

Here is the caller graph for this function:

void create_overlay_pathname ( const char *  name,
char *  buf,
size_t  size 
)

Same as create_pathname(), but for the overlay maps.

/

Parameters
namepath of the overlay map.
bufbuffer that will contain the full path.
sizebuffer's length.

Definition at line 125 of file map.c.

References Settings::localdir, Settings::mapdir, settings, and snprintf.

Referenced by cfapi_map_create_path(), command_overlay_reset(), load_overlay_map(), mapfile_load(), and save_map().

Here is the caller graph for this function:

char* create_pathname ( const char *  name,
char *  buf,
size_t  size 
)

Get the full path to a map file.

This simply means prepending the correct map directory to the given path.

Parameters
namepath of the map.
bufbuffer that will contain the full path.
sizebuffer's length.
Returns
buf.

Definition at line 104 of file map.c.

References Settings::datadir, Settings::mapdir, settings, and snprintf.

Referenced by CREMapInformationManager::browseMaps(), cfapi_map_create_path(), check_path(), enter_fixed_template_map(), enter_unique_map(), mapfile_load(), CREMapInformationManager::process(), process_map(), and save_map().

Here is the caller graph for this function:

void create_template_pathname ( const char *  name,
char *  buf,
size_t  size 
)

same as create_pathname(), but for the template maps.

Parameters
namepath of the template map.
bufbuffer that will contain the full path.
sizebuf's length

Definition at line 145 of file map.c.

References Settings::localdir, settings, snprintf, and Settings::templatedir.

Referenced by enter_fixed_template_map(), and enter_random_template_map().

Here is the caller graph for this function:

void delete_map ( mapstruct m)

Frees the map, including the mapstruct.

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

Parameters
mpointer to mapstruct, if NULL no action. Will be invalid after this function.

Definition at line 1741 of file map.c.

References first_map, free_map(), mapdef::in_memory, llevError, LOG(), MAP_IN_MEMORY, MAP_SAVING, mapdef::next, mapdef::path, mapdef::tile_map, and mapdef::tmpname.

Referenced by cfapi_map_delete_map(), flush_old_maps(), free_all_maps(), free_style_maps(), init_dynamic(), key_confirm_quit(), mapfile_load(), monsterFight(), CREMapInformationManager::process(), process_map(), ready_map_name(), START_TEST(), swap_map(), and teardown().

Here is the call graph for this function:

Here is the caller graph for this function:

static void delete_unique_items ( mapstruct m)
static

This goes through map 'm' and removes any unique items on the map.

Parameters
mmap to check.

Definition at line 1364 of file map.c.

References clean_object(), FLAG_IS_FLOOR, FLAG_IS_LINKED, FLAG_UNIQUE, FOR_MAP_FINISH, FOR_MAP_PREPARE, MAP_HEIGHT, MAP_WIDTH, object_free_drop_inventory(), object_remove(), QUERY_FLAG, and remove_button_link().

Referenced by load_unique_objects().

Here is the call graph for this function:

Here is the caller graph for this function:

void dump_all_maps ( void  )

Prints out debug-information about all maps.

This basically just goes through all the maps and calls dump_map() on each one. Can be used by a DM with the dumpallmaps command.

Definition at line 270 of file map.c.

References dump_map(), first_map, and mapdef::next.

Referenced by command_dumpallmaps().

Here is the call graph for this function:

Here is the caller graph for this function:

void dump_map ( const mapstruct m)

Prints out debug-information about a map.

Dumping these at llevError doesn't seem right, but is necessary to make sure the information is in fact logged. Can be used by a DM with the dumpmap command.

Parameters
mmap to dump.

Definition at line 247 of file map.c.

References mapdef::darkness, mapdef::difficulty, mapdef::in_memory, llevError, LOG(), MAP_ENTER_X, MAP_ENTER_Y, MAP_HEIGHT, MAP_WIDTH, mapdef::maplore, mapdef::msg, mapdef::path, and mapdef::tmpname.

Referenced by command_dumpmap(), and dump_all_maps().

Here is the call graph for this function:

Here is the caller graph for this function:

void fix_container ( object container)

When the map is loaded, load_object() does not actually insert objects into inventory, but just links them.

What this does is go through and insert them properly.

Parameters
containerobject that contains the inventory. This is needed so that we can update the containers weight.
Todo:
This is unusued, should it be used somewhere?

Definition at line 544 of file map.c.

References fix_container(), FOR_OB_AND_BELOW_FINISH, FOR_OB_AND_BELOW_PREPARE, obj::inv, object_insert_in_ob(), and object_sum_weight().

Referenced by fix_container().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fix_container_multipart ( object container)
static

Go through all the objects in a container (recursively) looking for objects whose arch says they are multipart yet according to the info we have, they only have the head (as would be expected when they are saved).

We do have to look for the old maps that did save the more sections and not re-add sections for them.

Parameters
containerobject that contains the inventory.

Definition at line 569 of file map.c.

References add_string(), arch_to_object(), CLEAR_FLAG, obj::env, FLAG_REMOVED, FOR_INV_FINISH, FOR_INV_PREPARE, free_string(), obj::head, obj::more, archt::more, obj::name, and obj::title.

Referenced by link_multipart_objects().

Here is the call graph for this function:

Here is the caller graph for this function:

void free_all_maps ( void  )

Frees all allocated maps.

Definition at line 1963 of file map.c.

References delete_map(), first_map, mapdef::in_memory, llevDebug, LOG(), MAP_IN_MEMORY, and MAP_SAVING.

Referenced by cleanup().

Here is the call graph for this function:

Here is the caller graph for this function:

static void free_all_objects ( mapstruct m)
static

Remove and free all objects in the given map.

Parameters
mmap to free.

Definition at line 1647 of file map.c.

References clean_object(), FLAG_REMOVED, GET_MAP_OB, HEAD, mapdef::in_memory, llevDebug, LOG(), obj::map, MAP_HEIGHT, MAP_IN_MEMORY, MAP_WIDTH, obj::name, obj::next, object_free_drop_inventory(), object_remove(), objects, and QUERY_FLAG.

Referenced by free_map(), and save_map().

Here is the call graph for this function:

Here is the caller graph for this function:

void free_map ( mapstruct m)

Frees everything allocated by the given mapstructure.

Don't free tmpname - our caller is left to do that. Mapstructure itself is not freed.

Parameters
mmap to free.

Definition at line 1694 of file map.c.

References mapdef::background_music, mapdef::buttons, EVENT_MAPUNLOAD, execute_global_event(), free_all_objects(), FREE_AND_CLEAR, free_objectlinkpt(), mapdef::in_memory, llevError, LOG(), MAP_SWAPPED, mapdef::maplore, mapdef::msg, mapdef::name, mapdef::shopitems, mapdef::shoprace, mapdef::spaces, mapdef::tile_map, and mapdef::tile_path.

Referenced by delete_map(), CRECombatSimulator::fight(), START_TEST(), swap_map(), and teardown().

Here is the call graph for this function:

Here is the caller graph for this function:

mapstruct* get_empty_map ( int  sizex,
int  sizey 
)

Creates and returns a map of the specific size.

Used in random map code and the editor.

Parameters
sizex
sizeymap size.
Returns
new map.
Note
will never return NULL, as get_linked_map() never fails.

Definition at line 874 of file map.c.

References allocate_map(), get_linked_map(), mapdef::height, mapdef::in_memory, MAP_SWAPPED, and mapdef::width.

Referenced by cfapi_map_get_map(), CRECombatSimulator::fight(), make_map_floor(), monsterFight(), setup(), and START_TEST().

Here is the call graph for this function:

Here is the caller graph for this function:

mapstruct* get_linked_map ( void  )

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

Modified to no longer take a path option which was not being used anyways. MSW 2001-07-01

Returns
new structure.
Note
will never return NULL, but call fatal() if memory error.

Definition at line 793 of file map.c.

References fatal(), first_map, mapdef::in_memory, mapdef::last_reset_time, MAP_ENTER_X, MAP_ENTER_Y, MAP_HEIGHT, MAP_RESET_TIMEOUT, MAP_SWAPPED, MAP_TIMEOUT, MAP_WIDTH, mapdef::next, and OUT_OF_MEMORY.

Referenced by get_empty_map(), mapfile_load(), and read_map_log().

Here is the call graph for this function:

Here is the caller graph for this function:

int get_map_flags ( mapstruct oldmap,
mapstruct **  newmap,
int16_t  x,
int16_t  y,
int16_t nx,
int16_t ny 
)

This rolls up wall, blocks_magic, blocks_view, etc, all into one function that just returns a P_.

. value (see map.h) it will also do map translation for tiled maps, returning new values into newmap, nx, and ny. Any and all of those values can be null, in which case if a new map is needed (returned by a P_NEW_MAP value, another call to get_map_from_coord is needed. The case of not passing values is if we're just checking for the existence of something on those spaces, but don't expect to insert/remove anything from those spaces.

Parameters
oldmapmap for which we want information.
newmapif not NULL, will contain the actual map checked if not oldmap.
x
ycoordinates to check
nx
nyif not NULL, will contain the actual coordinates checked.
Returns
flags for specified position, with maybe P_OUT_OF_MAP or P_NEW_MAP set.

Definition at line 302 of file map.c.

References MapSpace::flags, get_map_from_coord(), P_NEW_MAP, P_OUT_OF_MAP, mapdef::spaces, and mapdef::width.

Referenced by alchemy(), animate_weapon(), armour_improver_type_apply(), attempt_jump(), can_see_monsterP(), cast_cause_disease(), cast_cone(), cast_create_obj(), cast_destruction(), cast_detection(), cast_earth_to_dust(), cast_light(), cast_polymorph(), cast_raise_dead_spell(), cast_spell(), cast_transfer(), cfapi_map_get_map_property(), cfapi_map_get_object_at(), check_bullet(), check_infection(), check_wall(), command_save(), common_process_projectile(), counterspell(), create_bomb(), dimension_door(), dispel_rune(), do_harvest(), do_skill_ident(), do_throw(), draw_client_map(), execute_word_of_recall(), expand_lighted_sight(), expand_sight(), find_target_for_friendly_spell(), find_traps(), fire_arch_from_position(), fire_bolt(), fire_bow(), forklightning(), get_pointed_target(), hideability(), hit_map(), magic_mapping_mark(), magic_mapping_mark_recursive(), magic_wall(), map_find_dir(), monster_communicate(), monster_find_nearest_living_creature(), monster_npc_call_help(), monster_stand_in_light(), mood_change(), move_aura(), move_ball_spell(), move_bolt(), move_bullet(), move_missile(), move_ob(), move_player_mover(), move_swarm_spell(), move_to(), ob_blocked(), object_find_multi_free_spot_within_radius(), ok_to_put_more(), path_to_player(), pets_get_enemy(), pets_move(), pets_move_golem(), pick_arrow_target(), probe(), process_players1(), remove_adjacent_doors(), remove_trap(), roll_ob(), singing(), skill_attack(), spell_failure(), spell_find_dir(), stand_near_hostile(), steal(), teleport(), try_fit(), use_oratory(), weapon_improver_type_apply(), and write_rune().

Here is the call graph for this function:

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

This is basically the same as out_of_map above(), but instead we return NULL if no map is valid (coordinates out of bounds and no tiled map), otherwise it returns the map as that the coordinates are really on, and updates x and y to be the localized coordinates.

Using this is more efficient than calling out_of_map and then figuring out what the real map is

Parameters
mmap we want to look at. Must not be NULL.
x
ycoordinates, which will contain the real position that was checked.
Returns
map that is at specified location. Will be NULL if not on any map.

Definition at line 2366 of file map.c.

References get_map_from_coord(), mapdef::in_memory, load_and_link_tiled_map(), MAP_HEIGHT, MAP_IN_MEMORY, MAP_WIDTH, mapdef::tile_map, and mapdef::tile_path.

Referenced by cfapi_map_get_map(), draw_client_map2(), get_map_flags(), get_map_from_coord(), look_at(), monster_use_bow(), move_player_attack(), object_insert_in_map(), object_remove(), and pets_move().

Here is the call graph for this function:

Here is the caller graph for this function:

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

From map.c 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.

Parameters
op1object which wants to go to op2's location.
op2target of op1.
retvalvector for op1 to go to op2.
flagsif 1, don't translate for closest body part of 'op1'
Returns
1=ok; 0=the objects are not on the same map

Definition at line 2516 of file map.c.

References adjacent_map(), rv_vector::direction, rv_vector::distance, rv_vector::distance_x, rv_vector::distance_y, find_dir_2(), isqrt(), obj::map, obj::more, rv_vector::part, obj::x, and obj::y.

Referenced by flee_player(), monster_can_detect_enemy(), monster_can_hit(), monster_cast_spell(), monster_find_enemy(), monster_move(), monster_use_bow(), monster_use_range(), monster_use_scroll(), monster_use_skill(), path_to_player(), pets_get_enemy(), pets_move(), player_can_view(), process_players1(), and spring_trap().

Here is the call graph for this function:

Here is the caller graph for this function:

int get_rangevector_from_mapcoord ( const mapstruct m,
int  x,
int  y,
const object op2,
rv_vector retval,
int  flags 
)

This is basically the same as get_rangevector() above, but instead of the first parameter being an object, it instead is the map and x,y coordinates - this is used for path to player - since the object is not infact moving but we are trying to traverse the path, we need this.

flags has no meaning for this function at this time - I kept it in to be more consistant with the above function and also in case they are needed for something in the future. Also, since no object is pasted, the best field of the rv_vector is set to NULL.

Parameters
mmap to consider.
x
yorigin coordinates.
op2target object.
retvalvector to get to op2.
flagsunused.
Returns
1=ok; 0=the objects are not on the same map

Definition at line 2589 of file map.c.

References adjacent_map(), rv_vector::direction, rv_vector::distance, rv_vector::distance_x, rv_vector::distance_y, find_dir_2(), isqrt(), obj::map, rv_vector::part, obj::x, and obj::y.

Referenced by path_to_player().

Here is the call graph for this function:

Here is the caller graph for this function:

mapstruct* has_been_loaded ( const char *  name)

Checks whether map has been loaded.

Parameters
namepath of the map to search. Can be NULL.
Returns
the mapstruct which has a name matching the given argument. return NULL if no match is found.

Definition at line 79 of file map.c.

References first_map, mapdef::next, and mapdef::path.

Referenced by cfapi_map_has_been_loaded(), check_login(), command_reset(), is_legal_2ways_exit(), monsterFight(), and ready_map_name().

Here is the caller graph for this function:

static void link_multipart_objects ( mapstruct m)
static

Go through all the objects on the map looking for objects whose arch says they are multipart yet according to the info we have, they only have the head (as would be expected when they are saved).

We do have to look for the old maps that did save the more sections and not re-add sections for them.

Parameters
mmap to check.

Definition at line 610 of file map.c.

References fix_container_multipart(), FOR_MAP_FINISH, FOR_MAP_PREPARE, MAP_HEIGHT, MAP_WIDTH, and object_fix_multipart().

Referenced by load_objects().

Here is the call graph for this function:

Here is the caller graph for this function:

static mapstruct* load_and_link_tiled_map ( mapstruct orig_map,
int  tile_num 
)
static

This updates the orig_map->tile_map[tile_num] value after loading the map.

It also takes care of linking back the freshly loaded maps tile_map values if it tiles back to this one. It returns the value of orig_map->tile_map[tile_num]. It really only does this so that it is easier for calling functions to verify success.

Parameters
orig_mapmap for which we load the tiled map.
tile_numtile to load. Must be between 0 and 3 inclusive.
Returns
linked map, or NULL on failure.
Todo:
check ready_map_name() 's return value, which can be NULL?

Definition at line 2261 of file map.c.

References HUGE_BUF, mapdef::path, path_combine_and_normalize(), ready_map_name(), mapdef::tile_map, and mapdef::tile_path.

Referenced by get_map_from_coord(), and out_of_map().

Here is the call graph for this function:

Here is the caller graph for this function:

static int load_map_header ( FILE *  fp,
mapstruct m 
)
static

This loads the header information of the map.

The header contains things like difficulty, size, timeout, etc. this used to be stored in the map object, but with the addition of tiling, fields beyond that easily named in an object structure were needed, so it just made sense to put all the stuff in the map object so that names actually make sense. This could be done in lex (like the object loader), but I think currently, there are few enough fields this is not a big deal. MSW 2001-07-01

Parameters
fpfile to read from.
mmap being read.
Returns
0 on success, 1 on failure.

Definition at line 1027 of file map.c.

References mapdef::background_music, check_path(), mapdef::darkness, mapdef::difficulty, mapdef::enter_x, mapdef::enter_y, mapdef::fixed_resettime, get_region_by_name(), mapdef::height, HUGE_BUF, mapdef::is_template, mapdef::last_reset_time, llevError, LOG(), mapdef::maplore, mapdef::msg, mapdef::name, mapdef::nosmooth, mapdef::outdoor, parse_shop_string(), mapdef::path, path_combine_and_normalize(), mapdef::region, mapdef::reset_timeout, mapdef::shopgreed, mapdef::shopitems, mapdef::shopmax, mapdef::shopmin, mapdef::shoprace, snprintf, strdup_local, mapdef::tile_path, mapdef::timeout, mapdef::unique, and mapdef::width.

Referenced by load_overlay_map(), load_temporary_map(), and mapfile_load().

Here is the call graph for this function:

Here is the caller graph for this function:

static void load_objects ( mapstruct m,
FILE *  fp,
int  mapflags 
)
static
static int load_overlay_map ( const char *  filename,
mapstruct m 
)
static

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

Parameters
filenamefilename for overlay.
mmap we want to load.
Returns
0 on success, non zero in case of error, which is LOG'ed.

Definition at line 1329 of file map.c.

References create_overlay_pathname(), mapdef::in_memory, llevError, load_map_header(), load_objects(), LOG(), MAP_IN_MEMORY, MAP_LOADING, MAP_OVERLAY, MAX_BUF, and mapdef::path.

Referenced by ready_map_name().

Here is the call graph for this function:

Here is the caller graph for this function:

static int load_temporary_map ( mapstruct m)
static

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

Parameters
mmap we want to reload.
Returns
0 if success, non zero if failure, in which case error was LOG'ed.

Definition at line 1293 of file map.c.

References allocate_map(), mapdef::in_memory, llevError, load_map_header(), load_objects(), LOG(), MAP_IN_MEMORY, MAP_LOADING, mapdef::path, and mapdef::tmpname.

Referenced by ready_map_name().

Here is the call graph for this function:

Here is the caller graph for this function:

static void load_unique_objects ( mapstruct m)
static

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

Parameters
mmap to load unique items into.

Definition at line 1389 of file map.c.

References create_items_path(), delete_unique_items(), mapdef::in_memory, llevDebug, LO_NOREAD, load_object(), load_objects(), LOG(), MAP_IN_MEMORY, MAP_LOADING, MAX_BUF, mapdef::path, R_OK, snprintf, and mapdef::tmpname.

Referenced by ready_map_name().

Here is the call graph for this function:

Here is the caller graph for this function:

object* map_find_by_flag ( mapstruct map,
int  x,
int  y,
int  flag 
)

Finds an object in a map tile by flag number.

Checks the objects' heads.

Parameters
mapthe map to search.
xthe x-coordiate to search.
ythe y-coordiate to search.
flagthe flag to seacrh for
Returns
first object's head in the tile that has the flag set. NULL if no match.
Note
will not search in inventory of objects.

Definition at line 2650 of file map.c.

References obj::above, GET_MAP_OB, HEAD, and QUERY_FLAG.

Referenced by cast_light(), common_process_projectile(), do_mood_floor(), get_pointed_target(), and mood_change().

Here is the caller graph for this function:

const char* map_get_path ( const object item)

Return the map path on which the specified item is.

Parameters
itemwhat to return the map path for.
Returns
path, map's name, or error string, never NULL.

Definition at line 2690 of file map.c.

References obj::env, obj::map, map_get_path(), mapdef::name, and mapdef::path.

Referenced by gate_type_process(), and map_get_path().

Here is the call graph for this function:

Here is the caller graph for this function:

void map_remove_unique_files ( const mapstruct map)

Remove files containing the map's unique items.

Parameters
map

Definition at line 2667 of file map.c.

References create_items_path(), HUGE_BUF, mapdef::path, snprintf, mapdef::unique, and unlink.

Referenced by command_reset().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t map_size ( mapstruct m)

Calculate map size without intermediate sign extension.

Definition at line 830 of file map.c.

References mapdef::height, and mapdef::width.

Referenced by allocate_map(), command_style_map_info(), and malloc_info().

Here is the caller graph for this function:

mapstruct* mapfile_load ( const char *  map,
int  flags 
)

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

A pointer to this structure is returned, or NULL on failure. flags correspond to those in map.h. Main ones used are MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and

Parameters
mapMap path
flagsAdditional options for loading the map:
Returns
loaded map, or NULL if failure.

Definition at line 1235 of file map.c.

References allocate_map(), apply_auto_fix(), calculate_difficulty(), create_overlay_pathname(), create_pathname(), delete_map(), EVENT_MAPLOAD, execute_global_event(), get_linked_map(), HUGE_BUF, mapdef::in_memory, llevDebug, llevError, load_map_header(), load_objects(), LOG(), MAP_DIFFICULTY, MAP_IN_MEMORY, MAP_LOADING, MAP_OVERLAY, MAP_PLAYER_UNIQUE, MAP_STYLE, MAX_BUF, mapdef::path, safe_strncpy, set_map_reset_time(), snprintf, and update_buttons().

Referenced by enter_fixed_template_map(), enter_unique_map(), load_style_map(), and ready_map_name().

Here is the call graph for this function:

Here is the caller graph for this function:

int ob_blocked ( const object ob,
mapstruct m,
int16_t  x,
int16_t  y 
)

Returns true if the given object can't fit in the given spot.

This is meant for multi space objects - for single space objecs, just calling get_map_blocked and checking that against movement type of object. This function goes through all the parts of the multipart object and makes sure they can be inserted.

While this doesn't call out of map, the get_map_flags does.

This function has been used to deprecate arch_out_of_map - this function also does that check, and since in most cases, a call to one would follow the other, doesn't make a lot of sense to have two seperate functions for this.

This returns nonzero if this arch can not go on the space provided, 0 otherwise. the return value will contain the P_.. value so the caller can know why this object can't go on the map. Note that callers should not expect P_NEW_MAP to be set in return codes - since the object is multispace - if we did return values, what do you return if half the object is one map, half on another.

Parameters
obobject to test.
m
x
ymap and coordinates to check.
Returns
0 if the object can fit on specified space, non-zero else.
Note
This used to be arch_blocked, but with new movement code, we need to have actual object to check its move_type against the move_block values.

Definition at line 489 of file map.c.

References AB_NO_PASS, obj::arch, archt::clone, get_map_flags(), GET_MAP_MOVE_BLOCK, obj::more, archt::more, MOVE_ALL, obj::move_type, OB_TYPE_MOVE_BLOCK, P_IS_ALIVE, P_OUT_OF_MAP, TRANSPORT, obj::type, obj::x, and obj::y.

Referenced by enter_map(), monster_compute_path(), move_creator(), object_find_first_free_spot(), object_find_free_spot(), object_find_multi_free_spot_around(), object_find_multi_free_spot_within_radius(), pets_summon_golem(), pets_summon_object(), and turn_one_transport().

Here is the call graph for this function:

Here is the caller graph for this function:

int on_same_map ( const object op1,
const object op2 
)

Checks whether 2 objects are on the same map or not.

Note we only look one map out to keep the processing simple and efficient. This could probably be a macro. MSW 2001-08-05

Parameters
op1first object.
op2second object.
Returns
TRUE if op1 and op2 are effectively on the same map (as related to map tiling).
Note
This looks for a path from op1 to op2, so if the tiled maps are assymetric and op2 has a path to op1, this will still return false.

Definition at line 2627 of file map.c.

References adjacent_map(), and obj::map.

Referenced by abort_attack(), adj_attackroll(), cfapi_object_on_same_map(), get_attack_mode(), monster_check_enemy(), monster_find_enemy(), monster_move(), move_ball_spell(), pets_get_enemy(), pets_move(), pets_remove_all(), and share_exp().

Here is the call graph for this function:

Here is the caller graph for this function:

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

this returns TRUE if the coordinates (x,y) are out of map m.

This function also takes into account any tiling considerations, loading adjacant maps as needed. This is the function should always be used when it necessary to check for valid coordinates. This function will recursively call itself for the tiled maps.

Parameters
mmap to consider. Must not be NULL.
x
ycoordinates.
Returns
1 if out of map, 0 else

Definition at line 2294 of file map.c.

References mapdef::in_memory, load_and_link_tiled_map(), MAP_HEIGHT, MAP_IN_MEMORY, MAP_WIDTH, out_of_map(), mapdef::tile_map, and mapdef::tile_path.

Referenced by animate_bomb(), attack_message(), cfapi_map_out_of_map(), cfapi_object_teleport(), command_create(), enter_map(), esrv_draw_look(), explode_bullet(), look_at(), map_find_by_archetype(), map_find_by_type(), move_player_attack(), move_teleporter(), object_insert_in_map(), out_of_map(), and pick_lock().

Here is the call graph for this function:

Here is the caller graph for this function:

static shopitems* parse_shop_string ( const char *  input_string,
const mapstruct map 
)
static

Takes a string from a map definition and outputs a pointer to the array of shopitems corresponding to that string.

Memory is allocated for this, it must be freed at a later date. Called by parse_map_headers() below.

Parameters
input_stringshop item line.
mapmap for which to parse the string, in case of warning.
Returns
new array that should be freed by the caller.

Definition at line 896 of file map.c.

References CALLOC, fatal(), get_typedata(), get_typedata_by_name(), shopitem::index, llevDebug, llevError, LOG(), typedata::name, shopitem::name, mapdef::name, typedata::name_pl, shopitem::name_pl, typedata::number, OUT_OF_MEMORY, strdup_local, shopitem::strength, strip_endline(), and shopitem::typenum.

Referenced by load_map_header().

Here is the call graph for this function:

Here is the caller graph for this function:

static void print_shop_string ( mapstruct m,
char *  output_string,
int  size 
)
static

Opposite of parse string(), this puts the string that was originally fed in to the map (or something equivilent) into output_string.

Parameters
mmap we're considering.
output_stringstring to write to.
sizeoutput_string's length.

Definition at line 982 of file map.c.

References shopitem::index, MAX_BUF, shopitem::name, mapdef::shopitems, snprintf, shopitem::strength, and shopitem::typenum.

Referenced by save_map().

Here is the caller graph for this function:

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.
flags
  • 0x1 (MAP_FLUSH): flush the map - always load from the map directory, and don't do unique items or the like.
  • 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. dont do any more name translation on it.
Returns
pointer to the given map, NULL on failure.

Definition at line 1803 of file map.c.

References clean_tmp_map(), decay_objects(), delete_map(), has_been_loaded(), mapdef::in_memory, mapdef::last_reset_time, load_overlay_map(), load_temporary_map(), load_unique_objects(), MAP_FLUSH, MAP_IN_MEMORY, MAP_LOADING, MAP_OVERLAY, MAP_PLAYER_UNIQUE, mapfile_load(), mapdef::outdoor, seconds(), set_darkness_map(), and mapdef::tmpname.

Referenced by cast_create_town_portal(), cfapi_map_get_map(), enter_exit(), enter_fixed_template_map(), enter_player_maplevel(), enter_random_template_map(), enter_unique_map(), init_dynamic(), is_legal_2ways_exit(), load_and_link_tiled_map(), place_exits(), CREMapInformationManager::process(), process_map(), START_TEST(), and teardown().

Here is the call graph for this function:

Here is the caller graph for this function:

int save_map ( mapstruct m,
int  flag 
)

Saves a map to file.

If flag is SAVE_MODE_INPLACE, it is saved into the same file it was (originally) loaded from. Otherwise a temporary filename will be genarated, 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
mmap to save.
flagOne of SAVE_MODE_xxx values.
Returns
one of SAVE_ERROR_xxx values.

Definition at line 1436 of file map.c.

References mapdef::background_music, create_items_path(), create_overlay_pathname(), create_pathname(), mapdef::darkness, mapdef::difficulty, mapdef::enter_x, mapdef::enter_y, mapdef::fixed_resettime, FMT64U, free_all_objects(), mapdef::height, mapdef::in_memory, mapdef::is_template, mapdef::last_reset_time, llevDebug, llevError, LOG(), make_path_to_file(), MAP_IN_MEMORY, MAP_SAVING, mapdef::maplore, MAX_BUF, mapdef::msg, regiondef::name, mapdef::name, mapdef::nosmooth, of_cancel(), of_close(), of_open(), mapdef::outdoor, mapdef::path, print_shop_string(), mapdef::region, mapdef::reset_timeout, SAVE_ERROR_CLOSE, SAVE_ERROR_NO_PATH, SAVE_ERROR_OK, SAVE_ERROR_RCREATION, SAVE_ERROR_RRENAME, SAVE_ERROR_UCREATION, SAVE_ERROR_URENAME, SAVE_ERROR_WRITE, SAVE_FLAG_NO_REMOVE, SAVE_MODE, SAVE_MODE_NORMAL, SAVE_MODE_OVERLAY, save_objects(), settings, mapdef::shopgreed, mapdef::shopitems, mapdef::shopmax, mapdef::shopmin, mapdef::shoprace, snprintf, mapdef::swap_time, TEMP_EXT, tempnam(), mapdef::tile_path, Settings::tmpdir, mapdef::tmpname, mapdef::unique, unlink, and mapdef::width.

Referenced by clean_tmp_files(), command_overlay_save(), generate_map(), START_TEST(), swap_map(), and teardown().

Here is the call graph for this function:

Here is the caller graph for this function:

static int save_objects ( mapstruct m,
FILE *  fp,
FILE *  fp2,
int  flag 
)
static

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

Modified by MSW 2001-07-01 to do in a single pass - reduces code, and we only save the head of multi part objects - this is needed in order to do map tiling properly.

Parameters
mmap to save.
fpfile where regular objects are saved.
fp2file to save unique objects.
flagcombination of SAVE_FLAG_xxx flags.
Returns
one of SAVE_ERROR_xxx value.

Definition at line 748 of file map.c.

References FLAG_IS_FLOOR, FLAG_OBJ_ORIGINAL, FLAG_UNIQUE, FLAG_UNPAID, FOR_MAP_FINISH, FOR_MAP_PREPARE, llevDebug, LOG(), MAP_HEIGHT, MAP_WIDTH, object_get_owner(), PLAYER, QUERY_FLAG, SAVE_FLAG_NO_REMOVE, SAVE_FLAG_SAVE_UNPAID, and save_object().

Referenced by save_map().

Here is the call graph for this function:

Here is the caller graph for this function:

void set_map_reset_time ( mapstruct map)

Updates the map's timeout.

Parameters
mapmap to update.

Definition at line 2233 of file map.c.

References MAP_DEFAULTRESET, MAP_MAXRESET, MAP_RESET_TIMEOUT, MAP_WHEN_RESET, and seconds().

Referenced by mapfile_load(), and swap_map().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Variable Documentation

const Map_Layer_Info map_layer_info[MAP_LAYERS]
static
Initial value:
= {
}
#define MAP_LAYER_FLOOR
Definition: map.h:40
#define MAP_LAYER_LIVING2
Definition: map.h:47
#define MAP_LAYER_ITEM3
Definition: map.h:45
#define MAP_LAYER_NO_PICK2
Non pickable ground objects.
Definition: map.h:42
#define MAP_LAYER_FLY2
Arrows, etc.
Definition: map.h:49

the ob->map_layer holds the low layer.

For the update_position() logic, we also need to know the higher layer and whether visibility should be honored. This table has that information, so that it doesn't need to be hardcoded.

Definition at line 63 of file map.c.

const char* const map_layer_name[MAP_LAYERS]
Initial value:
= {
"floor", "no_pick", "no_pick", "item", "item",
"item", "living", "living", "fly", "fly"
}

These correspond to the layer names in map.h - since some of the types can be on multiple layers, names are duplicated to correspond to that layer.

Definition at line 46 of file map.c.

Referenced by get_ob_diff().

int nrofallocobjects

How many OBs allocated (free + used)

Definition at line 57 of file object.c.

Referenced by swap_below_max().

int nroffreeobjects

How many OBs allocated and free (free)

Definition at line 56 of file object.c.

Referenced by swap_below_max().