From: Christian Heller Date: Sun, 1 Feb 2015 03:47:47 +0000 (+0100) Subject: Server: Minor refactoring of get_dir_to_nearest_target(). X-Git-Tag: tce~548 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7Byoutube_prefix%7D%7D%7B%7Bvideo_id%7D%7D?a=commitdiff_plain;h=ddb4196d9b87b71af5988657bcda9407557d3acd;p=plomrogue Server: Minor refactoring of get_dir_to_nearest_target(). --- diff --git a/src/server/ai.c b/src/server/ai.c index ae56cdb..83ae798 100644 --- a/src/server/ai.c +++ b/src/server/ai.c @@ -205,11 +205,12 @@ static void init_score_map(char filter, uint16_t * score_map, uint32_t map_size, static uint8_t get_dir_to_nearest_target(struct Thing * t_eye, char filter) { char dir_to_nearest_target = 0; - uint8_t run_i = 9 /* maximum mem depth age below never-explored */ + 1; uint8_t mem_depth_char = ' '; - while (run_i && ('s' == filter || seeing_thing(t_eye, filter))) + uint8_t run_i = 's' == filter ? 9 /* max explored mem depth age */ + 1 : 1; + while ( run_i && !dir_to_nearest_target + && ('s' == filter || seeing_thing(t_eye, filter))) { - run_i = 's' != filter ? 0 : run_i - 1; + run_i--; uint32_t map_size = world.map.length * world.map.length; uint16_t * score_map = try_malloc(map_size * sizeof(uint16_t),__func__); init_score_map('s' == filter ? mem_depth_char : filter, @@ -235,7 +236,6 @@ static uint8_t get_dir_to_nearest_target(struct Thing * t_eye, char filter) { t_eye->command = get_thing_action_id_by_name(s[S_CMD_MOVE]); t_eye->arg = dir_to_nearest_target; - run_i = 0; } } return dir_to_nearest_target;