OSDN Git Service

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