3 * @brief オブジェクトの実装 / Object code, part 2
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\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
22 #include "cmd-spell.h"
27 #include "objectkind.h"
28 #include "object-boost.h"
29 #include "object-ego.h"
30 #include "object-flavor.h"
31 #include "object-hook.h"
32 #include "object-curse.h"
33 #include "objectkind-hook.h"
36 #include "player-status.h"
37 #include "player-move.h"
38 #include "player-effects.h"
39 #include "player-class.h"
40 #include "player-personality.h"
42 #include "monsterrace-hook.h"
43 #include "object-ego.h"
44 #include "view-mainwindow.h"
47 * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
48 * @param o_idx 削除対象のオブジェクト構造体ポインタ
51 void excise_object_idx(OBJECT_IDX o_idx)
55 OBJECT_IDX this_o_idx, next_o_idx = 0;
56 OBJECT_IDX prev_o_idx = 0;
59 j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
61 if (OBJECT_IS_HELD_MONSTER(j_ptr))
64 m_ptr = &p_ptr->current_floor_ptr->m_list[j_ptr->held_m_idx];
66 /* Scan all objects in the grid */
67 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
70 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
71 next_o_idx = o_ptr->next_o_idx;
73 if (this_o_idx == o_idx)
78 /* Remove from list */
79 m_ptr->hold_o_idx = next_o_idx;
88 k_ptr = &p_ptr->current_floor_ptr->o_list[prev_o_idx];
90 /* Remove from list */
91 k_ptr->next_o_idx = next_o_idx;
94 /* Forget next pointer */
95 o_ptr->next_o_idx = 0;
100 /* Save prev_o_idx */
101 prev_o_idx = this_o_idx;
110 POSITION y = j_ptr->iy;
111 POSITION x = j_ptr->ix;
113 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
115 /* Scan all objects in the grid */
116 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
119 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
120 next_o_idx = o_ptr->next_o_idx;
122 if (this_o_idx == o_idx)
127 /* Remove from list */
128 g_ptr->o_idx = next_o_idx;
136 /* Previous object */
137 k_ptr = &p_ptr->current_floor_ptr->o_list[prev_o_idx];
139 /* Remove from list */
140 k_ptr->next_o_idx = next_o_idx;
143 /* Forget next pointer */
144 o_ptr->next_o_idx = 0;
149 /* Save prev_o_idx */
150 prev_o_idx = this_o_idx;
156 * @brief オブジェクトを削除する /
157 * Delete a dungeon object
158 * @param o_idx 削除対象のオブジェクト構造体ポインタ
161 * Handle "stacks" of objects correctly.
163 void delete_object_idx(OBJECT_IDX o_idx)
168 excise_object_idx(o_idx);
171 j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
174 if (!OBJECT_IS_HELD_MONSTER(j_ptr))
184 p_ptr->current_floor_ptr->o_cnt--;
189 * @brief フロアにマスに落ちているオブジェクトを全て削除する / Deletes all objects at given location
190 * Delete a dungeon object
191 * @param y 削除したフロアマスのY座標
192 * @param x 削除したフロアマスのX座標
195 void delete_object(POSITION y, POSITION x)
198 OBJECT_IDX this_o_idx, next_o_idx = 0;
200 /* Refuse "illegal" locations */
201 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
203 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
205 /* Scan all objects in the grid */
206 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
209 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
210 next_o_idx = o_ptr->next_o_idx;
214 p_ptr->current_floor_ptr->o_cnt--;
217 /* Objects are gone */
225 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
226 * Move an object from index i1 to index i2 in the object list
227 * @param i1 整理したい配列の始点
228 * @param i2 整理したい配列の終点
231 static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
238 if (i1 == i2) return;
241 for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
243 o_ptr = &p_ptr->current_floor_ptr->o_list[i];
245 /* Skip "dead" objects */
246 if (!o_ptr->k_idx) continue;
248 /* Repair "next" pointers */
249 if (o_ptr->next_o_idx == i1)
252 o_ptr->next_o_idx = i2;
255 o_ptr = &p_ptr->current_floor_ptr->o_list[i1];
257 if (OBJECT_IS_HELD_MONSTER(o_ptr))
260 m_ptr = &p_ptr->current_floor_ptr->m_list[o_ptr->held_m_idx];
263 if (m_ptr->hold_o_idx == i1)
266 m_ptr->hold_o_idx = i2;
275 /* Acquire location */
280 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
283 if (g_ptr->o_idx == i1)
291 p_ptr->current_floor_ptr->o_list[i2] = p_ptr->current_floor_ptr->o_list[i1];
299 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
300 * Compact and Reorder the object list.
301 * @param size 最低でも減らしたいオブジェクト数の水準
305 * This function can be very dangerous, use with caution!\n
307 * When actually "compacting" objects, we base the saving throw on a\n
308 * combination of object level, distance from player, and current\n
311 * After "compacting" (if needed), we "reorder" the objects into a more\n
312 * compact order, and we reset the allocation info, and the "live" array.\n
314 void compact_objects(int size)
319 int cur_lev, cur_dis, chance;
325 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
326 p_ptr->redraw |= (PR_MAP);
327 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
331 /* Compact at least 'size' objects */
332 for (num = 0, cnt = 1; num < size; cnt++)
334 /* Get more vicious each iteration */
337 /* Get closer each iteration */
338 cur_dis = 5 * (20 - cnt);
340 /* Examine the objects */
341 for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
343 o_ptr = &p_ptr->current_floor_ptr->o_list[i];
345 if (!OBJECT_IS_VALID(o_ptr)) continue;
347 /* Hack -- High level objects start out "immune" */
348 if (k_info[o_ptr->k_idx].level > cur_lev) continue;
350 if (OBJECT_IS_HELD_MONSTER(o_ptr))
353 m_ptr = &p_ptr->current_floor_ptr->m_list[o_ptr->held_m_idx];
358 /* Monsters protect their objects */
359 if (randint0(100) < 90) continue;
369 /* Nearby objects start out "immune" */
370 if ((cur_dis > 0) && (distance(p_ptr->y, p_ptr->x, y, x) < cur_dis)) continue;
375 /* Hack -- only compact artifacts in emergencies */
376 if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
377 (cnt < 1000)) chance = 100;
379 /* Apply the saving throw */
380 if (randint0(100) < chance) continue;
382 delete_object_idx(i);
390 /* Excise dead objects (backwards!) */
391 for (i = p_ptr->current_floor_ptr->o_max - 1; i >= 1; i--)
393 o_ptr = &p_ptr->current_floor_ptr->o_list[i];
395 /* Skip real objects */
396 if (o_ptr->k_idx) continue;
398 /* Move last object into open hole */
399 compact_objects_aux(p_ptr->current_floor_ptr->o_max - 1, i);
401 /* Compress "p_ptr->current_floor_ptr->o_max" */
402 p_ptr->current_floor_ptr->o_max--;
407 * @brief グローバルオブジェクト配列から空きを取得する /
408 * Acquires and returns the index of a "free" object.
409 * @return 開いているオブジェクト要素のID
411 * This routine should almost never fail, but in case it does,
412 * we must be sure to handle "failure" of this routine.
414 OBJECT_IDX o_pop(void)
418 /* Initial allocation */
419 if (p_ptr->current_floor_ptr->o_max < current_world_ptr->max_o_idx)
422 i = p_ptr->current_floor_ptr->o_max;
424 /* Expand object array */
425 p_ptr->current_floor_ptr->o_max++;
428 p_ptr->current_floor_ptr->o_cnt++;
430 /* Use this object */
435 /* Recycle dead objects */
436 for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
439 o_ptr = &p_ptr->current_floor_ptr->o_list[i];
441 /* Skip live objects */
442 if (o_ptr->k_idx) continue;
445 p_ptr->current_floor_ptr->o_cnt++;
447 /* Use this object */
452 /* Warn the player (except during dungeon creation) */
453 if (current_world_ptr->character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
459 * Hack -- function hook to restrict "get_obj_num_prep()" function
461 bool(*get_obj_num_hook)(KIND_OBJECT_IDX k_idx);
464 * @brief オブジェクト生成テーブルに生成制約を加える /
465 * Apply a "object restriction function" to the "object allocation table"
467 * @details 生成の制約はグローバルのget_obj_num_hook関数ポインタで加える
469 static errr get_obj_num_prep(void)
474 alloc_entry *table = alloc_kind_table;
476 /* Scan the allocation table */
477 for (i = 0; i < alloc_kind_size; i++)
479 /* Accept objects which pass the restriction, if any */
480 if (!get_obj_num_hook || (*get_obj_num_hook)(table[i].index))
482 /* Accept this object */
483 table[i].prob2 = table[i].prob1;
486 /* Do not use this object */
489 /* Decline this object */
500 * @brief オブジェクト生成テーブルからアイテムを取得する /
501 * Choose an object kind that seems "appropriate" to the given level
503 * @return 選ばれたオブジェクトベースID
505 * This function uses the "prob2" field of the "object allocation table",\n
506 * and various local information, to calculate the "prob3" field of the\n
507 * same table, which is then used to choose an "appropriate" object, in\n
508 * a relatively efficient manner.\n
510 * It is (slightly) more likely to acquire an object of the given level\n
511 * than one of a lower level. This is done by choosing several objects\n
512 * appropriate to the given level and keeping the "hardest" one.\n
514 * Note that if no objects are "appropriate", then this function will\n
515 * fail, and return zero, but this should *almost* never happen.\n
517 OBJECT_IDX get_obj_num(DEPTH level, BIT_FLAGS mode)
520 KIND_OBJECT_IDX k_idx;
523 alloc_entry *table = alloc_kind_table;
525 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
528 if ((level > 0) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
530 /* Occasional "boost" */
531 if (one_in_(GREAT_OBJ))
533 /* What a bizarre calculation */
534 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
541 /* Process probabilities */
542 for (i = 0; i < alloc_kind_size; i++)
544 /* Objects are sorted by depth */
545 if (table[i].level > level) break;
550 k_idx = table[i].index;
552 /* Access the actual kind */
553 k_ptr = &k_info[k_idx];
555 if ((mode & AM_FORBID_CHEST) && (k_ptr->tval == TV_CHEST)) continue;
558 table[i].prob3 = table[i].prob2;
561 total += table[i].prob3;
564 /* No legal objects */
565 if (total <= 0) return (0);
569 value = randint0(total);
571 /* Find the object */
572 for (i = 0; i < alloc_kind_size; i++)
574 /* Found the entry */
575 if (value < table[i].prob3) break;
578 value = value - table[i].prob3;
585 /* Try for a "better" object once (50%) or twice (10%) */
592 value = randint0(total);
594 /* Find the object */
595 for (i = 0; i < alloc_kind_size; i++)
597 /* Found the entry */
598 if (value < table[i].prob3) break;
601 value = value - table[i].prob3;
604 /* Keep the "best" one */
605 if (table[i].level < table[j].level) i = j;
608 /* Try for a "better" object twice (10%) */
615 value = randint0(total);
617 /* Find the object */
618 for (i = 0; i < alloc_kind_size; i++)
620 /* Found the entry */
621 if (value < table[i].prob3) break;
624 value = value - table[i].prob3;
627 /* Keep the "best" one */
628 if (table[i].level < table[j].level) i = j;
631 return (table[i].index);
635 * @brief オブジェクトを鑑定済にする /
636 * Known is true when the "attributes" of an object are "known".
637 * @param o_ptr 鑑定済にするオブジェクトの構造体参照ポインタ
639 * These include tohit, todam, toac, cost, and pval (charges).\n
641 * Note that "knowing" an object gives you everything that an "awareness"\n
642 * gives you, and much more. In fact, the player is always "aware" of any\n
643 * item of which he has full "knowledge".\n
645 * But having full knowledge of, say, one "wand of wonder", does not, by\n
646 * itself, give you knowledge, or even awareness, of other "wands of wonder".\n
647 * It happens that most "identify" routines (including "buying from a shop")\n
648 * will make the player "aware" of the object as well as fully "know" it.\n
650 * This routine also removes any inscriptions generated by "feelings".\n
652 void object_known(object_type *o_ptr)
654 /* Remove "default inscriptions" */
655 o_ptr->feeling = FEEL_NONE;
657 /* Clear the "Felt" info */
658 o_ptr->ident &= ~(IDENT_SENSE);
660 /* Clear the "Empty" info */
661 o_ptr->ident &= ~(IDENT_EMPTY);
663 /* Now we know about the item */
664 o_ptr->ident |= (IDENT_KNOWN);
668 * @brief オブジェクトを*鑑定*済にする /
669 * The player is now aware of the effects of the given object.
670 * @param o_ptr *鑑定*済にするオブジェクトの構造体参照ポインタ
673 void object_aware(object_type *o_ptr)
675 bool mihanmei = !object_is_aware(o_ptr);
677 /* Fully aware of the effects */
678 k_info[o_ptr->k_idx].aware = TRUE;
680 if(mihanmei && !(k_info[o_ptr->k_idx].gen_flags & TRG_INSTA_ART) && record_ident &&
681 !p_ptr->is_dead && ((o_ptr->tval >= TV_AMULET && o_ptr->tval <= TV_POTION) || (o_ptr->tval == TV_FOOD)))
685 GAME_TEXT o_name[MAX_NLEN];
688 object_copy(q_ptr, o_ptr);
691 object_desc(o_name, q_ptr, OD_NAME_ONLY);
693 exe_write_diary(p_ptr, NIKKI_HANMEI, 0, o_name);
698 * @brief オブジェクトを試行済にする /
699 * Something has been "sampled"
700 * @param o_ptr 試行済にするオブジェクトの構造体参照ポインタ
703 void object_tried(object_type *o_ptr)
705 /* Mark it as tried (even if "aware") */
706 k_info[o_ptr->k_idx].tried = TRUE;
710 * @brief 重度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item. Method 1 (Heavy).
711 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
712 * @return 擬似鑑定結果のIDを返す。
714 byte value_check_aux1(object_type *o_ptr)
717 if (object_is_artifact(o_ptr))
720 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_TERRIBLE;
727 if (object_is_ego(o_ptr))
730 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_WORTHLESS;
733 return FEEL_EXCELLENT;
737 if (object_is_cursed(o_ptr)) return FEEL_CURSED;
740 if (object_is_broken(o_ptr)) return FEEL_BROKEN;
742 if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
744 /* Good "armor" bonus */
745 if (o_ptr->to_a > 0) return FEEL_GOOD;
747 /* Good "weapon" bonus */
748 if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
750 /* Default to "average" */
755 * @brief 軽度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item. Method 2 (Light).
756 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
757 * @return 擬似鑑定結果のIDを返す。
759 byte value_check_aux2(object_type *o_ptr)
761 /* Cursed items (all of them) */
762 if (object_is_cursed(o_ptr)) return FEEL_CURSED;
764 /* Broken items (all of them) */
765 if (object_is_broken(o_ptr)) return FEEL_BROKEN;
767 /* Artifacts -- except cursed/broken ones */
768 if (object_is_artifact(o_ptr)) return FEEL_UNCURSED;
770 /* Ego-Items -- except cursed/broken ones */
771 if (object_is_ego(o_ptr)) return FEEL_UNCURSED;
773 /* Good armor bonus */
774 if (o_ptr->to_a > 0) return FEEL_UNCURSED;
776 /* Good weapon bonuses */
777 if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
784 * @brief 未鑑定なベースアイテムの基本価格を返す /
785 * Return the "value" of an "unknown" item Make a guess at the value of non-aware items
786 * @param o_ptr 未鑑定価格を確認したいオブジェクトの構造体参照ポインタ
787 * @return オブジェクトの未鑑定価格
789 static PRICE object_value_base(object_type *o_ptr)
791 /* Aware item -- use template cost */
792 if (object_is_aware(o_ptr)) return (k_info[o_ptr->k_idx].cost);
794 /* Analyze the type */
799 case TV_FOOD: return (5L);
801 /* Un-aware Potions */
802 case TV_POTION: return (20L);
804 /* Un-aware Scrolls */
805 case TV_SCROLL: return (20L);
807 /* Un-aware Staffs */
808 case TV_STAFF: return (70L);
811 case TV_WAND: return (50L);
814 case TV_ROD: return (90L);
817 case TV_RING: return (45L);
819 /* Un-aware Amulets */
820 case TV_AMULET: return (45L);
822 /* Figurines, relative to monster level */
825 DEPTH level = r_info[o_ptr->pval].level;
826 if (level < 20) return level*50L;
827 else if (level < 30) return 1000+(level-20)*150L;
828 else if (level < 40) return 2500+(level-30)*350L;
829 else if (level < 50) return 6000+(level-40)*800L;
830 else return 14000+(level-50)*2000L;
834 if (!o_ptr->pval) return 1000L;
835 else return ((r_info[o_ptr->pval].level) * 50L + 1000);
838 /* Paranoia -- Oops */
844 * @brief オブジェクトのフラグ類から価格を算出する /
845 * Return the value of the flags the object has...
846 * @param o_ptr フラグ価格を確認したいオブジェクトの構造体参照ポインタ
847 * @param plusses フラグに与える価格の基本重み
848 * @return オブジェクトのフラグ価格
850 PRICE flag_cost(object_type *o_ptr, int plusses)
853 BIT_FLAGS flgs[TR_FLAG_SIZE];
857 object_kind *k_ptr = &k_info[o_ptr->k_idx];
859 object_flags(o_ptr, flgs);
862 * Exclude fixed flags of the base item.
863 * pval bonuses of base item will be treated later.
865 for (i = 0; i < TR_FLAG_SIZE; i++)
866 flgs[i] &= ~(k_ptr->flags[i]);
868 /* Exclude fixed flags of the fixed artifact. */
869 if (object_is_fixed_artifact(o_ptr))
871 artifact_type *a_ptr = &a_info[o_ptr->name1];
873 for (i = 0; i < TR_FLAG_SIZE; i++)
874 flgs[i] &= ~(a_ptr->flags[i]);
877 /* Exclude fixed flags of the ego-item. */
878 else if (object_is_ego(o_ptr))
880 ego_item_type *e_ptr = &e_info[o_ptr->name2];
882 for (i = 0; i < TR_FLAG_SIZE; i++)
883 flgs[i] &= ~(e_ptr->flags[i]);
888 * Calucurate values of remaining flags
890 if (have_flag(flgs, TR_STR)) total += (1500 * plusses);
891 if (have_flag(flgs, TR_INT)) total += (1500 * plusses);
892 if (have_flag(flgs, TR_WIS)) total += (1500 * plusses);
893 if (have_flag(flgs, TR_DEX)) total += (1500 * plusses);
894 if (have_flag(flgs, TR_CON)) total += (1500 * plusses);
895 if (have_flag(flgs, TR_CHR)) total += (750 * plusses);
896 if (have_flag(flgs, TR_MAGIC_MASTERY)) total += (600 * plusses);
897 if (have_flag(flgs, TR_STEALTH)) total += (250 * plusses);
898 if (have_flag(flgs, TR_SEARCH)) total += (100 * plusses);
899 if (have_flag(flgs, TR_INFRA)) total += (150 * plusses);
900 if (have_flag(flgs, TR_TUNNEL)) total += (175 * plusses);
901 if ((have_flag(flgs, TR_SPEED)) && (plusses > 0))
902 total += (10000 + (2500 * plusses));
903 if ((have_flag(flgs, TR_BLOWS)) && (plusses > 0))
904 total += (10000 + (2500 * plusses));
908 if (have_flag(flgs, TR_CHAOTIC)) {total += 5000;count++;}
909 if (have_flag(flgs, TR_VAMPIRIC)) {total += 6500;count++;}
910 if (have_flag(flgs, TR_FORCE_WEAPON)) {tmp_cost += 2500;count++;}
911 if (have_flag(flgs, TR_KILL_ANIMAL)) {tmp_cost += 2800;count++;}
912 else if (have_flag(flgs, TR_SLAY_ANIMAL)) {tmp_cost += 1800;count++;}
913 if (have_flag(flgs, TR_KILL_EVIL)) {tmp_cost += 3300;count++;}
914 else if (have_flag(flgs, TR_SLAY_EVIL)) {tmp_cost += 2300;count++;}
915 if (have_flag(flgs, TR_KILL_HUMAN)) {tmp_cost += 2800;count++;}
916 else if (have_flag(flgs, TR_SLAY_HUMAN)) {tmp_cost += 1800;count++;}
917 if (have_flag(flgs, TR_KILL_UNDEAD)) {tmp_cost += 2800;count++;}
918 else if (have_flag(flgs, TR_SLAY_UNDEAD)) {tmp_cost += 1800;count++;}
919 if (have_flag(flgs, TR_KILL_DEMON)) {tmp_cost += 2800;count++;}
920 else if (have_flag(flgs, TR_SLAY_DEMON)) {tmp_cost += 1800;count++;}
921 if (have_flag(flgs, TR_KILL_ORC)) {tmp_cost += 2500;count++;}
922 else if (have_flag(flgs, TR_SLAY_ORC)) {tmp_cost += 1500;count++;}
923 if (have_flag(flgs, TR_KILL_TROLL)) {tmp_cost += 2800;count++;}
924 else if (have_flag(flgs, TR_SLAY_TROLL)) {tmp_cost += 1800;count++;}
925 if (have_flag(flgs, TR_KILL_GIANT)) {tmp_cost += 2800;count++;}
926 else if (have_flag(flgs, TR_SLAY_GIANT)) {tmp_cost += 1800;count++;}
927 if (have_flag(flgs, TR_KILL_DRAGON)) {tmp_cost += 2800;count++;}
928 else if (have_flag(flgs, TR_SLAY_DRAGON)) {tmp_cost += 1800;count++;}
930 if (have_flag(flgs, TR_VORPAL)) {tmp_cost += 2500;count++;}
931 if (have_flag(flgs, TR_IMPACT)) {tmp_cost += 2500;count++;}
932 if (have_flag(flgs, TR_BRAND_POIS)) {tmp_cost += 3800;count++;}
933 if (have_flag(flgs, TR_BRAND_ACID)) {tmp_cost += 3800;count++;}
934 if (have_flag(flgs, TR_BRAND_ELEC)) {tmp_cost += 3800;count++;}
935 if (have_flag(flgs, TR_BRAND_FIRE)) {tmp_cost += 2500;count++;}
936 if (have_flag(flgs, TR_BRAND_COLD)) {tmp_cost += 2500;count++;}
937 total += (tmp_cost * count);
939 if (have_flag(flgs, TR_SUST_STR)) total += 850;
940 if (have_flag(flgs, TR_SUST_INT)) total += 850;
941 if (have_flag(flgs, TR_SUST_WIS)) total += 850;
942 if (have_flag(flgs, TR_SUST_DEX)) total += 850;
943 if (have_flag(flgs, TR_SUST_CON)) total += 850;
944 if (have_flag(flgs, TR_SUST_CHR)) total += 250;
945 if (have_flag(flgs, TR_RIDING)) total += 0;
946 if (have_flag(flgs, TR_EASY_SPELL)) total += 1500;
947 if (have_flag(flgs, TR_THROW)) total += 5000;
948 if (have_flag(flgs, TR_FREE_ACT)) total += 4500;
949 if (have_flag(flgs, TR_HOLD_EXP)) total += 8500;
953 if (have_flag(flgs, TR_IM_ACID)) {tmp_cost += 15000;count += 2;}
954 if (have_flag(flgs, TR_IM_ELEC)) {tmp_cost += 15000;count += 2;}
955 if (have_flag(flgs, TR_IM_FIRE)) {tmp_cost += 15000;count += 2;}
956 if (have_flag(flgs, TR_IM_COLD)) {tmp_cost += 15000;count += 2;}
957 if (have_flag(flgs, TR_REFLECT)) {tmp_cost += 5000;count += 2;}
958 if (have_flag(flgs, TR_RES_ACID)) {tmp_cost += 500;count++;}
959 if (have_flag(flgs, TR_RES_ELEC)) {tmp_cost += 500;count++;}
960 if (have_flag(flgs, TR_RES_FIRE)) {tmp_cost += 500;count++;}
961 if (have_flag(flgs, TR_RES_COLD)) {tmp_cost += 500;count++;}
962 if (have_flag(flgs, TR_RES_POIS)) {tmp_cost += 1000;count += 2;}
963 if (have_flag(flgs, TR_RES_FEAR)) {tmp_cost += 1000;count += 2;}
964 if (have_flag(flgs, TR_RES_LITE)) {tmp_cost += 800;count += 2;}
965 if (have_flag(flgs, TR_RES_DARK)) {tmp_cost += 800;count += 2;}
966 if (have_flag(flgs, TR_RES_BLIND)) {tmp_cost += 900;count += 2;}
967 if (have_flag(flgs, TR_RES_CONF)) {tmp_cost += 900;count += 2;}
968 if (have_flag(flgs, TR_RES_SOUND)) {tmp_cost += 900;count += 2;}
969 if (have_flag(flgs, TR_RES_SHARDS)) {tmp_cost += 900;count += 2;}
970 if (have_flag(flgs, TR_RES_NETHER)) {tmp_cost += 900;count += 2;}
971 if (have_flag(flgs, TR_RES_NEXUS)) {tmp_cost += 900;count += 2;}
972 if (have_flag(flgs, TR_RES_CHAOS)) {tmp_cost += 1000;count += 2;}
973 if (have_flag(flgs, TR_RES_DISEN)) {tmp_cost += 2000;count += 2;}
974 total += (tmp_cost * count);
976 if (have_flag(flgs, TR_SH_FIRE)) total += 5000;
977 if (have_flag(flgs, TR_SH_ELEC)) total += 5000;
978 if (have_flag(flgs, TR_SH_COLD)) total += 5000;
979 if (have_flag(flgs, TR_NO_TELE)) total -= 10000;
980 if (have_flag(flgs, TR_NO_MAGIC)) total += 2500;
981 if (have_flag(flgs, TR_TY_CURSE)) total -= 15000;
982 if (have_flag(flgs, TR_HIDE_TYPE)) total += 0;
983 if (have_flag(flgs, TR_SHOW_MODS)) total += 0;
984 if (have_flag(flgs, TR_LEVITATION)) total += 1250;
985 if (have_flag(flgs, TR_LITE_1)) total += 1500;
986 if (have_flag(flgs, TR_LITE_2)) total += 2500;
987 if (have_flag(flgs, TR_LITE_3)) total += 4000;
988 if (have_flag(flgs, TR_LITE_M1)) total -= 1500;
989 if (have_flag(flgs, TR_LITE_M2)) total -= 2500;
990 if (have_flag(flgs, TR_LITE_M3)) total -= 4000;
991 if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
992 if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
993 if (have_flag(flgs, TR_ESP_ANIMAL)) total += 1000;
994 if (have_flag(flgs, TR_ESP_UNDEAD)) total += 1000;
995 if (have_flag(flgs, TR_ESP_DEMON)) total += 1000;
996 if (have_flag(flgs, TR_ESP_ORC)) total += 1000;
997 if (have_flag(flgs, TR_ESP_TROLL)) total += 1000;
998 if (have_flag(flgs, TR_ESP_GIANT)) total += 1000;
999 if (have_flag(flgs, TR_ESP_DRAGON)) total += 1000;
1000 if (have_flag(flgs, TR_ESP_HUMAN)) total += 1000;
1001 if (have_flag(flgs, TR_ESP_EVIL)) total += 15000;
1002 if (have_flag(flgs, TR_ESP_GOOD)) total += 2000;
1003 if (have_flag(flgs, TR_ESP_NONLIVING)) total += 2000;
1004 if (have_flag(flgs, TR_ESP_UNIQUE)) total += 10000;
1005 if (have_flag(flgs, TR_SLOW_DIGEST)) total += 750;
1006 if (have_flag(flgs, TR_REGEN)) total += 2500;
1007 if (have_flag(flgs, TR_WARNING)) total += 2000;
1008 if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
1009 if (have_flag(flgs, TR_XTRA_MIGHT)) total += 2250;
1010 if (have_flag(flgs, TR_XTRA_SHOTS)) total += 10000;
1011 if (have_flag(flgs, TR_IGNORE_ACID)) total += 100;
1012 if (have_flag(flgs, TR_IGNORE_ELEC)) total += 100;
1013 if (have_flag(flgs, TR_IGNORE_FIRE)) total += 100;
1014 if (have_flag(flgs, TR_IGNORE_COLD)) total += 100;
1015 if (have_flag(flgs, TR_ACTIVATE)) total += 100;
1016 if (have_flag(flgs, TR_DRAIN_EXP)) total -= 12500;
1017 if (have_flag(flgs, TR_DRAIN_HP)) total -= 12500;
1018 if (have_flag(flgs, TR_DRAIN_MANA)) total -= 12500;
1019 if (have_flag(flgs, TR_CALL_ANIMAL)) total -= 12500;
1020 if (have_flag(flgs, TR_CALL_DEMON)) total -= 10000;
1021 if (have_flag(flgs, TR_CALL_DRAGON)) total -= 10000;
1022 if (have_flag(flgs, TR_CALL_UNDEAD)) total -= 10000;
1023 if (have_flag(flgs, TR_COWARDICE)) total -= 5000;
1024 if (have_flag(flgs, TR_LOW_MELEE)) total -= 5000;
1025 if (have_flag(flgs, TR_LOW_AC)) total -= 5000;
1026 if (have_flag(flgs, TR_LOW_MAGIC)) total -= 15000;
1027 if (have_flag(flgs, TR_FAST_DIGEST)) total -= 10000;
1028 if (have_flag(flgs, TR_SLOW_REGEN)) total -= 10000;
1029 if (have_flag(flgs, TR_TELEPORT))
1031 if (object_is_cursed(o_ptr))
1036 if (have_flag(flgs, TR_AGGRAVATE)) total -= 10000;
1037 if (have_flag(flgs, TR_BLESSED)) total += 750;
1038 if (o_ptr->curse_flags & TR_ADD_L_CURSE) total -= 5000;
1039 if (o_ptr->curse_flags & TR_ADD_H_CURSE) total -= 12500;
1040 if (o_ptr->curse_flags & TRC_CURSED) total -= 5000;
1041 if (o_ptr->curse_flags & TRC_HEAVY_CURSE) total -= 12500;
1042 if (o_ptr->curse_flags & TRC_PERMA_CURSE) total -= 15000;
1044 /* Also, give some extra for activatable powers... */
1045 if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
1047 const activation_type* const act_ptr = find_activation_info(o_ptr);
1049 total += act_ptr->value;
1058 * @brief オブジェクトの真の価格を算出する /
1059 * Return the value of the flags the object has...
1060 * @param o_ptr 本価格を確認したいオブジェクトの構造体参照ポインタ
1061 * @return オブジェクトの本価格
1063 * Return the "real" price of a "known" item, not including discounts\n
1065 * Wand and staffs get cost for each charge\n
1067 * Armor is worth an extra 100 gold per bonus point to armor class.\n
1069 * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).\n
1071 * Missiles are only worth 5 gold per bonus point, since they\n
1072 * usually appear in groups of 20, and we want the player to get\n
1073 * the same amount of cash for any "equivalent" item. Note that\n
1074 * missiles never have any of the "pval" flags, and in fact, they\n
1075 * only have a few of the available flags, primarily of the "slay"\n
1076 * and "brand" and "ignore" variety.\n
1078 * Armor with a negative armor bonus is worthless.\n
1079 * Weapons with negative hit+damage bonuses are worthless.\n
1081 * Every wearable item with a "pval" bonus is worth extra (see below).\n
1083 PRICE object_value_real(object_type *o_ptr)
1086 BIT_FLAGS flgs[TR_FLAG_SIZE];
1087 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1090 /* Hack -- "worthless" items */
1091 if (!k_info[o_ptr->k_idx].cost) return (0L);
1094 value = k_info[o_ptr->k_idx].cost;
1096 /* Extract some flags */
1097 object_flags(o_ptr, flgs);
1100 if (object_is_fixed_artifact(o_ptr))
1102 artifact_type *a_ptr = &a_info[o_ptr->name1];
1104 /* Hack -- "worthless" artifacts */
1105 if (!a_ptr->cost) return (0L);
1107 /* Hack -- Use the artifact cost instead */
1108 value = a_ptr->cost;
1109 value += flag_cost(o_ptr, o_ptr->pval);
1111 /* Don't add pval bonuses etc. */
1116 else if (object_is_ego(o_ptr))
1118 ego_item_type *e_ptr = &e_info[o_ptr->name2];
1120 /* Hack -- "worthless" ego-items */
1121 if (!e_ptr->cost) return (0L);
1123 /* Hack -- Reward the ego-item with a bonus */
1124 value += e_ptr->cost;
1125 value += flag_cost(o_ptr, o_ptr->pval);
1133 for (i = 0; i < TR_FLAG_SIZE; i++)
1134 if (o_ptr->art_flags[i]) flag = TRUE;
1136 if (flag) value += flag_cost(o_ptr, o_ptr->pval);
1139 /* Analyze pval bonus for normal object */
1140 switch (o_ptr->tval)
1163 if (!o_ptr->pval) break;
1165 /* Hack -- Negative "pval" is always bad */
1166 if (o_ptr->pval < 0) return (0L);
1168 /* Give credit for stat bonuses */
1169 if (have_flag(flgs, TR_STR)) value += (o_ptr->pval * 200L);
1170 if (have_flag(flgs, TR_INT)) value += (o_ptr->pval * 200L);
1171 if (have_flag(flgs, TR_WIS)) value += (o_ptr->pval * 200L);
1172 if (have_flag(flgs, TR_DEX)) value += (o_ptr->pval * 200L);
1173 if (have_flag(flgs, TR_CON)) value += (o_ptr->pval * 200L);
1174 if (have_flag(flgs, TR_CHR)) value += (o_ptr->pval * 200L);
1176 /* Give credit for stealth and searching */
1177 if (have_flag(flgs, TR_MAGIC_MASTERY)) value += (o_ptr->pval * 100);
1178 if (have_flag(flgs, TR_STEALTH)) value += (o_ptr->pval * 100L);
1179 if (have_flag(flgs, TR_SEARCH)) value += (o_ptr->pval * 100L);
1181 /* Give credit for infra-vision and tunneling */
1182 if (have_flag(flgs, TR_INFRA)) value += (o_ptr->pval * 50L);
1183 if (have_flag(flgs, TR_TUNNEL)) value += (o_ptr->pval * 50L);
1185 /* Give credit for extra attacks */
1186 if (have_flag(flgs, TR_BLOWS)) value += (o_ptr->pval * 5000L);
1188 /* Give credit for speed bonus */
1189 if (have_flag(flgs, TR_SPEED)) value += (o_ptr->pval * 10000L);
1195 /* Analyze the item */
1196 switch (o_ptr->tval)
1201 /* Pay extra for charges, depending on standard number of
1202 * charges. Handle new-style wands correctly. -LM-
1204 value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
1210 /* Pay extra for charges, depending on standard number of
1213 value += (value * o_ptr->pval / (k_ptr->pval * 2));
1222 /* Hack -- negative bonuses are bad */
1223 if (o_ptr->to_h + o_ptr->to_d + o_ptr->to_a < 0) return (0L);
1225 /* Give credit for bonuses */
1226 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
1242 /* Hack -- negative armor bonus */
1243 if (o_ptr->to_a < 0) return (0L);
1245 /* Give credit for bonuses */
1246 value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
1258 /* Hack -- negative hit/damage bonuses */
1259 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1261 /* Factor in the bonuses */
1262 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 100L);
1264 /* Hack -- Factor in extra damage dice and sides */
1265 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
1266 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
1276 /* Hack -- negative hit/damage bonuses */
1277 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1279 /* Factor in the bonuses */
1280 value += ((o_ptr->to_h + o_ptr->to_d) * 5L);
1282 /* Hack -- Factor in extra damage dice and sides */
1283 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
1284 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
1289 /* Figurines, relative to monster level */
1292 DEPTH level = r_info[o_ptr->pval].level;
1293 if (level < 20) value = level*50L;
1294 else if (level < 30) value = 1000+(level-20)*150L;
1295 else if (level < 40) value = 2500+(level-30)*350L;
1296 else if (level < 50) value = 6000+(level-40)*800L;
1297 else value = 14000+(level-50)*2000L;
1303 if (!o_ptr->pval) value = 1000L;
1304 else value = ((r_info[o_ptr->pval].level) * 50L + 1000);
1310 if (!o_ptr->pval) value = 0L;
1315 /* Worthless object */
1316 if (value < 0) return 0L;
1318 /* Return the value */
1324 * @brief オブジェクト価格算出のメインルーチン /
1325 * Return the price of an item including plusses (and charges)
1326 * @param o_ptr 判明している現価格を確認したいオブジェクトの構造体参照ポインタ
1327 * @return オブジェクトの判明している現価格
1329 * This function returns the "value" of the given item (qty one)\n
1331 * Never notice "unknown" bonuses or properties, including "curses",\n
1332 * since that would give the player information he did not have.\n
1334 * Note that discounted items stay discounted forever, even if\n
1335 * the discount is "forgotten" by the player via memory loss.\n
1337 PRICE object_value(object_type *o_ptr)
1341 /* Unknown items -- acquire a base value */
1342 if (object_is_known(o_ptr))
1344 /* Broken items -- worthless */
1345 if (object_is_broken(o_ptr)) return (0L);
1347 /* Cursed items -- worthless */
1348 if (object_is_cursed(o_ptr)) return (0L);
1350 /* Real value (see above) */
1351 value = object_value_real(o_ptr);
1354 /* Known items -- acquire the actual value */
1357 /* Hack -- Felt broken items */
1358 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_broken(o_ptr)) return (0L);
1360 /* Hack -- Felt cursed items */
1361 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_cursed(o_ptr)) return (0L);
1363 /* Base value (see above) */
1364 value = object_value_base(o_ptr);
1367 /* Apply discount (if any) */
1368 if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
1370 /* Return the final value */
1378 * @brief 魔法棒やロッドのスロット分割時に使用回数を分配する /
1379 * Distribute charges of rods or wands.
1380 * @param o_ptr 分割元オブジェクトの構造体参照ポインタ source item
1381 * @param q_ptr 分割先オブジェクトの構造体参照ポインタ target item, must be of the same type as o_ptr
1382 * @param amt 分割したい回数量 number of items that are transfered
1385 * Hack -- If rods or wands are dropped, the total maximum timeout or\n
1386 * charges need to be allocated between the two stacks. If all the items\n
1387 * are being dropped, it makes for a neater message to leave the original\n
1388 * stack's pval alone. -LM-\n
1390 void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
1392 if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD))
1394 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1395 if (amt < o_ptr->number) o_ptr->pval -= q_ptr->pval;
1397 /* Hack -- Rods also need to have their timeouts distributed. The
1398 * dropped stack will accept all time remaining to charge up to its
1401 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
1403 if (q_ptr->pval > o_ptr->timeout)
1404 q_ptr->timeout = o_ptr->timeout;
1406 q_ptr->timeout = q_ptr->pval;
1408 if (amt < o_ptr->number) o_ptr->timeout -= q_ptr->timeout;
1414 * @brief 魔法棒やロッドの使用回数を減らす /
1415 * @param o_ptr オブジェクトの構造体参照ポインタ source item
1416 * @param amt 減らしたい回数量 number of items that are transfered
1419 * Hack -- If rods or wand are destroyed, the total maximum timeout or\n
1420 * charges of the stack needs to be reduced, unless all the items are\n
1421 * being destroyed. -LM-\n
1423 void reduce_charges(object_type *o_ptr, int amt)
1425 if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD)) &&
1426 (amt < o_ptr->number))
1428 o_ptr->pval -= o_ptr->pval * amt / o_ptr->number;
1433 * Determine if an item can "absorb" a second item
1435 * See "object_absorb()" for the actual "absorption" code.
1437 * If permitted, we allow staffs (if they are known to have equal charges
1438 * and both are either known or confirmed empty) and wands (if both are
1439 * either known or confirmed empty) and rods (in all cases) to combine.
1440 * Staffs will unstack (if necessary) when they are used, but wands and
1441 * rods will only unstack if one is dropped. -LM-
1443 * If permitted, we allow weapons/armor to stack, if fully "known".
1445 * Missiles will combine if both stacks have the same "known" status.
1446 * This is done to make unidentified stacks of missiles useful.
1448 * Food, potions, scrolls, and "easy know" items always stack.
1450 * Chests, and activatable items, never stack (for various reasons).
1454 * A "stack" of items is limited to less than or equal to 99 items (hard-coded).
1456 #define MAX_STACK_SIZE 99
1460 * @brief 両オブジェクトをスロットに重ね合わせ可能な最大数を返す。
1461 * Determine if an item can partly absorb a second item. Return maximum number of stack.
1462 * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1463 * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1464 * @return 重ね合わせ可能なアイテム数
1466 int object_similar_part(object_type *o_ptr, object_type *j_ptr)
1470 /* Default maximum number of stack */
1471 int max_num = MAX_STACK_SIZE;
1473 /* Require identical object types */
1474 if (o_ptr->k_idx != j_ptr->k_idx) return 0;
1477 /* Analyze the items */
1478 switch (o_ptr->tval)
1480 /* Chests and Statues*/
1491 if ((o_ptr->sval != SV_PHOTO) || (j_ptr->sval != SV_PHOTO)) return 0;
1492 if (o_ptr->pval != j_ptr->pval) return 0;
1496 /* Figurines and Corpses*/
1501 if (o_ptr->pval != j_ptr->pval) return 0;
1507 /* Food and Potions and Scrolls */
1519 /* Require either knowledge or known empty for both staffs. */
1520 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1521 !object_is_known(o_ptr)) ||
1522 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1523 !object_is_known(j_ptr))) return 0;
1525 /* Require identical charges, since staffs are bulky. */
1526 if (o_ptr->pval != j_ptr->pval) return 0;
1535 /* Require either knowledge or known empty for both wands. */
1536 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1537 !object_is_known(o_ptr)) ||
1538 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1539 !object_is_known(j_ptr))) return 0;
1541 /* Wand charges combine in O&ZAngband. */
1547 /* Staffs and Wands and Rods */
1550 /* Prevent overflaw of timeout */
1551 max_num = MIN(max_num, MAX_SHORT / k_info[o_ptr->k_idx].pval);
1557 /* Weapons and Armor */
1573 /* Rings, Amulets, Lites */
1579 /* Require full knowledge of both items */
1580 if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1590 /* Require identical knowledge of both items */
1591 if (object_is_known(o_ptr) != object_is_known(j_ptr)) return 0;
1592 if (o_ptr->feeling != j_ptr->feeling) return 0;
1594 /* Require identical "bonuses" */
1595 if (o_ptr->to_h != j_ptr->to_h) return 0;
1596 if (o_ptr->to_d != j_ptr->to_d) return 0;
1597 if (o_ptr->to_a != j_ptr->to_a) return 0;
1599 /* Require identical "pval" code */
1600 if (o_ptr->pval != j_ptr->pval) return 0;
1602 /* Artifacts never stack */
1603 if (object_is_artifact(o_ptr) || object_is_artifact(j_ptr)) return 0;
1605 /* Require identical "ego-item" names */
1606 if (o_ptr->name2 != j_ptr->name2) return 0;
1608 /* Require identical added essence */
1609 if (o_ptr->xtra3 != j_ptr->xtra3) return 0;
1610 if (o_ptr->xtra4 != j_ptr->xtra4) return 0;
1612 /* Hack -- Never stack "powerful" items */
1613 if (o_ptr->xtra1 || j_ptr->xtra1) return 0;
1615 /* Hack -- Never stack recharging items */
1616 if (o_ptr->timeout || j_ptr->timeout) return 0;
1618 /* Require identical "values" */
1619 if (o_ptr->ac != j_ptr->ac) return 0;
1620 if (o_ptr->dd != j_ptr->dd) return 0;
1621 if (o_ptr->ds != j_ptr->ds) return 0;
1630 /* Require knowledge */
1631 if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1639 /* Hack -- Identical art_flags! */
1640 for (i = 0; i < TR_FLAG_SIZE; i++)
1641 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return 0;
1643 /* Hack -- Require identical "cursed" status */
1644 if (o_ptr->curse_flags != j_ptr->curse_flags) return 0;
1646 /* Hack -- Require identical "broken" status */
1647 if ((o_ptr->ident & (IDENT_BROKEN)) != (j_ptr->ident & (IDENT_BROKEN))) return 0;
1650 /* Hack -- require semi-matching "inscriptions" */
1651 if (o_ptr->inscription && j_ptr->inscription &&
1652 (o_ptr->inscription != j_ptr->inscription))
1655 /* Hack -- normally require matching "inscriptions" */
1656 if (!stack_force_notes && (o_ptr->inscription != j_ptr->inscription)) return 0;
1658 /* Hack -- normally require matching "discounts" */
1659 if (!stack_force_costs && (o_ptr->discount != j_ptr->discount)) return 0;
1662 /* They match, so they must be similar */
1667 * @brief 両オブジェクトをスロットに重ねることができるかどうかを返す。
1668 * Determine if an item can absorb a second item.
1669 * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1670 * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1671 * @return 重ね合わせ可能ならばTRUEを返す。
1673 bool object_similar(object_type *o_ptr, object_type *j_ptr)
1675 int total = o_ptr->number + j_ptr->number;
1678 /* Are these objects similar? */
1679 max_num = object_similar_part(o_ptr, j_ptr);
1681 /* Return if not similar */
1682 if (!max_num) return FALSE;
1684 /* Maximal "stacking" limit */
1685 if (total > max_num) return (0);
1688 /* They match, so they must be similar */
1694 * @brief 両オブジェクトをスロットに重ね合わせる。
1695 * Allow one item to "absorb" another, assuming they are similar
1696 * @param o_ptr 重ね合わせ先のオブジェクトの構造体参照ポインタ
1697 * @param j_ptr 重ね合わせ元のオブジェクトの構造体参照ポインタ
1700 void object_absorb(object_type *o_ptr, object_type *j_ptr)
1702 int max_num = object_similar_part(o_ptr, j_ptr);
1703 int total = o_ptr->number + j_ptr->number;
1704 int diff = (total > max_num) ? total - max_num : 0;
1706 /* Combine quantity, lose excess items */
1707 o_ptr->number = (total > max_num) ? max_num : total;
1709 /* Hack -- blend "known" status */
1710 if (object_is_known(j_ptr)) object_known(o_ptr);
1712 /* Hack -- clear "storebought" if only one has it */
1713 if (((o_ptr->ident & IDENT_STORE) || (j_ptr->ident & IDENT_STORE)) &&
1714 (!((o_ptr->ident & IDENT_STORE) && (j_ptr->ident & IDENT_STORE))))
1716 if (j_ptr->ident & IDENT_STORE) j_ptr->ident &= 0xEF;
1717 if (o_ptr->ident & IDENT_STORE) o_ptr->ident &= 0xEF;
1720 /* Hack -- blend "mental" status */
1721 if (j_ptr->ident & (IDENT_MENTAL)) o_ptr->ident |= (IDENT_MENTAL);
1723 /* Hack -- blend "inscriptions" */
1724 if (j_ptr->inscription) o_ptr->inscription = j_ptr->inscription;
1726 /* Hack -- blend "feelings" */
1727 if (j_ptr->feeling) o_ptr->feeling = j_ptr->feeling;
1729 /* Hack -- could average discounts */
1730 /* Hack -- save largest discount */
1731 if (o_ptr->discount < j_ptr->discount) o_ptr->discount = j_ptr->discount;
1733 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1734 if (o_ptr->tval == TV_ROD)
1736 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1737 o_ptr->timeout += j_ptr->timeout * (j_ptr->number - diff) / j_ptr->number;
1740 /* Hack -- if wands are stacking, combine the charges. -LM- */
1741 if (o_ptr->tval == TV_WAND)
1743 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1749 * @brief tvalとsvalに対応するベースアイテムのIDを返す。
1750 * Find the index of the object_kind with the given tval and sval
1751 * @param tval 検索したいベースアイテムのtval
1752 * @param sval 検索したいベースアイテムのsval
1755 KIND_OBJECT_IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
1759 KIND_OBJECT_IDX bk = 0;
1762 for (k = 1; k < max_k_idx; k++)
1764 object_kind *k_ptr = &k_info[k];
1766 /* Require correct tval */
1767 if (k_ptr->tval != tval) continue;
1770 if (k_ptr->sval == sval) return (k);
1772 /* Ignore illegal items */
1773 if (sval != SV_ANY) continue;
1775 /* Apply the randomizer */
1776 if (!one_in_(++num)) continue;
1778 /* Use this value */
1782 /* Return this choice */
1789 msg_format(_("アイテムがない (%d,%d)", "No object (%d,%d)"), tval, sval);
1798 * @brief オブジェクトを初期化する
1799 * Wipe an object clean.
1800 * @param o_ptr 初期化したいオブジェクトの構造体参照ポインタ
1803 void object_wipe(object_type *o_ptr)
1805 /* Wipe the structure */
1806 (void)WIPE(o_ptr, object_type);
1811 * @brief オブジェクトを複製する
1812 * Wipe an object clean.
1813 * @param o_ptr 複製元のオブジェクトの構造体参照ポインタ
1814 * @param j_ptr 複製先のオブジェクトの構造体参照ポインタ
1817 void object_copy(object_type *o_ptr, object_type *j_ptr)
1819 /* Copy the structure */
1820 (void)COPY(o_ptr, j_ptr, object_type);
1825 * @brief オブジェクト構造体にベースアイテムを作成する
1826 * Prepare an object based on an object kind.
1827 * @param o_ptr 代入したいオブジェクトの構造体参照ポインタ
1828 * @param k_idx 新たに作成したいベースアイテム情報のID
1831 void object_prep(object_type *o_ptr, KIND_OBJECT_IDX k_idx)
1833 object_kind *k_ptr = &k_info[k_idx];
1835 /* Clear the record */
1838 /* Save the kind index */
1839 o_ptr->k_idx = k_idx;
1841 /* Efficiency -- tval/sval */
1842 o_ptr->tval = k_ptr->tval;
1843 o_ptr->sval = k_ptr->sval;
1845 /* Default "pval" */
1846 o_ptr->pval = k_ptr->pval;
1848 /* Default number */
1851 /* Default weight */
1852 o_ptr->weight = k_ptr->weight;
1855 o_ptr->to_h = k_ptr->to_h;
1856 o_ptr->to_d = k_ptr->to_d;
1857 o_ptr->to_a = k_ptr->to_a;
1860 o_ptr->ac = k_ptr->ac;
1861 o_ptr->dd = k_ptr->dd;
1862 o_ptr->ds = k_ptr->ds;
1864 /* Default activation */
1865 if (k_ptr->act_idx > 0) o_ptr->xtra2 = (XTRA8)k_ptr->act_idx;
1867 /* Hack -- worthless items are always "broken" */
1868 if (k_info[o_ptr->k_idx].cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
1870 /* Hack -- cursed items are always "cursed" */
1871 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
1872 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
1873 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
1874 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
1875 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
1876 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
1881 * @brief デバッグ時にアイテム生成情報をメッセージに出力する / Cheat -- describe a created object for the user
1882 * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ
1885 static void object_mention(object_type *o_ptr)
1887 GAME_TEXT o_name[MAX_NLEN];
1889 object_aware(o_ptr);
1890 object_known(o_ptr);
1892 /* Mark the item as fully known */
1893 o_ptr->ident |= (IDENT_MENTAL);
1894 object_desc(o_name, o_ptr, 0);
1895 msg_format_wizard(CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
1900 * @brief アイテムのエゴをレア度の重みに合わせてランダムに選択する
1901 * Choose random ego type
1902 * @param slot 取得したいエゴの装備部位
1903 * @param good TRUEならば通常のエゴ、FALSEならば呪いのエゴが選択対象となる。
1904 * @return 選択されたエゴ情報のID、万一選択できなかった場合はmax_e_idxが返る。
1906 static byte get_random_ego(byte slot, bool good)
1909 ego_item_type *e_ptr;
1913 for (i = 1; i < max_e_idx; i++)
1917 if (e_ptr->slot == slot
1918 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
1921 total += (255 / e_ptr->rarity);
1925 value = randint1(total);
1927 for (i = 1; i < max_e_idx; i++)
1931 if (e_ptr->slot == slot
1932 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
1935 value -= (255 / e_ptr->rarity);
1936 if (value <= 0L) break;
1944 * @brief 武器系オブジェクトに生成ランクごとの強化を与えるサブルーチン
1945 * Apply magic to an item known to be a "weapon"
1946 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
1947 * @param level 生成基準階
1948 * @param power 生成ランク
1951 * Hack -- note special base damage dice boosting\n
1952 * Hack -- note special processing for weapon/digger\n
1954 void apply_magic_weapon(object_type *o_ptr, DEPTH level, int power)
1956 HIT_PROB tohit1 = randint1(5) + (HIT_PROB)m_bonus(5, level);
1957 HIT_POINT todam1 = randint1(5) + (HIT_POINT)m_bonus(5, level);
1959 HIT_PROB tohit2 = (HIT_PROB)m_bonus(10, level);
1960 HIT_POINT todam2 = (HIT_POINT)m_bonus(10, level);
1962 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
1964 tohit2 = (tohit2 + 1) / 2;
1965 todam2 = (todam2 + 1) / 2;
1972 o_ptr->to_h += tohit1;
1973 o_ptr->to_d += todam1;
1979 o_ptr->to_h += tohit2;
1980 o_ptr->to_d += todam2;
1988 o_ptr->to_h -= tohit1;
1989 o_ptr->to_d -= todam1;
1994 /* Penalize again */
1995 o_ptr->to_h -= tohit2;
1996 o_ptr->to_d -= todam2;
1999 /* Cursed (if "bad") */
2000 if (o_ptr->to_h + o_ptr->to_d < 0) o_ptr->curse_flags |= TRC_CURSED;
2003 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)) return;
2005 switch (o_ptr->tval)
2012 if (one_in_(30) || (power > 2)) /* power > 2 is debug only */
2013 become_random_artifact(o_ptr, FALSE);
2015 /* Special Ego-item */
2016 o_ptr->name2 = EGO_DIGGING;
2020 else if (power < -1)
2022 /* Hack -- Horrible digging bonus */
2023 o_ptr->pval = 0 - (5 + randint1(5));
2029 /* Hack -- Reverse digging bonus */
2030 o_ptr->pval = 0 - (o_ptr->pval);
2043 if (one_in_(40) || (power > 2)) /* power > 2 is debug only */
2045 become_random_artifact(o_ptr, FALSE);
2050 /* Roll for an ego-item */
2051 o_ptr->name2 = get_random_ego(INVEN_RARM, TRUE);
2052 if (o_ptr->name2 == EGO_SHARPNESS && o_ptr->tval != TV_SWORD)
2054 if (o_ptr->name2 == EGO_EARTHQUAKES && o_ptr->tval != TV_HAFTED)
2056 if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2061 switch (o_ptr->name2)
2064 if (one_in_(4) && (level > 40))
2065 add_flag(o_ptr->art_flags, TR_BLOWS);
2069 add_flag(o_ptr->art_flags, TR_RES_POIS);
2071 add_flag(o_ptr->art_flags, TR_WARNING);
2073 case EGO_KILL_DRAGON:
2075 add_flag(o_ptr->art_flags, TR_RES_POIS);
2079 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2081 case EGO_SLAYING_WEAPON:
2082 if (one_in_(3)) /* double damage */
2089 } while (one_in_(o_ptr->dd));
2094 } while (one_in_(o_ptr->ds));
2099 add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2101 if (o_ptr->tval == TV_SWORD && one_in_(3))
2103 add_flag(o_ptr->art_flags, TR_VORPAL);
2108 add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
2114 add_flag(o_ptr->art_flags, TR_HOLD_EXP);
2116 add_flag(o_ptr->art_flags, TR_DEX);
2118 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2121 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, level) + 1;
2123 case EGO_EARTHQUAKES:
2124 if (one_in_(3) && (level > 60))
2125 add_flag(o_ptr->art_flags, TR_BLOWS);
2127 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, level);
2131 add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
2135 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2137 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2139 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2140 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2143 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CHAOTIC);
2144 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BLOWS);
2145 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2146 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2150 if (!o_ptr->art_name)
2152 /* Hack -- Super-charge the damage dice */
2153 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2155 /* Hack -- Lower the damage dice */
2156 if (o_ptr->dd > 9) o_ptr->dd = 9;
2161 else if (power < -1)
2163 /* Roll for ego-item */
2164 if (randint0(MAX_DEPTH) < level)
2168 o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE);
2169 if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2175 switch (o_ptr->name2)
2178 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2179 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2182 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2183 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_NETHER);
2184 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2185 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2186 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2187 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2202 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2204 become_random_artifact(o_ptr, FALSE);
2207 o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE);
2221 if (power > 2) /* power > 2 is debug only */
2223 become_random_artifact(o_ptr, FALSE);
2227 o_ptr->name2 = get_random_ego(INVEN_AMMO, TRUE);
2229 switch (o_ptr->name2)
2231 case EGO_SLAYING_BOLT:
2236 /* Hack -- super-charge the damage dice */
2237 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2239 /* Hack -- restrict the damage dice */
2240 if (o_ptr->dd > 9) o_ptr->dd = 9;
2244 else if (power < -1)
2246 /* Roll for ego-item */
2247 if (randint0(MAX_DEPTH) < level)
2249 o_ptr->name2 = get_random_ego(INVEN_AMMO, FALSE);
2259 * @brief 防具系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2260 * Apply magic to an item known to be "armor"
2261 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2262 * @param level 生成基準階
2263 * @param power 生成ランク
2266 * Hack -- note special processing for crown/helm\n
2267 * Hack -- note special processing for robe of permanence\n
2269 static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
2271 ARMOUR_CLASS toac1 = (ARMOUR_CLASS)randint1(5) + m_bonus(5, level);
2272 ARMOUR_CLASS toac2 = (ARMOUR_CLASS)m_bonus(10, level);
2278 o_ptr->to_a += toac1;
2284 o_ptr->to_a += toac2;
2292 o_ptr->to_a -= toac1;
2297 /* Penalize again */
2298 o_ptr->to_a -= toac2;
2301 /* Cursed (if "bad") */
2302 if (o_ptr->to_a < 0) o_ptr->curse_flags |= TRC_CURSED;
2305 switch (o_ptr->tval)
2309 if (one_in_(50) || (power > 2)) /* power > 2 is debug only */
2310 become_random_artifact(o_ptr, FALSE);
2320 /* Hack -- Try for "Robes of the Magi" */
2321 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
2322 (o_ptr->sval == SV_ROBE) &&
2323 (randint0(100) < 15))
2327 o_ptr->name2 = EGO_YOIYAMI;
2328 o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
2329 o_ptr->sval = SV_YOIYAMI_ROBE;
2335 o_ptr->name2 = EGO_PERMANENCE;
2340 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2342 become_random_artifact(o_ptr, FALSE);
2348 bool okay_flag = TRUE;
2350 o_ptr->name2 = get_random_ego(INVEN_BODY, TRUE);
2352 switch (o_ptr->name2)
2355 if (o_ptr->tval != TV_HARD_ARMOR)
2361 if (o_ptr->tval != TV_SOFT_ARMOR)
2370 if (okay_flag) break;
2372 switch (o_ptr->name2)
2374 case EGO_RESISTANCE:
2376 add_flag(o_ptr->art_flags, TR_RES_POIS);
2379 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2380 o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
2384 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2386 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2388 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2389 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2391 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2392 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2393 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2394 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2395 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2396 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2397 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2398 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2401 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2402 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2403 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2404 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2405 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2406 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2419 if (o_ptr->sval == SV_DRAGON_SHIELD)
2421 dragon_resist(o_ptr);
2422 if (!one_in_(3)) break;
2428 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2430 become_random_artifact(o_ptr, FALSE);
2436 o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE);
2437 if (o_ptr->sval != SV_SMALL_METAL_SHIELD && o_ptr->sval != SV_LARGE_METAL_SHIELD
2438 && o_ptr->name2 == EGO_S_DWARVEN)
2445 switch (o_ptr->name2)
2448 if (!one_in_(3)) one_high_resistance(o_ptr);
2449 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_POIS);
2451 case EGO_REFLECTION:
2452 if (o_ptr->sval == SV_MIRROR_SHIELD)
2457 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2458 o_ptr->ac = k_info[o_ptr->k_idx].ac + 3;
2467 if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
2469 dragon_resist(o_ptr);
2470 if (!one_in_(3)) break;
2474 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2476 become_random_artifact(o_ptr, FALSE);
2479 o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE);
2483 else if (power < -1)
2485 o_ptr->name2 = get_random_ego(INVEN_HANDS, FALSE);
2493 if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
2495 dragon_resist(o_ptr);
2496 if (!one_in_(3)) break;
2501 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2503 become_random_artifact(o_ptr, FALSE);
2506 o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE);
2508 switch (o_ptr->name2)
2510 case EGO_SLOW_DESCENT:
2513 one_high_resistance(o_ptr);
2519 else if (power < -1)
2521 o_ptr->name2 = get_random_ego(INVEN_FEET, FALSE);
2532 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2534 become_random_artifact(o_ptr, FALSE);
2539 bool ok_flag = TRUE;
2540 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2542 switch (o_ptr->name2)
2545 if (add_esp_strong(o_ptr)) add_esp_weak(o_ptr, TRUE);
2546 else add_esp_weak(o_ptr, FALSE);
2550 case EGO_REGENERATION:
2551 case EGO_LORDLINESS:
2557 if (one_in_(2)) add_esp_strong(o_ptr);
2558 else add_esp_weak(o_ptr, FALSE);
2561 default:/* not existing crown (wisdom,lite, etc...) */
2565 break; /* while (1) */
2571 else if (power < -1)
2575 bool ok_flag = TRUE;
2576 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2578 switch (o_ptr->name2)
2580 case EGO_ANCIENT_CURSE:
2581 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2582 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2583 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2584 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2585 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2586 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2590 break; /* while (1) */
2599 if (o_ptr->sval == SV_DRAGON_HELM)
2601 dragon_resist(o_ptr);
2602 if (!one_in_(3)) break;
2608 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2610 become_random_artifact(o_ptr, FALSE);
2615 bool ok_flag = TRUE;
2616 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2618 switch (o_ptr->name2)
2620 case EGO_BRILLIANCE:
2622 case EGO_INFRAVISION:
2623 case EGO_H_PROTECTION:
2628 if (one_in_(2)) add_esp_strong(o_ptr);
2629 else add_esp_weak(o_ptr, FALSE);
2633 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_1);
2634 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_2);
2637 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2639 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2641 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2642 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2644 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2645 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2646 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2647 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2648 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2649 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2650 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2651 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2653 default:/* not existing helm (Magi, Might, etc...)*/
2657 break; /* while (1) */
2662 else if (power < -1)
2666 bool ok_flag = TRUE;
2667 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2669 switch (o_ptr->name2)
2671 case EGO_ANCIENT_CURSE:
2675 break; /* while (1) */
2686 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2688 become_random_artifact(o_ptr, FALSE);
2691 o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE);
2693 switch (o_ptr->name2)
2702 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_COWARDICE);
2703 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CALL_UNDEAD);
2704 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_SLOW_REGEN);
2705 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2712 else if (power < -1)
2714 o_ptr->name2 = get_random_ego(INVEN_OUTER, FALSE);
2725 * @brief 装飾品系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2726 * Apply magic to an item known to be a "ring" or "amulet"
2727 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2728 * @param level 生成基準階
2729 * @param power 生成ランク
2732 * Hack -- note special "pval boost" code for ring of speed\n
2733 * Hack -- note that some items must be cursed (or blessed)\n
2735 static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
2737 /* Apply magic (good or bad) according to type */
2738 switch (o_ptr->tval)
2743 switch (o_ptr->sval)
2745 case SV_RING_ATTACKS:
2748 o_ptr->pval = (PARAMETER_VALUE)m_bonus(2, level);
2749 if (one_in_(15)) o_ptr->pval++;
2750 if (o_ptr->pval < 1) o_ptr->pval = 1;
2756 o_ptr->ident |= (IDENT_BROKEN);
2759 o_ptr->curse_flags |= TRC_CURSED;
2762 o_ptr->pval = 0 - (o_ptr->pval);
2773 /* Strength, Constitution, Dexterity, Intelligence */
2779 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2785 o_ptr->ident |= (IDENT_BROKEN);
2788 o_ptr->curse_flags |= TRC_CURSED;
2791 o_ptr->pval = 0 - (o_ptr->pval);
2797 /* Ring of Speed! */
2800 /* Base speed (1 to 10) */
2801 o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
2803 /* Super-charge the ring */
2804 while (randint0(100) < 50) o_ptr->pval++;
2810 o_ptr->ident |= (IDENT_BROKEN);
2813 o_ptr->curse_flags |= TRC_CURSED;
2816 o_ptr->pval = 0 - (o_ptr->pval);
2824 case SV_RING_LORDLY:
2828 one_lordly_high_resistance(o_ptr);
2832 /* Bonus to armor class */
2833 o_ptr->to_a = 10 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2837 case SV_RING_WARNING:
2839 if (one_in_(3)) one_low_esp(o_ptr);
2844 case SV_RING_SEARCHING:
2846 /* Bonus to searching */
2847 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2853 o_ptr->ident |= (IDENT_BROKEN);
2856 o_ptr->curse_flags |= TRC_CURSED;
2859 o_ptr->pval = 0 - (o_ptr->pval);
2865 /* Flames, Acid, Ice */
2866 case SV_RING_FLAMES:
2871 /* Bonus to armor class */
2872 o_ptr->to_a = 5 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2876 /* Weakness, Stupidity */
2877 case SV_RING_WEAKNESS:
2878 case SV_RING_STUPIDITY:
2881 o_ptr->ident |= (IDENT_BROKEN);
2884 o_ptr->curse_flags |= TRC_CURSED;
2887 o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2888 if (power > 0) power = 0 - power;
2893 /* WOE, Stupidity */
2897 o_ptr->ident |= (IDENT_BROKEN);
2900 o_ptr->curse_flags |= TRC_CURSED;
2903 o_ptr->to_a = 0 - (5 + (ARMOUR_CLASS)m_bonus(10, level));
2904 o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2905 if (power > 0) power = 0 - power;
2910 /* Ring of damage */
2911 case SV_RING_DAMAGE:
2913 /* Bonus to damage */
2914 o_ptr->to_d = 1 + randint1(5) + (HIT_POINT)m_bonus(16, level);
2920 o_ptr->ident |= (IDENT_BROKEN);
2923 o_ptr->curse_flags |= TRC_CURSED;
2926 o_ptr->to_d = 0 - o_ptr->to_d;
2932 /* Ring of Accuracy */
2933 case SV_RING_ACCURACY:
2936 o_ptr->to_h = 1 + randint1(5) + (HIT_PROB)m_bonus(16, level);
2942 o_ptr->ident |= (IDENT_BROKEN);
2945 o_ptr->curse_flags |= TRC_CURSED;
2948 o_ptr->to_h = 0 - o_ptr->to_h;
2954 /* Ring of Protection */
2955 case SV_RING_PROTECTION:
2957 /* Bonus to armor class */
2958 o_ptr->to_a = 5 + randint1(8) + (ARMOUR_CLASS)m_bonus(10, level);
2964 o_ptr->ident |= (IDENT_BROKEN);
2967 o_ptr->curse_flags |= TRC_CURSED;
2970 o_ptr->to_a = 0 - o_ptr->to_a;
2976 /* Ring of Slaying */
2977 case SV_RING_SLAYING:
2979 /* Bonus to damage and to hit */
2980 o_ptr->to_d = randint1(5) + (HIT_POINT)m_bonus(12, level);
2981 o_ptr->to_h = randint1(5) + (HIT_PROB)m_bonus(12, level);
2987 o_ptr->ident |= (IDENT_BROKEN);
2990 o_ptr->curse_flags |= TRC_CURSED;
2992 /* Reverse bonuses */
2993 o_ptr->to_h = 0 - o_ptr->to_h;
2994 o_ptr->to_d = 0 - o_ptr->to_d;
3000 case SV_RING_MUSCLE:
3002 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(3, level);
3003 if (one_in_(4)) o_ptr->pval++;
3009 o_ptr->ident |= (IDENT_BROKEN);
3012 o_ptr->curse_flags |= TRC_CURSED;
3014 /* Reverse bonuses */
3015 o_ptr->pval = 0 - o_ptr->pval;
3020 case SV_RING_AGGRAVATION:
3023 o_ptr->ident |= (IDENT_BROKEN);
3026 o_ptr->curse_flags |= TRC_CURSED;
3028 if (power > 0) power = 0 - power;
3032 if ((one_in_(400) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3033 || (power > 2)) /* power > 2 is debug only */
3035 o_ptr->pval = MIN(o_ptr->pval, 4);
3036 /* Randart amulet */
3037 become_random_artifact(o_ptr, FALSE);
3039 else if ((power == 2) && one_in_(2))
3041 while(!o_ptr->name2)
3043 int tmp = m_bonus(10, level);
3044 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3045 switch(randint1(28))
3048 o_ptr->name2 = EGO_RING_THROW;
3051 if (have_flag(k_ptr->flags, TR_REGEN)) break;
3052 o_ptr->name2 = EGO_RING_REGEN;
3055 if (have_flag(k_ptr->flags, TR_LITE_1)) break;
3056 o_ptr->name2 = EGO_RING_LITE;
3059 if (have_flag(k_ptr->flags, TR_TELEPORT)) break;
3060 o_ptr->name2 = EGO_RING_TELEPORT;
3063 if (o_ptr->to_h) break;
3064 o_ptr->name2 = EGO_RING_TO_H;
3067 if (o_ptr->to_d) break;
3068 o_ptr->name2 = EGO_RING_TO_D;
3071 if ((o_ptr->to_h) || (o_ptr->to_d)) break;
3072 o_ptr->name2 = EGO_RING_SLAY;
3075 if ((have_flag(k_ptr->flags, TR_STR)) || o_ptr->to_h || o_ptr->to_d) break;
3076 o_ptr->name2 = EGO_RING_WIZARD;
3079 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3080 o_ptr->name2 = EGO_RING_HERO;
3083 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3084 if (tmp > 8) o_ptr->name2 = EGO_RING_MANA_BALL;
3085 else if (tmp > 4) o_ptr->name2 = EGO_RING_MANA_BOLT;
3086 else o_ptr->name2 = EGO_RING_MAGIC_MIS;
3089 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3090 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;
3091 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_F;
3092 else if (tmp > 3) o_ptr->name2 = EGO_RING_FIRE_BALL;
3093 else o_ptr->name2 = EGO_RING_FIRE_BOLT;
3096 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3097 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;
3098 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_C;
3099 else if (tmp > 3) o_ptr->name2 = EGO_RING_COLD_BALL;
3100 else o_ptr->name2 = EGO_RING_COLD_BOLT;
3103 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3104 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;
3105 if (tmp > 4) o_ptr->name2 = EGO_RING_ELEC_BALL;
3106 else o_ptr->name2 = EGO_RING_ELEC_BOLT;
3109 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3110 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;
3111 if (tmp > 4) o_ptr->name2 = EGO_RING_ACID_BALL;
3112 else o_ptr->name2 = EGO_RING_ACID_BOLT;
3114 case 21: case 22: case 23: case 24: case 25: case 26:
3115 switch (o_ptr->sval)
3118 if (!one_in_(3)) break;
3119 o_ptr->name2 = EGO_RING_D_SPEED;
3121 case SV_RING_DAMAGE:
3122 case SV_RING_ACCURACY:
3123 case SV_RING_SLAYING:
3124 if (one_in_(2)) break;
3125 if (one_in_(2)) o_ptr->name2 = EGO_RING_HERO;
3128 o_ptr->name2 = EGO_RING_BERSERKER;
3129 o_ptr->to_h -= 2+randint1(4);
3130 o_ptr->to_d += 2+randint1(4);
3133 case SV_RING_PROTECTION:
3134 o_ptr->name2 = EGO_RING_SUPER_AC;
3135 o_ptr->to_a += 7 + m_bonus(5, level);
3137 case SV_RING_RES_FEAR:
3138 o_ptr->name2 = EGO_RING_HERO;
3141 if (one_in_(2)) break;
3142 o_ptr->name2 = EGO_RING_HUNTER;
3144 case SV_RING_SEARCHING:
3145 o_ptr->name2 = EGO_RING_STEALTH;
3147 case SV_RING_TELEPORTATION:
3148 o_ptr->name2 = EGO_RING_TELE_AWAY;
3150 case SV_RING_RES_BLINDNESS:
3152 o_ptr->name2 = EGO_RING_RES_LITE;
3154 o_ptr->name2 = EGO_RING_RES_DARK;
3156 case SV_RING_LORDLY:
3157 if (!one_in_(20)) break;
3158 one_lordly_high_resistance(o_ptr);
3159 one_lordly_high_resistance(o_ptr);
3160 o_ptr->name2 = EGO_RING_TRUE;
3162 case SV_RING_SUSTAIN:
3163 if (!one_in_(4)) break;
3164 o_ptr->name2 = EGO_RING_RES_TIME;
3166 case SV_RING_FLAMES:
3167 if (!one_in_(2)) break;
3168 o_ptr->name2 = EGO_RING_DRAGON_F;
3171 if (!one_in_(2)) break;
3172 o_ptr->name2 = EGO_RING_DRAGON_C;
3174 case SV_RING_WARNING:
3175 if (!one_in_(2)) break;
3176 o_ptr->name2 = EGO_RING_M_DETECT;
3184 o_ptr->curse_flags = 0L;
3186 else if ((power == -2) && one_in_(2))
3188 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3189 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3190 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3191 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3192 o_ptr->art_flags[0] = 0;
3193 o_ptr->art_flags[1] = 0;
3194 while(!o_ptr->name2)
3196 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3200 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3201 o_ptr->name2 = EGO_RING_DRAIN_EXP;
3204 o_ptr->name2 = EGO_RING_NO_MELEE;
3207 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3208 o_ptr->name2 = EGO_RING_AGGRAVATE;
3211 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3212 o_ptr->name2 = EGO_RING_TY_CURSE;
3215 o_ptr->name2 = EGO_RING_ALBINO;
3220 o_ptr->ident |= (IDENT_BROKEN);
3223 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3231 switch (o_ptr->sval)
3233 /* Amulet of wisdom/charisma */
3234 case SV_AMULET_INTELLIGENCE:
3235 case SV_AMULET_WISDOM:
3236 case SV_AMULET_CHARISMA:
3238 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
3244 o_ptr->ident |= (IDENT_BROKEN);
3247 o_ptr->curse_flags |= (TRC_CURSED);
3249 /* Reverse bonuses */
3250 o_ptr->pval = 0 - o_ptr->pval;
3256 /* Amulet of brilliance */
3257 case SV_AMULET_BRILLIANCE:
3259 o_ptr->pval = 1 + m_bonus(3, level);
3260 if (one_in_(4)) o_ptr->pval++;
3266 o_ptr->ident |= (IDENT_BROKEN);
3269 o_ptr->curse_flags |= (TRC_CURSED);
3271 /* Reverse bonuses */
3272 o_ptr->pval = 0 - o_ptr->pval;
3278 case SV_AMULET_NO_MAGIC: case SV_AMULET_NO_TELE:
3282 o_ptr->curse_flags |= (TRC_CURSED);
3287 case SV_AMULET_RESISTANCE:
3289 if (one_in_(5)) one_high_resistance(o_ptr);
3290 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_RES_POIS);
3294 /* Amulet of searching */
3295 case SV_AMULET_SEARCHING:
3297 o_ptr->pval = randint1(2) + (PARAMETER_VALUE)m_bonus(4, level);
3303 o_ptr->ident |= (IDENT_BROKEN);
3306 o_ptr->curse_flags |= (TRC_CURSED);
3308 /* Reverse bonuses */
3309 o_ptr->pval = 0 - (o_ptr->pval);
3315 /* Amulet of the Magi -- never cursed */
3316 case SV_AMULET_THE_MAGI:
3318 o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
3319 o_ptr->to_a = randint1(5) + (ARMOUR_CLASS)m_bonus(5, level);
3321 /* gain one low ESP */
3322 add_esp_weak(o_ptr, FALSE);
3327 /* Amulet of Doom -- always cursed */
3328 case SV_AMULET_DOOM:
3331 o_ptr->ident |= (IDENT_BROKEN);
3334 o_ptr->curse_flags |= (TRC_CURSED);
3337 o_ptr->pval = 0 - (randint1(5) + (PARAMETER_VALUE)m_bonus(5, level));
3338 o_ptr->to_a = 0 - (randint1(5) + (ARMOUR_CLASS)m_bonus(5, level));
3339 if (power > 0) power = 0 - power;
3344 case SV_AMULET_MAGIC_MASTERY:
3346 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(4, level);
3352 o_ptr->ident |= (IDENT_BROKEN);
3355 o_ptr->curse_flags |= (TRC_CURSED);
3357 /* Reverse bonuses */
3358 o_ptr->pval = 0 - o_ptr->pval;
3364 if ((one_in_(150) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3365 || (power > 2)) /* power > 2 is debug only */
3367 o_ptr->pval = MIN(o_ptr->pval, 4);
3368 /* Randart amulet */
3369 become_random_artifact(o_ptr, FALSE);
3371 else if ((power == 2) && one_in_(2))
3373 while(!o_ptr->name2)
3375 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3376 switch(randint1(21))
3379 if (have_flag(k_ptr->flags, TR_SLOW_DIGEST)) break;
3380 o_ptr->name2 = EGO_AMU_SLOW_D;
3383 if (o_ptr->pval) break;
3384 o_ptr->name2 = EGO_AMU_INFRA;
3387 if (have_flag(k_ptr->flags, TR_SEE_INVIS)) break;
3388 o_ptr->name2 = EGO_AMU_SEE_INVIS;
3391 if (have_flag(k_ptr->flags, TR_HOLD_EXP)) break;
3392 o_ptr->name2 = EGO_AMU_HOLD_EXP;
3395 if (have_flag(k_ptr->flags, TR_LEVITATION)) break;
3396 o_ptr->name2 = EGO_AMU_LEVITATION;
3398 case 10: case 11: case 21:
3399 o_ptr->name2 = EGO_AMU_AC;
3402 if (have_flag(k_ptr->flags, TR_RES_FIRE)) break;
3403 if (m_bonus(10, level) > 8)
3404 o_ptr->name2 = EGO_AMU_RES_FIRE_;
3406 o_ptr->name2 = EGO_AMU_RES_FIRE;
3409 if (have_flag(k_ptr->flags, TR_RES_COLD)) break;
3410 if (m_bonus(10, level) > 8)
3411 o_ptr->name2 = EGO_AMU_RES_COLD_;
3413 o_ptr->name2 = EGO_AMU_RES_COLD;
3416 if (have_flag(k_ptr->flags, TR_RES_ELEC)) break;
3417 if (m_bonus(10, level) > 8)
3418 o_ptr->name2 = EGO_AMU_RES_ELEC_;
3420 o_ptr->name2 = EGO_AMU_RES_ELEC;
3423 if (have_flag(k_ptr->flags, TR_RES_ACID)) break;
3424 if (m_bonus(10, level) > 8)
3425 o_ptr->name2 = EGO_AMU_RES_ACID_;
3427 o_ptr->name2 = EGO_AMU_RES_ACID;
3429 case 16: case 17: case 18: case 19: case 20:
3430 switch (o_ptr->sval)
3432 case SV_AMULET_TELEPORT:
3433 if (m_bonus(10, level) > 9) o_ptr->name2 = EGO_AMU_D_DOOR;
3434 else if (one_in_(2)) o_ptr->name2 = EGO_AMU_JUMP;
3435 else o_ptr->name2 = EGO_AMU_TELEPORT;
3437 case SV_AMULET_RESIST_ACID:
3438 if ((m_bonus(10, level) > 6) && one_in_(2)) o_ptr->name2 = EGO_AMU_RES_ACID_;
3440 case SV_AMULET_SEARCHING:
3441 o_ptr->name2 = EGO_AMU_STEALTH;
3443 case SV_AMULET_BRILLIANCE:
3444 if (!one_in_(3)) break;
3445 o_ptr->name2 = EGO_AMU_IDENT;
3447 case SV_AMULET_CHARISMA:
3448 if (!one_in_(3)) break;
3449 o_ptr->name2 = EGO_AMU_CHARM;
3451 case SV_AMULET_THE_MAGI:
3452 if (one_in_(2)) break;
3453 o_ptr->name2 = EGO_AMU_GREAT;
3455 case SV_AMULET_RESISTANCE:
3456 if (!one_in_(5)) break;
3457 o_ptr->name2 = EGO_AMU_DEFENDER;
3459 case SV_AMULET_TELEPATHY:
3460 if (!one_in_(3)) break;
3461 o_ptr->name2 = EGO_AMU_DETECTION;
3466 o_ptr->curse_flags = 0L;
3468 else if ((power == -2) && one_in_(2))
3470 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3471 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3472 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3473 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3474 o_ptr->art_flags[0] = 0;
3475 o_ptr->art_flags[1] = 0;
3476 while(!o_ptr->name2)
3478 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3482 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3483 o_ptr->name2 = EGO_AMU_DRAIN_EXP;
3486 o_ptr->name2 = EGO_AMU_FOOL;
3489 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3490 o_ptr->name2 = EGO_AMU_AGGRAVATE;
3493 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3494 o_ptr->name2 = EGO_AMU_TY_CURSE;
3497 o_ptr->name2 = EGO_AMU_NAIVETY;
3502 o_ptr->ident |= (IDENT_BROKEN);
3505 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3514 * @brief その他雑多のオブジェクトに生成ランクごとの強化を与えるサブルーチン
3515 * Apply magic to an item known to be "boring"
3516 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3517 * @param level 生成基準階
3518 * @param power 生成ランク
3521 * Hack -- note the special code for various items
3523 static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
3525 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3530 /* Apply magic (good or bad) according to type */
3531 switch (o_ptr->tval)
3540 o_ptr->ident |= (IDENT_BROKEN);
3543 o_ptr->curse_flags |= (TRC_CURSED);
3550 o_ptr->xtra4 = o_ptr->pval;
3556 /* Hack -- Torches -- random fuel */
3557 if (o_ptr->sval == SV_LITE_TORCH)
3559 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3563 /* Hack -- Lanterns -- random fuel */
3564 if (o_ptr->sval == SV_LITE_LANTERN)
3566 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3570 if (power > 2) /* power > 2 is debug only */
3572 become_random_artifact(o_ptr, FALSE);
3574 else if ((power == 2) || ((power == 1) && one_in_(3)))
3576 while (!o_ptr->name2)
3580 bool okay_flag = TRUE;
3582 o_ptr->name2 = get_random_ego(INVEN_LITE, TRUE);
3584 switch (o_ptr->name2)
3587 if (o_ptr->sval == SV_LITE_FEANOR)
3595 else if (power == -2)
3597 o_ptr->name2 = get_random_ego(INVEN_LITE, FALSE);
3599 switch (o_ptr->name2)
3601 case EGO_LITE_DARKNESS:
3604 if (o_ptr->sval == SV_LITE_TORCH)
3606 add_flag(o_ptr->art_flags, TR_LITE_M1);
3608 else if (o_ptr->sval == SV_LITE_LANTERN)
3610 add_flag(o_ptr->art_flags, TR_LITE_M2);
3612 else if (o_ptr->sval == SV_LITE_FEANOR)
3614 add_flag(o_ptr->art_flags, TR_LITE_M3);
3626 /* The wand or staff gets a number of initial charges equal
3627 * to between 1/2 (+1) and the full object kind's pval. -LM-
3629 o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
3635 /* Transfer the pval. -LM- */
3636 o_ptr->pval = k_ptr->pval;
3643 object_aware(o_ptr);
3644 object_known(o_ptr);
3650 PARAMETER_VALUE i = 1;
3653 monster_race *r_ptr;
3655 /* Pick a random non-unique monster race */
3658 i = randint1(max_r_idx - 1);
3660 if (!item_monster_okay(i)) continue;
3661 if (i == MON_TSUCHINOKO) continue;
3665 check = (p_ptr->current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - p_ptr->current_floor_ptr->dun_level) : 0;
3667 /* Ignore dead monsters */
3668 if (!r_ptr->rarity) continue;
3670 /* Ignore uncommon monsters */
3671 if (r_ptr->rarity > 100) continue;
3673 /* Prefer less out-of-depth monsters */
3674 if (randint0(check)) continue;
3681 /* Some figurines are cursed */
3682 if (one_in_(6)) o_ptr->curse_flags |= TRC_CURSED;
3689 PARAMETER_VALUE i = 1;
3694 monster_race *r_ptr;
3696 if (o_ptr->sval == SV_SKELETON)
3698 match = RF9_DROP_SKELETON;
3700 else if (o_ptr->sval == SV_CORPSE)
3702 match = RF9_DROP_CORPSE;
3705 /* Hack -- Remove the monster restriction */
3706 get_mon_num_prep(item_monster_okay, NULL);
3708 /* Pick a random non-unique monster race */
3711 i = get_mon_num(p_ptr->current_floor_ptr->dun_level);
3715 check = (p_ptr->current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - p_ptr->current_floor_ptr->dun_level) : 0;
3717 /* Ignore dead monsters */
3718 if (!r_ptr->rarity) continue;
3720 /* Ignore corpseless monsters */
3721 if (!(r_ptr->flags9 & match)) continue;
3723 /* Prefer less out-of-depth monsters */
3724 if (randint0(check)) continue;
3732 object_aware(o_ptr);
3733 object_known(o_ptr);
3739 PARAMETER_VALUE i = 1;
3741 monster_race *r_ptr;
3743 /* Pick a random monster race */
3746 i = randint1(max_r_idx - 1);
3750 /* Ignore dead monsters */
3751 if (!r_ptr->rarity) continue;
3760 msg_format(_("%sの像", "Statue of %s"), r_name + r_ptr->name);
3762 object_aware(o_ptr);
3763 object_known(o_ptr);
3770 DEPTH obj_level = k_info[o_ptr->k_idx].level;
3772 /* Hack -- skip ruined chests */
3773 if (obj_level <= 0) break;
3775 /* Hack -- pick a "difficulty" */
3776 o_ptr->pval = randint1(obj_level);
3777 if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
3779 o_ptr->xtra3 = p_ptr->current_floor_ptr->dun_level + 5;
3781 /* Never exceed "difficulty" of 55 to 59 */
3782 if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
3790 * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
3791 * Complete the "creation" of an object by applying "magic" to the item
3792 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3794 * @param mode 生成オプション
3797 * This includes not only rolling for random bonuses, but also putting the\n
3798 * finishing touches on ego-items and artifacts, giving charges to wands and\n
3799 * staffs, giving fuel to lites, and placing traps on chests.\n
3801 * In particular, note that "Instant Artifacts", if "created" by an external\n
3802 * routine, must pass through this function to complete the actual creation.\n
3804 * The base "chance" of the item being "good" increases with the "level"\n
3805 * parameter, which is usually derived from the dungeon level, being equal\n
3806 * to the level plus 10, up to a maximum of 75. If "good" is true, then\n
3807 * the object is guaranteed to be "good". If an object is "good", then\n
3808 * the chance that the object will be "great" (ego-item or artifact), also\n
3809 * increases with the "level", being equal to half the level, plus 5, up to\n
3810 * a maximum of 20. If "great" is true, then the object is guaranteed to be\n
3811 * "great". At dungeon level 65 and below, 15/100 objects are "great".\n
3813 * If the object is not "good", there is a chance it will be "cursed", and\n
3814 * if it is "cursed", there is a chance it will be "broken". These chances\n
3815 * are related to the "good" / "great" chances above.\n
3817 * Otherwise "normal" rings and amulets will be "good" half the time and\n
3818 * "cursed" half the time, unless the ring/amulet is always good or cursed.\n
3820 * If "okay" is true, and the object is going to be "great", then there is\n
3821 * a chance that an artifact will be created. This is true even if both the\n
3822 * "good" and "great" arguments are false. As a total hack, if "great" is\n
3823 * true, then the item gets 3 extra "attempts" to become an artifact.\n
3825 void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
3827 int i, rolls, f1, f2, power;
3829 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) lev += randint0(p_ptr->lev/2+10);
3831 /* Maximum "level" for various things */
3832 if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1;
3834 /* Base chance of being "good" */
3837 /* Maximal chance of being "good" */
3838 if (f1 > d_info[p_ptr->dungeon_idx].obj_good) f1 = d_info[p_ptr->dungeon_idx].obj_good;
3840 /* Base chance of being "great" */
3843 /* Maximal chance of being "great" */
3844 if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[p_ptr->dungeon_idx].obj_great))
3845 f2 = d_info[p_ptr->dungeon_idx].obj_great;
3847 if (p_ptr->muta3 & MUT3_GOOD_LUCK)
3852 else if(p_ptr->muta3 & MUT3_BAD_LUCK)
3861 /* Roll for "good" */
3862 if ((mode & AM_GOOD) || magik(f1))
3867 /* Roll for "great" */
3868 if ((mode & AM_GREAT) || magik(f2))
3872 /* Roll for "special" */
3873 if (mode & AM_SPECIAL) power = 3;
3877 /* Roll for "cursed" */
3880 /* Assume "cursed" */
3883 /* Roll for "broken" */
3884 if (magik(f2)) power = -2;
3888 if (mode & AM_CURSED)
3890 /* Assume 'cursed' */
3895 /* Everything else gets more badly cursed */
3902 /* Assume no rolls */
3905 /* Get one roll if excellent */
3906 if (power >= 2) rolls = 1;
3908 /* Hack -- Get four rolls if forced great or special */
3909 if (mode & (AM_GREAT | AM_SPECIAL)) rolls = 4;
3911 /* Hack -- Get no rolls if not allowed */
3912 if ((mode & AM_NO_FIXED_ART) || o_ptr->name1) rolls = 0;
3914 /* Roll for artifacts if allowed */
3915 for (i = 0; i < rolls; i++)
3917 /* Roll for an artifact */
3918 if (make_artifact(o_ptr)) break;
3919 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77))
3921 if (make_artifact(o_ptr)) break;
3926 /* Hack -- analyze artifacts */
3927 if (object_is_fixed_artifact(o_ptr))
3929 artifact_type *a_ptr = &a_info[o_ptr->name1];
3931 /* Hack -- Mark the artifact as "created" */
3934 /* Hack -- Memorize location of artifact in saved floors */
3935 if (current_world_ptr->character_dungeon)
3936 a_ptr->floor_id = p_ptr->floor_id;
3938 /* Extract the other fields */
3939 o_ptr->pval = a_ptr->pval;
3940 o_ptr->ac = a_ptr->ac;
3941 o_ptr->dd = a_ptr->dd;
3942 o_ptr->ds = a_ptr->ds;
3943 o_ptr->to_a = a_ptr->to_a;
3944 o_ptr->to_h = a_ptr->to_h;
3945 o_ptr->to_d = a_ptr->to_d;
3946 o_ptr->weight = a_ptr->weight;
3947 o_ptr->xtra2 = a_ptr->act_idx;
3949 if (o_ptr->name1 == ART_MILIM)
3951 if(p_ptr->pseikaku == SEIKAKU_SEXY)
3957 /* Hack -- extract the "broken" flag */
3958 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
3960 /* Hack -- extract the "cursed" flag */
3961 if (a_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
3962 if (a_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
3963 if (a_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
3964 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
3965 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
3966 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
3971 switch (o_ptr->tval)
3980 if (power) apply_magic_weapon(o_ptr, lev, power);
3986 if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) apply_magic_weapon(o_ptr, lev, power);
3992 if (power && !(o_ptr->sval == SV_DOKUBARI)) apply_magic_weapon(o_ptr, lev, power);
4006 /* Elven Cloak and Black Clothes ... */
4007 if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) ||
4008 ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
4009 o_ptr->pval = randint1(4);
4013 ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) ||
4014 ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD)) ||
4015 ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)) ||
4016 ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
4017 a_m_aux_2(o_ptr, lev, power);
4019 if (power) a_m_aux_2(o_ptr, lev, power);
4027 if (!power && (randint0(100) < 50)) power = -1;
4028 a_m_aux_3(o_ptr, lev, power);
4034 a_m_aux_4(o_ptr, lev, power);
4039 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
4040 (o_ptr->sval == SV_ABUNAI_MIZUGI) &&
4041 (p_ptr->pseikaku == SEIKAKU_SEXY))
4044 add_flag(o_ptr->art_flags, TR_STR);
4045 add_flag(o_ptr->art_flags, TR_INT);
4046 add_flag(o_ptr->art_flags, TR_WIS);
4047 add_flag(o_ptr->art_flags, TR_DEX);
4048 add_flag(o_ptr->art_flags, TR_CON);
4049 add_flag(o_ptr->art_flags, TR_CHR);
4052 /* Hack -- analyze ego-items */
4053 if (object_is_ego(o_ptr))
4055 ego_item_type *e_ptr = &e_info[o_ptr->name2];
4057 /* Hack -- acquire "broken" flag */
4058 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4060 /* Hack -- acquire "cursed" flag */
4061 if (e_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4062 if (e_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4063 if (e_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4064 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4065 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4066 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4068 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN)) one_sustain(o_ptr);
4069 if (e_ptr->gen_flags & (TRG_XTRA_POWER)) one_ability(o_ptr);
4070 if (e_ptr->gen_flags & (TRG_XTRA_H_RES)) one_high_resistance(o_ptr);
4071 if (e_ptr->gen_flags & (TRG_XTRA_E_RES)) one_ele_resistance(o_ptr);
4072 if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
4073 if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
4074 if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
4075 if (e_ptr->gen_flags & (TRG_XTRA_DICE))
4081 while (one_in_(o_ptr->dd));
4083 if (o_ptr->dd > 9) o_ptr->dd = 9;
4086 /* Hack -- apply activatin index if needed */
4087 if (e_ptr->act_idx) o_ptr->xtra2 = (XTRA8)e_ptr->act_idx;
4089 /* Hack -- apply extra penalties if needed */
4090 if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL)))
4092 /* Hack -- obtain bonuses */
4093 if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
4094 if (e_ptr->max_to_d) o_ptr->to_d -= randint1(e_ptr->max_to_d);
4095 if (e_ptr->max_to_a) o_ptr->to_a -= randint1(e_ptr->max_to_a);
4097 /* Hack -- obtain pval */
4098 if (e_ptr->max_pval) o_ptr->pval -= randint1(e_ptr->max_pval);
4101 /* Hack -- apply extra bonuses if needed */
4104 /* Hack -- obtain bonuses */
4105 if (e_ptr->max_to_h)
4107 if (e_ptr->max_to_h > 127)
4108 o_ptr->to_h -= randint1(256-e_ptr->max_to_h);
4109 else o_ptr->to_h += randint1(e_ptr->max_to_h);
4111 if (e_ptr->max_to_d)
4113 if (e_ptr->max_to_d > 127)
4114 o_ptr->to_d -= randint1(256-e_ptr->max_to_d);
4115 else o_ptr->to_d += randint1(e_ptr->max_to_d);
4117 if (e_ptr->max_to_a)
4119 if (e_ptr->max_to_a > 127)
4120 o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
4121 else o_ptr->to_a += randint1(e_ptr->max_to_a);
4124 /* Accuracy ego must have high to_h */
4125 if(o_ptr->name2 == EGO_ACCURACY)
4127 while(o_ptr->to_h < o_ptr->to_d + 10)
4132 o_ptr->to_h = MAX(o_ptr->to_h, 15);
4135 /* Accuracy ego must have high to_h */
4136 if(o_ptr->name2 == EGO_VELOCITY)
4138 while(o_ptr->to_d < o_ptr->to_h + 10)
4143 o_ptr->to_d = MAX(o_ptr->to_d, 15);
4146 /* Protection ego must have high to_a */
4147 if((o_ptr->name2 == EGO_PROTECTION) || (o_ptr->name2 == EGO_S_PROTECTION) || (o_ptr->name2 == EGO_H_PROTECTION))
4149 o_ptr->to_a = MAX(o_ptr->to_a, 15);
4152 /* Hack -- obtain pval */
4153 if (e_ptr->max_pval)
4155 if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS)))
4158 if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
4160 else if (o_ptr->name2 == EGO_DEMON)
4162 if(have_flag(o_ptr->art_flags, TR_BLOWS))
4164 o_ptr->pval += randint1(2);
4168 o_ptr->pval += randint1(e_ptr->max_pval);
4171 else if (o_ptr->name2 == EGO_ATTACKS)
4173 o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
4174 if (o_ptr->pval > 3) o_ptr->pval = 3;
4175 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
4176 o_ptr->pval += randint1(2);
4178 else if (o_ptr->name2 == EGO_BAT)
4180 o_ptr->pval = randint1(e_ptr->max_pval);
4181 if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
4183 else if (o_ptr->name2 == EGO_A_DEMON || o_ptr->name2 == EGO_DRUID || o_ptr->name2 == EGO_OLOG)
4185 o_ptr->pval = randint1(e_ptr->max_pval);
4189 o_ptr->pval += randint1(e_ptr->max_pval);
4194 if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
4196 o_ptr->pval = randint1(o_ptr->pval);
4198 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
4205 /* Examine real objects */
4208 object_kind *k_ptr = &k_info[o_ptr->k_idx];
4210 /* Hack -- acquire "broken" flag */
4211 if (!k_info[o_ptr->k_idx].cost) o_ptr->ident |= (IDENT_BROKEN);
4213 /* Hack -- acquire "cursed" flag */
4214 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
4215 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
4216 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
4217 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4218 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4219 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4227 * @brief 生成階に応じたベースアイテムの生成を行う。
4228 * Attempt to make an object (normal or good/great)
4229 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4230 * @param mode オプションフラグ
4231 * @return 生成に成功したらTRUEを返す。
4233 * This routine plays nasty games to generate the "special artifacts".\n
4234 * This routine uses "p_ptr->current_floor_ptr->object_level" for the "generation level".\n
4235 * We assume that the given object has been "wiped".\n
4237 bool make_object(object_type *j_ptr, BIT_FLAGS mode)
4243 /* Chance of "special object" */
4244 prob = ((mode & AM_GOOD) ? 10 : 1000);
4246 /* Base level for the object */
4247 base = ((mode & AM_GOOD) ? (p_ptr->current_floor_ptr->object_level + 10) : p_ptr->current_floor_ptr->object_level);
4250 /* Generate a special object, or a normal object */
4251 if (!one_in_(prob) || !make_artifact_special(j_ptr))
4253 KIND_OBJECT_IDX k_idx;
4256 if ((mode & AM_GOOD) && !get_obj_num_hook)
4258 /* Activate restriction (if already specified, use that) */
4259 get_obj_num_hook = kind_is_good;
4262 /* Restricted objects - prepare allocation table */
4263 if (get_obj_num_hook) get_obj_num_prep();
4265 /* Pick a random object */
4266 k_idx = get_obj_num(base, mode);
4268 /* Restricted objects */
4269 if (get_obj_num_hook)
4271 /* Clear restriction */
4272 get_obj_num_hook = NULL;
4274 /* Reset allocation table to default */
4278 /* Handle failure */
4279 if (!k_idx) return (FALSE);
4281 /* Prepare the object */
4282 object_prep(j_ptr, k_idx);
4285 /* Apply magic (allow artifacts) */
4286 apply_magic(j_ptr, p_ptr->current_floor_ptr->object_level, mode);
4288 /* Hack -- generate multiple spikes/missiles */
4289 switch (j_ptr->tval)
4297 j_ptr->number = (byte)damroll(6, 7);
4301 if (cheat_peek) object_mention(j_ptr);
4309 * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
4310 * Attempt to place an object (normal or good/great) at the given location.
4311 * @param y 配置したいフロアのY座標
4312 * @param x 配置したいフロアのX座標
4313 * @param mode オプションフラグ
4314 * @return 生成に成功したらTRUEを返す。
4316 * This routine plays nasty games to generate the "special artifacts".\n
4317 * This routine uses "p_ptr->current_floor_ptr->object_level" for the "generation level".\n
4318 * This routine requires a clean floor grid destination.\n
4320 void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
4325 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
4331 /* Paranoia -- check bounds */
4332 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
4334 /* Require floor space */
4335 if (!cave_drop_bold(p_ptr->current_floor_ptr, y, x)) return;
4337 /* Avoid stacking on other objects */
4338 if (g_ptr->o_idx) return;
4343 /* Make an object (if possible) */
4344 if (!make_object(q_ptr, mode)) return;
4352 o_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
4354 /* Structure Copy */
4355 object_copy(o_ptr, q_ptr);
4361 o_ptr->next_o_idx = g_ptr->o_idx;
4363 g_ptr->o_idx = o_idx;
4369 /* Hack -- Preserve artifacts */
4370 if (object_is_fixed_artifact(q_ptr))
4372 a_info[q_ptr->name1].cur_num = 0;
4378 OBJECT_SUBTYPE_VALUE coin_type; /* Hack -- force coin type */
4381 * @brief 生成階に応じた財宝オブジェクトの生成を行う。
4382 * Make a treasure object
4383 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4384 * @return 生成に成功したらTRUEを返す。
4386 * The location must be a legal, clean, floor grid.
4388 bool make_gold(object_type *j_ptr)
4393 /* Hack -- Pick a Treasure variety */
4394 i = ((randint1(p_ptr->current_floor_ptr->object_level + 2) + 2) / 2) - 1;
4396 /* Apply "extra" magic */
4397 if (one_in_(GREAT_OBJ))
4399 i += randint1(p_ptr->current_floor_ptr->object_level + 1);
4402 /* Hack -- Creeping Coins only generate "themselves" */
4403 if (coin_type) i = coin_type;
4405 /* Do not create "illegal" Treasure Types */
4406 if (i >= MAX_GOLD) i = MAX_GOLD - 1;
4408 /* Prepare a gold object */
4409 object_prep(j_ptr, OBJ_GOLD_LIST + i);
4411 /* Hack -- Base coin cost */
4412 base = k_info[OBJ_GOLD_LIST + i].cost;
4414 /* Determine how much the treasure is "worth" */
4415 j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
4423 * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
4424 * Places a treasure (Gold or Gems) at given location
4425 * @param y 配置したいフロアのY座標
4426 * @param x 配置したいフロアのX座標
4427 * @return 生成に成功したらTRUEを返す。
4429 * The location must be a legal, clean, floor grid.
4431 void place_gold(POSITION y, POSITION x)
4436 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
4442 /* Paranoia -- check bounds */
4443 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
4445 /* Require floor space */
4446 if (!cave_drop_bold(p_ptr->current_floor_ptr, y, x)) return;
4448 /* Avoid stacking on other objects */
4449 if (g_ptr->o_idx) return;
4454 /* Make some gold */
4455 if (!make_gold(q_ptr)) return;
4463 o_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
4464 object_copy(o_ptr, q_ptr);
4471 o_ptr->next_o_idx = g_ptr->o_idx;
4473 g_ptr->o_idx = o_idx;
4481 * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
4482 * Let an object fall to the ground at or near a location.
4483 * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
4484 * @param chance ドロップの消滅率(%)
4485 * @param y 配置したいフロアのY座標
4486 * @param x 配置したいフロアのX座標
4487 * @return 生成に成功したらオブジェクトのIDを返す。
4489 * The initial location is assumed to be "in_bounds(p_ptr->current_floor_ptr, )".\n
4491 * This function takes a parameter "chance". This is the percentage\n
4492 * chance that the item will "disappear" instead of drop. If the object\n
4493 * has been thrown, then this is the chance of disappearance on contact.\n
4495 * Hack -- this function uses "chance" to determine if it should produce\n
4496 * some form of "description" of the drop event (under the player).\n
4498 * We check several locations to see if we can find a location at which\n
4499 * the object can combine, stack, or be placed. Artifacts will try very\n
4500 * hard to be placed, including "teleporting" to a useful grid if needed.\n
4502 OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
4509 POSITION ty, tx = 0;
4511 OBJECT_IDX o_idx = 0;
4512 OBJECT_IDX this_o_idx, next_o_idx = 0;
4516 GAME_TEXT o_name[MAX_NLEN];
4522 /* Extract plural */
4523 bool plural = (j_ptr->number != 1);
4526 /* Describe object */
4527 object_desc(o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4530 /* Handle normal "breakage" */
4531 if (!object_is_artifact(j_ptr) && (randint0(100) < chance))
4534 msg_format("%sは消えた。", o_name);
4536 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4538 if (current_world_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
4555 /* Scan local grids */
4556 for (dy = -3; dy <= 3; dy++)
4558 /* Scan local grids */
4559 for (dx = -3; dx <= 3; dx++)
4563 /* Calculate actual distance */
4564 d = (dy * dy) + (dx * dx);
4566 /* Ignore distant grids */
4567 if (d > 10) continue;
4572 if (!in_bounds(p_ptr->current_floor_ptr, ty, tx)) continue;
4574 /* Require line of projection */
4575 if (!projectable(p_ptr->current_floor_ptr, y, x, ty, tx)) continue;
4578 g_ptr = &p_ptr->current_floor_ptr->grid_array[ty][tx];
4580 /* Require floor space */
4581 if (!cave_drop_bold(p_ptr->current_floor_ptr, ty, tx)) continue;
4586 /* Scan objects in that grid */
4587 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4590 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
4591 next_o_idx = o_ptr->next_o_idx;
4593 /* Check for possible combination */
4594 if (object_similar(o_ptr, j_ptr)) comb = TRUE;
4600 /* Add new object */
4602 if (k > 99) continue;
4604 /* Calculate score */
4605 s = 1000 - (d + k * 5);
4607 /* Skip bad values */
4608 if (s < bs) continue;
4610 /* New best value */
4613 /* Apply the randomizer to equivalent values */
4614 if ((++bn >= 2) && !one_in_(bn)) continue;
4628 /* Handle lack of space */
4629 if (!flag && !object_is_artifact(j_ptr))
4632 msg_format("%sは消えた。", o_name);
4634 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4637 if (current_world_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4645 for (i = 0; !flag && (i < 1000); i++)
4648 ty = rand_spread(by, 1);
4649 tx = rand_spread(bx, 1);
4651 if (!in_bounds(p_ptr->current_floor_ptr, ty, tx)) continue;
4653 /* Bounce to that location */
4657 /* Require floor space */
4658 if (!cave_drop_bold(p_ptr->current_floor_ptr, by, bx)) continue;
4666 int candidates = 0, pick;
4668 for (ty = 1; ty < p_ptr->current_floor_ptr->height - 1; ty++)
4670 for (tx = 1; tx < p_ptr->current_floor_ptr->width - 1; tx++)
4672 /* A valid space found */
4673 if (cave_drop_bold(p_ptr->current_floor_ptr, ty, tx)) candidates++;
4677 /* No valid place! */
4681 msg_format("%sは消えた。", o_name);
4683 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4686 if (current_world_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4688 /* Mega-Hack -- preserve artifacts */
4691 /* Hack -- Preserve unknown artifacts */
4692 if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr))
4694 /* Mega-Hack -- Preserve the artifact */
4695 a_info[j_ptr->name1].cur_num = 0;
4703 /* Choose a random one */
4704 pick = randint1(candidates);
4706 for (ty = 1; ty < p_ptr->current_floor_ptr->height - 1; ty++)
4708 for (tx = 1; tx < p_ptr->current_floor_ptr->width - 1; tx++)
4710 if (cave_drop_bold(p_ptr->current_floor_ptr, ty, tx))
4714 /* Is this a picked one? */
4727 g_ptr = &p_ptr->current_floor_ptr->grid_array[by][bx];
4729 /* Scan objects in that grid for combination */
4730 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4733 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
4734 next_o_idx = o_ptr->next_o_idx;
4736 /* Check for combination */
4737 if (object_similar(o_ptr, j_ptr))
4739 object_absorb(o_ptr, j_ptr);
4748 if (!done) o_idx = o_pop();
4751 if (!done && !o_idx)
4754 msg_format("%sは消えた。", o_name);
4756 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4759 if (current_world_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
4761 /* Hack -- Preserve artifacts */
4762 if (object_is_fixed_artifact(j_ptr))
4764 a_info[j_ptr->name1].cur_num = 0;
4774 /* Structure copy */
4775 object_copy(&p_ptr->current_floor_ptr->o_list[o_idx], j_ptr);
4777 /* Access new object */
4778 j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
4785 j_ptr->held_m_idx = 0;
4788 j_ptr->next_o_idx = g_ptr->o_idx;
4790 g_ptr->o_idx = o_idx;
4800 /* Mega-Hack -- no message if "dropped" by player */
4801 /* Message when an object falls under the player */
4802 if (chance && player_bold(p_ptr, by, bx))
4804 msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
4811 * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
4812 * Describe the charges on an item in the p_ptr->inventory_list.
4813 * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4816 void inven_item_charges(INVENTORY_IDX item)
4818 object_type *o_ptr = &p_ptr->inventory_list[item];
4820 /* Require staff/wand */
4821 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
4823 /* Require known item */
4824 if (!object_is_known(o_ptr)) return;
4827 if (o_ptr->pval <= 0)
4829 msg_print("もう魔力が残っていない。");
4833 msg_format("あと %d 回分の魔力が残っている。", o_ptr->pval);
4836 /* Multiple charges */
4837 if (o_ptr->pval != 1)
4839 msg_format("You have %d charges remaining.", o_ptr->pval);
4845 msg_format("You have %d charge remaining.", o_ptr->pval);
4852 * @brief アイテムの残り所持数メッセージを表示する /
4853 * Describe an item in the p_ptr->inventory_list.
4854 * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4857 void inven_item_describe(INVENTORY_IDX item)
4859 object_type *o_ptr = &p_ptr->inventory_list[item];
4860 GAME_TEXT o_name[MAX_NLEN];
4862 object_desc(o_name, o_ptr, 0);
4865 /* "no more" の場合はこちらで表示する */
4866 if (o_ptr->number <= 0)
4868 /*FIRST*//*ここはもう通らないかも */
4869 msg_format("もう%sを持っていない。", o_name);
4873 /* アイテム名を英日切り替え機能対応 */
4874 msg_format("まだ %sを持っている。", o_name);
4877 msg_format("You have %s.", o_name);
4883 * @brief アイテムを増減させ残り所持数メッセージを表示する /
4884 * Increase the "number" of an item in the p_ptr->inventory_list
4885 * @param item 所持数を増やしたいプレイヤーのアイテム所持スロット
4889 void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
4891 object_type *o_ptr = &p_ptr->inventory_list[item];
4894 num += o_ptr->number;
4897 if (num > 255) num = 255;
4898 else if (num < 0) num = 0;
4901 num -= o_ptr->number;
4903 /* Change the number and weight */
4906 /* Add the number */
4907 o_ptr->number += num;
4909 /* Add the weight */
4910 p_ptr->total_weight += (num * o_ptr->weight);
4911 p_ptr->update |= (PU_BONUS);
4912 p_ptr->update |= (PU_MANA);
4913 p_ptr->update |= (PU_COMBINE);
4914 p_ptr->window |= (PW_INVEN | PW_EQUIP);
4916 /* Hack -- Clear temporary elemental brands if player takes off weapons */
4917 if (!o_ptr->number && p_ptr->ele_attack)
4919 if ((item == INVEN_RARM) || (item == INVEN_LARM))
4921 if (!has_melee_weapon(p_ptr, INVEN_RARM + INVEN_LARM - item))
4923 /* Clear all temporary elemental brands */
4924 set_ele_attack(p_ptr, 0, 0);
4932 * @brief 所持アイテムスロットから所持数のなくなったアイテムを消去する /
4933 * Erase an p_ptr->inventory_list slot if it has no more items
4934 * @param item 消去したいプレイヤーのアイテム所持スロット
4937 void inven_item_optimize(INVENTORY_IDX item)
4939 object_type *o_ptr = &p_ptr->inventory_list[item];
4941 /* Only optimize real items */
4942 if (!o_ptr->k_idx) return;
4944 /* Only optimize empty items */
4945 if (o_ptr->number) return;
4947 /* The item is in the pack */
4948 if (item < INVEN_RARM)
4955 /* Slide everything down */
4956 for (i = item; i < INVEN_PACK; i++)
4958 /* Structure copy */
4959 p_ptr->inventory_list[i] = p_ptr->inventory_list[i+1];
4962 /* Erase the "final" slot */
4963 object_wipe(&p_ptr->inventory_list[i]);
4965 p_ptr->window |= (PW_INVEN);
4968 /* The item is being wielded */
4974 /* Erase the empty slot */
4975 object_wipe(&p_ptr->inventory_list[item]);
4976 p_ptr->update |= (PU_BONUS);
4977 p_ptr->update |= (PU_TORCH);
4978 p_ptr->update |= (PU_MANA);
4980 p_ptr->window |= (PW_EQUIP);
4983 p_ptr->window |= (PW_SPELL);
4987 * @brief 床上の魔道具の残り残量メッセージを表示する /
4988 * Describe the charges on an item on the floor.
4989 * @param item メッセージの対象にしたいアイテム所持スロット
4992 void floor_item_charges(INVENTORY_IDX item)
4994 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
4996 /* Require staff/wand */
4997 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
4999 /* Require known item */
5000 if (!object_is_known(o_ptr)) return;
5003 if (o_ptr->pval <= 0)
5005 msg_print("この床上のアイテムは、もう魔力が残っていない。");
5009 msg_format("この床上のアイテムは、あと %d 回分の魔力が残っている。", o_ptr->pval);
5012 /* Multiple charges */
5013 if (o_ptr->pval != 1)
5015 msg_format("There are %d charges remaining.", o_ptr->pval);
5021 msg_format("There is %d charge remaining.", o_ptr->pval);
5028 * @brief 床上のアイテムの残り数メッセージを表示する /
5029 * Describe the charges on an item on the floor.
5030 * @param item メッセージの対象にしたいアイテム所持スロット
5033 void floor_item_describe(INVENTORY_IDX item)
5035 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
5036 GAME_TEXT o_name[MAX_NLEN];
5038 object_desc(o_name, o_ptr, 0);
5041 /* "no more" の場合はこちらで表示を分ける */
5042 if (o_ptr->number <= 0)
5044 msg_format("床上には、もう%sはない。", o_name);
5048 msg_format("床上には、まだ %sがある。", o_name);
5051 msg_format("You see %s.", o_name);
5058 * @brief 床上のアイテムの数を増やす /
5059 * Increase the "number" of an item on the floor
5060 * @param item 増やしたいアイテムの所持スロット
5061 * @param num 増やしたいアイテムの数
5064 void floor_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
5066 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
5069 num += o_ptr->number;
5072 if (num > 255) num = 255;
5073 else if (num < 0) num = 0;
5076 num -= o_ptr->number;
5078 /* Change the number */
5079 o_ptr->number += num;
5084 * @brief 床上の数の無くなったアイテムスロットを消去する /
5085 * Optimize an item on the floor (destroy "empty" items)
5086 * @param item 消去したいアイテムの所持スロット
5089 void floor_item_optimize(INVENTORY_IDX item)
5091 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
5093 /* Paranoia -- be sure it exists */
5094 if (!o_ptr->k_idx) return;
5096 /* Only optimize empty items */
5097 if (o_ptr->number) return;
5099 delete_object_idx(item);
5104 * @brief アイテムを拾う際にザックから溢れずに済むかを判定する /
5105 * Check if we have space for an item in the pack without overflow
5106 * @param o_ptr 拾いたいオブジェクトの構造体参照ポインタ
5107 * @return 溢れずに済むならTRUEを返す
5109 bool inven_carry_okay(object_type *o_ptr)
5114 if (p_ptr->inven_cnt < INVEN_PACK) return (TRUE);
5117 for (j = 0; j < INVEN_PACK; j++)
5119 object_type *j_ptr = &p_ptr->inventory_list[j];
5120 if (!j_ptr->k_idx) continue;
5122 /* Check if the two items can be combined */
5123 if (object_similar(j_ptr, o_ptr)) return (TRUE);
5130 * @brief オブジェクトを定義された基準に従いソートするための関数 /
5131 * Check if we have space for an item in the pack without overflow
5132 * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
5133 * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
5134 * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
5135 * @return o_ptrの方が上位ならばTRUEを返す。
5137 bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
5141 /* Use empty slots */
5142 if (!j_ptr->k_idx) return TRUE;
5144 /* Hack -- readable books always come first */
5145 if ((o_ptr->tval == REALM1_BOOK) &&
5146 (j_ptr->tval != REALM1_BOOK)) return TRUE;
5147 if ((j_ptr->tval == REALM1_BOOK) &&
5148 (o_ptr->tval != REALM1_BOOK)) return FALSE;
5150 if ((o_ptr->tval == REALM2_BOOK) &&
5151 (j_ptr->tval != REALM2_BOOK)) return TRUE;
5152 if ((j_ptr->tval == REALM2_BOOK) &&
5153 (o_ptr->tval != REALM2_BOOK)) return FALSE;
5155 /* Objects sort by decreasing type */
5156 if (o_ptr->tval > j_ptr->tval) return TRUE;
5157 if (o_ptr->tval < j_ptr->tval) return FALSE;
5159 /* Non-aware (flavored) items always come last */
5160 /* Can happen in the home */
5161 if (!object_is_aware(o_ptr)) return FALSE;
5162 if (!object_is_aware(j_ptr)) return TRUE;
5164 /* Objects sort by increasing sval */
5165 if (o_ptr->sval < j_ptr->sval) return TRUE;
5166 if (o_ptr->sval > j_ptr->sval) return FALSE;
5168 /* Unidentified objects always come last */
5169 /* Objects in the home can be unknown */
5170 if (!object_is_known(o_ptr)) return FALSE;
5171 if (!object_is_known(j_ptr)) return TRUE;
5173 /* Fixed artifacts, random artifacts and ego items */
5174 if (object_is_fixed_artifact(o_ptr)) o_type = 3;
5175 else if (o_ptr->art_name) o_type = 2;
5176 else if (object_is_ego(o_ptr)) o_type = 1;
5179 if (object_is_fixed_artifact(j_ptr)) j_type = 3;
5180 else if (j_ptr->art_name) j_type = 2;
5181 else if (object_is_ego(j_ptr)) j_type = 1;
5184 if (o_type < j_type) return TRUE;
5185 if (o_type > j_type) return FALSE;
5187 switch (o_ptr->tval)
5193 if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
5194 if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
5200 /* Objects sort by increasing hit/damage bonuses */
5201 if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
5202 if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
5205 /* Hack: otherwise identical rods sort by
5206 increasing recharge time --dsb */
5208 if (o_ptr->pval < j_ptr->pval) return TRUE;
5209 if (o_ptr->pval > j_ptr->pval) return FALSE;
5213 /* Objects sort by decreasing value */
5214 return o_value > object_value(j_ptr);
5219 * @brief オブジェクトをプレイヤーが拾って所持スロットに納めるメインルーチン /
5220 * Add an item to the players p_ptr->inventory_list, and return the slot used.
5221 * @param o_ptr 拾うオブジェクトの構造体参照ポインタ
5222 * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5224 * If the new item can combine with an existing item in the p_ptr->inventory_list,\n
5225 * it will do so, using "object_similar()" and "object_absorb()", else,\n
5226 * the item will be placed into the "proper" location in the p_ptr->inventory_list.\n
5228 * This function can be used to "over-fill" the player's pack, but only\n
5229 * once, and such an action must trigger the "overflow" code immediately.\n
5230 * Note that when the pack is being "over-filled", the new item must be\n
5231 * placed into the "overflow" slot, and the "overflow" must take place\n
5232 * before the pack is reordered, but (optionally) after the pack is\n
5233 * combined. This may be tricky. See "dungeon.c" for info.\n
5235 * Note that this code must remove any location/stack information\n
5236 * from the object once it is placed into the p_ptr->inventory_list.\n
5238 s16b inven_carry(object_type *o_ptr)
5240 INVENTORY_IDX i, j, k;
5241 INVENTORY_IDX n = -1;
5246 /* Check for combining */
5247 for (j = 0; j < INVEN_PACK; j++)
5249 j_ptr = &p_ptr->inventory_list[j];
5250 if (!j_ptr->k_idx) continue;
5252 /* Hack -- track last item */
5255 /* Check if the two items can be combined */
5256 if (object_similar(j_ptr, o_ptr))
5258 object_absorb(j_ptr, o_ptr);
5260 p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
5261 p_ptr->update |= (PU_BONUS);
5262 p_ptr->window |= (PW_INVEN);
5269 if (p_ptr->inven_cnt > INVEN_PACK) return (-1);
5271 /* Find an empty slot */
5272 for (j = 0; j <= INVEN_PACK; j++)
5274 j_ptr = &p_ptr->inventory_list[j];
5276 /* Use it if found */
5277 if (!j_ptr->k_idx) break;
5284 /* Reorder the pack */
5287 /* Get the "value" of the item */
5288 s32b o_value = object_value(o_ptr);
5290 /* Scan every occupied slot */
5291 for (j = 0; j < INVEN_PACK; j++)
5293 if (object_sort_comp(o_ptr, o_value, &p_ptr->inventory_list[j])) break;
5300 for (k = n; k >= i; k--)
5302 /* Hack -- Slide the item */
5303 object_copy(&p_ptr->inventory_list[k+1], &p_ptr->inventory_list[k]);
5306 /* Wipe the empty slot */
5307 object_wipe(&p_ptr->inventory_list[i]);
5312 object_copy(&p_ptr->inventory_list[i], o_ptr);
5314 /* Access new object */
5315 j_ptr = &p_ptr->inventory_list[i];
5318 j_ptr->next_o_idx = 0;
5320 /* Forget monster */
5321 j_ptr->held_m_idx = 0;
5323 /* Forget location */
5324 j_ptr->iy = j_ptr->ix = 0;
5326 /* Player touches it, and no longer marked */
5327 j_ptr->marked = OM_TOUCHED;
5329 p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
5331 /* Count the items */
5333 p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
5334 p_ptr->window |= (PW_INVEN);
5336 /* Return the slot */
5342 * @brief 装備スロットからオブジェクトを外すメインルーチン /
5343 * Take off (some of) a non-cursed equipment item
5344 * @param item オブジェクトを外したい所持テーブルのID
5346 * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5348 * Note that only one item at a time can be wielded per slot.\n
5349 * Note that taking off an item when "full" may cause that item\n
5350 * to fall to the ground.\n
5351 * Return the p_ptr->inventory_list slot into which the item is placed.\n
5353 INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
5364 GAME_TEXT o_name[MAX_NLEN];
5367 /* Get the item to take off */
5368 o_ptr = &p_ptr->inventory_list[item];
5369 if (amt <= 0) return (-1);
5372 if (amt > o_ptr->number) amt = o_ptr->number;
5374 object_copy(q_ptr, o_ptr);
5376 /* Modify quantity */
5377 q_ptr->number = amt;
5379 object_desc(o_name, q_ptr, 0);
5381 /* Took off weapon */
5382 if (((item == INVEN_RARM) || (item == INVEN_LARM)) &&
5383 object_is_melee_weapon(o_ptr))
5385 act = _("を装備からはずした", "You were wielding");
5389 else if (item == INVEN_BOW)
5391 act = _("を装備からはずした", "You were holding");
5394 /* Took off light */
5395 else if (item == INVEN_LITE)
5397 act = _("を光源からはずした", "You were holding");
5400 /* Took off something */
5403 act = _("を装備からはずした", "You were wearing");
5406 /* Modify, Optimize */
5407 inven_item_increase(item, -amt);
5408 inven_item_optimize(item);
5410 /* Carry the object */
5411 slot = inven_carry(q_ptr);
5414 msg_format("%s(%c)%s。", o_name, index_to_label(slot), act);
5416 msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
5426 * @brief 所持スロットから床下にオブジェクトを落とすメインルーチン /
5427 * Drop (some of) a non-cursed p_ptr->inventory_list/equipment item
5428 * @param item 所持テーブルのID
5429 * @param amt 落としたい個数
5432 * The object will be dropped "near" the current location
5434 void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
5440 GAME_TEXT o_name[MAX_NLEN];
5442 /* Access original object */
5443 o_ptr = &p_ptr->inventory_list[item];
5446 if (amt <= 0) return;
5449 if (amt > o_ptr->number) amt = o_ptr->number;
5451 /* Take off equipment */
5452 if (item >= INVEN_RARM)
5454 /* Take off first */
5455 item = inven_takeoff(item, amt);
5457 /* Access original object */
5458 o_ptr = &p_ptr->inventory_list[item];
5463 /* Obtain local object */
5464 object_copy(q_ptr, o_ptr);
5466 /* Distribute charges of wands or rods */
5467 distribute_charges(o_ptr, q_ptr, amt);
5469 /* Modify quantity */
5470 q_ptr->number = amt;
5472 /* Describe local object */
5473 object_desc(o_name, q_ptr, 0);
5475 msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(item));
5477 /* Drop it near the player */
5478 (void)drop_near(q_ptr, 0, p_ptr->y, p_ptr->x);
5480 /* Modify, Describe, Optimize */
5481 inven_item_increase(item, -amt);
5482 inven_item_describe(item);
5483 inven_item_optimize(item);
5488 * @brief プレイヤーの所持スロットに存在するオブジェクトをまとめなおす /
5489 * Combine items in the pack
5492 * Note special handling of the "overflow" slot
5494 void combine_pack(player_type *owner_ptr)
5499 bool flag = FALSE, combined;
5505 /* Combine the pack (backwards) */
5506 for (i = INVEN_PACK; i > 0; i--)
5508 o_ptr = &owner_ptr->inventory_list[i];
5510 /* Skip empty items */
5511 if (!o_ptr->k_idx) continue;
5513 /* Scan the items above that item */
5514 for (j = 0; j < i; j++)
5518 j_ptr = &owner_ptr->inventory_list[j];
5520 /* Skip empty items */
5521 if (!j_ptr->k_idx) continue;
5524 * Get maximum number of the stack if these
5525 * are similar, get zero otherwise.
5527 max_num = object_similar_part(j_ptr, o_ptr);
5529 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
5530 if (max_num && j_ptr->number < max_num)
5532 if (o_ptr->number + j_ptr->number <= max_num)
5537 /* Add together the item counts */
5538 object_absorb(j_ptr, o_ptr);
5540 /* One object is gone */
5541 owner_ptr->inven_cnt--;
5543 /* Slide everything down */
5544 for (k = i; k < INVEN_PACK; k++)
5546 /* Structure copy */
5547 owner_ptr->inventory_list[k] = owner_ptr->inventory_list[k+1];
5550 /* Erase the "final" slot */
5551 object_wipe(&owner_ptr->inventory_list[k]);
5555 int old_num = o_ptr->number;
5556 int remain = j_ptr->number + o_ptr->number - max_num;
5558 o_ptr->number -= remain;
5560 /* Add together the item counts */
5561 object_absorb(j_ptr, o_ptr);
5563 o_ptr->number = remain;
5565 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
5566 if (o_ptr->tval == TV_ROD)
5568 o_ptr->pval = o_ptr->pval * remain / old_num;
5569 o_ptr->timeout = o_ptr->timeout * remain / old_num;
5572 /* Hack -- if wands are stacking, combine the charges. -LM- */
5573 if (o_ptr->tval == TV_WAND)
5575 o_ptr->pval = o_ptr->pval * remain / old_num;
5579 owner_ptr->window |= (PW_INVEN);
5591 if (flag) msg_print(_("ザックの中のアイテムをまとめ直した。", "You combine some items in your pack."));
5595 * @brief プレイヤーの所持スロットに存在するオブジェクトを並び替える /
5596 * Reorder items in the pack
5599 * Note special handling of the "overflow" slot
5601 void reorder_pack(void)
5611 /* Re-order the pack (forwards) */
5612 for (i = 0; i < INVEN_PACK; i++)
5614 /* Mega-Hack -- allow "proper" over-flow */
5615 if ((i == INVEN_PACK) && (p_ptr->inven_cnt == INVEN_PACK)) break;
5617 o_ptr = &p_ptr->inventory_list[i];
5619 /* Skip empty slots */
5620 if (!o_ptr->k_idx) continue;
5622 /* Get the "value" of the item */
5623 o_value = object_value(o_ptr);
5625 /* Scan every occupied slot */
5626 for (j = 0; j < INVEN_PACK; j++)
5628 if (object_sort_comp(o_ptr, o_value, &p_ptr->inventory_list[j])) break;
5631 /* Never move down */
5632 if (j >= i) continue;
5638 /* Save a copy of the moving item */
5639 object_copy(q_ptr, &p_ptr->inventory_list[i]);
5641 /* Slide the objects */
5642 for (k = i; k > j; k--)
5644 /* Slide the item */
5645 object_copy(&p_ptr->inventory_list[k], &p_ptr->inventory_list[k-1]);
5648 /* Insert the moving item */
5649 object_copy(&p_ptr->inventory_list[j], q_ptr);
5651 p_ptr->window |= (PW_INVEN);
5654 if (flag) msg_print(_("ザックの中のアイテムを並べ直した。", "You reorder some items in your pack."));
5658 * @brief 現在アクティブになっているウィンドウにオブジェクトの詳細を表示する /
5659 * Hack -- display an object kind in the current window
5660 * @param k_idx ベースアイテムの参照ID
5663 * Include list of usable spells for readible books
5665 void display_koff(KIND_OBJECT_IDX k_idx)
5672 REALM_IDX use_realm;
5674 GAME_TEXT o_name[MAX_NLEN];
5677 /* Erase the window */
5678 for (y = 0; y < Term->hgt; y++)
5680 /* Erase the line */
5681 Term_erase(0, y, 255);
5688 /* Prepare the object */
5689 object_prep(q_ptr, k_idx);
5690 object_desc(o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
5692 /* Mention the object name */
5693 Term_putstr(0, 0, -1, TERM_WHITE, o_name);
5695 /* Access the item's sval */
5697 use_realm = tval2realm(q_ptr->tval);
5699 /* Warriors are illiterate */
5700 if (p_ptr->realm1 || p_ptr->realm2)
5702 if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2)) return;
5706 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return;
5707 if (!is_magic(use_realm)) return;
5708 if ((p_ptr->pclass == CLASS_RED_MAGE) && (use_realm != REALM_ARCANE) && (sval > 1)) return;
5711 /* Display spells in readible books */
5715 SPELL_IDX spells[64];
5717 /* Extract spells */
5718 for (spell = 0; spell < 32; spell++)
5720 /* Check for this spell */
5721 if (fake_spell_flags[sval] & (1L << spell))
5723 /* Collect this spell */
5724 spells[num++] = spell;
5729 print_spells(p_ptr, 0, spells, num, 2, 0, use_realm);
5735 * @brief 投擲時たいまつに投げやすい/焼棄/アンデッドスレイの特別効果を返す。
5736 * Torches have special abilities when they are flaming.
5737 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5738 * @param flgs 特別に追加するフラグを返す参照ポインタ
5741 void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs)
5743 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5745 if (o_ptr->xtra4 > 0)
5747 add_flag(flgs, TR_BRAND_FIRE);
5748 add_flag(flgs, TR_KILL_UNDEAD);
5749 add_flag(flgs, TR_THROW);
5755 * @brief 投擲時たいまつにダイスを与える。
5756 * Torches have special abilities when they are flaming.
5757 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5758 * @param dd 特別なダイス数を返す参照ポインタ
5759 * @param ds 特別なダイス面数を返す参照ポインタ
5762 void torch_dice(object_type *o_ptr, DICE_NUMBER *dd, DICE_SID *ds)
5764 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5766 if (o_ptr->xtra4 > 0)
5775 * @brief 投擲時命中したたいまつの寿命を縮める。
5776 * Torches have special abilities when they are flaming.
5777 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5780 void torch_lost_fuel(object_type *o_ptr)
5782 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5784 o_ptr->xtra4 -= (FUEL_TORCH / 25);
5785 if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0;
5790 * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す /
5791 * @param o_ptr 判定する射撃武器のアイテム情報参照ポインタ
5792 * @return 対応する矢/弾薬のベースアイテムID
5794 int bow_tval_ammo(object_type *o_ptr)
5796 /* Analyze the launcher */
5797 switch (o_ptr->sval)