X-Git-Url: https://plomlompom.com/repos/index.html?a=blobdiff_plain;f=src%2Fmain.c;h=ce01ee52be2797723c8c2fd9a5a2d7620f4e3ed0;hb=0f12557b88c73f8629ffafc38dc59ab5bd15e687;hp=4dd1673bcf897f543a04a07fccb45d4def917699;hpb=d951e2631a19500f1bb8c29f9e029a9d9fb29ae7;p=plomrogue diff --git a/src/main.c b/src/main.c index 4dd1673..ce01ee5 100644 --- a/src/main.c +++ b/src/main.c @@ -3,11 +3,14 @@ #include #include #include +#include +#include #include "windows.h" #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 +32,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,9 +40,46 @@ 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); // 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); @@ -71,10 +111,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();