From 8ecafcc15a8550def390142029e64ac8aa297e21 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Feb 2010 00:08:25 +0000 Subject: [PATCH] - Added A_CheckSightOrRange, with changes. SVN r2179 (trunk) --- src/thingdef/thingdef_codeptr.cpp | 53 +++++++++++++++++++++++++++++++ wadsrc/static/actors/actor.txt | 2 ++ 2 files changed, 55 insertions(+) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 2c8eb2684..f709b06a9 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -1897,7 +1897,60 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSight) } ACTION_JUMP(jump); +} +//=========================================================================== +// +// A_CheckSightOrRange +// Jumps if this actor is out of range of all players *and* out of sight. +// Useful for maps with many multi-actor special effects. +// +//=========================================================================== +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSightOrRange) +{ + ACTION_PARAM_START(2); + double range = EvalExpressionF(ParameterIndex+0, self); + ACTION_PARAM_STATE(jump, 1); + + ACTION_SET_RESULT(false); // Jumps should never set the result for inventory state chains! + + range = range * range * (double(FRACUNIT) * FRACUNIT); // no need for square roots + for (int i = 0; i < MAXPLAYERS; ++i) + { + if (playeringame[i]) + { + AActor *camera = players[i].camera; + + // Check distance first, since it's cheaper than checking sight. + double dx = self->x - camera->x; + double dy = self->y - camera->y; + double dz; + fixed_t eyez = (camera->z + camera->height - (camera->height>>2)); // same eye height as P_CheckSight + if (eyez > self->z + self->height) + { + dz = self->z + self->height - eyez; + } + else if (eyez < self->z) + { + dz = self->z - eyez; + } + else + { + dz = 0; + } + if ((dx*dx) + (dy*dy) + (dz*dz) <= range) + { // Within range + return; + } + + // Now check LOS. + if (P_CheckSight(camera, self, true)) + { // Visible + return; + } + } + } + ACTION_JUMP(jump); } diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 90a592c3a..1b8be9933 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -270,6 +270,8 @@ ACTOR Actor native //: Thinker action native A_SetSpecial(int spec, int arg0 = 0, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0); action native A_Quake(int intensity, int duration, int damrad, int tremrad, sound sfx = "world/quake"); + action native A_CheckSightOrRange(float distance, state label); + States { Spawn: