From 165b3fe8ece5f6a6fc4015db455520d7df3b6581 Mon Sep 17 00:00:00 2001 From: Cong Date: Wed, 9 Nov 2022 14:00:43 +1100 Subject: [PATCH] Don't auto melee if player shooting #742 --- src/cdogs/actors.c | 20 ++++++++++++-------- src/cdogs/actors.h | 3 ++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/cdogs/actors.c b/src/cdogs/actors.c index c7d0a9c90..149b49b3e 100644 --- a/src/cdogs/actors.c +++ b/src/cdogs/actors.c @@ -301,7 +301,7 @@ static struct vec2 GetConstrainedPos( const Map *map, const struct vec2 from, const struct vec2 to, const struct vec2i size); static void OnMove(TActor *a); -bool TryMoveActor(TActor *actor, struct vec2 pos) +static bool TryMoveActor(TActor *actor, struct vec2 pos) { CASSERT( !svec2_is_nearly_equal(actor->Pos, pos, EPSILON_POS), @@ -329,11 +329,12 @@ bool TryMoveActor(TActor *actor, struct vec2 pos) if (target && actor->health > 0) { // We are running into an object or actor - // If we have an auto-melee weapon, switch to it + // If we have an auto-melee weapon and aren't shooting, switch to it const Weapon *meleeW = &actor->guns[MELEE_SLOT]; if (actor->gunIndex != MELEE_SLOT && meleeW->Gun && meleeW->Gun->Type == GUNTYPE_MELEE && meleeW->Gun->u.Normal.Auto && + !actor->hasShot && CanMeleeTarget(actor, meleeW, target)) { GameEvent e = GameEventNew(GAME_EVENT_ACTOR_SWITCH_GUN); @@ -1023,9 +1024,10 @@ static bool TryGrenade(TActor *a, const int cmd) return willGrenade; } -static bool ActorTryMove(TActor *actor, int cmd, int hasShot, int ticks); +static bool ActorTryMove(TActor *actor, int cmd, int ticks); void CommandActor(TActor *actor, int cmd, int ticks) { + actor->hasShot = false; // If this is a pilot, command the vehicle instead if (actor->vehicleUID != -1) { @@ -1048,12 +1050,14 @@ void CommandActor(TActor *actor, int cmd, int ticks) { const bool hasChangedDirection = ActorTryChangeDirection(actor, cmd, actor->lastCmd); - const bool hasShot = ActorTryShoot(actor, cmd); + actor->hasShot = ActorTryShoot(actor, cmd); const bool hasGrenaded = TryGrenade(actor, cmd); - const bool hasMoved = ActorTryMove(actor, cmd, hasShot, ticks); + const bool hasMoved = + ActorTryMove(actor, cmd, ticks); ActorAnimation anim = actor->anim.Type; // Idle if player hasn't done anything - if (!(hasChangedDirection || hasShot || hasGrenaded || hasMoved)) + if (!(hasChangedDirection || actor->hasShot || hasGrenaded || + hasMoved)) { anim = ACTORANIMATION_IDLE; } @@ -1091,11 +1095,11 @@ void CommandActor(TActor *actor, int cmd, int ticks) actor->lastCmd = cmd; } -static bool ActorTryMove(TActor *actor, int cmd, int hasShot, int ticks) +static bool ActorTryMove(TActor *actor, int cmd, int ticks) { const bool canMoveWhenShooting = ConfigGetEnum(&gConfig, "Game.FireMoveStyle") != FIREMOVE_STOP || - !hasShot || + !actor->hasShot || (ConfigGetEnum(&gConfig, "Game.SwitchMoveStyle") == SWITCHMOVE_STRAFE && (cmd & CMD_BUTTON2)); diff --git a/src/cdogs/actors.h b/src/cdogs/actors.h index 731e0ab45..a252c116b 100644 --- a/src/cdogs/actors.h +++ b/src/cdogs/actors.h @@ -171,6 +171,8 @@ typedef struct Actor color_t footprintMask; int footprintCounter; + bool hasShot; + // Signals to other AIs what this actor is doing ActorAction action; AIContext *aiContext; @@ -190,7 +192,6 @@ extern CArray gActors; // of TActor void ActorSetState(TActor *actor, const ActorAnimation state); void UpdateActorState(TActor *actor, int ticks); -bool TryMoveActor(TActor *actor, struct vec2 pos); void ActorMove(const NActorMove am); void CommandActor(TActor *actor, int cmd, int ticks); void SlideActor(TActor *actor, int cmd);