From 52a24e0bc42a157e049dbb0e6dc453f6576cdc9c Mon Sep 17 00:00:00 2001 From: lachwright Date: Mon, 18 Nov 2019 13:30:07 +0800 Subject: [PATCH] Allow AI Tails to carry the player --- src/b_bot.c | 38 ++++++++++++++++++++------------------ src/p_map.c | 3 --- src/p_user.c | 7 +++++-- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index fd70f88c2..e1c3cf387 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -33,6 +33,17 @@ static boolean spinmode = false; static boolean thinkfly = false; static mobj_t *overlay; +static inline void B_ResetAI() +{ + jump_last = false; + spin_last = false; + anxiety = 0; + panic = false; + flymode = 0; + spinmode = false; + thinkfly = false; +} + static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) { boolean forward=false, backward=false, left=false, right=false, jump=false, spin=false; @@ -135,11 +146,9 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm if (!jump_last) { jump = true; - if (bot->pflags & PF_JUMPED) - { - flymode = 1; - thinkfly = false; - } + flymode = 1; + thinkfly = false; + bot->pflags |= PF_CANCARRY; } } @@ -168,14 +177,8 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm flymode = 0; // Set carried state - if (bot->pflags & PF_THOKKED && flymode == 1 - && !P_IsObjectOnGround(sonic) - && dist < touchdist - && zdist < 32*scale - && flip * sonic->momz < 0) + if (player->powers[pw_carry] == CR_PLAYER && sonic->tracer == tails) { - P_SetTarget(&sonic->tracer, tails); - player->powers[pw_carry] = CR_PLAYER; flymode = 2; player->pflags &= ~PF_JUMPED; } @@ -193,12 +196,9 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm else if (!jump_last) jump = true; // End flymode - if (player->pflags & PF_JUMPED - || player->powers[pw_carry] != CR_PLAYER + if (player->powers[pw_carry] != CR_PLAYER || P_IsObjectOnGround(sonic)) { - player->powers[pw_carry] = CR_NONE; - P_SetTarget(&sonic->tracer, NULL); flymode = 0; } } @@ -379,7 +379,7 @@ void B_BuildTiccmd(player_t *player, ticcmd_t *cmd) void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward, boolean left, boolean right, boolean strafeleft, boolean straferight, boolean jump, boolean spin) { // don't try to do stuff if your sonic is in a minecart or something - if (players[consoleplayer].powers[pw_carry]) + if (players[consoleplayer].powers[pw_carry] && players[consoleplayer].powers[pw_carry] != CR_PLAYER) return; // Turn the virtual keypresses into ticcmd_t. if (twodlevel || mo->flags2 & MF2_TWOD) { @@ -462,7 +462,7 @@ boolean B_CheckRespawn(player_t *player) // If he's doing any of these things, he probably doesn't want to see us. if (sonic->player->pflags & (PF_GLIDING|PF_SLIDING|PF_BOUNCING) || (sonic->player->panim != PA_IDLE && sonic->player->panim != PA_WALK) - || (sonic->player->powers[pw_carry])) + || (sonic->player->powers[pw_carry] && sonic->player->powers[pw_carry] != CR_PLAYER)) return false; // Low ceiling, do not want! @@ -497,6 +497,8 @@ void B_RespawnBot(INT32 playernum) if (!sonic || sonic->health <= 0) return; + B_ResetAI(); + player->bot = 1; P_SpawnPlayer(playernum); tails = player->mo; diff --git a/src/p_map.c b/src/p_map.c index bb56a50b1..29ad6bcbc 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -592,9 +592,6 @@ static void P_DoTailsCarry(player_t *sonic, player_t *tails) if (!(tails->pflags & PF_CANCARRY)) return; - if (tails->bot == 1) - return; - if ((sonic->mo->eflags & MFE_VERTICALFLIP) != (tails->mo->eflags & MFE_VERTICALFLIP)) return; // Both should be in same gravity diff --git a/src/p_user.c b/src/p_user.c index 3c481e7e2..6b4de4598 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -5295,7 +5295,10 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) player->powers[pw_tailsfly] = tailsflytics + 1; // Set the fly timer player->pflags &= ~(PF_JUMPED|PF_NOJUMPDAMAGE|PF_SPINNING|PF_STARTDASH); - player->pflags |= (PF_THOKKED|PF_CANCARRY); + if (player->bot == 1) + player->pflags |= PF_THOKKED; + else + player->pflags |= (PF_THOKKED|PF_CANCARRY); } break; case CA_GLIDEANDCLIMB: @@ -12276,7 +12279,7 @@ void P_PlayerAfterThink(player_t *player) player->mo->momz = tails->momz; } - if (gametype == GT_COOP) + if (gametype == GT_COOP && (!tails->player || tails->player->bot != 1)) { player->mo->angle = tails->angle;