OSDN Git Service

[Refactor] #37353 externs.h から util.h への宣言移動。
[hengband/hengband.git] / src / spells-object.c
1 
2 #include "angband.h"
3 #include "util.h"
4
5 #include "artifact.h"
6 #include "floor.h"
7 #include "grid.h"
8 #include "spells-object.h"
9 #include "object-boost.h"
10 #include "object-hook.h"
11 #include "object-flavor.h"
12 #include "player-status.h"
13 #include "avatar.h"
14 #include "player-effects.h"
15
16
17 typedef struct
18 {
19         OBJECT_TYPE_VALUE tval;
20         OBJECT_SUBTYPE_VALUE sval;
21         PERCENTAGE prob;
22         byte flag;
23 } amuse_type;
24
25 /*
26  * Scatter some "amusing" objects near the player
27  */
28
29 #define AMS_NOTHING   0x00 /* No restriction */
30 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
31 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
32 #define AMS_MULTIPLE  0x04 /* Drop 1-3 objects for one type */
33 #define AMS_PILE      0x08 /* Drop 1-99 pile objects for one type */
34
35 static amuse_type amuse_info[] =
36 {
37         { TV_BOTTLE, SV_ANY, 5, AMS_NOTHING },
38         { TV_JUNK, SV_ANY, 3, AMS_MULTIPLE },
39         { TV_SPIKE, SV_ANY, 10, AMS_PILE },
40         { TV_STATUE, SV_ANY, 15, AMS_NOTHING },
41         { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE },
42         { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE },
43         { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
44         { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING },
45         { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, //Fishing Pole of Taikobo
46         { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, //Broken Dagger of Magician
47         { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING },
48         { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING },
49         { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
50
51         { 0, 0, 0 }
52 };
53
54 /*!
55  * @brief「弾/矢の製造」処理 / do_cmd_cast calls this function if the player's class is 'archer'.
56  * Hook to determine if an object is contertible in an arrow/bolt
57  * @return 製造を実際に行ったらTRUE、キャンセルしたらFALSEを返す
58  */
59 bool create_ammo(void)
60 {
61         int ext = 0;
62         char ch;
63
64         object_type     forge;
65         object_type *q_ptr;
66
67         char com[80];
68         GAME_TEXT o_name[MAX_NLEN];
69
70         q_ptr = &forge;
71
72         if (p_ptr->lev >= 20)
73                 sprintf(com, _("[S]弾, [A]矢, [B]クロスボウの矢 :", "Create [S]hots, Create [A]rrow or Create [B]olt ?"));
74         else if (p_ptr->lev >= 10)
75                 sprintf(com, _("[S]弾, [A]矢:", "Create [S]hots or Create [A]rrow ?"));
76         else
77                 sprintf(com, _("[S]弾:", "Create [S]hots ?"));
78
79         if (p_ptr->confused)
80         {
81                 msg_print(_("混乱してる!", "You are too confused!"));
82                 return FALSE;
83         }
84
85         if (p_ptr->blind)
86         {
87                 msg_print(_("目が見えない!", "You are blind!"));
88                 return FALSE;
89         }
90
91         while (TRUE)
92         {
93                 if (!get_com(com, &ch, TRUE))
94                 {
95                         return FALSE;
96                 }
97                 if (ch == 'S' || ch == 's')
98                 {
99                         ext = 1;
100                         break;
101                 }
102                 if ((ch == 'A' || ch == 'a') && (p_ptr->lev >= 10))
103                 {
104                         ext = 2;
105                         break;
106                 }
107                 if ((ch == 'B' || ch == 'b') && (p_ptr->lev >= 20))
108                 {
109                         ext = 3;
110                         break;
111                 }
112         }
113
114         /**********Create shots*********/
115         if (ext == 1)
116         {
117                 POSITION x, y;
118                 DIRECTION dir;
119                 grid_type *g_ptr;
120
121                 if (!get_rep_dir(&dir, FALSE)) return FALSE;
122                 y = p_ptr->y + ddy[dir];
123                 x = p_ptr->x + ddx[dir];
124                 g_ptr = &current_floor_ptr->grid_array[y][x];
125
126                 if (!have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_CAN_DIG))
127                 {
128                         msg_print(_("そこには岩石がない。", "You need pile of rubble."));
129                         return FALSE;
130                 }
131                 else if (!cave_have_flag_grid(g_ptr, FF_CAN_DIG) || !cave_have_flag_grid(g_ptr, FF_HURT_ROCK))
132                 {
133                         msg_print(_("硬すぎて崩せなかった。", "You failed to make ammo."));
134                 }
135                 else
136                 {
137                         s16b slot;
138                         q_ptr = &forge;
139
140                         /* Hack -- Give the player some small firestones */
141                         object_prep(q_ptr, lookup_kind(TV_SHOT, (OBJECT_SUBTYPE_VALUE)m_bonus(1, p_ptr->lev) + 1));
142                         q_ptr->number = (byte)rand_range(15, 30);
143                         object_aware(q_ptr);
144                         object_known(q_ptr);
145                         apply_magic(q_ptr, p_ptr->lev, AM_NO_FIXED_ART);
146                         q_ptr->discount = 99;
147
148                         slot = inven_carry(q_ptr);
149
150                         object_desc(o_name, q_ptr, 0);
151                         msg_format(_("%sを作った。", "You make some ammo."), o_name);
152
153                         /* Auto-inscription */
154                         if (slot >= 0) autopick_alter_item(slot, FALSE);
155
156                         /* Destroy the wall */
157                         cave_alter_feat(y, x, FF_HURT_ROCK);
158
159                         p_ptr->update |= (PU_FLOW);
160                 }
161         }
162         /**********Create arrows*********/
163         else if (ext == 2)
164         {
165                 OBJECT_IDX item;
166                 concptr q, s;
167                 s16b slot;
168
169                 item_tester_hook = item_tester_hook_convertible;
170
171                 q = _("どのアイテムから作りますか? ", "Convert which item? ");
172                 s = _("材料を持っていない。", "You have no item to convert.");
173                 q_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
174                 if (!q_ptr) return FALSE;
175
176                 q_ptr = &forge;
177
178                 /* Hack -- Give the player some small firestones */
179                 object_prep(q_ptr, lookup_kind(TV_ARROW, (OBJECT_SUBTYPE_VALUE)m_bonus(1, p_ptr->lev) + 1));
180                 q_ptr->number = (byte)rand_range(5, 10);
181                 object_aware(q_ptr);
182                 object_known(q_ptr);
183                 apply_magic(q_ptr, p_ptr->lev, AM_NO_FIXED_ART);
184
185                 q_ptr->discount = 99;
186
187                 object_desc(o_name, q_ptr, 0);
188                 msg_format(_("%sを作った。", "You make some ammo."), o_name);
189
190                 if (item >= 0)
191                 {
192                         inven_item_increase(item, -1);
193                         inven_item_describe(item);
194                         inven_item_optimize(item);
195                 }
196                 else
197                 {
198                         floor_item_increase(0 - item, -1);
199                         floor_item_describe(0 - item);
200                         floor_item_optimize(0 - item);
201                 }
202
203                 slot = inven_carry(q_ptr);
204
205                 /* Auto-inscription */
206                 if (slot >= 0) autopick_alter_item(slot, FALSE);
207         }
208         /**********Create bolts*********/
209         else if (ext == 3)
210         {
211                 OBJECT_IDX item;
212                 concptr q, s;
213                 s16b slot;
214
215                 item_tester_hook = item_tester_hook_convertible;
216
217                 q = _("どのアイテムから作りますか? ", "Convert which item? ");
218                 s = _("材料を持っていない。", "You have no item to convert.");
219
220                 q_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
221                 if (!q_ptr) return FALSE;
222
223                 q_ptr = &forge;
224
225                 /* Hack -- Give the player some small firestones */
226                 object_prep(q_ptr, lookup_kind(TV_BOLT, (OBJECT_SUBTYPE_VALUE)m_bonus(1, p_ptr->lev) + 1));
227                 q_ptr->number = (byte)rand_range(4, 8);
228                 object_aware(q_ptr);
229                 object_known(q_ptr);
230                 apply_magic(q_ptr, p_ptr->lev, AM_NO_FIXED_ART);
231
232                 q_ptr->discount = 99;
233
234                 object_desc(o_name, q_ptr, 0);
235                 msg_format(_("%sを作った。", "You make some ammo."), o_name);
236
237                 if (item >= 0)
238                 {
239                         inven_item_increase(item, -1);
240                         inven_item_describe(item);
241                         inven_item_optimize(item);
242                 }
243                 else
244                 {
245                         floor_item_increase(0 - item, -1);
246                         floor_item_describe(0 - item);
247                         floor_item_optimize(0 - item);
248                 }
249
250                 slot = inven_carry(q_ptr);
251
252                 /* Auto-inscription */
253                 if (slot >= 0) autopick_alter_item(slot, FALSE);
254         }
255         return TRUE;
256 }
257
258 /*!
259  * @brief 魔道具術師の魔力取り込み処理
260  * @return 取り込みを実行したらTRUE、キャンセルしたらFALSEを返す
261  */
262 bool import_magic_device(void)
263 {
264         OBJECT_IDX item;
265         PARAMETER_VALUE pval;
266         int ext = 0;
267         concptr q, s;
268         object_type *o_ptr;
269         GAME_TEXT o_name[MAX_NLEN];
270
271         /* Only accept legal items */
272         item_tester_hook = item_tester_hook_recharge;
273
274         q = _("どのアイテムの魔力を取り込みますか? ", "Gain power of which item? ");
275         s = _("魔力を取り込めるアイテムがない。", "You have nothing to gain power.");
276
277         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
278         if (!o_ptr) return (FALSE);
279
280         if (o_ptr->tval == TV_STAFF && o_ptr->sval == SV_STAFF_NOTHING)
281         {
282                 msg_print(_("この杖には発動の為の能力は何も備わっていないようだ。", "This staff doesn't have any magical ability."));
283                 return FALSE;
284         }
285
286         if (!object_is_known(o_ptr))
287         {
288                 msg_print(_("鑑定されていないと取り込めない。", "You need to identify before absorbing."));
289                 return FALSE;
290         }
291
292         if (o_ptr->timeout)
293         {
294                 msg_print(_("充填中のアイテムは取り込めない。", "This item is still charging."));
295                 return FALSE;
296         }
297
298         pval = o_ptr->pval;
299         if (o_ptr->tval == TV_ROD)
300                 ext = 72;
301         else if (o_ptr->tval == TV_WAND)
302                 ext = 36;
303
304         if (o_ptr->tval == TV_ROD)
305         {
306                 p_ptr->magic_num2[o_ptr->sval + ext] += (MAGIC_NUM2)o_ptr->number;
307                 if (p_ptr->magic_num2[o_ptr->sval + ext] > 99) p_ptr->magic_num2[o_ptr->sval + ext] = 99;
308         }
309         else
310         {
311                 int num;
312                 for (num = o_ptr->number; num; num--)
313                 {
314                         int gain_num = pval;
315                         if (o_ptr->tval == TV_WAND) gain_num = (pval + num - 1) / num;
316                         if (p_ptr->magic_num2[o_ptr->sval + ext])
317                         {
318                                 gain_num *= 256;
319                                 gain_num = (gain_num / 3 + randint0(gain_num / 3)) / 256;
320                                 if (gain_num < 1) gain_num = 1;
321                         }
322                         p_ptr->magic_num2[o_ptr->sval + ext] += (MAGIC_NUM2)gain_num;
323                         if (p_ptr->magic_num2[o_ptr->sval + ext] > 99) p_ptr->magic_num2[o_ptr->sval + ext] = 99;
324                         p_ptr->magic_num1[o_ptr->sval + ext] += pval * 0x10000;
325                         if (p_ptr->magic_num1[o_ptr->sval + ext] > 99 * 0x10000) p_ptr->magic_num1[o_ptr->sval + ext] = 99 * 0x10000;
326                         if (p_ptr->magic_num1[o_ptr->sval + ext] > p_ptr->magic_num2[o_ptr->sval + ext] * 0x10000) p_ptr->magic_num1[o_ptr->sval + ext] = p_ptr->magic_num2[o_ptr->sval + ext] * 0x10000;
327                         if (o_ptr->tval == TV_WAND) pval -= (pval + num - 1) / num;
328                 }
329         }
330
331         object_desc(o_name, o_ptr, 0);
332         msg_format(_("%sの魔力を取り込んだ。", "You absorb magic of %s."), o_name);
333
334         /* Eliminate the item (from the pack) */
335         if (item >= 0)
336         {
337                 inven_item_increase(item, -999);
338                 inven_item_describe(item);
339                 inven_item_optimize(item);
340         }
341
342         /* Eliminate the item (from the floor) */
343         else
344         {
345                 floor_item_increase(0 - item, -999);
346                 floor_item_describe(0 - item);
347                 floor_item_optimize(0 - item);
348         }
349         take_turn(p_ptr, 100);
350         return TRUE;
351 }
352
353 /*!
354  * @brief 誰得ドロップを行う。
355  * @param y1 配置したいフロアのY座標
356  * @param x1 配置したいフロアのX座標
357  * @param num 誰得の処理回数
358  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
359  * @return なし
360  */
361 void amusement(POSITION y1, POSITION x1, int num, bool known)
362 {
363         object_type *i_ptr;
364         object_type object_type_body;
365         int n, t = 0;
366
367         for (n = 0; amuse_info[n].tval != 0; n++)
368         {
369                 t += amuse_info[n].prob;
370         }
371
372         /* Acquirement */
373         while (num)
374         {
375                 int i;
376                 KIND_OBJECT_IDX k_idx;
377                 ARTIFACT_IDX a_idx = 0;
378                 int r = randint0(t);
379                 bool insta_art, fixed_art;
380
381                 for (i = 0; ; i++)
382                 {
383                         r -= amuse_info[i].prob;
384                         if (r <= 0) break;
385                 }
386                 i_ptr = &object_type_body;
387                 object_wipe(i_ptr);
388                 k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
389
390                 /* Paranoia - reroll if nothing */
391                 if (!k_idx) continue;
392
393                 /* Search an artifact index if need */
394                 insta_art = (k_info[k_idx].gen_flags & TRG_INSTA_ART);
395                 fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
396
397                 if (insta_art || fixed_art)
398                 {
399                         for (a_idx = 1; a_idx < max_a_idx; a_idx++)
400                         {
401                                 if (insta_art && !(a_info[a_idx].gen_flags & TRG_INSTA_ART)) continue;
402                                 if (a_info[a_idx].tval != k_info[k_idx].tval) continue;
403                                 if (a_info[a_idx].sval != k_info[k_idx].sval) continue;
404                                 if (a_info[a_idx].cur_num > 0) continue;
405                                 break;
406                         }
407
408                         if (a_idx >= max_a_idx) continue;
409                 }
410
411                 /* Make an object (if possible) */
412                 object_prep(i_ptr, k_idx);
413                 if (a_idx) i_ptr->name1 = a_idx;
414                 apply_magic(i_ptr, 1, AM_NO_FIXED_ART);
415
416                 if (amuse_info[i].flag & AMS_NO_UNIQUE)
417                 {
418                         if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE) continue;
419                 }
420
421                 if (amuse_info[i].flag & AMS_MULTIPLE) i_ptr->number = randint1(3);
422                 if (amuse_info[i].flag & AMS_PILE) i_ptr->number = randint1(99);
423
424                 if (known)
425                 {
426                         object_aware(i_ptr);
427                         object_known(i_ptr);
428                 }
429
430                 /* Paranoia - reroll if nothing */
431                 if (!(i_ptr->k_idx)) continue;
432
433                 (void)drop_near(i_ptr, -1, y1, x1);
434
435                 num--;
436         }
437 }
438
439
440
441 /*!
442  * @brief 獲得ドロップを行う。
443  * Scatter some "great" objects near the player
444  * @param y1 配置したいフロアのY座標
445  * @param x1 配置したいフロアのX座標
446  * @param num 獲得の処理回数
447  * @param great TRUEならば必ず高級品以上を落とす
448  * @param special TRUEならば必ず特別品を落とす
449  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
450  * @return なし
451  */
452 void acquirement(POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
453 {
454         object_type *i_ptr;
455         object_type object_type_body;
456         BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : 0L) | (special ? AM_SPECIAL : 0L);
457
458         /* Acquirement */
459         while (num--)
460         {
461                 i_ptr = &object_type_body;
462                 object_wipe(i_ptr);
463
464                 /* Make a good (or great) object (if possible) */
465                 if (!make_object(i_ptr, mode)) continue;
466
467                 if (known)
468                 {
469                         object_aware(i_ptr);
470                         object_known(i_ptr);
471                 }
472
473                 (void)drop_near(i_ptr, -1, y1, x1);
474         }
475 }
476
477 void acquire_chaos_weapon(player_type *creature_ptr)
478 {
479         object_type forge;
480         object_type *q_ptr = &forge;
481         OBJECT_TYPE_VALUE dummy = TV_SWORD;
482         OBJECT_SUBTYPE_VALUE dummy2;
483         switch (randint1(creature_ptr->lev))
484         {
485         case 0: case 1:
486                 dummy2 = SV_DAGGER;
487                 break;
488         case 2: case 3:
489                 dummy2 = SV_MAIN_GAUCHE;
490                 break;
491         case 4:
492                 dummy2 = SV_TANTO;
493                 break;
494         case 5: case 6:
495                 dummy2 = SV_RAPIER;
496                 break;
497         case 7: case 8:
498                 dummy2 = SV_SMALL_SWORD;
499                 break;
500         case 9: case 10:
501                 dummy2 = SV_BASILLARD;
502                 break;
503         case 11: case 12: case 13:
504                 dummy2 = SV_SHORT_SWORD;
505                 break;
506         case 14: case 15:
507                 dummy2 = SV_SABRE;
508                 break;
509         case 16: case 17:
510                 dummy2 = SV_CUTLASS;
511                 break;
512         case 18:
513                 dummy2 = SV_WAKIZASHI;
514                 break;
515         case 19:
516                 dummy2 = SV_KHOPESH;
517                 break;
518         case 20:
519                 dummy2 = SV_TULWAR;
520                 break;
521         case 21:
522                 dummy2 = SV_BROAD_SWORD;
523                 break;
524         case 22: case 23:
525                 dummy2 = SV_LONG_SWORD;
526                 break;
527         case 24: case 25:
528                 dummy2 = SV_SCIMITAR;
529                 break;
530         case 26:
531                 dummy2 = SV_NINJATO;
532                 break;
533         case 27:
534                 dummy2 = SV_KATANA;
535                 break;
536         case 28: case 29:
537                 dummy2 = SV_BASTARD_SWORD;
538                 break;
539         case 30:
540                 dummy2 = SV_GREAT_SCIMITAR;
541                 break;
542         case 31:
543                 dummy2 = SV_CLAYMORE;
544                 break;
545         case 32:
546                 dummy2 = SV_ESPADON;
547                 break;
548         case 33:
549                 dummy2 = SV_TWO_HANDED_SWORD;
550                 break;
551         case 34:
552                 dummy2 = SV_FLAMBERGE;
553                 break;
554         case 35:
555                 dummy2 = SV_NO_DACHI;
556                 break;
557         case 36:
558                 dummy2 = SV_EXECUTIONERS_SWORD;
559                 break;
560         case 37:
561                 dummy2 = SV_ZWEIHANDER;
562                 break;
563         case 38:
564                 dummy2 = SV_HAYABUSA;
565                 break;
566         default:
567                 dummy2 = SV_BLADE_OF_CHAOS;
568         }
569
570         object_prep(q_ptr, lookup_kind(dummy, dummy2));
571         q_ptr->to_h = 3 + randint1(current_floor_ptr->dun_level) % 10;
572         q_ptr->to_d = 3 + randint1(current_floor_ptr->dun_level) % 10;
573         one_resistance(q_ptr);
574         q_ptr->name2 = EGO_CHAOTIC;
575         (void)drop_near(q_ptr, -1, creature_ptr->y, creature_ptr->x);
576 }
577
578
579 /*!
580  * @brief 防具呪縛処理 /
581  * Curse the players armor
582  * @return 実際に呪縛されたらTRUEを返す
583  */
584 bool curse_armor(void)
585 {
586         int i;
587         object_type *o_ptr;
588
589         GAME_TEXT o_name[MAX_NLEN];
590
591         /* Curse the body armor */
592         o_ptr = &inventory[INVEN_BODY];
593
594         /* Nothing to curse */
595         if (!o_ptr->k_idx) return (FALSE);
596
597         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
598
599         /* Attempt a saving throw for artifacts */
600         if (object_is_artifact(o_ptr) && (randint0(100) < 50))
601         {
602                 /* Cool */
603 #ifdef JP
604                 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!",
605                         "恐怖の暗黒オーラ", "防具", o_name);
606 #else
607                 msg_format("A %s tries to %s, but your %s resists the effects!",
608                         "terrible black aura", "surround your armor", o_name);
609 #endif
610
611         }
612
613         /* not artifact or failed save... */
614         else
615         {
616                 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
617                 chg_virtue(V_ENCHANT, -5);
618
619                 /* Blast the armor */
620                 o_ptr->name1 = 0;
621                 o_ptr->name2 = EGO_BLASTED;
622                 o_ptr->to_a = 0 - randint1(5) - randint1(5);
623                 o_ptr->to_h = 0;
624                 o_ptr->to_d = 0;
625                 o_ptr->ac = 0;
626                 o_ptr->dd = 0;
627                 o_ptr->ds = 0;
628
629                 for (i = 0; i < TR_FLAG_SIZE; i++)
630                         o_ptr->art_flags[i] = 0;
631
632                 /* Curse it */
633                 o_ptr->curse_flags = TRC_CURSED;
634
635                 /* Break it */
636                 o_ptr->ident |= (IDENT_BROKEN);
637                 p_ptr->update |= (PU_BONUS | PU_MANA);
638                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
639         }
640
641         return (TRUE);
642 }
643
644 /*!
645  * @brief 武器呪縛処理 /
646  * Curse the players weapon
647  * @param force 無条件に呪縛を行うならばTRUE
648  * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
649  * @return 実際に呪縛されたらTRUEを返す
650  */
651 bool curse_weapon_object(bool force, object_type *o_ptr)
652 {
653         int i;
654         GAME_TEXT o_name[MAX_NLEN];
655
656         /* Nothing to curse */
657         if (!o_ptr->k_idx) return (FALSE);
658         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
659
660         /* Attempt a saving throw */
661         if (object_is_artifact(o_ptr) && (randint0(100) < 50) && !force)
662         {
663                 /* Cool */
664 #ifdef JP
665                 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!",
666                         "恐怖の暗黒オーラ", "武器", o_name);
667 #else
668                 msg_format("A %s tries to %s, but your %s resists the effects!",
669                         "terrible black aura", "surround your weapon", o_name);
670 #endif
671         }
672
673         /* not artifact or failed save... */
674         else
675         {
676                 if (!force) msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
677                 chg_virtue(V_ENCHANT, -5);
678
679                 /* Shatter the weapon */
680                 o_ptr->name1 = 0;
681                 o_ptr->name2 = EGO_SHATTERED;
682                 o_ptr->to_h = 0 - randint1(5) - randint1(5);
683                 o_ptr->to_d = 0 - randint1(5) - randint1(5);
684                 o_ptr->to_a = 0;
685                 o_ptr->ac = 0;
686                 o_ptr->dd = 0;
687                 o_ptr->ds = 0;
688
689                 for (i = 0; i < TR_FLAG_SIZE; i++)
690                         o_ptr->art_flags[i] = 0;
691
692                 /* Curse it */
693                 o_ptr->curse_flags = TRC_CURSED;
694
695                 /* Break it */
696                 o_ptr->ident |= (IDENT_BROKEN);
697                 p_ptr->update |= (PU_BONUS | PU_MANA);
698                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
699         }
700
701         return (TRUE);
702 }
703
704 /*!
705  * @brief 武器呪縛処理のメインルーチン /
706  * Curse the players weapon
707  * @param force 無条件に呪縛を行うならばTRUE
708  * @param slot 呪縛する武器の装備スロット
709  * @return 実際に呪縛されたらTRUEを返す
710  */
711 bool curse_weapon(bool force, int slot)
712 {
713         return curse_weapon_object(force, &inventory[slot]);
714 }
715
716
717 /*!
718  * @brief 防具の錆止め防止処理
719  * @return ターン消費を要する処理を行ったならばTRUEを返す
720  */
721 bool rustproof(void)
722 {
723         OBJECT_IDX item;
724         object_type *o_ptr;
725         GAME_TEXT o_name[MAX_NLEN];
726         concptr q, s;
727
728         /* Select a piece of armour */
729         item_tester_hook = object_is_armour;
730
731         q = _("どの防具に錆止めをしますか?", "Rustproof which piece of armour? ");
732         s = _("錆止めできるものがありません。", "You have nothing to rustproof.");
733
734         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
735         if (!o_ptr) return FALSE;
736
737         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
738
739         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
740
741         if ((o_ptr->to_a < 0) && !object_is_cursed(o_ptr))
742         {
743 #ifdef JP
744                 msg_format("%sは新品同様になった!", o_name);
745 #else
746                 msg_format("%s %s look%s as good as new!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
747 #endif
748
749                 o_ptr->to_a = 0;
750         }
751
752 #ifdef JP
753         msg_format("%sは腐食しなくなった。", o_name);
754 #else
755         msg_format("%s %s %s now protected against corrosion.", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "are" : "is"));
756 #endif
757
758         calc_android_exp();
759         return TRUE;
760 }
761
762 /*!
763  * @brief ボルトのエゴ化処理(火炎エゴのみ) /
764  * Enchant some bolts
765  * @return 常にTRUEを返す
766  */
767 bool brand_bolts(void)
768 {
769         int i;
770
771         /* Use the first acceptable bolts */
772         for (i = 0; i < INVEN_PACK; i++)
773         {
774                 object_type *o_ptr = &inventory[i];
775
776                 /* Skip non-bolts */
777                 if (o_ptr->tval != TV_BOLT) continue;
778
779                 /* Skip artifacts and ego-items */
780                 if (object_is_artifact(o_ptr) || object_is_ego(o_ptr))
781                         continue;
782
783                 /* Skip cursed/broken items */
784                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) continue;
785
786                 /* Randomize */
787                 if (randint0(100) < 75) continue;
788
789                 msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
790
791                 /* Ego-item */
792                 o_ptr->name2 = EGO_FLAME;
793                 enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
794                 return (TRUE);
795         }
796
797         if (flush_failure) flush();
798
799         /* Fail */
800         msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
801
802         return (TRUE);
803 }
804
805
806 bool perilous_secrets(player_type *creature_ptr)
807 {
808         if (!ident_spell(FALSE)) return FALSE;
809
810         if (mp_ptr->spell_book)
811         {
812                 /* Sufficient mana */
813                 if (20 <= creature_ptr->csp)
814                 {
815                         /* Use some mana */
816                         creature_ptr->csp -= 20;
817                 }
818
819                 /* Over-exert the player */
820                 else
821                 {
822                         int oops = 20 - creature_ptr->csp;
823
824                         /* No mana left */
825                         creature_ptr->csp = 0;
826                         creature_ptr->csp_frac = 0;
827
828                         msg_print(_("石を制御できない!", "You are too weak to control the stone!"));
829                         /* Hack -- Bypass free action */
830                         (void)set_paralyzed(creature_ptr->paralyzed + randint1(5 * oops + 1));
831
832                         /* Confusing. */
833                         (void)set_confused(creature_ptr->confused + randint1(5 * oops + 1));
834                 }
835                 creature_ptr->redraw |= (PR_MANA);
836         }
837         take_hit(DAMAGE_LOSELIFE, damroll(1, 12), _("危険な秘密", "perilous secrets"), -1);
838         /* Confusing. */
839         if (one_in_(5)) (void)set_confused(creature_ptr->confused + randint1(10));
840
841         /* Exercise a little care... */
842         if (one_in_(20)) take_hit(DAMAGE_LOSELIFE, damroll(4, 10), _("危険な秘密", "perilous secrets"), -1);
843         return TRUE;
844
845 }
846
847 /*!
848  * @brief 固定アーティファクト『ブラッディムーン』の特性を変更する。
849  * @details スレイ2d2種、及びone_resistance()による耐性1d2種、pval2種を得る。
850  * @param o_ptr 対象のオブジェクト構造体(ブラッディムーン)のポインタ
851  * @return なし
852  */
853 void get_bloody_moon_flags(object_type *o_ptr)
854 {
855         int dummy, i;
856
857         for (i = 0; i < TR_FLAG_SIZE; i++)
858                 o_ptr->art_flags[i] = a_info[ART_BLOOD].flags[i];
859
860         dummy = randint1(2) + randint1(2);
861         for (i = 0; i < dummy; i++)
862         {
863                 int flag = randint0(26);
864                 if (flag >= 20) add_flag(o_ptr->art_flags, TR_KILL_UNDEAD + flag - 20);
865                 else if (flag == 19) add_flag(o_ptr->art_flags, TR_KILL_ANIMAL);
866                 else if (flag == 18) add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
867                 else add_flag(o_ptr->art_flags, TR_CHAOTIC + flag);
868         }
869
870         dummy = randint1(2);
871         for (i = 0; i < dummy; i++) one_resistance(o_ptr);
872
873         for (i = 0; i < 2; i++)
874         {
875                 int tmp = randint0(11);
876                 if (tmp < A_MAX) add_flag(o_ptr->art_flags, TR_STR + tmp);
877                 else add_flag(o_ptr->art_flags, TR_STEALTH + tmp - 6);
878         }
879 }
880
881 /*!
882  * @brief 寿命つき光源の燃素追加処理 /
883  * Charge a lite (torch or latern)
884  * @return なし
885  */
886 void phlogiston(void)
887 {
888         GAME_TURN max_flog = 0;
889         object_type * o_ptr = &inventory[INVEN_LITE];
890
891         /* It's a lamp */
892         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_LANTERN))
893         {
894                 max_flog = FUEL_LAMP;
895         }
896
897         /* It's a torch */
898         else if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
899         {
900                 max_flog = FUEL_TORCH;
901         }
902
903         /* No torch to refill */
904         else
905         {
906                 msg_print(_("燃素を消費するアイテムを装備していません。", "You are not wielding anything which uses phlogiston."));
907                 return;
908         }
909
910         if (o_ptr->xtra4 >= max_flog)
911         {
912                 msg_print(_("このアイテムにはこれ以上燃素を補充できません。", "No more phlogiston can be put in this item."));
913                 return;
914         }
915
916         /* Refuel */
917         o_ptr->xtra4 += (XTRA16)(max_flog / 2);
918         msg_print(_("照明用アイテムに燃素を補充した。", "You add phlogiston to your light item."));
919
920         if (o_ptr->xtra4 >= max_flog)
921         {
922                 o_ptr->xtra4 = (XTRA16)max_flog;
923                 msg_print(_("照明用アイテムは満タンになった。", "Your light item is full."));
924         }
925
926         p_ptr->update |= (PU_TORCH);
927 }
928
929 /*!
930  * @brief 武器の祝福処理 /
931  * Bless a weapon
932  * @return ターン消費を要する処理を行ったならばTRUEを返す
933  */
934 bool bless_weapon(void)
935 {
936         OBJECT_IDX item;
937         object_type *o_ptr;
938         BIT_FLAGS flgs[TR_FLAG_SIZE];
939         GAME_TEXT o_name[MAX_NLEN];
940         concptr q, s;
941
942         /* Bless only weapons */
943         item_tester_hook = object_is_weapon;
944
945         q = _("どのアイテムを祝福しますか?", "Bless which weapon? ");
946         s = _("祝福できる武器がありません。", "You have weapon to bless.");
947
948         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
949         if (!o_ptr) return FALSE;
950
951         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
952         object_flags(o_ptr, flgs);
953
954         if (object_is_cursed(o_ptr))
955         {
956                 if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint1(100) < 33)) ||
957                         have_flag(flgs, TR_ADD_L_CURSE) ||
958                         have_flag(flgs, TR_ADD_H_CURSE) ||
959                         (o_ptr->curse_flags & TRC_PERMA_CURSE))
960                 {
961 #ifdef JP
962                         msg_format("%sを覆う黒いオーラは祝福を跳ね返した!", o_name);
963 #else
964                         msg_format("The black aura on %s %s disrupts the blessing!", ((item >= 0) ? "your" : "the"), o_name);
965 #endif
966
967                         return TRUE;
968                 }
969
970 #ifdef JP
971                 msg_format("%s から邪悪なオーラが消えた。", o_name);
972 #else
973                 msg_format("A malignant aura leaves %s %s.", ((item >= 0) ? "your" : "the"), o_name);
974 #endif
975
976
977                 o_ptr->curse_flags = 0L;
978
979                 o_ptr->ident |= (IDENT_SENSE);
980                 o_ptr->feeling = FEEL_NONE;
981
982                 /* Recalculate the bonuses */
983                 p_ptr->update |= (PU_BONUS);
984                 p_ptr->window |= (PW_EQUIP);
985         }
986
987         /*
988          * Next, we try to bless it. Artifacts have a 1/3 chance of
989          * being blessed, otherwise, the operation simply disenchants
990          * them, godly power negating the magic. Ok, the explanation
991          * is silly, but otherwise priests would always bless every
992          * artifact weapon they find. Ego weapons and normal weapons
993          * can be blessed automatically.
994          */
995         if (have_flag(flgs, TR_BLESSED))
996         {
997 #ifdef JP
998                 msg_format("%s は既に祝福されている。", o_name);
999 #else
1000                 msg_format("%s %s %s blessed already.",
1001                         ((item >= 0) ? "Your" : "The"), o_name,
1002                         ((o_ptr->number > 1) ? "were" : "was"));
1003 #endif
1004
1005                 return TRUE;
1006         }
1007
1008         if (!(object_is_artifact(o_ptr) || object_is_ego(o_ptr)) || one_in_(3))
1009         {
1010 #ifdef JP
1011                 msg_format("%sは輝いた!", o_name);
1012 #else
1013                 msg_format("%s %s shine%s!",
1014                         ((item >= 0) ? "Your" : "The"), o_name,
1015                         ((o_ptr->number > 1) ? "" : "s"));
1016 #endif
1017
1018                 add_flag(o_ptr->art_flags, TR_BLESSED);
1019                 o_ptr->discount = 99;
1020         }
1021         else
1022         {
1023                 bool dis_happened = FALSE;
1024                 msg_print(_("その武器は祝福を嫌っている!", "The weapon resists your blessing!"));
1025
1026                 /* Disenchant tohit */
1027                 if (o_ptr->to_h > 0)
1028                 {
1029                         o_ptr->to_h--;
1030                         dis_happened = TRUE;
1031                 }
1032
1033                 if ((o_ptr->to_h > 5) && (randint0(100) < 33)) o_ptr->to_h--;
1034
1035                 /* Disenchant todam */
1036                 if (o_ptr->to_d > 0)
1037                 {
1038                         o_ptr->to_d--;
1039                         dis_happened = TRUE;
1040                 }
1041
1042                 if ((o_ptr->to_d > 5) && (randint0(100) < 33)) o_ptr->to_d--;
1043
1044                 /* Disenchant toac */
1045                 if (o_ptr->to_a > 0)
1046                 {
1047                         o_ptr->to_a--;
1048                         dis_happened = TRUE;
1049                 }
1050
1051                 if ((o_ptr->to_a > 5) && (randint0(100) < 33)) o_ptr->to_a--;
1052
1053                 if (dis_happened)
1054                 {
1055                         msg_print(_("周囲が凡庸な雰囲気で満ちた...", "There is a static feeling in the air..."));
1056
1057 #ifdef JP
1058                         msg_format("%s は劣化した!", o_name);
1059 #else
1060                         msg_format("%s %s %s disenchanted!", ((item >= 0) ? "Your" : "The"), o_name,
1061                                 ((o_ptr->number > 1) ? "were" : "was"));
1062 #endif
1063
1064                 }
1065         }
1066
1067         p_ptr->update |= (PU_BONUS);
1068         p_ptr->window |= (PW_EQUIP | PW_PLAYER);
1069         calc_android_exp();
1070
1071         return TRUE;
1072 }
1073
1074
1075 /*!
1076  * @brief 盾磨き処理 /
1077  * pulish shield
1078  * @return ターン消費を要する処理を行ったならばTRUEを返す
1079  */
1080 bool pulish_shield(void)
1081 {
1082         OBJECT_IDX item;
1083         object_type *o_ptr;
1084         BIT_FLAGS flgs[TR_FLAG_SIZE];
1085         GAME_TEXT o_name[MAX_NLEN];
1086         concptr            q, s;
1087
1088         /* Assume enchant weapon */
1089         item_tester_tval = TV_SHIELD;
1090
1091         q = _("どの盾を磨きますか?", "Pulish which weapon? ");
1092         s = _("磨く盾がありません。", "You have weapon to pulish.");
1093
1094         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
1095         if (!o_ptr) return FALSE;
1096
1097         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1098         object_flags(o_ptr, flgs);
1099
1100         if (o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) &&
1101                 !object_is_cursed(o_ptr) && (o_ptr->sval != SV_MIRROR_SHIELD))
1102         {
1103 #ifdef JP
1104                 msg_format("%sは輝いた!", o_name);
1105 #else
1106                 msg_format("%s %s shine%s!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
1107 #endif
1108                 o_ptr->name2 = EGO_REFLECTION;
1109                 enchant(o_ptr, randint0(3) + 4, ENCH_TOAC);
1110
1111                 o_ptr->discount = 99;
1112                 chg_virtue(V_ENCHANT, 2);
1113
1114                 return TRUE;
1115         }
1116         else
1117         {
1118                 if (flush_failure) flush();
1119
1120                 msg_print(_("失敗した。", "Failed."));
1121                 chg_virtue(V_ENCHANT, -2);
1122         }
1123         calc_android_exp();
1124
1125         return FALSE;
1126 }