From d304b75ee742d50b6cfa9ad81c44d37fb84a4b5a Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 3 Aug 2014 23:29:12 +0200 Subject: [PATCH] Server: Ensure that AI does not move towards enemies outside its FOV. --- src/server/ai.c | 4 +++- src/server/field_of_view.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/server/ai.c b/src/server/ai.c index c613928..91a6c86 100644 --- a/src/server/ai.c +++ b/src/server/ai.c @@ -5,6 +5,7 @@ #include /* uint8_t, uint16_t, uint32_t, UINT16_MAX */ #include /* free() */ #include "../common/try_malloc.h" /* try_malloc() */ +#include "field_of_view.h" /* HIDDEN */ #include "hardcoded_strings.h" /* s */ #include "thing_actions.h" /* get_thing_action_id_by_name() */ #include "things.h" /* struct Thing */ @@ -138,7 +139,8 @@ static char get_dir_to_nearest_enemy(struct Thing * t_origin) struct Thing * t = world.things; for (; t != NULL; t = t->next) { - if (!t->lifepoints || t == t_origin) + if ( !t->lifepoints || t == t_origin + || HIDDEN == t_origin->fov_map[t->pos.y*world.map.length+t->pos.x]) { continue; } diff --git a/src/server/field_of_view.h b/src/server/field_of_view.h index 9060f1d..aa8fe7c 100644 --- a/src/server/field_of_view.h +++ b/src/server/field_of_view.h @@ -15,7 +15,7 @@ struct Thing; /* States that cells in the field of view map may be in. */ enum fov_cell_states { - HIDDEN = 0x00, + HIDDEN = 0x00, VISIBLE = 0x01 }; -- 2.30.2