mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Move changes to K_GetBestWaypointForMobj so that K_GetClosestWaypointToMobj can stay the same
This commit is contained in:
parent
7fff21acd4
commit
721fb369fd
4 changed files with 50 additions and 52 deletions
|
|
@ -5749,7 +5749,7 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
|
|||
|
||||
if ((player != NULL) && (player->mo != NULL) && (P_MobjWasRemoved(player->mo) == false))
|
||||
{
|
||||
waypoint_t *waypoint = K_GetClosestWaypointToMobj(player->mo);
|
||||
waypoint_t *waypoint = K_GetBestWaypointForMobj(player->mo);
|
||||
boolean updaterespawn = false;
|
||||
|
||||
bestwaypoint = waypoint;
|
||||
|
|
|
|||
|
|
@ -222,8 +222,46 @@ waypoint_t *K_GetClosestWaypointToMobj(mobj_t *const mobj)
|
|||
{
|
||||
checkwaypoint = &waypointheap[i];
|
||||
|
||||
// TODO: Keep the old version of this function,
|
||||
// make the vertical axis faking & sight checks a separate function.
|
||||
checkdist = P_AproxDistance(
|
||||
(mobj->x >> FRACBITS) - (checkwaypoint->mobj->x >> FRACBITS),
|
||||
(mobj->y >> FRACBITS) - (checkwaypoint->mobj->y >> FRACBITS));
|
||||
checkdist = P_AproxDistance(checkdist, (mobj->z >> FRACBITS) - (checkwaypoint->mobj->z >> FRACBITS));
|
||||
|
||||
if (checkdist < closestdist)
|
||||
{
|
||||
closestwaypoint = checkwaypoint;
|
||||
closestdist = checkdist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return closestwaypoint;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
|
||||
|
||||
See header file for description.
|
||||
--------------------------------------------------*/
|
||||
waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
|
||||
{
|
||||
waypoint_t *bestwaypoint = NULL;
|
||||
|
||||
if ((mobj == NULL) || P_MobjWasRemoved(mobj))
|
||||
{
|
||||
CONS_Debug(DBG_GAMELOGIC, "NULL mobj in K_GetBestWaypointForMobj.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t i = 0U;
|
||||
waypoint_t *checkwaypoint = NULL;
|
||||
fixed_t closestdist = INT32_MAX;
|
||||
fixed_t checkdist = INT32_MAX;
|
||||
|
||||
for (i = 0; i < numwaypoints; i++)
|
||||
{
|
||||
checkwaypoint = &waypointheap[i];
|
||||
|
||||
checkdist = P_AproxDistance(
|
||||
(mobj->x >> FRACBITS) - (checkwaypoint->mobj->x >> FRACBITS),
|
||||
(mobj->y >> FRACBITS) - (checkwaypoint->mobj->y >> FRACBITS));
|
||||
|
|
@ -237,49 +275,8 @@ waypoint_t *K_GetClosestWaypointToMobj(mobj_t *const mobj)
|
|||
continue;
|
||||
}
|
||||
|
||||
closestwaypoint = checkwaypoint;
|
||||
closestdist = checkdist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return closestwaypoint;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
waypoint_t *K_GetBestWaypointTouchingMobj(mobj_t *const mobj)
|
||||
|
||||
See header file for description.
|
||||
--------------------------------------------------*/
|
||||
waypoint_t *K_GetBestWaypointTouchingMobj(mobj_t *const mobj)
|
||||
{
|
||||
waypoint_t *bestwaypoint = NULL;
|
||||
|
||||
if ((mobj == NULL) || P_MobjWasRemoved(mobj))
|
||||
{
|
||||
CONS_Debug(DBG_GAMELOGIC, "NULL mobj in K_GetBestWaypointTouchingMobj.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t i = 0U;
|
||||
waypoint_t *checkwaypoint = NULL;
|
||||
fixed_t bestdist = INT32_MAX;
|
||||
fixed_t checkdist = INT32_MAX;
|
||||
|
||||
for (i = 0; i < numwaypoints; i++)
|
||||
{
|
||||
checkwaypoint = &waypointheap[i];
|
||||
checkdist = P_AproxDistance(
|
||||
(mobj->x >> FRACBITS) - (checkwaypoint->mobj->x >> FRACBITS),
|
||||
(mobj->y >> FRACBITS) - (checkwaypoint->mobj->y >> FRACBITS));
|
||||
checkdist = P_AproxDistance(checkdist, (mobj->z >> FRACBITS) - (checkwaypoint->mobj->z >> FRACBITS));
|
||||
|
||||
// The mobj has to be touching this waypoint to use it.
|
||||
if ((checkdist <= (checkwaypoint->mobj->radius >> FRACBITS))
|
||||
&& (checkdist < bestdist))
|
||||
{
|
||||
bestwaypoint = checkwaypoint;
|
||||
bestdist = checkdist;
|
||||
closestdist = checkdist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,17 +152,19 @@ waypoint_t *K_GetClosestWaypointToMobj(mobj_t *const mobj);
|
|||
|
||||
|
||||
/*--------------------------------------------------
|
||||
waypoint_t *K_GetBestWaypointTouchingMobj(mobj_t *const mobj)
|
||||
waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj)
|
||||
|
||||
Returns the waypoint closest to the finish line that an mobj is touching
|
||||
Similar to K_GetClosestWaypointToMobj, but prioritizes horizontal distance over vertical distance, and
|
||||
sight checks to ensure that the waypoint and mobj are the in same area. Can potentially return NULL if
|
||||
there are no visible waypoints.
|
||||
|
||||
Input Arguments:-
|
||||
mobj - mobj to get the waypoint for.
|
||||
|
||||
Return:-
|
||||
The best waypoint for the mobj
|
||||
The best waypoint for the mobj, or NULL if there were no matches
|
||||
--------------------------------------------------*/
|
||||
waypoint_t *K_GetBestWaypointTouchingMobj(mobj_t *const mobj);
|
||||
waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj);
|
||||
|
||||
|
||||
/*--------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -8741,7 +8741,7 @@ void A_SPBChase(mobj_t *actor)
|
|||
{
|
||||
// Previously set nextwaypoint
|
||||
lastwaypoint = K_GetWaypointFromIndex((size_t)actor->cusval);
|
||||
tempwaypoint = K_GetBestWaypointTouchingMobj(actor);
|
||||
tempwaypoint = K_GetBestWaypointForMobj(actor);
|
||||
// check if the tempwaypoint corresponds to lastwaypoint's next ID at least;
|
||||
// This is to avoid situations where the SPB decides to suicide jump down a bridge because it found a COMPLETELY unrelated waypoint down there.
|
||||
|
||||
|
|
@ -8752,7 +8752,7 @@ void A_SPBChase(mobj_t *actor)
|
|||
bestwaypoint = K_GetWaypointFromIndex((size_t)actor->extravalue2); // keep going from the PREVIOUS wp.
|
||||
}
|
||||
else
|
||||
bestwaypoint = K_GetBestWaypointTouchingMobj(actor);
|
||||
bestwaypoint = K_GetBestWaypointForMobj(actor);
|
||||
|
||||
if (bestwaypoint == NULL && lastwaypoint == NULL)
|
||||
{
|
||||
|
|
@ -8781,7 +8781,6 @@ void A_SPBChase(mobj_t *actor)
|
|||
nextwaypoint = lastwaypoint;
|
||||
}
|
||||
|
||||
|
||||
if (nextwaypoint != NULL)
|
||||
{
|
||||
const fixed_t xywaypointdist = P_AproxDistance(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue