OSDN Git Service

[Fix] #37476 モルグル武器のペナルティがswitch文ミスで重くなっていた問題を修正。 / Fix morgul weapon has too heavy...
[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                                                         break;
2239                                                 case EGO_WEIRD:
2240                                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2241                                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_NETHER);
2242                                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2243                                                         if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2244                                                         if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2245                                                         if (one_in_(6)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2246                                                         break;
2247                                         }
2248                                 }
2249                         }
2250
2251                         break;
2252                 }
2253
2254
2255                 case TV_BOW:
2256                 {
2257                         /* Very good */
2258                         if (power > 1)
2259                         {
2260                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2261                                 {
2262                                         create_artifact(o_ptr, FALSE);
2263                                         break;
2264                                 }
2265                                 o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE);
2266                         }
2267
2268                         break;
2269                 }
2270
2271
2272                 case TV_BOLT:
2273                 case TV_ARROW:
2274                 case TV_SHOT:
2275                 {
2276                         /* Very good */
2277                         if (power > 1)
2278                         {
2279                                 if (power > 2) /* power > 2 is debug only */
2280                                 {
2281                                         create_artifact(o_ptr, FALSE);
2282                                         break;
2283                                 }
2284
2285                                 o_ptr->name2 = get_random_ego(INVEN_AMMO, TRUE);
2286
2287                                 switch (o_ptr->name2)
2288                                 {
2289                                 case EGO_SLAYING_BOLT:
2290                                         o_ptr->dd++;
2291                                         break;
2292                                 }
2293
2294                                 /* Hack -- super-charge the damage dice */
2295                                 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2296
2297                                 /* Hack -- restrict the damage dice */
2298                                 if (o_ptr->dd > 9) o_ptr->dd = 9;
2299                         }
2300
2301                         /* Very cursed */
2302                         else if (power < -1)
2303                         {
2304                                 /* Roll for ego-item */
2305                                 if (randint0(MAX_DEPTH) < level)
2306                                 {
2307                                         o_ptr->name2 = get_random_ego(INVEN_AMMO, FALSE);
2308                                 }
2309                         }
2310
2311                         break;
2312                 }
2313         }
2314 }
2315
2316 /*!
2317  * @brief 防具系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2318  * Apply magic to an item known to be "armor"
2319  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2320  * @param level 生成基準階
2321  * @param power 生成ランク
2322  * @return なし
2323  * @details
2324  * Hack -- note special processing for crown/helm\n
2325  * Hack -- note special processing for robe of permanence\n
2326  */
2327 static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
2328 {
2329         ARMOUR_CLASS toac1 = (ARMOUR_CLASS)randint1(5) + m_bonus(5, level);
2330         ARMOUR_CLASS toac2 = (ARMOUR_CLASS)m_bonus(10, level);
2331
2332         /* Good */
2333         if (power > 0)
2334         {
2335                 /* Enchant */
2336                 o_ptr->to_a += toac1;
2337
2338                 /* Very good */
2339                 if (power > 1)
2340                 {
2341                         /* Enchant again */
2342                         o_ptr->to_a += toac2;
2343                 }
2344         }
2345
2346         /* Cursed */
2347         else if (power < 0)
2348         {
2349                 /* Penalize */
2350                 o_ptr->to_a -= toac1;
2351
2352                 /* Very cursed */
2353                 if (power < -1)
2354                 {
2355                         /* Penalize again */
2356                         o_ptr->to_a -= toac2;
2357                 }
2358
2359                 /* Cursed (if "bad") */
2360                 if (o_ptr->to_a < 0) o_ptr->curse_flags |= TRC_CURSED;
2361         }
2362
2363         switch (o_ptr->tval)
2364         {
2365                 case TV_DRAG_ARMOR:
2366                 {
2367                         if (one_in_(50) || (power > 2)) /* power > 2 is debug only */
2368                                 create_artifact(o_ptr, FALSE);
2369                         break;
2370                 }
2371
2372                 case TV_HARD_ARMOR:
2373                 case TV_SOFT_ARMOR:
2374                 {
2375                         /* Very good */
2376                         if (power > 1)
2377                         {
2378                                 /* Hack -- Try for "Robes of the Magi" */
2379                                 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
2380                                     (o_ptr->sval == SV_ROBE) &&
2381                                     (randint0(100) < 15))
2382                                 {
2383                                         if (one_in_(5))
2384                                         {
2385                                                 o_ptr->name2 = EGO_YOIYAMI;
2386                                                 o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
2387                                                 o_ptr->sval = SV_YOIYAMI_ROBE;
2388                                                 o_ptr->ac = 0;
2389                                                 o_ptr->to_a = 0;
2390                                         }
2391                                         else
2392                                         {
2393                                                 o_ptr->name2 = EGO_PERMANENCE;
2394                                         }
2395                                         break;
2396                                 }
2397
2398                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2399                                 {
2400                                         create_artifact(o_ptr, FALSE);
2401                                         break;
2402                                 }
2403
2404                                 while (1)
2405                                 {
2406                                         bool okay_flag = TRUE;
2407
2408                                         o_ptr->name2 = get_random_ego(INVEN_BODY, TRUE);
2409
2410                                         switch (o_ptr->name2)
2411                                         {
2412                                                 case EGO_DWARVEN:
2413                                                         if (o_ptr->tval != TV_HARD_ARMOR)
2414                                                         {
2415                                                                 okay_flag = FALSE;
2416                                                         }
2417                                                 break;
2418                                                 case EGO_DRUID:
2419                                                         if (o_ptr->tval != TV_SOFT_ARMOR)
2420                                                         {
2421                                                                 okay_flag = FALSE;
2422                                                         }
2423                                                 break;
2424                                                 default:
2425                                                 break;
2426                                         }
2427
2428                                         if (okay_flag) break;
2429                                 }
2430                                 switch (o_ptr->name2)
2431                                 {
2432                                   case EGO_RESISTANCE:
2433                                         if (one_in_(4))
2434                                                 add_flag(o_ptr->art_flags, TR_RES_POIS);
2435                                                 break;
2436                                   case EGO_DWARVEN:
2437                                         o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2438                                         o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
2439                                         break;
2440                                         
2441                                   case EGO_A_DEMON:
2442                                         if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2443                                         one_in_(3) ? 
2444                                                 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2445                                                 one_in_(2) ?
2446                                                         add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2447                                                         add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2448                                                 
2449                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2450                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2451                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2452                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2453                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2454                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2455                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2456                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2457                                         break;
2458                                   case EGO_A_MORGUL:
2459                                         if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2460                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2461                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2462                                         if (one_in_(6)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2463                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2464                                         if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2465                                         break;
2466                                   default:
2467                                         break;
2468                                 }
2469                         }
2470
2471                         break;
2472                 }
2473
2474                 case TV_SHIELD:
2475                 {
2476
2477                         if (o_ptr->sval == SV_DRAGON_SHIELD)
2478                         {
2479                                 dragon_resist(o_ptr);
2480                                 if (!one_in_(3)) break;
2481                         }
2482
2483                         /* Very good */
2484                         if (power > 1)
2485                         {
2486                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2487                                 {
2488                                         create_artifact(o_ptr, FALSE);
2489                                         break;
2490                                 }
2491                                 
2492                                 while(1)
2493                                 {
2494                                         o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE);
2495                                         if (o_ptr->sval != SV_SMALL_METAL_SHIELD && o_ptr->sval != SV_LARGE_METAL_SHIELD 
2496                                                                 && o_ptr->name2 == EGO_S_DWARVEN)
2497                                         {
2498                                                 continue;
2499                                         }
2500                                         break;
2501                                 }
2502                                 
2503                                 switch (o_ptr->name2)
2504                                 {
2505                                 case EGO_ENDURANCE:
2506                                         if (!one_in_(3)) one_high_resistance(o_ptr);
2507                                         if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_POIS);
2508                                         break;
2509                                 case EGO_REFLECTION:
2510                                         if (o_ptr->sval == SV_MIRROR_SHIELD)
2511                                                 o_ptr->name2 = 0;
2512                                         break;
2513                                         
2514                                 case EGO_S_DWARVEN:
2515                                         o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2516                                         o_ptr->ac = k_info[o_ptr->k_idx].ac + 3;
2517                                         break;
2518                                 }
2519                         }
2520                         break;
2521                 }
2522
2523                 case TV_GLOVES:
2524                 {
2525                         if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
2526                         {
2527                                 dragon_resist(o_ptr);
2528                                 if (!one_in_(3)) break;
2529                         }
2530                         if (power > 1)
2531                         {
2532                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2533                                 {
2534                                         create_artifact(o_ptr, FALSE);
2535                                         break;
2536                                 }
2537                                 o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE);
2538                         }
2539                         
2540                         /* Very cursed */
2541                         else if (power < -1)
2542                         {
2543                                 o_ptr->name2 = get_random_ego(INVEN_HANDS, FALSE);
2544                         }
2545
2546                         break;
2547                 }
2548
2549                 case TV_BOOTS:
2550                 {
2551                         if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
2552                         {
2553                                 dragon_resist(o_ptr);
2554                                 if (!one_in_(3)) break;
2555                         }
2556                         /* Very good */
2557                         if (power > 1)
2558                         {
2559                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2560                                 {
2561                                         create_artifact(o_ptr, FALSE);
2562                                         break;
2563                                 }
2564                                 o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE);
2565
2566                                 switch (o_ptr->name2)
2567                                 {
2568                                 case EGO_SLOW_DESCENT:
2569                                         if (one_in_(2))
2570                                         {
2571                                                 one_high_resistance(o_ptr);
2572                                         }
2573                                         break;
2574                                 }
2575                         }
2576                         /* Very cursed */
2577                         else if (power < -1)
2578                         {
2579                                 o_ptr->name2 = get_random_ego(INVEN_FEET, FALSE);
2580                         }
2581
2582                         break;
2583                 }
2584
2585                 case TV_CROWN:
2586                 {
2587                         /* Very good */
2588                         if (power > 1)
2589                         {
2590                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2591                                 {
2592                                         create_artifact(o_ptr, FALSE);
2593                                         break;
2594                                 }
2595                                 while (1)
2596                                 {
2597                                         bool ok_flag = TRUE;
2598                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2599
2600                                         switch (o_ptr->name2)
2601                                         {
2602                                         case EGO_TELEPATHY:
2603                                                 if (add_esp_strong(o_ptr)) add_esp_weak(o_ptr, TRUE);
2604                                                 else add_esp_weak(o_ptr, FALSE);
2605                                                 break;
2606                                         case EGO_MAGI:
2607                                         case EGO_MIGHT:
2608                                         case EGO_REGENERATION:
2609                                         case EGO_LORDLINESS:
2610                                         case EGO_BASILISK:
2611                                                 break;
2612                                         case EGO_SEEING:
2613                                                 if (one_in_(3))
2614                                                 {
2615                                                         if (one_in_(2)) add_esp_strong(o_ptr);
2616                                                         else add_esp_weak(o_ptr, FALSE);
2617                                                 }
2618                                                 break;
2619                                         default:/* not existing crown (wisdom,lite, etc...) */
2620                                                 ok_flag = FALSE;
2621                                         }
2622                                         if (ok_flag)
2623                                                 break; /* while (1) */
2624                                 }
2625                                 break;
2626                         }
2627
2628                         /* Very cursed */
2629                         else if (power < -1)
2630                         {       
2631                                 while (1)
2632                                 {
2633                                         bool ok_flag = TRUE;
2634                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2635
2636                                         switch (o_ptr->name2)
2637                                         {
2638                                           case EGO_ANCIENT_CURSE:
2639                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2640                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2641                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2642                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2643                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2644                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2645                                                 break;
2646                                         }
2647                                         if (ok_flag)
2648                                                 break; /* while (1) */
2649                                 }
2650                         }
2651
2652                         break;
2653                 }
2654
2655                 case TV_HELM:
2656                 {
2657                         if (o_ptr->sval == SV_DRAGON_HELM)
2658                         {
2659                                 dragon_resist(o_ptr);
2660                                 if (!one_in_(3)) break;
2661                         }
2662
2663                         /* Very good */
2664                         if (power > 1)
2665                         {
2666                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2667                                 {
2668                                         create_artifact(o_ptr, FALSE);
2669                                         break;
2670                                 }
2671                                 while (1)
2672                                 {
2673                                         bool ok_flag = TRUE;
2674                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2675
2676                                         switch (o_ptr->name2)
2677                                         {
2678                                         case EGO_BRILLIANCE:
2679                                         case EGO_DARK:
2680                                         case EGO_INFRAVISION:
2681                                         case EGO_H_PROTECTION:
2682                                                 break;
2683                                         case EGO_SEEING:
2684                                                 if (one_in_(7))
2685                                                 {
2686                                                         if (one_in_(2)) add_esp_strong(o_ptr);
2687                                                         else add_esp_weak(o_ptr, FALSE);
2688                                                 }
2689                                                 break;
2690                                         case EGO_LITE:
2691                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_1);
2692                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_2);
2693                                                 break;
2694                                         case EGO_H_DEMON:
2695                                                 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2696                                                 one_in_(3) ? 
2697                                                         add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2698                                                         one_in_(2) ?
2699                                                                 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2700                                                                 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2701                                                 
2702                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2703                                                 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2704                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2705                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2706                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2707                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2708                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2709                                                 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2710                                                 break;
2711                                         default:/* not existing helm (Magi, Might, etc...)*/
2712                                                 ok_flag = FALSE;
2713                                         }
2714                                         if (ok_flag)
2715                                                 break; /* while (1) */
2716                                 }
2717                                 break;
2718                         }
2719                         /* Very cursed */
2720                         else if (power < -1)
2721                         {
2722                                 while (1)
2723                                 {
2724                                         bool ok_flag = TRUE;
2725                                         o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2726
2727                                         switch (o_ptr->name2)
2728                                         {
2729                                           case EGO_ANCIENT_CURSE:
2730                                                 ok_flag = FALSE;
2731                                         }
2732                                         if (ok_flag)
2733                                                 break; /* while (1) */
2734                                 }
2735                         }
2736                         break;
2737                 }
2738
2739                 case TV_CLOAK:
2740                 {
2741                         /* Very good */
2742                         if (power > 1)
2743                         {
2744                                 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2745                                 {
2746                                         create_artifact(o_ptr, FALSE);
2747                                         break;
2748                                 }
2749                                 o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE);
2750
2751                                 switch (o_ptr->name2)
2752                                 {
2753                                 case EGO_BAT:
2754                                         o_ptr->to_d -= 6;
2755                                         o_ptr->to_h -= 6;
2756                                         break;
2757                                 case EGO_NAZGUL:
2758                                         o_ptr->to_d -= 3;
2759                                         o_ptr->to_h -= 3;
2760                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_COWARDICE);
2761                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CALL_UNDEAD);
2762                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_SLOW_REGEN);
2763                                         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2764                                         break;
2765                                 }
2766
2767                         }
2768
2769                         /* Very cursed */
2770                         else if (power < -1)
2771                         {
2772                                 o_ptr->name2 = get_random_ego(INVEN_OUTER, FALSE);
2773                         }
2774
2775                         break;
2776                 }
2777         }
2778
2779 }
2780
2781
2782 /*!
2783  * @brief 装飾品系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2784  * Apply magic to an item known to be a "ring" or "amulet"
2785  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2786  * @param level 生成基準階
2787  * @param power 生成ランク
2788  * @return なし
2789  * @details
2790  * Hack -- note special "pval boost" code for ring of speed\n
2791  * Hack -- note that some items must be cursed (or blessed)\n
2792  */
2793 static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
2794 {
2795         /* Apply magic (good or bad) according to type */
2796         switch (o_ptr->tval)
2797         {
2798                 case TV_RING:
2799                 {
2800                         /* Analyze */
2801                         switch (o_ptr->sval)
2802                         {
2803                                 case SV_RING_ATTACKS:
2804                                 {
2805                                         /* Stat bonus */
2806                                         o_ptr->pval = (PARAMETER_VALUE)m_bonus(2, level);
2807                                         if (one_in_(15)) o_ptr->pval++;
2808                                         if (o_ptr->pval < 1) o_ptr->pval = 1;
2809
2810                                         /* Cursed */
2811                                         if (power < 0)
2812                                         {
2813                                                 /* Broken */
2814                                                 o_ptr->ident |= (IDENT_BROKEN);
2815
2816                                                 /* Cursed */
2817                                                 o_ptr->curse_flags |= TRC_CURSED;
2818
2819                                                 /* Reverse pval */
2820                                                 o_ptr->pval = 0 - (o_ptr->pval);
2821                                         }
2822
2823                                         break;
2824                                 }
2825
2826                                 case SV_RING_SHOTS:
2827                                 {
2828                                         break;
2829                                 }
2830
2831                                 /* Strength, Constitution, Dexterity, Intelligence */
2832                                 case SV_RING_STR:
2833                                 case SV_RING_CON:
2834                                 case SV_RING_DEX:
2835                                 {
2836                                         /* Stat bonus */
2837                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2838
2839                                         /* Cursed */
2840                                         if (power < 0)
2841                                         {
2842                                                 /* Broken */
2843                                                 o_ptr->ident |= (IDENT_BROKEN);
2844
2845                                                 /* Cursed */
2846                                                 o_ptr->curse_flags |= TRC_CURSED;
2847
2848                                                 /* Reverse pval */
2849                                                 o_ptr->pval = 0 - (o_ptr->pval);
2850                                         }
2851
2852                                         break;
2853                                 }
2854
2855                                 /* Ring of Speed! */
2856                                 case SV_RING_SPEED:
2857                                 {
2858                                         /* Base speed (1 to 10) */
2859                                         o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
2860
2861                                         /* Super-charge the ring */
2862                                         while (randint0(100) < 50) o_ptr->pval++;
2863
2864                                         /* Cursed Ring */
2865                                         if (power < 0)
2866                                         {
2867                                                 /* Broken */
2868                                                 o_ptr->ident |= (IDENT_BROKEN);
2869
2870                                                 /* Cursed */
2871                                                 o_ptr->curse_flags |= TRC_CURSED;
2872
2873                                                 /* Reverse pval */
2874                                                 o_ptr->pval = 0 - (o_ptr->pval);
2875
2876                                                 break;
2877                                         }
2878
2879                                         break;
2880                                 }
2881
2882                                 case SV_RING_LORDLY:
2883                                 {
2884                                         do
2885                                         {
2886                                                 one_lordly_high_resistance(o_ptr);
2887                                         }
2888                                         while (one_in_(4));
2889
2890                                         /* Bonus to armor class */
2891                                         o_ptr->to_a = 10 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2892                                 }
2893                                 break;
2894
2895                                 case SV_RING_WARNING:
2896                                 {
2897                                         if (one_in_(3)) one_low_esp(o_ptr);
2898                                         break;
2899                                 }
2900
2901                                 /* Searching */
2902                                 case SV_RING_SEARCHING:
2903                                 {
2904                                         /* Bonus to searching */
2905                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2906
2907                                         /* Cursed */
2908                                         if (power < 0)
2909                                         {
2910                                                 /* Broken */
2911                                                 o_ptr->ident |= (IDENT_BROKEN);
2912
2913                                                 /* Cursed */
2914                                                 o_ptr->curse_flags |= TRC_CURSED;
2915
2916                                                 /* Reverse pval */
2917                                                 o_ptr->pval = 0 - (o_ptr->pval);
2918                                         }
2919
2920                                         break;
2921                                 }
2922
2923                                 /* Flames, Acid, Ice */
2924                                 case SV_RING_FLAMES:
2925                                 case SV_RING_ACID:
2926                                 case SV_RING_ICE:
2927                                 case SV_RING_ELEC:
2928                                 {
2929                                         /* Bonus to armor class */
2930                                         o_ptr->to_a = 5 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2931                                         break;
2932                                 }
2933
2934                                 /* Weakness, Stupidity */
2935                                 case SV_RING_WEAKNESS:
2936                                 case SV_RING_STUPIDITY:
2937                                 {
2938                                         /* Broken */
2939                                         o_ptr->ident |= (IDENT_BROKEN);
2940
2941                                         /* Cursed */
2942                                         o_ptr->curse_flags |= TRC_CURSED;
2943
2944                                         /* Penalize */
2945                                         o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2946                                         if (power > 0) power = 0 - power;
2947
2948                                         break;
2949                                 }
2950
2951                                 /* WOE, Stupidity */
2952                                 case SV_RING_WOE:
2953                                 {
2954                                         /* Broken */
2955                                         o_ptr->ident |= (IDENT_BROKEN);
2956
2957                                         /* Cursed */
2958                                         o_ptr->curse_flags |= TRC_CURSED;
2959
2960                                         /* Penalize */
2961                                         o_ptr->to_a = 0 - (5 + (ARMOUR_CLASS)m_bonus(10, level));
2962                                         o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2963                                         if (power > 0) power = 0 - power;
2964
2965                                         break;
2966                                 }
2967
2968                                 /* Ring of damage */
2969                                 case SV_RING_DAMAGE:
2970                                 {
2971                                         /* Bonus to damage */
2972                                         o_ptr->to_d = 1 + randint1(5) + (HIT_POINT)m_bonus(16, level);
2973
2974                                         /* Cursed */
2975                                         if (power < 0)
2976                                         {
2977                                                 /* Broken */
2978                                                 o_ptr->ident |= (IDENT_BROKEN);
2979
2980                                                 /* Cursed */
2981                                                 o_ptr->curse_flags |= TRC_CURSED;
2982
2983                                                 /* Reverse bonus */
2984                                                 o_ptr->to_d = 0 - o_ptr->to_d;
2985                                         }
2986
2987                                         break;
2988                                 }
2989
2990                                 /* Ring of Accuracy */
2991                                 case SV_RING_ACCURACY:
2992                                 {
2993                                         /* Bonus to hit */
2994                                         o_ptr->to_h = 1 + randint1(5) + (HIT_PROB)m_bonus(16, level);
2995
2996                                         /* Cursed */
2997                                         if (power < 0)
2998                                         {
2999                                                 /* Broken */
3000                                                 o_ptr->ident |= (IDENT_BROKEN);
3001
3002                                                 /* Cursed */
3003                                                 o_ptr->curse_flags |= TRC_CURSED;
3004
3005                                                 /* Reverse tohit */
3006                                                 o_ptr->to_h = 0 - o_ptr->to_h;
3007                                         }
3008
3009                                         break;
3010                                 }
3011
3012                                 /* Ring of Protection */
3013                                 case SV_RING_PROTECTION:
3014                                 {
3015                                         /* Bonus to armor class */
3016                                         o_ptr->to_a = 5 + randint1(8) + (ARMOUR_CLASS)m_bonus(10, level);
3017
3018                                         /* Cursed */
3019                                         if (power < 0)
3020                                         {
3021                                                 /* Broken */
3022                                                 o_ptr->ident |= (IDENT_BROKEN);
3023
3024                                                 /* Cursed */
3025                                                 o_ptr->curse_flags |= TRC_CURSED;
3026
3027                                                 /* Reverse toac */
3028                                                 o_ptr->to_a = 0 - o_ptr->to_a;
3029                                         }
3030
3031                                         break;
3032                                 }
3033
3034                                 /* Ring of Slaying */
3035                                 case SV_RING_SLAYING:
3036                                 {
3037                                         /* Bonus to damage and to hit */
3038                                         o_ptr->to_d = randint1(5) + (HIT_POINT)m_bonus(12, level);
3039                                         o_ptr->to_h = randint1(5) + (HIT_PROB)m_bonus(12, level);
3040
3041                                         /* Cursed */
3042                                         if (power < 0)
3043                                         {
3044                                                 /* Broken */
3045                                                 o_ptr->ident |= (IDENT_BROKEN);
3046
3047                                                 /* Cursed */
3048                                                 o_ptr->curse_flags |= TRC_CURSED;
3049
3050                                                 /* Reverse bonuses */
3051                                                 o_ptr->to_h = 0 - o_ptr->to_h;
3052                                                 o_ptr->to_d = 0 - o_ptr->to_d;
3053                                         }
3054
3055                                         break;
3056                                 }
3057
3058                                 case SV_RING_MUSCLE:
3059                                 {
3060                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(3, level);
3061                                         if (one_in_(4)) o_ptr->pval++;
3062
3063                                         /* Cursed */
3064                                         if (power < 0)
3065                                         {
3066                                                 /* Broken */
3067                                                 o_ptr->ident |= (IDENT_BROKEN);
3068
3069                                                 /* Cursed */
3070                                                 o_ptr->curse_flags |= TRC_CURSED;
3071
3072                                                 /* Reverse bonuses */
3073                                                 o_ptr->pval = 0 - o_ptr->pval;
3074                                         }
3075
3076                                         break;
3077                                 }
3078                                 case SV_RING_AGGRAVATION:
3079                                 {
3080                                         /* Broken */
3081                                         o_ptr->ident |= (IDENT_BROKEN);
3082
3083                                         /* Cursed */
3084                                         o_ptr->curse_flags |= TRC_CURSED;
3085
3086                                         if (power > 0) power = 0 - power;
3087                                         break;
3088                                 }
3089                         }
3090                         if ((one_in_(400) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3091                             || (power > 2)) /* power > 2 is debug only */
3092                         {
3093                                 o_ptr->pval = MIN(o_ptr->pval, 4);
3094                                 /* Randart amulet */
3095                                 create_artifact(o_ptr, FALSE);
3096                         }
3097                         else if ((power == 2) && one_in_(2))
3098                         {
3099                                 while(!o_ptr->name2)
3100                                 {
3101                                         int tmp = m_bonus(10, level);
3102                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3103                                         switch(randint1(28))
3104                                         {
3105                                         case 1: case 2:
3106                                                 o_ptr->name2 = EGO_RING_THROW;
3107                                                 break;
3108                                         case 3: case 4:
3109                                                 if (have_flag(k_ptr->flags, TR_REGEN)) break;
3110                                                 o_ptr->name2 = EGO_RING_REGEN;
3111                                                 break;
3112                                         case 5: case 6:
3113                                                 if (have_flag(k_ptr->flags, TR_LITE_1)) break;
3114                                                 o_ptr->name2 = EGO_RING_LITE;
3115                                                 break;
3116                                         case 7: case 8:
3117                                                 if (have_flag(k_ptr->flags, TR_TELEPORT)) break;
3118                                                 o_ptr->name2 = EGO_RING_TELEPORT;
3119                                                 break;
3120                                         case 9: case 10:
3121                                                 if (o_ptr->to_h) break;
3122                                                 o_ptr->name2 = EGO_RING_TO_H;
3123                                                 break;
3124                                         case 11: case 12:
3125                                                 if (o_ptr->to_d) break;
3126                                                 o_ptr->name2 = EGO_RING_TO_D;
3127                                                 break;
3128                                         case 13:
3129                                                 if ((o_ptr->to_h) || (o_ptr->to_d)) break;
3130                                                 o_ptr->name2 = EGO_RING_SLAY;
3131                                                 break;
3132                                         case 14:
3133                                                 if ((have_flag(k_ptr->flags, TR_STR)) || o_ptr->to_h || o_ptr->to_d) break;
3134                                                 o_ptr->name2 = EGO_RING_WIZARD;
3135                                                 break;
3136                                         case 15:
3137                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3138                                                 o_ptr->name2 = EGO_RING_HERO;
3139                                                 break;
3140                                         case 16:
3141                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3142                                                 if (tmp > 8) o_ptr->name2 = EGO_RING_MANA_BALL;
3143                                                 else if (tmp > 4) o_ptr->name2 = EGO_RING_MANA_BOLT;
3144                                                 else o_ptr->name2 = EGO_RING_MAGIC_MIS;
3145                                                 break;
3146                                         case 17:
3147                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3148                                                 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;
3149                                                 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_F;
3150                                                 else if (tmp > 3) o_ptr->name2 = EGO_RING_FIRE_BALL;
3151                                                 else o_ptr->name2 = EGO_RING_FIRE_BOLT;
3152                                                 break;
3153                                         case 18:
3154                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3155                                                 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;
3156                                                 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_C;
3157                                                 else if (tmp > 3) o_ptr->name2 = EGO_RING_COLD_BALL;
3158                                                 else o_ptr->name2 = EGO_RING_COLD_BOLT;
3159                                                 break;
3160                                         case 19:
3161                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3162                                                 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;
3163                                                 if (tmp > 4) o_ptr->name2 = EGO_RING_ELEC_BALL;
3164                                                 else o_ptr->name2 = EGO_RING_ELEC_BOLT;
3165                                                 break;
3166                                         case 20:
3167                                                 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3168                                                 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;
3169                                                 if (tmp > 4) o_ptr->name2 = EGO_RING_ACID_BALL;
3170                                                 else o_ptr->name2 = EGO_RING_ACID_BOLT;
3171                                                 break;
3172                                         case 21: case 22: case 23: case 24: case 25: case 26:
3173                                                 switch (o_ptr->sval)
3174                                                 {
3175                                                 case SV_RING_SPEED:
3176                                                         if (!one_in_(3)) break;
3177                                                         o_ptr->name2 = EGO_RING_D_SPEED;
3178                                                         break;
3179                                                 case SV_RING_DAMAGE:
3180                                                 case SV_RING_ACCURACY:
3181                                                 case SV_RING_SLAYING:
3182                                                         if (one_in_(2)) break;
3183                                                         if (one_in_(2)) o_ptr->name2 = EGO_RING_HERO;
3184                                                         else
3185                                                         {
3186                                                                 o_ptr->name2 = EGO_RING_BERSERKER;
3187                                                                 o_ptr->to_h -= 2+randint1(4);
3188                                                                 o_ptr->to_d += 2+randint1(4);
3189                                                         }
3190                                                         break;
3191                                                 case SV_RING_PROTECTION:
3192                                                         o_ptr->name2 = EGO_RING_SUPER_AC;
3193                                                         o_ptr->to_a += 7 + m_bonus(5, level);
3194                                                         break;
3195                                                 case SV_RING_RES_FEAR:
3196                                                         o_ptr->name2 = EGO_RING_HERO;
3197                                                         break;
3198                                                 case SV_RING_SHOTS:
3199                                                         if (one_in_(2)) break;
3200                                                         o_ptr->name2 = EGO_RING_HUNTER;
3201                                                         break;
3202                                                 case SV_RING_SEARCHING:
3203                                                         o_ptr->name2 = EGO_RING_STEALTH;
3204                                                         break;
3205                                                 case SV_RING_TELEPORTATION:
3206                                                         o_ptr->name2 = EGO_RING_TELE_AWAY;
3207                                                         break;
3208                                                 case SV_RING_RES_BLINDNESS:
3209                                                         if (one_in_(2))
3210                                                                 o_ptr->name2 = EGO_RING_RES_LITE;
3211                                                         else
3212                                                                 o_ptr->name2 = EGO_RING_RES_DARK;
3213                                                         break;
3214                                                 case SV_RING_LORDLY:
3215                                                         if (!one_in_(20)) break;
3216                                                         one_lordly_high_resistance(o_ptr);
3217                                                         one_lordly_high_resistance(o_ptr);
3218                                                         o_ptr->name2 = EGO_RING_TRUE;
3219                                                         break;
3220                                                 case SV_RING_SUSTAIN:
3221                                                         if (!one_in_(4)) break;
3222                                                         o_ptr->name2 = EGO_RING_RES_TIME;
3223                                                         break;
3224                                                 case SV_RING_FLAMES:
3225                                                         if (!one_in_(2)) break;
3226                                                         o_ptr->name2 = EGO_RING_DRAGON_F;
3227                                                         break;
3228                                                 case SV_RING_ICE:
3229                                                         if (!one_in_(2)) break;
3230                                                         o_ptr->name2 = EGO_RING_DRAGON_C;
3231                                                         break;
3232                                                 case SV_RING_WARNING:
3233                                                         if (!one_in_(2)) break;
3234                                                         o_ptr->name2 = EGO_RING_M_DETECT;
3235                                                         break;
3236                                                 default:
3237                                                         break;
3238                                                 }
3239                                                 break;
3240                                         }
3241                                 }
3242                                 o_ptr->curse_flags = 0L;
3243                         }
3244                         else if ((power == -2) && one_in_(2))
3245                         {
3246                                 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3247                                 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3248                                 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3249                                 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3250                                 o_ptr->art_flags[0] = 0;
3251                                 o_ptr->art_flags[1] = 0;
3252                                 while(!o_ptr->name2)
3253                                 {
3254                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3255                                         switch(randint1(5))
3256                                         {
3257                                         case 1:
3258                                                 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3259                                                 o_ptr->name2 = EGO_RING_DRAIN_EXP;
3260                                                 break;
3261                                         case 2:
3262                                                 o_ptr->name2 = EGO_RING_NO_MELEE;
3263                                                 break;
3264                                         case 3:
3265                                                 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3266                                                 o_ptr->name2 = EGO_RING_AGGRAVATE;
3267                                                 break;
3268                                         case 4:
3269                                                 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3270                                                 o_ptr->name2 = EGO_RING_TY_CURSE;
3271                                                 break;
3272                                         case 5:
3273                                                 o_ptr->name2 = EGO_RING_ALBINO;
3274                                                 break;
3275                                         }
3276                                 }
3277                                 /* Broken */
3278                                 o_ptr->ident |= (IDENT_BROKEN);
3279
3280                                 /* Cursed */
3281                                 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3282                         }
3283                         break;
3284                 }
3285
3286                 case TV_AMULET:
3287                 {
3288                         /* Analyze */
3289                         switch (o_ptr->sval)
3290                         {
3291                                 /* Amulet of wisdom/charisma */
3292                                 case SV_AMULET_INTELLIGENCE:
3293                                 case SV_AMULET_WISDOM:
3294                                 case SV_AMULET_CHARISMA:
3295                                 {
3296                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
3297
3298                                         /* Cursed */
3299                                         if (power < 0)
3300                                         {
3301                                                 /* Broken */
3302                                                 o_ptr->ident |= (IDENT_BROKEN);
3303
3304                                                 /* Cursed */
3305                                                 o_ptr->curse_flags |= (TRC_CURSED);
3306
3307                                                 /* Reverse bonuses */
3308                                                 o_ptr->pval = 0 - o_ptr->pval;
3309                                         }
3310
3311                                         break;
3312                                 }
3313
3314                                 /* Amulet of brilliance */
3315                                 case SV_AMULET_BRILLIANCE:
3316                                 {
3317                                         o_ptr->pval = 1 + m_bonus(3, level);
3318                                         if (one_in_(4)) o_ptr->pval++;
3319
3320                                         /* Cursed */
3321                                         if (power < 0)
3322                                         {
3323                                                 /* Broken */
3324                                                 o_ptr->ident |= (IDENT_BROKEN);
3325
3326                                                 /* Cursed */
3327                                                 o_ptr->curse_flags |= (TRC_CURSED);
3328
3329                                                 /* Reverse bonuses */
3330                                                 o_ptr->pval = 0 - o_ptr->pval;
3331                                         }
3332
3333                                         break;
3334                                 }
3335
3336                                 case SV_AMULET_NO_MAGIC: case SV_AMULET_NO_TELE:
3337                                 {
3338                                         if (power < 0)
3339                                         {
3340                                                 o_ptr->curse_flags |= (TRC_CURSED);
3341                                         }
3342                                         break;
3343                                 }
3344
3345                                 case SV_AMULET_RESISTANCE:
3346                                 {
3347                                         if (one_in_(5)) one_high_resistance(o_ptr);
3348                                         if (one_in_(5)) add_flag(o_ptr->art_flags, TR_RES_POIS);
3349                                 }
3350                                 break;
3351
3352                                 /* Amulet of searching */
3353                                 case SV_AMULET_SEARCHING:
3354                                 {
3355                                         o_ptr->pval = randint1(2) + (PARAMETER_VALUE)m_bonus(4, level);
3356
3357                                         /* Cursed */
3358                                         if (power < 0)
3359                                         {
3360                                                 /* Broken */
3361                                                 o_ptr->ident |= (IDENT_BROKEN);
3362
3363                                                 /* Cursed */
3364                                                 o_ptr->curse_flags |= (TRC_CURSED);
3365
3366                                                 /* Reverse bonuses */
3367                                                 o_ptr->pval = 0 - (o_ptr->pval);
3368                                         }
3369
3370                                         break;
3371                                 }
3372
3373                                 /* Amulet of the Magi -- never cursed */
3374                                 case SV_AMULET_THE_MAGI:
3375                                 {
3376                                         o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
3377                                         o_ptr->to_a = randint1(5) + (ARMOUR_CLASS)m_bonus(5, level);
3378
3379                                         /* gain one low ESP */
3380                                         add_esp_weak(o_ptr, FALSE);
3381
3382                                         break;
3383                                 }
3384
3385                                 /* Amulet of Doom -- always cursed */
3386                                 case SV_AMULET_DOOM:
3387                                 {
3388                                         /* Broken */
3389                                         o_ptr->ident |= (IDENT_BROKEN);
3390
3391                                         /* Cursed */
3392                                         o_ptr->curse_flags |= (TRC_CURSED);
3393
3394                                         /* Penalize */
3395                                         o_ptr->pval = 0 - (randint1(5) + (PARAMETER_VALUE)m_bonus(5, level));
3396                                         o_ptr->to_a = 0 - (randint1(5) + (ARMOUR_CLASS)m_bonus(5, level));
3397                                         if (power > 0) power = 0 - power;
3398
3399                                         break;
3400                                 }
3401
3402                                 case SV_AMULET_MAGIC_MASTERY:
3403                                 {
3404                                         o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(4, level);
3405
3406                                         /* Cursed */
3407                                         if (power < 0)
3408                                         {
3409                                                 /* Broken */
3410                                                 o_ptr->ident |= (IDENT_BROKEN);
3411
3412                                                 /* Cursed */
3413                                                 o_ptr->curse_flags |= (TRC_CURSED);
3414
3415                                                 /* Reverse bonuses */
3416                                                 o_ptr->pval = 0 - o_ptr->pval;
3417                                         }
3418
3419                                         break;
3420                                 }
3421                         }
3422                         if ((one_in_(150) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3423                             || (power > 2)) /* power > 2 is debug only */
3424                         {
3425                                 o_ptr->pval = MIN(o_ptr->pval, 4);
3426                                 /* Randart amulet */
3427                                 create_artifact(o_ptr, FALSE);
3428                         }
3429                         else if ((power == 2) && one_in_(2))
3430                         {
3431                                 while(!o_ptr->name2)
3432                                 {
3433                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3434                                         switch(randint1(21))
3435                                         {
3436                                         case 1: case 2:
3437                                                 if (have_flag(k_ptr->flags, TR_SLOW_DIGEST)) break;
3438                                                 o_ptr->name2 = EGO_AMU_SLOW_D;
3439                                                 break;
3440                                         case 3: case 4:
3441                                                 if (o_ptr->pval) break;
3442                                                 o_ptr->name2 = EGO_AMU_INFRA;
3443                                                 break;
3444                                         case 5: case 6:
3445                                                 if (have_flag(k_ptr->flags, TR_SEE_INVIS)) break;
3446                                                 o_ptr->name2 = EGO_AMU_SEE_INVIS;
3447                                                 break;
3448                                         case 7: case 8:
3449                                                 if (have_flag(k_ptr->flags, TR_HOLD_EXP)) break;
3450                                                 o_ptr->name2 = EGO_AMU_HOLD_EXP;
3451                                                 break;
3452                                         case 9:
3453                                                 if (have_flag(k_ptr->flags, TR_LEVITATION)) break;
3454                                                 o_ptr->name2 = EGO_AMU_LEVITATION;
3455                                                 break;
3456                                         case 10: case 11: case 21:
3457                                                 o_ptr->name2 = EGO_AMU_AC;
3458                                                 break;
3459                                         case 12:
3460                                                 if (have_flag(k_ptr->flags, TR_RES_FIRE)) break;
3461                                                 if (m_bonus(10, level) > 8)
3462                                                         o_ptr->name2 = EGO_AMU_RES_FIRE_;
3463                                                 else
3464                                                         o_ptr->name2 = EGO_AMU_RES_FIRE;
3465                                                 break;
3466                                         case 13:
3467                                                 if (have_flag(k_ptr->flags, TR_RES_COLD)) break;
3468                                                 if (m_bonus(10, level) > 8)
3469                                                         o_ptr->name2 = EGO_AMU_RES_COLD_;
3470                                                 else
3471                                                         o_ptr->name2 = EGO_AMU_RES_COLD;
3472                                                 break;
3473                                         case 14:
3474                                                 if (have_flag(k_ptr->flags, TR_RES_ELEC)) break;
3475                                                 if (m_bonus(10, level) > 8)
3476                                                         o_ptr->name2 = EGO_AMU_RES_ELEC_;
3477                                                 else
3478                                                         o_ptr->name2 = EGO_AMU_RES_ELEC;
3479                                                 break;
3480                                         case 15:
3481                                                 if (have_flag(k_ptr->flags, TR_RES_ACID)) break;
3482                                                 if (m_bonus(10, level) > 8)
3483                                                         o_ptr->name2 = EGO_AMU_RES_ACID_;
3484                                                 else
3485                                                         o_ptr->name2 = EGO_AMU_RES_ACID;
3486                                                 break;
3487                                         case 16: case 17: case 18: case 19: case 20:
3488                                                 switch (o_ptr->sval)
3489                                                 {
3490                                                 case SV_AMULET_TELEPORT:
3491                                                         if (m_bonus(10, level) > 9) o_ptr->name2 = EGO_AMU_D_DOOR;
3492                                                         else if (one_in_(2)) o_ptr->name2 = EGO_AMU_JUMP;
3493                                                         else o_ptr->name2 = EGO_AMU_TELEPORT;
3494                                                         break;
3495                                                 case SV_AMULET_RESIST_ACID:
3496                                                         if ((m_bonus(10, level) > 6) && one_in_(2)) o_ptr->name2 = EGO_AMU_RES_ACID_;
3497                                                         break;
3498                                                 case SV_AMULET_SEARCHING:
3499                                                         o_ptr->name2 = EGO_AMU_STEALTH;
3500                                                         break;
3501                                                 case SV_AMULET_BRILLIANCE:
3502                                                         if (!one_in_(3)) break;
3503                                                         o_ptr->name2 = EGO_AMU_IDENT;
3504                                                         break;
3505                                                 case SV_AMULET_CHARISMA:
3506                                                         if (!one_in_(3)) break;
3507                                                         o_ptr->name2 = EGO_AMU_CHARM;
3508                                                         break;
3509                                                 case SV_AMULET_THE_MAGI:
3510                                                         if (one_in_(2)) break;
3511                                                         o_ptr->name2 = EGO_AMU_GREAT;
3512                                                         break;
3513                                                 case SV_AMULET_RESISTANCE:
3514                                                         if (!one_in_(5)) break;
3515                                                         o_ptr->name2 = EGO_AMU_DEFENDER;
3516                                                         break;
3517                                                 case SV_AMULET_TELEPATHY:
3518                                                         if (!one_in_(3)) break;
3519                                                         o_ptr->name2 = EGO_AMU_DETECTION;
3520                                                         break;
3521                                                 }
3522                                         }
3523                                 }
3524                                 o_ptr->curse_flags = 0L;
3525                         }
3526                         else if ((power == -2) && one_in_(2))
3527                         {
3528                                 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3529                                 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3530                                 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3531                                 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3532                                 o_ptr->art_flags[0] = 0;
3533                                 o_ptr->art_flags[1] = 0;
3534                                 while(!o_ptr->name2)
3535                                 {
3536                                         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3537                                         switch(randint1(5))
3538                                         {
3539                                         case 1:
3540                                                 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3541                                                 o_ptr->name2 = EGO_AMU_DRAIN_EXP;
3542                                                 break;
3543                                         case 2:
3544                                                 o_ptr->name2 = EGO_AMU_FOOL;
3545                                                 break;
3546                                         case 3:
3547                                                 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3548                                                 o_ptr->name2 = EGO_AMU_AGGRAVATE;
3549                                                 break;
3550                                         case 4:
3551                                                 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3552                                                 o_ptr->name2 = EGO_AMU_TY_CURSE;
3553                                                 break;
3554                                         case 5:
3555                                                 o_ptr->name2 = EGO_AMU_NAIVETY;
3556                                                 break;
3557                                         }
3558                                 }
3559                                 /* Broken */
3560                                 o_ptr->ident |= (IDENT_BROKEN);
3561
3562                                 /* Cursed */
3563                                 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3564                         }
3565                         break;
3566                 }
3567         }
3568 }
3569
3570
3571 /*!
3572  * @brief その他雑多のオブジェクトに生成ランクごとの強化を与えるサブルーチン
3573  * Apply magic to an item known to be "boring"
3574  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3575  * @param level 生成基準階
3576  * @param power 生成ランク
3577  * @return なし
3578  * @details
3579  * Hack -- note the special code for various items
3580  */
3581 static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
3582 {
3583         object_kind *k_ptr = &k_info[o_ptr->k_idx];
3584
3585         /* Unused */
3586         (void)level;
3587
3588         /* Apply magic (good or bad) according to type */
3589         switch (o_ptr->tval)
3590         {
3591                 case TV_WHISTLE:
3592                 {
3593 #if 0
3594                         /* Cursed */
3595                         if (power < 0)
3596                         {
3597                                 /* Broken */
3598                                 o_ptr->ident |= (IDENT_BROKEN);
3599
3600                                 /* Cursed */
3601                                 o_ptr->curse_flags |= (TRC_CURSED);
3602                         }
3603 #endif
3604                         break;
3605                 }
3606                 case TV_FLASK:
3607                 {
3608                         o_ptr->xtra4 = o_ptr->pval;
3609                         o_ptr->pval = 0;
3610                         break;
3611                 }
3612                 case TV_LITE:
3613                 {
3614                         /* Hack -- Torches -- random fuel */
3615                         if (o_ptr->sval == SV_LITE_TORCH)
3616                         {
3617                                 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3618                                 o_ptr->pval = 0;
3619                         }
3620
3621                         /* Hack -- Lanterns -- random fuel */
3622                         if (o_ptr->sval == SV_LITE_LANTERN)
3623                         {
3624                                 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3625                                 o_ptr->pval = 0;
3626                         }
3627
3628                         if (power > 2) /* power > 2 is debug only */
3629                         {
3630                                 create_artifact(o_ptr, FALSE);
3631                         }
3632                         else if ((power == 2) || ((power == 1) && one_in_(3)))
3633                         {
3634                                 while (!o_ptr->name2)
3635                                 {
3636                                         while (1)
3637                                         {
3638                                                 bool okay_flag = TRUE;
3639
3640                                                 o_ptr->name2 = get_random_ego(INVEN_LITE, TRUE);
3641
3642                                                 switch (o_ptr->name2)
3643                                                 {
3644                                                 case EGO_LITE_LONG:
3645                                                         if (o_ptr->sval == SV_LITE_FEANOR)
3646                                                                 okay_flag = FALSE;
3647                                                 }
3648                                                 if (okay_flag)
3649                                                         break;
3650                                         }
3651                                 }
3652                         }
3653                         else if (power == -2)
3654                         {
3655                                 o_ptr->name2 = get_random_ego(INVEN_LITE, FALSE);
3656
3657                                 switch (o_ptr->name2)
3658                                 {
3659                                 case EGO_LITE_DARKNESS:
3660                                         o_ptr->xtra4 = 0;
3661                                         
3662                                         if (o_ptr->sval == SV_LITE_TORCH)
3663                                         {
3664                                                 add_flag(o_ptr->art_flags, TR_LITE_M1);
3665                                         }
3666                                         else if (o_ptr->sval == SV_LITE_LANTERN)
3667                                         {
3668                                                 add_flag(o_ptr->art_flags, TR_LITE_M2);
3669                                         }
3670                                         else if (o_ptr->sval == SV_LITE_FEANOR)
3671                                         {
3672                                                 add_flag(o_ptr->art_flags, TR_LITE_M3);
3673                                         }
3674                                         break;
3675                                 }
3676                         }
3677
3678                         break;
3679                 }
3680
3681                 case TV_WAND:
3682                 case TV_STAFF:
3683                 {
3684                         /* The wand or staff gets a number of initial charges equal
3685                          * to between 1/2 (+1) and the full object kind's pval. -LM-
3686                          */
3687                         o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
3688                         break;
3689                 }
3690
3691                 case TV_ROD:
3692                 {
3693                         /* Transfer the pval. -LM- */
3694                         o_ptr->pval = k_ptr->pval;
3695                         break;
3696                 }
3697
3698                 case TV_CAPTURE:
3699                 {
3700                         o_ptr->pval = 0;
3701                         object_aware(o_ptr);
3702                         object_known(o_ptr);
3703                         break;
3704                 }
3705
3706                 case TV_FIGURINE:
3707                 {
3708                         PARAMETER_VALUE i = 1;
3709                         int check;
3710
3711                         monster_race *r_ptr;
3712
3713                         /* Pick a random non-unique monster race */
3714                         while (1)
3715                         {
3716                                 i = randint1(max_r_idx - 1);
3717
3718                                 if (!item_monster_okay(i)) continue;
3719                                 if (i == MON_TSUCHINOKO) continue;
3720
3721                                 r_ptr = &r_info[i];
3722
3723                                 check = (current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - current_floor_ptr->dun_level) : 0;
3724
3725                                 /* Ignore dead monsters */
3726                                 if (!r_ptr->rarity) continue;
3727
3728                                 /* Ignore uncommon monsters */
3729                                 if (r_ptr->rarity > 100) continue;
3730
3731                                 /* Prefer less out-of-depth monsters */
3732                                 if (randint0(check)) continue;
3733
3734                                 break;
3735                         }
3736
3737                         o_ptr->pval = i;
3738
3739                         /* Some figurines are cursed */
3740                         if (one_in_(6)) o_ptr->curse_flags |= TRC_CURSED;
3741
3742                         break;
3743                 }
3744
3745                 case TV_CORPSE:
3746                 {
3747                         PARAMETER_VALUE i = 1;
3748                         int check;
3749
3750                         u32b match = 0;
3751
3752                         monster_race *r_ptr;
3753
3754                         if (o_ptr->sval == SV_SKELETON)
3755                         {
3756                                 match = RF9_DROP_SKELETON;
3757                         }
3758                         else if (o_ptr->sval == SV_CORPSE)
3759                         {
3760                                 match = RF9_DROP_CORPSE;
3761                         }
3762
3763                         /* Hack -- Remove the monster restriction */
3764                         get_mon_num_prep(item_monster_okay, NULL);
3765
3766                         /* Pick a random non-unique monster race */
3767                         while (1)
3768                         {
3769                                 i = get_mon_num(current_floor_ptr->dun_level);
3770
3771                                 r_ptr = &r_info[i];
3772
3773                                 check = (current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - current_floor_ptr->dun_level) : 0;
3774
3775                                 /* Ignore dead monsters */
3776                                 if (!r_ptr->rarity) continue;
3777
3778                                 /* Ignore corpseless monsters */
3779                                 if (!(r_ptr->flags9 & match)) continue;
3780
3781                                 /* Prefer less out-of-depth monsters */
3782                                 if (randint0(check)) continue;
3783
3784                                 break;
3785                         }
3786
3787                         o_ptr->pval = i;
3788
3789
3790                         object_aware(o_ptr);
3791                         object_known(o_ptr);
3792                         break;
3793                 }
3794
3795                 case TV_STATUE:
3796                 {
3797                         PARAMETER_VALUE i = 1;
3798
3799                         monster_race *r_ptr;
3800
3801                         /* Pick a random monster race */
3802                         while (1)
3803                         {
3804                                 i = randint1(max_r_idx - 1);
3805
3806                                 r_ptr = &r_info[i];
3807
3808                                 /* Ignore dead monsters */
3809                                 if (!r_ptr->rarity) continue;
3810
3811                                 break;
3812                         }
3813
3814                         o_ptr->pval = i;
3815
3816                         if (cheat_peek)
3817                         {
3818                                 msg_format(_("%sの像", "Statue of %s"), r_name + r_ptr->name);
3819                         }
3820                         object_aware(o_ptr);
3821                         object_known(o_ptr);
3822
3823                         break;
3824                 }
3825
3826                 case TV_CHEST:
3827                 {
3828                         DEPTH obj_level = k_info[o_ptr->k_idx].level;
3829
3830                         /* Hack -- skip ruined chests */
3831                         if (obj_level <= 0) break;
3832
3833                         /* Hack -- pick a "difficulty" */
3834                         o_ptr->pval = randint1(obj_level);
3835                         if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
3836
3837                         o_ptr->xtra3 = current_floor_ptr->dun_level + 5;
3838
3839                         /* Never exceed "difficulty" of 55 to 59 */
3840                         if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
3841
3842                         break;
3843                 }
3844         }
3845 }
3846
3847 /*!
3848  * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
3849  * Complete the "creation" of an object by applying "magic" to the item
3850  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3851  * @param lev 生成基準階
3852  * @param mode 生成オプション
3853  * @return なし
3854  * @details
3855  * This includes not only rolling for random bonuses, but also putting the\n
3856  * finishing touches on ego-items and artifacts, giving charges to wands and\n
3857  * staffs, giving fuel to lites, and placing traps on chests.\n
3858  *\n
3859  * In particular, note that "Instant Artifacts", if "created" by an external\n
3860  * routine, must pass through this function to complete the actual creation.\n
3861  *\n
3862  * The base "chance" of the item being "good" increases with the "level"\n
3863  * parameter, which is usually derived from the dungeon level, being equal\n
3864  * to the level plus 10, up to a maximum of 75.  If "good" is true, then\n
3865  * the object is guaranteed to be "good".  If an object is "good", then\n
3866  * the chance that the object will be "great" (ego-item or artifact), also\n
3867  * increases with the "level", being equal to half the level, plus 5, up to\n
3868  * a maximum of 20.  If "great" is true, then the object is guaranteed to be\n
3869  * "great".  At dungeon level 65 and below, 15/100 objects are "great".\n
3870  *\n
3871  * If the object is not "good", there is a chance it will be "cursed", and\n
3872  * if it is "cursed", there is a chance it will be "broken".  These chances\n
3873  * are related to the "good" / "great" chances above.\n
3874  *\n
3875  * Otherwise "normal" rings and amulets will be "good" half the time and\n
3876  * "cursed" half the time, unless the ring/amulet is always good or cursed.\n
3877  *\n
3878  * If "okay" is true, and the object is going to be "great", then there is\n
3879  * a chance that an artifact will be created.  This is true even if both the\n
3880  * "good" and "great" arguments are false.  As a total hack, if "great" is\n
3881  * true, then the item gets 3 extra "attempts" to become an artifact.\n
3882  */
3883 void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
3884 {
3885         int i, rolls, f1, f2, power;
3886
3887         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) lev += randint0(p_ptr->lev/2+10);
3888
3889         /* Maximum "level" for various things */
3890         if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1;
3891
3892         /* Base chance of being "good" */
3893         f1 = lev + 10;
3894
3895         /* Maximal chance of being "good" */
3896         if (f1 > d_info[p_ptr->dungeon_idx].obj_good) f1 = d_info[p_ptr->dungeon_idx].obj_good;
3897
3898         /* Base chance of being "great" */
3899         f2 = f1 * 2 / 3;
3900
3901         /* Maximal chance of being "great" */
3902         if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[p_ptr->dungeon_idx].obj_great))
3903                 f2 = d_info[p_ptr->dungeon_idx].obj_great;
3904
3905         if (p_ptr->muta3 & MUT3_GOOD_LUCK)
3906         {
3907                 f1 += 5;
3908                 f2 += 2;
3909         }
3910         else if(p_ptr->muta3 & MUT3_BAD_LUCK)
3911         {
3912                 f1 -= 5;
3913                 f2 -= 2;
3914         }
3915
3916         /* Assume normal */
3917         power = 0;
3918
3919         /* Roll for "good" */
3920         if ((mode & AM_GOOD) || magik(f1))
3921         {
3922                 /* Assume "good" */
3923                 power = 1;
3924
3925                 /* Roll for "great" */
3926                 if ((mode & AM_GREAT) || magik(f2))
3927                 {
3928                         power = 2;
3929
3930                         /* Roll for "special" */
3931                         if (mode & AM_SPECIAL) power = 3;
3932                 }
3933         }
3934
3935         /* Roll for "cursed" */
3936         else if (magik(f1))
3937         {
3938                 /* Assume "cursed" */
3939                 power = -1;
3940
3941                 /* Roll for "broken" */
3942                 if (magik(f2)) power = -2;
3943         }
3944
3945         /* Apply curse */
3946         if (mode & AM_CURSED)
3947         {
3948                 /* Assume 'cursed' */
3949                 if (power > 0)
3950                 {
3951                         power = 0 - power;
3952                 }
3953                 /* Everything else gets more badly cursed */
3954                 else
3955                 {
3956                         power--;
3957                 }
3958         }
3959
3960         /* Assume no rolls */
3961         rolls = 0;
3962
3963         /* Get one roll if excellent */
3964         if (power >= 2) rolls = 1;
3965
3966         /* Hack -- Get four rolls if forced great or special */
3967         if (mode & (AM_GREAT | AM_SPECIAL)) rolls = 4;
3968
3969         /* Hack -- Get no rolls if not allowed */
3970         if ((mode & AM_NO_FIXED_ART) || o_ptr->name1) rolls = 0;
3971
3972         /* Roll for artifacts if allowed */
3973         for (i = 0; i < rolls; i++)
3974         {
3975                 /* Roll for an artifact */
3976                 if (make_artifact(o_ptr)) break;
3977                 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77))
3978                 {
3979                         if (make_artifact(o_ptr)) break;
3980                 }
3981         }
3982
3983
3984         /* Hack -- analyze artifacts */
3985         if (object_is_fixed_artifact(o_ptr))
3986         {
3987                 artifact_type *a_ptr = &a_info[o_ptr->name1];
3988
3989                 /* Hack -- Mark the artifact as "created" */
3990                 a_ptr->cur_num = 1;
3991
3992                 /* Hack -- Memorize location of artifact in saved floors */
3993                 if (character_dungeon)
3994                         a_ptr->floor_id = p_ptr->floor_id;
3995
3996                 /* Extract the other fields */
3997                 o_ptr->pval = a_ptr->pval;
3998                 o_ptr->ac = a_ptr->ac;
3999                 o_ptr->dd = a_ptr->dd;
4000                 o_ptr->ds = a_ptr->ds;
4001                 o_ptr->to_a = a_ptr->to_a;
4002                 o_ptr->to_h = a_ptr->to_h;
4003                 o_ptr->to_d = a_ptr->to_d;
4004                 o_ptr->weight = a_ptr->weight;
4005                 o_ptr->xtra2 = a_ptr->act_idx;
4006
4007                 if (o_ptr->name1 == ART_MILIM)
4008                 {
4009                     if(p_ptr->pseikaku == SEIKAKU_SEXY)
4010                     {
4011                         o_ptr->pval = 3;
4012                     }
4013                 }
4014
4015                 /* Hack -- extract the "broken" flag */
4016                 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4017
4018                 /* Hack -- extract the "cursed" flag */
4019                 if (a_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4020                 if (a_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4021                 if (a_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4022                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4023                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4024                 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4025
4026                 return;
4027         }
4028
4029         switch (o_ptr->tval)
4030         {
4031                 case TV_DIGGING:
4032                 case TV_HAFTED:
4033                 case TV_BOW:
4034                 case TV_SHOT:
4035                 case TV_ARROW:
4036                 case TV_BOLT:
4037                 {
4038                         if (power) apply_magic_weapon(o_ptr, lev, power);
4039                         break;
4040                 }
4041
4042                 case TV_POLEARM:
4043                 {
4044                         if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) apply_magic_weapon(o_ptr, lev, power);
4045                         break;
4046                 }
4047
4048                 case TV_SWORD:
4049                 {
4050                         if (power && !(o_ptr->sval == SV_DOKUBARI)) apply_magic_weapon(o_ptr, lev, power);
4051                         break;
4052                 }
4053
4054                 case TV_DRAG_ARMOR:
4055                 case TV_HARD_ARMOR:
4056                 case TV_SOFT_ARMOR:
4057                 case TV_SHIELD:
4058                 case TV_HELM:
4059                 case TV_CROWN:
4060                 case TV_CLOAK:
4061                 case TV_GLOVES:
4062                 case TV_BOOTS:
4063                 {
4064                         /* Elven Cloak and Black Clothes ... */
4065                         if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) ||
4066                             ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
4067                                 o_ptr->pval = randint1(4);
4068
4069 #if 1
4070                         if (power ||
4071                              ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) ||
4072                              ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD)) ||
4073                              ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)) ||
4074                              ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
4075                                 a_m_aux_2(o_ptr, lev, power);
4076 #else
4077                         if (power) a_m_aux_2(o_ptr, lev, power);
4078 #endif
4079                         break;
4080                 }
4081
4082                 case TV_RING:
4083                 case TV_AMULET:
4084                 {
4085                         if (!power && (randint0(100) < 50)) power = -1;
4086                         a_m_aux_3(o_ptr, lev, power);
4087                         break;
4088                 }
4089
4090                 default:
4091                 {
4092                         a_m_aux_4(o_ptr, lev, power);
4093                         break;
4094                 }
4095         }
4096
4097         if ((o_ptr->tval == TV_SOFT_ARMOR) &&
4098             (o_ptr->sval == SV_ABUNAI_MIZUGI) &&
4099             (p_ptr->pseikaku == SEIKAKU_SEXY))
4100         {
4101                 o_ptr->pval = 3;
4102                 add_flag(o_ptr->art_flags, TR_STR);
4103                 add_flag(o_ptr->art_flags, TR_INT);
4104                 add_flag(o_ptr->art_flags, TR_WIS);
4105                 add_flag(o_ptr->art_flags, TR_DEX);
4106                 add_flag(o_ptr->art_flags, TR_CON);
4107                 add_flag(o_ptr->art_flags, TR_CHR);
4108         }
4109
4110         /* Hack -- analyze ego-items */
4111         if (object_is_ego(o_ptr))
4112         {
4113                 ego_item_type *e_ptr = &e_info[o_ptr->name2];
4114
4115                 /* Hack -- acquire "broken" flag */
4116                 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4117
4118                 /* Hack -- acquire "cursed" flag */
4119                 if (e_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4120                 if (e_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4121                 if (e_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4122                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4123                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4124                 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4125
4126                 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN)) one_sustain(o_ptr);
4127                 if (e_ptr->gen_flags & (TRG_XTRA_POWER)) one_ability(o_ptr);
4128                 if (e_ptr->gen_flags & (TRG_XTRA_H_RES)) one_high_resistance(o_ptr);
4129                 if (e_ptr->gen_flags & (TRG_XTRA_E_RES)) one_ele_resistance(o_ptr);
4130                 if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
4131                 if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
4132                 if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
4133                 if (e_ptr->gen_flags & (TRG_XTRA_DICE))
4134                 {
4135                         do
4136                         {
4137                                 o_ptr->dd++;
4138                         }
4139                         while (one_in_(o_ptr->dd));
4140
4141                         if (o_ptr->dd > 9) o_ptr->dd = 9;
4142                 }
4143
4144                 /* Hack -- apply activatin index if needed */
4145                 if (e_ptr->act_idx) o_ptr->xtra2 = (XTRA8)e_ptr->act_idx;
4146
4147                 /* Hack -- apply extra penalties if needed */
4148                 if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL)))
4149                 {
4150                         /* Hack -- obtain bonuses */
4151                         if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
4152                         if (e_ptr->max_to_d) o_ptr->to_d -= randint1(e_ptr->max_to_d);
4153                         if (e_ptr->max_to_a) o_ptr->to_a -= randint1(e_ptr->max_to_a);
4154
4155                         /* Hack -- obtain pval */
4156                         if (e_ptr->max_pval) o_ptr->pval -= randint1(e_ptr->max_pval);
4157                 }
4158
4159                 /* Hack -- apply extra bonuses if needed */
4160                 else
4161                 {
4162                         /* Hack -- obtain bonuses */
4163                         if (e_ptr->max_to_h)
4164                         {
4165                                 if (e_ptr->max_to_h > 127)
4166                                         o_ptr->to_h -= randint1(256-e_ptr->max_to_h);
4167                                 else o_ptr->to_h += randint1(e_ptr->max_to_h);
4168                         }
4169                         if (e_ptr->max_to_d)
4170                         {
4171                                 if (e_ptr->max_to_d > 127)
4172                                         o_ptr->to_d -= randint1(256-e_ptr->max_to_d);
4173                                 else o_ptr->to_d += randint1(e_ptr->max_to_d);
4174                         }
4175                         if (e_ptr->max_to_a)
4176                         {
4177                                 if (e_ptr->max_to_a > 127)
4178                                         o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
4179                                 else o_ptr->to_a += randint1(e_ptr->max_to_a);
4180                         }
4181                         
4182                         /* Accuracy ego must have high to_h */
4183                         if(o_ptr->name2 == EGO_ACCURACY)
4184                         {
4185                                 while(o_ptr->to_h < o_ptr->to_d + 10)
4186                                 {
4187                                         o_ptr->to_h += 5;
4188                                         o_ptr->to_d -= 5;
4189                                 }
4190                                 o_ptr->to_h = MAX(o_ptr->to_h, 15);
4191                         }
4192                         
4193                         /* Accuracy ego must have high to_h */
4194                         if(o_ptr->name2 == EGO_VELOCITY)
4195                         {
4196                                 while(o_ptr->to_d < o_ptr->to_h + 10)
4197                                 {
4198                                         o_ptr->to_d += 5;
4199                                         o_ptr->to_h -= 5;
4200                                 }
4201                                 o_ptr->to_d = MAX(o_ptr->to_d, 15);
4202                         }
4203                         
4204                         /* Protection ego must have high to_a */
4205                         if((o_ptr->name2 == EGO_PROTECTION) || (o_ptr->name2 == EGO_S_PROTECTION) || (o_ptr->name2 == EGO_H_PROTECTION))
4206                         {
4207                                 o_ptr->to_a = MAX(o_ptr->to_a, 15);
4208                         }
4209
4210                         /* Hack -- obtain pval */
4211                         if (e_ptr->max_pval)
4212                         {
4213                                 if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS)))
4214                                 {
4215                                         o_ptr->pval++;
4216                                         if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
4217                                 }
4218                                 else if (o_ptr->name2 == EGO_DEMON)
4219                                 {
4220                                         if(have_flag(o_ptr->art_flags, TR_BLOWS))
4221                                         {
4222                                                 o_ptr->pval += randint1(2);
4223                                         }
4224                                         else
4225                                         {
4226                                                 o_ptr->pval += randint1(e_ptr->max_pval);
4227                                         }
4228                                 }
4229                                 else if (o_ptr->name2 == EGO_ATTACKS)
4230                                 {
4231                                         o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
4232                                         if (o_ptr->pval > 3) o_ptr->pval = 3;
4233                                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
4234                                                 o_ptr->pval += randint1(2);
4235                                 }
4236                                 else if (o_ptr->name2 == EGO_BAT)
4237                                 {
4238                                         o_ptr->pval = randint1(e_ptr->max_pval);
4239                                         if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
4240                                 }
4241                                 else if (o_ptr->name2 == EGO_A_DEMON || o_ptr->name2 == EGO_DRUID || o_ptr->name2 == EGO_OLOG)
4242                                 {
4243                                         o_ptr->pval = randint1(e_ptr->max_pval);
4244                                 }
4245                                 else
4246                                 {
4247                                         o_ptr->pval += randint1(e_ptr->max_pval);
4248                                 }
4249                                 
4250                                 
4251                         }
4252                         if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
4253                         {
4254                                 o_ptr->pval = randint1(o_ptr->pval);
4255                         }
4256                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
4257                                 o_ptr->pval = 2;
4258                 }
4259                 
4260                 return;
4261         }
4262
4263         /* Examine real objects */
4264         if (o_ptr->k_idx)
4265         {
4266                 object_kind *k_ptr = &k_info[o_ptr->k_idx];
4267
4268                 /* Hack -- acquire "broken" flag */
4269                 if (!k_info[o_ptr->k_idx].cost) o_ptr->ident |= (IDENT_BROKEN);
4270
4271                 /* Hack -- acquire "cursed" flag */
4272                 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
4273                 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
4274                 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
4275                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4276                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4277                 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4278         }
4279
4280         
4281 }
4282
4283
4284 /*!
4285  * @brief 生成階に応じたベースアイテムの生成を行う。
4286  * Attempt to make an object (normal or good/great)
4287  * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4288  * @param mode オプションフラグ
4289  * @return 生成に成功したらTRUEを返す。
4290  * @details
4291  * This routine plays nasty games to generate the "special artifacts".\n
4292  * This routine uses "current_floor_ptr->object_level" for the "generation level".\n
4293  * We assume that the given object has been "wiped".\n
4294  */
4295 bool make_object(object_type *j_ptr, BIT_FLAGS mode)
4296 {
4297         PERCENTAGE prob;
4298         DEPTH base;
4299
4300
4301         /* Chance of "special object" */
4302         prob = ((mode & AM_GOOD) ? 10 : 1000);
4303
4304         /* Base level for the object */
4305         base = ((mode & AM_GOOD) ? (current_floor_ptr->object_level + 10) : current_floor_ptr->object_level);
4306
4307
4308         /* Generate a special object, or a normal object */
4309         if (!one_in_(prob) || !make_artifact_special(j_ptr))
4310         {
4311                 KIND_OBJECT_IDX k_idx;
4312
4313                 /* Good objects */
4314                 if ((mode & AM_GOOD) && !get_obj_num_hook)
4315                 {
4316                         /* Activate restriction (if already specified, use that) */
4317                         get_obj_num_hook = kind_is_good;
4318                 }
4319
4320                 /* Restricted objects - prepare allocation table */
4321                 if (get_obj_num_hook) get_obj_num_prep();
4322
4323                 /* Pick a random object */
4324                 k_idx = get_obj_num(base);
4325
4326                 /* Restricted objects */
4327                 if (get_obj_num_hook)
4328                 {
4329                         /* Clear restriction */
4330                         get_obj_num_hook = NULL;
4331
4332                         /* Reset allocation table to default */
4333                         get_obj_num_prep();
4334                 }
4335
4336                 /* Handle failure */
4337                 if (!k_idx) return (FALSE);
4338
4339                 /* Prepare the object */
4340                 object_prep(j_ptr, k_idx);
4341         }
4342
4343         /* Apply magic (allow artifacts) */
4344         apply_magic(j_ptr, current_floor_ptr->object_level, mode);
4345
4346         /* Hack -- generate multiple spikes/missiles */
4347         switch (j_ptr->tval)
4348         {
4349                 case TV_SPIKE:
4350                 case TV_SHOT:
4351                 case TV_ARROW:
4352                 case TV_BOLT:
4353                 {
4354                         if (!j_ptr->name1)
4355                                 j_ptr->number = (byte)damroll(6, 7);
4356                 }
4357         }
4358
4359         if (cheat_peek) object_mention(j_ptr);
4360
4361         /* Success */
4362         return (TRUE);
4363 }
4364
4365
4366 /*!
4367  * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
4368  * Attempt to place an object (normal or good/great) at the given location.
4369  * @param y 配置したいフロアのY座標
4370  * @param x 配置したいフロアのX座標
4371  * @param mode オプションフラグ
4372  * @return 生成に成功したらTRUEを返す。
4373  * @details
4374  * This routine plays nasty games to generate the "special artifacts".\n
4375  * This routine uses "current_floor_ptr->object_level" for the "generation level".\n
4376  * This routine requires a clean floor grid destination.\n
4377  */
4378 void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
4379 {
4380         OBJECT_IDX o_idx;
4381
4382         /* Acquire grid */
4383         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
4384
4385         object_type forge;
4386         object_type *q_ptr;
4387
4388
4389         /* Paranoia -- check bounds */
4390         if (!in_bounds(y, x)) return;
4391
4392         /* Require floor space */
4393         if (!cave_drop_bold(y, x)) return;
4394
4395         /* Avoid stacking on other objects */
4396         if (g_ptr->o_idx) return;
4397
4398         q_ptr = &forge;
4399         object_wipe(q_ptr);
4400
4401         /* Make an object (if possible) */
4402         if (!make_object(q_ptr, mode)) return;
4403
4404
4405         /* Make an object */
4406         o_idx = o_pop();
4407
4408         /* Success */
4409         if (o_idx)
4410         {
4411                 object_type *o_ptr;
4412                 o_ptr = &current_floor_ptr->o_list[o_idx];
4413
4414                 /* Structure Copy */
4415                 object_copy(o_ptr, q_ptr);
4416
4417                 o_ptr->iy = y;
4418                 o_ptr->ix = x;
4419
4420                 /* Build a stack */
4421                 o_ptr->next_o_idx = g_ptr->o_idx;
4422
4423                 g_ptr->o_idx = o_idx;
4424                 note_spot(y, x);
4425                 lite_spot(y, x);
4426         }
4427         else
4428         {
4429                 /* Hack -- Preserve artifacts */
4430                 if (object_is_fixed_artifact(q_ptr))
4431                 {
4432                         a_info[q_ptr->name1].cur_num = 0;
4433                 }
4434         }
4435 }
4436
4437
4438 /*!
4439  * @brief 生成階に応じた財宝オブジェクトの生成を行う。
4440  * Make a treasure object
4441  * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4442  * @return 生成に成功したらTRUEを返す。
4443  * @details
4444  * The location must be a legal, clean, floor grid.
4445  */
4446 bool make_gold(object_type *j_ptr)
4447 {
4448         int i;
4449         s32b base;
4450
4451         /* Hack -- Pick a Treasure variety */
4452         i = ((randint1(current_floor_ptr->object_level + 2) + 2) / 2) - 1;
4453
4454         /* Apply "extra" magic */
4455         if (one_in_(GREAT_OBJ))
4456         {
4457                 i += randint1(current_floor_ptr->object_level + 1);
4458         }
4459
4460         /* Hack -- Creeping Coins only generate "themselves" */
4461         if (coin_type) i = coin_type;
4462
4463         /* Do not create "illegal" Treasure Types */
4464         if (i >= MAX_GOLD) i = MAX_GOLD - 1;
4465
4466         /* Prepare a gold object */
4467         object_prep(j_ptr, OBJ_GOLD_LIST + i);
4468
4469         /* Hack -- Base coin cost */
4470         base = k_info[OBJ_GOLD_LIST + i].cost;
4471
4472         /* Determine how much the treasure is "worth" */
4473         j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
4474
4475         /* Success */
4476         return (TRUE);
4477 }
4478
4479
4480 /*!
4481  * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
4482  * Places a treasure (Gold or Gems) at given location
4483  * @param y 配置したいフロアのY座標
4484  * @param x 配置したいフロアのX座標
4485  * @return 生成に成功したらTRUEを返す。
4486  * @details
4487  * The location must be a legal, clean, floor grid.
4488  */
4489 void place_gold(POSITION y, POSITION x)
4490 {
4491         OBJECT_IDX o_idx;
4492
4493         /* Acquire grid */
4494         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
4495
4496         object_type forge;
4497         object_type *q_ptr;
4498
4499
4500         /* Paranoia -- check bounds */
4501         if (!in_bounds(y, x)) return;
4502
4503         /* Require floor space */
4504         if (!cave_drop_bold(y, x)) return;
4505
4506         /* Avoid stacking on other objects */
4507         if (g_ptr->o_idx) return;
4508
4509         q_ptr = &forge;
4510         object_wipe(q_ptr);
4511
4512         /* Make some gold */
4513         if (!make_gold(q_ptr)) return;
4514
4515         /* Make an object */
4516         o_idx = o_pop();
4517
4518         /* Success */
4519         if (o_idx)
4520         {
4521                 object_type *o_ptr;
4522                 o_ptr = &current_floor_ptr->o_list[o_idx];
4523
4524                 /* Copy the object */
4525                 object_copy(o_ptr, q_ptr);
4526
4527                 /* Save location */
4528                 o_ptr->iy = y;
4529                 o_ptr->ix = x;
4530
4531                 /* Build a stack */
4532                 o_ptr->next_o_idx = g_ptr->o_idx;
4533
4534                 g_ptr->o_idx = o_idx;
4535                 note_spot(y, x);
4536                 lite_spot(y, x);
4537         }
4538 }
4539
4540
4541 /*!
4542  * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
4543  * Let an object fall to the ground at or near a location.
4544  * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
4545  * @param chance ドロップの成功率(%)
4546  * @param y 配置したいフロアのY座標
4547  * @param x 配置したいフロアのX座標
4548  * @return 生成に成功したらオブジェクトのIDを返す。
4549  * @details
4550  * The initial location is assumed to be "in_bounds()".\n
4551  *\n
4552  * This function takes a parameter "chance".  This is the percentage\n
4553  * chance that the item will "disappear" instead of drop.  If the object\n
4554  * has been thrown, then this is the chance of disappearance on contact.\n
4555  *\n
4556  * Hack -- this function uses "chance" to determine if it should produce\n
4557  * some form of "description" of the drop event (under the player).\n
4558  *\n
4559  * We check several locations to see if we can find a location at which\n
4560  * the object can combine, stack, or be placed.  Artifacts will try very\n
4561  * hard to be placed, including "teleporting" to a useful grid if needed.\n
4562  */
4563 OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
4564 {
4565         int i, k, d, s;
4566
4567         int bs, bn;
4568         POSITION by, bx;
4569         POSITION dy, dx;
4570         POSITION ty, tx = 0;
4571
4572         OBJECT_IDX o_idx = 0;
4573         OBJECT_IDX this_o_idx, next_o_idx = 0;
4574
4575         grid_type *g_ptr;
4576
4577         GAME_TEXT o_name[MAX_NLEN];
4578
4579         bool flag = FALSE;
4580         bool done = FALSE;
4581
4582 #ifndef JP
4583         /* Extract plural */
4584         bool plural = (j_ptr->number != 1);
4585 #endif
4586
4587         /* Describe object */
4588         object_desc(o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4589
4590
4591         /* Handle normal "breakage" */
4592         if (!object_is_artifact(j_ptr) && (randint0(100) < chance))
4593         {
4594 #ifdef JP
4595                 msg_format("%sは消えた。", o_name);
4596 #else
4597                 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4598 #endif
4599                 if (p_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
4600
4601                 /* Failure */
4602                 return (0);
4603         }
4604
4605
4606         /* Score */
4607         bs = -1;
4608
4609         /* Picker */
4610         bn = 0;
4611
4612         /* Default */
4613         by = y;
4614         bx = x;
4615
4616         /* Scan local grids */
4617         for (dy = -3; dy <= 3; dy++)
4618         {
4619                 /* Scan local grids */
4620                 for (dx = -3; dx <= 3; dx++)
4621                 {
4622                         bool comb = FALSE;
4623
4624                         /* Calculate actual distance */
4625                         d = (dy * dy) + (dx * dx);
4626
4627                         /* Ignore distant grids */
4628                         if (d > 10) continue;
4629
4630                         ty = y + dy;
4631                         tx = x + dx;
4632
4633                         /* Skip illegal grids */
4634                         if (!in_bounds(ty, tx)) continue;
4635
4636                         /* Require line of projection */
4637                         if (!projectable(y, x, ty, tx)) continue;
4638
4639                         /* Obtain grid */
4640                         g_ptr = &current_floor_ptr->grid_array[ty][tx];
4641
4642                         /* Require floor space */
4643                         if (!cave_drop_bold(ty, tx)) continue;
4644
4645                         /* No objects */
4646                         k = 0;
4647
4648                         /* Scan objects in that grid */
4649                         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4650                         {
4651                                 object_type *o_ptr;
4652                                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
4653                                 next_o_idx = o_ptr->next_o_idx;
4654
4655                                 /* Check for possible combination */
4656                                 if (object_similar(o_ptr, j_ptr)) comb = TRUE;
4657
4658                                 /* Count objects */
4659                                 k++;
4660                         }
4661
4662                         /* Add new object */
4663                         if (!comb) k++;
4664
4665                         /* Paranoia */
4666                         if (k > 99) continue;
4667
4668                         /* Calculate score */
4669                         s = 1000 - (d + k * 5);
4670
4671                         /* Skip bad values */
4672                         if (s < bs) continue;
4673
4674                         /* New best value */
4675                         if (s > bs) bn = 0;
4676
4677                         /* Apply the randomizer to equivalent values */
4678                         if ((++bn >= 2) && !one_in_(bn)) continue;
4679
4680                         /* Keep score */
4681                         bs = s;
4682
4683                         /* Track it */
4684                         by = ty;
4685                         bx = tx;
4686
4687                         flag = TRUE;
4688                 }
4689         }
4690
4691
4692         /* Handle lack of space */
4693         if (!flag && !object_is_artifact(j_ptr))
4694         {
4695 #ifdef JP
4696                 msg_format("%sは消えた。", o_name);
4697 #else
4698                 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4699 #endif
4700
4701                 if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4702
4703                 /* Failure */
4704                 return (0);
4705         }
4706
4707
4708         /* Find a grid */
4709         for (i = 0; !flag && (i < 1000); i++)
4710         {
4711                 /* Bounce around */
4712                 ty = rand_spread(by, 1);
4713                 tx = rand_spread(bx, 1);
4714
4715                 /* Verify location */
4716                 if (!in_bounds(ty, tx)) continue;
4717
4718                 /* Bounce to that location */
4719                 by = ty;
4720                 bx = tx;
4721
4722                 /* Require floor space */
4723                 if (!cave_drop_bold(by, bx)) continue;
4724
4725                 flag = TRUE;
4726         }
4727
4728
4729         if (!flag)
4730         {
4731                 int candidates = 0, pick;
4732
4733                 for (ty = 1; ty < current_floor_ptr->height - 1; ty++)
4734                 {
4735                         for (tx = 1; tx < current_floor_ptr->width - 1; tx++)
4736                         {
4737                                 /* A valid space found */
4738                                 if (cave_drop_bold(ty, tx)) candidates++;
4739                         }
4740                 }
4741
4742                 /* No valid place! */
4743                 if (!candidates)
4744                 {
4745 #ifdef JP
4746                         msg_format("%sは消えた。", o_name);
4747 #else
4748                         msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4749 #endif
4750
4751                         if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4752
4753                         /* Mega-Hack -- preserve artifacts */
4754                         if (preserve_mode)
4755                         {
4756                                 /* Hack -- Preserve unknown artifacts */
4757                                 if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr))
4758                                 {
4759                                         /* Mega-Hack -- Preserve the artifact */
4760                                         a_info[j_ptr->name1].cur_num = 0;
4761                                 }
4762                         }
4763
4764                         /* Failure */
4765                         return 0;
4766                 }
4767
4768                 /* Choose a random one */
4769                 pick = randint1(candidates);
4770
4771                 for (ty = 1; ty < current_floor_ptr->height - 1; ty++)
4772                 {
4773                         for (tx = 1; tx < current_floor_ptr->width - 1; tx++)
4774                         {
4775                                 if (cave_drop_bold(ty, tx))
4776                                 {
4777                                         pick--;
4778
4779                                         /* Is this a picked one? */
4780                                         if (!pick) break;
4781                                 }
4782                         }
4783
4784                         if (!pick) break;
4785                 }
4786
4787                 by = ty;
4788                 bx = tx;
4789         }
4790
4791
4792         g_ptr = &current_floor_ptr->grid_array[by][bx];
4793
4794         /* Scan objects in that grid for combination */
4795         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4796         {
4797                 object_type *o_ptr;
4798                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
4799                 next_o_idx = o_ptr->next_o_idx;
4800
4801                 /* Check for combination */
4802                 if (object_similar(o_ptr, j_ptr))
4803                 {
4804                         object_absorb(o_ptr, j_ptr);
4805
4806                         /* Success */
4807                         done = TRUE;
4808
4809                         break;
4810                 }
4811         }
4812
4813         if (!done) o_idx = o_pop();
4814
4815         /* Failure */
4816         if (!done && !o_idx)
4817         {
4818 #ifdef JP
4819                 msg_format("%sは消えた。", o_name);
4820 #else
4821                 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4822 #endif
4823
4824                 if (p_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
4825
4826                 /* Hack -- Preserve artifacts */
4827                 if (object_is_fixed_artifact(j_ptr))
4828                 {
4829                         a_info[j_ptr->name1].cur_num = 0;
4830                 }
4831
4832                 /* Failure */
4833                 return (0);
4834         }
4835
4836         /* Stack */
4837         if (!done)
4838         {
4839                 /* Structure copy */
4840                 object_copy(&current_floor_ptr->o_list[o_idx], j_ptr);
4841
4842                 /* Access new object */
4843                 j_ptr = &current_floor_ptr->o_list[o_idx];
4844
4845                 /* Locate */
4846                 j_ptr->iy = by;
4847                 j_ptr->ix = bx;
4848
4849                 /* No monster */
4850                 j_ptr->held_m_idx = 0;
4851
4852                 /* Build a stack */
4853                 j_ptr->next_o_idx = g_ptr->o_idx;
4854
4855                 g_ptr->o_idx = o_idx;
4856
4857                 /* Success */
4858                 done = TRUE;
4859         }
4860
4861         note_spot(by, bx);
4862         lite_spot(by, bx);
4863         sound(SOUND_DROP);
4864
4865         /* Mega-Hack -- no message if "dropped" by player */
4866         /* Message when an object falls under the player */
4867         if (chance && player_bold(by, bx))
4868         {
4869                 msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
4870         }
4871
4872         return (o_idx);
4873 }
4874
4875 /*!
4876  * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
4877  * Describe the charges on an item in the inventory.
4878  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4879  * @return なし
4880  */
4881 void inven_item_charges(INVENTORY_IDX item)
4882 {
4883         object_type *o_ptr = &inventory[item];
4884
4885         /* Require staff/wand */
4886         if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
4887
4888         /* Require known item */
4889         if (!object_is_known(o_ptr)) return;
4890
4891 #ifdef JP
4892         if (o_ptr->pval <= 0)
4893         {
4894                 msg_print("もう魔力が残っていない。");
4895         }
4896         else
4897         {
4898                 msg_format("あと %d 回分の魔力が残っている。", o_ptr->pval);
4899         }
4900 #else
4901         /* Multiple charges */
4902         if (o_ptr->pval != 1)
4903         {
4904                 msg_format("You have %d charges remaining.", o_ptr->pval);
4905         }
4906
4907         /* Single charge */
4908         else
4909         {
4910                 msg_format("You have %d charge remaining.", o_ptr->pval);
4911         }
4912 #endif
4913
4914 }
4915
4916 /*!
4917  * @brief アイテムの残り所持数メッセージを表示する /
4918  * Describe an item in the inventory.
4919  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4920  * @return なし
4921  */
4922 void inven_item_describe(INVENTORY_IDX item)
4923 {
4924         object_type *o_ptr = &inventory[item];
4925         GAME_TEXT o_name[MAX_NLEN];
4926
4927         object_desc(o_name, o_ptr, 0);
4928
4929 #ifdef JP
4930         /* "no more" の場合はこちらで表示する */
4931         if (o_ptr->number <= 0)
4932         {
4933                 /*FIRST*//*ここはもう通らないかも */
4934                 msg_format("もう%sを持っていない。", o_name);
4935         }
4936         else
4937         {
4938                 /* アイテム名を英日切り替え機能対応 */
4939                 msg_format("まだ %sを持っている。", o_name);
4940         }
4941 #else
4942         msg_format("You have %s.", o_name);
4943 #endif
4944
4945 }
4946
4947 /*!
4948  * @brief アイテムを増減させ残り所持数メッセージを表示する /
4949  * Increase the "number" of an item in the inventory
4950  * @param item 所持数を増やしたいプレイヤーのアイテム所持スロット
4951  * @param num 増やしたい量
4952  * @return なし
4953  */
4954 void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
4955 {
4956         object_type *o_ptr = &inventory[item];
4957
4958         /* Apply */
4959         num += o_ptr->number;
4960
4961         /* Bounds check */
4962         if (num > 255) num = 255;
4963         else if (num < 0) num = 0;
4964
4965         /* Un-apply */
4966         num -= o_ptr->number;
4967
4968         /* Change the number and weight */
4969         if (num)
4970         {
4971                 /* Add the number */
4972                 o_ptr->number += num;
4973
4974                 /* Add the weight */
4975                 p_ptr->total_weight += (num * o_ptr->weight);
4976                 p_ptr->update |= (PU_BONUS);
4977                 p_ptr->update |= (PU_MANA);
4978                 p_ptr->update |= (PU_COMBINE);
4979                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
4980
4981                 /* Hack -- Clear temporary elemental brands if player takes off weapons */
4982                 if (!o_ptr->number && p_ptr->ele_attack)
4983                 {
4984                         if ((item == INVEN_RARM) || (item == INVEN_LARM))
4985                         {
4986                                 if (!has_melee_weapon(INVEN_RARM + INVEN_LARM - item))
4987                                 {
4988                                         /* Clear all temporary elemental brands */
4989                                         set_ele_attack(0, 0);
4990                                 }
4991                         }
4992                 }
4993         }
4994 }
4995
4996 /*!
4997  * @brief 所持アイテムスロットから所持数のなくなったアイテムを消去する /
4998  * Erase an inventory slot if it has no more items
4999  * @param item 消去したいプレイヤーのアイテム所持スロット
5000  * @return なし
5001  */
5002 void inven_item_optimize(INVENTORY_IDX item)
5003 {
5004         object_type *o_ptr = &inventory[item];
5005
5006         /* Only optimize real items */
5007         if (!o_ptr->k_idx) return;
5008
5009         /* Only optimize empty items */
5010         if (o_ptr->number) return;
5011
5012         /* The item is in the pack */
5013         if (item < INVEN_RARM)
5014         {
5015                 int i;
5016
5017                 /* One less item */
5018                 inven_cnt--;
5019
5020                 /* Slide everything down */
5021                 for (i = item; i < INVEN_PACK; i++)
5022                 {
5023                         /* Structure copy */
5024                         inventory[i] = inventory[i+1];
5025                 }
5026
5027                 /* Erase the "final" slot */
5028                 object_wipe(&inventory[i]);
5029
5030                 p_ptr->window |= (PW_INVEN);
5031         }
5032
5033         /* The item is being wielded */
5034         else
5035         {
5036                 /* One less item */
5037                 equip_cnt--;
5038
5039                 /* Erase the empty slot */
5040                 object_wipe(&inventory[item]);
5041                 p_ptr->update |= (PU_BONUS);
5042                 p_ptr->update |= (PU_TORCH);
5043                 p_ptr->update |= (PU_MANA);
5044
5045                 p_ptr->window |= (PW_EQUIP);
5046         }
5047
5048         p_ptr->window |= (PW_SPELL);
5049 }
5050
5051 /*!
5052  * @brief 床上の魔道具の残り残量メッセージを表示する /
5053  * Describe the charges on an item on the floor.
5054  * @param item メッセージの対象にしたいアイテム所持スロット
5055  * @return なし
5056  */
5057 void floor_item_charges(INVENTORY_IDX item)
5058 {
5059         object_type *o_ptr = &current_floor_ptr->o_list[item];
5060
5061         /* Require staff/wand */
5062         if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5063
5064         /* Require known item */
5065         if (!object_is_known(o_ptr)) return;
5066
5067 #ifdef JP
5068         if (o_ptr->pval <= 0)
5069         {
5070                 msg_print("この床上のアイテムは、もう魔力が残っていない。");
5071         }
5072         else
5073         {
5074                 msg_format("この床上のアイテムは、あと %d 回分の魔力が残っている。", o_ptr->pval);
5075         }
5076 #else
5077         /* Multiple charges */
5078         if (o_ptr->pval != 1)
5079         {
5080                 msg_format("There are %d charges remaining.", o_ptr->pval);
5081         }
5082
5083         /* Single charge */
5084         else
5085         {
5086                 msg_format("There is %d charge remaining.", o_ptr->pval);
5087         }
5088 #endif
5089
5090 }
5091
5092 /*!
5093  * @brief 床上のアイテムの残り数メッセージを表示する /
5094  * Describe the charges on an item on the floor.
5095  * @param item メッセージの対象にしたいアイテム所持スロット
5096  * @return なし
5097  */
5098 void floor_item_describe(INVENTORY_IDX item)
5099 {
5100         object_type *o_ptr = &current_floor_ptr->o_list[item];
5101         GAME_TEXT o_name[MAX_NLEN];
5102
5103         object_desc(o_name, o_ptr, 0);
5104
5105 #ifdef JP
5106         /* "no more" の場合はこちらで表示を分ける */
5107         if (o_ptr->number <= 0)
5108         {
5109                 msg_format("床上には、もう%sはない。", o_name);
5110         }
5111         else
5112         {
5113                 msg_format("床上には、まだ %sがある。", o_name);
5114         }
5115 #else
5116         msg_format("You see %s.", o_name);
5117 #endif
5118
5119 }
5120
5121
5122 /*!
5123  * @brief 床上のアイテムの数を増やす /
5124  * Increase the "number" of an item on the floor
5125  * @param item 増やしたいアイテムの所持スロット
5126  * @param num 増やしたいアイテムの数
5127  * @return なし
5128  */
5129 void floor_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
5130 {
5131         object_type *o_ptr = &current_floor_ptr->o_list[item];
5132
5133         /* Apply */
5134         num += o_ptr->number;
5135
5136         /* Bounds check */
5137         if (num > 255) num = 255;
5138         else if (num < 0) num = 0;
5139
5140         /* Un-apply */
5141         num -=  o_ptr->number;
5142
5143         /* Change the number */
5144         o_ptr->number += num;
5145 }
5146
5147
5148 /*!
5149  * @brief 床上の数の無くなったアイテムスロットを消去する /
5150  * Optimize an item on the floor (destroy "empty" items)
5151  * @param item 消去したいアイテムの所持スロット
5152  * @return なし
5153  */
5154 void floor_item_optimize(INVENTORY_IDX item)
5155 {
5156         object_type *o_ptr = &current_floor_ptr->o_list[item];
5157
5158         /* Paranoia -- be sure it exists */
5159         if (!o_ptr->k_idx) return;
5160
5161         /* Only optimize empty items */
5162         if (o_ptr->number) return;
5163
5164         delete_object_idx(item);
5165 }
5166
5167
5168 /*!
5169  * @brief アイテムを拾う際にザックから溢れずに済むかを判定する /
5170  * Check if we have space for an item in the pack without overflow
5171  * @param o_ptr 拾いたいオブジェクトの構造体参照ポインタ
5172  * @return 溢れずに済むならTRUEを返す
5173  */
5174 bool inven_carry_okay(object_type *o_ptr)
5175 {
5176         int j;
5177
5178         /* Empty slot? */
5179         if (inven_cnt < INVEN_PACK) return (TRUE);
5180
5181         /* Similar slot? */
5182         for (j = 0; j < INVEN_PACK; j++)
5183         {
5184                 object_type *j_ptr = &inventory[j];
5185
5186                 /* Skip non-objects */
5187                 if (!j_ptr->k_idx) continue;
5188
5189                 /* Check if the two items can be combined */
5190                 if (object_similar(j_ptr, o_ptr)) return (TRUE);
5191         }
5192
5193         return (FALSE);
5194 }
5195
5196 /*!
5197  * @brief オブジェクトを定義された基準に従いソートするための関数 /
5198  * Check if we have space for an item in the pack without overflow
5199  * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
5200  * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
5201  * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
5202  * @return o_ptrの方が上位ならばTRUEを返す。
5203  */
5204 bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
5205 {
5206         int o_type, j_type;
5207
5208         /* Use empty slots */
5209         if (!j_ptr->k_idx) return TRUE;
5210
5211         /* Hack -- readable books always come first */
5212         if ((o_ptr->tval == REALM1_BOOK) &&
5213             (j_ptr->tval != REALM1_BOOK)) return TRUE;
5214         if ((j_ptr->tval == REALM1_BOOK) &&
5215             (o_ptr->tval != REALM1_BOOK)) return FALSE;
5216
5217         if ((o_ptr->tval == REALM2_BOOK) &&
5218             (j_ptr->tval != REALM2_BOOK)) return TRUE;
5219         if ((j_ptr->tval == REALM2_BOOK) &&
5220             (o_ptr->tval != REALM2_BOOK)) return FALSE;
5221
5222         /* Objects sort by decreasing type */
5223         if (o_ptr->tval > j_ptr->tval) return TRUE;
5224         if (o_ptr->tval < j_ptr->tval) return FALSE;
5225
5226         /* Non-aware (flavored) items always come last */
5227         /* Can happen in the home */
5228         if (!object_is_aware(o_ptr)) return FALSE;
5229         if (!object_is_aware(j_ptr)) return TRUE;
5230
5231         /* Objects sort by increasing sval */
5232         if (o_ptr->sval < j_ptr->sval) return TRUE;
5233         if (o_ptr->sval > j_ptr->sval) return FALSE;
5234
5235         /* Unidentified objects always come last */
5236         /* Objects in the home can be unknown */
5237         if (!object_is_known(o_ptr)) return FALSE;
5238         if (!object_is_known(j_ptr)) return TRUE;
5239
5240         /* Fixed artifacts, random artifacts and ego items */
5241         if (object_is_fixed_artifact(o_ptr)) o_type = 3;
5242         else if (o_ptr->art_name) o_type = 2;
5243         else if (object_is_ego(o_ptr)) o_type = 1;
5244         else o_type = 0;
5245
5246         if (object_is_fixed_artifact(j_ptr)) j_type = 3;
5247         else if (j_ptr->art_name) j_type = 2;
5248         else if (object_is_ego(j_ptr)) j_type = 1;
5249         else j_type = 0;
5250
5251         if (o_type < j_type) return TRUE;
5252         if (o_type > j_type) return FALSE;
5253
5254         switch (o_ptr->tval)
5255         {
5256         case TV_FIGURINE:
5257         case TV_STATUE:
5258         case TV_CORPSE:
5259         case TV_CAPTURE:
5260                 if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
5261                 if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
5262                 return FALSE;
5263
5264         case TV_SHOT:
5265         case TV_ARROW:
5266         case TV_BOLT:
5267                 /* Objects sort by increasing hit/damage bonuses */
5268                 if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
5269                 if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
5270                 break;
5271
5272         /* Hack:  otherwise identical rods sort by
5273         increasing recharge time --dsb */
5274         case TV_ROD:
5275                 if (o_ptr->pval < j_ptr->pval) return TRUE;
5276                 if (o_ptr->pval > j_ptr->pval) return FALSE;
5277                 break;
5278         }
5279
5280         /* Objects sort by decreasing value */
5281         return o_value > object_value(j_ptr);
5282 }
5283
5284
5285 /*!
5286  * @brief オブジェクトをプレイヤーが拾って所持スロットに納めるメインルーチン /
5287  * Add an item to the players inventory, and return the slot used.
5288  * @param o_ptr 拾うオブジェクトの構造体参照ポインタ
5289  * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5290  * @details
5291  * If the new item can combine with an existing item in the inventory,\n
5292  * it will do so, using "object_similar()" and "object_absorb()", else,\n
5293  * the item will be placed into the "proper" location in the inventory.\n
5294  *\n
5295  * This function can be used to "over-fill" the player's pack, but only\n
5296  * once, and such an action must trigger the "overflow" code immediately.\n
5297  * Note that when the pack is being "over-filled", the new item must be\n
5298  * placed into the "overflow" slot, and the "overflow" must take place\n
5299  * before the pack is reordered, but (optionally) after the pack is\n
5300  * combined.  This may be tricky.  See "dungeon.c" for info.\n
5301  *\n
5302  * Note that this code must remove any location/stack information\n
5303  * from the object once it is placed into the inventory.\n
5304  */
5305 s16b inven_carry(object_type *o_ptr)
5306 {
5307         INVENTORY_IDX i, j, k;
5308         INVENTORY_IDX n = -1;
5309
5310         object_type *j_ptr;
5311
5312
5313         /* Check for combining */
5314         for (j = 0; j < INVEN_PACK; j++)
5315         {
5316                 j_ptr = &inventory[j];
5317
5318                 /* Skip non-objects */
5319                 if (!j_ptr->k_idx) continue;
5320
5321                 /* Hack -- track last item */
5322                 n = j;
5323
5324                 /* Check if the two items can be combined */
5325                 if (object_similar(j_ptr, o_ptr))
5326                 {
5327                         object_absorb(j_ptr, o_ptr);
5328
5329                         p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
5330                         p_ptr->update |= (PU_BONUS);
5331                         p_ptr->window |= (PW_INVEN);
5332
5333                         /* Success */
5334                         return (j);
5335                 }
5336         }
5337
5338
5339         /* Paranoia */
5340         if (inven_cnt > INVEN_PACK) return (-1);
5341
5342         /* Find an empty slot */
5343         for (j = 0; j <= INVEN_PACK; j++)
5344         {
5345                 j_ptr = &inventory[j];
5346
5347                 /* Use it if found */
5348                 if (!j_ptr->k_idx) break;
5349         }
5350
5351         /* Use that slot */
5352         i = j;
5353
5354
5355         /* Reorder the pack */
5356         if (i < INVEN_PACK)
5357         {
5358                 /* Get the "value" of the item */
5359                 s32b o_value = object_value(o_ptr);
5360
5361                 /* Scan every occupied slot */
5362                 for (j = 0; j < INVEN_PACK; j++)
5363                 {
5364                         if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
5365                 }
5366
5367                 /* Use that slot */
5368                 i = j;
5369
5370                 /* Slide objects */
5371                 for (k = n; k >= i; k--)
5372                 {
5373                         /* Hack -- Slide the item */
5374                         object_copy(&inventory[k+1], &inventory[k]);
5375                 }
5376
5377                 /* Wipe the empty slot */
5378                 object_wipe(&inventory[i]);
5379         }
5380
5381
5382         /* Copy the item */
5383         object_copy(&inventory[i], o_ptr);
5384
5385         /* Access new object */
5386         j_ptr = &inventory[i];
5387
5388         /* Forget stack */
5389         j_ptr->next_o_idx = 0;
5390
5391         /* Forget monster */
5392         j_ptr->held_m_idx = 0;
5393
5394         /* Forget location */
5395         j_ptr->iy = j_ptr->ix = 0;
5396
5397         /* Player touches it, and no longer marked */
5398         j_ptr->marked = OM_TOUCHED;
5399
5400         p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
5401
5402         /* Count the items */
5403         inven_cnt++;
5404         p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
5405         p_ptr->window |= (PW_INVEN);
5406
5407         /* Return the slot */
5408         return (i);
5409 }
5410
5411
5412 /*!
5413  * @brief 装備スロットからオブジェクトを外すメインルーチン /
5414  * Take off (some of) a non-cursed equipment item
5415  * @param item オブジェクトを外したい所持テーブルのID
5416  * @param amt 外したい個数
5417  * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5418  * @details
5419  * Note that only one item at a time can be wielded per slot.\n
5420  * Note that taking off an item when "full" may cause that item\n
5421  * to fall to the ground.\n
5422  * Return the inventory slot into which the item is placed.\n
5423  */
5424 INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
5425 {
5426         INVENTORY_IDX slot;
5427
5428         object_type forge;
5429         object_type *q_ptr;
5430
5431         object_type *o_ptr;
5432
5433         concptr act;
5434
5435         GAME_TEXT o_name[MAX_NLEN];
5436
5437
5438         /* Get the item to take off */
5439         o_ptr = &inventory[item];
5440
5441         /* Paranoia */
5442         if (amt <= 0) return (-1);
5443
5444         /* Verify */
5445         if (amt > o_ptr->number) amt = o_ptr->number;
5446         q_ptr = &forge;
5447
5448         /* Obtain a local object */
5449         object_copy(q_ptr, o_ptr);
5450
5451         /* Modify quantity */
5452         q_ptr->number = amt;
5453
5454         object_desc(o_name, q_ptr, 0);
5455
5456         /* Took off weapon */
5457         if (((item == INVEN_RARM) || (item == INVEN_LARM)) &&
5458             object_is_melee_weapon(o_ptr))
5459         {
5460                 act = _("を装備からはずした", "You were wielding");
5461         }
5462
5463         /* Took off bow */
5464         else if (item == INVEN_BOW)
5465         {
5466                 act = _("を装備からはずした", "You were holding");
5467         }
5468
5469         /* Took off light */
5470         else if (item == INVEN_LITE)
5471         {
5472                 act = _("を光源からはずした", "You were holding");
5473         }
5474
5475         /* Took off something */
5476         else
5477         {
5478                 act = _("を装備からはずした", "You were wearing");
5479         }
5480
5481         /* Modify, Optimize */
5482         inven_item_increase(item, -amt);
5483         inven_item_optimize(item);
5484
5485         /* Carry the object */
5486         slot = inven_carry(q_ptr);
5487
5488 #ifdef JP
5489         msg_format("%s(%c)%s。", o_name, index_to_label(slot), act);
5490 #else
5491         msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
5492 #endif
5493
5494
5495         /* Return slot */
5496         return (slot);
5497 }
5498
5499
5500 /*!
5501  * @brief 所持スロットから床下にオブジェクトを落とすメインルーチン /
5502  * Drop (some of) a non-cursed inventory/equipment item
5503  * @param item 所持テーブルのID
5504  * @param amt 落としたい個数
5505  * @return なし
5506  * @details
5507  * The object will be dropped "near" the current location
5508  */
5509 void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
5510 {
5511         object_type forge;
5512         object_type *q_ptr;
5513         object_type *o_ptr;
5514
5515         GAME_TEXT o_name[MAX_NLEN];
5516
5517         /* Access original object */
5518         o_ptr = &inventory[item];
5519
5520         /* Error check */
5521         if (amt <= 0) return;
5522
5523         /* Not too many */
5524         if (amt > o_ptr->number) amt = o_ptr->number;
5525
5526         /* Take off equipment */
5527         if (item >= INVEN_RARM)
5528         {
5529                 /* Take off first */
5530                 item = inven_takeoff(item, amt);
5531
5532                 /* Access original object */
5533                 o_ptr = &inventory[item];
5534         }
5535
5536         q_ptr = &forge;
5537
5538         /* Obtain local object */
5539         object_copy(q_ptr, o_ptr);
5540
5541         /* Distribute charges of wands or rods */
5542         distribute_charges(o_ptr, q_ptr, amt);
5543
5544         /* Modify quantity */
5545         q_ptr->number = amt;
5546
5547         /* Describe local object */
5548         object_desc(o_name, q_ptr, 0);
5549
5550         msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(item));
5551
5552         /* Drop it near the player */
5553         (void)drop_near(q_ptr, 0, p_ptr->y, p_ptr->x);
5554
5555         /* Modify, Describe, Optimize */
5556         inven_item_increase(item, -amt);
5557         inven_item_describe(item);
5558         inven_item_optimize(item);
5559 }
5560
5561
5562 /*!
5563  * @brief プレイヤーの所持スロットに存在するオブジェクトをまとめなおす /
5564  * Combine items in the pack
5565  * @return なし
5566  * @details
5567  * Note special handling of the "overflow" slot
5568  */
5569 void combine_pack(void)
5570 {
5571         int             i, j, k;
5572         object_type *o_ptr;
5573         object_type     *j_ptr;
5574         bool            flag = FALSE, combined;
5575
5576         do
5577         {
5578                 combined = FALSE;
5579
5580                 /* Combine the pack (backwards) */
5581                 for (i = INVEN_PACK; i > 0; i--)
5582                 {
5583                         o_ptr = &inventory[i];
5584
5585                         /* Skip empty items */
5586                         if (!o_ptr->k_idx) continue;
5587
5588                         /* Scan the items above that item */
5589                         for (j = 0; j < i; j++)
5590                         {
5591                                 int max_num;
5592
5593                                 j_ptr = &inventory[j];
5594
5595                                 /* Skip empty items */
5596                                 if (!j_ptr->k_idx) continue;
5597
5598                                 /*
5599                                  * Get maximum number of the stack if these
5600                                  * are similar, get zero otherwise.
5601                                  */
5602                                 max_num = object_similar_part(j_ptr, o_ptr);
5603
5604                                 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
5605                                 if (max_num && j_ptr->number < max_num)
5606                                 {
5607                                         if (o_ptr->number + j_ptr->number <= max_num)
5608                                         {
5609                                                 /* Take note */
5610                                                 flag = TRUE;
5611
5612                                                 /* Add together the item counts */
5613                                                 object_absorb(j_ptr, o_ptr);
5614
5615                                                 /* One object is gone */
5616                                                 inven_cnt--;
5617
5618                                                 /* Slide everything down */
5619                                                 for (k = i; k < INVEN_PACK; k++)
5620                                                 {
5621                                                         /* Structure copy */
5622                                                         inventory[k] = inventory[k+1];
5623                                                 }
5624
5625                                                 /* Erase the "final" slot */
5626                                                 object_wipe(&inventory[k]);
5627                                         }
5628                                         else
5629                                         {
5630                                                 int old_num = o_ptr->number;
5631                                                 int remain = j_ptr->number + o_ptr->number - max_num;
5632 #if 0
5633                                                 o_ptr->number -= remain;
5634 #endif
5635                                                 /* Add together the item counts */
5636                                                 object_absorb(j_ptr, o_ptr);
5637
5638                                                 o_ptr->number = remain;
5639
5640                                                 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
5641                                                 if (o_ptr->tval == TV_ROD)
5642                                                 {
5643                                                         o_ptr->pval =  o_ptr->pval * remain / old_num;
5644                                                         o_ptr->timeout = o_ptr->timeout * remain / old_num;
5645                                                 }
5646
5647                                                 /* Hack -- if wands are stacking, combine the charges. -LM- */
5648                                                 if (o_ptr->tval == TV_WAND)
5649                                                 {
5650                                                         o_ptr->pval = o_ptr->pval * remain / old_num;
5651                                                 }
5652                                         }
5653
5654                                         p_ptr->window |= (PW_INVEN);
5655
5656                                         /* Take note */
5657                                         combined = TRUE;
5658
5659                                         break;
5660                                 }
5661                         }
5662                 }
5663         }
5664         while (combined);
5665
5666         if (flag) msg_print(_("ザックの中のアイテムをまとめ直した。", "You combine some items in your pack."));
5667 }
5668
5669 /*!
5670  * @brief プレイヤーの所持スロットに存在するオブジェクトを並び替える /
5671  * Reorder items in the pack
5672  * @return なし
5673  * @details
5674  * Note special handling of the "overflow" slot
5675  */
5676 void reorder_pack(void)
5677 {
5678         int             i, j, k;
5679         s32b            o_value;
5680         object_type     forge;
5681         object_type     *q_ptr;
5682         object_type *o_ptr;
5683         bool            flag = FALSE;
5684
5685
5686         /* Re-order the pack (forwards) */
5687         for (i = 0; i < INVEN_PACK; i++)
5688         {
5689                 /* Mega-Hack -- allow "proper" over-flow */
5690                 if ((i == INVEN_PACK) && (inven_cnt == INVEN_PACK)) break;
5691
5692                 o_ptr = &inventory[i];
5693
5694                 /* Skip empty slots */
5695                 if (!o_ptr->k_idx) continue;
5696
5697                 /* Get the "value" of the item */
5698                 o_value = object_value(o_ptr);
5699
5700                 /* Scan every occupied slot */
5701                 for (j = 0; j < INVEN_PACK; j++)
5702                 {
5703                         if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
5704                 }
5705
5706                 /* Never move down */
5707                 if (j >= i) continue;
5708
5709                 /* Take note */
5710                 flag = TRUE;
5711                 q_ptr = &forge;
5712
5713                 /* Save a copy of the moving item */
5714                 object_copy(q_ptr, &inventory[i]);
5715
5716                 /* Slide the objects */
5717                 for (k = i; k > j; k--)
5718                 {
5719                         /* Slide the item */
5720                         object_copy(&inventory[k], &inventory[k-1]);
5721                 }
5722
5723                 /* Insert the moving item */
5724                 object_copy(&inventory[j], q_ptr);
5725
5726                 p_ptr->window |= (PW_INVEN);
5727         }
5728
5729         if (flag) msg_print(_("ザックの中のアイテムを並べ直した。", "You reorder some items in your pack."));
5730 }
5731
5732 /*!
5733  * @brief 現在アクティブになっているウィンドウにオブジェクトの詳細を表示する /
5734  * Hack -- display an object kind in the current window
5735  * @param k_idx ベースアイテムの参照ID
5736  * @return なし
5737  * @details
5738  * Include list of usable spells for readible books
5739  */
5740 void display_koff(KIND_OBJECT_IDX k_idx)
5741 {
5742         int y;
5743
5744         object_type forge;
5745         object_type *q_ptr;
5746         int         sval;
5747         REALM_IDX   use_realm;
5748
5749         GAME_TEXT o_name[MAX_NLEN];
5750
5751
5752         /* Erase the window */
5753         for (y = 0; y < Term->hgt; y++)
5754         {
5755                 /* Erase the line */
5756                 Term_erase(0, y, 255);
5757         }
5758
5759         /* No info */
5760         if (!k_idx) return;
5761         q_ptr = &forge;
5762
5763         /* Prepare the object */
5764         object_prep(q_ptr, k_idx);
5765         object_desc(o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
5766
5767         /* Mention the object name */
5768         Term_putstr(0, 0, -1, TERM_WHITE, o_name);
5769
5770         /* Access the item's sval */
5771         sval = q_ptr->sval;
5772         use_realm = tval2realm(q_ptr->tval);
5773
5774         /* Warriors are illiterate */
5775         if (p_ptr->realm1 || p_ptr->realm2)
5776         {
5777                 if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2)) return;
5778         }
5779         else
5780         {
5781                 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return;
5782                 if (!is_magic(use_realm)) return;
5783                 if ((p_ptr->pclass == CLASS_RED_MAGE) && (use_realm != REALM_ARCANE) && (sval > 1)) return;
5784         }
5785
5786         /* Display spells in readible books */
5787         {
5788                 int     spell = -1;
5789                 int     num = 0;
5790                 SPELL_IDX    spells[64];
5791
5792                 /* Extract spells */
5793                 for (spell = 0; spell < 32; spell++)
5794                 {
5795                         /* Check for this spell */
5796                         if (fake_spell_flags[sval] & (1L << spell))
5797                         {
5798                                 /* Collect this spell */
5799                                 spells[num++] = spell;
5800                         }
5801                 }
5802
5803                 /* Print spells */
5804                 print_spells(0, spells, num, 2, 0, use_realm);
5805         }
5806 }
5807
5808
5809 /*!
5810  * @brief 投擲時たいまつに投げやすい/焼棄/アンデッドスレイの特別効果を返す。
5811  * Torches have special abilities when they are flaming.
5812  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5813  * @param flgs 特別に追加するフラグを返す参照ポインタ
5814  * @return なし
5815  */
5816 void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs)
5817 {
5818         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5819         {
5820                 if (o_ptr->xtra4 > 0)
5821                 {
5822                         add_flag(flgs, TR_BRAND_FIRE);
5823                         add_flag(flgs, TR_KILL_UNDEAD);
5824                         add_flag(flgs, TR_THROW);
5825                 }
5826         }
5827 }
5828
5829 /*!
5830  * @brief 投擲時たいまつにダイスを与える。
5831  * Torches have special abilities when they are flaming.
5832  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5833  * @param dd 特別なダイス数を返す参照ポインタ
5834  * @param ds 特別なダイス面数を返す参照ポインタ
5835  * @return なし
5836  */
5837 void torch_dice(object_type *o_ptr, DICE_NUMBER *dd, DICE_SID *ds)
5838 {
5839         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5840         {
5841                 if (o_ptr->xtra4 > 0)
5842                 {
5843                         (*dd) = 1;
5844                         (*ds) = 6;
5845                 }
5846         }
5847 }
5848
5849 /*!
5850  * @brief 投擲時命中したたいまつの寿命を縮める。
5851  * Torches have special abilities when they are flaming.
5852  * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5853  * @return なし
5854  */
5855 void torch_lost_fuel(object_type *o_ptr)
5856 {
5857         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5858         {
5859                 o_ptr->xtra4 -= (FUEL_TORCH / 25);
5860                 if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0;
5861         }
5862 }