X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fmain.c;h=693f204d9f785d6034e765a33c1a5eb173bbee95;hb=27cee0624f3dc430199c99f000179a3385e4d7c5;hp=ce01ee52be2797723c8c2fd9a5a2d7620f4e3ed0;hpb=0f12557b88c73f8629ffafc38dc59ab5bd15e687;p=plomrogue diff --git a/src/main.c b/src/main.c index ce01ee5..693f204 100644 --- a/src/main.c +++ b/src/main.c @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include "windows.h" #include "draw_wins.h" #include "keybindings.h" @@ -40,46 +38,10 @@ int main (int argc, char *argv[]) { world.player = &player; world.monster = 0; world.item = 0; - world.item_def = 0; - world.monster_def = 0; - FILE * file = fopen("defs", "r"); - uint16_t linemax; - textfile_sizes (file, &linemax, NULL); - char m_or_i; - struct MapObjDef mod; - struct ItemDef id; - struct MonsterDef md; - struct ItemDef * * p_p_id = &world.item_def; - struct MonsterDef * * p_p_md = &world.monster_def; - char * defline = malloc(linemax); - char * line_p; - while (fgets (defline, linemax, file)) { - mod.next = 0; - mod.id = atoi(defline); - line_p = strchr(defline, ' ') + 1; - m_or_i = * line_p; - mod.mapchar = * (line_p + 2); - if ('i' == m_or_i) - line_p = line_p + 5; - else { - md.hitpoints_start = atoi (line_p + 4); - line_p = strchr (line_p + 4, ' ') + 1; } - mod.desc = calloc (strlen (line_p), sizeof(char)); - memcpy (mod.desc, line_p, strlen(line_p) - 1); - if ('i' == m_or_i) { - id.map_obj_def = mod; - * p_p_id = malloc (sizeof (struct ItemDef)); - * * p_p_id = id; - p_p_id = (struct ItemDef * *) * p_p_id; } - else { - md.map_obj_def = mod; - * p_p_md = malloc (sizeof (struct MonsterDef)); - * * p_p_md = md; - p_p_md = (struct MonsterDef * *) * p_p_md; } } - free(defline); - fclose(file); + init_map_object_defs(&world, "defs"); // For interactive mode, try to load world state from savefile. + FILE * file; if (1 == world.interactive && 0 == access("savefile", F_OK)) { file = fopen("savefile", "r"); world.seed = read_uint32_bigendian(file); @@ -88,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. @@ -173,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 { @@ -199,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); } } }