X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fmisc.c;h=8d38d59c383297ef3be00af1f3f67ce562d5e01c;hb=0f12557b88c73f8629ffafc38dc59ab5bd15e687;hp=6832b1aec81bd30e31ca96b66088fd3577a2767b;hpb=8661a8acfacc7cdd2935732fe5ead7d279a200b0;p=plomrogue diff --git a/src/misc.c b/src/misc.c index 6832b1a..8d38d59 100644 --- a/src/misc.c +++ b/src/misc.c @@ -5,8 +5,30 @@ #include "keybindings.h" #include "readwrite.h" #include "map_objects.h" +#include "map_object_actions.h" #include "map.h" #include "main.h" +#include "yx_uint16.h" + +extern void textfile_sizes (FILE * file, uint16_t * linemax_p, uint16_t * n_lines_p) { +// Learn largest line length (linemax_p) and (n_lines_p if not set to NULL) number of lines. + uint16_t n_lines = 0; + int c = 0; + uint16_t linemax = 0; + uint16_t c_count = 0; + while (EOF != c) { + c_count++; + c = getc(file); + if ('\n' == c) { + if (c_count > linemax) + linemax = c_count + 1; + c_count = 0; + if (n_lines_p) + n_lines++; } } + fseek(file, 0, SEEK_SET); + * linemax_p = linemax; + if (n_lines_p) + * n_lines_p = n_lines; } extern uint16_t rrand(char use_seed, uint32_t new_seed) { // Pseudo-random number generator (LGC algorithm). Use instead of rand() to ensure portable predictability. @@ -59,7 +81,7 @@ extern void turn_over (struct World * world, char action) { world->turn++; rrand(1, world->seed * world->turn); struct Monster * monster; - for (monster = world->monster; monster != 0; monster = monster->cmo.next) + for (monster = world->monster; monster != 0; monster = monster->map_obj.next) move_monster(world, monster); } extern void save_game(struct World * world) { @@ -98,6 +120,14 @@ extern void growshrink_active_window (struct WinMeta * win_meta, char change) { else if (change == '*') size.x++; resize_active_win (win_meta, size); } } +extern struct yx_uint16 find_passable_pos (struct Map * map) { +// Return a random passable position on map. + struct yx_uint16 pos; + for (pos.y = pos.x = 0; 0 == is_passable(map, pos);) { + pos.y = rrand(0, 0) % map->size.y; + pos.x = rrand(0, 0) % map->size.x; } + return pos; } + extern unsigned char meta_keys(int key, struct World * world, struct WinMeta * win_meta, struct Win * win_keys, struct Win * win_map, struct Win * win_info, struct Win * win_log) {