1 | /* |
1 | /* |
2 | * static char *rcsid_map_c = |
2 | * static char *rcsid_map_c = |
3 | * "$Id: map.C,v 1.12 2006/08/28 16:52:51 root Exp $"; |
3 | * "$Id: map.C,v 1.18 2006/08/31 17:54:14 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
173 | * Can not use strcat because we need to cycle through |
173 | * Can not use strcat because we need to cycle through |
174 | * all the names. |
174 | * all the names. |
175 | */ |
175 | */ |
176 | endbuf = buf + strlen(buf); |
176 | endbuf = buf + strlen(buf); |
177 | |
177 | |
178 | for (i = 0; i < NROF_COMPRESS_METHODS; i++) { |
|
|
179 | if (uncomp[i][0]) |
|
|
180 | strcpy(endbuf, uncomp[i][0]); |
|
|
181 | else |
|
|
182 | *endbuf = '\0'; |
|
|
183 | if (!stat (buf, &statbuf)) |
178 | if (stat (buf, &statbuf)) |
184 | break; |
|
|
185 | } |
|
|
186 | if (i == NROF_COMPRESS_METHODS) |
|
|
187 | return (-1); |
179 | return -1; |
188 | if (!S_ISREG (statbuf.st_mode)) |
180 | if (!S_ISREG (statbuf.st_mode)) |
189 | return (-1); |
181 | return (-1); |
190 | |
182 | |
191 | if (((statbuf.st_mode & S_IRGRP) && getegid() == statbuf.st_gid) || |
183 | if (((statbuf.st_mode & S_IRGRP) && getegid() == statbuf.st_gid) || |
192 | ((statbuf.st_mode & S_IRUSR) && geteuid() == statbuf.st_uid) || |
184 | ((statbuf.st_mode & S_IRUSR) && geteuid() == statbuf.st_uid) || |
… | |
… | |
536 | /* if the archetype for the object is null, means that we |
528 | /* if the archetype for the object is null, means that we |
537 | * got an invalid object. Don't do anything with it - the game |
529 | * got an invalid object. Don't do anything with it - the game |
538 | * or editor will not be able to do anything with it either. |
530 | * or editor will not be able to do anything with it either. |
539 | */ |
531 | */ |
540 | if (op->arch==NULL) { |
532 | if (op->arch==NULL) { |
541 | LOG(llevDebug,"Discarding object without arch: %s\n", op->name?op->name:"(null)"); |
533 | LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)"); |
542 | continue; |
534 | continue; |
543 | } |
535 | } |
544 | |
536 | |
545 | |
537 | |
546 | switch(i) { |
538 | switch(i) { |
… | |
… | |
949 | m->winddir = atoi(value); |
941 | m->winddir = atoi(value); |
950 | } else if (!strcmp(key, "sky")) { |
942 | } else if (!strcmp(key, "sky")) { |
951 | m->sky = atoi(value); |
943 | m->sky = atoi(value); |
952 | } else if (!strcmp(key, "nosmooth")) { |
944 | } else if (!strcmp(key, "nosmooth")) { |
953 | m->nosmooth = atoi(value); |
945 | m->nosmooth = atoi(value); |
954 | } else if (!strcmp(key, "safe_map")) { |
|
|
955 | m->safe_map = atoi(value); |
|
|
956 | } |
946 | } |
957 | else if (!strncmp(key,"tile_path_", 10)) { |
947 | else if (!strncmp(key,"tile_path_", 10)) { |
958 | int tile=atoi(key+10); |
948 | int tile=atoi(key+10); |
959 | |
949 | |
960 | if (tile<1 || tile>4) { |
950 | if (tile<1 || tile>4) { |
… | |
… | |
1017 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1007 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1018 | * managed map list. |
1008 | * managed map list. |
1019 | */ |
1009 | */ |
1020 | |
1010 | |
1021 | mapstruct *load_original_map(const char *filename, int flags) { |
1011 | mapstruct *load_original_map(const char *filename, int flags) { |
1022 | FILE *fp; |
|
|
1023 | mapstruct *m; |
1012 | mapstruct *m; |
1024 | int comp; |
|
|
1025 | char pathname[MAX_BUF]; |
1013 | char pathname[MAX_BUF]; |
1026 | |
1014 | |
1027 | LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); |
1015 | LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); |
1028 | if (flags & MAP_PLAYER_UNIQUE) |
1016 | if (flags & MAP_PLAYER_UNIQUE) |
1029 | strcpy(pathname, filename); |
1017 | strcpy(pathname, filename); |
1030 | else if (flags & MAP_OVERLAY) |
1018 | else if (flags & MAP_OVERLAY) |
1031 | strcpy(pathname, create_overlay_pathname(filename)); |
1019 | strcpy(pathname, create_overlay_pathname(filename)); |
1032 | else |
1020 | else |
1033 | strcpy(pathname, create_pathname(filename)); |
1021 | strcpy(pathname, create_pathname(filename)); |
1034 | |
1022 | |
1035 | if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) { |
|
|
1036 | LOG(llevError, "Can't open %s: %s\n", pathname, strerror_local(errno)); |
|
|
1037 | return (NULL); |
|
|
1038 | } |
|
|
1039 | |
|
|
1040 | object_thawer thawer (fp, filename); |
1023 | object_thawer thawer (pathname); |
|
|
1024 | |
|
|
1025 | if (!thawer) |
|
|
1026 | return 0; |
1041 | |
1027 | |
1042 | m = get_linked_map(); |
1028 | m = get_linked_map(); |
1043 | |
1029 | |
1044 | strcpy (m->path, filename); |
1030 | strcpy (m->path, filename); |
1045 | if (load_map_header(thawer, m)) { |
1031 | if (load_map_header(thawer, m)) { |
… | |
… | |
1051 | |
1037 | |
1052 | allocate_map(m); |
1038 | allocate_map(m); |
1053 | |
1039 | |
1054 | m->in_memory=MAP_LOADING; |
1040 | m->in_memory=MAP_LOADING; |
1055 | load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); |
1041 | load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); |
1056 | close_and_delete(fp, comp); |
1042 | |
1057 | m->in_memory=MAP_IN_MEMORY; |
1043 | m->in_memory=MAP_IN_MEMORY; |
1058 | if (!MAP_DIFFICULTY(m)) |
1044 | if (!MAP_DIFFICULTY(m)) |
1059 | MAP_DIFFICULTY(m)=calculate_difficulty(m); |
1045 | MAP_DIFFICULTY(m)=calculate_difficulty(m); |
1060 | set_map_reset_time(m); |
1046 | set_map_reset_time(m); |
1061 | m->instantiate (); |
1047 | m->instantiate (); |
… | |
… | |
1067 | * Return the map object we load into (this can change from the passed |
1053 | * Return the map object we load into (this can change from the passed |
1068 | * option if we can't find the original map) |
1054 | * option if we can't find the original map) |
1069 | */ |
1055 | */ |
1070 | |
1056 | |
1071 | static mapstruct *load_temporary_map(mapstruct *m) { |
1057 | static mapstruct *load_temporary_map(mapstruct *m) { |
1072 | FILE *fp; |
|
|
1073 | int comp; |
1058 | int comp; |
1074 | char buf[MAX_BUF]; |
1059 | char buf[MAX_BUF]; |
1075 | |
1060 | |
1076 | if (!m->tmpname) { |
1061 | if (!m->tmpname) { |
1077 | LOG(llevError, "No temporary filename for map %s\n", m->path); |
1062 | LOG(llevError, "No temporary filename for map %s\n", m->path); |
… | |
… | |
1081 | if(m==NULL) return NULL; |
1066 | if(m==NULL) return NULL; |
1082 | fix_auto_apply(m); /* Chests which open as default */ |
1067 | fix_auto_apply(m); /* Chests which open as default */ |
1083 | return m; |
1068 | return m; |
1084 | } |
1069 | } |
1085 | |
1070 | |
1086 | if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { |
1071 | object_thawer thawer (m->tmpname); |
1087 | LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); |
1072 | |
|
|
1073 | if (!thawer) |
|
|
1074 | { |
1088 | strcpy(buf, m->path); |
1075 | strcpy (buf, m->path); |
1089 | delete_map(m); |
1076 | delete_map (m); |
1090 | m = load_original_map(buf, 0); |
1077 | m = load_original_map (buf, 0); |
1091 | if(m==NULL) return NULL; |
1078 | if (!m) return NULL; |
1092 | fix_auto_apply(m); /* Chests which open as default */ |
1079 | fix_auto_apply (m); /* Chests which open as default */ |
1093 | return m; |
1080 | return m; |
1094 | } |
1081 | } |
1095 | |
|
|
1096 | object_thawer thawer (fp, m->tmpname); |
|
|
1097 | |
1082 | |
1098 | if (load_map_header(thawer, m)) { |
1083 | if (load_map_header(thawer, m)) { |
1099 | LOG(llevError,"Error loading map header for %s (%s)\n", |
1084 | LOG(llevError,"Error loading map header for %s (%s)\n", |
1100 | m->path, m->tmpname); |
1085 | m->path, m->tmpname); |
1101 | delete_map(m); |
1086 | delete_map(m); |
… | |
… | |
1104 | } |
1089 | } |
1105 | allocate_map(m); |
1090 | allocate_map(m); |
1106 | |
1091 | |
1107 | m->in_memory=MAP_LOADING; |
1092 | m->in_memory=MAP_LOADING; |
1108 | load_objects (m, thawer, 0); |
1093 | load_objects (m, thawer, 0); |
1109 | close_and_delete(fp, comp); |
1094 | |
1110 | m->in_memory=MAP_IN_MEMORY; |
1095 | m->in_memory=MAP_IN_MEMORY; |
1111 | INVOKE_MAP (SWAPIN, m); |
1096 | INVOKE_MAP (SWAPIN, m); |
1112 | return m; |
1097 | return m; |
1113 | } |
1098 | } |
1114 | |
1099 | |
… | |
… | |
1117 | * Return the map object we load into (this can change from the passed |
1102 | * Return the map object we load into (this can change from the passed |
1118 | * option if we can't find the original map) |
1103 | * option if we can't find the original map) |
1119 | */ |
1104 | */ |
1120 | |
1105 | |
1121 | mapstruct *load_overlay_map(const char *filename, mapstruct *m) { |
1106 | mapstruct *load_overlay_map(const char *filename, mapstruct *m) { |
1122 | FILE *fp; |
|
|
1123 | int comp; |
|
|
1124 | char pathname[MAX_BUF]; |
1107 | char pathname[MAX_BUF]; |
1125 | |
1108 | |
1126 | strcpy(pathname, create_overlay_pathname(filename)); |
1109 | strcpy(pathname, create_overlay_pathname(filename)); |
1127 | |
1110 | |
1128 | if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) { |
|
|
1129 | /* LOG(llevDebug,"Can't open overlay %s\n", pathname);*/ |
|
|
1130 | return m; |
|
|
1131 | } |
|
|
1132 | |
|
|
1133 | object_thawer thawer (fp, pathname); |
1111 | object_thawer thawer (pathname); |
|
|
1112 | |
|
|
1113 | if (!thawer) |
|
|
1114 | return m; |
1134 | |
1115 | |
1135 | if (load_map_header(thawer, m)) { |
1116 | if (load_map_header(thawer, m)) { |
1136 | LOG(llevError,"Error loading map header for overlay %s (%s)\n", |
1117 | LOG(llevError,"Error loading map header for overlay %s (%s)\n", |
1137 | m->path, pathname); |
1118 | m->path, pathname); |
1138 | delete_map(m); |
1119 | delete_map(m); |
… | |
… | |
1141 | } |
1122 | } |
1142 | /*allocate_map(m);*/ |
1123 | /*allocate_map(m);*/ |
1143 | |
1124 | |
1144 | m->in_memory=MAP_LOADING; |
1125 | m->in_memory=MAP_LOADING; |
1145 | load_objects (m, thawer, MAP_OVERLAY); |
1126 | load_objects (m, thawer, MAP_OVERLAY); |
1146 | close_and_delete(fp, comp); |
1127 | |
1147 | m->in_memory=MAP_IN_MEMORY; |
1128 | m->in_memory=MAP_IN_MEMORY; |
1148 | return m; |
1129 | return m; |
1149 | } |
1130 | } |
1150 | |
1131 | |
1151 | /****************************************************************************** |
1132 | /****************************************************************************** |
… | |
… | |
1180 | /* |
1161 | /* |
1181 | * Loads unique objects from file(s) into the map which is in memory |
1162 | * Loads unique objects from file(s) into the map which is in memory |
1182 | * m is the map to load unique items into. |
1163 | * m is the map to load unique items into. |
1183 | */ |
1164 | */ |
1184 | static void load_unique_objects(mapstruct *m) { |
1165 | static void load_unique_objects(mapstruct *m) { |
1185 | FILE *fp; |
|
|
1186 | int comp,count; |
1166 | int count; |
1187 | char firstname[MAX_BUF]; |
1167 | char firstname[MAX_BUF]; |
1188 | |
1168 | |
1189 | for (count=0; count<10; count++) { |
1169 | for (count=0; count<10; count++) { |
1190 | sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); |
1170 | sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); |
1191 | if (!access(firstname, R_OK)) break; |
1171 | if (!access(firstname, R_OK)) break; |
1192 | } |
1172 | } |
1193 | /* If we get here, we did not find any map */ |
1173 | /* If we get here, we did not find any map */ |
1194 | if (count==10) return; |
1174 | if (count==10) return; |
1195 | |
1175 | |
1196 | if ((fp=open_and_uncompress(firstname, 0, &comp))==NULL) { |
|
|
1197 | /* There is no expectation that every map will have unique items, but this |
|
|
1198 | * is debug output, so leave it in. |
|
|
1199 | */ |
|
|
1200 | LOG(llevDebug, "Can't open unique items file for %s\n", create_items_path(m->path)); |
|
|
1201 | return; |
|
|
1202 | } |
|
|
1203 | |
|
|
1204 | object_thawer thawer (fp, firstname); |
1176 | object_thawer thawer (firstname); |
|
|
1177 | |
|
|
1178 | if (!thawer) |
|
|
1179 | return; |
1205 | |
1180 | |
1206 | m->in_memory=MAP_LOADING; |
1181 | m->in_memory=MAP_LOADING; |
1207 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1182 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1208 | delete_unique_items(m); /* original map before, don't duplicate them */ |
1183 | delete_unique_items(m); /* original map before, don't duplicate them */ |
1209 | load_object(thawer, NULL, LO_NOREAD,0); |
1184 | load_object(thawer, NULL, LO_NOREAD,0); |
1210 | load_objects (m, thawer, 0); |
1185 | load_objects (m, thawer, 0); |
1211 | close_and_delete(fp, comp); |
1186 | |
1212 | m->in_memory=MAP_IN_MEMORY; |
1187 | m->in_memory=MAP_IN_MEMORY; |
1213 | } |
1188 | } |
1214 | |
1189 | |
1215 | |
1190 | |
1216 | /* |
1191 | /* |
… | |
… | |
1250 | } |
1225 | } |
1251 | else |
1226 | else |
1252 | { |
1227 | { |
1253 | if (!m->tmpname) |
1228 | if (!m->tmpname) |
1254 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1229 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
|
|
1230 | |
1255 | strcpy (filename, m->tmpname); |
1231 | strcpy (filename, m->tmpname); |
1256 | } |
1232 | } |
1257 | |
1233 | |
1258 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1234 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1259 | m->in_memory = MAP_SAVING; |
1235 | m->in_memory = MAP_SAVING; |
1260 | |
1236 | |
1261 | object_freezer fp (filename); |
1237 | object_freezer freezer; |
1262 | |
1238 | |
1263 | /* legacy */ |
1239 | /* legacy */ |
1264 | fprintf (fp, "arch map\n"); |
1240 | fprintf (freezer, "arch map\n"); |
1265 | if (m->name) |
1241 | if (m->name) |
1266 | fprintf (fp, "name %s\n", m->name); |
1242 | fprintf (freezer, "name %s\n", m->name); |
1267 | if (!flag) |
1243 | if (!flag) |
1268 | fprintf (fp, "swap_time %d\n", m->swap_time); |
1244 | fprintf (freezer, "swap_time %d\n", m->swap_time); |
1269 | if (m->reset_timeout) |
1245 | if (m->reset_timeout) |
1270 | fprintf (fp, "reset_timeout %d\n", m->reset_timeout); |
1246 | fprintf (freezer, "reset_timeout %d\n", m->reset_timeout); |
1271 | if (m->fixed_resettime) |
1247 | if (m->fixed_resettime) |
1272 | fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); |
1248 | fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime); |
1273 | /* we unfortunately have no idea if this is a value the creator set |
1249 | /* we unfortunately have no idea if this is a value the creator set |
1274 | * or a difficulty value we generated when the map was first loaded |
1250 | * or a difficulty value we generated when the map was first loaded |
1275 | */ |
1251 | */ |
1276 | if (m->difficulty) |
1252 | if (m->difficulty) |
1277 | fprintf (fp, "difficulty %d\n", m->difficulty); |
1253 | fprintf (freezer, "difficulty %d\n", m->difficulty); |
1278 | if (m->region) |
1254 | if (m->region) |
1279 | fprintf (fp, "region %s\n", m->region->name); |
1255 | fprintf (freezer, "region %s\n", m->region->name); |
1280 | if (m->shopitems) |
1256 | if (m->shopitems) |
1281 | { |
1257 | { |
1282 | print_shop_string (m, shop); |
1258 | print_shop_string (m, shop); |
1283 | fprintf (fp, "shopitems %s\n", shop); |
1259 | fprintf (freezer, "shopitems %s\n", shop); |
1284 | } |
1260 | } |
1285 | if (m->shopgreed) |
1261 | if (m->shopgreed) |
1286 | fprintf (fp, "shopgreed %f\n", m->shopgreed); |
1262 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1287 | #ifndef WIN32 |
1263 | #ifndef WIN32 |
1288 | if (m->shopmin) |
1264 | if (m->shopmin) |
1289 | fprintf (fp, "shopmin %llu\n", m->shopmin); |
1265 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1290 | if (m->shopmax) |
1266 | if (m->shopmax) |
1291 | fprintf (fp, "shopmax %llu\n", m->shopmax); |
1267 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1292 | #else |
1268 | #else |
1293 | if (m->shopmin) |
1269 | if (m->shopmin) |
1294 | fprintf (fp, "shopmin %I64u\n", m->shopmin); |
1270 | fprintf (freezer, "shopmin %I64u\n", m->shopmin); |
1295 | if (m->shopmax) |
1271 | if (m->shopmax) |
1296 | fprintf (fp, "shopmax %I64u\n", m->shopmax); |
1272 | fprintf (freezer, "shopmax %I64u\n", m->shopmax); |
1297 | #endif |
1273 | #endif |
1298 | if (m->shoprace) |
1274 | if (m->shoprace) |
1299 | fprintf (fp, "shoprace %s\n", m->shoprace); |
1275 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1300 | if (m->darkness) |
1276 | if (m->darkness) |
1301 | fprintf (fp, "darkness %d\n", m->darkness); |
1277 | fprintf (freezer, "darkness %d\n", m->darkness); |
1302 | if (m->width) |
1278 | if (m->width) |
1303 | fprintf (fp, "width %d\n", m->width); |
1279 | fprintf (freezer, "width %d\n", m->width); |
1304 | if (m->height) |
1280 | if (m->height) |
1305 | fprintf (fp, "height %d\n", m->height); |
1281 | fprintf (freezer, "height %d\n", m->height); |
1306 | if (m->enter_x) |
1282 | if (m->enter_x) |
1307 | fprintf (fp, "enter_x %d\n", m->enter_x); |
1283 | fprintf (freezer, "enter_x %d\n", m->enter_x); |
1308 | if (m->enter_y) |
1284 | if (m->enter_y) |
1309 | fprintf (fp, "enter_y %d\n", m->enter_y); |
1285 | fprintf (freezer, "enter_y %d\n", m->enter_y); |
1310 | if (m->msg) |
1286 | if (m->msg) |
1311 | fprintf (fp, "msg\n%sendmsg\n", m->msg); |
1287 | fprintf (freezer, "msg\n%sendmsg\n", m->msg); |
1312 | if (m->maplore) |
1288 | if (m->maplore) |
1313 | fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); |
1289 | fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore); |
1314 | if (m->unique) |
1290 | if (m->unique) |
1315 | fprintf (fp, "unique %d\n", m->unique); |
1291 | fprintf (freezer, "unique %d\n", m->unique); |
1316 | if (m->templatemap) |
1292 | if (m->templatemap) |
1317 | fprintf (fp, "template %d\n", m->templatemap); |
1293 | fprintf (freezer, "template %d\n", m->templatemap); |
1318 | if (m->outdoor) |
1294 | if (m->outdoor) |
1319 | fprintf (fp, "outdoor %d\n", m->outdoor); |
1295 | fprintf (freezer, "outdoor %d\n", m->outdoor); |
1320 | if (m->temp) |
1296 | if (m->temp) |
1321 | fprintf (fp, "temp %d\n", m->temp); |
1297 | fprintf (freezer, "temp %d\n", m->temp); |
1322 | if (m->pressure) |
1298 | if (m->pressure) |
1323 | fprintf (fp, "pressure %d\n", m->pressure); |
1299 | fprintf (freezer, "pressure %d\n", m->pressure); |
1324 | if (m->humid) |
1300 | if (m->humid) |
1325 | fprintf (fp, "humid %d\n", m->humid); |
1301 | fprintf (freezer, "humid %d\n", m->humid); |
1326 | if (m->windspeed) |
1302 | if (m->windspeed) |
1327 | fprintf (fp, "windspeed %d\n", m->windspeed); |
1303 | fprintf (freezer, "windspeed %d\n", m->windspeed); |
1328 | if (m->winddir) |
1304 | if (m->winddir) |
1329 | fprintf (fp, "winddir %d\n", m->winddir); |
1305 | fprintf (freezer, "winddir %d\n", m->winddir); |
1330 | if (m->sky) |
1306 | if (m->sky) |
1331 | fprintf (fp, "sky %d\n", m->sky); |
1307 | fprintf (freezer, "sky %d\n", m->sky); |
1332 | if (m->nosmooth) |
1308 | if (m->nosmooth) |
1333 | fprintf (fp, "nosmooth %d\n", m->nosmooth); |
1309 | fprintf (freezer, "nosmooth %d\n", m->nosmooth); |
1334 | if (m->safe_map) |
|
|
1335 | fprintf (fp, "safe_map %d\n", m->safe_map); |
|
|
1336 | |
1310 | |
1337 | /* Save any tiling information, except on overlays */ |
1311 | /* Save any tiling information, except on overlays */ |
1338 | if (flag != 2) |
1312 | if (flag != 2) |
1339 | for (i = 0; i < 4; i++) |
1313 | for (i = 0; i < 4; i++) |
1340 | if (m->tile_path[i]) |
1314 | if (m->tile_path[i]) |
1341 | fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); |
1315 | fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]); |
1342 | |
1316 | |
1343 | fp.put (m); |
1317 | freezer.put (m); |
1344 | fprintf (fp, "end\n"); |
1318 | fprintf (freezer, "end\n"); |
1345 | |
1319 | |
1346 | /* In the game save unique items in the different file, but |
1320 | /* In the game save unique items in the different file, but |
1347 | * in the editor save them to the normal map file. |
1321 | * in the editor save them to the normal map file. |
1348 | * If unique map, save files in the proper destination (set by |
1322 | * If unique map, save files in the proper destination (set by |
1349 | * player) |
1323 | * player) |
1350 | */ |
1324 | */ |
1351 | if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) |
1325 | if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) |
1352 | { |
1326 | { |
|
|
1327 | object_freezer unique; |
|
|
1328 | |
|
|
1329 | if (flag == 2) |
|
|
1330 | save_objects (m, freezer, unique, 2); |
|
|
1331 | else |
|
|
1332 | save_objects (m, freezer, unique, 0); |
|
|
1333 | |
1353 | sprintf (buf, "%s.v00", create_items_path (m->path)); |
1334 | sprintf (buf, "%s.v00", create_items_path (m->path)); |
1354 | |
1335 | |
1355 | object_freezer fp2 (buf); |
1336 | unique.save (buf); |
1356 | |
|
|
1357 | if (flag == 2) |
|
|
1358 | save_objects (m, fp, fp2, 2); |
|
|
1359 | else |
|
|
1360 | save_objects (m, fp, fp2, 0); |
|
|
1361 | } |
1337 | } |
1362 | else |
1338 | else |
1363 | { /* save same file when not playing, like in editor */ |
1339 | { /* save same file when not playing, like in editor */ |
1364 | save_objects (m, fp, fp, 0); |
1340 | save_objects (m, freezer, freezer, 0); |
1365 | } |
1341 | } |
|
|
1342 | |
|
|
1343 | freezer.save (filename); |
1366 | |
1344 | |
1367 | return 0; |
1345 | return 0; |
1368 | } |
1346 | } |
1369 | |
1347 | |
1370 | |
1348 | |
… | |
… | |
1585 | if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { |
1563 | if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { |
1586 | m=load_overlay_map(name, m); |
1564 | m=load_overlay_map(name, m); |
1587 | if (m==NULL) |
1565 | if (m==NULL) |
1588 | return NULL; |
1566 | return NULL; |
1589 | } |
1567 | } |
|
|
1568 | |
|
|
1569 | if (flags & MAP_PLAYER_UNIQUE) |
|
|
1570 | INVOKE_MAP (SWAPIN, m); |
1590 | |
1571 | |
1591 | } else { |
1572 | } else { |
1592 | /* If in this loop, we found a temporary map, so load it up. */ |
1573 | /* If in this loop, we found a temporary map, so load it up. */ |
1593 | |
1574 | |
1594 | m=load_temporary_map (m); |
1575 | m=load_temporary_map (m); |