From d6314636628d64cbc6e9d6549706c2c9b6a24d44 Mon Sep 17 00:00:00 2001 From: mittorn Date: Wed, 7 Nov 2018 15:36:22 +0700 Subject: [PATCH] Autosave, map start save --- dlls/coop.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++--- dlls/coop_util.h | 1 + dlls/gravgunmod.h | 2 ++ dlls/triggers.cpp | 7 +++++-- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/dlls/coop.cpp b/dlls/coop.cpp index ce582776..28890a16 100644 --- a/dlls/coop.cpp +++ b/dlls/coop.cpp @@ -14,7 +14,7 @@ struct COOPMapState { char szMapName[32]; Vector vecOffset; - struct GGMCheckpoint { + struct COOPCheckpoint { char szDisplayName[32]; float flTime; struct GGMPosition pos; @@ -35,18 +35,32 @@ struct COOPLandmarkTransition { bool fLoading; }; +enum COOPSaveSlot +{ + COOP_SAVE_START1 = 0, + COOP_SAVE_START2, + COOP_SAVE_AUTO1, + COOP_SAVE_AUTO2, + COOP_SAVE_COUNT +}; + struct COOPState { // will be saved struct COOPPersist { // weapon list - char rgszWeapons[64][256]; + char rgszWeapons[64][32]; int iWeaponCount; + // data for spawnpoint struct GGMPosition savedPos; bool fSaved; + char rgszSaveSlots[COOP_SAVE_COUNT][32]; + char iLastAutoSave; } p; + + // runtime state struct COOPMapState *pMapStates; struct COOPMapState *pCurrentMap; @@ -144,6 +158,29 @@ bool COOP_ReadState( const char *path ) return true; } +void COOP_AutoSave( void ) +{ + strncpy( g_CoopState.p.rgszSaveSlots[COOP_SAVE_AUTO2], g_CoopState.p.rgszSaveSlots[COOP_SAVE_AUTO1], 31 ); + g_CoopState.p.iLastAutoSave ^= 1; + snprintf( g_CoopState.p.rgszSaveSlots[COOP_SAVE_AUTO1], 31, "%s-auto%d", STRING( gpGlobals->mapname ), g_CoopState.p.iLastAutoSave ); + GGM_Save( g_CoopState.p.rgszSaveSlots[COOP_SAVE_AUTO1] ); +} + +void COOP_MapStartSave( void ) +{ + char szSavename[32] = ""; + + snprintf( szSavename, 31, "%s-start", STRING( gpGlobals->mapname ) ); + + // moving to previous map and returning back should not trigger save + if( !strcmp( g_CoopState.p.rgszSaveSlots[COOP_SAVE_START1], szSavename ) || !strcmp( g_CoopState.p.rgszSaveSlots[COOP_SAVE_START2], szSavename ) ) + return; + + strncpy( g_CoopState.p.rgszSaveSlots[COOP_SAVE_START2], g_CoopState.p.rgszSaveSlots[COOP_SAVE_START1], 31 ); + strncpy( g_CoopState.p.rgszSaveSlots[COOP_SAVE_START1], szSavename, 31 ); + GGM_Save( g_CoopState.p.rgszSaveSlots[COOP_SAVE_START1] ); +} + edict_t *COOP_FindLandmark( const char *pLandmarkName ) { @@ -575,8 +612,10 @@ void COOP_ServerActivate( void ) snprintf( g_CoopState.pCurrentMap->p.rgCheckpoints[0].szDisplayName, 31, "From %s", g_CoopState.landmarkTransition.szSourceMap ); g_CoopState.pCurrentMap->p.rgCheckpoints[0].pos = g_CoopState.p.savedPos; } - + if( !g_CoopState.landmarkTransition.fLoading ) + COOP_MapStartSave(); memset( &g_CoopState.landmarkTransition, 0, sizeof( struct COOPLandmarkTransition ) ); + } bool COOP_GetOrigin( Vector *pvecNewOrigin, const Vector &vecOrigin, const char *pszMapName ) diff --git a/dlls/coop_util.h b/dlls/coop_util.h index d5852fc4..4fe941e6 100644 --- a/dlls/coop_util.h +++ b/dlls/coop_util.h @@ -57,6 +57,7 @@ void COOP_GiveDefaultWeapons( CBasePlayer *pPlayer ); void COOP_AddDefaultWeapon( const char *pszClassName ); void COOP_WriteState( const char *path ); bool COOP_ReadState( const char *path ); +void COOP_AutoSave( void ); struct COOPChangelevelData *COOP_GetTriggerData( CBaseEntity *pTrigger ); #endif // COOP_UTIL_H diff --git a/dlls/gravgunmod.h b/dlls/gravgunmod.h index 6960b1a6..8950cbd0 100644 --- a/dlls/gravgunmod.h +++ b/dlls/gravgunmod.h @@ -190,5 +190,7 @@ const char *GGM_GetAuthID( CBasePlayer *pPlayer ); void GGM_ServerActivate( void ); void COOP_SetupLandmarkTransition( const char *szNextMap, const char *szNextSpot, Vector vecLandmarkOffset, struct GGMPosition *pPos ); void GGM_ClearLists( void ); +void GGM_Save( const char *savename ); +void GGM_Load( const char *savename ); #endif // GRAVGUNMOD_H diff --git a/dlls/triggers.cpp b/dlls/triggers.cpp index 4aa7f182..cf3eb56b 100644 --- a/dlls/triggers.cpp +++ b/dlls/triggers.cpp @@ -2271,7 +2271,7 @@ LINK_ENTITY_TO_CLASS( trigger_autosave, CTriggerSave ) void CTriggerSave::Spawn( void ) { - if( g_pGameRules->IsDeathmatch() ) + if( !mp_coop.value && g_pGameRules->IsDeathmatch() ) { REMOVE_ENTITY( ENT( pev ) ); return; @@ -2292,7 +2292,10 @@ void CTriggerSave::SaveTouch( CBaseEntity *pOther ) SetTouch( NULL ); UTIL_Remove( this ); - SERVER_COMMAND( "autosave\n" ); + if( mp_coop.value ) + COOP_AutoSave(); + else + SERVER_COMMAND( "autosave\n" ); } #define SF_ENDSECTION_USEONLY 0x0001