A_CheckThingCount is an action that calls a specified state if the number of active Objects of a specified type is greater than or equal to a specified number. The lower 16 bits of Var1 determine the number to check against; the upper 16 bits determine the Object type to check. The lower 16 bits of Var2 determine the state to call. The upper 16 bits of Var2 determine the range in which to check (in fracunits): Only Objects whose distance to the actor is less than or equal to this value will be counted. If the value is 0, the whole map is checked for Objects to count. Note that Objects that initially spawned with the MF_NOTHINK flag, such as many of the non-animated scenery items included in SRB2, may not be detected and therefore will not be counted.
This action originates from the v2.0 modification SRB2Morphed and was added to SRB2 itself in v2.1.
Code – A_CheckThingCount
|
|
|
// Function: A_CheckThingCount
//
// Description: Calls a state depending on the number of active things in range.
//
// var1:
// lower 16 bits = number of things
// upper 16 bits = thing type
// var2:
// lower 16 bits = state to call
// upper 16 bits = range (if == 0, check whole map)
//
void A_CheckThingCount(mobj_t *actor)
{
INT32 locvar1 = var1;
INT32 locvar2 = var2;
const UINT16 loc1lw = (UINT16)(locvar1 & 65535);
const UINT16 loc1up = (UINT16)(locvar1 >> 16);
const UINT16 loc2lw = (UINT16)(locvar2 & 65535);
const UINT16 loc2up = (UINT16)(locvar2 >> 16);
INT32 count = 0;
thinker_t *th;
mobj_t *mo2;
fixed_t dist = 0;
#ifdef HAVE_BLUA
if (LUA_CallAction("A_CheckThingCount", actor))
return;
#endif
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
{
if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed)
continue;
mo2 = (mobj_t *)th;
if (mo2->type == (mobjtype_t)loc1up)
{
dist = P_AproxDistance(mo2->x - actor->x, mo2->y - actor->y);
if (loc2up == 0)
count++;
else
{
if (dist <= FixedMul(loc2up*FRACUNIT, actor->scale))
count++;
}
}
}
if(loc1lw <= count)
P_SetMobjState(actor, loc2lw);
}
|
|