X-Git-Url: https://plomlompom.com/repos/index.html?a=blobdiff_plain;f=src%2Froguelike.c;h=3604fbd3cc2981380fc9ec9112deefb647b62f1a;hb=5fc067b01c4651afec131a6c9f79c4cdd336e5c8;hp=68a593683be3525ec55a733c20707d4701fe2490;hpb=d966716bf65408119fae415c74fc274ff144f46d;p=plomrogue diff --git a/src/roguelike.c b/src/roguelike.c index 68a5936..3604fbd 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. @@ -70,14 +70,6 @@ struct Map init_map () { map.cells[y * map.size.x + x] = '.'; } return map; } -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; } - void map_scroll (struct Map * map, char dir) { // Scroll map into direction dir if possible by changing the offset. if (NORTH == dir && map->offset.y > 0) map->offset.y--; @@ -107,12 +99,14 @@ void save_game(struct World * world) { struct Monster * monster; for (monster = world->monster; monster != 0; monster = monster->next) { write_uint16_bigendian(monster->pos.y + 1, file); - write_uint16_bigendian(monster->pos.x + 1, file); } + write_uint16_bigendian(monster->pos.x + 1, file); + fputc(monster->name, file); } write_uint16_bigendian(0, file); struct Item * item; for (item = world->item; item != 0; item = item->next) { write_uint16_bigendian(item->pos.y + 1, file); - write_uint16_bigendian(item->pos.x + 1, file); } + write_uint16_bigendian(item->pos.x + 1, file); + fputc(item->name, file); } write_uint16_bigendian(0, file); fclose(file); } @@ -240,9 +234,9 @@ int main (int argc, char *argv[]) { else { monster->next = malloc(sizeof(struct Monster)); monster = monster->next; } - monster->name = 'M'; monster->pos.y = test - 1; - monster->pos.x = read_uint16_bigendian(file) - 1; } + monster->pos.x = read_uint16_bigendian(file) - 1; + monster->name = fgetc(file); } if (!start) monster->next = 0; start = 1; @@ -258,9 +252,9 @@ int main (int argc, char *argv[]) { else { item->next = malloc(sizeof(struct Item)); item = item->next; } - item->name = '#'; item->pos.y = test - 1; - item->pos.x = read_uint16_bigendian(file) - 1; } + item->pos.x = read_uint16_bigendian(file) - 1; + item->name = fgetc(file); } if (!start) item->next = 0; fclose(file); } @@ -299,7 +293,7 @@ int main (int argc, char *argv[]) { monster->next = malloc(sizeof(struct Monster)); monster = monster->next; } monster->pos = find_passable_pos(&map); - monster->name = 'M'; } + monster->name = 'A' + (rrand(0, 0) % 8); } if (!start) monster->next = 0; start = 1; @@ -313,7 +307,7 @@ int main (int argc, char *argv[]) { item->next = malloc(sizeof(struct Item)); item = item->next; } item->pos = find_passable_pos(&map); - item->name = '#'; } + item->name = '#' + (rrand(0, 0) % 4); } if (!start) item->next = 0; }