diff --git a/src/cdogs/actors.c b/src/cdogs/actors.c index 677d6eabb..2cd29cd74 100644 --- a/src/cdogs/actors.c +++ b/src/cdogs/actors.c @@ -1055,7 +1055,7 @@ static bool TryGrenade(TActor *a, const int cmd) } static bool ActorTryMove(TActor *actor, int cmd, int ticks); -void CommandActor(TActor *actor, int cmd, int ticks) +int CommandActor(TActor *actor, int cmd, int ticks) { GameEvent e; // If the actor is currently using a menu, control the menu instead @@ -1084,8 +1084,11 @@ void CommandActor(TActor *actor, int cmd, int ticks) actor->pickupMenu.pickup = NULL; actor->pickupMenu.effect = NULL; actor->pickupMenu.index = 0; + // Reset input KeyLockKeys(&gEventHandlers.keyboard); JoyLock(&gEventHandlers.joysticks); + actor->lastCmd = 0; + return 0; } else if (Up(cmd) && !Up(actor->lastCmd)) { @@ -1110,7 +1113,6 @@ void CommandActor(TActor *actor, int cmd, int ticks) } else { - actor->hasShot = false; // If this is a pilot, command the vehicle instead if (actor->vehicleUID != -1) @@ -1178,6 +1180,7 @@ void CommandActor(TActor *actor, int cmd, int ticks) } actor->lastCmd = cmd; + return cmd; } static bool ActorTryMove(TActor *actor, int cmd, int ticks) { diff --git a/src/cdogs/actors.h b/src/cdogs/actors.h index 15506f0cb..ed15b8468 100644 --- a/src/cdogs/actors.h +++ b/src/cdogs/actors.h @@ -127,10 +127,10 @@ typedef struct Actor // -1 if human character (get from player data), otherwise index into // CharacterStore OtherChars int charId; - int PlayerUID; // -1 unless a human player - int uid; // unique ID across all actors - int pilotUID; // the actor that controls this - // (same as uid for normal actors) + int PlayerUID; // -1 unless a human player + int uid; // unique ID across all actors + int pilotUID; // the actor that controls this + // (same as uid for normal actors) int vehicleUID; // -1 unless piloting a vehicle Weapon guns[MAX_WEAPONS]; CArray ammo; // of int @@ -203,7 +203,7 @@ extern CArray gActors; // of TActor void ActorSetState(TActor *actor, const ActorAnimation state); void UpdateActorState(TActor *actor, int ticks); void ActorMove(const NActorMove am); -void CommandActor(TActor *actor, int cmd, int ticks); +int CommandActor(TActor *actor, int cmd, int ticks); void SlideActor(TActor *actor, int cmd); void UpdateAllActors(const int ticks); void ActorsPilotVehicles(void); diff --git a/src/cdogs/ai.c b/src/cdogs/ai.c index c329d9aac..056d3212e 100644 --- a/src/cdogs/ai.c +++ b/src/cdogs/ai.c @@ -349,8 +349,7 @@ int AICommand(const int ticks) cmd = GetCmd(actor, delayModifier, rollLimit); actor->aiContext->Delay = MAX(0, actor->aiContext->Delay - ticks); } - CommandActor(actor, cmd, ticks); - actor->aiContext->LastCmd = cmd; + actor->aiContext->LastCmd = CommandActor(actor, cmd, ticks); count++; CA_FOREACH_END() return count; @@ -624,8 +623,8 @@ void InitializeBadGuys(void) { for (; o->placed < o->Count; o->placed++) { - const int charId = - CharacterStoreGetRandomSpecialId(&gCampaign.Setting.characters); + const int charId = CharacterStoreGetRandomSpecialId( + &gCampaign.Setting.characters); const Character *c = CArrayGet(&gCampaign.Setting.characters.OtherChars, charId); GameEvent e = GameEventNewActorAdd( diff --git a/src/game.c b/src/game.c index ac1d1ab41..e026205d8 100644 --- a/src/game.c +++ b/src/game.c @@ -22,7 +22,7 @@ This file incorporates work covered by the following copyright and permission notice: - Copyright (c) 2013-2022 Cong Xu + Copyright (c) 2013-2022, 2024 Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -516,7 +516,8 @@ static GameLoopResult RunGameUpdate(GameLoopData *data, LoopRunner *l) rData->cmds[idx] = AICoopGetCmd(player, ticksPerFrame); } PlayerSpecialCommands(player, rData->cmds[idx]); - CommandActor(player, rData->cmds[idx], ticksPerFrame); + rData->cmds[idx] = + CommandActor(player, rData->cmds[idx], ticksPerFrame); } }