Browse Source

Autosave, map start save

gravgun
mittorn 6 years ago
parent
commit
d631463662
  1. 45
      dlls/coop.cpp
  2. 1
      dlls/coop_util.h
  3. 2
      dlls/gravgunmod.h
  4. 7
      dlls/triggers.cpp

45
dlls/coop.cpp

@ -14,7 +14,7 @@ struct COOPMapState @@ -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 { @@ -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 ) @@ -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 ) @@ -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 )

1
dlls/coop_util.h

@ -57,6 +57,7 @@ void COOP_GiveDefaultWeapons( CBasePlayer *pPlayer ); @@ -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

2
dlls/gravgunmod.h

@ -190,5 +190,7 @@ const char *GGM_GetAuthID( CBasePlayer *pPlayer ); @@ -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

7
dlls/triggers.cpp

@ -2271,7 +2271,7 @@ LINK_ENTITY_TO_CLASS( trigger_autosave, CTriggerSave ) @@ -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 ) @@ -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

Loading…
Cancel
Save