mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 13:11:33 +00:00
- added Ryan Cordell's A_CheckRange submission.
This commit is contained in:
parent
5bbb18b6dd
commit
7d56311152
2 changed files with 63 additions and 0 deletions
|
@ -2501,6 +2501,68 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckSightOrRange)
|
|||
ACTION_JUMP(jump);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// A_CheckRange
|
||||
// Jumps if this actor is out of range of all players.
|
||||
//
|
||||
//===========================================================================
|
||||
static bool DoCheckRange(AActor *self, AActor *camera, double range)
|
||||
{
|
||||
if (camera == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 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 true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckRange)
|
||||
{
|
||||
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])
|
||||
{
|
||||
// Always check from each player.
|
||||
if (DoCheckRange(self, players[i].mo, range))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// If a player is viewing from a non-player, check that too.
|
||||
if (players[i].camera != NULL && players[i].camera->player == NULL &&
|
||||
DoCheckRange(self, players[i].camera, range))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
ACTION_JUMP(jump);
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
|
|
|
@ -302,6 +302,7 @@ ACTOR Actor native //: Thinker
|
|||
action native A_SetDamageType(name damagetype);
|
||||
|
||||
action native A_CheckSightOrRange(float distance, state label);
|
||||
action native A_CheckRange(float distance, state label);
|
||||
|
||||
action native A_RearrangePointers(int newtarget, int newmaster = AAPTR_DEFAULT, int newtracer = AAPTR_DEFAULT, int flags=0);
|
||||
action native A_TransferPointer(int ptr_source, int ptr_recepient, int sourcefield, int recepientfield=AAPTR_DEFAULT, int flags=0);
|
||||
|
|
Loading…
Reference in a new issue