diff --git a/src/doomstat.h b/src/doomstat.h index 54c6ae320..f8a3899ca 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -536,18 +536,6 @@ extern mapthing_t *playerstarts[MAXPLAYERS]; // Cooperative extern mapthing_t *bluectfstarts[MAXPLAYERS]; // CTF extern mapthing_t *redctfstarts[MAXPLAYERS]; // CTF -#define WAYPOINTSEQUENCESIZE 256 -#define NUMWAYPOINTSEQUENCES 256 -extern mobj_t *waypoints[NUMWAYPOINTSEQUENCES][WAYPOINTSEQUENCESIZE]; -extern UINT16 numwaypoints[NUMWAYPOINTSEQUENCES]; - -void P_AddWaypoint(UINT8 sequence, UINT8 id, mobj_t *waypoint); -mobj_t *P_GetFirstWaypoint(UINT8 sequence); -mobj_t *P_GetLastWaypoint(UINT8 sequence); -mobj_t *P_GetPreviousWaypoint(mobj_t *current, boolean wrap); -mobj_t *P_GetNextWaypoint(mobj_t *current, boolean wrap); -mobj_t *P_GetClosestWaypoint(UINT8 sequence, mobj_t *mo); - // ===================================== // Internal parameters, used for engine. // ===================================== diff --git a/src/p_mobj.c b/src/p_mobj.c index 3fd74f4a7..3780ef949 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11466,14 +11466,9 @@ ML_NOCLIMB : Direction not controllable mobj->threshold = min(mthing->extrainfo, 7); break; case MT_TUBEWAYPOINT: - { - UINT8 sequence = mthing->angle >> 8; - UINT8 id = mthing->angle & 255; - mobj->health = id; - mobj->threshold = sequence; - P_AddWaypoint(sequence, id, mobj); + mobj->health = mthing->angle & 255; + mobj->threshold = mthing->angle >> 8; break; - } case MT_NIGHTSDRONE: if (mthing->angle > 0) mobj->health = mthing->angle; diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 629595068..53d975e8e 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1803,12 +1803,12 @@ void T_PolyObjMove(polymove_t *th) // void T_PolyObjWaypoint(polywaypoint_t *th) { + mobj_t *mo2; mobj_t *target = NULL; mobj_t *waypoint = NULL; - mobj_t *mo2; + thinker_t *wp; fixed_t adjustx, adjusty, adjustz; fixed_t momx, momy, momz, dist; - thinker_t *wp; INT32 start; polyobj_t *po = Polyobj_GetForNum(th->polyObjNum); polyobj_t *oldpo = po; @@ -1825,7 +1825,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th) #endif // check for displacement due to override and reattach when possible - if (!po->thinker) + if (po->thinker == NULL) po->thinker = &th->thinker; // Find out target first. @@ -1913,7 +1913,39 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { CONS_Debug(DBG_POLYOBJ, "Looking for next waypoint...\n"); - waypoint = (th->direction == -1) ? P_GetPreviousWaypoint(target, false) : P_GetNextWaypoint(target, false); + // Find next waypoint + for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + { + if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker + continue; + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)wp; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) + { + if (mo2->health == target->health - 1) + { + waypoint = mo2; + break; + } + } + else + { + if (mo2->health == target->health + 1) + { + waypoint = mo2; + break; + } + } + } if (!waypoint && th->wrap) // If specified, wrap waypoints { @@ -1923,7 +1955,37 @@ void T_PolyObjWaypoint(polywaypoint_t *th) th->stophere = true; } - waypoint = (th->direction == -1) ? P_GetLastWaypoint(th->sequence) : P_GetFirstWaypoint(th->sequence); + for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + { + if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker + continue; + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)wp; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) + { + if (waypoint == NULL) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; + } + else + { + if (mo2->health == 0) + { + waypoint = mo2; + break; + } + } + } } else if (!waypoint && th->comeback) // Come back to the start { @@ -1932,7 +1994,38 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (!th->continuous) th->comeback = false; - waypoint = (th->direction == -1) ? P_GetPreviousWaypoint(target, false) : P_GetNextWaypoint(target, false); + for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + { + if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker + continue; + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)wp; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) + { + if (mo2->health == target->health - 1) + { + waypoint = mo2; + break; + } + } + else + { + if (mo2->health == target->health + 1) + { + waypoint = mo2; + break; + } + } + } } } @@ -2382,9 +2475,11 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) polyobj_t *po; polyobj_t *oldpo; polywaypoint_t *th; + mobj_t *mo2; mobj_t *first = NULL; mobj_t *last = NULL; mobj_t *target = NULL; + thinker_t *wp; INT32 start; if (!(po = Polyobj_GetForNum(pwdata->polyObjNum))) @@ -2410,7 +2505,10 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) th->polyObjNum = pwdata->polyObjNum; th->speed = pwdata->speed; th->sequence = pwdata->sequence; // Used to specify sequence # - th->direction = pwdata->reverse ? -1 : 1; + if (pwdata->reverse) + th->direction = -1; + else + th->direction = 1; th->comeback = pwdata->comeback; th->continuous = pwdata->continuous; @@ -2418,8 +2516,46 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) th->stophere = false; // Find the first waypoint we need to use - first = (th->direction == -1) ? P_GetLastWaypoint(th->sequence) : P_GetFirstWaypoint(th->sequence); - last = (th->direction == -1) ? P_GetFirstWaypoint(th->sequence) : P_GetLastWaypoint(th->sequence); + for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + { + if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker + continue; + if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)wp; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) // highest waypoint # + { + if (mo2->health == 0) + last = mo2; + else + { + if (first == NULL) + first = mo2; + else if (mo2->health > first->health) + first = mo2; + } + } + else // waypoint 0 + { + if (mo2->health == 0) + first = mo2; + else + { + if (last == NULL) + last = mo2; + else if (mo2->health > last->health) + last = mo2; + } + } + } if (!first) { diff --git a/src/p_setup.c b/src/p_setup.c index a5cf90a2d..fe3a0d7fc 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -149,101 +149,6 @@ mapthing_t *playerstarts[MAXPLAYERS]; mapthing_t *bluectfstarts[MAXPLAYERS]; mapthing_t *redctfstarts[MAXPLAYERS]; -// Maintain waypoints -mobj_t *waypoints[NUMWAYPOINTSEQUENCES][WAYPOINTSEQUENCESIZE]; -UINT16 numwaypoints[NUMWAYPOINTSEQUENCES]; - -void P_AddWaypoint(UINT8 sequence, UINT8 id, mobj_t *waypoint) -{ - waypoints[sequence][id] = waypoint; - if (id >= numwaypoints[sequence]) - numwaypoints[sequence] = id + 1; -} - -static void P_ResetWaypoints(void) -{ - UINT16 sequence, id; - for (sequence = 0; sequence < NUMWAYPOINTSEQUENCES; sequence++) - { - for (id = 0; id < numwaypoints[sequence]; id++) - waypoints[sequence][id] = NULL; - - numwaypoints[sequence] = 0; - } -} - -mobj_t *P_GetFirstWaypoint(UINT8 sequence) -{ - return waypoints[sequence][0]; -} - -mobj_t *P_GetLastWaypoint(UINT8 sequence) -{ - return waypoints[sequence][numwaypoints[sequence] - 1]; -} - -mobj_t *P_GetPreviousWaypoint(mobj_t *current, boolean wrap) -{ - UINT8 sequence = current->threshold; - UINT8 id = current->health; - - if (id == 0) - { - if (!wrap) - return NULL; - - id = numwaypoints[sequence] - 1; - } - else - id--; - - return waypoints[sequence][id]; -} - -mobj_t *P_GetNextWaypoint(mobj_t *current, boolean wrap) -{ - UINT8 sequence = current->threshold; - UINT8 id = current->health; - - if (id == numwaypoints[sequence] - 1) - { - if (!wrap) - return NULL; - - id = 0; - } - else - id++; - - return waypoints[sequence][id]; -} - -mobj_t *P_GetClosestWaypoint(UINT8 sequence, mobj_t *mo) -{ - UINT8 wp; - mobj_t *mo2, *result = NULL; - fixed_t bestdist = 0; - fixed_t curdist; - - for (wp = 0; wp < numwaypoints[sequence]; wp++) - { - mo2 = waypoints[sequence][wp]; - - if (!mo2) - continue; - - curdist = P_AproxDistance(P_AproxDistance(mo->x - mo2->x, mo->y - mo2->y), mo->z - mo2->z); - - if (result && curdist > bestdist) - continue; - - result = mo2; - bestdist = curdist; - } - - return result; -} - // Global state for PartialAddWadFile/MultiSetupWadFiles // Might be replacable with parameters, but non-trivial when the functions are called on separate tics static SINT8 partadd_stage = -1; @@ -3051,8 +2956,6 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) memset(playerstarts, 0, sizeof(playerstarts)); memset(skyboxmo, 0, sizeof(skyboxmo)); - P_ResetWaypoints(); - P_MapStart(); if (lastloadedmaplumpnum) diff --git a/src/p_spec.c b/src/p_spec.c index e14d09333..f12d5b00f 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3737,7 +3737,9 @@ DoneSection2: INT32 sequence; fixed_t speed; INT32 lineindex; + thinker_t *th; mobj_t *waypoint = NULL; + mobj_t *mo2; angle_t an; if (player->mo->tracer && player->mo->tracer->type == MT_TUBEWAYPOINT) @@ -3756,7 +3758,27 @@ DoneSection2: speed = abs(lines[lineindex].dx)/8; sequence = abs(lines[lineindex].dy)>>FRACBITS; - waypoint = P_GetFirstWaypoint(sequence); + // scan the thinkers + // to find the first waypoint + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + if (mo2->threshold != sequence) + continue; + if (mo2->health != 0) + continue; + + waypoint = mo2; + break; + } if (!waypoint) { @@ -3796,7 +3818,9 @@ DoneSection2: INT32 sequence; fixed_t speed; INT32 lineindex; + thinker_t *th; mobj_t *waypoint = NULL; + mobj_t *mo2; angle_t an; if (player->mo->tracer && player->mo->tracer->type == MT_TUBEWAYPOINT) @@ -3815,7 +3839,27 @@ DoneSection2: speed = -(abs(lines[lineindex].dx)/8); // Negative means reverse sequence = abs(lines[lineindex].dy)>>FRACBITS; - waypoint = P_GetLastWaypoint(sequence); + // scan the thinkers + // to find the last waypoint + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + if (mo2->threshold != sequence) + continue; + + if (!waypoint) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; + } if (!waypoint) { @@ -3966,12 +4010,15 @@ DoneSection2: INT32 sequence; fixed_t speed; INT32 lineindex; + thinker_t *th; mobj_t *waypointmid = NULL; mobj_t *waypointhigh = NULL; mobj_t *waypointlow = NULL; + mobj_t *mo2; mobj_t *closest = NULL; line_t junk; vertex_t v1, v2, resulthigh, resultlow; + mobj_t *highest = NULL; if (player->mo->tracer && player->mo->tracer->type == MT_TUBEWAYPOINT) break; @@ -4011,16 +4058,104 @@ DoneSection2: // Determine the closest spot on the line between the three waypoints // Put player at that location. - waypointmid = P_GetClosestWaypoint(sequence, player->mo); + // scan the thinkers + // to find the first waypoint + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; - if (!waypointmid) + mo2 = (mobj_t *)th; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold != sequence) + continue; + + if (!highest) + highest = mo2; + else if (mo2->health > highest->health) // Find the highest waypoint # in case we wrap + highest = mo2; + + if (closest && P_AproxDistance(P_AproxDistance(player->mo->x-mo2->x, player->mo->y-mo2->y), + player->mo->z-mo2->z) > P_AproxDistance(P_AproxDistance(player->mo->x-closest->x, + player->mo->y-closest->y), player->mo->z-closest->z)) + continue; + + // Found a target + closest = mo2; + } + + waypointmid = closest; + + closest = NULL; + + if (waypointmid == NULL) { CONS_Debug(DBG_GAMELOGIC, "ERROR: WAYPOINT(S) IN SEQUENCE %d NOT FOUND.\n", sequence); break; } - waypointlow = P_GetPreviousWaypoint(waypointmid, true); - waypointhigh = P_GetNextWaypoint(waypointmid, true); + // Find waypoint before this one (waypointlow) + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold != sequence) + continue; + + if (waypointmid->health == 0) + { + if (mo2->health != highest->health) + continue; + } + else if (mo2->health != waypointmid->health - 1) + continue; + + // Found a target + waypointlow = mo2; + break; + } + + // Find waypoint after this one (waypointhigh) + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold != sequence) + continue; + + if (waypointmid->health == highest->health) + { + if (mo2->health != 0) + continue; + } + else if (mo2->health != waypointmid->health + 1) + continue; + + // Found a target + waypointhigh = mo2; + break; + } CONS_Debug(DBG_GAMELOGIC, "WaypointMid: %d; WaypointLow: %d; WaypointHigh: %d\n", waypointmid->health, waypointlow ? waypointlow->health : -1, waypointhigh ? waypointhigh->health : -1); @@ -4071,7 +4206,6 @@ DoneSection2: if (lines[lineindex].flags & ML_EFFECT1) // Don't wrap { - mobj_t *highest = P_GetLastWaypoint(sequence); highest->flags |= MF_SLIDEME; } @@ -4083,7 +4217,7 @@ DoneSection2: player->mo->y = resulthigh.y; player->mo->z = resulthigh.z - P_GetPlayerHeight(player); } - else if ((lines[lineindex].flags & ML_EFFECT1) && waypointmid->health == numwaypoints[sequence] - 1) + else if ((lines[lineindex].flags & ML_EFFECT1) && waypointmid->health == highest->health) { closest = waypointmid; player->mo->x = resultlow.x; diff --git a/src/p_user.c b/src/p_user.c index af1e5c2fc..374443042 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2528,7 +2528,10 @@ static void P_MovePlayer(player_t *player) static void P_DoZoomTube(player_t *player) { + INT32 sequence; fixed_t speed; + thinker_t *th; + mobj_t *mo2; mobj_t *waypoint = NULL; fixed_t dist; boolean reverse; @@ -2544,6 +2547,8 @@ static void P_DoZoomTube(player_t *player) speed = abs(player->speed); + sequence = player->mo->tracer->threshold; + // change slope dist = P_AproxDistance(P_AproxDistance(player->mo->tracer->x - player->mo->x, player->mo->tracer->y - player->mo->y), player->mo->tracer->z - player->mo->z); @@ -2575,7 +2580,30 @@ static void P_DoZoomTube(player_t *player) CONS_Debug(DBG_GAMELOGIC, "Looking for next waypoint...\n"); // Find next waypoint - waypoint = reverse ? P_GetPreviousWaypoint(player->mo->tracer, false) : P_GetNextWaypoint(player->mo->tracer, false); + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker + continue; + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + mo2 = (mobj_t *)th; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold != sequence) + continue; + + if (reverse && mo2->health != player->mo->tracer->health - 1) + continue; + + if (!reverse && mo2->health != player->mo->tracer->health + 1) + continue; + + waypoint = mo2; + break; + } if (waypoint) {