diff --git a/src/autopick/autopick-destroyer.cpp b/src/autopick/autopick-destroyer.cpp index ea98d1f482..9fefa9d4ed 100644 --- a/src/autopick/autopick-destroyer.cpp +++ b/src/autopick/autopick-destroyer.cpp @@ -80,7 +80,7 @@ static bool is_opt_confirm_destroy(PlayerType *player_ptr, ItemEntity *o_ptr) } if (leave_worth) { - if (o_ptr->get_price() > 0) { + if (o_ptr->calc_price() > 0) { return false; } } diff --git a/src/autopick/autopick-matcher.cpp b/src/autopick/autopick-matcher.cpp index ae98c8f8d9..9ba0f5b28d 100644 --- a/src/autopick/autopick-matcher.cpp +++ b/src/autopick/autopick-matcher.cpp @@ -182,7 +182,7 @@ bool is_autopick_match(PlayerType *player_ptr, const ItemEntity *o_ptr, const au } } - if (entry.has(FLG_WORTHLESS) && (o_ptr->get_price() > 0)) { + if (entry.has(FLG_WORTHLESS) && (o_ptr->calc_price() > 0)) { return false; } diff --git a/src/cmd-item/cmd-destroy.cpp b/src/cmd-item/cmd-destroy.cpp index bdfbecc133..0e5eaeecec 100644 --- a/src/cmd-item/cmd-destroy.cpp +++ b/src/cmd-item/cmd-destroy.cpp @@ -45,7 +45,7 @@ using SelectionResult = std::tuple; static bool check_destory_item(PlayerType *player_ptr, const ItemEntity &destroying_item, short i_idx) { - if (!confirm_destroy && (destroying_item.get_price() <= 0)) { + if (!confirm_destroy && (destroying_item.calc_price() <= 0)) { return true; } diff --git a/src/cmd-item/cmd-equipment.cpp b/src/cmd-item/cmd-equipment.cpp index de0a1c7b46..50644bb136 100644 --- a/src/cmd-item/cmd-equipment.cpp +++ b/src/cmd-item/cmd-equipment.cpp @@ -55,7 +55,7 @@ /*! * @brief 装備時にアイテムを呪う処理 */ -static void do_curse_on_equip(OBJECT_IDX slot, ItemEntity *o_ptr, PlayerType *player_ptr) +static void do_curse_on_equip(OBJECT_IDX slot, ItemEntity &item, PlayerType *player_ptr) { auto &rfu = RedrawingFlagsUpdater::get_instance(); if (set_anubis_and_chariot(player_ptr) && ((slot == INVEN_MAIN_HAND) || (slot == INVEN_SUB_HAND))) { @@ -75,16 +75,16 @@ static void do_curse_on_equip(OBJECT_IDX slot, ItemEntity *o_ptr, PlayerType *pl return; } - auto should_curse = o_ptr->get_flags().has(TR_PERSISTENT_CURSE) || o_ptr->curse_flags.has(CurseTraitType::PERSISTENT_CURSE); - should_curse &= o_ptr->curse_flags.has_not(CurseTraitType::HEAVY_CURSE); + auto should_curse = item.get_flags().has(TR_PERSISTENT_CURSE) || item.curse_flags.has(CurseTraitType::PERSISTENT_CURSE); + should_curse &= item.curse_flags.has_not(CurseTraitType::HEAVY_CURSE); if (!should_curse) { return; } - const auto item_name = describe_flavor(player_ptr, *o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); - o_ptr->curse_flags.set(CurseTraitType::HEAVY_CURSE); + const auto item_name = describe_flavor(player_ptr, item, (OD_OMIT_PREFIX | OD_NAME_ONLY)); + item.curse_flags.set(CurseTraitType::HEAVY_CURSE); msg_format(_("悪意に満ちた黒いオーラが%sをとりまいた...", "There is a malignant black aura surrounding your %s..."), item_name.data()); - o_ptr->feeling = FEEL_NONE; + item.feeling = FEEL_NONE; rfu.set_flag(StatusRecalculatingFlag::BONUS); } @@ -336,7 +336,7 @@ void do_cmd_wield(PlayerType *player_ptr) o_ptr->ident |= (IDENT_SENSE); } - do_curse_on_equip(slot, o_ptr, player_ptr); + do_curse_on_equip(slot, *o_ptr, player_ptr); if (o_ptr->is_specific_artifact(FixedArtifactId::STONEMASK)) { auto is_specific_race = pr.equals(PlayerRaceType::VAMPIRE); is_specific_race |= pr.equals(PlayerRaceType::ANDROID); diff --git a/src/effect/effect-item.cpp b/src/effect/effect-item.cpp index d7bc1343c4..aa577b8a82 100644 --- a/src/effect/effect-item.cpp +++ b/src/effect/effect-item.cpp @@ -56,20 +56,20 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI processed_list.insert(this_o_idx); - auto *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx]; - bool ignore = false; - bool do_kill = false; + auto &item = player_ptr->current_floor_ptr->o_list[this_o_idx]; + auto ignore = false; + auto do_kill = false; concptr note_kill = nullptr; #ifdef JP #else - bool plural = (o_ptr->number > 1); + bool plural = (item.number > 1); #endif - const auto flags = o_ptr->get_flags(); - bool is_fixed_or_random_artifact = o_ptr->is_fixed_or_random_artifact(); + const auto flags = item.get_flags(); + bool is_fixed_or_random_artifact = item.is_fixed_or_random_artifact(); switch (typ) { case AttributeType::ACID: { - if (BreakerAcid().hates(o_ptr)) { + if (BreakerAcid().hates(&item)) { do_kill = true; note_kill = _("融けてしまった!", (plural ? " melt!" : " melts!")); if (flags.has(TR_IGNORE_ACID)) { @@ -80,7 +80,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI break; } case AttributeType::ELEC: { - if (BreakerElec().hates(o_ptr)) { + if (BreakerElec().hates(&item)) { do_kill = true; note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!")); if (flags.has(TR_IGNORE_ELEC)) { @@ -91,7 +91,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI break; } case AttributeType::FIRE: { - if (BreakerFire().hates(o_ptr)) { + if (BreakerFire().hates(&item)) { do_kill = true; note_kill = _("燃えてしまった!", (plural ? " burn up!" : " burns up!")); if (flags.has(TR_IGNORE_FIRE)) { @@ -102,7 +102,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI break; } case AttributeType::COLD: { - if (BreakerCold().hates(o_ptr)) { + if (BreakerCold().hates(&item)) { note_kill = _("砕け散ってしまった!", (plural ? " shatter!" : " shatters!")); do_kill = true; if (flags.has(TR_IGNORE_COLD)) { @@ -113,7 +113,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI break; } case AttributeType::PLASMA: { - if (BreakerFire().hates(o_ptr)) { + if (BreakerFire().hates(&item)) { do_kill = true; note_kill = _("燃えてしまった!", (plural ? " burn up!" : " burns up!")); if (flags.has(TR_IGNORE_FIRE)) { @@ -121,7 +121,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI } } - if (BreakerElec().hates(o_ptr)) { + if (BreakerElec().hates(&item)) { ignore = false; do_kill = true; note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!")); @@ -133,7 +133,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI break; } case AttributeType::METEOR: { - if (BreakerFire().hates(o_ptr)) { + if (BreakerFire().hates(&item)) { do_kill = true; note_kill = _("燃えてしまった!", (plural ? " burn up!" : " burns up!")); if (flags.has(TR_IGNORE_FIRE)) { @@ -141,7 +141,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI } } - if (BreakerCold().hates(o_ptr)) { + if (BreakerCold().hates(&item)) { ignore = false; do_kill = true; note_kill = _("砕け散ってしまった!", (plural ? " shatter!" : " shatters!")); @@ -156,7 +156,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI case AttributeType::SHARDS: case AttributeType::FORCE: case AttributeType::SOUND: { - if (BreakerCold().hates(o_ptr)) { + if (BreakerCold().hates(&item)) { note_kill = _("砕け散ってしまった!", (plural ? " shatter!" : " shatters!")); do_kill = true; } @@ -180,14 +180,14 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!")); if (flags.has(TR_RES_CHAOS)) { ignore = true; - } else if (o_ptr->bi_key == BaseitemKey(ItemKindType::SCROLL, SV_SCROLL_CHAOS)) { + } else if (item.bi_key == BaseitemKey(ItemKindType::SCROLL, SV_SCROLL_CHAOS)) { ignore = true; } break; } case AttributeType::HOLY_FIRE: case AttributeType::HELL_FIRE: { - if (o_ptr->is_cursed()) { + if (item.is_cursed()) { do_kill = true; note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!")); } @@ -200,23 +200,23 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI break; } case AttributeType::IDENTIFY: { - identify_item(player_ptr, o_ptr); + identify_item(player_ptr, &item); autopick_alter_item(player_ptr, (-this_o_idx), false); break; } case AttributeType::KILL_TRAP: case AttributeType::KILL_DOOR: { - if (o_ptr->bi_key.tval() != ItemKindType::CHEST) { + if (item.bi_key.tval() != ItemKindType::CHEST) { break; } - if (o_ptr->pval <= 0) { + if (item.pval <= 0) { break; } - o_ptr->pval = (0 - o_ptr->pval); - o_ptr->mark_as_known(); - if (known && o_ptr->marked.has(OmType::FOUND)) { + item.pval = (0 - item.pval); + item.mark_as_known(); + if (known && item.marked.has(OmType::FOUND)) { msg_print(_("カチッと音がした!", "Click!")); is_item_affected = true; } @@ -224,7 +224,7 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI break; } case AttributeType::ANIM_DEAD: { - if (o_ptr->bi_key.tval() != ItemKindType::MONSTER_REMAINS) { + if (item.bi_key.tval() != ItemKindType::MONSTER_REMAINS) { break; } @@ -233,9 +233,9 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI mode |= PM_FORCE_PET; } - for (int i = 0; i < o_ptr->number; i++) { - const auto &monrace = o_ptr->get_monrace(); - const auto sval = *o_ptr->bi_key.sval(); + for (int i = 0; i < item.number; i++) { + const auto &monrace = item.get_monrace(); + const auto sval = *item.bi_key.sval(); if (((sval == SV_CORPSE) && (randint1(100) > 80)) || ((sval == SV_SKELETON) && (randint1(100) > 60))) { if (!note_kill) { note_kill = _("灰になった。", (plural ? " become dust." : " becomes dust.")); @@ -262,25 +262,25 @@ bool affect_item(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POSITI } std::string item_name(""); - if (known && o_ptr->marked.has(OmType::FOUND)) { + if (known && item.marked.has(OmType::FOUND)) { is_item_affected = true; - item_name = describe_flavor(player_ptr, *o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); + item_name = describe_flavor(player_ptr, item, (OD_OMIT_PREFIX | OD_NAME_ONLY)); } if ((is_fixed_or_random_artifact || ignore)) { - if (known && o_ptr->marked.has(OmType::FOUND)) { + if (known && item.marked.has(OmType::FOUND)) { msg_format(_("%sは影響を受けない!", (plural ? "The %s are unaffected!" : "The %s is unaffected!")), item_name.data()); } continue; } - if (known && o_ptr->marked.has(OmType::FOUND) && note_kill) { + if (known && item.marked.has(OmType::FOUND) && note_kill) { msg_format(_("%sは%s", "The %s%s"), item_name.data(), note_kill); } - const auto bi_id = o_ptr->bi_id; - const auto is_potion = o_ptr->is_potion(); + const auto bi_id = item.bi_id; + const auto is_potion = item.is_potion(); delete_object_idx(player_ptr, this_o_idx); if (is_potion) { (void)potion_smash_effect(player_ptr, src_idx, y, x, bi_id); diff --git a/src/floor/floor-object.cpp b/src/floor/floor-object.cpp index 7250790431..fd526ae0aa 100644 --- a/src/floor/floor-object.cpp +++ b/src/floor/floor-object.cpp @@ -68,13 +68,12 @@ static errr get_obj_index_prep(void) * @param player_ptr プレイヤーへの参照ポインタ * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ */ -static void object_mention(PlayerType *player_ptr, ItemEntity *o_ptr) +static void object_mention(PlayerType *player_ptr, ItemEntity &item) { - object_aware(player_ptr, o_ptr); - o_ptr->mark_as_known(); - - o_ptr->ident |= (IDENT_FULL_KNOWN); - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + object_aware(player_ptr, &item); + item.mark_as_known(); + item.ident |= (IDENT_FULL_KNOWN); + const auto item_name = describe_flavor(player_ptr, item, 0); msg_format_wizard(player_ptr, CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), item_name.data()); } @@ -143,7 +142,7 @@ bool make_object(PlayerType *player_ptr, ItemEntity *j_ptr, BIT_FLAGS mode, std: ItemMagicApplier(player_ptr, j_ptr, floor_ptr->object_level, mode).execute(); set_ammo_quantity(j_ptr); if (cheat_peek) { - object_mention(player_ptr, j_ptr); + object_mention(player_ptr, *j_ptr); } return true; @@ -587,10 +586,10 @@ void floor_item_charges(FloorType *floor_ptr, INVENTORY_IDX i_idx) */ void floor_item_describe(PlayerType *player_ptr, INVENTORY_IDX i_idx) { - auto *o_ptr = &player_ptr->current_floor_ptr->o_list[i_idx]; - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + const auto &item = player_ptr->current_floor_ptr->o_list[i_idx]; + const auto item_name = describe_flavor(player_ptr, item, 0); #ifdef JP - if (o_ptr->number <= 0) { + if (item.number <= 0) { msg_format("床上には、もう%sはない。", item_name.data()); } else { msg_format("床上には、まだ %sがある。", item_name.data()); diff --git a/src/floor/floor-streams.cpp b/src/floor/floor-streams.cpp index ec6c2c6805..5c2cd31f22 100644 --- a/src/floor/floor-streams.cpp +++ b/src/floor/floor-streams.cpp @@ -351,16 +351,16 @@ void build_streamer(PlayerType *player_ptr, FEAT_IDX feat, int chance) /* Scan all objects in the grid */ for (const auto this_o_idx : grid.o_idx_list) { - auto *o_ptr = &floor.o_list[this_o_idx]; + auto &item = floor.o_list[this_o_idx]; /* Hack -- Preserve unknown artifacts */ - if (o_ptr->is_fixed_artifact()) { - o_ptr->get_fixed_artifact().is_generated = false; + if (item.is_fixed_artifact()) { + item.get_fixed_artifact().is_generated = false; if (cheat_peek) { - const auto item_name = describe_flavor(player_ptr, *o_ptr, (OD_NAME_ONLY | OD_STORE)); + const auto item_name = describe_flavor(player_ptr, item, (OD_NAME_ONLY | OD_STORE)); msg_format(_("伝説のアイテム (%s) はストリーマーにより削除された。", "Artifact (%s) was deleted by streamer."), item_name.data()); } - } else if (cheat_peek && o_ptr->is_random_artifact()) { + } else if (cheat_peek && item.is_random_artifact()) { msg_print(_("ランダム・アーティファクトの1つはストリーマーにより削除された。", "One of the random artifacts was deleted by streamer.")); } } diff --git a/src/floor/object-scanner.cpp b/src/floor/object-scanner.cpp index a6f5cdbb1f..4ca9739810 100644 --- a/src/floor/object-scanner.cpp +++ b/src/floor/object-scanner.cpp @@ -105,7 +105,6 @@ COMMAND_CODE show_floor_items(PlayerType *player_ptr, int target_item, POSITION { COMMAND_CODE i, m; int j, k, l; - ItemEntity *o_ptr; COMMAND_CODE out_index[23]{}; TERM_COLOR out_color[23]{}; std::array descriptions{}; @@ -117,12 +116,12 @@ COMMAND_CODE show_floor_items(PlayerType *player_ptr, int target_item, POSITION const auto &[wid, hgt] = term_get_size(); auto len = std::max((*min_width), 20); floor_num = scan_floor_items(player_ptr, floor_list, y, x, SCAN_FLOOR_ITEM_TESTER | SCAN_FLOOR_ONLY_MARKED, item_tester); - auto *floor_ptr = player_ptr->current_floor_ptr; + auto &floor = *player_ptr->current_floor_ptr; for (k = 0, i = 0; i < floor_num && i < 23; i++) { - o_ptr = &floor_ptr->o_list[floor_list[i]]; - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + const auto &item = floor.o_list[floor_list[i]]; + const auto item_name = describe_flavor(player_ptr, item, 0); out_index[k] = i; - const auto tval = o_ptr->bi_key.tval(); + const auto tval = item.bi_key.tval(); out_color[k] = tval_to_attr[enum2i(tval) & 0x7F]; descriptions[k] = item_name; l = descriptions[k].length() + 5; @@ -147,10 +146,10 @@ COMMAND_CODE show_floor_items(PlayerType *player_ptr, int target_item, POSITION *min_width = len; int col = (len > wid - 4) ? 0 : (wid - len - 1); - prepare_label_string_floor(floor_ptr, floor_label, floor_list, floor_num); + prepare_label_string_floor(&floor, floor_label, floor_list, floor_num); for (j = 0; j < k; j++) { m = floor_list[out_index[j]]; - o_ptr = &floor_ptr->o_list[m]; + const auto &item = floor.o_list[m]; prt("", j + 1, col ? col - 2 : col); std::string head; if (use_menu && target_item) { @@ -166,8 +165,8 @@ COMMAND_CODE show_floor_items(PlayerType *player_ptr, int target_item, POSITION put_str(head, j + 1, col); c_put_str(out_color[j], descriptions[j], j + 1, col + 3); - if (show_weights && (o_ptr->bi_key.tval() != ItemKindType::GOLD)) { - int wgt = o_ptr->weight * o_ptr->number; + if (show_weights && (item.bi_key.tval() != ItemKindType::GOLD)) { + int wgt = item.weight * item.number; const auto weight = format(_("%3d.%1d kg", "%3d.%1d lb"), _(lb_to_kg_integer(wgt), wgt / 10), _(lb_to_kg_fraction(wgt), wgt % 10)); prt(weight, j + 1, wid - 9); } diff --git a/src/hpmp/hp-mp-processor.cpp b/src/hpmp/hp-mp-processor.cpp index 56b2da9ebb..675e52d2af 100644 --- a/src/hpmp/hp-mp-processor.cpp +++ b/src/hpmp/hp-mp-processor.cpp @@ -141,15 +141,14 @@ void process_player_hp_mp(PlayerType *player_ptr) } } - const auto *o_ptr = &player_ptr->inventory_list[INVEN_LITE]; - const auto flags = o_ptr->get_flags(); - + const auto &item = player_ptr->inventory_list[INVEN_LITE]; + const auto flags = item.get_flags(); if ((player_ptr->inventory_list[INVEN_LITE].bi_key.tval() != ItemKindType::NONE) && flags.has_not(TR_DARK_SOURCE) && !has_resist_lite(player_ptr)) { - const auto item_name = describe_flavor(player_ptr, *o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); + const auto item_name = describe_flavor(player_ptr, item, (OD_OMIT_PREFIX | OD_NAME_ONLY)); msg_format(_("%sがあなたのアンデッドの肉体を焼き焦がした!", "The %s scorches your undead flesh!"), item_name.data()); cave_no_regen = true; if (!is_invuln(player_ptr)) { - const auto wielding_item_name = describe_flavor(player_ptr, *o_ptr, OD_NAME_ONLY); + const auto wielding_item_name = describe_flavor(player_ptr, item, OD_NAME_ONLY); std::stringstream ss; ss << _(wielding_item_name, "wielding ") << _("を装備したダメージ", wielding_item_name); take_hit(player_ptr, DAMAGE_NOESCAPE, 1, ss.str()); diff --git a/src/inventory/inventory-curse.cpp b/src/inventory/inventory-curse.cpp index 7c95688a14..6ea5a7e3fa 100644 --- a/src/inventory/inventory-curse.cpp +++ b/src/inventory/inventory-curse.cpp @@ -194,21 +194,20 @@ static void curse_teleport(PlayerType *player_ptr) return; } - ItemEntity *o_ptr; int i_keep = 0, count = 0; for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) { - o_ptr = &player_ptr->inventory_list[i]; - if (!o_ptr->is_valid()) { + const auto &item = player_ptr->inventory_list[i]; + if (!item.is_valid()) { continue; } - const auto flags = o_ptr->get_flags(); + const auto flags = item.get_flags(); if (flags.has_not(TR_TELEPORT)) { continue; } - if (o_ptr->is_inscribed() && angband_strchr(o_ptr->inscription->data(), '.')) { + if (item.is_inscribed() && angband_strchr(item.inscription->data(), '.')) { continue; } @@ -218,8 +217,8 @@ static void curse_teleport(PlayerType *player_ptr) } } - o_ptr = &player_ptr->inventory_list[i_keep]; - const auto item_name = describe_flavor(player_ptr, *o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); + const auto &item = player_ptr->inventory_list[i_keep]; + const auto item_name = describe_flavor(player_ptr, item, (OD_OMIT_PREFIX | OD_NAME_ONLY)); msg_format(_("%sがテレポートの能力を発動させようとしている。", "Your %s tries to teleport you."), item_name.data()); if (input_check_strict(player_ptr, _("テレポートしますか?", "Teleport? "), UserCheck::OKAY_CANCEL)) { disturb(player_ptr, false, true); @@ -292,8 +291,7 @@ static void multiply_high_curse(PlayerType *player_ptr) return; } - ItemEntity *o_ptr; - o_ptr = choose_cursed_obj_name(player_ptr, CurseTraitType::ADD_H_CURSE); + auto *o_ptr = choose_cursed_obj_name(player_ptr, CurseTraitType::ADD_H_CURSE); auto new_curse = get_curse(1, o_ptr); if (o_ptr->curse_flags.has(new_curse)) { return; @@ -312,8 +310,7 @@ static void persist_curse(PlayerType *player_ptr) return; } - ItemEntity *o_ptr; - o_ptr = choose_cursed_obj_name(player_ptr, CurseTraitType::PERSISTENT_CURSE); + auto *o_ptr = choose_cursed_obj_name(player_ptr, CurseTraitType::PERSISTENT_CURSE); if (o_ptr->curse_flags.has(CurseTraitType::HEAVY_CURSE)) { return; } diff --git a/src/inventory/inventory-damage.cpp b/src/inventory/inventory-damage.cpp index 36f857c5fe..e0c2361140 100644 --- a/src/inventory/inventory-damage.cpp +++ b/src/inventory/inventory-damage.cpp @@ -27,32 +27,30 @@ */ void inventory_damage(PlayerType *player_ptr, const ObjectBreaker &breaker, int perc) { - INVENTORY_IDX i; int j, amt; - ItemEntity *o_ptr; if (check_multishadow(player_ptr) || player_ptr->current_floor_ptr->inside_arena) { return; } /* Scan through the slots backwards */ - for (i = 0; i < INVEN_PACK; i++) { - o_ptr = &player_ptr->inventory_list[i]; - if (!o_ptr->is_valid()) { + for (short i = 0; i < INVEN_PACK; i++) { + auto &item = player_ptr->inventory_list[i]; + if (!item.is_valid()) { continue; } /* Hack -- for now, skip artifacts */ - if (o_ptr->is_fixed_or_random_artifact()) { + if (item.is_fixed_or_random_artifact()) { continue; } /* Give this item slot a shot at death */ - if (!breaker.can_destroy(o_ptr)) { + if (!breaker.can_destroy(&item)) { continue; } /* Count the casualties */ - for (amt = j = 0; j < o_ptr->number; ++j) { + for (amt = j = 0; j < item.number; ++j) { if (evaluate_percent(perc)) { amt++; } @@ -63,13 +61,13 @@ void inventory_damage(PlayerType *player_ptr, const ObjectBreaker &breaker, int continue; } - const auto item_name = describe_flavor(player_ptr, *o_ptr, OD_OMIT_PREFIX); + const auto item_name = describe_flavor(player_ptr, item, OD_OMIT_PREFIX); msg_format(_("%s(%c)が%s壊れてしまった!", "%sour %s (%c) %s destroyed!"), #ifdef JP - item_name.data(), index_to_label(i), ((o_ptr->number > 1) ? ((amt == o_ptr->number) ? "全部" : (amt > 1 ? "何個か" : "一個")) : "")); + item_name.data(), index_to_label(i), ((item.number > 1) ? ((amt == item.number) ? "全部" : (amt > 1 ? "何個か" : "一個")) : "")); #else - ((o_ptr->number > 1) ? ((amt == o_ptr->number) ? "All of y" : (amt > 1 ? "Some of y" : "One of y")) : "Y"), item_name.data(), index_to_label(i), + ((item.number > 1) ? ((amt == item.number) ? "All of y" : (amt > 1 ? "Some of y" : "One of y")) : "Y"), item_name.data(), index_to_label(i), ((amt > 1) ? "were" : "was")); #endif @@ -86,12 +84,12 @@ void inventory_damage(PlayerType *player_ptr, const ObjectBreaker &breaker, int #endif /* Potions smash open */ - if (o_ptr->is_potion()) { - (void)potion_smash_effect(player_ptr, 0, player_ptr->y, player_ptr->x, o_ptr->bi_id); + if (item.is_potion()) { + (void)potion_smash_effect(player_ptr, 0, player_ptr->y, player_ptr->x, item.bi_id); } /* Reduce the charges of rods/wands */ - reduce_charges(o_ptr, amt); + reduce_charges(&item, amt); /* Destroy "amt" items */ inven_item_increase(player_ptr, i, -amt); diff --git a/src/inventory/inventory-object.cpp b/src/inventory/inventory-object.cpp index fa1f4cdbc6..8044872c07 100644 --- a/src/inventory/inventory-object.cpp +++ b/src/inventory/inventory-object.cpp @@ -136,8 +136,6 @@ void inven_item_optimize(PlayerType *player_ptr, INVENTORY_IDX i_idx) */ void drop_from_inventory(PlayerType *player_ptr, INVENTORY_IDX i_idx, ITEM_NUMBER amt) { - ItemEntity forge; - ItemEntity *q_ptr; auto *o_ptr = &player_ptr->inventory_list[i_idx]; if (amt <= 0) { return; @@ -152,14 +150,13 @@ void drop_from_inventory(PlayerType *player_ptr, INVENTORY_IDX i_idx, ITEM_NUMBE o_ptr = &player_ptr->inventory_list[i_idx]; } - q_ptr = &forge; - q_ptr->copy_from(o_ptr); - distribute_charges(o_ptr, q_ptr, amt); + ItemEntity item = *o_ptr; + distribute_charges(o_ptr, &item, amt); - q_ptr->number = amt; - const auto item_name = describe_flavor(player_ptr, *q_ptr, 0); + item.number = amt; + const auto item_name = describe_flavor(player_ptr, item, 0); msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), item_name.data(), index_to_label(i_idx)); - (void)drop_near(player_ptr, q_ptr, 0, player_ptr->y, player_ptr->x); + (void)drop_near(player_ptr, &item, 0, player_ptr->y, player_ptr->x); vary_item(player_ptr, i_idx, -amt); } @@ -250,7 +247,6 @@ void combine_pack(PlayerType *player_ptr) void reorder_pack(PlayerType *player_ptr) { int i, j, k; - int32_t o_value; ItemEntity forge; ItemEntity *q_ptr; ItemEntity *o_ptr; @@ -266,9 +262,8 @@ void reorder_pack(PlayerType *player_ptr) continue; } - o_value = o_ptr->get_price(); for (j = 0; j < INVEN_PACK; j++) { - if (object_sort_comp(player_ptr, o_ptr, o_value, &player_ptr->inventory_list[j])) { + if (object_sort_comp(player_ptr, *o_ptr, player_ptr->inventory_list[j])) { break; } } @@ -338,9 +333,8 @@ int16_t store_item_to_inventory(PlayerType *player_ptr, ItemEntity *o_ptr) i = j; if (i < INVEN_PACK) { - const auto o_value = o_ptr->get_price(); for (j = 0; j < INVEN_PACK; j++) { - if (object_sort_comp(player_ptr, o_ptr, o_value, &player_ptr->inventory_list[j])) { + if (object_sort_comp(player_ptr, *o_ptr, player_ptr->inventory_list[j])) { break; } } @@ -406,24 +400,20 @@ bool check_store_item_to_inventory(PlayerType *player_ptr, const ItemEntity *o_p */ INVENTORY_IDX inven_takeoff(PlayerType *player_ptr, INVENTORY_IDX i_idx, ITEM_NUMBER amt) { - INVENTORY_IDX slot; - ItemEntity forge; - ItemEntity *q_ptr; - ItemEntity *o_ptr; - concptr act; - o_ptr = &player_ptr->inventory_list[i_idx]; + const auto &item_inventory = player_ptr->inventory_list[i_idx]; if (amt <= 0) { return -1; } - if (amt > o_ptr->number) { - amt = o_ptr->number; + if (amt > item_inventory.number) { + amt = item_inventory.number; } - q_ptr = &forge; - q_ptr->copy_from(o_ptr); - q_ptr->number = amt; - const auto item_name = describe_flavor(player_ptr, *q_ptr, 0); - if (((i_idx == INVEN_MAIN_HAND) || (i_idx == INVEN_SUB_HAND)) && o_ptr->is_melee_weapon()) { + + ItemEntity item = item_inventory; + item.number = amt; + const auto item_name = describe_flavor(player_ptr, item, 0); + std::string act; + if (((i_idx == INVEN_MAIN_HAND) || (i_idx == INVEN_SUB_HAND)) && item_inventory.is_melee_weapon()) { act = _("を装備からはずした", "You were wielding"); } else if (i_idx == INVEN_BOW) { act = _("を装備からはずした", "You were holding"); @@ -436,11 +426,11 @@ INVENTORY_IDX inven_takeoff(PlayerType *player_ptr, INVENTORY_IDX i_idx, ITEM_NU inven_item_increase(player_ptr, i_idx, -amt); inven_item_optimize(player_ptr, i_idx); - slot = store_item_to_inventory(player_ptr, q_ptr); + const auto slot = store_item_to_inventory(player_ptr, &item); #ifdef JP - msg_format("%s(%c)%s。", item_name.data(), index_to_label(slot), act); + msg_format("%s(%c)%s。", item_name.data(), index_to_label(slot), act.data()); #else - msg_format("%s %s (%c).", act, item_name.data(), index_to_label(slot)); + msg_format("%s %s (%c).", act.data(), item_name.data(), index_to_label(slot)); #endif return slot; diff --git a/src/inventory/inventory-util.cpp b/src/inventory/inventory-util.cpp index 60f5293e06..e534354016 100644 --- a/src/inventory/inventory-util.cpp +++ b/src/inventory/inventory-util.cpp @@ -281,14 +281,8 @@ INVENTORY_IDX label_to_inventory(PlayerType *player_ptr, int c) */ bool verify(PlayerType *player_ptr, concptr prompt, INVENTORY_IDX i_idx) { - ItemEntity *o_ptr; - if (i_idx >= 0) { - o_ptr = &player_ptr->inventory_list[i_idx]; - } else { - o_ptr = &player_ptr->current_floor_ptr->o_list[0 - i_idx]; - } - - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + const auto &item = i_idx >= 0 ? player_ptr->inventory_list[i_idx] : player_ptr->current_floor_ptr->o_list[0 - i_idx]; + const auto item_name = describe_flavor(player_ptr, item, 0); std::stringstream ss; ss << prompt; #ifndef JP diff --git a/src/inventory/pack-overflow.cpp b/src/inventory/pack-overflow.cpp index 9cb944f1eb..d3deb93943 100644 --- a/src/inventory/pack-overflow.cpp +++ b/src/inventory/pack-overflow.cpp @@ -25,13 +25,13 @@ void pack_overflow(PlayerType *player_ptr) return; } - auto *o_ptr = &player_ptr->inventory_list[INVEN_PACK]; + auto &item = player_ptr->inventory_list[INVEN_PACK]; disturb(player_ptr, false, true); msg_print(_("ザックからアイテムがあふれた!", "Your pack overflows!")); - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + const auto item_name = describe_flavor(player_ptr, item, 0); msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), item_name.data(), index_to_label(INVEN_PACK)); - (void)drop_near(player_ptr, o_ptr, 0, player_ptr->y, player_ptr->x); + (void)drop_near(player_ptr, &item, 0, player_ptr->y, player_ptr->x); vary_item(player_ptr, INVEN_PACK, -255); handle_stuff(player_ptr); diff --git a/src/inventory/player-inventory.cpp b/src/inventory/player-inventory.cpp index c5209b9b09..dea9c60811 100644 --- a/src/inventory/player-inventory.cpp +++ b/src/inventory/player-inventory.cpp @@ -94,24 +94,24 @@ void py_pickup_floor(PlayerType *player_ptr, bool pickup) auto &rfu = RedrawingFlagsUpdater::get_instance(); for (auto it = o_idx_list.begin(); it != o_idx_list.end();) { const OBJECT_IDX this_o_idx = *it++; - auto *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx]; - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + auto &item = player_ptr->current_floor_ptr->o_list[this_o_idx]; + const auto item_name = describe_flavor(player_ptr, item, 0); disturb(player_ptr, false, false); - if (o_ptr->bi_key.tval() == ItemKindType::GOLD) { - constexpr auto mes = _(" $%ld の価値がある%sを見つけた。", "You have found %ld gold pieces worth of %s."); - msg_format(mes, (long)o_ptr->pval, item_name.data()); + if (item.bi_key.tval() == ItemKindType::GOLD) { + constexpr auto mes = _(" $%d の価値がある%sを見つけた。", "You have found %d gold pieces worth of %s."); + msg_format(mes, item.pval, item_name.data()); sound(SOUND_SELL); - player_ptr->au += o_ptr->pval; + player_ptr->au += item.pval; rfu.set_flag(MainWindowRedrawingFlag::GOLD); rfu.set_flag(SubWindowRedrawingFlag::PLAYER); delete_object_idx(player_ptr, this_o_idx); continue; - } else if (o_ptr->marked.has(OmType::SUPRESS_MESSAGE)) { - o_ptr->marked.reset(OmType::SUPRESS_MESSAGE); + } else if (item.marked.has(OmType::SUPRESS_MESSAGE)) { + item.marked.reset(OmType::SUPRESS_MESSAGE); continue; } - if (check_store_item_to_inventory(player_ptr, o_ptr)) { + if (check_store_item_to_inventory(player_ptr, &item)) { can_pickup++; } @@ -125,8 +125,8 @@ void py_pickup_floor(PlayerType *player_ptr, bool pickup) if (!pickup) { if (floor_num == 1) { - auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx]; - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + const auto &item = player_ptr->current_floor_ptr->o_list[floor_o_idx]; + const auto item_name = describe_flavor(player_ptr, item, 0); msg_format(_("%sがある。", "You see %s."), item_name.data()); } else { msg_format(_("%d 個のアイテムの山がある。", "You see a pile of %d items."), floor_num); @@ -137,8 +137,8 @@ void py_pickup_floor(PlayerType *player_ptr, bool pickup) if (!can_pickup) { if (floor_num == 1) { - auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx]; - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + const auto &item = player_ptr->current_floor_ptr->o_list[floor_o_idx]; + const auto item_name = describe_flavor(player_ptr, item, 0); msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), item_name.data()); } else { msg_print(_("ザックには床にあるどのアイテムも入らない。", "You have no room for any of the objects on the floor.")); @@ -162,8 +162,8 @@ void py_pickup_floor(PlayerType *player_ptr, bool pickup) return; } - auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx]; - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + const auto &item = player_ptr->current_floor_ptr->o_list[floor_o_idx]; + const auto item_name = describe_flavor(player_ptr, item, 0); const auto prompt = format(_("%sを拾いますか? ", "Pick up %s? "), item_name.data()); if (!input_check(prompt)) { return; @@ -256,13 +256,13 @@ void carry(PlayerType *player_ptr, bool pickup) for (auto it = g_ptr->o_idx_list.begin(); it != g_ptr->o_idx_list.end();) { const OBJECT_IDX this_o_idx = *it++; - auto *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx]; - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); + auto &item = player_ptr->current_floor_ptr->o_list[this_o_idx]; + const auto item_name = describe_flavor(player_ptr, item, 0); disturb(player_ptr, false, false); - if (o_ptr->bi_key.tval() == ItemKindType::GOLD) { - int value = (long)o_ptr->pval; + if (item.bi_key.tval() == ItemKindType::GOLD) { + const auto value = item.pval; delete_object_idx(player_ptr, this_o_idx); - msg_format(_(" $%ld の価値がある%sを見つけた。", "You collect %ld gold pieces worth of %s."), (long)value, item_name.data()); + msg_format(_(" $%d の価値がある%sを見つけた。", "You collect %d gold pieces worth of %s."), value, item_name.data()); sound(SOUND_SELL); player_ptr->au += value; rfu.set_flag(MainWindowRedrawingFlag::GOLD); @@ -270,8 +270,8 @@ void carry(PlayerType *player_ptr, bool pickup) continue; } - if (o_ptr->marked.has(OmType::SUPRESS_MESSAGE)) { - o_ptr->marked.reset(OmType::SUPRESS_MESSAGE); + if (item.marked.has(OmType::SUPRESS_MESSAGE)) { + item.marked.reset(OmType::SUPRESS_MESSAGE); continue; } @@ -280,7 +280,7 @@ void carry(PlayerType *player_ptr, bool pickup) continue; } - if (!check_store_item_to_inventory(player_ptr, o_ptr)) { + if (!check_store_item_to_inventory(player_ptr, &item)) { msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), item_name.data()); continue; } diff --git a/src/inventory/recharge-processor.cpp b/src/inventory/recharge-processor.cpp index a4c62fd4ed..dd7ac060b4 100644 --- a/src/inventory/recharge-processor.cpp +++ b/src/inventory/recharge-processor.cpp @@ -20,20 +20,20 @@ * If player has inscribed the object with "!!", let him know when it's recharged. -LM- * @param o_ptr 対象オブジェクトの構造体参照ポインタ */ -static void recharged_notice(PlayerType *player_ptr, ItemEntity *o_ptr) +static void recharged_notice(PlayerType *player_ptr, const ItemEntity &item) { - if (!o_ptr->is_inscribed()) { + if (!item.is_inscribed()) { return; } - auto s = angband_strchr(o_ptr->inscription->data(), '!'); + auto s = angband_strchr(item.inscription->data(), '!'); while (s) { if (s[1] == '!') { - const auto item_name = describe_flavor(player_ptr, *o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); + const auto item_name = describe_flavor(player_ptr, item, (OD_OMIT_PREFIX | OD_NAME_ONLY)); #ifdef JP msg_format("%sは再充填された。", item_name.data()); #else - if (o_ptr->number > 1) { + if (item.number > 1) { msg_format("Your %s are recharged.", item_name.data()); } else { msg_format("Your %s is recharged.", item_name.data()); @@ -57,15 +57,15 @@ void recharge_magic_items(PlayerType *player_ptr) bool changed; for (changed = false, i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) { - auto *o_ptr = &player_ptr->inventory_list[i]; - if (!o_ptr->is_valid()) { + auto &item = player_ptr->inventory_list[i]; + if (!item.is_valid()) { continue; } - if (o_ptr->timeout > 0) { - o_ptr->timeout--; - if (!o_ptr->timeout) { - recharged_notice(player_ptr, o_ptr); + if (item.timeout > 0) { + item.timeout--; + if (!item.timeout) { + recharged_notice(player_ptr, item); changed = true; } } @@ -83,27 +83,27 @@ void recharge_magic_items(PlayerType *player_ptr) * one per turn. -LM- */ for (changed = false, i = 0; i < INVEN_PACK; i++) { - auto *o_ptr = &player_ptr->inventory_list[i]; - const auto &baseitem = o_ptr->get_baseitem(); - if (!o_ptr->is_valid()) { + auto &item = player_ptr->inventory_list[i]; + const auto &baseitem = item.get_baseitem(); + if (!item.is_valid()) { continue; } - if ((o_ptr->bi_key.tval() == ItemKindType::ROD) && (o_ptr->timeout)) { - TIME_EFFECT temp = (o_ptr->timeout + (baseitem.pval - 1)) / baseitem.pval; - if (temp > o_ptr->number) { - temp = (TIME_EFFECT)o_ptr->number; + if ((item.bi_key.tval() == ItemKindType::ROD) && (item.timeout)) { + TIME_EFFECT temp = (item.timeout + (baseitem.pval - 1)) / baseitem.pval; + if (temp > item.number) { + temp = (TIME_EFFECT)item.number; } - o_ptr->timeout -= temp; - if (o_ptr->timeout < 0) { - o_ptr->timeout = 0; + item.timeout -= temp; + if (item.timeout < 0) { + item.timeout = 0; } - if (!(o_ptr->timeout)) { - recharged_notice(player_ptr, o_ptr); + if (!(item.timeout)) { + recharged_notice(player_ptr, item); changed = true; - } else if (o_ptr->timeout % baseitem.pval) { + } else if (item.timeout % baseitem.pval) { changed = true; } } diff --git a/src/load/store-loader.cpp b/src/load/store-loader.cpp index 1813f5d9a3..7488b9ab0d 100644 --- a/src/load/store-loader.cpp +++ b/src/load/store-loader.cpp @@ -43,17 +43,13 @@ static void home_carry_load(PlayerType *player_ptr, store_type *store_ptr, ItemE return; } - const auto value = o_ptr->get_price(); - int slot; - for (slot = 0; slot < store_ptr->stock_num; slot++) { - if (object_sort_comp(player_ptr, o_ptr, value, store_ptr->stock[slot].get())) { - break; - } - } + const auto first = store_ptr->stock.begin(); + const auto last = store_ptr->stock.begin() + store_ptr->stock_num; + const auto slot_it = std::find_if(first, last, + [&](const auto &item) { return object_sort_comp(player_ptr, *o_ptr, *item); }); + const int slot = std::distance(first, slot_it); - for (auto i = store_ptr->stock_num; i > slot; i--) { - *store_ptr->stock[i] = *store_ptr->stock[i - 1]; - } + std::rotate(first + slot, last, last + 1); store_ptr->stock_num++; *store_ptr->stock[slot] = *o_ptr; diff --git a/src/lore/lore-util.cpp b/src/lore/lore-util.cpp index 4f91ad9b04..7b44f06431 100644 --- a/src/lore/lore-util.cpp +++ b/src/lore/lore-util.cpp @@ -118,6 +118,47 @@ std::vector lore_type::build_speed_description() const return texts; } +std::optional> lore_type::build_kill_unique_description() const +{ + if (this->kind_flags.has_not(MonsterKindType::UNIQUE)) { + return std::nullopt; + } + + std::vector texts; + const auto is_dead = (this->r_ptr->max_num == 0); + if (this->r_ptr->r_deaths > 0) { + constexpr auto fmt = _("%s^はあなたの先祖を %d 人葬っている", "%s^ has slain %d of your ancestors"); + texts.emplace_back(format(fmt, Who::who(this->msex).data(), this->r_ptr->r_deaths)); + texts.emplace_back(this->build_revenge_description(is_dead)); + texts.emplace_back("\n"); + } else { +#ifdef JP + const auto mes = is_dead ? "あなたはこの仇敵をすでに葬り去っている。" : "この仇敵はまだ生きている!"; +#else + const auto mes = is_dead ? "You have slain this foe. " : "This foe is still alive! "; +#endif + texts.emplace_back(mes); + texts.emplace_back("\n"); + } + + return texts; +} + +std::string lore_type::build_revenge_description(bool has_defeated) const +{ +#ifdef JP + return has_defeated ? "が、すでに仇討ちは果たしている!" : "のに、まだ仇討ちを果たしていない。"; +#else + if (has_defeated) { + return format(", but you have avenged %s! ", Who::whom(this->msex, this->r_ptr->r_deaths == 1).data()); + } + + std::stringstream ss; + ss << ", who remain" << (this->r_ptr->r_deaths == 1 ? "" : "s") << "unavenged. "; + return ss.str(); +#endif +} + std::vector lore_type::build_random_movement_description() const { if (this->behavior_flags.has_none_of({ MonsterBehaviorType::RAND_MOVE_50, MonsterBehaviorType::RAND_MOVE_25 })) { diff --git a/src/lore/lore-util.h b/src/lore/lore-util.h index 50b1e24fce..4010d06a1e 100644 --- a/src/lore/lore-util.h +++ b/src/lore/lore-util.h @@ -15,6 +15,7 @@ #include "system/angband.h" #include "term/term-color-types.h" #include "util/flag-group.h" +#include #include #include #include @@ -84,6 +85,8 @@ struct lore_type { bool has_reinforce() const; + std::optional> build_kill_unique_description() const; + std::string build_revenge_description(bool has_defeated) const; std::vector build_speed_description() const; private: diff --git a/src/spell-realm/spells-sorcery.cpp b/src/spell-realm/spells-sorcery.cpp index 12dd7a2752..03a7186cda 100644 --- a/src/spell-realm/spells-sorcery.cpp +++ b/src/spell-realm/spells-sorcery.cpp @@ -50,7 +50,7 @@ bool alchemy(PlayerType *player_ptr) o_ptr->number = old_number; if (!force) { - if (confirm_destroy || (o_ptr->get_price() > 0)) { + if (confirm_destroy || (o_ptr->calc_price() > 0)) { const auto out_val = format(_("本当に%sを金に変えますか?", "Really turn %s to gold? "), item_name.data()); if (!input_check(out_val)) { return false; diff --git a/src/store/home.cpp b/src/store/home.cpp index 1152e21580..24557c0fa1 100644 --- a/src/store/home.cpp +++ b/src/store/home.cpp @@ -10,6 +10,7 @@ #include "system/item-entity.h" #include "system/player-type-definition.h" #include "util/object-sort.h" +#include /*! * @brief 我が家にオブジェクトを加える / @@ -66,17 +67,13 @@ int home_carry(PlayerType *player_ptr, ItemEntity *o_ptr, StoreSaleType store_nu } } - const auto value = o_ptr->get_price(); - int slot; - for (slot = 0; slot < st_ptr->stock_num; slot++) { - if (object_sort_comp(player_ptr, o_ptr, value, st_ptr->stock[slot].get())) { - break; - } - } + const auto first = st_ptr->stock.begin(); + const auto last = st_ptr->stock.begin() + st_ptr->stock_num; + const auto slot_it = std::find_if(first, last, + [&](const auto &item) { return object_sort_comp(player_ptr, *o_ptr, *item); }); + const int slot = std::distance(first, slot_it); - for (int i = st_ptr->stock_num; i > slot; i--) { - *st_ptr->stock[i] = *st_ptr->stock[i - 1]; - } + std::rotate(first + slot, last, last + 1); st_ptr->stock_num++; *st_ptr->stock[slot] = *o_ptr; @@ -92,13 +89,12 @@ static bool exe_combine_store_items(ItemEntity *o_ptr, ItemEntity *j_ptr, const } object_absorb(j_ptr, o_ptr); - st_ptr->stock_num--; - int k; - for (k = i; k < st_ptr->stock_num; k++) { - *st_ptr->stock[k] = *st_ptr->stock[k + 1]; - } - st_ptr->stock[k]->wipe(); + const auto begin = st_ptr->stock.begin(); + std::rotate(begin + i, begin + i + 1, begin + st_ptr->stock_num); + + st_ptr->stock_num--; + st_ptr->stock[st_ptr->stock_num]->wipe(); *combined = true; return true; } @@ -137,37 +133,21 @@ static void sweep_reorder_store_item(ItemEntity *o_ptr, const int i, bool *combi } } -static void exe_reorder_store_item(PlayerType *player_ptr, bool *flag) +static bool exe_reorder_store_item(PlayerType *player_ptr) { - for (auto i = 0; i < st_ptr->stock_num; i++) { - auto &item = st_ptr->stock[i]; - if (!item->is_valid()) { - continue; - } + const auto comp = [player_ptr](const auto &item1, const auto &item2) { + return object_sort_comp(player_ptr, *item1, *item2); + }; - const auto o_value = item->get_price(); - int j; - for (j = 0; j < st_ptr->stock_num; j++) { - if (object_sort_comp(player_ptr, item.get(), o_value, st_ptr->stock[j].get())) { - break; - } - } - - if (j >= i) { - continue; - } + const auto first = st_ptr->stock.begin(); + const auto last = st_ptr->stock.begin() + st_ptr->stock_num; - *flag = true; - ItemEntity *j_ptr; - ItemEntity forge; - j_ptr = &forge; - j_ptr->copy_from(st_ptr->stock[i].get()); - for (auto k = i; k > j; k--) { - *st_ptr->stock[k] = *st_ptr->stock[k - 1]; - } - - *st_ptr->stock[j] = *j_ptr; + if (std::is_sorted(first, last, comp)) { + return false; } + + std::stable_sort(first, last, comp); + return true; } /*! @@ -203,7 +183,8 @@ bool combine_and_reorder_home(PlayerType *player_ptr, const StoreSaleType store_ flag |= combined; } - exe_reorder_store_item(player_ptr, &flag); + flag |= exe_reorder_store_item(player_ptr); + st_ptr = old_st_ptr; if (store_num != StoreSaleType::HOME) { stack_force_notes = old_stack_force_notes; diff --git a/src/store/pricing.cpp b/src/store/pricing.cpp index e0d1a20518..946ccb3108 100644 --- a/src/store/pricing.cpp +++ b/src/store/pricing.cpp @@ -33,7 +33,7 @@ */ int price_item(PlayerType *player_ptr, const ItemEntity *o_ptr, int greed, bool flip, StoreSaleType store_num) { - auto price = o_ptr->get_price(); + auto price = o_ptr->calc_price(); if (price <= 0) { return 0L; } diff --git a/src/store/sell-order.cpp b/src/store/sell-order.cpp index 7bbb03ea68..541d76d997 100644 --- a/src/store/sell-order.cpp +++ b/src/store/sell-order.cpp @@ -153,7 +153,7 @@ void store_sell(PlayerType *player_ptr, StoreSaleType store_num) player_ptr->au += price; store_prt_gold(player_ptr); - const auto dummy = q_ptr->get_price() * q_ptr->number; + const auto dummy = q_ptr->calc_price() * q_ptr->number; identify_item(player_ptr, o_ptr); q_ptr = &forge; @@ -165,7 +165,7 @@ void store_sell(PlayerType *player_ptr, StoreSaleType store_num) q_ptr->pval = o_ptr->pval * amt / o_ptr->number; } - const auto value = q_ptr->get_price() * q_ptr->number; + const auto value = q_ptr->calc_price() * q_ptr->number; const auto sold_item_name = describe_flavor(player_ptr, *q_ptr, 0); msg_format(_("%sを $%dで売却しました。", "You sold %s for %d gold."), sold_item_name.data(), price); diff --git a/src/store/service-checker.cpp b/src/store/service-checker.cpp index 16ca9b647a..00f40c37e1 100644 --- a/src/store/service-checker.cpp +++ b/src/store/service-checker.cpp @@ -225,7 +225,7 @@ bool store_will_buy(PlayerType *, const ItemEntity *o_ptr, StoreSaleType store_n return false; } - return o_ptr->get_price() > 0; + return o_ptr->calc_price() > 0; } static int mass_lite_produce(const PRICE cost) @@ -443,7 +443,7 @@ static byte decide_discount_rate(const PRICE cost) */ void mass_produce(ItemEntity *o_ptr, StoreSaleType store_num) { - const auto cost = o_ptr->get_price(); + const auto cost = o_ptr->calc_price(); int size = switch_mass_production(*o_ptr, cost, store_num); auto discount = decide_discount_rate(cost); if (o_ptr->is_random_artifact()) { diff --git a/src/store/store-util.cpp b/src/store/store-util.cpp index d58e6ca268..c0a0747394 100644 --- a/src/store/store-util.cpp +++ b/src/store/store-util.cpp @@ -11,6 +11,7 @@ #include "object/tval-types.h" #include "system/baseitem-info.h" #include "system/item-entity.h" +#include store_type *st_ptr = nullptr; @@ -44,11 +45,10 @@ void store_item_optimize(short i_idx) return; } - st_ptr->stock_num--; - for (int j = i_idx; j < st_ptr->stock_num; j++) { - *st_ptr->stock[j] = *st_ptr->stock[j + 1]; - } + const auto begin = st_ptr->stock.begin(); + std::rotate(begin + i_idx, begin + i_idx + 1, begin + st_ptr->stock_num); + st_ptr->stock_num--; st_ptr->stock[st_ptr->stock_num]->wipe(); } @@ -203,6 +203,45 @@ static void store_object_absorb(ItemEntity *o_ptr, ItemEntity *j_ptr) } } +/*! + * @brief 店舗のアイテムをソートするための比較関数 + * + * @param item1 比較対象アイテムへの参照 + * @param item2 比較対象アイテムへの参照 + * @return item1の方が上位ならばTRUEを返す。 + */ +static bool store_item_sort_comp(const ItemEntity &item1, const ItemEntity &item2) +{ + const auto item1_tval = item1.bi_key.tval(); + const auto item2_tval = item2.bi_key.tval(); + if (item1_tval > item2_tval) { + return true; + } + if (item1_tval < item2_tval) { + return false; + } + + const auto item1_sval = item1.bi_key.sval(); + const auto item2_sval = item2.bi_key.sval(); + if (item1_sval < item2_sval) { + return true; + } + if (item1_sval > item2_sval) { + return false; + } + + if (item1_tval == ItemKindType::ROD) { + if (item1.pval < item2.pval) { + return true; + } + if (item1.pval > item2.pval) { + return false; + } + } + + return item1.calc_price() > item2.calc_price(); +} + /*! * @brief 店舗にオブジェクトを加える * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ @@ -210,7 +249,7 @@ static void store_object_absorb(ItemEntity *o_ptr, ItemEntity *j_ptr) */ int store_carry(ItemEntity *o_ptr) { - const auto value = o_ptr->get_price(); + const auto value = o_ptr->calc_price(); if (value <= 0) { return -1; } @@ -218,8 +257,7 @@ int store_carry(ItemEntity *o_ptr) o_ptr->ident |= IDENT_FULL_KNOWN; o_ptr->inscription.reset(); o_ptr->feeling = FEEL_NONE; - int slot; - for (slot = 0; slot < st_ptr->stock_num; slot++) { + for (auto slot = 0; slot < st_ptr->stock_num; slot++) { auto &item = st_ptr->stock[slot]; if (store_object_similar(item.get(), o_ptr)) { store_object_absorb(item.get(), o_ptr); @@ -231,50 +269,13 @@ int store_carry(ItemEntity *o_ptr) return -1; } - const auto o_tval = o_ptr->bi_key.tval(); - const auto o_sval = o_ptr->bi_key.sval(); - for (slot = 0; slot < st_ptr->stock_num; slot++) { - const auto &item = st_ptr->stock[slot]; - const auto j_tval = item->bi_key.tval(); - const auto j_sval = item->bi_key.sval(); - if (o_tval > j_tval) { - break; - } - - if (o_tval < j_tval) { - continue; - } - - if (o_sval < j_sval) { - break; - } - - if (o_sval > j_sval) { - continue; - } + const auto first = st_ptr->stock.begin(); + const auto last = first + st_ptr->stock_num; + const auto slot_it = std::find_if(first, last, + [&](const auto &item) { return store_item_sort_comp(*o_ptr, *item); }); + const auto slot = std::distance(first, slot_it); - if (o_tval == ItemKindType::ROD) { - if (o_ptr->pval < item->pval) { - break; - } - if (o_ptr->pval > item->pval) { - continue; - } - } - - auto j_value = item->get_price(); - if (value > j_value) { - break; - } - - if (value < j_value) { - continue; - } - } - - for (int i = st_ptr->stock_num; i > slot; i--) { - *st_ptr->stock[i] = *st_ptr->stock[i - 1]; - } + std::rotate(first + slot, last, last + 1); st_ptr->stock_num++; *st_ptr->stock[slot] = *o_ptr; diff --git a/src/store/store.cpp b/src/store/store.cpp index c1c172494f..563eabac5b 100644 --- a/src/store/store.cpp +++ b/src/store/store.cpp @@ -365,11 +365,11 @@ static void store_create(PlayerType *player_ptr, short fix_k_idx, StoreSaleType } if (store_num == StoreSaleType::BLACK) { - if (black_market_crap(player_ptr, &item) || (item.get_price() < 10)) { + if (black_market_crap(player_ptr, &item) || (item.calc_price() < 10)) { continue; } } else { - if (item.get_price() <= 0) { + if (item.calc_price() <= 0) { continue; } } diff --git a/src/system/item-entity.cpp b/src/system/item-entity.cpp index cb7b9d14e9..7c02647534 100644 --- a/src/system/item-entity.cpp +++ b/src/system/item-entity.cpp @@ -609,7 +609,7 @@ DisplaySymbol ItemEntity::get_symbol() const * @brief アイテム価格算出のメインルーチン * @return 判明している現価格 */ -int ItemEntity::get_price() const +int ItemEntity::calc_price() const { int value; const auto is_worthless = this->is_broken() || this->is_cursed(); diff --git a/src/system/item-entity.h b/src/system/item-entity.h index 5ab917b500..9e8ac3ae46 100644 --- a/src/system/item-entity.h +++ b/src/system/item-entity.h @@ -131,7 +131,7 @@ class ItemEntity { bool is_glove_same_temper(const ItemEntity *j_ptr) const; bool can_pile(const ItemEntity *j_ptr) const; DisplaySymbol get_symbol() const; - int get_price() const; + int calc_price() const; bool is_specific_artifact(FixedArtifactId id) const; bool has_unidentified_name() const; ItemKindType get_arrow_kind() const; diff --git a/src/util/object-sort.cpp b/src/util/object-sort.cpp index 9ddcd33f53..8fd28efed4 100644 --- a/src/util/object-sort.cpp +++ b/src/util/object-sort.cpp @@ -31,96 +31,95 @@ static int get_item_sort_rank(const ItemEntity &item) } /*! - * @brief オブジェクトを定義された基準に従いソートするための関数 / + * @brief アイテムを定義された基準に従いソートするための関数 / * Check if we have space for an item in the pack without overflow - * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1 - * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?) - * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2 - * @return o_ptrの方が上位ならばTRUEを返す。 + * @param item1 比較対象アイテムへの参照 + * @param item2 比較対象アイテムへの参照 + * @return item1の方が上位ならばTRUEを返す。 */ -bool object_sort_comp(PlayerType *player_ptr, ItemEntity *o_ptr, int32_t o_value, ItemEntity *j_ptr) +bool object_sort_comp(PlayerType *player_ptr, const ItemEntity &item1, const ItemEntity &item2) { - if (!j_ptr->is_valid()) { + if (!item2.is_valid()) { return true; } - const auto o_tval = o_ptr->bi_key.tval(); - const auto j_tval = j_ptr->bi_key.tval(); + const auto item1_tval = item1.bi_key.tval(); + const auto item2_tval = item2.bi_key.tval(); PlayerRealm pr(player_ptr); const auto realm1_book = pr.realm1().get_book(); const auto realm2_book = pr.realm2().get_book(); - if ((o_tval == realm1_book) && (j_tval != realm1_book)) { + if ((item1_tval == realm1_book) && (item2_tval != realm1_book)) { return true; } - if ((j_tval == realm1_book) && (o_tval != realm1_book)) { + if ((item2_tval == realm1_book) && (item1_tval != realm1_book)) { return false; } - if ((o_tval == realm2_book) && (j_tval != realm2_book)) { + if ((item1_tval == realm2_book) && (item2_tval != realm2_book)) { return true; } - if ((j_tval == realm2_book) && (o_tval != realm2_book)) { + if ((item2_tval == realm2_book) && (item1_tval != realm2_book)) { return false; } - if (o_tval > j_tval) { + if (item1_tval > item2_tval) { return true; } - if (o_tval < j_tval) { + if (item1_tval < item2_tval) { return false; } - if (!o_ptr->is_aware()) { + if (!item1.is_aware()) { return false; } - if (!j_ptr->is_aware()) { + if (!item2.is_aware()) { return true; } - const auto o_sval = o_ptr->bi_key.sval(); - const auto j_sval = j_ptr->bi_key.sval(); - if (o_sval < j_sval) { + const auto item1_sval = item1.bi_key.sval(); + const auto item2_sval = item2.bi_key.sval(); + if (item1_sval < item2_sval) { return true; } - if (o_sval > j_sval) { + if (item1_sval > item2_sval) { return false; } - if (!o_ptr->is_known()) { + if (!item1.is_known()) { return false; } - if (!j_ptr->is_known()) { + if (!item2.is_known()) { return true; } - const auto o_rank = get_item_sort_rank(*o_ptr); - const auto j_rank = get_item_sort_rank(*j_ptr); - if (o_rank < j_rank) { + const auto item1_rank = get_item_sort_rank(item1); + const auto item2_rank = get_item_sort_rank(item2); + if (item1_rank < item2_rank) { return true; } - if (o_rank > j_rank) { + if (item1_rank > item2_rank) { return false; } - switch (o_tval) { + switch (item1_tval) { case ItemKindType::FIGURINE: case ItemKindType::STATUE: case ItemKindType::MONSTER_REMAINS: case ItemKindType::CAPTURE: { - const auto &monrace1 = o_ptr->get_monrace(); - const auto &monrace2 = j_ptr->get_monrace(); + const auto &monrace1 = item1.get_monrace(); + const auto &monrace2 = item2.get_monrace(); if (monrace2.order_level_strictly(monrace1)) { return true; } - if ((monrace1.level == monrace2.level) && (o_ptr->pval < j_ptr->pval)) { + if ((monrace1.level == monrace2.level) && (item1.pval < item2.pval)) { return true; } @@ -129,21 +128,21 @@ bool object_sort_comp(PlayerType *player_ptr, ItemEntity *o_ptr, int32_t o_value case ItemKindType::SHOT: case ItemKindType::ARROW: case ItemKindType::BOLT: - if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) { + if (item1.to_h + item1.to_d < item2.to_h + item2.to_d) { return true; } - if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) { + if (item1.to_h + item1.to_d > item2.to_h + item2.to_d) { return false; } break; case ItemKindType::ROD: - if (o_ptr->pval < j_ptr->pval) { + if (item1.pval < item2.pval) { return true; } - if (o_ptr->pval > j_ptr->pval) { + if (item1.pval > item2.pval) { return false; } @@ -152,5 +151,5 @@ bool object_sort_comp(PlayerType *player_ptr, ItemEntity *o_ptr, int32_t o_value break; } - return o_value > j_ptr->get_price(); + return item1.calc_price() > item2.calc_price(); } diff --git a/src/util/object-sort.h b/src/util/object-sort.h index e381c4bccc..c498e0fc06 100644 --- a/src/util/object-sort.h +++ b/src/util/object-sort.h @@ -4,4 +4,4 @@ class ItemEntity; class PlayerType; -bool object_sort_comp(PlayerType *player_ptr, ItemEntity *o_ptr, int32_t o_value, ItemEntity *j_ptr); +bool object_sort_comp(PlayerType *player_ptr, const ItemEntity &item1, const ItemEntity &item2); diff --git a/src/view/display-lore.cpp b/src/view/display-lore.cpp index a08ae57350..d2e69b9055 100644 --- a/src/view/display-lore.cpp +++ b/src/view/display-lore.cpp @@ -27,11 +27,6 @@ #include "view/display-symbol.h" #include "world/world.h" -/*! - * 英語の複数系記述用マクロ / Pluralizer. Args(count, singular, plural) - */ -#define plural(c, s, p) (((c) == 1) ? (s) : (p)) - /*! * @brief モンスター情報のヘッダを記述する * @param monrace_id モンスターの種族ID @@ -121,43 +116,14 @@ void output_monster_spoiler(MonraceId r_idx, hook_c_roff_pf roff_func) process_monster_lore(&dummy, r_idx, MONSTER_LORE_DEBUG); } -static bool display_kill_unique(lore_type *lore_ptr) -{ - if (lore_ptr->kind_flags.has_not(MonsterKindType::UNIQUE)) { - return false; - } - - bool dead = (lore_ptr->r_ptr->max_num == 0); - if (lore_ptr->r_ptr->r_deaths) { - hooked_roff(format(_("%s^はあなたの先祖を %d 人葬っている", "%s^ has slain %d of your ancestors"), Who::who(lore_ptr->msex).data(), lore_ptr->r_ptr->r_deaths)); - - if (dead) { - hooked_roff( - _(format("が、すでに仇討ちは果たしている!"), format(", but you have avenged %s! ", plural(lore_ptr->r_ptr->r_deaths, "him", "them")))); - } else { - hooked_roff( - _(format("のに、まだ仇討ちを果たしていない。"), format(", who %s unavenged. ", plural(lore_ptr->r_ptr->r_deaths, "remains", "remain")))); - } - - hooked_roff("\n"); - } else { - if (dead) { - hooked_roff(_("あなたはこの仇敵をすでに葬り去っている。", "You have slain this foe. ")); - } else { - hooked_roff(_("この仇敵はまだ生きている!", "This foe is still alive! ")); - } - - hooked_roff("\n"); - } - - return true; -} - static void display_killed(lore_type *lore_ptr) { - hooked_roff(_(format("このモンスターはあなたの先祖を %d 人葬っている", lore_ptr->r_ptr->r_deaths), - format("%d of your ancestors %s been killed by this creature, ", lore_ptr->r_ptr->r_deaths, plural(lore_ptr->r_ptr->r_deaths, "has", "have")))); - +#ifdef JP + hooked_roff(format("このモンスターはあなたの先祖を %d 人葬っている", lore_ptr->r_ptr->r_deaths)); +#else + const auto present_perfect_tense = lore_ptr->r_ptr->r_deaths == 1 ? "has" : "have"; + hooked_roff(format("%d of your ancestors %s been killed by this creature, ", lore_ptr->r_ptr->r_deaths, present_perfect_tense)); +#endif if (lore_ptr->r_ptr->r_pkills) { hooked_roff(format(_("が、あなたはこのモンスターを少なくとも %d 体は倒している。", "and you have exterminated at least %d of the creatures. "), lore_ptr->r_ptr->r_pkills)); @@ -224,10 +190,15 @@ void display_kill_numbers(lore_type *lore_ptr) return; } - if (display_kill_unique(lore_ptr)) { + const auto kill_unique_description = lore_ptr->build_kill_unique_description(); + if (!kill_unique_description) { return; } + for (const auto &[text, color] : *kill_unique_description) { + hook_c_roff(color, text); + } + if (lore_ptr->r_ptr->r_deaths == 0) { display_no_killed(lore_ptr); } else { diff --git a/src/window/display-sub-windows.cpp b/src/window/display-sub-windows.cpp index 18e3d7d57a..9828ba3908 100644 --- a/src/window/display-sub-windows.cpp +++ b/src/window/display-sub-windows.cpp @@ -659,8 +659,8 @@ static void display_found_item_list(PlayerType *player_ptr) std::sort( found_item_list.begin(), found_item_list.end(), - [player_ptr](ItemEntity *left, ItemEntity *right) -> bool { - return object_sort_comp(player_ptr, left, left->get_price(), right); + [player_ptr](const ItemEntity *left, const ItemEntity *right) -> bool { + return object_sort_comp(player_ptr, *left, *right); }); term_clear(); diff --git a/src/wizard/items-spoiler.cpp b/src/wizard/items-spoiler.cpp index 259811907e..84ae00f1c0 100644 --- a/src/wizard/items-spoiler.cpp +++ b/src/wizard/items-spoiler.cpp @@ -25,7 +25,7 @@ static std::pair get_info(const ItemEntity &item) { const auto level = item.get_baseitem().level; - const auto price = item.get_price(); + const auto price = item.calc_price(); return { level, price }; }