summaryrefslogtreecommitdiff
path: root/src/cmd5.cc
diff options
context:
space:
mode:
authorManoj Srivastava <srivasta@debian.org>2020-05-27 16:44:24 -0700
committerManoj Srivastava <srivasta@debian.org>2020-05-27 16:45:26 -0700
commit2c93afb0089a37de798da8d23824a84846ab7d7c (patch)
treea53be684627948ed96d64e2be7aac1bea83507b8 /src/cmd5.cc
parentd6b913d3ca2e84b75f3675fd6e9f5246c100cf27 (diff)
parente9d08c617ee73f0636e1f1a1d40582f193c37e81 (diff)
Merge branch 'upstream'
Diffstat (limited to 'src/cmd5.cc')
-rw-r--r--src/cmd5.cc155
1 files changed, 72 insertions, 83 deletions
diff --git a/src/cmd5.cc b/src/cmd5.cc
index a93759b0..c030addd 100644
--- a/src/cmd5.cc
+++ b/src/cmd5.cc
@@ -37,12 +37,11 @@
#include "stats.hpp"
#include "tables.hpp"
#include "util.hpp"
-#include "util.h"
-#include "variable.h"
#include "variable.hpp"
#include "wizard2.hpp"
#include "xtra1.hpp"
#include "xtra2.hpp"
+#include "z-form.hpp"
#include "z-rand.hpp"
#include <boost/noncopyable.hpp>
@@ -91,29 +90,32 @@ static object_filter_t const &item_tester_hook_browsable()
/*
* Are we using a mage staff
*/
-bool_ is_magestaff()
+bool is_magestaff()
{
- int i;
-
-
- i = 0;
+ int i = 0;
while (p_ptr->body_parts[i] == INVEN_WIELD)
{
object_type *o_ptr = &p_ptr->inventory[INVEN_WIELD + i];
/* Wielding a mage staff */
- if ((o_ptr->k_idx) && (o_ptr->tval == TV_MSTAFF)) return (TRUE);
+ if ((o_ptr->k_ptr) && (o_ptr->tval == TV_MSTAFF))
+ {
+ return true;
+ }
/* Next slot */
i++;
/* Paranoia */
- if (i >= (INVEN_TOTAL - INVEN_WIELD)) break;
+ if (i >= (INVEN_TOTAL - INVEN_WIELD))
+ {
+ break;
+ }
}
/* Not wielding a mage staff */
- return (FALSE);
+ return false;
}
@@ -131,11 +133,9 @@ static int print_book(s16b sval, s32b spell_idx, object_type *obj)
for (auto spell_idx : school_book->spell_idxs)
{
byte color = TERM_L_DARK;
- bool_ is_ok;
char label[8];
- is_ok = is_ok_spell(spell_idx, obj->pval);
- if (is_ok)
+ if (is_ok_spell(spell_idx, obj->pval))
{
color = (get_mana(spell_idx) > get_power(spell_idx)) ? TERM_ORANGE : TERM_L_GREEN;
}
@@ -170,8 +170,7 @@ static void browse_school_spell(int book, int spell_idx, object_type *o_ptr)
I2A(0), I2A(num - 1));
/* Save the screen */
- character_icky = TRUE;
- Term_save();
+ screen_save_no_flush();
/* Display a list of spells */
print_book(book, spell_idx, o_ptr);
@@ -208,8 +207,7 @@ static void browse_school_spell(int book, int spell_idx, object_type *o_ptr)
/* Restore the screen */
- Term_load();
- character_icky = FALSE;
+ screen_load_no_flush();
/* Show choices */
window_stuff();
@@ -267,7 +265,7 @@ static void do_poly_wounds()
s16b change = damroll(p_ptr->lev, 5);
- bool_ Nasty_effect = (randint(5) == 1);
+ bool Nasty_effect = (randint(5) == 1);
if (!(wounds || hit_p || Nasty_effect)) return;
@@ -321,7 +319,7 @@ void do_poly_self()
}
/* Deformities are discriminated against! */
- dec_stat(A_CHR, randint(6), TRUE);
+ dec_stat(A_CHR, randint(6), true);
if (effect_msg[0])
{
@@ -358,7 +356,7 @@ void do_poly_self()
goalexpfact = 100 + 3 * rand_int(poly_power);
/* Roll until an appropriate selection is made */
- while (1)
+ while (true)
{
new_race = rand_int(race_info.size());
expfact = race_info[new_race].ps.exp;
@@ -450,7 +448,7 @@ void do_poly_self()
/*
* Fetch an item (teleport it right underneath the caster)
*/
-void fetch(int dir, int wgt, bool_ require_los)
+void fetch(int dir, int wgt, bool require_los)
{
/* Check to see if an object is already there */
if (!cave[p_ptr->py][p_ptr->px].o_idxs.empty())
@@ -492,7 +490,7 @@ void fetch(int dir, int wgt, bool_ require_los)
int ty = p_ptr->py; /* Where to drop the item */
int tx = p_ptr->px;
- while (1)
+ while (true)
{
ty += ddy[dir];
tx += ddx[dir];
@@ -529,7 +527,7 @@ void fetch(int dir, int wgt, bool_ require_los)
/* Feedback */
char o_name[80];
- object_desc(o_name, o_ptr, TRUE, 0);
+ object_desc(o_name, o_ptr, true, 0);
msg_format("%^s flies through the air to your feet.", o_name);
note_spot(p_ptr->py, p_ptr->px);
@@ -550,7 +548,7 @@ std::string symbiote_name(bool capitalize)
buf.reserve(32);
// Fallback; shouldn't ever be necessary
- if (!o_ptr->k_idx)
+ if (!o_ptr->k_ptr)
{
buf += "A non-existent symbiote";
}
@@ -667,12 +665,11 @@ static std::tuple<int, int> choose_monster_power(monster_race const *r_ptr, bool
label, (symbiosis ? "symbiote" : "body"));
/* Save the screen */
- character_icky = TRUE;
- Term_save();
+ screen_save_no_flush();
/* Get a spell from the user */
monster_power const *power = nullptr;
- bool_ flag = FALSE; // Nothing chosen yet
+ bool flag = false; // Nothing chosen yet
while (!flag)
{
/* Show the list */
@@ -732,7 +729,7 @@ static std::tuple<int, int> choose_monster_power(monster_race const *r_ptr, bool
char choice;
if (!get_com(out_val, &choice))
{
- flag = FALSE;
+ flag = false;
break;
}
@@ -757,7 +754,7 @@ static std::tuple<int, int> choose_monster_power(monster_race const *r_ptr, bool
else
{
/* Can't uppercase digits XXX XXX XXX */
- ask = FALSE;
+ ask = false;
i = choice - '0' + 26;
}
@@ -795,12 +792,11 @@ static std::tuple<int, int> choose_monster_power(monster_race const *r_ptr, bool
}
/* Stop the loop */
- flag = TRUE;
+ flag = true;
}
/* Restore the screen */
- Term_load();
- character_icky = FALSE;
+ screen_load_no_flush();
/* Abort if needed */
if (!flag || (power == nullptr))
@@ -817,6 +813,8 @@ static std::tuple<int, int> choose_monster_power(monster_race const *r_ptr, bool
*/
static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_spell_idx)
{
+ auto const &dungeon_flags = game->dungeon_flags;
+
assert(monster_spell_idx < monster_spell_flag_set::nbits);
/* Shorthand */
@@ -842,14 +840,14 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
case SF_MULTIPLY_IDX:
{
- do_cmd_wiz_named_friendly(p_ptr->body_monster, FALSE);
+ do_cmd_wiz_named_friendly(p_ptr->body_monster, false);
break;
}
case SF_S_ANIMAL_IDX:
{
- summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, true);
break;
}
@@ -1469,7 +1467,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 4; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, true);
}
break;
@@ -1574,7 +1572,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 1; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_THUNDERLORD, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_THUNDERLORD, true);
}
break;
@@ -1587,7 +1585,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
for (int k = 0; k < 6; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_KIN, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_KIN, true);
}
break;
@@ -1597,7 +1595,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 1; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_HI_DEMON, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_HI_DEMON, true);
}
break;
@@ -1607,7 +1605,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 1; k++)
{
- summon_specific_friendly(y, x, rlev, 0, TRUE);
+ summon_specific_friendly(y, x, rlev, 0, true);
}
break;
@@ -1617,7 +1615,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 6; k++)
{
- summon_specific_friendly(y, x, rlev, 0, TRUE);
+ summon_specific_friendly(y, x, rlev, 0, true);
}
break;
@@ -1627,7 +1625,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 6; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_ANT, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_ANT, true);
}
break;
@@ -1637,7 +1635,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 6; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_SPIDER, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_SPIDER, true);
}
break;
@@ -1647,7 +1645,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 6; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_HOUND, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_HOUND, true);
}
break;
@@ -1657,7 +1655,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 6; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_HYDRA, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_HYDRA, true);
}
break;
@@ -1667,7 +1665,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 1; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_ANGEL, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_ANGEL, true);
}
break;
@@ -1677,7 +1675,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 1; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_DEMON, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_DEMON, true);
}
break;
@@ -1687,7 +1685,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 1; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_UNDEAD, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_UNDEAD, true);
}
break;
@@ -1697,7 +1695,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 1; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_DRAGON, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_DRAGON, true);
}
break;
@@ -1707,7 +1705,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 8; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, true);
}
break;
@@ -1717,7 +1715,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 8; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_HI_DRAGON_NO_UNIQUES, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_HI_DRAGON_NO_UNIQUES, true);
}
break;
@@ -1727,7 +1725,7 @@ static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_s
{
for (int k = 0; k < 8; k++)
{
- summon_specific_friendly(y, x, rlev, SUMMON_WRAITH, TRUE);
+ summon_specific_friendly(y, x, rlev, SUMMON_WRAITH, true);
}
break;
@@ -1821,11 +1819,12 @@ boost::optional<int> get_item_hook_find_spell(object_filter_t const &)
return boost::none;
}
- int const spell = find_spell(buf);
- if (spell == -1)
+ auto spell_idx = find_spell(buf);
+ if (!spell_idx)
{
return boost::none;
}
+ int const spell = *spell_idx;
for (int i = 0; i < INVEN_TOTAL; i++)
{
@@ -1866,40 +1865,41 @@ boost::optional<int> get_item_hook_find_spell(object_filter_t const &)
/*
* Is the spell castable?
*/
-bool_ is_ok_spell(s32b spell_idx, s32b pval)
+bool is_ok_spell(s32b spell_idx, s32b pval)
{
spell_type *spell = spell_at(spell_idx);
// Calculate availability based on caster's skill level.
s32b level;
- bool_ na;
+ bool na;
get_level_school(spell, 50, 0, &level, &na);
if (na || (level == 0))
{
- return FALSE;
+ return false;
}
// Are we permitted to cast based on item pval? Only music
// spells have non-zero minimum PVAL.
- if (pval < spell_type_minimum_pval(spell))
+ s32b min_pval = spell_type_minimum_pval(spell);
+ if (min_pval > 0 && pval < min_pval)
{
- return FALSE;
+ return false;
}
// OK, we're permitted to cast it.
- return TRUE;
+ return true;
}
/*
* Get a spell from a book
*/
-s32b get_school_spell(cptr do_what, s16b force_book)
+s32b get_school_spell(const char *do_what, s16b force_book)
{
int i, item;
s32b spell = -1;
int num = 0;
s32b where = 1;
int ask;
- bool_ flag;
+ bool flag;
char out_val[160];
object_type *o_ptr, forge;
int tmp;
@@ -1952,7 +1952,7 @@ s32b get_school_spell(cptr do_what, s16b force_book)
}
/* Nothing chosen yet */
- flag = FALSE;
+ flag = false;
/* Show choices */
window_stuff();
@@ -1973,8 +1973,7 @@ s32b get_school_spell(cptr do_what, s16b force_book)
}
/* Save the screen */
- character_icky = TRUE;
- Term_save();
+ screen_save_no_flush();
/* Go */
if (hack_force_spell == -1)
@@ -1993,8 +1992,8 @@ s32b get_school_spell(cptr do_what, s16b force_book)
/* Restore and save screen; this prevents
subprompt from leaving garbage when going
around the loop multiple times. */
- Term_load();
- Term_save();
+ screen_load_no_flush();
+ screen_save_no_flush();
/* Display a list of spells */
where = print_book(sval, pval, o_ptr);
@@ -2002,7 +2001,7 @@ s32b get_school_spell(cptr do_what, s16b force_book)
/* Input */
if (!get_com(out_val, &choice))
{
- flag = FALSE;
+ flag = false;
break;
}
@@ -2031,16 +2030,11 @@ s32b get_school_spell(cptr do_what, s16b force_book)
}
else
{
- bool_ ok;
-
/* Save the spell index */
spell = spell_x(sval, pval, i);
- /* Do we need to do some pre test */
- ok = is_ok_spell(spell, o_ptr->pval);
-
/* Require "okay" spells */
- if (!ok)
+ if (!is_ok_spell(spell, o_ptr->pval))
{
bell();
msg_format("You may not %s that spell.", do_what);
@@ -2049,19 +2043,16 @@ s32b get_school_spell(cptr do_what, s16b force_book)
}
/* Stop the loop */
- flag = TRUE;
+ flag = true;
}
}
}
else
{
- bool_ ok;
-
/* Require "okay" spells */
- ok = is_ok_spell(hack_force_spell, hack_force_spell_pval);
- if (ok)
+ if (is_ok_spell(hack_force_spell, hack_force_spell_pval))
{
- flag = TRUE;
+ flag = true;
spell = hack_force_spell;
}
else
@@ -2074,9 +2065,7 @@ s32b get_school_spell(cptr do_what, s16b force_book)
/* Restore the screen */
- Term_load();
- character_icky = FALSE;
-
+ screen_load_no_flush();
/* Show choices */
window_stuff();
@@ -2113,7 +2102,7 @@ void cast_school_spell()
/* Actualy cast the choice */
if (spell != -1)
{
- lua_cast_school_spell(spell, FALSE);
+ lua_cast_school_spell(spell, false);
}
}