-#include <stdint.h> /* uint8_t, uint32_t, UINT8_MAX */
-#include <string.h> /* strlen(), memset() */
-#include "../common/yx_uint16.h" /* struct yx_uint16 */
-#include "map_object_actions.h" /* get_moa_id_by_name() */
-#include "map_objects.h" /* struct MapObj */
-#include "world.h" /* global world */
-
-
-
-/* Write into "neighbor_scores" scores for immediate neighbors to cell at
- * "pos_yx" (YX coordinates) and "pos_i" (arry_index) in "score_map". Directions
- * determining neighborhood are defined by the letters of "dir"; their order
- * also determines in what order scores are written into "neighbor_score".
- * "len_dirs" is to store the result of a previous strlen(dir) (so it does not
- * have to be called repeatedly and costly in dijkstra_map(); same reason for
- * "pos_i"'s redundancy.). "max_score" is written into "neighbor_scores" for
- * illegal directions (that from "pos_yx" would lead beyond the map's border).
+#include <stdint.h> /* uint8_t, uint16_t, uint32_t, int16_t, UINT16_MAX */
+#include <stdlib.h> /* free() */
+#include "../common/try_malloc.h" /* try_malloc() */
+#include "hardcoded_strings.h" /* s */
+#include "thing_actions.h" /* get_thing_action_id_by_name() */
+#include "things.h" /* Thing, ThingType, ThingInMemory */
+#include "world.h" /* world */
+
+
+
+#define N_DIRS 6
+
+
+
+/* Write into "neighbors" scores of the N_DIRS immediate neighbors of the
+ * "score_map" cell at "pos_i" (array index), as found in the directions
+ * north-east, east, south-east etc. (clockwise order). Use "max_score" for
+ * illegal neighborhoods (i.e. if direction would lead beyond the map's border).
+ */
+static void get_neighbor_scores(uint16_t * score_map, uint16_t pos_i,
+ uint16_t max_score, uint16_t * neighbors);
+
+/* Iterate over scored cells in "score_map" of world.map's geometry. Compare
+ * each cell's score against the score of its immediate neighbors in N_DIRS
+ * directions. If any neighbor's score is at least two points lower than the
+ * current cell's score, re-set it to 1 point higher than its lowest-scored
+ * neighbor. Repeat this whole process until all cells have settled on their
+ * final score. Ignore cells whose score is greater than "max_score". Expect
+ * "max_score" to be the maximum score for cells, marking them as unreachable.
+ */
+static void dijkstra_map(uint16_t * score_map, uint16_t max_score);
+
+/* get_dir_to_nearest_thing() helper: Prepare "score_map" for dijkstra_map(). */
+static void init_score_map(char filter, uint16_t * score_map, uint32_t map_size,
+ struct Thing * t_eye);
+
+/* Set (if possible) as "t_eye"'s command a move to the path to the path-wise
+ * nearest thing that is not "t_eye" and fits criteria set by "filter". On
+ * success, return 1, else 0. Values for "filter":
+ * "e": thing in FOV is animate, but not of "t_eye"'s thing type; build path as
+ * avoiding things of "t_eye"'s type
+ * "c": thing in memorized map is consumable.
+ */
+static uint8_t get_dir_to_nearest_thing(struct Thing * t_eye, char filter);
+
+/* Return 1 if any thing not "t_eye" is known and fulfills some criteria defined
+ * by "filter", else 0. Values for "filter":
+ * "e": thing in FOV is animate, but not of "t_eye"'s thing type
+ * "c": thing in memorized map is consumable