OSDN Git Service

[Refactor] #3379 building_type に初期化子を付け、buildings を生配列からarray へ変えることで配列外アクセス時に例外を飛ばせる...
authorHourier <66951241+Hourier@users.noreply.github.com>
Thu, 8 Jun 2023 11:49:38 +0000 (20:49 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Fri, 9 Jun 2023 15:52:15 +0000 (00:52 +0900)
src/market/building-initializer.cpp
src/room/rooms-city.cpp
src/system/building-type-definition.cpp
src/system/building-type-definition.h

index 46972f0..f665b96 100644 (file)
@@ -80,7 +80,7 @@ void init_towns(void)
  */
 void init_buildings(void)
 {
-    for (auto i = 0; i < MAX_BLDG; i++) {
+    for (auto i = 0; i < MAX_BUILDINGS; i++) {
         buildings[i].name[0] = '\0';
         buildings[i].owner_name[0] = '\0';
         buildings[i].owner_race[0] = '\0';
index eceb1a7..e3d772f 100644 (file)
@@ -22,8 +22,8 @@ static bool precalc_ugarcade(int town_hgt, int town_wid, int n, std::vector<ugbl
 {
     POSITION i, y, x, center_y, center_x;
     int tmp, attempt = 10000;
-    POSITION max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
-    POSITION max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
+    auto max_buildings_height = 3 * town_hgt / MAX_TOWN_HGT;
+    auto max_buildings_width = 5 * town_wid / MAX_TOWN_WID;
     ugbldg_type *cur_ugbldg;
     std::vector<std::vector<bool>> ugarcade_used(town_hgt, std::vector<bool>(town_wid));
     bool abort;
@@ -34,13 +34,13 @@ static bool precalc_ugarcade(int town_hgt, int town_wid, int n, std::vector<ugbl
         do {
             center_y = rand_range(2, town_hgt - 3);
             center_x = rand_range(2, town_wid - 3);
-            tmp = center_y - randint1(max_bldg_hgt);
+            tmp = center_y - randint1(max_buildings_height);
             cur_ugbldg->y0 = std::max(tmp, 1);
-            tmp = center_x - randint1(max_bldg_wid);
+            tmp = center_x - randint1(max_buildings_width);
             cur_ugbldg->x0 = std::max(tmp, 1);
-            tmp = center_y + randint1(max_bldg_hgt);
+            tmp = center_y + randint1(max_buildings_height);
             cur_ugbldg->y1 = std::min(tmp, town_hgt - 2);
-            tmp = center_x + randint1(max_bldg_wid);
+            tmp = center_x + randint1(max_buildings_width);
             cur_ugbldg->x1 = std::min(tmp, town_wid - 2);
             for (abort = false, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++) {
                 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++) {
index 114c1b9..786dc79 100644 (file)
@@ -1,4 +1,4 @@
 #include "system/building-type-definition.h"
 
-building_type buildings[MAX_BLDG];
+std::array<building_type, MAX_BUILDINGS> buildings;
 MonsterRaceId battle_mon_list[4];
index 91be302..97de850 100644 (file)
@@ -3,29 +3,29 @@
 #include "player-info/class-types.h"
 #include "player-info/race-types.h"
 #include "realm/realm-types.h"
-#include "system/angband.h"
+#include <array>
 #include <vector>
 
-#define MAX_BLDG 32 /*!< 施設の種類最大数 / Number of buildings */
+constexpr auto MAX_BUILDINGS = 32; /*!< 施設の種類最大数 / Number of buildings */
 
-enum class MonsterRaceId : int16_t;
+enum class MonsterRaceId : short;
 
 struct building_type {
-    GAME_TEXT name[20]; /* proprietor name */
-    GAME_TEXT owner_name[20]; /* proprietor name */
-    GAME_TEXT owner_race[20]; /* proprietor race */
+    char name[20]{}; /* proprietor name */
+    char owner_name[20]{}; /* proprietor name */
+    char owner_race[20]{}; /* proprietor race */
 
-    GAME_TEXT act_names[8][30]; /* action names */
-    PRICE member_costs[8]; /* Costs for class members of building */
-    PRICE other_costs[8]; /* Costs for nonguild members */
-    char letters[8]; /* action letters */
-    int16_t actions[8]; /*!< 町の施設処理における行動ID */
-    int16_t action_restr[8]; /*!< 町の施設処理の規制処理ID */
+    char act_names[8][30]{}; /* action names */
+    int member_costs[8]{}; /* Costs for class members of building */
+    int other_costs[8]{}; /* Costs for nonguild members */
+    char letters[8]{}; /* action letters */
+    short actions[8]{}; /*!< 町の施設処理における行動ID */
+    short action_restr[8]{}; /*!< 町の施設処理の規制処理ID */
 
-    std::vector<short> member_class; /* which classes are part of guild */
-    std::vector<short> member_race; /* which races are part of guild */
-    std::vector<short> member_realm; /* 店主ごとの魔法領域 / which realms are part of guild */
+    std::vector<short> member_class{}; /* which classes are part of guild */
+    std::vector<short> member_race{}; /* which races are part of guild */
+    std::vector<short> member_realm{}; /* 店主ごとの魔法領域 / which realms are part of guild */
 };
 
-extern building_type buildings[MAX_BLDG];
+extern std::array<building_type, MAX_BUILDINGS> buildings;
 extern MonsterRaceId battle_mon_list[4];