* build_map_objects()
*/
#include "map.h" /* for struct Map, init_map() */
-#include "misc.h" /* for update_log(), toggle_window(), find_passable_pos(),
- * save_game()
- */
+#include "misc.h" /* for update_log(), find_passable_pos(), save_game() */
+#include "wincontrol.h" /* for toggle_window() */
#include "rrand.h" /* for rrand(), rrand_seed() */
#include "rexit.h" /* for exit_game() */
#include "control.h" /* for meta_control() */
int main(int argc, char *argv[])
{
struct World world;
+ world.turn = 0; /* Turns to 1 when map and objects are initalized. */
init_command_db(&world);
set_cleanup_flag(CLEANUP_COMMAND_DB);
world.score = 0;
world.log = calloc(1, sizeof(char));
set_cleanup_flag(CLEANUP_LOG);
- update_log (&world, " ");
+ update_log(&world, " ");
struct Player player;
player.hitpoints = 5;
world.player = &player;
world.monster = 0;
world.item = 0;
init_map_object_defs(&world, "config/defs");
+ set_cleanup_flag(CLEANUP_MAP_OBJECT_DEFS);
/* For interactive mode, try to load world state from savefile. */
char * err_o = "Trouble loading game (fopen() in main()) / "
{
exit_err(1, &world, err_r);
}
+ set_cleanup_flag(CLEANUP_MAP_OBJECTS);
exit_err(fclose(file), &world, err_c);
player.pos.y--;
player.pos.x--;
+ world.turn = 1;
}
/* For non-interactive mode, try to load world state from record file. */
"opening file 'record' for reading.";
err_r = "Trouble loading record file (read_uint32_bigendian() in "
"main()) / reading from opened file 'record'.";
- world.turn = 1;
if (0 == world.interactive)
{
file = fopen(recordfile, "r");
}
}
-
/* Generate map from seed and, if newly generated world, start positions of
* actors.
*/
struct Map map = init_map();
world.map = ↦
set_cleanup_flag(CLEANUP_MAP);
- if (1 == world.turn)
+ if (0 == world.turn)
{
player.pos = find_passable_pos(world.map);
void * foo;
build_map_objects(&world, foo, 3, 1 + rrand() % 3);
foo = build_map_objects(&world, &world.item, 4, 1 + rrand() % 3);
build_map_objects(&world, foo, 5, 1 + rrand() % 3);
+ set_cleanup_flag(CLEANUP_MAP_OBJECTS);
+ world.turn = 1;
}
/* Initialize window system and windows. */
init_keybindings(&world);
set_cleanup_flag(CLEANUP_KEYBINDINGS);
struct WinMeta win_meta;
- char * err_winmem = "Trouble with init_win:meta() or draw_all_wins() in "
+ char * err_winmem = "Trouble with init_win_meta() or draw_all_wins() in "
"main().";
exit_err(init_win_meta(screen, &win_meta), &world, err_winmem);
world.wins.meta = &win_meta;
- struct Win win_keys = init_win(&win_meta, "Keys",
- 0, 29, &world, draw_keys_win);
- world.wins.keys = &win_keys;
- struct Win win_info = init_win(&win_meta, "Info",
- 3, 20, &world, draw_info_win);
- world.wins.info = &win_info;
- uint16_t height_logwin = win_meta.padframe.size.y
- - (2 + win_info.frame.size.y);
- struct Win win_log = init_win(&win_meta, "Log",
- height_logwin, 20, &world, draw_log_win);
- world.wins.log = &win_log;
- uint16_t width_mapwin = win_meta.padframe.size.x - win_keys.frame.size.x
- - win_log.frame.size.x - 2;
- struct Win win_map = init_win(&win_meta, "Map",
- 0, width_mapwin, &world, draw_map_win);
- world.wins.map = &win_map;
- toggle_window(&win_meta, world.wins.keys);
- toggle_window(&win_meta, world.wins.map);
- toggle_window(&win_meta, world.wins.info);
- toggle_window(&win_meta, world.wins.log);
+ world.wins.keys = init_win_from_file(&world, "Keys", draw_keys_win);
+ set_cleanup_flag(CLEANUP_WIN_KEYS);
+ world.wins.info = init_win_from_file(&world, "Info", draw_info_win);
+ set_cleanup_flag(CLEANUP_WIN_INFO);
+ world.wins.log = init_win_from_file(&world, "Log", draw_log_win);
+ set_cleanup_flag(CLEANUP_WIN_LOG);
+ world.wins.map = init_win_from_file(&world, "Map", draw_map_win);
+ set_cleanup_flag(CLEANUP_WIN_MAP);
+
+ sorted_wintoggle(&world);
/* Replay mode. */
int key;