2
2
3
3
// #include <stdio.h>
4
4
// #include <string.h>
5
-
6
5
// #include <vector>
7
6
8
- #include " common/array .h"
7
+ #include " fallout2/fallout2 .h"
9
8
10
9
#include " fallout2/animation.h"
11
10
#include " fallout2/art.h"
45
44
#include " fallout2/window_manager_private.h"
46
45
#include " fallout2/worldmap.h"
47
46
47
+ #include " common/array.h"
48
+ #include " common/savefile.h"
49
+
50
+
48
51
namespace Fallout2 {
49
52
50
53
static char *mapBuildPath (char *name);
51
54
static int mapLoad (File *stream);
52
55
static int _map_age_dead_critters ();
53
56
static void _map_fix_critter_combat_data ();
54
57
static int _map_save ();
55
- static int _map_save_file (File *stream);
58
+ static int _map_save_file (Common::OutSaveFile *stream);
56
59
static void mapMakeMapsDirectory ();
57
60
static void isoWindowRefreshRect (Rect *rect);
58
61
static void isoWindowRefreshRectGame (Rect *rect);
@@ -67,7 +70,7 @@ static void _map_place_dude_and_mouse();
67
70
static void square_init ();
68
71
static void _square_reset ();
69
72
static int _square_load (File *stream, int a2);
70
- static int mapHeaderWrite (MapHeader *ptr, File *stream);
73
+ static int mapHeaderWrite (MapHeader *ptr, Common::OutSaveFile *stream);
71
74
static int mapHeaderRead (MapHeader *ptr, File *stream);
72
75
73
76
// 0x50B058
@@ -688,7 +691,12 @@ static char *mapBuildPath(char *name) {
688
691
689
692
if (*name != ' \\ ' ) {
690
693
// NOTE: Uppercased from "maps".
691
- snprintf (map_path, sizeof (map_path), " MAPS\\ %s" , name);
694
+ Common::String newMapName (g_engine->getTargetName ());
695
+ if (Common::String (name).contains (" .SAV" ))
696
+ snprintf (map_path, sizeof (map_path), " %s_maps_%s" , newMapName.c_str (), name);
697
+ else
698
+ snprintf (map_path, sizeof (map_path), " MAPS\\ %s" , name);
699
+ debug (" Built map path: %s" , map_path);
692
700
return map_path;
693
701
}
694
702
return name;
@@ -740,19 +748,21 @@ int mapLoadByName(char *fileName) {
740
748
strncpy (extension, " .SAV" , 5 );
741
749
742
750
const char *filePath = mapBuildPath (fileName);
751
+ // Check if .SAV map exists
743
752
744
- File *stream = fileOpen (filePath, " rb" );
753
+ // File *stream = fileOpen(filePath, "rb"); TODO saveload
745
754
746
755
strncpy (extension, " .MAP" , 5 );
747
756
748
- if (stream != NULL ) {
749
- fileClose (stream);
750
- rc = mapLoadSaved (fileName);
751
- wmMapMusicStart ();
752
- }
757
+ // if (stream != NULL) {
758
+ // fileClose(stream);
759
+ // rc = mapLoadSaved(fileName);
760
+ // wmMapMusicStart();
761
+ // }
753
762
}
754
763
755
764
if (rc == -1 ) {
765
+ debug (" .SAV map not found, looking for .MAP" );
756
766
const char *filePath = mapBuildPath (fileName);
757
767
File *stream = fileOpen (filePath, " rb" );
758
768
if (stream != NULL ) {
@@ -1201,6 +1211,8 @@ int mapHandleTransition() {
1201
1211
return 0 ;
1202
1212
}
1203
1213
1214
+ debug (" Doing map transition!" );
1215
+
1204
1216
gameMouseObjectsHide ();
1205
1217
1206
1218
gameMouseSetCursor (MOUSE_CURSOR_NONE);
@@ -1278,10 +1290,15 @@ static int _map_save() {
1278
1290
int rc = -1 ;
1279
1291
if (gMapHeader .name [0 ] != ' \0 ' ) {
1280
1292
char *mapFileName = mapBuildPath (gMapHeader .name );
1281
- File *stream = fileOpen (mapFileName, " wb" );
1293
+ Common::SaveFileManager *saveMan = g_system->getSavefileManager ();
1294
+
1295
+ Common::OutSaveFile *stream = saveMan->openForSaving (Common::String (mapFileName), false );
1296
+ // File *stream = fileOpen(mapFileName, "wb");
1282
1297
if (stream != NULL ) {
1283
1298
rc = _map_save_file (stream);
1284
- fileClose (stream);
1299
+ stream->finalize ();
1300
+ delete stream;
1301
+ // fileClose(stream);
1285
1302
} else {
1286
1303
snprintf (temp, sizeof (temp), " Unable to open %s to write!" , gMapHeader .name );
1287
1304
debugPrint (temp);
@@ -1299,7 +1316,7 @@ static int _map_save() {
1299
1316
}
1300
1317
1301
1318
// 0x483980
1302
- static int _map_save_file (File *stream) {
1319
+ static int _map_save_file (Common::OutSaveFile *stream) {
1303
1320
if (stream == NULL ) {
1304
1321
return -1 ;
1305
1322
}
@@ -1350,22 +1367,28 @@ static int _map_save_file(File *stream) {
1350
1367
mapHeaderWrite (&gMapHeader , stream);
1351
1368
1352
1369
if (gMapHeader .globalVariablesCount != 0 ) {
1353
- fileWriteInt32List (stream, gMapGlobalVars , gMapHeader .globalVariablesCount );
1370
+ for (int i = 0 ; i < gMapHeader .globalVariablesCount ; i++)
1371
+ stream->writeSint32BE (gMapGlobalVars [i]);
1372
+ // fileWriteInt32List(stream, gMapGlobalVars, gMapHeader.globalVariablesCount);
1354
1373
}
1355
1374
1356
1375
if (gMapHeader .localVariablesCount != 0 ) {
1357
- fileWriteInt32List (stream, gMapLocalVars , gMapHeader .localVariablesCount );
1376
+ for (int i = 0 ; i < gMapHeader .localVariablesCount ; i++)
1377
+ stream->writeSint32BE (gMapLocalVars [i]);
1378
+ // fileWriteInt32List(stream, gMapLocalVars, gMapHeader.localVariablesCount);
1358
1379
}
1359
1380
1360
1381
for (int elevation = 0 ; elevation < ELEVATION_COUNT; elevation++) {
1361
1382
if ((gMapHeader .flags & _map_data_elev_flags[elevation]) == 0 ) {
1362
- _db_fwriteLongCount (stream, _square[elevation]->field_0 , SQUARE_GRID_SIZE);
1383
+ for (int i = 0 ; i < SQUARE_GRID_SIZE; i++)
1384
+ stream->writeSint32BE (_square[elevation]->field_0 [i]);
1385
+ // _db_fwriteLongCount(stream, _square[elevation]->field_0, SQUARE_GRID_SIZE);
1363
1386
}
1364
1387
}
1365
1388
1366
1389
char err[80 ];
1367
1390
1368
- if (scriptSaveAll (stream) == -1 ) {
1391
+ /* if (scriptSaveAll(stream) == -1) { TODO saveload
1369
1392
snprintf(err, sizeof(err), "Error saving scripts in %s", gMapHeader.name);
1370
1393
_win_msg(err, 80, 80, _colorTable[31744]);
1371
1394
}
@@ -1374,7 +1397,7 @@ static int _map_save_file(File *stream) {
1374
1397
snprintf(err, sizeof(err), "Error saving objects in %s", gMapHeader.name);
1375
1398
_win_msg(err, 80, 80, _colorTable[31744]);
1376
1399
}
1377
-
1400
+ */
1378
1401
scriptsEnable ();
1379
1402
1380
1403
return 0 ;
@@ -1385,6 +1408,7 @@ int _map_save_in_game(bool a1) {
1385
1408
if (gMapHeader .name [0 ] == ' \0 ' ) {
1386
1409
return 0 ;
1387
1410
}
1411
+ debug (" Attempting map_save_in_game! a1 = %d" , a1);
1388
1412
1389
1413
animationStop ();
1390
1414
_partyMemberSaveProtos ();
@@ -1409,25 +1433,25 @@ int _map_save_in_game(bool a1) {
1409
1433
1410
1434
char name[16 ];
1411
1435
1412
- /* if (a1 && !wmMapIsSaveable()) { TODO world_map
1436
+ if (a1 && !wmMapIsSaveable ()) {
1413
1437
debugPrint (" \n Not saving RANDOM encounter map." );
1414
1438
1415
- strcpy (name, gMapHeader.name);
1439
+ strncpy (name, gMapHeader .name , sizeof (name) - 1 );
1416
1440
_strmfe (gMapHeader .name , name, " SAV" );
1417
1441
_MapDirEraseFile_ (" MAPS\\ " , gMapHeader .name );
1418
- strcpy (gMapHeader.name, name);
1442
+ strncpy (gMapHeader .name , name, sizeof ( gMapHeader . name ) - 1 );
1419
1443
} else {
1420
1444
debugPrint (" \n Saving \" .SAV\" map." );
1421
1445
1422
- strcpy (name, gMapHeader.name);
1446
+ strncpy (name, gMapHeader .name , sizeof (name) - 1 );
1423
1447
_strmfe (gMapHeader .name , name, " SAV" );
1424
1448
if (_map_save () == -1 ) {
1425
1449
return -1 ;
1426
1450
}
1427
1451
1428
- strcpy (gMapHeader.name, name);
1452
+ strncpy (gMapHeader .name , name, sizeof ( gMapHeader . name ) - 1 );
1429
1453
1430
- automapSaveCurrent();
1454
+ // automapSaveCurrent(); // TODO automap
1431
1455
1432
1456
if (a1) {
1433
1457
gMapHeader .name [0 ] = ' \0 ' ;
@@ -1436,7 +1460,7 @@ int _map_save_in_game(bool a1) {
1436
1460
_square_reset ();
1437
1461
gameTimeScheduleUpdateEvent ();
1438
1462
}
1439
- } */
1463
+ }
1440
1464
1441
1465
return 0 ;
1442
1466
}
@@ -1680,33 +1704,51 @@ static int _square_load(File *stream, int flags) {
1680
1704
}
1681
1705
1682
1706
// 0x4843B8
1683
- static int mapHeaderWrite (MapHeader *ptr, File *stream) {
1684
- if (fileWriteInt32 (stream, ptr->version ) == -1 )
1685
- return -1 ;
1686
- if (fileWriteFixedLengthString (stream, ptr->name , 16 ) == -1 )
1687
- return -1 ;
1688
- if (fileWriteInt32 (stream, ptr->enteringTile ) == -1 )
1689
- return -1 ;
1690
- if (fileWriteInt32 (stream, ptr->enteringElevation ) == -1 )
1691
- return -1 ;
1692
- if (fileWriteInt32 (stream, ptr->enteringRotation ) == -1 )
1693
- return -1 ;
1694
- if (fileWriteInt32 (stream, ptr->localVariablesCount ) == -1 )
1695
- return -1 ;
1696
- if (fileWriteInt32 (stream, ptr->scriptIndex ) == -1 )
1697
- return -1 ;
1698
- if (fileWriteInt32 (stream, ptr->flags ) == -1 )
1699
- return -1 ;
1700
- if (fileWriteInt32 (stream, ptr->darkness ) == -1 )
1701
- return -1 ;
1702
- if (fileWriteInt32 (stream, ptr->globalVariablesCount ) == -1 )
1703
- return -1 ;
1704
- if (fileWriteInt32 (stream, ptr->field_34 ) == -1 )
1705
- return -1 ;
1706
- if (fileWriteInt32 (stream, ptr->lastVisitTime ) == -1 )
1707
- return -1 ;
1708
- if (fileWriteInt32List (stream, ptr->field_3C , 44 ) == -1 )
1709
- return -1 ;
1707
+ static int mapHeaderWrite (MapHeader *ptr, Common::OutSaveFile *stream) {
1708
+ int i;
1709
+
1710
+ stream->writeSint32BE (ptr->version );
1711
+ for (i = 0 ; i < 16 ; i++)
1712
+ stream->writeByte (ptr->name [i]);
1713
+ stream->writeSint32BE (ptr->enteringTile );
1714
+ stream->writeSint32BE (ptr->enteringElevation );
1715
+ stream->writeSint32BE (ptr->enteringRotation );
1716
+ stream->writeSint32BE (ptr->localVariablesCount );
1717
+ stream->writeSint32BE (ptr->scriptIndex );
1718
+ stream->writeSint32BE (ptr->flags );
1719
+ stream->writeSint32BE (ptr->darkness );
1720
+ stream->writeSint32BE (ptr->globalVariablesCount );
1721
+ stream->writeSint32BE (ptr->field_34 );
1722
+ stream->writeSint32BE (ptr->lastVisitTime );
1723
+ for (i = 0 ; i < 44 ; i++)
1724
+ stream->writeByte (ptr->field_3C [i]);
1725
+
1726
+ /* if (fileWriteInt32(stream, ptr->version) == -1)
1727
+ return -1;
1728
+ if (fileWriteFixedLengthString(stream, ptr->name, 16) == -1)
1729
+ return -1;
1730
+ if (fileWriteInt32(stream, ptr->enteringTile) == -1)
1731
+ return -1;
1732
+ if (fileWriteInt32(stream, ptr->enteringElevation) == -1)
1733
+ return -1;
1734
+ if (fileWriteInt32(stream, ptr->enteringRotation) == -1)
1735
+ return -1;
1736
+ if (fileWriteInt32(stream, ptr->localVariablesCount) == -1)
1737
+ return -1;
1738
+ if (fileWriteInt32(stream, ptr->scriptIndex) == -1)
1739
+ return -1;
1740
+ if (fileWriteInt32(stream, ptr->flags) == -1)
1741
+ return -1;
1742
+ if (fileWriteInt32(stream, ptr->darkness) == -1)
1743
+ return -1;
1744
+ if (fileWriteInt32(stream, ptr->globalVariablesCount) == -1)
1745
+ return -1;
1746
+ if (fileWriteInt32(stream, ptr->field_34) == -1)
1747
+ return -1;
1748
+ if (fileWriteInt32(stream, ptr->lastVisitTime) == -1)
1749
+ return -1;
1750
+ if (fileWriteInt32List(stream, ptr->field_3C, 44) == -1)
1751
+ return -1;*/
1710
1752
1711
1753
return 0 ;
1712
1754
}
0 commit comments