OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengband/hengband.git] / src / object2.c
1 /*!
2  * @file object2.c
3  * @brief オブジェクトの実装 / Object code, part 2
4  * @date 2014/01/11
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7  *\n
8  * This software may be copied and distributed for educational, research,\n
9  * and not for profit purposes provided that this copyright and statement\n
10  * are included in all such copies.  Other copyrights may also apply.\n
11  * 2014 Deskull rearranged comment for Doxygen.\n
12  */
13
14 #include "angband.h"
15 #include "object-hook.h"
16
17 static void one_sustain(object_type *o_ptr);
18
19
20 static cptr const kaji_tips[5] =
21 {
22 #ifdef JP
23         "現在持っているエッセンスの一覧を表示する。",
24         "アイテムからエッセンスを取り出す。エッセンスを取られたアイテムは全く魔法がかかっていない初期状態に戻る。",
25         "既にエッセンスが付加されたアイテムからエッセンスのみ消し去る。エッセンスは手に入らない。",
26         "アイテムにエッセンスを付加する。既にエッセンスが付加されたアイテムやアーティファクトには付加できない。",
27         "武器や防具を強化したり、攻撃で傷つかないようにしたりする。エッセンスが付加されたアイテムやアーティファクトに対しても使用できる。",
28 #else
29         "Display essences you have.",
30         "Extract essences from an item. The item become non magical.",
31         "Remove added essences from an equipment which was improved before. The removed essence will be ruined.",
32         "Add essences to an item. The improved items or artifacts cannot be reimprove.",
33         "Enchant an equipment or make an equiment element-proofed. The improved items and artifacts can be enchanted too.",
34 #endif
35 };
36
37 /*!
38  * @brief 対象のオブジェクトにランダムな能力維持を一つ付加する。/ Choose one random sustain
39  * @details 重複の抑止はない。
40  * @param o_ptr 対象のオブジェクト構造体ポインタ
41  * @return なし
42  */
43 static void one_sustain(object_type *o_ptr)
44 {
45         switch (randint0(6))
46         {
47         case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
48         case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
49         case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
50         case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
51         case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
52         case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
53         }
54 }
55
56 /*!
57  * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
58  * @param o_idx 削除対象のオブジェクト構造体ポインタ
59  * @return なし
60  */
61 void excise_object_idx(OBJECT_IDX o_idx)
62 {
63         object_type *j_ptr;
64
65         OBJECT_IDX this_o_idx, next_o_idx = 0;
66
67         s16b prev_o_idx = 0;
68
69
70         /* Object */
71         j_ptr = &o_list[o_idx];
72
73         /* Monster */
74         if (j_ptr->held_m_idx)
75         {
76                 monster_type *m_ptr;
77
78                 /* Monster */
79                 m_ptr = &m_list[j_ptr->held_m_idx];
80
81                 /* Scan all objects in the grid */
82                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
83                 {
84                         object_type *o_ptr;
85
86                         /* Acquire object */
87                         o_ptr = &o_list[this_o_idx];
88
89                         /* Acquire next object */
90                         next_o_idx = o_ptr->next_o_idx;
91
92                         if (this_o_idx == o_idx)
93                         {
94                                 /* No previous */
95                                 if (prev_o_idx == 0)
96                                 {
97                                         /* Remove from list */
98                                         m_ptr->hold_o_idx = next_o_idx;
99                                 }
100
101                                 /* Real previous */
102                                 else
103                                 {
104                                         object_type *k_ptr;
105
106                                         /* Previous object */
107                                         k_ptr = &o_list[prev_o_idx];
108
109                                         /* Remove from list */
110                                         k_ptr->next_o_idx = next_o_idx;
111                                 }
112
113                                 /* Forget next pointer */
114                                 o_ptr->next_o_idx = 0;
115
116                                 break;
117                         }
118
119                         /* Save prev_o_idx */
120                         prev_o_idx = this_o_idx;
121                 }
122         }
123
124         /* Dungeon */
125         else
126         {
127                 cave_type *c_ptr;
128
129                 POSITION y = j_ptr->iy;
130                 POSITION x = j_ptr->ix;
131
132                 /* Grid */
133                 c_ptr = &cave[y][x];
134
135                 /* Scan all objects in the grid */
136                 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
137                 {
138                         object_type *o_ptr;
139
140                         /* Acquire object */
141                         o_ptr = &o_list[this_o_idx];
142
143                         /* Acquire next object */
144                         next_o_idx = o_ptr->next_o_idx;
145
146                         if (this_o_idx == o_idx)
147                         {
148                                 /* No previous */
149                                 if (prev_o_idx == 0)
150                                 {
151                                         /* Remove from list */
152                                         c_ptr->o_idx = next_o_idx;
153                                 }
154
155                                 /* Real previous */
156                                 else
157                                 {
158                                         object_type *k_ptr;
159
160                                         /* Previous object */
161                                         k_ptr = &o_list[prev_o_idx];
162
163                                         /* Remove from list */
164                                         k_ptr->next_o_idx = next_o_idx;
165                                 }
166
167                                 /* Forget next pointer */
168                                 o_ptr->next_o_idx = 0;
169
170                                 break;
171                         }
172
173                         /* Save prev_o_idx */
174                         prev_o_idx = this_o_idx;
175                 }
176         }
177 }
178
179 /*!
180  * @brief オブジェクトを削除する /
181  * Delete a dungeon object
182  * @param o_idx 削除対象のオブジェクト構造体ポインタ
183  * @return なし
184  * @details
185  * Handle "stacks" of objects correctly.
186  */
187 void delete_object_idx(OBJECT_IDX o_idx)
188 {
189         object_type *j_ptr;
190
191         /* Excise */
192         excise_object_idx(o_idx);
193
194         /* Object */
195         j_ptr = &o_list[o_idx];
196
197         /* Dungeon floor */
198         if (!(j_ptr->held_m_idx))
199         {
200                 POSITION y, x;
201
202                 /* Location */
203                 y = j_ptr->iy;
204                 x = j_ptr->ix;
205
206                 /* Visual update */
207                 lite_spot(y, x);
208         }
209
210         /* Wipe the object */
211         object_wipe(j_ptr);
212
213         /* Count objects */
214         o_cnt--;
215 }
216
217
218 /*!
219  * @brief フロアにマスに落ちているオブジェクトを全て削除する / Deletes all objects at given location
220  * Delete a dungeon object
221  * @param y 削除したフロアマスのY座標
222  * @param x 削除したフロアマスのX座標
223  * @return なし
224  */
225 void delete_object(POSITION y, POSITION x)
226 {
227         cave_type *c_ptr;
228         OBJECT_IDX this_o_idx, next_o_idx = 0;
229
230         /* Refuse "illegal" locations */
231         if (!in_bounds(y, x)) return;
232
233         /* Grid */
234         c_ptr = &cave[y][x];
235
236         /* Scan all objects in the grid */
237         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
238         {
239                 object_type *o_ptr;
240
241                 /* Acquire object */
242                 o_ptr = &o_list[this_o_idx];
243
244                 /* Acquire next object */
245                 next_o_idx = o_ptr->next_o_idx;
246
247                 /* Wipe the object */
248                 object_wipe(o_ptr);
249
250                 /* Count objects */
251                 o_cnt--;
252         }
253
254         /* Objects are gone */
255         c_ptr->o_idx = 0;
256
257         /* Visual update */
258         lite_spot(y, x);
259 }
260
261
262 /*!
263  * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
264  * Move an object from index i1 to index i2 in the object list
265  * @param i1 整理したい配列の始点
266  * @param i2 整理したい配列の終点
267  * @return なし
268  */
269 static void compact_objects_aux(IDX i1, IDX i2)
270 {
271         IDX i;
272         cave_type *c_ptr;
273         object_type *o_ptr;
274
275         /* Do nothing */
276         if (i1 == i2) return;
277
278
279         /* Repair objects */
280         for (i = 1; i < o_max; i++)
281         {
282                 /* Acquire object */
283                 o_ptr = &o_list[i];
284
285                 /* Skip "dead" objects */
286                 if (!o_ptr->k_idx) continue;
287
288                 /* Repair "next" pointers */
289                 if (o_ptr->next_o_idx == i1)
290                 {
291                         /* Repair */
292                         o_ptr->next_o_idx = i2;
293                 }
294         }
295
296
297         /* Acquire object */
298         o_ptr = &o_list[i1];
299
300
301         /* Monster */
302         if (o_ptr->held_m_idx)
303         {
304                 monster_type *m_ptr;
305
306                 /* Acquire monster */
307                 m_ptr = &m_list[o_ptr->held_m_idx];
308
309                 /* Repair monster */
310                 if (m_ptr->hold_o_idx == i1)
311                 {
312                         /* Repair */
313                         m_ptr->hold_o_idx = i2;
314                 }
315         }
316
317         /* Dungeon */
318         else
319         {
320                 POSITION y, x;
321
322                 /* Acquire location */
323                 y = o_ptr->iy;
324                 x = o_ptr->ix;
325
326                 /* Acquire grid */
327                 c_ptr = &cave[y][x];
328
329                 /* Repair grid */
330                 if (c_ptr->o_idx == i1)
331                 {
332                         /* Repair */
333                         c_ptr->o_idx = i2;
334                 }
335         }
336
337
338         /* Structure copy */
339         o_list[i2] = o_list[i1];
340
341         /* Wipe the hole */
342         object_wipe(o_ptr);
343 }
344
345
346 /*!
347  * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
348  * Compact and Reorder the object list.
349  * @param size 最低でも減らしたいオブジェクト数の水準
350  * @return なし
351  * @details
352  * (危険なので使用には注意すること)
353  * This function can be very dangerous, use with caution!\n
354  *\n
355  * When actually "compacting" objects, we base the saving throw on a\n
356  * combination of object level, distance from player, and current\n
357  * "desperation".\n
358  *\n
359  * After "compacting" (if needed), we "reorder" the objects into a more\n
360  * compact order, and we reset the allocation info, and the "live" array.\n
361  */
362 void compact_objects(int size)
363 {
364         OBJECT_IDX i;
365         POSITION y, x;
366         int num, cnt;
367         int cur_lev, cur_dis, chance;
368         object_type *o_ptr;
369
370
371         /* Compact */
372         if (size)
373         {
374                 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
375
376                 /* Redraw map */
377                 p_ptr->redraw |= (PR_MAP);
378
379                 /* Window stuff */
380                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
381         }
382
383
384         /* Compact at least 'size' objects */
385         for (num = 0, cnt = 1; num < size; cnt++)
386         {
387                 /* Get more vicious each iteration */
388                 cur_lev = 5 * cnt;
389
390                 /* Get closer each iteration */
391                 cur_dis = 5 * (20 - cnt);
392
393                 /* Examine the objects */
394                 for (i = 1; i < o_max; i++)
395                 {
396                         o_ptr = &o_list[i];
397
398                         /* Skip dead objects */
399                         if (!o_ptr->k_idx) continue;
400
401                         /* Hack -- High level objects start out "immune" */
402                         if (k_info[o_ptr->k_idx].level > cur_lev) continue;
403
404                         /* Monster */
405                         if (o_ptr->held_m_idx)
406                         {
407                                 monster_type *m_ptr;
408
409                                 /* Acquire monster */
410                                 m_ptr = &m_list[o_ptr->held_m_idx];
411
412                                 /* Get the location */
413                                 y = m_ptr->fy;
414                                 x = m_ptr->fx;
415
416                                 /* Monsters protect their objects */
417                                 if (randint0(100) < 90) continue;
418                         }
419
420                         /* Dungeon */
421                         else
422                         {
423                                 /* Get the location */
424                                 y = o_ptr->iy;
425                                 x = o_ptr->ix;
426                         }
427
428                         /* Nearby objects start out "immune" */
429                         if ((cur_dis > 0) && (distance(p_ptr->y, p_ptr->x, y, x) < cur_dis)) continue;
430
431                         /* Saving throw */
432                         chance = 90;
433
434                         /* Hack -- only compact artifacts in emergencies */
435                         if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
436                             (cnt < 1000)) chance = 100;
437
438                         /* Apply the saving throw */
439                         if (randint0(100) < chance) continue;
440
441                         /* Delete the object */
442                         delete_object_idx(i);
443
444                         /* Count it */
445                         num++;
446                 }
447         }
448
449
450         /* Excise dead objects (backwards!) */
451         for (i = o_max - 1; i >= 1; i--)
452         {
453                 o_ptr = &o_list[i];
454
455                 /* Skip real objects */
456                 if (o_ptr->k_idx) continue;
457
458                 /* Move last object into open hole */
459                 compact_objects_aux(o_max - 1, i);
460
461                 /* Compress "o_max" */
462                 o_max--;
463         }
464 }
465
466
467 /*!
468  * @brief グローバルオブジェクト配列を初期化する /
469  * Delete all the items when player leaves the level
470  * @note we do NOT visually reflect these (irrelevant) changes
471  * @details
472  * Hack -- we clear the "c_ptr->o_idx" field for every grid,
473  * and the "m_ptr->next_o_idx" field for every monster, since
474  * we know we are clearing every object.  Technically, we only
475  * clear those fields for grids/monsters containing objects,
476  * and we clear it once for every such object.
477  * @return なし
478  */
479 void wipe_o_list(void)
480 {
481         int i;
482
483         /* Delete the existing objects */
484         for (i = 1; i < o_max; i++)
485         {
486                 object_type *o_ptr = &o_list[i];
487
488                 /* Skip dead objects */
489                 if (!o_ptr->k_idx) continue;
490
491                 /* Mega-Hack -- preserve artifacts */
492                 if (!character_dungeon || preserve_mode)
493                 {
494                         /* Hack -- Preserve unknown artifacts */
495                         if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
496                         {
497                                 /* Mega-Hack -- Preserve the artifact */
498                                 a_info[o_ptr->name1].cur_num = 0;
499                         }
500                 }
501
502                 /* Monster */
503                 if (o_ptr->held_m_idx)
504                 {
505                         monster_type *m_ptr;
506
507                         /* Monster */
508                         m_ptr = &m_list[o_ptr->held_m_idx];
509
510                         /* Hack -- see above */
511                         m_ptr->hold_o_idx = 0;
512                 }
513
514                 /* Dungeon */
515                 else
516                 {
517                         cave_type *c_ptr;
518
519                         /* Access location */
520                         POSITION y = o_ptr->iy;
521                         POSITION x = o_ptr->ix;
522
523                         /* Access grid */
524                         c_ptr = &cave[y][x];
525
526                         /* Hack -- see above */
527                         c_ptr->o_idx = 0;
528                 }
529
530                 /* Wipe the object */
531                 object_wipe(o_ptr);
532         }
533
534         /* Reset "o_max" */
535         o_max = 1;
536
537         /* Reset "o_cnt" */
538         o_cnt = 0;
539 }
540
541
542 /*!
543  * @brief グローバルオブジェクト配列から空きを取得する /
544  * Acquires and returns the index of a "free" object.
545  * @return 開いているオブジェクト要素のID
546  * @details
547  * This routine should almost never fail, but in case it does,
548  * we must be sure to handle "failure" of this routine.
549  */
550 OBJECT_IDX o_pop(void)
551 {
552         OBJECT_IDX i;
553
554         /* Initial allocation */
555         if (o_max < max_o_idx)
556         {
557                 /* Get next space */
558                 i = o_max;
559
560                 /* Expand object array */
561                 o_max++;
562
563                 /* Count objects */
564                 o_cnt++;
565
566                 /* Use this object */
567                 return (i);
568         }
569
570
571         /* Recycle dead objects */
572         for (i = 1; i < o_max; i++)
573         {
574                 object_type *o_ptr;
575
576                 /* Acquire object */
577                 o_ptr = &o_list[i];
578
579                 /* Skip live objects */
580                 if (o_ptr->k_idx) continue;
581
582                 /* Count objects */
583                 o_cnt++;
584
585                 /* Use this object */
586                 return (i);
587         }
588
589
590         /* Warn the player (except during dungeon creation) */
591         if (character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
592
593         /* Oops */
594         return (0);
595 }
596
597
598 /*!
599  * @brief オブジェクト生成テーブルに生成制約を加える /
600  * Apply a "object restriction function" to the "object allocation table"
601  * @return 常に0を返す。
602  * @details 生成の制約はグローバルのget_obj_num_hook関数ポインタで加える
603  */
604 static errr get_obj_num_prep(void)
605 {
606         int i;
607
608         /* Get the entry */
609         alloc_entry *table = alloc_kind_table;
610
611         /* Scan the allocation table */
612         for (i = 0; i < alloc_kind_size; i++)
613         {
614                 /* Accept objects which pass the restriction, if any */
615                 if (!get_obj_num_hook || (*get_obj_num_hook)(table[i].index))
616                 {
617                         /* Accept this object */
618                         table[i].prob2 = table[i].prob1;
619                 }
620
621                 /* Do not use this object */
622                 else
623                 {
624                         /* Decline this object */
625                         table[i].prob2 = 0;
626                 }
627         }
628
629         /* Success */
630         return (0);
631 }
632
633
634 /*!
635  * @brief オブジェクト生成テーブルからアイテムを取得する /
636  * Choose an object kind that seems "appropriate" to the given level
637  * @param level 生成階
638  * @return 選ばれたオブジェクトベースID
639  * @details
640  * This function uses the "prob2" field of the "object allocation table",\n
641  * and various local information, to calculate the "prob3" field of the\n
642  * same table, which is then used to choose an "appropriate" object, in\n
643  * a relatively efficient manner.\n
644  *\n
645  * It is (slightly) more likely to acquire an object of the given level\n
646  * than one of a lower level.  This is done by choosing several objects\n
647  * appropriate to the given level and keeping the "hardest" one.\n
648  *\n
649  * Note that if no objects are "appropriate", then this function will\n
650  * fail, and return zero, but this should *almost* never happen.\n
651  */
652 OBJECT_IDX get_obj_num(DEPTH level)
653 {
654         int i, j, p;
655         KIND_OBJECT_IDX k_idx;
656         long value, total;
657         object_kind     *k_ptr;
658         alloc_entry     *table = alloc_kind_table;
659
660         if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
661
662         /* Boost level */
663         if ((level > 0) && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
664         {
665                 /* Occasional "boost" */
666                 if (one_in_(GREAT_OBJ))
667                 {
668                         /* What a bizarre calculation */
669                         level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
670                 }
671         }
672
673         /* Reset total */
674         total = 0L;
675
676         /* Process probabilities */
677         for (i = 0; i < alloc_kind_size; i++)
678         {
679                 /* Objects are sorted by depth */
680                 if (table[i].level > level) break;
681
682                 /* Default */
683                 table[i].prob3 = 0;
684
685                 /* Access the index */
686                 k_idx = table[i].index;
687
688                 /* Access the actual kind */
689                 k_ptr = &k_info[k_idx];
690
691                 /* Hack -- prevent embedded chests */
692                 if (opening_chest && (k_ptr->tval == TV_CHEST)) continue;
693
694                 /* Accept */
695                 table[i].prob3 = table[i].prob2;
696
697                 /* Total */
698                 total += table[i].prob3;
699         }
700
701         /* No legal objects */
702         if (total <= 0) return (0);
703
704
705         /* Pick an object */
706         value = randint0(total);
707
708         /* Find the object */
709         for (i = 0; i < alloc_kind_size; i++)
710         {
711                 /* Found the entry */
712                 if (value < table[i].prob3) break;
713
714                 /* Decrement */
715                 value = value - table[i].prob3;
716         }
717
718
719         /* Power boost */
720         p = randint0(100);
721
722         /* Try for a "better" object once (50%) or twice (10%) */
723         if (p < 60)
724         {
725                 /* Save old */
726                 j = i;
727
728                 /* Pick a object */
729                 value = randint0(total);
730
731                 /* Find the object */
732                 for (i = 0; i < alloc_kind_size; i++)
733                 {
734                         /* Found the entry */
735                         if (value < table[i].prob3) break;
736
737                         /* Decrement */
738                         value = value - table[i].prob3;
739                 }
740
741                 /* Keep the "best" one */
742                 if (table[i].level < table[j].level) i = j;
743         }
744
745         /* Try for a "better" object twice (10%) */
746         if (p < 10)
747         {
748                 /* Save old */
749                 j = i;
750
751                 /* Pick a object */
752                 value = randint0(total);
753
754                 /* Find the object */
755                 for (i = 0; i < alloc_kind_size; i++)
756                 {
757                         /* Found the entry */
758                         if (value < table[i].prob3) break;
759
760                         /* Decrement */
761                         value = value - table[i].prob3;
762                 }
763
764                 /* Keep the "best" one */
765                 if (table[i].level < table[j].level) i = j;
766         }
767
768
769         /* Result */
770         return (table[i].index);
771 }
772
773
774 /*!
775  * @brief オブジェクトを鑑定済にする /
776  * Known is true when the "attributes" of an object are "known".
777  * @param o_ptr 鑑定済にするオブジェクトの構造体参照ポインタ
778  * @return なし
779  * These include tohit, todam, toac, cost, and pval (charges).\n
780  *\n
781  * Note that "knowing" an object gives you everything that an "awareness"\n
782  * gives you, and much more.  In fact, the player is always "aware" of any\n
783  * item of which he has full "knowledge".\n
784  *\n
785  * But having full knowledge of, say, one "wand of wonder", does not, by\n
786  * itself, give you knowledge, or even awareness, of other "wands of wonder".\n
787  * It happens that most "identify" routines (including "buying from a shop")\n
788  * will make the player "aware" of the object as well as fully "know" it.\n
789  *\n
790  * This routine also removes any inscriptions generated by "feelings".\n
791  */
792 void object_known(object_type *o_ptr)
793 {
794         /* Remove "default inscriptions" */
795         o_ptr->feeling = FEEL_NONE;
796
797         /* Clear the "Felt" info */
798         o_ptr->ident &= ~(IDENT_SENSE);
799
800         /* Clear the "Empty" info */
801         o_ptr->ident &= ~(IDENT_EMPTY);
802
803         /* Now we know about the item */
804         o_ptr->ident |= (IDENT_KNOWN);
805 }
806
807 /*!
808  * @brief オブジェクトを*鑑定*済にする /
809  * The player is now aware of the effects of the given object.
810  * @param o_ptr *鑑定*済にするオブジェクトの構造体参照ポインタ
811  * @return なし
812  */
813 void object_aware(object_type *o_ptr)
814 {
815         bool mihanmei = !object_is_aware(o_ptr);
816
817         /* Fully aware of the effects */
818         k_info[o_ptr->k_idx].aware = TRUE;
819
820         if(mihanmei && !(k_info[o_ptr->k_idx].gen_flags & TRG_INSTA_ART) && record_ident &&
821            !p_ptr->is_dead && ((o_ptr->tval >= TV_AMULET && o_ptr->tval <= TV_POTION) || (o_ptr->tval == TV_FOOD)))
822         {
823                 object_type forge;
824                 object_type *q_ptr;
825                 char o_name[MAX_NLEN];
826
827                 q_ptr = &forge;
828                 object_copy(q_ptr, o_ptr);
829
830                 q_ptr->number = 1;
831                 object_desc(o_name, q_ptr, OD_NAME_ONLY);
832                 
833                 do_cmd_write_nikki(NIKKI_HANMEI, 0, o_name);
834         }
835 }
836
837 /*!
838  * @brief オブジェクトを試行済にする /
839  * Something has been "sampled"
840  * @param o_ptr 試行済にするオブジェクトの構造体参照ポインタ
841  * @return なし
842  */
843 void object_tried(object_type *o_ptr)
844 {
845         /* Mark it as tried (even if "aware") */
846         k_info[o_ptr->k_idx].tried = TRUE;
847 }
848
849 /*!
850 * @brief 重度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item.  Method 1 (Heavy).
851 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
852 * @return 擬似鑑定結果のIDを返す。
853 */
854 byte value_check_aux1(object_type *o_ptr)
855 {
856         /* Artifacts */
857         if (object_is_artifact(o_ptr))
858         {
859                 /* Cursed/Broken */
860                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_TERRIBLE;
861
862                 /* Normal */
863                 return FEEL_SPECIAL;
864         }
865
866         /* Ego-Items */
867         if (object_is_ego(o_ptr))
868         {
869                 /* Cursed/Broken */
870                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_WORTHLESS;
871
872                 /* Normal */
873                 return FEEL_EXCELLENT;
874         }
875
876         /* Cursed items */
877         if (object_is_cursed(o_ptr)) return FEEL_CURSED;
878
879         /* Broken items */
880         if (object_is_broken(o_ptr)) return FEEL_BROKEN;
881
882         if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
883
884         /* Good "armor" bonus */
885         if (o_ptr->to_a > 0) return FEEL_GOOD;
886
887         /* Good "weapon" bonus */
888         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
889
890         /* Default to "average" */
891         return FEEL_AVERAGE;
892 }
893
894 /*!
895 * @brief 軽度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item.  Method 2 (Light).
896 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
897 * @return 擬似鑑定結果のIDを返す。
898 */
899 byte value_check_aux2(object_type *o_ptr)
900 {
901         /* Cursed items (all of them) */
902         if (object_is_cursed(o_ptr)) return FEEL_CURSED;
903
904         /* Broken items (all of them) */
905         if (object_is_broken(o_ptr)) return FEEL_BROKEN;
906
907         /* Artifacts -- except cursed/broken ones */
908         if (object_is_artifact(o_ptr)) return FEEL_UNCURSED;
909
910         /* Ego-Items -- except cursed/broken ones */
911         if (object_is_ego(o_ptr)) return FEEL_UNCURSED;
912
913         /* Good armor bonus */
914         if (o_ptr->to_a > 0) return FEEL_UNCURSED;
915
916         /* Good weapon bonuses */
917         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
918
919         /* No feeling */
920         return FEEL_NONE;
921 }
922
923 /*!
924  * @brief 未鑑定なベースアイテムの基本価格を返す /
925  * Return the "value" of an "unknown" item Make a guess at the value of non-aware items
926  * @param o_ptr 未鑑定価格を確認したいオブジェクトの構造体参照ポインタ
927  * @return オブジェクトの未鑑定価格
928  */
929 static s32b object_value_base(object_type *o_ptr)
930 {
931         /* Aware item -- use template cost */
932         if (object_is_aware(o_ptr)) return (k_info[o_ptr->k_idx].cost);
933
934         /* Analyze the type */
935         switch (o_ptr->tval)
936         {
937
938                 /* Un-aware Food */
939                 case TV_FOOD: return (5L);
940
941                 /* Un-aware Potions */
942                 case TV_POTION: return (20L);
943
944                 /* Un-aware Scrolls */
945                 case TV_SCROLL: return (20L);
946
947                 /* Un-aware Staffs */
948                 case TV_STAFF: return (70L);
949
950                 /* Un-aware Wands */
951                 case TV_WAND: return (50L);
952
953                 /* Un-aware Rods */
954                 case TV_ROD: return (90L);
955
956                 /* Un-aware Rings */
957                 case TV_RING: return (45L);
958
959                 /* Un-aware Amulets */
960                 case TV_AMULET: return (45L);
961
962                 /* Figurines, relative to monster level */
963                 case TV_FIGURINE:
964                 {
965                         DEPTH level = r_info[o_ptr->pval].level;
966                         if (level < 20) return level*50L;
967                         else if (level < 30) return 1000+(level-20)*150L;
968                         else if (level < 40) return 2500+(level-30)*350L;
969                         else if (level < 50) return 6000+(level-40)*800L;
970                         else return 14000+(level-50)*2000L;
971                 }
972
973                 case TV_CAPTURE:
974                         if (!o_ptr->pval) return 1000L;
975                         else return ((r_info[o_ptr->pval].level) * 50L + 1000);
976         }
977
978         /* Paranoia -- Oops */
979         return (0L);
980 }
981
982
983 /*!
984  * @brief オブジェクトのフラグ類から価格を算出する /
985  * Return the value of the flags the object has...
986  * @param o_ptr フラグ価格を確認したいオブジェクトの構造体参照ポインタ
987  * @param plusses フラグに与える価格の基本重み
988  * @return オブジェクトのフラグ価格
989  */
990 s32b flag_cost(object_type *o_ptr, int plusses)
991 {
992         s32b total = 0;
993         BIT_FLAGS flgs[TR_FLAG_SIZE];
994         s32b tmp_cost;
995         int count;
996         int i;
997         object_kind *k_ptr = &k_info[o_ptr->k_idx];
998
999         object_flags(o_ptr, flgs);
1000
1001         /*
1002          * Exclude fixed flags of the base item.
1003          * pval bonuses of base item will be treated later.
1004          */
1005         for (i = 0; i < TR_FLAG_SIZE; i++)
1006                 flgs[i] &= ~(k_ptr->flags[i]);
1007
1008         /* Exclude fixed flags of the fixed artifact. */
1009         if (object_is_fixed_artifact(o_ptr))
1010         {
1011                 artifact_type *a_ptr = &a_info[o_ptr->name1];
1012
1013                 for (i = 0; i < TR_FLAG_SIZE; i++)
1014                         flgs[i] &= ~(a_ptr->flags[i]);
1015         }
1016
1017         /* Exclude fixed flags of the ego-item. */
1018         else if (object_is_ego(o_ptr))
1019         {
1020                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
1021
1022                 for (i = 0; i < TR_FLAG_SIZE; i++)
1023                         flgs[i] &= ~(e_ptr->flags[i]);
1024         }
1025
1026
1027         /*
1028          * Calucurate values of remaining flags
1029          */
1030         if (have_flag(flgs, TR_STR)) total += (1500 * plusses);
1031         if (have_flag(flgs, TR_INT)) total += (1500 * plusses);
1032         if (have_flag(flgs, TR_WIS)) total += (1500 * plusses);
1033         if (have_flag(flgs, TR_DEX)) total += (1500 * plusses);
1034         if (have_flag(flgs, TR_CON)) total += (1500 * plusses);
1035         if (have_flag(flgs, TR_CHR)) total += (750 * plusses);
1036         if (have_flag(flgs, TR_MAGIC_MASTERY)) total += (600 * plusses);
1037         if (have_flag(flgs, TR_STEALTH)) total += (250 * plusses);
1038         if (have_flag(flgs, TR_SEARCH)) total += (100 * plusses);
1039         if (have_flag(flgs, TR_INFRA)) total += (150 * plusses);
1040         if (have_flag(flgs, TR_TUNNEL)) total += (175 * plusses);
1041         if ((have_flag(flgs, TR_SPEED)) && (plusses > 0))
1042                 total += (10000 + (2500 * plusses));
1043         if ((have_flag(flgs, TR_BLOWS)) && (plusses > 0))
1044                 total += (10000 + (2500 * plusses));
1045
1046         tmp_cost = 0;
1047         count = 0;
1048         if (have_flag(flgs, TR_CHAOTIC)) {total += 5000;count++;}
1049         if (have_flag(flgs, TR_VAMPIRIC)) {total += 6500;count++;}
1050         if (have_flag(flgs, TR_FORCE_WEAPON)) {tmp_cost += 2500;count++;}
1051         if (have_flag(flgs, TR_KILL_ANIMAL)) {tmp_cost += 2800;count++;}
1052         else if (have_flag(flgs, TR_SLAY_ANIMAL)) {tmp_cost += 1800;count++;}
1053         if (have_flag(flgs, TR_KILL_EVIL)) {tmp_cost += 3300;count++;}
1054         else if (have_flag(flgs, TR_SLAY_EVIL)) {tmp_cost += 2300;count++;}
1055         if (have_flag(flgs, TR_KILL_HUMAN)) {tmp_cost += 2800;count++;}
1056         else if (have_flag(flgs, TR_SLAY_HUMAN)) {tmp_cost += 1800;count++;}
1057         if (have_flag(flgs, TR_KILL_UNDEAD)) {tmp_cost += 2800;count++;}
1058         else if (have_flag(flgs, TR_SLAY_UNDEAD)) {tmp_cost += 1800;count++;}
1059         if (have_flag(flgs, TR_KILL_DEMON)) {tmp_cost += 2800;count++;}
1060         else if (have_flag(flgs, TR_SLAY_DEMON)) {tmp_cost += 1800;count++;}
1061         if (have_flag(flgs, TR_KILL_ORC)) {tmp_cost += 2500;count++;}
1062         else if (have_flag(flgs, TR_SLAY_ORC)) {tmp_cost += 1500;count++;}
1063         if (have_flag(flgs, TR_KILL_TROLL)) {tmp_cost += 2800;count++;}
1064         else if (have_flag(flgs, TR_SLAY_TROLL)) {tmp_cost += 1800;count++;}
1065         if (have_flag(flgs, TR_KILL_GIANT)) {tmp_cost += 2800;count++;}
1066         else if (have_flag(flgs, TR_SLAY_GIANT)) {tmp_cost += 1800;count++;}
1067         if (have_flag(flgs, TR_KILL_DRAGON)) {tmp_cost += 2800;count++;}
1068         else if (have_flag(flgs, TR_SLAY_DRAGON)) {tmp_cost += 1800;count++;}
1069
1070         if (have_flag(flgs, TR_VORPAL)) {tmp_cost += 2500;count++;}
1071         if (have_flag(flgs, TR_IMPACT)) {tmp_cost += 2500;count++;}
1072         if (have_flag(flgs, TR_BRAND_POIS)) {tmp_cost += 3800;count++;}
1073         if (have_flag(flgs, TR_BRAND_ACID)) {tmp_cost += 3800;count++;}
1074         if (have_flag(flgs, TR_BRAND_ELEC)) {tmp_cost += 3800;count++;}
1075         if (have_flag(flgs, TR_BRAND_FIRE)) {tmp_cost += 2500;count++;}
1076         if (have_flag(flgs, TR_BRAND_COLD)) {tmp_cost += 2500;count++;}
1077         total += (tmp_cost * count);
1078
1079         if (have_flag(flgs, TR_SUST_STR)) total += 850;
1080         if (have_flag(flgs, TR_SUST_INT)) total += 850;
1081         if (have_flag(flgs, TR_SUST_WIS)) total += 850;
1082         if (have_flag(flgs, TR_SUST_DEX)) total += 850;
1083         if (have_flag(flgs, TR_SUST_CON)) total += 850;
1084         if (have_flag(flgs, TR_SUST_CHR)) total += 250;
1085         if (have_flag(flgs, TR_RIDING)) total += 0;
1086         if (have_flag(flgs, TR_EASY_SPELL)) total += 1500;
1087         if (have_flag(flgs, TR_THROW)) total += 5000;
1088         if (have_flag(flgs, TR_FREE_ACT)) total += 4500;
1089         if (have_flag(flgs, TR_HOLD_EXP)) total += 8500;
1090
1091         tmp_cost = 0;
1092         count = 0;
1093         if (have_flag(flgs, TR_IM_ACID)) {tmp_cost += 15000;count += 2;}
1094         if (have_flag(flgs, TR_IM_ELEC)) {tmp_cost += 15000;count += 2;}
1095         if (have_flag(flgs, TR_IM_FIRE)) {tmp_cost += 15000;count += 2;}
1096         if (have_flag(flgs, TR_IM_COLD)) {tmp_cost += 15000;count += 2;}
1097         if (have_flag(flgs, TR_REFLECT)) {tmp_cost += 5000;count += 2;}
1098         if (have_flag(flgs, TR_RES_ACID)) {tmp_cost += 500;count++;}
1099         if (have_flag(flgs, TR_RES_ELEC)) {tmp_cost += 500;count++;}
1100         if (have_flag(flgs, TR_RES_FIRE)) {tmp_cost += 500;count++;}
1101         if (have_flag(flgs, TR_RES_COLD)) {tmp_cost += 500;count++;}
1102         if (have_flag(flgs, TR_RES_POIS)) {tmp_cost += 1000;count += 2;}
1103         if (have_flag(flgs, TR_RES_FEAR)) {tmp_cost += 1000;count += 2;}
1104         if (have_flag(flgs, TR_RES_LITE)) {tmp_cost += 800;count += 2;}
1105         if (have_flag(flgs, TR_RES_DARK)) {tmp_cost += 800;count += 2;}
1106         if (have_flag(flgs, TR_RES_BLIND)) {tmp_cost += 900;count += 2;}
1107         if (have_flag(flgs, TR_RES_CONF)) {tmp_cost += 900;count += 2;}
1108         if (have_flag(flgs, TR_RES_SOUND)) {tmp_cost += 900;count += 2;}
1109         if (have_flag(flgs, TR_RES_SHARDS)) {tmp_cost += 900;count += 2;}
1110         if (have_flag(flgs, TR_RES_NETHER)) {tmp_cost += 900;count += 2;}
1111         if (have_flag(flgs, TR_RES_NEXUS)) {tmp_cost += 900;count += 2;}
1112         if (have_flag(flgs, TR_RES_CHAOS)) {tmp_cost += 1000;count += 2;}
1113         if (have_flag(flgs, TR_RES_DISEN)) {tmp_cost += 2000;count += 2;}
1114         total += (tmp_cost * count);
1115
1116         if (have_flag(flgs, TR_SH_FIRE)) total += 5000;
1117         if (have_flag(flgs, TR_SH_ELEC)) total += 5000;
1118         if (have_flag(flgs, TR_SH_COLD)) total += 5000;
1119         if (have_flag(flgs, TR_NO_TELE)) total -= 10000;
1120         if (have_flag(flgs, TR_NO_MAGIC)) total += 2500;
1121         if (have_flag(flgs, TR_TY_CURSE)) total -= 15000;
1122         if (have_flag(flgs, TR_HIDE_TYPE)) total += 0;
1123         if (have_flag(flgs, TR_SHOW_MODS)) total += 0;
1124         if (have_flag(flgs, TR_LEVITATION)) total += 1250;
1125         if (have_flag(flgs, TR_LITE_1)) total += 1500;
1126         if (have_flag(flgs, TR_LITE_2)) total += 2500;
1127         if (have_flag(flgs, TR_LITE_3)) total += 4000;
1128         if (have_flag(flgs, TR_LITE_M1)) total -= 1500;
1129         if (have_flag(flgs, TR_LITE_M2)) total -= 2500;
1130         if (have_flag(flgs, TR_LITE_M3)) total -= 4000;
1131         if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
1132         if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
1133         if (have_flag(flgs, TR_ESP_ANIMAL)) total += 1000;
1134         if (have_flag(flgs, TR_ESP_UNDEAD)) total += 1000;
1135         if (have_flag(flgs, TR_ESP_DEMON)) total += 1000;
1136         if (have_flag(flgs, TR_ESP_ORC)) total += 1000;
1137         if (have_flag(flgs, TR_ESP_TROLL)) total += 1000;
1138         if (have_flag(flgs, TR_ESP_GIANT)) total += 1000;
1139         if (have_flag(flgs, TR_ESP_DRAGON)) total += 1000;
1140         if (have_flag(flgs, TR_ESP_HUMAN)) total += 1000;
1141         if (have_flag(flgs, TR_ESP_EVIL)) total += 15000;
1142         if (have_flag(flgs, TR_ESP_GOOD)) total += 2000;
1143         if (have_flag(flgs, TR_ESP_NONLIVING)) total += 2000;
1144         if (have_flag(flgs, TR_ESP_UNIQUE)) total += 10000;
1145         if (have_flag(flgs, TR_SLOW_DIGEST)) total += 750;
1146         if (have_flag(flgs, TR_REGEN)) total += 2500;
1147         if (have_flag(flgs, TR_WARNING)) total += 2000;
1148         if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
1149         if (have_flag(flgs, TR_XTRA_MIGHT)) total += 2250;
1150         if (have_flag(flgs, TR_XTRA_SHOTS)) total += 10000;
1151         if (have_flag(flgs, TR_IGNORE_ACID)) total += 100;
1152         if (have_flag(flgs, TR_IGNORE_ELEC)) total += 100;
1153         if (have_flag(flgs, TR_IGNORE_FIRE)) total += 100;
1154         if (have_flag(flgs, TR_IGNORE_COLD)) total += 100;
1155         if (have_flag(flgs, TR_ACTIVATE)) total += 100;
1156         if (have_flag(flgs, TR_DRAIN_EXP)) total -= 12500;
1157         if (have_flag(flgs, TR_DRAIN_HP)) total -= 12500;
1158         if (have_flag(flgs, TR_DRAIN_MANA)) total -= 12500;
1159         if (have_flag(flgs, TR_CALL_ANIMAL)) total -= 12500;
1160         if (have_flag(flgs, TR_CALL_DEMON)) total -= 10000;
1161         if (have_flag(flgs, TR_CALL_DRAGON)) total -= 10000;
1162         if (have_flag(flgs, TR_CALL_UNDEAD)) total -= 10000;
1163         if (have_flag(flgs, TR_COWARDICE)) total -= 5000;
1164         if (have_flag(flgs, TR_LOW_MELEE)) total -= 5000;
1165         if (have_flag(flgs, TR_LOW_AC)) total -= 5000;
1166         if (have_flag(flgs, TR_LOW_MAGIC)) total -= 15000;
1167         if (have_flag(flgs, TR_FAST_DIGEST)) total -= 10000;
1168         if (have_flag(flgs, TR_SLOW_REGEN)) total -= 10000;
1169         if (have_flag(flgs, TR_TELEPORT))
1170         {
1171                 if (object_is_cursed(o_ptr))
1172                         total -= 7500;
1173                 else
1174                         total += 250;
1175         }
1176         if (have_flag(flgs, TR_AGGRAVATE)) total -= 10000;
1177         if (have_flag(flgs, TR_BLESSED)) total += 750;
1178         if (o_ptr->curse_flags & TR_ADD_L_CURSE) total -= 5000;
1179         if (o_ptr->curse_flags & TR_ADD_H_CURSE) total -= 12500;
1180         if (o_ptr->curse_flags & TRC_CURSED) total -= 5000;
1181         if (o_ptr->curse_flags & TRC_HEAVY_CURSE) total -= 12500;
1182         if (o_ptr->curse_flags & TRC_PERMA_CURSE) total -= 15000;
1183
1184         /* Also, give some extra for activatable powers... */
1185         if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
1186         {
1187                 const activation_type* const act_ptr = find_activation_info(o_ptr);
1188                 if (act_ptr) {
1189                         total += act_ptr->value;
1190                 }
1191         }
1192
1193         return total;
1194 }
1195
1196
1197 /*!
1198  * @brief オブジェクトの真の価格を算出する /
1199  * Return the value of the flags the object has...
1200  * @param o_ptr 本価格を確認したいオブジェクトの構造体参照ポインタ
1201  * @return オブジェクトの本価格
1202  * @details
1203  * Return the "real" price of a "known" item, not including discounts\n
1204  *\n
1205  * Wand and staffs get cost for each charge\n
1206  *\n
1207  * Armor is worth an extra 100 gold per bonus point to armor class.\n
1208  *\n
1209  * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).\n
1210  *\n
1211  * Missiles are only worth 5 gold per bonus point, since they\n
1212  * usually appear in groups of 20, and we want the player to get\n
1213  * the same amount of cash for any "equivalent" item.  Note that\n
1214  * missiles never have any of the "pval" flags, and in fact, they\n
1215  * only have a few of the available flags, primarily of the "slay"\n
1216  * and "brand" and "ignore" variety.\n
1217  *\n
1218  * Armor with a negative armor bonus is worthless.\n
1219  * Weapons with negative hit+damage bonuses are worthless.\n
1220  *\n
1221  * Every wearable item with a "pval" bonus is worth extra (see below).\n
1222  */
1223 PRICE object_value_real(object_type *o_ptr)
1224 {
1225         PRICE value;
1226         BIT_FLAGS flgs[TR_FLAG_SIZE];
1227         object_kind *k_ptr = &k_info[o_ptr->k_idx];
1228
1229
1230         /* Hack -- "worthless" items */
1231         if (!k_info[o_ptr->k_idx].cost) return (0L);
1232
1233         /* Base cost */
1234         value = k_info[o_ptr->k_idx].cost;
1235
1236         /* Extract some flags */
1237         object_flags(o_ptr, flgs);
1238
1239         /* Artifact */
1240         if (object_is_fixed_artifact(o_ptr))
1241         {
1242                 artifact_type *a_ptr = &a_info[o_ptr->name1];
1243
1244                 /* Hack -- "worthless" artifacts */
1245                 if (!a_ptr->cost) return (0L);
1246
1247                 /* Hack -- Use the artifact cost instead */
1248                 value = a_ptr->cost;
1249                 value += flag_cost(o_ptr, o_ptr->pval);
1250
1251                 /* Don't add pval bonuses etc. */
1252                 return (value);
1253         }
1254
1255         /* Ego-Item */
1256         else if (object_is_ego(o_ptr))
1257         {
1258                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
1259
1260                 /* Hack -- "worthless" ego-items */
1261                 if (!e_ptr->cost) return (0L);
1262
1263                 /* Hack -- Reward the ego-item with a bonus */
1264                 value += e_ptr->cost;
1265                 value += flag_cost(o_ptr, o_ptr->pval);
1266         }
1267
1268         else
1269         {
1270                 int i;
1271                 bool flag = FALSE;
1272
1273                 for (i = 0; i < TR_FLAG_SIZE; i++) 
1274                         if (o_ptr->art_flags[i]) flag = TRUE;
1275
1276                 if (flag) value += flag_cost(o_ptr, o_ptr->pval);
1277         }
1278
1279         /* Analyze pval bonus for normal object */
1280         switch (o_ptr->tval)
1281         {
1282         case TV_SHOT:
1283         case TV_ARROW:
1284         case TV_BOLT:
1285         case TV_BOW:
1286         case TV_DIGGING:
1287         case TV_HAFTED:
1288         case TV_POLEARM:
1289         case TV_SWORD:
1290         case TV_BOOTS:
1291         case TV_GLOVES:
1292         case TV_HELM:
1293         case TV_CROWN:
1294         case TV_SHIELD:
1295         case TV_CLOAK:
1296         case TV_SOFT_ARMOR:
1297         case TV_HARD_ARMOR:
1298         case TV_DRAG_ARMOR:
1299         case TV_LITE:
1300         case TV_AMULET:
1301         case TV_RING:
1302                 /* No pval */
1303                 if (!o_ptr->pval) break;
1304
1305                 /* Hack -- Negative "pval" is always bad */
1306                 if (o_ptr->pval < 0) return (0L);
1307
1308                 /* Give credit for stat bonuses */
1309                 if (have_flag(flgs, TR_STR)) value += (o_ptr->pval * 200L);
1310                 if (have_flag(flgs, TR_INT)) value += (o_ptr->pval * 200L);
1311                 if (have_flag(flgs, TR_WIS)) value += (o_ptr->pval * 200L);
1312                 if (have_flag(flgs, TR_DEX)) value += (o_ptr->pval * 200L);
1313                 if (have_flag(flgs, TR_CON)) value += (o_ptr->pval * 200L);
1314                 if (have_flag(flgs, TR_CHR)) value += (o_ptr->pval * 200L);
1315
1316                 /* Give credit for stealth and searching */
1317                 if (have_flag(flgs, TR_MAGIC_MASTERY)) value += (o_ptr->pval * 100);
1318                 if (have_flag(flgs, TR_STEALTH)) value += (o_ptr->pval * 100L);
1319                 if (have_flag(flgs, TR_SEARCH)) value += (o_ptr->pval * 100L);
1320
1321                 /* Give credit for infra-vision and tunneling */
1322                 if (have_flag(flgs, TR_INFRA)) value += (o_ptr->pval * 50L);
1323                 if (have_flag(flgs, TR_TUNNEL)) value += (o_ptr->pval * 50L);
1324
1325                 /* Give credit for extra attacks */
1326                 if (have_flag(flgs, TR_BLOWS)) value += (o_ptr->pval * 5000L);
1327
1328                 /* Give credit for speed bonus */
1329                 if (have_flag(flgs, TR_SPEED)) value += (o_ptr->pval * 10000L);
1330
1331                 break;
1332         }
1333
1334
1335         /* Analyze the item */
1336         switch (o_ptr->tval)
1337         {
1338                 /* Wands/Staffs */
1339                 case TV_WAND:
1340                 {
1341                         /* Pay extra for charges, depending on standard number of
1342                          * charges.  Handle new-style wands correctly. -LM-
1343                          */
1344                         value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
1345
1346                         break;
1347                 }
1348                 case TV_STAFF:
1349                 {
1350                         /* Pay extra for charges, depending on standard number of
1351                          * charges.  -LM-
1352                          */
1353                         value += (value * o_ptr->pval / (k_ptr->pval * 2));
1354
1355                         break;
1356                 }
1357
1358                 /* Rings/Amulets */
1359                 case TV_RING:
1360                 case TV_AMULET:
1361                 {
1362                         /* Hack -- negative bonuses are bad */
1363                         if (o_ptr->to_h + o_ptr->to_d + o_ptr->to_a < 0) return (0L);
1364
1365                         /* Give credit for bonuses */
1366                         value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
1367
1368                         break;
1369                 }
1370
1371                 /* Armor */
1372                 case TV_BOOTS:
1373                 case TV_GLOVES:
1374                 case TV_CLOAK:
1375                 case TV_CROWN:
1376                 case TV_HELM:
1377                 case TV_SHIELD:
1378                 case TV_SOFT_ARMOR:
1379                 case TV_HARD_ARMOR:
1380                 case TV_DRAG_ARMOR:
1381                 {
1382                         /* Hack -- negative armor bonus */
1383                         if (o_ptr->to_a < 0) return (0L);
1384
1385                         /* Give credit for bonuses */
1386                         value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
1387
1388                         break;
1389                 }
1390
1391                 /* Bows/Weapons */
1392                 case TV_BOW:
1393                 case TV_DIGGING:
1394                 case TV_HAFTED:
1395                 case TV_SWORD:
1396                 case TV_POLEARM:
1397                 {
1398                         /* Hack -- negative hit/damage bonuses */
1399                         if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1400
1401                         /* Factor in the bonuses */
1402                         value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 100L);
1403
1404                         /* Hack -- Factor in extra damage dice and sides */
1405                         value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
1406                         value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
1407
1408                         break;
1409                 }
1410
1411                 /* Ammo */
1412                 case TV_SHOT:
1413                 case TV_ARROW:
1414                 case TV_BOLT:
1415                 {
1416                         /* Hack -- negative hit/damage bonuses */
1417                         if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1418
1419                         /* Factor in the bonuses */
1420                         value += ((o_ptr->to_h + o_ptr->to_d) * 5L);
1421
1422                         /* Hack -- Factor in extra damage dice and sides */
1423                         value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
1424                         value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
1425
1426                         break;
1427                 }
1428
1429                 /* Figurines, relative to monster level */
1430                 case TV_FIGURINE:
1431                 {
1432                         DEPTH level = r_info[o_ptr->pval].level;
1433                         if (level < 20) value = level*50L;
1434                         else if (level < 30) value = 1000+(level-20)*150L;
1435                         else if (level < 40) value = 2500+(level-30)*350L;
1436                         else if (level < 50) value = 6000+(level-40)*800L;
1437                         else value = 14000+(level-50)*2000L;
1438                         break;
1439                 }
1440
1441                 case TV_CAPTURE:
1442                 {
1443                         if (!o_ptr->pval) value = 1000L;
1444                         else value = ((r_info[o_ptr->pval].level) * 50L + 1000);
1445                         break;
1446                 }
1447
1448                 case TV_CHEST:
1449                 {
1450                         if (!o_ptr->pval) value = 0L;
1451                         break;
1452                 }
1453         }
1454
1455         /* Worthless object */
1456         if (value < 0) return 0L;
1457
1458         /* Return the value */
1459         return (value);
1460 }
1461
1462
1463 /*!
1464  * @brief オブジェクト価格算出のメインルーチン /
1465  * Return the price of an item including plusses (and charges)
1466  * @param o_ptr 判明している現価格を確認したいオブジェクトの構造体参照ポインタ
1467  * @return オブジェクトの判明している現価格
1468  * @details
1469  * This function returns the "value" of the given item (qty one)\n
1470  *\n
1471  * Never notice "unknown" bonuses or properties, including "curses",\n
1472  * since that would give the player information he did not have.\n
1473  *\n
1474  * Note that discounted items stay discounted forever, even if\n
1475  * the discount is "forgotten" by the player via memory loss.\n
1476  */
1477 PRICE object_value(object_type *o_ptr)
1478 {
1479         PRICE value;
1480
1481         /* Unknown items -- acquire a base value */
1482         if (object_is_known(o_ptr))
1483         {
1484                 /* Broken items -- worthless */
1485                 if (object_is_broken(o_ptr)) return (0L);
1486
1487                 /* Cursed items -- worthless */
1488                 if (object_is_cursed(o_ptr)) return (0L);
1489
1490                 /* Real value (see above) */
1491                 value = object_value_real(o_ptr);
1492         }
1493
1494         /* Known items -- acquire the actual value */
1495         else
1496         {
1497                 /* Hack -- Felt broken items */
1498                 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_broken(o_ptr)) return (0L);
1499
1500                 /* Hack -- Felt cursed items */
1501                 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_cursed(o_ptr)) return (0L);
1502
1503                 /* Base value (see above) */
1504                 value = object_value_base(o_ptr);
1505         }
1506
1507
1508         /* Apply discount (if any) */
1509         if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
1510
1511
1512         /* Return the final value */
1513         return (value);
1514 }
1515
1516
1517
1518 /*!
1519  * @brief 破壊可能なアイテムかを返す /
1520  * Determines whether an object can be destroyed, and makes fake inscription.
1521  * @param o_ptr 破壊可能かを確認したいオブジェクトの構造体参照ポインタ
1522  * @return オブジェクトが破壊可能ならばTRUEを返す
1523  */
1524 bool can_player_destroy_object(object_type *o_ptr)
1525 {
1526         /* Artifacts cannot be destroyed */
1527         if (!object_is_artifact(o_ptr)) return TRUE;
1528
1529         /* If object is unidentified, makes fake inscription */
1530         if (!object_is_known(o_ptr))
1531         {
1532                 byte feel = FEEL_SPECIAL;
1533
1534                 /* Hack -- Handle icky artifacts */
1535                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) feel = FEEL_TERRIBLE;
1536
1537                 /* Hack -- inscribe the artifact */
1538                 o_ptr->feeling = feel;
1539
1540                 /* We have "felt" it (again) */
1541                 o_ptr->ident |= (IDENT_SENSE);
1542
1543                 /* Combine the pack */
1544                 p_ptr->notice |= (PN_COMBINE);
1545
1546                 /* Window stuff */
1547                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
1548
1549                 return FALSE;
1550         }
1551
1552         /* Identified artifact -- Nothing to do */
1553         return FALSE;
1554 }
1555
1556
1557 /*!
1558  * @brief 魔法棒やロッドのスロット分割時に使用回数を分配する /
1559  * Distribute charges of rods or wands.
1560  * @param o_ptr 分割元オブジェクトの構造体参照ポインタ source item
1561  * @param q_ptr 分割先オブジェクトの構造体参照ポインタ target item, must be of the same type as o_ptr
1562  * @param amt 分割したい回数量 number of items that are transfered
1563  * @return なし
1564  * @details
1565  * Hack -- If rods or wands are dropped, the total maximum timeout or\n
1566  * charges need to be allocated between the two stacks.  If all the items\n
1567  * are being dropped, it makes for a neater message to leave the original\n
1568  * stack's pval alone. -LM-\n
1569  */
1570 void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
1571 {
1572         if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD))
1573         {
1574                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1575                 if (amt < o_ptr->number) o_ptr->pval -= q_ptr->pval;
1576
1577                 /* Hack -- Rods also need to have their timeouts distributed.  The
1578                  * dropped stack will accept all time remaining to charge up to its
1579                  * maximum.
1580                  */
1581                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
1582                 {
1583                         if (q_ptr->pval > o_ptr->timeout)
1584                                 q_ptr->timeout = o_ptr->timeout;
1585                         else
1586                                 q_ptr->timeout = q_ptr->pval;
1587
1588                         if (amt < o_ptr->number) o_ptr->timeout -= q_ptr->timeout;
1589                 }
1590         }
1591 }
1592
1593 /*!
1594  * @brief 魔法棒やロッドの使用回数を減らす /
1595  * @param o_ptr オブジェクトの構造体参照ポインタ source item
1596  * @param amt 減らしたい回数量 number of items that are transfered
1597  * @return なし
1598  * @details
1599  * Hack -- If rods or wand are destroyed, the total maximum timeout or\n
1600  * charges of the stack needs to be reduced, unless all the items are\n
1601  * being destroyed. -LM-\n
1602  */
1603 void reduce_charges(object_type *o_ptr, int amt)
1604 {
1605         if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD)) &&
1606                 (amt < o_ptr->number))
1607         {
1608                 o_ptr->pval -= o_ptr->pval * amt / o_ptr->number;
1609         }
1610 }
1611
1612 /*
1613  * Determine if an item can "absorb" a second item
1614  *
1615  * See "object_absorb()" for the actual "absorption" code.
1616  *
1617  * If permitted, we allow staffs (if they are known to have equal charges
1618  * and both are either known or confirmed empty) and wands (if both are
1619  * either known or confirmed empty) and rods (in all cases) to combine.
1620  * Staffs will unstack (if necessary) when they are used, but wands and
1621  * rods will only unstack if one is dropped. -LM-
1622  *
1623  * If permitted, we allow weapons/armor to stack, if fully "known".
1624  *
1625  * Missiles will combine if both stacks have the same "known" status.
1626  * This is done to make unidentified stacks of missiles useful.
1627  *
1628  * Food, potions, scrolls, and "easy know" items always stack.
1629  *
1630  * Chests, and activatable items, never stack (for various reasons).
1631  */
1632
1633 /*
1634  * A "stack" of items is limited to less than or equal to 99 items (hard-coded).
1635  */
1636 #define MAX_STACK_SIZE 99
1637
1638
1639 /*!
1640  * @brief 両オブジェクトをスロットに重ね合わせ可能な最大数を返す。
1641  * Determine if an item can partly absorb a second item. Return maximum number of stack.
1642  * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1643  * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1644  * @return 重ね合わせ可能なアイテム数
1645  */
1646 int object_similar_part(object_type *o_ptr, object_type *j_ptr)
1647 {
1648         int i;
1649
1650         /* Default maximum number of stack */
1651         int max_num = MAX_STACK_SIZE;
1652
1653         /* Require identical object types */
1654         if (o_ptr->k_idx != j_ptr->k_idx) return 0;
1655
1656
1657         /* Analyze the items */
1658         switch (o_ptr->tval)
1659         {
1660                 /* Chests and Statues*/
1661                 case TV_CHEST:
1662                 case TV_CARD:
1663                 case TV_CAPTURE:
1664                 {
1665                         /* Never okay */
1666                         return 0;
1667                 }
1668
1669                 case TV_STATUE:
1670                 {
1671                         if ((o_ptr->sval != SV_PHOTO) || (j_ptr->sval != SV_PHOTO)) return 0;
1672                         if (o_ptr->pval != j_ptr->pval) return 0;
1673                         break;
1674                 }
1675
1676                 /* Figurines and Corpses*/
1677                 case TV_FIGURINE:
1678                 case TV_CORPSE:
1679                 {
1680                         /* Same monster */
1681                         if (o_ptr->pval != j_ptr->pval) return 0;
1682
1683                         /* Assume okay */
1684                         break;
1685                 }
1686
1687                 /* Food and Potions and Scrolls */
1688                 case TV_FOOD:
1689                 case TV_POTION:
1690                 case TV_SCROLL:
1691                 {
1692                         /* Assume okay */
1693                         break;
1694                 }
1695
1696                 /* Staffs */
1697                 case TV_STAFF:
1698                 {
1699                         /* Require either knowledge or known empty for both staffs. */
1700                         if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1701                                 !object_is_known(o_ptr)) ||
1702                                 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1703                                 !object_is_known(j_ptr))) return 0;
1704
1705                         /* Require identical charges, since staffs are bulky. */
1706                         if (o_ptr->pval != j_ptr->pval) return 0;
1707
1708                         /* Assume okay */
1709                         break;
1710                 }
1711
1712                 /* Wands */
1713                 case TV_WAND:
1714                 {
1715                         /* Require either knowledge or known empty for both wands. */
1716                         if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1717                                 !object_is_known(o_ptr)) ||
1718                                 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1719                                 !object_is_known(j_ptr))) return 0;
1720
1721                         /* Wand charges combine in O&ZAngband.  */
1722
1723                         /* Assume okay */
1724                         break;
1725                 }
1726
1727                 /* Staffs and Wands and Rods */
1728                 case TV_ROD:
1729                 {
1730                         /* Prevent overflaw of timeout */
1731                         max_num = MIN(max_num, MAX_SHORT / k_info[o_ptr->k_idx].pval);
1732
1733                         /* Assume okay */
1734                         break;
1735                 }
1736
1737                 /* Weapons and Armor */
1738                 case TV_BOW:
1739                 case TV_DIGGING:
1740                 case TV_HAFTED:
1741                 case TV_POLEARM:
1742                 case TV_SWORD:
1743                 case TV_BOOTS:
1744                 case TV_GLOVES:
1745                 case TV_HELM:
1746                 case TV_CROWN:
1747                 case TV_SHIELD:
1748                 case TV_CLOAK:
1749                 case TV_SOFT_ARMOR:
1750                 case TV_HARD_ARMOR:
1751                 case TV_DRAG_ARMOR:
1752
1753                 /* Rings, Amulets, Lites */
1754                 case TV_RING:
1755                 case TV_AMULET:
1756                 case TV_LITE:
1757                 case TV_WHISTLE:
1758                 {
1759                         /* Require full knowledge of both items */
1760                         if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1761
1762                         /* Fall through */
1763                 }
1764
1765                 /* Missiles */
1766                 case TV_BOLT:
1767                 case TV_ARROW:
1768                 case TV_SHOT:
1769                 {
1770                         /* Require identical knowledge of both items */
1771                         if (object_is_known(o_ptr) != object_is_known(j_ptr)) return 0;
1772                         if (o_ptr->feeling != j_ptr->feeling) return 0;
1773
1774                         /* Require identical "bonuses" */
1775                         if (o_ptr->to_h != j_ptr->to_h) return 0;
1776                         if (o_ptr->to_d != j_ptr->to_d) return 0;
1777                         if (o_ptr->to_a != j_ptr->to_a) return 0;
1778
1779                         /* Require identical "pval" code */
1780                         if (o_ptr->pval != j_ptr->pval) return 0;
1781
1782                         /* Artifacts never stack */
1783                         if (object_is_artifact(o_ptr) || object_is_artifact(j_ptr)) return 0;
1784
1785                         /* Require identical "ego-item" names */
1786                         if (o_ptr->name2 != j_ptr->name2) return 0;
1787
1788                         /* Require identical added essence  */
1789                         if (o_ptr->xtra3 != j_ptr->xtra3) return 0;
1790                         if (o_ptr->xtra4 != j_ptr->xtra4) return 0;
1791
1792                         /* Hack -- Never stack "powerful" items */
1793                         if (o_ptr->xtra1 || j_ptr->xtra1) return 0;
1794
1795                         /* Hack -- Never stack recharging items */
1796                         if (o_ptr->timeout || j_ptr->timeout) return 0;
1797
1798                         /* Require identical "values" */
1799                         if (o_ptr->ac != j_ptr->ac) return 0;
1800                         if (o_ptr->dd != j_ptr->dd) return 0;
1801                         if (o_ptr->ds != j_ptr->ds) return 0;
1802
1803                         /* Probably okay */
1804                         break;
1805                 }
1806
1807                 /* Various */
1808                 default:
1809                 {
1810                         /* Require knowledge */
1811                         if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1812
1813                         /* Probably okay */
1814                         break;
1815                 }
1816         }
1817
1818
1819         /* Hack -- Identical art_flags! */
1820         for (i = 0; i < TR_FLAG_SIZE; i++)
1821                 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return 0;
1822
1823         /* Hack -- Require identical "cursed" status */
1824         if (o_ptr->curse_flags != j_ptr->curse_flags) return 0;
1825
1826         /* Hack -- Require identical "broken" status */
1827         if ((o_ptr->ident & (IDENT_BROKEN)) != (j_ptr->ident & (IDENT_BROKEN))) return 0;
1828
1829
1830         /* Hack -- require semi-matching "inscriptions" */
1831         if (o_ptr->inscription && j_ptr->inscription &&
1832             (o_ptr->inscription != j_ptr->inscription))
1833                 return 0;
1834
1835         /* Hack -- normally require matching "inscriptions" */
1836         if (!stack_force_notes && (o_ptr->inscription != j_ptr->inscription)) return 0;
1837
1838         /* Hack -- normally require matching "discounts" */
1839         if (!stack_force_costs && (o_ptr->discount != j_ptr->discount)) return 0;
1840
1841
1842         /* They match, so they must be similar */
1843         return max_num;
1844 }
1845
1846 /*!
1847  * @brief 両オブジェクトをスロットに重ねることができるかどうかを返す。
1848  * Determine if an item can absorb a second item.
1849  * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1850  * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1851  * @return 重ね合わせ可能ならばTRUEを返す。
1852  */
1853 bool object_similar(object_type *o_ptr, object_type *j_ptr)
1854 {
1855         int total = o_ptr->number + j_ptr->number;
1856         int max_num;
1857
1858         /* Are these objects similar? */
1859         max_num = object_similar_part(o_ptr, j_ptr);
1860
1861         /* Return if not similar */
1862         if (!max_num) return FALSE;
1863
1864         /* Maximal "stacking" limit */
1865         if (total > max_num) return (0);
1866
1867
1868         /* They match, so they must be similar */
1869         return (TRUE);
1870 }
1871
1872
1873 /*!
1874  * @brief 両オブジェクトをスロットに重ね合わせる。
1875  * Allow one item to "absorb" another, assuming they are similar
1876  * @param o_ptr 重ね合わせ先のオブジェクトの構造体参照ポインタ
1877  * @param j_ptr 重ね合わせ元のオブジェクトの構造体参照ポインタ
1878  * @return なし
1879  */
1880 void object_absorb(object_type *o_ptr, object_type *j_ptr)
1881 {
1882         int max_num = object_similar_part(o_ptr, j_ptr);
1883         int total = o_ptr->number + j_ptr->number;
1884         int diff = (total > max_num) ? total - max_num : 0;
1885
1886         /* Combine quantity, lose excess items */
1887         o_ptr->number = (total > max_num) ? max_num : total;
1888
1889         /* Hack -- blend "known" status */
1890         if (object_is_known(j_ptr)) object_known(o_ptr);
1891
1892         /* Hack -- clear "storebought" if only one has it */
1893         if (((o_ptr->ident & IDENT_STORE) || (j_ptr->ident & IDENT_STORE)) &&
1894             (!((o_ptr->ident & IDENT_STORE) && (j_ptr->ident & IDENT_STORE))))
1895         {
1896                 if (j_ptr->ident & IDENT_STORE) j_ptr->ident &= 0xEF;
1897                 if (o_ptr->ident & IDENT_STORE) o_ptr->ident &= 0xEF;
1898         }
1899
1900         /* Hack -- blend "mental" status */
1901         if (j_ptr->ident & (IDENT_MENTAL)) o_ptr->ident |= (IDENT_MENTAL);
1902
1903         /* Hack -- blend "inscriptions" */
1904         if (j_ptr->inscription) o_ptr->inscription = j_ptr->inscription;
1905
1906         /* Hack -- blend "feelings" */
1907         if (j_ptr->feeling) o_ptr->feeling = j_ptr->feeling;
1908
1909         /* Hack -- could average discounts XXX XXX XXX */
1910         /* Hack -- save largest discount XXX XXX XXX */
1911         if (o_ptr->discount < j_ptr->discount) o_ptr->discount = j_ptr->discount;
1912
1913         /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1914         if (o_ptr->tval == TV_ROD)
1915         {
1916                 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1917                 o_ptr->timeout += j_ptr->timeout * (j_ptr->number - diff) / j_ptr->number;
1918         }
1919
1920         /* Hack -- if wands are stacking, combine the charges. -LM- */
1921         if (o_ptr->tval == TV_WAND)
1922         {
1923                 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1924         }
1925 }
1926
1927
1928 /*!
1929  * @brief tvalとsvalに対応するベースアイテムのIDを返す。
1930  * Find the index of the object_kind with the given tval and sval
1931  * @param tval 検索したいベースアイテムのtval
1932  * @param sval 検索したいベースアイテムのsval
1933  * @return なし
1934  */
1935 IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
1936 {
1937         IDX k;
1938         int num = 0;
1939         IDX bk = 0;
1940
1941         /* Look for it */
1942         for (k = 1; k < max_k_idx; k++)
1943         {
1944                 object_kind *k_ptr = &k_info[k];
1945
1946                 /* Require correct tval */
1947                 if (k_ptr->tval != tval) continue;
1948
1949                 /* Found a match */
1950                 if (k_ptr->sval == sval) return (k);
1951
1952                 /* Ignore illegal items */
1953                 if (sval != SV_ANY) continue;
1954
1955                 /* Apply the randomizer */
1956                 if (!one_in_(++num)) continue;
1957
1958                 /* Use this value */
1959                 bk = k;
1960         }
1961
1962         /* Return this choice */
1963         if (sval == SV_ANY)
1964         {
1965                 return bk;
1966         }
1967
1968 #if 0
1969         /* Oops */
1970         msg_format(_("アイテムがない (%d,%d)", "No object (%d,%d)"), tval, sval);
1971 #endif
1972
1973
1974         /* Oops */
1975         return (0);
1976 }
1977
1978
1979 /*!
1980  * @brief オブジェクトを初期化する
1981  * Wipe an object clean.
1982  * @param o_ptr 初期化したいオブジェクトの構造体参照ポインタ
1983  * @return なし
1984  */
1985 void object_wipe(object_type *o_ptr)
1986 {
1987         /* Wipe the structure */
1988         (void)WIPE(o_ptr, object_type);
1989 }
1990
1991
1992 /*!
1993  * @brief オブジェクトを複製する
1994  * Wipe an object clean.
1995  * @param o_ptr 複製元のオブジェクトの構造体参照ポインタ
1996  * @param j_ptr 複製先のオブジェクトの構造体参照ポインタ
1997  * @return なし
1998  */
1999 void object_copy(object_type *o_ptr, object_type *j_ptr)
2000 {
2001         /* Copy the structure */
2002         (void)COPY(o_ptr, j_ptr, object_type);
2003 }
2004
2005
2006 /*!
2007  * @brief オブジェクト構造体にベースアイテムを作成する
2008  * Prepare an object based on an object kind.
2009  * @param o_ptr 代入したいオブジェクトの構造体参照ポインタ
2010  * @param k_idx 新たに作成したいベースアイテム情報のID
2011  * @return なし
2012  */
2013 void object_prep(object_type *o_ptr, KIND_OBJECT_IDX k_idx)
2014 {
2015         object_kind *k_ptr = &k_info[k_idx];
2016
2017         /* Clear the record */
2018         object_wipe(o_ptr);
2019
2020         /* Save the kind index */
2021         o_ptr->k_idx = k_idx;
2022
2023         /* Efficiency -- tval/sval */
2024         o_ptr->tval = k_ptr->tval;
2025         o_ptr->sval = k_ptr->sval;
2026
2027         /* Default "pval" */
2028         o_ptr->pval = k_ptr->pval;
2029
2030         /* Default number */
2031         o_ptr->number = 1;
2032
2033         /* Default weight */
2034         o_ptr->weight = k_ptr->weight;
2035
2036         /* Default magic */
2037         o_ptr->to_h = k_ptr->to_h;
2038         o_ptr->to_d = k_ptr->to_d;
2039         o_ptr->to_a = k_ptr->to_a;
2040
2041         /* Default power */
2042         o_ptr->ac = k_ptr->ac;
2043         o_ptr->dd = k_ptr->dd;
2044         o_ptr->ds = k_ptr->ds;
2045
2046         /* Default activation */
2047         if (k_ptr->act_idx > 0) o_ptr->xtra2 = (XTRA8)k_ptr->act_idx;
2048
2049         /* Hack -- worthless items are always "broken" */
2050         if (k_info[o_ptr->k_idx].cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
2051
2052         /* Hack -- cursed items are always "cursed" */
2053         if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
2054         if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2055         if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
2056         if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
2057         if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
2058         if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
2059 }
2060
2061
2062 /*!
2063  * @brief 上質以上のオブジェクトに与えるための各種ボーナスを正規乱数も加えて算出する。
2064  * Help determine an "enchantment bonus" for an object.
2065  * @param max ボーナス値の限度
2066  * @param level ボーナス値に加味する基準生成階
2067  * @return 算出されたボーナス値
2068  * @details
2069  * To avoid floating point but still provide a smooth distribution of bonuses,\n
2070  * we simply round the results of division in such a way as to "average" the\n
2071  * correct floating point value.\n
2072  *\n
2073  * This function has been changed.  It uses "randnor()" to choose values from\n
2074  * a normal distribution, whose mean moves from zero towards the max as the\n
2075  * level increases, and whose standard deviation is equal to 1/4 of the max,\n
2076  * and whose values are forced to lie between zero and the max, inclusive.\n
2077  *\n
2078  * Since the "level" rarely passes 100 before Morgoth is dead, it is very\n
2079  * rare to get the "full" enchantment on an object, even a deep levels.\n
2080  *\n
2081  * It is always possible (albeit unlikely) to get the "full" enchantment.\n
2082  *\n
2083  * A sample distribution of values from "m_bonus(10, N)" is shown below:\n
2084  *\n
2085  *   N       0     1     2     3     4     5     6     7     8     9    10\n
2086  * ---    ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----\n
2087  *   0   66.37 13.01  9.73  5.47  2.89  1.31  0.72  0.26  0.12  0.09  0.03\n
2088  *   8   46.85 24.66 12.13  8.13  4.20  2.30  1.05  0.36  0.19  0.08  0.05\n
2089  *  16   30.12 27.62 18.52 10.52  6.34  3.52  1.95  0.90  0.31  0.15  0.05\n
2090  *  24   22.44 15.62 30.14 12.92  8.55  5.30  2.39  1.63  0.62  0.28  0.11\n
2091  *  32   16.23 11.43 23.01 22.31 11.19  7.18  4.46  2.13  1.20  0.45  0.41\n
2092  *  40   10.76  8.91 12.80 29.51 16.00  9.69  5.90  3.43  1.47  0.88  0.65\n
2093  *  48    7.28  6.81 10.51 18.27 27.57 11.76  7.85  4.99  2.80  1.22  0.94\n
2094  *  56    4.41  4.73  8.52 11.96 24.94 19.78 11.06  7.18  3.68  1.96  1.78\n
2095  *  64    2.81  3.07  5.65  9.17 13.01 31.57 13.70  9.30  6.04  3.04  2.64\n
2096  *  72    1.87  1.99  3.68  7.15 10.56 20.24 25.78 12.17  7.52  4.42  4.62\n
2097  *  80    1.02  1.23  2.78  4.75  8.37 12.04 27.61 18.07 10.28  6.52  7.33\n
2098  *  88    0.70  0.57  1.56  3.12  6.34 10.06 15.76 30.46 12.58  8.47 10.38\n
2099  *  96    0.27  0.60  1.25  2.28  4.30  7.60 10.77 22.52 22.51 11.37 16.53\n
2100  * 104    0.22  0.42  0.77  1.36  2.62  5.33  8.93 13.05 29.54 15.23 22.53\n
2101  * 112    0.15  0.20  0.56  0.87  2.00  3.83  6.86 10.06 17.89 27.31 30.27\n
2102  * 120    0.03  0.11  0.31  0.46  1.31  2.48  4.60  7.78 11.67 25.53 45.72\n
2103  * 128    0.02  0.01  0.13  0.33  0.83  1.41  3.24  6.17  9.57 14.22 64.07\n
2104  */
2105 int m_bonus(int max, DEPTH level)
2106 {
2107         int bonus, stand, extra, value;
2108
2109
2110         /* Paranoia -- enforce maximal "level" */
2111         if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
2112
2113
2114         /* The "bonus" moves towards the max */
2115         bonus = ((max * level) / MAX_DEPTH);
2116
2117         /* Hack -- determine fraction of error */
2118         extra = ((max * level) % MAX_DEPTH);
2119
2120         /* Hack -- simulate floating point computations */
2121         if (randint0(MAX_DEPTH) < extra) bonus++;
2122
2123
2124         /* The "stand" is equal to one quarter of the max */
2125         stand = (max / 4);
2126
2127         /* Hack -- determine fraction of error */
2128         extra = (max % 4);
2129
2130         /* Hack -- simulate floating point computations */
2131         if (randint0(4) < extra) stand++;
2132
2133
2134         /* Choose an "interesting" value */
2135         value = randnor(bonus, stand);
2136
2137         /* Enforce the minimum value */
2138         if (value < 0) return (0);
2139
2140         /* Enforce the maximum value */
2141         if (value > max) return (max);
2142
2143         /* Result */
2144         return (value);
2145 }
2146
2147
2148 /*!
2149  * @brief デバッグ時にアイテム生成情報をメッセージに出力する / Cheat -- describe a created object for the user
2150  * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ
2151  * @return なし
2152  */
2153 static void object_mention(object_type *o_ptr)
2154 {
2155         char o_name[MAX_NLEN];
2156
2157         object_aware(o_ptr);
2158         object_known(o_ptr);
2159
2160         /* Mark the item as fully known */
2161         o_ptr->ident |= (IDENT_MENTAL);
2162
2163         /* Description */
2164         object_desc(o_name, o_ptr, 0);
2165         msg_format_wizard(CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
2166 }
2167
2168 /*!
2169  * @brief INSTA_ART型の固定アーティファクトの生成を確率に応じて試行する。
2170  * Mega-Hack -- Attempt to create one of the "Special Objects"
2171  * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
2172  * @return 生成に成功したらTRUEを返す。
2173  * @details
2174  * We are only called from "make_object()", and we assume that\n
2175  * "apply_magic()" is called immediately after we return.\n
2176  *\n
2177  * Note -- see "make_artifact()" and "apply_magic()"\n
2178  */
2179 static bool make_artifact_special(object_type *o_ptr)
2180 {
2181         IDX i;
2182         KIND_OBJECT_IDX k_idx = 0;
2183
2184         /*! @note 地上ではキャンセルする / No artifacts in the town */
2185         if (!dun_level) return (FALSE);
2186
2187         /*! @note get_obj_num_hookによる指定がある場合は生成をキャンセルする / Themed object */
2188         if (get_obj_num_hook) return (FALSE);
2189
2190         /*! @note 全固定アーティファクト中からIDの若い順に生成対象とその確率を走査する / Check the artifact list (just the "specials") */
2191         for (i = 0; i < max_a_idx; i++)
2192         {
2193                 artifact_type *a_ptr = &a_info[i];
2194
2195                 /*! @note アーティファクト名が空の不正なデータは除外する / Skip "empty" artifacts */
2196                 if (!a_ptr->name) continue;
2197
2198                 /*! @note 既に生成回数がカウントされたアーティファクト、QUESTITEMと非INSTA_ARTは除外 / Cannot make an artifact twice */
2199                 if (a_ptr->cur_num) continue;
2200                 if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
2201                 if (!(a_ptr->gen_flags & TRG_INSTA_ART)) continue;
2202
2203                 /*! @note アーティファクト生成階が現在に対して足りない場合は高確率で1/(不足階層*2)を満たさないと生成リストに加えられない /
2204                  *  XXX XXX Enforce minimum "depth" (loosely) */
2205                 if (a_ptr->level > object_level)
2206                 {
2207                         /* @note  / Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
2208                         int d = (a_ptr->level - object_level) * 2;
2209                         if (!one_in_(d)) continue;
2210                 }
2211
2212                 /*! @note 1/(レア度)の確率を満たさないと除外される / Artifact "rarity roll" */
2213                 if (!one_in_(a_ptr->rarity)) continue;
2214
2215                 /*! @note INSTA_ART型固定アーティファクトのベースアイテムもチェック対象とする。ベースアイテムの生成階層が足りない場合1/(不足階層*5) を満たさないと除外される。 /
2216                  *  Find the base object. XXX XXX Enforce minimum "object" level (loosely). Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
2217                 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
2218                 if (k_info[k_idx].level > object_level)
2219                 {
2220                         int d = (k_info[k_idx].level - object_level) * 5;
2221                         if (!one_in_(d)) continue;
2222                 }
2223
2224                 /*! @note 前述の条件を満たしたら、後のIDのアーティファクトはチェックせずすぐ確定し生成処理に移す /
2225                  * Assign the template. Mega-Hack -- mark the item as an artifact. Hack: Some artifacts get random extra powers. Success. */
2226                 object_prep(o_ptr, k_idx);
2227
2228                 o_ptr->name1 = i;
2229                 random_artifact_resistance(o_ptr, a_ptr);
2230                 return (TRUE);
2231         }
2232
2233         /*! @note 全INSTA_ART固定アーティファクトを試行しても決まらなかった場合 FALSEを返す / Failure */
2234         return (FALSE);
2235 }
2236
2237
2238 /*!
2239  * @brief 非INSTA_ART型の固定アーティファクトの生成を確率に応じて試行する。
2240  * Mega-Hack -- Attempt to create one of the "Special Objects"
2241  * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
2242  * @return 生成に成功したらTRUEを返す。
2243  * @details
2244  * Attempt to change an object into an artifact\n
2245  * This routine should only be called by "apply_magic()"\n
2246  * Note -- see "make_artifact_special()" and "apply_magic()"\n
2247  */
2248 static bool make_artifact(object_type *o_ptr)
2249 {
2250         IDX i;
2251
2252
2253         /* No artifacts in the town */
2254         if (!dun_level) return (FALSE);
2255
2256         /* Paranoia -- no "plural" artifacts */
2257         if (o_ptr->number != 1) return (FALSE);
2258
2259         /* Check the artifact list (skip the "specials") */
2260         for (i = 0; i < max_a_idx; i++)
2261         {
2262                 artifact_type *a_ptr = &a_info[i];
2263
2264                 /* Skip "empty" items */
2265                 if (!a_ptr->name) continue;
2266
2267                 /* Cannot make an artifact twice */
2268                 if (a_ptr->cur_num) continue;
2269
2270                 if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
2271
2272                 if (a_ptr->gen_flags & TRG_INSTA_ART) continue;
2273
2274                 /* Must have the correct fields */
2275                 if (a_ptr->tval != o_ptr->tval) continue;
2276                 if (a_ptr->sval != o_ptr->sval) continue;
2277
2278                 /* XXX XXX Enforce minimum "depth" (loosely) */
2279                 if (a_ptr->level > dun_level)
2280                 {
2281                         /* Acquire the "out-of-depth factor" */
2282                         int d = (a_ptr->level - dun_level) * 2;
2283
2284                         /* Roll for out-of-depth creation */
2285                         if (!one_in_(d)) continue;
2286                 }
2287
2288                 /* We must make the "rarity roll" */
2289                 if (!one_in_(a_ptr->rarity)) continue;
2290
2291                 /* Hack -- mark the item as an artifact */
2292                 o_ptr->name1 = i;
2293
2294                 /* Hack: Some artifacts get random extra powers */
2295                 random_artifact_resistance(o_ptr, a_ptr);
2296
2297                 /* Success */
2298                 return (TRUE);
2299         }
2300
2301         /* Failure */
2302         return (FALSE);
2303 }
2304
2305
2306 /*!
2307  * @brief アイテムのエゴをレア度の重みに合わせてランダムに選択する
2308  * Choose random ego type
2309  * @param slot 取得したいエゴの装備部位
2310  * @param good TRUEならば通常のエゴ、FALSEならば呪いのエゴが選択対象となる。
2311  * @return 選択されたエゴ情報のID、万一選択できなかった場合はmax_e_idxが返る。
2312  */
2313 static byte get_random_ego(byte slot, bool good)
2314 {
2315         int i, value;
2316         ego_item_type *e_ptr;
2317
2318         long total = 0L;
2319         
2320         for (i = 1; i < max_e_idx; i++)
2321         {
2322                 e_ptr = &e_info[i];
2323                 
2324                 if (e_ptr->slot == slot
2325                     && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
2326                 {
2327                         if (e_ptr->rarity)
2328                                 total += (255 / e_ptr->rarity);
2329                 }
2330         }
2331
2332         value = randint1(total);
2333
2334         for (i = 1; i < max_e_idx; i++)
2335         {
2336                 e_ptr = &e_info[i];
2337                 
2338                 if (e_ptr->slot == slot
2339                     && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
2340                 {
2341                         if (e_ptr->rarity)
2342                                 value -= (255 / e_ptr->rarity);
2343                         if (value <= 0L) break;
2344                 }
2345         }
2346         return (byte)i;
2347 }
2348
2349
2350 /*!
2351  * @brief 武器系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2352  * Apply magic to an item known to be a "weapon"
2353  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2354  * @param level 生成基準階
2355  * @param power 生成ランク
2356  * @return なし
2357  * @details
2358  * Hack -- note special base damage dice boosting\n
2359  * Hack -- note special processing for weapon/digger\n
2360  */
2361 static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
2362 {
2363         HIT_PROB tohit1 = randint1(5) + (HIT_PROB)m_bonus(5, level);
2364         HIT_POINT todam1 = randint1(5) + (HIT_POINT)m_bonus(5, level);
2365
2366         HIT_PROB tohit2 = (HIT_PROB)m_bonus(10, level);
2367         HIT_POINT todam2 = (HIT_POINT)m_bonus(10, level);
2368
2369         if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
2370         {
2371                 tohit2 = (tohit2+1)/2;
2372                 todam2 = (todam2+1)/2;
2373         }
2374
2375         /* Good */
2376         if (power > 0)
2377         {
2378                 /* Enchant */
2379                 o_ptr->to_h += tohit1;
2380                 o_ptr->to_d += todam1;
2381
2382                 /* Very good */
2383                 if (power > 1)
2384                 {
2385                         /* Enchant again */
2386                         o_ptr->to_h += tohit2;
2387                         o_ptr->to_d += todam2;
2388                 }
2389         }
2390
2391         /* Cursed */
2392         else if (power < 0)
2393         {
2394                 /* Penalize */
2395                 o_ptr->to_h -= tohit1;
2396                 o_ptr->to_d -= todam1;
2397
2398                 /* Very cursed */
2399                 if (power < -1)
2400                 {
2401                         /* Penalize again */
2402                         o_ptr->to_h -= tohit2;
2403                         o_ptr->to_d -= todam2;
2404                 }
2405
2406                 /* Cursed (if "bad") */
2407                 if (o_ptr->to_h + o_ptr->to_d < 0) o_ptr->curse_flags |= TRC_CURSED;
2408         }
2409
2410         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)) return;
2411
2412         /* Analyze type */
2413         switch (o_ptr->tval)
2414         {
2415                 case TV_DIGGING:
2416                 {
2417                         /* Very good */
2418                         if (power > 1)
2419                         {
2420                                 if (one_in_(30) || (power > 2)) /* power > 2 is debug only */
2421                                         create_artifact(o_ptr, FALSE);
2422                                 else
2423                                         /* Special Ego-item */
2424                                         o_ptr->name2 = EGO_DIGGING;
2425                         }
2426
2427                         /* Very bad */
2428                         else if (power < -1)
2429                         {
2430                                 /* Hack -- Horrible digging bonus */
2431                                 o_ptr->pval = 0 - (5 + randint1(5));
2432                         }
2433
2434                         /* Bad */
2435                         else if (power < 0)
2436                         {
2437                                 /* Hack -- Reverse digging bonus */
2438                                 o_ptr->pval = 0 - (o_ptr->pval);
2439                         }
2440
2441                         break;
2442                 }
2443
2444
2445                 case TV_HAFTED:
2446                 case TV_POLEARM:
2447                 case TV_SWORD:
2448                 {
2449                         /* Very Good */
2450                         if (power > 1)
2451                         {
2452                                 if (one_in_(40) || (power > 2)) /* power > 2 is debug only */
2453                                 {
2454                                         create_artifact(o_ptr, FALSE);
2455                                         break;
2456                                 }
2457                                 while (1)
2458                                 {
2459                                         /* Roll for an ego-item */
2460                                         o_ptr->name2 = get_random_ego(INVEN_RARM, TRUE);
2461                                         if (o_ptr->name2 == EGO_SHARPNESS && o_ptr->tval != TV_SWORD)
2462                                                 continue;
2463                                         if (o_ptr->name2 == EGO_EARTHQUAKES && o_ptr->tval != TV_HAFTED)
2464                                                 continue;
2465                                         if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2466                                                 continue;
2467                                         break;
2468                                 }
2469
2470                                 switch (o_ptr->name2)
2471                                 {
2472                                 case EGO_HA:
2473                                         if (one_in_(4) && (level > 40))
2474                                                 add_flag(o_ptr->art_flags, TR_BLOWS);
2475                                         break;
2476                                 case EGO_DF:
2477                                         if (one_in_(3))
2478                                                 add_flag(o_ptr->art_flags, TR_RES_POIS);
2479                                         if (one_in_(3))
2480                                                 add_flag(o_ptr->art_flags, TR_WARNING);
2481                                         break;
2482                                 case EGO_KILL_DRAGON:
2483                                         if (one_in_(3))
2484                                                 add_flag(o_ptr->art_flags, TR_RES_POIS);
2485                                         break;
2486                                 case EGO_WEST:
2487                                         if (one_in_(3))
2488                                                 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2489                                         break;
2490                                 case EGO_SLAYING_WEAPON:
2491                                         if (one_in_(3)) /* double damage */
2492                                                 o_ptr->dd *= 2;
2493                                         else
2494                                         {
2495                                                 do
2496                                                 {
2497                                                         o_ptr->dd++;
2498                                                 }
2499                                                 while (one_in_(o_ptr->dd));
2500                                                 
2501                                                 do
2502                                                 {
2503                                                         o_ptr->ds++;
2504                                                 }
2505                                                 while (one_in_(o_ptr->ds));
2506                                         }
2507                                         
2508                                         if (one_in_(5))
2509                                         {
2510                                                 add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2511                                         }
2512                                         if (o_ptr->tval == TV_SWORD && one_in_(3))
2513                                         {
2514                                                 add_flag(o_ptr->art_flags, TR_VORPAL);
2515                                         }
2516                                         break;
2517                                 case EGO_TRUMP:
2518                                         if (one_in_(5))
2519                                                 add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
2520                                         if (one_in_(7))
2521                                                 one_ability(o_ptr);
2522                                         break;
2523                                 case EGO_PATTERN:
2524                                         if (one_in_(3))
2525                                                 add_flag(o_ptr->art_flags, TR_HOLD_EXP);
2526                                         if (one_in_(3))
2527                                                 add_flag(o_ptr->art_flags, TR_DEX);
2528                                         if (one_in_(5))
2529                                                 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2530                                         break;
2531                                 case EGO_SHARPNESS:
2532                                         o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, level) + 1;
2533                                         break;
2534                                 case EGO_EARTHQUAKES:
2535                                         if (one_in_(3) && (level > 60))
2536                                                 add_flag(o_ptr->art_flags, TR_BLOWS);
2537                                         else
2538                                                 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, level);
2539                                         break;
2540                                 case EGO_VAMPIRIC:
2541                                         if (one_in_(5))
2542                                                 add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
2543                                         break;
2544                                 case EGO_DEMON:
2545                                         
2546                                         if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2547                                         one_in_(3) ? 
2548                                                 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2549                                                 one_in_(2) ?
2550                                                         add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2551                                                         add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2552                                                 
2553                                         
2554                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CHAOTIC);
2555                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BLOWS);
2556                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2557                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2558                                         break;
2559                                 }
2560
2561                                 if (!o_ptr->art_name)
2562                                 {
2563                                         /* Hack -- Super-charge the damage dice */
2564                                         while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2565
2566                                         /* Hack -- Lower the damage dice */
2567                                         if (o_ptr->dd > 9) o_ptr->dd = 9;
2568                                 }
2569                         }
2570
2571                         /* Very cursed */
2572                         else if (power < -1)
2573                         {
2574                                 /* Roll for ego-item */
2575                                 if (randint0(MAX_DEPTH) < level)
2576                                 {
2577                                         while(1)
2578                                         {
2579                                                 o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE);
2580                                                 if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2581                                                 {
2582                                                         continue;
2583                                                 }
2584                                                 break;
2585                                         }
2586                                         switch (o_ptr->name2)
2587                                         {
2588                                         case EGO_MORGUL:
2589                                                 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2590                                                 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2591                                         case EGO_WEIRD:
2592                                                 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2593                                                 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_NETHER);
2594                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2595                                                 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2596                                                 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2597                                                 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2598                                         }
2599                                 }
2600                         }
2601
2602                         break;
2603                 }
2604
2605
2606                 case TV_BOW:
2607                 {
2608                         /* Very good */
2609                         if (power > 1)
2610                         {
2611                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2612                                 {
2613                                         create_artifact(o_ptr, FALSE);
2614                                         break;
2615                                 }
2616                                 o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE);
2617                         }
2618
2619                         break;
2620                 }
2621
2622
2623                 case TV_BOLT:
2624                 case TV_ARROW:
2625                 case TV_SHOT:
2626                 {
2627                         /* Very good */
2628                         if (power > 1)
2629                         {
2630                                 if (power > 2) /* power > 2 is debug only */
2631                                 {
2632                                         create_artifact(o_ptr, FALSE);
2633                                         break;
2634                                 }
2635
2636                                 o_ptr->name2 = get_random_ego(INVEN_AMMO, TRUE);
2637
2638                                 switch (o_ptr->name2)
2639                                 {
2640                                 case EGO_SLAYING_BOLT:
2641                                         o_ptr->dd++;
2642                                         break;
2643                                 }
2644
2645                                 /* Hack -- super-charge the damage dice */
2646                                 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2647
2648                                 /* Hack -- restrict the damage dice */
2649                                 if (o_ptr->dd > 9) o_ptr->dd = 9;
2650                         }
2651
2652                         /* Very cursed */
2653                         else if (power < -1)
2654                         {
2655                                 /* Roll for ego-item */
2656                                 if (randint0(MAX_DEPTH) < level)
2657                                 {
2658                                         o_ptr->name2 = get_random_ego(INVEN_AMMO, FALSE);
2659                                 }
2660                         }
2661
2662                         break;
2663                 }
2664         }
2665 }
2666
2667 /*!
2668  * @brief ドラゴン装備にランダムな耐性を与える
2669  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2670  * @return なし
2671  */
2672 static void dragon_resist(object_type * o_ptr)
2673 {
2674         do
2675         {
2676                 if (one_in_(4))
2677                         one_dragon_ele_resistance(o_ptr);
2678                 else
2679                         one_high_resistance(o_ptr);
2680         }
2681         while (one_in_(2));
2682 }
2683
2684 /*!
2685  * @brief オブジェクトにランダムな強いESPを与える
2686  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2687  * @return なし
2688  */
2689 static bool add_esp_strong(object_type *o_ptr)
2690 {
2691         bool nonliv = FALSE;
2692
2693         switch (randint1(3))
2694         {
2695         case 1: add_flag(o_ptr->art_flags, TR_ESP_EVIL); break;
2696         case 2: add_flag(o_ptr->art_flags, TR_TELEPATHY); break;
2697         case 3: add_flag(o_ptr->art_flags, TR_ESP_NONLIVING); nonliv = TRUE; break;
2698         }
2699
2700         return nonliv;
2701 }
2702
2703 /*!
2704  * @brief オブジェクトにランダムな弱いESPを与える
2705  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2706  * @param extra TRUEならばESPの最大付与数が増える(TRUE -> 3+1d6 / FALSE -> 1d3)
2707  * @return なし
2708  */
2709 static void add_esp_weak(object_type *o_ptr, bool extra)
2710 {
2711         int i;
2712         u32b weak_esp_list[] = {
2713                 TR_ESP_ANIMAL,
2714                 TR_ESP_UNDEAD,
2715                 TR_ESP_DEMON,
2716                 TR_ESP_ORC,
2717                 TR_ESP_TROLL,
2718                 TR_ESP_GIANT,
2719                 TR_ESP_DRAGON,
2720                 TR_ESP_HUMAN,
2721                 TR_ESP_GOOD,
2722                 TR_ESP_UNIQUE,
2723         };
2724         const int MAX_ESP_WEAK = sizeof(weak_esp_list) / sizeof(weak_esp_list[0]);
2725         const int add_count = MIN(MAX_ESP_WEAK, (extra) ? (3 + randint1(randint1(6))) : randint1(3));
2726
2727         /* Add unduplicated weak esp flags randomly */
2728         for (i = 0; i < add_count; ++ i)
2729         {
2730                 int choice = rand_range(i, MAX_ESP_WEAK - 1);
2731
2732                 add_flag(o_ptr->art_flags, weak_esp_list[choice]);
2733                 weak_esp_list[choice] = weak_esp_list[i];
2734         }
2735 }
2736
2737
2738 /*!
2739  * @brief 防具系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2740  * Apply magic to an item known to be "armor"
2741  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2742  * @param level 生成基準階
2743  * @param power 生成ランク
2744  * @return なし
2745  * @details
2746  * Hack -- note special processing for crown/helm\n
2747  * Hack -- note special processing for robe of permanence\n
2748  */
2749 static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
2750 {
2751         ARMOUR_CLASS toac1 = (ARMOUR_CLASS)randint1(5) + m_bonus(5, level);
2752         ARMOUR_CLASS toac2 = (ARMOUR_CLASS)m_bonus(10, level);
2753
2754         /* Good */
2755         if (power > 0)
2756         {
2757                 /* Enchant */
2758                 o_ptr->to_a += toac1;
2759
2760                 /* Very good */
2761                 if (power > 1)
2762                 {
2763                         /* Enchant again */
2764                         o_ptr->to_a += toac2;
2765                 }
2766         }
2767
2768         /* Cursed */
2769         else if (power < 0)
2770         {
2771                 /* Penalize */
2772                 o_ptr->to_a -= toac1;
2773
2774                 /* Very cursed */
2775                 if (power < -1)
2776                 {
2777                         /* Penalize again */
2778                         o_ptr->to_a -= toac2;
2779                 }
2780
2781                 /* Cursed (if "bad") */
2782                 if (o_ptr->to_a < 0) o_ptr->curse_flags |= TRC_CURSED;
2783         }
2784
2785
2786         /* Analyze type */
2787         switch (o_ptr->tval)
2788         {
2789                 case TV_DRAG_ARMOR:
2790                 {
2791                         if (one_in_(50) || (power > 2)) /* power > 2 is debug only */
2792                                 create_artifact(o_ptr, FALSE);
2793                         break;
2794                 }
2795
2796                 case TV_HARD_ARMOR:
2797                 case TV_SOFT_ARMOR:
2798                 {
2799                         /* Very good */
2800                         if (power > 1)
2801                         {
2802                                 /* Hack -- Try for "Robes of the Magi" */
2803                                 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
2804                                     (o_ptr->sval == SV_ROBE) &&
2805                                     (randint0(100) < 15))
2806                                 {
2807                                         if (one_in_(5))
2808                                         {
2809                                                 o_ptr->name2 = EGO_YOIYAMI;
2810                                                 o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
2811                                                 o_ptr->sval = SV_YOIYAMI_ROBE;
2812                                                 o_ptr->ac = 0;
2813                                                 o_ptr->to_a = 0;
2814                                         }
2815                                         else
2816                                         {
2817                                                 o_ptr->name2 = EGO_PERMANENCE;
2818                                         }
2819                                         break;
2820                                 }
2821
2822                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2823                                 {
2824                                         create_artifact(o_ptr, FALSE);
2825                                         break;
2826                                 }
2827
2828                                 while (1)
2829                                 {
2830                                         bool okay_flag = TRUE;
2831
2832                                         o_ptr->name2 = get_random_ego(INVEN_BODY, TRUE);
2833
2834                                         switch (o_ptr->name2)
2835                                         {
2836                                                 case EGO_DWARVEN:
2837                                                         if (o_ptr->tval != TV_HARD_ARMOR)
2838                                                         {
2839                                                                 okay_flag = FALSE;
2840                                                         }
2841                                                 break;
2842                                                 case EGO_DRUID:
2843                                                         if (o_ptr->tval != TV_SOFT_ARMOR)
2844                                                         {
2845                                                                 okay_flag = FALSE;
2846                                                         }
2847                                                 break;
2848                                                 default:
2849                                                 break;
2850                                         }
2851
2852                                         if (okay_flag) break;
2853                                 }
2854                                 switch (o_ptr->name2)
2855                                 {
2856                                   case EGO_RESISTANCE:
2857                                         if (one_in_(4))
2858                                                 add_flag(o_ptr->art_flags, TR_RES_POIS);
2859                                                 break;
2860                                   case EGO_DWARVEN:
2861                                         o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2862                                         o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
2863                                         break;
2864                                         
2865                                   case EGO_A_DEMON:
2866                                         if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2867                                         one_in_(3) ? 
2868                                                 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2869                                                 one_in_(2) ?
2870                                                         add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2871                                                         add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2872                                                 
2873                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2874                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2875                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2876                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2877                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2878                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2879                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2880                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2881                                         break;
2882                                   case EGO_A_MORGUL:
2883                                         if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2884                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2885                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2886                                         if (one_in_(6)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2887                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2888                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2889                                         break;
2890                                   default:
2891                                         break;
2892                                 }
2893                         }
2894
2895                         break;
2896                 }
2897
2898                 case TV_SHIELD:
2899                 {
2900
2901                         if (o_ptr->sval == SV_DRAGON_SHIELD)
2902                         {
2903                                 dragon_resist(o_ptr);
2904                                 if (!one_in_(3)) break;
2905                         }
2906
2907                         /* Very good */
2908                         if (power > 1)
2909                         {
2910                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2911                                 {
2912                                         create_artifact(o_ptr, FALSE);
2913                                         break;
2914                                 }
2915                                 
2916                                 while(1)
2917                                 {
2918                                         o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE);
2919                                         if (o_ptr->sval != SV_SMALL_METAL_SHIELD && o_ptr->sval != SV_LARGE_METAL_SHIELD 
2920                                                                 && o_ptr->name2 == EGO_S_DWARVEN)
2921                                         {
2922                                                 continue;
2923                                         }
2924                                         break;
2925                                 }
2926                                 
2927                                 switch (o_ptr->name2)
2928                                 {
2929                                 case EGO_ENDURANCE:
2930                                         if (!one_in_(3)) one_high_resistance(o_ptr);
2931                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_POIS);
2932                                         break;
2933                                 case EGO_REFLECTION:
2934                                         if (o_ptr->sval == SV_MIRROR_SHIELD)
2935                                                 o_ptr->name2 = 0;
2936                                         break;
2937                                         
2938                                 case EGO_S_DWARVEN:
2939                                         o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2940                                         o_ptr->ac = k_info[o_ptr->k_idx].ac + 3;
2941                                         break;
2942                                 }
2943                         }
2944                         break;
2945                 }
2946
2947                 case TV_GLOVES:
2948                 {
2949                         if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
2950                         {
2951                                 dragon_resist(o_ptr);
2952                                 if (!one_in_(3)) break;
2953                         }
2954                         if (power > 1)
2955                         {
2956                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2957                                 {
2958                                         create_artifact(o_ptr, FALSE);
2959                                         break;
2960                                 }
2961                                 o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE);
2962                         }
2963                         
2964                         /* Very cursed */
2965                         else if (power < -1)
2966                         {
2967                                 o_ptr->name2 = get_random_ego(INVEN_HANDS, FALSE);
2968                         }
2969
2970                         break;
2971                 }
2972
2973                 case TV_BOOTS:
2974                 {
2975                         if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
2976                         {
2977                                 dragon_resist(o_ptr);
2978                                 if (!one_in_(3)) break;
2979                         }
2980                         /* Very good */
2981                         if (power > 1)
2982                         {
2983                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2984                                 {
2985                                         create_artifact(o_ptr, FALSE);
2986                                         break;
2987                                 }
2988                                 o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE);
2989
2990                                 switch (o_ptr->name2)
2991                                 {
2992                                 case EGO_SLOW_DESCENT:
2993                                         if (one_in_(2))
2994                                         {
2995                                                 one_high_resistance(o_ptr);
2996                                         }
2997                                         break;
2998                                 }
2999                         }
3000                         /* Very cursed */
3001                         else if (power < -1)
3002                         {
3003                                 o_ptr->name2 = get_random_ego(INVEN_FEET, FALSE);
3004                         }
3005
3006                         break;
3007                 }
3008
3009                 case TV_CROWN:
3010                 {
3011                         /* Very good */
3012                         if (power > 1)
3013                         {
3014                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
3015                                 {
3016                                         create_artifact(o_ptr, FALSE);
3017                                         break;
3018                                 }
3019                                 while (1)
3020                                 {
3021                                         bool ok_flag = TRUE;
3022                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
3023
3024                                         switch (o_ptr->name2)
3025                                         {
3026                                         case EGO_TELEPATHY:
3027                                                 if (add_esp_strong(o_ptr)) add_esp_weak(o_ptr, TRUE);
3028                                                 else add_esp_weak(o_ptr, FALSE);
3029                                                 break;
3030                                         case EGO_MAGI:
3031                                         case EGO_MIGHT:
3032                                         case EGO_REGENERATION:
3033                                         case EGO_LORDLINESS:
3034                                         case EGO_BASILISK:
3035                                                 break;
3036                                         case EGO_SEEING:
3037                                                 if (one_in_(3))
3038                                                 {
3039                                                         if (one_in_(2)) add_esp_strong(o_ptr);
3040                                                         else add_esp_weak(o_ptr, FALSE);
3041                                                 }
3042                                                 break;
3043                                         default:/* not existing crown (wisdom,lite, etc...) */
3044                                                 ok_flag = FALSE;
3045                                         }
3046                                         if (ok_flag)
3047                                                 break; /* while (1) */
3048                                 }
3049                                 break;
3050                         }
3051
3052                         /* Very cursed */
3053                         else if (power < -1)
3054                         {       
3055                                 while (1)
3056                                 {
3057                                         bool ok_flag = TRUE;
3058                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
3059
3060                                         switch (o_ptr->name2)
3061                                         {
3062                                           case EGO_ANCIENT_CURSE:
3063                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
3064                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_TELE);
3065                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
3066                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
3067                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
3068                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
3069                                                 break;
3070                                         }
3071                                         if (ok_flag)
3072                                                 break; /* while (1) */
3073                                 }
3074                         }
3075
3076                         break;
3077                 }
3078
3079                 case TV_HELM:
3080                 {
3081                         if (o_ptr->sval == SV_DRAGON_HELM)
3082                         {
3083                                 dragon_resist(o_ptr);
3084                                 if (!one_in_(3)) break;
3085                         }
3086
3087                         /* Very good */
3088                         if (power > 1)
3089                         {
3090                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
3091                                 {
3092                                         create_artifact(o_ptr, FALSE);
3093                                         break;
3094                                 }
3095                                 while (1)
3096                                 {
3097                                         bool ok_flag = TRUE;
3098                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
3099
3100                                         switch (o_ptr->name2)
3101                                         {
3102                                         case EGO_BRILLIANCE:
3103                                         case EGO_DARK:
3104                                         case EGO_INFRAVISION:
3105                                         case EGO_H_PROTECTION:
3106                                                 break;
3107                                         case EGO_SEEING:
3108                                                 if (one_in_(7))
3109                                                 {
3110                                                         if (one_in_(2)) add_esp_strong(o_ptr);
3111                                                         else add_esp_weak(o_ptr, FALSE);
3112                                                 }
3113                                                 break;
3114                                         case EGO_LITE:
3115                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_1);
3116                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_2);
3117                                                 break;
3118                                         case EGO_H_DEMON:
3119                                                 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
3120                                                 one_in_(3) ? 
3121                                                         add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
3122                                                         one_in_(2) ?
3123                                                                 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
3124                                                                 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
3125                                                 
3126                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
3127                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
3128                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
3129                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
3130                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
3131                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
3132                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
3133                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
3134                                                 break;
3135                                         default:/* not existing helm (Magi, Might, etc...)*/
3136                                                 ok_flag = FALSE;
3137                                         }
3138                                         if (ok_flag)
3139                                                 break; /* while (1) */
3140                                 }
3141                                 break;
3142                         }
3143                         /* Very cursed */
3144                         else if (power < -1)
3145                         {
3146                                 while (1)
3147                                 {
3148                                         bool ok_flag = TRUE;
3149                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
3150
3151                                         switch (o_ptr->name2)
3152                                         {
3153                                           case EGO_ANCIENT_CURSE:
3154                                                 ok_flag = FALSE;
3155                                         }
3156                                         if (ok_flag)
3157                                                 break; /* while (1) */
3158                                 }
3159                         }
3160                         break;
3161                 }
3162
3163                 case TV_CLOAK:
3164                 {
3165                         /* Very good */
3166                         if (power > 1)
3167                         {
3168                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
3169                                 {
3170                                         create_artifact(o_ptr, FALSE);
3171                                         break;
3172                                 }
3173                                 o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE);
3174
3175                                 switch (o_ptr->name2)
3176                                 {
3177                                 case EGO_BAT:
3178                                         o_ptr->to_d -= 6;
3179                                         o_ptr->to_h -= 6;
3180                                         break;
3181                                 case EGO_NAZGUL:
3182                                         o_ptr->to_d -= 3;
3183                                         o_ptr->to_h -= 3;
3184                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_COWARDICE);
3185                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CALL_UNDEAD);
3186                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_SLOW_REGEN);
3187                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
3188                                         break;
3189                                 }
3190
3191                         }
3192
3193                         /* Very cursed */
3194                         else if (power < -1)
3195                         {
3196                                 o_ptr->name2 = get_random_ego(INVEN_OUTER, FALSE);
3197                         }
3198
3199                         break;
3200                 }
3201         }
3202
3203 }
3204
3205
3206 /*!
3207  * @brief 装飾品系オブジェクトに生成ランクごとの強化を与えるサブルーチン
3208  * Apply magic to an item known to be a "ring" or "amulet"
3209  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3210  * @param level 生成基準階
3211  * @param power 生成ランク
3212  * @return なし
3213  * @details
3214  * Hack -- note special "pval boost" code for ring of speed\n
3215  * Hack -- note that some items must be cursed (or blessed)\n
3216  */
3217 static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
3218 {
3219         /* Apply magic (good or bad) according to type */
3220         switch (o_ptr->tval)
3221         {
3222                 case TV_RING:
3223                 {
3224                         /* Analyze */
3225                         switch (o_ptr->sval)
3226                         {
3227                                 case SV_RING_ATTACKS:
3228                                 {
3229                                         /* Stat bonus */
3230                                         o_ptr->pval = (PARAMETER_VALUE)m_bonus(2, level);
3231                                         if (one_in_(15)) o_ptr->pval++;
3232                                         if (o_ptr->pval < 1) o_ptr->pval = 1;
3233
3234                                         /* Cursed */
3235                                         if (power < 0)
3236                                         {
3237                                                 /* Broken */
3238                                                 o_ptr->ident |= (IDENT_BROKEN);
3239
3240                                                 /* Cursed */
3241                                                 o_ptr->curse_flags |= TRC_CURSED;
3242
3243                                                 /* Reverse pval */
3244                                                 o_ptr->pval = 0 - (o_ptr->pval);
3245                                         }
3246
3247                                         break;
3248                                 }
3249
3250                                 case SV_RING_SHOTS:
3251                                 {
3252                                         break;
3253                                 }
3254
3255                                 /* Strength, Constitution, Dexterity, Intelligence */
3256                                 case SV_RING_STR:
3257                                 case SV_RING_CON:
3258                                 case SV_RING_DEX:
3259                                 {
3260                                         /* Stat bonus */
3261                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
3262
3263                                         /* Cursed */
3264                                         if (power < 0)
3265                                         {
3266                                                 /* Broken */
3267                                                 o_ptr->ident |= (IDENT_BROKEN);
3268
3269                                                 /* Cursed */
3270                                                 o_ptr->curse_flags |= TRC_CURSED;
3271
3272                                                 /* Reverse pval */
3273                                                 o_ptr->pval = 0 - (o_ptr->pval);
3274                                         }
3275
3276                                         break;
3277                                 }
3278
3279                                 /* Ring of Speed! */
3280                                 case SV_RING_SPEED:
3281                                 {
3282                                         /* Base speed (1 to 10) */
3283                                         o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
3284
3285                                         /* Super-charge the ring */
3286                                         while (randint0(100) < 50) o_ptr->pval++;
3287
3288                                         /* Cursed Ring */
3289                                         if (power < 0)
3290                                         {
3291                                                 /* Broken */
3292                                                 o_ptr->ident |= (IDENT_BROKEN);
3293
3294                                                 /* Cursed */
3295                                                 o_ptr->curse_flags |= TRC_CURSED;
3296
3297                                                 /* Reverse pval */
3298                                                 o_ptr->pval = 0 - (o_ptr->pval);
3299
3300                                                 break;
3301                                         }
3302
3303                                         break;
3304                                 }
3305
3306                                 case SV_RING_LORDLY:
3307                                 {
3308                                         do
3309                                         {
3310                                                 one_lordly_high_resistance(o_ptr);
3311                                         }
3312                                         while (one_in_(4));
3313
3314                                         /* Bonus to armor class */
3315                                         o_ptr->to_a = 10 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
3316                                 }
3317                                 break;
3318
3319                                 case SV_RING_WARNING:
3320                                 {
3321                                         if (one_in_(3)) one_low_esp(o_ptr);
3322                                         break;
3323                                 }
3324
3325                                 /* Searching */
3326                                 case SV_RING_SEARCHING:
3327                                 {
3328                                         /* Bonus to searching */
3329                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
3330
3331                                         /* Cursed */
3332                                         if (power < 0)
3333                                         {
3334                                                 /* Broken */
3335                                                 o_ptr->ident |= (IDENT_BROKEN);
3336
3337                                                 /* Cursed */
3338                                                 o_ptr->curse_flags |= TRC_CURSED;
3339
3340                                                 /* Reverse pval */
3341                                                 o_ptr->pval = 0 - (o_ptr->pval);
3342                                         }
3343
3344                                         break;
3345                                 }
3346
3347                                 /* Flames, Acid, Ice */
3348                                 case SV_RING_FLAMES:
3349                                 case SV_RING_ACID:
3350                                 case SV_RING_ICE:
3351                                 case SV_RING_ELEC:
3352                                 {
3353                                         /* Bonus to armor class */
3354                                         o_ptr->to_a = 5 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
3355                                         break;
3356                                 }
3357
3358                                 /* Weakness, Stupidity */
3359                                 case SV_RING_WEAKNESS:
3360                                 case SV_RING_STUPIDITY:
3361                                 {
3362                                         /* Broken */
3363                                         o_ptr->ident |= (IDENT_BROKEN);
3364
3365                                         /* Cursed */
3366                                         o_ptr->curse_flags |= TRC_CURSED;
3367
3368                                         /* Penalize */
3369                                         o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
3370                                         if (power > 0) power = 0 - power;
3371
3372                                         break;
3373                                 }
3374
3375                                 /* WOE, Stupidity */
3376                                 case SV_RING_WOE:
3377                                 {
3378                                         /* Broken */
3379                                         o_ptr->ident |= (IDENT_BROKEN);
3380
3381                                         /* Cursed */
3382                                         o_ptr->curse_flags |= TRC_CURSED;
3383
3384                                         /* Penalize */
3385                                         o_ptr->to_a = 0 - (5 + (ARMOUR_CLASS)m_bonus(10, level));
3386                                         o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
3387                                         if (power > 0) power = 0 - power;
3388
3389                                         break;
3390                                 }
3391
3392                                 /* Ring of damage */
3393                                 case SV_RING_DAMAGE:
3394                                 {
3395                                         /* Bonus to damage */
3396                                         o_ptr->to_d = 1 + randint1(5) + (HIT_POINT)m_bonus(16, level);
3397
3398                                         /* Cursed */
3399                                         if (power < 0)
3400                                         {
3401                                                 /* Broken */
3402                                                 o_ptr->ident |= (IDENT_BROKEN);
3403
3404                                                 /* Cursed */
3405                                                 o_ptr->curse_flags |= TRC_CURSED;
3406
3407                                                 /* Reverse bonus */
3408                                                 o_ptr->to_d = 0 - o_ptr->to_d;
3409                                         }
3410
3411                                         break;
3412                                 }
3413
3414                                 /* Ring of Accuracy */
3415                                 case SV_RING_ACCURACY:
3416                                 {
3417                                         /* Bonus to hit */
3418                                         o_ptr->to_h = 1 + randint1(5) + (HIT_PROB)m_bonus(16, level);
3419
3420                                         /* Cursed */
3421                                         if (power < 0)
3422                                         {
3423                                                 /* Broken */
3424                                                 o_ptr->ident |= (IDENT_BROKEN);
3425
3426                                                 /* Cursed */
3427                                                 o_ptr->curse_flags |= TRC_CURSED;
3428
3429                                                 /* Reverse tohit */
3430                                                 o_ptr->to_h = 0 - o_ptr->to_h;
3431                                         }
3432
3433                                         break;
3434                                 }
3435
3436                                 /* Ring of Protection */
3437                                 case SV_RING_PROTECTION:
3438                                 {
3439                                         /* Bonus to armor class */
3440                                         o_ptr->to_a = 5 + randint1(8) + (ARMOUR_CLASS)m_bonus(10, level);
3441
3442                                         /* Cursed */
3443                                         if (power < 0)
3444                                         {
3445                                                 /* Broken */
3446                                                 o_ptr->ident |= (IDENT_BROKEN);
3447
3448                                                 /* Cursed */
3449                                                 o_ptr->curse_flags |= TRC_CURSED;
3450
3451                                                 /* Reverse toac */
3452                                                 o_ptr->to_a = 0 - o_ptr->to_a;
3453                                         }
3454
3455                                         break;
3456                                 }
3457
3458                                 /* Ring of Slaying */
3459                                 case SV_RING_SLAYING:
3460                                 {
3461                                         /* Bonus to damage and to hit */
3462                                         o_ptr->to_d = randint1(5) + (HIT_POINT)m_bonus(12, level);
3463                                         o_ptr->to_h = randint1(5) + (HIT_PROB)m_bonus(12, level);
3464
3465                                         /* Cursed */
3466                                         if (power < 0)
3467                                         {
3468                                                 /* Broken */
3469                                                 o_ptr->ident |= (IDENT_BROKEN);
3470
3471                                                 /* Cursed */
3472                                                 o_ptr->curse_flags |= TRC_CURSED;
3473
3474                                                 /* Reverse bonuses */
3475                                                 o_ptr->to_h = 0 - o_ptr->to_h;
3476                                                 o_ptr->to_d = 0 - o_ptr->to_d;
3477                                         }
3478
3479                                         break;
3480                                 }
3481
3482                                 case SV_RING_MUSCLE:
3483                                 {
3484                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(3, level);
3485                                         if (one_in_(4)) o_ptr->pval++;
3486
3487                                         /* Cursed */
3488                                         if (power < 0)
3489                                         {
3490                                                 /* Broken */
3491                                                 o_ptr->ident |= (IDENT_BROKEN);
3492
3493                                                 /* Cursed */
3494                                                 o_ptr->curse_flags |= TRC_CURSED;
3495
3496                                                 /* Reverse bonuses */
3497                                                 o_ptr->pval = 0 - o_ptr->pval;
3498                                         }
3499
3500                                         break;
3501                                 }
3502                                 case SV_RING_AGGRAVATION:
3503                                 {
3504                                         /* Broken */
3505                                         o_ptr->ident |= (IDENT_BROKEN);
3506
3507                                         /* Cursed */
3508                                         o_ptr->curse_flags |= TRC_CURSED;
3509
3510                                         if (power > 0) power = 0 - power;
3511                                         break;
3512                                 }
3513                         }
3514                         if ((one_in_(400) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3515                             || (power > 2)) /* power > 2 is debug only */
3516                         {
3517                                 o_ptr->pval = MIN(o_ptr->pval, 4);
3518                                 /* Randart amulet */
3519                                 create_artifact(o_ptr, FALSE);
3520                         }
3521                         else if ((power == 2) && one_in_(2))
3522                         {
3523                                 while(!o_ptr->name2)
3524                                 {
3525                                         int tmp = m_bonus(10, level);
3526                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3527                                         switch(randint1(28))
3528                                         {
3529                                         case 1: case 2:
3530                                                 o_ptr->name2 = EGO_RING_THROW;
3531                                                 break;
3532                                         case 3: case 4:
3533                                                 if (have_flag(k_ptr->flags, TR_REGEN)) break;
3534                                                 o_ptr->name2 = EGO_RING_REGEN;
3535                                                 break;
3536                                         case 5: case 6:
3537                                                 if (have_flag(k_ptr->flags, TR_LITE_1)) break;
3538                                                 o_ptr->name2 = EGO_RING_LITE;
3539                                                 break;
3540                                         case 7: case 8:
3541                                                 if (have_flag(k_ptr->flags, TR_TELEPORT)) break;
3542                                                 o_ptr->name2 = EGO_RING_TELEPORT;
3543                                                 break;
3544                                         case 9: case 10:
3545                                                 if (o_ptr->to_h) break;
3546                                                 o_ptr->name2 = EGO_RING_TO_H;
3547                                                 break;
3548                                         case 11: case 12:
3549                                                 if (o_ptr->to_d) break;
3550                                                 o_ptr->name2 = EGO_RING_TO_D;
3551                                                 break;
3552                                         case 13:
3553                                                 if ((o_ptr->to_h) || (o_ptr->to_d)) break;
3554                                                 o_ptr->name2 = EGO_RING_SLAY;
3555                                                 break;
3556                                         case 14:
3557                                                 if ((have_flag(k_ptr->flags, TR_STR)) || o_ptr->to_h || o_ptr->to_d) break;
3558                                                 o_ptr->name2 = EGO_RING_WIZARD;
3559                                                 break;
3560                                         case 15:
3561                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3562                                                 o_ptr->name2 = EGO_RING_HERO;
3563                                                 break;
3564                                         case 16:
3565                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3566                                                 if (tmp > 8) o_ptr->name2 = EGO_RING_MANA_BALL;
3567                                                 else if (tmp > 4) o_ptr->name2 = EGO_RING_MANA_BOLT;
3568                                                 else o_ptr->name2 = EGO_RING_MAGIC_MIS;
3569                                                 break;
3570                                         case 17:
3571                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3572                                                 if (!(have_flag(k_ptr->flags, TR_RES_FIRE)) && (have_flag(k_ptr->flags, TR_RES_COLD) || have_flag(k_ptr->flags, TR_RES_ELEC) || have_flag(k_ptr->flags, TR_RES_ACID))) break;
3573                                                 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_F;
3574                                                 else if (tmp > 3) o_ptr->name2 = EGO_RING_FIRE_BALL;
3575                                                 else o_ptr->name2 = EGO_RING_FIRE_BOLT;
3576                                                 break;
3577                                         case 18:
3578                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3579                                                 if (!(have_flag(k_ptr->flags, TR_RES_COLD)) && (have_flag(k_ptr->flags, TR_RES_FIRE) || have_flag(k_ptr->flags, TR_RES_ELEC) || have_flag(k_ptr->flags, TR_RES_ACID))) break;
3580                                                 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_C;
3581                                                 else if (tmp > 3) o_ptr->name2 = EGO_RING_COLD_BALL;
3582                                                 else o_ptr->name2 = EGO_RING_COLD_BOLT;
3583                                                 break;
3584                                         case 19:
3585                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3586                                                 if (!(have_flag(k_ptr->flags, TR_RES_ELEC)) && (have_flag(k_ptr->flags, TR_RES_COLD) || have_flag(k_ptr->flags, TR_RES_FIRE) || have_flag(k_ptr->flags, TR_RES_ACID))) break;
3587                                                 if (tmp > 4) o_ptr->name2 = EGO_RING_ELEC_BALL;
3588                                                 else o_ptr->name2 = EGO_RING_ELEC_BOLT;
3589                                                 break;
3590                                         case 20:
3591                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3592                                                 if (!(have_flag(k_ptr->flags, TR_RES_ACID)) && (have_flag(k_ptr->flags, TR_RES_COLD) || have_flag(k_ptr->flags, TR_RES_ELEC) || have_flag(k_ptr->flags, TR_RES_FIRE))) break;
3593                                                 if (tmp > 4) o_ptr->name2 = EGO_RING_ACID_BALL;
3594                                                 else o_ptr->name2 = EGO_RING_ACID_BOLT;
3595                                                 break;
3596                                         case 21: case 22: case 23: case 24: case 25: case 26:
3597                                                 switch (o_ptr->sval)
3598                                                 {
3599                                                 case SV_RING_SPEED:
3600                                                         if (!one_in_(3)) break;
3601                                                         o_ptr->name2 = EGO_RING_D_SPEED;
3602                                                         break;
3603                                                 case SV_RING_DAMAGE:
3604                                                 case SV_RING_ACCURACY:
3605                                                 case SV_RING_SLAYING:
3606                                                         if (one_in_(2)) break;
3607                                                         if (one_in_(2)) o_ptr->name2 = EGO_RING_HERO;
3608                                                         else
3609                                                         {
3610                                                                 o_ptr->name2 = EGO_RING_BERSERKER;
3611                                                                 o_ptr->to_h -= 2+randint1(4);
3612                                                                 o_ptr->to_d += 2+randint1(4);
3613                                                         }
3614                                                         break;
3615                                                 case SV_RING_PROTECTION:
3616                                                         o_ptr->name2 = EGO_RING_SUPER_AC;
3617                                                         o_ptr->to_a += 7 + m_bonus(5, level);
3618                                                         break;
3619                                                 case SV_RING_RES_FEAR:
3620                                                         o_ptr->name2 = EGO_RING_HERO;
3621                                                         break;
3622                                                 case SV_RING_SHOTS:
3623                                                         if (one_in_(2)) break;
3624                                                         o_ptr->name2 = EGO_RING_HUNTER;
3625                                                         break;
3626                                                 case SV_RING_SEARCHING:
3627                                                         o_ptr->name2 = EGO_RING_STEALTH;
3628                                                         break;
3629                                                 case SV_RING_TELEPORTATION:
3630                                                         o_ptr->name2 = EGO_RING_TELE_AWAY;
3631                                                         break;
3632                                                 case SV_RING_RES_BLINDNESS:
3633                                                         if (one_in_(2))
3634                                                                 o_ptr->name2 = EGO_RING_RES_LITE;
3635                                                         else
3636                                                                 o_ptr->name2 = EGO_RING_RES_DARK;
3637                                                         break;
3638                                                 case SV_RING_LORDLY:
3639                                                         if (!one_in_(20)) break;
3640                                                         one_lordly_high_resistance(o_ptr);
3641                                                         one_lordly_high_resistance(o_ptr);
3642                                                         o_ptr->name2 = EGO_RING_TRUE;
3643                                                         break;
3644                                                 case SV_RING_SUSTAIN:
3645                                                         if (!one_in_(4)) break;
3646                                                         o_ptr->name2 = EGO_RING_RES_TIME;
3647                                                         break;
3648                                                 case SV_RING_FLAMES:
3649                                                         if (!one_in_(2)) break;
3650                                                         o_ptr->name2 = EGO_RING_DRAGON_F;
3651                                                         break;
3652                                                 case SV_RING_ICE:
3653                                                         if (!one_in_(2)) break;
3654                                                         o_ptr->name2 = EGO_RING_DRAGON_C;
3655                                                         break;
3656                                                 case SV_RING_WARNING:
3657                                                         if (!one_in_(2)) break;
3658                                                         o_ptr->name2 = EGO_RING_M_DETECT;
3659                                                         break;
3660                                                 default:
3661                                                         break;
3662                                                 }
3663                                                 break;
3664                                         }
3665                                 }
3666                                 /* Uncurse it */
3667                                 o_ptr->curse_flags = 0L;
3668                         }
3669                         else if ((power == -2) && one_in_(2))
3670                         {
3671                                 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3672                                 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3673                                 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3674                                 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3675                                 o_ptr->art_flags[0] = 0;
3676                                 o_ptr->art_flags[1] = 0;
3677                                 while(!o_ptr->name2)
3678                                 {
3679                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3680                                         switch(randint1(5))
3681                                         {
3682                                         case 1:
3683                                                 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3684                                                 o_ptr->name2 = EGO_RING_DRAIN_EXP;
3685                                                 break;
3686                                         case 2:
3687                                                 o_ptr->name2 = EGO_RING_NO_MELEE;
3688                                                 break;
3689                                         case 3:
3690                                                 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3691                                                 o_ptr->name2 = EGO_RING_AGGRAVATE;
3692                                                 break;
3693                                         case 4:
3694                                                 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3695                                                 o_ptr->name2 = EGO_RING_TY_CURSE;
3696                                                 break;
3697                                         case 5:
3698                                                 o_ptr->name2 = EGO_RING_ALBINO;
3699                                                 break;
3700                                         }
3701                                 }
3702                                 /* Broken */
3703                                 o_ptr->ident |= (IDENT_BROKEN);
3704
3705                                 /* Cursed */
3706                                 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3707                         }
3708                         break;
3709                 }
3710
3711                 case TV_AMULET:
3712                 {
3713                         /* Analyze */
3714                         switch (o_ptr->sval)
3715                         {
3716                                 /* Amulet of wisdom/charisma */
3717                                 case SV_AMULET_INTELLIGENCE:
3718                                 case SV_AMULET_WISDOM:
3719                                 case SV_AMULET_CHARISMA:
3720                                 {
3721                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
3722
3723                                         /* Cursed */
3724                                         if (power < 0)
3725                                         {
3726                                                 /* Broken */
3727                                                 o_ptr->ident |= (IDENT_BROKEN);
3728
3729                                                 /* Cursed */
3730                                                 o_ptr->curse_flags |= (TRC_CURSED);
3731
3732                                                 /* Reverse bonuses */
3733                                                 o_ptr->pval = 0 - o_ptr->pval;
3734                                         }
3735
3736                                         break;
3737                                 }
3738
3739                                 /* Amulet of brilliance */
3740                                 case SV_AMULET_BRILLIANCE:
3741                                 {
3742                                         o_ptr->pval = 1 + m_bonus(3, level);
3743                                         if (one_in_(4)) o_ptr->pval++;
3744
3745                                         /* Cursed */
3746                                         if (power < 0)
3747                                         {
3748                                                 /* Broken */
3749                                                 o_ptr->ident |= (IDENT_BROKEN);
3750
3751                                                 /* Cursed */
3752                                                 o_ptr->curse_flags |= (TRC_CURSED);
3753
3754                                                 /* Reverse bonuses */
3755                                                 o_ptr->pval = 0 - o_ptr->pval;
3756                                         }
3757
3758                                         break;
3759                                 }
3760
3761                                 case SV_AMULET_NO_MAGIC: case SV_AMULET_NO_TELE:
3762                                 {
3763                                         if (power < 0)
3764                                         {
3765                                                 o_ptr->curse_flags |= (TRC_CURSED);
3766                                         }
3767                                         break;
3768                                 }
3769
3770                                 case SV_AMULET_RESISTANCE:
3771                                 {
3772                                         if (one_in_(5)) one_high_resistance(o_ptr);
3773                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_RES_POIS);
3774                                 }
3775                                 break;
3776
3777                                 /* Amulet of searching */
3778                                 case SV_AMULET_SEARCHING:
3779                                 {
3780                                         o_ptr->pval = randint1(2) + (PARAMETER_VALUE)m_bonus(4, level);
3781
3782                                         /* Cursed */
3783                                         if (power < 0)
3784                                         {
3785                                                 /* Broken */
3786                                                 o_ptr->ident |= (IDENT_BROKEN);
3787
3788                                                 /* Cursed */
3789                                                 o_ptr->curse_flags |= (TRC_CURSED);
3790
3791                                                 /* Reverse bonuses */
3792                                                 o_ptr->pval = 0 - (o_ptr->pval);
3793                                         }
3794
3795                                         break;
3796                                 }
3797
3798                                 /* Amulet of the Magi -- never cursed */
3799                                 case SV_AMULET_THE_MAGI:
3800                                 {
3801                                         o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
3802                                         o_ptr->to_a = randint1(5) + (ARMOUR_CLASS)m_bonus(5, level);
3803
3804                                         /* gain one low ESP */
3805                                         add_esp_weak(o_ptr, FALSE);
3806
3807                                         break;
3808                                 }
3809
3810                                 /* Amulet of Doom -- always cursed */
3811                                 case SV_AMULET_DOOM:
3812                                 {
3813                                         /* Broken */
3814                                         o_ptr->ident |= (IDENT_BROKEN);
3815
3816                                         /* Cursed */
3817                                         o_ptr->curse_flags |= (TRC_CURSED);
3818
3819                                         /* Penalize */
3820                                         o_ptr->pval = 0 - (randint1(5) + (PARAMETER_VALUE)m_bonus(5, level));
3821                                         o_ptr->to_a = 0 - (randint1(5) + (ARMOUR_CLASS)m_bonus(5, level));
3822                                         if (power > 0) power = 0 - power;
3823
3824                                         break;
3825                                 }
3826
3827                                 case SV_AMULET_MAGIC_MASTERY:
3828                                 {
3829                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(4, level);
3830
3831                                         /* Cursed */
3832                                         if (power < 0)
3833                                         {
3834                                                 /* Broken */
3835                                                 o_ptr->ident |= (IDENT_BROKEN);
3836
3837                                                 /* Cursed */
3838                                                 o_ptr->curse_flags |= (TRC_CURSED);
3839
3840                                                 /* Reverse bonuses */
3841                                                 o_ptr->pval = 0 - o_ptr->pval;
3842                                         }
3843
3844                                         break;
3845                                 }
3846                         }
3847                         if ((one_in_(150) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3848                             || (power > 2)) /* power > 2 is debug only */
3849                         {
3850                                 o_ptr->pval = MIN(o_ptr->pval, 4);
3851                                 /* Randart amulet */
3852                                 create_artifact(o_ptr, FALSE);
3853                         }
3854                         else if ((power == 2) && one_in_(2))
3855                         {
3856                                 while(!o_ptr->name2)
3857                                 {
3858                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3859                                         switch(randint1(21))
3860                                         {
3861                                         case 1: case 2:
3862                                                 if (have_flag(k_ptr->flags, TR_SLOW_DIGEST)) break;
3863                                                 o_ptr->name2 = EGO_AMU_SLOW_D;
3864                                                 break;
3865                                         case 3: case 4:
3866                                                 if (o_ptr->pval) break;
3867                                                 o_ptr->name2 = EGO_AMU_INFRA;
3868                                                 break;
3869                                         case 5: case 6:
3870                                                 if (have_flag(k_ptr->flags, TR_SEE_INVIS)) break;
3871                                                 o_ptr->name2 = EGO_AMU_SEE_INVIS;
3872                                                 break;
3873                                         case 7: case 8:
3874                                                 if (have_flag(k_ptr->flags, TR_HOLD_EXP)) break;
3875                                                 o_ptr->name2 = EGO_AMU_HOLD_EXP;
3876                                                 break;
3877                                         case 9:
3878                                                 if (have_flag(k_ptr->flags, TR_LEVITATION)) break;
3879                                                 o_ptr->name2 = EGO_AMU_LEVITATION;
3880                                                 break;
3881                                         case 10: case 11: case 21:
3882                                                 o_ptr->name2 = EGO_AMU_AC;
3883                                                 break;
3884                                         case 12:
3885                                                 if (have_flag(k_ptr->flags, TR_RES_FIRE)) break;
3886                                                 if (m_bonus(10, level) > 8)
3887                                                         o_ptr->name2 = EGO_AMU_RES_FIRE_;
3888                                                 else
3889                                                         o_ptr->name2 = EGO_AMU_RES_FIRE;
3890                                                 break;
3891                                         case 13:
3892                                                 if (have_flag(k_ptr->flags, TR_RES_COLD)) break;
3893                                                 if (m_bonus(10, level) > 8)
3894                                                         o_ptr->name2 = EGO_AMU_RES_COLD_;
3895                                                 else
3896                                                         o_ptr->name2 = EGO_AMU_RES_COLD;
3897                                                 break;
3898                                         case 14:
3899                                                 if (have_flag(k_ptr->flags, TR_RES_ELEC)) break;
3900                                                 if (m_bonus(10, level) > 8)
3901                                                         o_ptr->name2 = EGO_AMU_RES_ELEC_;
3902                                                 else
3903                                                         o_ptr->name2 = EGO_AMU_RES_ELEC;
3904                                                 break;
3905                                         case 15:
3906                                                 if (have_flag(k_ptr->flags, TR_RES_ACID)) break;
3907                                                 if (m_bonus(10, level) > 8)
3908                                                         o_ptr->name2 = EGO_AMU_RES_ACID_;
3909                                                 else
3910                                                         o_ptr->name2 = EGO_AMU_RES_ACID;
3911                                                 break;
3912                                         case 16: case 17: case 18: case 19: case 20:
3913                                                 switch (o_ptr->sval)
3914                                                 {
3915                                                 case SV_AMULET_TELEPORT:
3916                                                         if (m_bonus(10, level) > 9) o_ptr->name2 = EGO_AMU_D_DOOR;
3917                                                         else if (one_in_(2)) o_ptr->name2 = EGO_AMU_JUMP;
3918                                                         else o_ptr->name2 = EGO_AMU_TELEPORT;
3919                                                         break;
3920                                                 case SV_AMULET_RESIST_ACID:
3921                                                         if ((m_bonus(10, level) > 6) && one_in_(2)) o_ptr->name2 = EGO_AMU_RES_ACID_;
3922                                                         break;
3923                                                 case SV_AMULET_SEARCHING:
3924                                                         o_ptr->name2 = EGO_AMU_STEALTH;
3925                                                         break;
3926                                                 case SV_AMULET_BRILLIANCE:
3927                                                         if (!one_in_(3)) break;
3928                                                         o_ptr->name2 = EGO_AMU_IDENT;
3929                                                         break;
3930                                                 case SV_AMULET_CHARISMA:
3931                                                         if (!one_in_(3)) break;
3932                                                         o_ptr->name2 = EGO_AMU_CHARM;
3933                                                         break;
3934                                                 case SV_AMULET_THE_MAGI:
3935                                                         if (one_in_(2)) break;
3936                                                         o_ptr->name2 = EGO_AMU_GREAT;
3937                                                         break;
3938                                                 case SV_AMULET_RESISTANCE:
3939                                                         if (!one_in_(5)) break;
3940                                                         o_ptr->name2 = EGO_AMU_DEFENDER;
3941                                                         break;
3942                                                 case SV_AMULET_TELEPATHY:
3943                                                         if (!one_in_(3)) break;
3944                                                         o_ptr->name2 = EGO_AMU_DETECTION;
3945                                                         break;
3946                                                 }
3947                                         }
3948                                 }
3949                                 /* Uncurse it */
3950                                 o_ptr->curse_flags = 0L;
3951                         }
3952                         else if ((power == -2) && one_in_(2))
3953                         {
3954                                 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3955                                 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3956                                 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3957                                 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3958                                 o_ptr->art_flags[0] = 0;
3959                                 o_ptr->art_flags[1] = 0;
3960                                 while(!o_ptr->name2)
3961                                 {
3962                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3963                                         switch(randint1(5))
3964                                         {
3965                                         case 1:
3966                                                 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3967                                                 o_ptr->name2 = EGO_AMU_DRAIN_EXP;
3968                                                 break;
3969                                         case 2:
3970                                                 o_ptr->name2 = EGO_AMU_FOOL;
3971                                                 break;
3972                                         case 3:
3973                                                 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3974                                                 o_ptr->name2 = EGO_AMU_AGGRAVATE;
3975                                                 break;
3976                                         case 4:
3977                                                 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3978                                                 o_ptr->name2 = EGO_AMU_TY_CURSE;
3979                                                 break;
3980                                         case 5:
3981                                                 o_ptr->name2 = EGO_AMU_NAIVETY;
3982                                                 break;
3983                                         }
3984                                 }
3985                                 /* Broken */
3986                                 o_ptr->ident |= (IDENT_BROKEN);
3987
3988                                 /* Cursed */
3989                                 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3990                         }
3991                         break;
3992                 }
3993         }
3994 }
3995
3996 /*!
3997  * @brief モンスターが人形のベースにできるかを返す
3998  * @param r_idx チェックしたいモンスター種族のID
3999  * @return 人形にできるならTRUEを返す
4000  */
4001 static bool item_monster_okay(MONRACE_IDX r_idx)
4002 {
4003         monster_race *r_ptr = &r_info[r_idx];
4004
4005         /* No uniques */
4006         if (r_ptr->flags1 & RF1_UNIQUE) return (FALSE);
4007         if (r_ptr->flags7 & RF7_KAGE) return (FALSE);
4008         if (r_ptr->flagsr & RFR_RES_ALL) return (FALSE);
4009         if (r_ptr->flags7 & RF7_NAZGUL) return (FALSE);
4010         if (r_ptr->flags1 & RF1_FORCE_DEPTH) return (FALSE);
4011         if (r_ptr->flags7 & RF7_UNIQUE2) return (FALSE);
4012
4013         /* Okay */
4014         return (TRUE);
4015 }
4016
4017
4018 /*!
4019  * @brief その他雑多のオブジェクトに生成ランクごとの強化を与えるサブルーチン
4020  * Apply magic to an item known to be "boring"
4021  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
4022  * @param level 生成基準階
4023  * @param power 生成ランク
4024  * @return なし
4025  * @details
4026  * Hack -- note the special code for various items
4027  */
4028 static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
4029 {
4030         object_kind *k_ptr = &k_info[o_ptr->k_idx];
4031
4032         /* Unused */
4033         (void)level;
4034
4035         /* Apply magic (good or bad) according to type */
4036         switch (o_ptr->tval)
4037         {
4038                 case TV_WHISTLE:
4039                 {
4040 #if 0
4041                         /* Cursed */
4042                         if (power < 0)
4043                         {
4044                                 /* Broken */
4045                                 o_ptr->ident |= (IDENT_BROKEN);
4046
4047                                 /* Cursed */
4048                                 o_ptr->curse_flags |= (TRC_CURSED);
4049                         }
4050 #endif
4051                         break;
4052                 }
4053                 case TV_FLASK:
4054                 {
4055                         o_ptr->xtra4 = o_ptr->pval;
4056                         o_ptr->pval = 0;
4057                         break;
4058                 }
4059                 case TV_LITE:
4060                 {
4061                         /* Hack -- Torches -- random fuel */
4062                         if (o_ptr->sval == SV_LITE_TORCH)
4063                         {
4064                                 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
4065                                 o_ptr->pval = 0;
4066                         }
4067
4068                         /* Hack -- Lanterns -- random fuel */
4069                         if (o_ptr->sval == SV_LITE_LANTERN)
4070                         {
4071                                 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
4072                                 o_ptr->pval = 0;
4073                         }
4074
4075                         if (power > 2) /* power > 2 is debug only */
4076                         {
4077                                 create_artifact(o_ptr, FALSE);
4078                         }
4079                         else if ((power == 2) || ((power == 1) && one_in_(3)))
4080                         {
4081                                 while (!o_ptr->name2)
4082                                 {
4083                                         while (1)
4084                                         {
4085                                                 bool okay_flag = TRUE;
4086
4087                                                 o_ptr->name2 = get_random_ego(INVEN_LITE, TRUE);
4088
4089                                                 switch (o_ptr->name2)
4090                                                 {
4091                                                 case EGO_LITE_LONG:
4092                                                         if (o_ptr->sval == SV_LITE_FEANOR)
4093                                                                 okay_flag = FALSE;
4094                                                 }
4095                                                 if (okay_flag)
4096                                                         break;
4097                                         }
4098                                 }
4099                         }
4100                         else if (power == -2)
4101                         {
4102                                 o_ptr->name2 = get_random_ego(INVEN_LITE, FALSE);
4103
4104                                 switch (o_ptr->name2)
4105                                 {
4106                                 case EGO_LITE_DARKNESS:
4107                                         o_ptr->xtra4 = 0;
4108                                         
4109                                         if (o_ptr->sval == SV_LITE_TORCH)
4110                                         {
4111                                                 add_flag(o_ptr->art_flags, TR_LITE_M1);
4112                                         }
4113                                         else if (o_ptr->sval == SV_LITE_LANTERN)
4114                                         {
4115                                                 add_flag(o_ptr->art_flags, TR_LITE_M2);
4116                                         }
4117                                         else if (o_ptr->sval == SV_LITE_FEANOR)
4118                                         {
4119                                                 add_flag(o_ptr->art_flags, TR_LITE_M3);
4120                                         }
4121                                         break;
4122                                 }
4123                         }
4124
4125                         break;
4126                 }
4127
4128                 case TV_WAND:
4129                 case TV_STAFF:
4130                 {
4131                         /* The wand or staff gets a number of initial charges equal
4132                          * to between 1/2 (+1) and the full object kind's pval. -LM-
4133                          */
4134                         o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
4135                         break;
4136                 }
4137
4138                 case TV_ROD:
4139                 {
4140                         /* Transfer the pval. -LM- */
4141                         o_ptr->pval = k_ptr->pval;
4142                         break;
4143                 }
4144
4145                 case TV_CAPTURE:
4146                 {
4147                         o_ptr->pval = 0;
4148                         object_aware(o_ptr);
4149                         object_known(o_ptr);
4150                         break;
4151                 }
4152
4153                 case TV_FIGURINE:
4154                 {
4155                         PARAMETER_VALUE i = 1;
4156                         int check;
4157
4158                         monster_race *r_ptr;
4159
4160                         /* Pick a random non-unique monster race */
4161                         while (1)
4162                         {
4163                                 i = randint1(max_r_idx - 1);
4164
4165                                 if (!item_monster_okay(i)) continue;
4166                                 if (i == MON_TSUCHINOKO) continue;
4167
4168                                 r_ptr = &r_info[i];
4169
4170                                 check = (dun_level < r_ptr->level) ? (r_ptr->level - dun_level) : 0;
4171
4172                                 /* Ignore dead monsters */
4173                                 if (!r_ptr->rarity) continue;
4174
4175                                 /* Ignore uncommon monsters */
4176                                 if (r_ptr->rarity > 100) continue;
4177
4178                                 /* Prefer less out-of-depth monsters */
4179                                 if (randint0(check)) continue;
4180
4181                                 break;
4182                         }
4183
4184                         o_ptr->pval = i;
4185
4186                         /* Some figurines are cursed */
4187                         if (one_in_(6)) o_ptr->curse_flags |= TRC_CURSED;
4188
4189                         break;
4190                 }
4191
4192                 case TV_CORPSE:
4193                 {
4194                         PARAMETER_VALUE i = 1;
4195                         int check;
4196
4197                         u32b match = 0;
4198
4199                         monster_race *r_ptr;
4200
4201                         if (o_ptr->sval == SV_SKELETON)
4202                         {
4203                                 match = RF9_DROP_SKELETON;
4204                         }
4205                         else if (o_ptr->sval == SV_CORPSE)
4206                         {
4207                                 match = RF9_DROP_CORPSE;
4208                         }
4209
4210                         /* Hack -- Remove the monster restriction */
4211                         get_mon_num_prep(item_monster_okay, NULL);
4212
4213                         /* Pick a random non-unique monster race */
4214                         while (1)
4215                         {
4216                                 i = get_mon_num(dun_level);
4217
4218                                 r_ptr = &r_info[i];
4219
4220                                 check = (dun_level < r_ptr->level) ? (r_ptr->level - dun_level) : 0;
4221
4222                                 /* Ignore dead monsters */
4223                                 if (!r_ptr->rarity) continue;
4224
4225                                 /* Ignore corpseless monsters */
4226                                 if (!(r_ptr->flags9 & match)) continue;
4227
4228                                 /* Prefer less out-of-depth monsters */
4229                                 if (randint0(check)) continue;
4230
4231                                 break;
4232                         }
4233
4234                         o_ptr->pval = i;
4235
4236
4237                         object_aware(o_ptr);
4238                         object_known(o_ptr);
4239                         break;
4240                 }
4241
4242                 case TV_STATUE:
4243                 {
4244                         PARAMETER_VALUE i = 1;
4245
4246                         monster_race *r_ptr;
4247
4248                         /* Pick a random monster race */
4249                         while (1)
4250                         {
4251                                 i = randint1(max_r_idx - 1);
4252
4253                                 r_ptr = &r_info[i];
4254
4255                                 /* Ignore dead monsters */
4256                                 if (!r_ptr->rarity) continue;
4257
4258                                 break;
4259                         }
4260
4261                         o_ptr->pval = i;
4262
4263                         if (cheat_peek)
4264                         {
4265                                 msg_format(_("%sの像", "Statue of %s"), r_name + r_ptr->name);
4266                         }
4267                         object_aware(o_ptr);
4268                         object_known(o_ptr);
4269
4270                         break;
4271                 }
4272
4273                 case TV_CHEST:
4274                 {
4275                         DEPTH obj_level = k_info[o_ptr->k_idx].level;
4276
4277                         /* Hack -- skip ruined chests */
4278                         if (obj_level <= 0) break;
4279
4280                         /* Hack -- pick a "difficulty" */
4281                         o_ptr->pval = randint1(obj_level);
4282                         if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
4283
4284                         o_ptr->xtra3 = dun_level + 5;
4285
4286                         /* Never exceed "difficulty" of 55 to 59 */
4287                         if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
4288
4289                         break;
4290                 }
4291         }
4292 }
4293
4294 /*!
4295  * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
4296  * Complete the "creation" of an object by applying "magic" to the item
4297  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
4298  * @param lev 生成基準階
4299  * @param mode 生成オプション
4300  * @return なし
4301  * @details
4302  * This includes not only rolling for random bonuses, but also putting the\n
4303  * finishing touches on ego-items and artifacts, giving charges to wands and\n
4304  * staffs, giving fuel to lites, and placing traps on chests.\n
4305  *\n
4306  * In particular, note that "Instant Artifacts", if "created" by an external\n
4307  * routine, must pass through this function to complete the actual creation.\n
4308  *\n
4309  * The base "chance" of the item being "good" increases with the "level"\n
4310  * parameter, which is usually derived from the dungeon level, being equal\n
4311  * to the level plus 10, up to a maximum of 75.  If "good" is true, then\n
4312  * the object is guaranteed to be "good".  If an object is "good", then\n
4313  * the chance that the object will be "great" (ego-item or artifact), also\n
4314  * increases with the "level", being equal to half the level, plus 5, up to\n
4315  * a maximum of 20.  If "great" is true, then the object is guaranteed to be\n
4316  * "great".  At dungeon level 65 and below, 15/100 objects are "great".\n
4317  *\n
4318  * If the object is not "good", there is a chance it will be "cursed", and\n
4319  * if it is "cursed", there is a chance it will be "broken".  These chances\n
4320  * are related to the "good" / "great" chances above.\n
4321  *\n
4322  * Otherwise "normal" rings and amulets will be "good" half the time and\n
4323  * "cursed" half the time, unless the ring/amulet is always good or cursed.\n
4324  *\n
4325  * If "okay" is true, and the object is going to be "great", then there is\n
4326  * a chance that an artifact will be created.  This is true even if both the\n
4327  * "good" and "great" arguments are false.  As a total hack, if "great" is\n
4328  * true, then the item gets 3 extra "attempts" to become an artifact.\n
4329  */
4330 void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
4331 {
4332         int i, rolls, f1, f2, power;
4333
4334         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) lev += randint0(p_ptr->lev/2+10);
4335
4336         /* Maximum "level" for various things */
4337         if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1;
4338
4339         /* Base chance of being "good" */
4340         f1 = lev + 10;
4341
4342         /* Maximal chance of being "good" */
4343         if (f1 > d_info[dungeon_type].obj_good) f1 = d_info[dungeon_type].obj_good;
4344
4345         /* Base chance of being "great" */
4346         f2 = f1 * 2 / 3;
4347
4348         /* Maximal chance of being "great" */
4349         if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[dungeon_type].obj_great))
4350                 f2 = d_info[dungeon_type].obj_great;
4351
4352         if (p_ptr->muta3 & MUT3_GOOD_LUCK)
4353         {
4354                 f1 += 5;
4355                 f2 += 2;
4356         }
4357         else if(p_ptr->muta3 & MUT3_BAD_LUCK)
4358         {
4359                 f1 -= 5;
4360                 f2 -= 2;
4361         }
4362
4363         /* Assume normal */
4364         power = 0;
4365
4366         /* Roll for "good" */
4367         if ((mode & AM_GOOD) || magik(f1))
4368         {
4369                 /* Assume "good" */
4370                 power = 1;
4371
4372                 /* Roll for "great" */
4373                 if ((mode & AM_GREAT) || magik(f2))
4374                 {
4375                         power = 2;
4376
4377                         /* Roll for "special" */
4378                         if (mode & AM_SPECIAL) power = 3;
4379                 }
4380         }
4381
4382         /* Roll for "cursed" */
4383         else if (magik(f1))
4384         {
4385                 /* Assume "cursed" */
4386                 power = -1;
4387
4388                 /* Roll for "broken" */
4389                 if (magik(f2)) power = -2;
4390         }
4391
4392         /* Apply curse */
4393         if (mode & AM_CURSED)
4394         {
4395                 /* Assume 'cursed' */
4396                 if (power > 0)
4397                 {
4398                         power = 0 - power;
4399                 }
4400                 /* Everything else gets more badly cursed */
4401                 else
4402                 {
4403                         power--;
4404                 }
4405         }
4406
4407         /* Assume no rolls */
4408         rolls = 0;
4409
4410         /* Get one roll if excellent */
4411         if (power >= 2) rolls = 1;
4412
4413         /* Hack -- Get four rolls if forced great or special */
4414         if (mode & (AM_GREAT | AM_SPECIAL)) rolls = 4;
4415
4416         /* Hack -- Get no rolls if not allowed */
4417         if ((mode & AM_NO_FIXED_ART) || o_ptr->name1) rolls = 0;
4418
4419         /* Roll for artifacts if allowed */
4420         for (i = 0; i < rolls; i++)
4421         {
4422                 /* Roll for an artifact */
4423                 if (make_artifact(o_ptr)) break;
4424                 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77))
4425                 {
4426                         if (make_artifact(o_ptr)) break;
4427                 }
4428         }
4429
4430
4431         /* Hack -- analyze artifacts */
4432         if (object_is_fixed_artifact(o_ptr))
4433         {
4434                 artifact_type *a_ptr = &a_info[o_ptr->name1];
4435
4436                 /* Hack -- Mark the artifact as "created" */
4437                 a_ptr->cur_num = 1;
4438
4439                 /* Hack -- Memorize location of artifact in saved floors */
4440                 if (character_dungeon)
4441                         a_ptr->floor_id = p_ptr->floor_id;
4442
4443                 /* Extract the other fields */
4444                 o_ptr->pval = a_ptr->pval;
4445                 o_ptr->ac = a_ptr->ac;
4446                 o_ptr->dd = a_ptr->dd;
4447                 o_ptr->ds = a_ptr->ds;
4448                 o_ptr->to_a = a_ptr->to_a;
4449                 o_ptr->to_h = a_ptr->to_h;
4450                 o_ptr->to_d = a_ptr->to_d;
4451                 o_ptr->weight = a_ptr->weight;
4452                 o_ptr->xtra2 = a_ptr->act_idx;
4453
4454                 if (o_ptr->name1 == ART_MILIM)
4455                 {
4456                     if(p_ptr->pseikaku == SEIKAKU_SEXY)
4457                     {
4458                         o_ptr->pval = 3;
4459                     }
4460                 }
4461
4462                 /* Hack -- extract the "broken" flag */
4463                 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4464
4465                 /* Hack -- extract the "cursed" flag */
4466                 if (a_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4467                 if (a_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4468                 if (a_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4469                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4470                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4471                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4472
4473                 return;
4474         }
4475
4476
4477         /* Apply magic */
4478         switch (o_ptr->tval)
4479         {
4480                 case TV_DIGGING:
4481                 case TV_HAFTED:
4482                 case TV_BOW:
4483                 case TV_SHOT:
4484                 case TV_ARROW:
4485                 case TV_BOLT:
4486                 {
4487                         if (power) a_m_aux_1(o_ptr, lev, power);
4488                         break;
4489                 }
4490
4491                 case TV_POLEARM:
4492                 {
4493                         if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) a_m_aux_1(o_ptr, lev, power);
4494                         break;
4495                 }
4496
4497                 case TV_SWORD:
4498                 {
4499                         if (power && !(o_ptr->sval == SV_DOKUBARI)) a_m_aux_1(o_ptr, lev, power);
4500                         break;
4501                 }
4502
4503                 case TV_DRAG_ARMOR:
4504                 case TV_HARD_ARMOR:
4505                 case TV_SOFT_ARMOR:
4506                 case TV_SHIELD:
4507                 case TV_HELM:
4508                 case TV_CROWN:
4509                 case TV_CLOAK:
4510                 case TV_GLOVES:
4511                 case TV_BOOTS:
4512                 {
4513                         /* Elven Cloak and Black Clothes ... */
4514                         if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) ||
4515                             ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
4516                                 o_ptr->pval = randint1(4);
4517
4518 #if 1
4519                         if (power ||
4520                              ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) ||
4521                              ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD)) ||
4522                              ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)) ||
4523                              ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
4524                                 a_m_aux_2(o_ptr, lev, power);
4525 #else
4526                         if (power) a_m_aux_2(o_ptr, lev, power);
4527 #endif
4528                         break;
4529                 }
4530
4531                 case TV_RING:
4532                 case TV_AMULET:
4533                 {
4534                         if (!power && (randint0(100) < 50)) power = -1;
4535                         a_m_aux_3(o_ptr, lev, power);
4536                         break;
4537                 }
4538
4539                 default:
4540                 {
4541                         a_m_aux_4(o_ptr, lev, power);
4542                         break;
4543                 }
4544         }
4545
4546         if ((o_ptr->tval == TV_SOFT_ARMOR) &&
4547             (o_ptr->sval == SV_ABUNAI_MIZUGI) &&
4548             (p_ptr->pseikaku == SEIKAKU_SEXY))
4549         {
4550                 o_ptr->pval = 3;
4551                 add_flag(o_ptr->art_flags, TR_STR);
4552                 add_flag(o_ptr->art_flags, TR_INT);
4553                 add_flag(o_ptr->art_flags, TR_WIS);
4554                 add_flag(o_ptr->art_flags, TR_DEX);
4555                 add_flag(o_ptr->art_flags, TR_CON);
4556                 add_flag(o_ptr->art_flags, TR_CHR);
4557         }
4558
4559         /* Hack -- analyze ego-items */
4560         if (object_is_ego(o_ptr))
4561         {
4562                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
4563
4564                 /* Hack -- acquire "broken" flag */
4565                 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4566
4567                 /* Hack -- acquire "cursed" flag */
4568                 if (e_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4569                 if (e_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4570                 if (e_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4571                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4572                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4573                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4574
4575                 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN)) one_sustain(o_ptr);
4576                 if (e_ptr->gen_flags & (TRG_XTRA_POWER)) one_ability(o_ptr);
4577                 if (e_ptr->gen_flags & (TRG_XTRA_H_RES)) one_high_resistance(o_ptr);
4578                 if (e_ptr->gen_flags & (TRG_XTRA_E_RES)) one_ele_resistance(o_ptr);
4579                 if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
4580                 if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
4581                 if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
4582                 if (e_ptr->gen_flags & (TRG_XTRA_DICE))
4583                 {
4584                         do
4585                         {
4586                                 o_ptr->dd++;
4587                         }
4588                         while (one_in_(o_ptr->dd));
4589
4590                         if (o_ptr->dd > 9) o_ptr->dd = 9;
4591                 }
4592
4593                 /* Hack -- apply activatin index if needed */
4594                 if (e_ptr->act_idx) o_ptr->xtra2 = (XTRA8)e_ptr->act_idx;
4595
4596                 /* Hack -- apply extra penalties if needed */
4597                 if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL)))
4598                 {
4599                         /* Hack -- obtain bonuses */
4600                         if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
4601                         if (e_ptr->max_to_d) o_ptr->to_d -= randint1(e_ptr->max_to_d);
4602                         if (e_ptr->max_to_a) o_ptr->to_a -= randint1(e_ptr->max_to_a);
4603
4604                         /* Hack -- obtain pval */
4605                         if (e_ptr->max_pval) o_ptr->pval -= randint1(e_ptr->max_pval);
4606                 }
4607
4608                 /* Hack -- apply extra bonuses if needed */
4609                 else
4610                 {
4611                         /* Hack -- obtain bonuses */
4612                         if (e_ptr->max_to_h)
4613                         {
4614                                 if (e_ptr->max_to_h > 127)
4615                                         o_ptr->to_h -= randint1(256-e_ptr->max_to_h);
4616                                 else o_ptr->to_h += randint1(e_ptr->max_to_h);
4617                         }
4618                         if (e_ptr->max_to_d)
4619                         {
4620                                 if (e_ptr->max_to_d > 127)
4621                                         o_ptr->to_d -= randint1(256-e_ptr->max_to_d);
4622                                 else o_ptr->to_d += randint1(e_ptr->max_to_d);
4623                         }
4624                         if (e_ptr->max_to_a)
4625                         {
4626                                 if (e_ptr->max_to_a > 127)
4627                                         o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
4628                                 else o_ptr->to_a += randint1(e_ptr->max_to_a);
4629                         }
4630                         
4631                         /* Accuracy ego must have high to_h */
4632                         if(o_ptr->name2 == EGO_ACCURACY)
4633                         {
4634                                 while(o_ptr->to_h < o_ptr->to_d + 10)
4635                                 {
4636                                         o_ptr->to_h += 5;
4637                                         o_ptr->to_d -= 5;
4638                                 }
4639                                 o_ptr->to_h = MAX(o_ptr->to_h, 15);
4640                         }
4641                         
4642                         /* Accuracy ego must have high to_h */
4643                         if(o_ptr->name2 == EGO_VELOCITY)
4644                         {
4645                                 while(o_ptr->to_d < o_ptr->to_h + 10)
4646                                 {
4647                                         o_ptr->to_d += 5;
4648                                         o_ptr->to_h -= 5;
4649                                 }
4650                                 o_ptr->to_d = MAX(o_ptr->to_d, 15);
4651                         }
4652                         
4653                         /* Protection ego must have high to_a */
4654                         if((o_ptr->name2 == EGO_PROTECTION) || (o_ptr->name2 == EGO_S_PROTECTION) || (o_ptr->name2 == EGO_H_PROTECTION))
4655                         {
4656                                 o_ptr->to_a = MAX(o_ptr->to_a, 15);
4657                         }
4658
4659                         /* Hack -- obtain pval */
4660                         if (e_ptr->max_pval)
4661                         {
4662                                 if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS)))
4663                                 {
4664                                         o_ptr->pval++;
4665                                         if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
4666                                 }
4667                                 else if (o_ptr->name2 == EGO_DEMON)
4668                                 {
4669                                         if(have_flag(o_ptr->art_flags, TR_BLOWS))
4670                                         {
4671                                                 o_ptr->pval += randint1(2);
4672                                         }
4673                                         else
4674                                         {
4675                                                 o_ptr->pval += randint1(e_ptr->max_pval);
4676                                         }
4677                                 }
4678                                 else if (o_ptr->name2 == EGO_ATTACKS)
4679                                 {
4680                                         o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
4681                                         if (o_ptr->pval > 3) o_ptr->pval = 3;
4682                                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
4683                                                 o_ptr->pval += randint1(2);
4684                                 }
4685                                 else if (o_ptr->name2 == EGO_BAT)
4686                                 {
4687                                         o_ptr->pval = randint1(e_ptr->max_pval);
4688                                         if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
4689                                 }
4690                                 else if (o_ptr->name2 == EGO_A_DEMON || o_ptr->name2 == EGO_DRUID || o_ptr->name2 == EGO_OLOG)
4691                                 {
4692                                         o_ptr->pval = randint1(e_ptr->max_pval);
4693                                 }
4694                                 else
4695                                 {
4696                                         o_ptr->pval += randint1(e_ptr->max_pval);
4697                                 }
4698                                 
4699                                 
4700                         }
4701                         if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
4702                         {
4703                                 o_ptr->pval = randint1(o_ptr->pval);
4704                         }
4705                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
4706                                 o_ptr->pval = 2;
4707                 }
4708                 
4709                 return;
4710         }
4711
4712         /* Examine real objects */
4713         if (o_ptr->k_idx)
4714         {
4715                 object_kind *k_ptr = &k_info[o_ptr->k_idx];
4716
4717                 /* Hack -- acquire "broken" flag */
4718                 if (!k_info[o_ptr->k_idx].cost) o_ptr->ident |= (IDENT_BROKEN);
4719
4720                 /* Hack -- acquire "cursed" flag */
4721                 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
4722                 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
4723                 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
4724                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4725                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4726                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4727         }
4728
4729         
4730 }
4731
4732
4733 /*!
4734  * @brief ベースアイテムが上質として扱われるかどうかを返す。
4735  * Hack -- determine if a template is "good"
4736  * @param k_idx 判定したいベースアイテムのID
4737  * @return ベースアイテムが上質ならばTRUEを返す。
4738  */
4739 static bool kind_is_good(KIND_OBJECT_IDX k_idx)
4740 {
4741         object_kind *k_ptr = &k_info[k_idx];
4742
4743         /* Analyze the item type */
4744         switch (k_ptr->tval)
4745         {
4746                 /* Armor -- Good unless damaged */
4747                 case TV_HARD_ARMOR:
4748                 case TV_SOFT_ARMOR:
4749                 case TV_DRAG_ARMOR:
4750                 case TV_SHIELD:
4751                 case TV_CLOAK:
4752                 case TV_BOOTS:
4753                 case TV_GLOVES:
4754                 case TV_HELM:
4755                 case TV_CROWN:
4756                 {
4757                         if (k_ptr->to_a < 0) return (FALSE);
4758                         return (TRUE);
4759                 }
4760
4761                 /* Weapons -- Good unless damaged */
4762                 case TV_BOW:
4763                 case TV_SWORD:
4764                 case TV_HAFTED:
4765                 case TV_POLEARM:
4766                 case TV_DIGGING:
4767                 {
4768                         if (k_ptr->to_h < 0) return (FALSE);
4769                         if (k_ptr->to_d < 0) return (FALSE);
4770                         return (TRUE);
4771                 }
4772
4773                 /* Ammo -- Arrows/Bolts are good */
4774                 case TV_BOLT:
4775                 case TV_ARROW:
4776                 {
4777                         return (TRUE);
4778                 }
4779
4780                 /* Books -- High level books are good (except Arcane books) */
4781                 case TV_LIFE_BOOK:
4782                 case TV_SORCERY_BOOK:
4783                 case TV_NATURE_BOOK:
4784                 case TV_CHAOS_BOOK:
4785                 case TV_DEATH_BOOK:
4786                 case TV_TRUMP_BOOK:
4787                 case TV_CRAFT_BOOK:
4788                 case TV_DAEMON_BOOK:
4789                 case TV_CRUSADE_BOOK:
4790                 case TV_MUSIC_BOOK:
4791                 case TV_HISSATSU_BOOK:
4792                 case TV_HEX_BOOK:
4793                 {
4794                         if (k_ptr->sval >= SV_BOOK_MIN_GOOD) return (TRUE);
4795                         return (FALSE);
4796                 }
4797
4798                 /* Rings -- Rings of Speed are good */
4799                 case TV_RING:
4800                 {
4801                         if (k_ptr->sval == SV_RING_SPEED) return (TRUE);
4802                         if (k_ptr->sval == SV_RING_LORDLY) return (TRUE);
4803                         return (FALSE);
4804                 }
4805
4806                 /* Amulets -- Amulets of the Magi and Resistance are good */
4807                 case TV_AMULET:
4808                 {
4809                         if (k_ptr->sval == SV_AMULET_THE_MAGI) return (TRUE);
4810                         if (k_ptr->sval == SV_AMULET_RESISTANCE) return (TRUE);
4811                         return (FALSE);
4812                 }
4813         }
4814
4815         /* Assume not good */
4816         return (FALSE);
4817 }
4818
4819 /*!
4820  * @brief 生成階に応じたベースアイテムの生成を行う。
4821  * Attempt to make an object (normal or good/great)
4822  * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4823  * @param mode オプションフラグ
4824  * @return 生成に成功したらTRUEを返す。
4825  * @details
4826  * This routine plays nasty games to generate the "special artifacts".\n
4827  * This routine uses "object_level" for the "generation level".\n
4828  * We assume that the given object has been "wiped".\n
4829  */
4830 bool make_object(object_type *j_ptr, BIT_FLAGS mode)
4831 {
4832         PERCENTAGE prob;
4833         DEPTH base;
4834
4835
4836         /* Chance of "special object" */
4837         prob = ((mode & AM_GOOD) ? 10 : 1000);
4838
4839         /* Base level for the object */
4840         base = ((mode & AM_GOOD) ? (object_level + 10) : object_level);
4841
4842
4843         /* Generate a special object, or a normal object */
4844         if (!one_in_(prob) || !make_artifact_special(j_ptr))
4845         {
4846                 KIND_OBJECT_IDX k_idx;
4847
4848                 /* Good objects */
4849                 if ((mode & AM_GOOD) && !get_obj_num_hook)
4850                 {
4851                         /* Activate restriction (if already specified, use that) */
4852                         get_obj_num_hook = kind_is_good;
4853                 }
4854
4855                 /* Restricted objects - prepare allocation table */
4856                 if (get_obj_num_hook) get_obj_num_prep();
4857
4858                 /* Pick a random object */
4859                 k_idx = get_obj_num(base);
4860
4861                 /* Restricted objects */
4862                 if (get_obj_num_hook)
4863                 {
4864                         /* Clear restriction */
4865                         get_obj_num_hook = NULL;
4866
4867                         /* Reset allocation table to default */
4868                         get_obj_num_prep();
4869                 }
4870
4871                 /* Handle failure */
4872                 if (!k_idx) return (FALSE);
4873
4874                 /* Prepare the object */
4875                 object_prep(j_ptr, k_idx);
4876         }
4877
4878         /* Apply magic (allow artifacts) */
4879         apply_magic(j_ptr, object_level, mode);
4880
4881         /* Hack -- generate multiple spikes/missiles */
4882         switch (j_ptr->tval)
4883         {
4884                 case TV_SPIKE:
4885                 case TV_SHOT:
4886                 case TV_ARROW:
4887                 case TV_BOLT:
4888                 {
4889                         if (!j_ptr->name1)
4890                                 j_ptr->number = (byte)damroll(6, 7);
4891                 }
4892         }
4893
4894         if (cheat_peek) object_mention(j_ptr);
4895
4896         /* Success */
4897         return (TRUE);
4898 }
4899
4900
4901 /*!
4902  * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
4903  * Attempt to place an object (normal or good/great) at the given location.
4904  * @param y 配置したいフロアのY座標
4905  * @param x 配置したいフロアのX座標
4906  * @param mode オプションフラグ
4907  * @return 生成に成功したらTRUEを返す。
4908  * @details
4909  * This routine plays nasty games to generate the "special artifacts".\n
4910  * This routine uses "object_level" for the "generation level".\n
4911  * This routine requires a clean floor grid destination.\n
4912  */
4913 void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
4914 {
4915         OBJECT_IDX o_idx;
4916
4917         /* Acquire grid */
4918         cave_type *c_ptr = &cave[y][x];
4919
4920         object_type forge;
4921         object_type *q_ptr;
4922
4923
4924         /* Paranoia -- check bounds */
4925         if (!in_bounds(y, x)) return;
4926
4927         /* Require floor space */
4928         if (!cave_drop_bold(y, x)) return;
4929
4930         /* Avoid stacking on other objects */
4931         if (c_ptr->o_idx) return;
4932
4933
4934         /* Get local object */
4935         q_ptr = &forge;
4936
4937         /* Wipe the object */
4938         object_wipe(q_ptr);
4939
4940         /* Make an object (if possible) */
4941         if (!make_object(q_ptr, mode)) return;
4942
4943
4944         /* Make an object */
4945         o_idx = o_pop();
4946
4947         /* Success */
4948         if (o_idx)
4949         {
4950                 object_type *o_ptr;
4951
4952                 /* Acquire object */
4953                 o_ptr = &o_list[o_idx];
4954
4955                 /* Structure Copy */
4956                 object_copy(o_ptr, q_ptr);
4957
4958                 /* Location */
4959                 o_ptr->iy = y;
4960                 o_ptr->ix = x;
4961
4962                 /* Build a stack */
4963                 o_ptr->next_o_idx = c_ptr->o_idx;
4964
4965                 /* Place the object */
4966                 c_ptr->o_idx = o_idx;
4967
4968                 /* Notice */
4969                 note_spot(y, x);
4970
4971                 /* Redraw */
4972                 lite_spot(y, x);
4973         }
4974         else
4975         {
4976                 /* Hack -- Preserve artifacts */
4977                 if (object_is_fixed_artifact(q_ptr))
4978                 {
4979                         a_info[q_ptr->name1].cur_num = 0;
4980                 }
4981         }
4982 }
4983
4984
4985 /*!
4986  * @brief 生成階に応じた財宝オブジェクトの生成を行う。
4987  * Make a treasure object
4988  * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4989  * @return 生成に成功したらTRUEを返す。
4990  * @details
4991  * The location must be a legal, clean, floor grid.
4992  */
4993 bool make_gold(object_type *j_ptr)
4994 {
4995         int i;
4996         s32b base;
4997
4998         /* Hack -- Pick a Treasure variety */
4999         i = ((randint1(object_level + 2) + 2) / 2) - 1;
5000
5001         /* Apply "extra" magic */
5002         if (one_in_(GREAT_OBJ))
5003         {
5004                 i += randint1(object_level + 1);
5005         }
5006
5007         /* Hack -- Creeping Coins only generate "themselves" */
5008         if (coin_type) i = coin_type;
5009
5010         /* Do not create "illegal" Treasure Types */
5011         if (i >= MAX_GOLD) i = MAX_GOLD - 1;
5012
5013         /* Prepare a gold object */
5014         object_prep(j_ptr, OBJ_GOLD_LIST + i);
5015
5016         /* Hack -- Base coin cost */
5017         base = k_info[OBJ_GOLD_LIST + i].cost;
5018
5019         /* Determine how much the treasure is "worth" */
5020         j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
5021
5022         /* Success */
5023         return (TRUE);
5024 }
5025
5026
5027 /*!
5028  * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
5029  * Places a treasure (Gold or Gems) at given location
5030  * @param y 配置したいフロアのY座標
5031  * @param x 配置したいフロアのX座標
5032  * @return 生成に成功したらTRUEを返す。
5033  * @details
5034  * The location must be a legal, clean, floor grid.
5035  */
5036 void place_gold(POSITION y, POSITION x)
5037 {
5038         OBJECT_IDX o_idx;
5039
5040         /* Acquire grid */
5041         cave_type *c_ptr = &cave[y][x];
5042
5043         object_type forge;
5044         object_type *q_ptr;
5045
5046
5047         /* Paranoia -- check bounds */
5048         if (!in_bounds(y, x)) return;
5049
5050         /* Require floor space */
5051         if (!cave_drop_bold(y, x)) return;
5052
5053         /* Avoid stacking on other objects */
5054         if (c_ptr->o_idx) return;
5055
5056
5057         /* Get local object */
5058         q_ptr = &forge;
5059
5060         /* Wipe the object */
5061         object_wipe(q_ptr);
5062
5063         /* Make some gold */
5064         if (!make_gold(q_ptr)) return;
5065
5066         /* Make an object */
5067         o_idx = o_pop();
5068
5069         /* Success */
5070         if (o_idx)
5071         {
5072                 object_type *o_ptr;
5073
5074                 /* Acquire object */
5075                 o_ptr = &o_list[o_idx];
5076
5077                 /* Copy the object */
5078                 object_copy(o_ptr, q_ptr);
5079
5080                 /* Save location */
5081                 o_ptr->iy = y;
5082                 o_ptr->ix = x;
5083
5084                 /* Build a stack */
5085                 o_ptr->next_o_idx = c_ptr->o_idx;
5086
5087                 /* Place the object */
5088                 c_ptr->o_idx = o_idx;
5089
5090                 /* Notice */
5091                 note_spot(y, x);
5092
5093                 /* Redraw */
5094                 lite_spot(y, x);
5095         }
5096 }
5097
5098
5099 /*!
5100  * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
5101  * Let an object fall to the ground at or near a location.
5102  * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
5103  * @param chance ドロップの成功率(%)
5104  * @param y 配置したいフロアのY座標
5105  * @param x 配置したいフロアのX座標
5106  * @return 生成に成功したらオブジェクトのIDを返す。
5107  * @details
5108  * The initial location is assumed to be "in_bounds()".\n
5109  *\n
5110  * This function takes a parameter "chance".  This is the percentage\n
5111  * chance that the item will "disappear" instead of drop.  If the object\n
5112  * has been thrown, then this is the chance of disappearance on contact.\n
5113  *\n
5114  * Hack -- this function uses "chance" to determine if it should produce\n
5115  * some form of "description" of the drop event (under the player).\n
5116  *\n
5117  * We check several locations to see if we can find a location at which\n
5118  * the object can combine, stack, or be placed.  Artifacts will try very\n
5119  * hard to be placed, including "teleporting" to a useful grid if needed.\n
5120  */
5121 OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
5122 {
5123         int i, k, d, s;
5124
5125         int bs, bn;
5126         POSITION by, bx;
5127         POSITION dy, dx;
5128         POSITION ty, tx = 0;
5129
5130         OBJECT_IDX o_idx = 0;
5131         OBJECT_IDX this_o_idx, next_o_idx = 0;
5132
5133         cave_type *c_ptr;
5134
5135         char o_name[MAX_NLEN];
5136
5137         bool flag = FALSE;
5138         bool done = FALSE;
5139
5140 #ifndef JP
5141         /* Extract plural */
5142         bool plural = (j_ptr->number != 1);
5143 #endif
5144
5145         /* Describe object */
5146         object_desc(o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
5147
5148
5149         /* Handle normal "breakage" */
5150         if (!object_is_artifact(j_ptr) && (randint0(100) < chance))
5151         {
5152 #ifdef JP
5153                 msg_format("%sは消えた。", o_name);
5154 #else
5155                 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
5156 #endif
5157                 /* Debug */
5158                 if (p_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
5159
5160                 /* Failure */
5161                 return (0);
5162         }
5163
5164
5165         /* Score */
5166         bs = -1;
5167
5168         /* Picker */
5169         bn = 0;
5170
5171         /* Default */
5172         by = y;
5173         bx = x;
5174
5175         /* Scan local grids */
5176         for (dy = -3; dy <= 3; dy++)
5177         {
5178                 /* Scan local grids */
5179                 for (dx = -3; dx <= 3; dx++)
5180                 {
5181                         bool comb = FALSE;
5182
5183                         /* Calculate actual distance */
5184                         d = (dy * dy) + (dx * dx);
5185
5186                         /* Ignore distant grids */
5187                         if (d > 10) continue;
5188
5189                         /* Location */
5190                         ty = y + dy;
5191                         tx = x + dx;
5192
5193                         /* Skip illegal grids */
5194                         if (!in_bounds(ty, tx)) continue;
5195
5196                         /* Require line of projection */
5197                         if (!projectable(y, x, ty, tx)) continue;
5198
5199                         /* Obtain grid */
5200                         c_ptr = &cave[ty][tx];
5201
5202                         /* Require floor space */
5203                         if (!cave_drop_bold(ty, tx)) continue;
5204
5205                         /* No objects */
5206                         k = 0;
5207
5208                         /* Scan objects in that grid */
5209                         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
5210                         {
5211                                 object_type *o_ptr;
5212
5213                                 /* Acquire object */
5214                                 o_ptr = &o_list[this_o_idx];
5215
5216                                 /* Acquire next object */
5217                                 next_o_idx = o_ptr->next_o_idx;
5218
5219                                 /* Check for possible combination */
5220                                 if (object_similar(o_ptr, j_ptr)) comb = TRUE;
5221
5222                                 /* Count objects */
5223                                 k++;
5224                         }
5225
5226                         /* Add new object */
5227                         if (!comb) k++;
5228
5229                         /* Paranoia */
5230                         if (k > 99) continue;
5231
5232                         /* Calculate score */
5233                         s = 1000 - (d + k * 5);
5234
5235                         /* Skip bad values */
5236                         if (s < bs) continue;
5237
5238                         /* New best value */
5239                         if (s > bs) bn = 0;
5240
5241                         /* Apply the randomizer to equivalent values */
5242                         if ((++bn >= 2) && !one_in_(bn)) continue;
5243
5244                         /* Keep score */
5245                         bs = s;
5246
5247                         /* Track it */
5248                         by = ty;
5249                         bx = tx;
5250
5251                         /* Okay */
5252                         flag = TRUE;
5253                 }
5254         }
5255
5256
5257         /* Handle lack of space */
5258         if (!flag && !object_is_artifact(j_ptr))
5259         {
5260 #ifdef JP
5261                 msg_format("%sは消えた。", o_name);
5262 #else
5263                 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
5264 #endif
5265
5266
5267                 /* Debug */
5268                 if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
5269
5270                 /* Failure */
5271                 return (0);
5272         }
5273
5274
5275         /* Find a grid */
5276         for (i = 0; !flag && (i < 1000); i++)
5277         {
5278                 /* Bounce around */
5279                 ty = rand_spread(by, 1);
5280                 tx = rand_spread(bx, 1);
5281
5282                 /* Verify location */
5283                 if (!in_bounds(ty, tx)) continue;
5284
5285                 /* Bounce to that location */
5286                 by = ty;
5287                 bx = tx;
5288
5289                 /* Require floor space */
5290                 if (!cave_drop_bold(by, bx)) continue;
5291
5292                 /* Okay */
5293                 flag = TRUE;
5294         }
5295
5296
5297         if (!flag)
5298         {
5299                 int candidates = 0, pick;
5300
5301                 for (ty = 1; ty < cur_hgt - 1; ty++)
5302                 {
5303                         for (tx = 1; tx < cur_wid - 1; tx++)
5304                         {
5305                                 /* A valid space found */
5306                                 if (cave_drop_bold(ty, tx)) candidates++;
5307                         }
5308                 }
5309
5310                 /* No valid place! */
5311                 if (!candidates)
5312                 {
5313 #ifdef JP
5314                         msg_format("%sは消えた。", o_name);
5315 #else
5316                         msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
5317 #endif
5318
5319                         /* Debug */
5320                         if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
5321
5322                         /* Mega-Hack -- preserve artifacts */
5323                         if (preserve_mode)
5324                         {
5325                                 /* Hack -- Preserve unknown artifacts */
5326                                 if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr))
5327                                 {
5328                                         /* Mega-Hack -- Preserve the artifact */
5329                                         a_info[j_ptr->name1].cur_num = 0;
5330                                 }
5331                         }
5332
5333                         /* Failure */
5334                         return 0;
5335                 }
5336
5337                 /* Choose a random one */
5338                 pick = randint1(candidates);
5339
5340                 for (ty = 1; ty < cur_hgt - 1; ty++)
5341                 {
5342                         for (tx = 1; tx < cur_wid - 1; tx++)
5343                         {
5344                                 if (cave_drop_bold(ty, tx))
5345                                 {
5346                                         pick--;
5347
5348                                         /* Is this a picked one? */
5349                                         if (!pick) break;
5350                                 }
5351                         }
5352
5353                         if (!pick) break;
5354                 }
5355
5356                 by = ty;
5357                 bx = tx;
5358         }
5359
5360
5361         /* Grid */
5362         c_ptr = &cave[by][bx];
5363
5364         /* Scan objects in that grid for combination */
5365         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
5366         {
5367                 object_type *o_ptr;
5368
5369                 /* Acquire object */
5370                 o_ptr = &o_list[this_o_idx];
5371
5372                 /* Acquire next object */
5373                 next_o_idx = o_ptr->next_o_idx;
5374
5375                 /* Check for combination */
5376                 if (object_similar(o_ptr, j_ptr))
5377                 {
5378                         /* Combine the items */
5379                         object_absorb(o_ptr, j_ptr);
5380
5381                         /* Success */
5382                         done = TRUE;
5383
5384                         break;
5385                 }
5386         }
5387
5388         /* Get new object */
5389         if (!done) o_idx = o_pop();
5390
5391         /* Failure */
5392         if (!done && !o_idx)
5393         {
5394 #ifdef JP
5395                 msg_format("%sは消えた。", o_name);
5396 #else
5397                 msg_format("The %s disappear%s.",
5398                            o_name, (plural ? "" : "s"));
5399 #endif
5400
5401
5402                 /* Debug */
5403                 if (p_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
5404
5405                 /* Hack -- Preserve artifacts */
5406                 if (object_is_fixed_artifact(j_ptr))
5407                 {
5408                         a_info[j_ptr->name1].cur_num = 0;
5409                 }
5410
5411                 /* Failure */
5412                 return (0);
5413         }
5414
5415         /* Stack */
5416         if (!done)
5417         {
5418                 /* Structure copy */
5419                 object_copy(&o_list[o_idx], j_ptr);
5420
5421                 /* Access new object */
5422                 j_ptr = &o_list[o_idx];
5423
5424                 /* Locate */
5425                 j_ptr->iy = by;
5426                 j_ptr->ix = bx;
5427
5428                 /* No monster */
5429                 j_ptr->held_m_idx = 0;
5430
5431                 /* Build a stack */
5432                 j_ptr->next_o_idx = c_ptr->o_idx;
5433
5434                 /* Place the object */
5435                 c_ptr->o_idx = o_idx;
5436
5437                 /* Success */
5438                 done = TRUE;
5439         }
5440
5441         /* Note the spot */
5442         note_spot(by, bx);
5443
5444         /* Draw the spot */
5445         lite_spot(by, bx);
5446
5447         sound(SOUND_DROP);
5448
5449         /* Mega-Hack -- no message if "dropped" by player */
5450         /* Message when an object falls under the player */
5451         if (chance && player_bold(by, bx))
5452         {
5453                 msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
5454         }
5455
5456         /* XXX XXX XXX */
5457
5458         /* Result */
5459         return (o_idx);
5460 }
5461
5462
5463 /*!
5464  * @brief 獲得ドロップを行う。
5465  * Scatter some "great" objects near the player
5466  * @param y1 配置したいフロアのY座標
5467  * @param x1 配置したいフロアのX座標
5468  * @param num 獲得の処理回数
5469  * @param great TRUEならば必ず高級品以上を落とす
5470  * @param special TRUEならば必ず特別品を落とす
5471  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
5472  * @return なし
5473  */
5474 void acquirement(POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
5475 {
5476         object_type *i_ptr;
5477         object_type object_type_body;
5478         BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : 0L) | (special ? AM_SPECIAL : 0L) ;
5479
5480         /* Acquirement */
5481         while (num--)
5482         {
5483                 /* Get local object */
5484                 i_ptr = &object_type_body;
5485
5486                 /* Wipe the object */
5487                 object_wipe(i_ptr);
5488
5489                 /* Make a good (or great) object (if possible) */
5490                 if (!make_object(i_ptr, mode)) continue;
5491
5492                 if (known)
5493                 {
5494                         object_aware(i_ptr);
5495                         object_known(i_ptr);
5496                 }
5497
5498                 /* Drop the object */
5499                 (void)drop_near(i_ptr, -1, y1, x1);
5500         }
5501 }
5502
5503 /*
5504  * Scatter some "amusing" objects near the player
5505  */
5506
5507 #define AMS_NOTHING   0x00 /* No restriction */
5508 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
5509 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
5510 #define AMS_MULTIPLE  0x04 /* Drop 1-3 objects for one type */
5511 #define AMS_PILE      0x08 /* Drop 1-99 pile objects for one type */
5512
5513 typedef struct
5514 {
5515         OBJECT_TYPE_VALUE tval;
5516         OBJECT_SUBTYPE_VALUE sval;
5517         PERCENTAGE prob;
5518         byte flag;
5519 } amuse_type;
5520
5521 amuse_type amuse_info[] =
5522 {
5523         { TV_BOTTLE, SV_ANY, 5, AMS_NOTHING },
5524         { TV_JUNK, SV_ANY, 3, AMS_MULTIPLE },
5525         { TV_SPIKE, SV_ANY, 10, AMS_PILE },
5526         { TV_STATUE, SV_ANY, 15, AMS_NOTHING },
5527         { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE },
5528         { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE },
5529         { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
5530         { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING },
5531         { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, //Fishing Pole of Taikobo
5532         { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, //Broken Dagger of Magician
5533         { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING },
5534         { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING },
5535         { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
5536
5537         { 0, 0, 0 }
5538 };
5539
5540 /*!
5541  * @brief 誰得ドロップを行う。
5542  * @param y1 配置したいフロアのY座標
5543  * @param x1 配置したいフロアのX座標
5544  * @param num 誰得の処理回数
5545  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
5546  * @return なし
5547  */
5548 void amusement(POSITION y1, POSITION x1, int num, bool known)
5549 {
5550         object_type *i_ptr;
5551         object_type object_type_body;
5552         int n, t = 0;
5553
5554         for (n = 0; amuse_info[n].tval != 0; n++)
5555         {
5556                 t += amuse_info[n].prob;
5557         }
5558
5559         /* Acquirement */
5560         while (num)
5561         {
5562                 int i;
5563                 KIND_OBJECT_IDX k_idx;
5564                 ARTIFACT_IDX a_idx = 0;
5565                 int r = randint0(t);
5566                 bool insta_art, fixed_art;
5567
5568                 for (i = 0; ; i++)
5569                 {
5570                         r -= amuse_info[i].prob;
5571                         if (r <= 0) break;
5572                 }
5573
5574                 /* Get local object */
5575                 i_ptr = &object_type_body;
5576
5577                 /* Wipe the object */
5578                 object_wipe(i_ptr);
5579
5580                 /* Wipe the object */
5581                 k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
5582
5583                 /* Paranoia - reroll if nothing */
5584                 if (!k_idx) continue;
5585
5586                 /* Search an artifact index if need */
5587                 insta_art = (k_info[k_idx].gen_flags & TRG_INSTA_ART);
5588                 fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
5589
5590                 if (insta_art || fixed_art)
5591                 {
5592                         for (a_idx = 1; a_idx < max_a_idx; a_idx++)
5593                         {
5594                                 if (insta_art && !(a_info[a_idx].gen_flags & TRG_INSTA_ART)) continue;
5595                                 if (a_info[a_idx].tval != k_info[k_idx].tval) continue;
5596                                 if (a_info[a_idx].sval != k_info[k_idx].sval) continue;
5597                                 if (a_info[a_idx].cur_num > 0) continue;
5598                                 break;
5599                         }
5600
5601                         if (a_idx >= max_a_idx) continue;
5602                 }
5603
5604                 /* Make an object (if possible) */
5605                 object_prep(i_ptr, k_idx);
5606                 if (a_idx) i_ptr->name1 = a_idx;
5607                 apply_magic(i_ptr, 1, AM_NO_FIXED_ART);
5608
5609                 if (amuse_info[i].flag & AMS_NO_UNIQUE)
5610                 {
5611                         if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE) continue;
5612                 }
5613
5614                 if (amuse_info[i].flag & AMS_MULTIPLE) i_ptr->number = randint1(3);
5615                 if (amuse_info[i].flag & AMS_PILE) i_ptr->number = randint1(99);
5616
5617                 if (known)
5618                 {
5619                         object_aware(i_ptr);
5620                         object_known(i_ptr);
5621                 }
5622
5623                 /* Paranoia - reroll if nothing */
5624                 if (!(i_ptr->k_idx)) continue;
5625
5626                 /* Drop the object */
5627                 (void)drop_near(i_ptr, -1, y1, x1);
5628
5629                 num--;
5630         }
5631 }
5632
5633
5634 /*!
5635  * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
5636  * Describe the charges on an item in the inventory.
5637  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
5638  * @return なし
5639  */
5640 void inven_item_charges(INVENTORY_IDX item)
5641 {
5642         object_type *o_ptr = &inventory[item];
5643
5644         /* Require staff/wand */
5645         if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5646
5647         /* Require known item */
5648         if (!object_is_known(o_ptr)) return;
5649
5650 #ifdef JP
5651         if (o_ptr->pval <= 0)
5652         {
5653                 msg_print("もう魔力が残っていない。");
5654         }
5655         else
5656         {
5657                 msg_format("あと %d 回分の魔力が残っている。", o_ptr->pval);
5658         }
5659 #else
5660         /* Multiple charges */
5661         if (o_ptr->pval != 1)
5662         {
5663                 /* Print a message */
5664                 msg_format("You have %d charges remaining.", o_ptr->pval);
5665         }
5666
5667         /* Single charge */
5668         else
5669         {
5670                 /* Print a message */
5671                 msg_format("You have %d charge remaining.", o_ptr->pval);
5672         }
5673 #endif
5674
5675 }
5676
5677 /*!
5678  * @brief アイテムの残り所持数メッセージを表示する /
5679  * Describe an item in the inventory.
5680  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
5681  * @return なし
5682  */
5683 void inven_item_describe(INVENTORY_IDX item)
5684 {
5685         object_type *o_ptr = &inventory[item];
5686         char        o_name[MAX_NLEN];
5687
5688         /* Get a description */
5689         object_desc(o_name, o_ptr, 0);
5690
5691         /* Print a message */
5692 #ifdef JP
5693         /* "no more" の場合はこちらで表示する */
5694         if (o_ptr->number <= 0)
5695         {
5696                 /*FIRST*//*ここはもう通らないかも */
5697                 msg_format("もう%sを持っていない。", o_name);
5698         }
5699         else
5700         {
5701                 /* アイテム名を英日切り替え機能対応 */
5702                 msg_format("まだ %sを持っている。", o_name);
5703         }
5704 #else
5705         msg_format("You have %s.", o_name);
5706 #endif
5707
5708 }
5709
5710 /*!
5711  * @brief アイテムの残り所持数メッセージを表示する /
5712  * Increase the "number" of an item in the inventory
5713  * @param item 所持数を増やしたいプレイヤーのアイテム所持スロット
5714  * @param num 増やしたい量
5715  * @return なし
5716  */
5717 void inven_item_increase(INVENTORY_IDX item, int num)
5718 {
5719         object_type *o_ptr = &inventory[item];
5720
5721         /* Apply */
5722         num += o_ptr->number;
5723
5724         /* Bounds check */
5725         if (num > 255) num = 255;
5726         else if (num < 0) num = 0;
5727
5728         /* Un-apply */
5729         num -= (ITEM_NUMBER)o_ptr->number;
5730
5731         /* Change the number and weight */
5732         if (num)
5733         {
5734                 /* Add the number */
5735                 o_ptr->number += num;
5736
5737                 /* Add the weight */
5738                 p_ptr->total_weight += (num * o_ptr->weight);
5739
5740                 /* Recalculate bonuses */
5741                 p_ptr->update |= (PU_BONUS);
5742
5743                 /* Recalculate mana XXX */
5744                 p_ptr->update |= (PU_MANA);
5745
5746                 /* Combine the pack */
5747                 p_ptr->notice |= (PN_COMBINE);
5748
5749                 /* Window stuff */
5750                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
5751
5752                 /* Hack -- Clear temporary elemental brands if player takes off weapons */
5753                 if (!o_ptr->number && p_ptr->ele_attack)
5754                 {
5755                         if ((item == INVEN_RARM) || (item == INVEN_LARM))
5756                         {
5757                                 if (!buki_motteruka(INVEN_RARM + INVEN_LARM - item))
5758                                 {
5759                                         /* Clear all temporary elemental brands */
5760                                         set_ele_attack(0, 0);
5761                                 }
5762                         }
5763                 }
5764         }
5765 }
5766
5767 /*!
5768  * @brief 所持アイテムスロットから所持数のなくなったアイテムを消去する /
5769  * Erase an inventory slot if it has no more items
5770  * @param item 消去したいプレイヤーのアイテム所持スロット
5771  * @return なし
5772  */
5773 void inven_item_optimize(INVENTORY_IDX item)
5774 {
5775         object_type *o_ptr = &inventory[item];
5776
5777         /* Only optimize real items */
5778         if (!o_ptr->k_idx) return;
5779
5780         /* Only optimize empty items */
5781         if (o_ptr->number) return;
5782
5783         /* The item is in the pack */
5784         if (item < INVEN_RARM)
5785         {
5786                 int i;
5787
5788                 /* One less item */
5789                 inven_cnt--;
5790
5791                 /* Slide everything down */
5792                 for (i = item; i < INVEN_PACK; i++)
5793                 {
5794                         /* Structure copy */
5795                         inventory[i] = inventory[i+1];
5796                 }
5797
5798                 /* Erase the "final" slot */
5799                 object_wipe(&inventory[i]);
5800
5801                 /* Window stuff */
5802                 p_ptr->window |= (PW_INVEN);
5803         }
5804
5805         /* The item is being wielded */
5806         else
5807         {
5808                 /* One less item */
5809                 equip_cnt--;
5810
5811                 /* Erase the empty slot */
5812                 object_wipe(&inventory[item]);
5813
5814                 /* Recalculate bonuses */
5815                 p_ptr->update |= (PU_BONUS);
5816
5817                 /* Recalculate torch */
5818                 p_ptr->update |= (PU_TORCH);
5819
5820                 /* Recalculate mana XXX */
5821                 p_ptr->update |= (PU_MANA);
5822
5823                 /* Window stuff */
5824                 p_ptr->window |= (PW_EQUIP);
5825         }
5826
5827         /* Window stuff */
5828         p_ptr->window |= (PW_SPELL);
5829 }
5830
5831 /*!
5832  * @brief 床上の魔道具の残り残量メッセージを表示する /
5833  * Describe the charges on an item on the floor.
5834  * @param item メッセージの対象にしたいアイテム所持スロット
5835  * @return なし
5836  */
5837 void floor_item_charges(INVENTORY_IDX item)
5838 {
5839         object_type *o_ptr = &o_list[item];
5840
5841         /* Require staff/wand */
5842         if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5843
5844         /* Require known item */
5845         if (!object_is_known(o_ptr)) return;
5846
5847 #ifdef JP
5848         if (o_ptr->pval <= 0)
5849         {
5850                 msg_print("この床上のアイテムは、もう魔力が残っていない。");
5851         }
5852         else
5853         {
5854                 msg_format("この床上のアイテムは、あと %d 回分の魔力が残っている。", o_ptr->pval);
5855         }
5856 #else
5857         /* Multiple charges */
5858         if (o_ptr->pval != 1)
5859         {
5860                 /* Print a message */
5861                 msg_format("There are %d charges remaining.", o_ptr->pval);
5862         }
5863
5864         /* Single charge */
5865         else
5866         {
5867                 /* Print a message */
5868                 msg_format("There is %d charge remaining.", o_ptr->pval);
5869         }
5870 #endif
5871
5872 }
5873
5874 /*!
5875  * @brief 床上のアイテムの残り数メッセージを表示する /
5876  * Describe the charges on an item on the floor.
5877  * @param item メッセージの対象にしたいアイテム所持スロット
5878  * @return なし
5879  */
5880 void floor_item_describe(INVENTORY_IDX item)
5881 {
5882         object_type *o_ptr = &o_list[item];
5883         char        o_name[MAX_NLEN];
5884
5885         /* Get a description */
5886         object_desc(o_name, o_ptr, 0);
5887
5888         /* Print a message */
5889 #ifdef JP
5890         /* "no more" の場合はこちらで表示を分ける */
5891         if (o_ptr->number <= 0)
5892         {
5893                 msg_format("床上には、もう%sはない。", o_name);
5894         }
5895         else
5896         {
5897                 msg_format("床上には、まだ %sがある。", o_name);
5898         }
5899 #else
5900         msg_format("You see %s.", o_name);
5901 #endif
5902
5903 }
5904
5905
5906 /*!
5907  * @brief 床上のアイテムの数を増やす /
5908  * Increase the "number" of an item on the floor
5909  * @param item 増やしたいアイテムの所持スロット
5910  * @param num 増やしたいアイテムの数
5911  * @return なし
5912  */
5913 void floor_item_increase(INVENTORY_IDX item, int num)
5914 {
5915         object_type *o_ptr = &o_list[item];
5916
5917         /* Apply */
5918         num += o_ptr->number;
5919
5920         /* Bounds check */
5921         if (num > 255) num = 255;
5922         else if (num < 0) num = 0;
5923
5924         /* Un-apply */
5925         num -= (int)o_ptr->number;
5926
5927         /* Change the number */
5928         o_ptr->number += (ITEM_NUMBER)num;
5929 }
5930
5931
5932 /*!
5933  * @brief 床上の数の無くなったアイテムスロットを消去する /
5934  * Optimize an item on the floor (destroy "empty" items)
5935  * @param item 消去したいアイテムの所持スロット
5936  * @return なし
5937  */
5938 void floor_item_optimize(INVENTORY_IDX item)
5939 {
5940         object_type *o_ptr = &o_list[item];
5941
5942         /* Paranoia -- be sure it exists */
5943         if (!o_ptr->k_idx) return;
5944
5945         /* Only optimize empty items */
5946         if (o_ptr->number) return;
5947
5948         /* Delete the object */
5949         delete_object_idx(item);
5950 }
5951
5952
5953 /*!
5954  * @brief アイテムを拾う際にザックから溢れずに済むかを判定する /
5955  * Check if we have space for an item in the pack without overflow
5956  * @param o_ptr 拾いたいオブジェクトの構造体参照ポインタ
5957  * @return 溢れずに済むならTRUEを返す
5958  */
5959 bool inven_carry_okay(object_type *o_ptr)
5960 {
5961         int j;
5962
5963         /* Empty slot? */
5964         if (inven_cnt < INVEN_PACK) return (TRUE);
5965
5966         /* Similar slot? */
5967         for (j = 0; j < INVEN_PACK; j++)
5968         {
5969                 object_type *j_ptr = &inventory[j];
5970
5971                 /* Skip non-objects */
5972                 if (!j_ptr->k_idx) continue;
5973
5974                 /* Check if the two items can be combined */
5975                 if (object_similar(j_ptr, o_ptr)) return (TRUE);
5976         }
5977
5978         /* Nope */
5979         return (FALSE);
5980 }
5981
5982 /*!
5983  * @brief オブジェクトを定義された基準に従いソートするための関数 /
5984  * Check if we have space for an item in the pack without overflow
5985  * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
5986  * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
5987  * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
5988  * @return o_ptrの方が上位ならばTRUEを返す。
5989  */
5990 bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
5991 {
5992         int o_type, j_type;
5993
5994         /* Use empty slots */
5995         if (!j_ptr->k_idx) return TRUE;
5996
5997         /* Hack -- readable books always come first */
5998         if ((o_ptr->tval == REALM1_BOOK) &&
5999             (j_ptr->tval != REALM1_BOOK)) return TRUE;
6000         if ((j_ptr->tval == REALM1_BOOK) &&
6001             (o_ptr->tval != REALM1_BOOK)) return FALSE;
6002
6003         if ((o_ptr->tval == REALM2_BOOK) &&
6004             (j_ptr->tval != REALM2_BOOK)) return TRUE;
6005         if ((j_ptr->tval == REALM2_BOOK) &&
6006             (o_ptr->tval != REALM2_BOOK)) return FALSE;
6007
6008         /* Objects sort by decreasing type */
6009         if (o_ptr->tval > j_ptr->tval) return TRUE;
6010         if (o_ptr->tval < j_ptr->tval) return FALSE;
6011
6012         /* Non-aware (flavored) items always come last */
6013         /* Can happen in the home */
6014         if (!object_is_aware(o_ptr)) return FALSE;
6015         if (!object_is_aware(j_ptr)) return TRUE;
6016
6017         /* Objects sort by increasing sval */
6018         if (o_ptr->sval < j_ptr->sval) return TRUE;
6019         if (o_ptr->sval > j_ptr->sval) return FALSE;
6020
6021         /* Unidentified objects always come last */
6022         /* Objects in the home can be unknown */
6023         if (!object_is_known(o_ptr)) return FALSE;
6024         if (!object_is_known(j_ptr)) return TRUE;
6025
6026         /* Fixed artifacts, random artifacts and ego items */
6027         if (object_is_fixed_artifact(o_ptr)) o_type = 3;
6028         else if (o_ptr->art_name) o_type = 2;
6029         else if (object_is_ego(o_ptr)) o_type = 1;
6030         else o_type = 0;
6031
6032         if (object_is_fixed_artifact(j_ptr)) j_type = 3;
6033         else if (j_ptr->art_name) j_type = 2;
6034         else if (object_is_ego(j_ptr)) j_type = 1;
6035         else j_type = 0;
6036
6037         if (o_type < j_type) return TRUE;
6038         if (o_type > j_type) return FALSE;
6039
6040         switch (o_ptr->tval)
6041         {
6042         case TV_FIGURINE:
6043         case TV_STATUE:
6044         case TV_CORPSE:
6045         case TV_CAPTURE:
6046                 if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
6047                 if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
6048                 return FALSE;
6049
6050         case TV_SHOT:
6051         case TV_ARROW:
6052         case TV_BOLT:
6053                 /* Objects sort by increasing hit/damage bonuses */
6054                 if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
6055                 if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
6056                 break;
6057
6058         /* Hack:  otherwise identical rods sort by
6059         increasing recharge time --dsb */
6060         case TV_ROD:
6061                 if (o_ptr->pval < j_ptr->pval) return TRUE;
6062                 if (o_ptr->pval > j_ptr->pval) return FALSE;
6063                 break;
6064         }
6065
6066         /* Objects sort by decreasing value */
6067         return o_value > object_value(j_ptr);
6068 }
6069
6070
6071 /*!
6072  * @brief オブジェクトをプレイヤーが拾って所持スロットに納めるメインルーチン /
6073  * Add an item to the players inventory, and return the slot used.
6074  * @param o_ptr 拾うオブジェクトの構造体参照ポインタ
6075  * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
6076  * @details
6077  * If the new item can combine with an existing item in the inventory,\n
6078  * it will do so, using "object_similar()" and "object_absorb()", else,\n
6079  * the item will be placed into the "proper" location in the inventory.\n
6080  *\n
6081  * This function can be used to "over-fill" the player's pack, but only\n
6082  * once, and such an action must trigger the "overflow" code immediately.\n
6083  * Note that when the pack is being "over-filled", the new item must be\n
6084  * placed into the "overflow" slot, and the "overflow" must take place\n
6085  * before the pack is reordered, but (optionally) after the pack is\n
6086  * combined.  This may be tricky.  See "dungeon.c" for info.\n
6087  *\n
6088  * Note that this code must remove any location/stack information\n
6089  * from the object once it is placed into the inventory.\n
6090  */
6091 s16b inven_carry(object_type *o_ptr)
6092 {
6093         INVENTORY_IDX i, j, k;
6094         INVENTORY_IDX n = -1;
6095
6096         object_type *j_ptr;
6097
6098
6099         /* Check for combining */
6100         for (j = 0; j < INVEN_PACK; j++)
6101         {
6102                 j_ptr = &inventory[j];
6103
6104                 /* Skip non-objects */
6105                 if (!j_ptr->k_idx) continue;
6106
6107                 /* Hack -- track last item */
6108                 n = j;
6109
6110                 /* Check if the two items can be combined */
6111                 if (object_similar(j_ptr, o_ptr))
6112                 {
6113                         /* Combine the items */
6114                         object_absorb(j_ptr, o_ptr);
6115
6116                         /* Increase the weight */
6117                         p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
6118
6119                         /* Recalculate bonuses */
6120                         p_ptr->update |= (PU_BONUS);
6121
6122                         /* Window stuff */
6123                         p_ptr->window |= (PW_INVEN);
6124
6125                         /* Success */
6126                         return (j);
6127                 }
6128         }
6129
6130
6131         /* Paranoia */
6132         if (inven_cnt > INVEN_PACK) return (-1);
6133
6134         /* Find an empty slot */
6135         for (j = 0; j <= INVEN_PACK; j++)
6136         {
6137                 j_ptr = &inventory[j];
6138
6139                 /* Use it if found */
6140                 if (!j_ptr->k_idx) break;
6141         }
6142
6143         /* Use that slot */
6144         i = j;
6145
6146
6147         /* Reorder the pack */
6148         if (i < INVEN_PACK)
6149         {
6150                 /* Get the "value" of the item */
6151                 s32b o_value = object_value(o_ptr);
6152
6153                 /* Scan every occupied slot */
6154                 for (j = 0; j < INVEN_PACK; j++)
6155                 {
6156                         if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
6157                 }
6158
6159                 /* Use that slot */
6160                 i = j;
6161
6162                 /* Slide objects */
6163                 for (k = n; k >= i; k--)
6164                 {
6165                         /* Hack -- Slide the item */
6166                         object_copy(&inventory[k+1], &inventory[k]);
6167                 }
6168
6169                 /* Wipe the empty slot */
6170                 object_wipe(&inventory[i]);
6171         }
6172
6173
6174         /* Copy the item */
6175         object_copy(&inventory[i], o_ptr);
6176
6177         /* Access new object */
6178         j_ptr = &inventory[i];
6179
6180         /* Forget stack */
6181         j_ptr->next_o_idx = 0;
6182
6183         /* Forget monster */
6184         j_ptr->held_m_idx = 0;
6185
6186         /* Forget location */
6187         j_ptr->iy = j_ptr->ix = 0;
6188
6189         /* Player touches it, and no longer marked */
6190         j_ptr->marked = OM_TOUCHED;
6191
6192         /* Increase the weight */
6193         p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
6194
6195         /* Count the items */
6196         inven_cnt++;
6197
6198         /* Recalculate bonuses */
6199         p_ptr->update |= (PU_BONUS);
6200
6201         /* Combine and Reorder pack */
6202         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
6203
6204         /* Window stuff */
6205         p_ptr->window |= (PW_INVEN);
6206
6207         /* Return the slot */
6208         return (i);
6209 }
6210
6211
6212 /*!
6213  * @brief 装備スロットからオブジェクトを外すメインルーチン /
6214  * Take off (some of) a non-cursed equipment item
6215  * @param item オブジェクトを外したい所持テーブルのID
6216  * @param amt 外したい個数
6217  * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
6218  * @details
6219  * Note that only one item at a time can be wielded per slot.\n
6220  * Note that taking off an item when "full" may cause that item\n
6221  * to fall to the ground.\n
6222  * Return the inventory slot into which the item is placed.\n
6223  */
6224 INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
6225 {
6226         INVENTORY_IDX slot;
6227
6228         object_type forge;
6229         object_type *q_ptr;
6230
6231         object_type *o_ptr;
6232
6233         cptr act;
6234
6235         char o_name[MAX_NLEN];
6236
6237
6238         /* Get the item to take off */
6239         o_ptr = &inventory[item];
6240
6241         /* Paranoia */
6242         if (amt <= 0) return (-1);
6243
6244         /* Verify */
6245         if (amt > o_ptr->number) amt = o_ptr->number;
6246
6247         /* Get local object */
6248         q_ptr = &forge;
6249
6250         /* Obtain a local object */
6251         object_copy(q_ptr, o_ptr);
6252
6253         /* Modify quantity */
6254         q_ptr->number = amt;
6255
6256         /* Describe the object */
6257         object_desc(o_name, q_ptr, 0);
6258
6259         /* Took off weapon */
6260         if (((item == INVEN_RARM) || (item == INVEN_LARM)) &&
6261             object_is_melee_weapon(o_ptr))
6262         {
6263                 act = _("を装備からはずした", "You were wielding");
6264         }
6265
6266         /* Took off bow */
6267         else if (item == INVEN_BOW)
6268         {
6269                 act = _("を装備からはずした", "You were holding");
6270         }
6271
6272         /* Took off light */
6273         else if (item == INVEN_LITE)
6274         {
6275                 act = _("を光源からはずした", "You were holding");
6276         }
6277
6278         /* Took off something */
6279         else
6280         {
6281                 act = _("を装備からはずした", "You were wearing");
6282         }
6283
6284         /* Modify, Optimize */
6285         inven_item_increase(item, -amt);
6286         inven_item_optimize(item);
6287
6288         /* Carry the object */
6289         slot = inven_carry(q_ptr);
6290
6291 #ifdef JP
6292         msg_format("%s(%c)%s。", o_name, index_to_label(slot), act);
6293 #else
6294         msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
6295 #endif
6296
6297
6298         /* Return slot */
6299         return (slot);
6300 }
6301
6302
6303 /*!
6304  * @brief 所持スロットから床下にオブジェクトを落とすメインルーチン /
6305  * Drop (some of) a non-cursed inventory/equipment item
6306  * @param item 所持テーブルのID
6307  * @param amt 落としたい個数
6308  * @return なし
6309  * @details
6310  * The object will be dropped "near" the current location
6311  */
6312 void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
6313 {
6314         object_type forge;
6315         object_type *q_ptr;
6316         object_type *o_ptr;
6317
6318         char o_name[MAX_NLEN];
6319
6320
6321         /* Access original object */
6322         o_ptr = &inventory[item];
6323
6324         /* Error check */
6325         if (amt <= 0) return;
6326
6327         /* Not too many */
6328         if (amt > o_ptr->number) amt = o_ptr->number;
6329
6330
6331         /* Take off equipment */
6332         if (item >= INVEN_RARM)
6333         {
6334                 /* Take off first */
6335                 item = inven_takeoff(item, amt);
6336
6337                 /* Access original object */
6338                 o_ptr = &inventory[item];
6339         }
6340
6341
6342         /* Get local object */
6343         q_ptr = &forge;
6344
6345         /* Obtain local object */
6346         object_copy(q_ptr, o_ptr);
6347
6348         /* Distribute charges of wands or rods */
6349         distribute_charges(o_ptr, q_ptr, amt);
6350
6351         /* Modify quantity */
6352         q_ptr->number = amt;
6353
6354         /* Describe local object */
6355         object_desc(o_name, q_ptr, 0);
6356
6357         msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(item));
6358
6359         /* Drop it near the player */
6360         (void)drop_near(q_ptr, 0, p_ptr->y, p_ptr->x);
6361
6362         /* Modify, Describe, Optimize */
6363         inven_item_increase(item, -amt);
6364         inven_item_describe(item);
6365         inven_item_optimize(item);
6366 }
6367
6368
6369 /*!
6370  * @brief プレイヤーの所持スロットに存在するオブジェクトをまとめなおす /
6371  * Combine items in the pack
6372  * @return なし
6373  * @details
6374  * Note special handling of the "overflow" slot
6375  */
6376 void combine_pack(void)
6377 {
6378         int             i, j, k;
6379         object_type     *o_ptr;
6380         object_type     *j_ptr;
6381         bool            flag = FALSE, combined;
6382
6383         do
6384         {
6385                 combined = FALSE;
6386
6387                 /* Combine the pack (backwards) */
6388                 for (i = INVEN_PACK; i > 0; i--)
6389                 {
6390                         /* Get the item */
6391                         o_ptr = &inventory[i];
6392
6393                         /* Skip empty items */
6394                         if (!o_ptr->k_idx) continue;
6395
6396                         /* Scan the items above that item */
6397                         for (j = 0; j < i; j++)
6398                         {
6399                                 int max_num;
6400
6401                                 /* Get the item */
6402                                 j_ptr = &inventory[j];
6403
6404                                 /* Skip empty items */
6405                                 if (!j_ptr->k_idx) continue;
6406
6407                                 /*
6408                                  * Get maximum number of the stack if these
6409                                  * are similar, get zero otherwise.
6410                                  */
6411                                 max_num = object_similar_part(j_ptr, o_ptr);
6412
6413                                 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
6414                                 if (max_num && j_ptr->number < max_num)
6415                                 {
6416                                         if (o_ptr->number + j_ptr->number <= max_num)
6417                                         {
6418                                                 /* Take note */
6419                                                 flag = TRUE;
6420
6421                                                 /* Add together the item counts */
6422                                                 object_absorb(j_ptr, o_ptr);
6423
6424                                                 /* One object is gone */
6425                                                 inven_cnt--;
6426
6427                                                 /* Slide everything down */
6428                                                 for (k = i; k < INVEN_PACK; k++)
6429                                                 {
6430                                                         /* Structure copy */
6431                                                         inventory[k] = inventory[k+1];
6432                                                 }
6433
6434                                                 /* Erase the "final" slot */
6435                                                 object_wipe(&inventory[k]);
6436                                         }
6437                                         else
6438                                         {
6439                                                 int old_num = o_ptr->number;
6440                                                 int remain = j_ptr->number + o_ptr->number - max_num;
6441 #if 0
6442                                                 o_ptr->number -= remain;
6443 #endif
6444                                                 /* Add together the item counts */
6445                                                 object_absorb(j_ptr, o_ptr);
6446
6447                                                 o_ptr->number = remain;
6448
6449                                                 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
6450                                                 if (o_ptr->tval == TV_ROD)
6451                                                 {
6452                                                         o_ptr->pval =  o_ptr->pval * remain / old_num;
6453                                                         o_ptr->timeout = o_ptr->timeout * remain / old_num;
6454                                                 }
6455
6456                                                 /* Hack -- if wands are stacking, combine the charges. -LM- */
6457                                                 if (o_ptr->tval == TV_WAND)
6458                                                 {
6459                                                         o_ptr->pval = o_ptr->pval * remain / old_num;
6460                                                 }
6461                                         }
6462
6463                                         /* Window stuff */
6464                                         p_ptr->window |= (PW_INVEN);
6465
6466                                         /* Take note */
6467                                         combined = TRUE;
6468
6469                                         break;
6470                                 }
6471                         }
6472                 }
6473         }
6474         while (combined);
6475
6476         if (flag) msg_print(_("ザックの中のアイテムをまとめ直した。", "You combine some items in your pack."));
6477 }
6478
6479 /*!
6480  * @brief プレイヤーの所持スロットに存在するオブジェクトを並び替える /
6481  * Reorder items in the pack
6482  * @return なし
6483  * @details
6484  * Note special handling of the "overflow" slot
6485  */
6486 void reorder_pack(void)
6487 {
6488         int             i, j, k;
6489         s32b            o_value;
6490         object_type     forge;
6491         object_type     *q_ptr;
6492         object_type     *o_ptr;
6493         bool            flag = FALSE;
6494
6495
6496         /* Re-order the pack (forwards) */
6497         for (i = 0; i < INVEN_PACK; i++)
6498         {
6499                 /* Mega-Hack -- allow "proper" over-flow */
6500                 if ((i == INVEN_PACK) && (inven_cnt == INVEN_PACK)) break;
6501
6502                 /* Get the item */
6503                 o_ptr = &inventory[i];
6504
6505                 /* Skip empty slots */
6506                 if (!o_ptr->k_idx) continue;
6507
6508                 /* Get the "value" of the item */
6509                 o_value = object_value(o_ptr);
6510
6511                 /* Scan every occupied slot */
6512                 for (j = 0; j < INVEN_PACK; j++)
6513                 {
6514                         if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
6515                 }
6516
6517                 /* Never move down */
6518                 if (j >= i) continue;
6519
6520                 /* Take note */
6521                 flag = TRUE;
6522
6523                 /* Get local object */
6524                 q_ptr = &forge;
6525
6526                 /* Save a copy of the moving item */
6527                 object_copy(q_ptr, &inventory[i]);
6528
6529                 /* Slide the objects */
6530                 for (k = i; k > j; k--)
6531                 {
6532                         /* Slide the item */
6533                         object_copy(&inventory[k], &inventory[k-1]);
6534                 }
6535
6536                 /* Insert the moving item */
6537                 object_copy(&inventory[j], q_ptr);
6538
6539                 /* Window stuff */
6540                 p_ptr->window |= (PW_INVEN);
6541         }
6542
6543         if (flag) msg_print(_("ザックの中のアイテムを並べ直した。", "You reorder some items in your pack."));
6544 }
6545
6546 /*!
6547  * @brief 現在アクティブになっているウィンドウにオブジェクトの詳細を表示する /
6548  * Hack -- display an object kind in the current window
6549  * @param k_idx ベースアイテムの参照ID
6550  * @return なし
6551  * @details
6552  * Include list of usable spells for readible books
6553  */
6554 void display_koff(KIND_OBJECT_IDX k_idx)
6555 {
6556         int y;
6557
6558         object_type forge;
6559         object_type *q_ptr;
6560         int         sval;
6561         REALM_IDX   use_realm;
6562
6563         char o_name[MAX_NLEN];
6564
6565
6566         /* Erase the window */
6567         for (y = 0; y < Term->hgt; y++)
6568         {
6569                 /* Erase the line */
6570                 Term_erase(0, y, 255);
6571         }
6572
6573         /* No info */
6574         if (!k_idx) return;
6575
6576         /* Get local object */
6577         q_ptr = &forge;
6578
6579         /* Prepare the object */
6580         object_prep(q_ptr, k_idx);
6581
6582         /* Describe */
6583         object_desc(o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
6584
6585         /* Mention the object name */
6586         Term_putstr(0, 0, -1, TERM_WHITE, o_name);
6587
6588         /* Access the item's sval */
6589         sval = q_ptr->sval;
6590         use_realm = tval2realm(q_ptr->tval);
6591
6592         /* Warriors are illiterate */
6593         if (p_ptr->realm1 || p_ptr->realm2)
6594         {
6595                 if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2)) return;
6596         }
6597         else
6598         {
6599                 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return;
6600                 if (!is_magic(use_realm)) return;
6601                 if ((p_ptr->pclass == CLASS_RED_MAGE) && (use_realm != REALM_ARCANE) && (sval > 1)) return;
6602         }
6603
6604         /* Display spells in readible books */
6605         {
6606                 int     spell = -1;
6607                 int     num = 0;
6608                 SPELL_IDX    spells[64];
6609
6610                 /* Extract spells */
6611                 for (spell = 0; spell < 32; spell++)
6612                 {
6613                         /* Check for this spell */
6614                         if (fake_spell_flags[sval] & (1L << spell))
6615                         {
6616                                 /* Collect this spell */
6617                                 spells[num++] = spell;
6618                         }
6619                 }
6620
6621                 /* Print spells */
6622                 print_spells(0, spells, num, 2, 0, use_realm);
6623         }
6624 }
6625
6626 /*!
6627  * @brief 警告を放つアイテムを選択する /
6628  * Choose one of items that have warning flag
6629  * Calculate spell damages
6630  * @return 警告を行う
6631  */
6632 object_type *choose_warning_item(void)
6633 {
6634         int i;
6635         int choices[INVEN_TOTAL - INVEN_RARM];
6636         int number = 0;
6637
6638         /* Paranoia -- Player has no warning ability */
6639         if (!p_ptr->warning) return NULL;
6640
6641         /* Search Inventory */
6642         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
6643         {
6644                 BIT_FLAGS flgs[TR_FLAG_SIZE];
6645                 object_type *o_ptr = &inventory[i];
6646
6647                 object_flags(o_ptr, flgs);
6648                 if (have_flag(flgs, TR_WARNING))
6649                 {
6650                         choices[number] = i;
6651                         number++;
6652                 }
6653         }
6654
6655         /* Choice one of them */
6656         return number ? &inventory[choices[randint0(number)]] : NULL;
6657 }
6658
6659 /*!
6660  * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
6661  * Calculate spell damages
6662  * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
6663  * @param typ 効果属性のID
6664  * @param dam 基本ダメージ
6665  * @param max 算出した最大ダメージを返すポインタ
6666  * @return なし
6667  */
6668 static void spell_damcalc(monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
6669 {
6670         monster_race *r_ptr = &r_info[m_ptr->r_idx];
6671         int          rlev = r_ptr->level;
6672         bool         ignore_wraith_form = FALSE;
6673
6674         /* Vulnerability, resistance and immunity */
6675         switch (typ)
6676         {
6677         case GF_ELEC:
6678                 if (p_ptr->immune_elec)
6679                 {
6680                         dam = 0;
6681                         ignore_wraith_form = TRUE;
6682                 }
6683                 else
6684                 {
6685                         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
6686                         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
6687                         if (prace_is_(RACE_ANDROID)) dam += dam / 3;
6688                         if (p_ptr->resist_elec) dam = (dam + 2) / 3;
6689                         if (IS_OPPOSE_ELEC())
6690                                 dam = (dam + 2) / 3;
6691                 }
6692                 break;
6693
6694         case GF_POIS:
6695                 if (p_ptr->resist_pois) dam = (dam + 2) / 3;
6696                 if (IS_OPPOSE_POIS()) dam = (dam + 2) / 3;
6697                 break;
6698
6699         case GF_ACID:
6700                 if (p_ptr->immune_acid)
6701                 {
6702                         dam = 0;
6703                         ignore_wraith_form = TRUE;
6704                 }
6705                 else
6706                 {
6707                         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
6708                         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
6709                         if (p_ptr->resist_acid) dam = (dam + 2) / 3;
6710                         if (IS_OPPOSE_ACID()) dam = (dam + 2) / 3;
6711                 }
6712                 break;
6713
6714         case GF_COLD:
6715         case GF_ICE:
6716                 if (p_ptr->immune_cold)
6717                 {
6718                         dam = 0;
6719                         ignore_wraith_form = TRUE;
6720                 }
6721                 else
6722                 {
6723                         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
6724                         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
6725                         if (p_ptr->resist_cold) dam = (dam + 2) / 3;
6726                         if (IS_OPPOSE_COLD()) dam = (dam + 2) / 3;
6727                 }
6728                 break;
6729
6730         case GF_FIRE:
6731                 if (p_ptr->immune_fire)
6732                 {
6733                         dam = 0;
6734                         ignore_wraith_form = TRUE;
6735                 }
6736                 else
6737                 {
6738                         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
6739                         if (prace_is_(RACE_ENT)) dam += dam / 3;
6740                         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
6741                         if (p_ptr->resist_fire) dam = (dam + 2) / 3;
6742                         if (IS_OPPOSE_FIRE()) dam = (dam + 2) / 3;
6743                 }
6744                 break;
6745
6746         case GF_PSY_SPEAR:
6747                 ignore_wraith_form = TRUE;
6748                 break;
6749
6750         case GF_ARROW:
6751                 if (!p_ptr->blind &&
6752                     ((inventory[INVEN_RARM].k_idx && (inventory[INVEN_RARM].name1 == ART_ZANTETSU)) ||
6753                      (inventory[INVEN_LARM].k_idx && (inventory[INVEN_LARM].name1 == ART_ZANTETSU))))
6754                 {
6755                         dam = 0;
6756                         ignore_wraith_form = TRUE;
6757                 }
6758                 break;
6759
6760         case GF_LITE:
6761                 if (p_ptr->resist_lite) dam /= 2; /* Worst case of 4 / (d4 + 7) */
6762                 if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE)) dam *= 2;
6763                 else if (prace_is_(RACE_S_FAIRY)) dam = dam * 4 / 3;
6764
6765                 /*
6766                  * Cannot use "ignore_wraith_form" strictly (for "random one damage")
6767                  * "dam *= 2;" for later "dam /= 2"
6768                  */
6769                 if (p_ptr->wraith_form) dam *= 2;
6770                 break;
6771
6772         case GF_DARK:
6773                 if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE) || p_ptr->wraith_form)
6774                 {
6775                         dam = 0;
6776                         ignore_wraith_form = TRUE;
6777                 }
6778                 else if (p_ptr->resist_dark) dam /= 2; /* Worst case of 4 / (d4 + 7) */
6779                 break;
6780
6781         case GF_SHARDS:
6782                 if (p_ptr->resist_shard) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
6783                 break;
6784
6785         case GF_SOUND:
6786                 if (p_ptr->resist_sound) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
6787                 break;
6788
6789         case GF_CONFUSION:
6790                 if (p_ptr->resist_conf) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
6791                 break;
6792
6793         case GF_CHAOS:
6794                 if (p_ptr->resist_chaos) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
6795                 break;
6796
6797         case GF_NETHER:
6798                 if (prace_is_(RACE_SPECTRE))
6799                 {
6800                         dam = 0;
6801                         ignore_wraith_form = TRUE;
6802                 }
6803                 else if (p_ptr->resist_neth) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
6804                 break;
6805
6806         case GF_DISENCHANT:
6807                 if (p_ptr->resist_disen) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
6808                 break;
6809
6810         case GF_NEXUS:
6811                 if (p_ptr->resist_nexus) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
6812                 break;
6813
6814         case GF_TIME:
6815                 if (p_ptr->resist_time) dam /= 2; /* Worst case of 4 / (d4 + 7) */
6816                 break;
6817
6818         case GF_GRAVITY:
6819                 if (p_ptr->levitation) dam = (dam * 2) / 3;
6820                 break;
6821
6822         case GF_ROCKET:
6823                 if (p_ptr->resist_shard) dam /= 2;
6824                 break;
6825
6826         case GF_NUKE:
6827                 if (p_ptr->resist_pois) dam = (2 * dam + 2) / 5;
6828                 if (IS_OPPOSE_POIS()) dam = (2 * dam + 2) / 5;
6829                 break;
6830
6831         case GF_DEATH_RAY:
6832                 if (p_ptr->mimic_form)
6833                 {
6834                         if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)
6835                         {
6836                                 dam = 0;
6837                                 ignore_wraith_form = TRUE;
6838                         }
6839                 }
6840                 else
6841                 {
6842                         switch (p_ptr->prace)
6843                         {
6844                         case RACE_GOLEM:
6845                         case RACE_SKELETON:
6846                         case RACE_ZOMBIE:
6847                         case RACE_VAMPIRE:
6848                         case RACE_DEMON:
6849                         case RACE_SPECTRE:
6850                                 dam = 0;
6851                                 ignore_wraith_form = TRUE;
6852                                 break;
6853                         }
6854                 }
6855                 break;
6856
6857         case GF_HOLY_FIRE:
6858                 if (p_ptr->align > 10) dam /= 2;
6859                 else if (p_ptr->align < -10) dam *= 2;
6860                 break;
6861
6862         case GF_HELL_FIRE:
6863                 if (p_ptr->align > 10) dam *= 2;
6864                 break;
6865
6866         case GF_MIND_BLAST:
6867         case GF_BRAIN_SMASH:
6868                 if (100 + rlev / 2 <= MAX(5, p_ptr->skill_sav))
6869                 {
6870                         dam = 0;
6871                         ignore_wraith_form = TRUE;
6872                 }
6873                 break;
6874
6875         case GF_CAUSE_1:
6876         case GF_CAUSE_2:
6877         case GF_CAUSE_3:
6878         case GF_HAND_DOOM:
6879                 if (100 + rlev / 2 <= p_ptr->skill_sav)
6880                 {
6881                         dam = 0;
6882                         ignore_wraith_form = TRUE;
6883                 }
6884                 break;
6885
6886         case GF_CAUSE_4:
6887                 if ((100 + rlev / 2 <= p_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU))
6888                 {
6889                         dam = 0;
6890                         ignore_wraith_form = TRUE;
6891                 }
6892                 break;
6893         }
6894
6895         if (p_ptr->wraith_form && !ignore_wraith_form)
6896         {
6897                 dam /= 2;
6898                 if (!dam) dam = 1;
6899         }
6900
6901         if (dam > *max) *max = dam;
6902 }
6903
6904 /*!
6905 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
6906 * Calculate spell damages
6907 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
6908 * @param typ 効果属性のID
6909 * @param m_idx 魔法を行使するモンスターのID
6910 * @param max 算出した最大ダメージを返すポインタ
6911 * @return なし
6912 */
6913 void spell_damcalc_by_spellnum(int spell_num, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
6914 {
6915     monster_type *m_ptr = &m_list[m_idx];
6916     HIT_POINT dam = monspell_damage((spell_num), m_idx, DAM_MAX);
6917     spell_damcalc(m_ptr, typ, dam, max);
6918 }
6919
6920 /*!
6921  * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
6922  * Calculate blow damages
6923  * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
6924  * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
6925  * @return 算出された最大ダメージを返す。
6926  */
6927 static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
6928 {
6929         int  dam = blow_ptr->d_dice * blow_ptr->d_side;
6930         int  dummy_max = 0;
6931         bool check_wraith_form = TRUE;
6932
6933         if (blow_ptr->method != RBM_EXPLODE)
6934         {
6935                 ARMOUR_CLASS ac = p_ptr->ac + p_ptr->to_a;
6936
6937                 switch (blow_ptr->effect)
6938                 {
6939                 case RBE_SUPERHURT:
6940                 {
6941                         int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
6942                         dam = MAX(dam, tmp_dam * 2);
6943                         break;
6944                 }
6945
6946                 case RBE_HURT:
6947                 case RBE_SHATTER:
6948                         dam -= (dam * ((ac < 150) ? ac : 150) / 250);
6949                         break;
6950
6951                 case RBE_ACID:
6952                         spell_damcalc(m_ptr, GF_ACID, dam, &dummy_max);
6953                         dam = dummy_max;
6954                         check_wraith_form = FALSE;
6955                         break;
6956
6957                 case RBE_ELEC:
6958                         spell_damcalc(m_ptr, GF_ELEC, dam, &dummy_max);
6959                         dam = dummy_max;
6960                         check_wraith_form = FALSE;
6961                         break;
6962
6963                 case RBE_FIRE:
6964                         spell_damcalc(m_ptr, GF_FIRE, dam, &dummy_max);
6965                         dam = dummy_max;
6966                         check_wraith_form = FALSE;
6967                         break;
6968
6969                 case RBE_COLD:
6970                         spell_damcalc(m_ptr, GF_COLD, dam, &dummy_max);
6971                         dam = dummy_max;
6972                         check_wraith_form = FALSE;
6973                         break;
6974
6975                 case RBE_DR_MANA:
6976                         dam = 0;
6977                         check_wraith_form = FALSE;
6978                         break;
6979                 }
6980
6981                 if (check_wraith_form && p_ptr->wraith_form)
6982                 {
6983                         dam /= 2;
6984                         if (!dam) dam = 1;
6985                 }
6986         }
6987         else
6988         {
6989                 dam = (dam + 1) / 2;
6990                 spell_damcalc(m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
6991                 dam = dummy_max;
6992         }
6993
6994         return dam;
6995 }
6996
6997 /*!
6998  * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
6999  * Examine the grid (xx,yy) and warn the player if there are any danger
7000  * @param xx 危険性を調査するマスのX座標
7001  * @param yy 危険性を調査するマスのY座標
7002  * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
7003  */
7004 bool process_warning(int xx, int yy)
7005 {
7006         int mx, my;
7007         cave_type *c_ptr;
7008         char o_name[MAX_NLEN];
7009
7010 #define WARNING_AWARE_RANGE 12
7011         int dam_max = 0;
7012         static int old_damage = 0;
7013
7014         for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++)
7015         {
7016                 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++)
7017                 {
7018                         int dam_max0 = 0;
7019                         monster_type *m_ptr;
7020                         monster_race *r_ptr;
7021
7022                         if (!in_bounds(my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) continue;
7023
7024                         c_ptr = &cave[my][mx];
7025
7026                         if (!c_ptr->m_idx) continue;
7027
7028                         m_ptr = &m_list[c_ptr->m_idx];
7029
7030                         if (MON_CSLEEP(m_ptr)) continue;
7031                         if (!is_hostile(m_ptr)) continue;
7032
7033                         r_ptr = &r_info[m_ptr->r_idx];
7034
7035                         /* Monster spells (only powerful ones)*/
7036                         if (projectable(my, mx, yy, xx))
7037             {
7038                                 u32b f4 = r_ptr->flags4;
7039                                 u32b f5 = r_ptr->a_ability_flags1;
7040                                 u32b f6 = r_ptr->a_ability_flags2;
7041
7042                                 if (!(d_info[dungeon_type].flags1 & DF1_NO_MAGIC))
7043                                 {
7044                     if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(MS_BALL_CHAOS, GF_CHAOS, c_ptr->m_idx,  &dam_max0);
7045                     if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(MS_BALL_MANA, GF_MANA, c_ptr->m_idx, &dam_max0);
7046                     if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(MS_BALL_DARK, GF_DARK, c_ptr->m_idx, &dam_max0);
7047                     if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(MS_STARBURST, GF_LITE, c_ptr->m_idx, &dam_max0);
7048                     if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(MS_HAND_DOOM, GF_HAND_DOOM, c_ptr->m_idx, &dam_max0);
7049                     if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(MS_PSY_SPEAR, GF_PSY_SPEAR, c_ptr->m_idx, &dam_max0);
7050                                 }
7051                 if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(MS_ROCKET, GF_ROCKET, c_ptr->m_idx, &dam_max0);
7052                 if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(MS_BR_ACID, GF_ACID, c_ptr->m_idx, &dam_max0);
7053                 if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(MS_BR_ELEC, GF_ELEC, c_ptr->m_idx, &dam_max0);
7054                 if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(MS_BR_FIRE, GF_FIRE, c_ptr->m_idx, &dam_max0);
7055                 if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(MS_BR_COLD, GF_COLD, c_ptr->m_idx, &dam_max0);
7056                 if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(MS_BR_POIS, GF_POIS, c_ptr->m_idx, &dam_max0);
7057                 if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(MS_BR_NETHER, GF_NETHER, c_ptr->m_idx, &dam_max0);
7058                 if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(MS_BR_LITE, GF_LITE, c_ptr->m_idx, &dam_max0);
7059                 if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(MS_BR_DARK, GF_DARK, c_ptr->m_idx, &dam_max0);
7060                 if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(MS_BR_CONF, GF_CONFUSION, c_ptr->m_idx, &dam_max0);
7061                 if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(MS_BR_SOUND, GF_SOUND, c_ptr->m_idx, &dam_max0);
7062                 if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(MS_BR_CHAOS, GF_CHAOS, c_ptr->m_idx, &dam_max0);
7063                 if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(MS_BR_DISEN, GF_DISENCHANT, c_ptr->m_idx, &dam_max0);
7064                 if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(MS_BR_NEXUS, GF_NEXUS, c_ptr->m_idx, &dam_max0);
7065                 if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(MS_BR_TIME, GF_TIME, c_ptr->m_idx, &dam_max0);
7066                 if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(MS_BR_INERTIA, GF_INERTIAL, c_ptr->m_idx, &dam_max0);
7067                 if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(MS_BR_GRAVITY, GF_GRAVITY, c_ptr->m_idx, &dam_max0);
7068                 if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(MS_BR_SHARDS, GF_SHARDS, c_ptr->m_idx, &dam_max0);
7069                 if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(MS_BR_PLASMA, GF_PLASMA, c_ptr->m_idx, &dam_max0);
7070                 if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(MS_BR_FORCE, GF_FORCE, c_ptr->m_idx, &dam_max0);
7071                 if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(MS_BR_MANA, GF_MANA, c_ptr->m_idx, &dam_max0);
7072                 if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(MS_BR_NUKE, GF_NUKE, c_ptr->m_idx, &dam_max0);
7073                 if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(MS_BR_DISI, GF_DISINTEGRATE, c_ptr->m_idx, &dam_max0);
7074                         }
7075
7076                         /* Monster melee attacks */
7077                         if (!(r_ptr->flags1 & RF1_NEVER_BLOW) && !(d_info[dungeon_type].flags1 & DF1_NO_MELEE))
7078                         {
7079                                 if (mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)
7080                                 {
7081                                         int m;
7082                                         int dam_melee = 0;
7083                                         for (m = 0; m < 4; m++)
7084                                         {
7085                                                 /* Skip non-attacks */
7086                                                 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT)) continue;
7087
7088                                                 /* Extract the attack info */
7089                                                 dam_melee += blow_damcalc(m_ptr, &r_ptr->blow[m]);
7090                                                 if (r_ptr->blow[m].method == RBM_EXPLODE) break;
7091                                         }
7092                                         if (dam_melee > dam_max0) dam_max0 = dam_melee;
7093                                 }
7094                         }
7095
7096                         /* Contribution from this monster */
7097                         dam_max += dam_max0;
7098                 }
7099         }
7100
7101         /* Prevent excessive warning */
7102         if (dam_max > old_damage)
7103         {
7104                 old_damage = dam_max * 3 / 2;
7105
7106                 if (dam_max > p_ptr->chp / 2)
7107                 {
7108                         object_type *o_ptr = choose_warning_item();
7109
7110                         if (o_ptr)
7111                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
7112             else 
7113                 strcpy(o_name, _("体", "body")); /* Warning ability without item */
7114             msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
7115
7116                         disturb(0, 1);
7117             return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
7118                 }
7119         }
7120         else old_damage = old_damage / 2;
7121
7122         c_ptr = &cave[yy][xx];
7123         if (((!easy_disarm && is_trap(c_ptr->feat))
7124             || (c_ptr->mimic && is_trap(c_ptr->feat))) && !one_in_(13))
7125         {
7126                 object_type *o_ptr = choose_warning_item();
7127
7128                 if (o_ptr) 
7129             object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
7130         else
7131             strcpy(o_name, _("体", "body")); /* Warning ability without item */
7132         msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
7133                 disturb(0, 1);
7134         return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
7135         }
7136
7137         return TRUE;
7138 }
7139
7140 /*!
7141  * エッセンス情報の構造体 / A structure for smithing
7142  */
7143 typedef struct {
7144         int add;       /* TR flag number or special essence id */
7145         cptr add_name; /* Name of this ability */
7146         ESSENCE_IDX type;      /* Menu number */
7147         int essence;   /* Index for carrying essences */
7148         int value;     /* Needed value to add this ability */
7149 } essence_type;
7150
7151
7152 /*!
7153  * エッセンス情報テーブル Smithing type data for Weapon smith
7154  */
7155 #ifdef JP
7156 static essence_type essence_info[] = 
7157 {
7158         {TR_STR, "腕力", 4, TR_STR, 20},
7159         {TR_INT, "知能", 4, TR_INT, 20},
7160         {TR_WIS, "賢さ", 4, TR_WIS, 20},
7161         {TR_DEX, "器用さ", 4, TR_DEX, 20},
7162         {TR_CON, "耐久力", 4, TR_CON, 20},
7163         {TR_CHR, "魅力", 4, TR_CHR, 20},
7164         {TR_MAGIC_MASTERY, "魔力支配", 4, TR_MAGIC_MASTERY, 20},
7165         {TR_STEALTH, "隠密", 4, TR_STEALTH, 40},
7166         {TR_SEARCH, "探索", 4, TR_SEARCH, 15},
7167         {TR_INFRA, "赤外線視力", 4, TR_INFRA, 15},
7168         {TR_TUNNEL, "採掘", 4, TR_TUNNEL, 15},
7169         {TR_SPEED, "スピード", 4, TR_SPEED, 12},
7170         {TR_BLOWS, "追加攻撃", 1, TR_BLOWS, 20},
7171         {TR_CHAOTIC, "カオス攻撃", 1, TR_CHAOTIC, 15},
7172         {TR_VAMPIRIC, "吸血攻撃", 1, TR_VAMPIRIC, 60},
7173         {TR_IMPACT, "地震発動", 7, TR_IMPACT, 15},
7174         {TR_BRAND_POIS, "毒殺", 1, TR_BRAND_POIS, 20},
7175         {TR_BRAND_ACID, "溶解", 1, TR_BRAND_ACID, 20},
7176         {TR_BRAND_ELEC, "電撃", 1, TR_BRAND_ELEC, 20},
7177         {TR_BRAND_FIRE, "焼棄", 1, TR_BRAND_FIRE, 20},
7178         {TR_BRAND_COLD, "凍結", 1, TR_BRAND_COLD, 20},
7179         {TR_SUST_STR, "腕力維持", 3, TR_SUST_STR, 15},
7180         {TR_SUST_INT, "知能維持", 3, TR_SUST_STR, 15},
7181         {TR_SUST_WIS, "賢さ維持", 3, TR_SUST_STR, 15},
7182         {TR_SUST_DEX, "器用さ維持", 3, TR_SUST_STR, 15},
7183         {TR_SUST_CON, "耐久力維持", 3, TR_SUST_STR, 15},
7184         {TR_SUST_CHR, "魅力維持", 3, TR_SUST_STR, 15},
7185         {TR_IM_ACID, "酸免疫", 2, TR_IM_ACID, 20},
7186         {TR_IM_ELEC, "電撃免疫", 2, TR_IM_ACID, 20},
7187         {TR_IM_FIRE, "火炎免疫", 2, TR_IM_ACID, 20},
7188         {TR_IM_COLD, "冷気免疫", 2, TR_IM_ACID, 20},
7189         {TR_REFLECT, "反射", 2, TR_REFLECT, 20},
7190         {TR_FREE_ACT, "麻痺知らず", 3, TR_FREE_ACT, 20},
7191         {TR_HOLD_EXP, "経験値維持", 3, TR_HOLD_EXP, 20},
7192         {TR_RES_ACID, "耐酸", 2, TR_RES_ACID, 15},
7193         {TR_RES_ELEC, "耐電撃", 2, TR_RES_ELEC, 15},
7194         {TR_RES_FIRE, "耐火炎", 2, TR_RES_FIRE, 15},
7195         {TR_RES_COLD, "耐冷気", 2, TR_RES_COLD, 15},
7196         {TR_RES_POIS, "耐毒", 2, TR_RES_POIS, 25},
7197         {TR_RES_FEAR, "耐恐怖", 2, TR_RES_FEAR, 20},
7198         {TR_RES_LITE, "耐閃光", 2, TR_RES_LITE, 20},
7199         {TR_RES_DARK, "耐暗黒", 2, TR_RES_DARK, 20},
7200         {TR_RES_BLIND, "耐盲目", 2, TR_RES_BLIND, 20},
7201         {TR_RES_CONF, "耐混乱", 2, TR_RES_CONF, 20},
7202         {TR_RES_SOUND, "耐轟音", 2, TR_RES_SOUND, 20},
7203         {TR_RES_SHARDS, "耐破片", 2, TR_RES_SHARDS, 20},
7204         {TR_RES_NETHER, "耐地獄", 2, TR_RES_NETHER, 20},
7205         {TR_RES_NEXUS, "耐因果混乱", 2, TR_RES_NEXUS, 20},
7206         {TR_RES_CHAOS, "耐カオス", 2, TR_RES_CHAOS, 20},
7207         {TR_RES_DISEN, "耐劣化", 2, TR_RES_DISEN, 20},
7208         {TR_SH_FIRE, "", 0, -2, 0},
7209         {TR_SH_ELEC, "", 0, -2, 0},
7210         {TR_SH_COLD, "", 0, -2, 0},
7211         {TR_NO_MAGIC, "反魔法", 3, TR_NO_MAGIC, 15},
7212         {TR_WARNING, "警告", 3, TR_WARNING, 20},
7213         {TR_LEVITATION, "浮遊", 3, TR_LEVITATION, 20},
7214         {TR_LITE_1, "永久光源", 3, TR_LITE_1, 15},
7215         {TR_LITE_2, "", 0, -2, 0},
7216         {TR_LITE_3, "", 0, -2, 0},
7217         {TR_SEE_INVIS, "可視透明", 3, TR_SEE_INVIS, 20},
7218         {TR_TELEPATHY, "テレパシー", 6, TR_TELEPATHY, 15},
7219         {TR_SLOW_DIGEST, "遅消化", 3, TR_SLOW_DIGEST, 15},
7220         {TR_REGEN, "急速回復", 3, TR_REGEN, 20},
7221         {TR_TELEPORT, "テレポート", 3, TR_TELEPORT, 25},
7222
7223         {TR_SLAY_EVIL, "邪悪倍打", 5, TR_SLAY_EVIL, 100},
7224         {TR_KILL_EVIL, "邪悪倍倍打", 0, TR_SLAY_EVIL, 60},
7225         {TR_SLAY_ANIMAL, "動物倍打", 5, TR_SLAY_ANIMAL, 20},
7226         {TR_KILL_ANIMAL, "動物倍倍打", 5, TR_SLAY_ANIMAL, 60},
7227         {TR_SLAY_UNDEAD, "不死倍打", 5, TR_SLAY_UNDEAD, 20},
7228         {TR_KILL_UNDEAD, "不死倍倍打", 5, TR_SLAY_UNDEAD, 60},
7229         {TR_SLAY_DEMON, "悪魔倍打", 5, TR_SLAY_DEMON, 20},
7230         {TR_KILL_DEMON, "悪魔倍倍打", 5, TR_SLAY_DEMON, 60},
7231         {TR_SLAY_ORC, "オーク倍打", 5, TR_SLAY_ORC, 15},
7232         {TR_KILL_ORC, "オーク倍倍打", 5, TR_SLAY_ORC, 60},
7233         {TR_SLAY_TROLL, "トロル倍打", 5, TR_SLAY_TROLL, 15},
7234         {TR_KILL_TROLL, "トロル倍倍打", 5, TR_SLAY_TROLL, 60},
7235         {TR_SLAY_GIANT, "巨人倍打", 5, TR_SLAY_GIANT, 20},
7236         {TR_KILL_GIANT, "巨人倍倍打", 5, TR_SLAY_GIANT, 60},       
7237         {TR_SLAY_DRAGON, "竜倍打", 5, TR_SLAY_DRAGON, 20},
7238         {TR_KILL_DRAGON, "竜倍倍打", 5, TR_SLAY_DRAGON, 60},
7239         {TR_SLAY_HUMAN, "人間倍打", 5, TR_SLAY_HUMAN, 20},
7240         {TR_KILL_HUMAN, "人間倍倍打", 5, TR_SLAY_HUMAN, 60},
7241
7242         {TR_ESP_ANIMAL, "動物ESP", 6, TR_SLAY_ANIMAL, 40},
7243         {TR_ESP_UNDEAD, "不死ESP", 6, TR_SLAY_UNDEAD, 40}, 
7244         {TR_ESP_DEMON, "悪魔ESP", 6, TR_SLAY_DEMON, 40},       
7245         {TR_ESP_ORC, "オークESP", 6, TR_SLAY_ORC, 40},     
7246         {TR_ESP_TROLL, "トロルESP", 6, TR_SLAY_TROLL, 40},   
7247         {TR_ESP_GIANT, "巨人ESP", 6, TR_SLAY_GIANT, 40},       
7248         {TR_ESP_DRAGON, "竜ESP", 6, TR_SLAY_DRAGON, 40},
7249         {TR_ESP_HUMAN, "人間ESP", 6, TR_SLAY_HUMAN, 40},
7250
7251         {ESSENCE_ATTACK, "攻撃", 10, TR_ES_ATTACK, 30},
7252         {ESSENCE_AC, "防御", 10, TR_ES_AC, 15},
7253         {ESSENCE_TMP_RES_ACID, "酸耐性発動", 7, TR_RES_ACID, 50},
7254         {ESSENCE_TMP_RES_ELEC, "電撃耐性発動", 7, TR_RES_ELEC, 50},
7255         {ESSENCE_TMP_RES_FIRE, "火炎耐性発動", 7, TR_RES_FIRE, 50},
7256         {ESSENCE_TMP_RES_COLD, "冷気耐性発動", 7, TR_RES_COLD, 50},
7257         {ESSENCE_SH_FIRE, "火炎オーラ", 7, -1, 50},
7258         {ESSENCE_SH_ELEC, "電撃オーラ", 7, -1, 50},
7259         {ESSENCE_SH_COLD, "冷気オーラ", 7, -1, 50},
7260         {ESSENCE_RESISTANCE, "全耐性", 2, -1, 150},
7261         {ESSENCE_SUSTAIN, "装備保持", 10, -1, 10},
7262         {ESSENCE_SLAY_GLOVE, "殺戮の小手", 1, TR_ES_ATTACK, 200},
7263
7264         {-1, NULL, 0, -1, 0}
7265 };
7266 #else
7267 static essence_type essence_info[] = 
7268 {
7269         {TR_STR, "strength", 4, TR_STR, 20},
7270         {TR_INT, "intelligence", 4, TR_INT, 20},
7271         {TR_WIS, "wisdom", 4, TR_WIS, 20},
7272         {TR_DEX, "dexterity", 4, TR_DEX, 20},
7273         {TR_CON, "constitution", 4, TR_CON, 20},
7274         {TR_CHR, "charisma", 4, TR_CHR, 20},
7275         {TR_MAGIC_MASTERY, "magic mastery", 4, TR_MAGIC_MASTERY, 20},
7276         {TR_STEALTH, "stealth", 4, TR_STEALTH, 40},
7277         {TR_SEARCH, "serching", 4, TR_SEARCH, 15},
7278         {TR_INFRA, "infravision", 4, TR_INFRA, 15},
7279         {TR_TUNNEL, "digging", 4, TR_TUNNEL, 15},
7280         {TR_SPEED, "speed", 4, TR_SPEED, 12},
7281         {TR_BLOWS, "extra attack", 1, TR_BLOWS, 20},
7282         {TR_CHAOTIC, "chaos brand", 1, TR_CHAOTIC, 15},
7283         {TR_VAMPIRIC, "vampiric brand", 1, TR_VAMPIRIC, 60},
7284         {TR_IMPACT, "quake activation", 7, TR_IMPACT, 15},
7285         {TR_BRAND_POIS, "poison brand", 1, TR_BRAND_POIS, 20},
7286         {TR_BRAND_ACID, "acid brand", 1, TR_BRAND_ACID, 20},
7287         {TR_BRAND_ELEC, "electric brand", 1, TR_BRAND_ELEC, 20},
7288         {TR_BRAND_FIRE, "fire brand", 1, TR_BRAND_FIRE, 20},
7289         {TR_BRAND_COLD, "cold brand", 1, TR_BRAND_COLD, 20},
7290         {TR_SUST_STR, "sustain strength", 3, TR_SUST_STR, 15},
7291         {TR_SUST_INT, "sustain intelligence", 3, TR_SUST_STR, 15},
7292         {TR_SUST_WIS, "sustain wisdom", 3, TR_SUST_STR, 15},
7293         {TR_SUST_DEX, "sustain dexterity", 3, TR_SUST_STR, 15},
7294         {TR_SUST_CON, "sustain constitution", 3, TR_SUST_STR, 15},
7295         {TR_SUST_CHR, "sustain charisma", 3, TR_SUST_STR, 15},
7296         {TR_IM_ACID, "acid immunity", 2, TR_IM_ACID, 20},
7297         {TR_IM_ELEC, "electric immunity", 2, TR_IM_ACID, 20},
7298         {TR_IM_FIRE, "fire immunity", 2, TR_IM_ACID, 20},
7299         {TR_IM_COLD, "cold immunity", 2, TR_IM_ACID, 20},
7300         {TR_REFLECT, "reflection", 2, TR_REFLECT, 20},
7301         {TR_FREE_ACT, "free action", 3, TR_FREE_ACT, 20},
7302         {TR_HOLD_EXP, "hold experience", 3, TR_HOLD_EXP, 20},
7303         {TR_RES_ACID, "resistance to acid", 2, TR_RES_ACID, 15},
7304         {TR_RES_ELEC, "resistance to electric", 2, TR_RES_ELEC, 15},
7305         {TR_RES_FIRE, "resistance to fire", 2, TR_RES_FIRE, 15},
7306         {TR_RES_COLD, "resistance to cold", 2, TR_RES_COLD, 15},
7307         {TR_RES_POIS, "resistance to poison", 2, TR_RES_POIS, 25},
7308         {TR_RES_FEAR, "resistance to fear", 2, TR_RES_FEAR, 20},
7309         {TR_RES_LITE, "resistance to light", 2, TR_RES_LITE, 20},
7310         {TR_RES_DARK, "resistance to dark", 2, TR_RES_DARK, 20},
7311         {TR_RES_BLIND, "resistance to blind", 2, TR_RES_BLIND, 20},
7312         {TR_RES_CONF, "resistance to confusion", 2, TR_RES_CONF, 20},
7313         {TR_RES_SOUND, "resistance to sound", 2, TR_RES_SOUND, 20},
7314         {TR_RES_SHARDS, "resistance to shard", 2, TR_RES_SHARDS, 20},
7315         {TR_RES_NETHER, "resistance to nether", 2, TR_RES_NETHER, 20},
7316         {TR_RES_NEXUS, "resistance to nexus", 2, TR_RES_NEXUS, 20},
7317         {TR_RES_CHAOS, "resistance to chaos", 2, TR_RES_CHAOS, 20},
7318         {TR_RES_DISEN, "resistance to disenchantment", 2, TR_RES_DISEN, 20},
7319         {TR_SH_FIRE, "", 0, -2, 0},
7320         {TR_SH_ELEC, "", 0, -2, 0},
7321         {TR_SH_COLD, "", 0, -2, 0},
7322         {TR_NO_MAGIC, "anti magic", 3, TR_NO_MAGIC, 15},
7323         {TR_WARNING, "warning", 3, TR_WARNING, 20},
7324         {TR_LEVITATION, "levitation", 3, TR_LEVITATION, 20},
7325         {TR_LITE_1, "permanent light", 3, TR_LITE_1, 15},
7326         {TR_LITE_2, "", 0, -2, 0},
7327         {TR_LITE_3, "", 0, -2, 0},
7328         {TR_SEE_INVIS, "see invisible", 3, TR_SEE_INVIS, 20},
7329         {TR_TELEPATHY, "telepathy", 6, TR_TELEPATHY, 15},
7330         {TR_SLOW_DIGEST, "slow digestion", 3, TR_SLOW_DIGEST, 15},
7331         {TR_REGEN, "regeneration", 3, TR_REGEN, 20},
7332         {TR_TELEPORT, "teleport", 3, TR_TELEPORT, 25},
7333
7334         {TR_SLAY_EVIL, "slay evil", 5, TR_SLAY_EVIL, 100},
7335         {TR_SLAY_ANIMAL, "slay animal", 5, TR_SLAY_ANIMAL, 20},
7336         {TR_KILL_ANIMAL, "kill animal", 5, TR_SLAY_ANIMAL, 60},
7337         {TR_KILL_EVIL, "kill evil", 0, TR_SLAY_EVIL, 60},
7338         {TR_SLAY_UNDEAD, "slay undead", 5, TR_SLAY_UNDEAD, 20},
7339         {TR_KILL_UNDEAD, "kill undead", 5, TR_SLAY_UNDEAD, 60},
7340         {TR_SLAY_DEMON, "slay demon", 5, TR_SLAY_DEMON, 20},
7341         {TR_KILL_DEMON, "kill demon", 5, TR_SLAY_DEMON, 60},
7342         {TR_SLAY_ORC, "slay orc", 5, TR_SLAY_ORC, 15},
7343         {TR_KILL_ORC, "kill orc", 5, TR_SLAY_ORC, 60},
7344         {TR_SLAY_TROLL, "slay troll", 5, TR_SLAY_TROLL, 15},
7345         {TR_KILL_TROLL, "kill troll", 5, TR_SLAY_TROLL, 60},
7346         {TR_SLAY_GIANT, "slay giant", 5, TR_SLAY_GIANT, 20},
7347         {TR_KILL_GIANT, "kill giant", 5, TR_SLAY_GIANT, 60},       
7348         {TR_SLAY_DRAGON, "slay dragon", 5, TR_SLAY_DRAGON, 20},
7349         {TR_KILL_DRAGON, "kill dragon", 5, TR_SLAY_DRAGON, 60},
7350         {TR_SLAY_HUMAN, "slay human", 5, TR_SLAY_HUMAN, 20},
7351         {TR_KILL_HUMAN, "kill human", 5, TR_SLAY_HUMAN, 60},
7352
7353         {TR_ESP_ANIMAL, "sense animal", 6, TR_SLAY_ANIMAL, 40},
7354         {TR_ESP_UNDEAD, "sense undead", 6, TR_SLAY_UNDEAD, 40}, 
7355         {TR_ESP_DEMON, "sense demon", 6, TR_SLAY_DEMON, 40},       
7356         {TR_ESP_ORC, "sense orc", 6, TR_SLAY_ORC, 40},     
7357         {TR_ESP_TROLL, "sense troll", 6, TR_SLAY_TROLL, 40},   
7358         {TR_ESP_GIANT, "sense giant", 6, TR_SLAY_GIANT, 40},       
7359         {TR_ESP_DRAGON, "sense dragon", 6, TR_SLAY_DRAGON, 40},
7360         {TR_ESP_HUMAN, "sense human", 6, TR_SLAY_HUMAN, 40},
7361
7362         {ESSENCE_ATTACK, "weapon enchant", 10, TR_ES_ATTACK, 30},
7363         {ESSENCE_AC, "armor enchant", 10, TR_ES_AC, 15},
7364         {ESSENCE_TMP_RES_ACID, "resist acid activation", 7, TR_RES_ACID, 50},
7365         {ESSENCE_TMP_RES_ELEC, "resist electricity activation", 7, TR_RES_ELEC, 50},
7366         {ESSENCE_TMP_RES_FIRE, "resist fire activation", 7, TR_RES_FIRE, 50},
7367         {ESSENCE_TMP_RES_COLD, "resist cold activation", 7, TR_RES_COLD, 50},
7368         {ESSENCE_SH_FIRE, "fiery sheath", 7, -1, 50},
7369         {ESSENCE_SH_ELEC, "electric sheath", 7, -1, 50},
7370         {ESSENCE_SH_COLD, "sheath of coldness", 7, -1, 50},
7371         {ESSENCE_RESISTANCE, "resistance", 2, -1, 150},
7372         {ESSENCE_SUSTAIN, "elements proof", 10, -1, 10},
7373         {ESSENCE_SLAY_GLOVE, "gauntlets of slaying", 1, TR_ES_ATTACK, 200},
7374
7375         {-1, NULL, 0, -1, 0}
7376 };
7377 #endif
7378
7379
7380 /*!
7381  * エッセンス名テーブル / Essense names for Weapon smith
7382  */
7383 #ifdef JP
7384 cptr essence_name[] = 
7385 {
7386         "腕力",
7387         "知能",
7388         "賢さ",
7389         "器用さ",
7390         "耐久力",
7391         "魅力",
7392         "魔力支配",
7393         "",
7394         "隠密",
7395         "探索",
7396         "赤外線視力",
7397         "採掘",
7398         "スピード",
7399         "追加攻撃",
7400         "カオス攻撃",
7401         "吸血攻撃",
7402         "動物倍打",
7403         "邪悪倍打",
7404         "不死倍打",
7405         "悪魔倍打",
7406         "オーク倍打",
7407         "トロル倍打",
7408         "巨人倍打",
7409         "竜倍打",
7410         "",
7411         "",
7412         "地震",
7413         "毒殺",
7414         "溶解",
7415         "電撃",
7416         "焼棄",
7417         "凍結",
7418         "能力維持",
7419         "",
7420         "",
7421         "",
7422         "",
7423         "",
7424         "",
7425         "",
7426         "免疫",
7427         "",
7428         "",
7429         "",
7430         "",
7431         "反射",
7432         "麻痺知らず",
7433         "経験値維持",
7434         "耐酸",
7435         "耐電撃",
7436         "耐火炎",
7437         "耐冷気",
7438         "耐毒",
7439         "耐恐怖",
7440         "耐閃光",
7441         "耐暗黒",
7442         "耐盲目",
7443         "耐混乱",
7444         "耐轟音",
7445         "耐破片",
7446         "耐地獄",
7447         "耐因果混乱",
7448         "耐カオス",
7449         "耐劣化",
7450         "",
7451         "",
7452         "人間倍打",
7453         "",
7454         "",
7455         "反魔法",
7456         "",
7457         "",
7458         "警告",
7459         "",
7460         "",
7461         "",
7462         "浮遊",
7463         "永久光源",
7464         "可視透明",
7465         "テレパシー",
7466         "遅消化",
7467         "急速回復",
7468         "",
7469         "",
7470         "",
7471         "",
7472         "",
7473         "",
7474         "",
7475         "",
7476         "テレポート",
7477         "",
7478         "",
7479         "攻撃",
7480         "防御",
7481
7482         NULL
7483 };
7484
7485 #else
7486
7487 cptr essence_name[] = 
7488 {
7489         "strength",
7490         "intelligen.",
7491         "wisdom",
7492         "dexterity",
7493         "constitut.",
7494         "charisma",
7495         "magic mast.",
7496         "",
7497         "stealth",
7498         "serching",
7499         "infravision",
7500         "digging",
7501         "speed",
7502         "extra atk",
7503         "chaos brand",
7504         "vampiric",
7505         "slay animal",
7506         "slay evil",
7507         "slay undead",
7508         "slay demon",
7509         "slay orc",
7510         "slay troll",
7511         "slay giant",
7512         "slay dragon",
7513         "",
7514         "",
7515         "quake",
7516         "pois. brand",
7517         "acid brand",
7518         "elec. brand",
7519         "fire brand",
7520         "cold brand",
7521         "sustain",
7522         "",
7523         "",
7524         "",
7525         "",
7526         "",
7527         "",
7528         "",
7529         "immunity",
7530         "",
7531         "",
7532         "",
7533         "",
7534         "reflection",
7535         "free action",
7536         "hold exp",
7537         "res. acid",
7538         "res. elec.",
7539         "res. fire",
7540         "res. cold",
7541         "res. poison",
7542         "res. fear",
7543         "res. light",
7544         "res. dark",
7545         "res. blind",
7546         "res.confuse",
7547         "res. sound",
7548         "res. shard",
7549         "res. nether",
7550         "res. nexus",
7551         "res. chaos",
7552         "res. disen.",
7553         "",
7554         "",
7555         "slay human",
7556         "",
7557         "",
7558         "anti magic",
7559         "",
7560         "",
7561         "warning",
7562         "",
7563         "",
7564         "",
7565         "levitation",
7566         "perm. light",
7567         "see invis.",
7568         "telepathy",
7569         "slow dige.",
7570         "regen.",
7571         "",
7572         "",
7573         "",
7574         "",
7575         "",
7576         "",
7577         "",
7578         "",
7579         "teleport",
7580         "",
7581         "",
7582         "weapon enc.",
7583         "armor enc.",
7584
7585         NULL
7586 };
7587 #endif
7588
7589 /*!
7590  * @brief 所持しているエッセンス一覧を表示する
7591  * @return なし
7592  */
7593 static void display_essence(void)
7594 {
7595         int i, num = 0;
7596
7597         screen_save();
7598         for (i = 1; i < 22; i++)
7599         {
7600                 prt("",i,0);
7601         }
7602         prt(_("エッセンス   個数     エッセンス   個数     エッセンス   個数", 
7603                   "Essence      Num      Essence      Num      Essence      Num "), 1, 8);
7604         for (i = 0; essence_name[i]; i++)
7605         {
7606                 if (!essence_name[i][0]) continue;
7607                 prt(format("%-11s %5d", essence_name[i], p_ptr->magic_num1[i]), 2+num%21, 8+num/21*22);
7608                 num++;
7609         }
7610         prt(_("現在所持しているエッセンス", "List of all essences you have."), 0, 0);
7611         (void)inkey();
7612         screen_load();
7613         return;
7614 }
7615
7616 /*!
7617  * @brief エッセンスの抽出処理
7618  * @return なし
7619  */
7620 static void drain_essence(void)
7621 {
7622         int drain_value[sizeof(p_ptr->magic_num1) / sizeof(s32b)];
7623         int i;
7624         OBJECT_IDX item;
7625         int dec = 4;
7626         bool observe = FALSE;
7627         int old_ds, old_dd, old_to_h, old_to_d, old_ac, old_to_a, old_pval, old_name2;
7628         TIME_EFFECT old_timeout;
7629         BIT_FLAGS old_flgs[TR_FLAG_SIZE], new_flgs[TR_FLAG_SIZE];
7630         object_type *o_ptr;
7631         cptr q, s;
7632         POSITION iy, ix;
7633         byte_hack marked;
7634         ITEM_NUMBER number;
7635         OBJECT_IDX next_o_idx;
7636         WEIGHT weight;
7637
7638         for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
7639                 drain_value[i] = 0;
7640
7641         item_tester_hook = object_is_weapon_armour_ammo;
7642         item_tester_no_ryoute = TRUE;
7643
7644         /* Get an item */
7645         q = _("どのアイテムから抽出しますか?", "Extract from which item? ");
7646         s = _("抽出できるアイテムがありません。", "You have nothing you can extract from.");
7647
7648         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
7649
7650         /* Get the item (in the pack) */
7651         if (item >= 0)
7652         {
7653                 o_ptr = &inventory[item];
7654         }
7655
7656         /* Get the item (on the floor) */
7657         else
7658         {
7659                 o_ptr = &o_list[0 - item];
7660         }
7661
7662         if (object_is_known(o_ptr) && !object_is_nameless(o_ptr))
7663         {
7664                 char o_name[MAX_NLEN];
7665                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
7666                 if (!get_check(format(_("本当に%sから抽出してよろしいですか?", "Really extract from %s? "), o_name))) return;
7667         }
7668
7669         p_ptr->energy_use = 100;
7670
7671         object_flags(o_ptr, old_flgs);
7672         if (have_flag(old_flgs, TR_KILL_DRAGON)) add_flag(old_flgs, TR_SLAY_DRAGON);
7673         if (have_flag(old_flgs, TR_KILL_ANIMAL)) add_flag(old_flgs, TR_SLAY_ANIMAL);
7674         if (have_flag(old_flgs, TR_KILL_EVIL)) add_flag(old_flgs, TR_SLAY_EVIL);
7675         if (have_flag(old_flgs, TR_KILL_UNDEAD)) add_flag(old_flgs, TR_SLAY_UNDEAD);
7676         if (have_flag(old_flgs, TR_KILL_DEMON)) add_flag(old_flgs, TR_SLAY_DEMON);
7677         if (have_flag(old_flgs, TR_KILL_ORC)) add_flag(old_flgs, TR_SLAY_ORC);
7678         if (have_flag(old_flgs, TR_KILL_TROLL)) add_flag(old_flgs, TR_SLAY_TROLL);
7679         if (have_flag(old_flgs, TR_KILL_GIANT)) add_flag(old_flgs, TR_SLAY_GIANT);
7680         if (have_flag(old_flgs, TR_KILL_HUMAN)) add_flag(old_flgs, TR_SLAY_HUMAN);
7681
7682         old_to_a = o_ptr->to_a;
7683         old_ac = o_ptr->ac;
7684         old_to_h = o_ptr->to_h;
7685         old_to_d = o_ptr->to_d;
7686         old_ds = o_ptr->ds;
7687         old_dd = o_ptr->dd;
7688         old_pval = o_ptr->pval;
7689         old_name2 = o_ptr->name2;
7690         old_timeout = o_ptr->timeout;
7691         if (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE)) dec--;
7692         if (have_flag(old_flgs, TR_ADD_L_CURSE)) dec--;
7693         if (have_flag(old_flgs, TR_ADD_H_CURSE)) dec--;
7694         if (have_flag(old_flgs, TR_AGGRAVATE)) dec--;
7695         if (have_flag(old_flgs, TR_NO_TELE)) dec--;
7696         if (have_flag(old_flgs, TR_DRAIN_EXP)) dec--;
7697         if (have_flag(old_flgs, TR_DRAIN_HP)) dec--;
7698         if (have_flag(old_flgs, TR_DRAIN_MANA)) dec--;
7699         if (have_flag(old_flgs, TR_CALL_ANIMAL)) dec--;
7700         if (have_flag(old_flgs, TR_CALL_DEMON)) dec--;
7701         if (have_flag(old_flgs, TR_CALL_DRAGON)) dec--;
7702         if (have_flag(old_flgs, TR_CALL_UNDEAD)) dec--;
7703         if (have_flag(old_flgs, TR_COWARDICE)) dec--;
7704         if (have_flag(old_flgs, TR_LOW_MELEE)) dec--;
7705         if (have_flag(old_flgs, TR_LOW_AC)) dec--;
7706         if (have_flag(old_flgs, TR_LOW_MAGIC)) dec--;
7707         if (have_flag(old_flgs, TR_FAST_DIGEST)) dec--;
7708         if (have_flag(old_flgs, TR_SLOW_REGEN)) dec--;
7709         if (have_flag(old_flgs, TR_TY_CURSE)) dec--;
7710         
7711         iy = o_ptr->iy;
7712         ix = o_ptr->ix;
7713         next_o_idx = o_ptr->next_o_idx;
7714         marked = o_ptr->marked;
7715         weight = o_ptr->weight;
7716         number = o_ptr->number;
7717
7718         object_prep(o_ptr, o_ptr->k_idx);
7719
7720         o_ptr->iy=iy;
7721         o_ptr->ix=ix;
7722         o_ptr->next_o_idx=next_o_idx;
7723         o_ptr->marked=marked;
7724         o_ptr->number = number;
7725         if (o_ptr->tval == TV_DRAG_ARMOR) o_ptr->timeout = old_timeout;
7726         if (item >= 0) p_ptr->total_weight += (o_ptr->weight*o_ptr->number - weight*number);
7727         o_ptr->ident |= (IDENT_MENTAL);
7728         object_aware(o_ptr);
7729         object_known(o_ptr);
7730
7731         object_flags(o_ptr, new_flgs);
7732
7733         for (i = 0; essence_info[i].add_name; i++)
7734         {
7735                 essence_type *es_ptr = &essence_info[i];
7736                 PARAMETER_VALUE pval = 0;
7737
7738                 if (es_ptr->add < TR_FLAG_MAX && is_pval_flag(es_ptr->add) && old_pval)
7739                         pval = (have_flag(new_flgs, es_ptr->add)) ? old_pval - o_ptr->pval : old_pval;
7740
7741                 if (es_ptr->add < TR_FLAG_MAX &&
7742                     (!have_flag(new_flgs, es_ptr->add) || pval) &&
7743                     have_flag(old_flgs, es_ptr->add))
7744                 {
7745                         if (pval)
7746                         {
7747                                 drain_value[es_ptr->essence] += 10 * pval;
7748                         }
7749                         else if (es_ptr->essence != -2)
7750                         {
7751                                 drain_value[es_ptr->essence] += 10;
7752                         }
7753                         else if (es_ptr->add == TR_SH_FIRE)
7754                         {
7755                                 drain_value[TR_BRAND_FIRE] += 10;
7756                                 drain_value[TR_RES_FIRE] += 10;
7757                         }
7758                         else if (es_ptr->add == TR_SH_ELEC)
7759                         {
7760                                 drain_value[TR_BRAND_ELEC] += 10;
7761                                 drain_value[TR_RES_ELEC] += 10;
7762                         }
7763                         else if (es_ptr->add == TR_SH_COLD)
7764                         {
7765                                 drain_value[TR_BRAND_COLD] += 10;
7766                                 drain_value[TR_RES_COLD] += 10;
7767                         }
7768                         else if (es_ptr->add == TR_LITE_2)
7769                         {
7770                                 drain_value[TR_LITE_1] += 20;
7771                         }
7772                         else if (es_ptr->add == TR_LITE_3)
7773                         {
7774                                 drain_value[TR_LITE_1] += 30;
7775                         }
7776                 }
7777         }
7778
7779         if ((have_flag(old_flgs, TR_FORCE_WEAPON)) && !(have_flag(new_flgs, TR_FORCE_WEAPON)))
7780         {
7781                 drain_value[TR_INT] += 5;
7782                 drain_value[TR_WIS] += 5;
7783         }
7784         if ((have_flag(old_flgs, TR_VORPAL)) && !(have_flag(new_flgs, TR_VORPAL)))
7785         {
7786                 drain_value[TR_BRAND_POIS] += 5;
7787                 drain_value[TR_BRAND_ACID] += 5;
7788                 drain_value[TR_BRAND_ELEC] += 5;
7789                 drain_value[TR_BRAND_FIRE] += 5;
7790                 drain_value[TR_BRAND_COLD] += 5;
7791         }
7792         if ((have_flag(old_flgs, TR_DEC_MANA)) && !(have_flag(new_flgs, TR_DEC_MANA)))
7793         {
7794                 drain_value[TR_INT] += 10;
7795         }
7796         if ((have_flag(old_flgs, TR_XTRA_MIGHT)) && !(have_flag(new_flgs, TR_XTRA_MIGHT)))
7797         {
7798                 drain_value[TR_STR] += 10;
7799         }
7800         if ((have_flag(old_flgs, TR_XTRA_SHOTS)) && !(have_flag(new_flgs, TR_XTRA_SHOTS)))
7801         {
7802                 drain_value[TR_DEX] += 10;
7803         }
7804         if (old_name2 == EGO_2WEAPON)
7805         {
7806                 drain_value[TR_DEX] += 20;
7807         }
7808         if (object_is_weapon_ammo(o_ptr))
7809         {
7810                 if (old_ds > o_ptr->ds) drain_value[TR_ES_ATTACK] += (old_ds-o_ptr->ds)*10;
7811
7812                 if (old_dd > o_ptr->dd) drain_value[TR_ES_ATTACK] += (old_dd-o_ptr->dd)*10;
7813         }
7814         if (old_to_h > o_ptr->to_h) drain_value[TR_ES_ATTACK] += (old_to_h-o_ptr->to_h)*10;
7815         if (old_to_d > o_ptr->to_d) drain_value[TR_ES_ATTACK] += (old_to_d-o_ptr->to_d)*10;
7816         if (old_ac > o_ptr->ac) drain_value[TR_ES_AC] += (old_ac-o_ptr->ac)*10;
7817         if (old_to_a > o_ptr->to_a) drain_value[TR_ES_AC] += (old_to_a-o_ptr->to_a)*10;
7818
7819         for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
7820         {
7821                 drain_value[i] *= number;
7822                 drain_value[i] = drain_value[i] * dec / 4;
7823                 drain_value[i] = MAX(drain_value[i], 0);
7824                 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) drain_value[i] /= 10;
7825                 if (drain_value[i])
7826                 {
7827                         observe = TRUE;
7828                 }
7829         }
7830         if (!observe)
7831         {
7832                 msg_print(_("エッセンスは抽出できませんでした。", "You were not able to extract any essence."));
7833         }
7834         else
7835         {
7836                 msg_print(_("抽出したエッセンス:", "Extracted essences:"));
7837
7838                 for (i = 0; essence_name[i]; i++)
7839                 {
7840                         if (!essence_name[i][0]) continue;
7841                         if (!drain_value[i]) continue;
7842
7843                         p_ptr->magic_num1[i] += drain_value[i];
7844                         p_ptr->magic_num1[i] = MIN(20000, p_ptr->magic_num1[i]);
7845                         msg_print(NULL);
7846                         msg_format("%s...%d%s", essence_name[i], drain_value[i], _("。", ". "));
7847                 }
7848         }
7849
7850         /* Apply autodestroy/inscription to the drained item */
7851         autopick_alter_item(item, TRUE);
7852
7853         /* Combine the pack */
7854         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
7855
7856         /* Window stuff */
7857         p_ptr->window |= (PW_INVEN);
7858 }
7859
7860 /*!
7861  * @brief 付加するエッセンスの大別を選択する
7862  * @return 選んだエッセンスの大別ID
7863  */
7864 static COMMAND_CODE choose_essence(void)
7865 {
7866         COMMAND_CODE mode = 0;
7867         char choice;
7868         COMMAND_CODE menu_line = (use_menu ? 1 : 0);
7869
7870 #ifdef JP
7871         cptr menu_name[] = {
7872                 "武器属性", 
7873                 "耐性",
7874                 "能力",
7875                 "数値",
7876                 "スレイ",
7877                 "ESP",
7878                 "その他"
7879         };
7880 #else
7881         cptr menu_name[] = {
7882                 "Brand weapon",
7883                 "Resistance",
7884                 "Ability",
7885                 "Magic number", 
7886                 "Slay",
7887                 "ESP",
7888                 "Others"
7889         };
7890 #endif
7891         const COMMAND_CODE mode_max = 7;
7892
7893 #ifdef ALLOW_REPEAT
7894         if (repeat_pull(&mode) && 1 <= mode && mode <= mode_max)
7895                 return mode;
7896         mode = 0;
7897 #endif /* ALLOW_REPEAT */
7898
7899         if (use_menu)
7900         {
7901                 screen_save();
7902
7903                 while(!mode)
7904                 {
7905                         int i;
7906                         for (i = 0; i < mode_max; i++)
7907 #ifdef JP
7908                                 prt(format(" %s %s", (menu_line == 1+i) ? "》" : "  ", menu_name[i]), 2 + i, 14);
7909                         prt("どの種類のエッセンス付加を行いますか?", 0, 0);
7910 #else
7911                                 prt(format(" %s %s", (menu_line == 1+i) ? "> " : "  ", menu_name[i]), 2 + i, 14);
7912                         prt("Choose from menu.", 0, 0);
7913 #endif
7914
7915                         choice = inkey();
7916                         switch(choice)
7917                         {
7918                         case ESCAPE:
7919                         case 'z':
7920                         case 'Z':
7921                                 screen_load();
7922                                 return 0;
7923                         case '2':
7924                         case 'j':
7925                         case 'J':
7926                                 menu_line++;
7927                                 break;
7928                         case '8':
7929                         case 'k':
7930                         case 'K':
7931                                 menu_line += mode_max - 1;
7932                                 break;
7933                         case '\r':
7934                         case '\n':
7935                         case 'x':
7936                         case 'X':
7937                                 mode = menu_line;
7938                                 break;
7939                         }
7940                         if (menu_line > mode_max) menu_line -= mode_max;
7941                 }
7942                 screen_load();
7943         }
7944         else
7945         {
7946                 screen_save();
7947                 while (!mode)
7948                 {
7949                         int i;
7950
7951                         for (i = 0; i < mode_max; i++)
7952                                 prt(format("  %c) %s", 'a' + i, menu_name[i]), 2 + i, 14);
7953
7954                         if (!get_com(_("何を付加しますか:", "Command :"), &choice, TRUE))
7955                         {
7956                                 screen_load();
7957                                 return 0;
7958                         }
7959
7960                         if (isupper(choice)) choice = (char)tolower(choice);
7961
7962                         if ('a' <= choice && choice <= 'a' + (char)mode_max - 1)
7963                                 mode = (int)choice - 'a' + 1;
7964                 }
7965                 screen_load();
7966         }
7967
7968 #ifdef ALLOW_REPEAT
7969         repeat_push(mode);
7970 #endif /* ALLOW_REPEAT */
7971         return mode;
7972 }
7973
7974 /*!
7975  * @brief エッセンスを実際に付加する
7976  * @param mode エッセンスの大別ID
7977  * @return なし
7978  */
7979 static void add_essence(ESSENCE_IDX mode)
7980 {
7981         OBJECT_IDX item;
7982         int max_num = 0;
7983         COMMAND_CODE i;
7984         bool flag,redraw;
7985         char choice;
7986         cptr            q, s;
7987         object_type *o_ptr;
7988         int ask = TRUE;
7989         char out_val[160];
7990         int num[22];
7991         char o_name[MAX_NLEN];
7992         int use_essence;
7993         essence_type *es_ptr;
7994         bool able[22] = { 0 };
7995
7996         int menu_line = (use_menu ? 1 : 0);
7997
7998         for (i = 0; essence_info[i].add_name; i++)
7999         {
8000                 es_ptr = &essence_info[i];
8001
8002                 if (es_ptr->type != mode) continue;
8003                 num[max_num++] = i;
8004         }
8005
8006 #ifdef ALLOW_REPEAT
8007         if (!repeat_pull(&i) || i<0 || i>=max_num)
8008         {
8009 #endif /* ALLOW_REPEAT */
8010
8011
8012         /* Nothing chosen yet */
8013         flag = FALSE;
8014
8015         /* No redraw yet */
8016         redraw = FALSE;
8017
8018         /* Build a prompt */
8019         (void) strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの能力を付加しますか?", "(*=List, ESC=exit) Add which ability? "));
8020         if (use_menu) screen_save();
8021
8022         /* Get a spell from the user */
8023
8024         choice = (always_show_list || use_menu) ? ESCAPE:1;
8025         while (!flag)
8026         {
8027                 if( choice==ESCAPE ) choice = ' '; 
8028                 else if( !get_com(out_val, &choice, FALSE) )break; 
8029
8030                 if (use_menu && choice != ' ')
8031                 {
8032                         switch(choice)
8033                         {
8034                                 case '0':
8035                                 {
8036                                         screen_load();
8037                                         return;
8038                                 }
8039
8040                                 case '8':
8041                                 case 'k':
8042                                 case 'K':
8043                                 {
8044                                         menu_line += (max_num-1);
8045                                         break;
8046                                 }
8047
8048                                 case '2':
8049                                 case 'j':
8050                                 case 'J':
8051                                 {
8052                                         menu_line++;
8053                                         break;
8054                                 }
8055
8056                                 case '4':
8057                                 case 'h':
8058                                 case 'H':
8059                                 {
8060                                         menu_line = 1;
8061                                         break;
8062                                 }
8063                                 case '6':
8064                                 case 'l':
8065                                 case 'L':
8066                                 {
8067                                         menu_line = max_num;
8068                                         break;
8069                                 }
8070
8071                                 case 'x':
8072                                 case 'X':
8073                                 case '\r':
8074                                 case '\n':
8075                                 {
8076                                         i = menu_line - 1;
8077                                         ask = FALSE;
8078                                         break;
8079                                 }
8080                         }
8081                         if (menu_line > max_num) menu_line -= max_num;
8082                 }
8083                 /* Request redraw */
8084                 if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
8085                 {
8086                         /* Show the list */
8087                         if (!redraw || use_menu)
8088                         {
8089                                 byte y, x = 10;
8090                                 int ctr;
8091                                 char dummy[80], dummy2[80];
8092                                 byte col;
8093
8094                                 strcpy(dummy, "");
8095
8096                                 /* Show list */
8097                                 redraw = TRUE;
8098
8099                                 /* Save the screen */
8100                                 if (!use_menu) screen_save();
8101
8102                                 for (y = 1; y < 24; y++)
8103                                         prt("", y, x);
8104
8105                                 /* Print header(s) */
8106 #ifdef JP
8107                                 prt(format("   %-43s %6s/%s", "能力(必要エッセンス)", "必要数", "所持数"), 1, x);
8108
8109 #else
8110                                 prt(format("   %-43s %6s/%s", "Ability (needed essence)", "Needs", "Possess"), 1, x);
8111 #endif
8112                                 /* Print list */
8113                                 for (ctr = 0; ctr < max_num; ctr++)
8114                                 {
8115                                         es_ptr = &essence_info[num[ctr]];
8116
8117                                         if (use_menu)
8118                                         {
8119                                                 if (ctr == (menu_line-1))
8120                                                         strcpy(dummy, _("》 ", ">  "));
8121                                                 else strcpy(dummy, "   ");
8122                                                 
8123                                         }
8124                                         /* letter/number for power selection */
8125                                         else
8126                                         {
8127                                                 sprintf(dummy, "%c) ",I2A(ctr));
8128                                         }
8129
8130                                         strcat(dummy, es_ptr->add_name);
8131
8132                                         col = TERM_WHITE;
8133                                         able[ctr] = TRUE;
8134
8135                                         if (es_ptr->essence != -1)
8136                                         {
8137                                                 strcat(dummy, format("(%s)", essence_name[es_ptr->essence]));
8138                                                 if (p_ptr->magic_num1[es_ptr->essence] < es_ptr->value) able[ctr] = FALSE;
8139                                         }
8140                                         else
8141                                         {
8142                                                 switch(es_ptr->add)
8143                                                 {
8144                                                 case ESSENCE_SH_FIRE:
8145                                                         strcat(dummy, _("(焼棄+耐火炎)", "(brand fire + res.fire)"));
8146                                                         if (p_ptr->magic_num1[TR_BRAND_FIRE] < es_ptr->value) able[ctr] = FALSE;
8147                                                         if (p_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
8148                                                         break;
8149                                                 case ESSENCE_SH_ELEC:
8150                                                         strcat(dummy, _("(電撃+耐電撃)", "(brand elec. + res. elec.)"));
8151                                                         if (p_ptr->magic_num1[TR_BRAND_ELEC] < es_ptr->value) able[ctr] = FALSE;
8152                                                         if (p_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
8153                                                         break;
8154                                                 case ESSENCE_SH_COLD:
8155                                                         strcat(dummy, _("(凍結+耐冷気)", "(brand cold + res. cold)"));
8156                                                         if (p_ptr->magic_num1[TR_BRAND_COLD] < es_ptr->value) able[ctr] = FALSE;
8157                                                         if (p_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
8158                                                         break;
8159                                                 case ESSENCE_RESISTANCE:
8160                                                         strcat(dummy, _("(耐火炎+耐冷気+耐電撃+耐酸)", "(r.fire+r.cold+r.elec+r.acid)"));
8161                                                         if (p_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
8162                                                         if (p_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
8163                                                         if (p_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
8164                                                         if (p_ptr->magic_num1[TR_RES_ACID] < es_ptr->value) able[ctr] = FALSE;
8165                                                         break;
8166                                                 case ESSENCE_SUSTAIN:
8167                                                         strcat(dummy, _("(耐火炎+耐冷気+耐電撃+耐酸)", "(r.fire+r.cold+r.elec+r.acid)"));
8168                                                         if (p_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
8169                                                         if (p_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
8170                                                         if (p_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
8171                                                         if (p_ptr->magic_num1[TR_RES_ACID] < es_ptr->value) able[ctr] = FALSE;
8172                                                         break;
8173                                                 }
8174                                         }
8175
8176                                         if (!able[ctr]) col = TERM_RED;
8177
8178                                         if (es_ptr->essence != -1)
8179                                         {
8180                                                 sprintf(dummy2, "%-49s %3d/%d", dummy, es_ptr->value, (int)p_ptr->magic_num1[es_ptr->essence]);
8181                                         }
8182                                         else
8183                                         {
8184                                                 sprintf(dummy2, "%-49s %3d/(\?\?)", dummy, es_ptr->value);
8185                                         }
8186
8187                                         c_prt(col, dummy2, ctr+2, x);
8188                                 }
8189                         }
8190
8191                         /* Hide the list */
8192                         else
8193                         {
8194                                 /* Hide list */
8195                                 redraw = FALSE;
8196
8197                                 /* Restore the screen */
8198                                 screen_load();
8199                         }
8200
8201                         /* Redo asking */
8202                         continue;
8203                 }
8204
8205                 if (!use_menu)
8206                 {
8207                         /* Note verify */
8208                         ask = (isupper(choice));
8209
8210                         /* Lowercase */
8211                         if (ask) choice = (char)tolower(choice);
8212
8213                         /* Extract request */
8214                         i = (islower(choice) ? A2I(choice) : -1);
8215                 }
8216
8217                 /* Totally Illegal */
8218                 if ((i < 0) || (i >= max_num) || !able[i])
8219                 {
8220                         bell();
8221                         continue;
8222                 }
8223
8224                 /* Verify it */
8225                 if (ask)
8226                 {
8227                         char tmp_val[160];
8228
8229                         /* Prompt */
8230                         (void) strnfmt(tmp_val, 78, _("%sを付加しますか? ", "Add the abilitiy of %s? "), essence_info[num[i]].add_name);
8231
8232                         /* Belay that order */
8233                         if (!get_check(tmp_val)) continue;
8234                 }
8235
8236                 /* Stop the loop */
8237                 flag = TRUE;
8238         }
8239
8240         /* Restore the screen */
8241         if (redraw) screen_load();
8242
8243         if (!flag) return;
8244
8245 #ifdef ALLOW_REPEAT
8246         repeat_push(i);
8247         }
8248 #endif /* ALLOW_REPEAT */
8249
8250         es_ptr = &essence_info[num[i]];
8251
8252         if (es_ptr->add == ESSENCE_SLAY_GLOVE)
8253                 item_tester_tval = TV_GLOVES;
8254         else if (mode == 1 || mode == 5)
8255                 item_tester_hook = item_tester_hook_melee_ammo;
8256         else if (es_ptr->add == ESSENCE_ATTACK)
8257                 item_tester_hook = object_allow_enchant_weapon;
8258         else if (es_ptr->add == ESSENCE_AC)
8259                 item_tester_hook = object_is_armour;
8260         else
8261                 item_tester_hook = object_is_weapon_armour_ammo;
8262         item_tester_no_ryoute = TRUE;
8263
8264         /* Get an item */
8265         q = _("どのアイテムを改良しますか?", "Improve which item? ");
8266         s = _("改良できるアイテムがありません。", "You have nothing to improve.");
8267
8268         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
8269
8270         /* Get the item (in the pack) */
8271         if (item >= 0)
8272         {
8273                 o_ptr = &inventory[item];
8274         }
8275
8276         /* Get the item (on the floor) */
8277         else
8278         {
8279                 o_ptr = &o_list[0 - item];
8280         }
8281
8282         if ((mode != 10) && (object_is_artifact(o_ptr) || object_is_smith(o_ptr)))
8283         {
8284                 msg_print(_("そのアイテムはこれ以上改良できない。", "This item is no more able to be improved."));
8285                 return;
8286         }
8287
8288         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
8289
8290         use_essence = es_ptr->value;
8291         if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) use_essence = (use_essence+9)/10;
8292         if (o_ptr->number > 1)
8293         {
8294                 use_essence *= o_ptr->number;
8295                 msg_format(_("%d個あるのでエッセンスは%d必要です。", "It will take %d essences."), o_ptr->number, use_essence);
8296         }
8297
8298         if (es_ptr->essence != -1)
8299         {
8300                 if (p_ptr->magic_num1[es_ptr->essence] < use_essence)
8301                 {
8302                         msg_print(_("エッセンスが足りない。", "You don't have enough essences."));
8303                         return;
8304                 }
8305                 if (is_pval_flag(es_ptr->add))
8306                 {
8307                         if (o_ptr->pval < 0)
8308                         {
8309                                 msg_print(_("このアイテムの能力修正を強化することはできない。", "You cannot increase magic number of this item."));
8310                                 return;
8311                         }
8312                         else if (es_ptr->add == TR_BLOWS)
8313                         {
8314                                 if (o_ptr->pval > 1)
8315                                 {
8316                                         if (!get_check(_("修正値は1になります。よろしいですか?", "The magic number of this weapon will become 1. Are you sure? "))) return;
8317                                 }
8318
8319                                 o_ptr->pval = 1;
8320                                 msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence);
8321                         }
8322                         else if (o_ptr->pval > 0)
8323                         {
8324                                 use_essence *= o_ptr->pval;
8325                                 msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence);
8326                         }
8327                         else
8328                         {
8329                                 char tmp[80];
8330                                 char tmp_val[160];
8331                                 PARAMETER_VALUE pval;
8332                                 PARAMETER_VALUE limit = MIN(5, p_ptr->magic_num1[es_ptr->essence]/es_ptr->value);
8333
8334                                 sprintf(tmp, _("いくつ付加しますか? (1-%d): ", "Enchant how many? (1-%d): "), limit);
8335                                 strcpy(tmp_val, "1");
8336
8337                                 if (!get_string(tmp, tmp_val, 1)) return;
8338                                 pval = (PARAMETER_VALUE)atoi(tmp_val);
8339                                 if (pval > limit) pval = limit;
8340                                 else if (pval < 1) pval = 1;
8341                                 o_ptr->pval += pval;
8342                                 use_essence *= pval;
8343                                 msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence);
8344                         }
8345
8346                         if (p_ptr->magic_num1[es_ptr->essence] < use_essence)
8347                         {
8348                                 msg_print(_("エッセンスが足りない。", "You don't have enough essences."));
8349                                 return;
8350                         }
8351                 }
8352                 else if (es_ptr->add == ESSENCE_SLAY_GLOVE)
8353                 {
8354                         char tmp_val[160];
8355                         int val;
8356                         HIT_PROB get_to_h;
8357                         HIT_POINT get_to_d;
8358
8359                         strcpy(tmp_val, "1");
8360                         if (!get_string(format(_("いくつ付加しますか? (1-%d):", "Enchant how many? (1-%d):"), p_ptr->lev/7+3), tmp_val, 2)) return;
8361                         val = atoi(tmp_val);
8362                         if (val > p_ptr->lev/7+3) val = p_ptr->lev/7+3;
8363                         else if (val < 1) val = 1;
8364                         use_essence *= val;
8365                         msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence);
8366                         if (p_ptr->magic_num1[es_ptr->essence] < use_essence)
8367                         {
8368                                 msg_print(_("エッセンスが足りない。", "You don't have enough essences."));
8369                                 return;
8370                         }
8371                         get_to_h = ((val+1)/2+randint0(val/2+1));
8372                         get_to_d = ((val+1)/2+randint0(val/2+1));
8373                         o_ptr->xtra4 = (get_to_h<<8)+get_to_d;
8374                         o_ptr->to_h += get_to_h;
8375                         o_ptr->to_d += get_to_d;
8376                 }
8377                 p_ptr->magic_num1[es_ptr->essence] -= use_essence;
8378                 if (es_ptr->add == ESSENCE_ATTACK)
8379                 {
8380                         if ((o_ptr->to_h >= p_ptr->lev/5+5) && (o_ptr->to_d >= p_ptr->lev/5+5))
8381                         {
8382                                 msg_print(_("改良に失敗した。", "You failed to enchant."));
8383                                 p_ptr->energy_use = 100;
8384                                 return;
8385                         }
8386                         else
8387                         {
8388                                 if (o_ptr->to_h < p_ptr->lev/5+5) o_ptr->to_h++;
8389                                 if (o_ptr->to_d < p_ptr->lev/5+5) o_ptr->to_d++;
8390                         }
8391                 }
8392                 else if (es_ptr->add == ESSENCE_AC)
8393                 {
8394                         if (o_ptr->to_a >= p_ptr->lev/5+5)
8395                         {
8396                                 msg_print(_("改良に失敗した。", "You failed to enchant."));
8397                                 p_ptr->energy_use = 100;
8398                                 return;
8399                         }
8400                         else
8401                         {
8402                                 if (o_ptr->to_a < p_ptr->lev/5+5) o_ptr->to_a++;
8403                         }
8404                 }
8405                 else
8406                 {
8407                         o_ptr->xtra3 = es_ptr->add + 1;
8408                 }
8409         }
8410         else
8411         {
8412                 bool success = TRUE;
8413
8414                 switch(es_ptr->add)
8415                 {
8416                 case ESSENCE_SH_FIRE:
8417                         if ((p_ptr->magic_num1[TR_BRAND_FIRE] < use_essence) || (p_ptr->magic_num1[TR_RES_FIRE] < use_essence))
8418                         {
8419                                 success = FALSE;
8420                                 break;
8421                         }
8422                         p_ptr->magic_num1[TR_BRAND_FIRE] -= use_essence;
8423                         p_ptr->magic_num1[TR_RES_FIRE] -= use_essence;
8424                         break;
8425                 case ESSENCE_SH_ELEC:
8426                         if ((p_ptr->magic_num1[TR_BRAND_ELEC] < use_essence) || (p_ptr->magic_num1[TR_RES_ELEC] < use_essence))
8427                         {
8428                                 success = FALSE;
8429                                 break;
8430                         }
8431                         p_ptr->magic_num1[TR_BRAND_ELEC] -= use_essence;
8432                         p_ptr->magic_num1[TR_RES_ELEC] -= use_essence;
8433                         break;
8434                 case ESSENCE_SH_COLD:
8435                         if ((p_ptr->magic_num1[TR_BRAND_COLD] < use_essence) || (p_ptr->magic_num1[TR_RES_COLD] < use_essence))
8436                         {
8437                                 success = FALSE;
8438                                 break;
8439                         }
8440                         p_ptr->magic_num1[TR_BRAND_COLD] -= use_essence;
8441                         p_ptr->magic_num1[TR_RES_COLD] -= use_essence;
8442                         break;
8443                 case ESSENCE_RESISTANCE:
8444                 case ESSENCE_SUSTAIN:
8445                         if ((p_ptr->magic_num1[TR_RES_ACID] < use_essence) || (p_ptr->magic_num1[TR_RES_ELEC] < use_essence) || (p_ptr->magic_num1[TR_RES_FIRE] < use_essence) || (p_ptr->magic_num1[TR_RES_COLD] < use_essence))
8446                         {
8447                                 success = FALSE;
8448                                 break;
8449                         }
8450                         p_ptr->magic_num1[TR_RES_ACID] -= use_essence;
8451                         p_ptr->magic_num1[TR_RES_ELEC] -= use_essence;
8452                         p_ptr->magic_num1[TR_RES_FIRE] -= use_essence;
8453                         p_ptr->magic_num1[TR_RES_COLD] -= use_essence;
8454                         break;
8455                 }
8456                 if (!success)
8457                 {
8458                         msg_print(_("エッセンスが足りない。", "You don't have enough essences."));
8459                         return;
8460                 }
8461                 if (es_ptr->add == ESSENCE_SUSTAIN)
8462                 {
8463                         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
8464                         add_flag(o_ptr->art_flags, TR_IGNORE_ELEC);
8465                         add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
8466                         add_flag(o_ptr->art_flags, TR_IGNORE_COLD);
8467                 }
8468                 else
8469                 {
8470                         o_ptr->xtra3 = es_ptr->add + 1;
8471                 }
8472         }
8473
8474         p_ptr->energy_use = 100;
8475
8476 #ifdef JP
8477         msg_format("%sに%sの能力を付加しました。", o_name, es_ptr->add_name);
8478 #else
8479         msg_format("You have added ability of %s to %s.", es_ptr->add_name, o_name);
8480 #endif
8481
8482         /* Combine the pack */
8483         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
8484
8485         /* Window stuff */
8486         p_ptr->window |= (PW_INVEN);
8487 }
8488
8489 /*!
8490  * @brief エッセンスを消去する
8491  * @return なし
8492  */
8493 static void erase_essence(void)
8494 {
8495         OBJECT_IDX item;
8496         cptr q, s;
8497         object_type *o_ptr;
8498         char o_name[MAX_NLEN];
8499         BIT_FLAGS flgs[TR_FLAG_SIZE];
8500
8501         item_tester_hook = object_is_smith;
8502
8503         /* Get an item */
8504         q = _("どのアイテムのエッセンスを消去しますか?", "Remove from which item? ");
8505         s = _("エッセンスを付加したアイテムがありません。", "You have nothing to remove essence.");
8506
8507         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
8508
8509         /* Get the item (in the pack) */
8510         if (item >= 0)
8511         {
8512                 o_ptr = &inventory[item];
8513         }
8514
8515         /* Get the item (on the floor) */
8516         else
8517         {
8518                 o_ptr = &o_list[0 - item];
8519         }
8520
8521         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
8522         if (!get_check(format(_("よろしいですか? [%s]", "Are you sure? [%s]"), o_name))) return;
8523
8524         p_ptr->energy_use = 100;
8525
8526         if (o_ptr->xtra3 == 1+ESSENCE_SLAY_GLOVE)
8527         {
8528                 o_ptr->to_h -= (o_ptr->xtra4>>8);
8529                 o_ptr->to_d -= (o_ptr->xtra4 & 0x000f);
8530                 o_ptr->xtra4 = 0;
8531                 if (o_ptr->to_h < 0) o_ptr->to_h = 0;
8532                 if (o_ptr->to_d < 0) o_ptr->to_d = 0;
8533         }
8534         o_ptr->xtra3 = 0;
8535         object_flags(o_ptr, flgs);
8536         if (!(have_pval_flags(flgs))) o_ptr->pval = 0;
8537         msg_print(_("エッセンスを取り去った。", "You removed all essence you have added."));
8538
8539         /* Combine the pack */
8540         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
8541
8542         /* Window stuff */
8543         p_ptr->window |= (PW_INVEN);
8544 }
8545
8546 /*!
8547  * @brief 鍛冶コマンドのメインルーチン
8548  * @param only_browse TRUEならばエッセンス一覧の表示のみを行う
8549  * @return なし
8550  */
8551 void do_cmd_kaji(bool only_browse)
8552 {
8553         COMMAND_CODE mode = 0;
8554         char choice;
8555
8556         COMMAND_CODE menu_line = (use_menu ? 1 : 0);
8557
8558         if (!only_browse)
8559         {
8560                 if (p_ptr->confused)
8561                 {
8562                         msg_print(_("混乱していて作業できない!", "You are too confused!"));
8563                         return;
8564                 }
8565                 if (p_ptr->blind)
8566                 {
8567                         msg_print(_("目が見えなくて作業できない!", "You are blind!"));
8568                         return;
8569                 }
8570                 if (p_ptr->image)
8571                 {
8572                         msg_print(_("うまく見えなくて作業できない!", "You are hallucinating!"));
8573                         return;
8574                 }
8575         }
8576
8577 #ifdef ALLOW_REPEAT
8578         if (!(repeat_pull(&mode) && 1 <= mode && mode <= 5))
8579         {
8580 #endif /* ALLOW_REPEAT */
8581
8582         if (only_browse) screen_save();
8583         do {
8584         if (!only_browse) screen_save();
8585         if (use_menu)
8586         {
8587                 while(!mode)
8588                 {
8589 #ifdef JP
8590                         prt(format(" %s エッセンス一覧", (menu_line == 1) ? "》" : "  "), 2, 14);
8591                         prt(format(" %s エッセンス抽出", (menu_line == 2) ? "》" : "  "), 3, 14);
8592                         prt(format(" %s エッセンス消去", (menu_line == 3) ? "》" : "  "), 4, 14);
8593                         prt(format(" %s エッセンス付加", (menu_line == 4) ? "》" : "  "), 5, 14);
8594                         prt(format(" %s 武器/防具強化", (menu_line == 5) ? "》" : "  "), 6, 14);
8595                         prt(format("どの種類の技術を%sますか?", only_browse ? "調べ" : "使い"), 0, 0);
8596 #else
8597                         prt(format(" %s List essences", (menu_line == 1) ? "> " : "  "), 2, 14);
8598                         prt(format(" %s Extract essence", (menu_line == 2) ? "> " : "  "), 3, 14);
8599                         prt(format(" %s Remove essence", (menu_line == 3) ? "> " : "  "), 4, 14);
8600                         prt(format(" %s Add essence", (menu_line == 4) ? "> " : "  "), 5, 14);
8601                         prt(format(" %s Enchant weapon/armor", (menu_line == 5) ? "> " : "  "), 6, 14);
8602                         prt(format("Choose command from menu."), 0, 0);
8603 #endif
8604                         choice = inkey();
8605                         switch(choice)
8606                         {
8607                         case ESCAPE:
8608                         case 'z':
8609                         case 'Z':
8610                                 screen_load();
8611                                 return;
8612                         case '2':
8613                         case 'j':
8614                         case 'J':
8615                                 menu_line++;
8616                                 break;
8617                         case '8':
8618                         case 'k':
8619                         case 'K':
8620                                 menu_line+= 4;
8621                                 break;
8622                         case '\r':
8623                         case '\n':
8624                         case 'x':
8625                         case 'X':
8626                                 mode = menu_line;
8627                                 break;
8628                         }
8629                         if (menu_line > 5) menu_line -= 5;
8630                 }
8631         }
8632
8633         else
8634         {
8635                 while (!mode)
8636                 {
8637 #ifdef JP
8638                         prt("  a) エッセンス一覧", 2, 14);
8639                         prt("  b) エッセンス抽出", 3, 14);
8640                         prt("  c) エッセンス消去", 4, 14);
8641                         prt("  d) エッセンス付加", 5, 14);
8642                         prt("  e) 武器/防具強化", 6, 14);
8643                         if (!get_com(format("どの能力を%sますか:", only_browse ? "調べ" : "使い"), &choice, TRUE))
8644 #else
8645                         prt("  a) List essences", 2, 14);
8646                         prt("  b) Extract essence", 3, 14);
8647                         prt("  c) Remove essence", 4, 14);
8648                         prt("  d) Add essence", 5, 14);
8649                         prt("  e) Enchant weapon/armor", 6, 14);
8650                         if (!get_com("Command :", &choice, TRUE))
8651 #endif
8652                         {
8653                                 screen_load();
8654                                 return;
8655                         }
8656                         switch (choice)
8657                         {
8658                         case 'A':
8659                         case 'a':
8660                                 mode = 1;
8661                                 break;
8662                         case 'B':
8663                         case 'b':
8664                                 mode = 2;
8665                                 break;
8666                         case 'C':
8667                         case 'c':
8668                                 mode = 3;
8669                                 break;
8670                         case 'D':
8671                         case 'd':
8672                                 mode = 4;
8673                                 break;
8674                         case 'E':
8675                         case 'e':
8676                                 mode = 5;
8677                                 break;
8678                         }
8679                 }
8680         }
8681
8682         if (only_browse)
8683         {
8684                 char temp[62*5];
8685                 int line, j;
8686
8687                 /* Clear lines, position cursor  (really should use strlen here) */
8688                 Term_erase(14, 21, 255);
8689                 Term_erase(14, 20, 255);
8690                 Term_erase(14, 19, 255);
8691                 Term_erase(14, 18, 255);
8692                 Term_erase(14, 17, 255);
8693                 Term_erase(14, 16, 255);
8694
8695                 roff_to_buf(kaji_tips[mode-1], 62, temp, sizeof(temp));
8696                 for(j=0, line = 17;temp[j];j+=(1+strlen(&temp[j])))
8697                 {
8698                         prt(&temp[j], line, 15);
8699                         line++;
8700                 }
8701                 mode = 0;
8702         }
8703         if (!only_browse) screen_load();
8704         } while (only_browse);
8705 #ifdef ALLOW_REPEAT
8706         repeat_push(mode);
8707         }
8708 #endif /* ALLOW_REPEAT */
8709
8710         switch(mode)
8711         {
8712                 case 1: display_essence();break;
8713                 case 2: drain_essence();break;
8714                 case 3: erase_essence();break;
8715                 case 4:
8716                         mode = choose_essence();
8717                         if (mode == 0)
8718                                 break;
8719                         add_essence(mode);
8720                         break;
8721                 case 5: add_essence(10);break;
8722         }
8723 }
8724
8725
8726 /*!
8727  * @brief 投擲時たいまつに投げやすい/焼棄/アンデッドスレイの特別効果を返す。
8728  * Torches have special abilities when they are flaming.
8729  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
8730  * @param flgs 特別に追加するフラグを返す参照ポインタ
8731  * @return なし
8732  */
8733 void torch_flags(object_type *o_ptr, u32b *flgs)
8734 {
8735         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
8736         {
8737                 if (o_ptr->xtra4 > 0)
8738                 {
8739                         add_flag(flgs, TR_BRAND_FIRE);
8740                         add_flag(flgs, TR_KILL_UNDEAD);
8741                         add_flag(flgs, TR_THROW);
8742                 }
8743         }
8744 }
8745
8746 /*!
8747  * @brief 投擲時たいまつにダイスを与える。
8748  * Torches have special abilities when they are flaming.
8749  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
8750  * @param dd 特別なダイス数を返す参照ポインタ
8751  * @param ds 特別なダイス面数を返す参照ポインタ
8752  * @return なし
8753  */
8754 void torch_dice(object_type *o_ptr, int *dd, int *ds)
8755 {
8756         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
8757         {
8758                 if (o_ptr->xtra4 > 0)
8759                 {
8760                         (*dd) = 1;
8761                         (*ds) = 6;
8762                 }
8763         }
8764 }
8765
8766 /*!
8767  * @brief 投擲時命中したたいまつの寿命を縮める。
8768  * Torches have special abilities when they are flaming.
8769  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
8770  * @return なし
8771  */
8772 void torch_lost_fuel(object_type *o_ptr)
8773 {
8774         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
8775         {
8776                 o_ptr->xtra4 -= (FUEL_TORCH / 25);
8777                 if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0;
8778         }
8779 }