4 #include <stdlib.h> /* for exit(), free(), defines EXIT_SUCESS, EXIT_FAILURE */
5 #include <stdio.h> /* for printf(), perror() */
6 #include <stdint.h> /* for uint8_t */
7 #include <ncurses.h> /* for endwin() */
8 #include <errno.h> /* for errno */
9 #include "main.h" /* for World struct */
10 #include "map.h" /* for Map struct */
11 #include "keybindings.h" /* for KeysWinData, KeyBinding structs */
12 #include "command_db.h" /* for free_command_db() */
13 #include "windows.h" /* for Win struct, free_win(), free_winmeta() */
14 #include "map_objects.h" /* for free_item_defs(), free_monster_defs() */
15 #include "wincontrol.h" /* for get_win_by_id(), free_winconfs(), free_wins() */
18 /* The clean-up routine and the flag resource by which it decides what to do. */
19 static uint32_t cleanup_flags = 0x0000;
20 static void cleanup(struct World * world);
24 static void cleanup(struct World * world)
26 if (cleanup_flags & CLEANUP_NCURSES)
30 if (cleanup_flags & CLEANUP_MAP)
32 free(world->map->cells);
34 if (cleanup_flags & CLEANUP_KEYBINDINGS)
38 struct KeyBinding * kb_p = world->keybindings;
42 free(world->keybindings[key].name);
44 free(world->keybindings);
46 free_keybindings(world->keybindings);
47 free(world->keyswindata);
49 if (cleanup_flags & CLEANUP_LOG)
53 if (cleanup_flags & CLEANUP_COMMAND_DB)
55 free_command_db(world);
57 if (cleanup_flags & CLEANUP_MAP_OBJECTS)
59 free_items(world->item);
60 free_monsters(world->monster);
62 if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS)
64 free_item_defs(world->item_def);
65 free_monster_defs(world->monster_def);
67 if (cleanup_flags & CLEANUP_WINS)
71 if (cleanup_flags & CLEANUP_WINCONFS)
75 if (cleanup_flags & CLEANUP_WIN_META)
77 free_winmeta(world->wmeta);
83 extern void set_cleanup_flag(enum cleanup_flag flag)
85 cleanup_flags = cleanup_flags | flag;
90 extern void exit_game(struct World * world)
98 extern void exit_err(uint8_t err, struct World * world, char * msg)
107 msg = "Details unknown.";
109 printf("Aborted PlomRogue due to error. %s\nInternal error code: %d\n",
113 perror("errno states");