3 * @brief オブジェクトの実装 / Object code, part 2
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
8 * This software may be copied and distributed for educational, research,\n
9 * and not for profit purposes provided that this copyright and statement\n
10 * are included in all such copies. Other copyrights may also apply.\n
11 * 2014 Deskull rearranged comment for Doxygen.\n
22 #include "cmd-spell.h"
27 #include "objectkind.h"
28 #include "object-boost.h"
29 #include "object-ego.h"
30 #include "object-flavor.h"
31 #include "object-hook.h"
32 #include "object-curse.h"
33 #include "objectkind-hook.h"
36 #include "player-status.h"
37 #include "player-move.h"
38 #include "player-effects.h"
39 #include "player-class.h"
40 #include "player-personality.h"
42 #include "monsterrace-hook.h"
43 #include "object-ego.h"
44 #include "view-mainwindow.h"
47 * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
48 * @param o_idx 削除対象のオブジェクト構造体ポインタ
51 void excise_object_idx(OBJECT_IDX o_idx)
55 OBJECT_IDX this_o_idx, next_o_idx = 0;
56 OBJECT_IDX prev_o_idx = 0;
59 j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
61 if (OBJECT_IS_HELD_MONSTER(j_ptr))
64 m_ptr = &p_ptr->current_floor_ptr->m_list[j_ptr->held_m_idx];
66 /* Scan all objects in the grid */
67 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
70 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
71 next_o_idx = o_ptr->next_o_idx;
73 if (this_o_idx == o_idx)
78 /* Remove from list */
79 m_ptr->hold_o_idx = next_o_idx;
88 k_ptr = &p_ptr->current_floor_ptr->o_list[prev_o_idx];
90 /* Remove from list */
91 k_ptr->next_o_idx = next_o_idx;
94 /* Forget next pointer */
95 o_ptr->next_o_idx = 0;
100 /* Save prev_o_idx */
101 prev_o_idx = this_o_idx;
110 POSITION y = j_ptr->iy;
111 POSITION x = j_ptr->ix;
113 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
115 /* Scan all objects in the grid */
116 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
119 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
120 next_o_idx = o_ptr->next_o_idx;
122 if (this_o_idx == o_idx)
127 /* Remove from list */
128 g_ptr->o_idx = next_o_idx;
136 /* Previous object */
137 k_ptr = &p_ptr->current_floor_ptr->o_list[prev_o_idx];
139 /* Remove from list */
140 k_ptr->next_o_idx = next_o_idx;
143 /* Forget next pointer */
144 o_ptr->next_o_idx = 0;
149 /* Save prev_o_idx */
150 prev_o_idx = this_o_idx;
156 * @brief オブジェクトを削除する /
157 * Delete a dungeon object
158 * @param o_idx 削除対象のオブジェクト構造体ポインタ
161 * Handle "stacks" of objects correctly.
163 void delete_object_idx(OBJECT_IDX o_idx)
168 excise_object_idx(o_idx);
171 j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
174 if (!OBJECT_IS_HELD_MONSTER(j_ptr))
184 p_ptr->current_floor_ptr->o_cnt--;
189 * @brief フロアにマスに落ちているオブジェクトを全て削除する / Deletes all objects at given location
190 * Delete a dungeon object
191 * @param y 削除したフロアマスのY座標
192 * @param x 削除したフロアマスのX座標
195 void delete_object(POSITION y, POSITION x)
198 OBJECT_IDX this_o_idx, next_o_idx = 0;
200 /* Refuse "illegal" locations */
201 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
203 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
205 /* Scan all objects in the grid */
206 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
209 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
210 next_o_idx = o_ptr->next_o_idx;
214 p_ptr->current_floor_ptr->o_cnt--;
217 /* Objects are gone */
225 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
226 * Move an object from index i1 to index i2 in the object list
227 * @param i1 整理したい配列の始点
228 * @param i2 整理したい配列の終点
231 static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
238 if (i1 == i2) return;
241 for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
243 o_ptr = &p_ptr->current_floor_ptr->o_list[i];
245 /* Skip "dead" objects */
246 if (!o_ptr->k_idx) continue;
248 /* Repair "next" pointers */
249 if (o_ptr->next_o_idx == i1)
252 o_ptr->next_o_idx = i2;
255 o_ptr = &p_ptr->current_floor_ptr->o_list[i1];
257 if (OBJECT_IS_HELD_MONSTER(o_ptr))
260 m_ptr = &p_ptr->current_floor_ptr->m_list[o_ptr->held_m_idx];
263 if (m_ptr->hold_o_idx == i1)
266 m_ptr->hold_o_idx = i2;
275 /* Acquire location */
280 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
283 if (g_ptr->o_idx == i1)
291 p_ptr->current_floor_ptr->o_list[i2] = p_ptr->current_floor_ptr->o_list[i1];
299 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
300 * Compact and Reorder the object list.
301 * @param size 最低でも減らしたいオブジェクト数の水準
305 * This function can be very dangerous, use with caution!\n
307 * When actually "compacting" objects, we base the saving throw on a\n
308 * combination of object level, distance from player, and current\n
311 * After "compacting" (if needed), we "reorder" the objects into a more\n
312 * compact order, and we reset the allocation info, and the "live" array.\n
314 void compact_objects(int size)
319 int cur_lev, cur_dis, chance;
325 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
326 p_ptr->redraw |= (PR_MAP);
327 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
331 /* Compact at least 'size' objects */
332 for (num = 0, cnt = 1; num < size; cnt++)
334 /* Get more vicious each iteration */
337 /* Get closer each iteration */
338 cur_dis = 5 * (20 - cnt);
340 /* Examine the objects */
341 for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
343 o_ptr = &p_ptr->current_floor_ptr->o_list[i];
345 if (!OBJECT_IS_VALID(o_ptr)) continue;
347 /* Hack -- High level objects start out "immune" */
348 if (k_info[o_ptr->k_idx].level > cur_lev) continue;
350 if (OBJECT_IS_HELD_MONSTER(o_ptr))
353 m_ptr = &p_ptr->current_floor_ptr->m_list[o_ptr->held_m_idx];
358 /* Monsters protect their objects */
359 if (randint0(100) < 90) continue;
369 /* Nearby objects start out "immune" */
370 if ((cur_dis > 0) && (distance(p_ptr->y, p_ptr->x, y, x) < cur_dis)) continue;
375 /* Hack -- only compact artifacts in emergencies */
376 if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
377 (cnt < 1000)) chance = 100;
379 /* Apply the saving throw */
380 if (randint0(100) < chance) continue;
382 delete_object_idx(i);
390 /* Excise dead objects (backwards!) */
391 for (i = p_ptr->current_floor_ptr->o_max - 1; i >= 1; i--)
393 o_ptr = &p_ptr->current_floor_ptr->o_list[i];
395 /* Skip real objects */
396 if (o_ptr->k_idx) continue;
398 /* Move last object into open hole */
399 compact_objects_aux(p_ptr->current_floor_ptr->o_max - 1, i);
401 /* Compress "p_ptr->current_floor_ptr->o_max" */
402 p_ptr->current_floor_ptr->o_max--;
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 < p_ptr->current_floor_ptr->o_max; i++)
426 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[i];
428 if (!OBJECT_IS_VALID(o_ptr)) continue;
430 /* Mega-Hack -- preserve artifacts */
431 if (!current_world_ptr->character_dungeon || preserve_mode)
433 /* Hack -- Preserve unknown artifacts */
434 if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
436 /* Mega-Hack -- Preserve the artifact */
437 a_info[o_ptr->name1].cur_num = 0;
441 if (OBJECT_IS_HELD_MONSTER(o_ptr))
444 m_ptr = &p_ptr->current_floor_ptr->m_list[o_ptr->held_m_idx];
446 /* Hack -- see above */
447 m_ptr->hold_o_idx = 0;
455 /* Access location */
456 POSITION y = o_ptr->iy;
457 POSITION x = o_ptr->ix;
460 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
462 /* Hack -- see above */
468 /* Reset "p_ptr->current_floor_ptr->o_max" */
469 p_ptr->current_floor_ptr->o_max = 1;
471 /* Reset "p_ptr->current_floor_ptr->o_cnt" */
472 p_ptr->current_floor_ptr->o_cnt = 0;
477 * @brief グローバルオブジェクト配列から空きを取得する /
478 * Acquires and returns the index of a "free" object.
479 * @return 開いているオブジェクト要素のID
481 * This routine should almost never fail, but in case it does,
482 * we must be sure to handle "failure" of this routine.
484 OBJECT_IDX o_pop(void)
488 /* Initial allocation */
489 if (p_ptr->current_floor_ptr->o_max < current_world_ptr->max_o_idx)
492 i = p_ptr->current_floor_ptr->o_max;
494 /* Expand object array */
495 p_ptr->current_floor_ptr->o_max++;
498 p_ptr->current_floor_ptr->o_cnt++;
500 /* Use this object */
505 /* Recycle dead objects */
506 for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
509 o_ptr = &p_ptr->current_floor_ptr->o_list[i];
511 /* Skip live objects */
512 if (o_ptr->k_idx) continue;
515 p_ptr->current_floor_ptr->o_cnt++;
517 /* Use this object */
522 /* Warn the player (except during dungeon creation) */
523 if (current_world_ptr->character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
529 * Hack -- function hook to restrict "get_obj_num_prep()" function
531 bool(*get_obj_num_hook)(KIND_OBJECT_IDX k_idx);
534 * @brief オブジェクト生成テーブルに生成制約を加える /
535 * Apply a "object restriction function" to the "object allocation table"
537 * @details 生成の制約はグローバルのget_obj_num_hook関数ポインタで加える
539 static errr get_obj_num_prep(void)
544 alloc_entry *table = alloc_kind_table;
546 /* Scan the allocation table */
547 for (i = 0; i < alloc_kind_size; i++)
549 /* Accept objects which pass the restriction, if any */
550 if (!get_obj_num_hook || (*get_obj_num_hook)(table[i].index))
552 /* Accept this object */
553 table[i].prob2 = table[i].prob1;
556 /* Do not use this object */
559 /* Decline this object */
570 * @brief オブジェクト生成テーブルからアイテムを取得する /
571 * Choose an object kind that seems "appropriate" to the given level
573 * @return 選ばれたオブジェクトベースID
575 * This function uses the "prob2" field of the "object allocation table",\n
576 * and various local information, to calculate the "prob3" field of the\n
577 * same table, which is then used to choose an "appropriate" object, in\n
578 * a relatively efficient manner.\n
580 * It is (slightly) more likely to acquire an object of the given level\n
581 * than one of a lower level. This is done by choosing several objects\n
582 * appropriate to the given level and keeping the "hardest" one.\n
584 * Note that if no objects are "appropriate", then this function will\n
585 * fail, and return zero, but this should *almost* never happen.\n
587 OBJECT_IDX get_obj_num(DEPTH level, BIT_FLAGS mode)
590 KIND_OBJECT_IDX k_idx;
593 alloc_entry *table = alloc_kind_table;
595 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
598 if ((level > 0) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
600 /* Occasional "boost" */
601 if (one_in_(GREAT_OBJ))
603 /* What a bizarre calculation */
604 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
611 /* Process probabilities */
612 for (i = 0; i < alloc_kind_size; i++)
614 /* Objects are sorted by depth */
615 if (table[i].level > level) break;
620 k_idx = table[i].index;
622 /* Access the actual kind */
623 k_ptr = &k_info[k_idx];
625 if ((mode & AM_FORBID_CHEST) && (k_ptr->tval == TV_CHEST)) continue;
628 table[i].prob3 = table[i].prob2;
631 total += table[i].prob3;
634 /* No legal objects */
635 if (total <= 0) return (0);
639 value = randint0(total);
641 /* Find the object */
642 for (i = 0; i < alloc_kind_size; i++)
644 /* Found the entry */
645 if (value < table[i].prob3) break;
648 value = value - table[i].prob3;
655 /* Try for a "better" object once (50%) or twice (10%) */
662 value = randint0(total);
664 /* Find the object */
665 for (i = 0; i < alloc_kind_size; i++)
667 /* Found the entry */
668 if (value < table[i].prob3) break;
671 value = value - table[i].prob3;
674 /* Keep the "best" one */
675 if (table[i].level < table[j].level) i = j;
678 /* Try for a "better" object twice (10%) */
685 value = randint0(total);
687 /* Find the object */
688 for (i = 0; i < alloc_kind_size; i++)
690 /* Found the entry */
691 if (value < table[i].prob3) break;
694 value = value - table[i].prob3;
697 /* Keep the "best" one */
698 if (table[i].level < table[j].level) i = j;
701 return (table[i].index);
705 * @brief オブジェクトを鑑定済にする /
706 * Known is true when the "attributes" of an object are "known".
707 * @param o_ptr 鑑定済にするオブジェクトの構造体参照ポインタ
709 * These include tohit, todam, toac, cost, and pval (charges).\n
711 * Note that "knowing" an object gives you everything that an "awareness"\n
712 * gives you, and much more. In fact, the player is always "aware" of any\n
713 * item of which he has full "knowledge".\n
715 * But having full knowledge of, say, one "wand of wonder", does not, by\n
716 * itself, give you knowledge, or even awareness, of other "wands of wonder".\n
717 * It happens that most "identify" routines (including "buying from a shop")\n
718 * will make the player "aware" of the object as well as fully "know" it.\n
720 * This routine also removes any inscriptions generated by "feelings".\n
722 void object_known(object_type *o_ptr)
724 /* Remove "default inscriptions" */
725 o_ptr->feeling = FEEL_NONE;
727 /* Clear the "Felt" info */
728 o_ptr->ident &= ~(IDENT_SENSE);
730 /* Clear the "Empty" info */
731 o_ptr->ident &= ~(IDENT_EMPTY);
733 /* Now we know about the item */
734 o_ptr->ident |= (IDENT_KNOWN);
738 * @brief オブジェクトを*鑑定*済にする /
739 * The player is now aware of the effects of the given object.
740 * @param o_ptr *鑑定*済にするオブジェクトの構造体参照ポインタ
743 void object_aware(object_type *o_ptr)
745 bool mihanmei = !object_is_aware(o_ptr);
747 /* Fully aware of the effects */
748 k_info[o_ptr->k_idx].aware = TRUE;
750 if(mihanmei && !(k_info[o_ptr->k_idx].gen_flags & TRG_INSTA_ART) && record_ident &&
751 !p_ptr->is_dead && ((o_ptr->tval >= TV_AMULET && o_ptr->tval <= TV_POTION) || (o_ptr->tval == TV_FOOD)))
755 GAME_TEXT o_name[MAX_NLEN];
758 object_copy(q_ptr, o_ptr);
761 object_desc(o_name, q_ptr, OD_NAME_ONLY);
763 exe_write_diary(p_ptr, NIKKI_HANMEI, 0, o_name);
768 * @brief オブジェクトを試行済にする /
769 * Something has been "sampled"
770 * @param o_ptr 試行済にするオブジェクトの構造体参照ポインタ
773 void object_tried(object_type *o_ptr)
775 /* Mark it as tried (even if "aware") */
776 k_info[o_ptr->k_idx].tried = TRUE;
780 * @brief 重度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item. Method 1 (Heavy).
781 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
782 * @return 擬似鑑定結果のIDを返す。
784 byte value_check_aux1(object_type *o_ptr)
787 if (object_is_artifact(o_ptr))
790 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_TERRIBLE;
797 if (object_is_ego(o_ptr))
800 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_WORTHLESS;
803 return FEEL_EXCELLENT;
807 if (object_is_cursed(o_ptr)) return FEEL_CURSED;
810 if (object_is_broken(o_ptr)) return FEEL_BROKEN;
812 if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
814 /* Good "armor" bonus */
815 if (o_ptr->to_a > 0) return FEEL_GOOD;
817 /* Good "weapon" bonus */
818 if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
820 /* Default to "average" */
825 * @brief 軽度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item. Method 2 (Light).
826 * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
827 * @return 擬似鑑定結果のIDを返す。
829 byte value_check_aux2(object_type *o_ptr)
831 /* Cursed items (all of them) */
832 if (object_is_cursed(o_ptr)) return FEEL_CURSED;
834 /* Broken items (all of them) */
835 if (object_is_broken(o_ptr)) return FEEL_BROKEN;
837 /* Artifacts -- except cursed/broken ones */
838 if (object_is_artifact(o_ptr)) return FEEL_UNCURSED;
840 /* Ego-Items -- except cursed/broken ones */
841 if (object_is_ego(o_ptr)) return FEEL_UNCURSED;
843 /* Good armor bonus */
844 if (o_ptr->to_a > 0) return FEEL_UNCURSED;
846 /* Good weapon bonuses */
847 if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
854 * @brief 未鑑定なベースアイテムの基本価格を返す /
855 * Return the "value" of an "unknown" item Make a guess at the value of non-aware items
856 * @param o_ptr 未鑑定価格を確認したいオブジェクトの構造体参照ポインタ
857 * @return オブジェクトの未鑑定価格
859 static PRICE object_value_base(object_type *o_ptr)
861 /* Aware item -- use template cost */
862 if (object_is_aware(o_ptr)) return (k_info[o_ptr->k_idx].cost);
864 /* Analyze the type */
869 case TV_FOOD: return (5L);
871 /* Un-aware Potions */
872 case TV_POTION: return (20L);
874 /* Un-aware Scrolls */
875 case TV_SCROLL: return (20L);
877 /* Un-aware Staffs */
878 case TV_STAFF: return (70L);
881 case TV_WAND: return (50L);
884 case TV_ROD: return (90L);
887 case TV_RING: return (45L);
889 /* Un-aware Amulets */
890 case TV_AMULET: return (45L);
892 /* Figurines, relative to monster level */
895 DEPTH level = r_info[o_ptr->pval].level;
896 if (level < 20) return level*50L;
897 else if (level < 30) return 1000+(level-20)*150L;
898 else if (level < 40) return 2500+(level-30)*350L;
899 else if (level < 50) return 6000+(level-40)*800L;
900 else return 14000+(level-50)*2000L;
904 if (!o_ptr->pval) return 1000L;
905 else return ((r_info[o_ptr->pval].level) * 50L + 1000);
908 /* Paranoia -- Oops */
914 * @brief オブジェクトのフラグ類から価格を算出する /
915 * Return the value of the flags the object has...
916 * @param o_ptr フラグ価格を確認したいオブジェクトの構造体参照ポインタ
917 * @param plusses フラグに与える価格の基本重み
918 * @return オブジェクトのフラグ価格
920 PRICE flag_cost(object_type *o_ptr, int plusses)
923 BIT_FLAGS flgs[TR_FLAG_SIZE];
927 object_kind *k_ptr = &k_info[o_ptr->k_idx];
929 object_flags(o_ptr, flgs);
932 * Exclude fixed flags of the base item.
933 * pval bonuses of base item will be treated later.
935 for (i = 0; i < TR_FLAG_SIZE; i++)
936 flgs[i] &= ~(k_ptr->flags[i]);
938 /* Exclude fixed flags of the fixed artifact. */
939 if (object_is_fixed_artifact(o_ptr))
941 artifact_type *a_ptr = &a_info[o_ptr->name1];
943 for (i = 0; i < TR_FLAG_SIZE; i++)
944 flgs[i] &= ~(a_ptr->flags[i]);
947 /* Exclude fixed flags of the ego-item. */
948 else if (object_is_ego(o_ptr))
950 ego_item_type *e_ptr = &e_info[o_ptr->name2];
952 for (i = 0; i < TR_FLAG_SIZE; i++)
953 flgs[i] &= ~(e_ptr->flags[i]);
958 * Calucurate values of remaining flags
960 if (have_flag(flgs, TR_STR)) total += (1500 * plusses);
961 if (have_flag(flgs, TR_INT)) total += (1500 * plusses);
962 if (have_flag(flgs, TR_WIS)) total += (1500 * plusses);
963 if (have_flag(flgs, TR_DEX)) total += (1500 * plusses);
964 if (have_flag(flgs, TR_CON)) total += (1500 * plusses);
965 if (have_flag(flgs, TR_CHR)) total += (750 * plusses);
966 if (have_flag(flgs, TR_MAGIC_MASTERY)) total += (600 * plusses);
967 if (have_flag(flgs, TR_STEALTH)) total += (250 * plusses);
968 if (have_flag(flgs, TR_SEARCH)) total += (100 * plusses);
969 if (have_flag(flgs, TR_INFRA)) total += (150 * plusses);
970 if (have_flag(flgs, TR_TUNNEL)) total += (175 * plusses);
971 if ((have_flag(flgs, TR_SPEED)) && (plusses > 0))
972 total += (10000 + (2500 * plusses));
973 if ((have_flag(flgs, TR_BLOWS)) && (plusses > 0))
974 total += (10000 + (2500 * plusses));
978 if (have_flag(flgs, TR_CHAOTIC)) {total += 5000;count++;}
979 if (have_flag(flgs, TR_VAMPIRIC)) {total += 6500;count++;}
980 if (have_flag(flgs, TR_FORCE_WEAPON)) {tmp_cost += 2500;count++;}
981 if (have_flag(flgs, TR_KILL_ANIMAL)) {tmp_cost += 2800;count++;}
982 else if (have_flag(flgs, TR_SLAY_ANIMAL)) {tmp_cost += 1800;count++;}
983 if (have_flag(flgs, TR_KILL_EVIL)) {tmp_cost += 3300;count++;}
984 else if (have_flag(flgs, TR_SLAY_EVIL)) {tmp_cost += 2300;count++;}
985 if (have_flag(flgs, TR_KILL_HUMAN)) {tmp_cost += 2800;count++;}
986 else if (have_flag(flgs, TR_SLAY_HUMAN)) {tmp_cost += 1800;count++;}
987 if (have_flag(flgs, TR_KILL_UNDEAD)) {tmp_cost += 2800;count++;}
988 else if (have_flag(flgs, TR_SLAY_UNDEAD)) {tmp_cost += 1800;count++;}
989 if (have_flag(flgs, TR_KILL_DEMON)) {tmp_cost += 2800;count++;}
990 else if (have_flag(flgs, TR_SLAY_DEMON)) {tmp_cost += 1800;count++;}
991 if (have_flag(flgs, TR_KILL_ORC)) {tmp_cost += 2500;count++;}
992 else if (have_flag(flgs, TR_SLAY_ORC)) {tmp_cost += 1500;count++;}
993 if (have_flag(flgs, TR_KILL_TROLL)) {tmp_cost += 2800;count++;}
994 else if (have_flag(flgs, TR_SLAY_TROLL)) {tmp_cost += 1800;count++;}
995 if (have_flag(flgs, TR_KILL_GIANT)) {tmp_cost += 2800;count++;}
996 else if (have_flag(flgs, TR_SLAY_GIANT)) {tmp_cost += 1800;count++;}
997 if (have_flag(flgs, TR_KILL_DRAGON)) {tmp_cost += 2800;count++;}
998 else if (have_flag(flgs, TR_SLAY_DRAGON)) {tmp_cost += 1800;count++;}
1000 if (have_flag(flgs, TR_VORPAL)) {tmp_cost += 2500;count++;}
1001 if (have_flag(flgs, TR_IMPACT)) {tmp_cost += 2500;count++;}
1002 if (have_flag(flgs, TR_BRAND_POIS)) {tmp_cost += 3800;count++;}
1003 if (have_flag(flgs, TR_BRAND_ACID)) {tmp_cost += 3800;count++;}
1004 if (have_flag(flgs, TR_BRAND_ELEC)) {tmp_cost += 3800;count++;}
1005 if (have_flag(flgs, TR_BRAND_FIRE)) {tmp_cost += 2500;count++;}
1006 if (have_flag(flgs, TR_BRAND_COLD)) {tmp_cost += 2500;count++;}
1007 total += (tmp_cost * count);
1009 if (have_flag(flgs, TR_SUST_STR)) total += 850;
1010 if (have_flag(flgs, TR_SUST_INT)) total += 850;
1011 if (have_flag(flgs, TR_SUST_WIS)) total += 850;
1012 if (have_flag(flgs, TR_SUST_DEX)) total += 850;
1013 if (have_flag(flgs, TR_SUST_CON)) total += 850;
1014 if (have_flag(flgs, TR_SUST_CHR)) total += 250;
1015 if (have_flag(flgs, TR_RIDING)) total += 0;
1016 if (have_flag(flgs, TR_EASY_SPELL)) total += 1500;
1017 if (have_flag(flgs, TR_THROW)) total += 5000;
1018 if (have_flag(flgs, TR_FREE_ACT)) total += 4500;
1019 if (have_flag(flgs, TR_HOLD_EXP)) total += 8500;
1023 if (have_flag(flgs, TR_IM_ACID)) {tmp_cost += 15000;count += 2;}
1024 if (have_flag(flgs, TR_IM_ELEC)) {tmp_cost += 15000;count += 2;}
1025 if (have_flag(flgs, TR_IM_FIRE)) {tmp_cost += 15000;count += 2;}
1026 if (have_flag(flgs, TR_IM_COLD)) {tmp_cost += 15000;count += 2;}
1027 if (have_flag(flgs, TR_REFLECT)) {tmp_cost += 5000;count += 2;}
1028 if (have_flag(flgs, TR_RES_ACID)) {tmp_cost += 500;count++;}
1029 if (have_flag(flgs, TR_RES_ELEC)) {tmp_cost += 500;count++;}
1030 if (have_flag(flgs, TR_RES_FIRE)) {tmp_cost += 500;count++;}
1031 if (have_flag(flgs, TR_RES_COLD)) {tmp_cost += 500;count++;}
1032 if (have_flag(flgs, TR_RES_POIS)) {tmp_cost += 1000;count += 2;}
1033 if (have_flag(flgs, TR_RES_FEAR)) {tmp_cost += 1000;count += 2;}
1034 if (have_flag(flgs, TR_RES_LITE)) {tmp_cost += 800;count += 2;}
1035 if (have_flag(flgs, TR_RES_DARK)) {tmp_cost += 800;count += 2;}
1036 if (have_flag(flgs, TR_RES_BLIND)) {tmp_cost += 900;count += 2;}
1037 if (have_flag(flgs, TR_RES_CONF)) {tmp_cost += 900;count += 2;}
1038 if (have_flag(flgs, TR_RES_SOUND)) {tmp_cost += 900;count += 2;}
1039 if (have_flag(flgs, TR_RES_SHARDS)) {tmp_cost += 900;count += 2;}
1040 if (have_flag(flgs, TR_RES_NETHER)) {tmp_cost += 900;count += 2;}
1041 if (have_flag(flgs, TR_RES_NEXUS)) {tmp_cost += 900;count += 2;}
1042 if (have_flag(flgs, TR_RES_CHAOS)) {tmp_cost += 1000;count += 2;}
1043 if (have_flag(flgs, TR_RES_DISEN)) {tmp_cost += 2000;count += 2;}
1044 total += (tmp_cost * count);
1046 if (have_flag(flgs, TR_SH_FIRE)) total += 5000;
1047 if (have_flag(flgs, TR_SH_ELEC)) total += 5000;
1048 if (have_flag(flgs, TR_SH_COLD)) total += 5000;
1049 if (have_flag(flgs, TR_NO_TELE)) total -= 10000;
1050 if (have_flag(flgs, TR_NO_MAGIC)) total += 2500;
1051 if (have_flag(flgs, TR_TY_CURSE)) total -= 15000;
1052 if (have_flag(flgs, TR_HIDE_TYPE)) total += 0;
1053 if (have_flag(flgs, TR_SHOW_MODS)) total += 0;
1054 if (have_flag(flgs, TR_LEVITATION)) total += 1250;
1055 if (have_flag(flgs, TR_LITE_1)) total += 1500;
1056 if (have_flag(flgs, TR_LITE_2)) total += 2500;
1057 if (have_flag(flgs, TR_LITE_3)) total += 4000;
1058 if (have_flag(flgs, TR_LITE_M1)) total -= 1500;
1059 if (have_flag(flgs, TR_LITE_M2)) total -= 2500;
1060 if (have_flag(flgs, TR_LITE_M3)) total -= 4000;
1061 if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
1062 if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
1063 if (have_flag(flgs, TR_ESP_ANIMAL)) total += 1000;
1064 if (have_flag(flgs, TR_ESP_UNDEAD)) total += 1000;
1065 if (have_flag(flgs, TR_ESP_DEMON)) total += 1000;
1066 if (have_flag(flgs, TR_ESP_ORC)) total += 1000;
1067 if (have_flag(flgs, TR_ESP_TROLL)) total += 1000;
1068 if (have_flag(flgs, TR_ESP_GIANT)) total += 1000;
1069 if (have_flag(flgs, TR_ESP_DRAGON)) total += 1000;
1070 if (have_flag(flgs, TR_ESP_HUMAN)) total += 1000;
1071 if (have_flag(flgs, TR_ESP_EVIL)) total += 15000;
1072 if (have_flag(flgs, TR_ESP_GOOD)) total += 2000;
1073 if (have_flag(flgs, TR_ESP_NONLIVING)) total += 2000;
1074 if (have_flag(flgs, TR_ESP_UNIQUE)) total += 10000;
1075 if (have_flag(flgs, TR_SLOW_DIGEST)) total += 750;
1076 if (have_flag(flgs, TR_REGEN)) total += 2500;
1077 if (have_flag(flgs, TR_WARNING)) total += 2000;
1078 if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
1079 if (have_flag(flgs, TR_XTRA_MIGHT)) total += 2250;
1080 if (have_flag(flgs, TR_XTRA_SHOTS)) total += 10000;
1081 if (have_flag(flgs, TR_IGNORE_ACID)) total += 100;
1082 if (have_flag(flgs, TR_IGNORE_ELEC)) total += 100;
1083 if (have_flag(flgs, TR_IGNORE_FIRE)) total += 100;
1084 if (have_flag(flgs, TR_IGNORE_COLD)) total += 100;
1085 if (have_flag(flgs, TR_ACTIVATE)) total += 100;
1086 if (have_flag(flgs, TR_DRAIN_EXP)) total -= 12500;
1087 if (have_flag(flgs, TR_DRAIN_HP)) total -= 12500;
1088 if (have_flag(flgs, TR_DRAIN_MANA)) total -= 12500;
1089 if (have_flag(flgs, TR_CALL_ANIMAL)) total -= 12500;
1090 if (have_flag(flgs, TR_CALL_DEMON)) total -= 10000;
1091 if (have_flag(flgs, TR_CALL_DRAGON)) total -= 10000;
1092 if (have_flag(flgs, TR_CALL_UNDEAD)) total -= 10000;
1093 if (have_flag(flgs, TR_COWARDICE)) total -= 5000;
1094 if (have_flag(flgs, TR_LOW_MELEE)) total -= 5000;
1095 if (have_flag(flgs, TR_LOW_AC)) total -= 5000;
1096 if (have_flag(flgs, TR_LOW_MAGIC)) total -= 15000;
1097 if (have_flag(flgs, TR_FAST_DIGEST)) total -= 10000;
1098 if (have_flag(flgs, TR_SLOW_REGEN)) total -= 10000;
1099 if (have_flag(flgs, TR_TELEPORT))
1101 if (object_is_cursed(o_ptr))
1106 if (have_flag(flgs, TR_AGGRAVATE)) total -= 10000;
1107 if (have_flag(flgs, TR_BLESSED)) total += 750;
1108 if (o_ptr->curse_flags & TR_ADD_L_CURSE) total -= 5000;
1109 if (o_ptr->curse_flags & TR_ADD_H_CURSE) total -= 12500;
1110 if (o_ptr->curse_flags & TRC_CURSED) total -= 5000;
1111 if (o_ptr->curse_flags & TRC_HEAVY_CURSE) total -= 12500;
1112 if (o_ptr->curse_flags & TRC_PERMA_CURSE) total -= 15000;
1114 /* Also, give some extra for activatable powers... */
1115 if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
1117 const activation_type* const act_ptr = find_activation_info(o_ptr);
1119 total += act_ptr->value;
1128 * @brief オブジェクトの真の価格を算出する /
1129 * Return the value of the flags the object has...
1130 * @param o_ptr 本価格を確認したいオブジェクトの構造体参照ポインタ
1131 * @return オブジェクトの本価格
1133 * Return the "real" price of a "known" item, not including discounts\n
1135 * Wand and staffs get cost for each charge\n
1137 * Armor is worth an extra 100 gold per bonus point to armor class.\n
1139 * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).\n
1141 * Missiles are only worth 5 gold per bonus point, since they\n
1142 * usually appear in groups of 20, and we want the player to get\n
1143 * the same amount of cash for any "equivalent" item. Note that\n
1144 * missiles never have any of the "pval" flags, and in fact, they\n
1145 * only have a few of the available flags, primarily of the "slay"\n
1146 * and "brand" and "ignore" variety.\n
1148 * Armor with a negative armor bonus is worthless.\n
1149 * Weapons with negative hit+damage bonuses are worthless.\n
1151 * Every wearable item with a "pval" bonus is worth extra (see below).\n
1153 PRICE object_value_real(object_type *o_ptr)
1156 BIT_FLAGS flgs[TR_FLAG_SIZE];
1157 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1160 /* Hack -- "worthless" items */
1161 if (!k_info[o_ptr->k_idx].cost) return (0L);
1164 value = k_info[o_ptr->k_idx].cost;
1166 /* Extract some flags */
1167 object_flags(o_ptr, flgs);
1170 if (object_is_fixed_artifact(o_ptr))
1172 artifact_type *a_ptr = &a_info[o_ptr->name1];
1174 /* Hack -- "worthless" artifacts */
1175 if (!a_ptr->cost) return (0L);
1177 /* Hack -- Use the artifact cost instead */
1178 value = a_ptr->cost;
1179 value += flag_cost(o_ptr, o_ptr->pval);
1181 /* Don't add pval bonuses etc. */
1186 else if (object_is_ego(o_ptr))
1188 ego_item_type *e_ptr = &e_info[o_ptr->name2];
1190 /* Hack -- "worthless" ego-items */
1191 if (!e_ptr->cost) return (0L);
1193 /* Hack -- Reward the ego-item with a bonus */
1194 value += e_ptr->cost;
1195 value += flag_cost(o_ptr, o_ptr->pval);
1203 for (i = 0; i < TR_FLAG_SIZE; i++)
1204 if (o_ptr->art_flags[i]) flag = TRUE;
1206 if (flag) value += flag_cost(o_ptr, o_ptr->pval);
1209 /* Analyze pval bonus for normal object */
1210 switch (o_ptr->tval)
1233 if (!o_ptr->pval) break;
1235 /* Hack -- Negative "pval" is always bad */
1236 if (o_ptr->pval < 0) return (0L);
1238 /* Give credit for stat bonuses */
1239 if (have_flag(flgs, TR_STR)) value += (o_ptr->pval * 200L);
1240 if (have_flag(flgs, TR_INT)) value += (o_ptr->pval * 200L);
1241 if (have_flag(flgs, TR_WIS)) value += (o_ptr->pval * 200L);
1242 if (have_flag(flgs, TR_DEX)) value += (o_ptr->pval * 200L);
1243 if (have_flag(flgs, TR_CON)) value += (o_ptr->pval * 200L);
1244 if (have_flag(flgs, TR_CHR)) value += (o_ptr->pval * 200L);
1246 /* Give credit for stealth and searching */
1247 if (have_flag(flgs, TR_MAGIC_MASTERY)) value += (o_ptr->pval * 100);
1248 if (have_flag(flgs, TR_STEALTH)) value += (o_ptr->pval * 100L);
1249 if (have_flag(flgs, TR_SEARCH)) value += (o_ptr->pval * 100L);
1251 /* Give credit for infra-vision and tunneling */
1252 if (have_flag(flgs, TR_INFRA)) value += (o_ptr->pval * 50L);
1253 if (have_flag(flgs, TR_TUNNEL)) value += (o_ptr->pval * 50L);
1255 /* Give credit for extra attacks */
1256 if (have_flag(flgs, TR_BLOWS)) value += (o_ptr->pval * 5000L);
1258 /* Give credit for speed bonus */
1259 if (have_flag(flgs, TR_SPEED)) value += (o_ptr->pval * 10000L);
1265 /* Analyze the item */
1266 switch (o_ptr->tval)
1271 /* Pay extra for charges, depending on standard number of
1272 * charges. Handle new-style wands correctly. -LM-
1274 value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
1280 /* Pay extra for charges, depending on standard number of
1283 value += (value * o_ptr->pval / (k_ptr->pval * 2));
1292 /* Hack -- negative bonuses are bad */
1293 if (o_ptr->to_h + o_ptr->to_d + o_ptr->to_a < 0) return (0L);
1295 /* Give credit for bonuses */
1296 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
1312 /* Hack -- negative armor bonus */
1313 if (o_ptr->to_a < 0) return (0L);
1315 /* Give credit for bonuses */
1316 value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
1328 /* Hack -- negative hit/damage bonuses */
1329 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1331 /* Factor in the bonuses */
1332 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 100L);
1334 /* Hack -- Factor in extra damage dice and sides */
1335 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
1336 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
1346 /* Hack -- negative hit/damage bonuses */
1347 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1349 /* Factor in the bonuses */
1350 value += ((o_ptr->to_h + o_ptr->to_d) * 5L);
1352 /* Hack -- Factor in extra damage dice and sides */
1353 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
1354 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
1359 /* Figurines, relative to monster level */
1362 DEPTH level = r_info[o_ptr->pval].level;
1363 if (level < 20) value = level*50L;
1364 else if (level < 30) value = 1000+(level-20)*150L;
1365 else if (level < 40) value = 2500+(level-30)*350L;
1366 else if (level < 50) value = 6000+(level-40)*800L;
1367 else value = 14000+(level-50)*2000L;
1373 if (!o_ptr->pval) value = 1000L;
1374 else value = ((r_info[o_ptr->pval].level) * 50L + 1000);
1380 if (!o_ptr->pval) value = 0L;
1385 /* Worthless object */
1386 if (value < 0) return 0L;
1388 /* Return the value */
1394 * @brief オブジェクト価格算出のメインルーチン /
1395 * Return the price of an item including plusses (and charges)
1396 * @param o_ptr 判明している現価格を確認したいオブジェクトの構造体参照ポインタ
1397 * @return オブジェクトの判明している現価格
1399 * This function returns the "value" of the given item (qty one)\n
1401 * Never notice "unknown" bonuses or properties, including "curses",\n
1402 * since that would give the player information he did not have.\n
1404 * Note that discounted items stay discounted forever, even if\n
1405 * the discount is "forgotten" by the player via memory loss.\n
1407 PRICE object_value(object_type *o_ptr)
1411 /* Unknown items -- acquire a base value */
1412 if (object_is_known(o_ptr))
1414 /* Broken items -- worthless */
1415 if (object_is_broken(o_ptr)) return (0L);
1417 /* Cursed items -- worthless */
1418 if (object_is_cursed(o_ptr)) return (0L);
1420 /* Real value (see above) */
1421 value = object_value_real(o_ptr);
1424 /* Known items -- acquire the actual value */
1427 /* Hack -- Felt broken items */
1428 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_broken(o_ptr)) return (0L);
1430 /* Hack -- Felt cursed items */
1431 if ((o_ptr->ident & (IDENT_SENSE)) && object_is_cursed(o_ptr)) return (0L);
1433 /* Base value (see above) */
1434 value = object_value_base(o_ptr);
1437 /* Apply discount (if any) */
1438 if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
1440 /* Return the final value */
1448 * @brief 魔法棒やロッドのスロット分割時に使用回数を分配する /
1449 * Distribute charges of rods or wands.
1450 * @param o_ptr 分割元オブジェクトの構造体参照ポインタ source item
1451 * @param q_ptr 分割先オブジェクトの構造体参照ポインタ target item, must be of the same type as o_ptr
1452 * @param amt 分割したい回数量 number of items that are transfered
1455 * Hack -- If rods or wands are dropped, the total maximum timeout or\n
1456 * charges need to be allocated between the two stacks. If all the items\n
1457 * are being dropped, it makes for a neater message to leave the original\n
1458 * stack's pval alone. -LM-\n
1460 void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
1462 if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD))
1464 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1465 if (amt < o_ptr->number) o_ptr->pval -= q_ptr->pval;
1467 /* Hack -- Rods also need to have their timeouts distributed. The
1468 * dropped stack will accept all time remaining to charge up to its
1471 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
1473 if (q_ptr->pval > o_ptr->timeout)
1474 q_ptr->timeout = o_ptr->timeout;
1476 q_ptr->timeout = q_ptr->pval;
1478 if (amt < o_ptr->number) o_ptr->timeout -= q_ptr->timeout;
1484 * @brief 魔法棒やロッドの使用回数を減らす /
1485 * @param o_ptr オブジェクトの構造体参照ポインタ source item
1486 * @param amt 減らしたい回数量 number of items that are transfered
1489 * Hack -- If rods or wand are destroyed, the total maximum timeout or\n
1490 * charges of the stack needs to be reduced, unless all the items are\n
1491 * being destroyed. -LM-\n
1493 void reduce_charges(object_type *o_ptr, int amt)
1495 if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD)) &&
1496 (amt < o_ptr->number))
1498 o_ptr->pval -= o_ptr->pval * amt / o_ptr->number;
1503 * Determine if an item can "absorb" a second item
1505 * See "object_absorb()" for the actual "absorption" code.
1507 * If permitted, we allow staffs (if they are known to have equal charges
1508 * and both are either known or confirmed empty) and wands (if both are
1509 * either known or confirmed empty) and rods (in all cases) to combine.
1510 * Staffs will unstack (if necessary) when they are used, but wands and
1511 * rods will only unstack if one is dropped. -LM-
1513 * If permitted, we allow weapons/armor to stack, if fully "known".
1515 * Missiles will combine if both stacks have the same "known" status.
1516 * This is done to make unidentified stacks of missiles useful.
1518 * Food, potions, scrolls, and "easy know" items always stack.
1520 * Chests, and activatable items, never stack (for various reasons).
1524 * A "stack" of items is limited to less than or equal to 99 items (hard-coded).
1526 #define MAX_STACK_SIZE 99
1530 * @brief 両オブジェクトをスロットに重ね合わせ可能な最大数を返す。
1531 * Determine if an item can partly absorb a second item. Return maximum number of stack.
1532 * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1533 * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1534 * @return 重ね合わせ可能なアイテム数
1536 int object_similar_part(object_type *o_ptr, object_type *j_ptr)
1540 /* Default maximum number of stack */
1541 int max_num = MAX_STACK_SIZE;
1543 /* Require identical object types */
1544 if (o_ptr->k_idx != j_ptr->k_idx) return 0;
1547 /* Analyze the items */
1548 switch (o_ptr->tval)
1550 /* Chests and Statues*/
1561 if ((o_ptr->sval != SV_PHOTO) || (j_ptr->sval != SV_PHOTO)) return 0;
1562 if (o_ptr->pval != j_ptr->pval) return 0;
1566 /* Figurines and Corpses*/
1571 if (o_ptr->pval != j_ptr->pval) return 0;
1577 /* Food and Potions and Scrolls */
1589 /* Require either knowledge or known empty for both staffs. */
1590 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1591 !object_is_known(o_ptr)) ||
1592 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1593 !object_is_known(j_ptr))) return 0;
1595 /* Require identical charges, since staffs are bulky. */
1596 if (o_ptr->pval != j_ptr->pval) return 0;
1605 /* Require either knowledge or known empty for both wands. */
1606 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1607 !object_is_known(o_ptr)) ||
1608 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1609 !object_is_known(j_ptr))) return 0;
1611 /* Wand charges combine in O&ZAngband. */
1617 /* Staffs and Wands and Rods */
1620 /* Prevent overflaw of timeout */
1621 max_num = MIN(max_num, MAX_SHORT / k_info[o_ptr->k_idx].pval);
1627 /* Weapons and Armor */
1643 /* Rings, Amulets, Lites */
1649 /* Require full knowledge of both items */
1650 if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1660 /* Require identical knowledge of both items */
1661 if (object_is_known(o_ptr) != object_is_known(j_ptr)) return 0;
1662 if (o_ptr->feeling != j_ptr->feeling) return 0;
1664 /* Require identical "bonuses" */
1665 if (o_ptr->to_h != j_ptr->to_h) return 0;
1666 if (o_ptr->to_d != j_ptr->to_d) return 0;
1667 if (o_ptr->to_a != j_ptr->to_a) return 0;
1669 /* Require identical "pval" code */
1670 if (o_ptr->pval != j_ptr->pval) return 0;
1672 /* Artifacts never stack */
1673 if (object_is_artifact(o_ptr) || object_is_artifact(j_ptr)) return 0;
1675 /* Require identical "ego-item" names */
1676 if (o_ptr->name2 != j_ptr->name2) return 0;
1678 /* Require identical added essence */
1679 if (o_ptr->xtra3 != j_ptr->xtra3) return 0;
1680 if (o_ptr->xtra4 != j_ptr->xtra4) return 0;
1682 /* Hack -- Never stack "powerful" items */
1683 if (o_ptr->xtra1 || j_ptr->xtra1) return 0;
1685 /* Hack -- Never stack recharging items */
1686 if (o_ptr->timeout || j_ptr->timeout) return 0;
1688 /* Require identical "values" */
1689 if (o_ptr->ac != j_ptr->ac) return 0;
1690 if (o_ptr->dd != j_ptr->dd) return 0;
1691 if (o_ptr->ds != j_ptr->ds) return 0;
1700 /* Require knowledge */
1701 if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
1709 /* Hack -- Identical art_flags! */
1710 for (i = 0; i < TR_FLAG_SIZE; i++)
1711 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return 0;
1713 /* Hack -- Require identical "cursed" status */
1714 if (o_ptr->curse_flags != j_ptr->curse_flags) return 0;
1716 /* Hack -- Require identical "broken" status */
1717 if ((o_ptr->ident & (IDENT_BROKEN)) != (j_ptr->ident & (IDENT_BROKEN))) return 0;
1720 /* Hack -- require semi-matching "inscriptions" */
1721 if (o_ptr->inscription && j_ptr->inscription &&
1722 (o_ptr->inscription != j_ptr->inscription))
1725 /* Hack -- normally require matching "inscriptions" */
1726 if (!stack_force_notes && (o_ptr->inscription != j_ptr->inscription)) return 0;
1728 /* Hack -- normally require matching "discounts" */
1729 if (!stack_force_costs && (o_ptr->discount != j_ptr->discount)) return 0;
1732 /* They match, so they must be similar */
1737 * @brief 両オブジェクトをスロットに重ねることができるかどうかを返す。
1738 * Determine if an item can absorb a second item.
1739 * @param o_ptr 検証したいオブジェクトの構造体参照ポインタ1
1740 * @param j_ptr 検証したいオブジェクトの構造体参照ポインタ2
1741 * @return 重ね合わせ可能ならばTRUEを返す。
1743 bool object_similar(object_type *o_ptr, object_type *j_ptr)
1745 int total = o_ptr->number + j_ptr->number;
1748 /* Are these objects similar? */
1749 max_num = object_similar_part(o_ptr, j_ptr);
1751 /* Return if not similar */
1752 if (!max_num) return FALSE;
1754 /* Maximal "stacking" limit */
1755 if (total > max_num) return (0);
1758 /* They match, so they must be similar */
1764 * @brief 両オブジェクトをスロットに重ね合わせる。
1765 * Allow one item to "absorb" another, assuming they are similar
1766 * @param o_ptr 重ね合わせ先のオブジェクトの構造体参照ポインタ
1767 * @param j_ptr 重ね合わせ元のオブジェクトの構造体参照ポインタ
1770 void object_absorb(object_type *o_ptr, object_type *j_ptr)
1772 int max_num = object_similar_part(o_ptr, j_ptr);
1773 int total = o_ptr->number + j_ptr->number;
1774 int diff = (total > max_num) ? total - max_num : 0;
1776 /* Combine quantity, lose excess items */
1777 o_ptr->number = (total > max_num) ? max_num : total;
1779 /* Hack -- blend "known" status */
1780 if (object_is_known(j_ptr)) object_known(o_ptr);
1782 /* Hack -- clear "storebought" if only one has it */
1783 if (((o_ptr->ident & IDENT_STORE) || (j_ptr->ident & IDENT_STORE)) &&
1784 (!((o_ptr->ident & IDENT_STORE) && (j_ptr->ident & IDENT_STORE))))
1786 if (j_ptr->ident & IDENT_STORE) j_ptr->ident &= 0xEF;
1787 if (o_ptr->ident & IDENT_STORE) o_ptr->ident &= 0xEF;
1790 /* Hack -- blend "mental" status */
1791 if (j_ptr->ident & (IDENT_MENTAL)) o_ptr->ident |= (IDENT_MENTAL);
1793 /* Hack -- blend "inscriptions" */
1794 if (j_ptr->inscription) o_ptr->inscription = j_ptr->inscription;
1796 /* Hack -- blend "feelings" */
1797 if (j_ptr->feeling) o_ptr->feeling = j_ptr->feeling;
1799 /* Hack -- could average discounts */
1800 /* Hack -- save largest discount */
1801 if (o_ptr->discount < j_ptr->discount) o_ptr->discount = j_ptr->discount;
1803 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1804 if (o_ptr->tval == TV_ROD)
1806 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1807 o_ptr->timeout += j_ptr->timeout * (j_ptr->number - diff) / j_ptr->number;
1810 /* Hack -- if wands are stacking, combine the charges. -LM- */
1811 if (o_ptr->tval == TV_WAND)
1813 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1819 * @brief tvalとsvalに対応するベースアイテムのIDを返す。
1820 * Find the index of the object_kind with the given tval and sval
1821 * @param tval 検索したいベースアイテムのtval
1822 * @param sval 検索したいベースアイテムのsval
1825 KIND_OBJECT_IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
1829 KIND_OBJECT_IDX bk = 0;
1832 for (k = 1; k < max_k_idx; k++)
1834 object_kind *k_ptr = &k_info[k];
1836 /* Require correct tval */
1837 if (k_ptr->tval != tval) continue;
1840 if (k_ptr->sval == sval) return (k);
1842 /* Ignore illegal items */
1843 if (sval != SV_ANY) continue;
1845 /* Apply the randomizer */
1846 if (!one_in_(++num)) continue;
1848 /* Use this value */
1852 /* Return this choice */
1859 msg_format(_("アイテムがない (%d,%d)", "No object (%d,%d)"), tval, sval);
1868 * @brief オブジェクトを初期化する
1869 * Wipe an object clean.
1870 * @param o_ptr 初期化したいオブジェクトの構造体参照ポインタ
1873 void object_wipe(object_type *o_ptr)
1875 /* Wipe the structure */
1876 (void)WIPE(o_ptr, object_type);
1881 * @brief オブジェクトを複製する
1882 * Wipe an object clean.
1883 * @param o_ptr 複製元のオブジェクトの構造体参照ポインタ
1884 * @param j_ptr 複製先のオブジェクトの構造体参照ポインタ
1887 void object_copy(object_type *o_ptr, object_type *j_ptr)
1889 /* Copy the structure */
1890 (void)COPY(o_ptr, j_ptr, object_type);
1895 * @brief オブジェクト構造体にベースアイテムを作成する
1896 * Prepare an object based on an object kind.
1897 * @param o_ptr 代入したいオブジェクトの構造体参照ポインタ
1898 * @param k_idx 新たに作成したいベースアイテム情報のID
1901 void object_prep(object_type *o_ptr, KIND_OBJECT_IDX k_idx)
1903 object_kind *k_ptr = &k_info[k_idx];
1905 /* Clear the record */
1908 /* Save the kind index */
1909 o_ptr->k_idx = k_idx;
1911 /* Efficiency -- tval/sval */
1912 o_ptr->tval = k_ptr->tval;
1913 o_ptr->sval = k_ptr->sval;
1915 /* Default "pval" */
1916 o_ptr->pval = k_ptr->pval;
1918 /* Default number */
1921 /* Default weight */
1922 o_ptr->weight = k_ptr->weight;
1925 o_ptr->to_h = k_ptr->to_h;
1926 o_ptr->to_d = k_ptr->to_d;
1927 o_ptr->to_a = k_ptr->to_a;
1930 o_ptr->ac = k_ptr->ac;
1931 o_ptr->dd = k_ptr->dd;
1932 o_ptr->ds = k_ptr->ds;
1934 /* Default activation */
1935 if (k_ptr->act_idx > 0) o_ptr->xtra2 = (XTRA8)k_ptr->act_idx;
1937 /* Hack -- worthless items are always "broken" */
1938 if (k_info[o_ptr->k_idx].cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
1940 /* Hack -- cursed items are always "cursed" */
1941 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
1942 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
1943 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
1944 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
1945 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
1946 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
1951 * @brief デバッグ時にアイテム生成情報をメッセージに出力する / Cheat -- describe a created object for the user
1952 * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ
1955 static void object_mention(object_type *o_ptr)
1957 GAME_TEXT o_name[MAX_NLEN];
1959 object_aware(o_ptr);
1960 object_known(o_ptr);
1962 /* Mark the item as fully known */
1963 o_ptr->ident |= (IDENT_MENTAL);
1964 object_desc(o_name, o_ptr, 0);
1965 msg_format_wizard(CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
1970 * @brief アイテムのエゴをレア度の重みに合わせてランダムに選択する
1971 * Choose random ego type
1972 * @param slot 取得したいエゴの装備部位
1973 * @param good TRUEならば通常のエゴ、FALSEならば呪いのエゴが選択対象となる。
1974 * @return 選択されたエゴ情報のID、万一選択できなかった場合はmax_e_idxが返る。
1976 static byte get_random_ego(byte slot, bool good)
1979 ego_item_type *e_ptr;
1983 for (i = 1; i < max_e_idx; i++)
1987 if (e_ptr->slot == slot
1988 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
1991 total += (255 / e_ptr->rarity);
1995 value = randint1(total);
1997 for (i = 1; i < max_e_idx; i++)
2001 if (e_ptr->slot == slot
2002 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
2005 value -= (255 / e_ptr->rarity);
2006 if (value <= 0L) break;
2014 * @brief 武器系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2015 * Apply magic to an item known to be a "weapon"
2016 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2017 * @param level 生成基準階
2018 * @param power 生成ランク
2021 * Hack -- note special base damage dice boosting\n
2022 * Hack -- note special processing for weapon/digger\n
2024 void apply_magic_weapon(object_type *o_ptr, DEPTH level, int power)
2026 HIT_PROB tohit1 = randint1(5) + (HIT_PROB)m_bonus(5, level);
2027 HIT_POINT todam1 = randint1(5) + (HIT_POINT)m_bonus(5, level);
2029 HIT_PROB tohit2 = (HIT_PROB)m_bonus(10, level);
2030 HIT_POINT todam2 = (HIT_POINT)m_bonus(10, level);
2032 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
2034 tohit2 = (tohit2 + 1) / 2;
2035 todam2 = (todam2 + 1) / 2;
2042 o_ptr->to_h += tohit1;
2043 o_ptr->to_d += todam1;
2049 o_ptr->to_h += tohit2;
2050 o_ptr->to_d += todam2;
2058 o_ptr->to_h -= tohit1;
2059 o_ptr->to_d -= todam1;
2064 /* Penalize again */
2065 o_ptr->to_h -= tohit2;
2066 o_ptr->to_d -= todam2;
2069 /* Cursed (if "bad") */
2070 if (o_ptr->to_h + o_ptr->to_d < 0) o_ptr->curse_flags |= TRC_CURSED;
2073 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)) return;
2075 switch (o_ptr->tval)
2082 if (one_in_(30) || (power > 2)) /* power > 2 is debug only */
2083 become_random_artifact(o_ptr, FALSE);
2085 /* Special Ego-item */
2086 o_ptr->name2 = EGO_DIGGING;
2090 else if (power < -1)
2092 /* Hack -- Horrible digging bonus */
2093 o_ptr->pval = 0 - (5 + randint1(5));
2099 /* Hack -- Reverse digging bonus */
2100 o_ptr->pval = 0 - (o_ptr->pval);
2113 if (one_in_(40) || (power > 2)) /* power > 2 is debug only */
2115 become_random_artifact(o_ptr, FALSE);
2120 /* Roll for an ego-item */
2121 o_ptr->name2 = get_random_ego(INVEN_RARM, TRUE);
2122 if (o_ptr->name2 == EGO_SHARPNESS && o_ptr->tval != TV_SWORD)
2124 if (o_ptr->name2 == EGO_EARTHQUAKES && o_ptr->tval != TV_HAFTED)
2126 if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2131 switch (o_ptr->name2)
2134 if (one_in_(4) && (level > 40))
2135 add_flag(o_ptr->art_flags, TR_BLOWS);
2139 add_flag(o_ptr->art_flags, TR_RES_POIS);
2141 add_flag(o_ptr->art_flags, TR_WARNING);
2143 case EGO_KILL_DRAGON:
2145 add_flag(o_ptr->art_flags, TR_RES_POIS);
2149 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2151 case EGO_SLAYING_WEAPON:
2152 if (one_in_(3)) /* double damage */
2159 } while (one_in_(o_ptr->dd));
2164 } while (one_in_(o_ptr->ds));
2169 add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2171 if (o_ptr->tval == TV_SWORD && one_in_(3))
2173 add_flag(o_ptr->art_flags, TR_VORPAL);
2178 add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
2184 add_flag(o_ptr->art_flags, TR_HOLD_EXP);
2186 add_flag(o_ptr->art_flags, TR_DEX);
2188 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2191 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, level) + 1;
2193 case EGO_EARTHQUAKES:
2194 if (one_in_(3) && (level > 60))
2195 add_flag(o_ptr->art_flags, TR_BLOWS);
2197 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, level);
2201 add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
2205 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2207 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2209 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2210 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2213 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CHAOTIC);
2214 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BLOWS);
2215 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2216 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2220 if (!o_ptr->art_name)
2222 /* Hack -- Super-charge the damage dice */
2223 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2225 /* Hack -- Lower the damage dice */
2226 if (o_ptr->dd > 9) o_ptr->dd = 9;
2231 else if (power < -1)
2233 /* Roll for ego-item */
2234 if (randint0(MAX_DEPTH) < level)
2238 o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE);
2239 if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
2245 switch (o_ptr->name2)
2248 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2249 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2252 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2253 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_NETHER);
2254 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2255 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2256 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2257 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2272 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2274 become_random_artifact(o_ptr, FALSE);
2277 o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE);
2291 if (power > 2) /* power > 2 is debug only */
2293 become_random_artifact(o_ptr, FALSE);
2297 o_ptr->name2 = get_random_ego(INVEN_AMMO, TRUE);
2299 switch (o_ptr->name2)
2301 case EGO_SLAYING_BOLT:
2306 /* Hack -- super-charge the damage dice */
2307 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2309 /* Hack -- restrict the damage dice */
2310 if (o_ptr->dd > 9) o_ptr->dd = 9;
2314 else if (power < -1)
2316 /* Roll for ego-item */
2317 if (randint0(MAX_DEPTH) < level)
2319 o_ptr->name2 = get_random_ego(INVEN_AMMO, FALSE);
2329 * @brief 防具系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2330 * Apply magic to an item known to be "armor"
2331 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2332 * @param level 生成基準階
2333 * @param power 生成ランク
2336 * Hack -- note special processing for crown/helm\n
2337 * Hack -- note special processing for robe of permanence\n
2339 static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
2341 ARMOUR_CLASS toac1 = (ARMOUR_CLASS)randint1(5) + m_bonus(5, level);
2342 ARMOUR_CLASS toac2 = (ARMOUR_CLASS)m_bonus(10, level);
2348 o_ptr->to_a += toac1;
2354 o_ptr->to_a += toac2;
2362 o_ptr->to_a -= toac1;
2367 /* Penalize again */
2368 o_ptr->to_a -= toac2;
2371 /* Cursed (if "bad") */
2372 if (o_ptr->to_a < 0) o_ptr->curse_flags |= TRC_CURSED;
2375 switch (o_ptr->tval)
2379 if (one_in_(50) || (power > 2)) /* power > 2 is debug only */
2380 become_random_artifact(o_ptr, FALSE);
2390 /* Hack -- Try for "Robes of the Magi" */
2391 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
2392 (o_ptr->sval == SV_ROBE) &&
2393 (randint0(100) < 15))
2397 o_ptr->name2 = EGO_YOIYAMI;
2398 o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
2399 o_ptr->sval = SV_YOIYAMI_ROBE;
2405 o_ptr->name2 = EGO_PERMANENCE;
2410 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2412 become_random_artifact(o_ptr, FALSE);
2418 bool okay_flag = TRUE;
2420 o_ptr->name2 = get_random_ego(INVEN_BODY, TRUE);
2422 switch (o_ptr->name2)
2425 if (o_ptr->tval != TV_HARD_ARMOR)
2431 if (o_ptr->tval != TV_SOFT_ARMOR)
2440 if (okay_flag) break;
2442 switch (o_ptr->name2)
2444 case EGO_RESISTANCE:
2446 add_flag(o_ptr->art_flags, TR_RES_POIS);
2449 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2450 o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
2454 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2456 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2458 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2459 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2461 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2462 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2463 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2464 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2465 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2466 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2467 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2468 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2471 if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2472 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2473 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2474 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2475 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2476 if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2489 if (o_ptr->sval == SV_DRAGON_SHIELD)
2491 dragon_resist(o_ptr);
2492 if (!one_in_(3)) break;
2498 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2500 become_random_artifact(o_ptr, FALSE);
2506 o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE);
2507 if (o_ptr->sval != SV_SMALL_METAL_SHIELD && o_ptr->sval != SV_LARGE_METAL_SHIELD
2508 && o_ptr->name2 == EGO_S_DWARVEN)
2515 switch (o_ptr->name2)
2518 if (!one_in_(3)) one_high_resistance(o_ptr);
2519 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_POIS);
2521 case EGO_REFLECTION:
2522 if (o_ptr->sval == SV_MIRROR_SHIELD)
2527 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2528 o_ptr->ac = k_info[o_ptr->k_idx].ac + 3;
2537 if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
2539 dragon_resist(o_ptr);
2540 if (!one_in_(3)) break;
2544 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2546 become_random_artifact(o_ptr, FALSE);
2549 o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE);
2553 else if (power < -1)
2555 o_ptr->name2 = get_random_ego(INVEN_HANDS, FALSE);
2563 if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
2565 dragon_resist(o_ptr);
2566 if (!one_in_(3)) break;
2571 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2573 become_random_artifact(o_ptr, FALSE);
2576 o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE);
2578 switch (o_ptr->name2)
2580 case EGO_SLOW_DESCENT:
2583 one_high_resistance(o_ptr);
2589 else if (power < -1)
2591 o_ptr->name2 = get_random_ego(INVEN_FEET, FALSE);
2602 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2604 become_random_artifact(o_ptr, FALSE);
2609 bool ok_flag = TRUE;
2610 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2612 switch (o_ptr->name2)
2615 if (add_esp_strong(o_ptr)) add_esp_weak(o_ptr, TRUE);
2616 else add_esp_weak(o_ptr, FALSE);
2620 case EGO_REGENERATION:
2621 case EGO_LORDLINESS:
2627 if (one_in_(2)) add_esp_strong(o_ptr);
2628 else add_esp_weak(o_ptr, FALSE);
2631 default:/* not existing crown (wisdom,lite, etc...) */
2635 break; /* while (1) */
2641 else if (power < -1)
2645 bool ok_flag = TRUE;
2646 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2648 switch (o_ptr->name2)
2650 case EGO_ANCIENT_CURSE:
2651 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
2652 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_TELE);
2653 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2654 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2655 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2656 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2660 break; /* while (1) */
2669 if (o_ptr->sval == SV_DRAGON_HELM)
2671 dragon_resist(o_ptr);
2672 if (!one_in_(3)) break;
2678 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2680 become_random_artifact(o_ptr, FALSE);
2685 bool ok_flag = TRUE;
2686 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE);
2688 switch (o_ptr->name2)
2690 case EGO_BRILLIANCE:
2692 case EGO_INFRAVISION:
2693 case EGO_H_PROTECTION:
2698 if (one_in_(2)) add_esp_strong(o_ptr);
2699 else add_esp_weak(o_ptr, FALSE);
2703 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_1);
2704 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_2);
2707 if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
2709 add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
2711 add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
2712 add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2714 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
2715 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
2716 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
2717 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
2718 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
2719 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2720 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2721 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
2723 default:/* not existing helm (Magi, Might, etc...)*/
2727 break; /* while (1) */
2732 else if (power < -1)
2736 bool ok_flag = TRUE;
2737 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
2739 switch (o_ptr->name2)
2741 case EGO_ANCIENT_CURSE:
2745 break; /* while (1) */
2756 if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
2758 become_random_artifact(o_ptr, FALSE);
2761 o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE);
2763 switch (o_ptr->name2)
2772 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_COWARDICE);
2773 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CALL_UNDEAD);
2774 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_SLOW_REGEN);
2775 if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
2782 else if (power < -1)
2784 o_ptr->name2 = get_random_ego(INVEN_OUTER, FALSE);
2795 * @brief 装飾品系オブジェクトに生成ランクごとの強化を与えるサブルーチン
2796 * Apply magic to an item known to be a "ring" or "amulet"
2797 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
2798 * @param level 生成基準階
2799 * @param power 生成ランク
2802 * Hack -- note special "pval boost" code for ring of speed\n
2803 * Hack -- note that some items must be cursed (or blessed)\n
2805 static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
2807 /* Apply magic (good or bad) according to type */
2808 switch (o_ptr->tval)
2813 switch (o_ptr->sval)
2815 case SV_RING_ATTACKS:
2818 o_ptr->pval = (PARAMETER_VALUE)m_bonus(2, level);
2819 if (one_in_(15)) o_ptr->pval++;
2820 if (o_ptr->pval < 1) o_ptr->pval = 1;
2826 o_ptr->ident |= (IDENT_BROKEN);
2829 o_ptr->curse_flags |= TRC_CURSED;
2832 o_ptr->pval = 0 - (o_ptr->pval);
2843 /* Strength, Constitution, Dexterity, Intelligence */
2849 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2855 o_ptr->ident |= (IDENT_BROKEN);
2858 o_ptr->curse_flags |= TRC_CURSED;
2861 o_ptr->pval = 0 - (o_ptr->pval);
2867 /* Ring of Speed! */
2870 /* Base speed (1 to 10) */
2871 o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
2873 /* Super-charge the ring */
2874 while (randint0(100) < 50) o_ptr->pval++;
2880 o_ptr->ident |= (IDENT_BROKEN);
2883 o_ptr->curse_flags |= TRC_CURSED;
2886 o_ptr->pval = 0 - (o_ptr->pval);
2894 case SV_RING_LORDLY:
2898 one_lordly_high_resistance(o_ptr);
2902 /* Bonus to armor class */
2903 o_ptr->to_a = 10 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2907 case SV_RING_WARNING:
2909 if (one_in_(3)) one_low_esp(o_ptr);
2914 case SV_RING_SEARCHING:
2916 /* Bonus to searching */
2917 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
2923 o_ptr->ident |= (IDENT_BROKEN);
2926 o_ptr->curse_flags |= TRC_CURSED;
2929 o_ptr->pval = 0 - (o_ptr->pval);
2935 /* Flames, Acid, Ice */
2936 case SV_RING_FLAMES:
2941 /* Bonus to armor class */
2942 o_ptr->to_a = 5 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
2946 /* Weakness, Stupidity */
2947 case SV_RING_WEAKNESS:
2948 case SV_RING_STUPIDITY:
2951 o_ptr->ident |= (IDENT_BROKEN);
2954 o_ptr->curse_flags |= TRC_CURSED;
2957 o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2958 if (power > 0) power = 0 - power;
2963 /* WOE, Stupidity */
2967 o_ptr->ident |= (IDENT_BROKEN);
2970 o_ptr->curse_flags |= TRC_CURSED;
2973 o_ptr->to_a = 0 - (5 + (ARMOUR_CLASS)m_bonus(10, level));
2974 o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
2975 if (power > 0) power = 0 - power;
2980 /* Ring of damage */
2981 case SV_RING_DAMAGE:
2983 /* Bonus to damage */
2984 o_ptr->to_d = 1 + randint1(5) + (HIT_POINT)m_bonus(16, level);
2990 o_ptr->ident |= (IDENT_BROKEN);
2993 o_ptr->curse_flags |= TRC_CURSED;
2996 o_ptr->to_d = 0 - o_ptr->to_d;
3002 /* Ring of Accuracy */
3003 case SV_RING_ACCURACY:
3006 o_ptr->to_h = 1 + randint1(5) + (HIT_PROB)m_bonus(16, level);
3012 o_ptr->ident |= (IDENT_BROKEN);
3015 o_ptr->curse_flags |= TRC_CURSED;
3018 o_ptr->to_h = 0 - o_ptr->to_h;
3024 /* Ring of Protection */
3025 case SV_RING_PROTECTION:
3027 /* Bonus to armor class */
3028 o_ptr->to_a = 5 + randint1(8) + (ARMOUR_CLASS)m_bonus(10, level);
3034 o_ptr->ident |= (IDENT_BROKEN);
3037 o_ptr->curse_flags |= TRC_CURSED;
3040 o_ptr->to_a = 0 - o_ptr->to_a;
3046 /* Ring of Slaying */
3047 case SV_RING_SLAYING:
3049 /* Bonus to damage and to hit */
3050 o_ptr->to_d = randint1(5) + (HIT_POINT)m_bonus(12, level);
3051 o_ptr->to_h = randint1(5) + (HIT_PROB)m_bonus(12, level);
3057 o_ptr->ident |= (IDENT_BROKEN);
3060 o_ptr->curse_flags |= TRC_CURSED;
3062 /* Reverse bonuses */
3063 o_ptr->to_h = 0 - o_ptr->to_h;
3064 o_ptr->to_d = 0 - o_ptr->to_d;
3070 case SV_RING_MUSCLE:
3072 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(3, level);
3073 if (one_in_(4)) o_ptr->pval++;
3079 o_ptr->ident |= (IDENT_BROKEN);
3082 o_ptr->curse_flags |= TRC_CURSED;
3084 /* Reverse bonuses */
3085 o_ptr->pval = 0 - o_ptr->pval;
3090 case SV_RING_AGGRAVATION:
3093 o_ptr->ident |= (IDENT_BROKEN);
3096 o_ptr->curse_flags |= TRC_CURSED;
3098 if (power > 0) power = 0 - power;
3102 if ((one_in_(400) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3103 || (power > 2)) /* power > 2 is debug only */
3105 o_ptr->pval = MIN(o_ptr->pval, 4);
3106 /* Randart amulet */
3107 become_random_artifact(o_ptr, FALSE);
3109 else if ((power == 2) && one_in_(2))
3111 while(!o_ptr->name2)
3113 int tmp = m_bonus(10, level);
3114 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3115 switch(randint1(28))
3118 o_ptr->name2 = EGO_RING_THROW;
3121 if (have_flag(k_ptr->flags, TR_REGEN)) break;
3122 o_ptr->name2 = EGO_RING_REGEN;
3125 if (have_flag(k_ptr->flags, TR_LITE_1)) break;
3126 o_ptr->name2 = EGO_RING_LITE;
3129 if (have_flag(k_ptr->flags, TR_TELEPORT)) break;
3130 o_ptr->name2 = EGO_RING_TELEPORT;
3133 if (o_ptr->to_h) break;
3134 o_ptr->name2 = EGO_RING_TO_H;
3137 if (o_ptr->to_d) break;
3138 o_ptr->name2 = EGO_RING_TO_D;
3141 if ((o_ptr->to_h) || (o_ptr->to_d)) break;
3142 o_ptr->name2 = EGO_RING_SLAY;
3145 if ((have_flag(k_ptr->flags, TR_STR)) || o_ptr->to_h || o_ptr->to_d) break;
3146 o_ptr->name2 = EGO_RING_WIZARD;
3149 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3150 o_ptr->name2 = EGO_RING_HERO;
3153 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3154 if (tmp > 8) o_ptr->name2 = EGO_RING_MANA_BALL;
3155 else if (tmp > 4) o_ptr->name2 = EGO_RING_MANA_BOLT;
3156 else o_ptr->name2 = EGO_RING_MAGIC_MIS;
3159 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3160 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;
3161 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_F;
3162 else if (tmp > 3) o_ptr->name2 = EGO_RING_FIRE_BALL;
3163 else o_ptr->name2 = EGO_RING_FIRE_BOLT;
3166 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3167 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;
3168 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_C;
3169 else if (tmp > 3) o_ptr->name2 = EGO_RING_COLD_BALL;
3170 else o_ptr->name2 = EGO_RING_COLD_BOLT;
3173 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3174 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;
3175 if (tmp > 4) o_ptr->name2 = EGO_RING_ELEC_BALL;
3176 else o_ptr->name2 = EGO_RING_ELEC_BOLT;
3179 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3180 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;
3181 if (tmp > 4) o_ptr->name2 = EGO_RING_ACID_BALL;
3182 else o_ptr->name2 = EGO_RING_ACID_BOLT;
3184 case 21: case 22: case 23: case 24: case 25: case 26:
3185 switch (o_ptr->sval)
3188 if (!one_in_(3)) break;
3189 o_ptr->name2 = EGO_RING_D_SPEED;
3191 case SV_RING_DAMAGE:
3192 case SV_RING_ACCURACY:
3193 case SV_RING_SLAYING:
3194 if (one_in_(2)) break;
3195 if (one_in_(2)) o_ptr->name2 = EGO_RING_HERO;
3198 o_ptr->name2 = EGO_RING_BERSERKER;
3199 o_ptr->to_h -= 2+randint1(4);
3200 o_ptr->to_d += 2+randint1(4);
3203 case SV_RING_PROTECTION:
3204 o_ptr->name2 = EGO_RING_SUPER_AC;
3205 o_ptr->to_a += 7 + m_bonus(5, level);
3207 case SV_RING_RES_FEAR:
3208 o_ptr->name2 = EGO_RING_HERO;
3211 if (one_in_(2)) break;
3212 o_ptr->name2 = EGO_RING_HUNTER;
3214 case SV_RING_SEARCHING:
3215 o_ptr->name2 = EGO_RING_STEALTH;
3217 case SV_RING_TELEPORTATION:
3218 o_ptr->name2 = EGO_RING_TELE_AWAY;
3220 case SV_RING_RES_BLINDNESS:
3222 o_ptr->name2 = EGO_RING_RES_LITE;
3224 o_ptr->name2 = EGO_RING_RES_DARK;
3226 case SV_RING_LORDLY:
3227 if (!one_in_(20)) break;
3228 one_lordly_high_resistance(o_ptr);
3229 one_lordly_high_resistance(o_ptr);
3230 o_ptr->name2 = EGO_RING_TRUE;
3232 case SV_RING_SUSTAIN:
3233 if (!one_in_(4)) break;
3234 o_ptr->name2 = EGO_RING_RES_TIME;
3236 case SV_RING_FLAMES:
3237 if (!one_in_(2)) break;
3238 o_ptr->name2 = EGO_RING_DRAGON_F;
3241 if (!one_in_(2)) break;
3242 o_ptr->name2 = EGO_RING_DRAGON_C;
3244 case SV_RING_WARNING:
3245 if (!one_in_(2)) break;
3246 o_ptr->name2 = EGO_RING_M_DETECT;
3254 o_ptr->curse_flags = 0L;
3256 else if ((power == -2) && one_in_(2))
3258 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3259 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3260 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3261 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3262 o_ptr->art_flags[0] = 0;
3263 o_ptr->art_flags[1] = 0;
3264 while(!o_ptr->name2)
3266 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3270 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3271 o_ptr->name2 = EGO_RING_DRAIN_EXP;
3274 o_ptr->name2 = EGO_RING_NO_MELEE;
3277 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3278 o_ptr->name2 = EGO_RING_AGGRAVATE;
3281 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3282 o_ptr->name2 = EGO_RING_TY_CURSE;
3285 o_ptr->name2 = EGO_RING_ALBINO;
3290 o_ptr->ident |= (IDENT_BROKEN);
3293 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3301 switch (o_ptr->sval)
3303 /* Amulet of wisdom/charisma */
3304 case SV_AMULET_INTELLIGENCE:
3305 case SV_AMULET_WISDOM:
3306 case SV_AMULET_CHARISMA:
3308 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
3314 o_ptr->ident |= (IDENT_BROKEN);
3317 o_ptr->curse_flags |= (TRC_CURSED);
3319 /* Reverse bonuses */
3320 o_ptr->pval = 0 - o_ptr->pval;
3326 /* Amulet of brilliance */
3327 case SV_AMULET_BRILLIANCE:
3329 o_ptr->pval = 1 + m_bonus(3, level);
3330 if (one_in_(4)) o_ptr->pval++;
3336 o_ptr->ident |= (IDENT_BROKEN);
3339 o_ptr->curse_flags |= (TRC_CURSED);
3341 /* Reverse bonuses */
3342 o_ptr->pval = 0 - o_ptr->pval;
3348 case SV_AMULET_NO_MAGIC: case SV_AMULET_NO_TELE:
3352 o_ptr->curse_flags |= (TRC_CURSED);
3357 case SV_AMULET_RESISTANCE:
3359 if (one_in_(5)) one_high_resistance(o_ptr);
3360 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_RES_POIS);
3364 /* Amulet of searching */
3365 case SV_AMULET_SEARCHING:
3367 o_ptr->pval = randint1(2) + (PARAMETER_VALUE)m_bonus(4, level);
3373 o_ptr->ident |= (IDENT_BROKEN);
3376 o_ptr->curse_flags |= (TRC_CURSED);
3378 /* Reverse bonuses */
3379 o_ptr->pval = 0 - (o_ptr->pval);
3385 /* Amulet of the Magi -- never cursed */
3386 case SV_AMULET_THE_MAGI:
3388 o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
3389 o_ptr->to_a = randint1(5) + (ARMOUR_CLASS)m_bonus(5, level);
3391 /* gain one low ESP */
3392 add_esp_weak(o_ptr, FALSE);
3397 /* Amulet of Doom -- always cursed */
3398 case SV_AMULET_DOOM:
3401 o_ptr->ident |= (IDENT_BROKEN);
3404 o_ptr->curse_flags |= (TRC_CURSED);
3407 o_ptr->pval = 0 - (randint1(5) + (PARAMETER_VALUE)m_bonus(5, level));
3408 o_ptr->to_a = 0 - (randint1(5) + (ARMOUR_CLASS)m_bonus(5, level));
3409 if (power > 0) power = 0 - power;
3414 case SV_AMULET_MAGIC_MASTERY:
3416 o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(4, level);
3422 o_ptr->ident |= (IDENT_BROKEN);
3425 o_ptr->curse_flags |= (TRC_CURSED);
3427 /* Reverse bonuses */
3428 o_ptr->pval = 0 - o_ptr->pval;
3434 if ((one_in_(150) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
3435 || (power > 2)) /* power > 2 is debug only */
3437 o_ptr->pval = MIN(o_ptr->pval, 4);
3438 /* Randart amulet */
3439 become_random_artifact(o_ptr, FALSE);
3441 else if ((power == 2) && one_in_(2))
3443 while(!o_ptr->name2)
3445 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3446 switch(randint1(21))
3449 if (have_flag(k_ptr->flags, TR_SLOW_DIGEST)) break;
3450 o_ptr->name2 = EGO_AMU_SLOW_D;
3453 if (o_ptr->pval) break;
3454 o_ptr->name2 = EGO_AMU_INFRA;
3457 if (have_flag(k_ptr->flags, TR_SEE_INVIS)) break;
3458 o_ptr->name2 = EGO_AMU_SEE_INVIS;
3461 if (have_flag(k_ptr->flags, TR_HOLD_EXP)) break;
3462 o_ptr->name2 = EGO_AMU_HOLD_EXP;
3465 if (have_flag(k_ptr->flags, TR_LEVITATION)) break;
3466 o_ptr->name2 = EGO_AMU_LEVITATION;
3468 case 10: case 11: case 21:
3469 o_ptr->name2 = EGO_AMU_AC;
3472 if (have_flag(k_ptr->flags, TR_RES_FIRE)) break;
3473 if (m_bonus(10, level) > 8)
3474 o_ptr->name2 = EGO_AMU_RES_FIRE_;
3476 o_ptr->name2 = EGO_AMU_RES_FIRE;
3479 if (have_flag(k_ptr->flags, TR_RES_COLD)) break;
3480 if (m_bonus(10, level) > 8)
3481 o_ptr->name2 = EGO_AMU_RES_COLD_;
3483 o_ptr->name2 = EGO_AMU_RES_COLD;
3486 if (have_flag(k_ptr->flags, TR_RES_ELEC)) break;
3487 if (m_bonus(10, level) > 8)
3488 o_ptr->name2 = EGO_AMU_RES_ELEC_;
3490 o_ptr->name2 = EGO_AMU_RES_ELEC;
3493 if (have_flag(k_ptr->flags, TR_RES_ACID)) break;
3494 if (m_bonus(10, level) > 8)
3495 o_ptr->name2 = EGO_AMU_RES_ACID_;
3497 o_ptr->name2 = EGO_AMU_RES_ACID;
3499 case 16: case 17: case 18: case 19: case 20:
3500 switch (o_ptr->sval)
3502 case SV_AMULET_TELEPORT:
3503 if (m_bonus(10, level) > 9) o_ptr->name2 = EGO_AMU_D_DOOR;
3504 else if (one_in_(2)) o_ptr->name2 = EGO_AMU_JUMP;
3505 else o_ptr->name2 = EGO_AMU_TELEPORT;
3507 case SV_AMULET_RESIST_ACID:
3508 if ((m_bonus(10, level) > 6) && one_in_(2)) o_ptr->name2 = EGO_AMU_RES_ACID_;
3510 case SV_AMULET_SEARCHING:
3511 o_ptr->name2 = EGO_AMU_STEALTH;
3513 case SV_AMULET_BRILLIANCE:
3514 if (!one_in_(3)) break;
3515 o_ptr->name2 = EGO_AMU_IDENT;
3517 case SV_AMULET_CHARISMA:
3518 if (!one_in_(3)) break;
3519 o_ptr->name2 = EGO_AMU_CHARM;
3521 case SV_AMULET_THE_MAGI:
3522 if (one_in_(2)) break;
3523 o_ptr->name2 = EGO_AMU_GREAT;
3525 case SV_AMULET_RESISTANCE:
3526 if (!one_in_(5)) break;
3527 o_ptr->name2 = EGO_AMU_DEFENDER;
3529 case SV_AMULET_TELEPATHY:
3530 if (!one_in_(3)) break;
3531 o_ptr->name2 = EGO_AMU_DETECTION;
3536 o_ptr->curse_flags = 0L;
3538 else if ((power == -2) && one_in_(2))
3540 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3541 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3542 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3543 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3544 o_ptr->art_flags[0] = 0;
3545 o_ptr->art_flags[1] = 0;
3546 while(!o_ptr->name2)
3548 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3552 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3553 o_ptr->name2 = EGO_AMU_DRAIN_EXP;
3556 o_ptr->name2 = EGO_AMU_FOOL;
3559 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3560 o_ptr->name2 = EGO_AMU_AGGRAVATE;
3563 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3564 o_ptr->name2 = EGO_AMU_TY_CURSE;
3567 o_ptr->name2 = EGO_AMU_NAIVETY;
3572 o_ptr->ident |= (IDENT_BROKEN);
3575 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3584 * @brief その他雑多のオブジェクトに生成ランクごとの強化を与えるサブルーチン
3585 * Apply magic to an item known to be "boring"
3586 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3587 * @param level 生成基準階
3588 * @param power 生成ランク
3591 * Hack -- note the special code for various items
3593 static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
3595 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3600 /* Apply magic (good or bad) according to type */
3601 switch (o_ptr->tval)
3610 o_ptr->ident |= (IDENT_BROKEN);
3613 o_ptr->curse_flags |= (TRC_CURSED);
3620 o_ptr->xtra4 = o_ptr->pval;
3626 /* Hack -- Torches -- random fuel */
3627 if (o_ptr->sval == SV_LITE_TORCH)
3629 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3633 /* Hack -- Lanterns -- random fuel */
3634 if (o_ptr->sval == SV_LITE_LANTERN)
3636 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3640 if (power > 2) /* power > 2 is debug only */
3642 become_random_artifact(o_ptr, FALSE);
3644 else if ((power == 2) || ((power == 1) && one_in_(3)))
3646 while (!o_ptr->name2)
3650 bool okay_flag = TRUE;
3652 o_ptr->name2 = get_random_ego(INVEN_LITE, TRUE);
3654 switch (o_ptr->name2)
3657 if (o_ptr->sval == SV_LITE_FEANOR)
3665 else if (power == -2)
3667 o_ptr->name2 = get_random_ego(INVEN_LITE, FALSE);
3669 switch (o_ptr->name2)
3671 case EGO_LITE_DARKNESS:
3674 if (o_ptr->sval == SV_LITE_TORCH)
3676 add_flag(o_ptr->art_flags, TR_LITE_M1);
3678 else if (o_ptr->sval == SV_LITE_LANTERN)
3680 add_flag(o_ptr->art_flags, TR_LITE_M2);
3682 else if (o_ptr->sval == SV_LITE_FEANOR)
3684 add_flag(o_ptr->art_flags, TR_LITE_M3);
3696 /* The wand or staff gets a number of initial charges equal
3697 * to between 1/2 (+1) and the full object kind's pval. -LM-
3699 o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
3705 /* Transfer the pval. -LM- */
3706 o_ptr->pval = k_ptr->pval;
3713 object_aware(o_ptr);
3714 object_known(o_ptr);
3720 PARAMETER_VALUE i = 1;
3723 monster_race *r_ptr;
3725 /* Pick a random non-unique monster race */
3728 i = randint1(max_r_idx - 1);
3730 if (!item_monster_okay(i)) continue;
3731 if (i == MON_TSUCHINOKO) continue;
3735 check = (p_ptr->current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - p_ptr->current_floor_ptr->dun_level) : 0;
3737 /* Ignore dead monsters */
3738 if (!r_ptr->rarity) continue;
3740 /* Ignore uncommon monsters */
3741 if (r_ptr->rarity > 100) continue;
3743 /* Prefer less out-of-depth monsters */
3744 if (randint0(check)) continue;
3751 /* Some figurines are cursed */
3752 if (one_in_(6)) o_ptr->curse_flags |= TRC_CURSED;
3759 PARAMETER_VALUE i = 1;
3764 monster_race *r_ptr;
3766 if (o_ptr->sval == SV_SKELETON)
3768 match = RF9_DROP_SKELETON;
3770 else if (o_ptr->sval == SV_CORPSE)
3772 match = RF9_DROP_CORPSE;
3775 /* Hack -- Remove the monster restriction */
3776 get_mon_num_prep(item_monster_okay, NULL);
3778 /* Pick a random non-unique monster race */
3781 i = get_mon_num(p_ptr->current_floor_ptr->dun_level);
3785 check = (p_ptr->current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - p_ptr->current_floor_ptr->dun_level) : 0;
3787 /* Ignore dead monsters */
3788 if (!r_ptr->rarity) continue;
3790 /* Ignore corpseless monsters */
3791 if (!(r_ptr->flags9 & match)) continue;
3793 /* Prefer less out-of-depth monsters */
3794 if (randint0(check)) continue;
3802 object_aware(o_ptr);
3803 object_known(o_ptr);
3809 PARAMETER_VALUE i = 1;
3811 monster_race *r_ptr;
3813 /* Pick a random monster race */
3816 i = randint1(max_r_idx - 1);
3820 /* Ignore dead monsters */
3821 if (!r_ptr->rarity) continue;
3830 msg_format(_("%sの像", "Statue of %s"), r_name + r_ptr->name);
3832 object_aware(o_ptr);
3833 object_known(o_ptr);
3840 DEPTH obj_level = k_info[o_ptr->k_idx].level;
3842 /* Hack -- skip ruined chests */
3843 if (obj_level <= 0) break;
3845 /* Hack -- pick a "difficulty" */
3846 o_ptr->pval = randint1(obj_level);
3847 if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
3849 o_ptr->xtra3 = p_ptr->current_floor_ptr->dun_level + 5;
3851 /* Never exceed "difficulty" of 55 to 59 */
3852 if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
3860 * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
3861 * Complete the "creation" of an object by applying "magic" to the item
3862 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
3864 * @param mode 生成オプション
3867 * This includes not only rolling for random bonuses, but also putting the\n
3868 * finishing touches on ego-items and artifacts, giving charges to wands and\n
3869 * staffs, giving fuel to lites, and placing traps on chests.\n
3871 * In particular, note that "Instant Artifacts", if "created" by an external\n
3872 * routine, must pass through this function to complete the actual creation.\n
3874 * The base "chance" of the item being "good" increases with the "level"\n
3875 * parameter, which is usually derived from the dungeon level, being equal\n
3876 * to the level plus 10, up to a maximum of 75. If "good" is true, then\n
3877 * the object is guaranteed to be "good". If an object is "good", then\n
3878 * the chance that the object will be "great" (ego-item or artifact), also\n
3879 * increases with the "level", being equal to half the level, plus 5, up to\n
3880 * a maximum of 20. If "great" is true, then the object is guaranteed to be\n
3881 * "great". At dungeon level 65 and below, 15/100 objects are "great".\n
3883 * If the object is not "good", there is a chance it will be "cursed", and\n
3884 * if it is "cursed", there is a chance it will be "broken". These chances\n
3885 * are related to the "good" / "great" chances above.\n
3887 * Otherwise "normal" rings and amulets will be "good" half the time and\n
3888 * "cursed" half the time, unless the ring/amulet is always good or cursed.\n
3890 * If "okay" is true, and the object is going to be "great", then there is\n
3891 * a chance that an artifact will be created. This is true even if both the\n
3892 * "good" and "great" arguments are false. As a total hack, if "great" is\n
3893 * true, then the item gets 3 extra "attempts" to become an artifact.\n
3895 void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
3897 int i, rolls, f1, f2, power;
3899 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) lev += randint0(p_ptr->lev/2+10);
3901 /* Maximum "level" for various things */
3902 if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1;
3904 /* Base chance of being "good" */
3907 /* Maximal chance of being "good" */
3908 if (f1 > d_info[p_ptr->dungeon_idx].obj_good) f1 = d_info[p_ptr->dungeon_idx].obj_good;
3910 /* Base chance of being "great" */
3913 /* Maximal chance of being "great" */
3914 if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[p_ptr->dungeon_idx].obj_great))
3915 f2 = d_info[p_ptr->dungeon_idx].obj_great;
3917 if (p_ptr->muta3 & MUT3_GOOD_LUCK)
3922 else if(p_ptr->muta3 & MUT3_BAD_LUCK)
3931 /* Roll for "good" */
3932 if ((mode & AM_GOOD) || magik(f1))
3937 /* Roll for "great" */
3938 if ((mode & AM_GREAT) || magik(f2))
3942 /* Roll for "special" */
3943 if (mode & AM_SPECIAL) power = 3;
3947 /* Roll for "cursed" */
3950 /* Assume "cursed" */
3953 /* Roll for "broken" */
3954 if (magik(f2)) power = -2;
3958 if (mode & AM_CURSED)
3960 /* Assume 'cursed' */
3965 /* Everything else gets more badly cursed */
3972 /* Assume no rolls */
3975 /* Get one roll if excellent */
3976 if (power >= 2) rolls = 1;
3978 /* Hack -- Get four rolls if forced great or special */
3979 if (mode & (AM_GREAT | AM_SPECIAL)) rolls = 4;
3981 /* Hack -- Get no rolls if not allowed */
3982 if ((mode & AM_NO_FIXED_ART) || o_ptr->name1) rolls = 0;
3984 /* Roll for artifacts if allowed */
3985 for (i = 0; i < rolls; i++)
3987 /* Roll for an artifact */
3988 if (make_artifact(o_ptr)) break;
3989 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77))
3991 if (make_artifact(o_ptr)) break;
3996 /* Hack -- analyze artifacts */
3997 if (object_is_fixed_artifact(o_ptr))
3999 artifact_type *a_ptr = &a_info[o_ptr->name1];
4001 /* Hack -- Mark the artifact as "created" */
4004 /* Hack -- Memorize location of artifact in saved floors */
4005 if (current_world_ptr->character_dungeon)
4006 a_ptr->floor_id = p_ptr->floor_id;
4008 /* Extract the other fields */
4009 o_ptr->pval = a_ptr->pval;
4010 o_ptr->ac = a_ptr->ac;
4011 o_ptr->dd = a_ptr->dd;
4012 o_ptr->ds = a_ptr->ds;
4013 o_ptr->to_a = a_ptr->to_a;
4014 o_ptr->to_h = a_ptr->to_h;
4015 o_ptr->to_d = a_ptr->to_d;
4016 o_ptr->weight = a_ptr->weight;
4017 o_ptr->xtra2 = a_ptr->act_idx;
4019 if (o_ptr->name1 == ART_MILIM)
4021 if(p_ptr->pseikaku == SEIKAKU_SEXY)
4027 /* Hack -- extract the "broken" flag */
4028 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4030 /* Hack -- extract the "cursed" flag */
4031 if (a_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4032 if (a_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4033 if (a_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4034 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4035 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4036 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4041 switch (o_ptr->tval)
4050 if (power) apply_magic_weapon(o_ptr, lev, power);
4056 if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) apply_magic_weapon(o_ptr, lev, power);
4062 if (power && !(o_ptr->sval == SV_DOKUBARI)) apply_magic_weapon(o_ptr, lev, power);
4076 /* Elven Cloak and Black Clothes ... */
4077 if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) ||
4078 ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
4079 o_ptr->pval = randint1(4);
4083 ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) ||
4084 ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD)) ||
4085 ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)) ||
4086 ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
4087 a_m_aux_2(o_ptr, lev, power);
4089 if (power) a_m_aux_2(o_ptr, lev, power);
4097 if (!power && (randint0(100) < 50)) power = -1;
4098 a_m_aux_3(o_ptr, lev, power);
4104 a_m_aux_4(o_ptr, lev, power);
4109 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
4110 (o_ptr->sval == SV_ABUNAI_MIZUGI) &&
4111 (p_ptr->pseikaku == SEIKAKU_SEXY))
4114 add_flag(o_ptr->art_flags, TR_STR);
4115 add_flag(o_ptr->art_flags, TR_INT);
4116 add_flag(o_ptr->art_flags, TR_WIS);
4117 add_flag(o_ptr->art_flags, TR_DEX);
4118 add_flag(o_ptr->art_flags, TR_CON);
4119 add_flag(o_ptr->art_flags, TR_CHR);
4122 /* Hack -- analyze ego-items */
4123 if (object_is_ego(o_ptr))
4125 ego_item_type *e_ptr = &e_info[o_ptr->name2];
4127 /* Hack -- acquire "broken" flag */
4128 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4130 /* Hack -- acquire "cursed" flag */
4131 if (e_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4132 if (e_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4133 if (e_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4134 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4135 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4136 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4138 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN)) one_sustain(o_ptr);
4139 if (e_ptr->gen_flags & (TRG_XTRA_POWER)) one_ability(o_ptr);
4140 if (e_ptr->gen_flags & (TRG_XTRA_H_RES)) one_high_resistance(o_ptr);
4141 if (e_ptr->gen_flags & (TRG_XTRA_E_RES)) one_ele_resistance(o_ptr);
4142 if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
4143 if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
4144 if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
4145 if (e_ptr->gen_flags & (TRG_XTRA_DICE))
4151 while (one_in_(o_ptr->dd));
4153 if (o_ptr->dd > 9) o_ptr->dd = 9;
4156 /* Hack -- apply activatin index if needed */
4157 if (e_ptr->act_idx) o_ptr->xtra2 = (XTRA8)e_ptr->act_idx;
4159 /* Hack -- apply extra penalties if needed */
4160 if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL)))
4162 /* Hack -- obtain bonuses */
4163 if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
4164 if (e_ptr->max_to_d) o_ptr->to_d -= randint1(e_ptr->max_to_d);
4165 if (e_ptr->max_to_a) o_ptr->to_a -= randint1(e_ptr->max_to_a);
4167 /* Hack -- obtain pval */
4168 if (e_ptr->max_pval) o_ptr->pval -= randint1(e_ptr->max_pval);
4171 /* Hack -- apply extra bonuses if needed */
4174 /* Hack -- obtain bonuses */
4175 if (e_ptr->max_to_h)
4177 if (e_ptr->max_to_h > 127)
4178 o_ptr->to_h -= randint1(256-e_ptr->max_to_h);
4179 else o_ptr->to_h += randint1(e_ptr->max_to_h);
4181 if (e_ptr->max_to_d)
4183 if (e_ptr->max_to_d > 127)
4184 o_ptr->to_d -= randint1(256-e_ptr->max_to_d);
4185 else o_ptr->to_d += randint1(e_ptr->max_to_d);
4187 if (e_ptr->max_to_a)
4189 if (e_ptr->max_to_a > 127)
4190 o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
4191 else o_ptr->to_a += randint1(e_ptr->max_to_a);
4194 /* Accuracy ego must have high to_h */
4195 if(o_ptr->name2 == EGO_ACCURACY)
4197 while(o_ptr->to_h < o_ptr->to_d + 10)
4202 o_ptr->to_h = MAX(o_ptr->to_h, 15);
4205 /* Accuracy ego must have high to_h */
4206 if(o_ptr->name2 == EGO_VELOCITY)
4208 while(o_ptr->to_d < o_ptr->to_h + 10)
4213 o_ptr->to_d = MAX(o_ptr->to_d, 15);
4216 /* Protection ego must have high to_a */
4217 if((o_ptr->name2 == EGO_PROTECTION) || (o_ptr->name2 == EGO_S_PROTECTION) || (o_ptr->name2 == EGO_H_PROTECTION))
4219 o_ptr->to_a = MAX(o_ptr->to_a, 15);
4222 /* Hack -- obtain pval */
4223 if (e_ptr->max_pval)
4225 if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS)))
4228 if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
4230 else if (o_ptr->name2 == EGO_DEMON)
4232 if(have_flag(o_ptr->art_flags, TR_BLOWS))
4234 o_ptr->pval += randint1(2);
4238 o_ptr->pval += randint1(e_ptr->max_pval);
4241 else if (o_ptr->name2 == EGO_ATTACKS)
4243 o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
4244 if (o_ptr->pval > 3) o_ptr->pval = 3;
4245 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
4246 o_ptr->pval += randint1(2);
4248 else if (o_ptr->name2 == EGO_BAT)
4250 o_ptr->pval = randint1(e_ptr->max_pval);
4251 if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
4253 else if (o_ptr->name2 == EGO_A_DEMON || o_ptr->name2 == EGO_DRUID || o_ptr->name2 == EGO_OLOG)
4255 o_ptr->pval = randint1(e_ptr->max_pval);
4259 o_ptr->pval += randint1(e_ptr->max_pval);
4264 if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
4266 o_ptr->pval = randint1(o_ptr->pval);
4268 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
4275 /* Examine real objects */
4278 object_kind *k_ptr = &k_info[o_ptr->k_idx];
4280 /* Hack -- acquire "broken" flag */
4281 if (!k_info[o_ptr->k_idx].cost) o_ptr->ident |= (IDENT_BROKEN);
4283 /* Hack -- acquire "cursed" flag */
4284 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
4285 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
4286 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
4287 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4288 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4289 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4297 * @brief 生成階に応じたベースアイテムの生成を行う。
4298 * Attempt to make an object (normal or good/great)
4299 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4300 * @param mode オプションフラグ
4301 * @return 生成に成功したらTRUEを返す。
4303 * This routine plays nasty games to generate the "special artifacts".\n
4304 * This routine uses "p_ptr->current_floor_ptr->object_level" for the "generation level".\n
4305 * We assume that the given object has been "wiped".\n
4307 bool make_object(object_type *j_ptr, BIT_FLAGS mode)
4313 /* Chance of "special object" */
4314 prob = ((mode & AM_GOOD) ? 10 : 1000);
4316 /* Base level for the object */
4317 base = ((mode & AM_GOOD) ? (p_ptr->current_floor_ptr->object_level + 10) : p_ptr->current_floor_ptr->object_level);
4320 /* Generate a special object, or a normal object */
4321 if (!one_in_(prob) || !make_artifact_special(j_ptr))
4323 KIND_OBJECT_IDX k_idx;
4326 if ((mode & AM_GOOD) && !get_obj_num_hook)
4328 /* Activate restriction (if already specified, use that) */
4329 get_obj_num_hook = kind_is_good;
4332 /* Restricted objects - prepare allocation table */
4333 if (get_obj_num_hook) get_obj_num_prep();
4335 /* Pick a random object */
4336 k_idx = get_obj_num(base, mode);
4338 /* Restricted objects */
4339 if (get_obj_num_hook)
4341 /* Clear restriction */
4342 get_obj_num_hook = NULL;
4344 /* Reset allocation table to default */
4348 /* Handle failure */
4349 if (!k_idx) return (FALSE);
4351 /* Prepare the object */
4352 object_prep(j_ptr, k_idx);
4355 /* Apply magic (allow artifacts) */
4356 apply_magic(j_ptr, p_ptr->current_floor_ptr->object_level, mode);
4358 /* Hack -- generate multiple spikes/missiles */
4359 switch (j_ptr->tval)
4367 j_ptr->number = (byte)damroll(6, 7);
4371 if (cheat_peek) object_mention(j_ptr);
4379 * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
4380 * Attempt to place an object (normal or good/great) at the given location.
4381 * @param y 配置したいフロアのY座標
4382 * @param x 配置したいフロアのX座標
4383 * @param mode オプションフラグ
4384 * @return 生成に成功したらTRUEを返す。
4386 * This routine plays nasty games to generate the "special artifacts".\n
4387 * This routine uses "p_ptr->current_floor_ptr->object_level" for the "generation level".\n
4388 * This routine requires a clean floor grid destination.\n
4390 void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
4395 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
4401 /* Paranoia -- check bounds */
4402 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
4404 /* Require floor space */
4405 if (!cave_drop_bold(y, x)) return;
4407 /* Avoid stacking on other objects */
4408 if (g_ptr->o_idx) return;
4413 /* Make an object (if possible) */
4414 if (!make_object(q_ptr, mode)) return;
4422 o_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
4424 /* Structure Copy */
4425 object_copy(o_ptr, q_ptr);
4431 o_ptr->next_o_idx = g_ptr->o_idx;
4433 g_ptr->o_idx = o_idx;
4439 /* Hack -- Preserve artifacts */
4440 if (object_is_fixed_artifact(q_ptr))
4442 a_info[q_ptr->name1].cur_num = 0;
4448 OBJECT_SUBTYPE_VALUE coin_type; /* Hack -- force coin type */
4451 * @brief 生成階に応じた財宝オブジェクトの生成を行う。
4452 * Make a treasure object
4453 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
4454 * @return 生成に成功したらTRUEを返す。
4456 * The location must be a legal, clean, floor grid.
4458 bool make_gold(object_type *j_ptr)
4463 /* Hack -- Pick a Treasure variety */
4464 i = ((randint1(p_ptr->current_floor_ptr->object_level + 2) + 2) / 2) - 1;
4466 /* Apply "extra" magic */
4467 if (one_in_(GREAT_OBJ))
4469 i += randint1(p_ptr->current_floor_ptr->object_level + 1);
4472 /* Hack -- Creeping Coins only generate "themselves" */
4473 if (coin_type) i = coin_type;
4475 /* Do not create "illegal" Treasure Types */
4476 if (i >= MAX_GOLD) i = MAX_GOLD - 1;
4478 /* Prepare a gold object */
4479 object_prep(j_ptr, OBJ_GOLD_LIST + i);
4481 /* Hack -- Base coin cost */
4482 base = k_info[OBJ_GOLD_LIST + i].cost;
4484 /* Determine how much the treasure is "worth" */
4485 j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
4493 * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
4494 * Places a treasure (Gold or Gems) at given location
4495 * @param y 配置したいフロアのY座標
4496 * @param x 配置したいフロアのX座標
4497 * @return 生成に成功したらTRUEを返す。
4499 * The location must be a legal, clean, floor grid.
4501 void place_gold(POSITION y, POSITION x)
4506 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
4512 /* Paranoia -- check bounds */
4513 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
4515 /* Require floor space */
4516 if (!cave_drop_bold(y, x)) return;
4518 /* Avoid stacking on other objects */
4519 if (g_ptr->o_idx) return;
4524 /* Make some gold */
4525 if (!make_gold(q_ptr)) return;
4533 o_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
4534 object_copy(o_ptr, q_ptr);
4541 o_ptr->next_o_idx = g_ptr->o_idx;
4543 g_ptr->o_idx = o_idx;
4551 * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
4552 * Let an object fall to the ground at or near a location.
4553 * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
4554 * @param chance ドロップの消滅率(%)
4555 * @param y 配置したいフロアのY座標
4556 * @param x 配置したいフロアのX座標
4557 * @return 生成に成功したらオブジェクトのIDを返す。
4559 * The initial location is assumed to be "in_bounds(p_ptr->current_floor_ptr, )".\n
4561 * This function takes a parameter "chance". This is the percentage\n
4562 * chance that the item will "disappear" instead of drop. If the object\n
4563 * has been thrown, then this is the chance of disappearance on contact.\n
4565 * Hack -- this function uses "chance" to determine if it should produce\n
4566 * some form of "description" of the drop event (under the player).\n
4568 * We check several locations to see if we can find a location at which\n
4569 * the object can combine, stack, or be placed. Artifacts will try very\n
4570 * hard to be placed, including "teleporting" to a useful grid if needed.\n
4572 OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
4579 POSITION ty, tx = 0;
4581 OBJECT_IDX o_idx = 0;
4582 OBJECT_IDX this_o_idx, next_o_idx = 0;
4586 GAME_TEXT o_name[MAX_NLEN];
4592 /* Extract plural */
4593 bool plural = (j_ptr->number != 1);
4596 /* Describe object */
4597 object_desc(o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4600 /* Handle normal "breakage" */
4601 if (!object_is_artifact(j_ptr) && (randint0(100) < chance))
4604 msg_format("%sは消えた。", o_name);
4606 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4608 if (current_world_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
4625 /* Scan local grids */
4626 for (dy = -3; dy <= 3; dy++)
4628 /* Scan local grids */
4629 for (dx = -3; dx <= 3; dx++)
4633 /* Calculate actual distance */
4634 d = (dy * dy) + (dx * dx);
4636 /* Ignore distant grids */
4637 if (d > 10) continue;
4642 if (!in_bounds(p_ptr->current_floor_ptr, ty, tx)) continue;
4644 /* Require line of projection */
4645 if (!projectable(y, x, ty, tx)) continue;
4648 g_ptr = &p_ptr->current_floor_ptr->grid_array[ty][tx];
4650 /* Require floor space */
4651 if (!cave_drop_bold(ty, tx)) continue;
4656 /* Scan objects in that grid */
4657 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4660 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
4661 next_o_idx = o_ptr->next_o_idx;
4663 /* Check for possible combination */
4664 if (object_similar(o_ptr, j_ptr)) comb = TRUE;
4670 /* Add new object */
4672 if (k > 99) continue;
4674 /* Calculate score */
4675 s = 1000 - (d + k * 5);
4677 /* Skip bad values */
4678 if (s < bs) continue;
4680 /* New best value */
4683 /* Apply the randomizer to equivalent values */
4684 if ((++bn >= 2) && !one_in_(bn)) continue;
4698 /* Handle lack of space */
4699 if (!flag && !object_is_artifact(j_ptr))
4702 msg_format("%sは消えた。", o_name);
4704 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4707 if (current_world_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4715 for (i = 0; !flag && (i < 1000); i++)
4718 ty = rand_spread(by, 1);
4719 tx = rand_spread(bx, 1);
4721 if (!in_bounds(p_ptr->current_floor_ptr, ty, tx)) continue;
4723 /* Bounce to that location */
4727 /* Require floor space */
4728 if (!cave_drop_bold(by, bx)) continue;
4736 int candidates = 0, pick;
4738 for (ty = 1; ty < p_ptr->current_floor_ptr->height - 1; ty++)
4740 for (tx = 1; tx < p_ptr->current_floor_ptr->width - 1; tx++)
4742 /* A valid space found */
4743 if (cave_drop_bold(ty, tx)) candidates++;
4747 /* No valid place! */
4751 msg_format("%sは消えた。", o_name);
4753 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4756 if (current_world_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
4758 /* Mega-Hack -- preserve artifacts */
4761 /* Hack -- Preserve unknown artifacts */
4762 if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr))
4764 /* Mega-Hack -- Preserve the artifact */
4765 a_info[j_ptr->name1].cur_num = 0;
4773 /* Choose a random one */
4774 pick = randint1(candidates);
4776 for (ty = 1; ty < p_ptr->current_floor_ptr->height - 1; ty++)
4778 for (tx = 1; tx < p_ptr->current_floor_ptr->width - 1; tx++)
4780 if (cave_drop_bold(ty, tx))
4784 /* Is this a picked one? */
4797 g_ptr = &p_ptr->current_floor_ptr->grid_array[by][bx];
4799 /* Scan objects in that grid for combination */
4800 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4803 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
4804 next_o_idx = o_ptr->next_o_idx;
4806 /* Check for combination */
4807 if (object_similar(o_ptr, j_ptr))
4809 object_absorb(o_ptr, j_ptr);
4818 if (!done) o_idx = o_pop();
4821 if (!done && !o_idx)
4824 msg_format("%sは消えた。", o_name);
4826 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
4829 if (current_world_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
4831 /* Hack -- Preserve artifacts */
4832 if (object_is_fixed_artifact(j_ptr))
4834 a_info[j_ptr->name1].cur_num = 0;
4844 /* Structure copy */
4845 object_copy(&p_ptr->current_floor_ptr->o_list[o_idx], j_ptr);
4847 /* Access new object */
4848 j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
4855 j_ptr->held_m_idx = 0;
4858 j_ptr->next_o_idx = g_ptr->o_idx;
4860 g_ptr->o_idx = o_idx;
4870 /* Mega-Hack -- no message if "dropped" by player */
4871 /* Message when an object falls under the player */
4872 if (chance && player_bold(by, bx))
4874 msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
4881 * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
4882 * Describe the charges on an item in the p_ptr->inventory_list.
4883 * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4886 void inven_item_charges(INVENTORY_IDX item)
4888 object_type *o_ptr = &p_ptr->inventory_list[item];
4890 /* Require staff/wand */
4891 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
4893 /* Require known item */
4894 if (!object_is_known(o_ptr)) return;
4897 if (o_ptr->pval <= 0)
4899 msg_print("もう魔力が残っていない。");
4903 msg_format("あと %d 回分の魔力が残っている。", o_ptr->pval);
4906 /* Multiple charges */
4907 if (o_ptr->pval != 1)
4909 msg_format("You have %d charges remaining.", o_ptr->pval);
4915 msg_format("You have %d charge remaining.", o_ptr->pval);
4922 * @brief アイテムの残り所持数メッセージを表示する /
4923 * Describe an item in the p_ptr->inventory_list.
4924 * @param item 残量を表示したいプレイヤーのアイテム所持スロット
4927 void inven_item_describe(INVENTORY_IDX item)
4929 object_type *o_ptr = &p_ptr->inventory_list[item];
4930 GAME_TEXT o_name[MAX_NLEN];
4932 object_desc(o_name, o_ptr, 0);
4935 /* "no more" の場合はこちらで表示する */
4936 if (o_ptr->number <= 0)
4938 /*FIRST*//*ここはもう通らないかも */
4939 msg_format("もう%sを持っていない。", o_name);
4943 /* アイテム名を英日切り替え機能対応 */
4944 msg_format("まだ %sを持っている。", o_name);
4947 msg_format("You have %s.", o_name);
4953 * @brief アイテムを増減させ残り所持数メッセージを表示する /
4954 * Increase the "number" of an item in the p_ptr->inventory_list
4955 * @param item 所持数を増やしたいプレイヤーのアイテム所持スロット
4959 void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
4961 object_type *o_ptr = &p_ptr->inventory_list[item];
4964 num += o_ptr->number;
4967 if (num > 255) num = 255;
4968 else if (num < 0) num = 0;
4971 num -= o_ptr->number;
4973 /* Change the number and weight */
4976 /* Add the number */
4977 o_ptr->number += num;
4979 /* Add the weight */
4980 p_ptr->total_weight += (num * o_ptr->weight);
4981 p_ptr->update |= (PU_BONUS);
4982 p_ptr->update |= (PU_MANA);
4983 p_ptr->update |= (PU_COMBINE);
4984 p_ptr->window |= (PW_INVEN | PW_EQUIP);
4986 /* Hack -- Clear temporary elemental brands if player takes off weapons */
4987 if (!o_ptr->number && p_ptr->ele_attack)
4989 if ((item == INVEN_RARM) || (item == INVEN_LARM))
4991 if (!has_melee_weapon(p_ptr, INVEN_RARM + INVEN_LARM - item))
4993 /* Clear all temporary elemental brands */
4994 set_ele_attack(p_ptr, 0, 0);
5002 * @brief 所持アイテムスロットから所持数のなくなったアイテムを消去する /
5003 * Erase an p_ptr->inventory_list slot if it has no more items
5004 * @param item 消去したいプレイヤーのアイテム所持スロット
5007 void inven_item_optimize(INVENTORY_IDX item)
5009 object_type *o_ptr = &p_ptr->inventory_list[item];
5011 /* Only optimize real items */
5012 if (!o_ptr->k_idx) return;
5014 /* Only optimize empty items */
5015 if (o_ptr->number) return;
5017 /* The item is in the pack */
5018 if (item < INVEN_RARM)
5025 /* Slide everything down */
5026 for (i = item; i < INVEN_PACK; i++)
5028 /* Structure copy */
5029 p_ptr->inventory_list[i] = p_ptr->inventory_list[i+1];
5032 /* Erase the "final" slot */
5033 object_wipe(&p_ptr->inventory_list[i]);
5035 p_ptr->window |= (PW_INVEN);
5038 /* The item is being wielded */
5044 /* Erase the empty slot */
5045 object_wipe(&p_ptr->inventory_list[item]);
5046 p_ptr->update |= (PU_BONUS);
5047 p_ptr->update |= (PU_TORCH);
5048 p_ptr->update |= (PU_MANA);
5050 p_ptr->window |= (PW_EQUIP);
5053 p_ptr->window |= (PW_SPELL);
5057 * @brief 床上の魔道具の残り残量メッセージを表示する /
5058 * Describe the charges on an item on the floor.
5059 * @param item メッセージの対象にしたいアイテム所持スロット
5062 void floor_item_charges(INVENTORY_IDX item)
5064 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
5066 /* Require staff/wand */
5067 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5069 /* Require known item */
5070 if (!object_is_known(o_ptr)) return;
5073 if (o_ptr->pval <= 0)
5075 msg_print("この床上のアイテムは、もう魔力が残っていない。");
5079 msg_format("この床上のアイテムは、あと %d 回分の魔力が残っている。", o_ptr->pval);
5082 /* Multiple charges */
5083 if (o_ptr->pval != 1)
5085 msg_format("There are %d charges remaining.", o_ptr->pval);
5091 msg_format("There is %d charge remaining.", o_ptr->pval);
5098 * @brief 床上のアイテムの残り数メッセージを表示する /
5099 * Describe the charges on an item on the floor.
5100 * @param item メッセージの対象にしたいアイテム所持スロット
5103 void floor_item_describe(INVENTORY_IDX item)
5105 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
5106 GAME_TEXT o_name[MAX_NLEN];
5108 object_desc(o_name, o_ptr, 0);
5111 /* "no more" の場合はこちらで表示を分ける */
5112 if (o_ptr->number <= 0)
5114 msg_format("床上には、もう%sはない。", o_name);
5118 msg_format("床上には、まだ %sがある。", o_name);
5121 msg_format("You see %s.", o_name);
5128 * @brief 床上のアイテムの数を増やす /
5129 * Increase the "number" of an item on the floor
5130 * @param item 増やしたいアイテムの所持スロット
5131 * @param num 増やしたいアイテムの数
5134 void floor_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
5136 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
5139 num += o_ptr->number;
5142 if (num > 255) num = 255;
5143 else if (num < 0) num = 0;
5146 num -= o_ptr->number;
5148 /* Change the number */
5149 o_ptr->number += num;
5154 * @brief 床上の数の無くなったアイテムスロットを消去する /
5155 * Optimize an item on the floor (destroy "empty" items)
5156 * @param item 消去したいアイテムの所持スロット
5159 void floor_item_optimize(INVENTORY_IDX item)
5161 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
5163 /* Paranoia -- be sure it exists */
5164 if (!o_ptr->k_idx) return;
5166 /* Only optimize empty items */
5167 if (o_ptr->number) return;
5169 delete_object_idx(item);
5174 * @brief アイテムを拾う際にザックから溢れずに済むかを判定する /
5175 * Check if we have space for an item in the pack without overflow
5176 * @param o_ptr 拾いたいオブジェクトの構造体参照ポインタ
5177 * @return 溢れずに済むならTRUEを返す
5179 bool inven_carry_okay(object_type *o_ptr)
5184 if (p_ptr->inven_cnt < INVEN_PACK) return (TRUE);
5187 for (j = 0; j < INVEN_PACK; j++)
5189 object_type *j_ptr = &p_ptr->inventory_list[j];
5190 if (!j_ptr->k_idx) continue;
5192 /* Check if the two items can be combined */
5193 if (object_similar(j_ptr, o_ptr)) return (TRUE);
5200 * @brief オブジェクトを定義された基準に従いソートするための関数 /
5201 * Check if we have space for an item in the pack without overflow
5202 * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
5203 * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
5204 * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
5205 * @return o_ptrの方が上位ならばTRUEを返す。
5207 bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
5211 /* Use empty slots */
5212 if (!j_ptr->k_idx) return TRUE;
5214 /* Hack -- readable books always come first */
5215 if ((o_ptr->tval == REALM1_BOOK) &&
5216 (j_ptr->tval != REALM1_BOOK)) return TRUE;
5217 if ((j_ptr->tval == REALM1_BOOK) &&
5218 (o_ptr->tval != REALM1_BOOK)) return FALSE;
5220 if ((o_ptr->tval == REALM2_BOOK) &&
5221 (j_ptr->tval != REALM2_BOOK)) return TRUE;
5222 if ((j_ptr->tval == REALM2_BOOK) &&
5223 (o_ptr->tval != REALM2_BOOK)) return FALSE;
5225 /* Objects sort by decreasing type */
5226 if (o_ptr->tval > j_ptr->tval) return TRUE;
5227 if (o_ptr->tval < j_ptr->tval) return FALSE;
5229 /* Non-aware (flavored) items always come last */
5230 /* Can happen in the home */
5231 if (!object_is_aware(o_ptr)) return FALSE;
5232 if (!object_is_aware(j_ptr)) return TRUE;
5234 /* Objects sort by increasing sval */
5235 if (o_ptr->sval < j_ptr->sval) return TRUE;
5236 if (o_ptr->sval > j_ptr->sval) return FALSE;
5238 /* Unidentified objects always come last */
5239 /* Objects in the home can be unknown */
5240 if (!object_is_known(o_ptr)) return FALSE;
5241 if (!object_is_known(j_ptr)) return TRUE;
5243 /* Fixed artifacts, random artifacts and ego items */
5244 if (object_is_fixed_artifact(o_ptr)) o_type = 3;
5245 else if (o_ptr->art_name) o_type = 2;
5246 else if (object_is_ego(o_ptr)) o_type = 1;
5249 if (object_is_fixed_artifact(j_ptr)) j_type = 3;
5250 else if (j_ptr->art_name) j_type = 2;
5251 else if (object_is_ego(j_ptr)) j_type = 1;
5254 if (o_type < j_type) return TRUE;
5255 if (o_type > j_type) return FALSE;
5257 switch (o_ptr->tval)
5263 if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
5264 if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
5270 /* Objects sort by increasing hit/damage bonuses */
5271 if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
5272 if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
5275 /* Hack: otherwise identical rods sort by
5276 increasing recharge time --dsb */
5278 if (o_ptr->pval < j_ptr->pval) return TRUE;
5279 if (o_ptr->pval > j_ptr->pval) return FALSE;
5283 /* Objects sort by decreasing value */
5284 return o_value > object_value(j_ptr);
5289 * @brief オブジェクトをプレイヤーが拾って所持スロットに納めるメインルーチン /
5290 * Add an item to the players p_ptr->inventory_list, and return the slot used.
5291 * @param o_ptr 拾うオブジェクトの構造体参照ポインタ
5292 * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5294 * If the new item can combine with an existing item in the p_ptr->inventory_list,\n
5295 * it will do so, using "object_similar()" and "object_absorb()", else,\n
5296 * the item will be placed into the "proper" location in the p_ptr->inventory_list.\n
5298 * This function can be used to "over-fill" the player's pack, but only\n
5299 * once, and such an action must trigger the "overflow" code immediately.\n
5300 * Note that when the pack is being "over-filled", the new item must be\n
5301 * placed into the "overflow" slot, and the "overflow" must take place\n
5302 * before the pack is reordered, but (optionally) after the pack is\n
5303 * combined. This may be tricky. See "dungeon.c" for info.\n
5305 * Note that this code must remove any location/stack information\n
5306 * from the object once it is placed into the p_ptr->inventory_list.\n
5308 s16b inven_carry(object_type *o_ptr)
5310 INVENTORY_IDX i, j, k;
5311 INVENTORY_IDX n = -1;
5316 /* Check for combining */
5317 for (j = 0; j < INVEN_PACK; j++)
5319 j_ptr = &p_ptr->inventory_list[j];
5320 if (!j_ptr->k_idx) continue;
5322 /* Hack -- track last item */
5325 /* Check if the two items can be combined */
5326 if (object_similar(j_ptr, o_ptr))
5328 object_absorb(j_ptr, o_ptr);
5330 p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
5331 p_ptr->update |= (PU_BONUS);
5332 p_ptr->window |= (PW_INVEN);
5339 if (p_ptr->inven_cnt > INVEN_PACK) return (-1);
5341 /* Find an empty slot */
5342 for (j = 0; j <= INVEN_PACK; j++)
5344 j_ptr = &p_ptr->inventory_list[j];
5346 /* Use it if found */
5347 if (!j_ptr->k_idx) break;
5354 /* Reorder the pack */
5357 /* Get the "value" of the item */
5358 s32b o_value = object_value(o_ptr);
5360 /* Scan every occupied slot */
5361 for (j = 0; j < INVEN_PACK; j++)
5363 if (object_sort_comp(o_ptr, o_value, &p_ptr->inventory_list[j])) break;
5370 for (k = n; k >= i; k--)
5372 /* Hack -- Slide the item */
5373 object_copy(&p_ptr->inventory_list[k+1], &p_ptr->inventory_list[k]);
5376 /* Wipe the empty slot */
5377 object_wipe(&p_ptr->inventory_list[i]);
5382 object_copy(&p_ptr->inventory_list[i], o_ptr);
5384 /* Access new object */
5385 j_ptr = &p_ptr->inventory_list[i];
5388 j_ptr->next_o_idx = 0;
5390 /* Forget monster */
5391 j_ptr->held_m_idx = 0;
5393 /* Forget location */
5394 j_ptr->iy = j_ptr->ix = 0;
5396 /* Player touches it, and no longer marked */
5397 j_ptr->marked = OM_TOUCHED;
5399 p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
5401 /* Count the items */
5403 p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
5404 p_ptr->window |= (PW_INVEN);
5406 /* Return the slot */
5412 * @brief 装備スロットからオブジェクトを外すメインルーチン /
5413 * Take off (some of) a non-cursed equipment item
5414 * @param item オブジェクトを外したい所持テーブルのID
5416 * @return 収められた所持スロットのID、拾うことができなかった場合-1を返す。
5418 * Note that only one item at a time can be wielded per slot.\n
5419 * Note that taking off an item when "full" may cause that item\n
5420 * to fall to the ground.\n
5421 * Return the p_ptr->inventory_list slot into which the item is placed.\n
5423 INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
5434 GAME_TEXT o_name[MAX_NLEN];
5437 /* Get the item to take off */
5438 o_ptr = &p_ptr->inventory_list[item];
5439 if (amt <= 0) return (-1);
5442 if (amt > o_ptr->number) amt = o_ptr->number;
5444 object_copy(q_ptr, o_ptr);
5446 /* Modify quantity */
5447 q_ptr->number = amt;
5449 object_desc(o_name, q_ptr, 0);
5451 /* Took off weapon */
5452 if (((item == INVEN_RARM) || (item == INVEN_LARM)) &&
5453 object_is_melee_weapon(o_ptr))
5455 act = _("を装備からはずした", "You were wielding");
5459 else if (item == INVEN_BOW)
5461 act = _("を装備からはずした", "You were holding");
5464 /* Took off light */
5465 else if (item == INVEN_LITE)
5467 act = _("を光源からはずした", "You were holding");
5470 /* Took off something */
5473 act = _("を装備からはずした", "You were wearing");
5476 /* Modify, Optimize */
5477 inven_item_increase(item, -amt);
5478 inven_item_optimize(item);
5480 /* Carry the object */
5481 slot = inven_carry(q_ptr);
5484 msg_format("%s(%c)%s。", o_name, index_to_label(slot), act);
5486 msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
5496 * @brief 所持スロットから床下にオブジェクトを落とすメインルーチン /
5497 * Drop (some of) a non-cursed p_ptr->inventory_list/equipment item
5498 * @param item 所持テーブルのID
5499 * @param amt 落としたい個数
5502 * The object will be dropped "near" the current location
5504 void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
5510 GAME_TEXT o_name[MAX_NLEN];
5512 /* Access original object */
5513 o_ptr = &p_ptr->inventory_list[item];
5516 if (amt <= 0) return;
5519 if (amt > o_ptr->number) amt = o_ptr->number;
5521 /* Take off equipment */
5522 if (item >= INVEN_RARM)
5524 /* Take off first */
5525 item = inven_takeoff(item, amt);
5527 /* Access original object */
5528 o_ptr = &p_ptr->inventory_list[item];
5533 /* Obtain local object */
5534 object_copy(q_ptr, o_ptr);
5536 /* Distribute charges of wands or rods */
5537 distribute_charges(o_ptr, q_ptr, amt);
5539 /* Modify quantity */
5540 q_ptr->number = amt;
5542 /* Describe local object */
5543 object_desc(o_name, q_ptr, 0);
5545 msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(item));
5547 /* Drop it near the player */
5548 (void)drop_near(q_ptr, 0, p_ptr->y, p_ptr->x);
5550 /* Modify, Describe, Optimize */
5551 inven_item_increase(item, -amt);
5552 inven_item_describe(item);
5553 inven_item_optimize(item);
5558 * @brief プレイヤーの所持スロットに存在するオブジェクトをまとめなおす /
5559 * Combine items in the pack
5562 * Note special handling of the "overflow" slot
5564 void combine_pack(void)
5569 bool flag = FALSE, combined;
5575 /* Combine the pack (backwards) */
5576 for (i = INVEN_PACK; i > 0; i--)
5578 o_ptr = &p_ptr->inventory_list[i];
5580 /* Skip empty items */
5581 if (!o_ptr->k_idx) continue;
5583 /* Scan the items above that item */
5584 for (j = 0; j < i; j++)
5588 j_ptr = &p_ptr->inventory_list[j];
5590 /* Skip empty items */
5591 if (!j_ptr->k_idx) continue;
5594 * Get maximum number of the stack if these
5595 * are similar, get zero otherwise.
5597 max_num = object_similar_part(j_ptr, o_ptr);
5599 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
5600 if (max_num && j_ptr->number < max_num)
5602 if (o_ptr->number + j_ptr->number <= max_num)
5607 /* Add together the item counts */
5608 object_absorb(j_ptr, o_ptr);
5610 /* One object is gone */
5613 /* Slide everything down */
5614 for (k = i; k < INVEN_PACK; k++)
5616 /* Structure copy */
5617 p_ptr->inventory_list[k] = p_ptr->inventory_list[k+1];
5620 /* Erase the "final" slot */
5621 object_wipe(&p_ptr->inventory_list[k]);
5625 int old_num = o_ptr->number;
5626 int remain = j_ptr->number + o_ptr->number - max_num;
5628 o_ptr->number -= remain;
5630 /* Add together the item counts */
5631 object_absorb(j_ptr, o_ptr);
5633 o_ptr->number = remain;
5635 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
5636 if (o_ptr->tval == TV_ROD)
5638 o_ptr->pval = o_ptr->pval * remain / old_num;
5639 o_ptr->timeout = o_ptr->timeout * remain / old_num;
5642 /* Hack -- if wands are stacking, combine the charges. -LM- */
5643 if (o_ptr->tval == TV_WAND)
5645 o_ptr->pval = o_ptr->pval * remain / old_num;
5649 p_ptr->window |= (PW_INVEN);
5661 if (flag) msg_print(_("ザックの中のアイテムをまとめ直した。", "You combine some items in your pack."));
5665 * @brief プレイヤーの所持スロットに存在するオブジェクトを並び替える /
5666 * Reorder items in the pack
5669 * Note special handling of the "overflow" slot
5671 void reorder_pack(void)
5681 /* Re-order the pack (forwards) */
5682 for (i = 0; i < INVEN_PACK; i++)
5684 /* Mega-Hack -- allow "proper" over-flow */
5685 if ((i == INVEN_PACK) && (p_ptr->inven_cnt == INVEN_PACK)) break;
5687 o_ptr = &p_ptr->inventory_list[i];
5689 /* Skip empty slots */
5690 if (!o_ptr->k_idx) continue;
5692 /* Get the "value" of the item */
5693 o_value = object_value(o_ptr);
5695 /* Scan every occupied slot */
5696 for (j = 0; j < INVEN_PACK; j++)
5698 if (object_sort_comp(o_ptr, o_value, &p_ptr->inventory_list[j])) break;
5701 /* Never move down */
5702 if (j >= i) continue;
5708 /* Save a copy of the moving item */
5709 object_copy(q_ptr, &p_ptr->inventory_list[i]);
5711 /* Slide the objects */
5712 for (k = i; k > j; k--)
5714 /* Slide the item */
5715 object_copy(&p_ptr->inventory_list[k], &p_ptr->inventory_list[k-1]);
5718 /* Insert the moving item */
5719 object_copy(&p_ptr->inventory_list[j], q_ptr);
5721 p_ptr->window |= (PW_INVEN);
5724 if (flag) msg_print(_("ザックの中のアイテムを並べ直した。", "You reorder some items in your pack."));
5728 * @brief 現在アクティブになっているウィンドウにオブジェクトの詳細を表示する /
5729 * Hack -- display an object kind in the current window
5730 * @param k_idx ベースアイテムの参照ID
5733 * Include list of usable spells for readible books
5735 void display_koff(KIND_OBJECT_IDX k_idx)
5742 REALM_IDX use_realm;
5744 GAME_TEXT o_name[MAX_NLEN];
5747 /* Erase the window */
5748 for (y = 0; y < Term->hgt; y++)
5750 /* Erase the line */
5751 Term_erase(0, y, 255);
5758 /* Prepare the object */
5759 object_prep(q_ptr, k_idx);
5760 object_desc(o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
5762 /* Mention the object name */
5763 Term_putstr(0, 0, -1, TERM_WHITE, o_name);
5765 /* Access the item's sval */
5767 use_realm = tval2realm(q_ptr->tval);
5769 /* Warriors are illiterate */
5770 if (p_ptr->realm1 || p_ptr->realm2)
5772 if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2)) return;
5776 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return;
5777 if (!is_magic(use_realm)) return;
5778 if ((p_ptr->pclass == CLASS_RED_MAGE) && (use_realm != REALM_ARCANE) && (sval > 1)) return;
5781 /* Display spells in readible books */
5785 SPELL_IDX spells[64];
5787 /* Extract spells */
5788 for (spell = 0; spell < 32; spell++)
5790 /* Check for this spell */
5791 if (fake_spell_flags[sval] & (1L << spell))
5793 /* Collect this spell */
5794 spells[num++] = spell;
5799 print_spells(0, spells, num, 2, 0, use_realm);
5805 * @brief 投擲時たいまつに投げやすい/焼棄/アンデッドスレイの特別効果を返す。
5806 * Torches have special abilities when they are flaming.
5807 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5808 * @param flgs 特別に追加するフラグを返す参照ポインタ
5811 void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs)
5813 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5815 if (o_ptr->xtra4 > 0)
5817 add_flag(flgs, TR_BRAND_FIRE);
5818 add_flag(flgs, TR_KILL_UNDEAD);
5819 add_flag(flgs, TR_THROW);
5825 * @brief 投擲時たいまつにダイスを与える。
5826 * Torches have special abilities when they are flaming.
5827 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5828 * @param dd 特別なダイス数を返す参照ポインタ
5829 * @param ds 特別なダイス面数を返す参照ポインタ
5832 void torch_dice(object_type *o_ptr, DICE_NUMBER *dd, DICE_SID *ds)
5834 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5836 if (o_ptr->xtra4 > 0)
5845 * @brief 投擲時命中したたいまつの寿命を縮める。
5846 * Torches have special abilities when they are flaming.
5847 * @param o_ptr 投擲するオブジェクトの構造体参照ポインタ
5850 void torch_lost_fuel(object_type *o_ptr)
5852 if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
5854 o_ptr->xtra4 -= (FUEL_TORCH / 25);
5855 if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0;
5860 * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す /
5861 * @param o_ptr 判定する射撃武器のアイテム情報参照ポインタ
5862 * @return 対応する矢/弾薬のベースアイテムID
5864 int bow_tval_ammo(object_type *o_ptr)
5866 /* Analyze the launcher */
5867 switch (o_ptr->sval)