Skip to content

Commit

Permalink
Merge pull request #28 from rmm17/savingGame
Browse files Browse the repository at this point in the history
Saving game
  • Loading branch information
rmm17 authored Jul 19, 2022
2 parents 9df992e + ddde692 commit 60fc863
Show file tree
Hide file tree
Showing 17 changed files with 971 additions and 249 deletions.
4 changes: 4 additions & 0 deletions SOURCES/Assets/Text/de_ctxt.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
234,Kollisionsschaden aktiv
34,Kollisionsschaden inaktiv
950,Load game
951,Save game
952,This save already exists! Try again.
953,Create new save
4 changes: 4 additions & 0 deletions SOURCES/Assets/Text/en_ctxt.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
234,Collision Damage On
34,Collision Damage Off
950,Load game
951,Save game
952,This save already exists! Try again.
953,Create new save
4 changes: 4 additions & 0 deletions SOURCES/Assets/Text/fr_ctxt.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
234,D�g�ts de collision activ�s
34,D�g�ts de collision d�sactiv�s
950,Load game
951,Save game
952,This save already exists! Try again.
953,Create new save
4 changes: 4 additions & 0 deletions SOURCES/Assets/Text/it_ctxt.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
234,Danno da collisione attivato
34,Danno da collisione disattivato
950,Load game
951,Save game
952,This save already exists! Try again.
953,Create new save
4 changes: 4 additions & 0 deletions SOURCES/Assets/Text/sp_ctxt.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
234,Da�os por colisi�n activados
34,Da�os por colisi�n desactivados
950,Load game
951,Save game
952,This save already exists! Try again.
953,Create new save
1 change: 1 addition & 0 deletions SOURCES/COMMON.H
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@

#define MAX_FLAGS_CUBE 80
#define MAX_FLAGS_GAME 255
#define MAX_AUX_FLAGS_CUBE 10

#define MAX_INVENTORY 28

Expand Down
17 changes: 17 additions & 0 deletions SOURCES/C_EXTERN.H
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ extern T_FLAG ListFlagGame[] ;
extern UBYTE ListFlagCube[] ;
extern UBYTE ListFlagGame[] ;

extern T_AUX_FLAG_CUBE ListAuxFlagCube[]; //auxiliary cube flags set aside from the original ListFlagCube, to aid in manual saving

extern UBYTE ListFlagInventory[] ;


Expand All @@ -200,6 +202,8 @@ extern WORD GameListChoice[] ;

/*--------- perso ----------------------------*/

extern WORD PersoInvulnerable;

extern WORD FlagTheEnd ;

extern WORD ActionNormal ;
Expand Down Expand Up @@ -242,6 +246,18 @@ extern UBYTE Island ;
extern WORD Fuel ;
extern WORD NumPingouin ;

extern WORD HasLoadedSave ;
extern WORD HasLoadedListObjetsOnSave;
extern WORD HasLoadedListObjetTracksOnSave;
extern WORD HasLoadedListExtraOnSave;
extern WORD HasLoadedListZoneOnSave;
extern WORD HasLoadedKeysOnSave ;
extern WORD HasLoadedInventoryOnSave;
extern WORD HasLoadedListFlagCubeOnSave;
extern WORD HasLoadedListAuxFlagCubeOnSave;
extern WORD HasLoadedLastValidPersoOnSave;
extern WORD DisableAutoSave;

extern WORD NbFourLeafClover ;
extern WORD NbCloverBox ;

Expand Down Expand Up @@ -297,6 +313,7 @@ extern T_HQR_HEADER *HQR_Anims ;

extern LONG NbObjets ;
extern T_OBJET ListObjet[] ;
extern T_OBJET LastValidPerso;

extern T_SORT ListTri[] ;

Expand Down
28 changes: 28 additions & 0 deletions SOURCES/DEFINES.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@
//path des ressources
#define PATH_RESSOURCE ""

// with this define, save file names will use the name inserted by the player (e.g. TWINSEN.LBA), but these will be truncated on DOS and open the possibility of different saves replacing each other
#define WINDOWS_SAVE 1

// uncomment this line to go back to DOS file name saving (S0000.LBA), to bypass the DOS truncating issue
//#undef WINDOWS_SAVE

// disable auto saving on game over
#define DISABLE_GAME_OVER_SAVE 1

// uncomment to reenable auto saving on game over
//#undef DISABLE_GAME_OVER_SAVE

// disable copy saved game feature
#define DISABLE_COPY_SAVED_GAME 1

// uncomment to reenable copy saved game feature
//#undef DISABLE_COPY_SAVED_GAME

/*──────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────*/

Expand Down Expand Up @@ -150,6 +168,8 @@ extern ULONG UsedHQMemory ;
#define GEN_ANIM_SABRE 23
#define GEN_ANIM_DEGAINE 24

#define MAIN_LOOP_LOAD_GAME 3

/*──────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────*/
typedef struct
Expand Down Expand Up @@ -257,3 +277,11 @@ typedef struct
WORD Y ;
WORD Z ; } T_TRACK ;


// struct for some additional cube flags
typedef struct
{
WORD NumObj;
WORD PerformedOffsetLife;
} T_AUX_FLAG_CUBE;

152 changes: 98 additions & 54 deletions SOURCES/DISKFUNC.C
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ WORD LoadScene( WORD numscene )
{
T_OBJET *ptrobj ;
WORD n, info3 ;
WORD indexfile3d;
UBYTE string[256] ;
UBYTE mess[256] ;
WORD sizetoload ;
WORD indexfile3d ;

// PtrScene = PtrSce = LoadMalloc_HQR( PATH_RESSOURCE"scene.hqr", numscene ) ;

Expand Down Expand Up @@ -118,80 +118,124 @@ WORD LoadScene( WORD numscene )
// objets: OBJECT

NbObjets = GET_WORD ;
for( n=1; n<NbObjets; n++, ptrobj++ )

for (n = 1; n < NbObjets; n++, ptrobj++)
{
InitObject( n ) ;
T_OBJET* savedPtrObj;

if (HasLoadedListObjetsOnSave)
{
savedPtrObj = malloc(sizeof(T_OBJET));

if (savedPtrObj)
*savedPtrObj = *ptrobj;
}

InitObject(n);

ptrobj->Flags = GET_WORD ;
ptrobj->Flags = GET_WORD;

indexfile3d = GET_WORD ;
indexfile3d = GET_WORD;

if( !(ptrobj->Flags & SPRITE_3D) )
if (!(ptrobj->Flags & SPRITE_3D))
{

HQRM_Load( PATH_RESSOURCE"File3D.hqr", indexfile3d, (void**)&ptrobj->PtrFile3D ) ;
CHECK_MEMORY
HQRM_Load(PATH_RESSOURCE"File3D.hqr", indexfile3d, (void**)&ptrobj->PtrFile3D);
CHECK_MEMORY

/* ptrobj->PtrFile3D =
LoadMalloc_HQR(
PATH_RESSOURCE"File3D.hqr",
indexfile3d ) ;
*/
/* ptrobj->PtrFile3D =
LoadMalloc_HQR(
PATH_RESSOURCE"File3D.hqr",
indexfile3d ) ;
*/

}

ptrobj->GenBody = GET_BYTE ;
ptrobj->GenAnim = GET_BYTE ;
/*
if( n==5 )
{
CoulText( 15,0 ) ;
Text( 10, 300, "obj 5 org anim: %d", ptrobj->GenAnim ) ;
}
*/

ptrobj->Sprite = GET_WORD ;

ptrobj->OldPosX = ptrobj->PosObjX = GET_WORD ;
ptrobj->OldPosY = ptrobj->PosObjY = GET_WORD ;
ptrobj->OldPosZ = ptrobj->PosObjZ = GET_WORD ;
ptrobj->HitForce = GET_BYTE ;
ptrobj->OptionFlags = GET_WORD ;
ptrobj->OptionFlags &= ~EXTRA_GIVE_NOTHING ;
ptrobj->Beta = GET_WORD ;
ptrobj->SRot = GET_WORD ;
ptrobj->Move = GET_WORD ;

ptrobj->Info = GET_WORD ;
ptrobj->Info1 = GET_WORD ;
ptrobj->Info2 = GET_WORD ;
ptrobj->Info3 = GET_WORD ;

ptrobj->NbBonus = GET_BYTE ;
ptrobj->CoulObj = GET_BYTE ;
ptrobj->Armure = GET_BYTE ;
ptrobj->LifePoint = GET_BYTE ;

sizetoload = GET_WORD ;
ptrobj->PtrTrack = PtrSce ;
PtrSce = PtrSce + sizetoload ;

sizetoload = GET_WORD ;
ptrobj->PtrLife = PtrSce ;
PtrSce = PtrSce + sizetoload ;
ptrobj->GenBody = GET_BYTE;
ptrobj->GenAnim = GET_BYTE;
/*
if( n==5 )
{
CoulText( 15,0 ) ;
Text( 10, 300, "obj 5 org anim: %d", ptrobj->GenAnim ) ;
}
*/

ptrobj->Sprite = GET_WORD;

ptrobj->OldPosX = ptrobj->PosObjX = GET_WORD;
ptrobj->OldPosY = ptrobj->PosObjY = GET_WORD;
ptrobj->OldPosZ = ptrobj->PosObjZ = GET_WORD;
ptrobj->HitForce = GET_BYTE;
ptrobj->OptionFlags = GET_WORD;
ptrobj->OptionFlags &= ~EXTRA_GIVE_NOTHING;
ptrobj->Beta = GET_WORD;
ptrobj->SRot = GET_WORD;
ptrobj->Move = GET_WORD;

ptrobj->Info = GET_WORD;
ptrobj->Info1 = GET_WORD;
ptrobj->Info2 = GET_WORD;
ptrobj->Info3 = GET_WORD;

ptrobj->NbBonus = GET_BYTE;
ptrobj->CoulObj = GET_BYTE;
ptrobj->Armure = GET_BYTE;
ptrobj->LifePoint = GET_BYTE;

sizetoload = GET_WORD;
ptrobj->PtrTrack = PtrSce;
PtrSce = PtrSce + sizetoload;

sizetoload = GET_WORD;
ptrobj->PtrLife = PtrSce;
PtrSce = PtrSce + sizetoload;

//If loading from a save, replace content with the saved one (but keep the SCENE.HQR file reading flow from LoadScene for other necessary readings afterwards)
if (HasLoadedListObjetsOnSave && savedPtrObj)
{
//If object was saved while getting hit, starting animation will be the one from SCENE.HQR file (this is to avoid a glitch when a NPC is in the middle of an animation when a save is made)
if (savedPtrObj->GenAnim == GEN_ANIM_CHOC || savedPtrObj->GenAnim == GEN_ANIM_CHOC2)
savedPtrObj->GenAnim = ptrobj->GenAnim;

//This will retain NPC and object position and other states when loading a save
*ptrobj = *savedPtrObj;

//Do not render object if it's marked as dead on save.
if (savedPtrObj->LifePoint <= 0)
{
ptrobj->GenBody = NO_BODY;
ptrobj->GenAnim = NO_ANIM;
ptrobj->Anim = NO_ANIM;
ptrobj->WorkFlags |= OBJ_DEAD;
ptrobj->Sprite = -1;
ptrobj->Body = -1;

ptrobj->ZoneSce = -1;
ptrobj->OffsetTrack = -1;

//Do not reset OffsetLife if the object is a meca penguin (because if it's in inventory, it's marked as dead in code, and it's still needed when used)
if (n != NumPingouin)
ptrobj->OffsetLife = -1;
}

free(savedPtrObj);
}
}

// zone declechement: ZONE

NbZones = GET_WORD ;
ListZone = (T_ZONE*)PtrSce ;
if (!HasLoadedListZoneOnSave) //add flag for zones
ListZone = (T_ZONE*)PtrSce ;
PtrSce += NbZones * 12 * 2 ;

// point track: TRACK

NbBrickTrack = GET_WORD ;
ListBrickTrack = (T_TRACK*)PtrSce ;

HasLoadedListZoneOnSave = 0;

return TRUE ;
}

Expand Down
12 changes: 10 additions & 2 deletions SOURCES/EXTRA.C
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,16 @@ void ClearExtra()

for( n=0; n<MAX_EXTRAS; n++ )
{
ListExtra[n].Sprite = -1 ;
ListExtra[n].Divers = 1 ;
if (!HasLoadedListExtraOnSave)
{
ListExtra[n].Sprite = -1;
ListExtra[n].Divers = 1;
}
else
{
//Reset extra item timer to loading time
ListExtra[n].Timer = TimerRef;
}
}

}
Expand Down
Loading

0 comments on commit 60fc863

Please sign in to comment.