# HG changeset patch # User Adam Kaminski # Date 1632687797 14400 # Sun Sep 26 16:23:17 2021 -0400 # Node ID 40dfe0473a176c977fb6738c1bf19c538d684c9d # Parent bb8418622c7f353a9b8f701c506005e020e3d809 GAMEEVENT_ACTOR_DAMAGED is now triggered just before the actor receives damage. diff -r bb8418622c7f -r 40dfe0473a17 src/gamemode.cpp --- a/src/gamemode.cpp Sun Sep 26 12:49:28 2021 -0400 +++ b/src/gamemode.cpp Sun Sep 26 16:23:17 2021 -0400 @@ -67,6 +67,7 @@ #include "possession.h" #include "p_lnspec.h" #include "p_acs.h" +#include "gi.h" // [BB] The next includes are only needed for GAMEMODE_DisplayStandardMessage #include "sbar.h" #include "v_video.h" @@ -1103,6 +1104,36 @@ //***************************************************************************** // +void GAMEMODE_HandleDamageEvent ( AActor *target, AActor *inflictor, AActor *source, int damage, FName mod ) +{ + // [AK] Don't run any scripts if the target doesn't allow executing GAMEEVENT_ACTOR_DAMAGED. + if ( target->STFlags & STFL_NODAMAGEEVENTSCRIPT ) + return; + + // [AK] Don't run any scripts if the target can't execute GAMEEVENT_ACTOR_DAMAGED unless + // all actors are forced to execute it. + if ((( target->STFlags & STFL_USEDAMAGEEVENTSCRIPT ) == false ) && ( gameinfo.bForceDamageEventScripts == false )) + return; + + // [AK] We somehow need to pass the source and inflictor actor pointers into the script + // itself. A simple way to do this is temporarily changing the target's pointers to the + // source and inflictor, which we'll then use to initialize AAPTR_DAMAGE_SOURCE and + // AAPTR_DAMAGE_INFLICTOR for the script. + // The source actor is the activator, which we'll use to initialize AAPTR_DAMAGE_TARGET. + AActor *tempMaster = target->master; + AActor *tempTarget = target->target; + target->master = source; + target->target = inflictor; + + GAMEMODE_HandleEvent( GAMEEVENT_ACTOR_DAMAGED, target, damage, GlobalACSStrings.AddString( mod )); + + // [AK] Restore the source actor's old pointers. + target->master = tempMaster; + target->target = tempTarget; +} + +//***************************************************************************** +// void GAMEMODE_DisplayStandardMessage( const char *pszMessage, const bool bInformClients ) { if ( NETWORK_GetState( ) != NETSTATE_SERVER ) diff -r bb8418622c7f -r 40dfe0473a17 src/gamemode.h --- a/src/gamemode.h Sun Sep 26 12:49:28 2021 -0400 +++ b/src/gamemode.h Sun Sep 26 16:23:17 2021 -0400 @@ -213,6 +213,7 @@ 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 ); +void GAMEMODE_HandleDamageEvent ( AActor *target, AActor *inflictor, AActor *source, int damage, FName mod ); // [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 bb8418622c7f -r 40dfe0473a17 src/p_interaction.cpp --- a/src/p_interaction.cpp Sun Sep 26 12:49:28 2021 -0400 +++ b/src/p_interaction.cpp Sun Sep 26 16:23:17 2021 -0400 @@ -1508,7 +1508,8 @@ lOldTargetHealth = target->health; if (player) { - + bool bDamageEventHandled = false; // [AK] + // [TIHan/Spleen] Apply factor for damage dealt to players by monsters. ApplyCoopDamagefactor(damage, source); @@ -1553,6 +1554,10 @@ } } + // [AK] Trigger an event script indicating that the player has taken damage, if we can. + GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ); + bDamageEventHandled = true; + if (damage >= player->health && (G_SkillProperty(SKILLP_AutoUseHealth) || deathmatch) && !player->morphTics) @@ -1561,6 +1566,10 @@ } } + // [AK] If we haven't done so already, trigger an event script indicating that the player has taken damage. + if ( bDamageEventHandled == false ) + GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ); + player->health -= damage; // mirror mobj health here for Dave // [RH] Make voodoo dolls and real players record the same health target->health = player->mo->health -= damage; @@ -1625,6 +1634,9 @@ } } + // [AK] Trigger an event script indicating that the target actor has taken damage, if we can. + GAMEMODE_HandleDamageEvent( target, inflictor, source, damage, mod ); + target->health -= damage; } @@ -1665,26 +1677,6 @@ source->player->ulUnrewardedDamageDealt += MIN( (int)lOldTargetHealth, damage ); } - // [AK] Trigger an event script indicating that the target actor has taken damage, if we can. - if ((( target->STFlags & STFL_NODAMAGEEVENTSCRIPT ) == false ) && (( target->STFlags & STFL_USEDAMAGEEVENTSCRIPT ) || ( gameinfo.bForceDamageEventScripts ))) - { - // [AK] We somehow need to pass the source and inflictor actor pointers into the script - // itself. A simple way to do this is temporarily changing the target's pointers to the - // source and inflictor, which we'll then use to initialize AAPTR_DAMAGE_SOURCE and - // AAPTR_DAMAGE_INFLICTOR for the script. - // The source actor is the activator, which we'll use to initialize AAPTR_DAMAGE_TARGET. - AActor *tempMaster = target->master; - AActor *tempTarget = target->target; - target->master = source; - target->target = inflictor; - - GAMEMODE_HandleEvent( GAMEEVENT_ACTOR_DAMAGED, target, damage, GlobalACSStrings.AddString( mod )); - - // [AK] Restore the source actor's old pointers. - target->master = tempMaster; - target->target = tempTarget; - } - // [BC] Tell clients that this thing was damaged. if ( NETWORK_GetState( ) == NETSTATE_SERVER ) {