diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index fab7e38d8..e5b076acd 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -1006,7 +1006,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_OverlayOffset) PARAM_FLOAT_OPT(wx) { wx = 0.; } PARAM_FLOAT_OPT(wy) { wy = 32.; } PARAM_INT_OPT(flags) { flags = 0; } - A_OverlayOffset(self, layer, wx, wy, flags); + A_OverlayOffset(self, ((layer != 0) ? layer : stateinfo->mPSPIndex), wx, wy, flags); return 0; } @@ -1033,10 +1033,10 @@ DEFINE_ACTION_FUNCTION(AActor, A_OverlayFlags) PARAM_INT(flags); PARAM_BOOL(set); - if (self->player == nullptr) + if (!ACTION_CALL_FROM_PSPRITE()) return 0; - DPSprite *pspr = self->player->FindPSprite(layer); + DPSprite *pspr = self->player->FindPSprite(((layer != 0) ? layer : stateinfo->mPSPIndex)); if (pspr == nullptr) return 0; @@ -1049,6 +1049,52 @@ DEFINE_ACTION_FUNCTION(AActor, A_OverlayFlags) return 0; } +//--------------------------------------------------------------------------- +// +// PROC OverlayX/Y +// Action function to return the X/Y of an overlay. +//--------------------------------------------------------------------------- + +static double GetOverlayPosition(AActor *self, int layer, bool gety) +{ + if (layer) + { + DPSprite *pspr = self->player->FindPSprite(layer); + + if (pspr != nullptr) + { + return gety ? (pspr->y) : (pspr->x); + } + } + return 0.; +} + +DEFINE_ACTION_FUNCTION(AActor, OverlayX) +{ + PARAM_ACTION_PROLOGUE; + PARAM_INT_OPT(layer) { layer = 0; } + + if (ACTION_CALL_FROM_PSPRITE()) + { + double res = GetOverlayPosition(self, ((layer != 0) ? layer : stateinfo->mPSPIndex), false); + ACTION_RETURN_FLOAT(res); + } + ACTION_RETURN_FLOAT(0.); +} + +DEFINE_ACTION_FUNCTION(AActor, OverlayY) +{ + PARAM_ACTION_PROLOGUE; + PARAM_INT_OPT(layer) { layer = 0; } + + if (ACTION_CALL_FROM_PSPRITE()) + { + double res = GetOverlayPosition(self, ((layer != 0) ? layer : stateinfo->mPSPIndex), true); + ACTION_RETURN_FLOAT(res); + } + ACTION_RETURN_FLOAT(0.); +} + //--------------------------------------------------------------------------- // // PROC OverlayID diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 44b801f51..fb6b4c832 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -58,6 +58,8 @@ ACTOR Actor native //: Thinker native float GetSpriteRotation(int ptr = AAPTR_DEFAULT); native int GetMissileDamage(int mask, int add, int ptr = AAPTR_DEFAULT); action native int OverlayID(); + action native float OverlayX(int layer = 0); + action native float OverlayY(int layer = 0); // Action functions // Meh, MBF redundant functions. Only for DeHackEd support.