movement: generalize; use vectors #16
1 changed files with 5 additions and 5 deletions
fix: move guard check
I am stupid. I added the guard on the wrong check. Ffs...
commit
4044543fe1
10
src/main.c
10
src/main.c
|
|
@ -446,14 +446,14 @@ static int handle_movement_input(GameState *gs) {
|
|||
MoveResult result =
|
||||
try_move_entity(&gs->player.position, direction, &gs->map, &gs->player, gs->enemies, gs->enemy_count, true);
|
||||
if (result == MOVE_RESULT_MOVED) {
|
||||
if (target != NULL) {
|
||||
player_on_move(&gs->player);
|
||||
}
|
||||
player_on_move(&gs->player);
|
||||
action = 1;
|
||||
} else if (result == MOVE_RESULT_BLOCKED_ENEMY) {
|
||||
|
SquirrelModeler marked this conversation as resolved
Outdated
|
||||
target = player_find_enemy_at(gs->enemies, gs->enemy_count, new_x, new_y);
|
||||
player_attack(&gs->player, target);
|
||||
action = 1;
|
||||
if (target != NULL) {
|
||||
player_attack(&gs->player, target);
|
||||
action = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (action)
|
||||
|
|
|
|||
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.