55 "floor",
"no_pick",
"no_pick",
"item",
"item",
56 "item",
"living",
"living",
"fly",
"fly"
94 if (!strcmp(name, map->
path))
227 snprintf(buf,
sizeof(buf),
"%s", name);
229 return(_access(buf, 0));
237 endbuf = buf+strlen(buf);
244 if (!stat(buf, &statbuf))
247 if (i == NROF_COMPRESS_METHODS)
252 if (((statbuf.st_mode&
S_IRGRP) && getegid() == statbuf.st_gid)
253 || ((statbuf.st_mode&
S_IRUSR) && geteuid() == statbuf.st_uid)
257 if ((statbuf.st_mode&
S_IWGRP && getegid() == statbuf.st_gid)
258 || (statbuf.st_mode&
S_IWUSR && geteuid() == statbuf.st_uid)
374 object *tmp, *tmp_head;
381 LOG(
llevError,
"blocked_link: Passed map, x, y coordinates outside of map\n");
413 if (ob->
head != NULL)
424 tmp_head = tmp->
head;
427 if (tmp_head == ob) {
541 for (tmp = ob->
arch, part = ob; tmp != NULL; tmp = tmp->
more, part = part->
more) {
581 object *tmp = container->
inv, *next;
583 container->
inv = NULL;
584 while (tmp != NULL) {
608 object *tmp = container->
inv, *next;
610 while (tmp != NULL) {
618 for (at = tmp->
arch->
more, last = tmp; at != NULL; at = at->
more, last = op) {
658 for (tmp =
GET_MAP_OB(m, x, y); tmp != NULL; tmp = above) {
685 object *op, *prev = NULL, *last_more = NULL, *otmp;
690 while ((i =
load_object(fp, op, bufstate, mapflags))) {
701 if (op->
arch == NULL) {
725 last_more->
more = op,
735 for (i = 0; i < m->
width; i++) {
736 for (j = 0; j < m->
height; j++) {
739 for (otmp =
GET_MAP_OB(m, i, j); otmp; otmp = otmp->above) {
769 int i, j = 0, unique = 0, res;
776 for (op =
GET_MAP_OB(m, i, j); op; op = otmp) {
861 LOG(
llevError,
"allocate_map called with already allocated map (%s)\n", m->
path);
905 char *shop_string, *p, *q, *next_semicolon, *next_colon;
907 int i = 0, number_of_entries = 0;
923 memset(items, 0, (
sizeof(
shopitems)*number_of_entries+1));
924 for (i = 0; i < number_of_entries; i++) {
926 LOG(
llevError,
"parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
929 next_semicolon = strchr(p,
';');
930 next_colon = strchr(p,
':');
932 if (next_colon &&(!next_semicolon || next_colon < next_semicolon))
933 items[i].
strength = atoi(strchr(p,
':')+1);
935 if (isdigit(*p) || *p ==
'*') {
943 q = strpbrk(p,
";:");
955 LOG(
llevError,
"invalid type %s defined in shopitems in string %s\n", p, input_string);
958 items[i].
index = number_of_entries;
960 p = ++next_semicolon;
983 output_string[0] =
'\0';
996 snprintf(output_string+strlen(output_string), size-strlen(output_string),
"%s", tmp);
1020 char buf[
HUGE_BUF], *key = NULL, *value;
1023 while (fgets(buf,
sizeof(buf), fp) != NULL) {
1026 p = strchr(buf,
'\n');
1028 LOG(
llevError,
"Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", buf);
1034 while (isspace(*key))
1038 value = strchr(key,
' ');
1042 while (isspace(*value)) {
1044 if (*value ==
'\0') {
1067 if (!strcmp(key,
"msg")) {
1071 while (fgets(buf,
sizeof(buf), fp) != NULL) {
1072 if (!strcmp(buf,
"endmsg\n"))
1075 snprintf(msgbuf+msgpos,
sizeof(msgbuf)-msgpos,
"%s", buf);
1076 msgpos += strlen(buf);
1089 }
else if (!strcmp(key,
"maplore")) {
1093 while (fgets(buf,
HUGE_BUF-1, fp) != NULL) {
1094 if (!strcmp(buf,
"endmaplore\n"))
1097 snprintf(maplorebuf+maplorepos,
sizeof(maplorebuf)-maplorepos,
"%s", buf);
1098 maplorepos += strlen(buf);
1101 if (maplorepos != 0)
1103 }
else if (!strcmp(key,
"end")) {
1105 }
else if (value == NULL) {
1106 LOG(
llevError,
"Got '%s' line without parameter in map header\n", key);
1107 }
else if (!strcmp(key,
"arch")) {
1109 if (strcmp(value,
"map"))
1110 LOG(
llevError,
"loading map and got a non 'arch map' line(%s %s)?\n", key, value);
1111 }
else if (!strcmp(key,
"name")) {
1119 }
else if (!strcmp(key,
"hp") || !strcmp(key,
"enter_x")) {
1121 }
else if (!strcmp(key,
"sp") || !strcmp(key,
"enter_y")) {
1123 }
else if (!strcmp(key,
"x") || !strcmp(key,
"width")) {
1124 m->
width = atoi(value);
1125 }
else if (!strcmp(key,
"y") || !strcmp(key,
"height")) {
1127 }
else if (!strcmp(key,
"weight") || !strcmp(key,
"reset_timeout")) {
1129 }
else if (!strcmp(key,
"value") || !strcmp(key,
"swap_time")) {
1131 }
else if (!strcmp(key,
"level") || !strcmp(key,
"difficulty")) {
1133 }
else if (!strcmp(key,
"invisible") || !strcmp(key,
"darkness")) {
1135 }
else if (!strcmp(key,
"stand_still") || !strcmp(key,
"fixed_resettime")) {
1137 }
else if (!strcmp(key,
"unique")) {
1139 }
else if (!strcmp(key,
"template")) {
1141 }
else if (!strcmp(key,
"region")) {
1143 }
else if (!strcmp(key,
"shopitems")) {
1145 }
else if (!strcmp(key,
"shopgreed")) {
1147 }
else if (!strcmp(key,
"shopmin")) {
1149 }
else if (!strcmp(key,
"shopmax")) {
1151 }
else if (!strcmp(key,
"shoprace")) {
1153 }
else if (!strcmp(key,
"outdoor")) {
1155 }
else if (!strcmp(key,
"nosmooth")) {
1157 }
else if (!strcmp(key,
"first_load")) {
1159 }
else if (!strncmp(key,
"tile_path_", 10)) {
1160 int tile = atoi(key+10);
1162 if (tile < 1 || tile > 4) {
1163 LOG(
llevError,
"load_map_header: tile location %d out of bounds (%s)\n", tile, m->
path);
1168 LOG(
llevError,
"load_map_header: tile location %d duplicated (%s)\n", tile, m->
path);
1175 snprintf(path,
sizeof(path),
"%s", value);
1186 if (*path !=
'\0') {
1191 }
else if (!strcmp(key,
"background_music")) {
1194 LOG(
llevError,
"Got unknown value in map header: %s %s\n", key, value);
1201 if (!key || strcmp(key,
"end")) {
1232 LOG(
llevDebug,
"load_original_map: %s (%x)\n", filename, flags);
1234 snprintf(pathname,
sizeof(pathname),
"%s", filename);
1249 strcpy(m->
path, filename);
1251 LOG(
llevError,
"Error loading map header for %s, flags=%d\n", filename, flags);
1354 LOG(
llevError,
"Error loading map header for overlay %s (%s)\n", m->
path, pathname);
1380 int i, j, unique = 0;
1386 for (op =
GET_MAP_OB(m, i, j); op; op = next) {
1412 for (count = 0; count < 10; count++) {
1413 snprintf(firstname,
sizeof(firstname),
"%s.v%02d", name, count);
1414 if (!access(firstname,
R_OK))
1425 LOG(
llevDebug,
"Can't open unique items file for %s\n", name);
1454 #define TEMP_EXT ".savefile"
1459 if (flag && !*m->
path) {
1493 snprintf(
final,
sizeof(
final),
"%s", filename);
1494 fp =
popen(buf,
"w");
1496 snprintf(
final,
sizeof(
final),
"%s", filename);
1498 fp = fopen(filename,
"w");
1507 fprintf(fp,
"arch map\n");
1508 if (m->
name) fprintf(fp,
"name %s\n", m->
name);
1509 if (!flag) fprintf(fp,
"swap_time %d\n", m->
swap_time);
1519 fprintf(fp,
"shopitems %s\n", shop);
1526 if (m->
width) fprintf(fp,
"width %d\n", m->
width);
1530 if (m->
msg) fprintf(fp,
"msg\n%sendmsg\n", m->
msg);
1531 if (m->
maplore) fprintf(fp,
"maplore\n%sendmaplore\n", m->
maplore);
1541 for (i = 0; i < 4; i++)
1543 fprintf(fp,
"tile_path_%d %s\n", i+1, m->
tile_path[i]);
1545 fprintf(fp,
"end\n");
1557 snprintf(final_unique,
sizeof(final_unique),
"%s.v00", name);
1559 if ((fp2 = fopen(buf,
"w")) == NULL) {
1560 LOG(
llevError,
"Can't open unique items file %s\n", buf);
1567 LOG(
llevError,
"Save error during object save: %d\n", res);
1574 LOG(
llevError,
"Save error during object save: %d\n", res);
1580 if (ftell(fp2) == 0) {
1592 if (rename(buf, final_unique) == -1) {
1593 LOG(
llevError,
"Couldn't rename unique file %s to %s\n", buf, final_unique);
1602 LOG(
llevError,
"Save error during object save: %d\n", res);
1616 if (fclose(fp) != 0) {
1622 if (rename(filename,
final) == -1) {
1623 LOG(
llevError,
"Couldn't rename regular file %s to %s\n", filename,
final);
1643 for (tmp = op->
inv; tmp; tmp = next) {
1665 object *previous_obj = NULL;
1668 if (op == previous_obj) {
1669 LOG(
llevDebug,
"free_all_objects: Link error, bailing out.\n");
1673 if (op->
head != NULL)
1692 LOG(
llevDebug,
"free_all_objects: object %s still on map after it should have been freed\n", op->
name);
1728 for (i = 0; i < 4; i++) {
1776 for (i = 0; i < 4; i++)
1857 if (!(flags&(
MAP_FLUSH|MAP_PLAYER_UNIQUE)))
1923 sint64 exp_pr_sq, total_exp = 0;
1944 for (i = 1; i < 20; i++)
1980 LOG(
llevDebug,
"free_all_maps: Freed %d maps\n", real_maps);
2001 int new_level = m->
darkness+change;
2005 || (new_level <= 0 && m->darkness == 0)
2055 static inline void add_face_layer(
int low_layer,
int high_layer,
object *ob,
object *layers[],
int honor_visibility) {
2059 for (l = low_layer; l <= high_layer; l++) {
2065 if (!honor_visibility)
2072 for (l1 = (l-1); l1 >= low_layer; l1--) {
2073 if (layers[l1]->face->visibility > layers[l1+1]->
face->
visibility) {
2075 layers[l1+1] = layers[l1];
2085 if (!honor_visibility) {
2089 for (l = low_layer; l < high_layer; l++)
2090 layers[l] = layers[l+1];
2091 layers[high_layer] = ob;
2101 for (l = high_layer; l >= low_layer; l--) {
2103 for (l1 = low_layer; l1 < l; l1++)
2104 layers[l1] = layers[l1+1];
2125 object *tmp, *
player = NULL;
2129 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
2133 LOG(
llevDebug,
"update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->
path, x, y);
2137 memset(layers, 0,
MAP_LAYERS*
sizeof(
object *));
2171 memset(layers+1, 0, (
MAP_LAYERS-1)*
sizeof(
object *));
2182 if (tmp == tmp->
above) {
2211 if (((oldflags&~(P_NEED_UPDATE|
P_NO_ERROR)) != flags)
2213 LOG(
llevDebug,
"update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n",
2214 m->
path, x, y, (oldflags&~P_NEED_UPDATE), flags);
2268 int dest_tile = (tile_num+2)%4;
2280 return orig_map->
tile_map[tile_num];
2434 }
else if (map1->
tile_map[0] == map2) {
2437 }
else if (map1->
tile_map[1] == map2) {
2440 }
else if (map1->
tile_map[2] == map2) {
2443 }
else if (map1->
tile_map[3] == map2) {
2511 retval->
part = NULL;
2520 if (!(flags&0x1) && op1->
more) {
2531 for (tmp = op1->
more; tmp != NULL; tmp = tmp->
more) {
2534 if (tmpi < best_distance) {
2535 best_distance = tmpi;
2544 retval->
part = best;
2580 retval->
part = NULL;
2585 retval->
part = NULL;
2631 for (count = 0; count < 10; count++) {
2632 snprintf(path,
sizeof(path),
"%s.v%02d", base, count);
int find_dir_2(int x, int y)
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny)
static void allocate_map(mapstruct *m)
mapstruct * get_linked_map(void)
static mapstruct * load_and_link_tiled_map(mapstruct *orig_map, int tile_num)
char * tempnam_local(const char *dir, const char *pfx)
mapstruct * get_empty_map(int sizex, int sizey)
region * get_region_by_name(const char *region_name)
void make_path_to_file(const char *filename)
static int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag)
int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info)
struct mapdef * tile_map[4]
void remove_from_active_list(object *op)
char * create_pathname(const char *name, char *buf, size_t size)
mapstruct * ready_map_name(const char *name, int flags)
static mapstruct * load_overlay_map(const char *filename, mapstruct *m)
void free_string(sstring str)
#define SET_MAP_LIGHT(M, X, Y, L)
int calculate_difficulty(mapstruct *m)
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
sint64 level_exp(int level, double expmul)
struct Map_Layer_Info Map_Layer_Info
static mapstruct * load_temporary_map(mapstruct *m)
void decay_objects(mapstruct *m)
static shopitems * parse_shop_string(const char *input_string)
void close_and_delete(FILE *fp, int compressed)
mapstruct * load_original_map(const char *filename, int flags)
#define OUT_OF_REAL_MAP(M, X, Y)
signed long sum_weight(object *op)
const typedata * get_typedata_by_name(const char *name)
void strip_endline(char *buf)
void free_map(mapstruct *m)
void free_objectlinkpt(oblinkpt *obp)
int change_map_light(mapstruct *m, int change)
#define MAP_WHEN_RESET(m)
#define MAP_LAYER_LIVING2
const typedata * get_typedata(int itemtype)
#define SAVE_FLAG_SAVE_UNPAID
void fix_multipart_object(object *tmp)
#define MAP_LAYER_NO_PICK1
static int load_map_header(FILE *fp, mapstruct *m)
void remove_ob(object *op)
void get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval, int flags)
void fix_auto_apply(mapstruct *m)
#define FLAG_OBJ_ORIGINAL
int blocked_link(object *ob, mapstruct *m, int sx, int sy)
#define SET_MAP_MOVE_SLOW(M, X, Y, C)
void get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags)
static void link_multipart_objects(mapstruct *m)
char * path_combine_and_normalize(const char *src, const char *dst, char *path, size_t size)
void update_position(mapstruct *m, int x, int y)
#define SET_MAP_PLAYER(M, X, Y, C)
struct timeval last_reset_time
int execute_global_event(int eventcode,...)
#define OB_TYPE_MOVE_BLOCK(ob1, type)
#define FLAG_OVERLAY_FLOOR
#define SAVE_ERROR_NO_PATH
mapstruct * get_map_from_coord(mapstruct *m, sint16 *x, sint16 *y)
#define GET_MAP_MOVE_BLOCK(M, X, Y)
#define MAP_DIFFICULTY(m)
#define NROF_COMPRESS_METHODS
#define SAVE_ERROR_URENAME
static void delete_unique_items(mapstruct *m)
#define SET_MAP_MOVE_OFF(M, X, Y, C)
const char * map_layer_name[MAP_LAYERS]
int on_same_map(const object *op1, const object *op2)
#define QUERY_FLAG(xyz, p)
#define CLEAR_FLAG(xyz, p)
char * strdup_local(const char *str)
static Map_Layer_Info map_layer_info[MAP_LAYERS]
#define INS_ABOVE_FLOOR_ONLY
object * insert_ob_in_ob(object *op, object *where)
void dump_map(const mapstruct *m)
object * get_object(void)
#define GENERATE_TYPE(xyz)
int save_object(FILE *fp, object *op, int flag)
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
static const flag_definition flags[]
#define MAP_LAYER_NO_PICK2
static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy)
#define SAVE_FLAG_NO_REMOVE
int save_map(mapstruct *m, int flag)
#define SAVE_ERROR_UCREATION
#define GET_MAP_FLAGS(M, X, Y)
int snprintf(char *dest, int max, const char *format,...)
const char * uncomp[NROF_COMPRESS_METHODS][3]
static void free_all_objects(mapstruct *m)
#define SET_MAP_MOVE_ON(M, X, Y, C)
void set_map_reset_time(mapstruct *map)
#define SET_MAP_FLAGS(M, X, Y, C)
#define MAP_LAYER_LIVING1
static void load_unique_objects(mapstruct *m)
void update_all_map_los(mapstruct *map)
#define MAP_PLAYER_UNIQUE
archetype * get_archetype_by_type_subtype(int type, int subtype)
int load_object(FILE *fp, object *op, int bufstate, int map_flags)
mapstruct * has_been_loaded(const char *name)
static void print_shop_string(mapstruct *m, char *output_string, int size)
static void load_objects(mapstruct *m, FILE *fp, int mapflags)
void fix_container(object *container)
int out_of_map(mapstruct *m, int x, int y)
void delete_map(mapstruct *m)
#define MAP_RESET_TIMEOUT(m)
#define GET_MAP_FACE_OBJS(M, X, Y)
static void create_items_path(const char *s, char *buf, size_t size)
sstring add_string(const char *str)
#define GET_MAP_OB(M, X, Y)
int check_path(const char *name, int prepend_dir)
static void fix_container_multipart(object *container)
#define OB_MOVE_BLOCK(ob1, ob2)
#define SAVE_ERROR_RRENAME
void LOG(LogLevel logLevel, const char *format,...)
#define SAVE_ERROR_RCREATION
struct shopitem * shopitems
#define MSG_TYPE_ATTACK_NOKEY
void set_darkness_map(mapstruct *m)
void free_object(object *ob)
void create_overlay_pathname(const char *name, char *buf, size_t size)
char * strerror_local(int errnum, char *buf, size_t size)
#define FREE_AND_CLEAR(xyz)
#define SET_MAP_MOVE_BLOCK(M, X, Y, C)
void create_template_pathname(const char *name, char *buf, size_t size)
void map_remove_unique_files(const mapstruct *map)
struct regiondef * region
void clean_tmp_map(mapstruct *m)
EXTERN mapstruct * first_map
object * arch_to_object(archetype *at)
FILE * open_and_uncompress(const char *name, int flag, int *compressed)
void clean_object(object *op)
void ext_info_map(int color, const mapstruct *map, uint8 type, uint8 subtype, const char *str1, const char *str2)
#define SAVE_MODE_OVERLAY
static void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility)
int ob_blocked(const object *ob, mapstruct *m, sint16 x, sint16 y)