OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Relocate-score-server' into...
[hengband/hengband.git] / src / object-enchant / apply-magic.c
index 204e45d..e81baee 100644 (file)
@@ -6,14 +6,14 @@
  */
 
 #include "object-enchant/apply-magic.h"
-#include "art-definition/art-armor-types.h"
+#include "artifact/fixed-art-types.h"
+#include "artifact/fixed-art-generator.h"
 #include "dungeon/dungeon.h"
-#include "floor/floor.h"
+#include "mutation/mutation-flag-types.h"
 #include "object-enchant/apply-magic-accessory.h"
 #include "object-enchant/apply-magic-armor.h"
 #include "object-enchant/apply-magic-others.h"
 #include "object-enchant/apply-magic-weapon.h"
-#include "object-enchant/artifact.h"
 #include "object-enchant/item-apply-magic.h"
 #include "object-enchant/object-boost.h"
 #include "object-enchant/object-curse.h"
 #include "object-enchant/tr-types.h"
 #include "object-enchant/trc-types.h"
 #include "object-enchant/trg-types.h"
-#include "object/object-hook.h"
+#include "object-hook/hook-checker.h"
+#include "object-hook/hook-enchant.h"
 #include "object/object-kind.h"
+#include "player/player-status-flags.h"
 #include "sv-definition/sv-armor-types.h"
 #include "sv-definition/sv-protector-types.h"
 #include "sv-definition/sv-weapon-types.h"
+#include "system/artifact-type-definition.h"
+#include "system/floor-type-definition.h"
 #include "util/bit-flags-calculator.h"
 #include "world/world.h"
 
 /*!
+ * @brief 0 および負数に対応した randint1()
+ * @param n
+ *
+ * n == 0 のとき、常に 0 を返す。
+ * n >  0 のとき、[1, n] の乱数を返す。
+ * n <  0 のとき、[n,-1] の乱数を返す。
+ */
+static int randint1_signed(const int n)
+{
+    if (n == 0)
+        return 0;
+
+    return n > 0 ? randint1(n) : -randint1(-n);
+}
+
+/*!
  * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
  * Complete the "creation" of an object by applying "magic" to the item
  * @param owner_ptr プレーヤーへの参照ポインタ
@@ -56,7 +76,7 @@ void apply_magic(player_type *owner_ptr, object_type *o_ptr, DEPTH lev, BIT_FLAG
     if ((owner_ptr->pseikaku != PERSONALITY_MUNCHKIN) && (f2 > d_info[owner_ptr->dungeon_idx].obj_great))
         f2 = d_info[owner_ptr->dungeon_idx].obj_great;
 
-    if (owner_ptr->muta3 & MUT3_GOOD_LUCK) {
+    if (has_good_luck(owner_ptr)) {
         f1 += 5;
         f2 += 2;
     } else if (owner_ptr->muta3 & MUT3_BAD_LUCK) {
@@ -97,7 +117,7 @@ void apply_magic(player_type *owner_ptr, object_type *o_ptr, DEPTH lev, BIT_FLAG
     for (int i = 0; i < rolls; i++) {
         if (make_artifact(owner_ptr, o_ptr))
             break;
-        if ((owner_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77)) {
+        if (has_good_luck(owner_ptr) && one_in_(77)) {
             if (make_artifact(owner_ptr, o_ptr))
                 break;
         }
@@ -260,26 +280,9 @@ void apply_magic(player_type *owner_ptr, object_type *o_ptr, DEPTH lev, BIT_FLAG
             if (e_ptr->max_pval)
                 o_ptr->pval -= randint1(e_ptr->max_pval);
         } else {
-            if (e_ptr->max_to_h) {
-                if (e_ptr->max_to_h > 127)
-                    o_ptr->to_h -= randint1(256 - e_ptr->max_to_h);
-                else
-                    o_ptr->to_h += randint1(e_ptr->max_to_h);
-            }
-
-            if (e_ptr->max_to_d) {
-                if (e_ptr->max_to_d > 127)
-                    o_ptr->to_d -= randint1(256 - e_ptr->max_to_d);
-                else
-                    o_ptr->to_d += randint1(e_ptr->max_to_d);
-            }
-
-            if (e_ptr->max_to_a) {
-                if (e_ptr->max_to_a > 127)
-                    o_ptr->to_a -= randint1(256 - e_ptr->max_to_a);
-                else
-                    o_ptr->to_a += randint1(e_ptr->max_to_a);
-            }
+            o_ptr->to_h += (HIT_PROB)randint1_signed(e_ptr->max_to_h);
+            o_ptr->to_d += randint1_signed(e_ptr->max_to_d);
+            o_ptr->to_a += (ARMOUR_CLASS)randint1_signed(e_ptr->max_to_a);
 
             if (o_ptr->name2 == EGO_ACCURACY) {
                 while (o_ptr->to_h < o_ptr->to_d + 10) {
@@ -302,12 +305,12 @@ void apply_magic(player_type *owner_ptr, object_type *o_ptr, DEPTH lev, BIT_FLAG
             }
 
             if (e_ptr->max_pval) {
-                if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS))) {
+                if ((o_ptr->name2 == EGO_HA) && (has_flag(o_ptr->art_flags, TR_BLOWS))) {
                     o_ptr->pval++;
                     if ((lev > 60) && one_in_(3) && ((o_ptr->dd * (o_ptr->ds + 1)) < 15))
                         o_ptr->pval++;
                 } else if (o_ptr->name2 == EGO_DEMON) {
-                    if (have_flag(o_ptr->art_flags, TR_BLOWS)) {
+                    if (has_flag(o_ptr->art_flags, TR_BLOWS)) {
                         o_ptr->pval += randint1(2);
                     } else {
                         o_ptr->pval += randint1(e_ptr->max_pval);