diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index d801a7e80..394619322 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -320,6 +320,40 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetDistance) return 0; } +//========================================================================== +// +// GetAngle +// +// NON-ACTION function to get the angle in degrees (normalized to -180..180) +// +//========================================================================== +DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetAngle) +{ + if (numret > 0) + { + assert(ret != NULL); + PARAM_SELF_PROLOGUE(AActor); + PARAM_BOOL(relative); + PARAM_INT_OPT(ptr) { ptr = AAPTR_TARGET; } + + AActor *target = COPY_AAPTR(self, ptr); + + if (!target || target == self) + { + ret->SetFloat(0); + } + else + { + DVector3 diff = self->Vec3To(target); + DAngle angto = diff.Angle(); + if (relative) angto = deltaangle(self->Angles.Yaw, angto); + ret->SetFloat(angto.Degrees); + } + return 1; + } + return 0; +} + //========================================================================== // // GetSpawnHealth diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 9222741bd..469c1b624 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -42,6 +42,7 @@ ACTOR Actor native //: Thinker native bool IsPointerEqual(int ptr_select1, int ptr_select2); native int CountInv(class itemtype, int ptr_select = AAPTR_DEFAULT); native float GetDistance(bool checkz, int ptr = AAPTR_DEFAULT); + native float GetAngle(bool relative, int ptr = AAPTR_DEFAULT); native int GetSpawnHealth(); native int GetGibHealth();