Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FOV args to A_JumpIf[Tracer/Target]InSight codepointers #49

Merged
merged 3 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions prboom2/doc/mbf21.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ MBF21 defaults:
- For future-proofing, if more nonzero args are defined on a state than its action pointer expects (e.g. defining Args3 on a state that uses A_WeaponSound), an error will be thrown on startup.

#### New DEHACKED Codepointers
- [PR](https://github.com/kraflab/dsda-doom/pull/20), [PR](https://github.com/kraflab/dsda-doom/pull/38), [PR](https://github.com/kraflab/dsda-doom/pull/40), [PR](https://github.com/kraflab/dsda-doom/pull/41), [PR](https://github.com/kraflab/dsda-doom/pull/45)
- [PR](https://github.com/kraflab/dsda-doom/pull/20), [PR](https://github.com/kraflab/dsda-doom/pull/38), [PR](https://github.com/kraflab/dsda-doom/pull/40), [PR](https://github.com/kraflab/dsda-doom/pull/41), [PR](https://github.com/kraflab/dsda-doom/pull/45), [PR](https://github.com/kraflab/dsda-doom/pull/49)
- All new MBF21 pointers use the new "Args" fields for params, rather than misc1/misc2 fields
- Arg fields are listed in order in the docs below, e.g. for `A_SpawnObject`, `type` is Args1, `angle` is Args2, etc.
- Although all args are integers internally, there are effectively the following types of args:
Expand Down Expand Up @@ -338,8 +338,7 @@ MBF21 defaults:
- Jumps to a state if caller's target is in line-of-sight.
- Args:
- `state (uint)`: State to jump to
- Notes:
- This function only considers line-of-sight, i.e. independent of calling actor's facing direction.
- `fov (fixed)`: Field-of-view, relative to calling actor's angle, to check for target in. If zero, the check will occur in all directions.

- **A_JumpIfTargetCloser(state, distance)**
- Jumps to a state if caller's target is closer than the specified distance.
Expand All @@ -354,8 +353,7 @@ MBF21 defaults:
- Jumps to a state if caller's tracer (seek target) is in line-of-sight.
- Args:
- `state (uint)`: State to jump to
- Notes:
- This function only considers line-of-sight, i.e. independent of calling actor's facing direction.
- `fov (fixed)`: Field-of-view, relative to calling actor's angle, to check for tracer in. If zero, the check will occur in all directions.

- **A_JumpIfTracerCloser(state, distance)**
- Jumps to a state if caller's tracer (seek target) is closer than the specified distance.
Expand Down
4 changes: 2 additions & 2 deletions prboom2/src/d_deh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,9 +1498,9 @@ static const deh_bexptr deh_bexptrs[] = // CPhipps - static const
{A_FindTracer, "A_FindTracer", 2, {0, 10}},
{A_ClearTracer, "A_ClearTracer", 0},
{A_JumpIfHealthBelow, "A_JumpIfHealthBelow", 2},
{A_JumpIfTargetInSight, "A_JumpIfTargetInSight", 1},
{A_JumpIfTargetInSight, "A_JumpIfTargetInSight", 2},
{A_JumpIfTargetCloser, "A_JumpIfTargetCloser", 2},
{A_JumpIfTracerInSight, "A_JumpIfTracerInSight", 1},
{A_JumpIfTracerInSight, "A_JumpIfTracerInSight", 2},
{A_JumpIfTracerCloser, "A_JumpIfTracerCloser", 2},
{A_JumpIfFlagsSet, "A_JumpIfFlagsSet", 3},
{A_AddFlags, "A_AddFlags", 2},
Expand Down
18 changes: 16 additions & 2 deletions prboom2/src/p_enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3324,15 +3324,22 @@ void A_JumpIfHealthBelow(mobj_t* actor)
// A_JumpIfTargetInSight
// Jumps to a state if caller's target is in line-of-sight.
// args[0]: State to jump to
// args[1]: Field-of-view to check (degrees, in fixed point); if zero, will check in all directions
//
void A_JumpIfTargetInSight(mobj_t* actor)
{
int state;
angle_t fov;

if (!mbf21 || !actor || !actor->target)
return;

state = actor->state->args[0];
state = (actor->state->args[0]);
fov = FixedToAngle(actor->state->args[1]);

// Check FOV first since it's faster
if (fov > 0 && !P_CheckFov(actor, actor->target, fov))
return;

if (P_CheckSight(actor, actor->target))
P_SetMobjState(actor, state);
Expand Down Expand Up @@ -3363,15 +3370,22 @@ void A_JumpIfTargetCloser(mobj_t* actor)
// A_JumpIfTracerInSight
// Jumps to a state if caller's tracer (seek target) is in line-of-sight.
// args[0]: State to jump to
// args[1]: Field-of-view to check (degrees, in fixed point); if zero, will check in all directions
//
void A_JumpIfTracerInSight(mobj_t* actor)
{
angle_t fov;
int state;

if (!mbf21 || !actor || !actor->tracer)
return;

state = actor->state->args[0];
state = (actor->state->args[0]);
fov = FixedToAngle(actor->state->args[1]);

// Check FOV first since it's faster
if (fov > 0 && !P_CheckFov(actor, actor->tracer, fov))
return;

if (P_CheckSight(actor, actor->tracer))
P_SetMobjState(actor, state);
Expand Down
1 change: 1 addition & 0 deletions prboom2/src/p_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dboolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, dboolean dropoff);
dboolean P_TeleportMove(mobj_t *thing, fixed_t x, fixed_t y,dboolean boss);
void P_SlideMove(mobj_t *mo);
dboolean P_CheckSight(mobj_t *t1, mobj_t *t2);
dboolean P_CheckFov(mobj_t *t1, mobj_t *t2, angle_t fov);
void P_UseLines(player_t *player);

typedef dboolean (*CrossSubsectorFunc)(int num);
Expand Down
21 changes: 3 additions & 18 deletions prboom2/src/p_maputl.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,14 +733,6 @@ dboolean P_PathTraverse(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2,
static mobj_t *RoughBlockCheck(mobj_t *mo, int index, angle_t fov)
{
mobj_t *link;
angle_t angle, minang, maxang;

// pre-calculate fov check stuff since it
// won't change during the blocklinks loop
if (fov > 0) {
minang = mo->angle - fov / 2;
maxang = mo->angle + fov / 2;
}

link = blocklinks[index];
while (link)
Expand Down Expand Up @@ -770,17 +762,10 @@ static mobj_t *RoughBlockCheck(mobj_t *mo, int index, angle_t fov)
}

// skip actors outside of specified FOV
// [XA] code borrowed from EE; thanks Quas :D
if (fov > 0)
if (fov > 0 && !P_CheckFov(mo, link, fov))
{
angle = R_PointToAngle2(mo->x, mo->y, link->x, link->y);
// if the angles are backward, compare differently
if((minang > maxang) ? angle < minang && angle > maxang
: angle < minang || angle > maxang)
{
link = link->bnext;
continue;
}
link = link->bnext;
continue;
}

// skip actors not in line of sight
Expand Down
20 changes: 20 additions & 0 deletions prboom2/src/p_sight.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,23 @@ dboolean P_CheckSight(mobj_t *t1, mobj_t *t2)
// the head node is the last node output
return P_CrossBSPNode(numnodes-1);
}

//
// P_CheckFov
// Returns true if t2 is within t1's field of view.
// Not directly related to P_CheckSight, but often
// used in tandem.
//
// Adapted from Eternity, so big thanks to Quasar
//
dboolean P_CheckFov(mobj_t *t1, mobj_t *t2, angle_t fov)
{
angle_t angle, minang, maxang;

angle = R_PointToAngle2(t1->x, t1->y, t2->x, t2->y);
minang = t1->angle - fov / 2;
maxang = t1->angle + fov / 2;

return((minang > maxang) ? angle >= minang || angle <= maxang
: angle >= minang && angle <= maxang);
}