OSDN Git Service

[Refactor] #1372 フロア中の最大アイテム数/最大モンスター数をgamevalue.h にコンパイル時定数で移した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 9 Dec 2023 13:24:14 +0000 (22:24 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 6 Apr 2024 12:16:22 +0000 (21:16 +0900)
src/dungeon/dungeon-processor.cpp
src/floor/floor-generator.cpp
src/load/floor-loader.cpp
src/load/old/load-v1-5-0.cpp
src/main/game-data-initializer.cpp
src/monster/monster-list.cpp
src/monster/monster-status.cpp
src/system/gamevalue.h
src/world/world-object.cpp
src/world/world.h

index 7c65ba5..d2ae3a1 100644 (file)
@@ -212,7 +212,7 @@ void process_dungeon(PlayerType *player_ptr, bool load_game)
     mproc_init(&floor);
 
     while (true) {
-        if ((floor.m_cnt + 32 > w_ptr->max_m_idx) && !is_watching) {
+        if ((floor.m_cnt + 32 > MAX_FLOOR_MONSTERS) && !is_watching) {
             compact_monsters(player_ptr, 64);
         }
 
@@ -220,7 +220,7 @@ void process_dungeon(PlayerType *player_ptr, bool load_game)
             compact_monsters(player_ptr, 0);
         }
 
-        if (floor.o_cnt + 32 > w_ptr->max_o_idx) {
+        if (floor.o_cnt + 32 > MAX_FLOOR_ITEMS) {
             compact_objects(player_ptr, 64);
         }
 
index 156f45c..0339a2c 100644 (file)
@@ -516,10 +516,10 @@ void generate_floor(PlayerType *player_ptr)
             okay = level_gen(player_ptr, &why);
         }
 
-        if (floor_ptr->o_max >= w_ptr->max_o_idx) {
+        if (floor_ptr->o_max >= MAX_FLOOR_ITEMS) {
             why = _("アイテムが多すぎる", "too many objects");
             okay = false;
-        } else if (floor_ptr->m_max >= w_ptr->max_m_idx) {
+        } else if (floor_ptr->m_max >= MAX_FLOOR_MONSTERS) {
             why = _("モンスターが多すぎる", "too many monsters");
             okay = false;
         }
index 4dfce27..030e002 100644 (file)
@@ -163,7 +163,7 @@ errr rd_saved_floor(PlayerType *player_ptr, saved_floor_type *sf_ptr)
     }
 
     limit = rd_u16b();
-    if (limit > w_ptr->max_o_idx) {
+    if (limit > MAX_FLOOR_ITEMS) {
         return 151;
     }
 
@@ -181,7 +181,7 @@ errr rd_saved_floor(PlayerType *player_ptr, saved_floor_type *sf_ptr)
     }
 
     limit = rd_u16b();
-    if (limit > w_ptr->max_m_idx) {
+    if (limit > MAX_FLOOR_MONSTERS) {
         return 161;
     }
 
index 1eda0d8..71aa645 100644 (file)
@@ -726,7 +726,7 @@ errr rd_dungeon_old(PlayerType *player_ptr)
 
     uint16_t limit;
     limit = rd_u16b();
-    if (limit > w_ptr->max_o_idx) {
+    if (limit > MAX_FLOOR_ITEMS) {
         load_note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
         return 151;
     }
@@ -746,7 +746,7 @@ errr rd_dungeon_old(PlayerType *player_ptr)
     }
 
     limit = rd_u16b();
-    if (limit > w_ptr->max_m_idx) {
+    if (limit > MAX_FLOOR_MONSTERS) {
         load_note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
         return 161;
     }
index 3b5b712..64cc3ca 100644 (file)
@@ -24,7 +24,6 @@
 #include "util/angband-files.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
-#include "world/world.h"
 #include <algorithm>
 
 /*!
@@ -49,10 +48,10 @@ void init_other(PlayerType *player_ptr)
 {
     player_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
     auto *floor_ptr = player_ptr->current_floor_ptr;
-    floor_ptr->o_list.assign(w_ptr->max_o_idx, {});
-    floor_ptr->m_list.assign(w_ptr->max_m_idx, {});
+    floor_ptr->o_list.assign(MAX_FLOOR_ITEMS, {});
+    floor_ptr->m_list.assign(MAX_FLOOR_MONSTERS, {});
     for (auto &list : floor_ptr->mproc_list) {
-        list.assign(w_ptr->max_m_idx, {});
+        list.assign(MAX_FLOOR_MONSTERS, {});
     }
 
     max_dlv.assign(dungeons_info.size(), {});
index 560dedb..71ed8c5 100644 (file)
 MONSTER_IDX m_pop(FloorType *floor_ptr)
 {
     /* Normal allocation */
-    if (floor_ptr->m_max < w_ptr->max_m_idx) {
-        MONSTER_IDX i = floor_ptr->m_max;
+    if (floor_ptr->m_max < MAX_FLOOR_MONSTERS) {
+        const auto i = floor_ptr->m_max;
         floor_ptr->m_max++;
         floor_ptr->m_cnt++;
         return i;
     }
 
     /* Recycle dead monsters */
-    for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++) {
-        MonsterEntity *m_ptr;
-        m_ptr = &floor_ptr->m_list[i];
-        if (MonsterRace(m_ptr->r_idx).is_valid()) {
+    for (short i = 1; i < floor_ptr->m_max; i++) {
+        const auto &monster = floor_ptr->m_list[i];
+        if (MonsterRace(monster.r_idx).is_valid()) {
             continue;
         }
+
         floor_ptr->m_cnt++;
         return i;
     }
@@ -79,6 +79,7 @@ MONSTER_IDX m_pop(FloorType *floor_ptr)
     if (w_ptr->character_dungeon) {
         msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
     }
+
     return 0;
 }
 
index d28f353..37805d3 100644 (file)
@@ -25,7 +25,6 @@
 #include "timed-effect/timed-effects.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
-#include "world/world.h"
 #if JP
 #else
 #include "monster/monster-description-types.h"
@@ -130,7 +129,7 @@ int get_mproc_idx(FloorType *floor_ptr, MONSTER_IDX m_idx, int mproc_type)
  */
 void mproc_add(FloorType *floor_ptr, MONSTER_IDX m_idx, int mproc_type)
 {
-    if (floor_ptr->mproc_max[mproc_type] < w_ptr->max_m_idx) {
+    if (floor_ptr->mproc_max[mproc_type] < MAX_FLOOR_MONSTERS) {
         floor_ptr->mproc_list[mproc_type][floor_ptr->mproc_max[mproc_type]++] = (int16_t)m_idx;
     }
 }
index 1368f9c..2e9185c 100644 (file)
@@ -21,6 +21,8 @@ constexpr auto MAX_MONSTER_SENSING = 100; /*!< モンスターの最大感知グ
 constexpr auto CHANCE_ABILITY_SCORE_DECREASE = 16; /*!< 属性攻撃を受けた際に能力値低下を起こす確率(1/n) */
 constexpr auto CHANCE_STRENGTHENING = 12; /*!< ランダムアーティファクトにバイアス外の耐性がつき、4を超えるpvalを許可する確率 */
 constexpr auto STANDARD_SPEED = 110; /* プレイヤー/モンスターの標準速度 (加速0) */
+constexpr short MAX_FLOOR_ITEMS = 1024; /*!< 1フロアに存在可能な最大アイテム数 */
+constexpr short MAX_FLOOR_MONSTERS = 1024; /*!< 1フロアに存在可能な最大モンスター数 */
 
 /*!
  * @brief 1フロアに存在可能な、増殖フラグ付きモンスター実体の最大数
index 34351dc..cb5c30b 100644 (file)
  */
 OBJECT_IDX o_pop(FloorType *floor_ptr)
 {
-    if (floor_ptr->o_max < w_ptr->max_o_idx) {
-        OBJECT_IDX i = floor_ptr->o_max;
+    if (floor_ptr->o_max < MAX_FLOOR_ITEMS) {
+        const auto i = floor_ptr->o_max;
         floor_ptr->o_max++;
         floor_ptr->o_cnt++;
         return i;
     }
 
-    for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++) {
+    for (short i = 1; i < floor_ptr->o_max; i++) {
         if (floor_ptr->o_list[i].is_valid()) {
             continue;
         }
index 58abdfc..73fa029 100644 (file)
@@ -70,9 +70,6 @@ public:
 
     bool wizard{}; /* This world under wizard mode */
 
-    OBJECT_IDX max_o_idx = 1024; /*!< 1フロアに存在可能な最大アイテム数 */
-    MONSTER_IDX max_m_idx = 1024; /*!< 1フロアに存在可能な最大モンスター数 */
-
     void set_arena(const bool new_status);
     bool get_arena() const;
     std::tuple<int, int, int> extract_date_time(PlayerRaceType start_race) const;