OSDN Git Service

af812a2845140e4c35654db0006bd7e371f12516
[hengband/hengband.git] / src / object-enchant / artifact.c
1 /*!
2  * @brief アーティファクトの生成と管理 / Artifact code
3  * @date 2013/12/11
4  * @author
5  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
6  * This software may be copied and distributed for educational, research, and\n
7  * not for profit purposes provided that this copyright and statement are\n
8  * included in all such copies.\n
9  * 2013 Deskull rearranged comment for Doxygen.
10  */
11
12 #include "object-enchant/artifact.h"
13 #include "artifact/random-art-activation.h"
14 #include "artifact/random-art-bias-types.h"
15 #include "artifact/random-art-characteristics.h"
16 #include "artifact/random-art-pval-investor.h"
17 #include "art-definition/art-armor-types.h"
18 #include "art-definition/art-protector-types.h"
19 #include "art-definition/art-sword-types.h"
20 #include "art-definition/art-weapon-types.h"
21 #include "art-definition/random-art-effects.h"
22 #include "cmd-item/cmd-smith.h"
23 #include "core/asking-player.h"
24 #include "core/window-redrawer.h"
25 #include "flavor/object-flavor.h"
26 #include "floor/floor-object.h"
27 #include "floor/floor.h"
28 #include "game-option/cheat-types.h"
29 #include "grid/grid.h"
30 #include "io/files-util.h"
31 #include "mind/mind-weaponsmith.h"
32 #include "object-enchant/object-boost.h"
33 #include "object-enchant/object-curse.h"
34 #include "object-enchant/object-ego.h"
35 #include "object-enchant/special-object-flags.h"
36 #include "object-enchant/tr-types.h"
37 #include "object-enchant/trc-types.h"
38 #include "object-enchant/trg-types.h"
39 #include "object-hook/hook-armor.h"
40 #include "object-hook/hook-checker.h"
41 #include "object-hook/hook-enchant.h"
42 #include "object-hook/hook-weapon.h"
43 #include "object/object-flags.h"
44 #include "object/object-generator.h"
45 #include "object/object-kind-hook.h"
46 #include "object/object-kind.h"
47 #include "object/object-value-calc.h"
48 #include "perception/identification.h"
49 #include "perception/object-perception.h"
50 #include "player/avatar.h"
51 #include "player/player-class.h"
52 #include "player/player-personalities-types.h"
53 #include "spell/spells-object.h"
54 #include "sv-definition/sv-armor-types.h"
55 #include "sv-definition/sv-weapon-types.h"
56 #include "system/system-variables.h"
57 #include "util/bit-flags-calculator.h"
58 #include "util/quarks.h"
59 #include "view/display-messages.h"
60 #include "wizard/artifact-bias-table.h"
61 #include "wizard/wizard-messages.h"
62 #include "world/world.h"
63
64 /*
65  * The artifact arrays
66  */
67 artifact_type *a_info;
68 char *a_name;
69 char *a_text;
70
71 /*
72  * Maximum number of artifacts in a_info.txt
73  */
74 ARTIFACT_IDX max_a_idx;
75
76 /*!
77  * @brief オブジェクトから能力発動IDを取得する。
78  * @details いくつかのケースで定義されている発動効果から、
79  * 鍛冶師による付与>固定アーティファクト>エゴ>ランダムアーティファクト>ベースアイテムの優先順位で走査していく。
80  * @param o_ptr 対象のオブジェクト構造体ポインタ
81  * @return 発動効果のIDを返す
82  */
83 int activation_index(player_type *player_ptr, object_type *o_ptr)
84 {
85     if (object_is_smith(player_ptr, o_ptr)) {
86         switch (o_ptr->xtra3 - 1) {
87         case ESSENCE_TMP_RES_ACID:
88             return ACT_RESIST_ACID;
89         case ESSENCE_TMP_RES_ELEC:
90             return ACT_RESIST_ELEC;
91         case ESSENCE_TMP_RES_FIRE:
92             return ACT_RESIST_FIRE;
93         case ESSENCE_TMP_RES_COLD:
94             return ACT_RESIST_COLD;
95         case TR_IMPACT:
96             return ACT_QUAKE;
97         }
98     }
99
100     if (object_is_fixed_artifact(o_ptr)) {
101         if (have_flag(a_info[o_ptr->name1].flags, TR_ACTIVATE)) {
102             return a_info[o_ptr->name1].act_idx;
103         }
104     }
105
106     if (object_is_ego(o_ptr)) {
107         if (have_flag(e_info[o_ptr->name2].flags, TR_ACTIVATE)) {
108             return e_info[o_ptr->name2].act_idx;
109         }
110     }
111
112     if (!object_is_random_artifact(o_ptr)) {
113         if (have_flag(k_info[o_ptr->k_idx].flags, TR_ACTIVATE)) {
114             return k_info[o_ptr->k_idx].act_idx;
115         }
116     }
117
118     return o_ptr->xtra2;
119 }
120
121 /*!
122  * @brief オブジェクトから発動効果構造体のポインタを取得する。
123  * @details activation_index() 関数の結果から参照する。
124  * @param o_ptr 対象のオブジェクト構造体ポインタ
125  * @return 発動効果構造体のポインタを返す
126  */
127 const activation_type *find_activation_info(player_type *player_ptr, object_type *o_ptr)
128 {
129     const int index = activation_index(player_ptr, o_ptr);
130     const activation_type *p;
131     for (p = activation_info; p->flag != NULL; ++p) {
132         if (p->index == index) {
133             return p;
134         }
135     }
136
137     return NULL;
138 }