diff --git a/doomsday/apps/libdoomsday/include/doomsday/world/actions.h b/doomsday/apps/libdoomsday/include/doomsday/world/actions.h index 1428497419..a94c27dbd4 100644 --- a/doomsday/apps/libdoomsday/include/doomsday/world/actions.h +++ b/doomsday/apps/libdoomsday/include/doomsday/world/actions.h @@ -32,9 +32,9 @@ typedef struct actionlink_s { extern "C" { #endif -LIBDOOMSDAY_PUBLIC void P_GetGameActions(); - +LIBDOOMSDAY_PUBLIC void P_GetGameActions(); LIBDOOMSDAY_PUBLIC acfnptr_t P_GetAction(const char *name); +LIBDOOMSDAY_PUBLIC void P_SetCurrentActionState(int state); #ifdef __cplusplus } // extern "C" @@ -42,9 +42,9 @@ LIBDOOMSDAY_PUBLIC acfnptr_t P_GetAction(const char *name); #ifdef __cplusplus -# include +#include LIBDOOMSDAY_PUBLIC acfnptr_t P_GetAction(const de::String &name); -LIBDOOMSDAY_PUBLIC void P_SetCurrentAction(const de::String &name); +LIBDOOMSDAY_PUBLIC void P_SetCurrentAction(const de::String &name); #endif // __cplusplus diff --git a/doomsday/apps/libdoomsday/src/world/actions.cpp b/doomsday/apps/libdoomsday/src/world/actions.cpp index 2310bb4d99..cdd197f1e0 100644 --- a/doomsday/apps/libdoomsday/src/world/actions.cpp +++ b/doomsday/apps/libdoomsday/src/world/actions.cpp @@ -19,7 +19,9 @@ #include "doomsday/world/actions.h" #include "doomsday/gameapi.h" #include "doomsday/doomsdayapp.h" +#include "doomsday/players.h" #include "doomsday/world/mobjthinkerdata.h" +#include "doomsday/defs/ded.h" #include #include @@ -33,8 +35,28 @@ using namespace de; static QMap s_actions; ///< name => native function pointer. static String s_currentAction; -static void C_DECL A_DoomsdayScript(struct mobj_s *mobj) +static void C_DECL A_DoomsdayScript(void *actor) { + struct mobj_s *mobj = reinterpret_cast(actor); + + // The actor can also be a player in the case of psprites. + // Look up the corresponding player. + { + auto &plrs = DoomsdayApp::players(); + for (int i = 0; i < DDMAXPLAYERS; ++i) + { + // Note: It is assumed that the player data structure begins with a pointer to + // the ddplayer_t. + + if (&plrs.at(i).publicData() == + *reinterpret_cast(actor)) + { + // Refer to the player mobj instead. + mobj = plrs.at(i).publicData().mo; + } + } + } + LOG_AS("A_DoomsdayScript"); try { @@ -77,6 +99,11 @@ void P_SetCurrentAction(const String &name) s_currentAction = name; } +void P_SetCurrentActionState(int state) +{ + P_SetCurrentAction(DED_Definitions()->states[state].gets(QStringLiteral("action"))); +} + acfnptr_t P_GetAction(const String &name) { if (!name.isEmpty()) diff --git a/doomsday/apps/plugins/common/src/world/mobj.cpp b/doomsday/apps/plugins/common/src/world/mobj.cpp index ca9ffa4b33..f069c1f024 100644 --- a/doomsday/apps/plugins/common/src/world/mobj.cpp +++ b/doomsday/apps/plugins/common/src/world/mobj.cpp @@ -417,7 +417,7 @@ static bool changeMobjState(mobj_t *mobj, statenum_t stateNum, bool doCallAction if (shouldCallAction(mobj)) { // Custom parameters in the action function are passed to libdoomsday this way. - P_SetCurrentAction(Defs().states[stateNum].gets(QStringLiteral("action"))); + P_SetCurrentActionState(stateNum); void (*action)(mobj_t *); action = de::function_cast(st->action); diff --git a/doomsday/apps/plugins/doom/src/p_pspr.c b/doomsday/apps/plugins/doom/src/p_pspr.c index c5f2599632..02e9195ea6 100644 --- a/doomsday/apps/plugins/doom/src/p_pspr.c +++ b/doomsday/apps/plugins/doom/src/p_pspr.c @@ -116,6 +116,9 @@ void P_SetPsprite(player_t* player, int position, statenum_t stnum) // Call the state action routine (modified handling). if(state->action) { + // Custom parameters in the action function are passed to libdoomsday this way. + P_SetCurrentActionState((int) stnum); + state->action(player, psp); if(!psp->state) break; diff --git a/doomsday/apps/plugins/doom64/src/p_pspr.c b/doomsday/apps/plugins/doom64/src/p_pspr.c index 305ebef439..6915cfb984 100644 --- a/doomsday/apps/plugins/doom64/src/p_pspr.c +++ b/doomsday/apps/plugins/doom64/src/p_pspr.c @@ -123,6 +123,9 @@ void P_SetPsprite(player_t *player, int position, statenum_t stnum) // Modified handling. if(state->action) { + // Custom parameters in the action function are passed to libdoomsday this way. + P_SetCurrentActionState((int) stnum); + state->action(player, psp); if(!psp->state) break; diff --git a/doomsday/apps/plugins/heretic/src/p_pspr.c b/doomsday/apps/plugins/heretic/src/p_pspr.c index 81fced98f6..e876776822 100644 --- a/doomsday/apps/plugins/heretic/src/p_pspr.c +++ b/doomsday/apps/plugins/heretic/src/p_pspr.c @@ -37,6 +37,8 @@ #include "p_tick.h" #include "player.h" +#include + #define LOWERSPEED (6) #define RAISESPEED (6) #define WEAPONBOTTOM (128) @@ -84,7 +86,11 @@ void P_SetPsprite(player_t *player, int position, statenum_t stnum) } if(state->action) - { // Call action routine. + { + // Custom parameters in the action function are passed to libdoomsday this way. + P_SetCurrentActionState((int) stnum); + + // Call action routine. state->action(player, psp); if(!psp->state) { diff --git a/doomsday/apps/plugins/hexen/src/p_pspr.c b/doomsday/apps/plugins/hexen/src/p_pspr.c index b23d721762..1dc6975648 100644 --- a/doomsday/apps/plugins/hexen/src/p_pspr.c +++ b/doomsday/apps/plugins/hexen/src/p_pspr.c @@ -320,7 +320,11 @@ void P_SetPsprite(player_t *plr, int position, statenum_t stnum) Player_NotifyPSpriteChange(plr, position); if(state->action) - { // Call action routine. + { + // Custom parameters in the action function are passed to libdoomsday this way. + P_SetCurrentActionState((int) stnum); + + // Call action routine. state->action(plr, psp); if(!psp->state) {