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. 5
      dlls/triggers.cpp

45
dlls/coop.cpp

@ -14,7 +14,7 @@ struct COOPMapState
{ {
char szMapName[32]; char szMapName[32];
Vector vecOffset; Vector vecOffset;
struct GGMCheckpoint { struct COOPCheckpoint {
char szDisplayName[32]; char szDisplayName[32];
float flTime; float flTime;
struct GGMPosition pos; struct GGMPosition pos;
@ -35,18 +35,32 @@ struct COOPLandmarkTransition {
bool fLoading; bool fLoading;
}; };
enum COOPSaveSlot
{
COOP_SAVE_START1 = 0,
COOP_SAVE_START2,
COOP_SAVE_AUTO1,
COOP_SAVE_AUTO2,
COOP_SAVE_COUNT
};
struct COOPState struct COOPState
{ {
// will be saved // will be saved
struct COOPPersist struct COOPPersist
{ {
// weapon list // weapon list
char rgszWeapons[64][256]; char rgszWeapons[64][32];
int iWeaponCount; int iWeaponCount;
// data for spawnpoint // data for spawnpoint
struct GGMPosition savedPos; struct GGMPosition savedPos;
bool fSaved; bool fSaved;
char rgszSaveSlots[COOP_SAVE_COUNT][32];
char iLastAutoSave;
} p; } p;
// runtime state
struct COOPMapState *pMapStates; struct COOPMapState *pMapStates;
struct COOPMapState *pCurrentMap; struct COOPMapState *pCurrentMap;
@ -144,6 +158,29 @@ bool COOP_ReadState( const char *path )
return true; 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 ) 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 ); 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; 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 ) ); memset( &g_CoopState.landmarkTransition, 0, sizeof( struct COOPLandmarkTransition ) );
} }
bool COOP_GetOrigin( Vector *pvecNewOrigin, const Vector &vecOrigin, const char *pszMapName ) 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 );
void COOP_AddDefaultWeapon( const char *pszClassName ); void COOP_AddDefaultWeapon( const char *pszClassName );
void COOP_WriteState( const char *path ); void COOP_WriteState( const char *path );
bool COOP_ReadState( const char *path ); bool COOP_ReadState( const char *path );
void COOP_AutoSave( void );
struct COOPChangelevelData *COOP_GetTriggerData( CBaseEntity *pTrigger ); struct COOPChangelevelData *COOP_GetTriggerData( CBaseEntity *pTrigger );
#endif // COOP_UTIL_H #endif // COOP_UTIL_H

2
dlls/gravgunmod.h

@ -190,5 +190,7 @@ const char *GGM_GetAuthID( CBasePlayer *pPlayer );
void GGM_ServerActivate( void ); void GGM_ServerActivate( void );
void COOP_SetupLandmarkTransition( const char *szNextMap, const char *szNextSpot, Vector vecLandmarkOffset, struct GGMPosition *pPos ); void COOP_SetupLandmarkTransition( const char *szNextMap, const char *szNextSpot, Vector vecLandmarkOffset, struct GGMPosition *pPos );
void GGM_ClearLists( void ); void GGM_ClearLists( void );
void GGM_Save( const char *savename );
void GGM_Load( const char *savename );
#endif // GRAVGUNMOD_H #endif // GRAVGUNMOD_H

5
dlls/triggers.cpp

@ -2271,7 +2271,7 @@ LINK_ENTITY_TO_CLASS( trigger_autosave, CTriggerSave )
void CTriggerSave::Spawn( void ) void CTriggerSave::Spawn( void )
{ {
if( g_pGameRules->IsDeathmatch() ) if( !mp_coop.value && g_pGameRules->IsDeathmatch() )
{ {
REMOVE_ENTITY( ENT( pev ) ); REMOVE_ENTITY( ENT( pev ) );
return; return;
@ -2292,6 +2292,9 @@ void CTriggerSave::SaveTouch( CBaseEntity *pOther )
SetTouch( NULL ); SetTouch( NULL );
UTIL_Remove( this ); UTIL_Remove( this );
if( mp_coop.value )
COOP_AutoSave();
else
SERVER_COMMAND( "autosave\n" ); SERVER_COMMAND( "autosave\n" );
} }

Loading…
Cancel
Save