+ if (seeing_thing(t_eye, filter))
+ {
+ 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(filter, score_map, map_size, t_eye);
+ dijkstra_map(score_map, UINT16_MAX-1);
+ uint16_t neighbors[N_DIRS];
+ uint16_t pos_i = (t_eye->pos.y * world.map.length) + t_eye->pos.x;
+ get_neighbor_scores(score_map, pos_i, UINT16_MAX-1, neighbors);
+ free(score_map);
+ uint16_t min_neighbor = UINT16_MAX-1;
+ char * dirs = "edcxsw";/* get_neighbor_scores()'s clockwise dir order.*/
+ uint8_t i;
+ for (i = 0; i < N_DIRS; i++)
+ {
+ if (min_neighbor > neighbors[i])
+ {
+ min_neighbor = neighbors[i];
+ dir_to_nearest_enemy = dirs[i];
+ }
+ }
+ }
+ if (dir_to_nearest_enemy)
+ {
+ t_eye->command = get_thing_action_id_by_name(s[S_CMD_MOVE]);
+ t_eye->arg = dir_to_nearest_enemy;
+ return 1;
+ }
+ return 0;
+}
+
+
+
+static uint8_t seeing_thing(struct Thing * t_eye, char filter)
+{
+ if (t_eye->fov_map)
+ {
+ struct Thing * t = world.things;
+ for (; t != NULL; t = t->next)
+ {
+ if ( t != t_eye
+ && 'v' == t_eye->fov_map[t->pos.y*world.map.length + t->pos.x])
+ {
+ if ('e' == filter && t->lifepoints && t->type != t_eye->type)
+ {
+ return 1;
+ }
+ else if ('c' == filter)
+ {
+ struct ThingType * tt = get_thing_type(t->type);
+ if (tt->consumable)
+ {
+ return 1;
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+
+
+static int16_t get_inventory_slot_to_consume(struct Thing * t_owner)
+{
+ uint8_t compare_consumability = 0;
+ int16_t selection = -1;
+ struct Thing * t = t_owner->owns;;
+ uint8_t i;
+ for (i = 0; t != NULL; t = t->next, i++)