From 00697caa6e40ea07fcb2f6fb78c18a770bd1d890 Mon Sep 17 00:00:00 2001 From: lachwright Date: Thu, 3 Oct 2019 12:49:46 +0800 Subject: [PATCH 01/10] Initial commit --- src/b_bot.c | 314 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 277 insertions(+), 37 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index 17211b353..02ac6d1bc 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -24,12 +24,36 @@ static boolean lastForward = false; static boolean lastBlocked = false; static boolean blocked = false; +static boolean jump_last = false; +static boolean spin_last = false; +static UINT8 anxiety = 0; +static boolean panic = false; +static UINT8 flymode = 0; +static boolean spinmode = false; +static boolean thinkfly = false; +static mobj_t *overlay; + 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; - angle_t angle; - INT16 rangle; - fixed_t dist; + + player_t *player = sonic->player, *bot = tails->player; + ticcmd_t *pcmd = &player->cmd; + boolean water = tails->eflags & MFE_UNDERWATER; + boolean flip = P_MobjFlip(tails); + boolean _2d = (tails->flags2 & MF2_TWOD) || twodlevel; + fixed_t scale = tails->scale; + + fixed_t dist = P_AproxDistance(sonic->x - tails->x, sonic->y - tails->y); + fixed_t zdist = flip * (sonic->z - tails->z); + angle_t ang = R_PointToAngle2(tails->x, tails->y, sonic->x, sonic->y); + fixed_t pmom = P_AproxDistance(sonic->momx, sonic->momy); + fixed_t bmom = P_AproxDistance(tails->momx, tails->momy); + fixed_t followmax = 128 * 8 *scale; + fixed_t followthres = 92 * scale; + fixed_t followmin = 32 * scale; + fixed_t comfortheight = 96 * scale; + fixed_t touchdist = 24 * scale; // We can't follow Sonic if he's not around! if (!sonic || sonic->health <= 0) @@ -58,46 +82,255 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm return; } - // Gather data about the environment - dist = P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y); - if (tails->player->pflags & PF_STARTDASH) - angle = sonic->angle; + // Adapted from CobaltBW's tails_AI.wad + + // Check water + if (water) + { + followmin = 0; + followthres = 16*scale; + followmax >>= 1; + thinkfly = false; + } + + // Check anxiety + if (spinmode) + { + anxiety = 0; + panic = false; + } + else if (dist > followmax || zdist > comfortheight) + { + anxiety = min(anxiety + 2, 70); + if (anxiety >= 70) + panic = true; + } else - angle = R_PointToAngle2(tails->x, tails->y, sonic->x, sonic->y); - - // Decide which direction to turn - angle = (tails->angle - angle); - if (angle < ANGLE_180) { - right = true; // We need to turn right - rangle = AngleFixed(angle)>>FRACBITS; - } else { - left = true; // We need to turn left - rangle = 360-(AngleFixed(angle)>>FRACBITS); + { + anxiety = max(anxiety - 1, 0); + panic = false; } - - // Decide to move forward if you're finished turning - if (abs(rangle) < 10) { // We're facing the right way? - left = right = false; // Stop turning - forward = true; // and walk forward instead. + + // Orientation + if ((bot->pflags & (PF_SPINNING|PF_STARTDASH)) || flymode == 2) + { + tails->angle = sonic->angle; } - if (dist < (sonic->radius+tails->radius)*3) // We're close enough? - forward = false; // Stop walking. - - // Decide when to jump - if (!(tails->player->pflags & (PF_JUMPED|PF_JUMPDOWN))) { // We're not jumping yet... - if (forward && lastForward && blocked && lastBlocked) // We've been stopped by a wall or something - jump = true; // Try to jump up - } else if ((tails->player->pflags & (PF_JUMPDOWN|PF_JUMPED)) == (PF_JUMPDOWN|PF_JUMPED)) { // When we're already jumping... - if (lastForward && blocked) // We're still stuck on something? + else + { + tails->angle = ang; + } + + // ******** + // FLY MODE + // spinmode check + if (spinmode) + thinkfly = false; + else + { + // Activate co-op flight + if (thinkfly && player->pflags & PF_JUMPED) + { + if (!jump_last) + { + jump = true; + if (bot->pflags & PF_JUMPED) + { + flymode = 1; + thinkfly = false; + } + } + } + + // Check positioning + // Thinker for co-op flight + if (!(water || pmom || bmom) + && (dist < touchdist) + && !(pcmd->forwardmove || pcmd->sidemove || player->dashspeed) + && P_IsObjectOnGround(sonic) && P_IsObjectOnGround(tails) + && !(player->pflags & PF_STASIS)) + thinkfly = true; + else + thinkfly = false; + + // Ready for takeoff + if (flymode == 1) + { + thinkfly = false; + if (zdist < -64*scale || (flip * tails->momz) > scale) // Make sure we're not too high up + spin = true; + else if (!jump_last) + jump = true; + + // Abort if the player moves away or spins + if (dist > followthres || player->dashspeed) + flymode = 0; + + // Set carried state + if (bot->pflags & PF_THOKKED && flymode == 1 + && !P_IsObjectOnGround(sonic) + && dist < touchdist + && zdist < 32*scale + && flip * sonic->momz < 0) + { + P_SetTarget(&sonic->tracer, tails); + player->powers[pw_carry] = CR_PLAYER; + flymode = 2; + player->pflags &= ~PF_JUMPED; + } + } + // Read player inputs + else if (flymode == 2) + { + cmd->forwardmove = pcmd->forwardmove; + cmd->sidemove = pcmd->sidemove; + if (pcmd->buttons & BT_USE) + { + spin = true; + jump = false; + } + else if (!jump_last) + jump = true; + // End flymode + if (player->pflags & PF_JUMPED + || player->powers[pw_carry] != CR_PLAYER + || P_IsObjectOnGround(sonic)) + { + player->powers[pw_carry] = CR_NONE; + P_SetTarget(&sonic->tracer, NULL); + flymode = 0; + } + } + } + + if (flymode && P_IsObjectOnGround(tails) && !(pcmd->buttons & BT_JUMP)) + flymode = 0; + + // ******** + // SPINNING + if (panic || flymode || !(player->pflags & PF_SPINNING) || (player->pflags & PF_JUMPED)) + spinmode = false; + else + { + if (!_2d) + { + // Spindash + if (player->dashspeed) + { + if (dist < followthres && dist > touchdist) // Do positioning + { + tails->angle = ang; + cmd->forwardmove = 50; + spinmode = true; + } + else if (dist < touchdist && !bmom + && (!(bot->pflags & PF_SPINNING) || (bot->dashspeed && bot->pflags & PF_SPINNING))) + { + tails->angle = sonic->angle; + spin = true; + spinmode = true; + } + else + spinmode = 0; + } + // Spin + else if (player->dashspeed == bot->dashspeed && player->pflags & PF_SPINNING) + { + if (bot->pflags & PF_SPINNING || !spin_last) + { + spin = true; + tails->angle = sonic->angle; + cmd->forwardmove = MAXPLMOVE; + spinmode = true; + } + else + spinmode = false; + } + } + // 2D mode + else + { + if ((player->dashspeed && !bmom) || (player->dashspeed == bot->dashspeed && player->pflags & PF_SPINNING)) + { + spin = true; + spinmode = true; + } + } + } + + // ******** + // FOLLOW + if (!(flymode || spinmode)) + { + // Too far + if (panic || dist > followthres) + { + if (!_2d) + cmd->forwardmove = MAXPLMOVE; + else if (sonic->x > tails->x) + cmd->sidemove = MAXPLMOVE; + else + cmd->sidemove = -MAXPLMOVE; + } + // Within threshold + else if (!panic && dist > followmin && abs(zdist) < 192*scale) + { + if (!_2d) + cmd->forwardmove = FixedHypot(pcmd->forwardmove, pcmd->sidemove); + else + cmd->sidemove = pcmd->sidemove; + } + // Below min + else if (dist < followmin) + { + // Copy inputs + tails->angle = sonic->angle; + bot->drawangle = player->drawangle; + cmd->forwardmove = 8 * pcmd->forwardmove / 10; + cmd->sidemove = 8 * pcmd->sidemove / 10; + } + } + + // ******** + // JUMP + if (!(flymode || spinmode)) + { + // Flying catch-up + if (bot->pflags & PF_THOKKED) + { + cmd->forwardmove = min(50, dist/scale/8); + if (zdist < -64*scale) + spin = true; + else if (zdist > 0 && !jump_last) + jump = true; + } + + // Just landed + if (tails->eflags & MFE_JUSTHITFLOOR) + jump = false; + // Start jump + else if (!jump_last && !(bot->pflags & PF_JUMPED) && !(player->pflags & PF_SPINNING) + && ((zdist > 32*scale && player->pflags & PF_JUMPED) // Following + || (zdist > 64*scale && panic) // Vertical catch-up + || (bmom < scale>>3 && dist > followthres && !(bot->powers[pw_carry])) // Stopped & not in carry state + || (bot->pflags & PF_SPINNING && !(bot->pflags & PF_JUMPED)))) // Spinning + jump = true; + // Hold jump + else if (bot->pflags & PF_JUMPED && jump_last && tails->momz*flip > 0 && (zdist > 0 || panic)) jump = true; - if (sonic->floorz > tails->floorz) // He's still above us? Jump HIGHER, then! + // Start flying + else if (bot->pflags & PF_JUMPED && panic && !jump_last) jump = true; } - - // Decide when to spin - if (sonic->player->pflags & PF_STARTDASH - && (tails->player->pflags & PF_STARTDASH || (P_AproxDistance(tails->momx, tails->momy) < 2*FRACUNIT && !forward))) - spin = true; + + // ******** + // HISTORY + jump_last = jump; + spin_last = spin; + + // ******** + // Thinkfly overlay + // doing this later :P // Turn the virtual keypresses into ticcmd_t. B_KeysToTiccmd(tails, cmd, forward, backward, left, right, false, false, jump, spin); @@ -188,6 +421,13 @@ void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward cmd->sidemove -= MAXPLMOVE<>16; if (straferight) cmd->sidemove += MAXPLMOVE<>16; + + // cap inputs so the bot can't accelerate faster diagonally + angle_t angle = R_PointToAngle2(0, 0, cmd->sidemove << FRACBITS, cmd->forwardmove << FRACBITS); + INT32 maxforward = abs(P_ReturnThrustY(NULL, angle, MAXPLMOVE)); + INT32 maxside = abs(P_ReturnThrustX(NULL, angle, MAXPLMOVE)); + cmd->forwardmove = max(min(cmd->forwardmove, maxforward), -maxforward); + cmd->sidemove = max(min(cmd->sidemove, maxside), -maxside); } if (jump) cmd->buttons |= BT_JUMP; From b120193eb72ea66112e5a70c3b6a6c87d5a53056 Mon Sep 17 00:00:00 2001 From: lachwright Date: Sat, 5 Oct 2019 02:48:20 +0800 Subject: [PATCH 02/10] Fix AI angling --- src/b_bot.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index 02ac6d1bc..be1d9dd60 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -114,11 +114,11 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm // Orientation if ((bot->pflags & (PF_SPINNING|PF_STARTDASH)) || flymode == 2) { - tails->angle = sonic->angle; + cmd->angleturn = (sonic->angle - tails->angle) >> FRACBITS; } else { - tails->angle = ang; + cmd->angleturn = (ang - tails->angle) >> FRACBITS; } // ******** @@ -219,14 +219,14 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm { if (dist < followthres && dist > touchdist) // Do positioning { - tails->angle = ang; + cmd->angleturn = (ang - tails->angle) >> FRACBITS; cmd->forwardmove = 50; spinmode = true; } else if (dist < touchdist && !bmom && (!(bot->pflags & PF_SPINNING) || (bot->dashspeed && bot->pflags & PF_SPINNING))) { - tails->angle = sonic->angle; + cmd->angleturn = (sonic->angle - tails->angle) >> FRACBITS; spin = true; spinmode = true; } @@ -239,7 +239,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm if (bot->pflags & PF_SPINNING || !spin_last) { spin = true; - tails->angle = sonic->angle; + cmd->angleturn = (sonic->angle - tails->angle) >> FRACBITS; cmd->forwardmove = MAXPLMOVE; spinmode = true; } @@ -284,7 +284,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm else if (dist < followmin) { // Copy inputs - tails->angle = sonic->angle; + cmd->angleturn = (sonic->angle - tails->angle) >> FRACBITS; bot->drawangle = player->drawangle; cmd->forwardmove = 8 * pcmd->forwardmove / 10; cmd->sidemove = 8 * pcmd->sidemove / 10; From b180fd7c91110295eaef89ad33962f5aa60fb7bc Mon Sep 17 00:00:00 2001 From: lachwright Date: Sat, 5 Oct 2019 03:02:27 +0800 Subject: [PATCH 03/10] Update to 9/25 Lua script --- src/b_bot.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index be1d9dd60..7d6732365 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -223,11 +223,13 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm cmd->forwardmove = 50; spinmode = true; } - else if (dist < touchdist && !bmom - && (!(bot->pflags & PF_SPINNING) || (bot->dashspeed && bot->pflags & PF_SPINNING))) + else if (dist < touchdist) { - cmd->angleturn = (sonic->angle - tails->angle) >> FRACBITS; - spin = true; + if (!bmom && (!(bot->pflags & PF_SPINNING) || (bot->dashspeed && bot->pflags & PF_SPINNING))) + { + cmd->angleturn = (sonic->angle - tails->angle) >> FRACBITS; + spin = true; + } spinmode = true; } else From 800052a746a953f3f05ee13c6429b5a0589073ab Mon Sep 17 00:00:00 2001 From: lachwright Date: Wed, 6 Nov 2019 13:59:53 +0800 Subject: [PATCH 04/10] WIP update to latest version of Lua script, halted because script inconsistencies still exist --- src/b_bot.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index fdccd08a4..e4c3a2110 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -36,24 +36,25 @@ static mobj_t *overlay; 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; - + player_t *player = sonic->player, *bot = tails->player; ticcmd_t *pcmd = &player->cmd; boolean water = tails->eflags & MFE_UNDERWATER; boolean flip = P_MobjFlip(tails); boolean _2d = (tails->flags2 & MF2_TWOD) || twodlevel; fixed_t scale = tails->scale; - + fixed_t dist = P_AproxDistance(sonic->x - tails->x, sonic->y - tails->y); fixed_t zdist = flip * (sonic->z - tails->z); angle_t ang = R_PointToAngle2(tails->x, tails->y, sonic->x, sonic->y); fixed_t pmom = P_AproxDistance(sonic->momx, sonic->momy); fixed_t bmom = P_AproxDistance(tails->momx, tails->momy); - fixed_t followmax = 128 * 8 *scale; - fixed_t followthres = 92 * scale; + fixed_t followmax = 128 * 8 * scale; // Max follow distance before AI begins to enter "panic" state + fixed_t followthres = 92 * scale; // Distance that AI will try to reach fixed_t followmin = 32 * scale; fixed_t comfortheight = 96 * scale; fixed_t touchdist = 24 * scale; + boolean stalled = (bmom < scale >> 1) && dist > followthres; // Helps to see if the AI is having trouble catching up // We can't follow Sonic if he's not around! if (!sonic || sonic->health <= 0) @@ -83,7 +84,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm } // Adapted from CobaltBW's tails_AI.wad - + // Check water if (water) { @@ -92,14 +93,14 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm followmax >>= 1; thinkfly = false; } - + // Check anxiety if (spinmode) { anxiety = 0; panic = false; } - else if (dist > followmax || zdist > comfortheight) + else if (dist > followmax || zdist > comfortheight || stalled) { anxiety = min(anxiety + 2, 70); if (anxiety >= 70) @@ -110,7 +111,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm anxiety = max(anxiety - 1, 0); panic = false; } - + // Orientation if ((bot->pflags & (PF_SPINNING|PF_STARTDASH)) || flymode == 2) { @@ -120,7 +121,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm { cmd->angleturn = (ang - tails->angle) >> FRACBITS; } - + // ******** // FLY MODE // spinmode check @@ -141,7 +142,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm } } } - + // Check positioning // Thinker for co-op flight if (!(water || pmom || bmom) From bf4dbead748acbc66b4abefa5891f31419314f31 Mon Sep 17 00:00:00 2001 From: lachwright Date: Mon, 18 Nov 2019 11:22:27 +0800 Subject: [PATCH 05/10] Update to latest script version --- src/b_bot.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index e4c3a2110..fd70f88c2 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -153,7 +153,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm thinkfly = true; else thinkfly = false; - + // Ready for takeoff if (flymode == 1) { @@ -180,7 +180,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm player->pflags &= ~PF_JUMPED; } } - // Read player inputs + // Read player inputs while carrying else if (flymode == 2) { cmd->forwardmove = pcmd->forwardmove; @@ -203,10 +203,10 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm } } } - + if (flymode && P_IsObjectOnGround(tails) && !(pcmd->buttons & BT_JUMP)) flymode = 0; - + // ******** // SPINNING if (panic || flymode || !(player->pflags & PF_SPINNING) || (player->pflags & PF_JUMPED)) @@ -234,7 +234,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm spinmode = true; } else - spinmode = 0; + spinmode = false; } // Spin else if (player->dashspeed == bot->dashspeed && player->pflags & PF_SPINNING) @@ -253,14 +253,15 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm // 2D mode else { - if ((player->dashspeed && !bmom) || (player->dashspeed == bot->dashspeed && player->pflags & PF_SPINNING)) + if (((player->dashspeed && !bmom) || (player->dashspeed == bot->dashspeed && (player->pflags & PF_SPINNING))) + && ((bot->pflags & PF_SPINNING) || !spin_last)) { spin = true; spinmode = true; } } } - + // ******** // FOLLOW if (!(flymode || spinmode)) @@ -288,7 +289,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm { // Copy inputs cmd->angleturn = (sonic->angle - tails->angle) >> FRACBITS; - bot->drawangle = player->drawangle; + bot->drawangle = ang; cmd->forwardmove = 8 * pcmd->forwardmove / 10; cmd->sidemove = 8 * pcmd->sidemove / 10; } @@ -301,21 +302,22 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm // Flying catch-up if (bot->pflags & PF_THOKKED) { - cmd->forwardmove = min(50, dist/scale/8); + cmd->forwardmove = min(MAXPLMOVE, (dist/scale)>>3); if (zdist < -64*scale) spin = true; else if (zdist > 0 && !jump_last) jump = true; } - + // Just landed if (tails->eflags & MFE_JUSTHITFLOOR) jump = false; // Start jump - else if (!jump_last && !(bot->pflags & PF_JUMPED) && !(player->pflags & PF_SPINNING) + else if (!jump_last && !(bot->pflags & PF_JUMPED) //&& !(player->pflags & PF_SPINNING) && ((zdist > 32*scale && player->pflags & PF_JUMPED) // Following || (zdist > 64*scale && panic) // Vertical catch-up - || (bmom < scale>>3 && dist > followthres && !(bot->powers[pw_carry])) // Stopped & not in carry state + || (stalled && anxiety > 20 && bot->powers[pw_carry] == CR_NONE) + //|| (bmom < scale>>3 && dist > followthres && !(bot->powers[pw_carry])) // Stopped & not in carry state || (bot->pflags & PF_SPINNING && !(bot->pflags & PF_JUMPED)))) // Spinning jump = true; // Hold jump @@ -325,12 +327,12 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm else if (bot->pflags & PF_JUMPED && panic && !jump_last) jump = true; } - + // ******** // HISTORY jump_last = jump; spin_last = spin; - + // ******** // Thinkfly overlay // doing this later :P From 52a24e0bc42a157e049dbb0e6dc453f6576cdc9c Mon Sep 17 00:00:00 2001 From: lachwright Date: Mon, 18 Nov 2019 13:30:07 +0800 Subject: [PATCH 06/10] 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; From 70051bd794e96b882ef5a23a2656321da9bce0eb Mon Sep 17 00:00:00 2001 From: lachwright Date: Mon, 18 Nov 2019 13:37:09 +0800 Subject: [PATCH 07/10] Don't let the bot decide to fly if it doesn't have the ability to fly --- src/b_bot.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index e1c3cf387..ce7807321 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -158,7 +158,8 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm && (dist < touchdist) && !(pcmd->forwardmove || pcmd->sidemove || player->dashspeed) && P_IsObjectOnGround(sonic) && P_IsObjectOnGround(tails) - && !(player->pflags & PF_STASIS)) + && !(player->pflags & PF_STASIS) + && bot->charability == CA_FLY) thinkfly = true; else thinkfly = false; @@ -324,7 +325,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm else if (bot->pflags & PF_JUMPED && jump_last && tails->momz*flip > 0 && (zdist > 0 || panic)) jump = true; // Start flying - else if (bot->pflags & PF_JUMPED && panic && !jump_last) + else if (bot->pflags & PF_JUMPED && panic && !jump_last && bot->charability == CA_FLY) jump = true; } From bb67b24143da5b9d4fd050ecb8f3cfba2abf39a6 Mon Sep 17 00:00:00 2001 From: lachwright Date: Mon, 18 Nov 2019 15:17:27 +0800 Subject: [PATCH 08/10] Add flight indicator --- src/b_bot.c | 15 ++++++++++++++- src/dehacked.c | 2 ++ src/hardware/hw_light.c | 1 + src/info.c | 4 ++++ src/info.h | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/b_bot.c b/src/b_bot.c index ce7807321..d3fc25aa6 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -336,7 +336,20 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm // ******** // Thinkfly overlay - // doing this later :P + if (thinkfly) + { + if (overlay == NULL) + { + overlay = P_SpawnMobjFromMobj(tails, 0, 0, 0, MT_OVERLAY); + P_SetTarget(&overlay->target, tails); + P_SetMobjState(overlay, S_FLIGHTINDICATOR); + } + } + else if (overlay != NULL) + { + P_RemoveMobj(overlay); + overlay = NULL; + } // Turn the virtual keypresses into ticcmd_t. B_KeysToTiccmd(tails, cmd, forward, backward, left, right, false, false, jump, spin); diff --git a/src/dehacked.c b/src/dehacked.c index fff9dbee8..cce596289 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -7139,6 +7139,8 @@ static const char *const STATE_LIST[] = { // array length left dynamic for sanit "S_FOUR2", "S_FIVE2", + "S_FLIGHTINDICATOR", + "S_LOCKON1", "S_LOCKON2", "S_LOCKON3", diff --git a/src/hardware/hw_light.c b/src/hardware/hw_light.c index 491cb739f..09545f28f 100644 --- a/src/hardware/hw_light.c +++ b/src/hardware/hw_light.c @@ -505,6 +505,7 @@ light_t *t_lspr[NUMSPRITES] = // Game Indicators &lspr[NOLIGHT], // SPR_SCOR &lspr[NOLIGHT], // SPR_DRWN + &lspr[NOLIGHT], // SPR_FLII &lspr[NOLIGHT], // SPR_LCKN &lspr[NOLIGHT], // SPR_TTAG &lspr[NOLIGHT], // SPR_GFLG diff --git a/src/info.c b/src/info.c index ed29fe2bf..125babd7d 100644 --- a/src/info.c +++ b/src/info.c @@ -402,6 +402,7 @@ char sprnames[NUMSPRITES + 1][5] = // Game Indicators "SCOR", // Score logo "DRWN", // Drowning Timer + "FLII", // Flight indicator "LCKN", // Target "TTAG", // Tag Sign "GFLG", // Got Flag sign @@ -3319,6 +3320,9 @@ state_t states[NUMSTATES] = {SPR_DRWN, 10, 40, {NULL}, 0, 0, S_NULL}, // S_FOUR2 {SPR_DRWN, 11, 40, {NULL}, 0, 0, S_NULL}, // S_FIVE2 + // Flight indicator + {SPR_FLII, FF_FULLBRIGHT|FF_ANIMATE|0, -1, {NULL}, 4, 4, S_NULL}, // S_FLIGHTINDICATOR + {SPR_LCKN, FF_FULLBRIGHT, 2, {NULL}, 0, 0, S_NULL}, // S_LOCKON1 {SPR_LCKN, 1|FF_FULLBRIGHT, 2, {NULL}, 0, 0, S_NULL}, // S_LOCKON2 {SPR_LCKN, 2|FF_FULLBRIGHT, 2, {NULL}, 0, 0, S_NULL}, // S_LOCKON3 diff --git a/src/info.h b/src/info.h index bbb6a21fc..16e535384 100644 --- a/src/info.h +++ b/src/info.h @@ -664,6 +664,7 @@ typedef enum sprite // Game Indicators SPR_SCOR, // Score logo SPR_DRWN, // Drowning Timer + SPR_FLII, // AI flight indicator SPR_LCKN, // Target SPR_TTAG, // Tag Sign SPR_GFLG, // Got Flag sign @@ -3454,6 +3455,8 @@ typedef enum state S_FOUR2, S_FIVE2, + S_FLIGHTINDICATOR, + S_LOCKON1, S_LOCKON2, S_LOCKON3, From f682de3f1b429c38cf8db428bb6ee2528075a4bb Mon Sep 17 00:00:00 2001 From: lachwright Date: Mon, 18 Nov 2019 15:55:55 +0800 Subject: [PATCH 09/10] Fix controllable flight ending when player hits the ground while being carried by Tailsbot --- src/b_bot.c | 4 +--- src/p_user.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index d3fc25aa6..0740dba4e 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -181,7 +181,6 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm if (player->powers[pw_carry] == CR_PLAYER && sonic->tracer == tails) { flymode = 2; - player->pflags &= ~PF_JUMPED; } } // Read player inputs while carrying @@ -197,8 +196,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm else if (!jump_last) jump = true; // End flymode - if (player->powers[pw_carry] != CR_PLAYER - || P_IsObjectOnGround(sonic)) + if (player->powers[pw_carry] != CR_PLAYER) { flymode = 0; } diff --git a/src/p_user.c b/src/p_user.c index 6b4de4598..837d7d75c 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8367,7 +8367,7 @@ static void P_MovePlayer(player_t *player) // Tails Put-Put noise if (player->charability == CA_FLY - && player->bot != 1 + && (player->pflags & PF_CANCARRY) && !(player->mo->eflags & MFE_UNDERWATER) && leveltime % 10 == 0 && !player->spectator) From 508fdb493b08d9938f15044f3c88f8c93ee2f4a8 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 18 Nov 2019 19:22:51 +0000 Subject: [PATCH 10/10] compilation fixes (no review yet, currently just about to have dinner) --- src/b_bot.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index 0740dba4e..badc36b27 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -33,7 +33,7 @@ static boolean spinmode = false; static boolean thinkfly = false; static mobj_t *overlay; -static inline void B_ResetAI() +static inline void B_ResetAI(void) { jump_last = false; spin_last = false; @@ -429,6 +429,7 @@ void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward cmd->sidemove += MAXPLMOVE<>16; } } else { + angle_t angle; if (forward) cmd->forwardmove += MAXPLMOVE<>16; if (backward) @@ -443,7 +444,7 @@ void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward cmd->sidemove += MAXPLMOVE<>16; // cap inputs so the bot can't accelerate faster diagonally - angle_t angle = R_PointToAngle2(0, 0, cmd->sidemove << FRACBITS, cmd->forwardmove << FRACBITS); + angle = R_PointToAngle2(0, 0, cmd->sidemove << FRACBITS, cmd->forwardmove << FRACBITS); INT32 maxforward = abs(P_ReturnThrustY(NULL, angle, MAXPLMOVE)); INT32 maxside = abs(P_ReturnThrustX(NULL, angle, MAXPLMOVE)); cmd->forwardmove = max(min(cmd->forwardmove, maxforward), -maxforward);