movement: generalize; use vectors #16
1 changed files with 1 additions and 1 deletions
fix: move action setter outside null guard
commit
7905ace2ca
|
|
@ -448,8 +448,8 @@ static int handle_movement_input(GameState *gs) {
|
|||
if (result == MOVE_RESULT_MOVED) {
|
||||
if (target != NULL) {
|
||||
player_on_move(&gs->player);
|
||||
action = 1;
|
||||
}
|
||||
|
SquirrelModeler marked this conversation as resolved
Outdated
|
||||
action = 1;
|
||||
} else if (result == MOVE_RESULT_BLOCKED_ENEMY) {
|
||||
target = player_find_enemy_at(gs->enemies, gs->enemy_count, new_x, new_y);
|
||||
player_attack(&gs->player, target);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue
You should probably guard against potential null target here before attacking.
Because if
try_move_entityreturnsMOVE_RESULT_BLOCKED_ENEMYbutplayer_find_enemy_atfails to find the enemy (be it due to differing lookup logic, or if the enemy was killed by effects earlier in the turn), target would beNULL, and thus lead to an ub inplayer_attack. Something like:If we move the action = 1 into the null guarded if statement, then enemy AI breaks. We can do:Which fixes that bug.Ignore this. I added an incorrect guard.