diff options
author | Bardur Arantsson <bardur@scientician.net> | 2018-03-25 20:07:30 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2018-03-25 20:07:30 +0200 |
commit | 45651c61e35ee203c434601ace5e95ccd5474375 (patch) | |
tree | c52f30588611a72deebd8f7f83199d1b0a644b5e | |
parent | 73238d2c617be1600bbb067e0d0bd388488f68d3 (diff) |
Add object_type->k_ptr to point directly to the object_kind
The idea is to eventually migrate off k_idx completely, but there are
still a couple of uses left.
43 files changed, 758 insertions, 611 deletions
diff --git a/src/birth.cc b/src/birth.cc index ab3503d5..81ee38c4 100644 --- a/src/birth.cc +++ b/src/birth.cc @@ -632,10 +632,10 @@ static void player_wipe() /* Reset the "objects" */ for (auto &k_entry: k_info) { - auto &k_ref = k_entry.second; - k_ref.tried = FALSE; - k_ref.aware = FALSE; - k_ref.artifact = 0; + auto k_ptr = k_entry.second; + k_ptr->tried = FALSE; + k_ptr->aware = FALSE; + k_ptr->artifact = 0; } diff --git a/src/cave.cc b/src/cave.cc index 2ab97283..c582eab3 100644 --- a/src/cave.cc +++ b/src/cave.cc @@ -439,9 +439,9 @@ static void image_object(byte *ap, char *cp) auto const &k_info = game->edit_data.k_info; // Select an object kind at random - auto const &k_ref = uniform_element(k_info)->second; - *cp = k_ref.x_char; - *ap = k_ref.x_attr; + auto const &k_ptr = uniform_element(k_info)->second; + *cp = k_ptr->x_char; + *ap = k_ptr->x_attr; } @@ -831,7 +831,6 @@ static void map_info(int y, int x, byte *ap, char *cp) auto const &st_info = game->edit_data.st_info; auto const &r_info = game->edit_data.r_info; auto const &f_info = game->edit_data.f_info; - auto const &k_info = game->edit_data.k_info; byte a; @@ -1038,7 +1037,7 @@ static void map_info(int y, int x, byte *ap, char *cp) *ap = object_attr(o_ptr); /* Multi-hued attr */ - if (!options->avoid_other && (k_info.at(o_ptr->k_idx).flags & TR_ATTR_MULTI)) + if (!options->avoid_other && (o_ptr->k_ptr->flags & TR_ATTR_MULTI)) { *ap = get_shimmer_color(); } @@ -1074,7 +1073,7 @@ static void map_info(int y, int x, byte *ap, char *cp) *ap = object_attr(o_ptr); /* Multi-hued attr */ - if (!options->avoid_other && (k_info.at(o_ptr->k_idx).flags & TR_ATTR_MULTI)) + if (!options->avoid_other && (o_ptr->k_ptr->flags & TR_ATTR_MULTI)) { *ap = get_shimmer_color(); } @@ -1223,7 +1222,6 @@ void map_info_default(int y, int x, byte *ap, char *cp) auto const &st_info = game->edit_data.st_info; auto const &r_info = game->edit_data.r_info; auto const &f_info = game->edit_data.f_info; - auto const &k_info = game->edit_data.k_info; byte a; @@ -1428,7 +1426,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) *ap = object_attr_default(o_ptr); /* Multi-hued attr */ - if (!avoid_other && (k_info.at(o_ptr->k_idx).flags & TR_ATTR_MULTI)) + if (!avoid_other && (o_ptr->k_ptr->flags & TR_ATTR_MULTI)) { *ap = get_shimmer_color(); } @@ -1464,7 +1462,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) *ap = object_attr_default(o_ptr); /* Multi-hued attr */ - if (!avoid_other && (k_info.at(o_ptr->k_idx).flags & TR_ATTR_MULTI)) + if (!avoid_other && (o_ptr->k_ptr->flags & TR_ATTR_MULTI)) { *ap = get_shimmer_color(); } @@ -3909,7 +3907,7 @@ void wiz_lite() object_type *o_ptr = &o_list[i]; /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) continue; /* Skip held objects */ if (o_ptr->held_m_idx) continue; @@ -4020,7 +4018,7 @@ void wiz_dark() object_type *o_ptr = &o_list[i]; /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) continue; /* Skip held objects */ if (o_ptr->held_m_idx) continue; diff --git a/src/cmd1.cc b/src/cmd1.cc index 13edf0ff..f7bdc172 100644 --- a/src/cmd1.cc +++ b/src/cmd1.cc @@ -527,7 +527,10 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, /* Get the carried monster */ auto o_ptr = &p_ptr->inventory[INVEN_CARRY]; - if (!o_ptr->k_idx) return; + if (!o_ptr->k_ptr) + { + return; + } /* Get monster race of the symbiote */ auto r_ptr = &r_info[o_ptr->pval]; @@ -2080,7 +2083,7 @@ void py_attack(int y, int x, int max_blow) py_attack_hand(&k, m_ptr, &special); } /* Handle normal weapon */ - else if (o_ptr->k_idx) + else if (o_ptr->k_ptr) { k = damroll(o_ptr->dd, o_ptr->ds); k = tot_dam_aux(o_ptr, k, m_ptr, &special); @@ -4297,23 +4300,17 @@ bool_ do_cmd_leave_body(bool_ drop_body) { auto const &r_info = game->edit_data.r_info; - object_type *o_ptr, forge; - - auto r_ptr = &r_info[p_ptr->body_monster]; - - int i; - - if (p_ptr->disembodied) { msg_print("You are already disembodied."); return FALSE; } - for (i = INVEN_WIELD; i < INVEN_TOTAL; i++) + for (int i = INVEN_WIELD; i < INVEN_TOTAL; i++) { - if (p_ptr->body_parts[i - INVEN_WIELD] && p_ptr->inventory[i].k_idx && - cursed_p(&p_ptr->inventory[i])) + if (p_ptr->body_parts[i - INVEN_WIELD] && + p_ptr->inventory[i].k_ptr && + cursed_p(&p_ptr->inventory[i])) { msg_print("A cursed object is preventing you from leaving your body."); return FALSE; @@ -4324,7 +4321,10 @@ bool_ do_cmd_leave_body(bool_ drop_body) { if (magik(25 + get_skill_scale(SKILL_POSSESSION, 25) + get_skill(SKILL_PRESERVATION))) { - o_ptr = &forge; + auto r_ptr = &r_info[p_ptr->body_monster]; + + object_type forge; + auto o_ptr = &forge; object_prep(o_ptr, lookup_kind(TV_CORPSE, SV_CORPSE_CORPSE)); o_ptr->number = 1; o_ptr->pval = 0; diff --git a/src/cmd2.cc b/src/cmd2.cc index 2623ca54..405521ce 100644 --- a/src/cmd2.cc +++ b/src/cmd2.cc @@ -1370,8 +1370,8 @@ static bool_ do_cmd_tunnel_aux(int y, int x, int dir) /* Must be have something to dig with (except for sandwalls) */ if ((c_ptr->feat < FEAT_SANDWALL) || (c_ptr->feat > FEAT_SANDWALL_K)) { - if (!p_ptr->inventory[INVEN_TOOL].k_idx || - (p_ptr->inventory[INVEN_TOOL].tval != TV_DIGGING)) + auto o_ptr = &p_ptr->inventory[INVEN_TOOL]; + if (!o_ptr->k_ptr || (o_ptr->tval != TV_DIGGING)) { msg_print("You need to have a shovel or pick in your tool slot."); @@ -1999,8 +1999,10 @@ static bool_ get_spike(int *ip) { object_type *o_ptr = &p_ptr->inventory[i]; - /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Check the "tval" code */ if (o_ptr->tval == TV_SPIKE) @@ -2717,7 +2719,7 @@ void do_cmd_fire() item = INVEN_AMMO; /* If nothing correct try to choose from the backpack */ - if ((p_ptr->tval_ammo != o_ptr->tval) || (!o_ptr->k_idx)) + if ((p_ptr->tval_ammo != o_ptr->tval) || (!o_ptr->k_ptr)) { /* Get an item */ if (!get_item(&item, @@ -3092,8 +3094,6 @@ void do_cmd_fire() */ void do_cmd_throw() { - auto const &k_info = game->edit_data.k_info; - int dir; s32b special = 0; @@ -3377,7 +3377,7 @@ void do_cmd_throw() if (special) attack_special(m_ptr, special, tdam); /* Anger friends */ - if (!(k_info.at(q_ptr->k_idx).tval == TV_POTION)) + if (!(q_ptr->k_ptr->tval == TV_POTION)) { char m_name[80]; monster_desc(m_name, m_ptr, 0); @@ -3417,7 +3417,7 @@ void do_cmd_throw() j = (hit_body ? breakage_chance(q_ptr) : 0); /* Potions smash open */ - if (k_info.at(q_ptr->k_idx).tval == TV_POTION) + if (q_ptr->k_ptr->tval == TV_POTION) { if ((hit_body) || (hit_wall) || (randint(100) < j)) { @@ -3468,8 +3468,6 @@ void do_cmd_throw() */ void do_cmd_boomerang() { - auto const &k_info = game->edit_data.k_info; - int dir; int j, y, x, ny, nx, ty, tx; @@ -3703,7 +3701,7 @@ void do_cmd_boomerang() if (special) attack_special(m_ptr, special, tdam); /* Anger friends */ - if (!(k_info.at(q_ptr->k_idx).tval == TV_POTION)) + if (!(q_ptr->k_ptr->tval == TV_POTION)) { char m_name[80]; monster_desc(m_name, m_ptr, 0); @@ -4467,7 +4465,7 @@ void do_cmd_steal() } /* Delete source item */ - o_list[item].k_idx = 0; + o_list[item].k_ptr.reset(); } screen_load(); diff --git a/src/cmd3.cc b/src/cmd3.cc index 59a21ff6..78fa05a1 100644 --- a/src/cmd3.cc +++ b/src/cmd3.cc @@ -171,9 +171,15 @@ 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); + } } } @@ -277,8 +283,8 @@ 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); msg_format("You cannot wield your %s with a shield.", o_name); @@ -293,8 +299,9 @@ 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); msg_format("You cannot wield your %s with a two-handed weapon.", o_name); @@ -302,7 +309,7 @@ void do_cmd_wield() } 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 +319,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,7 +351,7 @@ 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); @@ -352,7 +359,7 @@ void do_cmd_wield() } else { - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { if (!object_similar(o_ptr, q_ptr)) { @@ -559,8 +566,6 @@ void do_cmd_drop() */ void do_cmd_destroy() { - auto const &k_info = game->edit_data.k_info; - int old_number; bool_ force = FALSE; @@ -677,7 +682,7 @@ void do_cmd_destroy() /* Eru wont be happy */ if (flags & TR_BLESSED) { - inc_piety(GOD_ERU, -10 * k_info.at(o_ptr->k_idx).level); + inc_piety(GOD_ERU, -10 * o_ptr->k_ptr->level); } /* Eliminate the item */ diff --git a/src/cmd4.cc b/src/cmd4.cc index 5277fefa..7d1951cc 100644 --- a/src/cmd4.cc +++ b/src/cmd4.cc @@ -2172,7 +2172,7 @@ void do_cmd_visuals() /* Dump objects */ for (auto const &k_entry: k_info) { - auto const k_ptr = &k_entry.second; + auto const k_ptr = k_entry.second; /* Dump a comment */ fprintf(fff, "# %s\n", k_ptr->name.c_str()); @@ -2315,7 +2315,7 @@ void do_cmd_visuals() /* Hack -- query until done */ while (1) { - object_kind *k_ptr = &k_info.at(k_info_keys[k_idx]); + auto k_ptr = k_info.at(k_info_keys[k_idx]); byte da = k_ptr->d_attr; char dc = k_ptr->d_char; @@ -3056,7 +3056,7 @@ void do_cmd_knowledge_artifacts() std::unordered_set<int> okayk; for (auto const &k_entry: k_info) { - auto k_ptr = &k_entry.second; + auto k_ptr = k_entry.second; /* Skip "empty" artifacts */ if (!(k_ptr->flags & TR_NORM_ART)) continue; @@ -3091,7 +3091,7 @@ void do_cmd_knowledge_artifacts() if (object_known_p(o_ptr)) continue; /* Note the artifact */ - if (k_info.at(o_ptr->k_idx).flags & TR_NORM_ART) + if (o_ptr->k_ptr->flags & TR_NORM_ART) { okayk.erase(o_ptr->k_idx); } @@ -3109,10 +3109,8 @@ void do_cmd_knowledge_artifacts() /* Scan all objects the monster carries */ for (auto const this_o_idx: m_list[i].hold_o_idxs) { - object_type * o_ptr; - /* Acquire object */ - o_ptr = &o_list[this_o_idx]; + auto o_ptr = &o_list[this_o_idx]; /* Ignore random artifacts */ if (o_ptr->tval == TV_RANDART) continue; @@ -3124,7 +3122,7 @@ void do_cmd_knowledge_artifacts() if (object_known_p(o_ptr)) continue; /* Note the artifact */ - if (k_info.at(o_ptr->k_idx).flags & TR_NORM_ART) + if (o_ptr->k_ptr->flags & TR_NORM_ART) { okayk.erase(o_ptr->k_idx); } @@ -3138,10 +3136,10 @@ void do_cmd_knowledge_artifacts() /* Check the p_ptr->inventory and equipment */ for (i = 0; i < INVEN_TOTAL; i++) { - object_type *o_ptr = &p_ptr->inventory[i]; + auto o_ptr = &p_ptr->inventory[i]; /* Ignore non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) continue; /* Ignore random artifacts */ if (o_ptr->tval == TV_RANDART) continue; @@ -3153,7 +3151,7 @@ void do_cmd_knowledge_artifacts() if (object_known_p(o_ptr)) continue; /* Note the artifact */ - if (k_info.at(o_ptr->k_idx).flags & TR_NORM_ART) + if (o_ptr->k_ptr->flags & TR_NORM_ART) { okayk.erase(o_ptr->k_idx); } @@ -3581,7 +3579,7 @@ static void do_cmd_knowledge_objects() for (auto const &k: k_info_keys) { - auto k_ptr = &k_info.at(k); + auto k_ptr = k_info.at(k); /* Hack -- skip artifacts */ if (k_ptr->flags & TR_INSTA_ART) diff --git a/src/cmd5.cc b/src/cmd5.cc index a93759b0..a270a572 100644 --- a/src/cmd5.cc +++ b/src/cmd5.cc @@ -103,7 +103,7 @@ bool_ is_magestaff() 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++; @@ -550,7 +550,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"; } diff --git a/src/cmd6.cc b/src/cmd6.cc index 508aaabc..c292c25b 100644 --- a/src/cmd6.cc +++ b/src/cmd6.cc @@ -77,7 +77,7 @@ static select_by_name_t select_object_by_name(std::string const &prompt) { object_type *o_ptr = get_object(i); // Must have an actual item in the slot - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { continue; } @@ -977,7 +977,6 @@ static object_filter_t const &item_tester_hook_eatable() void do_cmd_eat_food() { auto const &r_info = game->edit_data.r_info; - auto const &k_info = game->edit_data.k_info; int ident, lev, fval = 0; @@ -1007,7 +1006,7 @@ void do_cmd_eat_food() ident = FALSE; /* Object level */ - lev = k_info.at(o_ptr->k_idx).level; + lev = o_ptr->k_ptr->level; /* Scripted foods */ hook_eat_in in = { o_ptr }; @@ -2480,8 +2479,6 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) */ void do_cmd_quaff_potion() { - auto const &k_info = game->edit_data.k_info; - int ident, lev; /* Get an item */ @@ -2507,7 +2504,7 @@ void do_cmd_quaff_potion() ident = FALSE; /* Object level */ - lev = k_info.at(o_ptr->k_idx).level; + lev = o_ptr->k_ptr->level; /* Demon Breath corruption can spoil potions. */ if (player_has_corruption(CORRUPT_DEMON_BREATH) && magik(9)) @@ -2684,7 +2681,7 @@ void do_cmd_drink_fountain() for (auto const &k_entry: k_info) { - auto k_ptr = &k_entry.second; + auto const &k_ptr = k_entry.second; if (k_ptr->tval != tval) continue; if (k_ptr->sval != sval) continue; @@ -2713,19 +2710,17 @@ void do_cmd_drink_fountain() */ bool_ curse_armor() { - object_type *o_ptr; - - char o_name[80]; - - /* Curse the body armor */ - o_ptr = &p_ptr->inventory[INVEN_BODY]; + auto o_ptr = &p_ptr->inventory[INVEN_BODY]; /* Nothing to curse */ - if (!o_ptr->k_idx) return (FALSE); - + if (!o_ptr->k_ptr) + { + return FALSE; + } /* Describe */ + char o_name[80]; object_desc(o_name, o_ptr, FALSE, 3); /* Attempt a saving throw for artifacts */ @@ -2775,19 +2770,17 @@ bool_ curse_armor() */ bool_ curse_weapon() { - object_type *o_ptr; - - char o_name[80]; - - /* Curse the weapon */ - o_ptr = &p_ptr->inventory[INVEN_WIELD]; + auto o_ptr = &p_ptr->inventory[INVEN_WIELD]; /* Nothing to curse */ - if (!o_ptr->k_idx) return (FALSE); - + if (!o_ptr->k_ptr) + { + return (FALSE); + } /* Describe */ + char o_name[80]; object_desc(o_name, o_ptr, FALSE, 3); /* Attempt a saving throw */ @@ -2858,7 +2851,6 @@ static object_filter_t const &item_tester_hook_readable() void do_cmd_read_scroll() { auto const &d_info = game->edit_data.d_info; - auto const &k_info = game->edit_data.k_info; auto &r_info = game->edit_data.r_info; /* Check some conditions */ @@ -2902,7 +2894,7 @@ void do_cmd_read_scroll() int ident = FALSE; /* Object level */ - int lev = k_info.at(o_ptr->k_idx).level; + int lev = o_ptr->k_ptr->level; /* Assume the scroll will get used up */ int used_up = TRUE; @@ -4140,7 +4132,7 @@ void do_cmd_zap_rod() ident = FALSE; /* Extract the item level */ - auto const tip_ptr = &k_info.at(lookup_kind(TV_ROD, o_ptr->pval)); + auto const &tip_ptr = k_info.at(lookup_kind(TV_ROD, o_ptr->pval)); auto const lev = tip_ptr->level; /* Base chance of success */ @@ -4796,7 +4788,6 @@ static void activate_valaroma() */ void do_cmd_activate() { - auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; int item, lev, chance; @@ -4832,7 +4823,7 @@ void do_cmd_activate() energy_use = 100; /* Extract the item level */ - lev = k_info.at(o_ptr->k_idx).level; + lev = o_ptr->k_ptr->level; /* Hack -- Use artifact level instead */ if (artifact_p(o_ptr)) @@ -4957,7 +4948,6 @@ void do_cmd_activate() const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { - auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; @@ -4991,7 +4981,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) /* Intrinsic to item type (rings of Ice, etc) */ if (!spell) - spell = k_info.at(o_ptr->k_idx).activate; + spell = o_ptr->k_ptr->activate; /* Complain about mis-configured .txt files? */ if (!spell) diff --git a/src/cmd7.cc b/src/cmd7.cc index 0d58647b..d2bb9e8d 100644 --- a/src/cmd7.cc +++ b/src/cmd7.cc @@ -112,8 +112,6 @@ void mindcraft_info(char *p, int power) */ void mimic_info(char *p, int power) { - auto const &k_info = game->edit_data.k_info; - int plev = get_skill(SKILL_MIMICRY); object_type *o_ptr = &p_ptr->inventory[INVEN_OUTER]; @@ -124,7 +122,7 @@ void mimic_info(char *p, int power) switch (power) { case 0: - strnfmt(p, 80, " dur %d", k_info.at(o_ptr->k_idx).pval2 + get_skill_scale(SKILL_MIMICRY, 1000)); + strnfmt(p, 80, " dur %d", o_ptr->k_ptr->pval2 + get_skill_scale(SKILL_MIMICRY, 1000)); break; case 1: strnfmt(p, 80, " dur %d+d20", 10 + plev); @@ -764,13 +762,6 @@ static int get_mimic_chance(int mimic) void do_cmd_mimic_lore() { - auto const &k_info = game->edit_data.k_info; - - int fail; - - object_type *o_ptr; - - /* Player has to be able to see */ if (p_ptr->blind || no_lite()) { @@ -797,7 +788,7 @@ void do_cmd_mimic_lore() /* Not in mimic forms -- Allow transformations */ else { - o_ptr = &p_ptr->inventory[INVEN_OUTER]; + object_type const *o_ptr = &p_ptr->inventory[INVEN_OUTER]; if ((o_ptr->tval != TV_CLOAK) || (o_ptr->sval != SV_MIMIC_CLOAK)) { @@ -806,7 +797,7 @@ void do_cmd_mimic_lore() } /* Calculate failure rate */ - fail = get_mimic_chance(o_ptr->pval2); + auto const fail = get_mimic_chance(o_ptr->pval2); if (fail > 75) { @@ -832,7 +823,7 @@ void do_cmd_mimic_lore() /* Success */ else { - set_mimic(k_info.at(o_ptr->k_idx).pval2 + get_skill_scale(SKILL_MIMICRY, 1000), o_ptr->pval2, get_skill(SKILL_MIMICRY)); + set_mimic(o_ptr->k_ptr->pval2 + get_skill_scale(SKILL_MIMICRY, 1000), o_ptr->pval2, get_skill(SKILL_MIMICRY)); } } @@ -2240,7 +2231,7 @@ void do_cmd_necromancer() object_type forge, *o_ptr = &forge; int k_idx = test_item_name("& Necromantic Teeth~"); - k_info[k_idx].allow_special = TRUE; + k_info[k_idx]->allow_special = TRUE; object_prep(o_ptr, k_idx); apply_magic(o_ptr, plev * 2, TRUE, TRUE, TRUE); @@ -2256,7 +2247,7 @@ void do_cmd_necromancer() object_known(o_ptr); inven_carry(o_ptr, FALSE); - k_info[k_idx].allow_special = FALSE; + k_info[k_idx]->allow_special = FALSE; break; } @@ -3086,7 +3077,7 @@ void do_cmd_symbiotic() { s32b percent1, percent2; - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { msg_print("You are not in symbiosis."); break; @@ -3117,7 +3108,7 @@ void do_cmd_symbiotic() /* Minor Symbiotic Powers */ case 4: { - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { msg_print("You are not in symbiosis."); break; @@ -3132,17 +3123,20 @@ void do_cmd_symbiotic() /* Heal Symbiote */ case 5: { - int hp; - - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { msg_print("You are not in symbiosis."); break; } - hp = o_ptr->pval3 * (15 + get_skill_scale(SKILL_SYMBIOTIC, 35)) / 100; + int const hp = + o_ptr->pval3 * (15 + get_skill_scale(SKILL_SYMBIOTIC, 35)) / 100; + o_ptr->pval2 += hp; - if (o_ptr->pval2 > o_ptr->pval3) o_ptr->pval2 = o_ptr->pval3; + if (o_ptr->pval2 > o_ptr->pval3) + { + o_ptr->pval2 = o_ptr->pval3; + } msg_format("%s is healed.", symbiote_name(true).c_str()); @@ -3156,13 +3150,13 @@ void do_cmd_symbiotic() /* Major Symbiotic Powers */ case 6: { - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { msg_print("You are not in symbiosis."); break; } - if(0 > use_symbiotic_power(o_ptr->pval, true)) + if (0 > use_symbiotic_power(o_ptr->pval, true)) return; break; diff --git a/src/dungeon.cc b/src/dungeon.cc index 47f47e92..7f9a19aa 100644 --- a/src/dungeon.cc +++ b/src/dungeon.cc @@ -134,10 +134,7 @@ static byte value_check_aux1(object_type const *o_ptr) static byte value_check_aux1_magic(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; - - auto k_ptr = &k_info.at(o_ptr->k_idx); - + auto const &k_ptr = o_ptr->k_ptr; switch (o_ptr->tval) { @@ -225,10 +222,7 @@ static byte value_check_aux2(object_type const *o_ptr) static byte value_check_aux2_magic(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; - - auto k_ptr = &k_info.at(o_ptr->k_idx); - + auto k_ptr = o_ptr->k_ptr; switch (o_ptr->tval) { @@ -415,13 +409,22 @@ void sense_objects(std::vector<int> const &object_idxs) object_type *o_ptr = get_object(i); /* Skip empty slots */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* We know about it already, do not tell us again */ - if (o_ptr->ident & (IDENT_SENSE)) continue; + if (o_ptr->ident & IDENT_SENSE) + { + continue; + } /* It is fully known, no information needed */ - if (object_known_p(o_ptr)) continue; + if (object_known_p(o_ptr)) + { + continue; + } /* Select appropriate sensing function, if any */ sense_function_t sense = select_sense(o_ptr, feel_combat, feel_magic); @@ -780,12 +783,9 @@ static void regen_monsters() { auto const &r_info = game->edit_data.r_info; - int i, frac; + auto o_ptr = &p_ptr->inventory[INVEN_CARRY]; - object_type *o_ptr = &p_ptr->inventory[INVEN_CARRY]; - - - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { auto r_ptr = &r_info[o_ptr->pval]; @@ -793,7 +793,7 @@ static void regen_monsters() if (o_ptr->pval2 < o_ptr->pval3) { /* Hack -- Base regeneration */ - frac = o_ptr->pval3 / 100; + int frac = o_ptr->pval3 / 100; /* Hack -- Minimal regeneration rate */ if (!frac) frac = 1; @@ -814,7 +814,7 @@ static void regen_monsters() } /* Regenerate everyone */ - for (i = 1; i < m_max; i++) + for (int i = 1; i < m_max; i++) { /* Check the i'th monster */ monster_type *m_ptr = &m_list[i]; @@ -829,7 +829,7 @@ static void regen_monsters() if (m_ptr->hp < m_ptr->maxhp) { /* Hack -- Base regeneration */ - frac = m_ptr->maxhp / 100; + int frac = m_ptr->maxhp / 100; /* Hack -- Minimal regeneration rate */ if (!frac) frac = 1; @@ -1289,7 +1289,7 @@ static void process_world() /*** Is the wielded monsters still hypnotised ***/ o_ptr = &p_ptr->inventory[INVEN_CARRY]; - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { auto r_ptr = &r_info[o_ptr->pval]; @@ -1583,7 +1583,10 @@ static void process_world() auto const flags = object_flags(o_ptr); /* Hitpoints multiplier consume a lot of food */ - if (o_ptr->k_idx && (flags & TR_LIFE)) i += o_ptr->pval * 5; + if (o_ptr->k_ptr && (flags & TR_LIFE)) + { + i += o_ptr->pval * 5; + } /* Slow digestion takes less food */ if (p_ptr->slow_digest) i -= 10; @@ -2556,7 +2559,10 @@ static void process_world() o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Extract the item flags */ auto const flags = object_flags(o_ptr); @@ -2790,7 +2796,10 @@ static void process_world() /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Hack: Skip wielded lights that need fuel (already handled above) */ if ((i == INVEN_LITE) && (o_ptr->tval == TV_LITE) && (flags & TR_FUEL_LITE)) continue; @@ -2823,7 +2832,10 @@ static void process_world() o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Examine the rod */ auto const flags = object_flags(o_ptr); @@ -2958,7 +2970,10 @@ static void process_world() o_ptr = &o_list[i]; /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Examine the rod */ auto const flags = object_flags(o_ptr); @@ -4145,7 +4160,6 @@ static void process_command() static void process_player() { auto const &f_info = game->edit_data.f_info; - auto const &k_info = game->edit_data.k_info; int i, j; @@ -4278,16 +4292,12 @@ static void process_player() if (options->fresh_before) Term_fresh(); /* Hack -- Pack Overflow */ - if (p_ptr->inventory[INVEN_PACK].k_idx) + if (p_ptr->inventory[INVEN_PACK].k_ptr) { int item = INVEN_PACK; - char o_name[80]; - - object_type *o_ptr; - /* Access the slot to be dropped */ - o_ptr = &p_ptr->inventory[item]; + auto o_ptr = &p_ptr->inventory[item]; /* Disturbing */ disturb(); @@ -4296,6 +4306,7 @@ static void process_player() msg_print("Your pack overflows!"); /* Describe */ + char o_name[80]; object_desc(o_name, o_ptr, TRUE, 3); /* Message */ @@ -4457,13 +4468,12 @@ static void process_player() { /* Acquire object -- for speed only base items are allowed to shimmer */ object_type *o_ptr = &o_list[i]; - auto k_ptr = &k_info.at(o_ptr->k_idx); /* Skip dead or carried objects */ - if ((!o_ptr->k_idx) || (!o_ptr->ix)) continue; + if ((!o_ptr->k_ptr) || (!o_ptr->ix)) continue; /* Skip non-multi-hued monsters */ - if (!(k_ptr->flags & TR_ATTR_MULTI)) continue; + if (!(o_ptr->k_ptr->flags & TR_ATTR_MULTI)) continue; /* Reset the flag */ shimmer_objects = TRUE; diff --git a/src/files.cc b/src/files.cc index dc9262a0..3cb4a1dc 100644 --- a/src/files.cc +++ b/src/files.cc @@ -346,7 +346,7 @@ errr process_pref_file_aux(char *buf) return (1); } - auto k_ptr = &k_info.at(i); + auto k_ptr = k_info.at(i); if (n1) { @@ -429,16 +429,16 @@ errr process_pref_file_aux(char *buf) for (auto &k_entry: k_info) { - auto &k_ref = k_entry.second; - if (k_ref.tval == j) + auto k_ptr = k_entry.second; + if (k_ptr->tval == j) { if (n1) { - k_ref.d_attr = n1; + k_ptr->d_attr = n1; } if (n2) { - k_ref.d_char = n2; + k_ptr->d_char = n2; } } } @@ -1568,18 +1568,29 @@ static object_flag_set wield_monster_flags() /* Get the carried monster */ auto o_ptr = &p_ptr->inventory[INVEN_CARRY]; - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { auto r_ptr = &r_info[o_ptr->pval]; if (r_ptr->flags & RF_INVISIBLE) + { flags |= TR_INVIS; + } + if (r_ptr->flags & RF_REFLECTING) + { flags |= TR_REFLECT; + } + if (r_ptr->flags & RF_CAN_FLY) + { flags |= TR_FEATHER; + } + if (r_ptr->flags & RF_AQUATIC) + { flags |= TR_WATER_BREATH; + } } return flags; @@ -4046,10 +4057,13 @@ static long total_points() /* The known objects increase the score */ for (auto const &k_entry: k_info) { - auto k_ptr = &k_entry.second; + auto k_ptr = k_entry.second; /* Hack -- skip artifacts */ - if (k_ptr->flags & TR_INSTA_ART) continue; + if (k_ptr->flags & TR_INSTA_ART) + { + continue; + } /* List known flavored objects */ if (k_ptr->flavor && k_ptr->aware) @@ -4172,7 +4186,10 @@ static void show_info() auto o_ptr = &o_ref; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Aware and Known */ object_aware(o_ptr); @@ -4188,7 +4205,10 @@ static void show_info() auto o_ptr = &o_ref; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Aware and Known */ object_aware(o_ptr); diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp index e83a5d51..3b8f2cd4 100644 --- a/src/game_edit_data.hpp +++ b/src/game_edit_data.hpp @@ -21,6 +21,7 @@ #include "vault_type.hpp" #include "wilderness_type_info.hpp" +#include <memory> #include <unordered_map> #include <vector> @@ -67,9 +68,9 @@ struct GameEditData { std::vector<set_type> set_info; /** - * Object kinds + * Object kinds. */ - std::unordered_map<int, object_kind> k_info; + std::unordered_map<int, std::shared_ptr<object_kind>> k_info; /** * Get a sorted vector of all the keys of k_info. diff --git a/src/generate.cc b/src/generate.cc index 1da96bb9..331f79a6 100644 --- a/src/generate.cc +++ b/src/generate.cc @@ -832,7 +832,7 @@ static void place_fountain(int y, int x) /* List of usable svals */ for (auto const &k_entry: k_info) { - auto k_ptr = &k_entry.second; + auto const &k_ptr = k_entry.second; if (((k_ptr->tval == TV_POTION) || (k_ptr->tval == TV_POTION2)) && (k_ptr->level <= dun_level) && (k_ptr->flags & TR_FOUNTAIN)) @@ -7970,53 +7970,54 @@ static bool_ cave_gen() } } - if (m_idx && d_ptr->final_object && - (k_info.at(d_ptr->final_object).artifact == FALSE)) + if (m_idx && d_ptr->final_object) { - object_type *q_ptr, forge, *o_ptr; - int o_idx; - - /* Get new object */ - o_idx = o_pop(); + auto k_ptr = k_info.at(d_ptr->final_object); - /* Proceed only if there's an object slot available */ - if (o_idx) + if (k_ptr->artifact == FALSE) { - /* Get local object */ - q_ptr = &forge; + /* Get new object */ + int o_idx = o_pop(); - k_info[d_ptr->final_object].allow_special = TRUE; + /* Proceed only if there's an object slot available */ + if (o_idx) + { + /* Get local object */ + object_type forge; + object_type *q_ptr = &forge; - /* Wipe the object */ - object_wipe(q_ptr); + k_info[d_ptr->final_object]->allow_special = TRUE; - /* Create the final object */ - object_prep(q_ptr, d_ptr->final_object); - apply_magic(q_ptr, 1, FALSE, FALSE, FALSE); + /* Wipe the object */ + object_wipe(q_ptr); - /* Where it is found ? */ - q_ptr->found = OBJ_FOUND_MONSTER; - q_ptr->found_aux1 = d_ptr->final_guardian; - q_ptr->found_aux2 = 0; - q_ptr->found_aux3 = dungeon_type; - q_ptr->found_aux4 = level_or_feat(dungeon_type, dun_level); + /* Create the final object */ + object_prep(q_ptr, d_ptr->final_object); + apply_magic(q_ptr, 1, FALSE, FALSE, FALSE); - k_info[d_ptr->final_object].allow_special = FALSE; + /* Where it is found ? */ + q_ptr->found = OBJ_FOUND_MONSTER; + q_ptr->found_aux1 = d_ptr->final_guardian; + q_ptr->found_aux2 = 0; + q_ptr->found_aux3 = dungeon_type; + q_ptr->found_aux4 = level_or_feat(dungeon_type, dun_level); - k_info.at(d_ptr->final_object).artifact = TRUE; + k_ptr->allow_special = FALSE; + k_ptr->artifact = TRUE; - /* Get the item */ - o_ptr = &o_list[o_idx]; + /* Get the item */ + object_type *o_ptr = &o_list[o_idx]; - /* Structure copy */ - object_copy(o_ptr, q_ptr); + /* Structure copy */ + object_copy(o_ptr, q_ptr); - /* Build a stack */ - o_ptr->held_m_idx = m_idx; - o_ptr->ix = 0; - o_ptr->iy = 0; + /* Build a stack */ + o_ptr->held_m_idx = m_idx; + o_ptr->ix = 0; + o_ptr->iy = 0; - m_list[m_idx].hold_o_idxs.push_back(o_idx); + m_list[m_idx].hold_o_idxs.push_back(o_idx); + } } } } diff --git a/src/init1.cc b/src/init1.cc index 34e4e0cf..36c7b8d9 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2238,8 +2238,7 @@ errr init_k_info_txt(FILE *fp) char *s, *t; /* Current entry */ - object_kind *k_ptr = NULL; - + std::shared_ptr<object_kind> k_ptr; /* Just before the first record */ error_idx = -1; @@ -2286,7 +2285,8 @@ errr init_k_info_txt(FILE *fp) error_idx = i; /* Point at the "info"; automatically creates an entry */ - k_ptr = &k_info[i]; + k_info.emplace(std::make_pair(i, std::make_shared<object_kind>())); + k_ptr = k_info[i]; k_ptr->name = s; /* Next... */ @@ -6244,7 +6244,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst /* Get local object */ object_type *o_ptr = &object_type_body; - k_info[object_index].allow_special = TRUE; + k_info[object_index]->allow_special = TRUE; /* Create the item */ object_prep(o_ptr, object_index); @@ -6254,7 +6254,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst o_ptr->found = OBJ_FOUND_SPECIAL; - k_info[object_index].allow_special = FALSE; + k_info[object_index]->allow_special = FALSE; drop_near(o_ptr, -1, y, x); } diff --git a/src/init2.cc b/src/init2.cc index c42c5970..4d2df8f8 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -716,7 +716,7 @@ static errr init_alloc() std::size_t kind_size = 0; for (auto const &k_entry: k_info) { - auto k_ptr = &k_entry.second; + auto const &k_ptr = k_entry.second; /* Scan allocation pairs */ for (std::size_t j = 0; j < ALLOCATION_MAX; j++) @@ -753,7 +753,7 @@ static errr init_alloc() /* Scan the objects */ for (auto const &k_entry: k_info) { - auto const k_ptr = &k_entry.second; + auto const &k_ptr = k_entry.second; /* Scan allocation pairs */ for (std::size_t j = 0; j < ALLOCATION_MAX; j++) @@ -928,7 +928,7 @@ static void init_guardians() /* Mark the final object */ if (d_ptr->final_object) { - auto k_ptr = &k_info.at(d_ptr->final_object); + auto const &k_ptr = k_info.at(d_ptr->final_object); k_ptr->flags |= TR_SPECIAL_GENE; } diff --git a/src/loadsave.cc b/src/loadsave.cc index 9a2d223e..76f6cb7e 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -362,12 +362,12 @@ template<typename M, typename FK, typename FV> void do_fixed_map(ls_flag_t flag, // value. if (map.count(key)) { - fv(&map.at(key), flag); + fv(map.at(key), flag); } else { typename M::mapped_type v; - fv(&v, flag); + fv(v, flag); } } } @@ -380,7 +380,7 @@ template<typename M, typename FK, typename FV> void do_fixed_map(ls_flag_t flag, auto key = entry.first; auto value = entry.second; fk(&key, flag); - fv(&value, flag); + fv(value, flag); } } } @@ -993,7 +993,6 @@ static bool_ wearable_p(object_type *o_ptr) */ static void do_item(object_type *o_ptr, ls_flag_t flag) { - auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; auto &e_info = game->edit_data.e_info; @@ -1002,6 +1001,7 @@ static void do_item(object_type *o_ptr, ls_flag_t flag) /* Kind */ do_s16b(&o_ptr->k_idx, flag); + o_ptr->k_ptr = game->edit_data.k_info.at(o_ptr->k_idx); /* Location */ do_byte(&o_ptr->iy, flag); @@ -1092,7 +1092,7 @@ static void do_item(object_type *o_ptr, ls_flag_t flag) /*********** END OF ls_flag_t::SAVE ***************/ /* Obtain the "kind" template */ - object_kind *k_ptr = &k_info.at(o_ptr->k_idx); + auto k_ptr = o_ptr->k_ptr; /* Obtain tval/sval from k_info */ o_ptr->tval = k_ptr->tval; @@ -1781,7 +1781,7 @@ static bool_ do_inventory(ls_flag_t flag) do_item(q_ptr, ls_flag_t::LOAD); /* Hack -- verify item */ - if (!q_ptr->k_idx) return (FALSE); + if (!q_ptr->k_ptr) return (FALSE); /* Wield equipment */ if (n >= INVEN_WIELD) @@ -1828,7 +1828,7 @@ static bool_ do_inventory(ls_flag_t flag) for (u16b i = 0; i < INVEN_TOTAL; i++) { object_type *o_ptr = &p_ptr->inventory[i]; - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) continue; do_u16b(&i, flag); do_item(o_ptr, flag); } @@ -2007,7 +2007,7 @@ static bool do_object_lore(ls_flag_t flag) auto &k_info = game->edit_data.k_info; do_fixed_map(flag, k_info, do_int, - [](object_kind *k_ptr, auto flag) -> void { + [](std::shared_ptr<object_kind> k_ptr, auto flag) -> void { do_bool(&k_ptr->aware, flag); do_bool(&k_ptr->tried, flag); do_bool(&k_ptr->artifact, flag); diff --git a/src/melee1.cc b/src/melee1.cc index 58ebfbaa..35b76638 100644 --- a/src/melee1.cc +++ b/src/melee1.cc @@ -1729,7 +1729,10 @@ bool_ make_attack_normal(int m_idx, byte divis) o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Drain charged wands/staffs Hack -- don't let artifacts get drained */ @@ -1867,10 +1870,16 @@ bool_ make_attack_normal(int m_idx, byte divis) o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Skip artifacts */ - if (artifact_p(o_ptr)) continue; + if (artifact_p(o_ptr)) + { + continue; + } /* Get a description */ object_desc(o_name, o_ptr, FALSE, 3); @@ -1950,7 +1959,10 @@ bool_ make_attack_normal(int m_idx, byte divis) o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Skip non-food objects */ if (o_ptr->tval != TV_FOOD) continue; diff --git a/src/melee2.cc b/src/melee2.cc index d769355a..6307fcbd 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2331,13 +2331,18 @@ void curse_equipment(int chance, int heavy_chance) object_type * o_ptr = &p_ptr->inventory[rand_range(INVEN_WIELD, INVEN_TOTAL - 1)]; - if (randint(100) > chance) return; + if (randint(100) > chance) + { + return; + } - if (!(o_ptr->k_idx)) return; + if (!o_ptr->k_ptr) + { + return; + } auto const flags = object_flags(o_ptr); - /* Extra, biased saving throw for blessed items */ if ((flags & TR_BLESSED) && (randint(888) > chance)) { @@ -2384,13 +2389,18 @@ void curse_equipment_dg(int chance, int heavy_chance) object_type * o_ptr = &p_ptr->inventory[rand_range(INVEN_WIELD, INVEN_TOTAL - 1)]; - if (randint(100) > chance) return; + if (randint(100) > chance) + { + return; + } - if (!(o_ptr->k_idx)) return; + if (!o_ptr->k_ptr) + { + return; + } auto const flags = object_flags(o_ptr); - /* Extra, biased saving throw for blessed items */ if ((flags & TR_BLESSED) && (randint(888) > chance)) { @@ -4157,24 +4167,40 @@ void find_corpse(monster_type *m_ptr, int *y, int *x) { auto const &r_info = game->edit_data.r_info; - int k, last = -1; + int last = -1; - for (k = 0; k < max_o_idx; k++) + for (int k = 0; k < max_o_idx; k++) { object_type *o_ptr = &o_list[k]; - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } + + if (o_ptr->tval != TV_CORPSE) + { + continue; + } - if (o_ptr->tval != TV_CORPSE) continue; - if ((o_ptr->sval != SV_CORPSE_CORPSE) && (o_ptr->sval != SV_CORPSE_SKELETON)) continue; + if ((o_ptr->sval != SV_CORPSE_CORPSE) && (o_ptr->sval != SV_CORPSE_SKELETON)) + { + continue; + } auto rt_ptr = &r_info[o_ptr->pval2]; /* Cannot incarnate into a higher level monster */ - if (rt_ptr->level > m_ptr->level) continue; + if (rt_ptr->level > m_ptr->level) + { + continue; + } /* Must be in LOS */ - if (!los(m_ptr->fy, m_ptr->fx, o_ptr->iy, o_ptr->ix)) continue; + if (!los(m_ptr->fy, m_ptr->fx, o_ptr->iy, o_ptr->ix)) + { + continue; + } if (last != -1) { diff --git a/src/monster2.cc b/src/monster2.cc index 4599f8b6..f8a83d9a 100644 --- a/src/monster2.cc +++ b/src/monster2.cc @@ -430,7 +430,6 @@ static cptr funny_comments[MAX_COMMENT] = */ void delete_monster_idx(int i) { - auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; auto &random_artifacts = game->random_artifacts; @@ -499,9 +498,9 @@ void delete_monster_idx(int i) { random_artifacts[o_ptr->sval].generated = FALSE; } - else if (k_info.at(o_ptr->k_idx).flags & TR_NORM_ART) + else if (o_ptr->k_ptr->flags & TR_NORM_ART) { - k_info.at(o_ptr->k_idx).artifact = FALSE; + o_ptr->k_ptr->artifact = FALSE; } else { @@ -1886,7 +1885,6 @@ void update_monsters(bool_ full) void monster_carry(monster_type *m_ptr, int m_idx, object_type *q_ptr) { - auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; auto &random_artifacts = game->random_artifacts; @@ -1916,9 +1914,9 @@ void monster_carry(monster_type *m_ptr, int m_idx, object_type *q_ptr) { a_info[q_ptr->name1].cur_num = 0; } - else if (k_info.at(q_ptr->k_idx).flags & TR_NORM_ART) + else if (q_ptr->k_ptr->flags & TR_NORM_ART) { - k_info.at(q_ptr->k_idx).artifact = 0; + q_ptr->k_ptr->artifact = 0; } else if (q_ptr->tval == TV_RANDART) { @@ -1952,20 +1950,24 @@ static int possible_randart[] = }; -bool_ kind_is_randart(int k_idx) +static bool kind_is_randart(int k_idx) { auto const &k_info = game->edit_data.k_info; - int max; - auto k_ptr = &k_info.at(k_idx); - - if (!kind_is_legal(k_idx)) return (FALSE); + if (!kind_is_legal(k_idx)) + { + return false; + } - for (max = 0; possible_randart[max] != -1; max++) + for (int max = 0; possible_randart[max] != -1; max++) { - if (k_ptr->tval == possible_randart[max]) return (TRUE); + if (k_info.at(k_idx)->tval == possible_randart[max]) + { + return true; + } } - return (FALSE); + + return false; } /* diff --git a/src/object1.cc b/src/object1.cc index 091c5046..8baa0f34 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -330,7 +330,7 @@ static char scroll_adj[MAX_TITLES][16]; static byte scroll_col[MAX_TITLES]; -static byte object_flavor(object_kind const *k_ptr) +static byte object_flavor(std::shared_ptr<object_kind> k_ptr) { /* Analyze the item */ switch (k_ptr->tval) @@ -393,7 +393,7 @@ static byte object_flavor(object_kind const *k_ptr) * * XXX XXX XXX Add "EASY_KNOW" flag to "k_info.txt" file */ -static bool_ object_easy_know(object_kind const *k_ptr) +static bool_ object_easy_know(std::shared_ptr<object_kind> k_ptr) { /* Analyze the "tval" */ switch (k_ptr->tval) @@ -594,7 +594,7 @@ void flavor_init() /* Analyze every object */ for (auto &k_entry: k_info) { - auto k_ptr = &k_entry.second; + auto const &k_ptr = k_entry.second; /* Extract "flavor" (if any) */ k_ptr->flavor = object_flavor(k_ptr); @@ -651,11 +651,11 @@ void reset_visuals() /* Extract default attr/char code for objects */ for (auto &k_entry: k_info) { - auto &k_ref = k_entry.second; + auto k_ptr = k_entry.second; /* Default attr/char */ - k_ref.x_attr = k_ref.d_attr; - k_ref.x_char = k_ref.d_char; + k_ptr->x_attr = k_ptr->d_attr; + k_ptr->x_char = k_ptr->d_char; } /* Extract default attr/char code for monsters */ @@ -785,13 +785,15 @@ bool_ object_flags_no_set = FALSE; */ object_flag_set object_flags(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; - auto k_ptr = &k_info.at(o_ptr->k_idx); + if (!o_ptr->k_ptr) + { + return object_flag_set(); + } /* Base object */ - auto f = k_ptr->flags; + auto f = o_ptr->k_ptr->flags; /* Artifact */ if (o_ptr->name1) @@ -818,15 +820,11 @@ object_flag_set object_flags(object_type const *o_ptr) /* Return object granted power */ int object_power(object_type *o_ptr) { - auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; - auto k_ptr = &k_info.at(o_ptr->k_idx); - int power = -1; - /* Base object */ - power = k_ptr->power; + int power = o_ptr->k_ptr->power; /* Ego-item */ if (o_ptr->name2) @@ -870,17 +868,16 @@ int object_power(object_type *o_ptr) */ object_flag_set object_flags_known(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; - auto k_ptr = &k_info.at(o_ptr->k_idx); - /* Must be identified */ if (!object_known_p(o_ptr)) { return object_flag_set(); } + auto k_ptr = o_ptr->k_ptr; + /* Base object */ auto flags = k_ptr->flags; @@ -1031,7 +1028,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) bool_ show_weapon = FALSE; bool_ show_armour = FALSE; - auto k_ptr = &k_info.at(o_ptr->k_idx); + auto k_ptr = o_ptr->k_ptr; /* Extract some flags */ auto const flags = object_flags(o_ptr); @@ -1046,7 +1043,13 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) auto const indexx = o_ptr->sval; /* Extract default "base" string */ - std::string basenm(k_ptr->name); + std::string k_name; + if (k_ptr) + { + k_name = k_ptr->name; + } + + std::string basenm(k_name); /* Assume no "modifier" string */ std::string modstr; @@ -1120,7 +1123,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) if (known && o_ptr->artifact_name.empty() && artifact_p(o_ptr)) { - basenm = k_ptr->name; + basenm = k_name; } break; @@ -1143,7 +1146,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) if (known && o_ptr->artifact_name.empty() && artifact_p(o_ptr)) { - basenm = k_ptr->name; + basenm = k_name; } break; @@ -1192,7 +1195,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) case TV_ROD_MAIN: { - modstr = k_info.at(lookup_kind(TV_ROD, o_ptr->pval)).name; + modstr = k_info.at(lookup_kind(TV_ROD, o_ptr->pval))->name; break; } @@ -1361,7 +1364,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) case TV_DAEMON_BOOK: case TV_BOOK: { - basenm = k_ptr->name; + basenm = k_name; if (o_ptr->sval == 255) { modstr = spell_type_name(spell_at(o_ptr->pval)); @@ -1377,7 +1380,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Mega Hack */ if ((!hack_name) && known && (k_ptr->flags & TR_FULL_NAME)) { - basenm = k_ptr->name; + basenm = k_name; } /* Copy of the base string _without_ a prefix */ @@ -1634,7 +1637,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } else { - t += k_ptr->name; + t += k_name; } } @@ -2050,10 +2053,8 @@ void object_desc(char *buf, object_type const *o_ptr, int pref, int mode) */ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) { - auto &k_info = game->edit_data.k_info; - /* Save the "aware" flag */ - bool_ hack_aware = k_info.at(o_ptr->k_idx).aware; + bool_ hack_aware = o_ptr->k_ptr->aware; /* Save the "known" flag */ bool_ hack_known = (o_ptr->ident & (IDENT_KNOWN)) ? TRUE : FALSE; @@ -2063,7 +2064,7 @@ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) o_ptr->ident |= (IDENT_KNOWN); /* Force "aware" for description */ - k_info.at(o_ptr->k_idx).aware = TRUE; + o_ptr->k_ptr->aware = TRUE; /* Describe the object */ @@ -2071,7 +2072,7 @@ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) /* Restore "aware" flag */ - k_info.at(o_ptr->k_idx).aware = hack_aware; + o_ptr->k_ptr->aware = hack_aware; /* Clear the known flag */ if (!hack_known) o_ptr->ident &= ~(IDENT_KNOWN); @@ -2434,7 +2435,6 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait { auto const &set_info = game->edit_data.set_info; auto const &st_info = game->edit_data.st_info; - auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; cptr vp[64]; @@ -2478,11 +2478,9 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if (object_known_p(o_ptr)) { - if (o_ptr->k_idx && (!trim_down)) + if (o_ptr->k_ptr && (!trim_down)) { - auto k_ptr = &k_info.at(o_ptr->k_idx); - - text_out_c(TERM_ORANGE, k_ptr->text); + text_out_c(TERM_ORANGE, o_ptr->k_ptr->text); text_out("\n"); } @@ -3434,7 +3432,7 @@ static s16b label_to_inven(int c) if ((i < 0) || (i > INVEN_PACK)) return ( -1); /* Empty slots can never be chosen */ - if (!p_ptr->inventory[i].k_idx) return ( -1); + if (!p_ptr->inventory[i].k_ptr) return ( -1); /* Return the index */ return (i); @@ -3456,7 +3454,7 @@ static s16b label_to_equip(int c) if ((i < INVEN_WIELD) || (i >= INVEN_TOTAL)) return ( -1); /* Empty slots can never be chosen */ - if (!p_ptr->inventory[i].k_idx) return ( -1); + if (!p_ptr->inventory[i].k_ptr) return ( -1); /* Return the index */ return (i); @@ -3479,7 +3477,10 @@ static int get_slot(int slot) if (p_ptr->body_parts[slot + i - INVEN_WIELD]) { /* Free ? return the slot */ - if (!p_ptr->inventory[slot + i].k_idx) return (slot + i); + if (!p_ptr->inventory[slot + i].k_ptr) + { + return (slot + i); + } } else break; @@ -3578,60 +3579,73 @@ s16b wield_slot_ideal(object_type const *o_ptr, bool_ ideal) case TV_SHOT: { + auto quiver_ptr = &p_ptr->inventory[INVEN_AMMO]; + auto launcher_ptr = &p_ptr->inventory[INVEN_BOW]; + if (ideal) { return INVEN_AMMO; } - else if (p_ptr->inventory[INVEN_AMMO].k_idx && - object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO]) && - p_ptr->inventory[INVEN_AMMO].number + o_ptr->number < MAX_STACK_SIZE) + else if (quiver_ptr->k_ptr && + object_similar(o_ptr, quiver_ptr) && + quiver_ptr->number + o_ptr->number < MAX_STACK_SIZE) { return get_slot(INVEN_AMMO); } - else if ((p_ptr->inventory[INVEN_BOW].k_idx) && (p_ptr->inventory[INVEN_BOW].tval == TV_BOW)) + else if (launcher_ptr->k_ptr && + (launcher_ptr->tval == TV_BOW) && + (launcher_ptr->sval < 10)) { - if (p_ptr->inventory[INVEN_BOW].sval < 10) - return get_slot(INVEN_AMMO); + return get_slot(INVEN_AMMO); } return -1; } case TV_ARROW: { + auto quiver_ptr = &p_ptr->inventory[INVEN_AMMO]; + auto launcher_ptr = &p_ptr->inventory[INVEN_BOW]; + if (ideal) { return INVEN_AMMO; } - else if (p_ptr->inventory[INVEN_AMMO].k_idx && - object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO]) && - p_ptr->inventory[INVEN_AMMO].number + o_ptr->number < MAX_STACK_SIZE) + else if (quiver_ptr->k_ptr && + object_similar(o_ptr, quiver_ptr) && + quiver_ptr->number + o_ptr->number < MAX_STACK_SIZE) { return get_slot(INVEN_AMMO); } - else if ((p_ptr->inventory[INVEN_BOW].k_idx) && (p_ptr->inventory[INVEN_BOW].tval == TV_BOW)) + else if (launcher_ptr->k_ptr && + (launcher_ptr->tval == TV_BOW) && + (launcher_ptr->sval >= 10) && + (launcher_ptr->sval < 20)) { - if ((p_ptr->inventory[INVEN_BOW].sval >= 10) && (p_ptr->inventory[INVEN_BOW].sval < 20)) - return get_slot(INVEN_AMMO); + return get_slot(INVEN_AMMO); } return -1; } case TV_BOLT: { + auto quiver_ptr = &p_ptr->inventory[INVEN_AMMO]; + auto launcher_ptr = &p_ptr->inventory[INVEN_BOW]; + if (ideal) { return INVEN_AMMO; } - else if (p_ptr->inventory[INVEN_AMMO].k_idx && - object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO]) && - p_ptr->inventory[INVEN_AMMO].number + o_ptr->number < MAX_STACK_SIZE) + else if (quiver_ptr->k_ptr && + object_similar(o_ptr, quiver_ptr) && + quiver_ptr->number + o_ptr->number < MAX_STACK_SIZE) { return get_slot(INVEN_AMMO); } - else if ((p_ptr->inventory[INVEN_BOW].k_idx) && (p_ptr->inventory[INVEN_BOW].tval == TV_BOW)) + else if ((launcher_ptr->k_ptr) && + (launcher_ptr->tval == TV_BOW) && + (launcher_ptr->sval >= 20)) { - if (p_ptr->inventory[INVEN_BOW].sval >= 20) - return get_slot(INVEN_AMMO); + return get_slot(INVEN_AMMO); } return -1; } @@ -3884,7 +3898,7 @@ static bool item_tester_okay(object_type const *o_ptr, object_filter_t const &fi } /* Require an item */ - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { return false; } @@ -3989,7 +4003,10 @@ void show_inven_aux(bool_ mirror, const object_filter_t &filter) o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Track */ z = i + 1; @@ -4067,7 +4084,10 @@ void show_inven_aux(bool_ mirror, const object_filter_t &filter) byte a = object_attr(o_ptr); char c = object_char(o_ptr); - if (!o_ptr->k_idx) c = ' '; + if (!o_ptr->k_ptr) + { + c = ' '; + } Term_draw(col + 3, row + j, a, c); } @@ -4185,8 +4205,8 @@ void show_equip_aux(bool_ mirror, object_filter_t const &filter) /* Inform the player that he/she can't use a shield */ if ((p_ptr->body_parts[i - INVEN_WIELD] == INVEN_ARM) && - !o_ptr->k_idx && - p_ptr->inventory[i - INVEN_ARM + INVEN_WIELD].k_idx) + !o_ptr->k_ptr && + p_ptr->inventory[i - INVEN_ARM + INVEN_WIELD].k_ptr) { object_type *q_ptr = &p_ptr->inventory[i - INVEN_ARM + INVEN_WIELD]; char q_name[80]; @@ -4217,7 +4237,7 @@ void show_equip_aux(bool_ mirror, object_filter_t const &filter) } if ((p_ptr->body_parts[i - INVEN_WIELD] == INVEN_WIELD) && - !o_ptr->k_idx) + !o_ptr->k_ptr) { sprintf(o_name, "(%s)", get_melee_name()); @@ -4310,7 +4330,10 @@ void show_equip_aux(bool_ mirror, object_filter_t const &filter) byte a = object_attr(o_ptr); char c = object_char(o_ptr); - if (!o_ptr->k_idx) c = ' '; + if (!o_ptr->k_ptr) + { + c = ' '; + } Term_draw(col + 3, row + j, a, c); } @@ -4497,7 +4520,7 @@ static int get_tag(int *cp, char tag) object_type *o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { continue; } @@ -6124,39 +6147,45 @@ static void apply_flags_set(s16b a_idx, s16b set_idx, object_flag_set *f) byte object_attr(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; auto const &random_artifacts = game->random_artifacts; if (o_ptr->tval == TV_RANDART) { return random_artifacts[o_ptr->sval].attr; } - else if (k_info.at(o_ptr->k_idx).flavor) + else if (!o_ptr->k_ptr) + { + return 0; + } + else if (o_ptr->k_ptr->flavor) { - return misc_to_attr[k_info.at(o_ptr->k_idx).flavor]; + return misc_to_attr[o_ptr->k_ptr->flavor]; } else { - return k_info.at(o_ptr->k_idx).x_attr; + return o_ptr->k_ptr->x_attr; } } byte object_attr_default(object_type *o_ptr) { - auto const &k_info = game->edit_data.k_info; auto const &random_artifacts = game->random_artifacts; if (o_ptr->tval == TV_RANDART) { return random_artifacts[o_ptr->sval].attr; } - else if (k_info.at(o_ptr->k_idx).flavor) + else if (!o_ptr->k_ptr) + { + return 0; + } + else if (o_ptr->k_ptr->flavor) { - return misc_to_attr[k_info.at(o_ptr->k_idx).flavor]; + return misc_to_attr[o_ptr->k_ptr->flavor]; } else { - return k_info.at(o_ptr->k_idx).d_attr; + return o_ptr->k_ptr->d_attr; } } @@ -6168,29 +6197,35 @@ byte object_attr_default(object_type *o_ptr) char object_char(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; + if (!o_ptr->k_ptr) + { + return '\0'; + } - if (k_info.at(o_ptr->k_idx).flavor) + if (o_ptr->k_ptr->flavor) { - return misc_to_char[k_info.at(o_ptr->k_idx).flavor]; + return misc_to_char[o_ptr->k_ptr->flavor]; } else { - return k_info.at(o_ptr->k_idx).x_char; + return o_ptr->k_ptr->x_char; } } char object_char_default(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; + if (!o_ptr->k_ptr) + { + return '\0'; + } - if (k_info.at(o_ptr->k_idx).flavor) + if (o_ptr->k_ptr->flavor) { - return misc_to_char[k_info.at(o_ptr->k_idx).flavor]; + return misc_to_char[o_ptr->k_ptr->flavor]; } else { - return k_info.at(o_ptr->k_idx).d_char; + return o_ptr->k_ptr->d_char; } } @@ -6199,13 +6234,11 @@ char object_char_default(object_type const *o_ptr) */ bool artifact_p(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; - return (o_ptr->tval == TV_RANDART) || (o_ptr->name1 ? true : false) || (!o_ptr->artifact_name.empty()) || - ((k_info.at(o_ptr->k_idx).flags & TR_NORM_ART) ? true : false); + ((o_ptr->k_ptr && (o_ptr->k_ptr->flags & TR_NORM_ART)) ? true : false); } /** diff --git a/src/object2.cc b/src/object2.cc index 4b29fb6e..54656edf 100644 --- a/src/object2.cc +++ b/src/object2.cc @@ -56,13 +56,15 @@ */ s32b calc_total_weight() { - int i; s32b total; - for (i = total = 0; i < INVEN_TOTAL; i++) + for (int i = total = 0; i < INVEN_TOTAL; i++) { object_type *o_ptr = &p_ptr->inventory[i]; - if (o_ptr->k_idx) total += o_ptr->weight * o_ptr->number; + if (o_ptr->k_ptr) + { + total += o_ptr->weight * o_ptr->number; + } } return total; } @@ -239,10 +241,7 @@ static void compact_objects_aux(int i1, int i2) */ void compact_objects(int size) { - auto const &k_info = game->edit_data.k_info; - int i, y, x, num; - int cur_lev, cur_dis, chance; /* Compact */ @@ -269,11 +268,10 @@ void compact_objects(int size) for (i = 1; i < o_max; i++) { object_type *o_ptr = &o_list[i]; - - auto k_ptr = &k_info.at(o_ptr->k_idx); + auto const &k_ptr = o_ptr->k_ptr; /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) continue; /* High level objects are "immune" as long as we're not desperate enough */ if (k_ptr->level > cur_lev) continue; @@ -352,7 +350,10 @@ void compact_objects(int size) object_type *o_ptr = &o_list[i]; /* Skip real objects */ - if (o_ptr->k_idx) continue; + if (o_ptr->k_ptr) + { + continue; + } /* Move last object into open hole */ compact_objects_aux(o_max - 1, i); @@ -378,18 +379,18 @@ void compact_objects(int size) */ void wipe_o_list() { - auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; - int i; - /* Delete the existing objects */ - for (i = 1; i < o_max; i++) + for (int i = 1; i < o_max; i++) { object_type *o_ptr = &o_list[i]; /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Mega-Hack -- preserve artifacts */ if (!character_dungeon || options->preserve) @@ -402,9 +403,9 @@ void wipe_o_list() { game->random_artifacts[o_ptr->sval].generated = FALSE; } - else if (k_info.at(o_ptr->k_idx).flags & TR_NORM_ART) + else if (o_ptr->k_ptr->flags & TR_NORM_ART) { - k_info.at(o_ptr->k_idx).artifact = FALSE; + o_ptr->k_ptr->artifact = FALSE; } else { @@ -488,7 +489,10 @@ s16b o_pop() o_ptr = &o_list[i]; /* Skip live objects */ - if (o_ptr->k_idx) continue; + if (o_ptr->k_ptr) + { + continue; + } /* Count objects */ o_cnt++; @@ -594,7 +598,7 @@ s16b get_obj_num(int level) k_idx = entry.index; /* Access the actual kind */ - auto k_ptr = &k_info.at(k_idx); + auto const &k_ptr = k_info.at(k_idx); /* Hack -- prevent embedded chests */ if (opening_chest && (k_ptr->tval == TV_CHEST)) continue; @@ -729,10 +733,8 @@ void object_known(object_type *o_ptr) */ bool object_known_p(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; - - return ((o_ptr->ident & (IDENT_KNOWN)) || - (k_info.at(o_ptr->k_idx).easy_know && k_info.at(o_ptr->k_idx).aware)); + return ((o_ptr->ident & IDENT_KNOWN) || + (o_ptr->k_ptr && o_ptr->k_ptr->easy_know && o_ptr->k_ptr->aware)); } @@ -742,10 +744,8 @@ bool object_known_p(object_type const *o_ptr) */ void object_aware(object_type *o_ptr) { - auto &k_info = game->edit_data.k_info; - /* Fully aware of the effects */ - k_info.at(o_ptr->k_idx).aware = TRUE; + o_ptr->k_ptr->aware = TRUE; } /** @@ -753,9 +753,7 @@ void object_aware(object_type *o_ptr) */ bool object_aware_p(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; - - return k_info.at(o_ptr->k_idx).aware; + return o_ptr->k_ptr && o_ptr->k_ptr->aware; } @@ -764,10 +762,8 @@ bool object_aware_p(object_type const *o_ptr) */ void object_tried(object_type *o_ptr) { - auto &k_info = game->edit_data.k_info; - /* Mark it as tried (even if "aware") */ - k_info.at(o_ptr->k_idx).tried = TRUE; + o_ptr->k_ptr->tried = TRUE; } @@ -776,9 +772,7 @@ void object_tried(object_type *o_ptr) */ bool object_tried_p(object_type const *o_ptr) { - auto const &k_info = game->edit_data.k_info; - - return k_info.at(o_ptr->k_idx).tried; + return o_ptr->k_ptr->tried; } @@ -789,12 +783,12 @@ bool object_tried_p(object_type const *o_ptr) static s32b object_value_base(object_type const *o_ptr) { auto const &r_info = game->edit_data.r_info; - auto const &k_info = game->edit_data.k_info; - - auto k_ptr = &k_info.at(o_ptr->k_idx); /* Aware item -- use template cost */ - if ((object_aware_p(o_ptr)) && (o_ptr->tval != TV_EGG)) return (k_ptr->cost); + if ((object_aware_p(o_ptr)) && (o_ptr->tval != TV_EGG)) + { + return o_ptr->k_ptr->cost; + } /* Analyze the type */ switch (o_ptr->tval) @@ -1096,20 +1090,22 @@ s32b object_value_real(object_type const *o_ptr) auto const &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; - s32b value; - - auto k_ptr = &k_info.at(o_ptr->k_idx); - if (o_ptr->tval == TV_RANDART) { return game->random_artifacts[o_ptr->sval].cost; } + /* Get the object kind */ + auto k_ptr = o_ptr->k_ptr; + /* Hack -- "worthless" items */ - if (!k_ptr->cost) return (0L); + if (!k_ptr->cost) + { + return (0L); + } /* Base cost */ - value = k_ptr->cost; + s32b value = k_ptr->cost; /* Extract some flags */ auto const flags = object_flags(o_ptr); @@ -1292,7 +1288,7 @@ s32b object_value_real(object_type const *o_ptr) if (tip_idx > 0) { /* Add its cost */ - value += k_info.at(tip_idx).cost; + value += k_info.at(tip_idx)->cost; } /* Done */ @@ -1463,13 +1459,16 @@ bool_ object_similar(object_type const *o_ptr, object_type const *j_ptr) { int total = o_ptr->number + j_ptr->number; + /* Require identical object types */ + if (o_ptr->k_ptr != j_ptr->k_ptr) + { + return FALSE; + } + /* Extract the flags */ auto const o_flags = object_flags(o_ptr); auto const j_flags = object_flags(j_ptr); - /* Require identical object types */ - if (o_ptr->k_idx != j_ptr->k_idx) return (0); - if ((o_flags & TR_SPELL_CONTAIN) || (j_flags & TR_SPELL_CONTAIN)) return FALSE; @@ -1812,8 +1811,8 @@ s16b lookup_kind(int tval, int sval) for (auto const &k_entry: k_info) { - auto const &k_ref = k_entry.second; - if ((k_ref.tval == tval) && (k_ref.sval == sval)) + auto const &k_ptr = k_entry.second; + if ((k_ptr->tval == tval) && (k_ptr->sval == sval)) { return k_entry.first; } @@ -1851,7 +1850,7 @@ void object_copy(object_type *o_ptr, object_type *j_ptr) * Initialize the experience of an object which is a * "sentient" object. */ -static void init_obj_exp(object_type *o_ptr, object_kind const *k_ptr) +static void init_obj_exp(object_type *o_ptr, std::shared_ptr<object_kind const> k_ptr) { o_ptr->elevel = (k_ptr->level / 10) + 1; o_ptr->exp = player_exp[o_ptr->elevel - 1]; @@ -1864,14 +1863,14 @@ static void init_obj_exp(object_type *o_ptr, object_kind const *k_ptr) void object_prep(object_type *o_ptr, int k_idx) { auto const &k_info = game->edit_data.k_info; - - auto k_ptr = &k_info.at(k_idx); + auto k_ptr = k_info.at(k_idx); /* Clear the record */ object_wipe(o_ptr); /* Save the kind index */ o_ptr->k_idx = k_idx; + o_ptr->k_ptr = k_ptr; /* Efficiency -- tval/sval */ o_ptr->tval = k_ptr->tval; @@ -2075,7 +2074,7 @@ static void random_artifact_power(object_type *o_ptr) auto flags = &o_ptr->art_flags; // Choose ability - auto try_choose = [&o_ptr, &flags](int choice) { + auto try_choose = [&flags](int choice) { switch (choice) { case 0: @@ -2221,12 +2220,13 @@ static bool_ make_artifact_special(object_type *o_ptr) /* Find the base object */ int k_idx = lookup_kind(a_ptr->tval, a_ptr->sval); + auto const &k_ptr = k_info.at(k_idx); /* XXX XXX Enforce minimum "object" level (loosely) */ - if (k_info.at(k_idx).level > object_level) + if (k_ptr->level > object_level) { /* Acquire the "out-of-depth factor" */ - int d = (k_info.at(k_idx).level - object_level) * 5; + int d = (k_ptr->level - object_level) * 5; /* Roll for out-of-depth creation */ if (rand_int(d) != 0) continue; @@ -2244,7 +2244,7 @@ static bool_ make_artifact_special(object_type *o_ptr) /* Hack give a basic exp/exp level to an object that needs it */ if (flags & TR_LEVELS) { - init_obj_exp(o_ptr, &k_info.at(k_idx)); + init_obj_exp(o_ptr, k_ptr); } /* Success */ @@ -2263,10 +2263,9 @@ static bool_ make_artifact_special(object_type *o_ptr) * * Note -- see "make_artifact_special()" and "apply_magic()" */ -static bool_ make_artifact(object_type *o_ptr) +static bool make_artifact(object_type *o_ptr) { auto const &a_info = game->edit_data.a_info; - auto const &k_info = game->edit_data.k_info; /* No artifacts in the town */ if (!dun_level) return (FALSE); @@ -2320,7 +2319,7 @@ static bool_ make_artifact(object_type *o_ptr) /* Hack give a basic exp/exp level to an object that needs it */ if (flags & TR_LEVELS) { - init_obj_exp(o_ptr, &k_info.at(o_ptr->k_idx)); + init_obj_exp(o_ptr, o_ptr->k_ptr); } /* Success */ @@ -2338,11 +2337,9 @@ static bool_ make_artifact(object_type *o_ptr) */ static bool_ make_ego_item(object_type *o_ptr, bool_ good) { - auto const &k_info = game->edit_data.k_info; auto const &e_info = game->edit_data.e_info; bool_ ret = FALSE; - auto k_ptr = &k_info.at(o_ptr->k_idx); if (artifact_p(o_ptr) || o_ptr->name2) return (FALSE); @@ -2381,10 +2378,15 @@ static bool_ make_ego_item(object_type *o_ptr, bool_ good) if ((!good) && e_ptr->cost) continue; /* Must posses the good flags */ + auto k_ptr = o_ptr->k_ptr; if ((k_ptr->flags & e_ptr->need_flags) != e_ptr->need_flags) + { continue; + } if (k_ptr->flags & e_ptr->forbid_flags) + { continue; + } /* ok */ ok_ego.push_back(i); @@ -3166,10 +3168,8 @@ static int get_stick_max_level(byte tval, int level, int spl) static void a_m_aux_4(object_type *o_ptr, int level, int power) { auto const &r_info = game->edit_data.r_info; - auto const &k_info = game->edit_data.k_info; s32b bonus_lvl, max_lvl; - auto k_ptr = &k_info.at(o_ptr->k_idx); /* Very good */ if (power > 1) @@ -3221,9 +3221,9 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power) /* Hack -- random fuel */ if (flags & TR_FUEL_LITE) { - if (k_info.at(o_ptr->k_idx).pval2 > 0) + if (o_ptr->k_ptr->pval2 > 0) { - o_ptr->timeout = randint(k_info.at(o_ptr->k_idx).pval2); + o_ptr->timeout = randint(o_ptr->k_ptr->pval2); } } @@ -3302,6 +3302,8 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power) case TV_WAND: { + auto k_ptr = o_ptr->k_ptr; + /* Decide the spell, pval == -1 means to bypass spell selection */ if (o_ptr->pval != -1) { @@ -3332,6 +3334,8 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power) case TV_STAFF: { + auto k_ptr = o_ptr->k_ptr; + /* Decide the spell, pval == -1 means to bypass spell selection */ if (o_ptr->pval != -1) { @@ -3364,7 +3368,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power) case TV_CHEST: { /* Hack -- skip ruined chests */ - if (k_info.at(o_ptr->k_idx).level <= 0) break; + if (o_ptr->k_ptr->level <= 0) break; /* Hack - set pval2 to the number of objects in it */ if (o_ptr->pval) @@ -3863,19 +3867,20 @@ void add_random_ego_flag(object_type *o_ptr, ego_flag_set const &fego, bool_ *li */ void apply_magic(object_type *o_ptr, int lev, bool_ okay, bool_ good, bool_ great, boost::optional<int> force_power) { - auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; int i, rolls; - auto k_ptr = &k_info.at(o_ptr->k_idx); + auto k_ptr = o_ptr->k_ptr; /* Aply luck */ lev += luck( -7, 7); /* Spell in it? No! */ if (k_ptr->flags & TR_SPELL_CONTAIN) + { o_ptr->pval2 = -1; + } /* Important to do before all else, be sure to have the basic obvious flags set */ o_ptr->art_oflags = k_ptr->oflags; @@ -3886,7 +3891,7 @@ void apply_magic(object_type *o_ptr, int lev, bool_ okay, bool_ good, bool_ grea /* Ahah! we tried to trick us !! */ if (k_ptr->artifact || ((k_ptr->flags & TR_SPECIAL_GENE) && - (!k_info[o_ptr->k_idx].allow_special))) + (!k_ptr->allow_special))) { object_prep(o_ptr, lookup_kind(k_ptr->btval, k_ptr->bsval)); if (wizard) msg_print("We've been tricked!"); @@ -3988,7 +3993,10 @@ void apply_magic(object_type *o_ptr, int lev, bool_ okay, bool_ good, bool_ grea for (i = 0; i < rolls; i++) { /* Roll for an artifact */ - if (make_artifact(o_ptr)) break; + if (make_artifact(o_ptr)) + { + break; + } } /* Mega hack -- to lazy to do it properly with hooks :) */ @@ -4197,9 +4205,9 @@ try_an_other_ego: /* Examine real objects */ - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { - object_kind *k_ptr = &k_info.at(o_ptr->k_idx); + auto k_ptr = o_ptr->k_ptr; /* Hack -- acquire "cursed" flag */ if (k_ptr->flags & TR_CURSED) o_ptr->ident |= (IDENT_CURSED); @@ -4265,14 +4273,10 @@ bool init_match_theme(obj_theme const &theme) /* * Maga-Hack -- match certain types of object only. */ -static bool kind_is_theme(obj_theme const *theme, int k_idx) +static bool kind_is_theme(obj_theme const *theme, std::shared_ptr<object_kind const> k_ptr) { - auto const &k_info = game->edit_data.k_info; - assert(theme != nullptr); - auto k_ptr = &k_info.at(k_idx); - s32b prob = 0; /* @@ -4455,9 +4459,12 @@ bool_ kind_is_legal(int k_idx) { auto const &k_info = game->edit_data.k_info; - auto k_ptr = &k_info.at(k_idx); + auto k_ptr = k_info.at(k_idx); - if (!kind_is_theme(match_theme, k_idx)) return FALSE; + if (!kind_is_theme(match_theme, k_ptr)) + { + return FALSE; + } if (k_ptr->flags & TR_SPECIAL_GENE) { @@ -4499,8 +4506,7 @@ bool_ kind_is_legal(int k_idx) static bool_ kind_is_good(int k_idx) { auto const &k_info = game->edit_data.k_info; - - auto k_ptr = &k_info.at(k_idx); + auto const &k_ptr = k_info.at(k_idx); if (!kind_is_legal(k_idx)) return FALSE; @@ -4598,7 +4604,7 @@ bool_ kind_is_artifactable(int k_idx) auto const &ra_info = game->edit_data.ra_info; auto const &k_info = game->edit_data.k_info; - auto k_ptr = &k_info.at(k_idx); + auto k_ptr = k_info.at(k_idx); if (kind_is_good(k_idx)) { // Consider the item artifactable if there is at least one @@ -4636,12 +4642,10 @@ bool_ kind_is_artifactable(int k_idx) */ bool_ make_object(object_type *j_ptr, bool_ good, bool_ great, obj_theme const &theme) { - auto const &k_info = game->edit_data.k_info; auto &alloc = game->alloc; int invprob, base; - /* Chance of "special object" */ invprob = (good ? 10 - luck( -9, 9) : 1000); @@ -4721,14 +4725,17 @@ bool_ make_object(object_type *j_ptr, bool_ good, bool_ great, obj_theme const & } /* hack, no multiple artifacts */ - if (artifact_p(j_ptr)) j_ptr->number = 1; + if (artifact_p(j_ptr)) + { + j_ptr->number = 1; + } /* Notice "okay" out-of-depth objects */ - if (!cursed_p(j_ptr) && - (k_info.at(j_ptr->k_idx).level > dun_level)) + auto j_level = j_ptr->k_ptr->level; + if (!cursed_p(j_ptr) && (j_level > dun_level)) { /* Rating increase */ - rating += (k_info.at(j_ptr->k_idx).level - dun_level); + rating += (j_level - dun_level); /* Cheat -- peek at items */ if (options->cheat_peek || p_ptr->precognition) @@ -4755,7 +4762,6 @@ bool_ make_object(object_type *j_ptr, bool_ good, bool_ great, obj_theme const & void place_object(int y, int x, bool_ good, bool_ great, int where) { auto const &d_info = game->edit_data.d_info; - auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; auto &random_artifacts = game->random_artifacts; @@ -4841,9 +4847,9 @@ void place_object(int y, int x, bool_ good, bool_ great, int where) { a_info[q_ptr->name1].cur_num = 0; } - else if (k_info.at(q_ptr->k_idx).flags & TR_NORM_ART) + else if (q_ptr->k_ptr->flags & TR_NORM_ART) { - k_info.at(q_ptr->k_idx).artifact = 0; + q_ptr->k_ptr->artifact = 0; } else if (q_ptr->tval == TV_RANDART) { @@ -4887,7 +4893,7 @@ bool_ make_gold(object_type *j_ptr) object_prep(j_ptr, OBJ_GOLD_LIST + i); /* Hack -- Base coin cost */ - s32b const base = k_info.at(OBJ_GOLD_LIST + i).cost; + s32b const base = k_info.at(OBJ_GOLD_LIST + i)->cost; /* Determine how much the treasure is "worth" */ j_ptr->pval = (base + (8L * randint(base)) + randint(8)); @@ -4987,7 +4993,6 @@ void place_gold(int y, int x) s16b drop_near(object_type *j_ptr, int chance, int y, int x) { auto const &f_info = game->edit_data.f_info; - auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; auto &random_artifacts = game->random_artifacts; @@ -5213,9 +5218,9 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x) { a_info[j_ptr->name1].cur_num = 0; } - else if (k_info.at(j_ptr->k_idx).flags & TR_NORM_ART) + else if (j_ptr->k_ptr->flags & TR_NORM_ART) { - k_info.at(j_ptr->k_idx).artifact = 0; + j_ptr->k_ptr->artifact = 0; } else if (j_ptr->tval == TV_RANDART) { @@ -5391,17 +5396,23 @@ void inven_item_increase(int item, int num) /* * Erase an inventory slot if it has no more items */ -bool_ inven_item_optimize(int item) +void inven_item_optimize(int item) { auto const &a_info = game->edit_data.a_info; object_type *o_ptr = &p_ptr->inventory[item]; /* Only optimize real items */ - if (!o_ptr->k_idx) return (FALSE); + if (!o_ptr->k_ptr) + { + return; + } /* Only optimize empty items */ - if (o_ptr->number) return (FALSE); + if (o_ptr->number) + { + return; + } /* The item is in the pack */ if (item < INVEN_WIELD) @@ -5452,8 +5463,6 @@ bool_ inven_item_optimize(int item) /* Window stuff */ p_ptr->window |= (PW_EQUIP); } - - return (TRUE); } @@ -5533,7 +5542,7 @@ void floor_item_optimize(int item) object_type *o_ptr = &o_list[item]; /* Paranoia -- be sure it exists */ - if (!o_ptr->k_idx) return; + if (!o_ptr->k_ptr) return; /* Only optimize empty items */ if (o_ptr->number) return; @@ -5590,20 +5599,18 @@ void inc_stack_size_ex(int item, int delta, optimize_flag opt, describe_flag des */ bool_ inven_carry_okay(object_type const *o_ptr) { - int j; - if (o_ptr->tval == TV_GOLD) return FALSE; /* Empty slot? */ if (inven_cnt < INVEN_PACK) return (TRUE); /* Similar slot? */ - for (j = 0; j < INVEN_PACK; j++) + for (int j = 0; j < INVEN_PACK; j++) { object_type *j_ptr = &p_ptr->inventory[j]; /* Skip non-objects */ - if (!j_ptr->k_idx) continue; + if (!j_ptr->k_ptr) continue; /* Check if the two items can be combined */ if (object_similar(j_ptr, o_ptr)) return (TRUE); @@ -5649,7 +5656,10 @@ s16b inven_carry(object_type *o_ptr, bool_ final) j_ptr = &p_ptr->inventory[j]; /* Skip non-objects */ - if (!j_ptr->k_idx) continue; + if (!j_ptr->k_ptr) + { + continue; + } /* Hack -- track last item */ n = j; @@ -5674,7 +5684,10 @@ s16b inven_carry(object_type *o_ptr, bool_ final) /* Paranoia */ - if (inven_cnt > INVEN_PACK) return ( -1); + if (inven_cnt > INVEN_PACK) + { + return ( -1); + } /* Find an empty slot */ @@ -5683,7 +5696,10 @@ s16b inven_carry(object_type *o_ptr, bool_ final) j_ptr = &p_ptr->inventory[j]; /* Use it if found */ - if (!j_ptr->k_idx) break; + if (!j_ptr->k_ptr) + { + break; + } } /* Use that slot */ @@ -5704,7 +5720,10 @@ s16b inven_carry(object_type *o_ptr, bool_ final) j_ptr = &p_ptr->inventory[j]; /* Use empty slots */ - if (!j_ptr->k_idx) break; + if (!j_ptr->k_ptr) + { + break; + } /* Objects sort by decreasing type */ if (o_ptr->tval > j_ptr->tval) break; @@ -5978,35 +5997,37 @@ void inven_drop(int item, int amt, int dy, int dx, bool_ silent) */ void combine_pack() { - int i, j, k; - object_type *o_ptr; - object_type *j_ptr; - bool_ flag = FALSE; - + bool flag = FALSE; /* Combine the pack (backwards) */ - for (i = INVEN_PACK; i > 0; i--) + for (int i = INVEN_PACK; i > 0; i--) { /* Get the item */ - o_ptr = &p_ptr->inventory[i]; + auto o_ptr = &p_ptr->inventory[i]; /* Skip empty items */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Scan the items above that item */ - for (j = 0; j < i; j++) + for (int j = 0; j < i; j++) { /* Get the item */ - j_ptr = &p_ptr->inventory[j]; + auto j_ptr = &p_ptr->inventory[j]; /* Skip empty items */ - if (!j_ptr->k_idx) continue; + if (!j_ptr->k_ptr) + { + continue; + } /* Can we drop "o_ptr" onto "j_ptr"? */ if (object_similar(j_ptr, o_ptr)) { /* Take note */ - flag = TRUE; + flag = true; /* Add together the item counts */ object_absorb(j_ptr, o_ptr); @@ -6015,6 +6036,7 @@ void combine_pack() inven_cnt--; /* Slide everything down */ + int k; for (k = i; k < INVEN_PACK; k++) { /* Structure copy */ @@ -6034,7 +6056,10 @@ void combine_pack() } /* Message */ - if (flag) msg_print("You combine some items in your pack."); + if (flag) + { + msg_print("You combine some items in your pack."); + } } @@ -6065,7 +6090,10 @@ void reorder_pack() o_ptr = &p_ptr->inventory[i]; /* Skip empty slots */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Get the "value" of the item */ o_value = object_value(o_ptr); @@ -6077,7 +6105,10 @@ void reorder_pack() j_ptr = &p_ptr->inventory[j]; /* Use empty slots */ - if (!j_ptr->k_idx) break; + if (!j_ptr->k_ptr) + { + break; + } /* Objects sort by decreasing type */ if (o_ptr->tval > j_ptr->tval) break; diff --git a/src/object2.hpp b/src/object2.hpp index a91631aa..1c1f59e8 100644 --- a/src/object2.hpp +++ b/src/object2.hpp @@ -21,7 +21,7 @@ bool_ kind_is_legal(int k_idx); void inven_item_charges(int item); void inven_item_describe(int item); void inven_item_increase(int item, int num); -bool_ inven_item_optimize(int item); +void inven_item_optimize(int item); void floor_item_charges(int item); void floor_item_describe(int item); void floor_item_increase(int item, int num); diff --git a/src/object_kind_fwd.hpp b/src/object_kind_fwd.hpp new file mode 100644 index 00000000..6d26db9f --- /dev/null +++ b/src/object_kind_fwd.hpp @@ -0,0 +1,3 @@ +#pragma once + +struct object_kind; diff --git a/src/object_type.hpp b/src/object_type.hpp index 3a34d181..36a10fd9 100644 --- a/src/object_type.hpp +++ b/src/object_type.hpp @@ -2,7 +2,9 @@ #include "h-basic.h" #include "object_flag_set.hpp" +#include "object_kind_fwd.hpp" +#include <memory> #include <string> /** @@ -35,6 +37,7 @@ struct object_type { s16b k_idx = 0; /* Kind index (zero if "dead") */ + std::shared_ptr<object_kind> k_ptr; byte iy = 0; /* Y-position on map, or zero */ byte ix = 0; /* X-position on map, or zero */ diff --git a/src/powers.cc b/src/powers.cc index 2c4ebe3e..a9068b5e 100644 --- a/src/powers.cc +++ b/src/powers.cc @@ -130,7 +130,6 @@ static bool_ power_chance(power_type *x_ptr) static void power_activate(int power) { auto const &f_info = game->edit_data.f_info; - auto const &k_info = game->edit_data.k_info; s16b plev = p_ptr->lev; char ch = 0; @@ -804,10 +803,20 @@ static void power_activate(int power) { object_type *o_ptr = &p_ptr->inventory[i]; - if (!o_ptr->k_idx) continue; - if (!cursed_p(o_ptr)) continue; + if (!o_ptr->k_ptr) + { + continue; + } - if (!o_ptr->sense) o_ptr->sense = SENSE_CURSED; + if (!cursed_p(o_ptr)) + { + continue; + } + + if (!o_ptr->sense) + { + o_ptr->sense = SENSE_CURSED; + } } } break; @@ -887,7 +896,7 @@ static void power_activate(int power) o_ptr = get_object(item); - lev = k_info.at(o_ptr->k_idx).level; + lev = o_ptr->k_ptr->level; if (o_ptr->tval == TV_ROD_MAIN) { diff --git a/src/q_betwen.cc b/src/q_betwen.cc index 6b30d9c5..969c0450 100644 --- a/src/q_betwen.cc +++ b/src/q_betwen.cc @@ -20,12 +20,12 @@ #define cquest (quest[QUEST_BETWEEN]) -static object_kind *get_golden_horn() +static std::shared_ptr<object_kind> get_golden_horn() { static auto &k_info = game->edit_data.k_info; static auto &k_golden_horn = k_info[test_item_name("& Golden Horn~ of the Thunderlords")]; - return &k_golden_horn; + return k_golden_horn; } static bool quest_between_move_hook(void *, void *in_, void *) diff --git a/src/q_narsil.cc b/src/q_narsil.cc index 8d3c2775..adcbb7f0 100644 --- a/src/q_narsil.cc +++ b/src/q_narsil.cc @@ -37,11 +37,17 @@ static bool quest_narsil_move_hook(void *, void *in_, void *) /* Look out for Narsil */ for (i = 0; i < INVEN_TOTAL; i++) { - o_ptr = get_object(i); + o_ptr = &p_ptr->inventory[i]; - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } - if (o_ptr->name1 == ART_NARSIL) break; + if (o_ptr->name1 == ART_NARSIL) + { + break; + } } if (i == INVEN_TOTAL) diff --git a/src/q_one.cc b/src/q_one.cc index 8985b695..c6162397 100644 --- a/src/q_one.cc +++ b/src/q_one.cc @@ -327,7 +327,7 @@ static bool quest_one_death_hook(void *, void *in_, void *) for (i = 0; i < INVEN_PACK; i++) { /* Skip non-objects */ - if (!p_ptr->inventory[i].k_idx) + if (!p_ptr->inventory[i].k_ptr) { break; } diff --git a/src/q_rand.cc b/src/q_rand.cc index 9cbc19b4..d1948bc2 100644 --- a/src/q_rand.cc +++ b/src/q_rand.cc @@ -218,7 +218,6 @@ bool_ is_randhero(int level) static void do_get_new_obj(int y, int x) { - auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; object_type *q_ptr[3], forge[3]; @@ -272,9 +271,9 @@ static void do_get_new_obj(int y, int x) { game->random_artifacts[o_ptr->sval].generated = FALSE; } - else if (k_info.at(o_ptr->k_idx).flags & TR_NORM_ART) + else if (o_ptr->k_ptr->flags & TR_NORM_ART) { - k_info.at(o_ptr->k_idx).artifact = FALSE; + o_ptr->k_ptr->artifact = FALSE; } else if (o_ptr->name1) { diff --git a/src/q_thief.cc b/src/q_thief.cc index a4505d2a..6e89a622 100644 --- a/src/q_thief.cc +++ b/src/q_thief.cc @@ -70,7 +70,7 @@ static bool quest_thieves_gen_hook(void *, void *, void *) { object_type *o_ptr = &p_ptr->inventory[x]; - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { continue; } diff --git a/src/q_ultrag.cc b/src/q_ultrag.cc index 5865c093..c59febed 100644 --- a/src/q_ultrag.cc +++ b/src/q_ultrag.cc @@ -22,12 +22,12 @@ #define cquest (quest[QUEST_ULTRA_GOOD]) -static object_kind *get_flame_imperishable() +static std::shared_ptr<object_kind> get_flame_imperishable() { static auto &k_info = game->edit_data.k_info; static auto &k_flame_imperishable = k_info[test_item_name("& Flame~ Imperishable")]; - return &k_flame_imperishable; + return k_flame_imperishable; } static bool quest_ultra_good_move_hook(void *, void *in_, void *) @@ -141,9 +141,9 @@ static bool quest_ultra_good_stair_hook(void *, void *in_, void *) /* Now look for an ULTIMATE artifact, that is, one imbued with the flame */ for (i = INVEN_WIELD; i < INVEN_TOTAL; i++) { - object_type *o_ptr = get_object(i); + auto o_ptr = &p_ptr->inventory[i]; - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { continue; } @@ -251,7 +251,7 @@ static bool quest_ultra_good_death_hook(void *, void *in_, void *) for (i = 0; i < INVEN_PACK; i++) { /* Skip non-objects */ - if (!p_ptr->inventory[i].k_idx) + if (!p_ptr->inventory[i].k_ptr) { break; } diff --git a/src/skills.cc b/src/skills.cc index af5e46c7..f52af2c9 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -810,7 +810,7 @@ static void choose_melee() for (i = INVEN_WIELD; p_ptr->body_parts[i - INVEN_WIELD] == INVEN_WIELD; i++) { - if (p_ptr->inventory[i].k_idx) + if (p_ptr->inventory[i].k_ptr) { if (cursed_p(&p_ptr->inventory[i])) { @@ -1194,7 +1194,7 @@ void do_cmd_activate_skill() } o_ptr = get_object(INVEN_WIELD); - if ((o_ptr->k_idx <= 0) || + if ((!o_ptr->k_ptr) || (o_ptr->tval != TV_MSTAFF)) { msg_print("You must wield a magestaff to use Geomancy."); diff --git a/src/spells1.cc b/src/spells1.cc index ac6a2c09..c7db5403 100644 --- a/src/spells1.cc +++ b/src/spells1.cc @@ -1276,7 +1276,7 @@ void take_hit(int damage, cptr hit_from) } /* Hurt the wielded monster if any */ - if ((o_ptr->k_idx) && (magik(5 + get_skill(SKILL_SYMBIOTIC))) && (!carried_monster_hit)) + if (o_ptr->k_ptr && (magik(5 + get_skill(SKILL_SYMBIOTIC))) && (!carried_monster_hit)) { auto sym_name = symbiote_name(true); @@ -1779,25 +1779,21 @@ typedef int (*inven_func)(object_type *); */ static int inven_damage(inven_func typ, int perc) { - auto const &k_info = game->edit_data.k_info; - - int i, j, k, amt; - - object_type *o_ptr; - - char o_name[80]; - + int j, k, amt; /* Count the casualties */ k = 0; /* Scan through the slots backwards */ - for (i = 0; i < INVEN_PACK; i++) + for (int i = 0; i < INVEN_PACK; i++) { - o_ptr = &p_ptr->inventory[i]; + object_type *o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Hack -- for now, skip artifacts */ if (artifact_p(o_ptr)) continue; @@ -1815,6 +1811,7 @@ static int inven_damage(inven_func typ, int perc) if (amt) { /* Get a description */ + char o_name[80]; object_desc(o_name, o_ptr, FALSE, 3); /* Message */ @@ -1826,7 +1823,7 @@ static int inven_damage(inven_func typ, int perc) ((amt > 1) ? "were" : "was")); /* Potions smash open */ - if (k_info.at(o_ptr->k_idx).tval == TV_POTION) + if (o_ptr->k_ptr->tval == TV_POTION) { potion_smash_effect(0, p_ptr->py, p_ptr->px, o_ptr->sval); } @@ -1896,7 +1893,7 @@ static int minus_ac() } /* Nothing to damage */ - if (!o_ptr->k_idx) return (FALSE); + if (!o_ptr->k_ptr) return (FALSE); /* No damage left to be done */ if (o_ptr->ac + o_ptr->to_a <= 0) return (FALSE); @@ -2300,7 +2297,7 @@ bool_ apply_disenchant(int mode) o_ptr = &p_ptr->inventory[t]; /* No item, nothing happens */ - if (!o_ptr->k_idx) return (FALSE); + if (!o_ptr->k_ptr) return (FALSE); /* Nothing to disenchant */ @@ -3737,7 +3734,6 @@ static int raise_ego[MAX_RAISE] = static bool_ project_o(int who, int r, int y, int x, int dam, int typ) { auto const &r_info = game->edit_data.r_info; - auto const &k_info = game->edit_data.k_info; cave_type *c_ptr = &cave[y][x]; @@ -4071,7 +4067,7 @@ static bool_ project_o(int who, int r, int y, int x, int dam, int typ) } o_sval = o_ptr->sval; - is_potion = ((k_info.at(o_ptr->k_idx).tval == TV_POTION) || (k_info.at(o_ptr->k_idx).tval == TV_POTION2)); + is_potion = ((o_ptr->k_ptr->tval == TV_POTION) || (o_ptr->k_ptr->tval == TV_POTION2)); /* Delete the object */ diff --git a/src/spells2.cc b/src/spells2.cc index b90a0b9b..143cb9e0 100644 --- a/src/spells2.cc +++ b/src/spells2.cc @@ -478,15 +478,16 @@ void identify_hooks(int i, object_type *o_ptr, identify_mode mode) */ bool_ identify_pack() { - int i; - /* Simply identify and know every item */ - for (i = 0; i < INVEN_TOTAL; i++) + for (int i = 0; i < INVEN_TOTAL; i++) { object_type *o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Aware and Known */ object_aware(o_ptr); @@ -528,7 +529,10 @@ void identify_pack_fully() object_type *o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } make_item_fully_identified(o_ptr); @@ -556,7 +560,7 @@ static int enchant_table[16] = static bool_ remove_curse_object(object_type *o_ptr, bool_ all) { /* Skip non-objects */ - if (!o_ptr->k_idx) return FALSE; + if (!o_ptr->k_ptr) return FALSE; /* Uncursed already */ if (!cursed_p(o_ptr)) return FALSE; @@ -991,7 +995,7 @@ bool_ lose_all_info() object_type *o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) continue; /* Allow "protection" by the MENTAL flag */ if (o_ptr->ident & (IDENT_MENTAL)) continue; @@ -1299,7 +1303,7 @@ template <typename P> bool detect_objects_fn(int radius, const char *object_mess object_type *o_ptr = &o_list[i]; /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) continue; /* Location */ int y, x; @@ -2387,8 +2391,6 @@ object_filter_t const &item_tester_hook_recharge() */ bool_ recharge(int power) { - auto const &k_info = game->edit_data.k_info; - int recharge_strength, recharge_amount; int lev; bool_ fail = FALSE; @@ -2414,7 +2416,7 @@ bool_ recharge(int power) auto const flags = object_flags(o_ptr); /* Extract the object "level" */ - lev = k_info.at(o_ptr->k_idx).level; + lev = o_ptr->k_ptr->level; /* Recharge a rod */ if (o_ptr->tval == TV_ROD_MAIN) @@ -4655,7 +4657,7 @@ void activate_dg_curse() lose_all_info(); break; case 27: case 28: case 29: - if (p_ptr->inventory[INVEN_WIELD].k_idx) + if (p_ptr->inventory[INVEN_WIELD].k_ptr) { msg_print("Your weapon now seems useless..."); p_ptr->inventory[INVEN_WIELD].art_flags = TR_NEVER_BLOW; diff --git a/src/spells3.cc b/src/spells3.cc index d2f09a0e..325e58cd 100644 --- a/src/spells3.cc +++ b/src/spells3.cc @@ -2940,8 +2940,6 @@ static object_filter_t const &udun_object_is_drainable() casting_result udun_drain() { - auto const &k_info = game->edit_data.k_info; - /* Ask for an item */ int item; if (!get_item(&item, @@ -2961,10 +2959,8 @@ casting_result udun_drain() case TV_STAFF: case TV_WAND: { - auto k_ptr = &k_info.at(o_ptr->k_idx); - /* Generate mana */ - increase_mana(o_ptr->pval * k_ptr->level * o_ptr->number); + increase_mana(o_ptr->pval * o_ptr->k_ptr->level * o_ptr->number); /* Destroy it */ inc_stack_size(item, -99); diff --git a/src/spells6.cc b/src/spells6.cc index 555f252f..37d251a6 100644 --- a/src/spells6.cc +++ b/src/spells6.cc @@ -146,7 +146,7 @@ static bool_ geomancy_depends_satisfied() o_ptr = get_object(INVEN_WIELD); return ((o_ptr != NULL) && - (o_ptr->k_idx > 0) && + (o_ptr->k_ptr) && (o_ptr->tval == TV_MSTAFF)); } diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc index 72ac1c8b..2dae0971 100644 --- a/src/squelch/condition.cc +++ b/src/squelch/condition.cc @@ -878,9 +878,7 @@ void StateCondition::to_json(jsoncons::json &j) const bool SymbolCondition::is_match(object_type *o_ptr) const { - auto const &k_info = game->edit_data.k_info; - - return k_info.at(o_ptr->k_idx).d_char == m_symbol; + return o_ptr->k_ptr->d_char == m_symbol; } std::shared_ptr<Condition> SymbolCondition::from_json(jsoncons::json const &j) diff --git a/src/squeltch.cc b/src/squeltch.cc index e8ac4427..f55739d6 100644 --- a/src/squeltch.cc +++ b/src/squeltch.cc @@ -60,8 +60,6 @@ static squelch::Automatizer *automatizer = nullptr; void squeltch_grid() { - auto const &k_info = game->edit_data.k_info; - if (!automatizer_enabled) { return; @@ -77,7 +75,7 @@ void squeltch_grid() object_type * o_ptr = &o_list[this_o_idx]; // We've now seen one of these - if (!k_info.at(o_ptr->k_idx).flavor) + if (!o_ptr->k_ptr->flavor) { object_aware(o_ptr); } @@ -103,7 +101,7 @@ void squeltch_inventory() for (int i = 0; i < INVEN_PACK; i++) { object_type *o_ptr = &p_ptr->inventory[i]; - if ((o_ptr->k_idx > 0) && automatizer->apply_rules(o_ptr, i)) + if (o_ptr->k_ptr && automatizer->apply_rules(o_ptr, i)) { // We have changes changed = true; diff --git a/src/store.cc b/src/store.cc index 29d06d45..7ce167b8 100644 --- a/src/store.cc +++ b/src/store.cc @@ -488,7 +488,7 @@ static bool_ store_object_similar(object_type const *o_ptr, object_type *j_ptr) if (o_ptr == j_ptr) return (0); /* Different objects cannot be stacked */ - if (o_ptr->k_idx != j_ptr->k_idx) return (0); + if (o_ptr->k_ptr != j_ptr->k_ptr) return (0); /* Different charges (etc) cannot be stacked, unless wands or rods. */ if ((o_ptr->pval != j_ptr->pval) && (o_ptr->tval != TV_WAND)) return (0); @@ -1050,7 +1050,7 @@ static void store_item_optimize(int item) auto const o_ptr = &st_ptr->stock[item]; /* Must exist */ - if (!o_ptr->k_idx) return; + if (!o_ptr->k_ptr) return; /* Must have no items */ if (o_ptr->number) return; @@ -1090,7 +1090,10 @@ static bool_ black_market_crap(object_type *o_ptr) for (auto const &stock_obj: town_info[p_ptr->town_num].store[i].stock) { /* Duplicate item "type", assume crappy */ - if (o_ptr->k_idx == stock_obj.k_idx) return (TRUE); + if (o_ptr->k_ptr == stock_obj.k_ptr) + { + return (TRUE); + } } } @@ -1161,12 +1164,12 @@ static bool_ kind_is_storeok(int k_idx) { auto const &k_info = game->edit_data.k_info; - auto k_ptr = &k_info.at(k_idx); + auto k_ptr = k_info.at(k_idx); - if (k_info.at(k_idx).flags & TR_NORM_ART) + if (k_ptr->flags & TR_NORM_ART) return ( FALSE ); - if (k_info.at(k_idx).flags & TR_INSTA_ART) + if (k_ptr->flags & TR_INSTA_ART) return ( FALSE ); if (!kind_is_legal(k_idx)) return FALSE; @@ -1184,7 +1187,7 @@ struct is_artifact_p : public boost::static_visitor<bool> { bool operator ()(store_item_filter_by_k_idx f) const { auto const &k_info = game->edit_data.k_info; - return bool(k_info.at(f.k_idx).flags & TR_NORM_ART); + return bool(k_info.at(f.k_idx)->flags & TR_NORM_ART); } bool operator ()(store_item_filter_by_tval) const @@ -1373,13 +1376,18 @@ static void store_create() /* Only if not already done */ if (!obj_all_done) { + auto k_ptr = k_info.at(k_idx); /* Don't allow k_info artifacts */ - if (k_info.at(k_idx).flags & TR_NORM_ART) + if (k_ptr->flags & TR_NORM_ART) + { continue; + } /* Don't allow artifacts */ - if (k_info.at(k_idx).flags & TR_INSTA_ART) + if (k_ptr->flags & TR_INSTA_ART) + { continue; + } /* Get local object */ q_ptr = &forge; @@ -1396,7 +1404,7 @@ static void store_create() auto const flags = object_flags(q_ptr); if (flags & TR_FUEL_LITE) { - q_ptr->timeout = k_info.at(q_ptr->k_idx).pval2; + q_ptr->timeout = q_ptr->k_ptr->pval2; } } @@ -1472,7 +1480,10 @@ static void display_entry(int pos) byte a = object_attr(o_ptr); char c = object_char(o_ptr); - if (!o_ptr->k_idx) c = ' '; + if (!o_ptr->k_ptr) + { + c = ' '; + } Term_draw(cur_col, i + 6, a, c); cur_col += 2; @@ -3302,7 +3313,7 @@ void do_cmd_store() handle_stuff(); /* XXX XXX XXX Pack Overflow */ - if (p_ptr->inventory[INVEN_PACK].k_idx) + if (p_ptr->inventory[INVEN_PACK].k_ptr) { int item = INVEN_PACK; @@ -3331,24 +3342,18 @@ void do_cmd_store() /* Hack -- Drop items into the home */ else { - int item_pos; - - object_type forge; - object_type *q_ptr; - - char o_name[80]; - - /* Give a message */ msg_print("Your pack overflows!"); /* Get local object */ - q_ptr = &forge; + object_type forge; + auto q_ptr = &forge; /* Grab a copy of the item */ object_copy(q_ptr, o_ptr); /* Describe it */ + char o_name[80]; object_desc(o_name, q_ptr, TRUE, 3); /* Message */ @@ -3361,7 +3366,7 @@ void do_cmd_store() handle_stuff(); /* Let the home carry it */ - item_pos = home_carry(q_ptr); + int item_pos = home_carry(q_ptr); /* Redraw the home */ if (item_pos >= 0) @@ -3762,7 +3767,7 @@ void do_cmd_home_trump() handle_stuff(); /* XXX XXX XXX Pack Overflow */ - if (p_ptr->inventory[INVEN_PACK].k_idx) + if (p_ptr->inventory[INVEN_PACK].k_ptr) { int item = INVEN_PACK; @@ -3791,24 +3796,18 @@ void do_cmd_home_trump() /* Hack -- Drop items into the home */ else { - int item_pos; - - object_type forge; - object_type *q_ptr; - - char o_name[80]; - - /* Give a message */ msg_print("Your pack overflows!"); /* Get local object */ - q_ptr = &forge; + object_type forge; + auto q_ptr = &forge; /* Grab a copy of the item */ object_copy(q_ptr, o_ptr); /* Describe it */ + char o_name[80]; object_desc(o_name, q_ptr, TRUE, 3); /* Message */ @@ -3821,7 +3820,7 @@ void do_cmd_home_trump() handle_stuff(); /* Let the home carry it */ - item_pos = home_carry(q_ptr); + int const item_pos = home_carry(q_ptr); /* Redraw the home */ if (item_pos >= 0) diff --git a/src/util.cc b/src/util.cc index c9ee3999..1bada275 100644 --- a/src/util.cc +++ b/src/util.cc @@ -2991,7 +2991,10 @@ void request_command(int shopping) object_type *o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* No inscription */ if (o_ptr->inscription.empty()) @@ -3372,8 +3375,7 @@ int test_item_name(cptr needle) for (auto const &k_entry: k_info) { - auto const &name = k_entry.second.name; - if (iequals(needle, name)) + if (iequals(needle, k_entry.second->name)) { return k_entry.first; } diff --git a/src/wizard2.cc b/src/wizard2.cc index cee8feff..64eefb77 100644 --- a/src/wizard2.cc +++ b/src/wizard2.cc @@ -416,8 +416,6 @@ static void do_cmd_wiz_change() */ static void wiz_display_item(object_type *o_ptr) { - auto const &k_info = game->edit_data.k_info; - int i, j = 13; char buf[256]; @@ -433,7 +431,7 @@ static void wiz_display_item(object_type *o_ptr) prt(buf, 2, j); prt(format("kind = %-5d level = %-4d tval = %-5d sval = %-5d", - o_ptr->k_idx, k_info.at(o_ptr->k_idx).level, + o_ptr->k_idx, o_ptr->k_ptr->level, o_ptr->tval, o_ptr->sval), 4, j); prt(format("number = %-3d wgt = %-6d ac = %-5d damage = %dd%d", @@ -587,13 +585,16 @@ static int wiz_create_itemtype() choice.reserve(60); for (auto &k_entry: k_info) { - auto k_ptr = &k_entry.second; + auto const &k_ptr = k_entry.second; /* Analyze matching items */ if (k_ptr->tval == tval) { /* Hack -- Skip instant artifacts */ - if (k_ptr->flags & TR_INSTA_ART) continue; + if (k_ptr->flags & TR_INSTA_ART) + { + continue; + } /* Acquire the "name" of object */ auto buf = strip_name(k_ptr->name); @@ -1284,7 +1285,7 @@ void do_cmd_wiz_cure_all() /* Heal the player monster */ /* Get the carried monster */ o_ptr = &p_ptr->inventory[INVEN_CARRY]; - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { o_ptr->pval2 = o_ptr->pval3; } @@ -1374,7 +1375,7 @@ static void do_cmd_wiz_learn() /* Scan every object */ for (auto const &k_entry: k_info) { - auto const k_ptr = &k_entry.second; + auto const &k_ptr = k_entry.second; /* Induce awareness */ if (k_ptr->level <= command_arg) diff --git a/src/xtra1.cc b/src/xtra1.cc index 12dbfdbd..dcef2886 100644 --- a/src/xtra1.cc +++ b/src/xtra1.cc @@ -1414,9 +1414,12 @@ static void calc_powers() /* Add objects powers */ for (i = INVEN_WIELD; i < INVEN_TOTAL; i++) { - object_type *o_ptr = &p_ptr->inventory[i]; + auto o_ptr = &p_ptr->inventory[i]; - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } p = object_power(o_ptr); if (p != -1) @@ -1565,10 +1568,10 @@ static void calc_mana() auto const flags = object_flags(o_ptr); /* Normal gloves hurt mage-type spells */ - if (o_ptr->k_idx && - !(flags & TR_FREE_ACT) && - !((flags & TR_DEX) && (o_ptr->pval > 0)) && - !(flags & TR_SPELL_CONTAIN)) + if (o_ptr->k_ptr && + !(flags & TR_FREE_ACT) && + !((flags & TR_DEX) && (o_ptr->pval > 0)) && + !(flags & TR_SPELL_CONTAIN)) { /* Encumbered */ p_ptr->cumber_glove = TRUE; @@ -1821,7 +1824,10 @@ static void calc_torch() o_ptr = &p_ptr->inventory[i]; /* Skip empty slots */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Extract the flags */ auto const flags = object_flags(o_ptr); @@ -1908,7 +1914,7 @@ void calc_wield_monster() /* Get the carried monster */ auto o_ptr = &p_ptr->inventory[INVEN_CARRY]; - if (o_ptr->k_idx) + if (o_ptr->k_ptr) { auto r_ptr = &r_info[o_ptr->pval]; @@ -2041,7 +2047,7 @@ void calc_body() /* Ok now if the player lost a body part, he must drop the object he had on it */ for (i = 0; i < INVEN_TOTAL - INVEN_WIELD; i++) { - if ((!p_ptr->body_parts[i]) && (p_ptr->inventory[i + INVEN_WIELD].k_idx)) + if ((!p_ptr->body_parts[i]) && p_ptr->inventory[i + INVEN_WIELD].k_ptr) { /* Drop it NOW ! */ inven_takeoff(i + INVEN_WIELD, 255, TRUE); @@ -2129,7 +2135,7 @@ int get_weaponmastery_skill() { o_ptr = &p_ptr->inventory[INVEN_WIELD + i]; - if (!o_ptr->k_idx) + if (!o_ptr->k_ptr) { i++; continue; @@ -2604,19 +2610,19 @@ static void apply_lflags(LF const &lflags) */ static bool_ monk_empty_hands() { - int i; - object_type *o_ptr; - - if (p_ptr->melee_style != SKILL_HAND) return FALSE; - - i = 0; - while (p_ptr->body_parts[i] == INVEN_WIELD) + if (p_ptr->melee_style != SKILL_HAND) { - o_ptr = &p_ptr->inventory[INVEN_WIELD + i]; + return FALSE; + } - if (o_ptr->k_idx) return FALSE; + for (int i = 0; p_ptr->body_parts[i] == INVEN_WIELD; i++) + { + auto o_ptr = &p_ptr->inventory[INVEN_WIELD + i]; - i++; + if (o_ptr->k_ptr) + { + return FALSE; + } } return TRUE; @@ -2914,7 +2920,10 @@ void calc_bonuses(bool_ silent) o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_ptr) + { + continue; + } /* Extract the item flags */ object_flags_no_set = TRUE; @@ -2976,32 +2985,32 @@ void calc_bonuses(bool_ silent) /* Monks get extra ac for armour _not worn_ */ if ((p_ptr->melee_style == SKILL_HAND) && !(monk_heavy_armor())) { - if (!(p_ptr->inventory[INVEN_BODY].k_idx)) + if (!(p_ptr->inventory[INVEN_BODY].k_ptr)) { p_ptr->to_a += get_skill_scale(SKILL_HAND, 75); p_ptr->dis_to_a += get_skill_scale(SKILL_HAND, 75); } - if (!(p_ptr->inventory[INVEN_OUTER].k_idx) && (get_skill(SKILL_HAND) > 15)) + if (!(p_ptr->inventory[INVEN_OUTER].k_ptr) && (get_skill(SKILL_HAND) > 15)) { p_ptr->to_a += ((get_skill(SKILL_HAND) - 13) / 3); p_ptr->dis_to_a += ((get_skill(SKILL_HAND) - 13) / 3); } - if (!(p_ptr->inventory[INVEN_ARM].k_idx) && (get_skill(SKILL_HAND) > 10)) + if (!(p_ptr->inventory[INVEN_ARM].k_ptr) && (get_skill(SKILL_HAND) > 10)) { p_ptr->to_a += ((get_skill(SKILL_HAND) - 8) / 3); p_ptr->dis_to_a += ((get_skill(SKILL_HAND) - 8) / 3); } - if (!(p_ptr->inventory[INVEN_HEAD].k_idx) && (get_skill(SKILL_HAND) > 4)) + if (!(p_ptr->inventory[INVEN_HEAD].k_ptr) && (get_skill(SKILL_HAND) > 4)) { p_ptr->to_a += (get_skill(SKILL_HAND) - 2) / 3; p_ptr->dis_to_a += (get_skill(SKILL_HAND) - 2) / 3; } - if (!(p_ptr->inventory[INVEN_HANDS].k_idx)) + if (!(p_ptr->inventory[INVEN_HANDS].k_ptr)) { p_ptr->to_a += (get_skill(SKILL_HAND) / 2); p_ptr->dis_to_a += (get_skill(SKILL_HAND) / 2); } - if (!(p_ptr->inventory[INVEN_FEET].k_idx)) + if (!(p_ptr->inventory[INVEN_FEET].k_ptr)) { p_ptr->to_a += (get_skill(SKILL_HAND) / 3); p_ptr->dis_to_a += (get_skill(SKILL_HAND) / 3); @@ -3426,7 +3435,7 @@ void calc_bonuses(bool_ silent) } /* Compute "extra shots" if needed */ - if (o_ptr->k_idx && !p_ptr->heavy_shoot) + if (o_ptr->k_ptr && !p_ptr->heavy_shoot) { int archery = get_archery_skill(); @@ -3469,7 +3478,7 @@ void calc_bonuses(bool_ silent) o_ptr = &p_ptr->inventory[INVEN_TOOL]; /* Boost digging skill by tool weight */ - if (o_ptr->k_idx && (o_ptr->tval == TV_DIGGING)) + if (o_ptr->k_ptr && (o_ptr->tval == TV_DIGGING)) { p_ptr->skill_dig += (o_ptr->weight / 10); } @@ -3481,7 +3490,7 @@ void calc_bonuses(bool_ silent) p_ptr->heavy_wield = FALSE; /* Normal weapons */ - if (o_ptr->k_idx && !p_ptr->heavy_wield) + if (o_ptr->k_ptr && !p_ptr->heavy_wield) { int str_index, dex_index; @@ -3667,7 +3676,7 @@ void calc_bonuses(bool_ silent) o_ptr = &p_ptr->inventory[INVEN_WIELD + i]; /* 2handed weapon and shield = less damage */ - if (p_ptr->inventory[INVEN_WIELD + i].k_idx && p_ptr->inventory[INVEN_ARM + i].k_idx) + if (o_ptr->k_ptr && p_ptr->inventory[INVEN_ARM + i].k_ptr) { auto const flags = object_flags(&p_ptr->inventory[INVEN_WIELD + i]); if (flags & TR_COULD2H) @@ -3687,8 +3696,10 @@ void calc_bonuses(bool_ silent) } /* Priest weapon penalty for non-blessed edged weapons */ - if (((forbid_non_blessed()) && (!p_ptr->bless_blade) && - ((o_ptr->tval == TV_AXE) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM))) && (o_ptr->k_idx)) + if (((forbid_non_blessed()) && + (!p_ptr->bless_blade) && + ((o_ptr->tval == TV_AXE) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM))) && + o_ptr->k_ptr) { /* Reduce the real bonuses */ p_ptr->to_h -= 15; @@ -3707,7 +3718,8 @@ void calc_bonuses(bool_ silent) { int malus = get_skill_scale(SKILL_SORCERY, 100); - if ((o_ptr->tval != TV_MSTAFF) && (o_ptr->k_idx)) + if ((o_ptr->tval != TV_MSTAFF) && + o_ptr->k_ptr) { /* Reduce the real bonuses */ p_ptr->to_h -= malus; @@ -3793,7 +3805,7 @@ void calc_bonuses(bool_ silent) { msg_print("You have trouble wielding such a heavy bow."); } - else if (p_ptr->inventory[INVEN_BOW].k_idx) + else if (p_ptr->inventory[INVEN_BOW].k_ptr) { msg_print("You have no trouble wielding your bow."); } @@ -3819,7 +3831,7 @@ void calc_bonuses(bool_ silent) { msg_print("You have trouble wielding such a heavy weapon."); } - else if (p_ptr->inventory[INVEN_WIELD].k_idx) + else if (p_ptr->inventory[INVEN_WIELD].k_ptr) { msg_print("You have no trouble wielding your weapon."); } @@ -3845,7 +3857,7 @@ void calc_bonuses(bool_ silent) { msg_print("You do not feel comfortable with your weapon."); } - else if (p_ptr->inventory[INVEN_WIELD].k_idx) + else if (p_ptr->inventory[INVEN_WIELD].k_ptr) { msg_print("You feel comfortable with your weapon."); } @@ -4309,9 +4321,13 @@ void gain_fate(byte fate) /* Invalidate the cached allocation table */ alloc.kind_table_valid = false; - auto k_ptr = &k_info.at(fates[i].o_idx); + auto const &k_ptr = k_info.at(fates[i].o_idx); - if (!(k_ptr->flags & TR_INSTA_ART) && !(k_ptr->flags & TR_NORM_ART)) break; + if (!(k_ptr->flags & TR_INSTA_ART) + && !(k_ptr->flags & TR_NORM_ART)) + { + break; + } } level = rand_range(max_dlv[dungeon_type] - 20, max_dlv[dungeon_type] + 20); fates[i].level = (level < 1) ? 1 : (level > 98) ? 98 : level; diff --git a/src/xtra2.cc b/src/xtra2.cc index 2f582c89..def4f683 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -3090,7 +3090,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) auto const flags = object_flags(o_ptr); /* Can the weapon gain levels ? */ - if ((o_ptr->k_idx) && (flags & TR_LEVELS)) + if (o_ptr->k_ptr && (flags & TR_LEVELS)) { /* Give some experience for the kill */ const int new_exp = ((long)r_ptr->mexp * m_ptr->level) / (div * 2); @@ -4248,7 +4248,7 @@ static int target_set_aux(int y, int x, int mode, cptr info_) sv = c_ptr->special - SV_POTION_LAST; } - info = k_info.at(lookup_kind(tv, sv)).name; + info = k_info.at(lookup_kind(tv, sv))->name; } /* Display a message */ @@ -4985,7 +4985,7 @@ static bool_ test_object_wish(char *name, object_type *o_ptr, object_type *forge for (auto &k_entry: k_info) { - auto k_ptr = &k_entry.second; + auto k_ptr = k_entry.second; o_ptr = forge; |