OSDN Git Service

[Refactor] #2617 struct artifact_type をclass ArtifactType にリネームした
[hengbandforosx/hengbandosx.git] / src / floor / fixed-map-generator.cpp
index 3fa99fd..427d25d 100644 (file)
@@ -1,5 +1,6 @@
 #include "floor/fixed-map-generator.h"
 #include "artifact/fixed-art-generator.h"
+#include "artifact/fixed-art-types.h"
 #include "dungeon/quest.h"
 #include "floor/floor-object.h"
 #include "floor/floor-town.h"
@@ -18,8 +19,8 @@
 #include "monster-race/race-flags7.h"
 #include "monster/monster-util.h"
 #include "monster/smart-learn-types.h"
-#include "object-enchant/apply-magic.h"
 #include "object-enchant/item-apply-magic.h"
+#include "object-enchant/item-magic-applier.h"
 #include "object-enchant/object-ego.h"
 #include "object-enchant/trg-types.h"
 #include "object/object-info.h"
@@ -74,14 +75,15 @@ static void drop_here(floor_type *floor_ptr, ObjectType *j_ptr, POSITION y, POSI
     g_ptr->o_idx_list.add(floor_ptr, o_idx);
 }
 
-static void generate_artifact(PlayerType *player_ptr, qtwg_type *qtwg_ptr, const ARTIFACT_IDX artifact_index)
+static void generate_artifact(PlayerType *player_ptr, qtwg_type *qtwg_ptr, const FixedArtifactId artifact_index)
 {
-    if (artifact_index == 0) {
+    if (artifact_index == FixedArtifactId::NONE) {
         return;
     }
 
-    if ((a_info[artifact_index].cur_num == 0) && create_named_art(player_ptr, artifact_index, *qtwg_ptr->y, *qtwg_ptr->x)) {
-        a_info[artifact_index].cur_num = 1;
+    const auto int_artifact_index = enum2i(artifact_index);
+    if (!a_info[int_artifact_index].is_generated && create_named_art(player_ptr, artifact_index, *qtwg_ptr->y, *qtwg_ptr->x)) {
+        a_info[int_artifact_index].is_generated = true;
         return;
     }
 
@@ -103,7 +105,6 @@ static void parse_qtw_D(PlayerType *player_ptr, qtwg_type *qtwg_ptr, char *s)
         OBJECT_IDX object_index = letter[idx].object;
         MONSTER_IDX monster_index = letter[idx].monster;
         int random = letter[idx].random;
-        ARTIFACT_IDX artifact_index = letter[idx].artifact;
         g_ptr->feat = conv_dungeon_feat(floor_ptr, letter[idx].feature);
         if (init_flags & INIT_ONLY_FEATURES) {
             continue;
@@ -125,23 +126,26 @@ static void parse_qtw_D(PlayerType *player_ptr, qtwg_type *qtwg_ptr, char *s)
                 clone = true;
             }
 
-            old_cur_num = r_info[monster_index].cur_num;
-            old_max_num = r_info[monster_index].max_num;
+            const auto r_idx = i2enum<MonsterRaceId>(monster_index);
+            auto &r_ref = r_info[r_idx];
 
-            if (r_info[monster_index].kind_flags.has(MonsterKindType::UNIQUE)) {
-                r_info[monster_index].cur_num = 0;
-                r_info[monster_index].max_num = 1;
-            } else if (r_info[monster_index].flags7 & RF7_NAZGUL) {
-                if (r_info[monster_index].cur_num == r_info[monster_index].max_num) {
-                    r_info[monster_index].max_num++;
+            old_cur_num = r_ref.cur_num;
+            old_max_num = r_ref.max_num;
+
+            if (r_ref.kind_flags.has(MonsterKindType::UNIQUE)) {
+                r_ref.cur_num = 0;
+                r_ref.max_num = 1;
+            } else if (r_ref.population_flags.has(MonsterPopulationType::NAZGUL)) {
+                if (r_ref.cur_num == r_ref.max_num) {
+                    r_ref.max_num++;
                 }
             }
 
-            place_monster_aux(player_ptr, 0, *qtwg_ptr->y, *qtwg_ptr->x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
+            place_monster_aux(player_ptr, 0, *qtwg_ptr->y, *qtwg_ptr->x, r_idx, (PM_ALLOW_SLEEP | PM_NO_KAGE));
             if (clone) {
                 floor_ptr->m_list[hack_m_idx_ii].mflag2.set(MonsterConstantFlagType::CLONED);
-                r_info[monster_index].cur_num = old_cur_num;
-                r_info[monster_index].max_num = old_max_num;
+                r_ref.cur_num = old_cur_num;
+                r_ref.max_num = old_max_num;
             }
         }
 
@@ -185,11 +189,11 @@ static void parse_qtw_D(PlayerType *player_ptr, qtwg_type *qtwg_ptr, char *s)
                 coin_type = 0;
             }
 
-            apply_magic_to_object(player_ptr, o_ptr, floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
+            ItemMagicApplier(player_ptr, o_ptr, floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD).execute();
             drop_here(floor_ptr, o_ptr, *qtwg_ptr->y, *qtwg_ptr->x);
         }
 
-        generate_artifact(player_ptr, qtwg_ptr, artifact_index);
+        generate_artifact(player_ptr, qtwg_ptr, letter[idx].artifact);
         g_ptr->special = letter[idx].special;
     }
 }
@@ -205,7 +209,7 @@ static bool parse_qtw_QQ(quest_type *q_ptr, char **zz, int num)
     }
 
     monster_race *r_ptr;
-    artifact_type *a_ptr;
+    ArtifactType *a_ptr;
 
     if (num < 9) {
         return true;
@@ -216,8 +220,8 @@ static bool parse_qtw_QQ(quest_type *q_ptr, char **zz, int num)
     q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
     q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
     q_ptr->level = (DEPTH)atoi(zz[6]);
-    q_ptr->r_idx = (MONRACE_IDX)atoi(zz[7]);
-    q_ptr->k_idx = (KIND_OBJECT_IDX)atoi(zz[8]);
+    q_ptr->r_idx = i2enum<MonsterRaceId>(atoi(zz[7]));
+    q_ptr->reward_artifact_idx = i2enum<FixedArtifactId>(atoi(zz[8]));
     q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
 
     if (num > 10) {
@@ -229,7 +233,7 @@ static bool parse_qtw_QQ(quest_type *q_ptr, char **zz, int num)
         r_ptr->flags1 |= RF1_QUESTOR;
     }
 
-    a_ptr = &a_info[q_ptr->k_idx];
+    a_ptr = &a_info[enum2i(q_ptr->reward_artifact_idx)];
     a_ptr->gen_flags.set(ItemGenerationTraitType::QUESTITEM);
     return true;
 }
@@ -248,24 +252,26 @@ static bool parse_qtw_QR(quest_type *q_ptr, char **zz, int num)
     }
 
     int count = 0;
-    ARTIFACT_IDX idx, reward_idx = 0;
-    for (idx = 2; idx < num; idx++) {
-        ARTIFACT_IDX a_idx = (ARTIFACT_IDX)atoi(zz[idx]);
-        if (a_idx < 1) {
+    FixedArtifactId reward_idx = FixedArtifactId::NONE;
+    for (auto idx = 2; idx < num; idx++) {
+        const auto a_idx = i2enum<FixedArtifactId>(atoi(zz[idx]));
+        if (a_idx == FixedArtifactId::NONE) {
             continue;
         }
-        if (a_info[a_idx].cur_num > 0) {
+
+        if (a_info[enum2i(a_idx)].is_generated) {
             continue;
         }
+
         count++;
         if (one_in_(count)) {
             reward_idx = a_idx;
         }
     }
 
-    if (reward_idx) {
-        q_ptr->k_idx = (KIND_OBJECT_IDX)reward_idx;
-        a_info[reward_idx].gen_flags.set(ItemGenerationTraitType::QUESTITEM);
+    if (reward_idx != FixedArtifactId::NONE) {
+        q_ptr->reward_artifact_idx = reward_idx;
+        a_info[enum2i(reward_idx)].gen_flags.set(ItemGenerationTraitType::QUESTITEM);
     } else {
         q_ptr->type = QuestKindType::KILL_ALL;
     }
@@ -300,8 +306,8 @@ static int parse_qtw_Q(qtwg_type *qtwg_ptr, char **zz)
         return PARSE_ERROR_TOO_FEW_ARGUMENTS;
     }
 
-    quest_type *q_ptr;
-    q_ptr = &(quest_map[i2enum<QuestId>(atoi(zz[0]))]);
+    auto &quest_list = QuestList::get_instance();
+    auto *q_ptr = &(quest_list[i2enum<QuestId>(atoi(zz[0]))]);
     if (parse_qtw_QQ(q_ptr, zz, num)) {
         return PARSE_ERROR_NONE;
     }
@@ -388,8 +394,6 @@ static bool parse_qtw_M(qtwg_type *qtwg_ptr, char **zz)
 
     if (zz[0][0] == 'T') {
         max_towns = static_cast<int16_t>(atoi(zz[1]));
-    } else if (zz[0][0] == 'Q') {
-        max_q_idx = (int16_t)atoi(zz[1]);
     } else if (zz[0][0] == 'O') {
         w_ptr->max_o_idx = (OBJECT_IDX)atoi(zz[1]);
     } else if (zz[0][0] == 'M') {