From e45282bdff1e2407bf1da605132bc394ffe9ad73 Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 28 Dec 2022 23:31:46 +0000 Subject: [PATCH] K_GetPossibleSpecialTarget() * Standardises conditions under which the UFO Catcher can be "targeted" (Jawz, SPB, tether) * Makes SPBs explode a little ahead of driving distance if UFO Catcher is no longer targetable --- src/k_kart.c | 25 ++++++++++++------------- src/k_roulette.c | 4 +--- src/k_specialstage.c | 15 +++++++++++++++ src/k_specialstage.h | 11 +++++++++++ src/objects/spb.c | 23 ++++++++++++++--------- 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 9bea5e721..80ff8790f 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1339,9 +1339,7 @@ static boolean K_TryDraft(player_t *player, mobj_t *dest, fixed_t minDist, fixed */ static void K_UpdateDraft(player_t *player) { - const boolean addUfo = ((specialstageinfo.valid == true) - && (specialstageinfo.ufo != NULL && P_MobjWasRemoved(specialstageinfo.ufo) == false) - && specialstageinfo.ufo->health > 1); + mobj_t *addUfo = K_GetPossibleSpecialTarget(); fixed_t topspd = K_GetKartSpeed(player, false, false); fixed_t draftdistance; @@ -1381,10 +1379,10 @@ static void K_UpdateDraft(player_t *player) // Not enough speed to draft. if (player->speed >= 20 * player->mo->scale) { - if (addUfo == true) + if (addUfo != NULL) { // Tether off of the UFO! - if (K_TryDraft(player, specialstageinfo.ufo, minDist, draftdistance, leniency) == true) + if (K_TryDraft(player, addUfo, minDist, draftdistance, leniency) == true) { return; // Finished doing our draft. } @@ -1438,11 +1436,11 @@ static void K_UpdateDraft(player_t *player) fixed_t dist = P_AproxDistance(P_AproxDistance(victim->mo->x - player->mo->x, victim->mo->y - player->mo->y), victim->mo->z - player->mo->z); K_DrawDraftCombiring(player, victim->mo, dist, draftdistance, true); } - else if (addUfo == true) + else if (addUfo != NULL) { // kind of a hack to not have to mess with how lastdraft works - fixed_t dist = P_AproxDistance(P_AproxDistance(specialstageinfo.ufo->x - player->mo->x, specialstageinfo.ufo->y - player->mo->y), specialstageinfo.ufo->z - player->mo->z); - K_DrawDraftCombiring(player, specialstageinfo.ufo, dist, draftdistance, true); + fixed_t dist = P_AproxDistance(P_AproxDistance(addUfo->x - player->mo->x, addUfo->y - player->mo->y), addUfo->z - player->mo->z); + K_DrawDraftCombiring(player, addUfo, dist, draftdistance, true); } } else // Remove draft speed boost. @@ -6831,8 +6829,8 @@ mobj_t *K_FindJawzTarget(mobj_t *actor, player_t *source, angle_t range) if (specialstageinfo.valid == true) { - // Always target the UFO. - return specialstageinfo.ufo; + // Always target the UFO (but not the emerald) + return K_GetPossibleSpecialTarget(); } for (i = 0; i < MAXPLAYERS; i++) @@ -8066,10 +8064,11 @@ void K_KartPlayerAfterThink(player_t *player) mobj_t *ret = NULL; - if (specialstageinfo.valid == true && lastTargID == MAXPLAYERS) + if (specialstageinfo.valid == true + && lastTargID == MAXPLAYERS) { - // Aiming at the UFO. - lastTarg = specialstageinfo.ufo; + // Aiming at the UFO (but never the emerald). + lastTarg = K_GetPossibleSpecialTarget(); } else if ((lastTargID >= 0 && lastTargID <= MAXPLAYERS) && playeringame[lastTargID] == true) diff --git a/src/k_roulette.c b/src/k_roulette.c index 1c3c2db62..da12d5209 100644 --- a/src/k_roulette.c +++ b/src/k_roulette.c @@ -1122,9 +1122,7 @@ void K_FillItemRouletteData(const player_t *player, itemroulette_t *const roulet // Use a special, pre-determined item reel for Time Attack / Free Play / End of Sealed Stars if (specialstageinfo.valid) { - if (specialstageinfo.ufo == NULL - || P_MobjWasRemoved(specialstageinfo.ufo) - || specialstageinfo.ufo->health == 1) + if (K_GetPossibleSpecialTarget() == NULL) { for (i = 0; K_KartItemReelSpecialEnd[i] != KITEM_NONE; i++) { diff --git a/src/k_specialstage.c b/src/k_specialstage.c index 76f986bcb..d5eb172ce 100644 --- a/src/k_specialstage.c +++ b/src/k_specialstage.c @@ -121,3 +121,18 @@ void K_TickSpecialStage(void) K_MoveExitBeam(); } + +mobj_t *K_GetPossibleSpecialTarget(void) +{ + if (specialstageinfo.valid == false) + return NULL; + + if (specialstageinfo.ufo == NULL + || P_MobjWasRemoved(specialstageinfo.ufo)) + return NULL; + + if (specialstageinfo.ufo->health <= 1) //UFOEmeraldChase(specialstageinfo.ufo) + return NULL; + + return specialstageinfo.ufo; +} diff --git a/src/k_specialstage.h b/src/k_specialstage.h index 091a39f7d..d12691144 100644 --- a/src/k_specialstage.h +++ b/src/k_specialstage.h @@ -50,5 +50,16 @@ void K_InitSpecialStage(void); void K_TickSpecialStage(void); +/*-------------------------------------------------- + mobj_t *K_GetPossibleSpecialTarget(void) + + Gets the global special stage target if valid + (for Jawz, tether, etc) + + Return:- + Target or NULL +--------------------------------------------------*/ + +mobj_t *K_GetPossibleSpecialTarget(void); #endif diff --git a/src/objects/spb.c b/src/objects/spb.c index 19bb4d7a1..cdb654c5f 100644 --- a/src/objects/spb.c +++ b/src/objects/spb.c @@ -857,6 +857,20 @@ void Obj_SPBThink(mobj_t *spb) ghost->colorized = true; } + if (spb_nothink(spb) <= 1) + { + if (specialstageinfo.valid == true) + { + bestRank = 0; + + if ((bestMobj = K_GetPossibleSpecialTarget()) == NULL) + { + spb->fuse = TICRATE/3; + spb_nothink(spb) = spb->fuse + 2; + } + } + } + if (spb_nothink(spb) > 0) { // Init values, don't think yet. @@ -874,15 +888,6 @@ void Obj_SPBThink(mobj_t *spb) } else { - if (specialstageinfo.valid == true) - { - if (specialstageinfo.ufo != NULL && P_MobjWasRemoved(specialstageinfo.ufo) == false) - { - bestRank = 1; - bestMobj = specialstageinfo.ufo; - } - } - // Find the player with the best rank for (i = 0; i < MAXPLAYERS; i++) {