diff options
Diffstat (limited to 'src/xtra2.cc')
-rw-r--r-- | src/xtra2.cc | 749 |
1 files changed, 229 insertions, 520 deletions
diff --git a/src/xtra2.cc b/src/xtra2.cc index 096f8966..d8b87f51 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -14,8 +14,10 @@ #include "corrupt.hpp" #include "dungeon_info_type.hpp" #include "ego_item_type.hpp" +#include "feature_flag.hpp" #include "feature_type.hpp" #include "files.hpp" +#include "game.hpp" #include "gods.hpp" #include "hook_player_level_in.hpp" #include "hook_monster_death_in.hpp" @@ -27,17 +29,20 @@ #include "monster3.hpp" #include "monster_ego.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "monster_type.hpp" #include "notes.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "object_kind.hpp" #include "options.hpp" #include "player_class.hpp" #include "player_race.hpp" +#include "player_race_flag.hpp" #include "player_race_mod.hpp" #include "player_type.hpp" -#include "quark.hpp" +#include "point.hpp" #include "randart.hpp" #include "skill_type.hpp" #include "skills.hpp" @@ -46,7 +51,6 @@ #include "stats.hpp" #include "store_info_type.hpp" #include "tables.hpp" -#include "trap_type.hpp" #include "util.hpp" #include "util.h" #include "variable.h" @@ -57,14 +61,16 @@ #include "xtra1.hpp" #include "z-rand.hpp" -#include <type_traits> +#include <boost/algorithm/string/predicate.hpp> #include <cassert> +#include <fmt/format.h> +#include <type_traits> + -#include <boost/algorithm/string/predicate.hpp> using boost::algorithm::iequals; -static void corrupt_corrupted(void); +static void corrupt_corrupted(); /* * Set "p_ptr->parasite" and "p_ptr->parasite_r_idx" @@ -129,7 +135,7 @@ bool_ set_parasite(int v, int r) if (!notice) return (FALSE); /* Disturb */ - if (disturb_state) disturb(0); + disturb_on_state(); /* Recalculate bonuses */ p_ptr->update |= (PU_BONUS); @@ -182,8 +188,7 @@ static bool_ set_simple_field( return (FALSE); /* Disturb */ - if (disturb_state) - disturb(0); + disturb_on_state(); /* Recalculate bonuses */ p_ptr->update |= (PU_BONUS); @@ -398,17 +403,6 @@ bool_ set_strike(int v) } /* - * Set "p_ptr->oppose_ld" - */ -bool_ set_oppose_ld(int v) -{ - return set_simple_field( - &p_ptr->oppose_ld, v, - TERM_WHITE, "You feel protected against light's fluctuation.", - TERM_WHITE, "You are no longer protected against light's fluctuation."); -} - -/* * Set "p_ptr->oppose_cc" */ bool_ set_oppose_cc(int v) @@ -420,33 +414,13 @@ bool_ set_oppose_cc(int v) } /* - * Set "p_ptr->oppose_ss" - */ -bool_ set_oppose_ss(int v) -{ - return set_simple_field( - &p_ptr->oppose_ss, v, - TERM_WHITE, "You feel protected against the ravages of sound and shards.", - TERM_WHITE, "You are no longer protected against the ravages of sound and shards."); -} - -/* - * Set "p_ptr->oppose_nex" - */ -bool_ set_oppose_nex(int v) -{ - return set_simple_field( - &p_ptr->oppose_nex, v, - TERM_WHITE, "You feel protected against the strange forces of nexus.", - TERM_WHITE, "You are no longer protected against the strange forces of nexus."); -} - -/* * Set "p_ptr->tim_mimic", and "p_ptr->mimic_form", * notice observable changes */ bool_ set_mimic(int v, int p, int level) { + auto &s_info = game->s_info; + bool_ notice = FALSE; /* Hack -- Force good values */ @@ -473,7 +447,7 @@ bool_ set_mimic(int v, int p, int level) notice = TRUE; if (p == resolve_mimic_name("Bear")) { - s_info[SKILL_BEAR].hidden = TRUE; + s_info[SKILL_BEAR].hidden = true; select_default_melee(); } p = 0; @@ -488,7 +462,7 @@ bool_ set_mimic(int v, int p, int level) if (!notice) return (FALSE); /* Disturb */ - if (disturb_state) disturb(0); + disturb_on_state(); /* Redraw title */ p_ptr->redraw |= (PR_FRAME); @@ -785,7 +759,7 @@ bool_ set_fast(int v, int p) if (!notice) return (FALSE); /* Disturb */ - if (disturb_state) disturb(0); + disturb_on_state(); /* Recalculate bonuses */ p_ptr->update |= (PU_BONUS); @@ -963,45 +937,6 @@ bool_ set_protevil(int v) } /* - * Set "p_ptr->protgood", notice observable changes - */ -bool_ set_protgood(int v) -{ - bool_ notice = set_simple_field( - &p_ptr->protgood, v, - TERM_WHITE, "You feel safe from good!", - TERM_WHITE, "You no longer feel safe from good."); - - if (notice) - { - /* Handle stuff */ - handle_stuff(); - } - - /* Result */ - return notice; -} - -/* - * Set "p_ptr->protundead", notice observable changes - */ -bool_ set_protundead(int v) -{ - bool_ notice = set_simple_field( - &p_ptr->protundead, v, - TERM_WHITE, "You feel safe from undead!", - TERM_WHITE, "You no longer feel safe from undead."); - - if (notice) { - /* Handle stuff */ - handle_stuff(); - } - - /* Result */ - return notice; -} - -/* * Set "p_ptr->set_shadow", notice observable changes */ bool_ set_shadow(int v) @@ -1127,7 +1062,7 @@ bool_ set_tim_thunder(int v, int p1, int p2) if (!notice) return (FALSE); /* Disturb */ - if (disturb_state) disturb(0); + disturb_on_state(); /* Recalculate bonuses */ p_ptr->update |= (PU_BONUS); @@ -1334,7 +1269,7 @@ bool_ set_tim_regen(int v, int p) if (!notice) return (FALSE); /* Disturb */ - if (disturb_state) disturb(0); + disturb_on_state(); /* Handle stuff */ handle_stuff(); @@ -1358,7 +1293,7 @@ bool_ set_stun(int v) /* Hack -- Force good values */ v = (v > 10000) ? 10000 : (v < 0) ? 0 : v; - if (race_flags1_p(PR1_NO_STUN)) v = 0; + if (race_flags_p(PR_NO_STUN)) v = 0; /* Knocked out */ if (p_ptr->stun > 100) @@ -1438,25 +1373,25 @@ bool_ set_stun(int v) { if (!p_ptr->sustain_int) { - (void) do_dec_stat(A_INT, STAT_DEC_NORMAL); + do_dec_stat(A_INT, STAT_DEC_NORMAL); } if (!p_ptr->sustain_wis) { - (void) do_dec_stat(A_WIS, STAT_DEC_NORMAL); + do_dec_stat(A_WIS, STAT_DEC_NORMAL); } } else if (randint(2) == 1) { if (!p_ptr->sustain_int) { - (void) do_dec_stat(A_INT, STAT_DEC_NORMAL); + do_dec_stat(A_INT, STAT_DEC_NORMAL); } } else { if (!p_ptr->sustain_wis) { - (void) do_dec_stat(A_WIS, STAT_DEC_NORMAL); + do_dec_stat(A_WIS, STAT_DEC_NORMAL); } } } @@ -1474,7 +1409,7 @@ bool_ set_stun(int v) /* None */ case 0: msg_print("You are no longer stunned."); - if (disturb_state) disturb(0); + disturb_on_state(); break; } @@ -1489,7 +1424,7 @@ bool_ set_stun(int v) if (!notice) return (FALSE); /* Disturb */ - if (disturb_state) disturb(0); + disturb_on_state(); /* Recalculate bonuses */ p_ptr->update |= (PU_BONUS); @@ -1519,7 +1454,7 @@ bool_ set_cut(int v) /* Hack -- Force good values */ v = (v > 10000) ? 10000 : (v < 0) ? 0 : v; - if (race_flags1_p(PR1_NO_CUT)) v = 0; + if (race_flags_p(PR_NO_CUT)) v = 0; /* Mortal wound */ if (p_ptr->cut > 1000) @@ -1682,7 +1617,7 @@ bool_ set_cut(int v) /* None */ case 0: msg_print("You are no longer bleeding."); - if (disturb_state) disturb(0); + disturb_on_state(); break; } @@ -1697,7 +1632,7 @@ bool_ set_cut(int v) if (!notice) return (FALSE); /* Disturb */ - if (disturb_state) disturb(0); + disturb_on_state(); /* Recalculate bonuses */ p_ptr->update |= (PU_BONUS); @@ -1911,7 +1846,7 @@ bool_ set_food(int v) if (!notice) return (FALSE); /* Disturb */ - if (disturb_state) disturb(0); + disturb_on_state(); /* Recalculate bonuses */ p_ptr->update |= (PU_BONUS); @@ -1930,7 +1865,7 @@ bool_ set_food(int v) /* * Advance experience levels and print experience */ -void check_experience(void) +void check_experience() { int gained = 0; bool_ level_corruption = FALSE; @@ -1982,8 +1917,8 @@ void check_experience(void) /* Gain levels while possible */ - while ((p_ptr->lev < PY_MAX_LEVEL) && (p_ptr->lev < max_plev) && - (p_ptr->exp >= (player_exp[p_ptr->lev - 1] * p_ptr->expfact / 100L))) + while ((p_ptr->lev < PY_MAX_LEVEL) && + (p_ptr->exp >= (player_exp[p_ptr->lev - 1] * p_ptr->expfact / 100L))) { /* Gain a level */ p_ptr->lev++; @@ -1994,16 +1929,13 @@ void check_experience(void) if (p_ptr->lev > p_ptr->max_plv) { p_ptr->max_plv = p_ptr->lev; - if ((race_flags1_p(PR1_CORRUPT)) && + if ((race_flags_p(PR_CORRUPT)) && (randint(3) == 1)) { level_corruption = TRUE; } } - /* Sound */ - sound(SOUND_LEVEL); - /* Message */ cmsg_format(TERM_L_GREEN, "Welcome to level %d.", p_ptr->lev); @@ -2067,7 +1999,7 @@ void check_experience_obj(object_type *o_ptr) /* Gain levels while possible */ while ((o_ptr->elevel < PY_MAX_LEVEL) && - (o_ptr->exp >= (player_exp[o_ptr->elevel - 1] * 5 / 2))) + (o_ptr->exp >= calc_object_need_exp(o_ptr))) { char buf[100]; @@ -2089,7 +2021,7 @@ void check_experience_obj(object_type *o_ptr) */ void gain_exp(s32b amount) { - if ((p_ptr->max_exp > 0) && (race_flags1_p(PR1_CORRUPT))) + if ((p_ptr->max_exp > 0) && (race_flags_p(PR_CORRUPT))) { if ((randint(p_ptr->max_exp) < amount) || (randint(12000000) < amount)) { @@ -2181,13 +2113,13 @@ void place_corpse(monster_type *m_ptr) auto const r_ptr = m_ptr->race(); /* It has a physical form */ - if (r_ptr->flags9 & RF9_DROP_CORPSE) + if (r_ptr->flags & RF_DROP_CORPSE) { /* Wipe the object */ object_prep(i_ptr, lookup_kind(TV_CORPSE, SV_CORPSE_CORPSE)); /* Unique corpses are unique */ - if (r_ptr->flags1 & RF1_UNIQUE) + if (r_ptr->flags & RF_UNIQUE) { object_aware(i_ptr); i_ptr->name1 = 201; @@ -2217,13 +2149,13 @@ void place_corpse(monster_type *m_ptr) } /* The creature is an animated skeleton. */ - if (!(r_ptr->flags9 & RF9_DROP_CORPSE) && (r_ptr->flags9 & RF9_DROP_SKELETON)) + if (!(r_ptr->flags & RF_DROP_CORPSE) && (r_ptr->flags & RF_DROP_SKELETON)) { /* Wipe the object */ object_prep(i_ptr, lookup_kind(TV_CORPSE, SV_CORPSE_SKELETON)); /* Unique corpses are unique */ - if (r_ptr->flags1 & RF1_UNIQUE) + if (r_ptr->flags & RF_UNIQUE) { object_aware(i_ptr); i_ptr->name1 = 201; @@ -2469,15 +2401,14 @@ static void monster_death_gods(int m_idx, monster_type *m_ptr) */ void monster_death(int m_idx) { - int dump_item = 0; - int dump_gold = 0; + auto const &d_info = game->edit_data.d_info; + auto const &f_info = game->edit_data.f_info; + auto &a_info = game->edit_data.a_info; monster_type *m_ptr = &m_list[m_idx]; auto const r_ptr = m_ptr->race(); - bool_ visible = (m_ptr->ml || (r_ptr->flags1 & (RF1_UNIQUE))); - bool_ create_stairs = FALSE; int force_coin = get_coin_type(r_ptr); @@ -2524,7 +2455,7 @@ void monster_death(int m_idx) } /* If the doppleganger die, the variable must be set accordingly */ - if (r_ptr->flags9 & RF9_DOPPLEGANGER) doppleganger = 0; + if (r_ptr->flags & RF_DOPPLEGANGER) doppleganger = 0; /* Need copy of object list since we're going to mutate it */ auto const object_idxs(m_ptr->hold_o_idxs); @@ -2547,9 +2478,6 @@ void monster_death(int m_idx) /* Delete the object */ delete_object_idx(this_o_idx); - if (q_ptr->tval == TV_GOLD) dump_gold++; - else dump_item++; - /* Drop it */ drop_near(q_ptr, -1, y, x); } @@ -2571,31 +2499,41 @@ void monster_death(int m_idx) /* Mega-Hack -- Name the sword */ - q_ptr->art_name = quark_add("'Stormbringer'"); + q_ptr->artifact_name = "'Stormbringer'"; q_ptr->to_h = 16; q_ptr->to_d = 16; q_ptr->ds = 6; q_ptr->dd = 6; q_ptr->pval = 2; - q_ptr->art_flags1 |= ( TR1_VAMPIRIC | TR1_STR | TR1_CON | TR1_BLOWS ); - q_ptr->art_flags2 |= ( TR2_FREE_ACT | TR2_HOLD_LIFE | - TR2_RES_NEXUS | TR2_RES_CHAOS | TR2_RES_NETHER | - TR2_RES_CONF ); /* No longer resist_disen */ - q_ptr->art_flags3 |= ( TR3_IGNORE_ACID | TR3_IGNORE_ELEC | - TR3_IGNORE_FIRE | TR3_IGNORE_COLD); - /* Just to be sure */ - - q_ptr->art_flags3 |= TR3_NO_TELE; /* How's that for a downside? */ + q_ptr->art_flags |= + TR_VAMPIRIC | + TR_STR | + TR_CON | + TR_BLOWS | + TR_FREE_ACT | + TR_HOLD_LIFE | + TR_RES_NEXUS | + TR_RES_CHAOS | + TR_RES_NETHER | + TR_RES_CONF | + TR_IGNORE_ACID | + TR_IGNORE_ELEC | + TR_IGNORE_FIRE | + TR_IGNORE_COLD | + TR_NO_TELE | + TR_CURSED | + TR_HEAVY_CURSE; - /* For game balance... */ - q_ptr->art_flags3 |= (TR3_CURSED | TR3_HEAVY_CURSE); q_ptr->ident |= IDENT_CURSED; - if (randint(2) == 1) - q_ptr->art_flags3 |= (TR3_DRAIN_EXP); + { + q_ptr->art_flags |= TR_DRAIN_EXP; + } else - q_ptr->art_flags3 |= (TR3_AGGRAVATE); + { + q_ptr->art_flags |= TR_AGGRAVATE; + } q_ptr->found = OBJ_FOUND_MONSTER; q_ptr->found_aux1 = m_ptr->r_idx; @@ -2650,7 +2588,7 @@ void monster_death(int m_idx) else if (strstr(r_ptr->name, "Unmaker")) { int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL; - (void)project(m_idx, 6, y, x, 100, GF_CHAOS, flg); + project(m_idx, 6, y, x, 100, GF_CHAOS, flg); } /* Pink horrors are replaced with 2 Blue horrors */ else if (strstr(r_ptr->name, "ink horror")) @@ -2678,7 +2616,7 @@ void monster_death(int m_idx) } /* Mega-Hack -- drop "winner" treasures */ - else if (r_ptr->flags1 & (RF1_DROP_CHOSEN)) + else if (r_ptr->flags & RF_DROP_CHOSEN) { if (strstr(r_ptr->name, "Morgoth, Lord of Darkness")) { @@ -2740,7 +2678,7 @@ void monster_death(int m_idx) /* Drop it in the dungeon */ drop_near(q_ptr, -1, y, x); } - else if (r_ptr->flags7 & RF7_NAZGUL) + else if (r_ptr->flags & RF_NAZGUL) { /* Get local object */ q_ptr = &forge; @@ -2757,7 +2695,7 @@ void monster_death(int m_idx) create_artifact(q_ptr, TRUE, FALSE); /* Save the inscription */ - q_ptr->art_name = quark_add(format("of %s", r_ptr->name)); + q_ptr->artifact_name = fmt::format("of {}", r_ptr->name); q_ptr->found = OBJ_FOUND_MONSTER; q_ptr->found_aux1 = m_ptr->r_idx; @@ -2770,46 +2708,14 @@ void monster_death(int m_idx) } else { - byte a_idx = 0; - int chance = 0; - int I_kind = 0; - - if (strstr(r_ptr->name, "Marda, rider of the Gold Laronth")) - { - a_idx = ART_MARDA; - chance = 50; - } - else if (strstr(r_ptr->name, "Saruman of Many Colours")) - { - a_idx = ART_PALANTIR; - chance = 30; - } - else if (strstr(r_ptr->name, "Hagen, son of Alberich")) - { - a_idx = ART_NIMLOTH; - chance = 66; - } - else if (strstr(r_ptr->name, "Durin's Bane")) - { - a_idx = ART_CALRIS; - chance = 60; - } - else if (strstr(r_ptr->name, "Gothmog, the High Captain of Balrogs")) - { - a_idx = ART_GOTHMOG; - chance = 50; - } - else if (strstr(r_ptr->name, "Eol, the Dark Elf")) - { - a_idx = ART_ANGUIREL; - chance = 50; - } + byte a_idx = r_ptr->artifact_idx; + int chance = r_ptr->artifact_chance; if ((a_idx > 0) && ((randint(99) < chance) || (wizard))) { if (a_info[a_idx].cur_num == 0) { - artifact_type *a_ptr = &a_info[a_idx]; + auto a_ptr = &a_info[a_idx]; /* Get local object */ q_ptr = &forge; @@ -2818,7 +2724,7 @@ void monster_death(int m_idx) object_wipe(q_ptr); /* Acquire the "kind" index */ - I_kind = lookup_kind(a_ptr->tval, a_ptr->sval); + int I_kind = lookup_kind(a_ptr->tval, a_ptr->sval); /* Create the artifact */ object_prep(q_ptr, I_kind); @@ -2837,7 +2743,7 @@ void monster_death(int m_idx) q_ptr->weight = a_ptr->weight; /* Hack -- acquire "cursed" flag */ - if (a_ptr->flags3 & (TR3_CURSED)) q_ptr->ident |= (IDENT_CURSED); + if (a_ptr->flags & TR_CURSED) q_ptr->ident |= (IDENT_CURSED); random_artifact_resistance(q_ptr); @@ -2857,7 +2763,7 @@ void monster_death(int m_idx) } /* Hack - the protected monsters must be advanged */ - else if (r_ptr->flags9 & RF9_WYRM_PROTECT) + else if (r_ptr->flags & RF_WYRM_PROTECT) { int xx = x, yy = y; int attempts = 100; @@ -2995,13 +2901,6 @@ void monster_death(int m_idx) if ((!force_coin) && (magik(10 + get_skill_scale(SKILL_PRESERVATION, 75))) && (!(m_ptr->mflag & MFLAG_NO_DROP))) place_corpse(m_ptr); - /* Take note of any dropped treasure */ - if (visible && (dump_item || dump_gold)) - { - /* Take notes on treasure */ - lore_treasure(m_idx, dump_item, dump_gold); - } - /* Create a magical staircase */ if (create_stairs && (dun_level < d_info[dungeon_type].maxdepth)) { @@ -3009,7 +2908,7 @@ void monster_death(int m_idx) { for (int j = -1; j <= 1; j++) { - if (!(f_info[cave[y + j][x + i].feat].flags1 & FF1_PERMANENT)) + if (!(f_info[cave[y + j][x + i].feat].flags & FF_PERMANENT)) { cave_set_feat(y + j, x + i, d_info[dungeon_type].floor1); } @@ -3082,7 +2981,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); /* Some mosnters are immune to death */ - if (r_ptr->flags7 & RF7_NO_DEATH) return FALSE; + if (r_ptr->flags & RF_NO_DEATH) return FALSE; /* Wake it up */ m_ptr->csleep = 0; @@ -3106,7 +3005,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) /* Extract monster name */ monster_desc(m_name, m_ptr, 0); - if ((r_ptr->flags7 & RF7_DG_CURSE) && (randint(2) == 1)) + if ((r_ptr->flags & RF_DG_CURSE) && (randint(2) == 1)) { int curses = 2 + randint(5); @@ -3120,7 +3019,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) while (--curses); } - if (r_ptr->flags2 & (RF2_CAN_SPEAK)) + if (r_ptr->flags & RF_CAN_SPEAK) { char line_got[80]; /* Dump a message */ @@ -3129,10 +3028,6 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) msg_format("%^s says: %s", m_name, line_got); } - - /* Make a sound */ - sound(SOUND_KILL); - /* Death by Missile/Spell attack */ if (note) { @@ -3146,10 +3041,10 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) } /* Death by Physical attack -- non-living monster */ - else if ((r_ptr->flags3 & (RF3_DEMON)) || - (r_ptr->flags3 & (RF3_UNDEAD)) || - (r_ptr->flags2 & (RF2_STUPID)) || - (r_ptr->flags3 & (RF3_NONLIVING)) || + else if ((r_ptr->flags & RF_DEMON) || + (r_ptr->flags & RF_UNDEAD) || + (r_ptr->flags & RF_STUPID) || + (r_ptr->flags & RF_NONLIVING) || (strchr("Evg", r_ptr->d_char))) { cmsg_format(TERM_L_RED, "You have destroyed %s.", m_name); @@ -3190,15 +3085,12 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) if (!note) { - object_type *o_ptr; - u32b f1, f2, f3, f4, f5, esp; - /* Access the weapon */ - o_ptr = &p_ptr->inventory[INVEN_WIELD]; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + object_type *o_ptr = &p_ptr->inventory[INVEN_WIELD]; + auto const flags = object_flags(o_ptr); /* Can the weapon gain levels ? */ - if ((o_ptr->k_idx) && (f4 & TR4_LEVELS)) + if ((o_ptr->k_idx) && (flags & TR_LEVELS)) { /* Give some experience for the kill */ const int new_exp = ((long)r_ptr->mexp * m_ptr->level) / (div * 2); @@ -3210,7 +3102,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) } /* When the player kills a Unique, it stays dead */ - if (r_ptr->flags1 & (RF1_UNIQUE)) + if (r_ptr->flags & RF_UNIQUE) { r_ptr->max_num = 0; } @@ -3219,7 +3111,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) monster_death(m_idx); /* Eru doesn't appreciate good monster death */ - if (r_ptr->flags3 & RF3_GOOD) + if (r_ptr->flags & RF_GOOD) { inc_piety(GOD_ERU, -7 * m_ptr->level); inc_piety(GOD_MANWE, -10 * m_ptr->level); @@ -3231,7 +3123,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) } /* Manwe appreciate evil monster death */ - if (r_ptr->flags3 & RF3_EVIL) + if (r_ptr->flags & RF_EVIL) { int inc = std::max(1, m_ptr->level / 2); @@ -3247,7 +3139,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) if (praying_to(GOD_TULKAS)) { inc_piety(GOD_TULKAS, inc / 2); - if (r_ptr->flags3 & RF3_DEMON) + if (r_ptr->flags & RF_DEMON) { inc_piety(GOD_TULKAS, inc); } @@ -3255,7 +3147,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) } /* Yavanna likes when corruption is destroyed */ - if ((r_ptr->flags3 & RF3_NONLIVING) || (r_ptr->flags3 & RF3_DEMON) || (r_ptr->flags3 & RF3_UNDEAD)) + if ((r_ptr->flags & RF_NONLIVING) || (r_ptr->flags & RF_DEMON) || (r_ptr->flags & RF_UNDEAD)) { int inc = std::max(1, m_ptr->level / 2); inc_piety(GOD_YAVANNA, inc); @@ -3268,12 +3160,12 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) inc_piety(GOD_YAVANNA, -inc); /* Killing animals in her name is a VERY bad idea */ - if (r_ptr->flags3 & RF3_ANIMAL) + if (r_ptr->flags & RF_ANIMAL) inc_piety(GOD_YAVANNA, -(inc * 3)); } /* SHould we absorb its soul? */ - if (p_ptr->absorb_soul && (!(r_ptr->flags3 & RF3_UNDEAD)) && (!(r_ptr->flags3 & RF3_NONLIVING))) + if (p_ptr->absorb_soul && (!(r_ptr->flags & RF_UNDEAD)) && (!(r_ptr->flags & RF_NONLIVING))) { msg_print("You absorb the life of the dying soul."); hp_player(1 + (m_ptr->level / 2) + get_skill_scale(SKILL_NECROMANCY, 40)); @@ -3283,7 +3175,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) * XXX XXX XXX Mega-Hack -- Remove random quest rendered * impossible */ - if (r_ptr->flags1 & (RF1_UNIQUE)) + if (r_ptr->flags & RF_UNIQUE) { int i; @@ -3311,7 +3203,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) } /* Make note of unique kills */ - if (r_ptr->flags1 & RF1_UNIQUE) + if (r_ptr->flags & RF_UNIQUE) { char note[80]; @@ -3322,14 +3214,11 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) } /* Recall even invisible uniques or winners */ - if (m_ptr->ml || (r_ptr->flags1 & (RF1_UNIQUE))) + if (m_ptr->ml || (r_ptr->flags & RF_UNIQUE)) { /* Count kills this life */ if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++; - /* Count kills in all lives */ - if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++; - /* Hack -- Auto-recall */ monster_race_track(m_ptr->r_idx, m_ptr->ego); } @@ -3366,7 +3255,7 @@ void get_screen_size(int *wid_p, int *hgt_p) * Calculates current boundaries * Called below. */ -static void panel_bounds(void) +static void panel_bounds() { int wid, hgt; @@ -3449,7 +3338,7 @@ bool_ change_panel(int dy, int dx) * * The map is reprinted if necessary, and "TRUE" is returned. */ -void verify_panel(void) +void verify_panel() { int y = p_ptr->py; int x = p_ptr->px; @@ -3488,7 +3377,7 @@ void verify_panel(void) if (max_pcol_min < 0) max_pcol_min = 0; /* An option: center on player */ - if (center_player) + if (options->center_player) { /* Center vertically */ prow_min = y - panel_hgt; @@ -3562,7 +3451,10 @@ void verify_panel(void) panel_col_min = pcol_min; /* Hack -- optional disturb on "panel change" */ - if (disturb_panel && !center_player) disturb(0); + if (options->disturb_panel && !options->center_player) + { + disturb(); + } /* Recalculate the boundaries */ panel_bounds(); @@ -3581,7 +3473,7 @@ void verify_panel(void) /* * Map resizing whenever the main term changes size */ -void resize_map(void) +void resize_map() { /* Only if the dungeon exists */ if (!character_dungeon) return; @@ -3630,7 +3522,7 @@ void resize_map(void) /* * Redraw a term when it is resized */ -void resize_window(void) +void resize_window() { /* Only if the dungeon exists */ if (!character_dungeon) return; @@ -3669,9 +3561,9 @@ static cptr look_mon_desc(int m_idx) /* Determine if the monster is "living" (vs "undead") */ monster_type *m_ptr = &m_list[m_idx]; auto const r_ptr = m_ptr->race(); - if (r_ptr->flags3 & (RF3_UNDEAD)) living = FALSE; - if (r_ptr->flags3 & (RF3_DEMON)) living = FALSE; - if (r_ptr->flags3 & (RF3_NONLIVING)) living = FALSE; + if (r_ptr->flags & RF_UNDEAD) living = FALSE; + if (r_ptr->flags & RF_DEMON) living = FALSE; + if (r_ptr->flags & RF_NONLIVING) living = FALSE; if (strchr("Egv", r_ptr->d_char)) living = FALSE; @@ -3706,81 +3598,6 @@ static cptr look_mon_desc(int m_idx) -/* - * Current "comp" function for ang_sort() - */ -static bool_ (*ang_sort_comp)(vptr u, vptr v, int a, int b) = nullptr; - -/* - * Current "swap" function for ang_sort() - */ -static void (*ang_sort_swap)(vptr u, vptr v, int a, int b) = nullptr; - - - -/* - * Angband sorting algorithm -- quick sort in place - * - * Note that the details of the data we are sorting is hidden, - * and we rely on the "ang_sort_comp()" and "ang_sort_swap()" - * function hooks to interact with the data, which is given as - * two pointers, and which may have any user-defined form. - */ -static void ang_sort_aux(vptr u, vptr v, int p, int q) -{ - int z, a, b; - - /* Done sort */ - if (p >= q) return; - - /* Pivot */ - z = p; - - /* Begin */ - a = p; - b = q; - - /* Partition */ - while (TRUE) - { - /* Slide i2 */ - while (!(*ang_sort_comp)(u, v, b, z)) b--; - - /* Slide i1 */ - while (!(*ang_sort_comp)(u, v, z, a)) a++; - - /* Done partition */ - if (a >= b) break; - - /* Swap */ - (*ang_sort_swap)(u, v, a, b); - - /* Advance */ - a++, b--; - } - - /* Recurse left side */ - ang_sort_aux(u, v, p, b); - - /* Recurse right side */ - ang_sort_aux(u, v, b + 1, q); -} - - -/* - * Angband sorting algorithm -- quick sort in place - * - * Note that the details of the data we are sorting is hidden, - * and we rely on the "ang_sort_comp()" and "ang_sort_swap()" - * function hooks to interact with the data, which is given as - * two pointers, and which may have any user-defined form. - */ -static void ang_sort(vptr u, vptr v, int n) -{ - /* Sort the array */ - ang_sort_aux(u, v, 0, n - 1); -} - /*** Targetting Code ***/ @@ -3802,6 +3619,8 @@ static void ang_sort(vptr u, vptr v, int n) */ static bool target_able(int m_idx) { + auto const &r_info = game->edit_data.r_info; + monster_type *m_ptr = &m_list[m_idx]; /* Monster must be alive */ @@ -3820,7 +3639,7 @@ static bool target_able(int m_idx) if (is_friend(m_ptr) > 0) return (FALSE); /* Honor flag */ - if (r_info[m_ptr->r_idx].flags7 & RF7_NO_TARGET) return (FALSE); + if (r_info[m_ptr->r_idx].flags & RF_NO_TARGET) return (FALSE); /* XXX XXX XXX Hack -- Never target trappers */ /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */ @@ -3837,7 +3656,7 @@ static bool target_able(int m_idx) * * We return TRUE if the target is "okay" and FALSE otherwise. */ -bool_ target_okay(void) +bool_ target_okay() { /* Accept stationary targets */ if (target_who < 0) return (TRUE); @@ -3866,108 +3685,37 @@ bool_ target_okay(void) /* - * Sorting hook -- comp function -- by "distance to player" - * - * We use "u" and "v" to point to arrays of "x" and "y" positions, - * and sort the arrays by double-distance to the player. - */ -static bool_ ang_sort_comp_distance(vptr u, vptr v, int a, int b) -{ - byte *x = (byte*)(u); - byte *y = (byte*)(v); - - int da, db, kx, ky; - - /* Absolute distance components */ - kx = x[a]; - kx -= p_ptr->px; - kx = ABS(kx); - ky = y[a]; - ky -= p_ptr->py; - ky = ABS(ky); - - /* Approximate Double Distance to the first point */ - da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx)); - - /* Absolute distance components */ - kx = x[b]; - kx -= p_ptr->px; - kx = ABS(kx); - ky = y[b]; - ky -= p_ptr->py; - ky = ABS(ky); - - /* Approximate Double Distance to the first point */ - db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx)); - - /* Compare the distances */ - return (da <= db); -} - - -/* - * Sorting hook -- swap function -- by "distance to player" - * - * We use "u" and "v" to point to arrays of "x" and "y" positions, - * and sort the arrays by distance to the player. - */ -static void ang_sort_swap_distance(vptr u, vptr v, int a, int b) -{ - byte *x = (byte*)(u); - byte *y = (byte*)(v); - - byte temp; - - /* Swap "x" */ - temp = x[a]; - x[a] = x[b]; - x[b] = temp; - - /* Swap "y" */ - temp = y[a]; - y[a] = y[b]; - y[b] = temp; -} - - - -/* * Hack -- help "select" a location (see below) */ -static s16b target_pick(int y1, int x1, int dy, int dx) +static s16b target_pick(point p, int dy, int dx, std::vector<point> const &points) { - int i, v; - - int x2, y2, x3, y3, x4, y4; - int b_i = -1, b_v = 9999; - /* Scan the locations */ - for (i = 0; i < temp_n; i++) + for (std::size_t i = 0; i < points.size(); i++) { /* Point 2 */ - x2 = temp_x[i]; - y2 = temp_y[i]; + int x2 = points[i].x(); + int y2 = points[i].y(); /* Directed distance */ - x3 = (x2 - x1); - y3 = (y2 - y1); + int x3 = (x2 - p.x()); + int y3 = (y2 - p.y()); /* Verify quadrant */ if (dx && (x3 * dx <= 0)) continue; if (dy && (y3 * dy <= 0)) continue; /* Absolute distance */ - x4 = ABS(x3); - y4 = ABS(y3); + int x4 = ABS(x3); + int y4 = ABS(y3); /* Verify quadrant */ if (dy && !dx && (x4 > y4)) continue; if (dx && !dy && (y4 > x4)) continue; /* Approximate Double Distance */ - v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4)); + int v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4)); /* XXX XXX XXX Penalize location */ @@ -3989,6 +3737,9 @@ static s16b target_pick(int y1, int x1, int dy, int dx) */ static bool_ target_set_accept(int y, int x) { + auto const &r_info = game->edit_data.r_info; + auto const &f_info = game->edit_data.f_info; + /* Player grid is always interesting */ if ((y == p_ptr->py) && (x == p_ptr->px)) return (TRUE); @@ -4001,7 +3752,7 @@ static bool_ target_set_accept(int y, int x) cave_type *c_ptr = &cave[y][x]; /* Visible monsters */ - if (c_ptr->m_idx && c_ptr->m_idx < max_r_idx) + if (c_ptr->m_idx && c_ptr->m_idx < static_cast<int>(r_info.size())) { monster_type *m_ptr = &m_list[c_ptr->m_idx]; @@ -4025,9 +3776,6 @@ static bool_ target_set_accept(int y, int x) /* Interesting memorized features */ if (c_ptr->info & (CAVE_MARK)) { - /* Traps are interesting */ - if (c_ptr->info & (CAVE_TRDT)) return (TRUE); - /* Hack -- Doors are boring */ if (c_ptr->feat == FEAT_OPEN) return (FALSE); if (c_ptr->feat == FEAT_BROKEN) return (FALSE); @@ -4035,7 +3783,7 @@ static bool_ target_set_accept(int y, int x) (c_ptr->feat <= FEAT_DOOR_TAIL)) return (FALSE); /* Accept 'naturally' interesting features */ - if (f_info[c_ptr->feat].flags1 & FF1_NOTICE) return (TRUE); + if (f_info[c_ptr->feat].flags & FF_NOTICE) return (TRUE); } /* Nope */ @@ -4048,39 +3796,42 @@ static bool_ target_set_accept(int y, int x) * * Return the number of target_able monsters in the set. */ -static void target_set_prepare(int mode) +static std::vector<point> target_set_prepare(int mode) { - int y, x; + std::vector<point> points; - /* Reset "temp" array */ - temp_n = 0; - - /* Scan the current panel */ - for (y = panel_row_min; y <= panel_row_max; y++) + // Scan the current panel + for (int y = panel_row_min; y <= panel_row_max; y++) { - for (x = panel_col_min; x <= panel_col_max; x++) + for (int x = panel_col_min; x <= panel_col_max; x++) { cave_type *c_ptr = &cave[y][x]; - /* Require "interesting" contents */ + // Require "interesting" contents if (!target_set_accept(y, x)) continue; - /* Require target_able monsters for "TARGET_KILL" */ + // Require target_able monsters for "TARGET_KILL" if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue; - /* Save the location */ - temp_x[temp_n] = x; - temp_y[temp_n] = y; - temp_n++; + // Save the location + points.push_back(point(x,y)); } } - /* Set the sort hooks */ - ang_sort_comp = ang_sort_comp_distance; - ang_sort_swap = ang_sort_swap_distance; + // Sort the points by distance to player; we'll + // use a stable sort to avoid equidistant targets + // "swapping" priorities. + std::stable_sort( + std::begin(points), + std::end(points), + [](point i, point j) -> bool { + auto di = distance(p_ptr->py, p_ptr->px, i.y(), i.x()); + auto dj = distance(p_ptr->py, p_ptr->px, j.y(), j.x()); + return di < dj; + } + ); - /* Sort the positions */ - ang_sort(temp_x, temp_y, temp_n); + return points; } @@ -4142,6 +3893,12 @@ bool_ target_object(int y, int x, int mode, cptr info, bool_ *boring, */ static int target_set_aux(int y, int x, int mode, cptr info) { + auto const &d_info = game->edit_data.d_info; + auto const &st_info = game->edit_data.st_info; + auto const &wf_info = game->edit_data.wf_info; + auto const &f_info = game->edit_data.f_info; + auto const &k_info = game->edit_data.k_info; + cave_type *c_ptr = &cave[y][x]; cptr s1, s2, s3; @@ -4206,7 +3963,7 @@ static int target_set_aux(int y, int x, int mode, cptr info) auto const r_ptr = m_ptr->race(); /* Mimics special treatment -- looks like an object */ - if ((r_ptr->flags9 & RF9_MIMIC) && (m_ptr->csleep)) + if ((r_ptr->flags & RF_MIMIC) && (m_ptr->csleep)) { /* Acquire object */ object_type *o_ptr = &o_list[m_ptr->mimic_o_idx()]; @@ -4254,7 +4011,7 @@ static int target_set_aux(int y, int x, int mode, cptr info) Term_save(); /* Recall on screen */ - screen_roff(m_ptr->r_idx, m_ptr->ego, 0); + screen_roff(m_ptr->r_idx, m_ptr->ego); /* Hack -- Complete the prompt (again) */ Term_addstr( -1, TERM_WHITE, format(" [r,%s]", info)); @@ -4329,8 +4086,8 @@ static int target_set_aux(int y, int x, int mode, cptr info) s1 = "It is "; /* Hack -- take account of gender */ - if (r_ptr->flags1 & (RF1_FEMALE)) s1 = "She is "; - else if (r_ptr->flags1 & (RF1_MALE)) s1 = "He is "; + if (r_ptr->flags & RF_FEMALE) s1 = "She is "; + else if (r_ptr->flags & RF_MALE) s1 = "He is "; /* Use a preposition */ s2 = "carrying "; @@ -4404,34 +4161,6 @@ static int target_set_aux(int y, int x, int mode, cptr info) } } - /* Actual traps */ - if ((c_ptr->info & (CAVE_TRDT)) && c_ptr->t_idx) - { - cptr name = "a trap", s4; - - /* Name trap */ - if (t_info[c_ptr->t_idx].ident) - { - s4 = format("(%s)", t_info[c_ptr->t_idx].name); - } - else - { - s4 = "an unknown trap"; - } - - /* Display a message */ - sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, s4); - prt(out_val, 0, 0); - move_cursor_relative(y, x); - query = inkey(); - - /* Stop on everything but "return" */ - if ((query != '\r') && (query != '\n')) break; - - /* Repeat forever */ - continue; - } - /* Feature (apply "mimic") */ if (c_ptr->mimic) { @@ -4452,7 +4181,7 @@ static int target_set_aux(int y, int x, int mode, cptr info) /* Terrain feature if needed */ if (boring || (feat >= FEAT_GLYPH)) { - cptr name; + std::string name; /* Hack -- special handling for building doors */ if (feat == FEAT_SHOP) @@ -4494,10 +4223,11 @@ static int target_set_aux(int y, int x, int mode, cptr info) if (p_ptr->wild_mode && (feat == FEAT_TOWN)) { + auto const &wilderness = game->wilderness; + auto const &wf = wf_info[wilderness(x, y).feat]; + s3 = ""; - name = format("%s(%s)", - wf_info[wild_map[y][x].feat].name, - wf_info[wild_map[y][x].feat].text); + name = fmt::format("{}({})", wf.name, wf.text); } if ((feat == FEAT_FOUNTAIN) && (c_ptr->info & CAVE_IDNT)) @@ -4521,12 +4251,12 @@ static int target_set_aux(int y, int x, int mode, cptr info) /* Display a message */ if (!wizard) { - sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info); + sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name.c_str(), info); } else { sprintf(out_val, "%s%s%s%s [%s] (%d:%d:%d)", - s1, s2, s3, name, info, + s1, s2, s3, name.c_str(), info, c_ptr->feat, c_ptr->mimic, c_ptr->special); } prt(out_val, 0, 0); @@ -4603,8 +4333,6 @@ bool_ target_set(int mode) char info[80]; - cave_type *c_ptr; - int screen_wid, screen_hgt; int panel_wid, panel_hgt; @@ -4624,7 +4352,7 @@ bool_ target_set(int mode) /* Prepare the "temp" array */ - target_set_prepare(mode); + std::vector<point> points = target_set_prepare(mode); /* Start near the player */ m = 0; @@ -4633,13 +4361,13 @@ bool_ target_set(int mode) while (!done) { /* Interesting grids */ - if (flag && temp_n) + if (flag && points.size()) { - y = temp_y[m]; - x = temp_x[m]; + y = points[m].y(); + x = points[m].x(); /* Access */ - c_ptr = &cave[y][x]; + cave_type *c_ptr = &cave[y][x]; /* Allow target */ if (target_able(c_ptr->m_idx)) @@ -4696,7 +4424,7 @@ bool_ target_set(int mode) case '*': case '+': { - if (++m == temp_n) + if (++m == points.size()) { m = 0; } @@ -4707,7 +4435,7 @@ bool_ target_set(int mode) { if (m-- == 0) { - m = temp_n - 1; + m = points.size() - 1; } break; } @@ -4763,7 +4491,7 @@ bool_ target_set(int mode) if (d) { /* Find a new monster */ - i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]); + i = target_pick(points[m], ddy[d], ddx[d], points); /* Scroll to find interesting grid */ if (i < 0) @@ -4777,14 +4505,13 @@ bool_ target_set(int mode) /* Note panel change */ if (change_panel(dy, dx)) { - int ty = temp_y[m]; - int tx = temp_x[m]; + auto const t = points[m]; /* Recalculate interesting grids */ target_set_prepare(mode); /* Find a new monster */ - i = target_pick(ty, tx, dy, dx); + i = target_pick(t, dy, dx, points); /* Restore panel if needed */ if (i < 0) @@ -4806,9 +4533,6 @@ bool_ target_set(int mode) /* Arbitrary grids */ else { - /* Access */ - c_ptr = &cave[y][x]; - /* Default prompt */ strcpy(info, "q,t,p,m,+,-,'dir'"); @@ -4936,9 +4660,6 @@ bool_ target_set(int mode) } } - /* Forget */ - temp_n = 0; - /* Clear the top line */ prt("", 0, 0); @@ -5003,7 +4724,10 @@ bool_ get_aim_dir(int *dp) dir = command_dir; /* Hack -- auto-target if requested */ - if (use_old_target && target_okay()) dir = 5; + if (options->use_old_target && target_okay()) + { + dir = 5; + } /* Ask until satisfied */ while (!dir) @@ -5250,19 +4974,22 @@ void set_grace(s32b v) static bool_ test_object_wish(char *name, object_type *o_ptr, object_type *forge, const char *what) { - int i, j, jb, save_aware; + auto &k_info = game->edit_data.k_info; + auto const &e_info = game->edit_data.e_info; + + int save_aware; char buf[200]; /* try all objects, this *IS* a very ugly and slow method :( */ - for (i = 0; i < max_k_idx; i++) + for (std::size_t i = 0; i < k_info.size(); i++) { - object_kind *k_ptr = &k_info[i]; + auto k_ptr = &k_info[i]; o_ptr = forge; if (!k_ptr->name) continue; - if (k_ptr->flags3 & TR3_NORM_ART) continue; - if (k_ptr->flags3 & TR3_INSTA_ART) continue; + if (k_ptr->flags & TR_NORM_ART) continue; + if (k_ptr->flags & TR_INSTA_ART) continue; if (k_ptr->tval == TV_GOLD) continue; object_prep(o_ptr, i); @@ -5282,9 +5009,9 @@ static bool_ test_object_wish(char *name, object_type *o_ptr, object_type *forge (o_ptr->tval == TV_ROD_MAIN && strstr(name, "rod of"))) { /* try all ego */ - for (j = max_e_idx - 1; j >= 0; j--) + for (std::size_t j = 0; j < e_info.size(); j++) { - ego_item_type *e_ptr = &e_info[j]; + auto e_ptr = &e_info[j]; bool_ ok = FALSE; if (j && !e_ptr->name) continue; @@ -5310,9 +5037,9 @@ static bool_ test_object_wish(char *name, object_type *o_ptr, object_type *forge } /* try all ego */ - for (jb = max_e_idx - 1; jb >= 0; jb--) + for (std::size_t jb = 0; jb < e_info.size(); jb++) { - ego_item_type *eb_ptr = &e_info[jb]; + auto eb_ptr = &e_info[jb]; bool_ ok = FALSE; if (jb && !eb_ptr->name) continue; @@ -5403,13 +5130,17 @@ static void clean_wish_name(char *buf, char *name) /* * Allow the player to make a wish */ -void make_wish(void) +void make_wish() { - char buf[200], name[200], *mname; - int i, j, mstatus = MSTATUS_ENEMY; + auto const &re_info = game->edit_data.re_info; + auto const &r_info = game->edit_data.r_info; + + char name[200], *mname; + int mstatus = MSTATUS_ENEMY; object_type forge, *o_ptr = &forge; /* Make an empty string */ + char buf[200]; buf[0] = 0; /* Ask for the wish */ @@ -5461,16 +5192,20 @@ void make_wish(void) else mstatus = MSTATUS_PET; mname = name + 10; } - else mname = name; - for (i = 1; i < max_r_idx; i++) + else + { + mname = name; + } + + for (std::size_t i = 1; i < r_info.size(); i++) { - monster_race *r_ptr = &r_info[i]; + auto r_ptr = &r_info[i]; if (!r_ptr->name) continue; - if (r_ptr->flags9 & RF9_SPECIAL_GENE) continue; - if (r_ptr->flags9 & RF9_NEVER_GENE) continue; - if (r_ptr->flags1 & RF1_UNIQUE) continue; + if (r_ptr->flags & RF_SPECIAL_GENE) continue; + if (r_ptr->flags & RF_NEVER_GENE) continue; + if (r_ptr->flags & RF_UNIQUE) continue; sprintf(buf, "%s", r_ptr->name); strlower(buf); @@ -5478,9 +5213,9 @@ void make_wish(void) if (strstr(mname, buf)) { /* try all ego */ - for (j = max_re_idx - 1; j >= 0; j--) + for (std::size_t j = 0; j < re_info.size(); j++) { - monster_ego *re_ptr = &re_info[j]; + auto re_ptr = &re_info[j]; if (j && !re_ptr->name) continue; @@ -5501,6 +5236,7 @@ void make_wish(void) { sprintf(buf, "%s", r_ptr->name); } + strlower(buf); if (iequals(mname, buf)) @@ -5516,7 +5252,9 @@ void make_wish(void) /* Create the monster */ if (place_monster_one(wy, wx, i, j, FALSE, mstatus)) + { msg_print("Your wish becomes truth!"); + } /* Don't search any more */ return; @@ -5531,7 +5269,7 @@ void make_wish(void) * Corrupted have a 1/3 chance of losing a mutation each time this is called, * assuming they have any in the first place */ -static void corrupt_corrupted(void) +static void corrupt_corrupted() { if (magik(45)) { @@ -5549,66 +5287,37 @@ static void corrupt_corrupted(void) /* * Change to an other subrace */ -void switch_subrace(int racem, bool_ copy_old) +void switch_subrace(std::size_t racem, bool_ copy_old) { - if ((racem < 0) && (racem >= max_rmp_idx)) return; + auto &race_mod_info = game->edit_data.race_mod_info; + + assert(racem < race_mod_info.size()); /* If we switch to the saved subrace, we copy over the old subrace data */ if (copy_old && (racem == SUBRACE_SAVE)) { - // This code is very reliant on the race_mod_info - // elements being simple PODs, in particular the - // text pointers being *unmanaged* owned pointers. - static_assert(std::is_pod<player_race_mod>::value, - "This code needs reworking"); - // Keep references to owned pointers. - auto old_title = race_mod_info[SUBRACE_SAVE].title; - auto old_desc = race_mod_info[SUBRACE_SAVE].desc; + // Keep old description + auto old_desc = race_mod_info[SUBRACE_SAVE].description; // Copy everything race_mod_info[SUBRACE_SAVE] = race_mod_info[p_ptr->pracem]; - // "Undo" copy of title and description (since they're *owned* pointers) - race_mod_info[SUBRACE_SAVE].title = old_title; - race_mod_info[SUBRACE_SAVE].desc = old_desc; - // Replace subrace title with the title currently held by player. - set_subrace_title(&race_mod_info[SUBRACE_SAVE], race_mod_info[p_ptr->pracem].title); + // Reinstate description + race_mod_info[SUBRACE_SAVE].description = old_desc; } p_ptr->pracem = racem; rmp_ptr = &race_mod_info[p_ptr->pracem]; } -void set_subrace_title(player_race_mod *rmp_ptr, cptr name) -{ - // Free old title. - free(rmp_ptr->title); - // Allocate copy of new title. - rmp_ptr->title = strdup(name); - if (!rmp_ptr->title) { - abort(); - } -} - -void set_subrace_description(player_race_mod *rmp_ptr, cptr desc) -{ - // Free old description - free(rmp_ptr->desc); - // Allocate copy of new description. - rmp_ptr->desc = strdup(desc); - if (!rmp_ptr->desc) { - abort(); - } -} - /* * Rebirth, recalc hp & exp/level */ void do_rebirth() { /* Experience factor */ - p_ptr->expfact = rp_ptr->r_exp + rmp_ptr->r_exp + cp_ptr->c_exp; + p_ptr->expfact = rp_ptr->ps.exp + rmp_ptr->ps.exp + cp_ptr->ps.exp; /* Hitdice */ - p_ptr->hitdie = rp_ptr->r_mhp + rmp_ptr->r_mhp + cp_ptr->c_mhp; + p_ptr->hitdie = rp_ptr->ps.mhp + rmp_ptr->ps.mhp + cp_ptr->ps.mhp; /* Recalc HP */ do_cmd_rerate(); |