forked from 1dot13/source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveLoadGame.cpp
9964 lines (8342 loc) · 373 KB
/
SaveLoadGame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Types.h"
#include "Soldier Profile.h"
#include "FileMan.h"
#include <string.h>
#include <stdio.h>
#include "Debug.h"
#include "OverHead.h"
#include "Keys.h"
#include "finances.h"
#include "History.h"
#include "files.h"
#include "Laptop.h"
#include "iniReader.h"
#include "Email.h"
#include "Strategicmap.h"
#include "Game Events.h"
#include "Game Clock.h"
#include "Soldier Create.h"
#include "WorldDef.h"
#include "LaptopSave.h"
#include "strategicmap.h"
#include "Queen Command.h"
#include "SaveLoadGame.h"
#include "Tactical Save.h"
#include "Squads.h"
#include "Environment.h"
#include "Lighting.h"
#include "Strategic Movement.h"
#include "Strategic.h"
#include "Isometric Utils.h"
#include "Quests.h"
#include "opplist.h"
#include "message.h"
#include "NPC.h"
#include "Merc Hiring.h"
#include "SaveLoadScreen.h"
#include "GameVersion.h"
#include "GameSettings.h"
#include "Music Control.h"
#include "Options Screen.h"
#include "Ai.h"
#include "RenderWorld.h"
#include "SmokeEffects.h"
#include "Random.h"
#include "Map Screen Interface.h"
#include "Map Screen Interface Border.h"
#include "Map Screen Interface Bottom.h"
#include "Interface.h"
#include "Map Screen Helicopter.h"
#include "Environment.h"
#include "Arms Dealer Init.h"
#include "Tactical Placement GUI.h"
#include "Strategic Mines.h"
#include "Strategic Town Loyalty.h"
#include "Vehicles.h"
#include "Merc Contract.h"
#include "Bullets.h"
#include "air raid.h"
#include "physics.h"
#include "Strategic Pathing.h"
#include "TeamTurns.h"
#include "explosion control.h"
#include "Creature Spreading.h"
#include "Strategic Status.h"
#include "Prebattle Interface.h"
#include "Boxing.h"
#include "Strategic AI.h"
#include "Map Screen Interface Map.h"
#include "Meanwhile.h"
#include "dialogue control.h"
#include "text.h"
#include "Map Screen Interface.h"
#include "lighteffects.h"
#include "HelpScreen.h"
#include "Animated ProgressBar.h"
#include "merctextbox.h"
#include "render dirty.h"
#include "Map Information.h"
#include "Interface Items.h"
#include "Civ Quotes.h"
#include "Scheduling.h"
#include "Animation Data.h"
#include "Game Init.h"
#include "cheats.h"
#include "Strategic Event Handler.h"
#include "interface panels.h"
#include "interface dialogue.h"
#include "Assignments.h"
#include "Interface Items.h"
#include "Shopkeeper Interface.h"
#include "postalservice.h"
// HEADROCK HAM B1: Additional Include for HAM
#include "MilitiaSquads.h"
// HEADROCK HAM 3.5: Another include for HAM
#include "Facilities.h"
// HEADROCK HAM 3.6: Yet another include, goddammit
#include "Town Militia.h"
#include "Items.h"
#include "Encyclopedia_new.h"
#include "CampaignStats.h" // added by Flugente
#include "DynamicDialogue.h" // added by Flugente
#include "PMC.h" // added by Flugente
#include "ASD.h" // added by Flugente
#include "MilitiaIndividual.h" // added by Flugente
#include "Rebel Command.h"
#include "BobbyR.h"
#include "Imp Portraits.h"
#include "Loading Screen.h"
#include "Interface Utils.h"
#include "Squads.h"
#include "IMP Confirm.h"
#include "Enemy Soldier Save.h"
#include "BobbyRMailOrder.h"
#include "Mercs.h"
#include "INIReader.h"
#include "mercs.h"
#include "soldier Profile.h"
#ifdef JA2UB
#include "Ja25 Strategic Ai.h"
#include "Ja25_Tactical.h"
#endif
#include "LuaInitNPCs.h"
#include "Vehicles.h"
#include "BriefingRoom_Data.h"
#include <vfs/Core/vfs.h>
//rain
//end rain
#include "connect.h"
#include "Map Screen Interface Map Inventory.h"//dnl ch51 081009
#include "Sys Globals.h"//dnl ch74 201013
#include "Ambient Control.h" // added by Flugente for HandleNewSectorAmbience(...)
/////////////////////////////////////////////////////
//
// Local Defines
//
/////////////////////////////////////////////////////
#ifdef JA2UB
#include "Strategic Movement.h"
#include "LuaInitNPCs.h"
#include "ub_config.h"
#include "Ja25Update.h"
#endif
#include "LuaInitNPCs.h"
#ifdef JA2UB
//void ConvertWeapons( SOLDIERTYPE *pSoldier );
extern void MakeBadSectorListFromMapsOnHardDrive( BOOLEAN fDisplayMessages ); // ja25 UB
#endif
void GetBestPossibleSectorXYZValues( INT16 *psSectorX, INT16 *psSectorY, INT8 *pbSectorZ );
extern void NextLoopCheckForEnoughFreeHardDriveSpace();
extern void UpdatePersistantGroupsFromOldSave( UINT32 uiSavedGameVersion );
extern void TrashAllSoldiers( );
extern void ResetJA2ClockGlobalTimers( void );
extern void BeginLoadScreen( void );
extern void EndLoadScreen();
extern CPostalService gPostalService;
extern void initMapViewAndBorderCoordinates(void);
//Global variable used
#ifdef JA2BETAVERSION
UINT32 guiNumberOfMapTempFiles; //Test purposes
UINT32 guiSizeOfTempFiles;
CHAR gzNameOfMapTempFile[128];
#endif
//#define LOADSAVEGAME_LOGTIME 1
#ifdef LOADSAVEGAME_LOGTIME
#include "TimeLogging.h"
#endif
extern SOLDIERTYPE *gpSMCurrentMerc;
extern INT32 giSortStateForMapScreenList;
extern INT16 sDeadMercs[ NUMBER_OF_SQUADS ][ NUMBER_OF_SOLDIERS_PER_SQUAD ];
extern INT32 giRTAILastUpdateTime;
extern BOOLEAN gfRedrawSaveLoadScreen;
extern UINT8 gubScreenCount;
extern INT16 sWorldSectorLocationOfFirstBattle;
extern BOOLEAN gfGamePaused;
extern BOOLEAN gfLockPauseState;
extern BOOLEAN gfLoadedGame;
extern HELP_SCREEN_STRUCT gHelpScreen;
extern UINT8 gubDesertTemperature;
extern UINT8 gubGlobalTemperature;
extern BOOLEAN gfCreatureMeanwhileScenePlayed;
#ifdef JA2BETAVERSION
extern UINT8 gubReportMapscreenLock;
#endif
BOOLEAN gMusicModeToPlay = FALSE;
//extern BOOLEAN gfFirstTimeInGameHeliCrash;
#ifdef JA2BETAVERSION
BOOLEAN gfDisplaySaveGamesNowInvalidatedMsg = FALSE;
#endif
BOOLEAN gfUseConsecutiveQuickSaveSlots = FALSE;
UINT32 guiCurrentQuickSaveNumber = 0;
UINT32 guiLastSaveGameNum = 1;
BOOLEAN DoesAutoSaveFileExist( BOOLEAN fLatestAutoSave );
UINT32 guiJA2EncryptionSet = 0;
UINT32 CalcJA2EncryptionSet( SAVED_GAME_HEADER * pSaveGameHeader );
typedef struct
{
//The screen that the gaem was saved from
UINT32 uiCurrentScreen;
UINT32 uiCurrentUniqueSoldierId;
//The music that was playing when the game was saved
UINT8 ubMusicMode;
//Flag indicating that we have purchased something from Tony
BOOLEAN fHavePurchasedItemsFromTony;
//The selected soldier in tactical
UINT16 usSelectedSoldier;
// The x and y scroll position
INT16 sRenderCenterX;
INT16 sRenderCenterY;
BOOLEAN fAtLeastOneMercWasHired;
//General Map screen state flags
BOOLEAN fShowItemsFlag;
BOOLEAN fShowTownFlag;
BOOLEAN fShowTeamFlag;
BOOLEAN fShowMineFlag;
UINT8 usMapDisplayColourMode;
BOOLEAN filler1; // Flugente: unused
// is the helicopter available to player?
BOOLEAN fHelicopterAvailable;
// helicopter vehicle id
INT32 iHelicopterVehicleId;
// total distance travelled
INT32 iTotalHeliDistanceSinceRefuel;
// total owed to player
INT32 iTotalAccumulatedCostByPlayer;
// whether or not skyrider is alive and well? and on our side yet?
BOOLEAN fSkyRiderAvailable;
// skyrider engaging in a monologue
BOOLEAN UNUSEDfSkyriderMonologue;
// list of sector locations
INT16 UNUSED[ 2 ][ 2 ];
// is the heli in the air?
BOOLEAN fHelicopterIsAirBorne;
// is the pilot returning straight to base?
BOOLEAN fHeliReturnStraightToBase;
// heli hovering
BOOLEAN fHoveringHelicopter;
// time started hovering
UINT32 uiStartHoverTime;
// what state is skyrider's dialogue in in?
UINT32 uiHelicopterSkyriderTalkState;
// the flags for skyrider events
BOOLEAN fShowEstoniRefuelHighLight;
BOOLEAN fShowOtherSAMHighLight;
BOOLEAN fShowDrassenSAMHighLight;
UINT32 uiEnvWeather; // Flugente: unused
UINT8 ubDefaultButton;
BOOLEAN fSkyriderEmptyHelpGiven;
BOOLEAN fEnterMapDueToContract;
UINT8 ubHelicopterHitsTaken;
UINT8 ubQuitType;
BOOLEAN fSkyriderSaidCongratsOnTakingSAM;
INT16 sContractRehireSoldierID;
GAME_OPTIONS GameOptions;
UINT32 uiSeedNumber;
//The GetJA2Clock() value
UINT32 uiBaseJA2Clock;
INT16 sCurInterfacePanel;
UINT8 ubSMCurrentMercID;
BOOLEAN fFirstTimeInMapScreen;
BOOLEAN fDisableDueToBattleRoster;
BOOLEAN fDisableMapInterfaceDueToBattle;
INT32 sBoxerGridNo[ NUM_BOXERS ];
UINT8 ubBoxerID[ NUM_BOXERS ];
BOOLEAN fBoxerFought[ NUM_BOXERS ];
BOOLEAN fHelicopterDestroyed; //if the chopper is destroyed
BOOLEAN fShowMapScreenHelpText; //If true, displays help in mapscreen
INT32 iSortStateForMapScreenList;
BOOLEAN fFoundTixa;
UINT32 uiTimeOfLastSkyriderMonologue;
BOOLEAN fShowCambriaHospitalHighLight;
BOOLEAN fSkyRiderSetUp;
BOOLEAN fRefuelingSiteAvailable[ MAX_NUMBER_OF_REFUEL_SITES ];
//Meanwhile stuff
MEANWHILE_DEFINITION gCurrentMeanwhileDef;
BOOLEAN ubPlayerProgressSkyriderLastCommentedOn;
BOOLEAN gfMeanwhileTryingToStart;
BOOLEAN gfInMeanwhile;
// list of dead guys for squads...in id values->-1 means no one home
INT16 sDeadMercs[ NUMBER_OF_SQUADS ][ NUMBER_OF_SOLDIERS_PER_SQUAD ];
// levels of publicly known noises
INT8 gbPublicNoiseLevel[MAXTEAMS];
UINT8 gubScreenCount;
UINT16 usOldMeanWhileFlags;
INT32 iPortraitNumber;
INT16 sWorldSectorLocationOfFirstBattle;
BOOLEAN fUnReadMailFlag;
BOOLEAN fNewMailFlag;
BOOLEAN fOldUnReadFlag;
BOOLEAN fOldNewMailFlag;
BOOLEAN fShowMilitia;
BOOLEAN fNewFilesInFileViewer;
BOOLEAN fLastBoxingMatchWonByPlayer;
UINT32 uiUNUSED;
BOOLEAN fSamSiteFound[ MAX_NUMBER_OF_SAMS ];
UINT8 ubNumTerrorists;
UINT8 ubCambriaMedicalObjects;
BOOLEAN fDisableTacticalPanelButtons;
INT16 sSelMapX;
INT16 sSelMapY;
INT32 iCurrentMapSectorZ;
UINT16 usHasPlayerSeenHelpScreenInCurrentScreen;
BOOLEAN fHideHelpInAllScreens;
UINT8 ubBoxingMatchesWon;
UINT8 ubBoxersRests;
BOOLEAN fBoxersResting;
UINT8 ubDesertTemperature;
UINT8 ubGlobalTemperature;
INT16 sMercArriveSectorX;
INT16 sMercArriveSectorY;
BOOLEAN fCreatureMeanwhileScenePlayed;
UINT8 ubPlayerNum;
//New stuff for the Prebattle interface / autoresolve
BOOLEAN fPersistantPBI;
UINT8 ubEnemyEncounterCode;
BOOLEAN ubExplicitEnemyEncounterCode;
BOOLEAN fBlitBattleSectorLocator;
UINT8 ubPBSectorX;
UINT8 ubPBSectorY;
UINT8 ubPBSectorZ;
BOOLEAN fCantRetreatInPBI;
BOOLEAN fExplosionQueueActive;
UINT8 ubUnused[1];
UINT32 uiMeanWhileFlags;
INT8 bSelectedInfoChar;
INT8 bHospitalPriceModifier;
INT8 bUnused2[ 2 ];
INT32 iHospitalTempBalance;
INT32 iHospitalRefund;
INT8 fPlayerTeamSawJoey;
INT8 fMikeShouldSayHi;
// HEADROCK HAM 3.6: New global variable that tracks money owed for facility use.
INT32 iTotalOwedForFacilityOperationsToday;
// HEADROCK HAM 3.6: Now saving Skyrider Cost Modifier variable;
INT16 sSkyriderCostModifier;
// HEADROCK HAM 3.6: New global variable indicating whether we owe cash for facility work.
BOOLEAN fOutstandingFacilityDebt;
// HEADROCK HAM 3.6: Global variable keeping track of Militia Upkeep Costs at last midnight.
UINT32 uiTotalUpkeepForMilitia;
UINT32 sMercArrivalGridNo;
//JA25 UB
#ifdef JA2UB
INT8 fMorrisShouldSayHi;
BOOLEAN fFirstTimeInGameHeliCrash;
UINT32 sINITIALHELIGRIDNO[ 7 ];
UINT32 sLOCATEGRIDNO;
UINT32 sLOCATEGRIDNO2;
UINT32 sJerryGridNo;
BOOLEAN sJerryQuotes;
BOOLEAN sInJerry;
BOOLEAN sInGameHeliCrash;
BOOLEAN sLaptopQuestEnabled;
BOOLEAN sTEX_AND_JOHN;
BOOLEAN sRandom_Manuel_Text;
BOOLEAN sEVENT_ATTACK_INITIAL_SECTOR_IF_PLAYER_STILL_THERE_UB;
BOOLEAN sHandleAddingEnemiesToTunnelMaps_UB;
BOOLEAN sInGameHeli;
BOOLEAN spJA2UB;
BOOLEAN sfDeadMerc;
UINT8 subEndDefaultSectorX;
UINT8 subEndDefaultSectorY;
UINT8 subEndDefaultSectorZ;
BOOLEAN sTestUB;
BOOLEAN sLaptopLinkInsurance;
BOOLEAN sLaptopLinkFuneral;
BOOLEAN sLaptopLinkBobby;
BOOLEAN ubFiller2[255];
UINT32 ubFiller3[255];
INT8 ubFiller4[255];
#endif
// Flugente: was mobile restriction, now it's just a filler
UINT8 ubFiller1[256];
BOOLEAN HiddenNames[500]; //legion by Jazz
// anv: amount of hours to repair completion
UINT8 ubHelicopterHoursToRepair;
UINT8 ubHelicopterBasicRepairsSoFar;
UINT8 ubHelicopterSeriousRepairsSoFar;
UINT8 ubHelicopterHoverTime;
UINT8 ubHelicopterTimeToFullRefuel;
// Buggler: New global variable that tracks money earned for facility use.
INT32 iTotalEarnedForFacilityOperationsToday;
UINT8 filler2; // Flugente: unused
UINT8 ubFiller[265]; //This structure should be 1588 bytes
} GENERAL_SAVE_INFO;
UINT32 guiCurrentSaveGameVersion = SAVE_GAME_VERSION;
/////////////////////////////////////////////////////
//
// Global Variables
//
/////////////////////////////////////////////////////
//CHAR8 gsSaveGameNameWithPath[ 512 ];
CHAR8 gSaveDir[ MAX_PATH ]; // Snap: Initilized by InitSaveDir
UINT8 gubSaveGameLoc=0;
UINT32 guiScreenToGotoAfterLoadingSavedGame = 0;
extern EmailPtr pEmailList;
extern UINT32 guiCurrentUniqueSoldierId;
extern BOOLEAN gfHavePurchasedItemsFromTony;
/////////////////////////////////////////////////////
//
// Function Prototypes
//
/////////////////////////////////////////////////////
BOOLEAN SaveMercProfiles( HWFILE hFile );
BOOLEAN LoadSavedMercProfiles( HWFILE hwFile );
BOOLEAN SaveSoldierStructure( HWFILE hFile );
BOOLEAN LoadSoldierStructure( HWFILE hFile );
// CHRISL: New functions to save and load LBENODE data
BOOLEAN SaveLBENODEToSaveGameFile( HWFILE hFile );
BOOLEAN LoadLBENODEFromSaveGameFile( HWFILE hFile );
//BOOLEAN SavePtrInfo( PTR *pData, UINT32 uiSizeOfObject, HWFILE hFile );
//BOOLEAN LoadPtrInfo( PTR *pData, UINT32 uiSizeOfObject, HWFILE hFile );
BOOLEAN SaveEmailToSavedGame( HWFILE hFile );
BOOLEAN LoadEmailFromSavedGame( HWFILE hFile );
BOOLEAN SaveTacticalStatusToSavedGame( HWFILE hFile );
BOOLEAN LoadTacticalStatusFromSavedGame( HWFILE hFile );
BOOLEAN SetMercsInsertionGridNo( );
BOOLEAN LoadOppListInfoFromSavedGame( HWFILE hFile );
BOOLEAN SaveOppListInfoToSavedGame( HWFILE hFile );
BOOLEAN LoadMercPathToSoldierStruct( HWFILE hFilem, UINT8 ubID );
BOOLEAN SaveMercPathFromSoldierStruct( HWFILE hFilem, UINT8 ubID );
BOOLEAN LoadGeneralInfo( HWFILE hFile );
BOOLEAN SaveGeneralInfo( HWFILE hFile );
BOOLEAN SavePreRandomNumbersToSaveGameFile( HWFILE hFile );
BOOLEAN LoadPreRandomNumbersFromSaveGameFile( HWFILE hFile );
BOOLEAN SaveWatchedLocsToSavedGame( HWFILE hFile );
BOOLEAN LoadWatchedLocsFromSavedGame( HWFILE hFile );
BOOLEAN LoadMeanwhileDefsFromSaveGameFile( HWFILE hFile );
BOOLEAN SaveMeanwhileDefsFromSaveGameFile( HWFILE hFile );
void PauseBeforeSaveGame( void );
void UnPauseAfterSaveGame( void );
void UpdateMercMercContractInfo();
void HandleOldBobbyRMailOrders();
//ppp
#ifdef JA2BETAVERSION
void InitSaveGameFilePosition();
void InitLoadGameFilePosition();
void SaveGameFilePosition( INT32 iPos, STR pMsg );
void LoadGameFilePosition( INT32 iPos, STR pMsg );
void WriteTempFileNameToFile( STR pFileName, UINT32 uiSizeOfFile, HFILE hSaveFile );
void InitShutDownMapTempFileTest( BOOLEAN fInit, STR pNameOfFile, UINT8 ubSaveGameID );
#endif
#ifdef JA2BETAVERSION
extern BOOLEAN ValidateSoldierInitLinks( UINT8 ubCode );
#endif
void ValidateStrategicGroups();
/////////////////////////////////////////////////////
//
// Functions
//
/////////////////////////////////////////////////////
//ADB
//Some notes on saving and loading functions:
//some of these classes are saved in 2 places, in the savegame and in the sector file
//when this happens, the class data saved to the sector file is not encrypted,
//while the savegame may or may not be, this is why there is a bool for save.
//to load from a sector, the data is first loaded in one fell swoop and put in a buffer
//then, each class's data is read from the buffer, so it needs a function that takes a buffer not a file
//this function can automatically assume it is reading non encrypted data
//the regular loading function may or may not be reading encrypted data
//but that is determined on a class by class basis
//when saving encrypted data there is only one new function,
//but there are 2 loading functions to support really old versions
//the encryption set is determined by the savegame header, so make sure
//that saving and loading are logically mirrors, or when changing
//savegame versions you'll try decrypting it differently
//some class's structure have changed. for these, there is a conversion that needs to take place
//the savegame version is read and the data loaded accordingly, then converted
//load once, convert as many times as necessary
//when changing the structure of some class, check if it is someplace in
//LoadWorld, if it is, you've got to rebuild the maps
//if all that sounds compilcated, it is
extern int gLastLBEUniqueID;
/*
// CHRISL: New function to save/load LBENODE data
BOOLEAN SaveLBENODEToSaveGameFile( HWFILE hFile )
{
UINT32 uiNumBytesWritten;
if ( !FileWrite( hFile, &gLastLBEUniqueID, sizeof(int), &uiNumBytesWritten ) )
{
return(FALSE);
}
return TRUE;
}
BOOLEAN LoadLBENODEFromSaveGameFile( HWFILE hFile )
{
UINT32 uiNumBytesRead;
if ( !FileRead( hFile, &gLastLBEUniqueID, sizeof(int), &uiNumBytesRead ) )
{
return(FALSE);
}
return TRUE;
}
*/
BOOLEAN LBENODE::Load( HWFILE hFile )
{
UINT32 uiNumBytesRead;
//if we are at the most current version, then fine
if ( guiCurrentSaveGameVersion >= NIV_SAVEGAME_DATATYPE_CHANGE )
{
if ( !FileRead( hFile, this, SIZEOF_LBENODE_POD, &uiNumBytesRead ) )
{
return(FALSE);
}
if (uniqueID >= gLastLBEUniqueID) {
//can happen because of the order things are saved and loaded,
//when combined with copy assignment which makes a new LBENODE
gLastLBEUniqueID = uniqueID + 1;
}
int size;
if ( !FileRead( hFile, &size, sizeof(int), &uiNumBytesRead ) )
{
return(FALSE);
}
inv.resize(size);
for (std::vector<OBJECTTYPE>::iterator iter = inv.begin(); iter != inv.end(); ++iter) {
if (! iter->Load(hFile)) {
return FALSE;
}
}
}
else
{
//we shouldn't be loading from anything before the first change
AssertGE(guiCurrentSaveGameVersion, NIV_SAVEGAME_DATATYPE_CHANGE);
}
return TRUE;
}
BOOLEAN LBENODE::Load( INT8** hBuffer, float dMajorMapVersion, UINT8 ubMinorMapVersion )
{
if (dMajorMapVersion >= 6.0 && ubMinorMapVersion > 26 ) {
LOADDATA( this, *hBuffer, SIZEOF_LBENODE_POD );
if (uniqueID >= gLastLBEUniqueID) {
//can happen because of the order things are saved and loaded,
//when combined with copy assignment which makes a new LBENODE
gLastLBEUniqueID = uniqueID + 1;
}
int size;
LOADDATA( &size, *hBuffer, sizeof(int) );
inv.resize(size);
for (std::vector<OBJECTTYPE>::iterator iter = inv.begin(); iter != inv.end(); ++iter) {
iter->Load(hBuffer, dMajorMapVersion, ubMinorMapVersion);
}
}
else {
AssertGE(guiCurrentSaveGameVersion, NIV_SAVEGAME_DATATYPE_CHANGE);
}
return TRUE;
}
BOOLEAN LBENODE::Save( HWFILE hFile, bool fSavingMap )
{
UINT32 uiNumBytesWritten;
int size = inv.size();
if ( !FileWrite( hFile, this, SIZEOF_LBENODE_POD, &uiNumBytesWritten ) )
{
return(FALSE);
}
if ( !FileWrite( hFile, &size, sizeof(int), &uiNumBytesWritten ) )
{
return(FALSE);
}
for (std::vector<OBJECTTYPE>::iterator iter = inv.begin(); iter != inv.end(); ++iter) {
//we are not saving to a map, at least not yet
if (! iter->Save(hFile, false)) {
return FALSE;
}
}
return TRUE;
}
BOOLEAN LoadArmsDealerInventoryFromSavedGameFile( HWFILE hFile )
{
UINT32 uiNumBytesRead;
UINT8 ubArmsDealer;
UINT16 usItemIndex;
//Free all the dealers special inventory arrays
ShutDownArmsDealers();
if (guiCurrentSaveGameVersion >= NIV_SAVEGAME_DATATYPE_CHANGE)
{
int dealers;
if (!FileRead( hFile, &dealers, sizeof( int ), &uiNumBytesRead ))
{
return( FALSE );
}
// Flugente: regardless of the number of dealers in the old save, we need this to have the proper size from now on
gArmsDealersInventory.resize( NUM_ARMS_DEALERS );
if ( guiCurrentSaveGameVersion >= NONPROFILE_MERCHANTS )
{
if ( !FileRead( hFile, gArmsDealerStatus, sizeof(gArmsDealerStatus), &uiNumBytesRead ) )
{
return(FALSE);
}
}
else
{
// Flugente: as we increased the number of dealers, we can only read part of the array
if ( !FileRead( hFile, gArmsDealerStatus, sizeof(ARMS_DEALER_STATUS) * 40, &uiNumBytesRead ) )
{
return(FALSE);
}
}
//loop through all the dealers inventories
for( ubArmsDealer=0; ubArmsDealer<dealers; ++ubArmsDealer )
{
int size;
if (!FileRead( hFile, &size, sizeof( int ), &uiNumBytesRead ))
{
return( FALSE );
}
gArmsDealersInventory[ubArmsDealer].resize(size);
//loop through this dealer's individual items
DealerItemList::iterator iterend = gArmsDealersInventory[ubArmsDealer].end( );
for (DealerItemList::iterator iter = gArmsDealersInventory[ubArmsDealer].begin(); iter != iterend; ++iter )
{
if (! iter->Load(hFile) )
{
return FALSE;
}
//CHRISL: Because of the "100rnd" bug that Tony is experiencing, lets look at each item as we create it. If the
// item is ammo, reset the bItemCondition value to equal the number of rounds. Hopefully this will be unneccessary
// but for the time being, it may help to alleviate the "100rnd" bug.
if(Item[iter->object.usItem].usItemClass == IC_AMMO)
{
// Flugente: this condition is unnecessary, as we afterwards make sure that iter->bItemCondition = iter->object[0]->data.ubShotsLeft anyway
//This condition should catch any dealer ammo items that have both invalid bItemCondition and ubShotsLeft values.
// We'll only make bItemCondition valid at this point. Let the next condition correct ubShotsLeft.
/*if( iter->bItemCondition > Magazine[Item[iter->object.usItem].ubClassIndex].ubMagSize)
{
iter->bItemCondition = Magazine[Item[iter->object.usItem].ubClassIndex].ubMagSize;
}*/
//This condition should catch any dealer ammo items that have an invalid bItemCondition assuming ubShotsLeft is valid
if(iter->bItemCondition != iter->object[0]->data.ubShotsLeft)
{
iter->bItemCondition = iter->object[0]->data.ubShotsLeft;
}
}
}
}
}
else
{
//the format has changed and needs to be updated
OLD_ARMS_DEALER_STATUS_101 gOldArmsDealerStatus[NUM_ARMS_DEALERS];
//OLD_DEALER_ITEM_HEADER_101 gOldArmsDealersInventory[NUM_ARMS_DEALERS][MAXITEMS];
//pointer to an array of OLD_DEALER_ITEM_HEADER_101 that is sized [NUM_ARMS_DEALERS][MAXITEMS]
typedef OLD_DEALER_ITEM_HEADER_101(*pointerToArmsDealersInventoryArray)[NUM_ARMS_DEALERS][MAXITEMS];
pointerToArmsDealersInventoryArray pOldArmsDealersInventory
= (pointerToArmsDealersInventoryArray) new OLD_DEALER_ITEM_HEADER_101[NUM_ARMS_DEALERS][MAXITEMS];
// Elgin was added to the dealers list in Game Version #54, enlarging these 2 tables...
// Manny was added to the dealers list in Game Version #55, enlarging these 2 tables...
bool fIncludesElgin = guiCurrentSaveGameVersion >= 54;
bool fIncludesManny = guiCurrentSaveGameVersion >= 55;
UINT32 uiDealersSaved;
if (fIncludesElgin && fIncludesManny ){
uiDealersSaved = NUM_ORIGINAL_ARMS_DEALERS;
}
else if ( !fIncludesElgin ) {
// read 2 fewer element without Elgin or Manny in there...
uiDealersSaved = NUM_ORIGINAL_ARMS_DEALERS - 2;
}
else {
// read one fewer element without Elgin in there...
uiDealersSaved = NUM_ORIGINAL_ARMS_DEALERS - 1;
}
gArmsDealersInventory.resize(uiDealersSaved);
if (!FileRead( hFile, gOldArmsDealerStatus, uiDealersSaved * sizeof( OLD_ARMS_DEALER_STATUS_101 ), &uiNumBytesRead ))
{
return( FALSE );
}
if (!FileRead( hFile, (*pOldArmsDealersInventory), uiDealersSaved * sizeof( OLD_DEALER_ITEM_HEADER_101 ) * MAXITEMS, &uiNumBytesRead ))
{
return( FALSE );
}
if ( !fIncludesElgin ) {
// initialize Elgin now...
InitializeOneArmsDealer( ARMS_DEALER_ELGIN );
}
if ( !fIncludesManny ) {
// initialize Manny now...
InitializeOneArmsDealer( ARMS_DEALER_MANNY );
}
OLD_DEALER_SPECIAL_ITEM_101 oldSpecial;
DEALER_SPECIAL_ITEM loadedSpecial;
//loop through all the dealers inventories
for( ubArmsDealer=0; ubArmsDealer<uiDealersSaved; ++ubArmsDealer )
{
gArmsDealerStatus[ubArmsDealer] = gOldArmsDealerStatus[ubArmsDealer];
//loop through this dealer's individual items
for ( usItemIndex = 1; usItemIndex < gMAXITEMS_READ; ++usItemIndex )
{
//some things are much much better stored in status now
gArmsDealerStatus[ubArmsDealer].fPreviouslyEligible[usItemIndex] = (*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].fPreviouslyEligible;
gArmsDealerStatus[ubArmsDealer].ubStrayAmmo[usItemIndex] = (*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubStrayAmmo;
//if there are any perfect items, insert them immediately
if ((*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubPerfectItems)
{
gArmsDealersInventory[ubArmsDealer].push_back(DEALER_SPECIAL_ITEM());
DEALER_SPECIAL_ITEM* pPerfectItem = &gArmsDealersInventory[ubArmsDealer].back();
CreateObjectForDealer(usItemIndex, 100, (*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubPerfectItems, &pPerfectItem->object);
//cannot set to 100, could be ammo
pPerfectItem->bItemCondition = pPerfectItem->object[0]->data.objectStatus;
}
//if there are any items on order, order them
if ((*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubQtyOnOrder)
{
OrderDealerItems(ubArmsDealer, usItemIndex,
(*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubQtyOnOrder,
(*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].uiOrderArrivalTime);
}
//if there are any special elements allocated for this item, load them
for ( int x = 0; x < (*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex].ubElementsAlloced; ++x)
{
if (!FileRead( hFile, &oldSpecial, sizeof( OLD_DEALER_SPECIAL_ITEM_101 ), &uiNumBytesRead ))
{
return( FALSE );
}
//not all elements alloced are full, some are empty!
//convert and add to arms dealer list (if applicable)
loadedSpecial.ConvertFrom101((*pOldArmsDealersInventory)[ubArmsDealer][usItemIndex], oldSpecial, ubArmsDealer, usItemIndex);
}
}
}
delete [] pOldArmsDealersInventory;
}
// we need to refresh our selection at this point, as lua data may depend on campaign specifics
HandlePossibleArmsDealerIntelRefresh( TRUE );
return( TRUE );
}
BOOLEAN DEALER_SPECIAL_ITEM::Save(HWFILE hFile)
{
UINT32 uiNumBytesWritten;
if ( !FileWrite( hFile, this, SIZEOF_DEALER_SPECIAL_ITEM_POD, &uiNumBytesWritten ) )
{
return FALSE;
}
if ( !this->object.Save(hFile, FALSE) )
{
return FALSE;
}
return TRUE;
}
BOOLEAN DEALER_SPECIAL_ITEM::Load(HWFILE hFile)
{
UINT32 uiNumBytesRead;
//if we are at the most current version, then fine
if ( guiCurrentSaveGameVersion >= NIV_SAVEGAME_DATATYPE_CHANGE )
{
if ( !FileRead( hFile, this, SIZEOF_DEALER_SPECIAL_ITEM_POD, &uiNumBytesRead ) )
{
return FALSE;
}
if ( !this->object.Load(hFile) )
{
return FALSE;
}
}
else
{
//this will never be loaded from sometime before the first change
AssertGE(guiCurrentSaveGameVersion, NIV_SAVEGAME_DATATYPE_CHANGE);
}
return TRUE;
}
BOOLEAN REAL_OBJECT::Save(HWFILE hFile)
{
UINT32 uiNumBytesWritten;
if ( !FileWrite( hFile, this, SIZEOF_REAL_OBJECT_POD, &uiNumBytesWritten ) )
{
return FALSE;
}
if ( !this->Obj.Save(hFile, FALSE) )
{
return FALSE;
}
return TRUE;
}
BOOLEAN REAL_OBJECT::Load(HWFILE hFile)
{
UINT32 uiNumBytesRead;
//if we are at the most current version, then fine
if ( guiCurrentSaveGameVersion >= NIV_SAVEGAME_DATATYPE_CHANGE )
{
if ( !FileRead( hFile, this, SIZEOF_REAL_OBJECT_POD, &uiNumBytesRead ) )
{
return FALSE;
}
if ( !this->Obj.Load(hFile) )
{
return FALSE;
}
}
else
{
if ( guiCurrentSaveGameVersion < NIV_SAVEGAME_DATATYPE_CHANGE )
{
OLD_REAL_OBJECT_101 oldObject;
if ( !FileRead( hFile, &oldObject, sizeof( OLD_REAL_OBJECT_101 ), &uiNumBytesRead ) )
{
return FALSE;
}
*this = oldObject;
}
}
return TRUE;
}
BOOLEAN INVENTORY_IN_SLOT::Save(HWFILE hFile)
{
UINT32 uiNumBytesWritten;
if ( !FileWrite( hFile, this, SIZEOF_INVENTORY_IN_SLOT_POD, &uiNumBytesWritten ) )
{
return FALSE;
}
if ( !this->ItemObject.Save(hFile, FALSE) )
{
return FALSE;
}