diff options
author | Bardur Arantsson <bardur@scientician.net> | 2016-09-17 09:58:14 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2016-09-17 09:58:14 +0200 |
commit | 6006546b4d015619b7d119d400fac819da6bc826 (patch) | |
tree | 2a1704a5c22cf2485917185316af0a5417a3de55 | |
parent | 6adef091b0713941e1149ecf21a5ab6feee3b06d (diff) |
Factor out 'flush_failure' option handling
-rw-r--r-- | src/cmd1.cc | 2 | ||||
-rw-r--r-- | src/cmd2.cc | 12 | ||||
-rw-r--r-- | src/cmd3.cc | 2 | ||||
-rw-r--r-- | src/cmd6.cc | 16 | ||||
-rw-r--r-- | src/cmd7.cc | 14 | ||||
-rw-r--r-- | src/powers.cc | 2 | ||||
-rw-r--r-- | src/randart.cc | 2 | ||||
-rw-r--r-- | src/spells2.cc | 2 | ||||
-rw-r--r-- | src/spells4.cc | 5 | ||||
-rw-r--r-- | src/util.cc | 12 | ||||
-rw-r--r-- | src/util.hpp | 1 |
11 files changed, 40 insertions, 30 deletions
diff --git a/src/cmd1.cc b/src/cmd1.cc index 71096f7f..d0541eb3 100644 --- a/src/cmd1.cc +++ b/src/cmd1.cc @@ -2699,7 +2699,7 @@ static bool_ easy_open_door(int y, int x) else { /* Failure */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("You failed to pick the lock."); diff --git a/src/cmd2.cc b/src/cmd2.cc index 2a8d33e7..fd31b564 100644 --- a/src/cmd2.cc +++ b/src/cmd2.cc @@ -819,7 +819,7 @@ static bool_ do_cmd_open_chest(int y, int x, s16b o_idx) /* We may continue repeating */ more = TRUE; - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to pick the lock."); } @@ -1080,7 +1080,7 @@ static bool_ do_cmd_open_aux(int y, int x, int dir) else { /* Failure */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("You failed to pick the lock."); @@ -1879,7 +1879,7 @@ static bool_ do_cmd_disarm_chest(int y, int x, s16b o_idx) { /* We may keep trying */ more = TRUE; - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to disarm the chest."); } @@ -1977,7 +1977,7 @@ static bool_ do_cmd_disarm_aux(int y, int x, int dir, int do_pickup) else if ((i > 5) && (randint(i) > 5)) { /* Failure */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_format("You failed to disarm the %s.", name); @@ -2873,7 +2873,7 @@ void do_cmd_rest(void) if (cave[p_ptr->py][p_ptr->px].feat == FEAT_BETWEEN) { /* 'R&\n' is one of our favourite macros, so we have to do this */ - if (flush_failure) flush(); + flush_on_failure(); /* Tell the player why */ msg_print(format("Resting on a %s is too dangerous!", @@ -2887,7 +2887,7 @@ void do_cmd_rest(void) if (p_ptr->necro_extra & CLASS_UNDEAD) { /* 'R&\n' is one of our favourite macros, so we have to do this */ - if (flush_failure) flush(); + flush_on_failure(); /* Tell the player why */ msg_print("Resting is impossible while undead!"); diff --git a/src/cmd3.cc b/src/cmd3.cc index 9a4e3fc2..dd837906 100644 --- a/src/cmd3.cc +++ b/src/cmd3.cc @@ -1595,7 +1595,7 @@ bool_ do_cmd_sense_grid_mana() /* Roll for usage */ if ((chance < USE_DEVICE) || (randint(chance) < USE_DEVICE)) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to sense the grid's mana."); return FALSE; } diff --git a/src/cmd6.cc b/src/cmd6.cc index 841c6684..4490b5de 100644 --- a/src/cmd6.cc +++ b/src/cmd6.cc @@ -3750,7 +3750,7 @@ void do_cmd_use_staff(void) /* Roll for usage */ if (magik(chance)) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to use the staff properly."); return; } @@ -3758,7 +3758,7 @@ void do_cmd_use_staff(void) /* Notice empty staffs */ if (o_ptr->pval <= 0) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("The staff has no charges left."); o_ptr->ident |= (IDENT_EMPTY); return; @@ -3915,7 +3915,7 @@ void do_cmd_aim_wand(void) /* Roll for usage */ if (magik(chance)) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to use the wand properly."); return; } @@ -3923,7 +3923,7 @@ void do_cmd_aim_wand(void) /* The wand is already empty! */ if (o_ptr->pval <= 0) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("The wand has no charges left."); o_ptr->ident |= (IDENT_EMPTY); return; @@ -4200,7 +4200,7 @@ void do_cmd_zap_rod(void) if ((chance < USE_DEVICE) || (randint(chance) < USE_DEVICE)) { /* Flush input if necessary */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("You failed to use the rod properly."); @@ -4218,7 +4218,7 @@ void do_cmd_zap_rod(void) if (o_ptr->timeout < cost) { /* Flush input if necessary */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("The rod does not have enough mana yet."); @@ -4668,7 +4668,7 @@ bool_ brand_bolts(void) } /* Flush */ - if (flush_failure) flush(); + flush_on_failure(); /* Fail */ msg_print("The fiery enchantment failed."); @@ -4916,7 +4916,7 @@ void do_cmd_activate(void) /* Roll for usage */ if ((chance < USE_DEVICE) || (randint(chance) < USE_DEVICE)) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to activate it properly."); return; } diff --git a/src/cmd7.cc b/src/cmd7.cc index 6aac9050..aaec34b7 100644 --- a/src/cmd7.cc +++ b/src/cmd7.cc @@ -420,7 +420,7 @@ void do_cmd_mindcraft(void) /* Failed spell */ if (rand_int(100) < chance) { - if (flush_failure) flush(); + flush_on_failure(); msg_format("You failed to concentrate hard enough!"); @@ -945,7 +945,7 @@ void do_cmd_mimic(void) /* Failed spell */ if (rand_int(100) < fail) { - if (flush_failure) flush(); + flush_on_failure(); msg_format("You failed to concentrate hard enough!"); @@ -1576,7 +1576,7 @@ void do_cmd_powermage(void) char sfail[80]; /* Flush input if told so */ - if (flush_failure) flush(); + flush_on_failure(); /* Insane players can see something strange */ if (rand_int(100) < insanity) @@ -1754,7 +1754,7 @@ void brand_ammo(int brand_type, int bolts_only) } else { - if (flush_failure) flush(); + flush_on_failure(); msg_print("The enchantment failed."); } } @@ -2199,7 +2199,7 @@ void do_cmd_necromancer(void) /* Failed spell */ if (rand_int(100) < chance) { - if (flush_failure) flush(); + flush_on_failure(); msg_format("You failed to concentrate hard enough!"); if (randint(100) < (chance / 2)) @@ -2581,7 +2581,7 @@ int rune_exec(rune_spell *spell, int cost) char sfail[80]; /* Flush input if told so */ - if (flush_failure) flush(); + flush_on_failure(); /* Insane players can see something strange */ if (rand_int(100) < insanity) @@ -4060,7 +4060,7 @@ void do_cmd_symbiotic(void) /* Failed spell */ if (rand_int(100) < chance) { - if (flush_failure) flush(); + flush_on_failure(); msg_format("You failed to concentrate hard enough!"); } else diff --git a/src/powers.cc b/src/powers.cc index b58eb164..8edfb7b5 100644 --- a/src/powers.cc +++ b/src/powers.cc @@ -122,7 +122,7 @@ static bool_ power_chance(power_type *x_ptr) return (TRUE); } - if (flush_failure) flush(); + flush_on_failure(); msg_print("You've failed to concentrate hard enough."); return (FALSE); diff --git a/src/randart.cc b/src/randart.cc index 9528faee..e22f1c93 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -458,7 +458,7 @@ bool_ artifact_scroll(void) if (!okay) { /* Flush */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("The enchantment failed."); diff --git a/src/spells2.cc b/src/spells2.cc index 45fd18eb..5fd21698 100644 --- a/src/spells2.cc +++ b/src/spells2.cc @@ -2910,7 +2910,7 @@ bool_ enchant_spell(int num_hit, int num_dam, int num_ac, int num_pval) if (!okay) { /* Flush */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("The enchantment failed."); diff --git a/src/spells4.cc b/src/spells4.cc index 62586758..199aea98 100644 --- a/src/spells4.cc +++ b/src/spells4.cc @@ -512,10 +512,7 @@ void lua_cast_school_spell(s32b s, bool_ no_cost) /* failures are dangerous; we'll flush the input buffer so it isn't missed. */ - if (flush_failure) - { - flush(); - } + flush_on_failure(); msg_print("You failed to get the spell off!"); } diff --git a/src/util.cc b/src/util.cc index d899b2f2..d1bc6bbd 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1221,6 +1221,18 @@ void flush(void) /* + * Flush input if the 'flush_failure' option is set. + */ +void flush_on_failure() +{ + if (flush_failure) + { + flush(); + } +} + + +/* * Flush the screen, make a noise */ void bell(void) diff --git a/src/util.hpp b/src/util.hpp index 583fd4aa..2953ca11 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -24,6 +24,7 @@ extern errr fd_read(int fd, char *buf, huge n); extern errr fd_write(int fd, cptr buf, huge n); extern errr fd_close(int fd); extern void flush(void); +extern void flush_on_failure(); extern void move_cursor(int row, int col); extern void text_to_ascii(char *buf, cptr str); extern void ascii_to_text(char *buf, cptr str); |