OSDN Git Service

[Refactor] rbm_type, rbe_type に enum バリアント数を追加
authortaotao54321 <taotao54321@gmail.com>
Sat, 13 Feb 2021 11:43:30 +0000 (20:43 +0900)
committertaotao54321 <taotao54321@gmail.com>
Sat, 13 Feb 2021 11:43:30 +0000 (20:43 +0900)
NB_<型名> というバリアントを enum のバリアント数を表す定数として定義する。
そして、配列サイズなどバリアント数が必要な箇所ではこの定数を使う。

従来は配列サイズなどを別個に定数定義していたため、enum のバリアントが増
えたのに配列サイズの方を変え忘れて配列外参照を起こしたりしていた。
本修正により自動で配列サイズの方も変わるので、少なくとも配列外参照はなく
なる。ただし、配列内容の追加忘れまでは防げない(初期化時に要素が足りなく
ても単に0初期化されるため。今後の課題)。

src/info-reader/race-info-tokens-table.c
src/info-reader/race-info-tokens-table.h
src/monster-attack/monster-attack-effect.h
src/monster-attack/monster-attack-types.c
src/monster-attack/monster-attack-types.h

index ce59888..5de0e6c 100644 (file)
@@ -1,10 +1,12 @@
 #include "info-reader/race-info-tokens-table.h"
+#include "monster-attack/monster-attack-effect.h"
+#include "monster-attack/monster-attack-types.h"
 
 /*!
   * モンスターの打撃手段トークンの定義 /
   * Monster Blow Methods
   */
-concptr r_info_blow_method[NUM_R_BLOW_METHOD] = {
+concptr r_info_blow_method[NB_RBM_TYPE + 1] = {
        "",
        "HIT",
        "TOUCH",
@@ -38,7 +40,7 @@ concptr r_info_blow_method[NUM_R_BLOW_METHOD] = {
  * モンスターの打撃属性トークンの定義 /
  * Monster Blow Effects
  */
-concptr r_info_blow_effect[NUM_R_BLOW_EFFECT] = {
+concptr r_info_blow_effect[NB_RBE_TYPE + 1] = {
        "",
        "HURT",
        "POISON",
index b8afc28..06c1358 100644 (file)
@@ -1,9 +1,9 @@
 #pragma once
 
+#include "monster-attack/monster-attack-effect.h"
+#include "monster-attack/monster-attack-types.h"
 #include "system/angband.h"
 
-#define NUM_R_BLOW_METHOD 27
-#define NUM_R_BLOW_EFFECT 38
 #define NUM_R_FLAGS_1 32
 #define NUM_R_FLAGS_2 32
 #define NUM_R_FLAGS_3 32
@@ -15,8 +15,8 @@
 #define NUM_R_FLAGS_9 33
 #define NUM_R_FLAGS_R 32
 
-extern concptr r_info_blow_method[NUM_R_BLOW_METHOD];
-extern concptr r_info_blow_effect[NUM_R_BLOW_EFFECT];
+extern concptr r_info_blow_method[NB_RBM_TYPE + 1];
+extern concptr r_info_blow_effect[NB_RBE_TYPE + 1];
 extern concptr r_info_flags1[NUM_R_FLAGS_1];
 extern concptr r_info_flags2[NUM_R_FLAGS_2];
 extern concptr r_info_flags3[NUM_R_FLAGS_3];
index d1504c7..7f9faf0 100644 (file)
@@ -2,6 +2,9 @@
 
 /*!
  * @note モンスターの攻撃効果 / New monster blow effects
+ *
+ * "Race Blow Effect" の略。
+ * 実装の都合上、0 から始まる連番でなければならない。
  */
 typedef enum rbe_type {
     RBE_NONE = 0,
@@ -41,4 +44,6 @@ typedef enum rbe_type {
     RBE_INERTIA = 34, /*!< モンスターの攻撃効果: 減速させる*/
     RBE_STUN = 35, /*!< モンスターの攻撃効果: 朦朧とさせる*/
     RBE_FLAVOR = 36, /*!< モンスターの攻撃効果: フレーバー(メッセージ表示のみ) */
+
+    NB_RBE_TYPE, /*!< enum バリアント数 */
 } rbe_type;
index 962c1b9..642ab90 100644 (file)
@@ -1,11 +1,12 @@
 #include "monster-attack/monster-attack-types.h"
+#include "monster-attack/monster-attack-effect.h"
 #include "spell/spell-types.h"
 
 /*!
  * @brief モンスターの打撃効力テーブル /
  * The table of monsters' blow effects
  */
-const mbe_info_type mbe_info[MAX_MBE] = {
+const mbe_info_type mbe_info[NB_RBE_TYPE] = {
     {
         0,
         0,
index 555266a..52956fe 100644 (file)
@@ -1,10 +1,14 @@
 #pragma once
 
+#include "monster-attack/monster-attack-effect.h"
 #include "system/angband.h"
 
 /*!
  * @note モンスターの打撃方法 / New monster blow methods
  * 打撃の種別に応じて傷と朦朧が発生するかがコメントの通りに決まる
+ *
+ * "Race Blow Method" の略。
+ * 実装の都合上、0 から始まる連番でなければならない。
  */
 typedef enum rbm_type {
     RBM_NONE = 0,
@@ -33,13 +37,13 @@ typedef enum rbm_type {
     RBM_MOAN = 23, /*!< モンスターの攻撃種別:うめく */
     RBM_SHOW = 24, /*!< モンスターの攻撃種別:歌う */
     RBM_SHOOT = 25, /*!< モンスターの攻撃種別:射撃(非打撃) */
-} rbm_type;
 
-#define MAX_MBE 34
+    NB_RBM_TYPE, /*!< enum バリアント数 */
+} rbm_type;
 
 typedef struct mbe_info_type {
     int power; /* The attack "power" */
     int explode_type; /* Explosion effect */
 } mbe_info_type;
 
-extern const mbe_info_type mbe_info[MAX_MBE];
+extern const mbe_info_type mbe_info[NB_RBE_TYPE];