X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fmisc.c;h=6aeb8b45303a229b120593848a5a8ebd5c9c3241;hb=c7cdbe6260e5cd6a8efe2c73a02c9635b67ec4b7;hp=a8918a9ccdfdc76a1899226298823b4fbacbfd43;hpb=7b6558a08527dc27995af156e43734be3da950a0;p=plomrogue diff --git a/src/misc.c b/src/misc.c index a8918a9..6aeb8b4 100644 --- a/src/misc.c +++ b/src/misc.c @@ -4,19 +4,21 @@ #include /* for exit(), EXIT_SUCCESS define, calloc(), free() */ #include /* for strlen(), strcmp(), memcpy() */ #include /* for endwin() */ -#include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(), */ - /* resize_active_win(), cycle_active_win(), */ - /* shift_active_win(), struct Win, struct WinMeta */ -#include "keybindings.h" /* for get_action_key(), save_keybindings(), */ - /* keyswin_move_selection(), keyswin_mod_key() */ -#include "readwrite.h" /* for write_uint16_bigendian() */ - /* write_uint32_bigendian() */ +#include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(), + * resize_active_win(), cycle_active_win(), + * shift_active_win(), struct Win, struct WinMeta + */ +#include "keybindings.h" /* for get_action_key(), save_keybindings(), + * keyswin_move_selection(), keyswin_mod_key() + */ +#include "readwrite.h" /* for write_uint16_bigendian(), write_uint32_bigendian() + */ #include "map_objects.h" /* for struct Monster, write_map_objects(), */ - /* write_map_objects_monsterdata() */ #include "map_object_actions.h" /* for is_passable(), move_monster() */ -#include "map.h" /* for map_scroll()/map_center_player(), Map struct, dir enum */ +#include "map.h" /* for map_scroll(),map_center_player(), Map struct,dir enum */ #include "main.h" /* for World struct */ #include "yx_uint16.h" /* for yx_uint16 */ +#include "rrand.h" /* for rrand(), rrand_seed() */ @@ -71,22 +73,6 @@ extern void textfile_sizes(FILE * file, uint16_t * linemax_p, -extern uint16_t rrand(char use_seed, uint32_t new_seed) -{ - static uint32_t seed; - if (0 != use_seed) - { - seed = new_seed; - } - - /* Constants as recommended by POSIX.1-2001 (see man page rand(3)). */ - seed = ((seed * 1103515245) + 12345) % 2147483648; - - return (seed / 65536); /* TODO: Use bit-shifting for ignoring the less */ -} /* random least significant 16 bits. */ - - - extern void update_log(struct World * world, char * text) { static char * last_msg; @@ -151,7 +137,7 @@ extern void turn_over(struct World * world, char action) fclose(file); } world->turn++; - rrand(1, world->seed * world->turn); + rrand_seed(world->seed * world->turn); struct Monster * monster; for (monster = world->monster; monster != 0; @@ -171,8 +157,8 @@ extern void save_game(struct World * world) write_uint16_bigendian(world->player->pos.y + 1, file); write_uint16_bigendian(world->player->pos.x + 1, file); fputc(world->player->hitpoints, file); - write_map_objects (world->monster, file, write_map_objects_monsterdata); - write_map_objects (world->item, file, NULL); + write_map_objects(world, world->monster, file); + write_map_objects(world, world->item, file); fclose(file); } @@ -238,8 +224,8 @@ extern struct yx_uint16 find_passable_pos(struct Map * 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; + pos.y = rrand() % map->size.y; + pos.x = rrand() % map->size.x; } return pos; }