A_CheckTrueRange is an action that calls the state specified by Var2 if the total distance (in all three dimensions) between the actor and its target or tracer is less than or equal to the value determined by the lower 16 bits of Var1 (in fracunits). If the upper 16 bits of Var1 are 0, the target is used; if they are 1, the tracer is used. If the Z dimension should be ignored in the distance calculation, use A_CheckRange instead.
This action originates from the v2.0 modification SRB2Morphed and was added to SRB2 itself in v2.1.
Code – A_CheckTrueRange
|
|
|
// Function: A_CheckTrueRange
//
// Description: Calls a state if the object's target is in true range. (Checks height, too.)
//
// var1:
// lower 16 bits = range
// upper 16 bits = 0 - target, 1 - tracer
// var2 = state number
//
void A_CheckTrueRange(mobj_t *actor)
{
INT32 locvar1 = var1;
INT32 locvar2 = var2;
fixed_t height; // vertical range
fixed_t dist; // horizontal range
fixed_t l; // true range
#ifdef HAVE_BLUA
if (LUA_CallAction("A_CheckTrueRange", actor))
return;
#endif
if ((!(locvar1 >> 16) && !actor->target) || ((locvar1 >> 16) && !actor->tracer))
return;
if (!(locvar1 >> 16)) // target
{
height = actor->target->z - actor->z;
dist = P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y);
}
else // tracer
{
height = actor->tracer->z - actor->z;
dist = P_AproxDistance(actor->tracer->x - actor->x, actor->tracer->y - actor->y);
}
l = P_AproxDistance(dist, height);
if (l <= FixedMul((locvar1 & 65535)*FRACUNIT, actor->scale))
P_SetMobjState(actor, locvar2);
}
|
|