1 | /* |
1 | /* |
2 | * static char *rcsid_map_c = |
2 | * static char *rcsid_map_c = |
3 | * "$Id: map.C,v 1.16 2006/08/30 16:30:37 root Exp $"; |
3 | * "$Id: map.C,v 1.17 2006/08/31 06:23:19 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 | |
… | |
… | |
1225 | } |
1225 | } |
1226 | else |
1226 | else |
1227 | { |
1227 | { |
1228 | if (!m->tmpname) |
1228 | if (!m->tmpname) |
1229 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1229 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
|
|
1230 | |
1230 | strcpy (filename, m->tmpname); |
1231 | strcpy (filename, m->tmpname); |
1231 | } |
1232 | } |
1232 | |
1233 | |
1233 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1234 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1234 | m->in_memory = MAP_SAVING; |
1235 | m->in_memory = MAP_SAVING; |
1235 | |
1236 | |
1236 | object_freezer fp (filename); |
1237 | object_freezer freezer; |
1237 | |
1238 | |
1238 | /* legacy */ |
1239 | /* legacy */ |
1239 | fprintf (fp, "arch map\n"); |
1240 | fprintf (freezer, "arch map\n"); |
1240 | if (m->name) |
1241 | if (m->name) |
1241 | fprintf (fp, "name %s\n", m->name); |
1242 | fprintf (freezer, "name %s\n", m->name); |
1242 | if (!flag) |
1243 | if (!flag) |
1243 | fprintf (fp, "swap_time %d\n", m->swap_time); |
1244 | fprintf (freezer, "swap_time %d\n", m->swap_time); |
1244 | if (m->reset_timeout) |
1245 | if (m->reset_timeout) |
1245 | fprintf (fp, "reset_timeout %d\n", m->reset_timeout); |
1246 | fprintf (freezer, "reset_timeout %d\n", m->reset_timeout); |
1246 | if (m->fixed_resettime) |
1247 | if (m->fixed_resettime) |
1247 | fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); |
1248 | fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime); |
1248 | /* 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 |
1249 | * 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 |
1250 | */ |
1251 | */ |
1251 | if (m->difficulty) |
1252 | if (m->difficulty) |
1252 | fprintf (fp, "difficulty %d\n", m->difficulty); |
1253 | fprintf (freezer, "difficulty %d\n", m->difficulty); |
1253 | if (m->region) |
1254 | if (m->region) |
1254 | fprintf (fp, "region %s\n", m->region->name); |
1255 | fprintf (freezer, "region %s\n", m->region->name); |
1255 | if (m->shopitems) |
1256 | if (m->shopitems) |
1256 | { |
1257 | { |
1257 | print_shop_string (m, shop); |
1258 | print_shop_string (m, shop); |
1258 | fprintf (fp, "shopitems %s\n", shop); |
1259 | fprintf (freezer, "shopitems %s\n", shop); |
1259 | } |
1260 | } |
1260 | if (m->shopgreed) |
1261 | if (m->shopgreed) |
1261 | fprintf (fp, "shopgreed %f\n", m->shopgreed); |
1262 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1262 | #ifndef WIN32 |
1263 | #ifndef WIN32 |
1263 | if (m->shopmin) |
1264 | if (m->shopmin) |
1264 | fprintf (fp, "shopmin %llu\n", m->shopmin); |
1265 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1265 | if (m->shopmax) |
1266 | if (m->shopmax) |
1266 | fprintf (fp, "shopmax %llu\n", m->shopmax); |
1267 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1267 | #else |
1268 | #else |
1268 | if (m->shopmin) |
1269 | if (m->shopmin) |
1269 | fprintf (fp, "shopmin %I64u\n", m->shopmin); |
1270 | fprintf (freezer, "shopmin %I64u\n", m->shopmin); |
1270 | if (m->shopmax) |
1271 | if (m->shopmax) |
1271 | fprintf (fp, "shopmax %I64u\n", m->shopmax); |
1272 | fprintf (freezer, "shopmax %I64u\n", m->shopmax); |
1272 | #endif |
1273 | #endif |
1273 | if (m->shoprace) |
1274 | if (m->shoprace) |
1274 | fprintf (fp, "shoprace %s\n", m->shoprace); |
1275 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1275 | if (m->darkness) |
1276 | if (m->darkness) |
1276 | fprintf (fp, "darkness %d\n", m->darkness); |
1277 | fprintf (freezer, "darkness %d\n", m->darkness); |
1277 | if (m->width) |
1278 | if (m->width) |
1278 | fprintf (fp, "width %d\n", m->width); |
1279 | fprintf (freezer, "width %d\n", m->width); |
1279 | if (m->height) |
1280 | if (m->height) |
1280 | fprintf (fp, "height %d\n", m->height); |
1281 | fprintf (freezer, "height %d\n", m->height); |
1281 | if (m->enter_x) |
1282 | if (m->enter_x) |
1282 | fprintf (fp, "enter_x %d\n", m->enter_x); |
1283 | fprintf (freezer, "enter_x %d\n", m->enter_x); |
1283 | if (m->enter_y) |
1284 | if (m->enter_y) |
1284 | fprintf (fp, "enter_y %d\n", m->enter_y); |
1285 | fprintf (freezer, "enter_y %d\n", m->enter_y); |
1285 | if (m->msg) |
1286 | if (m->msg) |
1286 | fprintf (fp, "msg\n%sendmsg\n", m->msg); |
1287 | fprintf (freezer, "msg\n%sendmsg\n", m->msg); |
1287 | if (m->maplore) |
1288 | if (m->maplore) |
1288 | fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); |
1289 | fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore); |
1289 | if (m->unique) |
1290 | if (m->unique) |
1290 | fprintf (fp, "unique %d\n", m->unique); |
1291 | fprintf (freezer, "unique %d\n", m->unique); |
1291 | if (m->templatemap) |
1292 | if (m->templatemap) |
1292 | fprintf (fp, "template %d\n", m->templatemap); |
1293 | fprintf (freezer, "template %d\n", m->templatemap); |
1293 | if (m->outdoor) |
1294 | if (m->outdoor) |
1294 | fprintf (fp, "outdoor %d\n", m->outdoor); |
1295 | fprintf (freezer, "outdoor %d\n", m->outdoor); |
1295 | if (m->temp) |
1296 | if (m->temp) |
1296 | fprintf (fp, "temp %d\n", m->temp); |
1297 | fprintf (freezer, "temp %d\n", m->temp); |
1297 | if (m->pressure) |
1298 | if (m->pressure) |
1298 | fprintf (fp, "pressure %d\n", m->pressure); |
1299 | fprintf (freezer, "pressure %d\n", m->pressure); |
1299 | if (m->humid) |
1300 | if (m->humid) |
1300 | fprintf (fp, "humid %d\n", m->humid); |
1301 | fprintf (freezer, "humid %d\n", m->humid); |
1301 | if (m->windspeed) |
1302 | if (m->windspeed) |
1302 | fprintf (fp, "windspeed %d\n", m->windspeed); |
1303 | fprintf (freezer, "windspeed %d\n", m->windspeed); |
1303 | if (m->winddir) |
1304 | if (m->winddir) |
1304 | fprintf (fp, "winddir %d\n", m->winddir); |
1305 | fprintf (freezer, "winddir %d\n", m->winddir); |
1305 | if (m->sky) |
1306 | if (m->sky) |
1306 | fprintf (fp, "sky %d\n", m->sky); |
1307 | fprintf (freezer, "sky %d\n", m->sky); |
1307 | if (m->nosmooth) |
1308 | if (m->nosmooth) |
1308 | fprintf (fp, "nosmooth %d\n", m->nosmooth); |
1309 | fprintf (freezer, "nosmooth %d\n", m->nosmooth); |
1309 | |
1310 | |
1310 | /* Save any tiling information, except on overlays */ |
1311 | /* Save any tiling information, except on overlays */ |
1311 | if (flag != 2) |
1312 | if (flag != 2) |
1312 | for (i = 0; i < 4; i++) |
1313 | for (i = 0; i < 4; i++) |
1313 | if (m->tile_path[i]) |
1314 | if (m->tile_path[i]) |
1314 | 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]); |
1315 | |
1316 | |
1316 | fp.put (m); |
1317 | freezer.put (m); |
1317 | fprintf (fp, "end\n"); |
1318 | fprintf (freezer, "end\n"); |
1318 | |
1319 | |
1319 | /* In the game save unique items in the different file, but |
1320 | /* In the game save unique items in the different file, but |
1320 | * in the editor save them to the normal map file. |
1321 | * in the editor save them to the normal map file. |
1321 | * If unique map, save files in the proper destination (set by |
1322 | * If unique map, save files in the proper destination (set by |
1322 | * player) |
1323 | * player) |
1323 | */ |
1324 | */ |
1324 | if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) |
1325 | if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) |
1325 | { |
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 | |
1326 | sprintf (buf, "%s.v00", create_items_path (m->path)); |
1334 | sprintf (buf, "%s.v00", create_items_path (m->path)); |
1327 | |
1335 | |
1328 | object_freezer fp2 (buf); |
1336 | unique.save (buf); |
1329 | |
|
|
1330 | if (flag == 2) |
|
|
1331 | save_objects (m, fp, fp2, 2); |
|
|
1332 | else |
|
|
1333 | save_objects (m, fp, fp2, 0); |
|
|
1334 | } |
1337 | } |
1335 | else |
1338 | else |
1336 | { /* save same file when not playing, like in editor */ |
1339 | { /* save same file when not playing, like in editor */ |
1337 | save_objects (m, fp, fp, 0); |
1340 | save_objects (m, freezer, freezer, 0); |
1338 | } |
1341 | } |
|
|
1342 | |
|
|
1343 | freezer.save (filename); |
1339 | |
1344 | |
1340 | return 0; |
1345 | return 0; |
1341 | } |
1346 | } |
1342 | |
1347 | |
1343 | |
1348 | |