OSDN Git Service

[Refactor] #37353 コメント整理。 / Refactor comments.
[hengband/hengband.git] / src / object2.c
1 /*!
2  * @file object2.c
3  * @brief オブジェクトの実装 / Object code, part 2
4  * @date 2014/01/11
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7  *\n
8  * This software may be copied and distributed for educational, research,\n
9  * and not for profit purposes provided that this copyright and statement\n
10  * are included in all such copies.  Other copyrights may also apply.\n
11  * 2014 Deskull rearranged comment for Doxygen.\n
12  */
13
14 #include "angband.h"
15 #include "object-boost.h"
16 #include "object-hook.h"
17 #include "object-curse.h"
18 #include "objectkind-hook.h"
19 #include "artifact.h"
20 #include "player-status.h"
21 #include "feature.h"
22 #include "player-move.h"
23
24 #include "monsterrace-hook.h"
25
26 /*!
27  * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
28  * @param o_idx 削除対象のオブジェクト構造体ポインタ
29  * @return なし
30  */
31 void excise_object_idx(OBJECT_IDX o_idx)
32 {
33         object_type *j_ptr;
34
35         OBJECT_IDX this_o_idx, next_o_idx = 0;
36         OBJECT_IDX prev_o_idx = 0;
37
38         /* Object */
39         j_ptr = &current_floor_ptr->o_list[o_idx];
40
41         if (j_ptr->held_m_idx)
42         {
43                 monster_type *m_ptr;
44                 m_ptr = &current_floor_ptr->m_list[j_ptr->held_m_idx];
45
46                 /* Scan all objects in the grid */
47                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
48                 {
49                         object_type *o_ptr;
50                         o_ptr = &current_floor_ptr->o_list[this_o_idx];
51                         next_o_idx = o_ptr->next_o_idx;
52
53                         if (this_o_idx == o_idx)
54                         {
55                                 /* No previous */
56                                 if (prev_o_idx == 0)
57                                 {
58                                         /* Remove from list */
59                                         m_ptr->hold_o_idx = next_o_idx;
60                                 }
61
62                                 /* Real previous */
63                                 else
64                                 {
65                                         object_type *k_ptr;
66
67                                         /* Previous object */
68                                         k_ptr = &current_floor_ptr->o_list[prev_o_idx];
69
70                                         /* Remove from list */
71                                         k_ptr->next_o_idx = next_o_idx;
72                                 }
73
74                                 /* Forget next pointer */
75                                 o_ptr->next_o_idx = 0;
76
77                                 break;
78                         }
79
80                         /* Save prev_o_idx */
81                         prev_o_idx = this_o_idx;
82                 }
83         }
84
85         /* Dungeon */
86         else
87         {
88                 grid_type *g_ptr;
89
90                 POSITION y = j_ptr->iy;
91                 POSITION x = j_ptr->ix;
92
93                 g_ptr = &current_floor_ptr->grid_array[y][x];
94
95                 /* Scan all objects in the grid */
96                 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
97                 {
98                         object_type *o_ptr;
99                         o_ptr = &current_floor_ptr->o_list[this_o_idx];
100                         next_o_idx = o_ptr->next_o_idx;
101
102                         if (this_o_idx == o_idx)
103                         {
104                                 /* No previous */
105                                 if (prev_o_idx == 0)
106                                 {
107                                         /* Remove from list */
108                                         g_ptr->o_idx = next_o_idx;
109                                 }
110
111                                 /* Real previous */
112                                 else
113                                 {
114                                         object_type *k_ptr;
115
116                                         /* Previous object */
117                                         k_ptr = &current_floor_ptr->o_list[prev_o_idx];
118
119                                         /* Remove from list */
120                                         k_ptr->next_o_idx = next_o_idx;
121                                 }
122
123                                 /* Forget next pointer */
124                                 o_ptr->next_o_idx = 0;
125
126                                 break;
127                         }
128
129                         /* Save prev_o_idx */
130                         prev_o_idx = this_o_idx;
131                 }
132         }
133 }
134
135 /*!
136  * @brief オブジェクトを削除する /
137  * Delete a dungeon object
138  * @param o_idx 削除対象のオブジェクト構造体ポインタ
139  * @return なし
140  * @details
141  * Handle "stacks" of objects correctly.
142  */
143 void delete_object_idx(OBJECT_IDX o_idx)
144 {
145         object_type *j_ptr;
146
147         /* Excise */
148         excise_object_idx(o_idx);
149
150         /* Object */
151         j_ptr = &current_floor_ptr->o_list[o_idx];
152
153         /* Dungeon floor */
154         if (!(j_ptr->held_m_idx))
155         {
156                 POSITION y, x;
157
158                 y = j_ptr->iy;
159                 x = j_ptr->ix;
160
161                 /* Visual update */
162                 lite_spot(y, x);
163         }
164         object_wipe(j_ptr);
165
166         /* Count objects */
167         o_cnt--;
168 }
169
170
171 /*!
172  * @brief フロアにマスに落ちているオブジェクトを全て削除する / Deletes all objects at given location
173  * Delete a dungeon object
174  * @param y 削除したフロアマスのY座標
175  * @param x 削除したフロアマスのX座標
176  * @return なし
177  */
178 void delete_object(POSITION y, POSITION x)
179 {
180         grid_type *g_ptr;
181         OBJECT_IDX this_o_idx, next_o_idx = 0;
182
183         /* Refuse "illegal" locations */
184         if (!in_bounds(y, x)) return;
185
186         g_ptr = &current_floor_ptr->grid_array[y][x];
187
188         /* Scan all objects in the grid */
189         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
190         {
191                 object_type *o_ptr;
192                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
193                 next_o_idx = o_ptr->next_o_idx;
194                 object_wipe(o_ptr);
195
196                 /* Count objects */
197                 o_cnt--;
198         }
199
200         /* Objects are gone */
201         g_ptr->o_idx = 0;
202
203         /* Visual update */
204         lite_spot(y, x);
205 }
206
207
208 /*!
209  * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
210  * Move an object from index i1 to index i2 in the object list
211  * @param i1 整理したい配列の始点
212  * @param i2 整理したい配列の終点
213  * @return なし
214  */
215 static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
216 {
217         OBJECT_IDX i;
218         grid_type *g_ptr;
219         object_type *o_ptr;
220
221         /* Do nothing */
222         if (i1 == i2) return;
223
224         /* Repair objects */
225         for (i = 1; i < o_max; i++)
226         {
227                 o_ptr = &current_floor_ptr->o_list[i];
228
229                 /* Skip "dead" objects */
230                 if (!o_ptr->k_idx) continue;
231
232                 /* Repair "next" pointers */
233                 if (o_ptr->next_o_idx == i1)
234                 {
235                         /* Repair */
236                         o_ptr->next_o_idx = i2;
237                 }
238         }
239         o_ptr = &current_floor_ptr->o_list[i1];
240
241         if (o_ptr->held_m_idx)
242         {
243                 monster_type *m_ptr;
244
245                 /* Acquire monster */
246                 m_ptr = &current_floor_ptr->m_list[o_ptr->held_m_idx];
247
248                 /* Repair monster */
249                 if (m_ptr->hold_o_idx == i1)
250                 {
251                         /* Repair */
252                         m_ptr->hold_o_idx = i2;
253                 }
254         }
255
256         /* Dungeon */
257         else
258         {
259                 POSITION y, x;
260
261                 /* Acquire location */
262                 y = o_ptr->iy;
263                 x = o_ptr->ix;
264
265                 /* Acquire grid */
266                 g_ptr = &current_floor_ptr->grid_array[y][x];
267
268                 /* Repair grid */
269                 if (g_ptr->o_idx == i1)
270                 {
271                         /* Repair */
272                         g_ptr->o_idx = i2;
273                 }
274         }
275
276         /* Structure copy */
277         current_floor_ptr->o_list[i2] = current_floor_ptr->o_list[i1];
278
279         /* Wipe the hole */
280         object_wipe(o_ptr);
281 }
282
283
284 /*!
285  * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
286  * Compact and Reorder the object list.
287  * @param size 最低でも減らしたいオブジェクト数の水準
288  * @return なし
289  * @details
290  * (危険なので使用には注意すること)
291  * This function can be very dangerous, use with caution!\n
292  *\n
293  * When actually "compacting" objects, we base the saving throw on a\n
294  * combination of object level, distance from player, and current\n
295  * "desperation".\n
296  *\n
297  * After "compacting" (if needed), we "reorder" the objects into a more\n
298  * compact order, and we reset the allocation info, and the "live" array.\n
299  */
300 void compact_objects(int size)
301 {
302         OBJECT_IDX i;
303         POSITION y, x;
304         int num, cnt;
305         int cur_lev, cur_dis, chance;
306         object_type *o_ptr;
307
308         /* Compact */
309         if (size)
310         {
311                 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
312                 p_ptr->redraw |= (PR_MAP);
313                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
314         }
315
316
317         /* Compact at least 'size' objects */
318         for (num = 0, cnt = 1; num < size; cnt++)
319         {
320                 /* Get more vicious each iteration */
321                 cur_lev = 5 * cnt;
322
323                 /* Get closer each iteration */
324                 cur_dis = 5 * (20 - cnt);
325
326                 /* Examine the objects */
327                 for (i = 1; i < o_max; i++)
328                 {
329                         o_ptr = &current_floor_ptr->o_list[i];
330
331                         /* Skip dead objects */
332                         if (!o_ptr->k_idx) continue;
333
334                         /* Hack -- High level objects start out "immune" */
335                         if (k_info[o_ptr->k_idx].level > cur_lev) continue;
336
337                         if (o_ptr->held_m_idx)
338                         {
339                                 monster_type *m_ptr;
340
341                                 /* Acquire monster */
342                                 m_ptr = &current_floor_ptr->m_list[o_ptr->held_m_idx];
343
344                                 y = m_ptr->fy;
345                                 x = m_ptr->fx;
346
347                                 /* Monsters protect their objects */
348                                 if (randint0(100) < 90) continue;
349                         }
350
351                         /* Dungeon */
352                         else
353                         {
354                                 y = o_ptr->iy;
355                                 x = o_ptr->ix;
356                         }
357
358                         /* Nearby objects start out "immune" */
359                         if ((cur_dis > 0) && (distance(p_ptr->y, p_ptr->x, y, x) < cur_dis)) continue;
360
361                         /* Saving throw */
362                         chance = 90;
363
364                         /* Hack -- only compact artifacts in emergencies */
365                         if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
366                             (cnt < 1000)) chance = 100;
367
368                         /* Apply the saving throw */
369                         if (randint0(100) < chance) continue;
370
371                         delete_object_idx(i);
372
373                         /* Count it */
374                         num++;
375                 }
376         }
377
378
379         /* Excise dead objects (backwards!) */
380         for (i = o_max - 1; i >= 1; i--)
381         {
382                 o_ptr = &current_floor_ptr->o_list[i];
383
384                 /* Skip real objects */
385                 if (o_ptr->k_idx) continue;
386
387                 /* Move last object into open hole */
388                 compact_objects_aux(o_max - 1, i);
389
390                 /* Compress "o_max" */
391                 o_max--;
392         }
393 }
394
395
396 /*!
397  * @brief グローバルオブジェクト配列を初期化する /
398  * Delete all the items when player leaves the level
399  * @note we do NOT visually reflect these (irrelevant) changes
400  * @details
401  * Hack -- we clear the "g_ptr->o_idx" field for every grid,
402  * and the "m_ptr->next_o_idx" field for every monster, since
403  * we know we are clearing every object.  Technically, we only
404  * clear those fields for grids/monsters containing objects,
405  * and we clear it once for every such object.
406  * @return なし
407  */
408 void wipe_o_list(void)
409 {
410         int i;
411
412         /* Delete the existing objects */
413         for (i = 1; i < o_max; i++)
414         {
415                 object_type *o_ptr = &current_floor_ptr->o_list[i];
416
417                 /* Skip dead objects */
418                 if (!o_ptr->k_idx) continue;
419
420                 /* Mega-Hack -- preserve artifacts */
421                 if (!character_dungeon || preserve_mode)
422                 {
423                         /* Hack -- Preserve unknown artifacts */
424                         if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
425                         {
426                                 /* Mega-Hack -- Preserve the artifact */
427                                 a_info[o_ptr->name1].cur_num = 0;
428                         }
429                 }
430
431                 if (o_ptr->held_m_idx)
432                 {
433                         monster_type *m_ptr;
434                         m_ptr = &current_floor_ptr->m_list[o_ptr->held_m_idx];
435
436                         /* Hack -- see above */
437                         m_ptr->hold_o_idx = 0;
438                 }
439
440                 /* Dungeon */
441                 else
442                 {
443                         grid_type *g_ptr;
444
445                         /* Access location */
446                         POSITION y = o_ptr->iy;
447                         POSITION x = o_ptr->ix;
448
449                         /* Access grid */
450                         g_ptr = &current_floor_ptr->grid_array[y][x];
451
452                         /* Hack -- see above */
453                         g_ptr->o_idx = 0;
454                 }
455                 object_wipe(o_ptr);
456         }
457
458         /* Reset "o_max" */
459         o_max = 1;
460
461         /* Reset "o_cnt" */
462         o_cnt = 0;
463 }
464
465
466 /*!
467  * @brief グローバルオブジェクト配列から空きを取得する /
468  * Acquires and returns the index of a "free" object.
469  * @return 開いているオブジェクト要素のID
470  * @details
471  * This routine should almost never fail, but in case it does,
472  * we must be sure to handle "failure" of this routine.
473  */
474 OBJECT_IDX o_pop(void)
475 {
476         OBJECT_IDX i;
477
478         /* Initial allocation */
479         if (o_max < current_floor_ptr->max_o_idx)
480         {
481                 /* Get next space */
482                 i = o_max;
483
484                 /* Expand object array */
485                 o_max++;
486
487                 /* Count objects */
488                 o_cnt++;
489
490                 /* Use this object */
491                 return (i);
492         }
493
494
495         /* Recycle dead objects */
496         for (i = 1; i < o_max; i++)
497         {
498                 object_type *o_ptr;
499                 o_ptr = &current_floor_ptr->o_list[i];
500
501                 /* Skip live objects */
502                 if (o_ptr->k_idx) continue;
503
504                 /* Count objects */
505                 o_cnt++;
506
507                 /* Use this object */
508                 return (i);
509         }
510
511
512         /* Warn the player (except during dungeon creation) */
513         if (character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
514
515         return (0);
516 }
517
518
519 /*!
520  * @brief オブジェクト生成テーブルに生成制約を加える /
521  * Apply a "object restriction function" to the "object allocation table"
522  * @return 常に0を返す。
523  * @details 生成の制約はグローバルのget_obj_num_hook関数ポインタで加える
524  */
525 static errr get_obj_num_prep(void)
526 {
527         int i;
528
529         /* Get the entry */
530         alloc_entry *table = alloc_kind_table;
531
532         /* Scan the allocation table */
533         for (i = 0; i < alloc_kind_size; i++)
534         {
535                 /* Accept objects which pass the restriction, if any */
536                 if (!get_obj_num_hook || (*get_obj_num_hook)(table[i].index))
537                 {
538                         /* Accept this object */
539                         table[i].prob2 = table[i].prob1;
540                 }
541
542                 /* Do not use this object */
543                 else
544                 {
545                         /* Decline this object */
546                         table[i].prob2 = 0;
547                 }
548         }
549
550         /* Success */
551         return (0);
552 }
553
554
555 /*!
556  * @brief オブジェクト生成テーブルからアイテムを取得する /
557  * Choose an object kind that seems "appropriate" to the given level
558  * @param level 生成階
559  * @return 選ばれたオブジェクトベースID
560  * @details
561  * This function uses the "prob2" field of the "object allocation table",\n
562  * and various local information, to calculate the "prob3" field of the\n
563  * same table, which is then used to choose an "appropriate" object, in\n
564  * a relatively efficient manner.\n
565  *\n
566  * It is (slightly) more likely to acquire an object of the given level\n
567  * than one of a lower level.  This is done by choosing several objects\n
568  * appropriate to the given level and keeping the "hardest" one.\n
569  *\n
570  * Note that if no objects are "appropriate", then this function will\n
571  * fail, and return zero, but this should *almost* never happen.\n
572  */
573 OBJECT_IDX get_obj_num(DEPTH level)
574 {
575         int i, j, p;
576         KIND_OBJECT_IDX k_idx;
577         long value, total;
578         object_kind     *k_ptr;
579         alloc_entry     *table = alloc_kind_table;
580
581         if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
582
583         /* Boost level */
584         if ((level > 0) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
585         {
586                 /* Occasional "boost" */
587                 if (one_in_(GREAT_OBJ))
588                 {
589                         /* What a bizarre calculation */
590                         level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
591                 }
592         }
593
594         /* Reset total */
595         total = 0L;
596
597         /* Process probabilities */
598         for (i = 0; i < alloc_kind_size; i++)
599         {
600                 /* Objects are sorted by depth */
601                 if (table[i].level > level) break;
602
603                 /* Default */
604                 table[i].prob3 = 0;
605
606                 k_idx = table[i].index;
607
608                 /* Access the actual kind */
609                 k_ptr = &k_info[k_idx];
610
611                 /* Hack -- prevent embedded chests */
612                 if (opening_chest && (k_ptr->tval == TV_CHEST)) continue;
613
614                 /* Accept */
615                 table[i].prob3 = table[i].prob2;
616
617                 /* Total */
618                 total += table[i].prob3;
619         }
620
621         /* No legal objects */
622         if (total <= 0) return (0);
623
624
625         /* Pick an object */
626         value = randint0(total);
627
628         /* Find the object */
629         for (i = 0; i < alloc_kind_size; i++)
630         {
631                 /* Found the entry */
632                 if (value < table[i].prob3) break;
633
634                 /* Decrement */
635                 value = value - table[i].prob3;
636         }
637
638
639         /* Power boost */
640         p = randint0(100);
641
642         /* Try for a "better" object once (50%) or twice (10%) */
643         if (p < 60)
644         {
645                 /* Save old */
646                 j = i;
647
648                 /* Pick a object */
649                 value = randint0(total);
650
651                 /* Find the object */
652                 for (i = 0; i < alloc_kind_size; i++)
653                 {
654                         /* Found the entry */
655                         if (value < table[i].prob3) break;
656
657                         /* Decrement */
658                         value = value - table[i].prob3;
659                 }
660
661                 /* Keep the "best" one */
662                 if (table[i].level < table[j].level) i = j;
663         }
664
665         /* Try for a "better" object twice (10%) */
666         if (p < 10)
667         {
668                 /* Save old */
669                 j = i;
670
671                 /* Pick a object */
672                 value = randint0(total);
673
674                 /* Find the object */
675                 for (i = 0; i < alloc_kind_size; i++)
676                 {
677                         /* Found the entry */
678                         if (value < table[i].prob3) break;
679
680                         /* Decrement */
681                         value = value - table[i].prob3;
682                 }
683
684                 /* Keep the "best" one */
685                 if (table[i].level < table[j].level) i = j;
686         }
687
688         return (table[i].index);
689 }
690
691
692 /*!
693  * @brief オブジェクトを鑑定済にする /
694  * Known is true when the "attributes" of an object are "known".
695  * @param o_ptr 鑑定済にするオブジェクトの構造体参照ポインタ
696  * @return なし
697  * These include tohit, todam, toac, cost, and pval (charges).\n
698  *\n
699  * Note that "knowing" an object gives you everything that an "awareness"\n
700  * gives you, and much more.  In fact, the player is always "aware" of any\n
701  * item of which he has full "knowledge".\n
702  *\n
703  * But having full knowledge of, say, one "wand of wonder", does not, by\n
704  * itself, give you knowledge, or even awareness, of other "wands of wonder".\n
705  * It happens that most "identify" routines (including "buying from a shop")\n
706  * will make the player "aware" of the object as well as fully "know" it.\n
707  *\n
708  * This routine also removes any inscriptions generated by "feelings".\n
709  */
710 void object_known(object_type *o_ptr)
711 {
712         /* Remove "default inscriptions" */
713         o_ptr->feeling = FEEL_NONE;
714
715         /* Clear the "Felt" info */
716         o_ptr->ident &= ~(IDENT_SENSE);
717
718         /* Clear the "Empty" info */
719         o_ptr->ident &= ~(IDENT_EMPTY);
720
721         /* Now we know about the item */
722         o_ptr->ident |= (IDENT_KNOWN);
723 }
724
725 /*!
726  * @brief オブジェクトを*鑑定*済にする /
727  * The player is now aware of the effects of the given object.
728  * @param o_ptr *鑑定*済にするオブジェクトの構造体参照ポインタ
729  * @return なし
730  */
731 void object_aware(object_type *o_ptr)
732 {
733         bool mihanmei = !object_is_aware(o_ptr);
734
735         /* Fully aware of the effects */
736         k_info[o_ptr->k_idx].aware = TRUE;
737
738         if(mihanmei && !(k_info[o_ptr->k_idx].gen_flags & TRG_INSTA_ART) && record_ident &&
739            !p_ptr->is_dead && ((o_ptr->tval >= TV_AMULET && o_ptr->tval <= TV_POTION) || (o_ptr->tval == TV_FOOD)))
740         {
741                 object_type forge;
742                 object_type *q_ptr;
743                 GAME_TEXT o_name[MAX_NLEN];
744
745                 q_ptr = &forge;
746                 object_copy(q_ptr, o_ptr);
747
748                 q_ptr->number = 1;
749                 object_desc(o_name, q_ptr, OD_NAME_ONLY);
750                 
751                 do_cmd_write_nikki(NIKKI_HANMEI, 0, o_name);
752         }
753 }
754
755 /*!
756  * @brief オブジェクトを試行済にする /
757  * Something has been "sampled"
758  * @param o_ptr 試行済にするオブジェクトの構造体参照ポインタ
759  * @return なし
760  */
761 void object_tried(object_type *o_ptr)
762 {
763         /* Mark it as tried (even if "aware") */
764         k_info[o_ptr->k_idx].tried = TRUE;
765 }
766
767 /*!
768 * @brief 重度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item.  Method 1 (Heavy).
769 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
770 * @return 擬似鑑定結果のIDを返す。
771 */
772 byte value_check_aux1(object_type *o_ptr)
773 {
774         /* Artifacts */
775         if (object_is_artifact(o_ptr))
776         {
777                 /* Cursed/Broken */
778                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_TERRIBLE;
779
780                 /* Normal */
781                 return FEEL_SPECIAL;
782         }
783
784         /* Ego-Items */
785         if (object_is_ego(o_ptr))
786         {
787                 /* Cursed/Broken */
788                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_WORTHLESS;
789
790                 /* Normal */
791                 return FEEL_EXCELLENT;
792         }
793
794         /* Cursed items */
795         if (object_is_cursed(o_ptr)) return FEEL_CURSED;
796
797         /* Broken items */
798         if (object_is_broken(o_ptr)) return FEEL_BROKEN;
799
800         if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
801
802         /* Good "armor" bonus */
803         if (o_ptr->to_a > 0) return FEEL_GOOD;
804
805         /* Good "weapon" bonus */
806         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
807
808         /* Default to "average" */
809         return FEEL_AVERAGE;
810 }
811
812 /*!
813 * @brief 軽度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item.  Method 2 (Light).
814 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
815 * @return 擬似鑑定結果のIDを返す。
816 */
817 byte value_check_aux2(object_type *o_ptr)
818 {
819         /* Cursed items (all of them) */
820         if (object_is_cursed(o_ptr)) return FEEL_CURSED;
821
822         /* Broken items (all of them) */
823         if (object_is_broken(o_ptr)) return FEEL_BROKEN;
824
825         /* Artifacts -- except cursed/broken ones */
826         if (object_is_artifact(o_ptr)) return FEEL_UNCURSED;
827
828         /* Ego-Items -- except cursed/broken ones */
829         if (object_is_ego(o_ptr)) return FEEL_UNCURSED;
830
831         /* Good armor bonus */
832         if (o_ptr->to_a > 0) return FEEL_UNCURSED;
833
834         /* Good weapon bonuses */
835         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
836
837         /* No feeling */
838         return FEEL_NONE;
839 }
840
841 /*!
842  * @brief 未鑑定なベースアイテムの基本価格を返す /
843  * Return the "value" of an "unknown" item Make a guess at the value of non-aware items
844  * @param o_ptr 未鑑定価格を確認したいオブジェクトの構造体参照ポインタ
845  * @return オブジェクトの未鑑定価格
846  */
847 static PRICE object_value_base(object_type *o_ptr)
848 {
849         /* Aware item -- use template cost */
850         if (object_is_aware(o_ptr)) return (k_info[o_ptr->k_idx].cost);
851
852         /* Analyze the type */
853         switch (o_ptr->tval)
854         {
855
856                 /* Un-aware Food */
857                 case TV_FOOD: return (5L);
858
859                 /* Un-aware Potions */
860                 case TV_POTION: return (20L);
861
862                 /* Un-aware Scrolls */
863                 case TV_SCROLL: return (20L);
864
865                 /* Un-aware Staffs */
866                 case TV_STAFF: return (70L);
867
868                 /* Un-aware Wands */
869                 case TV_WAND: return (50L);
870
871                 /* Un-aware Rods */
872                 case TV_ROD: return (90L);
873
874                 /* Un-aware Rings */
875                 case TV_RING: return (45L);
876
877                 /* Un-aware Amulets */
878                 case TV_AMULET: return (45L);
879
880                 /* Figurines, relative to monster level */
881                 case TV_FIGURINE:
882                 {
883                         DEPTH level = r_info[o_ptr->pval].level;
884                         if (level < 20) return level*50L;
885                         else if (level < 30) return 1000+(level-20)*150L;
886                         else if (level < 40) return 2500+(level-30)*350L;
887                         else if (level < 50) return 6000+(level-40)*800L;
888                         else return 14000+(level-50)*2000L;
889                 }
890
891                 case TV_CAPTURE:
892                         if (!o_ptr->pval) return 1000L;
893                         else return ((r_info[o_ptr->pval].level) * 50L + 1000);
894         }
895
896         /* Paranoia -- Oops */
897         return (0L);
898 }
899
900
901 /*!
902  * @brief オブジェクトのフラグ類から価格を算出する /
903  * Return the value of the flags the object has...
904  * @param o_ptr フラグ価格を確認したいオブジェクトの構造体参照ポインタ
905  * @param plusses フラグに与える価格の基本重み
906  * @return オブジェクトのフラグ価格
907  */
908 PRICE flag_cost(object_type *o_ptr, int plusses)
909 {
910         PRICE total = 0;
911         BIT_FLAGS flgs[TR_FLAG_SIZE];
912         PRICE tmp_cost;
913         int count;
914         int i;
915         object_kind *k_ptr = &k_info[o_ptr->k_idx];
916
917         object_flags(o_ptr, flgs);
918
919         /*
920          * Exclude fixed flags of the base item.
921          * pval bonuses of base item will be treated later.
922          */
923         for (i = 0; i < TR_FLAG_SIZE; i++)
924                 flgs[i] &= ~(k_ptr->flags[i]);
925
926         /* Exclude fixed flags of the fixed artifact. */
927         if (object_is_fixed_artifact(o_ptr))
928         {
929                 artifact_type *a_ptr = &a_info[o_ptr->name1];
930
931                 for (i = 0; i < TR_FLAG_SIZE; i++)
932                         flgs[i] &= ~(a_ptr->flags[i]);
933         }
934
935         /* Exclude fixed flags of the ego-item. */
936         else if (object_is_ego(o_ptr))
937         {
938                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
939
940                 for (i = 0; i < TR_FLAG_SIZE; i++)
941                         flgs[i] &= ~(e_ptr->flags[i]);
942         }
943
944
945         /*
946          * Calucurate values of remaining flags
947          */
948         if (have_flag(flgs, TR_STR)) total += (1500 * plusses);
949         if (have_flag(flgs, TR_INT)) total += (1500 * plusses);
950         if (have_flag(flgs, TR_WIS)) total += (1500 * plusses);
951         if (have_flag(flgs, TR_DEX)) total += (1500 * plusses);
952         if (have_flag(flgs, TR_CON)) total += (1500 * plusses);
953         if (have_flag(flgs, TR_CHR)) total += (750 * plusses);
954         if (have_flag(flgs, TR_MAGIC_MASTERY)) total += (600 * plusses);
955         if (have_flag(flgs, TR_STEALTH)) total += (250 * plusses);
956         if (have_flag(flgs, TR_SEARCH)) total += (100 * plusses);
957         if (have_flag(flgs, TR_INFRA)) total += (150 * plusses);
958         if (have_flag(flgs, TR_TUNNEL)) total += (175 * plusses);
959         if ((have_flag(flgs, TR_SPEED)) && (plusses > 0))
960                 total += (10000 + (2500 * plusses));
961         if ((have_flag(flgs, TR_BLOWS)) && (plusses > 0))
962                 total += (10000 + (2500 * plusses));
963
964         tmp_cost = 0;
965         count = 0;
966         if (have_flag(flgs, TR_CHAOTIC)) {total += 5000;count++;}
967         if (have_flag(flgs, TR_VAMPIRIC)) {total += 6500;count++;}
968         if (have_flag(flgs, TR_FORCE_WEAPON)) {tmp_cost += 2500;count++;}
969         if (have_flag(flgs, TR_KILL_ANIMAL)) {tmp_cost += 2800;count++;}
970         else if (have_flag(flgs, TR_SLAY_ANIMAL)) {tmp_cost += 1800;count++;}
971         if (have_flag(flgs, TR_KILL_EVIL)) {tmp_cost += 3300;count++;}
972         else if (have_flag(flgs, TR_SLAY_EVIL)) {tmp_cost += 2300;count++;}
973         if (have_flag(flgs, TR_KILL_HUMAN)) {tmp_cost += 2800;count++;}
974         else if (have_flag(flgs, TR_SLAY_HUMAN)) {tmp_cost += 1800;count++;}
975         if (have_flag(flgs, TR_KILL_UNDEAD)) {tmp_cost += 2800;count++;}
976         else if (have_flag(flgs, TR_SLAY_UNDEAD)) {tmp_cost += 1800;count++;}
977         if (have_flag(flgs, TR_KILL_DEMON)) {tmp_cost += 2800;count++;}
978         else if (have_flag(flgs, TR_SLAY_DEMON)) {tmp_cost += 1800;count++;}
979         if (have_flag(flgs, TR_KILL_ORC)) {tmp_cost += 2500;count++;}
980         else if (have_flag(flgs, TR_SLAY_ORC)) {tmp_cost += 1500;count++;}
981         if (have_flag(flgs, TR_KILL_TROLL)) {tmp_cost += 2800;count++;}
982         else if (have_flag(flgs, TR_SLAY_TROLL)) {tmp_cost += 1800;count++;}
983         if (have_flag(flgs, TR_KILL_GIANT)) {tmp_cost += 2800;count++;}
984         else if (have_flag(flgs, TR_SLAY_GIANT)) {tmp_cost += 1800;count++;}
985         if (have_flag(flgs, TR_KILL_DRAGON)) {tmp_cost += 2800;count++;}
986         else if (have_flag(flgs, TR_SLAY_DRAGON)) {tmp_cost += 1800;count++;}
987
988         if (have_flag(flgs, TR_VORPAL)) {tmp_cost += 2500;count++;}
989         if (have_flag(flgs, TR_IMPACT)) {tmp_cost += 2500;count++;}
990         if (have_flag(flgs, TR_BRAND_POIS)) {tmp_cost += 3800;count++;}
991         if (have_flag(flgs, TR_BRAND_ACID)) {tmp_cost += 3800;count++;}
992         if (have_flag(flgs, TR_BRAND_ELEC)) {tmp_cost += 3800;count++;}
993         if (have_flag(flgs, TR_BRAND_FIRE)) {tmp_cost += 2500;count++;}
994         if (have_flag(flgs, TR_BRAND_COLD)) {tmp_cost += 2500;count++;}
995         total += (tmp_cost * count);
996
997         if (have_flag(flgs, TR_SUST_STR)) total += 850;
998         if (have_flag(flgs, TR_SUST_INT)) total += 850;
999         if (have_flag(flgs, TR_SUST_WIS)) total += 850;
1000         if (have_flag(flgs, TR_SUST_DEX)) total += 850;
1001         if (have_flag(flgs, TR_SUST_CON)) total += 850;
1002         if (have_flag(flgs, TR_SUST_CHR)) total += 250;
1003         if (have_flag(flgs, TR_RIDING)) total += 0;
1004         if (have_flag(flgs, TR_EASY_SPELL)) total += 1500;
1005         if (have_flag(flgs, TR_THROW)) total += 5000;
1006         if (have_flag(flgs, TR_FREE_ACT)) total += 4500;
1007         if (have_flag(flgs, TR_HOLD_EXP)) total += 8500;
1008
1009         tmp_cost = 0;
1010         count = 0;
1011         if (have_flag(flgs, TR_IM_ACID)) {tmp_cost += 15000;count += 2;}
1012         if (have_flag(flgs, TR_IM_ELEC)) {tmp_cost += 15000;count += 2;}
1013         if (have_flag(flgs, TR_IM_FIRE)) {tmp_cost += 15000;count += 2;}
1014         if (have_flag(flgs, TR_IM_COLD)) {tmp_cost += 15000;count += 2;}
1015         if (have_flag(flgs, TR_REFLECT)) {tmp_cost += 5000;count += 2;}
1016         if (have_flag(flgs, TR_RES_ACID)) {tmp_cost += 500;count++;}
1017         if (have_flag(flgs, TR_RES_ELEC)) {tmp_cost += 500;count++;}
1018         if (have_flag(flgs, TR_RES_FIRE)) {tmp_cost += 500;count++;}
1019         if (have_flag(flgs, TR_RES_COLD)) {tmp_cost += 500;count++;}
1020         if (have_flag(flgs, TR_RES_POIS)) {tmp_cost += 1000;count += 2;}
1021         if (have_flag(flgs, TR_RES_FEAR)) {tmp_cost += 1000;count += 2;}
1022         if (have_flag(flgs, TR_RES_LITE)) {tmp_cost += 800;count += 2;}
1023         if (have_flag(flgs, TR_RES_DARK)) {tmp_cost += 800;count += 2;}
1024         if (have_flag(flgs, TR_RES_BLIND)) {tmp_cost += 900;count += 2;}
1025         if (have_flag(flgs, TR_RES_CONF)) {tmp_cost += 900;count += 2;}
1026         if (have_flag(flgs, TR_RES_SOUND)) {tmp_cost += 900;count += 2;}
1027         if (have_flag(flgs, TR_RES_SHARDS)) {tmp_cost += 900;count += 2;}
1028         if (have_flag(flgs, TR_RES_NETHER)) {tmp_cost += 900;count += 2;}
1029         if (have_flag(flgs, TR_RES_NEXUS)) {tmp_cost += 900;count += 2;}
1030         if (have_flag(flgs, TR_RES_CHAOS)) {tmp_cost += 1000;count += 2;}
1031         if (have_flag(flgs, TR_RES_DISEN)) {tmp_cost += 2000;count += 2;}
1032         total += (tmp_cost * count);
1033
1034         if (have_flag(flgs, TR_SH_FIRE)) total += 5000;
1035         if (have_flag(flgs, TR_SH_ELEC)) total += 5000;
1036         if (have_flag(flgs, TR_SH_COLD)) total += 5000;
1037         if (have_flag(flgs, TR_NO_TELE)) total -= 10000;
1038         if (have_flag(flgs, TR_NO_MAGIC)) total += 2500;
1039         if (have_flag(flgs, TR_TY_CURSE)) total -= 15000;
1040         if (have_flag(flgs, TR_HIDE_TYPE)) total += 0;
1041         if (have_flag(flgs, TR_SHOW_MODS)) total += 0;
1042         if (have_flag(flgs, TR_LEVITATION)) total += 1250;
1043         if (have_flag(flgs, TR_LITE_1)) total += 1500;
1044         if (have_flag(flgs, TR_LITE_2)) total += 2500;
1045         if (have_flag(flgs, TR_LITE_3)) total += 4000;
1046         if (have_flag(flgs, TR_LITE_M1)) total -= 1500;
1047         if (have_flag(flgs, TR_LITE_M2)) total -= 2500;
1048         if (have_flag(flgs, TR_LITE_M3)) total -= 4000;
1049         if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
1050         if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
1051         if (have_flag(flgs, TR_ESP_ANIMAL)) total += 1000;
1052         if (have_flag(flgs, TR_ESP_UNDEAD)) total += 1000;
1053         if (have_flag(flgs, TR_ESP_DEMON)) total += 1000;
1054         if (have_flag(flgs, TR_ESP_ORC)) total += 1000;
1055         if (have_flag(flgs, TR_ESP_TROLL)) total += 1000;
1056         if (have_flag(flgs, TR_ESP_GIANT)) total += 1000;
1057         if (have_flag(flgs, TR_ESP_DRAGON)) total += 1000;
1058         if (have_flag(flgs, TR_ESP_HUMAN)) total += 1000;
1059         if (have_flag(flgs, TR_ESP_EVIL)) total += 15000;
1060         if (have_flag(flgs, TR_ESP_GOOD)) total += 2000;
1061         if (have_flag(flgs, TR_ESP_NONLIVING)) total += 2000;
1062         if (have_flag(flgs, TR_ESP_UNIQUE)) total += 10000;
1063         if (have_flag(flgs, TR_SLOW_DIGEST)) total += 750;
1064         if (have_flag(flgs, TR_REGEN)) total += 2500;
1065         if (have_flag(flgs, TR_WARNING)) total += 2000;
1066         if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
1067         if (have_flag(flgs, TR_XTRA_MIGHT)) total += 2250;
1068         if (have_flag(flgs, TR_XTRA_SHOTS)) total += 10000;
1069         if (have_flag(flgs, TR_IGNORE_ACID)) total += 100;
1070         if (have_flag(flgs, TR_IGNORE_ELEC)) total += 100;
1071         if (have_flag(flgs, TR_IGNORE_FIRE)) total += 100;
1072         if (have_flag(flgs, TR_IGNORE_COLD)) total += 100;
1073         if (have_flag(flgs, TR_ACTIVATE)) total += 100;
1074         if (have_flag(flgs, TR_DRAIN_EXP)) total -= 12500;
1075         if (have_flag(flgs, TR_DRAIN_HP)) total -= 12500;
1076         if (have_flag(flgs, TR_DRAIN_MANA)) total -= 12500;
1077         if (have_flag(flgs, TR_CALL_ANIMAL)) total -= 12500;
1078         if (have_flag(flgs, TR_CALL_DEMON)) total -= 10000;
1079         if (have_flag(flgs, TR_CALL_DRAGON)) total -= 10000;
1080         if (have_flag(flgs, TR_CALL_UNDEAD)) total -= 10000;
1081         if (have_flag(flgs, TR_COWARDICE)) total -= 5000;
1082         if (have_flag(flgs, TR_LOW_MELEE)) total -= 5000;
1083         if (have_flag(flgs, TR_LOW_AC)) total -= 5000;
1084         if (have_flag(flgs, TR_LOW_MAGIC)) total -= 15000;
1085         if (have_flag(flgs, TR_FAST_DIGEST)) total -= 10000;
1086         if (have_flag(flgs, TR_SLOW_REGEN)) total -= 10000;
1087         if (have_flag(flgs, TR_TELEPORT))
1088         {
1089                 if (object_is_cursed(o_ptr))
1090                         total -= 7500;
1091                 else
1092                         total += 250;
1093         }
1094         if (have_flag(flgs, TR_AGGRAVATE)) total -= 10000;
1095         if (have_flag(flgs, TR_BLESSED)) total += 750;
1096         if (o_ptr->curse_flags & TR_ADD_L_CURSE) total -= 5000;
1097         if (o_ptr->curse_flags & TR_ADD_H_CURSE) total -= 12500;
1098         if (o_ptr->curse_flags & TRC_CURSED) total -= 5000;
1099         if (o_ptr->curse_flags & TRC_HEAVY_CURSE) total -= 12500;
1100         if (o_ptr->curse_flags & TRC_PERMA_CURSE) total -= 15000;
1101
1102         /* Also, give some extra for activatable powers... */
1103         if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
1104         {
1105                 const activation_type* const act_ptr = find_activation_info(o_ptr);
1106                 if (act_ptr) {
1107                         total += act_ptr->value;
1108                 }
1109         }
1110
1111         return total;
1112 }
1113
1114
1115 /*!
1116  * @brief オブジェクトの真の価格を算出する /
1117  * Return the value of the flags the object has...
1118  * @param o_ptr 本価格を確認したいオブジェクトの構造体参照ポインタ
1119  * @return オブジェクトの本価格
1120  * @details
1121  * Return the "real" price of a "known" item, not including discounts\n
1122  *\n
1123  * Wand and staffs get cost for each charge\n
1124  *\n
1125  * Armor is worth an extra 100 gold per bonus point to armor class.\n
1126  *\n
1127  * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).\n
1128  *\n
1129  * Missiles are only worth 5 gold per bonus point, since they\n
1130  * usually appear in groups of 20, and we want the player to get\n
1131  * the same amount of cash for any "equivalent" item.  Note that\n
1132  * missiles never have any of the "pval" flags, and in fact, they\n
1133  * only have a few of the available flags, primarily of the "slay"\n
1134  * and "brand" and "ignore" variety.\n
1135  *\n
1136  * Armor with a negative armor bonus is worthless.\n
1137  * Weapons with negative hit+damage bonuses are worthless.\n
1138  *\n
1139  * Every wearable item with a "pval" bonus is worth extra (see below).\n
1140  */
1141 PRICE object_value_real(object_type *o_ptr)
1142 {
1143         PRICE value;
1144         BIT_FLAGS flgs[TR_FLAG_SIZE];
1145         object_kind *k_ptr = &k_info[o_ptr->k_idx];
1146
1147
1148         /* Hack -- "worthless" items */
1149         if (!k_info[o_ptr->k_idx].cost) return (0L);
1150
1151         /* Base cost */
1152         value = k_info[o_ptr->k_idx].cost;
1153
1154         /* Extract some flags */
1155         object_flags(o_ptr, flgs);
1156
1157         /* Artifact */
1158         if (object_is_fixed_artifact(o_ptr))
1159         {
1160                 artifact_type *a_ptr = &a_info[o_ptr->name1];
1161
1162                 /* Hack -- "worthless" artifacts */
1163                 if (!a_ptr->cost) return (0L);
1164
1165                 /* Hack -- Use the artifact cost instead */
1166                 value = a_ptr->cost;
1167                 value += flag_cost(o_ptr, o_ptr->pval);
1168
1169                 /* Don't add pval bonuses etc. */
1170                 return (value);
1171         }
1172
1173         /* Ego-Item */
1174         else if (object_is_ego(o_ptr))
1175         {
1176                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
1177
1178                 /* Hack -- "worthless" ego-items */
1179                 if (!e_ptr->cost) return (0L);
1180
1181                 /* Hack -- Reward the ego-item with a bonus */
1182                 value += e_ptr->cost;
1183                 value += flag_cost(o_ptr, o_ptr->pval);
1184         }
1185
1186         else
1187         {
1188                 int i;
1189                 bool flag = FALSE;
1190
1191                 for (i = 0; i < TR_FLAG_SIZE; i++) 
1192                         if (o_ptr->art_flags[i]) flag = TRUE;
1193
1194                 if (flag) value += flag_cost(o_ptr, o_ptr->pval);
1195         }
1196
1197         /* Analyze pval bonus for normal object */
1198         switch (o_ptr->tval)
1199         {
1200         case TV_SHOT:
1201         case TV_ARROW:
1202         case TV_BOLT:
1203         case TV_BOW:
1204         case TV_DIGGING:
1205         case TV_HAFTED:
1206         case TV_POLEARM:
1207         case TV_SWORD:
1208         case TV_BOOTS:
1209         case TV_GLOVES:
1210         case TV_HELM:
1211         case TV_CROWN:
1212         case TV_SHIELD:
1213         case TV_CLOAK:
1214         case TV_SOFT_ARMOR:
1215         case TV_HARD_ARMOR:
1216         case TV_DRAG_ARMOR:
1217         case TV_LITE:
1218         case TV_AMULET:
1219         case TV_RING:
1220                 /* No pval */
1221                 if (!o_ptr->pval) break;
1222
1223                 /* Hack -- Negative "pval" is always bad */
1224                 if (o_ptr->pval < 0) return (0L);
1225
1226                 /* Give credit for stat bonuses */
1227                 if (have_flag(flgs, TR_STR)) value += (o_ptr->pval * 200L);
1228                 if (have_flag(flgs, TR_INT)) value += (o_ptr->pval * 200L);
1229                 if (have_flag(flgs, TR_WIS)) value += (o_ptr->pval * 200L);
1230                 if (have_flag(flgs, TR_DEX)) value += (o_ptr->pval * 200L);
1231                 if (have_flag(flgs, TR_CON)) value += (o_ptr->pval * 200L);
1232                 if (have_flag(flgs, TR_CHR)) value += (o_ptr->pval * 200L);
1233
1234                 /* Give credit for stealth and searching */
1235                 if (have_flag(flgs, TR_MAGIC_MASTERY)) value += (o_ptr->pval * 100);
1236                 if (have_flag(flgs, TR_STEALTH)) value += (o_ptr->pval * 100L);
1237                 if (have_flag(flgs, TR_SEARCH)) value += (o_ptr->pval * 100L);
1238
1239                 /* Give credit for infra-vision and tunneling */
1240                 if (have_flag(flgs, TR_INFRA)) value += (o_ptr->pval * 50L);
1241                 if (have_flag(flgs, TR_TUNNEL)) value += (o_ptr->pval * 50L);
1242
1243                 /* Give credit for extra attacks */
1244                 if (have_flag(flgs, TR_BLOWS)) value += (o_ptr->pval * 5000L);
1245
1246                 /* Give credit for speed bonus */
1247                 if (have_flag(flgs, TR_SPEED)) value += (o_ptr->pval * 10000L);
1248
1249                 break;
1250         }
1251
1252
1253         /* Analyze the item */
1254         switch (o_ptr->tval)
1255         {
1256                 /* Wands/Staffs */
1257                 case TV_WAND:
1258                 {
1259                         /* Pay extra for charges, depending on standard number of
1260                          * charges.  Handle new-style wands correctly. -LM-
1261                          */
1262                         value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
1263
1264                         break;
1265                 }
1266                 case TV_STAFF:
1267                 {
1268                         /* Pay extra for charges, depending on standard number of
1269                          * charges.  -LM-
1270                          */
1271                         value += (value * o_ptr->pval / (k_ptr->pval * 2));
1272
1273                         break;
1274                 }
1275
1276                 /* Rings/Amulets */
1277                 case TV_RING:
1278                 case TV_AMULET:
1279                 {
1280                         /* Hack -- negative bonuses are bad */
1281                         if (o_ptr->to_h + o_ptr->to_d + o_ptr->to_a < 0) return (0L);
1282
1283                         /* Give credit for bonuses */
1284                         value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
1285
1286                         break;
1287                 }
1288
1289                 /* Armor */
1290                 case TV_BOOTS:
1291                 case TV_GLOVES:
1292                 case TV_CLOAK:
1293                 case TV_CROWN:
1294                 case TV_HELM:
1295                 case TV_SHIELD:
1296                 case TV_SOFT_ARMOR:
1297                 case TV_HARD_ARMOR:
1298                 case TV_DRAG_ARMOR:
1299                 {
1300                         /* Hack -- negative armor bonus */
1301                         if (o_ptr->to_a < 0) return (0L);
1302
1303                         /* Give credit for bonuses */
1304                         value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
1305
1306                         break;
1307                 }
1308
1309                 /* Bows/Weapons */
1310                 case TV_BOW:
1311                 case TV_DIGGING:
1312                 case TV_HAFTED:
1313                 case TV_SWORD:
1314                 case TV_POLEARM:
1315                 {
1316                         /* Hack -- negative hit/damage bonuses */
1317                         if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1318
1319                         /* Factor in the bonuses */
1320                         value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 100L);
1321
1322                         /* Hack -- Factor in extra damage dice and sides */
1323                         value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
1324                         value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
1325
1326                         break;
1327                 }
1328
1329                 /* Ammo */
1330                 case TV_SHOT:
1331                 case TV_ARROW:
1332                 case TV_BOLT:
1333                 {
1334                         /* Hack -- negative hit/damage bonuses */
1335                         if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1336
1337                         /* Factor in the bonuses */
1338                         value += ((o_ptr->to_h + o_ptr->to_d) * 5L);
1339
1340                         /* Hack -- Factor in extra damage dice and sides */
1341                         value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
1342                         value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
1343
1344                         break;
1345                 }
1346
1347                 /* Figurines, relative to monster level */
1348                 case TV_FIGURINE:
1349                 {
1350                         DEPTH 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 PRICE object_value(object_type *o_ptr)
1396 {
1397         PRICE value;
1398
1399         /* Unknown items -- acquire a base value */
1400         if (object_is_known(o_ptr))
1401         {
1402                 /* Broken items -- worthless */
1403                 if (object_is_broken(o_ptr)) return (0L);
1404
1405                 /* Cursed items -- worthless */
1406                 if (object_is_cursed(o_ptr)) return (0L);
1407
1408                 /* Real value (see above) */
1409                 value = object_value_real(o_ptr);
1410         }
1411
1412         /* Known items -- acquire the actual value */
1413         else
1414         {
1415                 /* Hack -- Felt broken items */
1416                 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_broken(o_ptr)) return (0L);
1417
1418                 /* Hack -- Felt cursed items */
1419                 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_cursed(o_ptr)) return (0L);
1420
1421                 /* Base value (see above) */
1422                 value = object_value_base(o_ptr);
1423         }
1424
1425         /* Apply discount (if any) */
1426         if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
1427
1428         /* Return the final value */
1429         return (value);
1430 }
1431
1432
1433
1434
1435 /*!
1436  * @brief 魔法棒やロッドのスロット分割時に使用回数を分配する /
1437  * Distribute charges of rods or wands.
1438  * @param o_ptr 分割元オブジェクトの構造体参照ポインタ source item
1439  * @param q_ptr 分割先オブジェクトの構造体参照ポインタ target item, must be of the same type as o_ptr
1440  * @param amt 分割したい回数量 number of items that are transfered
1441  * @return なし
1442  * @details
1443  * Hack -- If rods or wands are dropped, the total maximum timeout or\n
1444  * charges need to be allocated between the two stacks.  If all the items\n
1445  * are being dropped, it makes for a neater message to leave the original\n
1446  * stack's pval alone. -LM-\n
1447  */
1448 void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
1449 {
1450         if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD))
1451         {
1452                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1453                 if (amt < o_ptr->number) o_ptr->pval -= q_ptr->pval;
1454
1455                 /* Hack -- Rods also need to have their timeouts distributed.  The
1456                  * dropped stack will accept all time remaining to charge up to its
1457                  * maximum.
1458                  */
1459                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
1460                 {
1461                         if (q_ptr->pval > o_ptr->timeout)
1462                                 q_ptr->timeout = o_ptr->timeout;
1463                         else
1464                                 q_ptr->timeout = q_ptr->pval;
1465
1466                         if (amt < o_ptr->number) o_ptr->timeout -= q_ptr->timeout;
1467                 }
1468         }
1469 }
1470
1471 /*!
1472  * @brief 魔法棒やロッドの使用回数を減らす /
1473  * @param o_ptr オブジェクトの構造体参照ポインタ source item
1474  * @param amt 減らしたい回数量 number of items that are transfered
1475  * @return なし
1476  * @details
1477  * Hack -- If rods or wand are destroyed, the total maximum timeout or\n
1478  * charges of the stack needs to be reduced, unless all the items are\n
1479  * being destroyed. -LM-\n
1480  */
1481 void reduce_charges(object_type *o_ptr, int amt)
1482 {
1483         if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD)) &&
1484                 (amt < o_ptr->number))
1485         {
1486                 o_ptr->pval -= o_ptr->pval * amt / o_ptr->number;
1487         }
1488 }
1489
1490 /*
1491  * Determine if an item can "absorb" a second item
1492  *
1493  * See "object_absorb()" for the actual "absorption" code.
1494  *
1495  * If permitted, we allow staffs (if they are known to have equal charges
1496  * and both are either known or confirmed empty) and wands (if both are
1497  * either known or confirmed empty) and rods (in all cases) to combine.
1498  * Staffs will unstack (if necessary) when they are used, but wands and
1499  * rods will only unstack if one is dropped. -LM-
1500  *
1501  * If permitted, we allow weapons/armor to stack, if fully "known".
1502  *
1503  * Missiles will combine if both stacks have the same "known" status.
1504  * This is done to make unidentified stacks of missiles useful.
1505  *
1506  * Food, potions, scrolls, and "easy know" items always stack.
1507  *
1508  * Chests, and activatable items, never stack (for various reasons).
1509  */
1510
1511 /*
1512  * A "stack" of items is limited to less than or equal to 99 items (hard-coded).
1513  */
1514 #define MAX_STACK_SIZE 99
1515
1516
1517 /*!
1518  * @brief 両オブジェクトをスロットに重ね合わせ可能な最大数を返す。
1519  * Determine if an item can partly absorb a second item. Return maximum number of stack.
1520  * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1521  * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1522  * @return 重ね合わせ可能なアイテム数
1523  */
1524 int object_similar_part(object_type *o_ptr, object_type *j_ptr)
1525 {
1526         int i;
1527
1528         /* Default maximum number of stack */
1529         int max_num = MAX_STACK_SIZE;
1530
1531         /* Require identical object types */
1532         if (o_ptr->k_idx != j_ptr->k_idx) return 0;
1533
1534
1535         /* Analyze the items */
1536         switch (o_ptr->tval)
1537         {
1538                 /* Chests and Statues*/
1539                 case TV_CHEST:
1540                 case TV_CARD:
1541                 case TV_CAPTURE:
1542                 {
1543                         /* Never okay */
1544                         return 0;
1545                 }
1546
1547                 case TV_STATUE:
1548                 {
1549                         if ((o_ptr->sval != SV_PHOTO) || (j_ptr->sval != SV_PHOTO)) return 0;
1550                         if (o_ptr->pval != j_ptr->pval) return 0;
1551                         break;
1552                 }
1553
1554                 /* Figurines and Corpses*/
1555                 case TV_FIGURINE:
1556                 case TV_CORPSE:
1557                 {
1558                         /* Same monster */
1559                         if (o_ptr->pval != j_ptr->pval) return 0;
1560
1561                         /* Assume okay */
1562                         break;
1563                 }
1564
1565                 /* Food and Potions and Scrolls */
1566                 case TV_FOOD:
1567                 case TV_POTION:
1568                 case TV_SCROLL:
1569                 {
1570                         /* Assume okay */
1571                         break;
1572                 }
1573
1574                 /* Staffs */
1575                 case TV_STAFF:
1576                 {
1577                         /* Require either knowledge or known empty for both staffs. */
1578                         if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1579                                 !object_is_known(o_ptr)) ||
1580                                 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1581                                 !object_is_known(j_ptr))) return 0;
1582
1583                         /* Require identical charges, since staffs are bulky. */
1584                         if (o_ptr->pval != j_ptr->pval) return 0;
1585
1586                         /* Assume okay */
1587                         break;
1588                 }
1589
1590                 /* Wands */
1591                 case TV_WAND:
1592                 {
1593                         /* Require either knowledge or known empty for both wands. */
1594                         if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1595                                 !object_is_known(o_ptr)) ||
1596                                 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1597                                 !object_is_known(j_ptr))) return 0;
1598
1599                         /* Wand charges combine in O&ZAngband.  */
1600
1601                         /* Assume okay */
1602                         break;
1603                 }
1604
1605                 /* Staffs and Wands and Rods */
1606                 case TV_ROD:
1607                 {
1608                         /* Prevent overflaw of timeout */
1609                         max_num = MIN(max_num, MAX_SHORT / k_info[o_ptr->k_idx].pval);
1610
1611                         /* Assume okay */
1612                         break;
1613                 }
1614
1615                 /* Weapons and Armor */
1616                 case TV_BOW:
1617                 case TV_DIGGING:
1618                 case TV_HAFTED:
1619                 case TV_POLEARM:
1620                 case TV_SWORD:
1621                 case TV_BOOTS:
1622                 case TV_GLOVES:
1623                 case TV_HELM:
1624                 case TV_CROWN:
1625                 case TV_SHIELD:
1626                 case TV_CLOAK:
1627                 case TV_SOFT_ARMOR:
1628                 case TV_HARD_ARMOR:
1629                 case TV_DRAG_ARMOR:
1630
1631                 /* Rings, Amulets, Lites */
1632                 case TV_RING:
1633                 case TV_AMULET:
1634                 case TV_LITE:
1635                 case TV_WHISTLE:
1636                 {
1637                         /* Require full knowledge of both items */
1638                         if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1639
1640                         /* Fall through */
1641                 }
1642
1643                 /* Missiles */
1644                 case TV_BOLT:
1645                 case TV_ARROW:
1646                 case TV_SHOT:
1647                 {
1648                         /* Require identical knowledge of both items */
1649                         if (object_is_known(o_ptr) != object_is_known(j_ptr)) return 0;
1650                         if (o_ptr->feeling != j_ptr->feeling) return 0;
1651
1652                         /* Require identical "bonuses" */
1653                         if (o_ptr->to_h != j_ptr->to_h) return 0;
1654                         if (o_ptr->to_d != j_ptr->to_d) return 0;
1655                         if (o_ptr->to_a != j_ptr->to_a) return 0;
1656
1657                         /* Require identical "pval" code */
1658                         if (o_ptr->pval != j_ptr->pval) return 0;
1659
1660                         /* Artifacts never stack */
1661                         if (object_is_artifact(o_ptr) || object_is_artifact(j_ptr)) return 0;
1662
1663                         /* Require identical "ego-item" names */
1664                         if (o_ptr->name2 != j_ptr->name2) return 0;
1665
1666                         /* Require identical added essence  */
1667                         if (o_ptr->xtra3 != j_ptr->xtra3) return 0;
1668                         if (o_ptr->xtra4 != j_ptr->xtra4) return 0;
1669
1670                         /* Hack -- Never stack "powerful" items */
1671                         if (o_ptr->xtra1 || j_ptr->xtra1) return 0;
1672
1673                         /* Hack -- Never stack recharging items */
1674                         if (o_ptr->timeout || j_ptr->timeout) return 0;
1675
1676                         /* Require identical "values" */
1677                         if (o_ptr->ac != j_ptr->ac) return 0;
1678                         if (o_ptr->dd != j_ptr->dd) return 0;
1679                         if (o_ptr->ds != j_ptr->ds) return 0;
1680
1681                         /* Probably okay */
1682                         break;
1683                 }
1684
1685                 /* Various */
1686                 default:
1687                 {
1688                         /* Require knowledge */
1689                         if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1690
1691                         /* Probably okay */
1692                         break;
1693                 }
1694         }
1695
1696
1697         /* Hack -- Identical art_flags! */
1698         for (i = 0; i < TR_FLAG_SIZE; i++)
1699                 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return 0;
1700
1701         /* Hack -- Require identical "cursed" status */
1702         if (o_ptr->curse_flags != j_ptr->curse_flags) return 0;
1703
1704         /* Hack -- Require identical "broken" status */
1705         if ((o_ptr->ident & (IDENT_BROKEN)) != (j_ptr->ident & (IDENT_BROKEN))) return 0;
1706
1707
1708         /* Hack -- require semi-matching "inscriptions" */
1709         if (o_ptr->inscription && j_ptr->inscription &&
1710             (o_ptr->inscription != j_ptr->inscription))
1711                 return 0;
1712
1713         /* Hack -- normally require matching "inscriptions" */
1714         if (!stack_force_notes && (o_ptr->inscription != j_ptr->inscription)) return 0;
1715
1716         /* Hack -- normally require matching "discounts" */
1717         if (!stack_force_costs && (o_ptr->discount != j_ptr->discount)) return 0;
1718
1719
1720         /* They match, so they must be similar */
1721         return max_num;
1722 }
1723
1724 /*!
1725  * @brief 両オブジェクトをスロットに重ねることができるかどうかを返す。
1726  * Determine if an item can absorb a second item.
1727  * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1728  * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1729  * @return 重ね合わせ可能ならばTRUEを返す。
1730  */
1731 bool object_similar(object_type *o_ptr, object_type *j_ptr)
1732 {
1733         int total = o_ptr->number + j_ptr->number;
1734         int max_num;
1735
1736         /* Are these objects similar? */
1737         max_num = object_similar_part(o_ptr, j_ptr);
1738
1739         /* Return if not similar */
1740         if (!max_num) return FALSE;
1741
1742         /* Maximal "stacking" limit */
1743         if (total > max_num) return (0);
1744
1745
1746         /* They match, so they must be similar */
1747         return (TRUE);
1748 }
1749
1750
1751 /*!
1752  * @brief 両オブジェクトをスロットに重ね合わせる。
1753  * Allow one item to "absorb" another, assuming they are similar
1754  * @param o_ptr 重ね合わせ先のオブジェクトの構造体参照ポインタ
1755  * @param j_ptr 重ね合わせ元のオブジェクトの構造体参照ポインタ
1756  * @return なし
1757  */
1758 void object_absorb(object_type *o_ptr, object_type *j_ptr)
1759 {
1760         int max_num = object_similar_part(o_ptr, j_ptr);
1761         int total = o_ptr->number + j_ptr->number;
1762         int diff = (total > max_num) ? total - max_num : 0;
1763
1764         /* Combine quantity, lose excess items */
1765         o_ptr->number = (total > max_num) ? max_num : total;
1766
1767         /* Hack -- blend "known" status */
1768         if (object_is_known(j_ptr)) object_known(o_ptr);
1769
1770         /* Hack -- clear "storebought" if only one has it */
1771         if (((o_ptr->ident & IDENT_STORE) || (j_ptr->ident & IDENT_STORE)) &&
1772             (!((o_ptr->ident & IDENT_STORE) && (j_ptr->ident & IDENT_STORE))))
1773         {
1774                 if (j_ptr->ident & IDENT_STORE) j_ptr->ident &= 0xEF;
1775                 if (o_ptr->ident & IDENT_STORE) o_ptr->ident &= 0xEF;
1776         }
1777
1778         /* Hack -- blend "mental" status */
1779         if (j_ptr->ident & (IDENT_MENTAL)) o_ptr->ident |= (IDENT_MENTAL);
1780
1781         /* Hack -- blend "inscriptions" */
1782         if (j_ptr->inscription) o_ptr->inscription = j_ptr->inscription;
1783
1784         /* Hack -- blend "feelings" */
1785         if (j_ptr->feeling) o_ptr->feeling = j_ptr->feeling;
1786
1787         /* Hack -- could average discounts */
1788         /* Hack -- save largest discount */
1789         if (o_ptr->discount < j_ptr->discount) o_ptr->discount = j_ptr->discount;
1790
1791         /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1792         if (o_ptr->tval == TV_ROD)
1793         {
1794                 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1795                 o_ptr->timeout += j_ptr->timeout * (j_ptr->number - diff) / j_ptr->number;
1796         }
1797
1798         /* Hack -- if wands are stacking, combine the charges. -LM- */
1799         if (o_ptr->tval == TV_WAND)
1800         {
1801                 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1802         }
1803 }
1804
1805
1806 /*!
1807  * @brief tvalとsvalに対応するベースアイテムのIDを返す。
1808  * Find the index of the object_kind with the given tval and sval
1809  * @param tval 検索したいベースアイテムのtval
1810  * @param sval 検索したいベースアイテムのsval
1811  * @return なし
1812  */
1813 KIND_OBJECT_IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
1814 {
1815         KIND_OBJECT_IDX k;
1816         int num = 0;
1817         KIND_OBJECT_IDX bk = 0;
1818
1819         /* Look for it */
1820         for (k = 1; k < max_k_idx; k++)
1821         {
1822                 object_kind *k_ptr = &k_info[k];
1823
1824                 /* Require correct tval */
1825                 if (k_ptr->tval != tval) continue;
1826
1827                 /* Found a match */
1828                 if (k_ptr->sval == sval) return (k);
1829
1830                 /* Ignore illegal items */
1831                 if (sval != SV_ANY) continue;
1832
1833                 /* Apply the randomizer */
1834                 if (!one_in_(++num)) continue;
1835
1836                 /* Use this value */
1837                 bk = k;
1838         }
1839
1840         /* Return this choice */
1841         if (sval == SV_ANY)
1842         {
1843                 return bk;
1844         }
1845
1846 #if 0
1847         msg_format(_("アイテムがない (%d,%d)", "No object (%d,%d)"), tval, sval);
1848 #endif
1849
1850
1851         return (0);
1852 }
1853
1854
1855 /*!
1856  * @brief オブジェクトを初期化する
1857  * Wipe an object clean.
1858  * @param o_ptr 初期化したいオブジェクトの構造体参照ポインタ
1859  * @return なし
1860  */
1861 void object_wipe(object_type *o_ptr)
1862 {
1863         /* Wipe the structure */
1864         (void)WIPE(o_ptr, object_type);
1865 }
1866
1867
1868 /*!
1869  * @brief オブジェクトを複製する
1870  * Wipe an object clean.
1871  * @param o_ptr 複製元のオブジェクトの構造体参照ポインタ
1872  * @param j_ptr 複製先のオブジェクトの構造体参照ポインタ
1873  * @return なし
1874  */
1875 void object_copy(object_type *o_ptr, object_type *j_ptr)
1876 {
1877         /* Copy the structure */
1878         (void)COPY(o_ptr, j_ptr, object_type);
1879 }
1880
1881
1882 /*!
1883  * @brief オブジェクト構造体にベースアイテムを作成する
1884  * Prepare an object based on an object kind.
1885  * @param o_ptr 代入したいオブジェクトの構造体参照ポインタ
1886  * @param k_idx 新たに作成したいベースアイテム情報のID
1887  * @return なし
1888  */
1889 void object_prep(object_type *o_ptr, KIND_OBJECT_IDX k_idx)
1890 {
1891         object_kind *k_ptr = &k_info[k_idx];
1892
1893         /* Clear the record */
1894         object_wipe(o_ptr);
1895
1896         /* Save the kind index */
1897         o_ptr->k_idx = k_idx;
1898
1899         /* Efficiency -- tval/sval */
1900         o_ptr->tval = k_ptr->tval;
1901         o_ptr->sval = k_ptr->sval;
1902
1903         /* Default "pval" */
1904         o_ptr->pval = k_ptr->pval;
1905
1906         /* Default number */
1907         o_ptr->number = 1;
1908
1909         /* Default weight */
1910         o_ptr->weight = k_ptr->weight;
1911
1912         /* Default magic */
1913         o_ptr->to_h = k_ptr->to_h;
1914         o_ptr->to_d = k_ptr->to_d;
1915         o_ptr->to_a = k_ptr->to_a;
1916
1917         /* Default power */
1918         o_ptr->ac = k_ptr->ac;
1919         o_ptr->dd = k_ptr->dd;
1920         o_ptr->ds = k_ptr->ds;
1921
1922         /* Default activation */
1923         if (k_ptr->act_idx > 0) o_ptr->xtra2 = (XTRA8)k_ptr->act_idx;
1924
1925         /* Hack -- worthless items are always "broken" */
1926         if (k_info[o_ptr->k_idx].cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
1927
1928         /* Hack -- cursed items are always "cursed" */
1929         if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
1930         if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
1931         if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
1932         if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
1933         if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
1934         if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
1935 }
1936
1937
1938 /*!
1939  * @brief デバッグ時にアイテム生成情報をメッセージに出力する / Cheat -- describe a created object for the user
1940  * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ
1941  * @return なし
1942  */
1943 static void object_mention(object_type *o_ptr)
1944 {
1945         GAME_TEXT o_name[MAX_NLEN];
1946
1947         object_aware(o_ptr);
1948         object_known(o_ptr);
1949
1950         /* Mark the item as fully known */
1951         o_ptr->ident |= (IDENT_MENTAL);
1952         object_desc(o_name, o_ptr, 0);
1953         msg_format_wizard(CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
1954 }
1955
1956
1957 /*!
1958  * @brief アイテムのエゴをレア度の重みに合わせてランダムに選択する
1959  * Choose random ego type
1960  * @param slot 取得したいエゴの装備部位
1961  * @param good TRUEならば通常のエゴ、FALSEならば呪いのエゴが選択対象となる。
1962  * @return 選択されたエゴ情報のID、万一選択できなかった場合はmax_e_idxが返る。
1963  */
1964 static byte get_random_ego(byte slot, bool good)
1965 {
1966         int i, value;
1967         ego_item_type *e_ptr;
1968
1969         long total = 0L;
1970         
1971         for (i = 1; i < max_e_idx; i++)
1972         {
1973                 e_ptr = &e_info[i];
1974                 
1975                 if (e_ptr->slot == slot
1976                     && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
1977                 {
1978                         if (e_ptr->rarity)
1979                                 total += (255 / e_ptr->rarity);
1980                 }
1981         }
1982
1983         value = randint1(total);
1984
1985         for (i = 1; i < max_e_idx; i++)
1986         {
1987                 e_ptr = &e_info[i];
1988                 
1989                 if (e_ptr->slot == slot
1990                     && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
1991                 {
1992                         if (e_ptr->rarity)
1993                                 value -= (255 / e_ptr->rarity);
1994                         if (value <= 0L) break;
1995                 }
1996         }
1997         return (byte)i;
1998 }
1999
2000
2001 /*!
2002  * @brief 武器系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2003  * Apply magic to an item known to be a "weapon"
2004  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2005  * @param level 生成基準階
2006  * @param power 生成ランク
2007  * @return なし
2008  * @details
2009  * Hack -- note special base damage dice boosting\n
2010  * Hack -- note special processing for weapon/digger\n
2011  */
2012 void apply_magic_weapon(object_type *o_ptr, DEPTH level, int power)
2013 {
2014         HIT_PROB tohit1 = randint1(5) + (HIT_PROB)m_bonus(5, level);
2015         HIT_POINT todam1 = randint1(5) + (HIT_POINT)m_bonus(5, level);
2016
2017         HIT_PROB tohit2 = (HIT_PROB)m_bonus(10, level);
2018         HIT_POINT todam2 = (HIT_POINT)m_bonus(10, level);
2019
2020         if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
2021         {
2022                 tohit2 = (tohit2 + 1) / 2;
2023                 todam2 = (todam2 + 1) / 2;
2024         }
2025
2026         /* Good */
2027         if (power > 0)
2028         {
2029                 /* Enchant */
2030                 o_ptr->to_h += tohit1;
2031                 o_ptr->to_d += todam1;
2032
2033                 /* Very good */
2034                 if (power > 1)
2035                 {
2036                         /* Enchant again */
2037                         o_ptr->to_h += tohit2;
2038                         o_ptr->to_d += todam2;
2039                 }
2040         }
2041
2042         /* Cursed */
2043         else if (power < 0)
2044         {
2045                 /* Penalize */
2046                 o_ptr->to_h -= tohit1;
2047                 o_ptr->to_d -= todam1;
2048
2049                 /* Very cursed */
2050                 if (power < -1)
2051                 {
2052                         /* Penalize again */
2053                         o_ptr->to_h -= tohit2;
2054                         o_ptr->to_d -= todam2;
2055                 }
2056
2057                 /* Cursed (if "bad") */
2058                 if (o_ptr->to_h + o_ptr->to_d < 0) o_ptr->curse_flags |= TRC_CURSED;
2059         }
2060
2061         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)) return;
2062
2063         switch (o_ptr->tval)
2064         {
2065                 case TV_DIGGING:
2066                 {
2067                         /* Very good */
2068                         if (power > 1)
2069                         {
2070                                 if (one_in_(30) || (power > 2)) /* power > 2 is debug only */
2071                                         create_artifact(o_ptr, FALSE);
2072                                 else
2073                                         /* Special Ego-item */
2074                                         o_ptr->name2 = EGO_DIGGING;
2075                         }
2076
2077                         /* Very bad */
2078                         else if (power < -1)
2079                         {
2080                                 /* Hack -- Horrible digging bonus */
2081                                 o_ptr->pval = 0 - (5 + randint1(5));
2082                         }
2083
2084                         /* Bad */
2085                         else if (power < 0)
2086                         {
2087                                 /* Hack -- Reverse digging bonus */
2088                                 o_ptr->pval = 0 - (o_ptr->pval);
2089                         }
2090
2091                         break;
2092                 }
2093
2094                 case TV_HAFTED:
2095                 case TV_POLEARM:
2096                 case TV_SWORD:
2097                 {
2098                         /* Very Good */
2099                         if (power > 1)
2100                         {
2101                                 if (one_in_(40) || (power > 2)) /* power > 2 is debug only */
2102                                 {
2103                                         create_artifact(o_ptr, FALSE);
2104                                         break;
2105                                 }
2106                                 while (1)
2107                                 {
2108                                         /* Roll for an ego-item */
2109                                         o_ptr->name2 = get_random_ego(INVEN_RARM, TRUE);
2110                                         if (o_ptr->name2 == EGO_SHARPNESS && o_ptr->tval != TV_SWORD)
2111                                                 continue;
2112                                         if (o_ptr->name2 == EGO_EARTHQUAKES && o_ptr->tval != TV_HAFTED)
2113                                                 continue;
2114                                         if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2115                                                 continue;
2116                                         break;
2117                                 }
2118
2119                                 switch (o_ptr->name2)
2120                                 {
2121                                 case EGO_HA:
2122                                         if (one_in_(4) && (level > 40))
2123                                                 add_flag(o_ptr->art_flags, TR_BLOWS);
2124                                         break;
2125                                 case EGO_DF:
2126                                         if (one_in_(3))
2127                                                 add_flag(o_ptr->art_flags, TR_RES_POIS);
2128                                         if (one_in_(3))
2129                                                 add_flag(o_ptr->art_flags, TR_WARNING);
2130                                         break;
2131                                 case EGO_KILL_DRAGON:
2132                                         if (one_in_(3))
2133                                                 add_flag(o_ptr->art_flags, TR_RES_POIS);
2134                                         break;
2135                                 case EGO_WEST:
2136                                         if (one_in_(3))
2137                                                 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2138                                         break;
2139                                 case EGO_SLAYING_WEAPON:
2140                                         if (one_in_(3)) /* double damage */
2141                                                 o_ptr->dd *= 2;
2142                                         else
2143                                         {
2144                                                 do
2145                                                 {
2146                                                         o_ptr->dd++;
2147                                                 } while (one_in_(o_ptr->dd));
2148
2149                                                 do
2150                                                 {
2151                                                         o_ptr->ds++;
2152                                                 } while (one_in_(o_ptr->ds));
2153                                         }
2154
2155                                         if (one_in_(5))
2156                                         {
2157                                                 add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2158                                         }
2159                                         if (o_ptr->tval == TV_SWORD && one_in_(3))
2160                                         {
2161                                                 add_flag(o_ptr->art_flags, TR_VORPAL);
2162                                         }
2163                                         break;
2164                                 case EGO_TRUMP:
2165                                         if (one_in_(5))
2166                                                 add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
2167                                         if (one_in_(7))
2168                                                 one_ability(o_ptr);
2169                                         break;
2170                                 case EGO_PATTERN:
2171                                         if (one_in_(3))
2172                                                 add_flag(o_ptr->art_flags, TR_HOLD_EXP);
2173                                         if (one_in_(3))
2174                                                 add_flag(o_ptr->art_flags, TR_DEX);
2175                                         if (one_in_(5))
2176                                                 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2177                                         break;
2178                                 case EGO_SHARPNESS:
2179                                         o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, level) + 1;
2180                                         break;
2181                                 case EGO_EARTHQUAKES:
2182                                         if (one_in_(3) && (level > 60))
2183                                                 add_flag(o_ptr->art_flags, TR_BLOWS);
2184                                         else
2185                                                 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, level);
2186                                         break;
2187                                 case EGO_VAMPIRIC:
2188                                         if (one_in_(5))
2189                                                 add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
2190                                         break;
2191                                 case EGO_DEMON:
2192
2193                                         if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2194                                         one_in_(3) ?
2195                                                 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2196                                                 one_in_(2) ?
2197                                                 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2198                                                 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2199
2200
2201                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CHAOTIC);
2202                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BLOWS);
2203                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2204                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2205                                         break;
2206                                 }
2207
2208                                 if (!o_ptr->art_name)
2209                                 {
2210                                         /* Hack -- Super-charge the damage dice */
2211                                         while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2212
2213                                         /* Hack -- Lower the damage dice */
2214                                         if (o_ptr->dd > 9) o_ptr->dd = 9;
2215                                 }
2216                         }
2217
2218                         /* Very cursed */
2219                         else if (power < -1)
2220                         {
2221                                 /* Roll for ego-item */
2222                                 if (randint0(MAX_DEPTH) < level)
2223                                 {
2224                                         while (1)
2225                                         {
2226                                                 o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE);
2227                                                 if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2228                                                 {
2229                                                         continue;
2230                                                 }
2231                                                 break;
2232                                         }
2233                                         switch (o_ptr->name2)
2234                                         {
2235                                         case EGO_MORGUL:
2236                                                 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2237                                                 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2238                                         case EGO_WEIRD:
2239                                                 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2240                                                 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_NETHER);
2241                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2242                                                 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2243                                                 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2244                                                 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2245                                         }
2246                                 }
2247                         }
2248
2249                         break;
2250                 }
2251
2252
2253                 case TV_BOW:
2254                 {
2255                         /* Very good */
2256                         if (power > 1)
2257                         {
2258                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2259                                 {
2260                                         create_artifact(o_ptr, FALSE);
2261                                         break;
2262                                 }
2263                                 o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE);
2264                         }
2265
2266                         break;
2267                 }
2268
2269
2270                 case TV_BOLT:
2271                 case TV_ARROW:
2272                 case TV_SHOT:
2273                 {
2274                         /* Very good */
2275                         if (power > 1)
2276                         {
2277                                 if (power > 2) /* power > 2 is debug only */
2278                                 {
2279                                         create_artifact(o_ptr, FALSE);
2280                                         break;
2281                                 }
2282
2283                                 o_ptr->name2 = get_random_ego(INVEN_AMMO, TRUE);
2284
2285                                 switch (o_ptr->name2)
2286                                 {
2287                                 case EGO_SLAYING_BOLT:
2288                                         o_ptr->dd++;
2289                                         break;
2290                                 }
2291
2292                                 /* Hack -- super-charge the damage dice */
2293                                 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2294
2295                                 /* Hack -- restrict the damage dice */
2296                                 if (o_ptr->dd > 9) o_ptr->dd = 9;
2297                         }
2298
2299                         /* Very cursed */
2300                         else if (power < -1)
2301                         {
2302                                 /* Roll for ego-item */
2303                                 if (randint0(MAX_DEPTH) < level)
2304                                 {
2305                                         o_ptr->name2 = get_random_ego(INVEN_AMMO, FALSE);
2306                                 }
2307                         }
2308
2309                         break;
2310                 }
2311         }
2312 }
2313
2314 /*!
2315  * @brief 防具系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2316  * Apply magic to an item known to be "armor"
2317  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2318  * @param level 生成基準階
2319  * @param power 生成ランク
2320  * @return なし
2321  * @details
2322  * Hack -- note special processing for crown/helm\n
2323  * Hack -- note special processing for robe of permanence\n
2324  */
2325 static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
2326 {
2327         ARMOUR_CLASS toac1 = (ARMOUR_CLASS)randint1(5) + m_bonus(5, level);
2328         ARMOUR_CLASS toac2 = (ARMOUR_CLASS)m_bonus(10, level);
2329
2330         /* Good */
2331         if (power > 0)
2332         {
2333                 /* Enchant */
2334                 o_ptr->to_a += toac1;
2335
2336                 /* Very good */
2337                 if (power > 1)
2338                 {
2339                         /* Enchant again */
2340                         o_ptr->to_a += toac2;
2341                 }
2342         }
2343
2344         /* Cursed */
2345         else if (power < 0)
2346         {
2347                 /* Penalize */
2348                 o_ptr->to_a -= toac1;
2349
2350                 /* Very cursed */
2351                 if (power < -1)
2352                 {
2353                         /* Penalize again */
2354                         o_ptr->to_a -= toac2;
2355                 }
2356
2357                 /* Cursed (if "bad") */
2358                 if (o_ptr->to_a < 0) o_ptr->curse_flags |= TRC_CURSED;
2359         }
2360
2361         switch (o_ptr->tval)
2362         {
2363                 case TV_DRAG_ARMOR:
2364                 {
2365                         if (one_in_(50) || (power > 2)) /* power > 2 is debug only */
2366                                 create_artifact(o_ptr, FALSE);
2367                         break;
2368                 }
2369
2370                 case TV_HARD_ARMOR:
2371                 case TV_SOFT_ARMOR:
2372                 {
2373                         /* Very good */
2374                         if (power > 1)
2375                         {
2376                                 /* Hack -- Try for "Robes of the Magi" */
2377                                 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
2378                                     (o_ptr->sval == SV_ROBE) &&
2379                                     (randint0(100) < 15))
2380                                 {
2381                                         if (one_in_(5))
2382                                         {
2383                                                 o_ptr->name2 = EGO_YOIYAMI;
2384                                                 o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
2385                                                 o_ptr->sval = SV_YOIYAMI_ROBE;
2386                                                 o_ptr->ac = 0;
2387                                                 o_ptr->to_a = 0;
2388                                         }
2389                                         else
2390                                         {
2391                                                 o_ptr->name2 = EGO_PERMANENCE;
2392                                         }
2393                                         break;
2394                                 }
2395
2396                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2397                                 {
2398                                         create_artifact(o_ptr, FALSE);
2399                                         break;
2400                                 }
2401
2402                                 while (1)
2403                                 {
2404                                         bool okay_flag = TRUE;
2405
2406                                         o_ptr->name2 = get_random_ego(INVEN_BODY, TRUE);
2407
2408                                         switch (o_ptr->name2)
2409                                         {
2410                                                 case EGO_DWARVEN:
2411                                                         if (o_ptr->tval != TV_HARD_ARMOR)
2412                                                         {
2413                                                                 okay_flag = FALSE;
2414                                                         }
2415                                                 break;
2416                                                 case EGO_DRUID:
2417                                                         if (o_ptr->tval != TV_SOFT_ARMOR)
2418                                                         {
2419                                                                 okay_flag = FALSE;
2420                                                         }
2421                                                 break;
2422                                                 default:
2423                                                 break;
2424                                         }
2425
2426                                         if (okay_flag) break;
2427                                 }
2428                                 switch (o_ptr->name2)
2429                                 {
2430                                   case EGO_RESISTANCE:
2431                                         if (one_in_(4))
2432                                                 add_flag(o_ptr->art_flags, TR_RES_POIS);
2433                                                 break;
2434                                   case EGO_DWARVEN:
2435                                         o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2436                                         o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
2437                                         break;
2438                                         
2439                                   case EGO_A_DEMON:
2440                                         if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2441                                         one_in_(3) ? 
2442                                                 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2443                                                 one_in_(2) ?
2444                                                         add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2445                                                         add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2446                                                 
2447                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2448                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2449                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2450                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2451                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2452                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2453                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2454                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2455                                         break;
2456                                   case EGO_A_MORGUL:
2457                                         if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2458                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2459                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2460                                         if (one_in_(6)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2461                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2462                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2463                                         break;
2464                                   default:
2465                                         break;
2466                                 }
2467                         }
2468
2469                         break;
2470                 }
2471
2472                 case TV_SHIELD:
2473                 {
2474
2475                         if (o_ptr->sval == SV_DRAGON_SHIELD)
2476                         {
2477                                 dragon_resist(o_ptr);
2478                                 if (!one_in_(3)) break;
2479                         }
2480
2481                         /* Very good */
2482                         if (power > 1)
2483                         {
2484                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2485                                 {
2486                                         create_artifact(o_ptr, FALSE);
2487                                         break;
2488                                 }
2489                                 
2490                                 while(1)
2491                                 {
2492                                         o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE);
2493                                         if (o_ptr->sval != SV_SMALL_METAL_SHIELD && o_ptr->sval != SV_LARGE_METAL_SHIELD 
2494                                                                 && o_ptr->name2 == EGO_S_DWARVEN)
2495                                         {
2496                                                 continue;
2497                                         }
2498                                         break;
2499                                 }
2500                                 
2501                                 switch (o_ptr->name2)
2502                                 {
2503                                 case EGO_ENDURANCE:
2504                                         if (!one_in_(3)) one_high_resistance(o_ptr);
2505                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_POIS);
2506                                         break;
2507                                 case EGO_REFLECTION:
2508                                         if (o_ptr->sval == SV_MIRROR_SHIELD)
2509                                                 o_ptr->name2 = 0;
2510                                         break;
2511                                         
2512                                 case EGO_S_DWARVEN:
2513                                         o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2514                                         o_ptr->ac = k_info[o_ptr->k_idx].ac + 3;
2515                                         break;
2516                                 }
2517                         }
2518                         break;
2519                 }
2520
2521                 case TV_GLOVES:
2522                 {
2523                         if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
2524                         {
2525                                 dragon_resist(o_ptr);
2526                                 if (!one_in_(3)) break;
2527                         }
2528                         if (power > 1)
2529                         {
2530                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2531                                 {
2532                                         create_artifact(o_ptr, FALSE);
2533                                         break;
2534                                 }
2535                                 o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE);
2536                         }
2537                         
2538                         /* Very cursed */
2539                         else if (power < -1)
2540                         {
2541                                 o_ptr->name2 = get_random_ego(INVEN_HANDS, FALSE);
2542                         }
2543
2544                         break;
2545                 }
2546
2547                 case TV_BOOTS:
2548                 {
2549                         if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
2550                         {
2551                                 dragon_resist(o_ptr);
2552                                 if (!one_in_(3)) break;
2553                         }
2554                         /* Very good */
2555                         if (power > 1)
2556                         {
2557                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2558                                 {
2559                                         create_artifact(o_ptr, FALSE);
2560                                         break;
2561                                 }
2562                                 o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE);
2563
2564                                 switch (o_ptr->name2)
2565                                 {
2566                                 case EGO_SLOW_DESCENT:
2567                                         if (one_in_(2))
2568                                         {
2569                                                 one_high_resistance(o_ptr);
2570                                         }
2571                                         break;
2572                                 }
2573                         }
2574                         /* Very cursed */
2575                         else if (power < -1)
2576                         {
2577                                 o_ptr->name2 = get_random_ego(INVEN_FEET, FALSE);
2578                         }
2579
2580                         break;
2581                 }
2582
2583                 case TV_CROWN:
2584                 {
2585                         /* Very good */
2586                         if (power > 1)
2587                         {
2588                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2589                                 {
2590                                         create_artifact(o_ptr, FALSE);
2591                                         break;
2592                                 }
2593                                 while (1)
2594                                 {
2595                                         bool ok_flag = TRUE;
2596                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2597
2598                                         switch (o_ptr->name2)
2599                                         {
2600                                         case EGO_TELEPATHY:
2601                                                 if (add_esp_strong(o_ptr)) add_esp_weak(o_ptr, TRUE);
2602                                                 else add_esp_weak(o_ptr, FALSE);
2603                                                 break;
2604                                         case EGO_MAGI:
2605                                         case EGO_MIGHT:
2606                                         case EGO_REGENERATION:
2607                                         case EGO_LORDLINESS:
2608                                         case EGO_BASILISK:
2609                                                 break;
2610                                         case EGO_SEEING:
2611                                                 if (one_in_(3))
2612                                                 {
2613                                                         if (one_in_(2)) add_esp_strong(o_ptr);
2614                                                         else add_esp_weak(o_ptr, FALSE);
2615                                                 }
2616                                                 break;
2617                                         default:/* not existing crown (wisdom,lite, etc...) */
2618                                                 ok_flag = FALSE;
2619                                         }
2620                                         if (ok_flag)
2621                                                 break; /* while (1) */
2622                                 }
2623                                 break;
2624                         }
2625
2626                         /* Very cursed */
2627                         else if (power < -1)
2628                         {       
2629                                 while (1)
2630                                 {
2631                                         bool ok_flag = TRUE;
2632                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2633
2634                                         switch (o_ptr->name2)
2635                                         {
2636                                           case EGO_ANCIENT_CURSE:
2637                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2638                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2639                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2640                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2641                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2642                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2643                                                 break;
2644                                         }
2645                                         if (ok_flag)
2646                                                 break; /* while (1) */
2647                                 }
2648                         }
2649
2650                         break;
2651                 }
2652
2653                 case TV_HELM:
2654                 {
2655                         if (o_ptr->sval == SV_DRAGON_HELM)
2656                         {
2657                                 dragon_resist(o_ptr);
2658                                 if (!one_in_(3)) break;
2659                         }
2660
2661                         /* Very good */
2662                         if (power > 1)
2663                         {
2664                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2665                                 {
2666                                         create_artifact(o_ptr, FALSE);
2667                                         break;
2668                                 }
2669                                 while (1)
2670                                 {
2671                                         bool ok_flag = TRUE;
2672                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2673
2674                                         switch (o_ptr->name2)
2675                                         {
2676                                         case EGO_BRILLIANCE:
2677                                         case EGO_DARK:
2678                                         case EGO_INFRAVISION:
2679                                         case EGO_H_PROTECTION:
2680                                                 break;
2681                                         case EGO_SEEING:
2682                                                 if (one_in_(7))
2683                                                 {
2684                                                         if (one_in_(2)) add_esp_strong(o_ptr);
2685                                                         else add_esp_weak(o_ptr, FALSE);
2686                                                 }
2687                                                 break;
2688                                         case EGO_LITE:
2689                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_1);
2690                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_2);
2691                                                 break;
2692                                         case EGO_H_DEMON:
2693                                                 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2694                                                 one_in_(3) ? 
2695                                                         add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2696                                                         one_in_(2) ?
2697                                                                 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2698                                                                 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2699                                                 
2700                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2701                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2702                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2703                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2704                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2705                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2706                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2707                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2708                                                 break;
2709                                         default:/* not existing helm (Magi, Might, etc...)*/
2710                                                 ok_flag = FALSE;
2711                                         }
2712                                         if (ok_flag)
2713                                                 break; /* while (1) */
2714                                 }
2715                                 break;
2716                         }
2717                         /* Very cursed */
2718                         else if (power < -1)
2719                         {
2720                                 while (1)
2721                                 {
2722                                         bool ok_flag = TRUE;
2723                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2724
2725                                         switch (o_ptr->name2)
2726                                         {
2727                                           case EGO_ANCIENT_CURSE:
2728                                                 ok_flag = FALSE;
2729                                         }
2730                                         if (ok_flag)
2731                                                 break; /* while (1) */
2732                                 }
2733                         }
2734                         break;
2735                 }
2736
2737                 case TV_CLOAK:
2738                 {
2739                         /* Very good */
2740                         if (power > 1)
2741                         {
2742                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2743                                 {
2744                                         create_artifact(o_ptr, FALSE);
2745                                         break;
2746                                 }
2747                                 o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE);
2748
2749                                 switch (o_ptr->name2)
2750                                 {
2751                                 case EGO_BAT:
2752                                         o_ptr->to_d -= 6;
2753                                         o_ptr->to_h -= 6;
2754                                         break;
2755                                 case EGO_NAZGUL:
2756                                         o_ptr->to_d -= 3;
2757                                         o_ptr->to_h -= 3;
2758                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_COWARDICE);
2759                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CALL_UNDEAD);
2760                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_SLOW_REGEN);
2761                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2762                                         break;
2763                                 }
2764
2765                         }
2766
2767                         /* Very cursed */
2768                         else if (power < -1)
2769                         {
2770                                 o_ptr->name2 = get_random_ego(INVEN_OUTER, FALSE);
2771                         }
2772
2773                         break;
2774                 }
2775         }
2776
2777 }
2778
2779
2780 /*!
2781  * @brief 装飾品系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2782  * Apply magic to an item known to be a "ring" or "amulet"
2783  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2784  * @param level 生成基準階
2785  * @param power 生成ランク
2786  * @return なし
2787  * @details
2788  * Hack -- note special "pval boost" code for ring of speed\n
2789  * Hack -- note that some items must be cursed (or blessed)\n
2790  */
2791 static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
2792 {
2793         /* Apply magic (good or bad) according to type */
2794         switch (o_ptr->tval)
2795         {
2796                 case TV_RING:
2797                 {
2798                         /* Analyze */
2799                         switch (o_ptr->sval)
2800                         {
2801                                 case SV_RING_ATTACKS:
2802                                 {
2803                                         /* Stat bonus */
2804                                         o_ptr->pval = (PARAMETER_VALUE)m_bonus(2, level);
2805                                         if (one_in_(15)) o_ptr->pval++;
2806                                         if (o_ptr->pval < 1) o_ptr->pval = 1;
2807
2808                                         /* Cursed */
2809                                         if (power < 0)
2810                                         {
2811                                                 /* Broken */
2812                                                 o_ptr->ident |= (IDENT_BROKEN);
2813
2814                                                 /* Cursed */
2815                                                 o_ptr->curse_flags |= TRC_CURSED;
2816
2817                                                 /* Reverse pval */
2818                                                 o_ptr->pval = 0 - (o_ptr->pval);
2819                                         }
2820
2821                                         break;
2822                                 }
2823
2824                                 case SV_RING_SHOTS:
2825                                 {
2826                                         break;
2827                                 }
2828
2829                                 /* Strength, Constitution, Dexterity, Intelligence */
2830                                 case SV_RING_STR:
2831                                 case SV_RING_CON:
2832                                 case SV_RING_DEX:
2833                                 {
2834                                         /* Stat bonus */
2835                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2836
2837                                         /* Cursed */
2838                                         if (power < 0)
2839                                         {
2840                                                 /* Broken */
2841                                                 o_ptr->ident |= (IDENT_BROKEN);
2842
2843                                                 /* Cursed */
2844                                                 o_ptr->curse_flags |= TRC_CURSED;
2845
2846                                                 /* Reverse pval */
2847                                                 o_ptr->pval = 0 - (o_ptr->pval);
2848                                         }
2849
2850                                         break;
2851                                 }
2852
2853                                 /* Ring of Speed! */
2854                                 case SV_RING_SPEED:
2855                                 {
2856                                         /* Base speed (1 to 10) */
2857                                         o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
2858
2859                                         /* Super-charge the ring */
2860                                         while (randint0(100) < 50) o_ptr->pval++;
2861
2862                                         /* Cursed Ring */
2863                                         if (power < 0)
2864                                         {
2865                                                 /* Broken */
2866                                                 o_ptr->ident |= (IDENT_BROKEN);
2867
2868                                                 /* Cursed */
2869                                                 o_ptr->curse_flags |= TRC_CURSED;
2870
2871                                                 /* Reverse pval */
2872                                                 o_ptr->pval = 0 - (o_ptr->pval);
2873
2874                                                 break;
2875                                         }
2876
2877                                         break;
2878                                 }
2879
2880                                 case SV_RING_LORDLY:
2881                                 {
2882                                         do
2883                                         {
2884                                                 one_lordly_high_resistance(o_ptr);
2885                                         }
2886                                         while (one_in_(4));
2887
2888                                         /* Bonus to armor class */
2889                                         o_ptr->to_a = 10 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2890                                 }
2891                                 break;
2892
2893                                 case SV_RING_WARNING:
2894                                 {
2895                                         if (one_in_(3)) one_low_esp(o_ptr);
2896                                         break;
2897                                 }
2898
2899                                 /* Searching */
2900                                 case SV_RING_SEARCHING:
2901                                 {
2902                                         /* Bonus to searching */
2903                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2904
2905                                         /* Cursed */
2906                                         if (power < 0)
2907                                         {
2908                                                 /* Broken */
2909                                                 o_ptr->ident |= (IDENT_BROKEN);
2910
2911                                                 /* Cursed */
2912                                                 o_ptr->curse_flags |= TRC_CURSED;
2913
2914                                                 /* Reverse pval */
2915                                                 o_ptr->pval = 0 - (o_ptr->pval);
2916                                         }
2917
2918                                         break;
2919                                 }
2920
2921                                 /* Flames, Acid, Ice */
2922                                 case SV_RING_FLAMES:
2923                                 case SV_RING_ACID:
2924                                 case SV_RING_ICE:
2925                                 case SV_RING_ELEC:
2926                                 {
2927                                         /* Bonus to armor class */
2928                                         o_ptr->to_a = 5 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2929                                         break;
2930                                 }
2931
2932                                 /* Weakness, Stupidity */
2933                                 case SV_RING_WEAKNESS:
2934                                 case SV_RING_STUPIDITY:
2935                                 {
2936                                         /* Broken */
2937                                         o_ptr->ident |= (IDENT_BROKEN);
2938
2939                                         /* Cursed */
2940                                         o_ptr->curse_flags |= TRC_CURSED;
2941
2942                                         /* Penalize */
2943                                         o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2944                                         if (power > 0) power = 0 - power;
2945
2946                                         break;
2947                                 }
2948
2949                                 /* WOE, Stupidity */
2950                                 case SV_RING_WOE:
2951                                 {
2952                                         /* Broken */
2953                                         o_ptr->ident |= (IDENT_BROKEN);
2954
2955                                         /* Cursed */
2956                                         o_ptr->curse_flags |= TRC_CURSED;
2957
2958                                         /* Penalize */
2959                                         o_ptr->to_a = 0 - (5 + (ARMOUR_CLASS)m_bonus(10, level));
2960                                         o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2961                                         if (power > 0) power = 0 - power;
2962
2963                                         break;
2964                                 }
2965
2966                                 /* Ring of damage */
2967                                 case SV_RING_DAMAGE:
2968                                 {
2969                                         /* Bonus to damage */
2970                                         o_ptr->to_d = 1 + randint1(5) + (HIT_POINT)m_bonus(16, level);
2971
2972                                         /* Cursed */
2973                                         if (power < 0)
2974                                         {
2975                                                 /* Broken */
2976                                                 o_ptr->ident |= (IDENT_BROKEN);
2977
2978                                                 /* Cursed */
2979                                                 o_ptr->curse_flags |= TRC_CURSED;
2980
2981                                                 /* Reverse bonus */
2982                                                 o_ptr->to_d = 0 - o_ptr->to_d;
2983                                         }
2984
2985                                         break;
2986                                 }
2987
2988                                 /* Ring of Accuracy */
2989                                 case SV_RING_ACCURACY:
2990                                 {
2991                                         /* Bonus to hit */
2992                                         o_ptr->to_h = 1 + randint1(5) + (HIT_PROB)m_bonus(16, level);
2993
2994                                         /* Cursed */
2995                                         if (power < 0)
2996                                         {
2997                                                 /* Broken */
2998                                                 o_ptr->ident |= (IDENT_BROKEN);
2999
3000                                                 /* Cursed */
3001                                                 o_ptr->curse_flags |= TRC_CURSED;
3002
3003                                                 /* Reverse tohit */
3004                                                 o_ptr->to_h = 0 - o_ptr->to_h;
3005                                         }
3006
3007                                         break;
3008                                 }
3009
3010                                 /* Ring of Protection */
3011                                 case SV_RING_PROTECTION:
3012                                 {
3013                                         /* Bonus to armor class */
3014                                         o_ptr->to_a = 5 + randint1(8) + (ARMOUR_CLASS)m_bonus(10, level);
3015
3016                                         /* Cursed */
3017                                         if (power < 0)
3018                                         {
3019                                                 /* Broken */
3020                                                 o_ptr->ident |= (IDENT_BROKEN);
3021
3022                                                 /* Cursed */
3023                                                 o_ptr->curse_flags |= TRC_CURSED;
3024
3025                                                 /* Reverse toac */
3026                                                 o_ptr->to_a = 0 - o_ptr->to_a;
3027                                         }
3028
3029                                         break;
3030                                 }
3031
3032                                 /* Ring of Slaying */
3033                                 case SV_RING_SLAYING:
3034                                 {
3035                                         /* Bonus to damage and to hit */
3036                                         o_ptr->to_d = randint1(5) + (HIT_POINT)m_bonus(12, level);
3037                                         o_ptr->to_h = randint1(5) + (HIT_PROB)m_bonus(12, level);
3038
3039                                         /* Cursed */
3040                                         if (power < 0)
3041                                         {
3042                                                 /* Broken */
3043                                                 o_ptr->ident |= (IDENT_BROKEN);
3044
3045                                                 /* Cursed */
3046                                                 o_ptr->curse_flags |= TRC_CURSED;
3047
3048                                                 /* Reverse bonuses */
3049                                                 o_ptr->to_h = 0 - o_ptr->to_h;
3050                                                 o_ptr->to_d = 0 - o_ptr->to_d;
3051                                         }
3052
3053                                         break;
3054                                 }
3055
3056                                 case SV_RING_MUSCLE:
3057                                 {
3058                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(3, level);
3059                                         if (one_in_(4)) o_ptr->pval++;
3060
3061                                         /* Cursed */
3062                                         if (power < 0)
3063                                         {
3064                                                 /* Broken */
3065                                                 o_ptr->ident |= (IDENT_BROKEN);
3066
3067                                                 /* Cursed */
3068                                                 o_ptr->curse_flags |= TRC_CURSED;
3069
3070                                                 /* Reverse bonuses */
3071                                                 o_ptr->pval = 0 - o_ptr->pval;
3072                                         }
3073
3074                                         break;
3075                                 }
3076                                 case SV_RING_AGGRAVATION:
3077                                 {
3078                                         /* Broken */
3079                                         o_ptr->ident |= (IDENT_BROKEN);
3080
3081                                         /* Cursed */
3082                                         o_ptr->curse_flags |= TRC_CURSED;
3083
3084                                         if (power > 0) power = 0 - power;
3085                                         break;
3086                                 }
3087                         }
3088                         if ((one_in_(400) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3089                             || (power > 2)) /* power > 2 is debug only */
3090                         {
3091                                 o_ptr->pval = MIN(o_ptr->pval, 4);
3092                                 /* Randart amulet */
3093                                 create_artifact(o_ptr, FALSE);
3094                         }
3095                         else if ((power == 2) && one_in_(2))
3096                         {
3097                                 while(!o_ptr->name2)
3098                                 {
3099                                         int tmp = m_bonus(10, level);
3100                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3101                                         switch(randint1(28))
3102                                         {
3103                                         case 1: case 2:
3104                                                 o_ptr->name2 = EGO_RING_THROW;
3105                                                 break;
3106                                         case 3: case 4:
3107                                                 if (have_flag(k_ptr->flags, TR_REGEN)) break;
3108                                                 o_ptr->name2 = EGO_RING_REGEN;
3109                                                 break;
3110                                         case 5: case 6:
3111                                                 if (have_flag(k_ptr->flags, TR_LITE_1)) break;
3112                                                 o_ptr->name2 = EGO_RING_LITE;
3113                                                 break;
3114                                         case 7: case 8:
3115                                                 if (have_flag(k_ptr->flags, TR_TELEPORT)) break;
3116                                                 o_ptr->name2 = EGO_RING_TELEPORT;
3117                                                 break;
3118                                         case 9: case 10:
3119                                                 if (o_ptr->to_h) break;
3120                                                 o_ptr->name2 = EGO_RING_TO_H;
3121                                                 break;
3122                                         case 11: case 12:
3123                                                 if (o_ptr->to_d) break;
3124                                                 o_ptr->name2 = EGO_RING_TO_D;
3125                                                 break;
3126                                         case 13:
3127                                                 if ((o_ptr->to_h) || (o_ptr->to_d)) break;
3128                                                 o_ptr->name2 = EGO_RING_SLAY;
3129                                                 break;
3130                                         case 14:
3131                                                 if ((have_flag(k_ptr->flags, TR_STR)) || o_ptr->to_h || o_ptr->to_d) break;
3132                                                 o_ptr->name2 = EGO_RING_WIZARD;
3133                                                 break;
3134                                         case 15:
3135                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3136                                                 o_ptr->name2 = EGO_RING_HERO;
3137                                                 break;
3138                                         case 16:
3139                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3140                                                 if (tmp > 8) o_ptr->name2 = EGO_RING_MANA_BALL;
3141                                                 else if (tmp > 4) o_ptr->name2 = EGO_RING_MANA_BOLT;
3142                                                 else o_ptr->name2 = EGO_RING_MAGIC_MIS;
3143                                                 break;
3144                                         case 17:
3145                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3146                                                 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;
3147                                                 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_F;
3148                                                 else if (tmp > 3) o_ptr->name2 = EGO_RING_FIRE_BALL;
3149                                                 else o_ptr->name2 = EGO_RING_FIRE_BOLT;
3150                                                 break;
3151                                         case 18:
3152                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3153                                                 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;
3154                                                 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_C;
3155                                                 else if (tmp > 3) o_ptr->name2 = EGO_RING_COLD_BALL;
3156                                                 else o_ptr->name2 = EGO_RING_COLD_BOLT;
3157                                                 break;
3158                                         case 19:
3159                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3160                                                 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;
3161                                                 if (tmp > 4) o_ptr->name2 = EGO_RING_ELEC_BALL;
3162                                                 else o_ptr->name2 = EGO_RING_ELEC_BOLT;
3163                                                 break;
3164                                         case 20:
3165                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3166                                                 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;
3167                                                 if (tmp > 4) o_ptr->name2 = EGO_RING_ACID_BALL;
3168                                                 else o_ptr->name2 = EGO_RING_ACID_BOLT;
3169                                                 break;
3170                                         case 21: case 22: case 23: case 24: case 25: case 26:
3171                                                 switch (o_ptr->sval)
3172                                                 {
3173                                                 case SV_RING_SPEED:
3174                                                         if (!one_in_(3)) break;
3175                                                         o_ptr->name2 = EGO_RING_D_SPEED;
3176                                                         break;
3177                                                 case SV_RING_DAMAGE:
3178                                                 case SV_RING_ACCURACY:
3179                                                 case SV_RING_SLAYING:
3180                                                         if (one_in_(2)) break;
3181                                                         if (one_in_(2)) o_ptr->name2 = EGO_RING_HERO;
3182                                                         else
3183                                                         {
3184                                                                 o_ptr->name2 = EGO_RING_BERSERKER;
3185                                                                 o_ptr->to_h -= 2+randint1(4);
3186                                                                 o_ptr->to_d += 2+randint1(4);
3187                                                         }
3188                                                         break;
3189                                                 case SV_RING_PROTECTION:
3190                                                         o_ptr->name2 = EGO_RING_SUPER_AC;
3191                                                         o_ptr->to_a += 7 + m_bonus(5, level);
3192                                                         break;
3193                                                 case SV_RING_RES_FEAR:
3194                                                         o_ptr->name2 = EGO_RING_HERO;
3195                                                         break;
3196                                                 case SV_RING_SHOTS:
3197                                                         if (one_in_(2)) break;
3198                                                         o_ptr->name2 = EGO_RING_HUNTER;
3199                                                         break;
3200                                                 case SV_RING_SEARCHING:
3201                                                         o_ptr->name2 = EGO_RING_STEALTH;
3202                                                         break;
3203                                                 case SV_RING_TELEPORTATION:
3204                                                         o_ptr->name2 = EGO_RING_TELE_AWAY;
3205                                                         break;
3206                                                 case SV_RING_RES_BLINDNESS:
3207                                                         if (one_in_(2))
3208                                                                 o_ptr->name2 = EGO_RING_RES_LITE;
3209                                                         else
3210                                                                 o_ptr->name2 = EGO_RING_RES_DARK;
3211                                                         break;
3212                                                 case SV_RING_LORDLY:
3213                                                         if (!one_in_(20)) break;
3214                                                         one_lordly_high_resistance(o_ptr);
3215                                                         one_lordly_high_resistance(o_ptr);
3216                                                         o_ptr->name2 = EGO_RING_TRUE;
3217                                                         break;
3218                                                 case SV_RING_SUSTAIN:
3219                                                         if (!one_in_(4)) break;
3220                                                         o_ptr->name2 = EGO_RING_RES_TIME;
3221                                                         break;
3222                                                 case SV_RING_FLAMES:
3223                                                         if (!one_in_(2)) break;
3224                                                         o_ptr->name2 = EGO_RING_DRAGON_F;
3225                                                         break;
3226                                                 case SV_RING_ICE:
3227                                                         if (!one_in_(2)) break;
3228                                                         o_ptr->name2 = EGO_RING_DRAGON_C;
3229                                                         break;
3230                                                 case SV_RING_WARNING:
3231                                                         if (!one_in_(2)) break;
3232                                                         o_ptr->name2 = EGO_RING_M_DETECT;
3233                                                         break;
3234                                                 default:
3235                                                         break;
3236                                                 }
3237                                                 break;
3238                                         }
3239                                 }
3240                                 o_ptr->curse_flags = 0L;
3241                         }
3242                         else if ((power == -2) && one_in_(2))
3243                         {
3244                                 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3245                                 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3246                                 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3247                                 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3248                                 o_ptr->art_flags[0] = 0;
3249                                 o_ptr->art_flags[1] = 0;
3250                                 while(!o_ptr->name2)
3251                                 {
3252                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3253                                         switch(randint1(5))
3254                                         {
3255                                         case 1:
3256                                                 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3257                                                 o_ptr->name2 = EGO_RING_DRAIN_EXP;
3258                                                 break;
3259                                         case 2:
3260                                                 o_ptr->name2 = EGO_RING_NO_MELEE;
3261                                                 break;
3262                                         case 3:
3263                                                 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3264                                                 o_ptr->name2 = EGO_RING_AGGRAVATE;
3265                                                 break;
3266                                         case 4:
3267                                                 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3268                                                 o_ptr->name2 = EGO_RING_TY_CURSE;
3269                                                 break;
3270                                         case 5:
3271                                                 o_ptr->name2 = EGO_RING_ALBINO;
3272                                                 break;
3273                                         }
3274                                 }
3275                                 /* Broken */
3276                                 o_ptr->ident |= (IDENT_BROKEN);
3277
3278                                 /* Cursed */
3279                                 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3280                         }
3281                         break;
3282                 }
3283
3284                 case TV_AMULET:
3285                 {
3286                         /* Analyze */
3287                         switch (o_ptr->sval)
3288                         {
3289                                 /* Amulet of wisdom/charisma */
3290                                 case SV_AMULET_INTELLIGENCE:
3291                                 case SV_AMULET_WISDOM:
3292                                 case SV_AMULET_CHARISMA:
3293                                 {
3294                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
3295
3296                                         /* Cursed */
3297                                         if (power < 0)
3298                                         {
3299                                                 /* Broken */
3300                                                 o_ptr->ident |= (IDENT_BROKEN);
3301
3302                                                 /* Cursed */
3303                                                 o_ptr->curse_flags |= (TRC_CURSED);
3304
3305                                                 /* Reverse bonuses */
3306                                                 o_ptr->pval = 0 - o_ptr->pval;
3307                                         }
3308
3309                                         break;
3310                                 }
3311
3312                                 /* Amulet of brilliance */
3313                                 case SV_AMULET_BRILLIANCE:
3314                                 {
3315                                         o_ptr->pval = 1 + m_bonus(3, level);
3316                                         if (one_in_(4)) o_ptr->pval++;
3317
3318                                         /* Cursed */
3319                                         if (power < 0)
3320                                         {
3321                                                 /* Broken */
3322                                                 o_ptr->ident |= (IDENT_BROKEN);
3323
3324                                                 /* Cursed */
3325                                                 o_ptr->curse_flags |= (TRC_CURSED);
3326
3327                                                 /* Reverse bonuses */
3328                                                 o_ptr->pval = 0 - o_ptr->pval;
3329                                         }
3330
3331                                         break;
3332                                 }
3333
3334                                 case SV_AMULET_NO_MAGIC: case SV_AMULET_NO_TELE:
3335                                 {
3336                                         if (power < 0)
3337                                         {
3338                                                 o_ptr->curse_flags |= (TRC_CURSED);
3339                                         }
3340                                         break;
3341                                 }
3342
3343                                 case SV_AMULET_RESISTANCE:
3344                                 {
3345                                         if (one_in_(5)) one_high_resistance(o_ptr);
3346                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_RES_POIS);
3347                                 }
3348                                 break;
3349
3350                                 /* Amulet of searching */
3351                                 case SV_AMULET_SEARCHING:
3352                                 {
3353                                         o_ptr->pval = randint1(2) + (PARAMETER_VALUE)m_bonus(4, level);
3354
3355                                         /* Cursed */
3356                                         if (power < 0)
3357                                         {
3358                                                 /* Broken */
3359                                                 o_ptr->ident |= (IDENT_BROKEN);
3360
3361                                                 /* Cursed */
3362                                                 o_ptr->curse_flags |= (TRC_CURSED);
3363
3364                                                 /* Reverse bonuses */
3365                                                 o_ptr->pval = 0 - (o_ptr->pval);
3366                                         }
3367
3368                                         break;
3369                                 }
3370
3371                                 /* Amulet of the Magi -- never cursed */
3372                                 case SV_AMULET_THE_MAGI:
3373                                 {
3374                                         o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
3375                                         o_ptr->to_a = randint1(5) + (ARMOUR_CLASS)m_bonus(5, level);
3376
3377                                         /* gain one low ESP */
3378                                         add_esp_weak(o_ptr, FALSE);
3379
3380                                         break;
3381                                 }
3382
3383                                 /* Amulet of Doom -- always cursed */
3384                                 case SV_AMULET_DOOM:
3385                                 {
3386                                         /* Broken */
3387                                         o_ptr->ident |= (IDENT_BROKEN);
3388
3389                                         /* Cursed */
3390                                         o_ptr->curse_flags |= (TRC_CURSED);
3391
3392                                         /* Penalize */
3393                                         o_ptr->pval = 0 - (randint1(5) + (PARAMETER_VALUE)m_bonus(5, level));
3394                                         o_ptr->to_a = 0 - (randint1(5) + (ARMOUR_CLASS)m_bonus(5, level));
3395                                         if (power > 0) power = 0 - power;
3396
3397                                         break;
3398                                 }
3399
3400                                 case SV_AMULET_MAGIC_MASTERY:
3401                                 {
3402                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(4, level);
3403
3404                                         /* Cursed */
3405                                         if (power < 0)
3406                                         {
3407                                                 /* Broken */
3408                                                 o_ptr->ident |= (IDENT_BROKEN);
3409
3410                                                 /* Cursed */
3411                                                 o_ptr->curse_flags |= (TRC_CURSED);
3412
3413                                                 /* Reverse bonuses */
3414                                                 o_ptr->pval = 0 - o_ptr->pval;
3415                                         }
3416
3417                                         break;
3418                                 }
3419                         }
3420                         if ((one_in_(150) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3421                             || (power > 2)) /* power > 2 is debug only */
3422                         {
3423                                 o_ptr->pval = MIN(o_ptr->pval, 4);
3424                                 /* Randart amulet */
3425                                 create_artifact(o_ptr, FALSE);
3426                         }
3427                         else if ((power == 2) && one_in_(2))
3428                         {
3429                                 while(!o_ptr->name2)
3430                                 {
3431                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3432                                         switch(randint1(21))
3433                                         {
3434                                         case 1: case 2:
3435                                                 if (have_flag(k_ptr->flags, TR_SLOW_DIGEST)) break;
3436                                                 o_ptr->name2 = EGO_AMU_SLOW_D;
3437                                                 break;
3438                                         case 3: case 4:
3439                                                 if (o_ptr->pval) break;
3440                                                 o_ptr->name2 = EGO_AMU_INFRA;
3441                                                 break;
3442                                         case 5: case 6:
3443                                                 if (have_flag(k_ptr->flags, TR_SEE_INVIS)) break;
3444                                                 o_ptr->name2 = EGO_AMU_SEE_INVIS;
3445                                                 break;
3446                                         case 7: case 8:
3447                                                 if (have_flag(k_ptr->flags, TR_HOLD_EXP)) break;
3448                                                 o_ptr->name2 = EGO_AMU_HOLD_EXP;
3449                                                 break;
3450                                         case 9:
3451                                                 if (have_flag(k_ptr->flags, TR_LEVITATION)) break;
3452                                                 o_ptr->name2 = EGO_AMU_LEVITATION;
3453                                                 break;
3454                                         case 10: case 11: case 21:
3455                                                 o_ptr->name2 = EGO_AMU_AC;
3456                                                 break;
3457                                         case 12:
3458                                                 if (have_flag(k_ptr->flags, TR_RES_FIRE)) break;
3459                                                 if (m_bonus(10, level) > 8)
3460                                                         o_ptr->name2 = EGO_AMU_RES_FIRE_;
3461                                                 else
3462                                                         o_ptr->name2 = EGO_AMU_RES_FIRE;
3463                                                 break;
3464                                         case 13:
3465                                                 if (have_flag(k_ptr->flags, TR_RES_COLD)) break;
3466                                                 if (m_bonus(10, level) > 8)
3467                                                         o_ptr->name2 = EGO_AMU_RES_COLD_;
3468                                                 else
3469                                                         o_ptr->name2 = EGO_AMU_RES_COLD;
3470                                                 break;
3471                                         case 14:
3472                                                 if (have_flag(k_ptr->flags, TR_RES_ELEC)) break;
3473                                                 if (m_bonus(10, level) > 8)
3474                                                         o_ptr->name2 = EGO_AMU_RES_ELEC_;
3475                                                 else
3476                                                         o_ptr->name2 = EGO_AMU_RES_ELEC;
3477                                                 break;
3478                                         case 15:
3479                                                 if (have_flag(k_ptr->flags, TR_RES_ACID)) break;
3480                                                 if (m_bonus(10, level) > 8)
3481                                                         o_ptr->name2 = EGO_AMU_RES_ACID_;
3482                                                 else
3483                                                         o_ptr->name2 = EGO_AMU_RES_ACID;
3484                                                 break;
3485                                         case 16: case 17: case 18: case 19: case 20:
3486                                                 switch (o_ptr->sval)
3487                                                 {
3488                                                 case SV_AMULET_TELEPORT:
3489                                                         if (m_bonus(10, level) > 9) o_ptr->name2 = EGO_AMU_D_DOOR;
3490                                                         else if (one_in_(2)) o_ptr->name2 = EGO_AMU_JUMP;
3491                                                         else o_ptr->name2 = EGO_AMU_TELEPORT;
3492                                                         break;
3493                                                 case SV_AMULET_RESIST_ACID:
3494                                                         if ((m_bonus(10, level) > 6) && one_in_(2)) o_ptr->name2 = EGO_AMU_RES_ACID_;
3495                                                         break;
3496                                                 case SV_AMULET_SEARCHING:
3497                                                         o_ptr->name2 = EGO_AMU_STEALTH;
3498                                                         break;
3499                                                 case SV_AMULET_BRILLIANCE:
3500                                                         if (!one_in_(3)) break;
3501                                                         o_ptr->name2 = EGO_AMU_IDENT;
3502                                                         break;
3503                                                 case SV_AMULET_CHARISMA:
3504                                                         if (!one_in_(3)) break;
3505                                                         o_ptr->name2 = EGO_AMU_CHARM;
3506                                                         break;
3507                                                 case SV_AMULET_THE_MAGI:
3508                                                         if (one_in_(2)) break;
3509                                                         o_ptr->name2 = EGO_AMU_GREAT;
3510                                                         break;
3511                                                 case SV_AMULET_RESISTANCE:
3512                                                         if (!one_in_(5)) break;
3513                                                         o_ptr->name2 = EGO_AMU_DEFENDER;
3514                                                         break;
3515                                                 case SV_AMULET_TELEPATHY:
3516                                                         if (!one_in_(3)) break;
3517                                                         o_ptr->name2 = EGO_AMU_DETECTION;
3518                                                         break;
3519                                                 }
3520                                         }
3521                                 }
3522                                 o_ptr->curse_flags = 0L;
3523                         }
3524                         else if ((power == -2) && one_in_(2))
3525                         {
3526                                 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3527                                 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3528                                 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3529                                 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3530                                 o_ptr->art_flags[0] = 0;
3531                                 o_ptr->art_flags[1] = 0;
3532                                 while(!o_ptr->name2)
3533                                 {
3534                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3535                                         switch(randint1(5))
3536                                         {
3537                                         case 1:
3538                                                 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3539                                                 o_ptr->name2 = EGO_AMU_DRAIN_EXP;
3540                                                 break;
3541                                         case 2:
3542                                                 o_ptr->name2 = EGO_AMU_FOOL;
3543                                                 break;
3544                                         case 3:
3545                                                 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3546                                                 o_ptr->name2 = EGO_AMU_AGGRAVATE;
3547                                                 break;
3548                                         case 4:
3549                                                 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3550                                                 o_ptr->name2 = EGO_AMU_TY_CURSE;
3551                                                 break;
3552                                         case 5:
3553                                                 o_ptr->name2 = EGO_AMU_NAIVETY;
3554                                                 break;
3555                                         }
3556                                 }
3557                                 /* Broken */
3558                                 o_ptr->ident |= (IDENT_BROKEN);
3559
3560                                 /* Cursed */
3561                                 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3562                         }
3563                         break;
3564                 }
3565         }
3566 }
3567
3568
3569 /*!
3570  * @brief その他雑多のオブジェクトに生成ランクごとの強化を与えるサブルーチン
3571  * Apply magic to an item known to be "boring"
3572  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3573  * @param level 生成基準階
3574  * @param power 生成ランク
3575  * @return なし
3576  * @details
3577  * Hack -- note the special code for various items
3578  */
3579 static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
3580 {
3581         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3582
3583         /* Unused */
3584         (void)level;
3585
3586         /* Apply magic (good or bad) according to type */
3587         switch (o_ptr->tval)
3588         {
3589                 case TV_WHISTLE:
3590                 {
3591 #if 0
3592                         /* Cursed */
3593                         if (power < 0)
3594                         {
3595                                 /* Broken */
3596                                 o_ptr->ident |= (IDENT_BROKEN);
3597
3598                                 /* Cursed */
3599                                 o_ptr->curse_flags |= (TRC_CURSED);
3600                         }
3601 #endif
3602                         break;
3603                 }
3604                 case TV_FLASK:
3605                 {
3606                         o_ptr->xtra4 = o_ptr->pval;
3607                         o_ptr->pval = 0;
3608                         break;
3609                 }
3610                 case TV_LITE:
3611                 {
3612                         /* Hack -- Torches -- random fuel */
3613                         if (o_ptr->sval == SV_LITE_TORCH)
3614                         {
3615                                 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3616                                 o_ptr->pval = 0;
3617                         }
3618
3619                         /* Hack -- Lanterns -- random fuel */
3620                         if (o_ptr->sval == SV_LITE_LANTERN)
3621                         {
3622                                 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3623                                 o_ptr->pval = 0;
3624                         }
3625
3626                         if (power > 2) /* power > 2 is debug only */
3627                         {
3628                                 create_artifact(o_ptr, FALSE);
3629                         }
3630                         else if ((power == 2) || ((power == 1) && one_in_(3)))
3631                         {
3632                                 while (!o_ptr->name2)
3633                                 {
3634                                         while (1)
3635                                         {
3636                                                 bool okay_flag = TRUE;
3637
3638                                                 o_ptr->name2 = get_random_ego(INVEN_LITE, TRUE);
3639
3640                                                 switch (o_ptr->name2)
3641                                                 {
3642                                                 case EGO_LITE_LONG:
3643                                                         if (o_ptr->sval == SV_LITE_FEANOR)
3644                                                                 okay_flag = FALSE;
3645                                                 }
3646                                                 if (okay_flag)
3647                                                         break;
3648                                         }
3649                                 }
3650                         }
3651                         else if (power == -2)
3652                         {
3653                                 o_ptr->name2 = get_random_ego(INVEN_LITE, FALSE);
3654
3655                                 switch (o_ptr->name2)
3656                                 {
3657                                 case EGO_LITE_DARKNESS:
3658                                         o_ptr->xtra4 = 0;
3659                                         
3660                                         if (o_ptr->sval == SV_LITE_TORCH)
3661                                         {
3662                                                 add_flag(o_ptr->art_flags, TR_LITE_M1);
3663                                         }
3664                                         else if (o_ptr->sval == SV_LITE_LANTERN)
3665                                         {
3666                                                 add_flag(o_ptr->art_flags, TR_LITE_M2);
3667                                         }
3668                                         else if (o_ptr->sval == SV_LITE_FEANOR)
3669                                         {
3670                                                 add_flag(o_ptr->art_flags, TR_LITE_M3);
3671                                         }
3672                                         break;
3673                                 }
3674                         }
3675
3676                         break;
3677                 }
3678
3679                 case TV_WAND:
3680                 case TV_STAFF:
3681                 {
3682                         /* The wand or staff gets a number of initial charges equal
3683                          * to between 1/2 (+1) and the full object kind's pval. -LM-
3684                          */
3685                         o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
3686                         break;
3687                 }
3688
3689                 case TV_ROD:
3690                 {
3691                         /* Transfer the pval. -LM- */
3692                         o_ptr->pval = k_ptr->pval;
3693                         break;
3694                 }
3695
3696                 case TV_CAPTURE:
3697                 {
3698                         o_ptr->pval = 0;
3699                         object_aware(o_ptr);
3700                         object_known(o_ptr);
3701                         break;
3702                 }
3703
3704                 case TV_FIGURINE:
3705                 {
3706                         PARAMETER_VALUE i = 1;
3707                         int check;
3708
3709                         monster_race *r_ptr;
3710
3711                         /* Pick a random non-unique monster race */
3712                         while (1)
3713                         {
3714                                 i = randint1(max_r_idx - 1);
3715
3716                                 if (!item_monster_okay(i)) continue;
3717                                 if (i == MON_TSUCHINOKO) continue;
3718
3719                                 r_ptr = &r_info[i];
3720
3721                                 check = (current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - current_floor_ptr->dun_level) : 0;
3722
3723                                 /* Ignore dead monsters */
3724                                 if (!r_ptr->rarity) continue;
3725
3726                                 /* Ignore uncommon monsters */
3727                                 if (r_ptr->rarity > 100) continue;
3728
3729                                 /* Prefer less out-of-depth monsters */
3730                                 if (randint0(check)) continue;
3731
3732                                 break;
3733                         }
3734
3735                         o_ptr->pval = i;
3736
3737                         /* Some figurines are cursed */
3738                         if (one_in_(6)) o_ptr->curse_flags |= TRC_CURSED;
3739
3740                         break;
3741                 }
3742
3743                 case TV_CORPSE:
3744                 {
3745                         PARAMETER_VALUE i = 1;
3746                         int check;
3747
3748                         u32b match = 0;
3749
3750                         monster_race *r_ptr;
3751
3752                         if (o_ptr->sval == SV_SKELETON)
3753                         {
3754                                 match = RF9_DROP_SKELETON;
3755                         }
3756                         else if (o_ptr->sval == SV_CORPSE)
3757                         {
3758                                 match = RF9_DROP_CORPSE;
3759                         }
3760
3761                         /* Hack -- Remove the monster restriction */
3762                         get_mon_num_prep(item_monster_okay, NULL);
3763
3764                         /* Pick a random non-unique monster race */
3765                         while (1)
3766                         {
3767                                 i = get_mon_num(current_floor_ptr->dun_level);
3768
3769                                 r_ptr = &r_info[i];
3770
3771                                 check = (current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - current_floor_ptr->dun_level) : 0;
3772
3773                                 /* Ignore dead monsters */
3774                                 if (!r_ptr->rarity) continue;
3775
3776                                 /* Ignore corpseless monsters */
3777                                 if (!(r_ptr->flags9 & match)) continue;
3778
3779                                 /* Prefer less out-of-depth monsters */
3780                                 if (randint0(check)) continue;
3781
3782                                 break;
3783                         }
3784
3785                         o_ptr->pval = i;
3786
3787
3788                         object_aware(o_ptr);
3789                         object_known(o_ptr);
3790                         break;
3791                 }
3792
3793                 case TV_STATUE:
3794                 {
3795                         PARAMETER_VALUE i = 1;
3796
3797                         monster_race *r_ptr;
3798
3799                         /* Pick a random monster race */
3800                         while (1)
3801                         {
3802                                 i = randint1(max_r_idx - 1);
3803
3804                                 r_ptr = &r_info[i];
3805
3806                                 /* Ignore dead monsters */
3807                                 if (!r_ptr->rarity) continue;
3808
3809                                 break;
3810                         }
3811
3812                         o_ptr->pval = i;
3813
3814                         if (cheat_peek)
3815                         {
3816                                 msg_format(_("%sの像", "Statue of %s"), r_name + r_ptr->name);
3817                         }
3818                         object_aware(o_ptr);
3819                         object_known(o_ptr);
3820
3821                         break;
3822                 }
3823
3824                 case TV_CHEST:
3825                 {
3826                         DEPTH obj_level = k_info[o_ptr->k_idx].level;
3827
3828                         /* Hack -- skip ruined chests */
3829                         if (obj_level <= 0) break;
3830
3831                         /* Hack -- pick a "difficulty" */
3832                         o_ptr->pval = randint1(obj_level);
3833                         if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
3834
3835                         o_ptr->xtra3 = current_floor_ptr->dun_level + 5;
3836
3837                         /* Never exceed "difficulty" of 55 to 59 */
3838                         if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
3839
3840                         break;
3841                 }
3842         }
3843 }
3844
3845 /*!
3846  * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
3847  * Complete the "creation" of an object by applying "magic" to the item
3848  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3849  * @param lev 生成基準階
3850  * @param mode 生成オプション
3851  * @return なし
3852  * @details
3853  * This includes not only rolling for random bonuses, but also putting the\n
3854  * finishing touches on ego-items and artifacts, giving charges to wands and\n
3855  * staffs, giving fuel to lites, and placing traps on chests.\n
3856  *\n
3857  * In particular, note that "Instant Artifacts", if "created" by an external\n
3858  * routine, must pass through this function to complete the actual creation.\n
3859  *\n
3860  * The base "chance" of the item being "good" increases with the "level"\n
3861  * parameter, which is usually derived from the dungeon level, being equal\n
3862  * to the level plus 10, up to a maximum of 75.  If "good" is true, then\n
3863  * the object is guaranteed to be "good".  If an object is "good", then\n
3864  * the chance that the object will be "great" (ego-item or artifact), also\n
3865  * increases with the "level", being equal to half the level, plus 5, up to\n
3866  * a maximum of 20.  If "great" is true, then the object is guaranteed to be\n
3867  * "great".  At dungeon level 65 and below, 15/100 objects are "great".\n
3868  *\n
3869  * If the object is not "good", there is a chance it will be "cursed", and\n
3870  * if it is "cursed", there is a chance it will be "broken".  These chances\n
3871  * are related to the "good" / "great" chances above.\n
3872  *\n
3873  * Otherwise "normal" rings and amulets will be "good" half the time and\n
3874  * "cursed" half the time, unless the ring/amulet is always good or cursed.\n
3875  *\n
3876  * If "okay" is true, and the object is going to be "great", then there is\n
3877  * a chance that an artifact will be created.  This is true even if both the\n
3878  * "good" and "great" arguments are false.  As a total hack, if "great" is\n
3879  * true, then the item gets 3 extra "attempts" to become an artifact.\n
3880  */
3881 void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
3882 {
3883         int i, rolls, f1, f2, power;
3884
3885         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) lev += randint0(p_ptr->lev/2+10);
3886
3887         /* Maximum "level" for various things */
3888         if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1;
3889
3890         /* Base chance of being "good" */
3891         f1 = lev + 10;
3892
3893         /* Maximal chance of being "good" */
3894         if (f1 > d_info[p_ptr->dungeon_idx].obj_good) f1 = d_info[p_ptr->dungeon_idx].obj_good;
3895
3896         /* Base chance of being "great" */
3897         f2 = f1 * 2 / 3;
3898
3899         /* Maximal chance of being "great" */
3900         if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[p_ptr->dungeon_idx].obj_great))
3901                 f2 = d_info[p_ptr->dungeon_idx].obj_great;
3902
3903         if (p_ptr->muta3 & MUT3_GOOD_LUCK)
3904         {
3905                 f1 += 5;
3906                 f2 += 2;
3907         }
3908         else if(p_ptr->muta3 & MUT3_BAD_LUCK)
3909         {
3910                 f1 -= 5;
3911                 f2 -= 2;
3912         }
3913
3914         /* Assume normal */
3915         power = 0;
3916
3917         /* Roll for "good" */
3918         if ((mode & AM_GOOD) || magik(f1))
3919         {
3920                 /* Assume "good" */
3921                 power = 1;
3922
3923                 /* Roll for "great" */
3924                 if ((mode & AM_GREAT) || magik(f2))
3925                 {
3926                         power = 2;
3927
3928                         /* Roll for "special" */
3929                         if (mode & AM_SPECIAL) power = 3;
3930                 }
3931         }
3932
3933         /* Roll for "cursed" */
3934         else if (magik(f1))
3935         {
3936                 /* Assume "cursed" */
3937                 power = -1;
3938
3939                 /* Roll for "broken" */
3940                 if (magik(f2)) power = -2;
3941         }
3942
3943         /* Apply curse */
3944         if (mode & AM_CURSED)
3945         {
3946                 /* Assume 'cursed' */
3947                 if (power > 0)
3948                 {
3949                         power = 0 - power;
3950                 }
3951                 /* Everything else gets more badly cursed */
3952                 else
3953                 {
3954                         power--;
3955                 }
3956         }
3957
3958         /* Assume no rolls */
3959         rolls = 0;
3960
3961         /* Get one roll if excellent */
3962         if (power >= 2) rolls = 1;
3963
3964         /* Hack -- Get four rolls if forced great or special */
3965         if (mode & (AM_GREAT | AM_SPECIAL)) rolls = 4;
3966
3967         /* Hack -- Get no rolls if not allowed */
3968         if ((mode & AM_NO_FIXED_ART) || o_ptr->name1) rolls = 0;
3969
3970         /* Roll for artifacts if allowed */
3971         for (i = 0; i < rolls; i++)
3972         {
3973                 /* Roll for an artifact */
3974                 if (make_artifact(o_ptr)) break;
3975                 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77))
3976                 {
3977                         if (make_artifact(o_ptr)) break;
3978                 }
3979         }
3980
3981
3982         /* Hack -- analyze artifacts */
3983         if (object_is_fixed_artifact(o_ptr))
3984         {
3985                 artifact_type *a_ptr = &a_info[o_ptr->name1];
3986
3987                 /* Hack -- Mark the artifact as "created" */
3988                 a_ptr->cur_num = 1;
3989
3990                 /* Hack -- Memorize location of artifact in saved floors */
3991                 if (character_dungeon)
3992                         a_ptr->floor_id = p_ptr->floor_id;
3993
3994                 /* Extract the other fields */
3995                 o_ptr->pval = a_ptr->pval;
3996                 o_ptr->ac = a_ptr->ac;
3997                 o_ptr->dd = a_ptr->dd;
3998                 o_ptr->ds = a_ptr->ds;
3999                 o_ptr->to_a = a_ptr->to_a;
4000                 o_ptr->to_h = a_ptr->to_h;
4001                 o_ptr->to_d = a_ptr->to_d;
4002                 o_ptr->weight = a_ptr->weight;
4003                 o_ptr->xtra2 = a_ptr->act_idx;
4004
4005                 if (o_ptr->name1 == ART_MILIM)
4006                 {
4007                     if(p_ptr->pseikaku == SEIKAKU_SEXY)
4008                     {
4009                         o_ptr->pval = 3;
4010                     }
4011                 }
4012
4013                 /* Hack -- extract the "broken" flag */
4014                 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4015
4016                 /* Hack -- extract the "cursed" flag */
4017                 if (a_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4018                 if (a_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4019                 if (a_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4020                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4021                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4022                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4023
4024                 return;
4025         }
4026
4027         switch (o_ptr->tval)
4028         {
4029                 case TV_DIGGING:
4030                 case TV_HAFTED:
4031                 case TV_BOW:
4032                 case TV_SHOT:
4033                 case TV_ARROW:
4034                 case TV_BOLT:
4035                 {
4036                         if (power) apply_magic_weapon(o_ptr, lev, power);
4037                         break;
4038                 }
4039
4040                 case TV_POLEARM:
4041                 {
4042                         if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) apply_magic_weapon(o_ptr, lev, power);
4043                         break;
4044                 }
4045
4046                 case TV_SWORD:
4047                 {
4048                         if (power && !(o_ptr->sval == SV_DOKUBARI)) apply_magic_weapon(o_ptr, lev, power);
4049                         break;
4050                 }
4051
4052                 case TV_DRAG_ARMOR:
4053                 case TV_HARD_ARMOR:
4054                 case TV_SOFT_ARMOR:
4055                 case TV_SHIELD:
4056                 case TV_HELM:
4057                 case TV_CROWN:
4058                 case TV_CLOAK:
4059                 case TV_GLOVES:
4060                 case TV_BOOTS:
4061                 {
4062                         /* Elven Cloak and Black Clothes ... */
4063                         if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) ||
4064                             ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
4065                                 o_ptr->pval = randint1(4);
4066
4067 #if 1
4068                         if (power ||
4069                              ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) ||
4070                              ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD)) ||
4071                              ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)) ||
4072                              ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
4073                                 a_m_aux_2(o_ptr, lev, power);
4074 #else
4075                         if (power) a_m_aux_2(o_ptr, lev, power);
4076 #endif
4077                         break;
4078                 }
4079
4080                 case TV_RING:
4081                 case TV_AMULET:
4082                 {
4083                         if (!power && (randint0(100) < 50)) power = -1;
4084                         a_m_aux_3(o_ptr, lev, power);
4085                         break;
4086                 }
4087
4088                 default:
4089                 {
4090                         a_m_aux_4(o_ptr, lev, power);
4091                         break;
4092                 }
4093         }
4094
4095         if ((o_ptr->tval == TV_SOFT_ARMOR) &&
4096             (o_ptr->sval == SV_ABUNAI_MIZUGI) &&
4097             (p_ptr->pseikaku == SEIKAKU_SEXY))
4098         {
4099                 o_ptr->pval = 3;
4100                 add_flag(o_ptr->art_flags, TR_STR);
4101                 add_flag(o_ptr->art_flags, TR_INT);
4102                 add_flag(o_ptr->art_flags, TR_WIS);
4103                 add_flag(o_ptr->art_flags, TR_DEX);
4104                 add_flag(o_ptr->art_flags, TR_CON);
4105                 add_flag(o_ptr->art_flags, TR_CHR);
4106         }
4107
4108         /* Hack -- analyze ego-items */
4109         if (object_is_ego(o_ptr))
4110         {
4111                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
4112
4113                 /* Hack -- acquire "broken" flag */
4114                 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4115
4116                 /* Hack -- acquire "cursed" flag */
4117                 if (e_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4118                 if (e_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4119                 if (e_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4120                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4121                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4122                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4123
4124                 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN)) one_sustain(o_ptr);
4125                 if (e_ptr->gen_flags & (TRG_XTRA_POWER)) one_ability(o_ptr);
4126                 if (e_ptr->gen_flags & (TRG_XTRA_H_RES)) one_high_resistance(o_ptr);
4127                 if (e_ptr->gen_flags & (TRG_XTRA_E_RES)) one_ele_resistance(o_ptr);
4128                 if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
4129                 if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
4130                 if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
4131                 if (e_ptr->gen_flags & (TRG_XTRA_DICE))
4132                 {
4133                         do
4134                         {
4135                                 o_ptr->dd++;
4136                         }
4137                         while (one_in_(o_ptr->dd));
4138
4139                         if (o_ptr->dd > 9) o_ptr->dd = 9;
4140                 }
4141
4142                 /* Hack -- apply activatin index if needed */
4143                 if (e_ptr->act_idx) o_ptr->xtra2 = (XTRA8)e_ptr->act_idx;
4144
4145                 /* Hack -- apply extra penalties if needed */
4146                 if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL)))
4147                 {
4148                         /* Hack -- obtain bonuses */
4149                         if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
4150                         if (e_ptr->max_to_d) o_ptr->to_d -= randint1(e_ptr->max_to_d);
4151                         if (e_ptr->max_to_a) o_ptr->to_a -= randint1(e_ptr->max_to_a);
4152
4153                         /* Hack -- obtain pval */
4154                         if (e_ptr->max_pval) o_ptr->pval -= randint1(e_ptr->max_pval);
4155                 }
4156
4157                 /* Hack -- apply extra bonuses if needed */
4158                 else
4159                 {
4160                         /* Hack -- obtain bonuses */
4161                         if (e_ptr->max_to_h)
4162                         {
4163                                 if (e_ptr->max_to_h > 127)
4164                                         o_ptr->to_h -= randint1(256-e_ptr->max_to_h);
4165                                 else o_ptr->to_h += randint1(e_ptr->max_to_h);
4166                         }
4167                         if (e_ptr->max_to_d)
4168                         {
4169                                 if (e_ptr->max_to_d > 127)
4170                                         o_ptr->to_d -= randint1(256-e_ptr->max_to_d);
4171                                 else o_ptr->to_d += randint1(e_ptr->max_to_d);
4172                         }
4173                         if (e_ptr->max_to_a)
4174                         {
4175                                 if (e_ptr->max_to_a > 127)
4176                                         o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
4177                                 else o_ptr->to_a += randint1(e_ptr->max_to_a);
4178                         }
4179                         
4180                         /* Accuracy ego must have high to_h */
4181                         if(o_ptr->name2 == EGO_ACCURACY)
4182                         {
4183                                 while(o_ptr->to_h < o_ptr->to_d + 10)
4184                                 {
4185                                         o_ptr->to_h += 5;
4186                                         o_ptr->to_d -= 5;
4187                                 }
4188                                 o_ptr->to_h = MAX(o_ptr->to_h, 15);
4189                         }
4190                         
4191                         /* Accuracy ego must have high to_h */
4192                         if(o_ptr->name2 == EGO_VELOCITY)
4193                         {
4194                                 while(o_ptr->to_d < o_ptr->to_h + 10)
4195                                 {
4196                                         o_ptr->to_d += 5;
4197                                         o_ptr->to_h -= 5;
4198                                 }
4199                                 o_ptr->to_d = MAX(o_ptr->to_d, 15);
4200                         }
4201                         
4202                         /* Protection ego must have high to_a */
4203                         if((o_ptr->name2 == EGO_PROTECTION) || (o_ptr->name2 == EGO_S_PROTECTION) || (o_ptr->name2 == EGO_H_PROTECTION))
4204                         {
4205                                 o_ptr->to_a = MAX(o_ptr->to_a, 15);
4206                         }
4207
4208                         /* Hack -- obtain pval */
4209                         if (e_ptr->max_pval)
4210                         {
4211                                 if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS)))
4212                                 {
4213                                         o_ptr->pval++;
4214                                         if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
4215                                 }
4216                                 else if (o_ptr->name2 == EGO_DEMON)
4217                                 {
4218                                         if(have_flag(o_ptr->art_flags, TR_BLOWS))
4219                                         {
4220                                                 o_ptr->pval += randint1(2);
4221                                         }
4222                                         else
4223                                         {
4224                                                 o_ptr->pval += randint1(e_ptr->max_pval);
4225                                         }
4226                                 }
4227                                 else if (o_ptr->name2 == EGO_ATTACKS)
4228                                 {
4229                                         o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
4230                                         if (o_ptr->pval > 3) o_ptr->pval = 3;
4231                                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
4232                                                 o_ptr->pval += randint1(2);
4233                                 }
4234                                 else if (o_ptr->name2 == EGO_BAT)
4235                                 {
4236                                         o_ptr->pval = randint1(e_ptr->max_pval);
4237                                         if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
4238                                 }
4239                                 else if (o_ptr->name2 == EGO_A_DEMON || o_ptr->name2 == EGO_DRUID || o_ptr->name2 == EGO_OLOG)
4240                                 {
4241                                         o_ptr->pval = randint1(e_ptr->max_pval);
4242                                 }
4243                                 else
4244                                 {
4245                                         o_ptr->pval += randint1(e_ptr->max_pval);
4246                                 }
4247                                 
4248                                 
4249                         }
4250                         if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
4251                         {
4252                                 o_ptr->pval = randint1(o_ptr->pval);
4253                         }
4254                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
4255                                 o_ptr->pval = 2;
4256                 }
4257                 
4258                 return;
4259         }
4260
4261         /* Examine real objects */
4262         if (o_ptr->k_idx)
4263         {
4264                 object_kind *k_ptr = &k_info[o_ptr->k_idx];
4265
4266                 /* Hack -- acquire "broken" flag */
4267                 if (!k_info[o_ptr->k_idx].cost) o_ptr->ident |= (IDENT_BROKEN);
4268
4269                 /* Hack -- acquire "cursed" flag */
4270                 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
4271                 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
4272                 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
4273                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4274                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4275                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4276         }
4277
4278         
4279 }
4280
4281
4282 /*!
4283  * @brief 生成階に応じたベースアイテムの生成を行う。
4284  * Attempt to make an object (normal or good/great)
4285  * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4286  * @param mode オプションフラグ
4287  * @return 生成に成功したらTRUEを返す。
4288  * @details
4289  * This routine plays nasty games to generate the "special artifacts".\n
4290  * This routine uses "current_floor_ptr->object_level" for the "generation level".\n
4291  * We assume that the given object has been "wiped".\n
4292  */
4293 bool make_object(object_type *j_ptr, BIT_FLAGS mode)
4294 {
4295         PERCENTAGE prob;
4296         DEPTH base;
4297
4298
4299         /* Chance of "special object" */
4300         prob = ((mode & AM_GOOD) ? 10 : 1000);
4301
4302         /* Base level for the object */
4303         base = ((mode & AM_GOOD) ? (current_floor_ptr->object_level + 10) : current_floor_ptr->object_level);
4304
4305
4306         /* Generate a special object, or a normal object */
4307         if (!one_in_(prob) || !make_artifact_special(j_ptr))
4308         {
4309                 KIND_OBJECT_IDX k_idx;
4310
4311                 /* Good objects */
4312                 if ((mode & AM_GOOD) && !get_obj_num_hook)
4313                 {
4314                         /* Activate restriction (if already specified, use that) */
4315                         get_obj_num_hook = kind_is_good;
4316                 }
4317
4318                 /* Restricted objects - prepare allocation table */
4319                 if (get_obj_num_hook) get_obj_num_prep();
4320
4321                 /* Pick a random object */
4322                 k_idx = get_obj_num(base);
4323
4324                 /* Restricted objects */
4325                 if (get_obj_num_hook)
4326                 {
4327                         /* Clear restriction */
4328                         get_obj_num_hook = NULL;
4329
4330                         /* Reset allocation table to default */
4331                         get_obj_num_prep();
4332                 }
4333
4334                 /* Handle failure */
4335                 if (!k_idx) return (FALSE);
4336
4337                 /* Prepare the object */
4338                 object_prep(j_ptr, k_idx);
4339         }
4340
4341         /* Apply magic (allow artifacts) */
4342         apply_magic(j_ptr, current_floor_ptr->object_level, mode);
4343
4344         /* Hack -- generate multiple spikes/missiles */
4345         switch (j_ptr->tval)
4346         {
4347                 case TV_SPIKE:
4348                 case TV_SHOT:
4349                 case TV_ARROW:
4350                 case TV_BOLT:
4351                 {
4352                         if (!j_ptr->name1)
4353                                 j_ptr->number = (byte)damroll(6, 7);
4354                 }
4355         }
4356
4357         if (cheat_peek) object_mention(j_ptr);
4358
4359         /* Success */
4360         return (TRUE);
4361 }
4362
4363
4364 /*!
4365  * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
4366  * Attempt to place an object (normal or good/great) at the given location.
4367  * @param y 配置したいフロアのY座標
4368  * @param x 配置したいフロアのX座標
4369  * @param mode オプションフラグ
4370  * @return 生成に成功したらTRUEを返す。
4371  * @details
4372  * This routine plays nasty games to generate the "special artifacts".\n
4373  * This routine uses "current_floor_ptr->object_level" for the "generation level".\n
4374  * This routine requires a clean floor grid destination.\n
4375  */
4376 void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
4377 {
4378         OBJECT_IDX o_idx;
4379
4380         /* Acquire grid */
4381         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
4382
4383         object_type forge;
4384         object_type *q_ptr;
4385
4386
4387         /* Paranoia -- check bounds */
4388         if (!in_bounds(y, x)) return;
4389
4390         /* Require floor space */
4391         if (!cave_drop_bold(y, x)) return;
4392
4393         /* Avoid stacking on other objects */
4394         if (g_ptr->o_idx) return;
4395
4396         q_ptr = &forge;
4397         object_wipe(q_ptr);
4398
4399         /* Make an object (if possible) */
4400         if (!make_object(q_ptr, mode)) return;
4401
4402
4403         /* Make an object */
4404         o_idx = o_pop();
4405
4406         /* Success */
4407         if (o_idx)
4408         {
4409                 object_type *o_ptr;
4410                 o_ptr = &current_floor_ptr->o_list[o_idx];
4411
4412                 /* Structure Copy */
4413                 object_copy(o_ptr, q_ptr);
4414
4415                 o_ptr->iy = y;
4416                 o_ptr->ix = x;
4417
4418                 /* Build a stack */
4419                 o_ptr->next_o_idx = g_ptr->o_idx;
4420
4421                 g_ptr->o_idx = o_idx;
4422                 note_spot(y, x);
4423                 lite_spot(y, x);
4424         }
4425         else
4426         {
4427                 /* Hack -- Preserve artifacts */
4428                 if (object_is_fixed_artifact(q_ptr))
4429                 {
4430                         a_info[q_ptr->name1].cur_num = 0;
4431                 }
4432         }
4433 }
4434
4435
4436 /*!
4437  * @brief 生成階に応じた財宝オブジェクトの生成を行う。
4438  * Make a treasure object
4439  * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4440  * @return 生成に成功したらTRUEを返す。
4441  * @details
4442  * The location must be a legal, clean, floor grid.
4443  */
4444 bool make_gold(object_type *j_ptr)
4445 {
4446         int i;
4447         s32b base;
4448
4449         /* Hack -- Pick a Treasure variety */
4450         i = ((randint1(current_floor_ptr->object_level + 2) + 2) / 2) - 1;
4451
4452         /* Apply "extra" magic */
4453         if (one_in_(GREAT_OBJ))
4454         {
4455                 i += randint1(current_floor_ptr->object_level + 1);
4456         }
4457
4458         /* Hack -- Creeping Coins only generate "themselves" */
4459         if (coin_type) i = coin_type;
4460
4461         /* Do not create "illegal" Treasure Types */
4462         if (i >= MAX_GOLD) i = MAX_GOLD - 1;
4463
4464         /* Prepare a gold object */
4465         object_prep(j_ptr, OBJ_GOLD_LIST + i);
4466
4467         /* Hack -- Base coin cost */
4468         base = k_info[OBJ_GOLD_LIST + i].cost;
4469
4470         /* Determine how much the treasure is "worth" */
4471         j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
4472
4473         /* Success */
4474         return (TRUE);
4475 }
4476
4477
4478 /*!
4479  * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
4480  * Places a treasure (Gold or Gems) at given location
4481  * @param y 配置したいフロアのY座標
4482  * @param x 配置したいフロアのX座標
4483  * @return 生成に成功したらTRUEを返す。
4484  * @details
4485  * The location must be a legal, clean, floor grid.
4486  */
4487 void place_gold(POSITION y, POSITION x)
4488 {
4489         OBJECT_IDX o_idx;
4490
4491         /* Acquire grid */
4492         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
4493
4494         object_type forge;
4495         object_type *q_ptr;
4496
4497
4498         /* Paranoia -- check bounds */
4499         if (!in_bounds(y, x)) return;
4500
4501         /* Require floor space */
4502         if (!cave_drop_bold(y, x)) return;
4503
4504         /* Avoid stacking on other objects */
4505         if (g_ptr->o_idx) return;
4506
4507         q_ptr = &forge;
4508         object_wipe(q_ptr);
4509
4510         /* Make some gold */
4511         if (!make_gold(q_ptr)) return;
4512
4513         /* Make an object */
4514         o_idx = o_pop();
4515
4516         /* Success */
4517         if (o_idx)
4518         {
4519                 object_type *o_ptr;
4520                 o_ptr = &current_floor_ptr->o_list[o_idx];
4521
4522                 /* Copy the object */
4523                 object_copy(o_ptr, q_ptr);
4524
4525                 /* Save location */
4526                 o_ptr->iy = y;
4527                 o_ptr->ix = x;
4528
4529                 /* Build a stack */
4530                 o_ptr->next_o_idx = g_ptr->o_idx;
4531
4532                 g_ptr->o_idx = o_idx;
4533                 note_spot(y, x);
4534                 lite_spot(y, x);
4535         }
4536 }
4537
4538
4539 /*!
4540  * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
4541  * Let an object fall to the ground at or near a location.
4542  * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
4543  * @param chance ドロップの成功率(%)
4544  * @param y 配置したいフロアのY座標
4545  * @param x 配置したいフロアのX座標
4546  * @return 生成に成功したらオブジェクトのIDを返す。
4547  * @details
4548  * The initial location is assumed to be "in_bounds()".\n
4549  *\n
4550  * This function takes a parameter "chance".  This is the percentage\n
4551  * chance that the item will "disappear" instead of drop.  If the object\n
4552  * has been thrown, then this is the chance of disappearance on contact.\n
4553  *\n
4554  * Hack -- this function uses "chance" to determine if it should produce\n
4555  * some form of "description" of the drop event (under the player).\n
4556  *\n
4557  * We check several locations to see if we can find a location at which\n
4558  * the object can combine, stack, or be placed.  Artifacts will try very\n
4559  * hard to be placed, including "teleporting" to a useful grid if needed.\n
4560  */
4561 OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
4562 {
4563         int i, k, d, s;
4564
4565         int bs, bn;
4566         POSITION by, bx;
4567         POSITION dy, dx;
4568         POSITION ty, tx = 0;
4569
4570         OBJECT_IDX o_idx = 0;
4571         OBJECT_IDX this_o_idx, next_o_idx = 0;
4572
4573         grid_type *g_ptr;
4574
4575         GAME_TEXT o_name[MAX_NLEN];
4576
4577         bool flag = FALSE;
4578         bool done = FALSE;
4579
4580 #ifndef JP
4581         /* Extract plural */
4582         bool plural = (j_ptr->number != 1);
4583 #endif
4584
4585         /* Describe object */
4586         object_desc(o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4587
4588
4589         /* Handle normal "breakage" */
4590         if (!object_is_artifact(j_ptr) && (randint0(100) < chance))
4591         {
4592 #ifdef JP
4593                 msg_format("%sは消えた。", o_name);
4594 #else
4595                 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4596 #endif
4597                 if (p_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
4598
4599                 /* Failure */
4600                 return (0);
4601         }
4602
4603
4604         /* Score */
4605         bs = -1;
4606
4607         /* Picker */
4608         bn = 0;
4609
4610         /* Default */
4611         by = y;
4612         bx = x;
4613
4614         /* Scan local grids */
4615         for (dy = -3; dy <= 3; dy++)
4616         {
4617                 /* Scan local grids */
4618                 for (dx = -3; dx <= 3; dx++)
4619                 {
4620                         bool comb = FALSE;
4621
4622                         /* Calculate actual distance */
4623                         d = (dy * dy) + (dx * dx);
4624
4625                         /* Ignore distant grids */
4626                         if (d > 10) continue;
4627
4628                         ty = y + dy;
4629                         tx = x + dx;
4630
4631                         /* Skip illegal grids */
4632                         if (!in_bounds(ty, tx)) continue;
4633
4634                         /* Require line of projection */
4635                         if (!projectable(y, x, ty, tx)) continue;
4636
4637                         /* Obtain grid */
4638                         g_ptr = &current_floor_ptr->grid_array[ty][tx];
4639
4640                         /* Require floor space */
4641                         if (!cave_drop_bold(ty, tx)) continue;
4642
4643                         /* No objects */
4644                         k = 0;
4645
4646                         /* Scan objects in that grid */
4647                         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4648                         {
4649                                 object_type *o_ptr;
4650                                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
4651                                 next_o_idx = o_ptr->next_o_idx;
4652
4653                                 /* Check for possible combination */
4654                                 if (object_similar(o_ptr, j_ptr)) comb = TRUE;
4655
4656                                 /* Count objects */
4657                                 k++;
4658                         }
4659
4660                         /* Add new object */
4661                         if (!comb) k++;
4662
4663                         /* Paranoia */
4664                         if (k > 99) continue;
4665
4666                         /* Calculate score */
4667                         s = 1000 - (d + k * 5);
4668
4669                         /* Skip bad values */
4670                         if (s < bs) continue;
4671
4672                         /* New best value */
4673                         if (s > bs) bn = 0;
4674
4675                         /* Apply the randomizer to equivalent values */
4676                         if ((++bn >= 2) && !one_in_(bn)) continue;
4677
4678                         /* Keep score */
4679                         bs = s;
4680
4681                         /* Track it */
4682                         by = ty;
4683                         bx = tx;
4684
4685                         flag = TRUE;
4686                 }
4687         }
4688
4689
4690         /* Handle lack of space */
4691         if (!flag && !object_is_artifact(j_ptr))
4692         {
4693 #ifdef JP
4694                 msg_format("%sは消えた。", o_name);
4695 #else
4696                 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4697 #endif
4698
4699                 if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4700
4701                 /* Failure */
4702                 return (0);
4703         }
4704
4705
4706         /* Find a grid */
4707         for (i = 0; !flag && (i < 1000); i++)
4708         {
4709                 /* Bounce around */
4710                 ty = rand_spread(by, 1);
4711                 tx = rand_spread(bx, 1);
4712
4713                 /* Verify location */
4714                 if (!in_bounds(ty, tx)) continue;
4715
4716                 /* Bounce to that location */
4717                 by = ty;
4718                 bx = tx;
4719
4720                 /* Require floor space */
4721                 if (!cave_drop_bold(by, bx)) continue;
4722
4723                 flag = TRUE;
4724         }
4725
4726
4727         if (!flag)
4728         {
4729                 int candidates = 0, pick;
4730
4731                 for (ty = 1; ty < current_floor_ptr->height - 1; ty++)
4732                 {
4733                         for (tx = 1; tx < current_floor_ptr->width - 1; tx++)
4734                         {
4735                                 /* A valid space found */
4736                                 if (cave_drop_bold(ty, tx)) candidates++;
4737                         }
4738                 }
4739
4740                 /* No valid place! */
4741                 if (!candidates)
4742                 {
4743 #ifdef JP
4744                         msg_format("%sは消えた。", o_name);
4745 #else
4746                         msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4747 #endif
4748
4749                         if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4750
4751                         /* Mega-Hack -- preserve artifacts */
4752                         if (preserve_mode)
4753                         {
4754                                 /* Hack -- Preserve unknown artifacts */
4755                                 if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr))
4756                                 {
4757                                         /* Mega-Hack -- Preserve the artifact */
4758                                         a_info[j_ptr->name1].cur_num = 0;
4759                                 }
4760                         }
4761
4762                         /* Failure */
4763                         return 0;
4764                 }
4765
4766                 /* Choose a random one */
4767                 pick = randint1(candidates);
4768
4769                 for (ty = 1; ty < current_floor_ptr->height - 1; ty++)
4770                 {
4771                         for (tx = 1; tx < current_floor_ptr->width - 1; tx++)
4772                         {
4773                                 if (cave_drop_bold(ty, tx))
4774                                 {
4775                                         pick--;
4776
4777                                         /* Is this a picked one? */
4778                                         if (!pick) break;
4779                                 }
4780                         }
4781
4782                         if (!pick) break;
4783                 }
4784
4785                 by = ty;
4786                 bx = tx;
4787         }
4788
4789
4790         g_ptr = &current_floor_ptr->grid_array[by][bx];
4791
4792         /* Scan objects in that grid for combination */
4793         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4794         {
4795                 object_type *o_ptr;
4796                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
4797                 next_o_idx = o_ptr->next_o_idx;
4798
4799                 /* Check for combination */
4800                 if (object_similar(o_ptr, j_ptr))
4801                 {
4802                         object_absorb(o_ptr, j_ptr);
4803
4804                         /* Success */
4805                         done = TRUE;
4806
4807                         break;
4808                 }
4809         }
4810
4811         if (!done) o_idx = o_pop();
4812
4813         /* Failure */
4814         if (!done && !o_idx)
4815         {
4816 #ifdef JP
4817                 msg_format("%sは消えた。", o_name);
4818 #else
4819                 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4820 #endif
4821
4822                 if (p_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
4823
4824                 /* Hack -- Preserve artifacts */
4825                 if (object_is_fixed_artifact(j_ptr))
4826                 {
4827                         a_info[j_ptr->name1].cur_num = 0;
4828                 }
4829
4830                 /* Failure */
4831                 return (0);
4832         }
4833
4834         /* Stack */
4835         if (!done)
4836         {
4837                 /* Structure copy */
4838                 object_copy(&current_floor_ptr->o_list[o_idx], j_ptr);
4839
4840                 /* Access new object */
4841                 j_ptr = &current_floor_ptr->o_list[o_idx];
4842
4843                 /* Locate */
4844                 j_ptr->iy = by;
4845                 j_ptr->ix = bx;
4846
4847                 /* No monster */
4848                 j_ptr->held_m_idx = 0;
4849
4850                 /* Build a stack */
4851                 j_ptr->next_o_idx = g_ptr->o_idx;
4852
4853                 g_ptr->o_idx = o_idx;
4854
4855                 /* Success */
4856                 done = TRUE;
4857         }
4858
4859         note_spot(by, bx);
4860         lite_spot(by, bx);
4861         sound(SOUND_DROP);
4862
4863         /* Mega-Hack -- no message if "dropped" by player */
4864         /* Message when an object falls under the player */
4865         if (chance && player_bold(by, bx))
4866         {
4867                 msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
4868         }
4869
4870         return (o_idx);
4871 }
4872
4873 /*!
4874  * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
4875  * Describe the charges on an item in the inventory.
4876  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4877  * @return なし
4878  */
4879 void inven_item_charges(INVENTORY_IDX item)
4880 {
4881         object_type *o_ptr = &inventory[item];
4882
4883         /* Require staff/wand */
4884         if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
4885
4886         /* Require known item */
4887         if (!object_is_known(o_ptr)) return;
4888
4889 #ifdef JP
4890         if (o_ptr->pval <= 0)
4891         {
4892                 msg_print("もう魔力が残っていない。");
4893         }
4894         else
4895         {
4896                 msg_format("あと %d 回分の魔力が残っている。", o_ptr->pval);
4897         }
4898 #else
4899         /* Multiple charges */
4900         if (o_ptr->pval != 1)
4901         {
4902                 msg_format("You have %d charges remaining.", o_ptr->pval);
4903         }
4904
4905         /* Single charge */
4906         else
4907         {
4908                 msg_format("You have %d charge remaining.", o_ptr->pval);
4909         }
4910 #endif
4911
4912 }
4913
4914 /*!
4915  * @brief アイテムの残り所持数メッセージを表示する /
4916  * Describe an item in the inventory.
4917  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4918  * @return なし
4919  */
4920 void inven_item_describe(INVENTORY_IDX item)
4921 {
4922         object_type *o_ptr = &inventory[item];
4923         GAME_TEXT o_name[MAX_NLEN];
4924
4925         object_desc(o_name, o_ptr, 0);
4926
4927 #ifdef JP
4928         /* "no more" の場合はこちらで表示する */
4929         if (o_ptr->number <= 0)
4930         {
4931                 /*FIRST*//*ここはもう通らないかも */
4932                 msg_format("もう%sを持っていない。", o_name);
4933         }
4934         else
4935         {
4936                 /* アイテム名を英日切り替え機能対応 */
4937                 msg_format("まだ %sを持っている。", o_name);
4938         }
4939 #else
4940         msg_format("You have %s.", o_name);
4941 #endif
4942
4943 }
4944
4945 /*!
4946  * @brief アイテムを増減させ残り所持数メッセージを表示する /
4947  * Increase the "number" of an item in the inventory
4948  * @param item 所持数を増やしたいプレイヤーのアイテム所持スロット
4949  * @param num 増やしたい量
4950  * @return なし
4951  */
4952 void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
4953 {
4954         object_type *o_ptr = &inventory[item];
4955
4956         /* Apply */
4957         num += o_ptr->number;
4958
4959         /* Bounds check */
4960         if (num > 255) num = 255;
4961         else if (num < 0) num = 0;
4962
4963         /* Un-apply */
4964         num -= o_ptr->number;
4965
4966         /* Change the number and weight */
4967         if (num)
4968         {
4969                 /* Add the number */
4970                 o_ptr->number += num;
4971
4972                 /* Add the weight */
4973                 p_ptr->total_weight += (num * o_ptr->weight);
4974                 p_ptr->update |= (PU_BONUS);
4975                 p_ptr->update |= (PU_MANA);
4976                 p_ptr->update |= (PU_COMBINE);
4977                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
4978
4979                 /* Hack -- Clear temporary elemental brands if player takes off weapons */
4980                 if (!o_ptr->number && p_ptr->ele_attack)
4981                 {
4982                         if ((item == INVEN_RARM) || (item == INVEN_LARM))
4983                         {
4984                                 if (!has_melee_weapon(INVEN_RARM + INVEN_LARM - item))
4985                                 {
4986                                         /* Clear all temporary elemental brands */
4987                                         set_ele_attack(0, 0);
4988                                 }
4989                         }
4990                 }
4991         }
4992 }
4993
4994 /*!
4995  * @brief 所持アイテムスロットから所持数のなくなったアイテムを消去する /
4996  * Erase an inventory slot if it has no more items
4997  * @param item 消去したいプレイヤーのアイテム所持スロット
4998  * @return なし
4999  */
5000 void inven_item_optimize(INVENTORY_IDX item)
5001 {
5002         object_type *o_ptr = &inventory[item];
5003
5004         /* Only optimize real items */
5005         if (!o_ptr->k_idx) return;
5006
5007         /* Only optimize empty items */
5008         if (o_ptr->number) return;
5009
5010         /* The item is in the pack */
5011         if (item < INVEN_RARM)
5012         {
5013                 int i;
5014
5015                 /* One less item */
5016                 inven_cnt--;
5017
5018                 /* Slide everything down */
5019                 for (i = item; i < INVEN_PACK; i++)
5020                 {
5021                         /* Structure copy */
5022                         inventory[i] = inventory[i+1];
5023                 }
5024
5025                 /* Erase the "final" slot */
5026                 object_wipe(&inventory[i]);
5027
5028                 p_ptr->window |= (PW_INVEN);
5029         }
5030
5031         /* The item is being wielded */
5032         else
5033         {
5034                 /* One less item */
5035                 equip_cnt--;
5036
5037                 /* Erase the empty slot */
5038                 object_wipe(&inventory[item]);
5039                 p_ptr->update |= (PU_BONUS);
5040                 p_ptr->update |= (PU_TORCH);
5041                 p_ptr->update |= (PU_MANA);
5042
5043                 p_ptr->window |= (PW_EQUIP);
5044         }
5045
5046         p_ptr->window |= (PW_SPELL);
5047 }
5048
5049 /*!
5050  * @brief 床上の魔道具の残り残量メッセージを表示する /
5051  * Describe the charges on an item on the floor.
5052  * @param item メッセージの対象にしたいアイテム所持スロット
5053  * @return なし
5054  */
5055 void floor_item_charges(INVENTORY_IDX item)
5056 {
5057         object_type *o_ptr = &current_floor_ptr->o_list[item];
5058
5059         /* Require staff/wand */
5060         if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5061
5062         /* Require known item */
5063         if (!object_is_known(o_ptr)) return;
5064
5065 #ifdef JP
5066         if (o_ptr->pval <= 0)
5067         {
5068                 msg_print("この床上のアイテムは、もう魔力が残っていない。");
5069         }
5070         else
5071         {
5072                 msg_format("この床上のアイテムは、あと %d 回分の魔力が残っている。", o_ptr->pval);
5073         }
5074 #else
5075         /* Multiple charges */
5076         if (o_ptr->pval != 1)
5077         {
5078                 msg_format("There are %d charges remaining.", o_ptr->pval);
5079         }
5080
5081         /* Single charge */
5082         else
5083         {
5084                 msg_format("There is %d charge remaining.", o_ptr->pval);
5085         }
5086 #endif
5087
5088 }
5089
5090 /*!
5091  * @brief 床上のアイテムの残り数メッセージを表示する /
5092  * Describe the charges on an item on the floor.
5093  * @param item メッセージの対象にしたいアイテム所持スロット
5094  * @return なし
5095  */
5096 void floor_item_describe(INVENTORY_IDX item)
5097 {
5098         object_type *o_ptr = &current_floor_ptr->o_list[item];
5099         GAME_TEXT o_name[MAX_NLEN];
5100
5101         object_desc(o_name, o_ptr, 0);
5102
5103 #ifdef JP
5104         /* "no more" の場合はこちらで表示を分ける */
5105         if (o_ptr->number <= 0)
5106         {
5107                 msg_format("床上には、もう%sはない。", o_name);
5108         }
5109         else
5110         {
5111                 msg_format("床上には、まだ %sがある。", o_name);
5112         }
5113 #else
5114         msg_format("You see %s.", o_name);
5115 #endif
5116
5117 }
5118
5119
5120 /*!
5121  * @brief 床上のアイテムの数を増やす /
5122  * Increase the "number" of an item on the floor
5123  * @param item 増やしたいアイテムの所持スロット
5124  * @param num 増やしたいアイテムの数
5125  * @return なし
5126  */
5127 void floor_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
5128 {
5129         object_type *o_ptr = &current_floor_ptr->o_list[item];
5130
5131         /* Apply */
5132         num += o_ptr->number;
5133
5134         /* Bounds check */
5135         if (num > 255) num = 255;
5136         else if (num < 0) num = 0;
5137
5138         /* Un-apply */
5139         num -=  o_ptr->number;
5140
5141         /* Change the number */
5142         o_ptr->number += num;
5143 }
5144
5145
5146 /*!
5147  * @brief 床上の数の無くなったアイテムスロットを消去する /
5148  * Optimize an item on the floor (destroy "empty" items)
5149  * @param item 消去したいアイテムの所持スロット
5150  * @return なし
5151  */
5152 void floor_item_optimize(INVENTORY_IDX item)
5153 {
5154         object_type *o_ptr = &current_floor_ptr->o_list[item];
5155
5156         /* Paranoia -- be sure it exists */
5157         if (!o_ptr->k_idx) return;
5158
5159         /* Only optimize empty items */
5160         if (o_ptr->number) return;
5161
5162         delete_object_idx(item);
5163 }
5164
5165
5166 /*!
5167  * @brief アイテムを拾う際にザックから溢れずに済むかを判定する /
5168  * Check if we have space for an item in the pack without overflow
5169  * @param o_ptr 拾いたいオブジェクトの構造体参照ポインタ
5170  * @return 溢れずに済むならTRUEを返す
5171  */
5172 bool inven_carry_okay(object_type *o_ptr)
5173 {
5174         int j;
5175
5176         /* Empty slot? */
5177         if (inven_cnt < INVEN_PACK) return (TRUE);
5178
5179         /* Similar slot? */
5180         for (j = 0; j < INVEN_PACK; j++)
5181         {
5182                 object_type *j_ptr = &inventory[j];
5183
5184                 /* Skip non-objects */
5185                 if (!j_ptr->k_idx) continue;
5186
5187                 /* Check if the two items can be combined */
5188                 if (object_similar(j_ptr, o_ptr)) return (TRUE);
5189         }
5190
5191         return (FALSE);
5192 }
5193
5194 /*!
5195  * @brief オブジェクトを定義された基準に従いソートするための関数 /
5196  * Check if we have space for an item in the pack without overflow
5197  * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
5198  * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
5199  * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
5200  * @return o_ptrの方が上位ならばTRUEを返す。
5201  */
5202 bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
5203 {
5204         int o_type, j_type;
5205
5206         /* Use empty slots */
5207         if (!j_ptr->k_idx) return TRUE;
5208
5209         /* Hack -- readable books always come first */
5210         if ((o_ptr->tval == REALM1_BOOK) &&
5211             (j_ptr->tval != REALM1_BOOK)) return TRUE;
5212         if ((j_ptr->tval == REALM1_BOOK) &&
5213             (o_ptr->tval != REALM1_BOOK)) return FALSE;
5214
5215         if ((o_ptr->tval == REALM2_BOOK) &&
5216             (j_ptr->tval != REALM2_BOOK)) return TRUE;
5217         if ((j_ptr->tval == REALM2_BOOK) &&
5218             (o_ptr->tval != REALM2_BOOK)) return FALSE;
5219
5220         /* Objects sort by decreasing type */
5221         if (o_ptr->tval > j_ptr->tval) return TRUE;
5222         if (o_ptr->tval < j_ptr->tval) return FALSE;
5223
5224         /* Non-aware (flavored) items always come last */
5225         /* Can happen in the home */
5226         if (!object_is_aware(o_ptr)) return FALSE;
5227         if (!object_is_aware(j_ptr)) return TRUE;
5228
5229         /* Objects sort by increasing sval */
5230         if (o_ptr->sval < j_ptr->sval) return TRUE;
5231         if (o_ptr->sval > j_ptr->sval) return FALSE;
5232
5233         /* Unidentified objects always come last */
5234         /* Objects in the home can be unknown */
5235         if (!object_is_known(o_ptr)) return FALSE;
5236         if (!object_is_known(j_ptr)) return TRUE;
5237
5238         /* Fixed artifacts, random artifacts and ego items */
5239         if (object_is_fixed_artifact(o_ptr)) o_type = 3;
5240         else if (o_ptr->art_name) o_type = 2;
5241         else if (object_is_ego(o_ptr)) o_type = 1;
5242         else o_type = 0;
5243
5244         if (object_is_fixed_artifact(j_ptr)) j_type = 3;
5245         else if (j_ptr->art_name) j_type = 2;
5246         else if (object_is_ego(j_ptr)) j_type = 1;
5247         else j_type = 0;
5248
5249         if (o_type < j_type) return TRUE;
5250         if (o_type > j_type) return FALSE;
5251
5252         switch (o_ptr->tval)
5253         {
5254         case TV_FIGURINE:
5255         case TV_STATUE:
5256         case TV_CORPSE:
5257         case TV_CAPTURE:
5258                 if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
5259                 if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
5260                 return FALSE;
5261
5262         case TV_SHOT:
5263         case TV_ARROW:
5264         case TV_BOLT:
5265                 /* Objects sort by increasing hit/damage bonuses */
5266                 if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
5267                 if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
5268                 break;
5269
5270         /* Hack:  otherwise identical rods sort by
5271         increasing recharge time --dsb */
5272         case TV_ROD:
5273                 if (o_ptr->pval < j_ptr->pval) return TRUE;
5274                 if (o_ptr->pval > j_ptr->pval) return FALSE;
5275                 break;
5276         }
5277
5278         /* Objects sort by decreasing value */
5279         return o_value > object_value(j_ptr);
5280 }
5281
5282
5283 /*!
5284  * @brief オブジェクトをプレイヤーが拾って所持スロットに納めるメインルーチン /
5285  * Add an item to the players inventory, and return the slot used.
5286  * @param o_ptr 拾うオブジェクトの構造体参照ポインタ
5287  * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5288  * @details
5289  * If the new item can combine with an existing item in the inventory,\n
5290  * it will do so, using "object_similar()" and "object_absorb()", else,\n
5291  * the item will be placed into the "proper" location in the inventory.\n
5292  *\n
5293  * This function can be used to "over-fill" the player's pack, but only\n
5294  * once, and such an action must trigger the "overflow" code immediately.\n
5295  * Note that when the pack is being "over-filled", the new item must be\n
5296  * placed into the "overflow" slot, and the "overflow" must take place\n
5297  * before the pack is reordered, but (optionally) after the pack is\n
5298  * combined.  This may be tricky.  See "dungeon.c" for info.\n
5299  *\n
5300  * Note that this code must remove any location/stack information\n
5301  * from the object once it is placed into the inventory.\n
5302  */
5303 s16b inven_carry(object_type *o_ptr)
5304 {
5305         INVENTORY_IDX i, j, k;
5306         INVENTORY_IDX n = -1;
5307
5308         object_type *j_ptr;
5309
5310
5311         /* Check for combining */
5312         for (j = 0; j < INVEN_PACK; j++)
5313         {
5314                 j_ptr = &inventory[j];
5315
5316                 /* Skip non-objects */
5317                 if (!j_ptr->k_idx) continue;
5318
5319                 /* Hack -- track last item */
5320                 n = j;
5321
5322                 /* Check if the two items can be combined */
5323                 if (object_similar(j_ptr, o_ptr))
5324                 {
5325                         object_absorb(j_ptr, o_ptr);
5326
5327                         p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
5328                         p_ptr->update |= (PU_BONUS);
5329                         p_ptr->window |= (PW_INVEN);
5330
5331                         /* Success */
5332                         return (j);
5333                 }
5334         }
5335
5336
5337         /* Paranoia */
5338         if (inven_cnt > INVEN_PACK) return (-1);
5339
5340         /* Find an empty slot */
5341         for (j = 0; j <= INVEN_PACK; j++)
5342         {
5343                 j_ptr = &inventory[j];
5344
5345                 /* Use it if found */
5346                 if (!j_ptr->k_idx) break;
5347         }
5348
5349         /* Use that slot */
5350         i = j;
5351
5352
5353         /* Reorder the pack */
5354         if (i < INVEN_PACK)
5355         {
5356                 /* Get the "value" of the item */
5357                 s32b o_value = object_value(o_ptr);
5358
5359                 /* Scan every occupied slot */
5360                 for (j = 0; j < INVEN_PACK; j++)
5361                 {
5362                         if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
5363                 }
5364
5365                 /* Use that slot */
5366                 i = j;
5367
5368                 /* Slide objects */
5369                 for (k = n; k >= i; k--)
5370                 {
5371                         /* Hack -- Slide the item */
5372                         object_copy(&inventory[k+1], &inventory[k]);
5373                 }
5374
5375                 /* Wipe the empty slot */
5376                 object_wipe(&inventory[i]);
5377         }
5378
5379
5380         /* Copy the item */
5381         object_copy(&inventory[i], o_ptr);
5382
5383         /* Access new object */
5384         j_ptr = &inventory[i];
5385
5386         /* Forget stack */
5387         j_ptr->next_o_idx = 0;
5388
5389         /* Forget monster */
5390         j_ptr->held_m_idx = 0;
5391
5392         /* Forget location */
5393         j_ptr->iy = j_ptr->ix = 0;
5394
5395         /* Player touches it, and no longer marked */
5396         j_ptr->marked = OM_TOUCHED;
5397
5398         p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
5399
5400         /* Count the items */
5401         inven_cnt++;
5402         p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
5403         p_ptr->window |= (PW_INVEN);
5404
5405         /* Return the slot */
5406         return (i);
5407 }
5408
5409
5410 /*!
5411  * @brief 装備スロットからオブジェクトを外すメインルーチン /
5412  * Take off (some of) a non-cursed equipment item
5413  * @param item オブジェクトを外したい所持テーブルのID
5414  * @param amt 外したい個数
5415  * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5416  * @details
5417  * Note that only one item at a time can be wielded per slot.\n
5418  * Note that taking off an item when "full" may cause that item\n
5419  * to fall to the ground.\n
5420  * Return the inventory slot into which the item is placed.\n
5421  */
5422 INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
5423 {
5424         INVENTORY_IDX slot;
5425
5426         object_type forge;
5427         object_type *q_ptr;
5428
5429         object_type *o_ptr;
5430
5431         concptr act;
5432
5433         GAME_TEXT o_name[MAX_NLEN];
5434
5435
5436         /* Get the item to take off */
5437         o_ptr = &inventory[item];
5438
5439         /* Paranoia */
5440         if (amt <= 0) return (-1);
5441
5442         /* Verify */
5443         if (amt > o_ptr->number) amt = o_ptr->number;
5444         q_ptr = &forge;
5445
5446         /* Obtain a local object */
5447         object_copy(q_ptr, o_ptr);
5448
5449         /* Modify quantity */
5450         q_ptr->number = amt;
5451
5452         object_desc(o_name, q_ptr, 0);
5453
5454         /* Took off weapon */
5455         if (((item == INVEN_RARM) || (item == INVEN_LARM)) &&
5456             object_is_melee_weapon(o_ptr))
5457         {
5458                 act = _("を装備からはずした", "You were wielding");
5459         }
5460
5461         /* Took off bow */
5462         else if (item == INVEN_BOW)
5463         {
5464                 act = _("を装備からはずした", "You were holding");
5465         }
5466
5467         /* Took off light */
5468         else if (item == INVEN_LITE)
5469         {
5470                 act = _("を光源からはずした", "You were holding");
5471         }
5472
5473         /* Took off something */
5474         else
5475         {
5476                 act = _("を装備からはずした", "You were wearing");
5477         }
5478
5479         /* Modify, Optimize */
5480         inven_item_increase(item, -amt);
5481         inven_item_optimize(item);
5482
5483         /* Carry the object */
5484         slot = inven_carry(q_ptr);
5485
5486 #ifdef JP
5487         msg_format("%s(%c)%s。", o_name, index_to_label(slot), act);
5488 #else
5489         msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
5490 #endif
5491
5492
5493         /* Return slot */
5494         return (slot);
5495 }
5496
5497
5498 /*!
5499  * @brief 所持スロットから床下にオブジェクトを落とすメインルーチン /
5500  * Drop (some of) a non-cursed inventory/equipment item
5501  * @param item 所持テーブルのID
5502  * @param amt 落としたい個数
5503  * @return なし
5504  * @details
5505  * The object will be dropped "near" the current location
5506  */
5507 void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
5508 {
5509         object_type forge;
5510         object_type *q_ptr;
5511         object_type *o_ptr;
5512
5513         GAME_TEXT o_name[MAX_NLEN];
5514
5515         /* Access original object */
5516         o_ptr = &inventory[item];
5517
5518         /* Error check */
5519         if (amt <= 0) return;
5520
5521         /* Not too many */
5522         if (amt > o_ptr->number) amt = o_ptr->number;
5523
5524         /* Take off equipment */
5525         if (item >= INVEN_RARM)
5526         {
5527                 /* Take off first */
5528                 item = inven_takeoff(item, amt);
5529
5530                 /* Access original object */
5531                 o_ptr = &inventory[item];
5532         }
5533
5534         q_ptr = &forge;
5535
5536         /* Obtain local object */
5537         object_copy(q_ptr, o_ptr);
5538
5539         /* Distribute charges of wands or rods */
5540         distribute_charges(o_ptr, q_ptr, amt);
5541
5542         /* Modify quantity */
5543         q_ptr->number = amt;
5544
5545         /* Describe local object */
5546         object_desc(o_name, q_ptr, 0);
5547
5548         msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(item));
5549
5550         /* Drop it near the player */
5551         (void)drop_near(q_ptr, 0, p_ptr->y, p_ptr->x);
5552
5553         /* Modify, Describe, Optimize */
5554         inven_item_increase(item, -amt);
5555         inven_item_describe(item);
5556         inven_item_optimize(item);
5557 }
5558
5559
5560 /*!
5561  * @brief プレイヤーの所持スロットに存在するオブジェクトをまとめなおす /
5562  * Combine items in the pack
5563  * @return なし
5564  * @details
5565  * Note special handling of the "overflow" slot
5566  */
5567 void combine_pack(void)
5568 {
5569         int             i, j, k;
5570         object_type *o_ptr;
5571         object_type     *j_ptr;
5572         bool            flag = FALSE, combined;
5573
5574         do
5575         {
5576                 combined = FALSE;
5577
5578                 /* Combine the pack (backwards) */
5579                 for (i = INVEN_PACK; i > 0; i--)
5580                 {
5581                         o_ptr = &inventory[i];
5582
5583                         /* Skip empty items */
5584                         if (!o_ptr->k_idx) continue;
5585
5586                         /* Scan the items above that item */
5587                         for (j = 0; j < i; j++)
5588                         {
5589                                 int max_num;
5590
5591                                 j_ptr = &inventory[j];
5592
5593                                 /* Skip empty items */
5594                                 if (!j_ptr->k_idx) continue;
5595
5596                                 /*
5597                                  * Get maximum number of the stack if these
5598                                  * are similar, get zero otherwise.
5599                                  */
5600                                 max_num = object_similar_part(j_ptr, o_ptr);
5601
5602                                 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
5603                                 if (max_num && j_ptr->number < max_num)
5604                                 {
5605                                         if (o_ptr->number + j_ptr->number <= max_num)
5606                                         {
5607                                                 /* Take note */
5608                                                 flag = TRUE;
5609
5610                                                 /* Add together the item counts */
5611                                                 object_absorb(j_ptr, o_ptr);
5612
5613                                                 /* One object is gone */
5614                                                 inven_cnt--;
5615
5616                                                 /* Slide everything down */
5617                                                 for (k = i; k < INVEN_PACK; k++)
5618                                                 {
5619                                                         /* Structure copy */
5620                                                         inventory[k] = inventory[k+1];
5621                                                 }
5622
5623                                                 /* Erase the "final" slot */
5624                                                 object_wipe(&inventory[k]);
5625                                         }
5626                                         else
5627                                         {
5628                                                 int old_num = o_ptr->number;
5629                                                 int remain = j_ptr->number + o_ptr->number - max_num;
5630 #if 0
5631                                                 o_ptr->number -= remain;
5632 #endif
5633                                                 /* Add together the item counts */
5634                                                 object_absorb(j_ptr, o_ptr);
5635
5636                                                 o_ptr->number = remain;
5637
5638                                                 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
5639                                                 if (o_ptr->tval == TV_ROD)
5640                                                 {
5641                                                         o_ptr->pval =  o_ptr->pval * remain / old_num;
5642                                                         o_ptr->timeout = o_ptr->timeout * remain / old_num;
5643                                                 }
5644
5645                                                 /* Hack -- if wands are stacking, combine the charges. -LM- */
5646                                                 if (o_ptr->tval == TV_WAND)
5647                                                 {
5648                                                         o_ptr->pval = o_ptr->pval * remain / old_num;
5649                                                 }
5650                                         }
5651
5652                                         p_ptr->window |= (PW_INVEN);
5653
5654                                         /* Take note */
5655                                         combined = TRUE;
5656
5657                                         break;
5658                                 }
5659                         }
5660                 }
5661         }
5662         while (combined);
5663
5664         if (flag) msg_print(_("ザックの中のアイテムをまとめ直した。", "You combine some items in your pack."));
5665 }
5666
5667 /*!
5668  * @brief プレイヤーの所持スロットに存在するオブジェクトを並び替える /
5669  * Reorder items in the pack
5670  * @return なし
5671  * @details
5672  * Note special handling of the "overflow" slot
5673  */
5674 void reorder_pack(void)
5675 {
5676         int             i, j, k;
5677         s32b            o_value;
5678         object_type     forge;
5679         object_type     *q_ptr;
5680         object_type *o_ptr;
5681         bool            flag = FALSE;
5682
5683
5684         /* Re-order the pack (forwards) */
5685         for (i = 0; i < INVEN_PACK; i++)
5686         {
5687                 /* Mega-Hack -- allow "proper" over-flow */
5688                 if ((i == INVEN_PACK) && (inven_cnt == INVEN_PACK)) break;
5689
5690                 o_ptr = &inventory[i];
5691
5692                 /* Skip empty slots */
5693                 if (!o_ptr->k_idx) continue;
5694
5695                 /* Get the "value" of the item */
5696                 o_value = object_value(o_ptr);
5697
5698                 /* Scan every occupied slot */
5699                 for (j = 0; j < INVEN_PACK; j++)
5700                 {
5701                         if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
5702                 }
5703
5704                 /* Never move down */
5705                 if (j >= i) continue;
5706
5707                 /* Take note */
5708                 flag = TRUE;
5709                 q_ptr = &forge;
5710
5711                 /* Save a copy of the moving item */
5712                 object_copy(q_ptr, &inventory[i]);
5713
5714                 /* Slide the objects */
5715                 for (k = i; k > j; k--)
5716                 {
5717                         /* Slide the item */
5718                         object_copy(&inventory[k], &inventory[k-1]);
5719                 }
5720
5721                 /* Insert the moving item */
5722                 object_copy(&inventory[j], q_ptr);
5723
5724                 p_ptr->window |= (PW_INVEN);
5725         }
5726
5727         if (flag) msg_print(_("ザックの中のアイテムを並べ直した。", "You reorder some items in your pack."));
5728 }
5729
5730 /*!
5731  * @brief 現在アクティブになっているウィンドウにオブジェクトの詳細を表示する /
5732  * Hack -- display an object kind in the current window
5733  * @param k_idx ベースアイテムの参照ID
5734  * @return なし
5735  * @details
5736  * Include list of usable spells for readible books
5737  */
5738 void display_koff(KIND_OBJECT_IDX k_idx)
5739 {
5740         int y;
5741
5742         object_type forge;
5743         object_type *q_ptr;
5744         int         sval;
5745         REALM_IDX   use_realm;
5746
5747         GAME_TEXT o_name[MAX_NLEN];
5748
5749
5750         /* Erase the window */
5751         for (y = 0; y < Term->hgt; y++)
5752         {
5753                 /* Erase the line */
5754                 Term_erase(0, y, 255);
5755         }
5756
5757         /* No info */
5758         if (!k_idx) return;
5759         q_ptr = &forge;
5760
5761         /* Prepare the object */
5762         object_prep(q_ptr, k_idx);
5763         object_desc(o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
5764
5765         /* Mention the object name */
5766         Term_putstr(0, 0, -1, TERM_WHITE, o_name);
5767
5768         /* Access the item's sval */
5769         sval = q_ptr->sval;
5770         use_realm = tval2realm(q_ptr->tval);
5771
5772         /* Warriors are illiterate */
5773         if (p_ptr->realm1 || p_ptr->realm2)
5774         {
5775                 if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2)) return;
5776         }
5777         else
5778         {
5779                 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return;
5780                 if (!is_magic(use_realm)) return;
5781                 if ((p_ptr->pclass == CLASS_RED_MAGE) && (use_realm != REALM_ARCANE) && (sval > 1)) return;
5782         }
5783
5784         /* Display spells in readible books */
5785         {
5786                 int     spell = -1;
5787                 int     num = 0;
5788                 SPELL_IDX    spells[64];
5789
5790                 /* Extract spells */
5791                 for (spell = 0; spell < 32; spell++)
5792                 {
5793                         /* Check for this spell */
5794                         if (fake_spell_flags[sval] & (1L << spell))
5795                         {
5796                                 /* Collect this spell */
5797                                 spells[num++] = spell;
5798                         }
5799                 }
5800
5801                 /* Print spells */
5802                 print_spells(0, spells, num, 2, 0, use_realm);
5803         }
5804 }
5805
5806
5807 /*!
5808  * @brief 投擲時たいまつに投げやすい/焼棄/アンデッドスレイの特別効果を返す。
5809  * Torches have special abilities when they are flaming.
5810  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5811  * @param flgs 特別に追加するフラグを返す参照ポインタ
5812  * @return なし
5813  */
5814 void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs)
5815 {
5816         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5817         {
5818                 if (o_ptr->xtra4 > 0)
5819                 {
5820                         add_flag(flgs, TR_BRAND_FIRE);
5821                         add_flag(flgs, TR_KILL_UNDEAD);
5822                         add_flag(flgs, TR_THROW);
5823                 }
5824         }
5825 }
5826
5827 /*!
5828  * @brief 投擲時たいまつにダイスを与える。
5829  * Torches have special abilities when they are flaming.
5830  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5831  * @param dd 特別なダイス数を返す参照ポインタ
5832  * @param ds 特別なダイス面数を返す参照ポインタ
5833  * @return なし
5834  */
5835 void torch_dice(object_type *o_ptr, DICE_NUMBER *dd, DICE_SID *ds)
5836 {
5837         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5838         {
5839                 if (o_ptr->xtra4 > 0)
5840                 {
5841                         (*dd) = 1;
5842                         (*ds) = 6;
5843                 }
5844         }
5845 }
5846
5847 /*!
5848  * @brief 投擲時命中したたいまつの寿命を縮める。
5849  * Torches have special abilities when they are flaming.
5850  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5851  * @return なし
5852  */
5853 void torch_lost_fuel(object_type *o_ptr)
5854 {
5855         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5856         {
5857                 o_ptr->xtra4 -= (FUEL_TORCH / 25);
5858                 if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0;
5859         }
5860 }