X-Git-Url: https://plomlompom.com/repos/?p=plomrogue;a=blobdiff_plain;f=libplomrogue.c;h=37cc8ef0085d6f4f341c7f9a05a2a27fba10a742;hp=4002dedefea35a17ffecb8f584b47493c9bd8984;hb=c94c0575b191d0162d8a1cbbbe4e59cca2e40324;hpb=879f49462f91269c1b058eeb10da5a2878c4a01f diff --git a/libplomrogue.c b/libplomrogue.c index 4002ded..37cc8ef 100644 --- a/libplomrogue.c +++ b/libplomrogue.c @@ -1,3 +1,4 @@ +#include /* pow() */ #include /* NULL */ #include /* ?(u)int(8|16|32)_t, ?(U)INT8_(MIN|MAX) */ #include /* free, malloc */ @@ -518,7 +519,8 @@ extern uint16_t get_neighbor_score(uint8_t i) * 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 UINT16_MAX - 1 (treat those as unreachable). + * whose score is greater than UINT16_MAX - 1 (treat those as unreachable). Also + * ignore cells whose score is smaller or equal the number of past iterations. * Return 1 on error, else 0. */ extern uint8_t dijkstra_map() @@ -538,7 +540,8 @@ extern uint8_t dijkstra_map() scores_still_changing = 0; for (pos = 0; pos < map_size; pos++) { - if (score_map[pos] <= max_score) + uint16_t score = score_map[pos]; + if (score <= max_score && score > i_scans) { get_neighbor_scores(pos, max_score, neighbors); min_neighbor = max_score; @@ -559,3 +562,76 @@ extern uint8_t dijkstra_map() } return 0; } + +extern uint8_t zero_score_map_where_char_on_memdepthmap(char c, + char * memdepthmap) +{ + if (!score_map) + { + return 1; + } + uint32_t map_size = maplength * maplength; + uint16_t pos; + for (pos = 0; pos < map_size; pos++) + { + if (c == memdepthmap[pos]) + { + score_map[pos] = 0; + } + } + return 0; +} + +extern void age_some_memdepthmap_on_nonfov_cells(char * memdepthmap, + char * fovmap) +{ + uint32_t map_size = maplength * maplength; + uint16_t pos; + for (pos = 0; pos < map_size; pos++) + { + if ('v' != fovmap[pos]) + { + char c = memdepthmap[pos]; + if( '0' <= c && '9' > c && !(rrand() % (uint16_t) pow(2, c - 48))) + { + memdepthmap[pos]++; + } + } + } +} + +extern uint8_t set_cells_passable_on_memmap_to_65534_on_scoremap(char * mem_map, + const char * symbols_passable) +{ + if (!score_map) + { + return 1; + } + uint32_t map_size = maplength * maplength; + uint16_t pos; + for (pos = 0; pos < map_size; pos++) + { + if (NULL != strchr(symbols_passable, mem_map[pos])) + { + score_map[pos] = 65534; + } + } + return 0; +} + + +extern void update_mem_and_memdepthmap_via_fovmap(char * map, char * fovmap, + char * memdepthmap, + char * memmap) +{ + uint32_t map_size = maplength * maplength; + uint16_t pos; + for (pos = 0; pos < map_size; pos++) + { + if ('v' == fovmap[pos]) + { + memdepthmap[pos] = '0'; + memmap[pos] = map[pos]; + } + } +}