OSDN Git Service

[Refactor] #38997 o_pop()、drop_near()、inven_drop() にplayer_type *引数を追加 (コールチェーンが長いのでそ...
[hengband/hengband.git] / src / artifact.c
index a7f4880..6d69e6b 100644 (file)
  */
 
 #include "angband.h"
-#include "cmd-activate.h"
-#include "object-curse.h"
-
-static int suppression_evil_dam(object_type *o_ptr);
-static int weakening_artifact(object_type *o_ptr);
+#include "util.h"
 
+#include "artifact.h"
+#include "cmd-smith.h"
 
-
-/*!
- * @brief 対象のオブジェクトにランダムな上位耐性を一つ付加する。/ Choose one random high resistance
- * @details 重複の抑止はない。候補は毒、閃光、暗黒、破片、盲目、混乱、地獄、因果混乱、カオス、劣化、恐怖のいずれか。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
- */
-void one_high_resistance(object_type *o_ptr)
-{
-       switch (randint0(12))
-       {
-               case  0: add_flag(o_ptr->art_flags, TR_RES_POIS);   break;
-               case  1: add_flag(o_ptr->art_flags, TR_RES_LITE);   break;
-               case  2: add_flag(o_ptr->art_flags, TR_RES_DARK);   break;
-               case  3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
-               case  4: add_flag(o_ptr->art_flags, TR_RES_BLIND);  break;
-               case  5: add_flag(o_ptr->art_flags, TR_RES_CONF);   break;
-               case  6: add_flag(o_ptr->art_flags, TR_RES_SOUND);  break;
-               case  7: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
-               case  8: add_flag(o_ptr->art_flags, TR_RES_NEXUS);  break;
-               case  9: add_flag(o_ptr->art_flags, TR_RES_CHAOS);  break;
-               case 10: add_flag(o_ptr->art_flags, TR_RES_DISEN);  break;
-               case 11: add_flag(o_ptr->art_flags, TR_RES_FEAR);   break;
-       }
-}
-
-/*!
- * @brief 対象のオブジェクトに王者の指輪向けの上位耐性を一つ付加する。/ Choose one random high resistance
- * @details 候補は閃光、暗黒、破片、盲目、混乱、地獄、因果混乱、カオス、恐怖であり
- * 王者の指輪にあらかじめついている耐性をone_high_resistance()から除外したものである。
- * ランダム付加そのものに重複の抑止はない。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
- */
-void one_lordly_high_resistance(object_type *o_ptr)
-{
-       switch (randint0(10))
-       {
-               case 0: add_flag(o_ptr->art_flags, TR_RES_LITE);   break;
-               case 1: add_flag(o_ptr->art_flags, TR_RES_DARK);   break;
-               case 2: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
-               case 3: add_flag(o_ptr->art_flags, TR_RES_BLIND);  break;
-               case 4: add_flag(o_ptr->art_flags, TR_RES_CONF);   break;
-               case 5: add_flag(o_ptr->art_flags, TR_RES_SOUND);  break;
-               case 6: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
-               case 7: add_flag(o_ptr->art_flags, TR_RES_NEXUS);  break;
-               case 8: add_flag(o_ptr->art_flags, TR_RES_CHAOS);  break;
-               case 9: add_flag(o_ptr->art_flags, TR_RES_FEAR);   break;
-       }
-}
-
-/*!
- * @brief 対象のオブジェクトに元素耐性を一つ付加する。/ Choose one random element resistance
- * @details 候補は火炎、冷気、電撃、酸のいずれかであり、重複の抑止はない。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
- */
-void one_ele_resistance(object_type *o_ptr)
-{
-       switch (randint0(4))
-       {
-               case  0: add_flag(o_ptr->art_flags, TR_RES_ACID); break;
-               case  1: add_flag(o_ptr->art_flags, TR_RES_ELEC); break;
-               case  2: add_flag(o_ptr->art_flags, TR_RES_COLD); break;
-               case  3: add_flag(o_ptr->art_flags, TR_RES_FIRE); break;
-       }
-}
-
-/*!
- * @brief 対象のオブジェクトにドラゴン装備向け元素耐性を一つ付加する。/ Choose one random element or poison resistance
- * @details 候補は1/7の確率で毒、6/7の確率で火炎、冷気、電撃、酸のいずれか(one_ele_resistance()のコール)であり、重複の抑止はない。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
- */
-void one_dragon_ele_resistance(object_type *o_ptr)
-{
-       if (one_in_(7))
-       {
-               add_flag(o_ptr->art_flags, TR_RES_POIS);
-       }
-       else
-       {
-               one_ele_resistance(o_ptr);
-       }
-}
-
-/*!
- * @brief 対象のオブジェクトに弱いESPを一つ付加する。/ Choose one lower rank esp
- * @details 候補は動物、アンデッド、悪魔、オーク、トロル、巨人、
- * ドラゴン、人間、善良、ユニークESPのいずれかであり、重複の抑止はない。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
- */
-void one_low_esp(object_type *o_ptr)
-{
-       switch (randint1(10))
-       {
-               case 1:  add_flag(o_ptr->art_flags, TR_ESP_ANIMAL);   break;
-               case 2:  add_flag(o_ptr->art_flags, TR_ESP_UNDEAD);   break;
-               case 3:  add_flag(o_ptr->art_flags, TR_ESP_DEMON);   break;
-               case 4:  add_flag(o_ptr->art_flags, TR_ESP_ORC);   break;
-               case 5:  add_flag(o_ptr->art_flags, TR_ESP_TROLL);   break;
-               case 6:  add_flag(o_ptr->art_flags, TR_ESP_GIANT);   break;
-               case 7:  add_flag(o_ptr->art_flags, TR_ESP_DRAGON);   break;
-               case 8:  add_flag(o_ptr->art_flags, TR_ESP_HUMAN);   break;
-               case 9:  add_flag(o_ptr->art_flags, TR_ESP_GOOD);   break;
-               case 10: add_flag(o_ptr->art_flags, TR_ESP_UNIQUE);   break;
-       }
-}
-
-
-/*!
- * @brief 対象のオブジェクトに耐性を一つ付加する。/ Choose one random resistance
- * @details 1/3で元素耐性(one_ele_resistance())、2/3で上位耐性(one_high_resistance)
- * をコールする。重複の抑止はない。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
+#include "avatar.h"
+#include "floor.h"
+#include "cmd-activate.h"
+#include "object.h"
+#include "objectkind.h"
+#include "object-boost.h"
+#include "object-curse.h"
+#include "object-ego.h"
+#include "object-flavor.h"
+#include "object-hook.h"
+#include "spells-object.h"
+#include "files.h"
+#include "grid.h"
+#include "monster.h"
+#include "view-mainwindow.h"
+#include "player-class.h"
+#include "player-personality.h"
+#include "world.h"
+
+ /*
+  * The artifact arrays
+  */
+artifact_type *a_info;
+char *a_name;
+char *a_text;
+
+/*
+ * Maximum number of artifacts in a_info.txt
  */
-void one_resistance(object_type *o_ptr)
-{
-       if (one_in_(3))
-       {
-               one_ele_resistance(o_ptr);
-       }
-       else
-       {
-               one_high_resistance(o_ptr);
-       }
-}
+ARTIFACT_IDX max_a_idx;
 
+static bool has_extreme_damage_rate(object_type *o_ptr);
+static bool weakening_artifact(object_type *o_ptr);
 
+#ifdef JP
 /*!
- * @brief 対象のオブジェクトに能力を一つ付加する。/ Choose one random ability
- * @details 候補は浮遊、永久光源+1、透明視、警告、遅消化、急回復、麻痺知らず、経験値維持のいずれか。
- * 重複の抑止はない。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
+ * @brief ランダムアーティファクトのバイアス名称テーブル
  */
-void one_ability(object_type *o_ptr)
+const concptr artifact_bias_name[MAX_BIAS] =
 {
-       switch (randint0(10))
-       {
-       case 0: add_flag(o_ptr->art_flags, TR_LEVITATION);  break;
-       case 1: add_flag(o_ptr->art_flags, TR_LITE_1);      break;
-       case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS);   break;
-       case 3: add_flag(o_ptr->art_flags, TR_WARNING);     break;
-       case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
-       case 5: add_flag(o_ptr->art_flags, TR_REGEN);       break;
-       case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT);    break;
-       case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP);   break;
-       case 8:
-       case 9:
-               one_low_esp(o_ptr);
-               break;
-       }
-}
-
-/*!
- * @brief 対象のオブジェクトに発動を一つ付加する。/ Choose one random activation
- * @details 候補多数。ランダムアーティファクトのバイアスには一切依存せず、
- * whileループによる構造で能力的に強力なものほど確率を落としている。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
- */
-void one_activation(object_type *o_ptr)
+       "なし",
+       "電撃",
+       "毒",
+       "火炎",
+       "冷気",
+       "酸",
+       "腕力",
+       "知力",
+       "賢さ",
+       "器用さ",
+       "耐久",
+       "魅力",
+       "混沌",
+       "プリースト",
+       "死霊",
+       "法",
+       "盗賊",
+       "メイジ",
+       "戦士",
+       "レンジャー",
+};
+#else
+const concptr artifact_bias_name[MAX_BIAS] =
 {
-       int type = 0;
-       int chance = 0;
-
-       while (randint1(100) >= chance)
-       {
-               type = randint1(255);
-               switch (type)
-               {
-                       case ACT_SUNLIGHT:
-                       case ACT_BO_MISS_1:
-                       case ACT_BA_POIS_1:
-                       case ACT_BO_ELEC_1:
-                       case ACT_BO_ACID_1:
-                       case ACT_BO_COLD_1:
-                       case ACT_BO_FIRE_1:
-                       case ACT_CONFUSE:
-                       case ACT_SLEEP:
-                       case ACT_QUAKE:
-                       case ACT_CURE_LW:
-                       case ACT_CURE_MW:
-                       case ACT_CURE_POISON:
-                       case ACT_BERSERK:
-                       case ACT_LIGHT:
-                       case ACT_MAP_LIGHT:
-                       case ACT_DEST_DOOR:
-                       case ACT_STONE_MUD:
-                       case ACT_TELEPORT:
-                               chance = 101;
-                               break;
-                       case ACT_BA_COLD_1:
-                       case ACT_BA_FIRE_1:
-                       case ACT_HYPODYNAMIA_1:
-                       case ACT_TELE_AWAY:
-                       case ACT_ESP:
-                       case ACT_RESIST_ALL:
-                       case ACT_DETECT_ALL:
-                       case ACT_RECALL:
-                       case ACT_SATIATE:
-                       case ACT_RECHARGE:
-                               chance = 85;
-                               break;
-                       case ACT_TERROR:
-                       case ACT_PROT_EVIL:
-                       case ACT_ID_PLAIN:
-                               chance = 75;
-                               break;
-                       case ACT_HYPODYNAMIA_2:
-                       case ACT_DRAIN_1:
-                       case ACT_BO_MISS_2:
-                       case ACT_BA_FIRE_2:
-                       case ACT_REST_EXP:
-                               chance = 66;
-                               break;
-                       case ACT_BA_FIRE_3:
-                       case ACT_BA_COLD_3:
-                       case ACT_BA_ELEC_3:
-                       case ACT_WHIRLWIND:
-                       case ACT_DRAIN_2:
-                       case ACT_CHARM_ANIMAL:
-                               chance = 50;
-                               break;
-                       case ACT_SUMMON_ANIMAL:
-                               chance = 40;
-                               break;
-                       case ACT_DISP_EVIL:
-                       case ACT_BA_MISS_3:
-                       case ACT_DISP_GOOD:
-                       case ACT_BANISH_EVIL:
-                       case ACT_GENOCIDE:
-                       case ACT_MASS_GENO:
-                       case ACT_CHARM_UNDEAD:
-                       case ACT_CHARM_OTHER:
-                       case ACT_SUMMON_PHANTOM:
-                       case ACT_REST_ALL:
-                       case ACT_RUNE_EXPLO:
-                               chance = 33;
-                               break;
-                       case ACT_CALL_CHAOS:
-                       case ACT_ROCKET:
-                       case ACT_CHARM_ANIMALS:
-                       case ACT_CHARM_OTHERS:
-                       case ACT_SUMMON_ELEMENTAL:
-                       case ACT_CURE_700:
-                       case ACT_SPEED:
-                       case ACT_ID_FULL:
-                       case ACT_RUNE_PROT:
-                               chance = 25;
-                               break;
-                       case ACT_CURE_1000:
-                       case ACT_XTRA_SPEED:
-                       case ACT_DETECT_XTRA:
-                       case ACT_DIM_DOOR:
-                               chance = 10;
-                               break;
-                       case ACT_SUMMON_UNDEAD:
-                       case ACT_SUMMON_DEMON:
-                       case ACT_WRAITH:
-                       case ACT_INVULN:
-                       case ACT_ALCHEMY:
-                               chance = 5;
-                               break;
-                       default:
-                               chance = 0;
-               }
-       }
+       "None",
+       "Elec",
+       "Poison",
+       "Fire",
+       "Cold",
+       "Acid",
+       "STR",
+       "INT",
+       "WIS",
+       "DEX",
+       "CON",
+       "CHA",
+       "Chaos",
+       "Pristly",
+       "Necromantic",
+       "Law",
+       "Rogue",
+       "Mage",
+       "Warrior",
+       "Ranger",
+};
+#endif
 
-       /* A type was chosen... */
-       o_ptr->xtra2 = (byte_hack)type;
-       add_flag(o_ptr->art_flags, TR_ACTIVATE);
-       o_ptr->timeout = 0;
-}
 
 /*!
  * @brief ランダムアーティファクト生成中、対象のオブジェクトを呪いのアーティファクトにする経過処理。/ generation process of cursed artifact.
@@ -1326,13 +1134,13 @@ static void random_slay(object_type *o_ptr)
                        break;
                case 3:
                case 4:
-                       if (one_in_(4))
+                       if (one_in_(8))
                        {
                                add_flag(o_ptr->art_flags, TR_KILL_EVIL);
                        }
                        else
                        {
-                       add_flag(o_ptr->art_flags, TR_SLAY_EVIL); 
+                               add_flag(o_ptr->art_flags, TR_SLAY_EVIL); 
                        }
                        if (!o_ptr->artifact_bias && one_in_(2))
                                o_ptr->artifact_bias = BIAS_LAW;
@@ -1690,7 +1498,7 @@ static void get_random_name(object_type *o_ptr, char *return_name, bool armour,
        }
        else
        {
-               cptr filename;
+               concptr filename;
 
                switch (armour)
                {
@@ -1741,7 +1549,7 @@ static void get_random_name(object_type *o_ptr, char *return_name, bool armour,
  * @param a_scroll アーティファクト生成の巻物上の処理。呪いのアーティファクトが生成対象外となる。
  * @return 常にTRUE(1)を返す
  */
-bool create_artifact(object_type *o_ptr, bool a_scroll)
+bool become_random_artifact(object_type *o_ptr, bool a_scroll)
 {
        GAME_TEXT new_name[1024];
        PARAMETER_VALUE has_pval = 0;
@@ -1893,21 +1701,13 @@ bool create_artifact(object_type *o_ptr, bool a_scroll)
                                random_slay(o_ptr);
                                break;
                        default:
-                               if (p_ptr->wizard) msg_print("Switch error in create_artifact!");
+                               if (current_world_ptr->wizard) msg_print("Switch error in become_random_artifact!");
                                powers++;
                }
        };
 
        if (has_pval)
        {
-#if 0
-               add_flag(o_ptr->art_flags, TR_SHOW_MODS);
-
-               /* This one commented out by gw's request... */
-               if (!a_scroll)
-                       add_flag(o_ptr->art_flags, TR_HIDE_TYPE);
-#endif
-
                if (have_flag(o_ptr->art_flags, TR_BLOWS))
                {
                        o_ptr->pval = randint1(2);
@@ -1960,14 +1760,14 @@ bool create_artifact(object_type *o_ptr, bool a_scroll)
                while ((o_ptr->to_d+o_ptr->to_h) > 20)
                {
                        if (one_in_(o_ptr->to_d) && one_in_(o_ptr->to_h)) break;
-                       o_ptr->to_d -= (s16b)randint0(3);
-                       o_ptr->to_h -= (s16b)randint0(3);
+                       o_ptr->to_d -= (HIT_POINT)randint0(3);
+                       o_ptr->to_h -= (HIT_PROB)randint0(3);
                }
                while ((o_ptr->to_d+o_ptr->to_h) > 10)
                {
                        if (one_in_(o_ptr->to_d) || one_in_(o_ptr->to_h)) break;
-                       o_ptr->to_d -= (s16b)randint0(3);
-                       o_ptr->to_h -= (s16b)randint0(3);
+                       o_ptr->to_d -= (HIT_POINT)randint0(3);
+                       o_ptr->to_h -= (HIT_PROB)randint0(3);
                }
        }
 
@@ -2015,22 +1815,17 @@ bool create_artifact(object_type *o_ptr, bool a_scroll)
                else power_level = 3;
        }
 
-       /* 平均対邪ダメージが一定以上なら11/12(WEIRD_LUCK)でダメージ抑制処理を行う */
-       if(suppression_evil_dam(o_ptr) && !one_in_(WEIRD_LUCK) && object_is_weapon(o_ptr))
+       /* ダメージ抑制処理を行う */
+       while (has_extreme_damage_rate(o_ptr) && !one_in_(SWORDFISH_LUCK))
        {
-               msg_format_wizard(CHEAT_OBJECT, "アーティファクトの抑制処理を行います。");
-               do
-               {
-                       if (weakening_artifact(o_ptr) == 0) break;
-               } while (suppression_evil_dam(o_ptr));
+               weakening_artifact(o_ptr);
        }
 
        if (a_scroll)
        {
-               GAME_TEXT dummy_name[80] = "";
-               cptr ask_msg = _("このアーティファクトを何と名付けますか?", "What do you want to call the artifact? ");
+               GAME_TEXT dummy_name[MAX_NLEN] = "";
+               concptr ask_msg = _("このアーティファクトを何と名付けますか?", "What do you want to call the artifact? ");
 
-               /* Identify it fully */
                object_aware(o_ptr);
                object_known(o_ptr);
 
@@ -2056,8 +1851,8 @@ bool create_artifact(object_type *o_ptr, bool a_scroll)
                        }
                }
                sprintf(new_name, _("《%s》", "'%s'"), dummy_name);
-               chg_virtue(V_INDIVIDUALISM, 2);
-               chg_virtue(V_ENCHANT, 5);
+               chg_virtue(p_ptr, V_INDIVIDUALISM, 2);
+               chg_virtue(p_ptr, V_ENCHANT, 5);
        }
        else
        {
@@ -2250,6 +2045,7 @@ void random_artifact_resistance(object_type * o_ptr, artifact_type *a_ptr)
 /*!
  * @brief フロアの指定された位置に固定アーティファクトを生成する。 / Create the artifact of the specified number
  * @details 固定アーティファクト構造体から基本ステータスをコピーした後、所定の座標でdrop_item()で落とす。
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param a_idx 生成する固定アーティファクト構造体のID
  * @param y アイテムを落とす地点のy座標
  * @param x アイテムを落とす地点のx座標
@@ -2258,11 +2054,11 @@ void random_artifact_resistance(object_type * o_ptr, artifact_type *a_ptr)
  * 仮に2個以上存在可能かつ装備品以外の固定アーティファクトが作成されれば
  * drop_near()関数の返り値は信用できなくなる.
  */
-bool create_named_art(ARTIFACT_IDX a_idx, POSITION y, POSITION x)
+bool create_named_art(player_type *player_ptr, ARTIFACT_IDX a_idx, POSITION y, POSITION x)
 {
        object_type forge;
        object_type *q_ptr;
-       IDX i;
+       KIND_OBJECT_IDX i;
 
        artifact_type *a_ptr = &a_info[a_idx];
        q_ptr = &forge;
@@ -2275,11 +2071,10 @@ bool create_named_art(ARTIFACT_IDX a_idx, POSITION y, POSITION x)
 
        if (!i) return FALSE;
 
-       /* Create the artifact */
        object_prep(q_ptr, i);
 
        /* Save the name */
-       q_ptr->name1 = (byte_hack)a_idx;
+       q_ptr->name1 = a_idx;
 
        /* Extract the fields */
        q_ptr->pval = a_ptr->pval;
@@ -2302,18 +2097,17 @@ bool create_named_art(ARTIFACT_IDX a_idx, POSITION y, POSITION x)
        random_artifact_resistance(q_ptr, a_ptr);
 
        /* Drop the artifact from heaven */
-       return drop_near(q_ptr, -1, y, x) ? TRUE : FALSE;
+       return drop_near(player_ptr, q_ptr, -1, y, x) ? TRUE : FALSE;
 }
 
 /*対邪平均ダメージの計算処理*/
-int calc_arm_avgdamage(object_type *o_ptr)
+HIT_POINT calc_arm_avgdamage(object_type *o_ptr)
 {
        BIT_FLAGS flgs[TR_FLAG_SIZE];
        object_flags(o_ptr, flgs);
 
        HIT_POINT dam, base, s_evil, forced, vorpal;
-       dam = base = s_evil = forced = vorpal = 0;
-
+       s_evil = forced = vorpal = 0;
        dam = base = (o_ptr->dd * o_ptr->ds + o_ptr->dd) / 2;
 
        if(have_flag(flgs, TR_KILL_EVIL))
@@ -2342,12 +2136,11 @@ int calc_arm_avgdamage(object_type *o_ptr)
 
        msg_format_wizard(CHEAT_OBJECT,"素:%d> 対邪:%d> 理力:%d> 切:%d> 最終:%d", base, s_evil, forced, vorpal, dam);
 
-       return(dam);
+       return dam;
 }
 
-static int suppression_evil_dam(object_type *o_ptr)
+static bool has_extreme_damage_rate(object_type *o_ptr)
 {
-       int num = FALSE;
        BIT_FLAGS flgs[TR_FLAG_SIZE];
        object_flags(o_ptr, flgs);
 
@@ -2355,83 +2148,209 @@ static int suppression_evil_dam(object_type *o_ptr)
        {
                if(have_flag(flgs, TR_BLOWS) && (o_ptr->pval == 1) && (calc_arm_avgdamage(o_ptr) > 52))
                {
-                       num = TRUE;
+                       return TRUE;
                }
                else if(have_flag(flgs, TR_BLOWS) && (o_ptr->pval == 2) && (calc_arm_avgdamage(o_ptr) > 43))
                {
-                       num = TRUE;
+                       return TRUE;
                }
                else if( have_flag(flgs, TR_BLOWS) && (o_ptr->pval == 3) && (calc_arm_avgdamage(o_ptr) > 33))
                {
-                       num = TRUE;
+                       return TRUE;
                }
                else if (calc_arm_avgdamage(o_ptr) > 63)
                {
-                       num = TRUE;
+                       return TRUE;
                }
        }
        else
        {
                if (have_flag(flgs, TR_BLOWS) && (o_ptr->pval == 1) && (calc_arm_avgdamage(o_ptr) > 65))
                {
-                       num = TRUE;
+                       return TRUE;
                }
                else if (have_flag(flgs, TR_BLOWS) && (o_ptr->pval == 2) && (calc_arm_avgdamage(o_ptr) > 52))
                {
-                       num = TRUE;
+                       return TRUE;
                }
                else if (have_flag(flgs, TR_BLOWS) && (o_ptr->pval == 3) && (calc_arm_avgdamage(o_ptr) > 40))
                {
-                       num = TRUE;
+                       return TRUE;
                }
                else if (calc_arm_avgdamage(o_ptr) > 75)
                {
-                       num = TRUE;
+                       return TRUE;
                }
        }
-       return(num);
+       return FALSE;
 }
 
-static int weakening_artifact(object_type *o_ptr)
+static bool weakening_artifact(object_type *o_ptr)
 {
-        KIND_OBJECT_IDX k_idx = lookup_kind(o_ptr->sval, o_ptr->tval);
-        object_kind *k_ptr = &k_info[k_idx];
-
-        if ((k_ptr->dd < o_ptr->dd) || (k_ptr->ds < o_ptr->ds))
-        {
-               DICE_NUMBER pre_dd = o_ptr->dd;
-               DICE_SID pre_ds = o_ptr->ds;
+       KIND_OBJECT_IDX k_idx = lookup_kind(o_ptr->tval, o_ptr->sval);
+       object_kind *k_ptr = &k_info[k_idx];
+       BIT_FLAGS flgs[TR_FLAG_SIZE];
+       object_flags(o_ptr, flgs);
 
-               if (o_ptr->dd > o_ptr->ds)
+       if (have_flag(flgs, TR_KILL_EVIL))
+       {
+               remove_flag(o_ptr->art_flags, TR_KILL_EVIL);
+               add_flag(o_ptr->art_flags, TR_SLAY_EVIL);
+               return TRUE;
+       }
+       else if (k_ptr->dd < o_ptr->dd)
+       {
+               o_ptr->dd--;
+               return TRUE;
+       }
+       else if (k_ptr->ds < o_ptr->ds)
+       {
+               o_ptr->ds--;
+               return TRUE;
+       }
+       else if (o_ptr->to_d > 10)
+       {
+               o_ptr->to_d = o_ptr->to_d - damroll(1, 6);
+               if (o_ptr->to_d < 10)
                {
-                       o_ptr->dd--;
+                       o_ptr->to_d = 10;
                }
-               else
+               return TRUE;
+       }
+       return FALSE;
+}
+
+/*!
+ * @brief 非INSTA_ART型の固定アーティファクトの生成を確率に応じて試行する。
+ * Mega-Hack -- Attempt to create one of the "Special Objects"
+ * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
+ * @return 生成に成功したらTRUEを返す。
+ * @details
+ * Attempt to change an object into an artifact\n
+ * This routine should only be called by "apply_magic()"\n
+ * Note -- see "make_artifact_special()" and "apply_magic()"\n
+ */
+bool make_artifact(object_type *o_ptr)
+{
+       ARTIFACT_IDX i;
+
+       /* No artifacts in the town */
+       if (!p_ptr->current_floor_ptr->dun_level) return (FALSE);
+
+       /* Paranoia -- no "plural" artifacts */
+       if (o_ptr->number != 1) return (FALSE);
+
+       /* Check the artifact list (skip the "specials") */
+       for (i = 0; i < max_a_idx; i++)
+       {
+               artifact_type *a_ptr = &a_info[i];
+
+               /* Skip "empty" items */
+               if (!a_ptr->name) continue;
+
+               /* Cannot make an artifact twice */
+               if (a_ptr->cur_num) continue;
+
+               if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
+
+               if (a_ptr->gen_flags & TRG_INSTA_ART) continue;
+
+               /* Must have the correct fields */
+               if (a_ptr->tval != o_ptr->tval) continue;
+               if (a_ptr->sval != o_ptr->sval) continue;
+
+               /* XXX XXX Enforce minimum "depth" (loosely) */
+               if (a_ptr->level > p_ptr->current_floor_ptr->dun_level)
                {
-                       o_ptr->ds--;
+                       /* Acquire the "out-of-depth factor" */
+                       int d = (a_ptr->level - p_ptr->current_floor_ptr->dun_level) * 2;
+
+                       /* Roll for out-of-depth creation */
+                       if (!one_in_(d)) continue;
                }
 
-               msg_format_wizard(CHEAT_OBJECT, 
-                       _("ダイスが抑制されました。%dd%d -> %dd%d", "Dice Supress %dd%d -> %dd%d"),
-                       pre_dd, pre_ds, o_ptr->dd, o_ptr->ds);
-               return 1;
+               /* We must make the "rarity roll" */
+               if (!one_in_(a_ptr->rarity)) continue;
+
+               /* Hack -- mark the item as an artifact */
+               o_ptr->name1 = i;
+
+               /* Hack: Some artifacts get random extra powers */
+               random_artifact_resistance(o_ptr, a_ptr);
+
+               /* Success */
+               return (TRUE);
        }
-       
-       if (o_ptr->to_d > 10)
+
+       /* Failure */
+       return (FALSE);
+}
+
+/*!
+ * @brief INSTA_ART型の固定アーティファクトの生成を確率に応じて試行する。
+ * Mega-Hack -- Attempt to create one of the "Special Objects"
+ * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
+ * @return 生成に成功したらTRUEを返す。
+ * @details
+ * We are only called from "make_object()", and we assume that\n
+ * "apply_magic()" is called immediately after we return.\n
+ *\n
+ * Note -- see "make_artifact()" and "apply_magic()"\n
+ */
+bool make_artifact_special(object_type *o_ptr)
+{
+       ARTIFACT_IDX i;
+       KIND_OBJECT_IDX k_idx = 0;
+
+       /*! @note 地上ではキャンセルする / No artifacts in the town */
+       if (!p_ptr->current_floor_ptr->dun_level) return (FALSE);
+
+       /*! @note get_obj_num_hookによる指定がある場合は生成をキャンセルする / Themed object */
+       if (get_obj_num_hook) return (FALSE);
+
+       /*! @note 全固定アーティファクト中からIDの若い順に生成対象とその確率を走査する / Check the artifact list (just the "specials") */
+       for (i = 0; i < max_a_idx; i++)
        {
-               HIT_POINT pre_damage = o_ptr->to_d;
+               artifact_type *a_ptr = &a_info[i];
 
-               o_ptr->to_d = o_ptr->to_d - damroll(1, 6);
-               if (o_ptr->to_d < 10)
+               /*! @note アーティファクト名が空の不正なデータは除外する / Skip "empty" artifacts */
+               if (!a_ptr->name) continue;
+
+               /*! @note 既に生成回数がカウントされたアーティファクト、QUESTITEMと非INSTA_ARTは除外 / Cannot make an artifact twice */
+               if (a_ptr->cur_num) continue;
+               if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
+               if (!(a_ptr->gen_flags & TRG_INSTA_ART)) continue;
+
+               /*! @note アーティファクト生成階が現在に対して足りない場合は高確率で1/(不足階層*2)を満たさないと生成リストに加えられない /
+                *  XXX XXX Enforce minimum "depth" (loosely) */
+               if (a_ptr->level > p_ptr->current_floor_ptr->object_level)
                {
-                       o_ptr->to_d = 10;
+                       /* @note  / Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
+                       int d = (a_ptr->level - p_ptr->current_floor_ptr->object_level) * 2;
+                       if (!one_in_(d)) continue;
+               }
+
+               /*! @note 1/(レア度)の確率を満たさないと除外される / Artifact "rarity roll" */
+               if (!one_in_(a_ptr->rarity)) continue;
+
+               /*! @note INSTA_ART型固定アーティファクトのベースアイテムもチェック対象とする。ベースアイテムの生成階層が足りない場合1/(不足階層*5) を満たさないと除外される。 /
+                *  Find the base object. XXX XXX Enforce minimum "object" level (loosely). Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
+               k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
+               if (k_info[k_idx].level > p_ptr->current_floor_ptr->object_level)
+               {
+                       int d = (k_info[k_idx].level - p_ptr->current_floor_ptr->object_level) * 5;
+                       if (!one_in_(d)) continue;
                }
 
-               msg_format_wizard(CHEAT_OBJECT,
-                       _("ダメージ修正が抑制されました。 %d -> %d", "Plus-Damage Supress %d -> %d"),
-                       pre_damage, o_ptr->to_d);
+               /*! @note 前述の条件を満たしたら、後のIDのアーティファクトはチェックせずすぐ確定し生成処理に移す /
+                * Assign the template. Mega-Hack -- mark the item as an artifact. Hack: Some artifacts get random extra powers. Success. */
+               object_prep(o_ptr, k_idx);
 
-               return 1;
-        }
-        return 0;
-}
\ No newline at end of file
+               o_ptr->name1 = i;
+               random_artifact_resistance(o_ptr, a_ptr);
+               return (TRUE);
+       }
+
+       /*! @note 全INSTA_ART固定アーティファクトを試行しても決まらなかった場合 FALSEを返す / Failure */
+       return (FALSE);
+}