Crossfire Server, Trunk
|
#include "global.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <math.h>
#include <unistd.h>
#include "sproto.h"
#include "loader.h"
#include "output_file.h"
#include "path.h"
#include "stats.h"
Go to the source code of this file.
Data Structures | |
struct | Map_Layer_Info |
Functions | |
static void | add_face_layer (int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility) |
static int | adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) |
void | allocate_map (mapstruct *m) |
int | blocked_link (object *ob, mapstruct *m, int16_t sx, int16_t sy) |
int | calculate_difficulty (mapstruct *m) |
int | change_map_light (mapstruct *m, int change) |
int | check_path (const char *name, int prepend_dir) |
void | clean_object (object *op) |
void | clean_tmp_map (mapstruct *m) |
static void | create_items_path (const char *s, char *buf, size_t size) |
void | create_overlay_pathname (const char *name, char *buf, size_t size) |
char * | create_pathname (const char *name, char *buf, size_t size) |
void | create_template_pathname (const char *name, char *buf, size_t size) |
void | delete_map (mapstruct *m) |
static void | delete_unique_items (mapstruct *m) |
void | dump_all_maps (void) |
void | dump_map (const mapstruct *m) |
static void | fix_container_multipart (object *container) |
void | free_all_maps (void) |
static void | free_all_objects (mapstruct *m) |
void | free_map (mapstruct *m) |
mapstruct * | get_empty_map (int sizex, int sizey) |
mapstruct * | get_linked_map (void) |
int | get_map_flags (mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny) |
mapstruct * | get_map_from_coord (mapstruct *m, int16_t *x, int16_t *y) |
int | get_rangevector (object *op1, const object *op2, rv_vector *retval, int flags) |
int | get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector *retval) |
mapstruct * | has_been_loaded (const char *name) |
static void | link_multipart_objects (mapstruct *m) |
static mapstruct * | load_and_link_tiled_map (mapstruct *orig_map, int tile_num) |
static int | load_map_header (FILE *fp, mapstruct *m) |
void | load_objects (mapstruct *m, FILE *fp, int mapflags) |
static int | load_overlay_map (const char *filename, mapstruct *m) |
static int | load_temporary_map (mapstruct *m) |
static void | load_unique_objects (mapstruct *m) |
object * | map_find_by_flag (mapstruct *map, int x, int y, int flag) |
const char * | map_get_path (const object *item) |
void | map_path (const char *map, int flags, char *pathname, size_t bufsize) |
bool | map_path_unique (const char *path) |
void | map_remove_unique_files (const mapstruct *map) |
void | map_reset_swap (mapstruct *m) |
uint32_t | map_size (mapstruct *m) |
MapSpace * | map_space (const mapstruct *m, int x, int y) |
mapstruct * | mapfile_load (const char *map, int flags) |
mapstruct * | mapfile_load_lowlevel (const char *map, const char *pathname, int flags) |
int | ob_blocked (const object *ob, mapstruct *m, int16_t x, int16_t y) |
int | on_same_map (const object *op1, const object *op2) |
int | out_of_map (mapstruct *m, int x, int y) |
static shopitems * | parse_shop_string (const char *input_string, const mapstruct *map) |
static void | print_shop_string (mapstruct *m, char *output_string, int size) |
mapstruct * | ready_map_name (const char *name, int flags) |
int | save_map (mapstruct *m, int flag) |
int | save_objects (mapstruct *m, FILE *fp, FILE *fp2, int flag) |
void | set_map_reset_time (mapstruct *map) |
void | update_position (mapstruct *m, int x, int y) |
Variables | |
static const Map_Layer_Info | map_layer_info [MAP_LAYERS] |
const char *const | map_layer_name [MAP_LAYERS] |
Map-related functions.
Definition in file map.cpp.
|
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.
low_layer | lower bounds to check (inclusive). |
high_layer | upper bounds to check (inclusive). |
ob | object to add to the layer. |
layers | layers to change. |
honor_visibility | if 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 2049 of file map.cpp.
References object::face, banquet::l, guildjoin::ob, Ice::tmp, and Face::visibility.
Referenced by update_position().
|
static |
Return whether map2 is adjacent to map1. If so, store the distance from map1 to map2 in dx/dy.
map1 | |
map2 | maps to consider. |
dx | |
dy | distance. Must not be NULL. Not altered if returns 0. |
Definition at line 2464 of file map.cpp.
References MAP_HEIGHT, MAP_WIDTH, and mapstruct::tile_map.
Referenced by get_rangevector(), get_rangevector_from_mapcoord(), and on_same_map().
void allocate_map | ( | mapstruct * | m | ) |
This basically allocates the dynamic array of spaces for the map.
m | map to check. |
Definition at line 812 of file map.cpp.
References fatal(), llevError, LOG(), m, MAP_IN_MEMORY, map_size(), and OUT_OF_MEMORY.
Referenced by get_empty_map(), load_temporary_map(), mapfile_load_lowlevel(), and mapsave_test().
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.
ob | object we ignore. Must not be NULL. |
m | map we're considering. |
sx | |
sy | target coordinates |
Definition at line 344 of file map.cpp.
References CHECK_INV, check_inv_recursive(), DOOR, draw_ext_info(), FLAG_ALIVE, FLAG_WIZ, FOR_MAP_FINISH, FOR_MAP_PREPARE, GET_MAP_MOVE_BLOCK, HEAD, llevError, LOG(), m, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_NOKEY, NDI_NAVY, NDI_UNIQUE, guildjoin::ob, OB_MOVE_BLOCK, OB_TYPE_MOVE_BLOCK, OUT_OF_REAL_MAP, P_IS_ALIVE, PLAYER, QUERY_FLAG, Ice::tmp, and TRANSPORT.
Referenced by move_ob(), and path_to_player().
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.
m | map for which to compute difficulty. |
Definition at line 1896 of file map.cpp.
References archetype::clone, living::exp, FLAG_GENERATOR, FLAG_MONSTER, FOR_MAP_FINISH, FOR_MAP_PREPARE, if(), level_exp(), m, MAP_DIFFICULTY, MAP_HEIGHT, MAP_WIDTH, object_get_value(), give::op, QUERY_FLAG, object::stats, diamondslots::x, and diamondslots::y.
Referenced by cfapi_map_get_map_property(), generate_random_map(), mapfile_load(), and CREMapInformationManager::process().
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.
m | map to change. |
change | delta of light. |
Definition at line 1994 of file map.cpp.
References ext_info_map(), m, 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(), generate_random_map(), and set_darkness_map().
int check_path | ( | const char * | name, |
int | prepend_dir | ||
) |
This function checks if a file with the given path exists.
name | map path to check. |
prepend_dir | If set, then we call create_pathname (which prepends libdir & mapdir). Otherwise, we assume the name given is fully complete. |
Definition at line 201 of file map.cpp.
References buf, create_pathname(), MAX_BUF, give::name, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, and strlcpy().
Referenced by cfapi_system_check_path(), and check_login().
void clean_object | ( | object * | op | ) |
Remove and free all objects in the inventory of the given object.
op | object to clean. |
Definition at line 1587 of file map.cpp.
References clean_object(), FLAG_IS_LINKED, FOR_INV_FINISH, FOR_INV_PREPARE, object_free_drop_inventory(), object_remove(), give::op, QUERY_FLAG, remove_button_link(), and Ice::tmp.
Referenced by cfapi_object_clean_object(), clean_object(), delete_unique_items(), and free_all_objects().
void clean_tmp_map | ( | mapstruct * | m | ) |
Removse the temporary file used by the map.
m | map, which mustn't be NULL but can have no temporary file set. |
Definition at line 1953 of file map.cpp.
References m, and nlohmann::detail::void().
Referenced by clean_tmp_files(), flush_old_maps(), and ready_map_name().
|
static |
This makes absolute path to the itemfile where unique objects will be saved. Converts '/' to '@'.
s | path of the map for the item. |
buf | buffer that will contain path. Must not be NULL. |
size | buffer's length. |
Definition at line 166 of file map.cpp.
References buf, Settings::localdir, settings, Floor::t, and Settings::uniquedir.
Referenced by load_unique_objects(), map_remove_unique_files(), and save_map().
void create_overlay_pathname | ( | const char * | name, |
char * | buf, | ||
size_t | size | ||
) |
Same as create_pathname(), but for the overlay maps. /
name | path of the overlay map. |
buf | buffer that will contain the full path. |
size | buffer's length. |
Definition at line 125 of file map.cpp.
References buf, Settings::localdir, Settings::mapdir, give::name, and settings.
Referenced by cfapi_map_create_path(), command_overlay_reset(), load_overlay_map(), map_path(), and save_map().
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.
name | path of the map. |
buf | buffer that will contain the full path. |
size | buffer's length. |
Definition at line 104 of file map.cpp.
References buf, Settings::datadir, Settings::mapdir, give::name, and settings.
Referenced by cfapi_map_create_path(), check_path(), CREMapInformationManager::checkItem(), enter_fixed_template_map(), map_path(), CREMapInformationManager::process(), process_map(), CREMapInformationManager::recurseStyleDirectory(), and save_map().
void create_template_pathname | ( | const char * | name, |
char * | buf, | ||
size_t | size | ||
) |
same as create_pathname(), but for the template maps.
name | path of the template map. |
buf | buffer that will contain the full path. |
size | buf's length |
Definition at line 145 of file map.cpp.
References buf, Settings::localdir, give::name, settings, and Settings::templatedir.
Referenced by enter_fixed_template_map(), and enter_random_template_map().
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.
m | pointer to mapstruct, if NULL no action. Will be invalid after this function. |
Definition at line 1696 of file map.cpp.
References first_map, FREE_AND_CLEAR_STR_IF, free_map(), llevError, LOG(), m, MAP_IN_MEMORY, MAP_SAVING, mapstruct::next, and Ice::tmp.
Referenced by cfapi_map_delete_map(), CREMapInformationManager::checkItem(), flush_old_maps(), free_all_maps(), free_style_maps(), init_dynamic(), key_confirm_quit(), mapfile_load_lowlevel(), monsterFight(), CREMapInformationManager::process(), process_map(), ready_map_name(), START_TEST(), swap_map(), and test_stand_in_light().
|
static |
This goes through map 'm' and removes any unique items on the map.
m | map to check. |
Definition at line 1323 of file map.cpp.
References clean_object(), FLAG_IS_FLOOR, FLAG_IS_LINKED, FLAG_UNIQUE, FOR_MAP_FINISH, FOR_MAP_PREPARE, m, MAP_HEIGHT, MAP_WIDTH, object_free_drop_inventory(), object_remove(), give::op, QUERY_FLAG, and remove_button_link().
Referenced by load_unique_objects().
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 268 of file map.cpp.
References dump_map(), first_map, and m.
Referenced by command_dumpallmaps().
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.
m | map to dump. |
Definition at line 245 of file map.cpp.
References llevError, LOG(), m, MAP_ENTER_X, MAP_ENTER_Y, MAP_HEIGHT, and MAP_WIDTH.
Referenced by command_dumpmap(), and dump_all_maps().
|
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.
container | object that contains the inventory. |
Definition at line 534 of file map.cpp.
References add_string(), arch_to_object(), CLEAR_FLAG, FLAG_REMOVED, FOR_INV_FINISH, FOR_INV_PREPARE, free_string(), object::more, archetype::more, give::op, and Ice::tmp.
Referenced by link_multipart_objects().
void free_all_maps | ( | void | ) |
Frees all allocated maps.
Definition at line 1962 of file map.cpp.
References delete_map(), first_map, mapstruct::in_memory, llevDebug, LOG(), MAP_IN_MEMORY, and MAP_SAVING.
Referenced by cleanup().
|
static |
Remove and free all objects in the given map.
m | map to free. |
Definition at line 1603 of file map.cpp.
References clean_object(), FLAG_REMOVED, FREE_OBJ_NO_DESTROY_CALLBACK, GET_MAP_OB, HEAD, llevDebug, llevError, LOG(), m, MAP_HEIGHT, MAP_IN_MEMORY, MAP_WIDTH, object_free(), object_remove(), objects, give::op, and QUERY_FLAG.
Referenced by free_map(), and save_map().
void free_map | ( | mapstruct * | m | ) |
Frees everything allocated by the given mapstructure. Don't free tmpname or the reset group - our caller is left to do that. Mapstructure itself is not freed.
m | map to free. |
Definition at line 1650 of file map.cpp.
References EVENT_MAPUNLOAD, events_execute_global_event(), free_all_objects(), FREE_AND_CLEAR, free_objectlinkpt(), llevError, LOG(), m, and MAP_SWAPPED.
Referenced by delete_map(), CRECombatSimulator::fight(), main(), mapsave_test(), START_TEST(), swap_map(), and teardown().
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.
sizex | |
sizey | map size. |
Definition at line 842 of file map.cpp.
References allocate_map(), get_linked_map(), m, and MAP_SWAPPED.
Referenced by cfapi_map_get_map(), do_map(), do_test(), CRECombatSimulator::fight(), make_map_floor(), monsterFight(), setup(), START_TEST(), and test_stand_in_light().
mapstruct* get_linked_map | ( | void | ) |
Allocates, initialises, and returns a pointer to a mapstruct, linked through first_map.
Definition at line 776 of file map.cpp.
References fatal(), first_map, disinfect::map, MAP_ENTER_X, MAP_ENTER_Y, MAP_HEIGHT, MAP_RESET_TIMEOUT, MAP_SWAPPED, MAP_WIDTH, and OUT_OF_MEMORY.
Referenced by get_empty_map(), mapfile_load_lowlevel(), mapsave_test(), and read_map_log().
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.
oldmap | map for which we want information. |
newmap | if not NULL, will contain the actual map checked if not oldmap. |
x | |
y | coordinates to check |
nx | |
ny | if not NULL, will contain the actual coordinates checked. |
Definition at line 300 of file map.cpp.
References MapSpace::flags, get_map_from_coord(), P_NEW_MAP, P_OUT_OF_MAP, mapstruct::spaces, mapstruct::width, diamondslots::x, and diamondslots::y.
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(), eventListener(), 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(), legacy_monster_stand_in_light(), magic_mapping_mark(), magic_mapping_mark_recursive(), magic_wall(), monster_communicate(), monster_find_nearest_enemy(), monster_npc_call_help(), mood_change(), move_aura(), move_ball_spell(), move_bolt(), move_bullet(), 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().
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
m | map we want to look at. Must not be NULL. |
x | |
y | coordinates, which will contain the real position that was checked. |
Definition at line 2370 of file map.cpp.
References load_and_link_tiled_map(), m, MAP_HEIGHT, MAP_IN_MEMORY, MAP_WIDTH, OUT_OF_REAL_MAP, diamondslots::x, and diamondslots::y.
Referenced by cfapi_map_get_map(), draw_client_map2(), get_map_flags(), look_at(), monster_stand_in_light_internal(), monster_use_bow(), move_player_attack(), object_insert_in_map(), object_remove(), and pets_move().
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.
op1 | object which wants to go to op2's location. |
op2 | target of op1. |
retval | vector for op1 to go to op2. |
flags | if 1, don't translate for closest body part of 'op1' |
Definition at line 2541 of file map.cpp.
References adjacent_map(), rv_vector::direction, rv_vector::distance, rv_vector::distance_x, rv_vector::distance_y, find_dir_2(), flags, ihypot(), object::map, object::more, rv_vector::part, Ice::tmp, object::x, and object::y.
Referenced by command_follow(), do_follow(), 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(), move_towards(), path_to_player(), pets_get_enemy(), pets_move(), player_can_view(), and spring_trap().
int get_rangevector_from_mapcoord | ( | const mapstruct * | m, |
int | x, | ||
int | y, | ||
const object * | op2, | ||
rv_vector * | retval | ||
) |
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. Since no object is pasted, the best field of the rv_vector is set to NULL.
m | map to consider. |
x | |
y | origin coordinates. |
op2 | target object. |
retval | vector to get to op2. |
Definition at line 2609 of file map.cpp.
References adjacent_map(), rv_vector::direction, rv_vector::distance, rv_vector::distance_x, rv_vector::distance_y, find_dir_2(), isqrt(), m, object::map, rv_vector::part, diamondslots::x, object::x, diamondslots::y, and object::y.
Referenced by path_to_player().
mapstruct* has_been_loaded | ( | const char * | name | ) |
Checks whether map has been loaded.
name | path of the map to search. Can be NULL. |
Definition at line 79 of file map.cpp.
References first_map, disinfect::map, and give::name.
Referenced by add_npc_to_random_map(), cfapi_map_has_been_loaded(), check_login(), command_reset(), command_swap(), is_legal_2ways_exit(), monsterFight(), and ready_map_name().
|
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.
m | map to check. |
Definition at line 575 of file map.cpp.
References fix_container_multipart(), FOR_MAP_FINISH, FOR_MAP_PREPARE, m, MAP_HEIGHT, MAP_WIDTH, object_fix_multipart(), Ice::tmp, diamondslots::x, and diamondslots::y.
Referenced by load_objects().
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.
orig_map | map for which we load the tiled map. |
tile_num | tile to load. Must be between 0 and 3 inclusive. |
Definition at line 2258 of file map.cpp.
References HUGE_BUF, llevError, LOG(), python_init::path, mapstruct::path, path_combine_and_normalize(), ready_map_name(), mapstruct::tile_map, and mapstruct::tile_path.
Referenced by get_map_from_coord(), and out_of_map().
|
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.
fp | file to read from. |
m | map being read. |
Definition at line 988 of file map.cpp.
References add_string(), buf, get_region_by_name(), HUGE_BUF, castle_read::key, llevError, LOG(), m, msgbuf, parse_shop_string(), strdup_local, create-tower::tile, and autojail::value.
Referenced by load_overlay_map(), load_temporary_map(), and mapfile_load_lowlevel().
void load_objects | ( | mapstruct * | m, |
FILE * | fp, | ||
int | mapflags | ||
) |
Loads (and parses) the objects into a given map from the specified file pointer.
m | m being loaded. |
fp | file to read from. |
mapflags | the same as we get with mapfile_load() |
Definition at line 603 of file map.cpp.
References FLAG_IS_FLOOR, FLAG_OBJ_ORIGINAL, FLAG_OVERLAY_FLOOR, FLAG_UNIQUE, FOR_MAP_FINISH, FOR_MAP_PREPARE, INS_ABOVE_FLOOR_ONLY, INS_MAP_LOAD, INS_NO_MERGE, INS_NO_WALK_ON, INS_ON_TOP, link_multipart_objects(), LL_MORE, LL_NORMAL, llevDebug, llevError, LO_NEWFILE, LO_REPEAT, load_object(), LOG(), m, MAP_HEIGHT, MAP_OVERLAY, MAP_PLAYER_UNIQUE, MAP_STYLE, MAP_WIDTH, object::more, object_free_drop_inventory(), object_insert_in_map_at(), object_new(), object_remove_from_active_list(), object_sum_weight(), give::op, PLAYER, PROFILE_BEGIN, PROFILE_END, QUERY_FLAG, and SET_FLAG.
Referenced by load_overlay_map(), load_temporary_map(), load_unique_objects(), mapfile_load_lowlevel(), and mapsave_test().
|
static |
Loads an overlay for a map, which has been loaded earlier, from file.
filename | filename for overlay. |
m | map we want to load. |
Definition at line 1288 of file map.cpp.
References create_overlay_pathname(), npc_dialog::filename, llevError, load_map_header(), load_objects(), LOG(), m, MAP_IN_MEMORY, MAP_LOADING, MAP_OVERLAY, and MAX_BUF.
Referenced by ready_map_name().
|
static |
Loads a map, which has been loaded earlier, from file.
m | map we want to reload. |
Definition at line 1252 of file map.cpp.
References allocate_map(), llevError, load_map_header(), load_objects(), LOG(), m, MAP_IN_MEMORY, and MAP_LOADING.
Referenced by ready_map_name().
|
static |
Loads unique objects from file(s) into the map which is in memory
m | map to load unique items into. |
Definition at line 1348 of file map.cpp.
References disinfect::count, create_items_path(), delete_unique_items(), llevDebug, LO_NOREAD, load_object(), load_objects(), LOG(), m, MAP_IN_MEMORY, MAP_LOADING, MAX_BUF, and give::name.
Referenced by ready_map_name().
Finds an object in a map tile by flag number. Checks the objects' heads.
map | the map to search. |
x | the x-coordiate to search. |
y | the y-coordiate to search. |
flag | the flag to seacrh for |
Definition at line 2670 of file map.cpp.
References GET_MAP_OB, HEAD, disinfect::map, QUERY_FLAG, Ice::tmp, diamondslots::x, and diamondslots::y.
Referenced by cast_light(), common_process_projectile(), do_monster_change(), do_mood_floor(), get_pointed_target(), and mood_change().
const char* map_get_path | ( | const object * | item | ) |
Return the map path on which the specified item is.
item | what to return the map path for. |
Definition at line 2712 of file map.cpp.
References map_get_path().
Referenced by gate_type_process(), and map_get_path().
void map_path | ( | const char * | map, |
int | flags, | ||
char * | pathname, | ||
size_t | bufsize | ||
) |
test_mapsave.cpp – save stability test
This file creates a program that loads and saves a map given by the in-game PATH (e.g. /world/world_105_115). If everything is working, load/save should not change the file.
Due to the lack of correct linked list reversing, we load/save twice to get the same order of objects again.
For normal (e.g. world) maps, load/save saves to a temporary file, so we can avoid modifying the original file and diff between the original and saved temporary file.
For unique (e.g. apartment) maps, this test SAVES OVER THE ORIGINAL FILE. So you should make a copy of the original file so you can diff the result.
Definition at line 1165 of file map.cpp.
References create_overlay_pathname(), create_pathname(), flags, Settings::localdir, disinfect::map, MAP_OVERLAY, MAP_PLAYER_UNIQUE, Settings::playerdir, and settings.
Referenced by main(), map_info(), and mapfile_load().
bool map_path_unique | ( | const char * | path | ) |
Return true if the given map path leads to a unique map. This is needed to correctly load a map with the MAP_UNIQUE flag set, because there are some contexts in which only a map path is available.
Definition at line 2732 of file map.cpp.
References python_init::path.
Referenced by cast_create_town_portal(), enter_exit(), and town_portal_destroy_existing().
void map_remove_unique_files | ( | const mapstruct * | map | ) |
Remove files containing the map's unique items.
map |
Definition at line 2687 of file map.cpp.
References disinfect::count, create_items_path(), HUGE_BUF, llevError, Settings::localdir, LOG(), disinfect::map, python_init::path, Settings::playerdir, and settings.
Referenced by command_reset().
void map_reset_swap | ( | mapstruct * | m | ) |
Call this when an in-memory map is used or referenced. Helps inform which maps to swap.
Definition at line 1750 of file map.cpp.
References m, and MAP_MINTIMEOUT.
Referenced by draw_client_map(), and ready_map_name().
uint32_t map_size | ( | mapstruct * | m | ) |
Calculate map size without intermediate sign extension.
Definition at line 798 of file map.cpp.
References m.
Referenced by allocate_map(), command_style_map_info(), and malloc_info().
Definition at line 2736 of file map.cpp.
References m, OUT_OF_REAL_MAP, diamondslots::x, and diamondslots::y.
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
map | Map path |
flags | Additional options for loading the map:
|
Definition at line 1216 of file map.cpp.
References apply_auto_fix(), calculate_difficulty(), EVENT_MAPLOAD, events_execute_global_event(), flags, llevDebug, LOG(), m, disinfect::map, MAP_DIFFICULTY, MAP_NO_DIFFICULTY, map_path(), MAP_STYLE, mapfile_load_lowlevel(), maps_loaded_total, MAX_BUF, PROFILE_BEGIN, PROFILE_END, set_map_reset_time(), and update_buttons().
Referenced by enter_fixed_template_map(), enter_unique_map(), load_style_map(), main(), mapsave_test(), CREMapInformationManager::process(), and ready_map_name().
mapstruct* mapfile_load_lowlevel | ( | const char * | map, |
const char * | pathname, | ||
int | flags | ||
) |
Definition at line 1175 of file map.cpp.
References allocate_map(), delete_map(), flags, get_linked_map(), HUGE_BUF, llevDebug, llevError, load_map_header(), load_objects(), LOG(), m, disinfect::map, MAP_IN_MEMORY, MAP_LOADING, MAP_PLAYER_UNIQUE, MAP_STYLE, and safe_strncpy.
Referenced by main(), and mapfile_load().
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 separate 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.
ob | object to test. |
m | |
x | |
y | map and coordinates to check. |
Definition at line 479 of file map.cpp.
References AB_NO_PASS, get_map_flags(), GET_MAP_MOVE_BLOCK, m, object::more, MOVE_ALL, object::move_type, guildjoin::ob, OB_TYPE_MOVE_BLOCK, P_IS_ALIVE, P_OUT_OF_MAP, Ice::tmp, TRANSPORT, diamondslots::x, and diamondslots::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().
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
op1 | first object. |
op2 | second object. |
Definition at line 2647 of file map.cpp.
References adjacent_map(), and object::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_attempt_follow(), pets_get_enemy(), pets_move(), and share_exp().
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.
m | map to consider. Must not be NULL. |
x | |
y | coordinates. |
Definition at line 2297 of file map.cpp.
References load_and_link_tiled_map(), m, MAP_HEIGHT, MAP_IN_MEMORY, MAP_WIDTH, out_of_map(), diamondslots::x, and diamondslots::y.
Referenced by animate_bomb(), cfapi_map_out_of_map(), command_create(), enter_map(), esrv_draw_look(), explode_bullet(), look_at(), move_player_attack(), move_teleporter(), object_insert_in_map(), object_teleport(), and out_of_map().
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.
input_string | shop item line. |
map | map for which to parse the string, in case of warning. |
Definition at line 864 of file map.cpp.
References CALLOC, fatal(), get_typedata(), get_typedata_by_name(), shopitems::index, llevDebug, llevError, LOG(), disinfect::map, typedata::name, shopitems::name, typedata::name_pl, shopitems::name_pl, typedata::number, OUT_OF_MEMORY, item::q, strdup_local, shopitems::strength, strip_endline(), and shopitems::typenum.
Referenced by load_map_header().
|
static |
Opposite of parse string(), this puts the string that was originally fed in to the map (or something equivilent) into output_string.
m | map we're considering. |
output_string | string to write to. |
size | output_string's length. |
Definition at line 946 of file map.cpp.
References m, MAX_BUF, and Ice::tmp.
Referenced by save_map().
mapstruct* ready_map_name | ( | const char * | name, |
int | flags | ||
) |
Makes sure the given map is loaded and swapped in.
name | path name of the map. |
flags |
|
Definition at line 1768 of file map.cpp.
References buf, clean_tmp_map(), decay_objects(), delete_map(), EVENT_MAPREADY, events_execute_global_event(), flags, has_been_loaded(), load_overlay_map(), load_temporary_map(), load_unique_objects(), Settings::localdir, m, MAP_FLUSH, MAP_IN_MEMORY, MAP_LOADING, MAP_OVERLAY, MAP_PLAYER_UNIQUE, map_reset_swap(), mapfile_load(), MAX_BUF, give::name, Settings::playerdir, seconds(), set_darkness_map(), and settings.
Referenced by cast_create_town_portal(), cfapi_map_get_map(), CREMapInformationManager::checkItem(), 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(), process_map(), START_TEST(), and town_portal_destroy_existing().
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)
m | map to save. |
flag | One of SAVE_MODE_xxx values. |
Definition at line 1395 of file map.cpp.
References create_items_path(), create_overlay_pathname(), create_pathname(), npc_dialog::filename, FMT64U, free_all_objects(), llevDebug, llevError, Settings::localdir, LOG(), m, make_path_to_file(), MAP_IN_MEMORY, MAP_SAVING, maps_saved_total, MAX_BUF, give::name, of_cancel(), of_close(), of_open(), Settings::playerdir, print_shop_string(), PROFILE_BEGIN, PROFILE_END, altar_valkyrie::res, SAVE_ERROR_CLOSE, SAVE_ERROR_NO_PATH, SAVE_ERROR_OK, SAVE_ERROR_RCREATION, SAVE_ERROR_UCREATION, SAVE_ERROR_URENAME, SAVE_FLAG_NO_REMOVE, SAVE_MODE, SAVE_MODE_NORMAL, SAVE_MODE_OVERLAY, save_objects(), settings, strlcpy(), and Settings::tmpdir.
Referenced by clean_tmp_files(), command_overlay_save(), generate_map(), main(), START_TEST(), and swap_map().
int save_objects | ( | mapstruct * | m, |
FILE * | fp, | ||
FILE * | fp2, | ||
int | flag | ||
) |
This saves all the objects on the map in a non destructive fashion. We only save the head of multi part objects - this is needed in order to do map tiling properly.
m | map to save. |
fp | file where regular objects are saved. |
fp2 | file to save unique objects. |
flag | combination of SAVE_FLAG_xxx flags. |
Definition at line 715 of file map.cpp.
References disinfect::count, FLAG_IS_FLOOR, FLAG_OBJ_ORIGINAL, FLAG_UNIQUE, FLAG_UNPAID, FOR_MAP_FINISH, FOR_MAP_PREPARE, llevDebug, LOG(), m, MAP_HEIGHT, MAP_WIDTH, object_get_owner(), give::op, PLAYER, PROFILE_BEGIN, PROFILE_END, QUERY_FLAG, SAVE_FLAG_NO_REMOVE, SAVE_FLAG_SAVE_UNPAID, save_object_in_sb(), stringbuffer_finish(), and stringbuffer_new().
Referenced by mapsave_test(), and save_map().
void set_map_reset_time | ( | mapstruct * | map | ) |
Updates the map's timeout.
map | map to update. |
Definition at line 2232 of file map.cpp.
References disinfect::map, MAP_DEFAULTRESET, MAP_MAXRESET, MAP_RESET_TIMEOUT, MAP_WHEN_RESET, and seconds().
Referenced by map_info(), mapfile_load(), and swap_map().
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)
m | map considered |
x | |
y | coordinates to update |
Definition at line 2118 of file map.cpp.
References add_face_layer(), blank_face, blocks_prayer, FLAG_ALIVE, FLAG_BLOCKSVIEW, FLAG_DAMNED, FLAG_IS_FLOOR, FLAG_MONSTER, FLAG_NO_MAGIC, FLAG_NO_PICK, FLAG_WIZ, flags, FOR_MAP_FINISH, FOR_MAP_PREPARE, GET_MAP_FACE_OBJS, GET_MAP_FLAGS, Map_Layer_Info::high_layer, Map_Layer_Info::honor_visibility, llevDebug, llevError, LOG(), m, MAP_LAYER_FLOOR, MAP_LAYER_FLY1, MAP_LAYER_FLY2, map_layer_info, MAP_LAYER_ITEM1, MAP_LAYER_ITEM3, MAP_LAYER_LIVING1, MAP_LAYER_LIVING2, MAP_LAYER_NO_PICK1, MAP_LAYER_NO_PICK2, MAP_LAYERS, MOVE_FLYING, object_value_set_shared(), P_BLOCKSVIEW, P_IS_ALIVE, P_NEED_UPDATE, P_NO_CLERIC, P_NO_ERROR, P_NO_MAGIC, P_PLAYER, PLAYER, QUERY_FLAG, SET_MAP_FLAGS, SET_MAP_LIGHT, SET_MAP_MOVE_BLOCK, SET_MAP_MOVE_OFF, SET_MAP_MOVE_ON, SET_MAP_MOVE_SLOW, SET_MAP_PLAYER, Ice::tmp, diamondslots::x, and diamondslots::y.
Referenced by cfapi_map_update_position(), cfapi_object_set_property(), do_turn(), draw_client_map(), object_insert_in_ob(), object_remove(), and object_update().
|
static |
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.cpp.
Referenced by update_position().
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.
Definition at line 46 of file map.cpp.
Referenced by get_ob_diff(), and while().