OSDN Git Service

モンスター魔法「ユニークモンスター口寄せ」を追加。併せて使用するモンスターの追加、巨大サイバー以下略の使用魔法に追加、青魔法とものまねも追加。
[hengbandforosx/hengbandosx.git] / src / object-enchant / others / apply-magic-others.cpp
index c73736a..12be934 100644 (file)
@@ -9,25 +9,27 @@
 #include "artifact/random-art-generator.h"
 #include "game-option/cheat-options.h"
 #include "inventory/inventory-slot-types.h"
+#include "monster-floor/place-monster-types.h"
 #include "monster-race/monster-race-hook.h"
 #include "monster-race/monster-race.h"
-#include "monster-race/race-flags9.h"
 #include "monster-race/race-indice-types.h"
 #include "monster/monster-list.h"
 #include "monster/monster-util.h"
 #include "object-enchant/object-ego.h"
 #include "object-enchant/tr-types.h"
 #include "object-enchant/trc-types.h"
-#include "object/object-kind.h"
+#include "object/tval-types.h"
 #include "perception/object-perception.h"
 #include "sv-definition/sv-lite-types.h"
 #include "sv-definition/sv-other-types.h"
+#include "system/baseitem-info.h"
 #include "system/floor-type-definition.h"
-#include "system/monster-race-definition.h"
-#include "system/object-type-definition.h"
+#include "system/item-entity.h"
+#include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
+#include <unordered_map>
 
 /*!
  * @brief コンストラクタ
@@ -36,7 +38,7 @@
  * @param power 生成ランク
  * @details power > 2はデバッグ専用.
  */
-OtherItemsEnchanter::OtherItemsEnchanter(PlayerType *player_ptr, ObjectType *o_ptr)
+OtherItemsEnchanter::OtherItemsEnchanter(PlayerType *player_ptr, ItemEntity *o_ptr)
     : player_ptr(player_ptr)
     , o_ptr(o_ptr)
 {
@@ -48,7 +50,8 @@ OtherItemsEnchanter::OtherItemsEnchanter(PlayerType *player_ptr, ObjectType *o_p
  */
 void OtherItemsEnchanter::apply_magic()
 {
-    switch (this->o_ptr->tval) {
+    const auto tval = this->o_ptr->bi_key.tval();
+    switch (tval) {
     case ItemKindType::FLASK:
         this->o_ptr->fuel = this->o_ptr->pval;
         this->o_ptr->pval = 0;
@@ -58,7 +61,7 @@ void OtherItemsEnchanter::apply_magic()
         this->enchant_wand_staff();
         break;
     case ItemKindType::ROD:
-        this->o_ptr->pval = k_info[this->o_ptr->k_idx].pval;
+        this->o_ptr->pval = this->o_ptr->get_baseitem().pval;
         break;
     case ItemKindType::CAPTURE:
         this->o_ptr->pval = 0;
@@ -89,8 +92,8 @@ void OtherItemsEnchanter::apply_magic()
  */
 void OtherItemsEnchanter::enchant_wand_staff()
 {
-    auto *k_ptr = &k_info[this->o_ptr->k_idx];
-    this->o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
+    const auto &baseitem = this->o_ptr->get_baseitem();
+    this->o_ptr->pval = baseitem.pval / 2 + randint1((baseitem.pval + 1) / 2);
 }
 
 /*
@@ -104,14 +107,14 @@ void OtherItemsEnchanter::enchant_wand_staff()
 void OtherItemsEnchanter::generate_figurine()
 {
     auto *floor_ptr = this->player_ptr->current_floor_ptr;
-    short r_idx;
+    MonsterRaceId r_idx;
     while (true) {
-        r_idx = randint1(r_info.size() - 1);
-        if (!item_monster_okay(this->player_ptr, r_idx) || (r_idx == MON_TSUCHINOKO)) {
+        r_idx = MonsterRace::pick_one_at_random();
+        if (!item_monster_okay(this->player_ptr, r_idx) || (r_idx == MonsterRaceId::TSUCHINOKO)) {
             continue;
         }
 
-        auto *r_ptr = &r_info[r_idx];
+        auto *r_ptr = &monraces_info[r_idx];
         auto check = (floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - floor_ptr->dun_level) : 0;
         if ((r_ptr->rarity == 0) || (r_ptr->rarity > 100) || (randint0(check) > 0)) {
             continue;
@@ -120,7 +123,7 @@ void OtherItemsEnchanter::generate_figurine()
         break;
     }
 
-    this->o_ptr->pval = r_idx;
+    this->o_ptr->pval = enum2i(r_idx);
     if (one_in_(6)) {
         this->o_ptr->curse_flags.set(CurseTraitType::CURSED);
     }
@@ -136,28 +139,31 @@ void OtherItemsEnchanter::generate_figurine()
  */
 void OtherItemsEnchanter::generate_corpse()
 {
-    uint32_t match = 0;
-    if (this->o_ptr->sval == SV_SKELETON) {
-        match = RF9_DROP_SKELETON;
-    } else if (this->o_ptr->sval == SV_CORPSE) {
-        match = RF9_DROP_CORPSE;
-    }
+    const std::unordered_map<int, MonsterDropType> match = {
+        { SV_SKELETON, MonsterDropType::DROP_SKELETON },
+        { SV_CORPSE, MonsterDropType::DROP_CORPSE },
+    };
 
     get_mon_num_prep(this->player_ptr, item_monster_okay, nullptr);
     auto *floor_ptr = this->player_ptr->current_floor_ptr;
-    short r_idx;
+    MonsterRaceId r_idx;
     while (true) {
-        r_idx = get_mon_num(this->player_ptr, 0, floor_ptr->dun_level, 0);
-        auto &r_ref = r_info[r_idx];
+        r_idx = get_mon_num(this->player_ptr, 0, floor_ptr->dun_level, PM_NONE);
+        auto &r_ref = monraces_info[r_idx];
         auto check = (floor_ptr->dun_level < r_ref.level) ? (r_ref.level - floor_ptr->dun_level) : 0;
-        if ((r_ref.rarity == 0) || none_bits(r_ref.flags9, match) || (randint0(check) > 0)) {
+        const auto sval = this->o_ptr->bi_key.sval();
+        if (!sval.has_value()) {
+            continue;
+        }
+
+        if ((r_ref.rarity == 0) || (match.find(sval.value()) != match.end() && r_ref.drop_flags.has_not(match.at(sval.value()))) || (randint0(check) > 0)) {
             continue;
         }
 
         break;
     }
 
-    this->o_ptr->pval = r_idx;
+    this->o_ptr->pval = enum2i(r_idx);
     object_aware(this->player_ptr, this->o_ptr);
     object_known(this->o_ptr);
 }
@@ -168,21 +174,20 @@ void OtherItemsEnchanter::generate_corpse()
  */
 void OtherItemsEnchanter::generate_statue()
 {
-    short r_idx;
-    const auto *r_ptr = &r_info[1];
-    while (true) {
-        r_idx = randint1(r_info.size() - 1);
-        r_ptr = &r_info[r_idx];
-        if (r_ptr->rarity == 0) {
-            continue;
+    auto pick_r_idx_for_statue = [] {
+        while (true) {
+            auto r_idx = MonsterRace::pick_one_at_random();
+            if (monraces_info[r_idx].rarity > 0) {
+                return r_idx;
+            }
         }
+    };
+    auto r_idx = pick_r_idx_for_statue();
+    auto *r_ptr = &monraces_info[r_idx];
 
-        break;
-    }
-
-    this->o_ptr->pval = r_idx;
+    this->o_ptr->pval = enum2i(r_idx);
     if (cheat_peek) {
-        msg_format(_("%sの像", "Statue of %s"), r_ptr->name.c_str());
+        msg_format(_("%sの像", "Statue of %s"), r_ptr->name.data());
     }
 
     object_aware(this->player_ptr, this->o_ptr);
@@ -195,13 +200,13 @@ void OtherItemsEnchanter::generate_statue()
  */
 void OtherItemsEnchanter::generate_chest()
 {
-    auto obj_level = k_info[this->o_ptr->k_idx].level;
+    auto obj_level = this->o_ptr->get_baseitem().level;
     if (obj_level <= 0) {
         return;
     }
 
     this->o_ptr->pval = randint1(obj_level);
-    if (this->o_ptr->sval == SV_CHEST_KANDUME) {
+    if (this->o_ptr->bi_key.sval() == SV_CHEST_KANDUME) {
         this->o_ptr->pval = 6;
     }