X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/form?a=blobdiff_plain;f=src%2Froguelike.c;h=ac735ace1771aa7d4c20c00ed45aa6459c620487;hb=22f0a5223adddd1d6e1ea8f6f521279906b35ecd;hp=f20bfe18e1b123ce7cb5d4ef592b59e30923a96c;hpb=5dfbb430e0aed478ced7cdc32c1777745a435532;p=plomrogue diff --git a/src/roguelike.c b/src/roguelike.c index f20bfe1..ac735ac 100644 --- a/src/roguelike.c +++ b/src/roguelike.c @@ -9,7 +9,7 @@ #include "draw_wins.h" #include "keybindings.h" #include "readwrite.h" -#include "actors.h" +#include "objects_on_map.h" uint16_t rrand(char use_seed, uint32_t new_seed) { // Pseudo-random number generator (LGC algorithm). Use instead of rand() to ensure portable predictability. @@ -276,9 +276,7 @@ int main (int argc, char *argv[]) { struct Map map = init_map(); world.map = ↦ if (1 == world.turn) { - for (player.pos.y = player.pos.x = 0; 0 == is_passable(&map, player.pos);) { - player.pos.y = rrand(0, 0) % map.size.y; - player.pos.x = rrand(0, 0) % map.size.x; } + player.pos = find_passable_pos(&map); unsigned char n_monsters = rrand(0, 0) % 16; unsigned char n_items = rrand(0, 0) % 48; unsigned char i; @@ -292,9 +290,7 @@ int main (int argc, char *argv[]) { else { monster->next = malloc(sizeof(struct Monster)); monster = monster->next; } - for (monster->pos.y = monster->pos.x = 0; 0 == is_passable(&map, monster->pos);) { - monster->pos.y = rrand(0, 0) % map.size.y; - monster->pos.x = rrand(0, 0) % map.size.x; } + monster->pos = find_passable_pos(&map); monster->name = 'M'; } if (!start) monster->next = 0; @@ -308,9 +304,7 @@ int main (int argc, char *argv[]) { else { item->next = malloc(sizeof(struct Item)); item = item->next; } - for (item->pos.y = item->pos.x = 0; 0 == is_passable(&map, item->pos);) { - item->pos.y = rrand(0, 0) % map.size.y; - item->pos.x = rrand(0, 0) % map.size.x; } + item->pos = find_passable_pos(&map); item->name = '#'; } if (!start) item->next = 0; }