From: Martin Read Date: Fri, 21 Feb 2014 02:04:24 +0000 (+0000) Subject: Another ball-of-mud, implementing return-to-main-menu when you quit or save. X-Git-Tag: 0.9.1~1 X-Git-Url: http://git.blackswordsonics.com/?a=commitdiff_plain;h=7447b5c37ef672842839c2a31e5bea9231c11b41;p=victrix-abyssi Another ball-of-mud, implementing return-to-main-menu when you quit or save. Yeah, again with the "no file-by-file account of this one". There's some gardening work mixed in. --- diff --git a/display-nc.cc b/display-nc.cc index 202d48e..ffd1b1e 100644 --- a/display-nc.cc +++ b/display-nc.cc @@ -142,6 +142,7 @@ static void run_main_menu(void); /* Static funcs */ static void draw_main_menu(void) { + wclear(fullscreen_window); mvwprintw(fullscreen_window, 1, 23, "----====< Victrix Abyssi >====----\n"); mvwprintw(fullscreen_window, 3, 25, "A roguelike game by Martin Read\n"); mvwprintw(fullscreen_window, 10, 25, "S)tart new game\n"); @@ -535,16 +536,19 @@ int launch_user_interface(void) wmove(message_window, 0, 0); map_updated = FALSE; status_updated = FALSE; - draw_main_menu(); - run_main_menu(); - if (!game_finished) + do { - status_updated = 1; - map_updated = 1; - hard_redraw = 1; - display_update(); - // WIP launch the game logic. - } + draw_main_menu(); + run_main_menu(); + if (!game_finished) + { + status_updated = 1; + map_updated = 1; + hard_redraw = 1; + display_update(); + main_loop(); + } + } while (1); return 0; } @@ -1463,6 +1467,8 @@ static void run_main_menu(void) noecho(); new_game(name); done = true; + wclear(message_window); + wmove(message_window, 0, 0); show_game_view(); break; case 'c': @@ -1474,6 +1480,8 @@ static void run_main_menu(void) // TODO implement loading properly. { int i; + wclear(message_window); + wmove(message_window, 0, 0); i = load_game(); if (i != -1) { @@ -1482,14 +1490,15 @@ static void run_main_menu(void) else { mvwprintw(fullscreen_window, 14, 30, "No saved game found.\n"); + update_panels(); + doupdate(); } } break; case 'q': case 'Q': - done = true; - game_finished = true; - break; + endwin(); + exit(0); } } while (!done); if (!game_finished) diff --git a/log.cc b/log.cc index 8d10a83..9cde6e3 100644 --- a/log.cc +++ b/log.cc @@ -240,6 +240,7 @@ int load_game(void) rebuild_mapobjs(); rebuild_mapmons(); fclose(fp); + game_finished = false; look_around_you(); notify_load_complete(); int i = unlinkat(datadir_fd, "victrix-abyssi.sav", 0); diff --git a/main.cc b/main.cc index c23ad70..ae7b484 100644 --- a/main.cc +++ b/main.cc @@ -43,13 +43,23 @@ #include #include -static void main_loop(void); bool game_finished; int32_t game_tick; bool wizard_mode = WIZARD_MODE; +void game_cleanup(void) +{ + depth = 0; + game_tick = 0; + level_cleanup(); + player_cleanup(); +} + void new_game(char const *name) { + game_finished = false; + depth = 1; + game_tick = 0; u_init(name); make_new_level(); } @@ -115,6 +125,7 @@ void main_loop(void) game_tick++; notify_tick(); } + game_cleanup(); } /*! \brief main() diff --git a/map.cc b/map.cc index 709a6a0..de25b79 100644 --- a/map.cc +++ b/map.cc @@ -33,7 +33,7 @@ #include Level lvl; -int depth = 1; +int depth; void drop_all_chunks(Level *l) { @@ -816,5 +816,20 @@ uint32_t rotate_connection_mask(uint32_t val, int clockwise_steps) return ((val << clockwise_steps) | ((val & 0xf) >> (4 - clockwise_steps))) & 0xf; } +void level_cleanup(void) +{ + int i; + for (i = 0; i < MONSTERS_IN_PLAY; ++i) + { + monsters[i].used = false; + } + for (i = 0; i < OBJECTS_IN_PLAY; ++i) + { + objects[i].used = false; + objects[i].with_you = false; + } + drop_all_chunks(&lvl); +} + /* map.cc */ // vim:cindent:ts=8:sw=4:expandtab diff --git a/map.hh b/map.hh index d71ea2c..22c78cd 100644 --- a/map.hh +++ b/map.hh @@ -289,17 +289,19 @@ extern int depth; extern enum level_theme current_theme; extern enum level_layout current_layout; -extern void leave_level(void); -extern void make_new_level(void); -extern void build_level(void); -extern void populate_level(void); -extern void inject_player(Level_key from); -extern void look_around_you(void); -extern bool terrain_is_opaque(Terrain terr); -extern bool terrain_blocks_beings(Terrain terr); -extern bool terrain_blocks_missiles(Terrain terr); -extern void serialize_level(FILE *fp, Level const *l); -extern void deserialize_level(FILE *fp, Level *l); +void leave_level(void); +void make_new_level(void); +void build_level(void); +void populate_level(void); +void inject_player(Level_key from); +void look_around_you(void); +bool terrain_is_opaque(Terrain terr); +bool terrain_blocks_beings(Terrain terr); +bool terrain_blocks_missiles(Terrain terr); +void serialize_level(FILE *fp, Level const *l); +void deserialize_level(FILE *fp, Level *l); + +void level_cleanup(void); #endif /* map.h */ diff --git a/player.hh b/player.hh index 4d46938..c9740f4 100644 --- a/player.hh +++ b/player.hh @@ -58,6 +58,7 @@ public: int armour; //!< Object handle of currently equipped armour. int ring; //!< Object handle of currently equipped ring. int sympathy[TOTAL_FELL_POWERS]; //!< Level of alignment with fell powers + /* Methods only after here plzkthx */ bool resists(Damtyp dtype) const; //!< Does player resist this Damtyp? bool martial(void) const //!< Is player significantly influenced by iron? { return sympathy[FePo_iron] > 10; } @@ -77,26 +78,28 @@ public: /* XXX u.c data and funcs */ extern Player u; -extern void u_init(char const *name); -extern void write_char_dump(void); -extern int do_death(Death d, char const *what); -extern void heal_u(int amount, int boost, int loud); -extern int damage_u(int amount, Death d, char const *what); -extern int gain_body(int amount); -extern int gain_agility(int amount); -extern int drain_body(int amount, char const *what, int permanent); -extern int drain_agility(int amount, char const *what, int permanent); -extern void gain_experience(int amount); -extern int lev_threshold(int level); -extern Action_cost move_player(Offset delta); -extern void reloc_player(Coord c); -extern void recalc_defence(void); -extern Pass_fail teleport_u(void); -extern void update_player(void); + +void u_init(char const *name); +void write_char_dump(void); +int do_death(Death d, char const *what); +void heal_u(int amount, int boost, int loud); +int damage_u(int amount, Death d, char const *what); +int gain_body(int amount); +int gain_agility(int amount); +int drain_body(int amount, char const *what, int permanent); +int drain_agility(int amount, char const *what, int permanent); +void gain_experience(int amount); +int lev_threshold(int level); +Action_cost move_player(Offset delta); +void reloc_player(Coord c); +void recalc_defence(void); +Pass_fail teleport_u(void); +void update_player(void); inline bool empty_handed(void) { return u.weapon == NO_OBJ; } -extern bool wielding_melee_weapon(void); -extern bool wielding_ranged_weapon(void); +bool wielding_melee_weapon(void); +bool wielding_ranged_weapon(void); +void player_cleanup(void); #endif /* player.hh */ diff --git a/rng.hh b/rng.hh index c1a9681..f68b254 100644 --- a/rng.hh +++ b/rng.hh @@ -39,14 +39,15 @@ extern void *saved_state_buffer; extern int saved_state_size; //extern uint32_t rng(void); -extern void rng_init(void); -extern int zero_die(int sides); /* 0..n-1 */ -extern int one_die(int sides); /* 1..n */ -extern int dice(int count, int sides); -extern int exc_flat(int lower, int upper); /* l+1 ... u-1 */ -extern int inc_flat(int lower, int upper); /* l ... u */ -extern Coord inc_boxed(Coord topleft, Coord botright); -extern Coord exc_boxed(Coord topleft, Coord botright); +void rng_init(void); +int zero_die(int sides); /* 0..n-1 */ +int one_die(int sides); /* 1..n */ +int dice(int count, int sides); +int exc_flat(int lower, int upper); /* l+1 ... u-1 */ +int inc_flat(int lower, int upper); /* l ... u */ +Coord inc_boxed(Coord topleft, Coord botright); +Coord exc_boxed(Coord topleft, Coord botright); +Offset random_step(void); /*! \brief An instance of Bob Jenkins' "small noncryptographic PRNG" * diff --git a/u.cc b/u.cc index 07cdf2c..42436c3 100644 --- a/u.cc +++ b/u.cc @@ -869,5 +869,26 @@ Action_cost do_player_action(Action *act) return Cost_none; } +void player_cleanup(void) +{ + int i; + memset(u.sympathy, '\0', sizeof u.sympathy); + memset(u.resistances, '\0', sizeof u.resistances); + u.experience = u.level = 0; + u.body = u.agility = u.bdam = u.adam = 0; + memset(u.name, '\0', sizeof u.name); + u.name[0] = '\0'; + u.pos.y = u.pos.x = 0; + u.hpmax = u.hpcur = 0; + u.food = 0; + u.leadfoot = u.protection = u.withering = u.armourmelt = 0; + u.level = 0; + u.weapon = u.armour = u.ring = NO_OBJ; + for (i = 0; i < 19; ++i) + { + u.inventory[i] = NO_OBJ; + } +} + /* u.cc */ // vim:cindent:expandtab diff --git a/victrix-abyssi.hh b/victrix-abyssi.hh index 39572a2..227b7a5 100644 --- a/victrix-abyssi.hh +++ b/victrix-abyssi.hh @@ -69,12 +69,12 @@ #endif /* XXX main.c data and funcs */ -extern Offset random_step(void); -extern Action_cost do_player_action(Action *act); extern bool game_finished; extern int game_tick; extern bool wizard_mode; -extern void new_game(char const *name); +Action_cost do_player_action(Action *act); +void new_game(char const *name); +void main_loop(void); /* XXX misc.c data and funcs */ extern char const *damtype_names[DT_COUNT];