# HG changeset patch # User Adam Kaminski # Date 1638110053 18000 # Sun Nov 28 09:34:13 2021 -0500 # Node ID db2059418e2d12c316d6db27f3c2f176192abb75 # Parent 8ff4cd1e0346291c8ececeedff8f2f5ce6a710a7 Added support for deciding the outcome of certain game events by changing the result value of ACS EVENT scripts. diff -r 8ff4cd1e0346 -r db2059418e2d src/gamemode.cpp --- a/src/gamemode.cpp Sat Nov 27 11:07:16 2021 -0500 +++ b/src/gamemode.cpp Sun Nov 28 09:34:13 2021 -0500 @@ -89,6 +89,9 @@ // Our current game mode. static GAMEMODE_e g_CurrentGameMode; +// [AK] The result value of the current event being executed. +static LONG g_lEventResult = 1; + // [BB] Implement the string table and the conversion functions for the GMF and GAMEMODE enums. #define GENERATE_ENUM_STRINGS // Start string generation #include "gamemode_enums.h" @@ -1079,11 +1082,11 @@ //***************************************************************************** // -void GAMEMODE_HandleEvent ( const GAMEEVENT_e Event, AActor *pActivator, const int DataOne, const int DataTwo ) +LONG GAMEMODE_HandleEvent ( const GAMEEVENT_e Event, AActor *pActivator, const int DataOne, const int DataTwo ) { // [BB] Clients don't start scripts. if ( NETWORK_InClientMode() ) - return; + return 1; // [AK] Allow events that are triggered by an actor spawning or // taking damage to be executed immediately, in case any of the @@ -1096,6 +1099,13 @@ // the second and third are specific to the event, e.g. the second is the number of the fragged player. // The third argument will be zero if it isn't used in the script. FBehavior::StaticStartTypedScripts( SCRIPT_Event, pActivator, true, Event, bRunNow, false, DataOne, DataTwo ); + + // [AK] Get the result value of the event, then reset it back to the default value. + LONG lResult = GAMEMODE_GetEventResult( ); + GAMEMODE_SetEventResult( 1 ); + + // [AK] Return the result value of the event. + return lResult; } //***************************************************************************** @@ -1129,6 +1139,20 @@ //***************************************************************************** // +LONG GAMEMODE_GetEventResult( ) +{ + return g_lEventResult; +} + +//***************************************************************************** +// +void GAMEMODE_SetEventResult( LONG lResult ) +{ + g_lEventResult = lResult; +} + +//***************************************************************************** +// void GAMEMODE_DisplayStandardMessage( const char *pszMessage, const bool bInformClients ) { if ( NETWORK_GetState( ) != NETSTATE_SERVER ) diff -r 8ff4cd1e0346 -r db2059418e2d src/gamemode.h --- a/src/gamemode.h Sat Nov 27 11:07:16 2021 -0500 +++ b/src/gamemode.h Sun Nov 28 09:34:13 2021 -0500 @@ -212,8 +212,10 @@ bool GAMEMODE_IsHandledSpecial ( AActor *Activator, int Special ); GAMESTATE_e GAMEMODE_GetState ( void ); void GAMEMODE_SetState ( GAMESTATE_e GameState ); -void GAMEMODE_HandleEvent ( const GAMEEVENT_e Event, AActor *pActivator = NULL, const int DataOne = 0, const int DataTwo = 0 ); +LONG GAMEMODE_HandleEvent ( const GAMEEVENT_e Event, AActor *pActivator = NULL, const int DataOne = 0, const int DataTwo = 0 ); void GAMEMODE_HandleDamageEvent ( AActor *target, AActor *inflictor, AActor *source, int damage, FName mod ); +LONG GAMEMODE_GetEventResult ( void ); +void GAMEMODE_SetEventResult ( LONG lResult ); // [BB] This function doesn't really belong here. Find a better place for it. void GAMEMODE_DisplayStandardMessage( const char *pszMessage, const bool bInformClients = false ); diff -r 8ff4cd1e0346 -r db2059418e2d src/p_acs.cpp --- a/src/p_acs.cpp Sat Nov 27 11:07:16 2021 -0500 +++ b/src/p_acs.cpp Sun Nov 28 09:34:13 2021 -0500 @@ -7800,6 +7800,14 @@ switch (state) { + // [AK] If this is the first tic of an event script, initialize the result value to whatever the current + // event's result value is supposed to be at this moment. This is so that in case there's multiple event + // scripts, the result of the event can easily be transferred from one script to the next. + case SCRIPT_Running: + if ( ACS_IsEventScript( script )) + resultValue = GAMEMODE_GetEventResult( ); + break; + case SCRIPT_Delayed: // Decrement the delay counter and enter state running // if it hits 0 @@ -11654,6 +11662,10 @@ // [AK] We're done running this script so any action or line specials activated now aren't done in ACS. g_pCurrentScript = NULL; + // [AK] If this is an event script and the result value differs from the event's result value, update it. + if (( ACS_IsEventScript( script )) && ( resultValue != GAMEMODE_GetEventResult( ))) + GAMEMODE_SetEventResult( resultValue ); + // [BB] Stop the net traffic measurement and add the result to this script's traffic. NETTRAFFIC_AddACSScriptTraffic ( script, NETWORK_StopTrafficMeasurement ( ) ); @@ -12263,6 +12275,19 @@ //***************************************************************************** // +bool ACS_IsEventScript( int script ) +{ + FBehavior *pModule = NULL; + const ScriptPtr *pScriptData = FBehavior::StaticFindScript( script, pModule ); + + if ( pScriptData == NULL ) + return ( false ); + + return ( pScriptData->Type == SCRIPT_Event ); +} + +//***************************************************************************** +// bool ACS_IsScriptClientSide( int script ) { FBehavior *pModule = NULL; diff -r 8ff4cd1e0346 -r db2059418e2d src/p_acs.h --- a/src/p_acs.h Sat Nov 27 11:07:16 2021 -0500 +++ b/src/p_acs.h Sun Nov 28 09:34:13 2021 -0500 @@ -1176,6 +1176,7 @@ // PROTOTYPES bool ACS_IsCalledFromConsoleCommand( void ); +bool ACS_IsEventScript( int script ); // [AK] bool ACS_IsCalledFromScript( void ); // [AK] bool ACS_IsScriptClientSide( int script ); bool ACS_IsScriptClientSide( const ScriptPtr *pScriptData );