Skip to content

Commit

Permalink
Fix repeated input after pickup menu #712
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Oct 8, 2024
1 parent f0c8932 commit b224a62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/cdogs/actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
10 changes: 5 additions & 5 deletions src/cdogs/actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/cdogs/ai.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b224a62

Please sign in to comment.