From e2f9e5a994677b9522f24bfe8feae8b525d822fc Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 9 Jun 2024 13:45:15 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20arena=5Finfo=20=E3=82=92arena-entry?= =?utf8?q?.cpp/h=20=E3=81=AE=E5=8C=BF=E5=90=8D=E5=90=8D=E5=89=8D=E7=A9=BA?= =?utf8?q?=E9=96=93=E3=81=AB=E7=B9=B0=E3=82=8A=E8=BE=BC=E3=82=93=E3=81=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/floor/floor-generator.cpp | 3 +- src/io-dump/character-dump.cpp | 7 +-- src/market/arena-entry.cpp | 117 +++++++++++++++++++++--------------- src/market/arena-entry.h | 12 ++-- src/market/arena.cpp | 3 +- src/monster-floor/monster-death.cpp | 7 +-- src/player/player-damage.cpp | 3 +- src/system/baseitem-info.cpp | 5 ++ src/system/baseitem-info.h | 2 +- 9 files changed, 90 insertions(+), 69 deletions(-) diff --git a/src/floor/floor-generator.cpp b/src/floor/floor-generator.cpp index 88aba4174..cd7270b49 100644 --- a/src/floor/floor-generator.cpp +++ b/src/floor/floor-generator.cpp @@ -139,7 +139,8 @@ static void generate_challenge_arena(PlayerType *player_ptr) build_arena(player_ptr, &y, &x); player_place(player_ptr, y, x); auto &entries = ArenaEntryList::get_instance(); - if (place_specific_monster(player_ptr, 0, player_ptr->y + 5, player_ptr->x, arena_info[entries.get_current_entry()].r_idx, PM_NO_KAGE | PM_NO_PET)) { + const auto &monrace = entries.get_monrace(); + if (place_specific_monster(player_ptr, 0, player_ptr->y + 5, player_ptr->x, monrace.idx, PM_NO_KAGE | PM_NO_PET)) { return; } diff --git a/src/io-dump/character-dump.cpp b/src/io-dump/character-dump.cpp index 5a0faa941..b663f6e12 100644 --- a/src/io-dump/character-dump.cpp +++ b/src/io-dump/character-dump.cpp @@ -277,12 +277,11 @@ static void dump_aux_arena(FILE *fff) if (defeated_entry && !entries.is_player_true_victor()) { const auto defeated_fight = *defeated_entry + 1; //!< entryは配列番号なので対戦回数と1つずれる. constexpr auto fmt = _("\n 闘技場: %d回戦で%sの前に敗北\n", "\n Arena: Defeated by %s in the %d%s fight\n"); - const auto &arena = arena_info[*defeated_entry]; - const auto &arena_monrace = monraces_info[arena.r_idx]; + const auto &monrace = entries.get_monrace(); #ifdef JP - fprintf(fff, fmt, defeated_fight, arena_monrace.name.data()); + fprintf(fff, fmt, defeated_fight, monrace.name.data()); #else - fprintf(fff, fmt, arena_monrace.name.data(), defeated_fight, get_ordinal_number_suffix(*defeated_entry).data()); + fprintf(fff, fmt, monrace.name.data(), defeated_fight, get_ordinal_number_suffix(*defeated_entry).data()); #endif fprintf(fff, "\n"); return; diff --git a/src/market/arena-entry.cpp b/src/market/arena-entry.cpp index 70aa2e63c..a7571e251 100644 --- a/src/market/arena-entry.cpp +++ b/src/market/arena-entry.cpp @@ -12,6 +12,57 @@ #include "system/building-type-definition.h" #include "system/monster-race-info.h" +namespace { +/*! + * @brief 闘技場のモンスターID及び報酬アイテムテーブル + */ +const std::vector ARENA_ENTRIES = { + { MonsterRaceId::NOBORTA, { ItemKindType::AMULET, SV_AMULET_ADORNMENT } }, + { MonsterRaceId::MORI_TROLL, { ItemKindType::FOOD, SV_FOOD_PINT_OF_WINE } }, + { MonsterRaceId::IMP, { ItemKindType::POTION, SV_POTION_SPEED } }, + { MonsterRaceId::LION_HEART, { ItemKindType::ROD, SV_ROD_DETECT_TRAP } }, + { MonsterRaceId::MASTER_YEEK, { ItemKindType::POTION, SV_POTION_CURING } }, + { MonsterRaceId::SABRE_TIGER, { ItemKindType::WAND, SV_WAND_STONE_TO_MUD } }, + { MonsterRaceId::LIZARD_KING, { ItemKindType::WAND, SV_WAND_TELEPORT_AWAY } }, + { MonsterRaceId::WYVERN, { ItemKindType::POTION, SV_POTION_HEALING } }, + { MonsterRaceId::ARCH_VILE, { ItemKindType::POTION, SV_POTION_RESISTANCE } }, + { MonsterRaceId::ELF_LORD, { ItemKindType::POTION, SV_POTION_ENLIGHTENMENT } }, + { MonsterRaceId::GHOUL_KING, { ItemKindType::FOOD, SV_FOOD_RESTORING } }, + { MonsterRaceId::COLBRAN, { ItemKindType::RING, SV_RING_ELEC } }, + { MonsterRaceId::BICLOPS, { ItemKindType::WAND, SV_WAND_ACID_BALL } }, + { MonsterRaceId::M_MINDCRAFTER, { ItemKindType::POTION, SV_POTION_SELF_KNOWLEDGE } }, + { MonsterRaceId::GROO, { ItemKindType::SCROLL, SV_SCROLL_ACQUIREMENT } }, + { MonsterRaceId::RAAL, { ItemKindType::SCROLL, SV_SCROLL_STAR_DESTRUCTION } }, + { MonsterRaceId::DREADMASTER, { ItemKindType::WAND, SV_WAND_HYPODYNAMIA } }, + { MonsterRaceId::ULTRA_PALADIN, { ItemKindType::STAFF, SV_STAFF_DISPEL_EVIL } }, + { MonsterRaceId::BARNEY, { ItemKindType::RING, SV_RING_RES_CHAOS } }, + { MonsterRaceId::TROLL_KING, { ItemKindType::SCROLL, SV_SCROLL_MASS_GENOCIDE } }, + { MonsterRaceId::BARON_HELL, { ItemKindType::SCROLL, SV_SCROLL_RUNE_OF_PROTECTION } }, + { MonsterRaceId::FALLEN_ANGEL, { ItemKindType::POTION, SV_POTION_AUGMENTATION } }, + { MonsterRaceId::ANCIENT_CRISTAL_DRAGON, { ItemKindType::WAND, SV_WAND_DRAGON_FIRE } }, + { MonsterRaceId::BRONZE_LICH, { ItemKindType::STAFF, SV_STAFF_DESTRUCTION } }, + { MonsterRaceId::DROLEM, { ItemKindType::POTION, SV_POTION_STAR_HEALING } }, + { MonsterRaceId::G_TITAN, { ItemKindType::WAND, SV_WAND_GENOCIDE } }, + { MonsterRaceId::G_BALROG, { ItemKindType::POTION, SV_POTION_EXPERIENCE } }, + { MonsterRaceId::ELDER_VAMPIRE, { ItemKindType::RING, SV_RING_SUSTAIN } }, + { MonsterRaceId::NIGHTWALKER, { ItemKindType::WAND, SV_WAND_STRIKING } }, + { MonsterRaceId::S_TYRANNO, { ItemKindType::SCROLL, SV_SCROLL_STAR_ACQUIREMENT } }, + { MonsterRaceId::MASTER_MYSTIC, { ItemKindType::ROD, SV_ROD_IDENTIFY } }, + { MonsterRaceId::LORD_CHAOS, { ItemKindType::POTION, SV_POTION_LIFE } }, + { MonsterRaceId::SHADOWLORD, { ItemKindType::POTION, SV_POTION_STAR_ENLIGHTENMENT } }, + { MonsterRaceId::ULT_BEHOLDER, { ItemKindType::AMULET, SV_AMULET_REFLECTION } }, + { MonsterRaceId::JABBERWOCK, { ItemKindType::ROD, SV_ROD_HEALING } }, + { MonsterRaceId::LOCKE_CLONE, { ItemKindType::WAND, SV_WAND_DISINTEGRATE } }, + { MonsterRaceId::WYRM_SPACE, { ItemKindType::ROD, SV_ROD_RESTORATION } }, + { MonsterRaceId::SHAMBLER, { ItemKindType::SCROLL, SV_SCROLL_STAR_ACQUIREMENT } }, + { MonsterRaceId::BLACK_REAVER, { ItemKindType::RING, SV_RING_LORDLY } }, + { MonsterRaceId::FENGHUANG, { ItemKindType::STAFF, SV_STAFF_THE_MAGI } }, + { MonsterRaceId::WYRM_POWER, { ItemKindType::SCROLL, SV_SCROLL_ARTIFACT } }, + { MonraceList::empty_id(), { ItemKindType::NONE, 0 } }, /* Victory prizing */ + { MonsterRaceId::HAGURE, { ItemKindType::SCROLL, SV_SCROLL_ARTIFACT } }, +}; +} + ArenaEntryList ArenaEntryList::instance{}; ArenaEntryList &ArenaEntryList::get_instance() @@ -24,7 +75,7 @@ ArenaEntryList &ArenaEntryList::get_instance() */ int ArenaEntryList::get_max_entries() const { - return std::ssize(arena_info) - 2; + return std::ssize(ARENA_ENTRIES) - 2; } int ArenaEntryList::get_current_entry() const @@ -47,6 +98,21 @@ bool ArenaEntryList::is_player_true_victor() const return this->current_entry > this->get_max_entries(); } +const BaseitemKey &ArenaEntryList::get_bi_key() const +{ + return ARENA_ENTRIES.at(this->current_entry).key; +} + +MonsterRaceInfo &ArenaEntryList::get_monrace() +{ + return MonraceList::get_instance().get_monrace(ARENA_ENTRIES.at(this->current_entry).monrace_id); +} + +const MonsterRaceInfo &ArenaEntryList::get_monrace() const +{ + return MonraceList::get_instance().get_monrace(ARENA_ENTRIES.at(this->current_entry).monrace_id); +} + void ArenaEntryList::increment_entry() { this->current_entry++; @@ -77,52 +143,3 @@ void ArenaEntryList::load_defeated_entry(int entry) this->defeated_entry = entry; } - -/*! - * @brief 闘技場のモンスターID及び報酬アイテムテーブル - */ -const std::vector arena_info = { - { MonsterRaceId::NOBORTA, { ItemKindType::AMULET, SV_AMULET_ADORNMENT } }, - { MonsterRaceId::MORI_TROLL, { ItemKindType::FOOD, SV_FOOD_PINT_OF_WINE } }, - { MonsterRaceId::IMP, { ItemKindType::POTION, SV_POTION_SPEED } }, - { MonsterRaceId::LION_HEART, { ItemKindType::ROD, SV_ROD_DETECT_TRAP } }, - { MonsterRaceId::MASTER_YEEK, { ItemKindType::POTION, SV_POTION_CURING } }, - { MonsterRaceId::SABRE_TIGER, { ItemKindType::WAND, SV_WAND_STONE_TO_MUD } }, - { MonsterRaceId::LIZARD_KING, { ItemKindType::WAND, SV_WAND_TELEPORT_AWAY } }, - { MonsterRaceId::WYVERN, { ItemKindType::POTION, SV_POTION_HEALING } }, - { MonsterRaceId::ARCH_VILE, { ItemKindType::POTION, SV_POTION_RESISTANCE } }, - { MonsterRaceId::ELF_LORD, { ItemKindType::POTION, SV_POTION_ENLIGHTENMENT } }, - { MonsterRaceId::GHOUL_KING, { ItemKindType::FOOD, SV_FOOD_RESTORING } }, - { MonsterRaceId::COLBRAN, { ItemKindType::RING, SV_RING_ELEC } }, - { MonsterRaceId::BICLOPS, { ItemKindType::WAND, SV_WAND_ACID_BALL } }, - { MonsterRaceId::M_MINDCRAFTER, { ItemKindType::POTION, SV_POTION_SELF_KNOWLEDGE } }, - { MonsterRaceId::GROO, { ItemKindType::SCROLL, SV_SCROLL_ACQUIREMENT } }, - { MonsterRaceId::RAAL, { ItemKindType::SCROLL, SV_SCROLL_STAR_DESTRUCTION } }, - { MonsterRaceId::DREADMASTER, { ItemKindType::WAND, SV_WAND_HYPODYNAMIA } }, - { MonsterRaceId::ULTRA_PALADIN, { ItemKindType::STAFF, SV_STAFF_DISPEL_EVIL } }, - { MonsterRaceId::BARNEY, { ItemKindType::RING, SV_RING_RES_CHAOS } }, - { MonsterRaceId::TROLL_KING, { ItemKindType::SCROLL, SV_SCROLL_MASS_GENOCIDE } }, - { MonsterRaceId::BARON_HELL, { ItemKindType::SCROLL, SV_SCROLL_RUNE_OF_PROTECTION } }, - { MonsterRaceId::FALLEN_ANGEL, { ItemKindType::POTION, SV_POTION_AUGMENTATION } }, - { MonsterRaceId::ANCIENT_CRISTAL_DRAGON, { ItemKindType::WAND, SV_WAND_DRAGON_FIRE } }, - { MonsterRaceId::BRONZE_LICH, { ItemKindType::STAFF, SV_STAFF_DESTRUCTION } }, - { MonsterRaceId::DROLEM, { ItemKindType::POTION, SV_POTION_STAR_HEALING } }, - { MonsterRaceId::G_TITAN, { ItemKindType::WAND, SV_WAND_GENOCIDE } }, - { MonsterRaceId::G_BALROG, { ItemKindType::POTION, SV_POTION_EXPERIENCE } }, - { MonsterRaceId::ELDER_VAMPIRE, { ItemKindType::RING, SV_RING_SUSTAIN } }, - { MonsterRaceId::NIGHTWALKER, { ItemKindType::WAND, SV_WAND_STRIKING } }, - { MonsterRaceId::S_TYRANNO, { ItemKindType::SCROLL, SV_SCROLL_STAR_ACQUIREMENT } }, - { MonsterRaceId::MASTER_MYSTIC, { ItemKindType::ROD, SV_ROD_IDENTIFY } }, - { MonsterRaceId::LORD_CHAOS, { ItemKindType::POTION, SV_POTION_LIFE } }, - { MonsterRaceId::SHADOWLORD, { ItemKindType::POTION, SV_POTION_STAR_ENLIGHTENMENT } }, - { MonsterRaceId::ULT_BEHOLDER, { ItemKindType::AMULET, SV_AMULET_REFLECTION } }, - { MonsterRaceId::JABBERWOCK, { ItemKindType::ROD, SV_ROD_HEALING } }, - { MonsterRaceId::LOCKE_CLONE, { ItemKindType::WAND, SV_WAND_DISINTEGRATE } }, - { MonsterRaceId::WYRM_SPACE, { ItemKindType::ROD, SV_ROD_RESTORATION } }, - { MonsterRaceId::SHAMBLER, { ItemKindType::SCROLL, SV_SCROLL_STAR_ACQUIREMENT } }, - { MonsterRaceId::BLACK_REAVER, { ItemKindType::RING, SV_RING_LORDLY } }, - { MonsterRaceId::FENGHUANG, { ItemKindType::STAFF, SV_STAFF_THE_MAGI } }, - { MonsterRaceId::WYRM_POWER, { ItemKindType::SCROLL, SV_SCROLL_ARTIFACT } }, - { MonraceList::empty_id(), { ItemKindType::NONE, 0 } }, /* Victory prizing */ - { MonsterRaceId::HAGURE, { ItemKindType::SCROLL, SV_SCROLL_ARTIFACT } }, -}; diff --git a/src/market/arena-entry.h b/src/market/arena-entry.h index 7f00df59e..29fe3be79 100644 --- a/src/market/arena-entry.h +++ b/src/market/arena-entry.h @@ -8,19 +8,20 @@ /*! * @brief 闘技場のモンスターエントリー構造体 */ -enum class MonsterRaceId : int16_t; +enum class MonsterRaceId : short; class ArenaMonsterEntry { public: ArenaMonsterEntry(MonsterRaceId r_idx, const BaseitemKey &key) - : r_idx(r_idx) + : monrace_id(r_idx) , key(key) { } - MonsterRaceId r_idx; /*!< 闘技場のモンスター種族ID(0ならば表彰式) / Monster (0 means victory prizing) */ + MonsterRaceId monrace_id; /*!< 闘技場のモンスター種族ID(0ならば表彰式) / Monster (0 means victory prizing) */ BaseitemKey key; }; +class MonsterRaceInfo; class ArenaEntryList { public: ~ArenaEntryList() = default; @@ -35,6 +36,9 @@ public: std::optional get_defeated_entry() const; bool is_player_victor() const; bool is_player_true_victor() const; + const BaseitemKey &get_bi_key() const; + MonsterRaceInfo &get_monrace(); + const MonsterRaceInfo &get_monrace() const; void increment_entry(); void reset_entry(); void set_defeated_entry(); @@ -48,5 +52,3 @@ private: int current_entry = 0; //!< 現在の対戦相手. std::optional defeated_entry; //!< 負けた相手. 無敗ならnullopt. v1.5.0.1以前の敗北済セーブデータは0固定. }; - -extern const std::vector arena_info; diff --git a/src/market/arena.cpp b/src/market/arena.cpp index 6ec0f9c14..56fdca0b5 100644 --- a/src/market/arena.cpp +++ b/src/market/arena.cpp @@ -159,8 +159,7 @@ static void see_arena_poster(PlayerType *player_ptr) return; } - const auto current_entry = entries.get_current_entry(); - const auto &monrace = MonraceList::get_instance().get_monrace(arena_info[current_entry].r_idx); + const auto &monrace = entries.get_monrace(); msg_format(_("%s に挑戦するものはいないか?", "Do I hear any challenges against: %s"), monrace.name.data()); LoreTracker::get_instance().set_trackee(monrace.idx); handle_stuff(player_ptr); diff --git a/src/monster-floor/monster-death.cpp b/src/monster-floor/monster-death.cpp index 9bc388eff..50aad1216 100644 --- a/src/monster-floor/monster-death.cpp +++ b/src/monster-floor/monster-death.cpp @@ -89,10 +89,9 @@ static void on_defeat_arena_monster(PlayerType *player_ptr, MonsterDeath *md_ptr msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion.")); } - const auto &arena = arena_info[entries.get_current_entry()]; - const auto tval = arena.key.tval(); - if (tval > ItemKindType::NONE) { - ItemEntity item(arena.key); + const auto &bi_key = entries.get_bi_key(); + if (bi_key.is_valid()) { + ItemEntity item(bi_key); ItemMagicApplier(player_ptr, &item, floor.object_level, AM_NO_FIXED_ART).execute(); (void)drop_near(player_ptr, &item, -1, md_ptr->md_y, md_ptr->md_x); } diff --git a/src/player/player-damage.cpp b/src/player/player-damage.cpp index de6ec9f25..8f549ccf6 100644 --- a/src/player/player-damage.cpp +++ b/src/player/player-damage.cpp @@ -378,8 +378,7 @@ int take_hit(PlayerType *player_ptr, int damage_type, int damage, std::string_vi if (floor.inside_arena) { auto &entries = ArenaEntryList::get_instance(); entries.set_defeated_entry(); - const auto current_entry = entries.get_current_entry(); - const auto &m_name = monraces_info[arena_info[current_entry].r_idx].name; + const auto &m_name = entries.get_monrace().name; msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name.data()); msg_print(nullptr); if (record_arena) { diff --git a/src/system/baseitem-info.cpp b/src/system/baseitem-info.cpp index ed4757be0..3fbeb7f4e 100644 --- a/src/system/baseitem-info.cpp +++ b/src/system/baseitem-info.cpp @@ -61,6 +61,11 @@ std::optional BaseitemKey::sval() const return this->subtype_value; } +bool BaseitemKey::is_valid() const +{ + return (this->type_value > ItemKindType::NONE) && this->subtype_value.has_value(); +} + bool BaseitemKey::is(ItemKindType tval) const { return this->type_value == tval; diff --git a/src/system/baseitem-info.h b/src/system/baseitem-info.h index ee02bffe6..c8511eb14 100644 --- a/src/system/baseitem-info.h +++ b/src/system/baseitem-info.h @@ -49,8 +49,8 @@ public: ItemKindType tval() const; std::optional sval() const; + bool is_valid() const; bool is(ItemKindType tval) const; - ItemKindType get_arrow_kind() const; bool is_spell_book() const; bool is_high_level_book() const; -- 2.11.0