X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fmain.c;h=693f204d9f785d6034e765a33c1a5eb173bbee95;hb=120715d0a4a308cdf748e1925be472ed6a59f092;hp=4dd1673bcf897f543a04a07fccb45d4def917699;hpb=d951e2631a19500f1bb8c29f9e029a9d9fb29ae7;p=plomrogue diff --git a/src/main.c b/src/main.c index 4dd1673..693f204 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,8 @@ #include "draw_wins.h" #include "keybindings.h" #include "readwrite.h" -#include "objects_on_map.h" +#include "map_objects.h" +#include "map_object_actions.h" #include "map.h" #include "misc.h" @@ -29,7 +30,7 @@ int main (int argc, char *argv[]) { default: exit(EXIT_FAILURE); } } - // Initialize log, player, monsters and items. + // Initialize log, player, monster/item definitions and monsters/items. world.log = calloc(1, sizeof(char)); update_log (&world, " "); struct Player player; @@ -37,6 +38,7 @@ int main (int argc, char *argv[]) { world.player = &player; world.monster = 0; world.item = 0; + init_map_object_defs(&world, "defs"); // For interactive mode, try to load world state from savefile. FILE * file; @@ -48,7 +50,7 @@ int main (int argc, char *argv[]) { player.pos.x = read_uint16_bigendian(file) - 1; player.hitpoints = fgetc(file); read_map_objects (&world.monster, file, sizeof(struct Monster), read_map_objects_monsterdata); - read_map_objects (&world.item, file, sizeof(struct Item), readwrite_map_objects_dummy); + read_map_objects (&world.item, file, sizeof(struct Item), NULL); fclose(file); } // For non-interactive mode, try to load world state from record file. @@ -71,10 +73,15 @@ int main (int argc, char *argv[]) { world.map = ↦ if (1 == world.turn) { player.pos = find_passable_pos(&map); - unsigned char n_monsters = rrand(0, 0) % 16; - unsigned char n_items = rrand(0, 0) % 48; - build_map_objects (&world.monster, n_monsters, sizeof(struct Monster), build_map_objects_monsterdata, &map); - build_map_objects (&world.item, n_items, sizeof(struct Item), build_map_objects_itemdata, &map); } + void * foo = build_map_objects (&world, &world.monster, 0, 1 + rrand(0,0) % 27, sizeof(struct Monster), + build_map_objects_monsterdata); + foo = build_map_objects (&world, foo, 1, 1 + rrand(0,0) % 9, sizeof(struct Monster), + build_map_objects_monsterdata); + build_map_objects (&world, foo, 2, 1 + rrand(0,0) % 3, sizeof(struct Monster), + build_map_objects_monsterdata); + foo = build_map_objects (&world, &world.item, 3, 1 + rrand(0,0) % 3, sizeof(struct Item), + build_map_objects_itemdata); + build_map_objects (&world, foo, 4, 1 + rrand(0,0) % 3, sizeof(struct Item), build_map_objects_itemdata); } // Initialize window system and windows. WINDOW * screen = initscr(); @@ -128,7 +135,7 @@ int main (int argc, char *argv[]) { else quit_called = meta_keys(key, &world, &win_meta, &win_keys, &win_map, &win_info, &win_log); if (1 == quit_called) - break; } } + exit_game(&world, &map); } } // Interactive mode. else { @@ -154,14 +161,4 @@ int main (int argc, char *argv[]) { else quit_called = meta_keys(key, &world, &win_meta, &win_keys, &win_map, &win_info, &win_log); if (1 == quit_called) - break; } } - - // Clean up and exit. - free(map.cells); - for (key = 0; key <= world.keyswindata->max; key++) - free(world.keybindings[key].name); - free(world.keybindings); - free(world.keyswindata); - free(world.log); - endwin(); - return 0; } + exit_game(&world, &map); } } }