OSDN Git Service

[Refactor] #40653 Separated mind-chaos-warrior.c/h from spells-object.c/h
[hengband/hengband.git] / src / spell / spells-object.c
1 /*!
2  * @brief アイテムに影響のある魔法の処理
3  * @date 2019/01/22
4  * @author deskull
5  */
6
7 #include "spell/spells-object.h"
8 #include "action/action-limited.h"
9 #include "autopick/autopick.h"
10 #include "core/asking-player.h"
11 #include "core/player-redraw-types.h"
12 #include "core/player-update-types.h"
13 #include "core/window-redrawer.h"
14 #include "flavor/flavor-describer.h"
15 #include "flavor/object-flavor-types.h"
16 #include "floor/cave.h"
17 #include "floor/floor-object.h"
18 #include "game-option/disturbance-options.h"
19 #include "grid/feature.h"
20 #include "grid/grid.h"
21 #include "inventory/inventory-object.h"
22 #include "inventory/inventory-slot-types.h"
23 #include "inventory/player-inventory.h"
24 #include "monster-race/monster-race.h"
25 #include "monster-race/race-flags1.h"
26 #include "object-enchant/apply-magic.h"
27 #include "object-enchant/item-apply-magic.h"
28 #include "object-enchant/item-feeling.h"
29 #include "object-enchant/object-boost.h"
30 #include "object-enchant/object-ego.h"
31 #include "object-enchant/special-object-flags.h"
32 #include "object-enchant/tr-types.h"
33 #include "object-enchant/trc-types.h"
34 #include "object-enchant/trg-types.h"
35 #include "object-hook/hook-armor.h"
36 #include "object-hook/hook-bow.h"
37 #include "object-hook/hook-checker.h"
38 #include "object-hook/hook-enchant.h"
39 #include "object-hook/hook-magic.h"
40 #include "object-hook/hook-weapon.h"
41 #include "object/item-tester-hooker.h"
42 #include "object/item-use-flags.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 "perception/object-perception.h"
48 #include "player-info/avatar.h"
49 #include "player/player-class.h"
50 #include "player/player-damage.h"
51 #include "player/player-status.h"
52 #include "racial/racial-android.h"
53 #include "spell-kind/spells-perception.h"
54 #include "status/bad-status-setter.h"
55 #include "sv-definition/sv-food-types.h"
56 #include "sv-definition/sv-lite-types.h"
57 #include "sv-definition/sv-other-types.h"
58 #include "sv-definition/sv-protector-types.h"
59 #include "sv-definition/sv-scroll-types.h"
60 #include "sv-definition/sv-staff-types.h"
61 #include "sv-definition/sv-weapon-types.h"
62 #include "system/artifact-type-definition.h"
63 #include "system/floor-type-definition.h"
64 #include "system/object-type-definition.h"
65 #include "target/target-getter.h"
66 #include "term/screen-processor.h"
67 #include "util/bit-flags-calculator.h"
68 #include "view/display-messages.h"
69
70 typedef struct {
71     tval_type tval;
72     OBJECT_SUBTYPE_VALUE sval;
73     PERCENTAGE prob;
74     byte flag;
75 } amuse_type;
76
77 /*!
78  * @brief 装備強化処理の失敗率定数(千分率) /
79  * Used by the "enchant" function (chance of failure)
80  * (modified for Zangband, we need better stuff there...) -- TY
81  * @return なし
82  */
83 static int enchant_table[16] = { 0, 10, 50, 100, 200, 300, 400, 500, 650, 800, 950, 987, 993, 995, 998, 1000 };
84
85 /*
86  * Scatter some "amusing" objects near the player
87  */
88
89 #define AMS_NOTHING 0x00 /* No restriction */
90 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
91 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
92 #define AMS_MULTIPLE 0x04 /* Drop 1-3 objects for one type */
93 #define AMS_PILE 0x08 /* Drop 1-99 pile objects for one type */
94
95 static amuse_type amuse_info[]
96     = { { TV_BOTTLE, SV_ANY, 5, AMS_NOTHING }, { TV_JUNK, SV_ANY, 3, AMS_MULTIPLE }, { TV_SPIKE, SV_ANY, 10, AMS_PILE }, { TV_STATUE, SV_ANY, 15, AMS_NOTHING },
97           { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE }, { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE }, { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
98           { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING }, { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, // Fishing Pole of Taikobo
99           { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, // Broken Dagger of Magician
100           { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING }, { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING }, { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
101
102           { 0, 0, 0, 0 } };
103
104 /*!
105  * @brief 誰得ドロップを行う。
106  * @param creature_ptr プレーヤーへの参照ポインタ
107  * @param y1 配置したいフロアのY座標
108  * @param x1 配置したいフロアのX座標
109  * @param num 誰得の処理回数
110  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
111  * @return なし
112  */
113 void amusement(player_type *creature_ptr, POSITION y1, POSITION x1, int num, bool known)
114 {
115     int t = 0;
116     for (int n = 0; amuse_info[n].tval != 0; n++) {
117         t += amuse_info[n].prob;
118     }
119
120     /* Acquirement */
121     object_type *i_ptr;
122     object_type object_type_body;
123     while (num) {
124         int i;
125         KIND_OBJECT_IDX k_idx;
126         ARTIFACT_IDX a_idx = 0;
127         int r = randint0(t);
128         bool insta_art, fixed_art;
129
130         for (i = 0;; i++) {
131             r -= amuse_info[i].prob;
132             if (r <= 0)
133                 break;
134         }
135         i_ptr = &object_type_body;
136         object_wipe(i_ptr);
137         k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
138
139         /* Paranoia - reroll if nothing */
140         if (!k_idx)
141             continue;
142
143         /* Search an artifact index if need */
144         insta_art = (k_info[k_idx].gen_flags & TRG_INSTA_ART);
145         fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
146
147         if (insta_art || fixed_art) {
148             for (a_idx = 1; a_idx < max_a_idx; a_idx++) {
149                 if (insta_art && !(a_info[a_idx].gen_flags & TRG_INSTA_ART))
150                     continue;
151                 if (a_info[a_idx].tval != k_info[k_idx].tval)
152                     continue;
153                 if (a_info[a_idx].sval != k_info[k_idx].sval)
154                     continue;
155                 if (a_info[a_idx].cur_num > 0)
156                     continue;
157                 break;
158             }
159
160             if (a_idx >= max_a_idx)
161                 continue;
162         }
163
164         /* Make an object (if possible) */
165         object_prep(creature_ptr, i_ptr, k_idx);
166         if (a_idx)
167             i_ptr->name1 = a_idx;
168         apply_magic(creature_ptr, i_ptr, 1, AM_NO_FIXED_ART);
169
170         if (amuse_info[i].flag & AMS_NO_UNIQUE) {
171             if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE)
172                 continue;
173         }
174
175         if (amuse_info[i].flag & AMS_MULTIPLE)
176             i_ptr->number = randint1(3);
177         if (amuse_info[i].flag & AMS_PILE)
178             i_ptr->number = randint1(99);
179
180         if (known) {
181             object_aware(creature_ptr, i_ptr);
182             object_known(i_ptr);
183         }
184
185         /* Paranoia - reroll if nothing */
186         if (!(i_ptr->k_idx))
187             continue;
188
189         (void)drop_near(creature_ptr, i_ptr, -1, y1, x1);
190
191         num--;
192     }
193 }
194
195 /*!
196  * @brief 獲得ドロップを行う。
197  * Scatter some "great" objects near the player
198  * @param caster_ptr プレーヤーへの参照ポインタ
199  * @param y1 配置したいフロアのY座標
200  * @param x1 配置したいフロアのX座標
201  * @param num 獲得の処理回数
202  * @param great TRUEならば必ず高級品以上を落とす
203  * @param special TRUEならば必ず特別品を落とす
204  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
205  * @return なし
206  */
207 void acquirement(player_type *caster_ptr, POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
208 {
209     object_type *i_ptr;
210     object_type object_type_body;
211     BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : 0L) | (special ? AM_SPECIAL : 0L);
212
213     /* Acquirement */
214     while (num--) {
215         i_ptr = &object_type_body;
216         object_wipe(i_ptr);
217
218         /* Make a good (or great) object (if possible) */
219         if (!make_object(caster_ptr, i_ptr, mode))
220             continue;
221
222         if (known) {
223             object_aware(caster_ptr, i_ptr);
224             object_known(i_ptr);
225         }
226
227         (void)drop_near(caster_ptr, i_ptr, -1, y1, x1);
228     }
229 }
230
231 /*!
232  * todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
233  * @brief 防具呪縛処理 /
234  * Curse the players armor
235  * @return 何も持っていない場合を除き、常にTRUEを返す
236  */
237 bool curse_armor(player_type *owner_ptr)
238 {
239     /* Curse the body armor */
240     object_type *o_ptr;
241     o_ptr = &owner_ptr->inventory_list[INVEN_BODY];
242
243     if (!o_ptr->k_idx)
244         return FALSE;
245
246     GAME_TEXT o_name[MAX_NLEN];
247     describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
248
249     /* Attempt a saving throw for artifacts */
250     if (object_is_artifact(o_ptr) && (randint0(100) < 50)) {
251         /* Cool */
252 #ifdef JP
253         msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "防具", o_name);
254 #else
255         msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your armor", o_name);
256 #endif
257         return TRUE;
258     }
259
260     /* not artifact or failed save... */
261     msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
262     chg_virtue(owner_ptr, V_ENCHANT, -5);
263
264     /* Blast the armor */
265     o_ptr->name1 = 0;
266     o_ptr->name2 = EGO_BLASTED;
267     o_ptr->to_a = 0 - randint1(5) - randint1(5);
268     o_ptr->to_h = 0;
269     o_ptr->to_d = 0;
270     o_ptr->ac = 0;
271     o_ptr->dd = 0;
272     o_ptr->ds = 0;
273
274     for (int i = 0; i < TR_FLAG_SIZE; i++)
275         o_ptr->art_flags[i] = 0;
276
277     /* Curse it */
278     o_ptr->curse_flags = TRC_CURSED;
279
280     /* Break it */
281     o_ptr->ident |= (IDENT_BROKEN);
282     owner_ptr->update |= (PU_BONUS | PU_MANA);
283     owner_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
284     return TRUE;
285 }
286
287 /*!
288  * todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
289  * @brief 武器呪縛処理 /
290  * Curse the players weapon
291  * @param owner_ptr 所持者の参照ポインタ
292  * @param force 無条件に呪縛を行うならばTRUE
293  * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
294  * @return 何も持っていない場合を除き、常にTRUEを返す
295  */
296 bool curse_weapon_object(player_type *owner_ptr, bool force, object_type *o_ptr)
297 {
298     if (!o_ptr->k_idx)
299         return FALSE;
300
301     GAME_TEXT o_name[MAX_NLEN];
302     describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
303
304     /* Attempt a saving throw */
305     if (object_is_artifact(o_ptr) && (randint0(100) < 50) && !force) {
306 #ifdef JP
307         msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "武器", o_name);
308 #else
309         msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your weapon", o_name);
310 #endif
311         return TRUE;
312     }
313
314     /* not artifact or failed save... */
315     if (!force)
316         msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
317     chg_virtue(owner_ptr, V_ENCHANT, -5);
318
319     /* Shatter the weapon */
320     o_ptr->name1 = 0;
321     o_ptr->name2 = EGO_SHATTERED;
322     o_ptr->to_h = 0 - randint1(5) - randint1(5);
323     o_ptr->to_d = 0 - randint1(5) - randint1(5);
324     o_ptr->to_a = 0;
325     o_ptr->ac = 0;
326     o_ptr->dd = 0;
327     o_ptr->ds = 0;
328
329     for (int i = 0; i < TR_FLAG_SIZE; i++)
330         o_ptr->art_flags[i] = 0;
331
332     /* Curse it */
333     o_ptr->curse_flags = TRC_CURSED;
334
335     /* Break it */
336     o_ptr->ident |= (IDENT_BROKEN);
337     owner_ptr->update |= (PU_BONUS | PU_MANA);
338     owner_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
339     return TRUE;
340 }
341
342 /*!
343  * @brief 防具の錆止め防止処理
344  * @param caster_ptr 錆止め実行者の参照ポインタ
345  * @return ターン消費を要する処理を行ったならばTRUEを返す
346  */
347 bool rustproof(player_type *caster_ptr)
348 {
349     /* Select a piece of armour */
350     item_tester_hook = object_is_armour;
351
352     concptr q = _("どの防具に錆止めをしますか?", "Rustproof which piece of armour? ");
353     concptr s = _("錆止めできるものがありません。", "You have nothing to rustproof.");
354
355     OBJECT_IDX item;
356     object_type *o_ptr;
357     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
358     if (!o_ptr)
359         return FALSE;
360
361     GAME_TEXT o_name[MAX_NLEN];
362     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
363
364     add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
365
366     if ((o_ptr->to_a < 0) && !object_is_cursed(o_ptr)) {
367 #ifdef JP
368         msg_format("%sは新品同様になった!", o_name);
369 #else
370         msg_format("%s %s look%s as good as new!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
371 #endif
372
373         o_ptr->to_a = 0;
374     }
375
376 #ifdef JP
377     msg_format("%sは腐食しなくなった。", o_name);
378 #else
379     msg_format("%s %s %s now protected against corrosion.", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "are" : "is"));
380 #endif
381
382     calc_android_exp(caster_ptr);
383     return TRUE;
384 }
385
386 /*!
387  * @brief ボルトのエゴ化処理(火炎エゴのみ) /
388  * Enchant some bolts
389  * @param caster_ptr プレーヤーへの参照ポインタ
390  * @return なし
391  */
392 void brand_bolts(player_type *caster_ptr)
393 {
394     /* Use the first acceptable bolts */
395     for (int i = 0; i < INVEN_PACK; i++) {
396         object_type *o_ptr = &caster_ptr->inventory_list[i];
397
398         /* Skip non-bolts */
399         if (o_ptr->tval != TV_BOLT)
400             continue;
401
402         /* Skip artifacts and ego-items */
403         if (object_is_artifact(o_ptr) || object_is_ego(o_ptr))
404             continue;
405
406         /* Skip cursed/broken items */
407         if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
408             continue;
409
410         /* Randomize */
411         if (randint0(100) < 75)
412             continue;
413
414         msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
415
416         /* Ego-item */
417         o_ptr->name2 = EGO_FLAME;
418         enchant(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
419         return;
420     }
421
422     if (flush_failure)
423         flush();
424     msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
425 }
426
427 bool perilous_secrets(player_type *user_ptr)
428 {
429     if (!ident_spell(user_ptr, FALSE, 0))
430         return FALSE;
431
432     if (mp_ptr->spell_book) {
433         /* Sufficient mana */
434         if (20 <= user_ptr->csp) {
435             /* Use some mana */
436             user_ptr->csp -= 20;
437         }
438
439         /* Over-exert the player */
440         else {
441             int oops = 20 - user_ptr->csp;
442
443             /* No mana left */
444             user_ptr->csp = 0;
445             user_ptr->csp_frac = 0;
446
447             msg_print(_("石を制御できない!", "You are too weak to control the stone!"));
448             /* Hack -- Bypass free action */
449             (void)set_paralyzed(user_ptr, user_ptr->paralyzed + randint1(5 * oops + 1));
450
451             /* Confusing. */
452             (void)set_confused(user_ptr, user_ptr->confused + randint1(5 * oops + 1));
453         }
454
455         user_ptr->redraw |= (PR_MANA);
456     }
457
458     take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(1, 12), _("危険な秘密", "perilous secrets"), -1);
459     /* Confusing. */
460     if (one_in_(5))
461         (void)set_confused(user_ptr, user_ptr->confused + randint1(10));
462
463     /* Exercise a little care... */
464     if (one_in_(20))
465         take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(4, 10), _("危険な秘密", "perilous secrets"), -1);
466     return TRUE;
467 }
468
469 /*!
470  * @brief 寿命つき光源の燃素追加処理 /
471  * Charge a lite (torch or latern)
472  * @return なし
473  */
474 void phlogiston(player_type *caster_ptr)
475 {
476     GAME_TURN max_flog = 0;
477     object_type *o_ptr = &caster_ptr->inventory_list[INVEN_LITE];
478
479     /* It's a lamp */
480     if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_LANTERN)) {
481         max_flog = FUEL_LAMP;
482     }
483
484     /* It's a torch */
485     else if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH)) {
486         max_flog = FUEL_TORCH;
487     }
488
489     /* No torch to refill */
490     else {
491         msg_print(_("燃素を消費するアイテムを装備していません。", "You are not wielding anything which uses phlogiston."));
492         return;
493     }
494
495     if (o_ptr->xtra4 >= max_flog) {
496         msg_print(_("このアイテムにはこれ以上燃素を補充できません。", "No more phlogiston can be put in this item."));
497         return;
498     }
499
500     /* Refuel */
501     o_ptr->xtra4 += (XTRA16)(max_flog / 2);
502     msg_print(_("照明用アイテムに燃素を補充した。", "You add phlogiston to your light item."));
503
504     if (o_ptr->xtra4 >= max_flog) {
505         o_ptr->xtra4 = (XTRA16)max_flog;
506         msg_print(_("照明用アイテムは満タンになった。", "Your light item is full."));
507     }
508
509     caster_ptr->update |= (PU_TORCH);
510 }
511
512 /*!
513  * @brief 武器の祝福処理 /
514  * Bless a weapon
515  * @return ターン消費を要する処理を行ったならばTRUEを返す
516  */
517 bool bless_weapon(player_type *caster_ptr)
518 {
519     /* Bless only weapons */
520     item_tester_hook = object_is_weapon;
521
522     concptr q = _("どのアイテムを祝福しますか?", "Bless which weapon? ");
523     concptr s = _("祝福できる武器がありません。", "You have weapon to bless.");
524
525     OBJECT_IDX item;
526     object_type *o_ptr;
527     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
528     if (!o_ptr)
529         return FALSE;
530
531     GAME_TEXT o_name[MAX_NLEN];
532     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
533     BIT_FLAGS flgs[TR_FLAG_SIZE];
534     object_flags(caster_ptr, o_ptr, flgs);
535
536     if (object_is_cursed(o_ptr)) {
537         if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint1(100) < 33)) || have_flag(flgs, TR_ADD_L_CURSE) || have_flag(flgs, TR_ADD_H_CURSE)
538             || (o_ptr->curse_flags & TRC_PERMA_CURSE)) {
539 #ifdef JP
540             msg_format("%sを覆う黒いオーラは祝福を跳ね返した!", o_name);
541 #else
542             msg_format("The black aura on %s %s disrupts the blessing!", ((item >= 0) ? "your" : "the"), o_name);
543 #endif
544
545             return TRUE;
546         }
547
548 #ifdef JP
549         msg_format("%s から邪悪なオーラが消えた。", o_name);
550 #else
551         msg_format("A malignant aura leaves %s %s.", ((item >= 0) ? "your" : "the"), o_name);
552 #endif
553
554         o_ptr->curse_flags = 0L;
555
556         o_ptr->ident |= (IDENT_SENSE);
557         o_ptr->feeling = FEEL_NONE;
558
559         /* Recalculate the bonuses */
560         caster_ptr->update |= (PU_BONUS);
561         caster_ptr->window |= (PW_EQUIP);
562     }
563
564     /*
565      * Next, we try to bless it. Artifacts have a 1/3 chance of
566      * being blessed, otherwise, the operation simply disenchants
567      * them, godly power negating the magic. Ok, the explanation
568      * is silly, but otherwise priests would always bless every
569      * artifact weapon they find. Ego weapons and normal weapons
570      * can be blessed automatically.
571      */
572     if (have_flag(flgs, TR_BLESSED)) {
573 #ifdef JP
574         msg_format("%s は既に祝福されている。", o_name);
575 #else
576         msg_format("%s %s %s blessed already.", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "were" : "was"));
577 #endif
578
579         return TRUE;
580     }
581
582     if (!(object_is_artifact(o_ptr) || object_is_ego(o_ptr)) || one_in_(3)) {
583 #ifdef JP
584         msg_format("%sは輝いた!", o_name);
585 #else
586         msg_format("%s %s shine%s!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
587 #endif
588
589         add_flag(o_ptr->art_flags, TR_BLESSED);
590         o_ptr->discount = 99;
591     } else {
592         bool dis_happened = FALSE;
593         msg_print(_("その武器は祝福を嫌っている!", "The weapon resists your blessing!"));
594
595         /* Disenchant tohit */
596         if (o_ptr->to_h > 0) {
597             o_ptr->to_h--;
598             dis_happened = TRUE;
599         }
600
601         if ((o_ptr->to_h > 5) && (randint0(100) < 33))
602             o_ptr->to_h--;
603
604         /* Disenchant todam */
605         if (o_ptr->to_d > 0) {
606             o_ptr->to_d--;
607             dis_happened = TRUE;
608         }
609
610         if ((o_ptr->to_d > 5) && (randint0(100) < 33))
611             o_ptr->to_d--;
612
613         /* Disenchant toac */
614         if (o_ptr->to_a > 0) {
615             o_ptr->to_a--;
616             dis_happened = TRUE;
617         }
618
619         if ((o_ptr->to_a > 5) && (randint0(100) < 33))
620             o_ptr->to_a--;
621
622         if (dis_happened) {
623             msg_print(_("周囲が凡庸な雰囲気で満ちた...", "There is a static feeling in the air..."));
624
625 #ifdef JP
626             msg_format("%s は劣化した!", o_name);
627 #else
628             msg_format("%s %s %s disenchanted!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "were" : "was"));
629 #endif
630         }
631     }
632
633     caster_ptr->update |= (PU_BONUS);
634     caster_ptr->window |= (PW_EQUIP | PW_PLAYER);
635     calc_android_exp(caster_ptr);
636
637     return TRUE;
638 }
639
640 /*!
641  * @brief 盾磨き処理 /
642  * pulish shield
643  * @return ターン消費を要する処理を行ったならばTRUEを返す
644  */
645 bool pulish_shield(player_type *caster_ptr)
646 {
647     concptr q = _("どの盾を磨きますか?", "Pulish which weapon? ");
648     concptr s = _("磨く盾がありません。", "You have weapon to pulish.");
649
650     OBJECT_IDX item;
651     object_type *o_ptr;
652     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), TV_SHIELD);
653     if (!o_ptr)
654         return FALSE;
655
656     GAME_TEXT o_name[MAX_NLEN];
657     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
658     BIT_FLAGS flgs[TR_FLAG_SIZE];
659     object_flags(caster_ptr, o_ptr, flgs);
660
661     bool is_pulish_successful = o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr);
662     is_pulish_successful &= !object_is_cursed(o_ptr);
663     is_pulish_successful &= (o_ptr->sval != SV_MIRROR_SHIELD);
664     if (is_pulish_successful) {
665 #ifdef JP
666         msg_format("%sは輝いた!", o_name);
667 #else
668         msg_format("%s %s shine%s!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
669 #endif
670         o_ptr->name2 = EGO_REFLECTION;
671         enchant(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOAC);
672
673         o_ptr->discount = 99;
674         chg_virtue(caster_ptr, V_ENCHANT, 2);
675
676         return TRUE;
677     }
678
679     if (flush_failure)
680         flush();
681
682     msg_print(_("失敗した。", "Failed."));
683     chg_virtue(caster_ptr, V_ENCHANT, -2);
684     calc_android_exp(caster_ptr);
685     return FALSE;
686 }
687
688 /*!
689  * @brief 呪いの打ち破り処理 /
690  * Break the curse of an item
691  * @param o_ptr 呪い装備情報の参照ポインタ
692  * @return なし
693  */
694 static void break_curse(object_type *o_ptr)
695 {
696     BIT_FLAGS is_curse_broken
697         = object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25);
698     if (!is_curse_broken) {
699         return;
700     }
701
702     msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
703
704     o_ptr->curse_flags = 0L;
705     o_ptr->ident |= (IDENT_SENSE);
706     o_ptr->feeling = FEEL_NONE;
707 }
708
709 /*!
710  * @brief 装備修正強化処理 /
711  * Enchants a plus onto an item. -RAK-
712  * @param caster_ptr プレーヤーへの参照ポインタ
713  * @param o_ptr 強化するアイテムの参照ポインタ
714  * @param n 強化基本量
715  * @param eflag 強化オプション(命中/ダメージ/AC)
716  * @return 強化に成功した場合TRUEを返す
717  * @details
718  * <pre>
719  * Revamped!  Now takes item pointer, number of times to try enchanting,
720  * and a flag of what to try enchanting.  Artifacts resist enchantment
721  * some of the time, and successful enchantment to at least +0 might
722  * break a curse on the item. -CFT-
723  *
724  * Note that an item can technically be enchanted all the way to +15 if
725  * you wait a very, very, long time.  Going from +9 to +10 only works
726  * about 5% of the time, and from +10 to +11 only about 1% of the time.
727  *
728  * Note that this function can now be used on "piles" of items, and
729  * the larger the pile, the lower the chance of success.
730  * </pre>
731  */
732 bool enchant(player_type *caster_ptr, object_type *o_ptr, int n, int eflag)
733 {
734     /* Large piles resist enchantment */
735     int prob = o_ptr->number * 100;
736
737     /* Missiles are easy to enchant */
738     if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT)) {
739         prob = prob / 20;
740     }
741
742     /* Try "n" times */
743     int chance;
744     bool res = FALSE;
745     bool a = object_is_artifact(o_ptr);
746     bool force = (eflag & ENCH_FORCE);
747     for (int i = 0; i < n; i++) {
748         /* Hack -- Roll for pile resistance */
749         if (!force && randint0(prob) >= 100)
750             continue;
751
752         /* Enchant to hit */
753         if (eflag & ENCH_TOHIT) {
754             if (o_ptr->to_h < 0)
755                 chance = 0;
756             else if (o_ptr->to_h > 15)
757                 chance = 1000;
758             else
759                 chance = enchant_table[o_ptr->to_h];
760
761             if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
762                 o_ptr->to_h++;
763                 res = TRUE;
764
765                 /* only when you get it above -1 -CFT */
766                 if (o_ptr->to_h >= 0)
767                     break_curse(o_ptr);
768             }
769         }
770
771         /* Enchant to damage */
772         if (eflag & ENCH_TODAM) {
773             if (o_ptr->to_d < 0)
774                 chance = 0;
775             else if (o_ptr->to_d > 15)
776                 chance = 1000;
777             else
778                 chance = enchant_table[o_ptr->to_d];
779
780             if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
781                 o_ptr->to_d++;
782                 res = TRUE;
783
784                 /* only when you get it above -1 -CFT */
785                 if (o_ptr->to_d >= 0)
786                     break_curse(o_ptr);
787             }
788         }
789
790         /* Enchant to armor class */
791         if (!(eflag & ENCH_TOAC)) {
792             continue;
793         }
794
795         if (o_ptr->to_a < 0)
796             chance = 0;
797         else if (o_ptr->to_a > 15)
798             chance = 1000;
799         else
800             chance = enchant_table[o_ptr->to_a];
801
802         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
803             o_ptr->to_a++;
804             res = TRUE;
805
806             /* only when you get it above -1 -CFT */
807             if (o_ptr->to_a >= 0)
808                 break_curse(o_ptr);
809         }
810     }
811
812     /* Failure */
813     if (!res)
814         return FALSE;
815     caster_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
816     caster_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
817
818     calc_android_exp(caster_ptr);
819
820     /* Success */
821     return TRUE;
822 }
823
824 /*!
825  * @brief 装備修正強化処理のメインルーチン /
826  * Enchant an item (in the inventory or on the floor)
827  * @param caster_ptr プレーヤーへの参照ポインタ
828  * @param num_hit 命中修正量
829  * @param num_dam ダメージ修正量
830  * @param num_ac AC修正量
831  * @return 強化に成功した場合TRUEを返す
832  * @details
833  * Note that "num_ac" requires armour, else weapon
834  * Returns TRUE if attempted, FALSE if cancelled
835  */
836 bool enchant_spell(player_type *caster_ptr, HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
837 {
838     /* Assume enchant weapon */
839     item_tester_hook = object_allow_enchant_weapon;
840
841     /* Enchant armor if requested */
842     if (num_ac)
843         item_tester_hook = object_is_armour;
844
845     concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
846     concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
847
848     OBJECT_IDX item;
849     object_type *o_ptr;
850     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
851     if (!o_ptr)
852         return FALSE;
853
854     GAME_TEXT o_name[MAX_NLEN];
855     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
856 #ifdef JP
857     msg_format("%s は明るく輝いた!", o_name);
858 #else
859     msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
860 #endif
861
862     /* Enchant */
863     bool is_enchant_successful = FALSE;
864     if (enchant(caster_ptr, o_ptr, num_hit, ENCH_TOHIT))
865         is_enchant_successful = TRUE;
866     if (enchant(caster_ptr, o_ptr, num_dam, ENCH_TODAM))
867         is_enchant_successful = TRUE;
868     if (enchant(caster_ptr, o_ptr, num_ac, ENCH_TOAC))
869         is_enchant_successful = TRUE;
870
871     if (!is_enchant_successful) {
872         if (flush_failure)
873             flush();
874         msg_print(_("強化に失敗した。", "The enchantment failed."));
875         if (one_in_(3))
876             chg_virtue(caster_ptr, V_ENCHANT, -1);
877     } else
878         chg_virtue(caster_ptr, V_ENCHANT, 1);
879
880     calc_android_exp(caster_ptr);
881
882     /* Something happened */
883     return TRUE;
884 }
885
886 /*!
887  * @brief 武器へのエゴ付加処理 /
888  * Brand the current weapon
889  * @param caster_ptr プレーヤーへの参照ポインタ
890  * @param brand_type エゴ化ID(e_info.txtとは連動していない)
891  * @return なし
892  */
893 void brand_weapon(player_type *caster_ptr, int brand_type)
894 {
895     /* Assume enchant weapon */
896     item_tester_hook = object_allow_enchant_melee_weapon;
897
898     concptr q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
899     concptr s = _("強化できる武器がない。", "You have nothing to enchant.");
900
901     OBJECT_IDX item;
902     object_type *o_ptr;
903     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0);
904     if (!o_ptr)
905         return;
906
907     bool is_special_item = o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) && !object_is_cursed(o_ptr)
908         && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) && !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE))
909         && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE));
910     if (!is_special_item) {
911         if (flush_failure)
912             flush();
913
914         msg_print(_("属性付加に失敗した。", "The branding failed."));
915         chg_virtue(caster_ptr, V_ENCHANT, -2);
916         calc_android_exp(caster_ptr);
917         return;
918     }
919
920     /* Let's get the name before it is changed... */
921     GAME_TEXT o_name[MAX_NLEN];
922     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
923
924     concptr act = NULL;
925     switch (brand_type) {
926     case 17:
927         if (o_ptr->tval == TV_SWORD) {
928             act = _("は鋭さを増した!", "becomes very sharp!");
929
930             o_ptr->name2 = EGO_SHARPNESS;
931             o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, caster_ptr->current_floor_ptr->dun_level) + 1;
932
933             if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
934                 o_ptr->pval = 2;
935         } else {
936             act = _("は破壊力を増した!", "seems very powerful.");
937             o_ptr->name2 = EGO_EARTHQUAKES;
938             o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, caster_ptr->current_floor_ptr->dun_level);
939         }
940
941         break;
942     case 16:
943         act = _("は人間の血を求めている!", "seems to be looking for humans!");
944         o_ptr->name2 = EGO_KILL_HUMAN;
945         break;
946     case 15:
947         act = _("は電撃に覆われた!", "covered with lightning!");
948         o_ptr->name2 = EGO_BRAND_ELEC;
949         break;
950     case 14:
951         act = _("は酸に覆われた!", "coated with acid!");
952         o_ptr->name2 = EGO_BRAND_ACID;
953         break;
954     case 13:
955         act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
956         o_ptr->name2 = EGO_KILL_EVIL;
957         break;
958     case 12:
959         act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
960         o_ptr->name2 = EGO_KILL_DEMON;
961         break;
962     case 11:
963         act = _("は屍を求めている!", "seems to be looking for undead!");
964         o_ptr->name2 = EGO_KILL_UNDEAD;
965         break;
966     case 10:
967         act = _("は動物の血を求めている!", "seems to be looking for animals!");
968         o_ptr->name2 = EGO_KILL_ANIMAL;
969         break;
970     case 9:
971         act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
972         o_ptr->name2 = EGO_KILL_DRAGON;
973         break;
974     case 8:
975         act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
976         o_ptr->name2 = EGO_KILL_TROLL;
977         break;
978     case 7:
979         act = _("はオークの血を求めている!", "seems to be looking for orcs!");
980         o_ptr->name2 = EGO_KILL_ORC;
981         break;
982     case 6:
983         act = _("は巨人の血を求めている!", "seems to be looking for giants!");
984         o_ptr->name2 = EGO_KILL_GIANT;
985         break;
986     case 5:
987         act = _("は非常に不安定になったようだ。", "seems very unstable now.");
988         o_ptr->name2 = EGO_TRUMP;
989         o_ptr->pval = randint1(2);
990         break;
991     case 4:
992         act = _("は血を求めている!", "thirsts for blood!");
993         o_ptr->name2 = EGO_VAMPIRIC;
994         break;
995     case 3:
996         act = _("は毒に覆われた。", "is coated with poison.");
997         o_ptr->name2 = EGO_BRAND_POIS;
998         break;
999     case 2:
1000         act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
1001         o_ptr->name2 = EGO_CHAOTIC;
1002         break;
1003     case 1:
1004         act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
1005         o_ptr->name2 = EGO_BRAND_FIRE;
1006         break;
1007     default:
1008         act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
1009         o_ptr->name2 = EGO_BRAND_COLD;
1010         break;
1011     }
1012
1013     msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
1014     enchant(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
1015
1016     o_ptr->discount = 99;
1017     chg_virtue(caster_ptr, V_ENCHANT, 2);
1018     calc_android_exp(caster_ptr);
1019 }
1020
1021 bool create_ration(player_type *creature_ptr)
1022 {
1023     object_type *q_ptr;
1024     object_type forge;
1025     q_ptr = &forge;
1026     object_prep(creature_ptr, q_ptr, lookup_kind(TV_FOOD, SV_FOOD_RATION));
1027     (void)drop_near(creature_ptr, q_ptr, -1, creature_ptr->y, creature_ptr->x);
1028     msg_print(_("食事を料理して作った。", "You cook some food."));
1029     return TRUE;
1030 }