2 * @brief オブジェクトの実装 / Object code, part 1
5 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research,\n
8 * and not for profit purposes provided that this copyright and statement\n
9 * are included in all such copies. Other copyrights may also apply.\n
10 * 2014 Deskull rearranged comment for Doxygen.\n
13 #include "object/object-info.h"
14 #include "art-definition/art-weapon-types.h"
15 #include "art-definition/random-art-effects.h"
16 #include "floor/floor.h"
17 #include "object-enchant/activation-info-table.h"
18 #include "object-enchant/artifact.h"
19 #include "object-enchant/dragon-breaths-table.h"
20 #include "object-enchant/object-ego.h"
21 #include "object/object-flags.h"
22 #include "object/object-kind.h"
23 #include "sv-definition/sv-other-types.h"
24 #include "sv-definition/sv-ring-types.h"
25 #include "term/term-color-types.h"
26 #include "util/bit-flags-calculator.h"
27 #include "util/int-char-converter.h"
30 * @brief オブジェクトの発動効果名称を返す(サブルーチン/ブレス)
31 * @param o_ptr 名称を取得する元のオブジェクト構造体参照ポインタ
32 * @return concptr 発動名称を返す文字列ポインタ
34 static concptr item_activation_dragon_breath(object_type *o_ptr)
36 static char desc[256];
37 BIT_FLAGS flgs[TR_FLAG_SIZE]; /* for resistance flags */
40 object_flags(o_ptr, flgs);
41 strcpy(desc, _("", "breath "));
43 for (int i = 0; dragonbreath_info[i].flag != 0; i++) {
44 if (have_flag(flgs, dragonbreath_info[i].flag)) {
46 strcat(desc, _("、", ", "));
48 strcat(desc, dragonbreath_info[i].name);
53 strcat(desc, _("のブレス(250)", ""));
58 * @brief オブジェクトの発動効果名称を返す(サブルーチン/汎用)
59 * @param o_ptr 名称を取得する元のオブジェクト構造体参照ポインタ
60 * @return concptr 発動名称を返す文字列ポインタ
62 static concptr item_activation_aux(object_type *o_ptr)
64 static char activation_detail[256];
66 const activation_type *const act_ptr = find_activation_info(o_ptr);
69 return _("未定義", "something undefined");
71 concptr desc = act_ptr->desc;
72 switch (act_ptr->index) {
74 if ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_FLAMES))
75 desc = _("火炎のブレス (200) と火への耐性", "breath of fire (200) and resist fire");
78 if ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_ICE))
79 desc = _("冷気のブレス (200) と冷気への耐性", "breath of cold (200) and resist cold");
82 desc = item_activation_dragon_breath(o_ptr);
85 if (o_ptr->name1 == ART_HYOUSIGI)
86 desc = _("拍子木を打ちならす", "beat wooden clappers");
89 if (((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_ACID)) || (o_ptr->name2 == EGO_BRAND_ACID))
90 desc = _("アシッド・ボール (100) と酸への耐性", "ball of acid (100) and resist acid");
93 if (((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_FLAMES)) || (o_ptr->name2 == EGO_BRAND_FIRE))
94 desc = _("ファイア・ボール (100) と火への耐性", "ball of fire (100) and resist fire");
97 if (((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_ICE)) || (o_ptr->name2 == EGO_BRAND_COLD))
98 desc = _("アイス・ボール (100) と冷気への耐性", "ball of cold (100) and resist cold");
100 case ACT_RESIST_ELEC:
101 if (((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_ELEC)) || (o_ptr->name2 == EGO_BRAND_ELEC))
102 desc = _("サンダー・ボール (100) と電撃への耐性", "ball of elec (100) and resist elec");
104 case ACT_RESIST_POIS:
105 if (o_ptr->name2 == EGO_BRAND_POIS)
106 desc = _("悪臭雲 (100) と毒への耐性", "ball of poison (100) and resist elec");
110 /* Timeout description */
111 int constant = act_ptr->timeout.constant;
112 int dice = act_ptr->timeout.dice;
113 if (constant == 0 && dice == 0) {
114 /* We can activate it every turn */
115 strcpy(timeout, _("いつでも", "every turn"));
116 } else if (constant < 0) {
117 /* Activations that have special timeout */
118 switch (act_ptr->index) {
120 sprintf(timeout, _("%d ターン毎", "every %d turns"), ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_FLAMES)) ? 200 : 250);
123 sprintf(timeout, _("%d ターン毎", "every %d turns"), ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_ICE)) ? 200 : 250);
126 strcpy(timeout, _("3*(レベル+10) ターン毎", "every 3 * (level+10) turns"));
129 strcpy(timeout, _("確率50%で壊れる", "(destroyed 50%)"));
132 strcpy(timeout, "undefined");
136 char constant_str[16], dice_str[16];
137 sprintf(constant_str, "%d", constant);
138 sprintf(dice_str, "d%d", dice);
139 sprintf(timeout, _("%s%s%s ターン毎", "every %s%s%s turns"), (constant > 0) ? constant_str : "", (constant > 0 && dice > 0) ? "+" : "",
140 (dice > 0) ? dice_str : "");
143 sprintf(activation_detail, _("%s : %s", "%s %s"), desc, timeout);
144 return activation_detail;
148 * @brief オブジェクトの発動効果名称を返す(メインルーチン) /
149 * Determine the "Activation" (if any) for an artifact Return a string, or NULL for "no activation"
150 * @param o_ptr 名称を取得する元のオブジェクト構造体参照ポインタ
151 * @return concptr 発動名称を返す文字列ポインタ
153 concptr activation_explanation(object_type *o_ptr)
155 BIT_FLAGS flgs[TR_FLAG_SIZE];
156 object_flags(o_ptr, flgs);
157 if (!(have_flag(flgs, TR_ACTIVATE)))
158 return (_("なし", "nothing"));
160 if (activation_index(o_ptr)) {
161 return item_activation_aux(o_ptr);
164 if (o_ptr->tval == TV_WHISTLE) {
165 return _("ペット呼び寄せ : 100+d100ターン毎", "call pet every 100+d100 turns");
168 if (o_ptr->tval == TV_CAPTURE) {
169 return _("モンスターを捕える、又は解放する。", "captures or releases a monster.");
172 return _("何も起きない", "Nothing");
176 * @brief オブジェクト選択時の選択アルファベットラベルを返す /
177 * Convert an inventory index into a one character label
178 * @param i プレイヤーの所持/装備オブジェクトID
179 * @return 対応するアルファベット
180 * @details Note that the label does NOT distinguish inven/equip.
182 char index_to_label(int i) { return (i < INVEN_RARM) ? (I2A(i)) : (I2A(i - INVEN_RARM)); }
185 * @brief オブジェクトの該当装備部位IDを返す /
186 * Determine which equipment slot (if any) an item likes
187 * @param o_ptr 名称を取得する元のオブジェクト構造体参照ポインタ
190 s16b wield_slot(player_type *owner_ptr, object_type *o_ptr)
192 switch (o_ptr->tval) {
197 if (!owner_ptr->inventory_list[INVEN_RARM].k_idx)
199 if (owner_ptr->inventory_list[INVEN_LARM].k_idx)
206 if (!owner_ptr->inventory_list[INVEN_LARM].k_idx)
208 if (owner_ptr->inventory_list[INVEN_RARM].k_idx)
216 if (!owner_ptr->inventory_list[INVEN_RIGHT].k_idx)
217 return (INVEN_RIGHT);
230 case TV_SOFT_ARMOR: {
234 return (INVEN_OUTER);
241 return (INVEN_HANDS);
252 * @brief tval/sval指定のベースアイテムがプレイヤーの使用可能な魔法書かどうかを返す /
253 * Hack: Check if a spellbook is one of the realms we can use. -- TY
254 * @param book_tval ベースアイテムのtval
255 * @param book_sval ベースアイテムのsval
256 * @return 使用可能な魔法書ならばTRUEを返す。
258 bool check_book_realm(player_type *owner_ptr, const tval_type book_tval, const OBJECT_SUBTYPE_VALUE book_sval)
260 if (book_tval < TV_LIFE_BOOK)
262 if (owner_ptr->pclass == CLASS_SORCERER) {
263 return is_magic(tval2realm(book_tval));
264 } else if (owner_ptr->pclass == CLASS_RED_MAGE) {
265 if (is_magic(tval2realm(book_tval)))
266 return ((book_tval == TV_ARCANE_BOOK) || (book_sval < 2));
269 return (REALM1_BOOK == book_tval || REALM2_BOOK == book_tval);
272 object_type *ref_item(player_type *owner_ptr, INVENTORY_IDX item)
274 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
275 return item >= 0 ? &owner_ptr->inventory_list[item] : &(floor_ptr->o_list[0 - item]);
279 * Return the "attr" for a given item.
280 * Use "flavor" if available.
281 * Default to user definitions.
283 TERM_COLOR object_attr(object_type *o_ptr)
285 return ((k_info[o_ptr->k_idx].flavor)
286 ? (k_info[k_info[o_ptr->k_idx].flavor].x_attr)
287 : ((!o_ptr->k_idx || (o_ptr->tval != TV_CORPSE) || (o_ptr->sval != SV_CORPSE) || (k_info[o_ptr->k_idx].x_attr != TERM_DARK))
288 ? (k_info[o_ptr->k_idx].x_attr)
289 : (r_info[o_ptr->pval].x_attr)));