… | |
… | |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <funcpoint.h> |
26 | #include <funcpoint.h> |
27 | |
27 | |
28 | #include <loader.h> |
28 | #include <loader.h> |
29 | #ifndef WIN32 /* ---win32 exclude header */ |
|
|
30 | # include <unistd.h> |
29 | #include <unistd.h> |
31 | #endif /* win32 */ |
|
|
32 | |
30 | |
33 | #include "path.h" |
31 | #include "path.h" |
34 | |
|
|
35 | |
32 | |
36 | /* |
33 | /* |
37 | * Returns the maptile which has a name matching the given argument. |
34 | * Returns the maptile which has a name matching the given argument. |
38 | * return NULL if no match is found. |
35 | * return NULL if no match is found. |
39 | */ |
36 | */ |
… | |
… | |
157 | int |
154 | int |
158 | check_path (const char *name, int prepend_dir) |
155 | check_path (const char *name, int prepend_dir) |
159 | { |
156 | { |
160 | char buf[MAX_BUF]; |
157 | char buf[MAX_BUF]; |
161 | |
158 | |
162 | #ifndef WIN32 |
|
|
163 | char *endbuf; |
159 | char *endbuf; |
164 | struct stat statbuf; |
160 | struct stat statbuf; |
165 | int mode = 0; |
161 | int mode = 0; |
166 | #endif |
|
|
167 | |
162 | |
168 | if (prepend_dir) |
163 | if (prepend_dir) |
169 | strcpy (buf, create_pathname (name)); |
164 | strcpy (buf, create_pathname (name)); |
170 | else |
165 | else |
171 | strcpy (buf, name); |
166 | strcpy (buf, name); |
172 | #ifdef WIN32 /* ***win32: check this sucker in windows style. */ |
|
|
173 | return (_access (buf, 0)); |
|
|
174 | #else |
|
|
175 | |
167 | |
176 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
168 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
177 | * this method should be equivalant and is clearer. |
169 | * this method should be equivalant and is clearer. |
178 | * Can not use strcat because we need to cycle through |
170 | * Can not use strcat because we need to cycle through |
179 | * all the names. |
171 | * all the names. |
… | |
… | |
192 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
184 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
193 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
185 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
194 | mode |= 2; |
186 | mode |= 2; |
195 | |
187 | |
196 | return (mode); |
188 | return (mode); |
197 | #endif |
|
|
198 | } |
189 | } |
199 | |
190 | |
200 | /* |
191 | /* |
201 | * Prints out debug-information about a map. |
192 | * Prints out debug-information about a map. |
202 | * Dumping these at llevError doesn't seem right, but is |
193 | * Dumping these at llevError doesn't seem right, but is |
… | |
… | |
540 | { |
531 | { |
541 | int i, j; |
532 | int i, j; |
542 | int unique; |
533 | int unique; |
543 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
534 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
544 | |
535 | |
545 | op = get_object (); |
536 | op = object::create (); |
546 | op->map = m; /* To handle buttons correctly */ |
537 | op->map = m; /* To handle buttons correctly */ |
547 | |
538 | |
548 | while ((i = load_object (fp, op, mapflags))) |
539 | while ((i = load_object (fp, op, mapflags))) |
549 | { |
540 | { |
550 | /* if the archetype for the object is null, means that we |
541 | /* if the archetype for the object is null, means that we |
… | |
… | |
558 | } |
549 | } |
559 | |
550 | |
560 | |
551 | |
561 | switch (i) |
552 | switch (i) |
562 | { |
553 | { |
563 | case LL_NORMAL: |
554 | case LL_NORMAL: |
564 | /* if we are loading an overlay, put the floors on the bottom */ |
555 | /* if we are loading an overlay, put the floors on the bottom */ |
565 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
556 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
566 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
557 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
567 | else |
558 | else |
568 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
559 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
569 | |
560 | |
570 | if (op->inv) |
561 | if (op->inv) |
571 | sum_weight (op); |
562 | sum_weight (op); |
572 | |
563 | |
573 | prev = op, last_more = op; |
564 | prev = op, last_more = op; |
574 | break; |
565 | break; |
575 | |
566 | |
576 | case LL_MORE: |
567 | case LL_MORE: |
577 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
568 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
578 | op->head = prev, last_more->more = op, last_more = op; |
569 | op->head = prev, last_more->more = op, last_more = op; |
579 | break; |
570 | break; |
580 | } |
571 | } |
581 | |
572 | |
582 | if (mapflags & MAP_STYLE) |
573 | if (mapflags & MAP_STYLE) |
583 | remove_from_active_list (op); |
574 | remove_from_active_list (op); |
584 | |
575 | |
585 | op = get_object (); |
576 | op = object::create (); |
586 | op->map = m; |
577 | op->map = m; |
587 | } |
578 | } |
588 | |
579 | |
589 | for (i = 0; i < m->width; i++) |
580 | for (i = 0; i < m->width; i++) |
590 | { |
581 | { |
… | |
… | |
594 | /* check for unique items, or unique squares */ |
585 | /* check for unique items, or unique squares */ |
595 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
586 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
596 | { |
587 | { |
597 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
588 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
598 | unique = 1; |
589 | unique = 1; |
|
|
590 | |
599 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
591 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
600 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
592 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
601 | } |
593 | } |
602 | } |
594 | } |
603 | } |
595 | } |
604 | |
596 | |
605 | free_object (op); |
597 | op->destroy (); |
606 | link_multipart_objects (m); |
598 | link_multipart_objects (m); |
607 | } |
599 | } |
608 | |
600 | |
609 | /* This saves all the objects on the map in a non destructive fashion. |
601 | /* This saves all the objects on the map in a non destructive fashion. |
610 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
602 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
… | |
… | |
737 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
729 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
738 | shopitems *items = NULL; |
730 | shopitems *items = NULL; |
739 | int i = 0, number_of_entries = 0; |
731 | int i = 0, number_of_entries = 0; |
740 | const typedata *current_type; |
732 | const typedata *current_type; |
741 | |
733 | |
742 | shop_string = strdup_local (input_string); |
734 | shop_string = strdup (input_string); |
743 | p = shop_string; |
735 | p = shop_string; |
744 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
736 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
745 | while (p) |
737 | while (p) |
746 | { |
738 | { |
747 | p = strchr (p, ';'); |
739 | p = strchr (p, ';'); |
… | |
… | |
871 | |
863 | |
872 | value = strchr (key, ' '); |
864 | value = strchr (key, ' '); |
873 | |
865 | |
874 | if (!value) |
866 | if (!value) |
875 | { |
867 | { |
876 | if (end = strchr (key, '\n')) |
868 | if ((end = strchr (key, '\n'))) |
877 | *end = 0; |
869 | *end = 0; |
878 | } |
870 | } |
879 | else |
871 | else |
880 | { |
872 | { |
881 | *value = 0; |
873 | *value = 0; |
… | |
… | |
933 | * with nothing between). There is no reason in those cases to |
925 | * with nothing between). There is no reason in those cases to |
934 | * keep the empty message. Also, msgbuf contains garbage data |
926 | * keep the empty message. Also, msgbuf contains garbage data |
935 | * when msgpos is zero, so copying it results in crashes |
927 | * when msgpos is zero, so copying it results in crashes |
936 | */ |
928 | */ |
937 | if (msgpos != 0) |
929 | if (msgpos != 0) |
938 | m->msg = strdup_local (msgbuf); |
930 | m->msg = strdup (msgbuf); |
939 | } |
931 | } |
940 | else if (!strcmp (key, "maplore")) |
932 | else if (!strcmp (key, "maplore")) |
941 | { |
933 | { |
942 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
934 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
943 | { |
935 | { |
… | |
… | |
949 | strcpy (maplorebuf + maplorepos, buf); |
941 | strcpy (maplorebuf + maplorepos, buf); |
950 | maplorepos += strlen (buf); |
942 | maplorepos += strlen (buf); |
951 | } |
943 | } |
952 | } |
944 | } |
953 | if (maplorepos != 0) |
945 | if (maplorepos != 0) |
954 | m->maplore = strdup_local (maplorebuf); |
946 | m->maplore = strdup (maplorebuf); |
955 | } |
947 | } |
956 | else if (!strcmp (key, "end")) |
948 | else if (!strcmp (key, "end")) |
957 | { |
949 | { |
958 | break; |
950 | break; |
959 | } |
951 | } |
… | |
… | |
968 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
960 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
969 | } |
961 | } |
970 | else if (!strcmp (key, "name")) |
962 | else if (!strcmp (key, "name")) |
971 | { |
963 | { |
972 | *end = 0; |
964 | *end = 0; |
973 | m->name = strdup_local (value); |
965 | m->name = strdup (value); |
974 | } |
966 | } |
975 | /* first strcmp value on these are old names supported |
967 | /* first strcmp value on these are old names supported |
976 | * for compatibility reasons. The new values (second) are |
968 | * for compatibility reasons. The new values (second) are |
977 | * what really should be used. |
969 | * what really should be used. |
978 | */ |
970 | */ |
979 | else if (!strcmp (key, "oid")) |
971 | else if (!strcmp (key, "oid")) |
980 | { |
|
|
981 | fp.get (m, atoi (value)); |
972 | fp.get (m, atoi (value)); |
982 | } |
|
|
983 | else if (!strcmp (key, "attach")) |
973 | else if (!strcmp (key, "attach")) |
984 | { |
|
|
985 | m->attach = value; |
974 | m->attach = value; |
986 | } |
|
|
987 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
975 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
988 | { |
|
|
989 | m->enter_x = atoi (value); |
976 | m->enter_x = atoi (value); |
990 | } |
|
|
991 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
977 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
992 | { |
|
|
993 | m->enter_y = atoi (value); |
978 | m->enter_y = atoi (value); |
994 | } |
|
|
995 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
979 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
996 | { |
|
|
997 | m->width = atoi (value); |
980 | m->width = atoi (value); |
998 | } |
|
|
999 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
981 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
1000 | { |
|
|
1001 | m->height = atoi (value); |
982 | m->height = atoi (value); |
1002 | } |
|
|
1003 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
983 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
1004 | { |
|
|
1005 | m->reset_timeout = atoi (value); |
984 | m->reset_timeout = atoi (value); |
1006 | } |
|
|
1007 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
985 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
1008 | { |
|
|
1009 | m->timeout = atoi (value); |
986 | m->timeout = atoi (value); |
1010 | } |
|
|
1011 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
987 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
1012 | { |
988 | m->difficulty = clamp (atoi (value), 1, settings.max_level); |
1013 | m->difficulty = atoi (value); |
|
|
1014 | } |
|
|
1015 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
989 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
1016 | { |
|
|
1017 | m->darkness = atoi (value); |
990 | m->darkness = atoi (value); |
1018 | } |
|
|
1019 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
991 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
1020 | { |
|
|
1021 | m->fixed_resettime = atoi (value); |
992 | m->fixed_resettime = atoi (value); |
1022 | } |
|
|
1023 | else if (!strcmp (key, "unique")) |
993 | else if (!strcmp (key, "unique")) |
1024 | { |
|
|
1025 | m->unique = atoi (value); |
994 | m->unique = atoi (value); |
1026 | } |
|
|
1027 | else if (!strcmp (key, "template")) |
995 | else if (!strcmp (key, "template")) |
1028 | { |
|
|
1029 | m->templatemap = atoi (value); |
996 | m->templatemap = atoi (value); |
1030 | } |
|
|
1031 | else if (!strcmp (key, "region")) |
997 | else if (!strcmp (key, "region")) |
1032 | { |
|
|
1033 | m->region = get_region_by_name (value); |
998 | m->region = get_region_by_name (value); |
1034 | } |
|
|
1035 | else if (!strcmp (key, "shopitems")) |
999 | else if (!strcmp (key, "shopitems")) |
1036 | { |
1000 | { |
1037 | *end = 0; |
1001 | *end = 0; |
1038 | m->shopitems = parse_shop_string (value); |
1002 | m->shopitems = parse_shop_string (value); |
1039 | } |
1003 | } |
1040 | else if (!strcmp (key, "shopgreed")) |
1004 | else if (!strcmp (key, "shopgreed")) |
1041 | { |
|
|
1042 | m->shopgreed = atof (value); |
1005 | m->shopgreed = atof (value); |
1043 | } |
|
|
1044 | else if (!strcmp (key, "shopmin")) |
1006 | else if (!strcmp (key, "shopmin")) |
1045 | { |
|
|
1046 | m->shopmin = atol (value); |
1007 | m->shopmin = atol (value); |
1047 | } |
|
|
1048 | else if (!strcmp (key, "shopmax")) |
1008 | else if (!strcmp (key, "shopmax")) |
1049 | { |
|
|
1050 | m->shopmax = atol (value); |
1009 | m->shopmax = atol (value); |
1051 | } |
|
|
1052 | else if (!strcmp (key, "shoprace")) |
1010 | else if (!strcmp (key, "shoprace")) |
1053 | { |
1011 | { |
1054 | *end = 0; |
1012 | *end = 0; |
1055 | m->shoprace = strdup_local (value); |
1013 | m->shoprace = strdup (value); |
1056 | } |
1014 | } |
1057 | else if (!strcmp (key, "outdoor")) |
1015 | else if (!strcmp (key, "outdoor")) |
1058 | { |
|
|
1059 | m->outdoor = atoi (value); |
1016 | m->outdoor = atoi (value); |
1060 | } |
|
|
1061 | else if (!strcmp (key, "temp")) |
1017 | else if (!strcmp (key, "temp")) |
1062 | { |
|
|
1063 | m->temp = atoi (value); |
1018 | m->temp = atoi (value); |
1064 | } |
|
|
1065 | else if (!strcmp (key, "pressure")) |
1019 | else if (!strcmp (key, "pressure")) |
1066 | { |
|
|
1067 | m->pressure = atoi (value); |
1020 | m->pressure = atoi (value); |
1068 | } |
|
|
1069 | else if (!strcmp (key, "humid")) |
1021 | else if (!strcmp (key, "humid")) |
1070 | { |
|
|
1071 | m->humid = atoi (value); |
1022 | m->humid = atoi (value); |
1072 | } |
|
|
1073 | else if (!strcmp (key, "windspeed")) |
1023 | else if (!strcmp (key, "windspeed")) |
1074 | { |
|
|
1075 | m->windspeed = atoi (value); |
1024 | m->windspeed = atoi (value); |
1076 | } |
|
|
1077 | else if (!strcmp (key, "winddir")) |
1025 | else if (!strcmp (key, "winddir")) |
1078 | { |
|
|
1079 | m->winddir = atoi (value); |
1026 | m->winddir = atoi (value); |
1080 | } |
|
|
1081 | else if (!strcmp (key, "sky")) |
1027 | else if (!strcmp (key, "sky")) |
1082 | { |
|
|
1083 | m->sky = atoi (value); |
1028 | m->sky = atoi (value); |
1084 | } |
|
|
1085 | else if (!strcmp (key, "nosmooth")) |
1029 | else if (!strcmp (key, "nosmooth")) |
1086 | { |
|
|
1087 | m->nosmooth = atoi (value); |
1030 | m->nosmooth = atoi (value); |
1088 | } |
|
|
1089 | else if (!strncmp (key, "tile_path_", 10)) |
1031 | else if (!strncmp (key, "tile_path_", 10)) |
1090 | { |
1032 | { |
1091 | int tile = atoi (key + 10); |
1033 | int tile = atoi (key + 10); |
1092 | |
1034 | |
1093 | if (tile < 1 || tile > 4) |
1035 | if (tile < 1 || tile > 4) |
… | |
… | |
1126 | } |
1068 | } |
1127 | |
1069 | |
1128 | if (editor) |
1070 | if (editor) |
1129 | { |
1071 | { |
1130 | /* Use the value as in the file. */ |
1072 | /* Use the value as in the file. */ |
1131 | m->tile_path[tile - 1] = strdup_local (value); |
1073 | m->tile_path[tile - 1] = strdup (value); |
1132 | } |
1074 | } |
1133 | else if (path != NULL) |
1075 | else if (path != NULL) |
1134 | { |
1076 | { |
1135 | /* Use the normalized value. */ |
1077 | /* Use the normalized value. */ |
1136 | m->tile_path[tile - 1] = strdup_local (path); |
1078 | m->tile_path[tile - 1] = strdup (path); |
1137 | } |
1079 | } |
1138 | } /* end if tile direction (in)valid */ |
1080 | } /* end if tile direction (in)valid */ |
1139 | } |
1081 | } |
1140 | else |
1082 | else |
1141 | { |
|
|
1142 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1083 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1143 | } |
|
|
1144 | } |
1084 | } |
|
|
1085 | |
1145 | if (!key || strcmp (key, "end")) |
1086 | if (!key || strcmp (key, "end")) |
1146 | { |
1087 | { |
1147 | LOG (llevError, "Got premature eof on map header!\n"); |
1088 | LOG (llevError, "Got premature eof on map header!\n"); |
1148 | return 1; |
1089 | return 1; |
1149 | } |
1090 | } |
|
|
1091 | |
1150 | return 0; |
1092 | return 0; |
1151 | } |
1093 | } |
1152 | |
1094 | |
1153 | /* |
1095 | /* |
1154 | * Opens the file "filename" and reads information about the map |
1096 | * Opens the file "filename" and reads information about the map |
… | |
… | |
1306 | |
1248 | |
1307 | for (i = 0; i < MAP_WIDTH (m); i++) |
1249 | for (i = 0; i < MAP_WIDTH (m); i++) |
1308 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1250 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1309 | { |
1251 | { |
1310 | unique = 0; |
1252 | unique = 0; |
|
|
1253 | |
1311 | for (op = get_map_ob (m, i, j); op; op = next) |
1254 | for (op = get_map_ob (m, i, j); op; op = next) |
1312 | { |
1255 | { |
1313 | next = op->above; |
1256 | next = op->above; |
|
|
1257 | |
1314 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1258 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1315 | unique = 1; |
1259 | unique = 1; |
|
|
1260 | |
1316 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1261 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1317 | { |
1262 | { |
1318 | clean_object (op); |
1263 | clean_object (op); |
|
|
1264 | |
1319 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1265 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1320 | remove_button_link (op); |
1266 | remove_button_link (op); |
1321 | remove_ob (op); |
1267 | |
1322 | free_object (op); |
1268 | op->destroy (); |
1323 | } |
1269 | } |
1324 | } |
1270 | } |
1325 | } |
1271 | } |
1326 | } |
1272 | } |
1327 | |
1273 | |
… | |
… | |
1396 | make_path_to_file (filename); |
1342 | make_path_to_file (filename); |
1397 | } |
1343 | } |
1398 | else |
1344 | else |
1399 | { |
1345 | { |
1400 | if (!m->tmpname) |
1346 | if (!m->tmpname) |
1401 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1347 | m->tmpname = tempnam (settings.tmpdir, NULL); |
1402 | |
1348 | |
1403 | strcpy (filename, m->tmpname); |
1349 | strcpy (filename, m->tmpname); |
1404 | } |
1350 | } |
1405 | |
1351 | |
1406 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1352 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
… | |
… | |
1430 | print_shop_string (m, shop); |
1376 | print_shop_string (m, shop); |
1431 | fprintf (freezer, "shopitems %s\n", shop); |
1377 | fprintf (freezer, "shopitems %s\n", shop); |
1432 | } |
1378 | } |
1433 | if (m->shopgreed) |
1379 | if (m->shopgreed) |
1434 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1380 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1435 | #ifndef WIN32 |
|
|
1436 | if (m->shopmin) |
1381 | if (m->shopmin) |
1437 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1382 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1438 | if (m->shopmax) |
1383 | if (m->shopmax) |
1439 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1384 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1440 | #else |
|
|
1441 | if (m->shopmin) |
|
|
1442 | fprintf (freezer, "shopmin %I64u\n", m->shopmin); |
|
|
1443 | if (m->shopmax) |
|
|
1444 | fprintf (freezer, "shopmax %I64u\n", m->shopmax); |
|
|
1445 | #endif |
|
|
1446 | if (m->shoprace) |
1385 | if (m->shoprace) |
1447 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1386 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1448 | if (m->darkness) |
1387 | if (m->darkness) |
1449 | fprintf (freezer, "darkness %d\n", m->darkness); |
1388 | fprintf (freezer, "darkness %d\n", m->darkness); |
1450 | if (m->width) |
1389 | if (m->width) |
… | |
… | |
1529 | object *tmp, *next; |
1468 | object *tmp, *next; |
1530 | |
1469 | |
1531 | for (tmp = op->inv; tmp; tmp = next) |
1470 | for (tmp = op->inv; tmp; tmp = next) |
1532 | { |
1471 | { |
1533 | next = tmp->below; |
1472 | next = tmp->below; |
|
|
1473 | |
1534 | clean_object (tmp); |
1474 | clean_object (tmp); |
1535 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1475 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1536 | remove_button_link (tmp); |
1476 | remove_button_link (tmp); |
1537 | remove_ob (tmp); |
1477 | |
1538 | free_object (tmp); |
1478 | tmp->destroy (); |
1539 | } |
1479 | } |
1540 | } |
1480 | } |
1541 | |
1481 | |
1542 | /* |
1482 | /* |
1543 | * Remove and free all objects in the given map. |
1483 | * Remove and free all objects in the given map. |
… | |
… | |
1559 | if (op == previous_obj) |
1499 | if (op == previous_obj) |
1560 | { |
1500 | { |
1561 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1501 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1562 | break; |
1502 | break; |
1563 | } |
1503 | } |
|
|
1504 | |
1564 | previous_obj = op; |
1505 | previous_obj = op; |
|
|
1506 | |
1565 | if (op->head != NULL) |
1507 | if (op->head != NULL) |
1566 | op = op->head; |
1508 | op = op->head; |
1567 | |
1509 | |
1568 | /* If the map isn't in memory, free_object will remove and |
1510 | /* If the map isn't in memory, free_object will remove and |
1569 | * free objects in op's inventory. So let it do the job. |
1511 | * free objects in op's inventory. So let it do the job. |
1570 | */ |
1512 | */ |
1571 | if (m->in_memory == MAP_IN_MEMORY) |
1513 | if (m->in_memory == MAP_IN_MEMORY) |
1572 | clean_object (op); |
1514 | clean_object (op); |
1573 | remove_ob (op); |
1515 | |
1574 | free_object (op); |
1516 | op->destroy (); |
1575 | } |
1517 | } |
1576 | } |
1518 | } |
1577 | } |
1519 | } |
1578 | |
1520 | |
1579 | /* |
1521 | /* |
… | |
… | |
1589 | if (!m->in_memory) |
1531 | if (!m->in_memory) |
1590 | { |
1532 | { |
1591 | LOG (llevError, "Trying to free freed map.\n"); |
1533 | LOG (llevError, "Trying to free freed map.\n"); |
1592 | return; |
1534 | return; |
1593 | } |
1535 | } |
|
|
1536 | |
|
|
1537 | // TODO: use new/delete |
|
|
1538 | #define FREE_AND_CLEAR(p) { free (p); p = NULL; } |
|
|
1539 | |
1594 | if (flag && m->spaces) |
1540 | if (flag && m->spaces) |
1595 | free_all_objects (m); |
1541 | free_all_objects (m); |
1596 | if (m->name) |
1542 | if (m->name) |
1597 | FREE_AND_CLEAR (m->name); |
1543 | FREE_AND_CLEAR (m->name); |
1598 | if (m->spaces) |
1544 | if (m->spaces) |
1599 | FREE_AND_CLEAR (m->spaces); |
1545 | FREE_AND_CLEAR (m->spaces); |
1600 | if (m->msg) |
1546 | if (m->msg) |
1601 | FREE_AND_CLEAR (m->msg); |
1547 | FREE_AND_CLEAR (m->msg); |
1602 | if (m->maplore) |
1548 | if (m->maplore) |
1603 | FREE_AND_CLEAR (m->maplore); |
1549 | FREE_AND_CLEAR (m->maplore); |
1604 | if (m->shopitems) |
1550 | |
1605 | delete[]m->shopitems; |
1551 | delete [] m->shopitems; |
1606 | m->shopitems = 0; |
1552 | m->shopitems = 0; |
|
|
1553 | |
1607 | if (m->shoprace) |
1554 | if (m->shoprace) |
1608 | FREE_AND_CLEAR (m->shoprace); |
1555 | FREE_AND_CLEAR (m->shoprace); |
|
|
1556 | |
1609 | if (m->buttons) |
1557 | if (m->buttons) |
1610 | free_objectlinkpt (m->buttons); |
1558 | free_objectlinkpt (m->buttons); |
|
|
1559 | |
1611 | m->buttons = NULL; |
1560 | m->buttons = NULL; |
|
|
1561 | |
1612 | for (i = 0; i < 4; i++) |
1562 | for (i = 0; i < 4; i++) |
1613 | { |
1563 | { |
1614 | if (m->tile_path[i]) |
1564 | if (m->tile_path[i]) |
1615 | FREE_AND_CLEAR (m->tile_path[i]); |
1565 | FREE_AND_CLEAR (m->tile_path[i]); |
1616 | m->tile_map[i] = NULL; |
1566 | m->tile_map[i] = NULL; |
1617 | } |
1567 | } |
|
|
1568 | |
1618 | m->in_memory = MAP_SWAPPED; |
1569 | m->in_memory = MAP_SWAPPED; |
|
|
1570 | |
|
|
1571 | #undef FREE_AND_CLEAR |
|
|
1572 | |
1619 | } |
1573 | } |
1620 | |
1574 | |
1621 | /* |
1575 | /* |
1622 | * function: vanish maptile |
1576 | * function: vanish maptile |
1623 | * m : pointer to maptile, if NULL no action |
1577 | * m : pointer to maptile, if NULL no action |
… | |
… | |
1683 | else |
1637 | else |
1684 | last->next = m->next; |
1638 | last->next = m->next; |
1685 | |
1639 | |
1686 | delete m; |
1640 | delete m; |
1687 | } |
1641 | } |
1688 | |
|
|
1689 | |
|
|
1690 | |
1642 | |
1691 | /* |
1643 | /* |
1692 | * Makes sure the given map is loaded and swapped in. |
1644 | * Makes sure the given map is loaded and swapped in. |
1693 | * name is path name of the map. |
1645 | * name is path name of the map. |
1694 | * flags meaning: |
1646 | * flags meaning: |
… | |
… | |
1697 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1649 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1698 | * dont do any more name translation on it. |
1650 | * dont do any more name translation on it. |
1699 | * |
1651 | * |
1700 | * Returns a pointer to the given map. |
1652 | * Returns a pointer to the given map. |
1701 | */ |
1653 | */ |
1702 | |
|
|
1703 | maptile * |
1654 | maptile * |
1704 | ready_map_name (const char *name, int flags) |
1655 | ready_map_name (const char *name, int flags) |
1705 | { |
1656 | { |
1706 | maptile *m; |
1657 | maptile *m; |
1707 | |
1658 | |
… | |
… | |
2153 | timeout = MAP_RESET_TIMEOUT (map); |
2104 | timeout = MAP_RESET_TIMEOUT (map); |
2154 | if (timeout <= 0) |
2105 | if (timeout <= 0) |
2155 | timeout = MAP_DEFAULTRESET; |
2106 | timeout = MAP_DEFAULTRESET; |
2156 | if (timeout >= MAP_MAXRESET) |
2107 | if (timeout >= MAP_MAXRESET) |
2157 | timeout = MAP_MAXRESET; |
2108 | timeout = MAP_MAXRESET; |
2158 | MAP_WHEN_RESET (map) = seconds () + timeout; |
2109 | MAP_WHEN_RESET (map) = time (0) + timeout; |
2159 | } |
2110 | } |
2160 | |
2111 | |
2161 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2112 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2162 | * the map. It also takes care of linking back the freshly loaded |
2113 | * the map. It also takes care of linking back the freshly loaded |
2163 | * maps tile_map values if it tiles back to this one. It returns |
2114 | * maps tile_map values if it tiles back to this one. It returns |