Added GetProximity(classname, distance, flags, ptr).

- Behaves similarly to A_CheckProximity but returns the count of classname instead of true/false.

# Conflicts:
#	wadsrc/static/actors/actor.txt
This commit is contained in:
Major Cooke 2016-07-29 12:50:15 -05:00 committed by Christoph Oelckers
parent d0b953cbb7
commit 167cb28563
4 changed files with 51 additions and 16 deletions

View File

@ -161,7 +161,7 @@ PClassActor *P_GetSpawnableType(int spawnnum);
void InitSpawnablesFromMapinfo(); void InitSpawnablesFromMapinfo();
int P_Thing_CheckInputNum(player_t *p, int inputnum); int P_Thing_CheckInputNum(player_t *p, int inputnum);
int P_Thing_Warp(AActor *caller, AActor *reference, double xofs, double yofs, double zofs, DAngle angle, int flags, double heightoffset, double radiusoffset, DAngle pitch); int P_Thing_Warp(AActor *caller, AActor *reference, double xofs, double yofs, double zofs, DAngle angle, int flags, double heightoffset, double radiusoffset, DAngle pitch);
bool P_Thing_CheckProximity(AActor *self, PClass *classname, double distance, int count, int flags, int ptr); int P_Thing_CheckProximity(AActor *self, PClass *classname, double distance, int count, int flags, int ptr, bool counting = false);
enum enum
{ {

View File

@ -696,16 +696,16 @@ int P_Thing_CheckInputNum(player_t *p, int inputnum)
} }
return renum; return renum;
} }
bool P_Thing_CheckProximity(AActor *self, PClass *classname, double distance, int count, int flags, int ptr) int P_Thing_CheckProximity(AActor *self, PClass *classname, double distance, int count, int flags, int ptr, bool counting)
{ {
AActor *ref = COPY_AAPTR(self, ptr); AActor *ref = COPY_AAPTR(self, ptr);
// We need these to check out. // We need these to check out.
if (!ref || !classname || distance <= 0) if (!ref || !classname || distance <= 0)
return false; return 0;
int counter = 0; int counter = 0;
bool result = false; int result = 0;
double closer = distance, farther = 0, current = distance; double closer = distance, farther = 0, current = distance;
const bool ptrWillChange = !!(flags & (CPXF_SETTARGET | CPXF_SETMASTER | CPXF_SETTRACER)); const bool ptrWillChange = !!(flags & (CPXF_SETTARGET | CPXF_SETMASTER | CPXF_SETTRACER));
const bool ptrDistPref = !!(flags & (CPXF_CLOSEST | CPXF_FARTHEST)); const bool ptrDistPref = !!(flags & (CPXF_CLOSEST | CPXF_FARTHEST));
@ -766,19 +766,19 @@ bool P_Thing_CheckProximity(AActor *self, PClass *classname, double distance, in
{ {
if (!(flags & (CPXF_COUNTDEAD | CPXF_DEADONLY))) if (!(flags & (CPXF_COUNTDEAD | CPXF_DEADONLY)))
continue; continue;
counter++;
} }
else else
{ {
if (flags & CPXF_DEADONLY) if (flags & CPXF_DEADONLY)
continue; continue;
counter++;
} }
counter++;
// Abort if the number of matching classes nearby is greater, we have obviously succeeded in our goal. // Abort if the number of matching classes nearby is greater, we have obviously succeeded in our goal.
if (counter > count) // Don't abort if calling the counting version CheckProximity non-action function.
if (!counting && counter > count)
{ {
result = (flags & (CPXF_LESSOREQUAL | CPXF_EXACT)) ? false : true; result = (flags & (CPXF_LESSOREQUAL | CPXF_EXACT)) ? 0 : 1;
// However, if we have one SET* flag and either the closest or farthest flags, keep the function going. // However, if we have one SET* flag and either the closest or farthest flags, keep the function going.
if (ptrWillChange && ptrDistPref) if (ptrWillChange && ptrDistPref)
@ -805,12 +805,14 @@ bool P_Thing_CheckProximity(AActor *self, PClass *classname, double distance, in
} }
} }
if (!counting)
{
if (counter == count) if (counter == count)
result = true; result = 1;
else if (counter < count) else if (counter < count)
result = !!((flags & CPXF_LESSOREQUAL) && !(flags & CPXF_EXACT)); result = !!((flags & CPXF_LESSOREQUAL) && !(flags & CPXF_EXACT)) ? 1 : 0;
}
return result; return counting ? counter : result;
} }
int P_Thing_Warp(AActor *caller, AActor *reference, double xofs, double yofs, double zofs, DAngle angle, int flags, double heightoffset, double radiusoffset, DAngle pitch) int P_Thing_Warp(AActor *caller, AActor *reference, double xofs, double yofs, double zofs, DAngle angle, int flags, double heightoffset, double radiusoffset, DAngle pitch)

View File

@ -643,6 +643,38 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetPlayerInput)
return 0; return 0;
} }
//==========================================================================
//
// GetProximity
//
// NON-ACTION function of A_CheckProximity that returns how much it counts.
// Takes a pointer as anyone may or may not be a player.
//==========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetProximity)
{
if (numret > 0)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_CLASS(classname, AActor);
PARAM_FLOAT(distance);
PARAM_INT_OPT(flags) { flags = 0; }
PARAM_INT_OPT(ptr) { ptr = AAPTR_DEFAULT; }
AActor *mobj = COPY_AAPTR(self, ptr);
if (mobj == nullptr)
{
ret->SetInt(0);
}
else
{
ret->SetInt(P_Thing_CheckProximity(self, classname, distance, 0, flags, ptr, true));
}
return 1;
}
return 0;
}
//=========================================================================== //===========================================================================
// //
// __decorate_internal_state__ // __decorate_internal_state__

View File

@ -50,6 +50,7 @@ ACTOR Actor native //: Thinker
native float GetCrouchFactor(int ptr = AAPTR_PLAYER1); native float GetCrouchFactor(int ptr = AAPTR_PLAYER1);
native float GetCVar(string cvar); native float GetCVar(string cvar);
native int GetPlayerInput(int inputnum, int ptr = AAPTR_DEFAULT); native int GetPlayerInput(int inputnum, int ptr = AAPTR_DEFAULT);
native int GetProximity(class<Actor> classname, float distance, int flags = 0, int ptr = AAPTR_DEFAULT);
native float GetSpriteAngle(int ptr = AAPTR_DEFAULT); native float GetSpriteAngle(int ptr = AAPTR_DEFAULT);
native float GetSpriteRotation(int ptr = AAPTR_DEFAULT); native float GetSpriteRotation(int ptr = AAPTR_DEFAULT);