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
20 #include "cmd-spell.h"
25 #include "objectkind.h"
26 #include "object-boost.h"
27 #include "object-ego.h"
28 #include "object-flavor.h"
29 #include "object-hook.h"
30 #include "object-curse.h"
31 #include "objectkind-hook.h"
34 #include "player-status.h"
35 #include "player-move.h"
36 #include "player-effects.h"
38 #include "monsterrace-hook.h"
39 #include "object-ego.h"
42 * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
43 * @param o_idx 削除対象のオブジェクト構造体ポインタ
46 void excise_object_idx(OBJECT_IDX o_idx)
50 OBJECT_IDX this_o_idx, next_o_idx = 0;
51 OBJECT_IDX prev_o_idx = 0;
54 j_ptr = ¤t_floor_ptr->o_list[o_idx];
56 if (j_ptr->held_m_idx)
59 m_ptr = ¤t_floor_ptr->m_list[j_ptr->held_m_idx];
61 /* Scan all objects in the grid */
62 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
65 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
66 next_o_idx = o_ptr->next_o_idx;
68 if (this_o_idx == o_idx)
73 /* Remove from list */
74 m_ptr->hold_o_idx = next_o_idx;
83 k_ptr = ¤t_floor_ptr->o_list[prev_o_idx];
85 /* Remove from list */
86 k_ptr->next_o_idx = next_o_idx;
89 /* Forget next pointer */
90 o_ptr->next_o_idx = 0;
96 prev_o_idx = this_o_idx;
105 POSITION y = j_ptr->iy;
106 POSITION x = j_ptr->ix;
108 g_ptr = ¤t_floor_ptr->grid_array[y][x];
110 /* Scan all objects in the grid */
111 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
114 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
115 next_o_idx = o_ptr->next_o_idx;
117 if (this_o_idx == o_idx)
122 /* Remove from list */
123 g_ptr->o_idx = next_o_idx;
131 /* Previous object */
132 k_ptr = ¤t_floor_ptr->o_list[prev_o_idx];
134 /* Remove from list */
135 k_ptr->next_o_idx = next_o_idx;
138 /* Forget next pointer */
139 o_ptr->next_o_idx = 0;
144 /* Save prev_o_idx */
145 prev_o_idx = this_o_idx;
151 * @brief オブジェクトを削除する /
152 * Delete a dungeon object
153 * @param o_idx 削除対象のオブジェクト構造体ポインタ
156 * Handle "stacks" of objects correctly.
158 void delete_object_idx(OBJECT_IDX o_idx)
163 excise_object_idx(o_idx);
166 j_ptr = ¤t_floor_ptr->o_list[o_idx];
169 if (!(j_ptr->held_m_idx))
179 current_floor_ptr->o_cnt--;
184 * @brief フロアにマスに落ちているオブジェクトを全て削除する / Deletes all objects at given location
185 * Delete a dungeon object
186 * @param y 削除したフロアマスのY座標
187 * @param x 削除したフロアマスのX座標
190 void delete_object(POSITION y, POSITION x)
193 OBJECT_IDX this_o_idx, next_o_idx = 0;
195 /* Refuse "illegal" locations */
196 if (!in_bounds(y, x)) return;
198 g_ptr = ¤t_floor_ptr->grid_array[y][x];
200 /* Scan all objects in the grid */
201 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
204 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
205 next_o_idx = o_ptr->next_o_idx;
209 current_floor_ptr->o_cnt--;
212 /* Objects are gone */
220 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
221 * Move an object from index i1 to index i2 in the object list
222 * @param i1 整理したい配列の始点
223 * @param i2 整理したい配列の終点
226 static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
233 if (i1 == i2) return;
236 for (i = 1; i < current_floor_ptr->o_max; i++)
238 o_ptr = ¤t_floor_ptr->o_list[i];
240 /* Skip "dead" objects */
241 if (!o_ptr->k_idx) continue;
243 /* Repair "next" pointers */
244 if (o_ptr->next_o_idx == i1)
247 o_ptr->next_o_idx = i2;
250 o_ptr = ¤t_floor_ptr->o_list[i1];
252 if (o_ptr->held_m_idx)
256 /* Acquire monster */
257 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
260 if (m_ptr->hold_o_idx == i1)
263 m_ptr->hold_o_idx = i2;
272 /* Acquire location */
277 g_ptr = ¤t_floor_ptr->grid_array[y][x];
280 if (g_ptr->o_idx == i1)
288 current_floor_ptr->o_list[i2] = current_floor_ptr->o_list[i1];
296 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
297 * Compact and Reorder the object list.
298 * @param size 最低でも減らしたいオブジェクト数の水準
302 * This function can be very dangerous, use with caution!\n
304 * When actually "compacting" objects, we base the saving throw on a\n
305 * combination of object level, distance from player, and current\n
308 * After "compacting" (if needed), we "reorder" the objects into a more\n
309 * compact order, and we reset the allocation info, and the "live" array.\n
311 void compact_objects(int size)
316 int cur_lev, cur_dis, chance;
322 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
323 p_ptr->redraw |= (PR_MAP);
324 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
328 /* Compact at least 'size' objects */
329 for (num = 0, cnt = 1; num < size; cnt++)
331 /* Get more vicious each iteration */
334 /* Get closer each iteration */
335 cur_dis = 5 * (20 - cnt);
337 /* Examine the objects */
338 for (i = 1; i < current_floor_ptr->o_max; i++)
340 o_ptr = ¤t_floor_ptr->o_list[i];
342 /* Skip dead objects */
343 if (!o_ptr->k_idx) continue;
345 /* Hack -- High level objects start out "immune" */
346 if (k_info[o_ptr->k_idx].level > cur_lev) continue;
348 if (o_ptr->held_m_idx)
352 /* Acquire monster */
353 m_ptr = ¤t_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 = current_floor_ptr->o_max - 1; i >= 1; i--)
393 o_ptr = ¤t_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(current_floor_ptr->o_max - 1, i);
401 /* Compress "current_floor_ptr->o_max" */
402 current_floor_ptr->o_max--;
408 * @brief グローバルオブジェクト配列を初期化する /
409 * Delete all the items when player leaves the level
410 * @note we do NOT visually reflect these (irrelevant) changes
412 * Hack -- we clear the "g_ptr->o_idx" field for every grid,
413 * and the "m_ptr->next_o_idx" field for every monster, since
414 * we know we are clearing every object. Technically, we only
415 * clear those fields for grids/monsters containing objects,
416 * and we clear it once for every such object.
419 void wipe_o_list(void)
423 /* Delete the existing objects */
424 for (i = 1; i < current_floor_ptr->o_max; i++)
426 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
428 /* Skip dead objects */
429 if (!o_ptr->k_idx) continue;
431 /* Mega-Hack -- preserve artifacts */
432 if (!character_dungeon || preserve_mode)
434 /* Hack -- Preserve unknown artifacts */
435 if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
437 /* Mega-Hack -- Preserve the artifact */
438 a_info[o_ptr->name1].cur_num = 0;
442 if (o_ptr->held_m_idx)
445 m_ptr = ¤t_floor_ptr->m_list[o_ptr->held_m_idx];
447 /* Hack -- see above */
448 m_ptr->hold_o_idx = 0;
456 /* Access location */
457 POSITION y = o_ptr->iy;
458 POSITION x = o_ptr->ix;
461 g_ptr = ¤t_floor_ptr->grid_array[y][x];
463 /* Hack -- see above */
469 /* Reset "current_floor_ptr->o_max" */
470 current_floor_ptr->o_max = 1;
472 /* Reset "current_floor_ptr->o_cnt" */
473 current_floor_ptr->o_cnt = 0;
478 * @brief グローバルオブジェクト配列から空きを取得する /
479 * Acquires and returns the index of a "free" object.
480 * @return 開いているオブジェクト要素のID
482 * This routine should almost never fail, but in case it does,
483 * we must be sure to handle "failure" of this routine.
485 OBJECT_IDX o_pop(void)
489 /* Initial allocation */
490 if (current_floor_ptr->o_max < current_floor_ptr->max_o_idx)
493 i = current_floor_ptr->o_max;
495 /* Expand object array */
496 current_floor_ptr->o_max++;
499 current_floor_ptr->o_cnt++;
501 /* Use this object */
506 /* Recycle dead objects */
507 for (i = 1; i < current_floor_ptr->o_max; i++)
510 o_ptr = ¤t_floor_ptr->o_list[i];
512 /* Skip live objects */
513 if (o_ptr->k_idx) continue;
516 current_floor_ptr->o_cnt++;
518 /* Use this object */
523 /* Warn the player (except during dungeon creation) */
524 if (character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
531 * @brief オブジェクト生成テーブルに生成制約を加える /
532 * Apply a "object restriction function" to the "object allocation table"
534 * @details 生成の制約はグローバルのget_obj_num_hook関数ポインタで加える
536 static errr get_obj_num_prep(void)
541 alloc_entry *table = alloc_kind_table;
543 /* Scan the allocation table */
544 for (i = 0; i < alloc_kind_size; i++)
546 /* Accept objects which pass the restriction, if any */
547 if (!get_obj_num_hook || (*get_obj_num_hook)(table[i].index))
549 /* Accept this object */
550 table[i].prob2 = table[i].prob1;
553 /* Do not use this object */
556 /* Decline this object */
567 * @brief オブジェクト生成テーブルからアイテムを取得する /
568 * Choose an object kind that seems "appropriate" to the given level
570 * @return 選ばれたオブジェクトベースID
572 * This function uses the "prob2" field of the "object allocation table",\n
573 * and various local information, to calculate the "prob3" field of the\n
574 * same table, which is then used to choose an "appropriate" object, in\n
575 * a relatively efficient manner.\n
577 * It is (slightly) more likely to acquire an object of the given level\n
578 * than one of a lower level. This is done by choosing several objects\n
579 * appropriate to the given level and keeping the "hardest" one.\n
581 * Note that if no objects are "appropriate", then this function will\n
582 * fail, and return zero, but this should *almost* never happen.\n
584 OBJECT_IDX get_obj_num(DEPTH level, BIT_FLAGS mode)
587 KIND_OBJECT_IDX k_idx;
590 alloc_entry *table = alloc_kind_table;
592 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
595 if ((level > 0) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
597 /* Occasional "boost" */
598 if (one_in_(GREAT_OBJ))
600 /* What a bizarre calculation */
601 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
608 /* Process probabilities */
609 for (i = 0; i < alloc_kind_size; i++)
611 /* Objects are sorted by depth */
612 if (table[i].level > level) break;
617 k_idx = table[i].index;
619 /* Access the actual kind */
620 k_ptr = &k_info[k_idx];
622 if ((mode & AM_FORBID_CHEST) && (k_ptr->tval == TV_CHEST)) continue;
625 table[i].prob3 = table[i].prob2;
628 total += table[i].prob3;
631 /* No legal objects */
632 if (total <= 0) return (0);
636 value = randint0(total);
638 /* Find the object */
639 for (i = 0; i < alloc_kind_size; i++)
641 /* Found the entry */
642 if (value < table[i].prob3) break;
645 value = value - table[i].prob3;
652 /* Try for a "better" object once (50%) or twice (10%) */
659 value = randint0(total);
661 /* Find the object */
662 for (i = 0; i < alloc_kind_size; i++)
664 /* Found the entry */
665 if (value < table[i].prob3) break;
668 value = value - table[i].prob3;
671 /* Keep the "best" one */
672 if (table[i].level < table[j].level) i = j;
675 /* Try for a "better" object twice (10%) */
682 value = randint0(total);
684 /* Find the object */
685 for (i = 0; i < alloc_kind_size; i++)
687 /* Found the entry */
688 if (value < table[i].prob3) break;
691 value = value - table[i].prob3;
694 /* Keep the "best" one */
695 if (table[i].level < table[j].level) i = j;
698 return (table[i].index);
702 * @brief オブジェクトを鑑定済にする /
703 * Known is true when the "attributes" of an object are "known".
704 * @param o_ptr 鑑定済にするオブジェクトの構造体参照ポインタ
706 * These include tohit, todam, toac, cost, and pval (charges).\n
708 * Note that "knowing" an object gives you everything that an "awareness"\n
709 * gives you, and much more. In fact, the player is always "aware" of any\n
710 * item of which he has full "knowledge".\n
712 * But having full knowledge of, say, one "wand of wonder", does not, by\n
713 * itself, give you knowledge, or even awareness, of other "wands of wonder".\n
714 * It happens that most "identify" routines (including "buying from a shop")\n
715 * will make the player "aware" of the object as well as fully "know" it.\n
717 * This routine also removes any inscriptions generated by "feelings".\n
719 void object_known(object_type *o_ptr)
721 /* Remove "default inscriptions" */
722 o_ptr->feeling = FEEL_NONE;
724 /* Clear the "Felt" info */
725 o_ptr->ident &= ~(IDENT_SENSE);
727 /* Clear the "Empty" info */
728 o_ptr->ident &= ~(IDENT_EMPTY);
730 /* Now we know about the item */
731 o_ptr->ident |= (IDENT_KNOWN);
735 * @brief オブジェクトを*鑑定*済にする /
736 * The player is now aware of the effects of the given object.
737 * @param o_ptr *鑑定*済にするオブジェクトの構造体参照ポインタ
740 void object_aware(object_type *o_ptr)
742 bool mihanmei = !object_is_aware(o_ptr);
744 /* Fully aware of the effects */
745 k_info[o_ptr->k_idx].aware = TRUE;
747 if(mihanmei && !(k_info[o_ptr->k_idx].gen_flags & TRG_INSTA_ART) && record_ident &&
748 !p_ptr->is_dead && ((o_ptr->tval >= TV_AMULET && o_ptr->tval <= TV_POTION) || (o_ptr->tval == TV_FOOD)))
752 GAME_TEXT o_name[MAX_NLEN];
755 object_copy(q_ptr, o_ptr);
758 object_desc(o_name, q_ptr, OD_NAME_ONLY);
760 do_cmd_write_nikki(NIKKI_HANMEI, 0, o_name);
765 * @brief オブジェクトを試行済にする /
766 * Something has been "sampled"
767 * @param o_ptr 試行済にするオブジェクトの構造体参照ポインタ
770 void object_tried(object_type *o_ptr)
772 /* Mark it as tried (even if "aware") */
773 k_info[o_ptr->k_idx].tried = TRUE;
777 * @brief 重度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item. Method 1 (Heavy).
778 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
779 * @return 擬似鑑定結果のIDを返す。
781 byte value_check_aux1(object_type *o_ptr)
784 if (object_is_artifact(o_ptr))
787 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_TERRIBLE;
794 if (object_is_ego(o_ptr))
797 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_WORTHLESS;
800 return FEEL_EXCELLENT;
804 if (object_is_cursed(o_ptr)) return FEEL_CURSED;
807 if (object_is_broken(o_ptr)) return FEEL_BROKEN;
809 if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
811 /* Good "armor" bonus */
812 if (o_ptr->to_a > 0) return FEEL_GOOD;
814 /* Good "weapon" bonus */
815 if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
817 /* Default to "average" */
822 * @brief 軽度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item. Method 2 (Light).
823 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
824 * @return 擬似鑑定結果のIDを返す。
826 byte value_check_aux2(object_type *o_ptr)
828 /* Cursed items (all of them) */
829 if (object_is_cursed(o_ptr)) return FEEL_CURSED;
831 /* Broken items (all of them) */
832 if (object_is_broken(o_ptr)) return FEEL_BROKEN;
834 /* Artifacts -- except cursed/broken ones */
835 if (object_is_artifact(o_ptr)) return FEEL_UNCURSED;
837 /* Ego-Items -- except cursed/broken ones */
838 if (object_is_ego(o_ptr)) return FEEL_UNCURSED;
840 /* Good armor bonus */
841 if (o_ptr->to_a > 0) return FEEL_UNCURSED;
843 /* Good weapon bonuses */
844 if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
851 * @brief 未鑑定なベースアイテムの基本価格を返す /
852 * Return the "value" of an "unknown" item Make a guess at the value of non-aware items
853 * @param o_ptr 未鑑定価格を確認したいオブジェクトの構造体参照ポインタ
854 * @return オブジェクトの未鑑定価格
856 static PRICE object_value_base(object_type *o_ptr)
858 /* Aware item -- use template cost */
859 if (object_is_aware(o_ptr)) return (k_info[o_ptr->k_idx].cost);
861 /* Analyze the type */
866 case TV_FOOD: return (5L);
868 /* Un-aware Potions */
869 case TV_POTION: return (20L);
871 /* Un-aware Scrolls */
872 case TV_SCROLL: return (20L);
874 /* Un-aware Staffs */
875 case TV_STAFF: return (70L);
878 case TV_WAND: return (50L);
881 case TV_ROD: return (90L);
884 case TV_RING: return (45L);
886 /* Un-aware Amulets */
887 case TV_AMULET: return (45L);
889 /* Figurines, relative to monster level */
892 DEPTH level = r_info[o_ptr->pval].level;
893 if (level < 20) return level*50L;
894 else if (level < 30) return 1000+(level-20)*150L;
895 else if (level < 40) return 2500+(level-30)*350L;
896 else if (level < 50) return 6000+(level-40)*800L;
897 else return 14000+(level-50)*2000L;
901 if (!o_ptr->pval) return 1000L;
902 else return ((r_info[o_ptr->pval].level) * 50L + 1000);
905 /* Paranoia -- Oops */
911 * @brief オブジェクトのフラグ類から価格を算出する /
912 * Return the value of the flags the object has...
913 * @param o_ptr フラグ価格を確認したいオブジェクトの構造体参照ポインタ
914 * @param plusses フラグに与える価格の基本重み
915 * @return オブジェクトのフラグ価格
917 PRICE flag_cost(object_type *o_ptr, int plusses)
920 BIT_FLAGS flgs[TR_FLAG_SIZE];
924 object_kind *k_ptr = &k_info[o_ptr->k_idx];
926 object_flags(o_ptr, flgs);
929 * Exclude fixed flags of the base item.
930 * pval bonuses of base item will be treated later.
932 for (i = 0; i < TR_FLAG_SIZE; i++)
933 flgs[i] &= ~(k_ptr->flags[i]);
935 /* Exclude fixed flags of the fixed artifact. */
936 if (object_is_fixed_artifact(o_ptr))
938 artifact_type *a_ptr = &a_info[o_ptr->name1];
940 for (i = 0; i < TR_FLAG_SIZE; i++)
941 flgs[i] &= ~(a_ptr->flags[i]);
944 /* Exclude fixed flags of the ego-item. */
945 else if (object_is_ego(o_ptr))
947 ego_item_type *e_ptr = &e_info[o_ptr->name2];
949 for (i = 0; i < TR_FLAG_SIZE; i++)
950 flgs[i] &= ~(e_ptr->flags[i]);
955 * Calucurate values of remaining flags
957 if (have_flag(flgs, TR_STR)) total += (1500 * plusses);
958 if (have_flag(flgs, TR_INT)) total += (1500 * plusses);
959 if (have_flag(flgs, TR_WIS)) total += (1500 * plusses);
960 if (have_flag(flgs, TR_DEX)) total += (1500 * plusses);
961 if (have_flag(flgs, TR_CON)) total += (1500 * plusses);
962 if (have_flag(flgs, TR_CHR)) total += (750 * plusses);
963 if (have_flag(flgs, TR_MAGIC_MASTERY)) total += (600 * plusses);
964 if (have_flag(flgs, TR_STEALTH)) total += (250 * plusses);
965 if (have_flag(flgs, TR_SEARCH)) total += (100 * plusses);
966 if (have_flag(flgs, TR_INFRA)) total += (150 * plusses);
967 if (have_flag(flgs, TR_TUNNEL)) total += (175 * plusses);
968 if ((have_flag(flgs, TR_SPEED)) && (plusses > 0))
969 total += (10000 + (2500 * plusses));
970 if ((have_flag(flgs, TR_BLOWS)) && (plusses > 0))
971 total += (10000 + (2500 * plusses));
975 if (have_flag(flgs, TR_CHAOTIC)) {total += 5000;count++;}
976 if (have_flag(flgs, TR_VAMPIRIC)) {total += 6500;count++;}
977 if (have_flag(flgs, TR_FORCE_WEAPON)) {tmp_cost += 2500;count++;}
978 if (have_flag(flgs, TR_KILL_ANIMAL)) {tmp_cost += 2800;count++;}
979 else if (have_flag(flgs, TR_SLAY_ANIMAL)) {tmp_cost += 1800;count++;}
980 if (have_flag(flgs, TR_KILL_EVIL)) {tmp_cost += 3300;count++;}
981 else if (have_flag(flgs, TR_SLAY_EVIL)) {tmp_cost += 2300;count++;}
982 if (have_flag(flgs, TR_KILL_HUMAN)) {tmp_cost += 2800;count++;}
983 else if (have_flag(flgs, TR_SLAY_HUMAN)) {tmp_cost += 1800;count++;}
984 if (have_flag(flgs, TR_KILL_UNDEAD)) {tmp_cost += 2800;count++;}
985 else if (have_flag(flgs, TR_SLAY_UNDEAD)) {tmp_cost += 1800;count++;}
986 if (have_flag(flgs, TR_KILL_DEMON)) {tmp_cost += 2800;count++;}
987 else if (have_flag(flgs, TR_SLAY_DEMON)) {tmp_cost += 1800;count++;}
988 if (have_flag(flgs, TR_KILL_ORC)) {tmp_cost += 2500;count++;}
989 else if (have_flag(flgs, TR_SLAY_ORC)) {tmp_cost += 1500;count++;}
990 if (have_flag(flgs, TR_KILL_TROLL)) {tmp_cost += 2800;count++;}
991 else if (have_flag(flgs, TR_SLAY_TROLL)) {tmp_cost += 1800;count++;}
992 if (have_flag(flgs, TR_KILL_GIANT)) {tmp_cost += 2800;count++;}
993 else if (have_flag(flgs, TR_SLAY_GIANT)) {tmp_cost += 1800;count++;}
994 if (have_flag(flgs, TR_KILL_DRAGON)) {tmp_cost += 2800;count++;}
995 else if (have_flag(flgs, TR_SLAY_DRAGON)) {tmp_cost += 1800;count++;}
997 if (have_flag(flgs, TR_VORPAL)) {tmp_cost += 2500;count++;}
998 if (have_flag(flgs, TR_IMPACT)) {tmp_cost += 2500;count++;}
999 if (have_flag(flgs, TR_BRAND_POIS)) {tmp_cost += 3800;count++;}
1000 if (have_flag(flgs, TR_BRAND_ACID)) {tmp_cost += 3800;count++;}
1001 if (have_flag(flgs, TR_BRAND_ELEC)) {tmp_cost += 3800;count++;}
1002 if (have_flag(flgs, TR_BRAND_FIRE)) {tmp_cost += 2500;count++;}
1003 if (have_flag(flgs, TR_BRAND_COLD)) {tmp_cost += 2500;count++;}
1004 total += (tmp_cost * count);
1006 if (have_flag(flgs, TR_SUST_STR)) total += 850;
1007 if (have_flag(flgs, TR_SUST_INT)) total += 850;
1008 if (have_flag(flgs, TR_SUST_WIS)) total += 850;
1009 if (have_flag(flgs, TR_SUST_DEX)) total += 850;
1010 if (have_flag(flgs, TR_SUST_CON)) total += 850;
1011 if (have_flag(flgs, TR_SUST_CHR)) total += 250;
1012 if (have_flag(flgs, TR_RIDING)) total += 0;
1013 if (have_flag(flgs, TR_EASY_SPELL)) total += 1500;
1014 if (have_flag(flgs, TR_THROW)) total += 5000;
1015 if (have_flag(flgs, TR_FREE_ACT)) total += 4500;
1016 if (have_flag(flgs, TR_HOLD_EXP)) total += 8500;
1020 if (have_flag(flgs, TR_IM_ACID)) {tmp_cost += 15000;count += 2;}
1021 if (have_flag(flgs, TR_IM_ELEC)) {tmp_cost += 15000;count += 2;}
1022 if (have_flag(flgs, TR_IM_FIRE)) {tmp_cost += 15000;count += 2;}
1023 if (have_flag(flgs, TR_IM_COLD)) {tmp_cost += 15000;count += 2;}
1024 if (have_flag(flgs, TR_REFLECT)) {tmp_cost += 5000;count += 2;}
1025 if (have_flag(flgs, TR_RES_ACID)) {tmp_cost += 500;count++;}
1026 if (have_flag(flgs, TR_RES_ELEC)) {tmp_cost += 500;count++;}
1027 if (have_flag(flgs, TR_RES_FIRE)) {tmp_cost += 500;count++;}
1028 if (have_flag(flgs, TR_RES_COLD)) {tmp_cost += 500;count++;}
1029 if (have_flag(flgs, TR_RES_POIS)) {tmp_cost += 1000;count += 2;}
1030 if (have_flag(flgs, TR_RES_FEAR)) {tmp_cost += 1000;count += 2;}
1031 if (have_flag(flgs, TR_RES_LITE)) {tmp_cost += 800;count += 2;}
1032 if (have_flag(flgs, TR_RES_DARK)) {tmp_cost += 800;count += 2;}
1033 if (have_flag(flgs, TR_RES_BLIND)) {tmp_cost += 900;count += 2;}
1034 if (have_flag(flgs, TR_RES_CONF)) {tmp_cost += 900;count += 2;}
1035 if (have_flag(flgs, TR_RES_SOUND)) {tmp_cost += 900;count += 2;}
1036 if (have_flag(flgs, TR_RES_SHARDS)) {tmp_cost += 900;count += 2;}
1037 if (have_flag(flgs, TR_RES_NETHER)) {tmp_cost += 900;count += 2;}
1038 if (have_flag(flgs, TR_RES_NEXUS)) {tmp_cost += 900;count += 2;}
1039 if (have_flag(flgs, TR_RES_CHAOS)) {tmp_cost += 1000;count += 2;}
1040 if (have_flag(flgs, TR_RES_DISEN)) {tmp_cost += 2000;count += 2;}
1041 total += (tmp_cost * count);
1043 if (have_flag(flgs, TR_SH_FIRE)) total += 5000;
1044 if (have_flag(flgs, TR_SH_ELEC)) total += 5000;
1045 if (have_flag(flgs, TR_SH_COLD)) total += 5000;
1046 if (have_flag(flgs, TR_NO_TELE)) total -= 10000;
1047 if (have_flag(flgs, TR_NO_MAGIC)) total += 2500;
1048 if (have_flag(flgs, TR_TY_CURSE)) total -= 15000;
1049 if (have_flag(flgs, TR_HIDE_TYPE)) total += 0;
1050 if (have_flag(flgs, TR_SHOW_MODS)) total += 0;
1051 if (have_flag(flgs, TR_LEVITATION)) total += 1250;
1052 if (have_flag(flgs, TR_LITE_1)) total += 1500;
1053 if (have_flag(flgs, TR_LITE_2)) total += 2500;
1054 if (have_flag(flgs, TR_LITE_3)) total += 4000;
1055 if (have_flag(flgs, TR_LITE_M1)) total -= 1500;
1056 if (have_flag(flgs, TR_LITE_M2)) total -= 2500;
1057 if (have_flag(flgs, TR_LITE_M3)) total -= 4000;
1058 if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
1059 if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
1060 if (have_flag(flgs, TR_ESP_ANIMAL)) total += 1000;
1061 if (have_flag(flgs, TR_ESP_UNDEAD)) total += 1000;
1062 if (have_flag(flgs, TR_ESP_DEMON)) total += 1000;
1063 if (have_flag(flgs, TR_ESP_ORC)) total += 1000;
1064 if (have_flag(flgs, TR_ESP_TROLL)) total += 1000;
1065 if (have_flag(flgs, TR_ESP_GIANT)) total += 1000;
1066 if (have_flag(flgs, TR_ESP_DRAGON)) total += 1000;
1067 if (have_flag(flgs, TR_ESP_HUMAN)) total += 1000;
1068 if (have_flag(flgs, TR_ESP_EVIL)) total += 15000;
1069 if (have_flag(flgs, TR_ESP_GOOD)) total += 2000;
1070 if (have_flag(flgs, TR_ESP_NONLIVING)) total += 2000;
1071 if (have_flag(flgs, TR_ESP_UNIQUE)) total += 10000;
1072 if (have_flag(flgs, TR_SLOW_DIGEST)) total += 750;
1073 if (have_flag(flgs, TR_REGEN)) total += 2500;
1074 if (have_flag(flgs, TR_WARNING)) total += 2000;
1075 if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
1076 if (have_flag(flgs, TR_XTRA_MIGHT)) total += 2250;
1077 if (have_flag(flgs, TR_XTRA_SHOTS)) total += 10000;
1078 if (have_flag(flgs, TR_IGNORE_ACID)) total += 100;
1079 if (have_flag(flgs, TR_IGNORE_ELEC)) total += 100;
1080 if (have_flag(flgs, TR_IGNORE_FIRE)) total += 100;
1081 if (have_flag(flgs, TR_IGNORE_COLD)) total += 100;
1082 if (have_flag(flgs, TR_ACTIVATE)) total += 100;
1083 if (have_flag(flgs, TR_DRAIN_EXP)) total -= 12500;
1084 if (have_flag(flgs, TR_DRAIN_HP)) total -= 12500;
1085 if (have_flag(flgs, TR_DRAIN_MANA)) total -= 12500;
1086 if (have_flag(flgs, TR_CALL_ANIMAL)) total -= 12500;
1087 if (have_flag(flgs, TR_CALL_DEMON)) total -= 10000;
1088 if (have_flag(flgs, TR_CALL_DRAGON)) total -= 10000;
1089 if (have_flag(flgs, TR_CALL_UNDEAD)) total -= 10000;
1090 if (have_flag(flgs, TR_COWARDICE)) total -= 5000;
1091 if (have_flag(flgs, TR_LOW_MELEE)) total -= 5000;
1092 if (have_flag(flgs, TR_LOW_AC)) total -= 5000;
1093 if (have_flag(flgs, TR_LOW_MAGIC)) total -= 15000;
1094 if (have_flag(flgs, TR_FAST_DIGEST)) total -= 10000;
1095 if (have_flag(flgs, TR_SLOW_REGEN)) total -= 10000;
1096 if (have_flag(flgs, TR_TELEPORT))
1098 if (object_is_cursed(o_ptr))
1103 if (have_flag(flgs, TR_AGGRAVATE)) total -= 10000;
1104 if (have_flag(flgs, TR_BLESSED)) total += 750;
1105 if (o_ptr->curse_flags & TR_ADD_L_CURSE) total -= 5000;
1106 if (o_ptr->curse_flags & TR_ADD_H_CURSE) total -= 12500;
1107 if (o_ptr->curse_flags & TRC_CURSED) total -= 5000;
1108 if (o_ptr->curse_flags & TRC_HEAVY_CURSE) total -= 12500;
1109 if (o_ptr->curse_flags & TRC_PERMA_CURSE) total -= 15000;
1111 /* Also, give some extra for activatable powers... */
1112 if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
1114 const activation_type* const act_ptr = find_activation_info(o_ptr);
1116 total += act_ptr->value;
1125 * @brief オブジェクトの真の価格を算出する /
1126 * Return the value of the flags the object has...
1127 * @param o_ptr 本価格を確認したいオブジェクトの構造体参照ポインタ
1128 * @return オブジェクトの本価格
1130 * Return the "real" price of a "known" item, not including discounts\n
1132 * Wand and staffs get cost for each charge\n
1134 * Armor is worth an extra 100 gold per bonus point to armor class.\n
1136 * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).\n
1138 * Missiles are only worth 5 gold per bonus point, since they\n
1139 * usually appear in groups of 20, and we want the player to get\n
1140 * the same amount of cash for any "equivalent" item. Note that\n
1141 * missiles never have any of the "pval" flags, and in fact, they\n
1142 * only have a few of the available flags, primarily of the "slay"\n
1143 * and "brand" and "ignore" variety.\n
1145 * Armor with a negative armor bonus is worthless.\n
1146 * Weapons with negative hit+damage bonuses are worthless.\n
1148 * Every wearable item with a "pval" bonus is worth extra (see below).\n
1150 PRICE object_value_real(object_type *o_ptr)
1153 BIT_FLAGS flgs[TR_FLAG_SIZE];
1154 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1157 /* Hack -- "worthless" items */
1158 if (!k_info[o_ptr->k_idx].cost) return (0L);
1161 value = k_info[o_ptr->k_idx].cost;
1163 /* Extract some flags */
1164 object_flags(o_ptr, flgs);
1167 if (object_is_fixed_artifact(o_ptr))
1169 artifact_type *a_ptr = &a_info[o_ptr->name1];
1171 /* Hack -- "worthless" artifacts */
1172 if (!a_ptr->cost) return (0L);
1174 /* Hack -- Use the artifact cost instead */
1175 value = a_ptr->cost;
1176 value += flag_cost(o_ptr, o_ptr->pval);
1178 /* Don't add pval bonuses etc. */
1183 else if (object_is_ego(o_ptr))
1185 ego_item_type *e_ptr = &e_info[o_ptr->name2];
1187 /* Hack -- "worthless" ego-items */
1188 if (!e_ptr->cost) return (0L);
1190 /* Hack -- Reward the ego-item with a bonus */
1191 value += e_ptr->cost;
1192 value += flag_cost(o_ptr, o_ptr->pval);
1200 for (i = 0; i < TR_FLAG_SIZE; i++)
1201 if (o_ptr->art_flags[i]) flag = TRUE;
1203 if (flag) value += flag_cost(o_ptr, o_ptr->pval);
1206 /* Analyze pval bonus for normal object */
1207 switch (o_ptr->tval)
1230 if (!o_ptr->pval) break;
1232 /* Hack -- Negative "pval" is always bad */
1233 if (o_ptr->pval < 0) return (0L);
1235 /* Give credit for stat bonuses */
1236 if (have_flag(flgs, TR_STR)) value += (o_ptr->pval * 200L);
1237 if (have_flag(flgs, TR_INT)) value += (o_ptr->pval * 200L);
1238 if (have_flag(flgs, TR_WIS)) value += (o_ptr->pval * 200L);
1239 if (have_flag(flgs, TR_DEX)) value += (o_ptr->pval * 200L);
1240 if (have_flag(flgs, TR_CON)) value += (o_ptr->pval * 200L);
1241 if (have_flag(flgs, TR_CHR)) value += (o_ptr->pval * 200L);
1243 /* Give credit for stealth and searching */
1244 if (have_flag(flgs, TR_MAGIC_MASTERY)) value += (o_ptr->pval * 100);
1245 if (have_flag(flgs, TR_STEALTH)) value += (o_ptr->pval * 100L);
1246 if (have_flag(flgs, TR_SEARCH)) value += (o_ptr->pval * 100L);
1248 /* Give credit for infra-vision and tunneling */
1249 if (have_flag(flgs, TR_INFRA)) value += (o_ptr->pval * 50L);
1250 if (have_flag(flgs, TR_TUNNEL)) value += (o_ptr->pval * 50L);
1252 /* Give credit for extra attacks */
1253 if (have_flag(flgs, TR_BLOWS)) value += (o_ptr->pval * 5000L);
1255 /* Give credit for speed bonus */
1256 if (have_flag(flgs, TR_SPEED)) value += (o_ptr->pval * 10000L);
1262 /* Analyze the item */
1263 switch (o_ptr->tval)
1268 /* Pay extra for charges, depending on standard number of
1269 * charges. Handle new-style wands correctly. -LM-
1271 value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
1277 /* Pay extra for charges, depending on standard number of
1280 value += (value * o_ptr->pval / (k_ptr->pval * 2));
1289 /* Hack -- negative bonuses are bad */
1290 if (o_ptr->to_h + o_ptr->to_d + o_ptr->to_a < 0) return (0L);
1292 /* Give credit for bonuses */
1293 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
1309 /* Hack -- negative armor bonus */
1310 if (o_ptr->to_a < 0) return (0L);
1312 /* Give credit for bonuses */
1313 value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
1325 /* Hack -- negative hit/damage bonuses */
1326 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1328 /* Factor in the bonuses */
1329 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 100L);
1331 /* Hack -- Factor in extra damage dice and sides */
1332 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
1333 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
1343 /* Hack -- negative hit/damage bonuses */
1344 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1346 /* Factor in the bonuses */
1347 value += ((o_ptr->to_h + o_ptr->to_d) * 5L);
1349 /* Hack -- Factor in extra damage dice and sides */
1350 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
1351 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
1356 /* Figurines, relative to monster level */
1359 DEPTH level = r_info[o_ptr->pval].level;
1360 if (level < 20) value = level*50L;
1361 else if (level < 30) value = 1000+(level-20)*150L;
1362 else if (level < 40) value = 2500+(level-30)*350L;
1363 else if (level < 50) value = 6000+(level-40)*800L;
1364 else value = 14000+(level-50)*2000L;
1370 if (!o_ptr->pval) value = 1000L;
1371 else value = ((r_info[o_ptr->pval].level) * 50L + 1000);
1377 if (!o_ptr->pval) value = 0L;
1382 /* Worthless object */
1383 if (value < 0) return 0L;
1385 /* Return the value */
1391 * @brief オブジェクト価格算出のメインルーチン /
1392 * Return the price of an item including plusses (and charges)
1393 * @param o_ptr 判明している現価格を確認したいオブジェクトの構造体参照ポインタ
1394 * @return オブジェクトの判明している現価格
1396 * This function returns the "value" of the given item (qty one)\n
1398 * Never notice "unknown" bonuses or properties, including "curses",\n
1399 * since that would give the player information he did not have.\n
1401 * Note that discounted items stay discounted forever, even if\n
1402 * the discount is "forgotten" by the player via memory loss.\n
1404 PRICE object_value(object_type *o_ptr)
1408 /* Unknown items -- acquire a base value */
1409 if (object_is_known(o_ptr))
1411 /* Broken items -- worthless */
1412 if (object_is_broken(o_ptr)) return (0L);
1414 /* Cursed items -- worthless */
1415 if (object_is_cursed(o_ptr)) return (0L);
1417 /* Real value (see above) */
1418 value = object_value_real(o_ptr);
1421 /* Known items -- acquire the actual value */
1424 /* Hack -- Felt broken items */
1425 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_broken(o_ptr)) return (0L);
1427 /* Hack -- Felt cursed items */
1428 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_cursed(o_ptr)) return (0L);
1430 /* Base value (see above) */
1431 value = object_value_base(o_ptr);
1434 /* Apply discount (if any) */
1435 if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
1437 /* Return the final value */
1445 * @brief 魔法棒やロッドのスロット分割時に使用回数を分配する /
1446 * Distribute charges of rods or wands.
1447 * @param o_ptr 分割元オブジェクトの構造体参照ポインタ source item
1448 * @param q_ptr 分割先オブジェクトの構造体参照ポインタ target item, must be of the same type as o_ptr
1449 * @param amt 分割したい回数量 number of items that are transfered
1452 * Hack -- If rods or wands are dropped, the total maximum timeout or\n
1453 * charges need to be allocated between the two stacks. If all the items\n
1454 * are being dropped, it makes for a neater message to leave the original\n
1455 * stack's pval alone. -LM-\n
1457 void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
1459 if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD))
1461 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1462 if (amt < o_ptr->number) o_ptr->pval -= q_ptr->pval;
1464 /* Hack -- Rods also need to have their timeouts distributed. The
1465 * dropped stack will accept all time remaining to charge up to its
1468 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
1470 if (q_ptr->pval > o_ptr->timeout)
1471 q_ptr->timeout = o_ptr->timeout;
1473 q_ptr->timeout = q_ptr->pval;
1475 if (amt < o_ptr->number) o_ptr->timeout -= q_ptr->timeout;
1481 * @brief 魔法棒やロッドの使用回数を減らす /
1482 * @param o_ptr オブジェクトの構造体参照ポインタ source item
1483 * @param amt 減らしたい回数量 number of items that are transfered
1486 * Hack -- If rods or wand are destroyed, the total maximum timeout or\n
1487 * charges of the stack needs to be reduced, unless all the items are\n
1488 * being destroyed. -LM-\n
1490 void reduce_charges(object_type *o_ptr, int amt)
1492 if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD)) &&
1493 (amt < o_ptr->number))
1495 o_ptr->pval -= o_ptr->pval * amt / o_ptr->number;
1500 * Determine if an item can "absorb" a second item
1502 * See "object_absorb()" for the actual "absorption" code.
1504 * If permitted, we allow staffs (if they are known to have equal charges
1505 * and both are either known or confirmed empty) and wands (if both are
1506 * either known or confirmed empty) and rods (in all cases) to combine.
1507 * Staffs will unstack (if necessary) when they are used, but wands and
1508 * rods will only unstack if one is dropped. -LM-
1510 * If permitted, we allow weapons/armor to stack, if fully "known".
1512 * Missiles will combine if both stacks have the same "known" status.
1513 * This is done to make unidentified stacks of missiles useful.
1515 * Food, potions, scrolls, and "easy know" items always stack.
1517 * Chests, and activatable items, never stack (for various reasons).
1521 * A "stack" of items is limited to less than or equal to 99 items (hard-coded).
1523 #define MAX_STACK_SIZE 99
1527 * @brief 両オブジェクトをスロットに重ね合わせ可能な最大数を返す。
1528 * Determine if an item can partly absorb a second item. Return maximum number of stack.
1529 * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1530 * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1531 * @return 重ね合わせ可能なアイテム数
1533 int object_similar_part(object_type *o_ptr, object_type *j_ptr)
1537 /* Default maximum number of stack */
1538 int max_num = MAX_STACK_SIZE;
1540 /* Require identical object types */
1541 if (o_ptr->k_idx != j_ptr->k_idx) return 0;
1544 /* Analyze the items */
1545 switch (o_ptr->tval)
1547 /* Chests and Statues*/
1558 if ((o_ptr->sval != SV_PHOTO) || (j_ptr->sval != SV_PHOTO)) return 0;
1559 if (o_ptr->pval != j_ptr->pval) return 0;
1563 /* Figurines and Corpses*/
1568 if (o_ptr->pval != j_ptr->pval) return 0;
1574 /* Food and Potions and Scrolls */
1586 /* Require either knowledge or known empty for both staffs. */
1587 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1588 !object_is_known(o_ptr)) ||
1589 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1590 !object_is_known(j_ptr))) return 0;
1592 /* Require identical charges, since staffs are bulky. */
1593 if (o_ptr->pval != j_ptr->pval) return 0;
1602 /* Require either knowledge or known empty for both wands. */
1603 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1604 !object_is_known(o_ptr)) ||
1605 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1606 !object_is_known(j_ptr))) return 0;
1608 /* Wand charges combine in O&ZAngband. */
1614 /* Staffs and Wands and Rods */
1617 /* Prevent overflaw of timeout */
1618 max_num = MIN(max_num, MAX_SHORT / k_info[o_ptr->k_idx].pval);
1624 /* Weapons and Armor */
1640 /* Rings, Amulets, Lites */
1646 /* Require full knowledge of both items */
1647 if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1657 /* Require identical knowledge of both items */
1658 if (object_is_known(o_ptr) != object_is_known(j_ptr)) return 0;
1659 if (o_ptr->feeling != j_ptr->feeling) return 0;
1661 /* Require identical "bonuses" */
1662 if (o_ptr->to_h != j_ptr->to_h) return 0;
1663 if (o_ptr->to_d != j_ptr->to_d) return 0;
1664 if (o_ptr->to_a != j_ptr->to_a) return 0;
1666 /* Require identical "pval" code */
1667 if (o_ptr->pval != j_ptr->pval) return 0;
1669 /* Artifacts never stack */
1670 if (object_is_artifact(o_ptr) || object_is_artifact(j_ptr)) return 0;
1672 /* Require identical "ego-item" names */
1673 if (o_ptr->name2 != j_ptr->name2) return 0;
1675 /* Require identical added essence */
1676 if (o_ptr->xtra3 != j_ptr->xtra3) return 0;
1677 if (o_ptr->xtra4 != j_ptr->xtra4) return 0;
1679 /* Hack -- Never stack "powerful" items */
1680 if (o_ptr->xtra1 || j_ptr->xtra1) return 0;
1682 /* Hack -- Never stack recharging items */
1683 if (o_ptr->timeout || j_ptr->timeout) return 0;
1685 /* Require identical "values" */
1686 if (o_ptr->ac != j_ptr->ac) return 0;
1687 if (o_ptr->dd != j_ptr->dd) return 0;
1688 if (o_ptr->ds != j_ptr->ds) return 0;
1697 /* Require knowledge */
1698 if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1706 /* Hack -- Identical art_flags! */
1707 for (i = 0; i < TR_FLAG_SIZE; i++)
1708 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return 0;
1710 /* Hack -- Require identical "cursed" status */
1711 if (o_ptr->curse_flags != j_ptr->curse_flags) return 0;
1713 /* Hack -- Require identical "broken" status */
1714 if ((o_ptr->ident & (IDENT_BROKEN)) != (j_ptr->ident & (IDENT_BROKEN))) return 0;
1717 /* Hack -- require semi-matching "inscriptions" */
1718 if (o_ptr->inscription && j_ptr->inscription &&
1719 (o_ptr->inscription != j_ptr->inscription))
1722 /* Hack -- normally require matching "inscriptions" */
1723 if (!stack_force_notes && (o_ptr->inscription != j_ptr->inscription)) return 0;
1725 /* Hack -- normally require matching "discounts" */
1726 if (!stack_force_costs && (o_ptr->discount != j_ptr->discount)) return 0;
1729 /* They match, so they must be similar */
1734 * @brief 両オブジェクトをスロットに重ねることができるかどうかを返す。
1735 * Determine if an item can absorb a second item.
1736 * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1737 * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1738 * @return 重ね合わせ可能ならばTRUEを返す。
1740 bool object_similar(object_type *o_ptr, object_type *j_ptr)
1742 int total = o_ptr->number + j_ptr->number;
1745 /* Are these objects similar? */
1746 max_num = object_similar_part(o_ptr, j_ptr);
1748 /* Return if not similar */
1749 if (!max_num) return FALSE;
1751 /* Maximal "stacking" limit */
1752 if (total > max_num) return (0);
1755 /* They match, so they must be similar */
1761 * @brief 両オブジェクトをスロットに重ね合わせる。
1762 * Allow one item to "absorb" another, assuming they are similar
1763 * @param o_ptr 重ね合わせ先のオブジェクトの構造体参照ポインタ
1764 * @param j_ptr 重ね合わせ元のオブジェクトの構造体参照ポインタ
1767 void object_absorb(object_type *o_ptr, object_type *j_ptr)
1769 int max_num = object_similar_part(o_ptr, j_ptr);
1770 int total = o_ptr->number + j_ptr->number;
1771 int diff = (total > max_num) ? total - max_num : 0;
1773 /* Combine quantity, lose excess items */
1774 o_ptr->number = (total > max_num) ? max_num : total;
1776 /* Hack -- blend "known" status */
1777 if (object_is_known(j_ptr)) object_known(o_ptr);
1779 /* Hack -- clear "storebought" if only one has it */
1780 if (((o_ptr->ident & IDENT_STORE) || (j_ptr->ident & IDENT_STORE)) &&
1781 (!((o_ptr->ident & IDENT_STORE) && (j_ptr->ident & IDENT_STORE))))
1783 if (j_ptr->ident & IDENT_STORE) j_ptr->ident &= 0xEF;
1784 if (o_ptr->ident & IDENT_STORE) o_ptr->ident &= 0xEF;
1787 /* Hack -- blend "mental" status */
1788 if (j_ptr->ident & (IDENT_MENTAL)) o_ptr->ident |= (IDENT_MENTAL);
1790 /* Hack -- blend "inscriptions" */
1791 if (j_ptr->inscription) o_ptr->inscription = j_ptr->inscription;
1793 /* Hack -- blend "feelings" */
1794 if (j_ptr->feeling) o_ptr->feeling = j_ptr->feeling;
1796 /* Hack -- could average discounts */
1797 /* Hack -- save largest discount */
1798 if (o_ptr->discount < j_ptr->discount) o_ptr->discount = j_ptr->discount;
1800 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1801 if (o_ptr->tval == TV_ROD)
1803 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1804 o_ptr->timeout += j_ptr->timeout * (j_ptr->number - diff) / j_ptr->number;
1807 /* Hack -- if wands are stacking, combine the charges. -LM- */
1808 if (o_ptr->tval == TV_WAND)
1810 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1816 * @brief tvalとsvalに対応するベースアイテムのIDを返す。
1817 * Find the index of the object_kind with the given tval and sval
1818 * @param tval 検索したいベースアイテムのtval
1819 * @param sval 検索したいベースアイテムのsval
1822 KIND_OBJECT_IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
1826 KIND_OBJECT_IDX bk = 0;
1829 for (k = 1; k < max_k_idx; k++)
1831 object_kind *k_ptr = &k_info[k];
1833 /* Require correct tval */
1834 if (k_ptr->tval != tval) continue;
1837 if (k_ptr->sval == sval) return (k);
1839 /* Ignore illegal items */
1840 if (sval != SV_ANY) continue;
1842 /* Apply the randomizer */
1843 if (!one_in_(++num)) continue;
1845 /* Use this value */
1849 /* Return this choice */
1856 msg_format(_("アイテムがない (%d,%d)", "No object (%d,%d)"), tval, sval);
1865 * @brief オブジェクトを初期化する
1866 * Wipe an object clean.
1867 * @param o_ptr 初期化したいオブジェクトの構造体参照ポインタ
1870 void object_wipe(object_type *o_ptr)
1872 /* Wipe the structure */
1873 (void)WIPE(o_ptr, object_type);
1878 * @brief オブジェクトを複製する
1879 * Wipe an object clean.
1880 * @param o_ptr 複製元のオブジェクトの構造体参照ポインタ
1881 * @param j_ptr 複製先のオブジェクトの構造体参照ポインタ
1884 void object_copy(object_type *o_ptr, object_type *j_ptr)
1886 /* Copy the structure */
1887 (void)COPY(o_ptr, j_ptr, object_type);
1892 * @brief オブジェクト構造体にベースアイテムを作成する
1893 * Prepare an object based on an object kind.
1894 * @param o_ptr 代入したいオブジェクトの構造体参照ポインタ
1895 * @param k_idx 新たに作成したいベースアイテム情報のID
1898 void object_prep(object_type *o_ptr, KIND_OBJECT_IDX k_idx)
1900 object_kind *k_ptr = &k_info[k_idx];
1902 /* Clear the record */
1905 /* Save the kind index */
1906 o_ptr->k_idx = k_idx;
1908 /* Efficiency -- tval/sval */
1909 o_ptr->tval = k_ptr->tval;
1910 o_ptr->sval = k_ptr->sval;
1912 /* Default "pval" */
1913 o_ptr->pval = k_ptr->pval;
1915 /* Default number */
1918 /* Default weight */
1919 o_ptr->weight = k_ptr->weight;
1922 o_ptr->to_h = k_ptr->to_h;
1923 o_ptr->to_d = k_ptr->to_d;
1924 o_ptr->to_a = k_ptr->to_a;
1927 o_ptr->ac = k_ptr->ac;
1928 o_ptr->dd = k_ptr->dd;
1929 o_ptr->ds = k_ptr->ds;
1931 /* Default activation */
1932 if (k_ptr->act_idx > 0) o_ptr->xtra2 = (XTRA8)k_ptr->act_idx;
1934 /* Hack -- worthless items are always "broken" */
1935 if (k_info[o_ptr->k_idx].cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
1937 /* Hack -- cursed items are always "cursed" */
1938 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
1939 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
1940 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
1941 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
1942 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
1943 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
1948 * @brief デバッグ時にアイテム生成情報をメッセージに出力する / Cheat -- describe a created object for the user
1949 * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ
1952 static void object_mention(object_type *o_ptr)
1954 GAME_TEXT o_name[MAX_NLEN];
1956 object_aware(o_ptr);
1957 object_known(o_ptr);
1959 /* Mark the item as fully known */
1960 o_ptr->ident |= (IDENT_MENTAL);
1961 object_desc(o_name, o_ptr, 0);
1962 msg_format_wizard(CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
1967 * @brief アイテムのエゴをレア度の重みに合わせてランダムに選択する
1968 * Choose random ego type
1969 * @param slot 取得したいエゴの装備部位
1970 * @param good TRUEならば通常のエゴ、FALSEならば呪いのエゴが選択対象となる。
1971 * @return 選択されたエゴ情報のID、万一選択できなかった場合はmax_e_idxが返る。
1973 static byte get_random_ego(byte slot, bool good)
1976 ego_item_type *e_ptr;
1980 for (i = 1; i < max_e_idx; i++)
1984 if (e_ptr->slot == slot
1985 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
1988 total += (255 / e_ptr->rarity);
1992 value = randint1(total);
1994 for (i = 1; i < max_e_idx; i++)
1998 if (e_ptr->slot == slot
1999 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
2002 value -= (255 / e_ptr->rarity);
2003 if (value <= 0L) break;
2011 * @brief 武器系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2012 * Apply magic to an item known to be a "weapon"
2013 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2014 * @param level 生成基準階
2015 * @param power 生成ランク
2018 * Hack -- note special base damage dice boosting\n
2019 * Hack -- note special processing for weapon/digger\n
2021 void apply_magic_weapon(object_type *o_ptr, DEPTH level, int power)
2023 HIT_PROB tohit1 = randint1(5) + (HIT_PROB)m_bonus(5, level);
2024 HIT_POINT todam1 = randint1(5) + (HIT_POINT)m_bonus(5, level);
2026 HIT_PROB tohit2 = (HIT_PROB)m_bonus(10, level);
2027 HIT_POINT todam2 = (HIT_POINT)m_bonus(10, level);
2029 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
2031 tohit2 = (tohit2 + 1) / 2;
2032 todam2 = (todam2 + 1) / 2;
2039 o_ptr->to_h += tohit1;
2040 o_ptr->to_d += todam1;
2046 o_ptr->to_h += tohit2;
2047 o_ptr->to_d += todam2;
2055 o_ptr->to_h -= tohit1;
2056 o_ptr->to_d -= todam1;
2061 /* Penalize again */
2062 o_ptr->to_h -= tohit2;
2063 o_ptr->to_d -= todam2;
2066 /* Cursed (if "bad") */
2067 if (o_ptr->to_h + o_ptr->to_d < 0) o_ptr->curse_flags |= TRC_CURSED;
2070 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)) return;
2072 switch (o_ptr->tval)
2079 if (one_in_(30) || (power > 2)) /* power > 2 is debug only */
2080 create_artifact(o_ptr, FALSE);
2082 /* Special Ego-item */
2083 o_ptr->name2 = EGO_DIGGING;
2087 else if (power < -1)
2089 /* Hack -- Horrible digging bonus */
2090 o_ptr->pval = 0 - (5 + randint1(5));
2096 /* Hack -- Reverse digging bonus */
2097 o_ptr->pval = 0 - (o_ptr->pval);
2110 if (one_in_(40) || (power > 2)) /* power > 2 is debug only */
2112 create_artifact(o_ptr, FALSE);
2117 /* Roll for an ego-item */
2118 o_ptr->name2 = get_random_ego(INVEN_RARM, TRUE);
2119 if (o_ptr->name2 == EGO_SHARPNESS && o_ptr->tval != TV_SWORD)
2121 if (o_ptr->name2 == EGO_EARTHQUAKES && o_ptr->tval != TV_HAFTED)
2123 if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2128 switch (o_ptr->name2)
2131 if (one_in_(4) && (level > 40))
2132 add_flag(o_ptr->art_flags, TR_BLOWS);
2136 add_flag(o_ptr->art_flags, TR_RES_POIS);
2138 add_flag(o_ptr->art_flags, TR_WARNING);
2140 case EGO_KILL_DRAGON:
2142 add_flag(o_ptr->art_flags, TR_RES_POIS);
2146 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2148 case EGO_SLAYING_WEAPON:
2149 if (one_in_(3)) /* double damage */
2156 } while (one_in_(o_ptr->dd));
2161 } while (one_in_(o_ptr->ds));
2166 add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2168 if (o_ptr->tval == TV_SWORD && one_in_(3))
2170 add_flag(o_ptr->art_flags, TR_VORPAL);
2175 add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
2181 add_flag(o_ptr->art_flags, TR_HOLD_EXP);
2183 add_flag(o_ptr->art_flags, TR_DEX);
2185 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2188 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, level) + 1;
2190 case EGO_EARTHQUAKES:
2191 if (one_in_(3) && (level > 60))
2192 add_flag(o_ptr->art_flags, TR_BLOWS);
2194 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, level);
2198 add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
2202 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2204 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2206 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2207 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2210 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CHAOTIC);
2211 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BLOWS);
2212 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2213 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2217 if (!o_ptr->art_name)
2219 /* Hack -- Super-charge the damage dice */
2220 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2222 /* Hack -- Lower the damage dice */
2223 if (o_ptr->dd > 9) o_ptr->dd = 9;
2228 else if (power < -1)
2230 /* Roll for ego-item */
2231 if (randint0(MAX_DEPTH) < level)
2235 o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE);
2236 if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2242 switch (o_ptr->name2)
2245 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2246 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2249 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2250 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_NETHER);
2251 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2252 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2253 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2254 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2269 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2271 create_artifact(o_ptr, FALSE);
2274 o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE);
2288 if (power > 2) /* power > 2 is debug only */
2290 create_artifact(o_ptr, FALSE);
2294 o_ptr->name2 = get_random_ego(INVEN_AMMO, TRUE);
2296 switch (o_ptr->name2)
2298 case EGO_SLAYING_BOLT:
2303 /* Hack -- super-charge the damage dice */
2304 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2306 /* Hack -- restrict the damage dice */
2307 if (o_ptr->dd > 9) o_ptr->dd = 9;
2311 else if (power < -1)
2313 /* Roll for ego-item */
2314 if (randint0(MAX_DEPTH) < level)
2316 o_ptr->name2 = get_random_ego(INVEN_AMMO, FALSE);
2326 * @brief 防具系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2327 * Apply magic to an item known to be "armor"
2328 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2329 * @param level 生成基準階
2330 * @param power 生成ランク
2333 * Hack -- note special processing for crown/helm\n
2334 * Hack -- note special processing for robe of permanence\n
2336 static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
2338 ARMOUR_CLASS toac1 = (ARMOUR_CLASS)randint1(5) + m_bonus(5, level);
2339 ARMOUR_CLASS toac2 = (ARMOUR_CLASS)m_bonus(10, level);
2345 o_ptr->to_a += toac1;
2351 o_ptr->to_a += toac2;
2359 o_ptr->to_a -= toac1;
2364 /* Penalize again */
2365 o_ptr->to_a -= toac2;
2368 /* Cursed (if "bad") */
2369 if (o_ptr->to_a < 0) o_ptr->curse_flags |= TRC_CURSED;
2372 switch (o_ptr->tval)
2376 if (one_in_(50) || (power > 2)) /* power > 2 is debug only */
2377 create_artifact(o_ptr, FALSE);
2387 /* Hack -- Try for "Robes of the Magi" */
2388 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
2389 (o_ptr->sval == SV_ROBE) &&
2390 (randint0(100) < 15))
2394 o_ptr->name2 = EGO_YOIYAMI;
2395 o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
2396 o_ptr->sval = SV_YOIYAMI_ROBE;
2402 o_ptr->name2 = EGO_PERMANENCE;
2407 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2409 create_artifact(o_ptr, FALSE);
2415 bool okay_flag = TRUE;
2417 o_ptr->name2 = get_random_ego(INVEN_BODY, TRUE);
2419 switch (o_ptr->name2)
2422 if (o_ptr->tval != TV_HARD_ARMOR)
2428 if (o_ptr->tval != TV_SOFT_ARMOR)
2437 if (okay_flag) break;
2439 switch (o_ptr->name2)
2441 case EGO_RESISTANCE:
2443 add_flag(o_ptr->art_flags, TR_RES_POIS);
2446 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2447 o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
2451 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2453 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2455 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2456 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2458 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2459 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2460 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2461 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2462 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2463 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2464 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2465 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2468 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2469 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2470 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2471 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2472 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2473 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2486 if (o_ptr->sval == SV_DRAGON_SHIELD)
2488 dragon_resist(o_ptr);
2489 if (!one_in_(3)) break;
2495 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2497 create_artifact(o_ptr, FALSE);
2503 o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE);
2504 if (o_ptr->sval != SV_SMALL_METAL_SHIELD && o_ptr->sval != SV_LARGE_METAL_SHIELD
2505 && o_ptr->name2 == EGO_S_DWARVEN)
2512 switch (o_ptr->name2)
2515 if (!one_in_(3)) one_high_resistance(o_ptr);
2516 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_POIS);
2518 case EGO_REFLECTION:
2519 if (o_ptr->sval == SV_MIRROR_SHIELD)
2524 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2525 o_ptr->ac = k_info[o_ptr->k_idx].ac + 3;
2534 if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
2536 dragon_resist(o_ptr);
2537 if (!one_in_(3)) break;
2541 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2543 create_artifact(o_ptr, FALSE);
2546 o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE);
2550 else if (power < -1)
2552 o_ptr->name2 = get_random_ego(INVEN_HANDS, FALSE);
2560 if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
2562 dragon_resist(o_ptr);
2563 if (!one_in_(3)) break;
2568 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2570 create_artifact(o_ptr, FALSE);
2573 o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE);
2575 switch (o_ptr->name2)
2577 case EGO_SLOW_DESCENT:
2580 one_high_resistance(o_ptr);
2586 else if (power < -1)
2588 o_ptr->name2 = get_random_ego(INVEN_FEET, FALSE);
2599 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2601 create_artifact(o_ptr, FALSE);
2606 bool ok_flag = TRUE;
2607 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2609 switch (o_ptr->name2)
2612 if (add_esp_strong(o_ptr)) add_esp_weak(o_ptr, TRUE);
2613 else add_esp_weak(o_ptr, FALSE);
2617 case EGO_REGENERATION:
2618 case EGO_LORDLINESS:
2624 if (one_in_(2)) add_esp_strong(o_ptr);
2625 else add_esp_weak(o_ptr, FALSE);
2628 default:/* not existing crown (wisdom,lite, etc...) */
2632 break; /* while (1) */
2638 else if (power < -1)
2642 bool ok_flag = TRUE;
2643 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2645 switch (o_ptr->name2)
2647 case EGO_ANCIENT_CURSE:
2648 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2649 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2650 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2651 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2652 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2653 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2657 break; /* while (1) */
2666 if (o_ptr->sval == SV_DRAGON_HELM)
2668 dragon_resist(o_ptr);
2669 if (!one_in_(3)) break;
2675 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2677 create_artifact(o_ptr, FALSE);
2682 bool ok_flag = TRUE;
2683 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2685 switch (o_ptr->name2)
2687 case EGO_BRILLIANCE:
2689 case EGO_INFRAVISION:
2690 case EGO_H_PROTECTION:
2695 if (one_in_(2)) add_esp_strong(o_ptr);
2696 else add_esp_weak(o_ptr, FALSE);
2700 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_1);
2701 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_2);
2704 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2706 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2708 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2709 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2711 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2712 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2713 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2714 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2715 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2716 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2717 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2718 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2720 default:/* not existing helm (Magi, Might, etc...)*/
2724 break; /* while (1) */
2729 else if (power < -1)
2733 bool ok_flag = TRUE;
2734 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2736 switch (o_ptr->name2)
2738 case EGO_ANCIENT_CURSE:
2742 break; /* while (1) */
2753 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2755 create_artifact(o_ptr, FALSE);
2758 o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE);
2760 switch (o_ptr->name2)
2769 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_COWARDICE);
2770 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CALL_UNDEAD);
2771 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_SLOW_REGEN);
2772 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2779 else if (power < -1)
2781 o_ptr->name2 = get_random_ego(INVEN_OUTER, FALSE);
2792 * @brief 装飾品系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2793 * Apply magic to an item known to be a "ring" or "amulet"
2794 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2795 * @param level 生成基準階
2796 * @param power 生成ランク
2799 * Hack -- note special "pval boost" code for ring of speed\n
2800 * Hack -- note that some items must be cursed (or blessed)\n
2802 static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
2804 /* Apply magic (good or bad) according to type */
2805 switch (o_ptr->tval)
2810 switch (o_ptr->sval)
2812 case SV_RING_ATTACKS:
2815 o_ptr->pval = (PARAMETER_VALUE)m_bonus(2, level);
2816 if (one_in_(15)) o_ptr->pval++;
2817 if (o_ptr->pval < 1) o_ptr->pval = 1;
2823 o_ptr->ident |= (IDENT_BROKEN);
2826 o_ptr->curse_flags |= TRC_CURSED;
2829 o_ptr->pval = 0 - (o_ptr->pval);
2840 /* Strength, Constitution, Dexterity, Intelligence */
2846 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2852 o_ptr->ident |= (IDENT_BROKEN);
2855 o_ptr->curse_flags |= TRC_CURSED;
2858 o_ptr->pval = 0 - (o_ptr->pval);
2864 /* Ring of Speed! */
2867 /* Base speed (1 to 10) */
2868 o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
2870 /* Super-charge the ring */
2871 while (randint0(100) < 50) o_ptr->pval++;
2877 o_ptr->ident |= (IDENT_BROKEN);
2880 o_ptr->curse_flags |= TRC_CURSED;
2883 o_ptr->pval = 0 - (o_ptr->pval);
2891 case SV_RING_LORDLY:
2895 one_lordly_high_resistance(o_ptr);
2899 /* Bonus to armor class */
2900 o_ptr->to_a = 10 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2904 case SV_RING_WARNING:
2906 if (one_in_(3)) one_low_esp(o_ptr);
2911 case SV_RING_SEARCHING:
2913 /* Bonus to searching */
2914 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2920 o_ptr->ident |= (IDENT_BROKEN);
2923 o_ptr->curse_flags |= TRC_CURSED;
2926 o_ptr->pval = 0 - (o_ptr->pval);
2932 /* Flames, Acid, Ice */
2933 case SV_RING_FLAMES:
2938 /* Bonus to armor class */
2939 o_ptr->to_a = 5 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2943 /* Weakness, Stupidity */
2944 case SV_RING_WEAKNESS:
2945 case SV_RING_STUPIDITY:
2948 o_ptr->ident |= (IDENT_BROKEN);
2951 o_ptr->curse_flags |= TRC_CURSED;
2954 o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2955 if (power > 0) power = 0 - power;
2960 /* WOE, Stupidity */
2964 o_ptr->ident |= (IDENT_BROKEN);
2967 o_ptr->curse_flags |= TRC_CURSED;
2970 o_ptr->to_a = 0 - (5 + (ARMOUR_CLASS)m_bonus(10, level));
2971 o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2972 if (power > 0) power = 0 - power;
2977 /* Ring of damage */
2978 case SV_RING_DAMAGE:
2980 /* Bonus to damage */
2981 o_ptr->to_d = 1 + randint1(5) + (HIT_POINT)m_bonus(16, level);
2987 o_ptr->ident |= (IDENT_BROKEN);
2990 o_ptr->curse_flags |= TRC_CURSED;
2993 o_ptr->to_d = 0 - o_ptr->to_d;
2999 /* Ring of Accuracy */
3000 case SV_RING_ACCURACY:
3003 o_ptr->to_h = 1 + randint1(5) + (HIT_PROB)m_bonus(16, level);
3009 o_ptr->ident |= (IDENT_BROKEN);
3012 o_ptr->curse_flags |= TRC_CURSED;
3015 o_ptr->to_h = 0 - o_ptr->to_h;
3021 /* Ring of Protection */
3022 case SV_RING_PROTECTION:
3024 /* Bonus to armor class */
3025 o_ptr->to_a = 5 + randint1(8) + (ARMOUR_CLASS)m_bonus(10, level);
3031 o_ptr->ident |= (IDENT_BROKEN);
3034 o_ptr->curse_flags |= TRC_CURSED;
3037 o_ptr->to_a = 0 - o_ptr->to_a;
3043 /* Ring of Slaying */
3044 case SV_RING_SLAYING:
3046 /* Bonus to damage and to hit */
3047 o_ptr->to_d = randint1(5) + (HIT_POINT)m_bonus(12, level);
3048 o_ptr->to_h = randint1(5) + (HIT_PROB)m_bonus(12, level);
3054 o_ptr->ident |= (IDENT_BROKEN);
3057 o_ptr->curse_flags |= TRC_CURSED;
3059 /* Reverse bonuses */
3060 o_ptr->to_h = 0 - o_ptr->to_h;
3061 o_ptr->to_d = 0 - o_ptr->to_d;
3067 case SV_RING_MUSCLE:
3069 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(3, level);
3070 if (one_in_(4)) o_ptr->pval++;
3076 o_ptr->ident |= (IDENT_BROKEN);
3079 o_ptr->curse_flags |= TRC_CURSED;
3081 /* Reverse bonuses */
3082 o_ptr->pval = 0 - o_ptr->pval;
3087 case SV_RING_AGGRAVATION:
3090 o_ptr->ident |= (IDENT_BROKEN);
3093 o_ptr->curse_flags |= TRC_CURSED;
3095 if (power > 0) power = 0 - power;
3099 if ((one_in_(400) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3100 || (power > 2)) /* power > 2 is debug only */
3102 o_ptr->pval = MIN(o_ptr->pval, 4);
3103 /* Randart amulet */
3104 create_artifact(o_ptr, FALSE);
3106 else if ((power == 2) && one_in_(2))
3108 while(!o_ptr->name2)
3110 int tmp = m_bonus(10, level);
3111 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3112 switch(randint1(28))
3115 o_ptr->name2 = EGO_RING_THROW;
3118 if (have_flag(k_ptr->flags, TR_REGEN)) break;
3119 o_ptr->name2 = EGO_RING_REGEN;
3122 if (have_flag(k_ptr->flags, TR_LITE_1)) break;
3123 o_ptr->name2 = EGO_RING_LITE;
3126 if (have_flag(k_ptr->flags, TR_TELEPORT)) break;
3127 o_ptr->name2 = EGO_RING_TELEPORT;
3130 if (o_ptr->to_h) break;
3131 o_ptr->name2 = EGO_RING_TO_H;
3134 if (o_ptr->to_d) break;
3135 o_ptr->name2 = EGO_RING_TO_D;
3138 if ((o_ptr->to_h) || (o_ptr->to_d)) break;
3139 o_ptr->name2 = EGO_RING_SLAY;
3142 if ((have_flag(k_ptr->flags, TR_STR)) || o_ptr->to_h || o_ptr->to_d) break;
3143 o_ptr->name2 = EGO_RING_WIZARD;
3146 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3147 o_ptr->name2 = EGO_RING_HERO;
3150 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3151 if (tmp > 8) o_ptr->name2 = EGO_RING_MANA_BALL;
3152 else if (tmp > 4) o_ptr->name2 = EGO_RING_MANA_BOLT;
3153 else o_ptr->name2 = EGO_RING_MAGIC_MIS;
3156 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3157 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;
3158 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_F;
3159 else if (tmp > 3) o_ptr->name2 = EGO_RING_FIRE_BALL;
3160 else o_ptr->name2 = EGO_RING_FIRE_BOLT;
3163 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3164 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;
3165 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_C;
3166 else if (tmp > 3) o_ptr->name2 = EGO_RING_COLD_BALL;
3167 else o_ptr->name2 = EGO_RING_COLD_BOLT;
3170 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3171 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;
3172 if (tmp > 4) o_ptr->name2 = EGO_RING_ELEC_BALL;
3173 else o_ptr->name2 = EGO_RING_ELEC_BOLT;
3176 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3177 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;
3178 if (tmp > 4) o_ptr->name2 = EGO_RING_ACID_BALL;
3179 else o_ptr->name2 = EGO_RING_ACID_BOLT;
3181 case 21: case 22: case 23: case 24: case 25: case 26:
3182 switch (o_ptr->sval)
3185 if (!one_in_(3)) break;
3186 o_ptr->name2 = EGO_RING_D_SPEED;
3188 case SV_RING_DAMAGE:
3189 case SV_RING_ACCURACY:
3190 case SV_RING_SLAYING:
3191 if (one_in_(2)) break;
3192 if (one_in_(2)) o_ptr->name2 = EGO_RING_HERO;
3195 o_ptr->name2 = EGO_RING_BERSERKER;
3196 o_ptr->to_h -= 2+randint1(4);
3197 o_ptr->to_d += 2+randint1(4);
3200 case SV_RING_PROTECTION:
3201 o_ptr->name2 = EGO_RING_SUPER_AC;
3202 o_ptr->to_a += 7 + m_bonus(5, level);
3204 case SV_RING_RES_FEAR:
3205 o_ptr->name2 = EGO_RING_HERO;
3208 if (one_in_(2)) break;
3209 o_ptr->name2 = EGO_RING_HUNTER;
3211 case SV_RING_SEARCHING:
3212 o_ptr->name2 = EGO_RING_STEALTH;
3214 case SV_RING_TELEPORTATION:
3215 o_ptr->name2 = EGO_RING_TELE_AWAY;
3217 case SV_RING_RES_BLINDNESS:
3219 o_ptr->name2 = EGO_RING_RES_LITE;
3221 o_ptr->name2 = EGO_RING_RES_DARK;
3223 case SV_RING_LORDLY:
3224 if (!one_in_(20)) break;
3225 one_lordly_high_resistance(o_ptr);
3226 one_lordly_high_resistance(o_ptr);
3227 o_ptr->name2 = EGO_RING_TRUE;
3229 case SV_RING_SUSTAIN:
3230 if (!one_in_(4)) break;
3231 o_ptr->name2 = EGO_RING_RES_TIME;
3233 case SV_RING_FLAMES:
3234 if (!one_in_(2)) break;
3235 o_ptr->name2 = EGO_RING_DRAGON_F;
3238 if (!one_in_(2)) break;
3239 o_ptr->name2 = EGO_RING_DRAGON_C;
3241 case SV_RING_WARNING:
3242 if (!one_in_(2)) break;
3243 o_ptr->name2 = EGO_RING_M_DETECT;
3251 o_ptr->curse_flags = 0L;
3253 else if ((power == -2) && one_in_(2))
3255 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3256 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3257 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3258 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3259 o_ptr->art_flags[0] = 0;
3260 o_ptr->art_flags[1] = 0;
3261 while(!o_ptr->name2)
3263 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3267 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3268 o_ptr->name2 = EGO_RING_DRAIN_EXP;
3271 o_ptr->name2 = EGO_RING_NO_MELEE;
3274 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3275 o_ptr->name2 = EGO_RING_AGGRAVATE;
3278 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3279 o_ptr->name2 = EGO_RING_TY_CURSE;
3282 o_ptr->name2 = EGO_RING_ALBINO;
3287 o_ptr->ident |= (IDENT_BROKEN);
3290 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3298 switch (o_ptr->sval)
3300 /* Amulet of wisdom/charisma */
3301 case SV_AMULET_INTELLIGENCE:
3302 case SV_AMULET_WISDOM:
3303 case SV_AMULET_CHARISMA:
3305 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
3311 o_ptr->ident |= (IDENT_BROKEN);
3314 o_ptr->curse_flags |= (TRC_CURSED);
3316 /* Reverse bonuses */
3317 o_ptr->pval = 0 - o_ptr->pval;
3323 /* Amulet of brilliance */
3324 case SV_AMULET_BRILLIANCE:
3326 o_ptr->pval = 1 + m_bonus(3, level);
3327 if (one_in_(4)) o_ptr->pval++;
3333 o_ptr->ident |= (IDENT_BROKEN);
3336 o_ptr->curse_flags |= (TRC_CURSED);
3338 /* Reverse bonuses */
3339 o_ptr->pval = 0 - o_ptr->pval;
3345 case SV_AMULET_NO_MAGIC: case SV_AMULET_NO_TELE:
3349 o_ptr->curse_flags |= (TRC_CURSED);
3354 case SV_AMULET_RESISTANCE:
3356 if (one_in_(5)) one_high_resistance(o_ptr);
3357 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_RES_POIS);
3361 /* Amulet of searching */
3362 case SV_AMULET_SEARCHING:
3364 o_ptr->pval = randint1(2) + (PARAMETER_VALUE)m_bonus(4, level);
3370 o_ptr->ident |= (IDENT_BROKEN);
3373 o_ptr->curse_flags |= (TRC_CURSED);
3375 /* Reverse bonuses */
3376 o_ptr->pval = 0 - (o_ptr->pval);
3382 /* Amulet of the Magi -- never cursed */
3383 case SV_AMULET_THE_MAGI:
3385 o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
3386 o_ptr->to_a = randint1(5) + (ARMOUR_CLASS)m_bonus(5, level);
3388 /* gain one low ESP */
3389 add_esp_weak(o_ptr, FALSE);
3394 /* Amulet of Doom -- always cursed */
3395 case SV_AMULET_DOOM:
3398 o_ptr->ident |= (IDENT_BROKEN);
3401 o_ptr->curse_flags |= (TRC_CURSED);
3404 o_ptr->pval = 0 - (randint1(5) + (PARAMETER_VALUE)m_bonus(5, level));
3405 o_ptr->to_a = 0 - (randint1(5) + (ARMOUR_CLASS)m_bonus(5, level));
3406 if (power > 0) power = 0 - power;
3411 case SV_AMULET_MAGIC_MASTERY:
3413 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(4, level);
3419 o_ptr->ident |= (IDENT_BROKEN);
3422 o_ptr->curse_flags |= (TRC_CURSED);
3424 /* Reverse bonuses */
3425 o_ptr->pval = 0 - o_ptr->pval;
3431 if ((one_in_(150) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3432 || (power > 2)) /* power > 2 is debug only */
3434 o_ptr->pval = MIN(o_ptr->pval, 4);
3435 /* Randart amulet */
3436 create_artifact(o_ptr, FALSE);
3438 else if ((power == 2) && one_in_(2))
3440 while(!o_ptr->name2)
3442 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3443 switch(randint1(21))
3446 if (have_flag(k_ptr->flags, TR_SLOW_DIGEST)) break;
3447 o_ptr->name2 = EGO_AMU_SLOW_D;
3450 if (o_ptr->pval) break;
3451 o_ptr->name2 = EGO_AMU_INFRA;
3454 if (have_flag(k_ptr->flags, TR_SEE_INVIS)) break;
3455 o_ptr->name2 = EGO_AMU_SEE_INVIS;
3458 if (have_flag(k_ptr->flags, TR_HOLD_EXP)) break;
3459 o_ptr->name2 = EGO_AMU_HOLD_EXP;
3462 if (have_flag(k_ptr->flags, TR_LEVITATION)) break;
3463 o_ptr->name2 = EGO_AMU_LEVITATION;
3465 case 10: case 11: case 21:
3466 o_ptr->name2 = EGO_AMU_AC;
3469 if (have_flag(k_ptr->flags, TR_RES_FIRE)) break;
3470 if (m_bonus(10, level) > 8)
3471 o_ptr->name2 = EGO_AMU_RES_FIRE_;
3473 o_ptr->name2 = EGO_AMU_RES_FIRE;
3476 if (have_flag(k_ptr->flags, TR_RES_COLD)) break;
3477 if (m_bonus(10, level) > 8)
3478 o_ptr->name2 = EGO_AMU_RES_COLD_;
3480 o_ptr->name2 = EGO_AMU_RES_COLD;
3483 if (have_flag(k_ptr->flags, TR_RES_ELEC)) break;
3484 if (m_bonus(10, level) > 8)
3485 o_ptr->name2 = EGO_AMU_RES_ELEC_;
3487 o_ptr->name2 = EGO_AMU_RES_ELEC;
3490 if (have_flag(k_ptr->flags, TR_RES_ACID)) break;
3491 if (m_bonus(10, level) > 8)
3492 o_ptr->name2 = EGO_AMU_RES_ACID_;
3494 o_ptr->name2 = EGO_AMU_RES_ACID;
3496 case 16: case 17: case 18: case 19: case 20:
3497 switch (o_ptr->sval)
3499 case SV_AMULET_TELEPORT:
3500 if (m_bonus(10, level) > 9) o_ptr->name2 = EGO_AMU_D_DOOR;
3501 else if (one_in_(2)) o_ptr->name2 = EGO_AMU_JUMP;
3502 else o_ptr->name2 = EGO_AMU_TELEPORT;
3504 case SV_AMULET_RESIST_ACID:
3505 if ((m_bonus(10, level) > 6) && one_in_(2)) o_ptr->name2 = EGO_AMU_RES_ACID_;
3507 case SV_AMULET_SEARCHING:
3508 o_ptr->name2 = EGO_AMU_STEALTH;
3510 case SV_AMULET_BRILLIANCE:
3511 if (!one_in_(3)) break;
3512 o_ptr->name2 = EGO_AMU_IDENT;
3514 case SV_AMULET_CHARISMA:
3515 if (!one_in_(3)) break;
3516 o_ptr->name2 = EGO_AMU_CHARM;
3518 case SV_AMULET_THE_MAGI:
3519 if (one_in_(2)) break;
3520 o_ptr->name2 = EGO_AMU_GREAT;
3522 case SV_AMULET_RESISTANCE:
3523 if (!one_in_(5)) break;
3524 o_ptr->name2 = EGO_AMU_DEFENDER;
3526 case SV_AMULET_TELEPATHY:
3527 if (!one_in_(3)) break;
3528 o_ptr->name2 = EGO_AMU_DETECTION;
3533 o_ptr->curse_flags = 0L;
3535 else if ((power == -2) && one_in_(2))
3537 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3538 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3539 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3540 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3541 o_ptr->art_flags[0] = 0;
3542 o_ptr->art_flags[1] = 0;
3543 while(!o_ptr->name2)
3545 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3549 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3550 o_ptr->name2 = EGO_AMU_DRAIN_EXP;
3553 o_ptr->name2 = EGO_AMU_FOOL;
3556 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3557 o_ptr->name2 = EGO_AMU_AGGRAVATE;
3560 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3561 o_ptr->name2 = EGO_AMU_TY_CURSE;
3564 o_ptr->name2 = EGO_AMU_NAIVETY;
3569 o_ptr->ident |= (IDENT_BROKEN);
3572 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3581 * @brief その他雑多のオブジェクトに生成ランクごとの強化を与えるサブルーチン
3582 * Apply magic to an item known to be "boring"
3583 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3584 * @param level 生成基準階
3585 * @param power 生成ランク
3588 * Hack -- note the special code for various items
3590 static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
3592 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3597 /* Apply magic (good or bad) according to type */
3598 switch (o_ptr->tval)
3607 o_ptr->ident |= (IDENT_BROKEN);
3610 o_ptr->curse_flags |= (TRC_CURSED);
3617 o_ptr->xtra4 = o_ptr->pval;
3623 /* Hack -- Torches -- random fuel */
3624 if (o_ptr->sval == SV_LITE_TORCH)
3626 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3630 /* Hack -- Lanterns -- random fuel */
3631 if (o_ptr->sval == SV_LITE_LANTERN)
3633 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3637 if (power > 2) /* power > 2 is debug only */
3639 create_artifact(o_ptr, FALSE);
3641 else if ((power == 2) || ((power == 1) && one_in_(3)))
3643 while (!o_ptr->name2)
3647 bool okay_flag = TRUE;
3649 o_ptr->name2 = get_random_ego(INVEN_LITE, TRUE);
3651 switch (o_ptr->name2)
3654 if (o_ptr->sval == SV_LITE_FEANOR)
3662 else if (power == -2)
3664 o_ptr->name2 = get_random_ego(INVEN_LITE, FALSE);
3666 switch (o_ptr->name2)
3668 case EGO_LITE_DARKNESS:
3671 if (o_ptr->sval == SV_LITE_TORCH)
3673 add_flag(o_ptr->art_flags, TR_LITE_M1);
3675 else if (o_ptr->sval == SV_LITE_LANTERN)
3677 add_flag(o_ptr->art_flags, TR_LITE_M2);
3679 else if (o_ptr->sval == SV_LITE_FEANOR)
3681 add_flag(o_ptr->art_flags, TR_LITE_M3);
3693 /* The wand or staff gets a number of initial charges equal
3694 * to between 1/2 (+1) and the full object kind's pval. -LM-
3696 o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
3702 /* Transfer the pval. -LM- */
3703 o_ptr->pval = k_ptr->pval;
3710 object_aware(o_ptr);
3711 object_known(o_ptr);
3717 PARAMETER_VALUE i = 1;
3720 monster_race *r_ptr;
3722 /* Pick a random non-unique monster race */
3725 i = randint1(max_r_idx - 1);
3727 if (!item_monster_okay(i)) continue;
3728 if (i == MON_TSUCHINOKO) continue;
3732 check = (current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - current_floor_ptr->dun_level) : 0;
3734 /* Ignore dead monsters */
3735 if (!r_ptr->rarity) continue;
3737 /* Ignore uncommon monsters */
3738 if (r_ptr->rarity > 100) continue;
3740 /* Prefer less out-of-depth monsters */
3741 if (randint0(check)) continue;
3748 /* Some figurines are cursed */
3749 if (one_in_(6)) o_ptr->curse_flags |= TRC_CURSED;
3756 PARAMETER_VALUE i = 1;
3761 monster_race *r_ptr;
3763 if (o_ptr->sval == SV_SKELETON)
3765 match = RF9_DROP_SKELETON;
3767 else if (o_ptr->sval == SV_CORPSE)
3769 match = RF9_DROP_CORPSE;
3772 /* Hack -- Remove the monster restriction */
3773 get_mon_num_prep(item_monster_okay, NULL);
3775 /* Pick a random non-unique monster race */
3778 i = get_mon_num(current_floor_ptr->dun_level);
3782 check = (current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - current_floor_ptr->dun_level) : 0;
3784 /* Ignore dead monsters */
3785 if (!r_ptr->rarity) continue;
3787 /* Ignore corpseless monsters */
3788 if (!(r_ptr->flags9 & match)) continue;
3790 /* Prefer less out-of-depth monsters */
3791 if (randint0(check)) continue;
3799 object_aware(o_ptr);
3800 object_known(o_ptr);
3806 PARAMETER_VALUE i = 1;
3808 monster_race *r_ptr;
3810 /* Pick a random monster race */
3813 i = randint1(max_r_idx - 1);
3817 /* Ignore dead monsters */
3818 if (!r_ptr->rarity) continue;
3827 msg_format(_("%sの像", "Statue of %s"), r_name + r_ptr->name);
3829 object_aware(o_ptr);
3830 object_known(o_ptr);
3837 DEPTH obj_level = k_info[o_ptr->k_idx].level;
3839 /* Hack -- skip ruined chests */
3840 if (obj_level <= 0) break;
3842 /* Hack -- pick a "difficulty" */
3843 o_ptr->pval = randint1(obj_level);
3844 if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
3846 o_ptr->xtra3 = current_floor_ptr->dun_level + 5;
3848 /* Never exceed "difficulty" of 55 to 59 */
3849 if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
3857 * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
3858 * Complete the "creation" of an object by applying "magic" to the item
3859 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3861 * @param mode 生成オプション
3864 * This includes not only rolling for random bonuses, but also putting the\n
3865 * finishing touches on ego-items and artifacts, giving charges to wands and\n
3866 * staffs, giving fuel to lites, and placing traps on chests.\n
3868 * In particular, note that "Instant Artifacts", if "created" by an external\n
3869 * routine, must pass through this function to complete the actual creation.\n
3871 * The base "chance" of the item being "good" increases with the "level"\n
3872 * parameter, which is usually derived from the dungeon level, being equal\n
3873 * to the level plus 10, up to a maximum of 75. If "good" is true, then\n
3874 * the object is guaranteed to be "good". If an object is "good", then\n
3875 * the chance that the object will be "great" (ego-item or artifact), also\n
3876 * increases with the "level", being equal to half the level, plus 5, up to\n
3877 * a maximum of 20. If "great" is true, then the object is guaranteed to be\n
3878 * "great". At dungeon level 65 and below, 15/100 objects are "great".\n
3880 * If the object is not "good", there is a chance it will be "cursed", and\n
3881 * if it is "cursed", there is a chance it will be "broken". These chances\n
3882 * are related to the "good" / "great" chances above.\n
3884 * Otherwise "normal" rings and amulets will be "good" half the time and\n
3885 * "cursed" half the time, unless the ring/amulet is always good or cursed.\n
3887 * If "okay" is true, and the object is going to be "great", then there is\n
3888 * a chance that an artifact will be created. This is true even if both the\n
3889 * "good" and "great" arguments are false. As a total hack, if "great" is\n
3890 * true, then the item gets 3 extra "attempts" to become an artifact.\n
3892 void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
3894 int i, rolls, f1, f2, power;
3896 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) lev += randint0(p_ptr->lev/2+10);
3898 /* Maximum "level" for various things */
3899 if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1;
3901 /* Base chance of being "good" */
3904 /* Maximal chance of being "good" */
3905 if (f1 > d_info[p_ptr->dungeon_idx].obj_good) f1 = d_info[p_ptr->dungeon_idx].obj_good;
3907 /* Base chance of being "great" */
3910 /* Maximal chance of being "great" */
3911 if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[p_ptr->dungeon_idx].obj_great))
3912 f2 = d_info[p_ptr->dungeon_idx].obj_great;
3914 if (p_ptr->muta3 & MUT3_GOOD_LUCK)
3919 else if(p_ptr->muta3 & MUT3_BAD_LUCK)
3928 /* Roll for "good" */
3929 if ((mode & AM_GOOD) || magik(f1))
3934 /* Roll for "great" */
3935 if ((mode & AM_GREAT) || magik(f2))
3939 /* Roll for "special" */
3940 if (mode & AM_SPECIAL) power = 3;
3944 /* Roll for "cursed" */
3947 /* Assume "cursed" */
3950 /* Roll for "broken" */
3951 if (magik(f2)) power = -2;
3955 if (mode & AM_CURSED)
3957 /* Assume 'cursed' */
3962 /* Everything else gets more badly cursed */
3969 /* Assume no rolls */
3972 /* Get one roll if excellent */
3973 if (power >= 2) rolls = 1;
3975 /* Hack -- Get four rolls if forced great or special */
3976 if (mode & (AM_GREAT | AM_SPECIAL)) rolls = 4;
3978 /* Hack -- Get no rolls if not allowed */
3979 if ((mode & AM_NO_FIXED_ART) || o_ptr->name1) rolls = 0;
3981 /* Roll for artifacts if allowed */
3982 for (i = 0; i < rolls; i++)
3984 /* Roll for an artifact */
3985 if (make_artifact(o_ptr)) break;
3986 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77))
3988 if (make_artifact(o_ptr)) break;
3993 /* Hack -- analyze artifacts */
3994 if (object_is_fixed_artifact(o_ptr))
3996 artifact_type *a_ptr = &a_info[o_ptr->name1];
3998 /* Hack -- Mark the artifact as "created" */
4001 /* Hack -- Memorize location of artifact in saved floors */
4002 if (character_dungeon)
4003 a_ptr->floor_id = p_ptr->floor_id;
4005 /* Extract the other fields */
4006 o_ptr->pval = a_ptr->pval;
4007 o_ptr->ac = a_ptr->ac;
4008 o_ptr->dd = a_ptr->dd;
4009 o_ptr->ds = a_ptr->ds;
4010 o_ptr->to_a = a_ptr->to_a;
4011 o_ptr->to_h = a_ptr->to_h;
4012 o_ptr->to_d = a_ptr->to_d;
4013 o_ptr->weight = a_ptr->weight;
4014 o_ptr->xtra2 = a_ptr->act_idx;
4016 if (o_ptr->name1 == ART_MILIM)
4018 if(p_ptr->pseikaku == SEIKAKU_SEXY)
4024 /* Hack -- extract the "broken" flag */
4025 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4027 /* Hack -- extract the "cursed" flag */
4028 if (a_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4029 if (a_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4030 if (a_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4031 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4032 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4033 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4038 switch (o_ptr->tval)
4047 if (power) apply_magic_weapon(o_ptr, lev, power);
4053 if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) apply_magic_weapon(o_ptr, lev, power);
4059 if (power && !(o_ptr->sval == SV_DOKUBARI)) apply_magic_weapon(o_ptr, lev, power);
4073 /* Elven Cloak and Black Clothes ... */
4074 if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) ||
4075 ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
4076 o_ptr->pval = randint1(4);
4080 ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) ||
4081 ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD)) ||
4082 ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)) ||
4083 ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
4084 a_m_aux_2(o_ptr, lev, power);
4086 if (power) a_m_aux_2(o_ptr, lev, power);
4094 if (!power && (randint0(100) < 50)) power = -1;
4095 a_m_aux_3(o_ptr, lev, power);
4101 a_m_aux_4(o_ptr, lev, power);
4106 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
4107 (o_ptr->sval == SV_ABUNAI_MIZUGI) &&
4108 (p_ptr->pseikaku == SEIKAKU_SEXY))
4111 add_flag(o_ptr->art_flags, TR_STR);
4112 add_flag(o_ptr->art_flags, TR_INT);
4113 add_flag(o_ptr->art_flags, TR_WIS);
4114 add_flag(o_ptr->art_flags, TR_DEX);
4115 add_flag(o_ptr->art_flags, TR_CON);
4116 add_flag(o_ptr->art_flags, TR_CHR);
4119 /* Hack -- analyze ego-items */
4120 if (object_is_ego(o_ptr))
4122 ego_item_type *e_ptr = &e_info[o_ptr->name2];
4124 /* Hack -- acquire "broken" flag */
4125 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4127 /* Hack -- acquire "cursed" flag */
4128 if (e_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4129 if (e_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4130 if (e_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4131 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4132 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4133 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4135 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN)) one_sustain(o_ptr);
4136 if (e_ptr->gen_flags & (TRG_XTRA_POWER)) one_ability(o_ptr);
4137 if (e_ptr->gen_flags & (TRG_XTRA_H_RES)) one_high_resistance(o_ptr);
4138 if (e_ptr->gen_flags & (TRG_XTRA_E_RES)) one_ele_resistance(o_ptr);
4139 if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
4140 if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
4141 if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
4142 if (e_ptr->gen_flags & (TRG_XTRA_DICE))
4148 while (one_in_(o_ptr->dd));
4150 if (o_ptr->dd > 9) o_ptr->dd = 9;
4153 /* Hack -- apply activatin index if needed */
4154 if (e_ptr->act_idx) o_ptr->xtra2 = (XTRA8)e_ptr->act_idx;
4156 /* Hack -- apply extra penalties if needed */
4157 if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL)))
4159 /* Hack -- obtain bonuses */
4160 if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
4161 if (e_ptr->max_to_d) o_ptr->to_d -= randint1(e_ptr->max_to_d);
4162 if (e_ptr->max_to_a) o_ptr->to_a -= randint1(e_ptr->max_to_a);
4164 /* Hack -- obtain pval */
4165 if (e_ptr->max_pval) o_ptr->pval -= randint1(e_ptr->max_pval);
4168 /* Hack -- apply extra bonuses if needed */
4171 /* Hack -- obtain bonuses */
4172 if (e_ptr->max_to_h)
4174 if (e_ptr->max_to_h > 127)
4175 o_ptr->to_h -= randint1(256-e_ptr->max_to_h);
4176 else o_ptr->to_h += randint1(e_ptr->max_to_h);
4178 if (e_ptr->max_to_d)
4180 if (e_ptr->max_to_d > 127)
4181 o_ptr->to_d -= randint1(256-e_ptr->max_to_d);
4182 else o_ptr->to_d += randint1(e_ptr->max_to_d);
4184 if (e_ptr->max_to_a)
4186 if (e_ptr->max_to_a > 127)
4187 o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
4188 else o_ptr->to_a += randint1(e_ptr->max_to_a);
4191 /* Accuracy ego must have high to_h */
4192 if(o_ptr->name2 == EGO_ACCURACY)
4194 while(o_ptr->to_h < o_ptr->to_d + 10)
4199 o_ptr->to_h = MAX(o_ptr->to_h, 15);
4202 /* Accuracy ego must have high to_h */
4203 if(o_ptr->name2 == EGO_VELOCITY)
4205 while(o_ptr->to_d < o_ptr->to_h + 10)
4210 o_ptr->to_d = MAX(o_ptr->to_d, 15);
4213 /* Protection ego must have high to_a */
4214 if((o_ptr->name2 == EGO_PROTECTION) || (o_ptr->name2 == EGO_S_PROTECTION) || (o_ptr->name2 == EGO_H_PROTECTION))
4216 o_ptr->to_a = MAX(o_ptr->to_a, 15);
4219 /* Hack -- obtain pval */
4220 if (e_ptr->max_pval)
4222 if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS)))
4225 if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
4227 else if (o_ptr->name2 == EGO_DEMON)
4229 if(have_flag(o_ptr->art_flags, TR_BLOWS))
4231 o_ptr->pval += randint1(2);
4235 o_ptr->pval += randint1(e_ptr->max_pval);
4238 else if (o_ptr->name2 == EGO_ATTACKS)
4240 o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
4241 if (o_ptr->pval > 3) o_ptr->pval = 3;
4242 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
4243 o_ptr->pval += randint1(2);
4245 else if (o_ptr->name2 == EGO_BAT)
4247 o_ptr->pval = randint1(e_ptr->max_pval);
4248 if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
4250 else if (o_ptr->name2 == EGO_A_DEMON || o_ptr->name2 == EGO_DRUID || o_ptr->name2 == EGO_OLOG)
4252 o_ptr->pval = randint1(e_ptr->max_pval);
4256 o_ptr->pval += randint1(e_ptr->max_pval);
4261 if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
4263 o_ptr->pval = randint1(o_ptr->pval);
4265 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
4272 /* Examine real objects */
4275 object_kind *k_ptr = &k_info[o_ptr->k_idx];
4277 /* Hack -- acquire "broken" flag */
4278 if (!k_info[o_ptr->k_idx].cost) o_ptr->ident |= (IDENT_BROKEN);
4280 /* Hack -- acquire "cursed" flag */
4281 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
4282 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
4283 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
4284 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4285 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4286 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4294 * @brief 生成階に応じたベースアイテムの生成を行う。
4295 * Attempt to make an object (normal or good/great)
4296 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4297 * @param mode オプションフラグ
4298 * @return 生成に成功したらTRUEを返す。
4300 * This routine plays nasty games to generate the "special artifacts".\n
4301 * This routine uses "current_floor_ptr->object_level" for the "generation level".\n
4302 * We assume that the given object has been "wiped".\n
4304 bool make_object(object_type *j_ptr, BIT_FLAGS mode)
4310 /* Chance of "special object" */
4311 prob = ((mode & AM_GOOD) ? 10 : 1000);
4313 /* Base level for the object */
4314 base = ((mode & AM_GOOD) ? (current_floor_ptr->object_level + 10) : current_floor_ptr->object_level);
4317 /* Generate a special object, or a normal object */
4318 if (!one_in_(prob) || !make_artifact_special(j_ptr))
4320 KIND_OBJECT_IDX k_idx;
4323 if ((mode & AM_GOOD) && !get_obj_num_hook)
4325 /* Activate restriction (if already specified, use that) */
4326 get_obj_num_hook = kind_is_good;
4329 /* Restricted objects - prepare allocation table */
4330 if (get_obj_num_hook) get_obj_num_prep();
4332 /* Pick a random object */
4333 k_idx = get_obj_num(base, mode);
4335 /* Restricted objects */
4336 if (get_obj_num_hook)
4338 /* Clear restriction */
4339 get_obj_num_hook = NULL;
4341 /* Reset allocation table to default */
4345 /* Handle failure */
4346 if (!k_idx) return (FALSE);
4348 /* Prepare the object */
4349 object_prep(j_ptr, k_idx);
4352 /* Apply magic (allow artifacts) */
4353 apply_magic(j_ptr, current_floor_ptr->object_level, mode);
4355 /* Hack -- generate multiple spikes/missiles */
4356 switch (j_ptr->tval)
4364 j_ptr->number = (byte)damroll(6, 7);
4368 if (cheat_peek) object_mention(j_ptr);
4376 * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
4377 * Attempt to place an object (normal or good/great) at the given location.
4378 * @param y 配置したいフロアのY座標
4379 * @param x 配置したいフロアのX座標
4380 * @param mode オプションフラグ
4381 * @return 生成に成功したらTRUEを返す。
4383 * This routine plays nasty games to generate the "special artifacts".\n
4384 * This routine uses "current_floor_ptr->object_level" for the "generation level".\n
4385 * This routine requires a clean floor grid destination.\n
4387 void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
4392 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
4398 /* Paranoia -- check bounds */
4399 if (!in_bounds(y, x)) return;
4401 /* Require floor space */
4402 if (!cave_drop_bold(y, x)) return;
4404 /* Avoid stacking on other objects */
4405 if (g_ptr->o_idx) return;
4410 /* Make an object (if possible) */
4411 if (!make_object(q_ptr, mode)) return;
4419 o_ptr = ¤t_floor_ptr->o_list[o_idx];
4421 /* Structure Copy */
4422 object_copy(o_ptr, q_ptr);
4428 o_ptr->next_o_idx = g_ptr->o_idx;
4430 g_ptr->o_idx = o_idx;
4436 /* Hack -- Preserve artifacts */
4437 if (object_is_fixed_artifact(q_ptr))
4439 a_info[q_ptr->name1].cur_num = 0;
4446 * @brief 生成階に応じた財宝オブジェクトの生成を行う。
4447 * Make a treasure object
4448 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4449 * @return 生成に成功したらTRUEを返す。
4451 * The location must be a legal, clean, floor grid.
4453 bool make_gold(object_type *j_ptr)
4458 /* Hack -- Pick a Treasure variety */
4459 i = ((randint1(current_floor_ptr->object_level + 2) + 2) / 2) - 1;
4461 /* Apply "extra" magic */
4462 if (one_in_(GREAT_OBJ))
4464 i += randint1(current_floor_ptr->object_level + 1);
4467 /* Hack -- Creeping Coins only generate "themselves" */
4468 if (coin_type) i = coin_type;
4470 /* Do not create "illegal" Treasure Types */
4471 if (i >= MAX_GOLD) i = MAX_GOLD - 1;
4473 /* Prepare a gold object */
4474 object_prep(j_ptr, OBJ_GOLD_LIST + i);
4476 /* Hack -- Base coin cost */
4477 base = k_info[OBJ_GOLD_LIST + i].cost;
4479 /* Determine how much the treasure is "worth" */
4480 j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
4488 * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
4489 * Places a treasure (Gold or Gems) at given location
4490 * @param y 配置したいフロアのY座標
4491 * @param x 配置したいフロアのX座標
4492 * @return 生成に成功したらTRUEを返す。
4494 * The location must be a legal, clean, floor grid.
4496 void place_gold(POSITION y, POSITION x)
4501 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
4507 /* Paranoia -- check bounds */
4508 if (!in_bounds(y, x)) return;
4510 /* Require floor space */
4511 if (!cave_drop_bold(y, x)) return;
4513 /* Avoid stacking on other objects */
4514 if (g_ptr->o_idx) return;
4519 /* Make some gold */
4520 if (!make_gold(q_ptr)) return;
4528 o_ptr = ¤t_floor_ptr->o_list[o_idx];
4529 object_copy(o_ptr, q_ptr);
4536 o_ptr->next_o_idx = g_ptr->o_idx;
4538 g_ptr->o_idx = o_idx;
4546 * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
4547 * Let an object fall to the ground at or near a location.
4548 * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
4549 * @param chance ドロップの消滅率(%)
4550 * @param y 配置したいフロアのY座標
4551 * @param x 配置したいフロアのX座標
4552 * @return 生成に成功したらオブジェクトのIDを返す。
4554 * The initial location is assumed to be "in_bounds()".\n
4556 * This function takes a parameter "chance". This is the percentage\n
4557 * chance that the item will "disappear" instead of drop. If the object\n
4558 * has been thrown, then this is the chance of disappearance on contact.\n
4560 * Hack -- this function uses "chance" to determine if it should produce\n
4561 * some form of "description" of the drop event (under the player).\n
4563 * We check several locations to see if we can find a location at which\n
4564 * the object can combine, stack, or be placed. Artifacts will try very\n
4565 * hard to be placed, including "teleporting" to a useful grid if needed.\n
4567 OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
4574 POSITION ty, tx = 0;
4576 OBJECT_IDX o_idx = 0;
4577 OBJECT_IDX this_o_idx, next_o_idx = 0;
4581 GAME_TEXT o_name[MAX_NLEN];
4587 /* Extract plural */
4588 bool plural = (j_ptr->number != 1);
4591 /* Describe object */
4592 object_desc(o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4595 /* Handle normal "breakage" */
4596 if (!object_is_artifact(j_ptr) && (randint0(100) < chance))
4599 msg_format("%sは消えた。", o_name);
4601 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4603 if (p_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
4620 /* Scan local grids */
4621 for (dy = -3; dy <= 3; dy++)
4623 /* Scan local grids */
4624 for (dx = -3; dx <= 3; dx++)
4628 /* Calculate actual distance */
4629 d = (dy * dy) + (dx * dx);
4631 /* Ignore distant grids */
4632 if (d > 10) continue;
4637 /* Skip illegal grids */
4638 if (!in_bounds(ty, tx)) continue;
4640 /* Require line of projection */
4641 if (!projectable(y, x, ty, tx)) continue;
4644 g_ptr = ¤t_floor_ptr->grid_array[ty][tx];
4646 /* Require floor space */
4647 if (!cave_drop_bold(ty, tx)) continue;
4652 /* Scan objects in that grid */
4653 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4656 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
4657 next_o_idx = o_ptr->next_o_idx;
4659 /* Check for possible combination */
4660 if (object_similar(o_ptr, j_ptr)) comb = TRUE;
4666 /* Add new object */
4668 if (k > 99) continue;
4670 /* Calculate score */
4671 s = 1000 - (d + k * 5);
4673 /* Skip bad values */
4674 if (s < bs) continue;
4676 /* New best value */
4679 /* Apply the randomizer to equivalent values */
4680 if ((++bn >= 2) && !one_in_(bn)) continue;
4694 /* Handle lack of space */
4695 if (!flag && !object_is_artifact(j_ptr))
4698 msg_format("%sは消えた。", o_name);
4700 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4703 if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4711 for (i = 0; !flag && (i < 1000); i++)
4714 ty = rand_spread(by, 1);
4715 tx = rand_spread(bx, 1);
4717 if (!in_bounds(ty, tx)) continue;
4719 /* Bounce to that location */
4723 /* Require floor space */
4724 if (!cave_drop_bold(by, bx)) continue;
4732 int candidates = 0, pick;
4734 for (ty = 1; ty < current_floor_ptr->height - 1; ty++)
4736 for (tx = 1; tx < current_floor_ptr->width - 1; tx++)
4738 /* A valid space found */
4739 if (cave_drop_bold(ty, tx)) candidates++;
4743 /* No valid place! */
4747 msg_format("%sは消えた。", o_name);
4749 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4752 if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4754 /* Mega-Hack -- preserve artifacts */
4757 /* Hack -- Preserve unknown artifacts */
4758 if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr))
4760 /* Mega-Hack -- Preserve the artifact */
4761 a_info[j_ptr->name1].cur_num = 0;
4769 /* Choose a random one */
4770 pick = randint1(candidates);
4772 for (ty = 1; ty < current_floor_ptr->height - 1; ty++)
4774 for (tx = 1; tx < current_floor_ptr->width - 1; tx++)
4776 if (cave_drop_bold(ty, tx))
4780 /* Is this a picked one? */
4793 g_ptr = ¤t_floor_ptr->grid_array[by][bx];
4795 /* Scan objects in that grid for combination */
4796 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4799 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
4800 next_o_idx = o_ptr->next_o_idx;
4802 /* Check for combination */
4803 if (object_similar(o_ptr, j_ptr))
4805 object_absorb(o_ptr, j_ptr);
4814 if (!done) o_idx = o_pop();
4817 if (!done && !o_idx)
4820 msg_format("%sは消えた。", o_name);
4822 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4825 if (p_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
4827 /* Hack -- Preserve artifacts */
4828 if (object_is_fixed_artifact(j_ptr))
4830 a_info[j_ptr->name1].cur_num = 0;
4840 /* Structure copy */
4841 object_copy(¤t_floor_ptr->o_list[o_idx], j_ptr);
4843 /* Access new object */
4844 j_ptr = ¤t_floor_ptr->o_list[o_idx];
4851 j_ptr->held_m_idx = 0;
4854 j_ptr->next_o_idx = g_ptr->o_idx;
4856 g_ptr->o_idx = o_idx;
4866 /* Mega-Hack -- no message if "dropped" by player */
4867 /* Message when an object falls under the player */
4868 if (chance && player_bold(by, bx))
4870 msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
4877 * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
4878 * Describe the charges on an item in the p_ptr->inventory_list.
4879 * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4882 void inven_item_charges(INVENTORY_IDX item)
4884 object_type *o_ptr = &p_ptr->inventory_list[item];
4886 /* Require staff/wand */
4887 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
4889 /* Require known item */
4890 if (!object_is_known(o_ptr)) return;
4893 if (o_ptr->pval <= 0)
4895 msg_print("もう魔力が残っていない。");
4899 msg_format("あと %d 回分の魔力が残っている。", o_ptr->pval);
4902 /* Multiple charges */
4903 if (o_ptr->pval != 1)
4905 msg_format("You have %d charges remaining.", o_ptr->pval);
4911 msg_format("You have %d charge remaining.", o_ptr->pval);
4918 * @brief アイテムの残り所持数メッセージを表示する /
4919 * Describe an item in the p_ptr->inventory_list.
4920 * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4923 void inven_item_describe(INVENTORY_IDX item)
4925 object_type *o_ptr = &p_ptr->inventory_list[item];
4926 GAME_TEXT o_name[MAX_NLEN];
4928 object_desc(o_name, o_ptr, 0);
4931 /* "no more" の場合はこちらで表示する */
4932 if (o_ptr->number <= 0)
4934 /*FIRST*//*ここはもう通らないかも */
4935 msg_format("もう%sを持っていない。", o_name);
4939 /* アイテム名を英日切り替え機能対応 */
4940 msg_format("まだ %sを持っている。", o_name);
4943 msg_format("You have %s.", o_name);
4949 * @brief アイテムを増減させ残り所持数メッセージを表示する /
4950 * Increase the "number" of an item in the p_ptr->inventory_list
4951 * @param item 所持数を増やしたいプレイヤーのアイテム所持スロット
4955 void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
4957 object_type *o_ptr = &p_ptr->inventory_list[item];
4960 num += o_ptr->number;
4963 if (num > 255) num = 255;
4964 else if (num < 0) num = 0;
4967 num -= o_ptr->number;
4969 /* Change the number and weight */
4972 /* Add the number */
4973 o_ptr->number += num;
4975 /* Add the weight */
4976 p_ptr->total_weight += (num * o_ptr->weight);
4977 p_ptr->update |= (PU_BONUS);
4978 p_ptr->update |= (PU_MANA);
4979 p_ptr->update |= (PU_COMBINE);
4980 p_ptr->window |= (PW_INVEN | PW_EQUIP);
4982 /* Hack -- Clear temporary elemental brands if player takes off weapons */
4983 if (!o_ptr->number && p_ptr->ele_attack)
4985 if ((item == INVEN_RARM) || (item == INVEN_LARM))
4987 if (!has_melee_weapon(INVEN_RARM + INVEN_LARM - item))
4989 /* Clear all temporary elemental brands */
4990 set_ele_attack(0, 0);
4998 * @brief 所持アイテムスロットから所持数のなくなったアイテムを消去する /
4999 * Erase an p_ptr->inventory_list slot if it has no more items
5000 * @param item 消去したいプレイヤーのアイテム所持スロット
5003 void inven_item_optimize(INVENTORY_IDX item)
5005 object_type *o_ptr = &p_ptr->inventory_list[item];
5007 /* Only optimize real items */
5008 if (!o_ptr->k_idx) return;
5010 /* Only optimize empty items */
5011 if (o_ptr->number) return;
5013 /* The item is in the pack */
5014 if (item < INVEN_RARM)
5021 /* Slide everything down */
5022 for (i = item; i < INVEN_PACK; i++)
5024 /* Structure copy */
5025 p_ptr->inventory_list[i] = p_ptr->inventory_list[i+1];
5028 /* Erase the "final" slot */
5029 object_wipe(&p_ptr->inventory_list[i]);
5031 p_ptr->window |= (PW_INVEN);
5034 /* The item is being wielded */
5040 /* Erase the empty slot */
5041 object_wipe(&p_ptr->inventory_list[item]);
5042 p_ptr->update |= (PU_BONUS);
5043 p_ptr->update |= (PU_TORCH);
5044 p_ptr->update |= (PU_MANA);
5046 p_ptr->window |= (PW_EQUIP);
5049 p_ptr->window |= (PW_SPELL);
5053 * @brief 床上の魔道具の残り残量メッセージを表示する /
5054 * Describe the charges on an item on the floor.
5055 * @param item メッセージの対象にしたいアイテム所持スロット
5058 void floor_item_charges(INVENTORY_IDX item)
5060 object_type *o_ptr = ¤t_floor_ptr->o_list[item];
5062 /* Require staff/wand */
5063 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5065 /* Require known item */
5066 if (!object_is_known(o_ptr)) return;
5069 if (o_ptr->pval <= 0)
5071 msg_print("この床上のアイテムは、もう魔力が残っていない。");
5075 msg_format("この床上のアイテムは、あと %d 回分の魔力が残っている。", o_ptr->pval);
5078 /* Multiple charges */
5079 if (o_ptr->pval != 1)
5081 msg_format("There are %d charges remaining.", o_ptr->pval);
5087 msg_format("There is %d charge remaining.", o_ptr->pval);
5094 * @brief 床上のアイテムの残り数メッセージを表示する /
5095 * Describe the charges on an item on the floor.
5096 * @param item メッセージの対象にしたいアイテム所持スロット
5099 void floor_item_describe(INVENTORY_IDX item)
5101 object_type *o_ptr = ¤t_floor_ptr->o_list[item];
5102 GAME_TEXT o_name[MAX_NLEN];
5104 object_desc(o_name, o_ptr, 0);
5107 /* "no more" の場合はこちらで表示を分ける */
5108 if (o_ptr->number <= 0)
5110 msg_format("床上には、もう%sはない。", o_name);
5114 msg_format("床上には、まだ %sがある。", o_name);
5117 msg_format("You see %s.", o_name);
5124 * @brief 床上のアイテムの数を増やす /
5125 * Increase the "number" of an item on the floor
5126 * @param item 増やしたいアイテムの所持スロット
5127 * @param num 増やしたいアイテムの数
5130 void floor_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
5132 object_type *o_ptr = ¤t_floor_ptr->o_list[item];
5135 num += o_ptr->number;
5138 if (num > 255) num = 255;
5139 else if (num < 0) num = 0;
5142 num -= o_ptr->number;
5144 /* Change the number */
5145 o_ptr->number += num;
5150 * @brief 床上の数の無くなったアイテムスロットを消去する /
5151 * Optimize an item on the floor (destroy "empty" items)
5152 * @param item 消去したいアイテムの所持スロット
5155 void floor_item_optimize(INVENTORY_IDX item)
5157 object_type *o_ptr = ¤t_floor_ptr->o_list[item];
5159 /* Paranoia -- be sure it exists */
5160 if (!o_ptr->k_idx) return;
5162 /* Only optimize empty items */
5163 if (o_ptr->number) return;
5165 delete_object_idx(item);
5170 * @brief アイテムを拾う際にザックから溢れずに済むかを判定する /
5171 * Check if we have space for an item in the pack without overflow
5172 * @param o_ptr 拾いたいオブジェクトの構造体参照ポインタ
5173 * @return 溢れずに済むならTRUEを返す
5175 bool inven_carry_okay(object_type *o_ptr)
5180 if (p_ptr->inven_cnt < INVEN_PACK) return (TRUE);
5183 for (j = 0; j < INVEN_PACK; j++)
5185 object_type *j_ptr = &p_ptr->inventory_list[j];
5186 if (!j_ptr->k_idx) continue;
5188 /* Check if the two items can be combined */
5189 if (object_similar(j_ptr, o_ptr)) return (TRUE);
5196 * @brief オブジェクトを定義された基準に従いソートするための関数 /
5197 * Check if we have space for an item in the pack without overflow
5198 * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
5199 * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
5200 * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
5201 * @return o_ptrの方が上位ならばTRUEを返す。
5203 bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
5207 /* Use empty slots */
5208 if (!j_ptr->k_idx) return TRUE;
5210 /* Hack -- readable books always come first */
5211 if ((o_ptr->tval == REALM1_BOOK) &&
5212 (j_ptr->tval != REALM1_BOOK)) return TRUE;
5213 if ((j_ptr->tval == REALM1_BOOK) &&
5214 (o_ptr->tval != REALM1_BOOK)) return FALSE;
5216 if ((o_ptr->tval == REALM2_BOOK) &&
5217 (j_ptr->tval != REALM2_BOOK)) return TRUE;
5218 if ((j_ptr->tval == REALM2_BOOK) &&
5219 (o_ptr->tval != REALM2_BOOK)) return FALSE;
5221 /* Objects sort by decreasing type */
5222 if (o_ptr->tval > j_ptr->tval) return TRUE;
5223 if (o_ptr->tval < j_ptr->tval) return FALSE;
5225 /* Non-aware (flavored) items always come last */
5226 /* Can happen in the home */
5227 if (!object_is_aware(o_ptr)) return FALSE;
5228 if (!object_is_aware(j_ptr)) return TRUE;
5230 /* Objects sort by increasing sval */
5231 if (o_ptr->sval < j_ptr->sval) return TRUE;
5232 if (o_ptr->sval > j_ptr->sval) return FALSE;
5234 /* Unidentified objects always come last */
5235 /* Objects in the home can be unknown */
5236 if (!object_is_known(o_ptr)) return FALSE;
5237 if (!object_is_known(j_ptr)) return TRUE;
5239 /* Fixed artifacts, random artifacts and ego items */
5240 if (object_is_fixed_artifact(o_ptr)) o_type = 3;
5241 else if (o_ptr->art_name) o_type = 2;
5242 else if (object_is_ego(o_ptr)) o_type = 1;
5245 if (object_is_fixed_artifact(j_ptr)) j_type = 3;
5246 else if (j_ptr->art_name) j_type = 2;
5247 else if (object_is_ego(j_ptr)) j_type = 1;
5250 if (o_type < j_type) return TRUE;
5251 if (o_type > j_type) return FALSE;
5253 switch (o_ptr->tval)
5259 if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
5260 if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
5266 /* Objects sort by increasing hit/damage bonuses */
5267 if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
5268 if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
5271 /* Hack: otherwise identical rods sort by
5272 increasing recharge time --dsb */
5274 if (o_ptr->pval < j_ptr->pval) return TRUE;
5275 if (o_ptr->pval > j_ptr->pval) return FALSE;
5279 /* Objects sort by decreasing value */
5280 return o_value > object_value(j_ptr);
5285 * @brief オブジェクトをプレイヤーが拾って所持スロットに納めるメインルーチン /
5286 * Add an item to the players p_ptr->inventory_list, and return the slot used.
5287 * @param o_ptr 拾うオブジェクトの構造体参照ポインタ
5288 * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5290 * If the new item can combine with an existing item in the p_ptr->inventory_list,\n
5291 * it will do so, using "object_similar()" and "object_absorb()", else,\n
5292 * the item will be placed into the "proper" location in the p_ptr->inventory_list.\n
5294 * This function can be used to "over-fill" the player's pack, but only\n
5295 * once, and such an action must trigger the "overflow" code immediately.\n
5296 * Note that when the pack is being "over-filled", the new item must be\n
5297 * placed into the "overflow" slot, and the "overflow" must take place\n
5298 * before the pack is reordered, but (optionally) after the pack is\n
5299 * combined. This may be tricky. See "dungeon.c" for info.\n
5301 * Note that this code must remove any location/stack information\n
5302 * from the object once it is placed into the p_ptr->inventory_list.\n
5304 s16b inven_carry(object_type *o_ptr)
5306 INVENTORY_IDX i, j, k;
5307 INVENTORY_IDX n = -1;
5312 /* Check for combining */
5313 for (j = 0; j < INVEN_PACK; j++)
5315 j_ptr = &p_ptr->inventory_list[j];
5316 if (!j_ptr->k_idx) continue;
5318 /* Hack -- track last item */
5321 /* Check if the two items can be combined */
5322 if (object_similar(j_ptr, o_ptr))
5324 object_absorb(j_ptr, o_ptr);
5326 p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
5327 p_ptr->update |= (PU_BONUS);
5328 p_ptr->window |= (PW_INVEN);
5335 if (p_ptr->inven_cnt > INVEN_PACK) return (-1);
5337 /* Find an empty slot */
5338 for (j = 0; j <= INVEN_PACK; j++)
5340 j_ptr = &p_ptr->inventory_list[j];
5342 /* Use it if found */
5343 if (!j_ptr->k_idx) break;
5350 /* Reorder the pack */
5353 /* Get the "value" of the item */
5354 s32b o_value = object_value(o_ptr);
5356 /* Scan every occupied slot */
5357 for (j = 0; j < INVEN_PACK; j++)
5359 if (object_sort_comp(o_ptr, o_value, &p_ptr->inventory_list[j])) break;
5366 for (k = n; k >= i; k--)
5368 /* Hack -- Slide the item */
5369 object_copy(&p_ptr->inventory_list[k+1], &p_ptr->inventory_list[k]);
5372 /* Wipe the empty slot */
5373 object_wipe(&p_ptr->inventory_list[i]);
5378 object_copy(&p_ptr->inventory_list[i], o_ptr);
5380 /* Access new object */
5381 j_ptr = &p_ptr->inventory_list[i];
5384 j_ptr->next_o_idx = 0;
5386 /* Forget monster */
5387 j_ptr->held_m_idx = 0;
5389 /* Forget location */
5390 j_ptr->iy = j_ptr->ix = 0;
5392 /* Player touches it, and no longer marked */
5393 j_ptr->marked = OM_TOUCHED;
5395 p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
5397 /* Count the items */
5399 p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
5400 p_ptr->window |= (PW_INVEN);
5402 /* Return the slot */
5408 * @brief 装備スロットからオブジェクトを外すメインルーチン /
5409 * Take off (some of) a non-cursed equipment item
5410 * @param item オブジェクトを外したい所持テーブルのID
5412 * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5414 * Note that only one item at a time can be wielded per slot.\n
5415 * Note that taking off an item when "full" may cause that item\n
5416 * to fall to the ground.\n
5417 * Return the p_ptr->inventory_list slot into which the item is placed.\n
5419 INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
5430 GAME_TEXT o_name[MAX_NLEN];
5433 /* Get the item to take off */
5434 o_ptr = &p_ptr->inventory_list[item];
5435 if (amt <= 0) return (-1);
5438 if (amt > o_ptr->number) amt = o_ptr->number;
5441 /* Obtain a local object */
5442 object_copy(q_ptr, o_ptr);
5444 /* Modify quantity */
5445 q_ptr->number = amt;
5447 object_desc(o_name, q_ptr, 0);
5449 /* Took off weapon */
5450 if (((item == INVEN_RARM) || (item == INVEN_LARM)) &&
5451 object_is_melee_weapon(o_ptr))
5453 act = _("を装備からはずした", "You were wielding");
5457 else if (item == INVEN_BOW)
5459 act = _("を装備からはずした", "You were holding");
5462 /* Took off light */
5463 else if (item == INVEN_LITE)
5465 act = _("を光源からはずした", "You were holding");
5468 /* Took off something */
5471 act = _("を装備からはずした", "You were wearing");
5474 /* Modify, Optimize */
5475 inven_item_increase(item, -amt);
5476 inven_item_optimize(item);
5478 /* Carry the object */
5479 slot = inven_carry(q_ptr);
5482 msg_format("%s(%c)%s。", o_name, index_to_label(slot), act);
5484 msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
5494 * @brief 所持スロットから床下にオブジェクトを落とすメインルーチン /
5495 * Drop (some of) a non-cursed p_ptr->inventory_list/equipment item
5496 * @param item 所持テーブルのID
5497 * @param amt 落としたい個数
5500 * The object will be dropped "near" the current location
5502 void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
5508 GAME_TEXT o_name[MAX_NLEN];
5510 /* Access original object */
5511 o_ptr = &p_ptr->inventory_list[item];
5514 if (amt <= 0) return;
5517 if (amt > o_ptr->number) amt = o_ptr->number;
5519 /* Take off equipment */
5520 if (item >= INVEN_RARM)
5522 /* Take off first */
5523 item = inven_takeoff(item, amt);
5525 /* Access original object */
5526 o_ptr = &p_ptr->inventory_list[item];
5531 /* Obtain local object */
5532 object_copy(q_ptr, o_ptr);
5534 /* Distribute charges of wands or rods */
5535 distribute_charges(o_ptr, q_ptr, amt);
5537 /* Modify quantity */
5538 q_ptr->number = amt;
5540 /* Describe local object */
5541 object_desc(o_name, q_ptr, 0);
5543 msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(item));
5545 /* Drop it near the player */
5546 (void)drop_near(q_ptr, 0, p_ptr->y, p_ptr->x);
5548 /* Modify, Describe, Optimize */
5549 inven_item_increase(item, -amt);
5550 inven_item_describe(item);
5551 inven_item_optimize(item);
5556 * @brief プレイヤーの所持スロットに存在するオブジェクトをまとめなおす /
5557 * Combine items in the pack
5560 * Note special handling of the "overflow" slot
5562 void combine_pack(void)
5567 bool flag = FALSE, combined;
5573 /* Combine the pack (backwards) */
5574 for (i = INVEN_PACK; i > 0; i--)
5576 o_ptr = &p_ptr->inventory_list[i];
5578 /* Skip empty items */
5579 if (!o_ptr->k_idx) continue;
5581 /* Scan the items above that item */
5582 for (j = 0; j < i; j++)
5586 j_ptr = &p_ptr->inventory_list[j];
5588 /* Skip empty items */
5589 if (!j_ptr->k_idx) continue;
5592 * Get maximum number of the stack if these
5593 * are similar, get zero otherwise.
5595 max_num = object_similar_part(j_ptr, o_ptr);
5597 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
5598 if (max_num && j_ptr->number < max_num)
5600 if (o_ptr->number + j_ptr->number <= max_num)
5605 /* Add together the item counts */
5606 object_absorb(j_ptr, o_ptr);
5608 /* One object is gone */
5611 /* Slide everything down */
5612 for (k = i; k < INVEN_PACK; k++)
5614 /* Structure copy */
5615 p_ptr->inventory_list[k] = p_ptr->inventory_list[k+1];
5618 /* Erase the "final" slot */
5619 object_wipe(&p_ptr->inventory_list[k]);
5623 int old_num = o_ptr->number;
5624 int remain = j_ptr->number + o_ptr->number - max_num;
5626 o_ptr->number -= remain;
5628 /* Add together the item counts */
5629 object_absorb(j_ptr, o_ptr);
5631 o_ptr->number = remain;
5633 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
5634 if (o_ptr->tval == TV_ROD)
5636 o_ptr->pval = o_ptr->pval * remain / old_num;
5637 o_ptr->timeout = o_ptr->timeout * remain / old_num;
5640 /* Hack -- if wands are stacking, combine the charges. -LM- */
5641 if (o_ptr->tval == TV_WAND)
5643 o_ptr->pval = o_ptr->pval * remain / old_num;
5647 p_ptr->window |= (PW_INVEN);
5659 if (flag) msg_print(_("ザックの中のアイテムをまとめ直した。", "You combine some items in your pack."));
5663 * @brief プレイヤーの所持スロットに存在するオブジェクトを並び替える /
5664 * Reorder items in the pack
5667 * Note special handling of the "overflow" slot
5669 void reorder_pack(void)
5679 /* Re-order the pack (forwards) */
5680 for (i = 0; i < INVEN_PACK; i++)
5682 /* Mega-Hack -- allow "proper" over-flow */
5683 if ((i == INVEN_PACK) && (p_ptr->inven_cnt == INVEN_PACK)) break;
5685 o_ptr = &p_ptr->inventory_list[i];
5687 /* Skip empty slots */
5688 if (!o_ptr->k_idx) continue;
5690 /* Get the "value" of the item */
5691 o_value = object_value(o_ptr);
5693 /* Scan every occupied slot */
5694 for (j = 0; j < INVEN_PACK; j++)
5696 if (object_sort_comp(o_ptr, o_value, &p_ptr->inventory_list[j])) break;
5699 /* Never move down */
5700 if (j >= i) continue;
5706 /* Save a copy of the moving item */
5707 object_copy(q_ptr, &p_ptr->inventory_list[i]);
5709 /* Slide the objects */
5710 for (k = i; k > j; k--)
5712 /* Slide the item */
5713 object_copy(&p_ptr->inventory_list[k], &p_ptr->inventory_list[k-1]);
5716 /* Insert the moving item */
5717 object_copy(&p_ptr->inventory_list[j], q_ptr);
5719 p_ptr->window |= (PW_INVEN);
5722 if (flag) msg_print(_("ザックの中のアイテムを並べ直した。", "You reorder some items in your pack."));
5726 * @brief 現在アクティブになっているウィンドウにオブジェクトの詳細を表示する /
5727 * Hack -- display an object kind in the current window
5728 * @param k_idx ベースアイテムの参照ID
5731 * Include list of usable spells for readible books
5733 void display_koff(KIND_OBJECT_IDX k_idx)
5740 REALM_IDX use_realm;
5742 GAME_TEXT o_name[MAX_NLEN];
5745 /* Erase the window */
5746 for (y = 0; y < Term->hgt; y++)
5748 /* Erase the line */
5749 Term_erase(0, y, 255);
5756 /* Prepare the object */
5757 object_prep(q_ptr, k_idx);
5758 object_desc(o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
5760 /* Mention the object name */
5761 Term_putstr(0, 0, -1, TERM_WHITE, o_name);
5763 /* Access the item's sval */
5765 use_realm = tval2realm(q_ptr->tval);
5767 /* Warriors are illiterate */
5768 if (p_ptr->realm1 || p_ptr->realm2)
5770 if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2)) return;
5774 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return;
5775 if (!is_magic(use_realm)) return;
5776 if ((p_ptr->pclass == CLASS_RED_MAGE) && (use_realm != REALM_ARCANE) && (sval > 1)) return;
5779 /* Display spells in readible books */
5783 SPELL_IDX spells[64];
5785 /* Extract spells */
5786 for (spell = 0; spell < 32; spell++)
5788 /* Check for this spell */
5789 if (fake_spell_flags[sval] & (1L << spell))
5791 /* Collect this spell */
5792 spells[num++] = spell;
5797 print_spells(0, spells, num, 2, 0, use_realm);
5803 * @brief 投擲時たいまつに投げやすい/焼棄/アンデッドスレイの特別効果を返す。
5804 * Torches have special abilities when they are flaming.
5805 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5806 * @param flgs 特別に追加するフラグを返す参照ポインタ
5809 void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs)
5811 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5813 if (o_ptr->xtra4 > 0)
5815 add_flag(flgs, TR_BRAND_FIRE);
5816 add_flag(flgs, TR_KILL_UNDEAD);
5817 add_flag(flgs, TR_THROW);
5823 * @brief 投擲時たいまつにダイスを与える。
5824 * Torches have special abilities when they are flaming.
5825 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5826 * @param dd 特別なダイス数を返す参照ポインタ
5827 * @param ds 特別なダイス面数を返す参照ポインタ
5830 void torch_dice(object_type *o_ptr, DICE_NUMBER *dd, DICE_SID *ds)
5832 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5834 if (o_ptr->xtra4 > 0)
5843 * @brief 投擲時命中したたいまつの寿命を縮める。
5844 * Torches have special abilities when they are flaming.
5845 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5848 void torch_lost_fuel(object_type *o_ptr)
5850 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5852 o_ptr->xtra4 -= (FUEL_TORCH / 25);
5853 if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0;
5858 * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す /
5859 * @param o_ptr 判定する射撃武器のアイテム情報参照ポインタ
5860 * @return 対応する矢/弾薬のベースアイテムID
5862 int bow_tval_ammo(object_type *o_ptr)
5864 /* Analyze the launcher */
5865 switch (o_ptr->sval)