diff options
Diffstat (limited to 'src/cmd3.cc')
-rw-r--r-- | src/cmd3.cc | 199 |
1 files changed, 82 insertions, 117 deletions
diff --git a/src/cmd3.cc b/src/cmd3.cc index cbf58820..6498d48b 100644 --- a/src/cmd3.cc +++ b/src/cmd3.cc @@ -33,19 +33,21 @@ #include "tables.hpp" #include "town_type.hpp" #include "util.hpp" -#include "util.h" -#include "variable.h" #include "variable.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-form.hpp" #include "z-rand.hpp" -#include <cassert> #include <algorithm> +#include <boost/algorithm/string/predicate.hpp> +#include <cassert> #include <fmt/format.h> #include <memory> #include <utility> +using boost::algorithm::equals; + /* * Display p_ptr->inventory */ @@ -55,11 +57,10 @@ void do_cmd_inven() /* Note that we are in "p_ptr->inventory" mode */ - command_wrk = FALSE; + command_wrk = false; /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Show the inventory */ show_inven_full(); @@ -81,9 +82,7 @@ void do_cmd_inven() command_new = inkey(); /* Restore the screen */ - Term_load(); - character_icky = FALSE; - + screen_load_no_flush(); /* Process "Escape" */ if (command_new == ESCAPE) @@ -96,7 +95,7 @@ void do_cmd_inven() else { /* Mega-Hack -- Don't disable keymaps for this key */ - request_command_inven_mode = TRUE; + request_command_inven_mode = true; } } @@ -110,11 +109,10 @@ void do_cmd_equip() /* Note that we are in "equipment" mode */ - command_wrk = TRUE; + command_wrk = true; /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Display the equipment */ show_equip_full(); @@ -137,9 +135,7 @@ void do_cmd_equip() command_new = inkey(); /* Restore the screen */ - Term_load(); - character_icky = FALSE; - + screen_load_no_flush(); /* Process "Escape" */ if (command_new == ESCAPE) @@ -152,7 +148,7 @@ void do_cmd_equip() else { /* Mega-Hack -- Don't disable keymaps for this key */ - request_command_inven_mode = TRUE; + request_command_inven_mode = true; } } @@ -171,33 +167,32 @@ static bool item_tester_hook_wear(object_type const *o_ptr) { object_type *q_ptr = &p_ptr->inventory[i]; - if (!q_ptr->k_idx) continue; + if (!q_ptr->k_ptr) + { + continue; + } - if (object_flags(q_ptr) & TR_ULTIMATE) return (FALSE); + if (object_flags(q_ptr) & TR_ULTIMATE) + { + return false; + } } } if ((slot < INVEN_WIELD) || ((p_ptr->body_parts[slot - INVEN_WIELD] == INVEN_WIELD) && (p_ptr->melee_style != SKILL_MASTERY))) - return (FALSE); + return false; /* Check for a usable slot */ - if (slot >= INVEN_WIELD) return (TRUE); + if (slot >= INVEN_WIELD) return true; /* Assume not wearable */ - return (FALSE); + return false; } -bool_ is_slot_ok(int slot) +static bool is_slot_ok(int slot) { - if ((slot >= INVEN_WIELD) && (slot < INVEN_TOTAL)) - { - return (TRUE); - } - else - { - return (FALSE); - } + return (slot >= INVEN_WIELD) && (slot < INVEN_TOTAL); } @@ -216,7 +211,7 @@ void do_cmd_wield() object_type *i_ptr; - cptr act; + const char *act; char o_name[80]; @@ -240,7 +235,7 @@ void do_cmd_wield() if (cursed_p(&p_ptr->inventory[slot])) { /* Describe it */ - object_desc(o_name, &p_ptr->inventory[slot], FALSE, 0); + object_desc(o_name, &p_ptr->inventory[slot], false, 0); /* Message */ msg_format("The %s you are %s appears to be cursed.", @@ -251,12 +246,12 @@ void do_cmd_wield() } if ((cursed_p(o_ptr)) && (options->wear_confirm) - && (object_known_p(o_ptr) || (o_ptr->ident & (IDENT_SENSE)))) + && (object_known_p(o_ptr))) { char dummy[512]; /* Describe it */ - object_desc(o_name, o_ptr, FALSE, 0); + object_desc(o_name, o_ptr, false, 0); strnfmt(dummy, 512, "Really use the %s {cursed}? ", o_name); if (!(get_check(dummy))) @@ -277,10 +272,10 @@ void do_cmd_wield() /* Two handed weapons can't be wielded with a shield */ if ((is_slot_ok(slot - INVEN_WIELD + INVEN_ARM)) && - (flags & TR_MUST2H) && - (p_ptr->inventory[slot - INVEN_WIELD + INVEN_ARM].k_idx != 0)) + (flags & TR_MUST2H) && + (p_ptr->inventory[slot - INVEN_WIELD + INVEN_ARM].k_ptr)) { - object_desc(o_name, o_ptr, FALSE, 0); + object_desc(o_name, o_ptr, false, 0); msg_format("You cannot wield your %s with a shield.", o_name); return; } @@ -293,16 +288,17 @@ void do_cmd_wield() auto const i_flags = object_flags(i_ptr); /* Prevent shield from being put on if wielding 2H */ - if ((i_flags & TR_MUST2H) && (i_ptr->k_idx) && - (p_ptr->body_parts[slot - INVEN_WIELD] == INVEN_ARM)) + if ((i_flags & TR_MUST2H) && + i_ptr->k_ptr && + (p_ptr->body_parts[slot - INVEN_WIELD] == INVEN_ARM)) { - object_desc(o_name, o_ptr, FALSE, 0); + object_desc(o_name, o_ptr, false, 0); msg_format("You cannot wield your %s with a two-handed weapon.", o_name); return; } if ((p_ptr->body_parts[slot - INVEN_WIELD] == INVEN_ARM) && - (i_flags & TR_COULD2H)) + (i_flags & TR_COULD2H)) { if (!get_check("Are you sure you want to restrict your fighting? ")) { @@ -312,8 +308,8 @@ void do_cmd_wield() } if ((is_slot_ok(slot - INVEN_WIELD + INVEN_ARM)) && - (p_ptr->inventory[slot - INVEN_WIELD + INVEN_ARM].k_idx != 0) && - (flags & TR_COULD2H)) + p_ptr->inventory[slot - INVEN_WIELD + INVEN_ARM].k_ptr && + (flags & TR_COULD2H)) { if (!get_check("Are you sure you want to use this weapon with a shield?")) { @@ -344,20 +340,20 @@ void do_cmd_wield() /* Take off existing item */ if (slot != INVEN_AMMO) { - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { /* Take off existing item */ - inven_takeoff(slot, 255, FALSE); + inven_takeoff(slot, 255, false); } } else { - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { if (!object_similar(o_ptr, q_ptr)) { /* Take off existing item */ - inven_takeoff(slot, 255, FALSE); + inven_takeoff(slot, 255, false); } else { @@ -404,7 +400,7 @@ void do_cmd_wield() } /* Describe the result */ - object_desc(o_name, o_ptr, TRUE, 3); + object_desc(o_name, o_ptr, true, 3); /* Message */ msg_format("%s %s (%c).", act, o_name, index_to_label(slot)); @@ -414,16 +410,12 @@ void do_cmd_wield() { /* Warn the player */ msg_print("Oops! It feels deathly cold!"); - - /* Note the curse */ - o_ptr->ident |= (IDENT_SENSE); - o_ptr->sense = SENSE_CURSED; } /* Take care of item sets */ if (o_ptr->name1) { - wield_set(o_ptr->name1, a_info[o_ptr->name1].set, FALSE); + wield_set(o_ptr->name1, a_info[o_ptr->name1].set, false); } /* Recalculate bonuses */ @@ -479,7 +471,7 @@ void do_cmd_takeoff() energy_use = 50; /* Take off the item */ - inven_takeoff(item, 255, FALSE); + inven_takeoff(item, 255, false); /* Recalculate hitpoint */ p_ptr->update |= (PU_HP); @@ -550,7 +542,7 @@ void do_cmd_drop() energy_use = 50; /* Drop (some of) the item */ - inven_drop(item, amt, p_ptr->py, p_ptr->px, FALSE); + inven_drop(item, amt, p_ptr->py, p_ptr->px, false); } @@ -559,18 +551,16 @@ void do_cmd_drop() */ void do_cmd_destroy() { - auto const &k_info = game->edit_data.k_info; - int old_number; - bool_ force = FALSE; + bool force = false; char o_name[80]; char out_val[160]; /* Hack -- force destruction */ - if (command_arg > 0) force = TRUE; + if (command_arg > 0) force = true; /* Get an item */ @@ -601,7 +591,7 @@ void do_cmd_destroy() /* Describe the object */ old_number = o_ptr->number; o_ptr->number = amt; - object_desc(o_name, o_ptr, TRUE, 3); + object_desc(o_name, o_ptr, true, 3); o_ptr->number = old_number; /* Verify unless quantity given */ @@ -629,28 +619,12 @@ void do_cmd_destroy() /* Artifacts cannot be destroyed */ if (artifact_p(o_ptr)) { - byte feel = SENSE_SPECIAL; - + /* Don't use any energy */ energy_use = 0; /* Message */ msg_format("You cannot destroy %s.", o_name); - /* Hack -- Handle icky artifacts */ - if (cursed_p(o_ptr)) feel = SENSE_TERRIBLE; - - /* Hack -- inscribe the artifact */ - o_ptr->sense = feel; - - /* We have "felt" it (again) */ - o_ptr->ident |= (IDENT_SENSE); - - /* Combine the pack */ - p_ptr->notice |= (PN_COMBINE); - - /* Window stuff */ - p_ptr->window |= (PW_INVEN | PW_EQUIP); - /* Done */ return; } @@ -677,7 +651,7 @@ void do_cmd_destroy() /* Eru wont be happy */ if (flags & TR_BLESSED) { - inc_piety(GOD_ERU, -10 * k_info[o_ptr->k_idx].level); + inc_piety(GOD_ERU, -10 * o_ptr->k_ptr->level); } /* Eliminate the item */ @@ -705,13 +679,13 @@ void do_cmd_observe() /* Description */ char o_name[80]; - object_desc(o_name, o_ptr, TRUE, 3); + object_desc(o_name, o_ptr, true, 3); /* Describe */ cmsg_format(TERM_L_BLUE, "%s", o_name); /* Describe it fully */ - if (!object_out_desc(o_ptr, NULL, FALSE, TRUE)) msg_print("You see nothing special."); + if (!object_out_desc(o_ptr, NULL, false, true)) msg_print("You see nothing special."); } @@ -776,7 +750,7 @@ void do_cmd_inscribe() /* Describe the activity */ char o_name[80]; - object_desc(o_name, o_ptr, TRUE, 3); + object_desc(o_name, o_ptr, true, 3); /* Message */ msg_format("Inscribing %s.", o_name); @@ -1032,7 +1006,7 @@ void do_cmd_locate() x2 = x1 = panel_col_min; /* Show panels until done */ - while (1) + while (true) { /* Describe the location */ if ((y2 == y1) && (x2 == x1)) @@ -1119,7 +1093,7 @@ void do_cmd_locate() * The table of "symbol info" -- each entry is a string of the form * "X:desc" where "X" is the trigger, and "desc" is the "info". */ -static cptr ident_info[] = +static const char *ident_info[] = { " :A dark grid", "!:A potion (or oil)", @@ -1350,19 +1324,19 @@ void do_cmd_query_symbol() char buf[128]; - bool_ all = FALSE; + bool all = false; - bool_ uniq = FALSE; + bool uniq = false; - bool_ norm = FALSE; + bool norm = false; - bool_ name = FALSE; + bool name = false; char temp[80] = ""; - bool_ recall = FALSE; + bool recall = false; bool (*sort_by)(int,int) = nullptr; @@ -1380,22 +1354,22 @@ void do_cmd_query_symbol() /* Describe */ if (sym == KTRL('A')) { - all = TRUE; + all = true; strcpy(buf, "Full monster list."); } else if (sym == KTRL('U')) { - all = uniq = TRUE; + all = uniq = true; strcpy(buf, "Unique monster list."); } else if (sym == KTRL('N')) { - all = norm = TRUE; + all = norm = true; strcpy(buf, "Non-unique monster list."); } else if (sym == KTRL('M')) { - all = name = TRUE; + all = name = true; if (!get_string("Name:", temp, 70)) return; strnfmt(buf, 128, "Monsters with a name \"%s\"", temp); strlower(temp); @@ -1491,7 +1465,7 @@ void do_cmd_query_symbol() i = who.size() - 1; /* Scan the monster memory */ - while (1) + while (true) { /* Extract a race */ auto r_idx = who[i]; @@ -1509,14 +1483,13 @@ void do_cmd_query_symbol() Term_addstr( -1, TERM_WHITE, " [(r)ecall, ESC]"); /* Interact */ - while (1) + while (true) { /* Recall */ if (recall) { /* Save the screen */ - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); /* Recall on screen */ screen_roff(who[i], 0); @@ -1532,8 +1505,7 @@ void do_cmd_query_symbol() if (recall) { /* Restore */ - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } /* Normal commands */ @@ -1575,7 +1547,7 @@ void do_cmd_query_symbol() /* * Try to "sense" the grid's mana */ -bool_ do_cmd_sense_grid_mana() +void do_cmd_sense_grid_mana() { int chance, i; @@ -1603,7 +1575,7 @@ bool_ do_cmd_sense_grid_mana() { flush_on_failure(); msg_print("You failed to sense the grid's mana."); - return FALSE; + return; } /* Try to give an "average" value */ @@ -1619,14 +1591,13 @@ bool_ do_cmd_sense_grid_mana() { msg_format("Average Area's mana: %d", (cave[p_ptr->py][p_ptr->px].mana / i) * i); } - return TRUE; } /* * Try to add a CLI action. */ -void cli_add(cptr active, cptr trigger, cptr descr) +void cli_add(const char *active, const char *trigger, const char *descr) { s16b num; cli_comm *cli_ptr, *old_ptr; @@ -1662,7 +1633,7 @@ void cli_add(cptr active, cptr trigger, cptr descr) if (strchr(trigger, '\'')) { char temp[80], *t; - cptr s; + const char *s; for (s = trigger, t = temp; ; s++, t++) { /* tokenize() causes each ' to be followed by another character, @@ -1707,9 +1678,9 @@ void cli_add(cptr active, cptr trigger, cptr descr) /* * Get a string using CLI completion. */ -static bool_ get_string_cli(cptr prompt, char *buf, int len) +static bool get_string_cli(const char *prompt, char *buf, int len) { - bool_ res; + bool res; /* Paranoia XXX XXX XXX */ @@ -1756,7 +1727,7 @@ void do_cmd_cli() /* Analyse the input */ for (cli_ptr = cli_info; cli_ptr->comm; cli_ptr++) { - if (!strcmp(buff, cli_ptr->comm)) + if (equals(buff, cli_ptr->comm)) { /* Process the command without keymaps or macros. */ command_new = cli_ptr->key; @@ -1790,20 +1761,14 @@ void do_cmd_cli_help() } } - /* Enter "icky" mode */ - character_icky = TRUE; - /* Save the screen */ - Term_save(); + screen_save_no_flush(); /* Display the file contents */ show_string(w.c_str(), "Command line help"); /* Restore the screen */ - Term_load(); - - /* Leave "icky" mode */ - character_icky = FALSE; + screen_load_no_flush(); } @@ -1813,14 +1778,14 @@ void do_cmd_cli_help() void do_cmd_html_dump() { char tmp_val[81]; - bool_ html = TRUE; + bool html = true; term_win *save; /* Save the screen */ save = Term_save_to(); if (wizard && get_check("WIZARD MODE: Do an help file dump?")) - html = FALSE; + html = false; /* Ask for a file */ if (html) |