A_CheckRange is an action that calls a state depending on the absolute horizontal distance between the actor and its target or tracer; the two Objects must be in range of each other for the action to call a state. The lower 16 bits of Var1 determines the maximum horizontal distance, measured in fracunits, between the two Objects to allow the state to be called with – i.e. if the distance between the actor and its target is less than or equal to the lower 16 bits of Var1, the state is called. Var1 can also be interpreted to be the "radius" of a circular area around the actor in which to check for its target – i.e. if the target is within the actor's searching area, the state is called. The upper 16 bits of Var1 determines whether the actor's target (0) or tracer (1) is used. Var2 determines the state to call when this action is successful; see List of states for a full list. If the chosen Object does not exist, this action will do nothing.
This action originates from the v2.0 modification SRB2Morphed and was added to SRB2 itself in v2.1.
Code – A_CheckRange
// Function: A_CheckRange
// Description: Calls a state if the object's target is in range.
// lower 16 bits = range
// upper 16 bits = 0 - target, 1 - tracer
// var2 = state number
void A_CheckRange(mobj_t *actor)
INT32 locvar1 = var1;
INT32 locvar2 = var2;
if (LUA_CallAction("A_CheckRange", actor))
if ((!(locvar1 >> 16) && !actor->target) || ((locvar1 >> 16) && !actor->tracer))
if (!(locvar1 >> 16)) //target
dist = P_AproxDistance(actor->target->x - actor->x, actor->target->y - actor->y);
dist = P_AproxDistance(actor->tracer->x - actor->x, actor->tracer->y - actor->y);
if (dist <= FixedMul((locvar1 & 65535)*FRACUNIT, actor->scale))