3 /* Purpose: Object code, part 2 */
6 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
19 * Excise a dungeon object from any stacks
21 void excise_object_idx(int o_idx)
25 s16b this_o_idx, next_o_idx = 0;
31 j_ptr = &o_list[o_idx];
34 if (j_ptr->held_m_idx)
39 m_ptr = &m_list[j_ptr->held_m_idx];
41 /* Scan all objects in the grid */
42 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
47 o_ptr = &o_list[this_o_idx];
49 /* Acquire next object */
50 next_o_idx = o_ptr->next_o_idx;
53 if (this_o_idx == o_idx)
58 /* Remove from list */
59 m_ptr->hold_o_idx = next_o_idx;
68 k_ptr = &o_list[prev_o_idx];
70 /* Remove from list */
71 k_ptr->next_o_idx = next_o_idx;
74 /* Forget next pointer */
75 o_ptr->next_o_idx = 0;
82 prev_o_idx = this_o_idx;
97 /* Scan all objects in the grid */
98 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
103 o_ptr = &o_list[this_o_idx];
105 /* Acquire next object */
106 next_o_idx = o_ptr->next_o_idx;
109 if (this_o_idx == o_idx)
114 /* Remove from list */
115 c_ptr->o_idx = next_o_idx;
123 /* Previous object */
124 k_ptr = &o_list[prev_o_idx];
126 /* Remove from list */
127 k_ptr->next_o_idx = next_o_idx;
130 /* Forget next pointer */
131 o_ptr->next_o_idx = 0;
137 /* Save prev_o_idx */
138 prev_o_idx = this_o_idx;
145 * Delete a dungeon object
147 * Handle "stacks" of objects correctly.
149 void delete_object_idx(int o_idx)
154 excise_object_idx(o_idx);
157 j_ptr = &o_list[o_idx];
160 if (!(j_ptr->held_m_idx))
172 /* Wipe the object */
181 * Deletes all objects at given location
183 void delete_object(int y, int x)
187 s16b this_o_idx, next_o_idx = 0;
190 /* Refuse "illegal" locations */
191 if (!in_bounds(y, x)) return;
197 /* Scan all objects in the grid */
198 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
203 o_ptr = &o_list[this_o_idx];
205 /* Acquire next object */
206 next_o_idx = o_ptr->next_o_idx;
208 /* Wipe the object */
215 /* Objects are gone */
224 * Move an object from index i1 to index i2 in the object list
226 static void compact_objects_aux(int i1, int i2)
236 if (i1 == i2) return;
240 for (i = 1; i < o_max; 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;
262 if (o_ptr->held_m_idx)
266 /* Acquire monster */
267 m_ptr = &m_list[o_ptr->held_m_idx];
270 if (m_ptr->hold_o_idx == i1)
273 m_ptr->hold_o_idx = i2;
282 /* Acquire location */
290 if (c_ptr->o_idx == i1)
299 o_list[i2] = o_list[i1];
307 * Compact and Reorder the object list
309 * This function can be very dangerous, use with caution!
311 * When actually "compacting" objects, we base the saving throw on a
312 * combination of object level, distance from player, and current
315 * After "compacting" (if needed), we "reorder" the objects into a more
316 * compact order, and we reset the allocation info, and the "live" array.
318 void compact_objects(int size)
320 int i, y, x, num, cnt;
321 int cur_lev, cur_dis, chance;
330 msg_print("¥¢¥¤¥Æ¥à¾ðÊó¤ò°µ½Ì¤·¤Æ¤¤¤Þ¤¹...");
332 msg_print("Compacting objects...");
337 p_ptr->redraw |= (PR_MAP);
340 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
344 /* Compact at least 'size' objects */
345 for (num = 0, cnt = 1; num < size; cnt++)
347 /* Get more vicious each iteration */
350 /* Get closer each iteration */
351 cur_dis = 5 * (20 - cnt);
353 /* Examine the objects */
354 for (i = 1; i < o_max; i++)
358 /* Skip dead objects */
359 if (!o_ptr->k_idx) continue;
361 /* Hack -- High level objects start out "immune" */
362 if (get_object_level(o_ptr) > cur_lev) continue;
365 if (o_ptr->held_m_idx)
369 /* Acquire monster */
370 m_ptr = &m_list[o_ptr->held_m_idx];
372 /* Get the location */
376 /* Monsters protect their objects */
377 if (randint0(100) < 90) continue;
383 /* Get the location */
388 /* Nearby objects start out "immune" */
389 if ((cur_dis > 0) && (distance(py, px, y, x) < cur_dis)) continue;
394 /* Hack -- only compact artifacts in emergencies */
395 if ((artifact_p(o_ptr) || o_ptr->art_name) &&
396 (cnt < 1000)) chance = 100;
398 /* Apply the saving throw */
399 if (randint0(100) < chance) continue;
401 /* Delete the object */
402 delete_object_idx(i);
410 /* Excise dead objects (backwards!) */
411 for (i = o_max - 1; i >= 1; i--)
415 /* Skip real objects */
416 if (o_ptr->k_idx) continue;
418 /* Move last object into open hole */
419 compact_objects_aux(o_max - 1, i);
421 /* Compress "o_max" */
428 * Delete all the items when player leaves the level
430 * Note -- we do NOT visually reflect these (irrelevant) changes
432 * Hack -- we clear the "c_ptr->o_idx" field for every grid,
433 * and the "m_ptr->next_o_idx" field for every monster, since
434 * we know we are clearing every object. Technically, we only
435 * clear those fields for grids/monsters containing objects,
436 * and we clear it once for every such object.
438 void wipe_o_list(void)
442 /* Delete the existing objects */
443 for (i = 1; i < o_max; i++)
445 object_type *o_ptr = &o_list[i];
447 /* Skip dead objects */
448 if (!o_ptr->k_idx) continue;
450 /* Mega-Hack -- preserve artifacts */
451 if (!character_dungeon || preserve_mode)
453 /* Hack -- Preserve unknown artifacts */
454 if (artifact_p(o_ptr) && !object_known_p(o_ptr))
456 /* Mega-Hack -- Preserve the artifact */
457 a_info[o_ptr->name1].cur_num = 0;
462 if (o_ptr->held_m_idx)
467 m_ptr = &m_list[o_ptr->held_m_idx];
469 /* Hack -- see above */
470 m_ptr->hold_o_idx = 0;
478 /* Access location */
485 /* Hack -- see above */
489 /* Wipe the object */
502 * Acquires and returns the index of a "free" object.
504 * This routine should almost never fail, but in case it does,
505 * we must be sure to handle "failure" of this routine.
512 /* Initial allocation */
513 if (o_max < max_o_idx)
518 /* Expand object array */
524 /* Use this object */
529 /* Recycle dead objects */
530 for (i = 1; i < o_max; i++)
537 /* Skip live objects */
538 if (o_ptr->k_idx) continue;
543 /* Use this object */
548 /* Warn the player (except during dungeon creation) */
550 if (character_dungeon) msg_print("¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
552 if (character_dungeon) msg_print("Too many objects!");
562 * Apply a "object restriction function" to the "object allocation table"
564 errr get_obj_num_prep(void)
569 alloc_entry *table = alloc_kind_table;
571 /* Scan the allocation table */
572 for (i = 0; i < alloc_kind_size; i++)
574 /* Accept objects which pass the restriction, if any */
575 if (!get_obj_num_hook || (*get_obj_num_hook)(table[i].index))
577 /* Accept this object */
578 table[i].prob2 = table[i].prob1;
581 /* Do not use this object */
584 /* Decline this object */
595 * Choose an object kind that seems "appropriate" to the given level
597 * This function uses the "prob2" field of the "object allocation table",
598 * and various local information, to calculate the "prob3" field of the
599 * same table, which is then used to choose an "appropriate" object, in
600 * a relatively efficient manner.
602 * It is (slightly) more likely to acquire an object of the given level
603 * than one of a lower level. This is done by choosing several objects
604 * appropriate to the given level and keeping the "hardest" one.
606 * Note that if no objects are "appropriate", then this function will
607 * fail, and return zero, but this should *almost* never happen.
609 s16b get_obj_num(int level)
615 alloc_entry *table = alloc_kind_table;
617 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
620 if ((level > 0) && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
622 /* Occasional "boost" */
623 if (one_in_(GREAT_OBJ))
625 /* What a bizarre calculation */
626 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
633 /* Process probabilities */
634 for (i = 0; i < alloc_kind_size; i++)
636 /* Objects are sorted by depth */
637 if (table[i].level > level) break;
642 /* Access the index */
643 k_idx = table[i].index;
645 /* Access the actual kind */
646 k_ptr = &k_info[k_idx];
648 /* Hack -- prevent embedded chests */
649 if (opening_chest && (k_ptr->tval == TV_CHEST)) continue;
652 table[i].prob3 = table[i].prob2;
655 total += table[i].prob3;
658 /* No legal objects */
659 if (total <= 0) return (0);
663 value = randint0(total);
665 /* Find the object */
666 for (i = 0; i < alloc_kind_size; i++)
668 /* Found the entry */
669 if (value < table[i].prob3) break;
672 value = value - table[i].prob3;
679 /* Try for a "better" object once (50%) or twice (10%) */
686 value = randint0(total);
688 /* Find the object */
689 for (i = 0; i < alloc_kind_size; i++)
691 /* Found the entry */
692 if (value < table[i].prob3) break;
695 value = value - table[i].prob3;
698 /* Keep the "best" one */
699 if (table[i].level < table[j].level) i = j;
702 /* Try for a "better" object twice (10%) */
709 value = randint0(total);
711 /* Find the object */
712 for (i = 0; i < alloc_kind_size; i++)
714 /* Found the entry */
715 if (value < table[i].prob3) break;
718 value = value - table[i].prob3;
721 /* Keep the "best" one */
722 if (table[i].level < table[j].level) i = j;
727 return (table[i].index);
732 * Known is true when the "attributes" of an object are "known".
733 * These include tohit, todam, toac, cost, and pval (charges).
735 * Note that "knowing" an object gives you everything that an "awareness"
736 * gives you, and much more. In fact, the player is always "aware" of any
737 * item of which he has full "knowledge".
739 * But having full knowledge of, say, one "wand of wonder", does not, by
740 * itself, give you knowledge, or even awareness, of other "wands of wonder".
741 * It happens that most "identify" routines (including "buying from a shop")
742 * will make the player "aware" of the object as well as fully "know" it.
744 * This routine also removes any inscriptions generated by "feelings".
746 void object_known(object_type *o_ptr)
748 /* Remove "default inscriptions" */
749 o_ptr->feeling = FEEL_NONE;
751 /* Clear the "Felt" info */
752 o_ptr->ident &= ~(IDENT_SENSE);
754 /* Clear the "Empty" info */
755 o_ptr->ident &= ~(IDENT_EMPTY);
757 /* Now we know about the item */
758 o_ptr->ident |= (IDENT_KNOWN);
763 * The player is now aware of the effects of the given object.
765 void object_aware(object_type *o_ptr)
767 bool mihanmei = !object_aware_p(o_ptr);
769 #ifndef SCRIPT_OBJ_KIND
770 /* Fully aware of the effects */
771 k_info[o_ptr->k_idx].aware = TRUE;
772 #else /* SCRIPT_OBJ_KIND */
773 /* Fully aware of the effects */
775 #endif /* SCRIPT_OBJ_KIND */
777 if(mihanmei && !(k_info[o_ptr->k_idx].gen_flags & TRG_INSTA_ART) && record_ident &&
778 !p_ptr->is_dead && ((o_ptr->tval >= TV_AMULET && o_ptr->tval <= TV_POTION) || (o_ptr->tval == TV_FOOD)))
782 char o_name[MAX_NLEN];
785 object_copy(q_ptr, o_ptr);
788 object_desc(o_name, q_ptr, TRUE, 0);
790 do_cmd_write_nikki(NIKKI_HANMEI, 0, o_name);
796 * Something has been "sampled"
798 void object_tried(object_type *o_ptr)
800 #ifndef SCRIPT_OBJ_KIND
801 /* Mark it as tried (even if "aware") */
802 k_info[o_ptr->k_idx].tried = TRUE;
803 #else /* SCRIPT_OBJ_KIND */
805 #endif /* SCRIPT_OBJ_KIND */
810 * Return the "value" of an "unknown" item
811 * Make a guess at the value of non-aware items
813 static s32b object_value_base(object_type *o_ptr)
815 /* Aware item -- use template cost */
816 if (object_aware_p(o_ptr)) return (get_object_cost(o_ptr));
818 /* Analyze the type */
823 case TV_FOOD: return (5L);
825 /* Un-aware Potions */
826 case TV_POTION: return (20L);
828 /* Un-aware Scrolls */
829 case TV_SCROLL: return (20L);
831 /* Un-aware Staffs */
832 case TV_STAFF: return (70L);
835 case TV_WAND: return (50L);
838 case TV_ROD: return (90L);
841 case TV_RING: return (45L);
843 /* Un-aware Amulets */
844 case TV_AMULET: return (45L);
846 /* Figurines, relative to monster level */
849 int level = r_info[o_ptr->pval].level;
850 if (level < 20) return level*50L;
851 else if (level < 30) return 1000+(level-20)*150L;
852 else if (level < 40) return 2500+(level-30)*350L;
853 else if (level < 50) return 6000+(level-40)*800L;
854 else return 14000+(level-50)*2000L;
859 if (!o_ptr->pval) return 1000L;
860 else return ((r_info[o_ptr->pval].level) * 50L + 1000);
863 /* Paranoia -- Oops */
868 /* Return the value of the flags the object has... */
869 s32b flag_cost(object_type * o_ptr, int plusses)
872 u32b flgs[TR_FLAG_SIZE];
877 object_flags(o_ptr, flgs);
881 artifact_type *a_ptr = &a_info[o_ptr->name1];
883 for (i = 0; i < TR_FLAG_SIZE; i++)
884 flgs[i] &= ~(a_ptr->flags[i]);
888 if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET))
890 object_kind *k_ptr = &k_info[o_ptr->k_idx];
892 for (i = 0; i < TR_FLAG_SIZE; i++)
893 flgs[i] &= ~(k_ptr->flags[i]);
898 ego_item_type *e_ptr = &e_info[o_ptr->name2];
900 for (i = 0; i < TR_FLAG_SIZE; i++)
901 flgs[i] &= ~(e_ptr->flags[i]);
904 else if (o_ptr->art_name)
910 if (have_flag(flgs, TR_STR)) total += (1500 * plusses);
911 if (have_flag(flgs, TR_INT)) total += (1500 * plusses);
912 if (have_flag(flgs, TR_WIS)) total += (1500 * plusses);
913 if (have_flag(flgs, TR_DEX)) total += (1500 * plusses);
914 if (have_flag(flgs, TR_CON)) total += (1500 * plusses);
915 if (have_flag(flgs, TR_CHR)) total += (750 * plusses);
916 if (have_flag(flgs, TR_MAGIC_MASTERY)) total += (600 * plusses);
917 if (have_flag(flgs, TR_STEALTH)) total += (250 * plusses);
918 if (have_flag(flgs, TR_SEARCH)) total += (100 * plusses);
919 if (have_flag(flgs, TR_INFRA)) total += (150 * plusses);
920 if (have_flag(flgs, TR_TUNNEL)) total += (175 * plusses);
921 if ((have_flag(flgs, TR_SPEED)) && (plusses > 0))
922 total += (10000 + (2500 * plusses));
923 if ((have_flag(flgs, TR_BLOWS)) && (plusses > 0))
924 total += (10000 + (2500 * plusses));
925 if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
929 if (have_flag(flgs, TR_CHAOTIC)) {total += 5000;count++;}
930 if (have_flag(flgs, TR_VAMPIRIC)) {total += 6500;count++;}
931 if (have_flag(flgs, TR_FORCE_WEAPON)) {tmp_cost += 2500;count++;}
932 if (have_flag(flgs, TR_KILL_ANIMAL)) {tmp_cost += 2800;count++;}
933 else if (have_flag(flgs, TR_SLAY_ANIMAL)) {tmp_cost += 1800;count++;}
934 if (have_flag(flgs, TR_KILL_EVIL)) {tmp_cost += 3300;count++;}
935 else if (have_flag(flgs, TR_SLAY_EVIL)) {tmp_cost += 2300;count++;}
936 if (have_flag(flgs, TR_KILL_HUMAN)) {tmp_cost += 2800;count++;}
937 else if (have_flag(flgs, TR_SLAY_HUMAN)) {tmp_cost += 1800;count++;}
938 if (have_flag(flgs, TR_KILL_UNDEAD)) {tmp_cost += 2800;count++;}
939 else if (have_flag(flgs, TR_SLAY_UNDEAD)) {tmp_cost += 1800;count++;}
940 if (have_flag(flgs, TR_KILL_DEMON)) {tmp_cost += 2800;count++;}
941 else if (have_flag(flgs, TR_SLAY_DEMON)) {tmp_cost += 1800;count++;}
942 if (have_flag(flgs, TR_KILL_ORC)) {tmp_cost += 2500;count++;}
943 else if (have_flag(flgs, TR_SLAY_ORC)) {tmp_cost += 1500;count++;}
944 if (have_flag(flgs, TR_KILL_TROLL)) {tmp_cost += 2800;count++;}
945 else if (have_flag(flgs, TR_SLAY_TROLL)) {tmp_cost += 1800;count++;}
946 if (have_flag(flgs, TR_KILL_GIANT)) {tmp_cost += 2800;count++;}
947 else if (have_flag(flgs, TR_SLAY_GIANT)) {tmp_cost += 1800;count++;}
948 if (have_flag(flgs, TR_KILL_DRAGON)) {tmp_cost += 2800;count++;}
949 else if (have_flag(flgs, TR_SLAY_DRAGON)) {tmp_cost += 1800;count++;}
951 if (have_flag(flgs, TR_VORPAL)) {tmp_cost += 2500;count++;}
952 if (have_flag(flgs, TR_IMPACT)) {tmp_cost += 2500;count++;}
953 if (have_flag(flgs, TR_BRAND_POIS)) {tmp_cost += 3800;count++;}
954 if (have_flag(flgs, TR_BRAND_ACID)) {tmp_cost += 3800;count++;}
955 if (have_flag(flgs, TR_BRAND_ELEC)) {tmp_cost += 3800;count++;}
956 if (have_flag(flgs, TR_BRAND_FIRE)) {tmp_cost += 2500;count++;}
957 if (have_flag(flgs, TR_BRAND_COLD)) {tmp_cost += 2500;count++;}
958 total += (tmp_cost * count);
960 if (have_flag(flgs, TR_SUST_STR)) total += 850;
961 if (have_flag(flgs, TR_SUST_INT)) total += 850;
962 if (have_flag(flgs, TR_SUST_WIS)) total += 850;
963 if (have_flag(flgs, TR_SUST_DEX)) total += 850;
964 if (have_flag(flgs, TR_SUST_CON)) total += 850;
965 if (have_flag(flgs, TR_SUST_CHR)) total += 250;
966 if (have_flag(flgs, TR_RIDING)) total += 0;
967 if (have_flag(flgs, TR_EASY_SPELL)) total += 1500;
968 if (have_flag(flgs, TR_THROW)) total += 5000;
969 if (have_flag(flgs, TR_FREE_ACT)) total += 4500;
970 if (have_flag(flgs, TR_HOLD_LIFE)) total += 8500;
974 if (have_flag(flgs, TR_IM_ACID)) {tmp_cost += 15000;count += 2;}
975 if (have_flag(flgs, TR_IM_ELEC)) {tmp_cost += 15000;count += 2;}
976 if (have_flag(flgs, TR_IM_FIRE)) {tmp_cost += 15000;count += 2;}
977 if (have_flag(flgs, TR_IM_COLD)) {tmp_cost += 15000;count += 2;}
978 if (have_flag(flgs, TR_REFLECT)) {tmp_cost += 5000;count += 2;}
979 if (have_flag(flgs, TR_RES_ACID)) {tmp_cost += 500;count++;}
980 if (have_flag(flgs, TR_RES_ELEC)) {tmp_cost += 500;count++;}
981 if (have_flag(flgs, TR_RES_FIRE)) {tmp_cost += 500;count++;}
982 if (have_flag(flgs, TR_RES_COLD)) {tmp_cost += 500;count++;}
983 if (have_flag(flgs, TR_RES_POIS)) {tmp_cost += 1000;count += 2;}
984 if (have_flag(flgs, TR_RES_FEAR)) {tmp_cost += 1000;count += 2;}
985 if (have_flag(flgs, TR_RES_LITE)) {tmp_cost += 800;count += 2;}
986 if (have_flag(flgs, TR_RES_DARK)) {tmp_cost += 800;count += 2;}
987 if (have_flag(flgs, TR_RES_BLIND)) {tmp_cost += 900;count += 2;}
988 if (have_flag(flgs, TR_RES_CONF)) {tmp_cost += 900;count += 2;}
989 if (have_flag(flgs, TR_RES_SOUND)) {tmp_cost += 900;count += 2;}
990 if (have_flag(flgs, TR_RES_SHARDS)) {tmp_cost += 900;count += 2;}
991 if (have_flag(flgs, TR_RES_NETHER)) {tmp_cost += 900;count += 2;}
992 if (have_flag(flgs, TR_RES_NEXUS)) {tmp_cost += 900;count += 2;}
993 if (have_flag(flgs, TR_RES_CHAOS)) {tmp_cost += 1000;count += 2;}
994 if (have_flag(flgs, TR_RES_DISEN)) {tmp_cost += 2000;count += 2;}
995 total += (tmp_cost * count);
997 if (have_flag(flgs, TR_SH_FIRE)) total += 5000;
998 if (have_flag(flgs, TR_SH_ELEC)) total += 5000;
999 if (have_flag(flgs, TR_SH_COLD)) total += 5000;
1000 if (have_flag(flgs, TR_NO_TELE)) total -= 10000;
1001 if (have_flag(flgs, TR_NO_MAGIC)) total += 2500;
1002 if (have_flag(flgs, TR_TY_CURSE)) total -= 15000;
1003 if (have_flag(flgs, TR_HIDE_TYPE)) total += 0;
1004 if (have_flag(flgs, TR_SHOW_MODS)) total += 0;
1005 if (have_flag(flgs, TR_FEATHER)) total += 1250;
1006 if (have_flag(flgs, TR_LITE)) total += 1250;
1007 if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
1008 if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
1009 if (have_flag(flgs, TR_ESP_ANIMAL)) total += 1000;
1010 if (have_flag(flgs, TR_ESP_UNDEAD)) total += 1000;
1011 if (have_flag(flgs, TR_ESP_DEMON)) total += 1000;
1012 if (have_flag(flgs, TR_ESP_ORC)) total += 1000;
1013 if (have_flag(flgs, TR_ESP_TROLL)) total += 1000;
1014 if (have_flag(flgs, TR_ESP_GIANT)) total += 1000;
1015 if (have_flag(flgs, TR_ESP_DRAGON)) total += 1000;
1016 if (have_flag(flgs, TR_ESP_HUMAN)) total += 1000;
1017 if (have_flag(flgs, TR_ESP_EVIL)) total += 15000;
1018 if (have_flag(flgs, TR_ESP_GOOD)) total += 2000;
1019 if (have_flag(flgs, TR_ESP_NONLIVING)) total += 2000;
1020 if (have_flag(flgs, TR_ESP_UNIQUE)) total += 10000;
1021 if (have_flag(flgs, TR_SLOW_DIGEST)) total += 750;
1022 if (have_flag(flgs, TR_REGEN)) total += 2500;
1023 if (have_flag(flgs, TR_WARNING)) total += 2000;
1024 if (have_flag(flgs, TR_XTRA_MIGHT)) total += 2250;
1025 if (have_flag(flgs, TR_XTRA_SHOTS)) total += 10000;
1026 if (have_flag(flgs, TR_IGNORE_ACID)) total += 100;
1027 if (have_flag(flgs, TR_IGNORE_ELEC)) total += 100;
1028 if (have_flag(flgs, TR_IGNORE_FIRE)) total += 100;
1029 if (have_flag(flgs, TR_IGNORE_COLD)) total += 100;
1030 if (have_flag(flgs, TR_ACTIVATE)) total += 100;
1031 if (have_flag(flgs, TR_DRAIN_EXP)) total -= 12500;
1032 if (have_flag(flgs, TR_TELEPORT))
1034 if (cursed_p(o_ptr))
1039 if (have_flag(flgs, TR_AGGRAVATE)) total -= 10000;
1040 if (have_flag(flgs, TR_BLESSED)) total += 750;
1041 if (o_ptr->curse_flags & TRC_CURSED) total -= 5000;
1042 if (o_ptr->curse_flags & TRC_HEAVY_CURSE) total -= 12500;
1043 if (o_ptr->curse_flags & TRC_PERMA_CURSE) total -= 15000;
1045 /* Also, give some extra for activatable powers... */
1046 if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
1048 int type = o_ptr->xtra2;
1050 if (type == ACT_SUNLIGHT) total += 250;
1051 else if (type == ACT_BO_MISS_1) total += 250;
1052 else if (type == ACT_BA_POIS_1) total += 300;
1053 else if (type == ACT_BO_ELEC_1) total += 250;
1054 else if (type == ACT_BO_ACID_1) total += 250;
1055 else if (type == ACT_BO_COLD_1) total += 250;
1056 else if (type == ACT_BO_FIRE_1) total += 250;
1057 else if (type == ACT_BA_COLD_1) total += 750;
1058 else if (type == ACT_BA_FIRE_1) total += 1000;
1059 else if (type == ACT_DRAIN_1) total += 500;
1060 else if (type == ACT_BA_COLD_2) total += 1250;
1061 else if (type == ACT_BA_ELEC_2) total += 1500;
1062 else if (type == ACT_DRAIN_2) total += 750;
1063 else if (type == ACT_VAMPIRE_1) total += 1000;
1064 else if (type == ACT_BO_MISS_2) total += 1000;
1065 else if (type == ACT_BA_FIRE_2) total += 1750;
1066 else if (type == ACT_BA_COLD_3) total += 2500;
1067 else if (type == ACT_BA_ELEC_3) total += 2500;
1068 else if (type == ACT_WHIRLWIND) total += 7500;
1069 else if (type == ACT_VAMPIRE_2) total += 2500;
1070 else if (type == ACT_CALL_CHAOS) total += 5000;
1071 else if (type == ACT_ROCKET) total += 5000;
1072 else if (type == ACT_DISP_EVIL) total += 4000;
1073 else if (type == ACT_DISP_GOOD) total += 3500;
1074 else if (type == ACT_BA_MISS_3) total += 5000;
1075 else if (type == ACT_CONFUSE) total += 500;
1076 else if (type == ACT_SLEEP) total += 750;
1077 else if (type == ACT_QUAKE) total += 600;
1078 else if (type == ACT_TERROR) total += 2500;
1079 else if (type == ACT_TELE_AWAY) total += 2000;
1080 else if (type == ACT_BANISH_EVIL) total += 2000;
1081 else if (type == ACT_GENOCIDE) total += 10000;
1082 else if (type == ACT_MASS_GENO) total += 10000;
1083 else if (type == ACT_CHARM_ANIMAL) total += 7500;
1084 else if (type == ACT_CHARM_UNDEAD) total += 10000;
1085 else if (type == ACT_CHARM_OTHER) total += 10000;
1086 else if (type == ACT_CHARM_ANIMALS) total += 12500;
1087 else if (type == ACT_CHARM_OTHERS) total += 17500;
1088 else if (type == ACT_SUMMON_ANIMAL) total += 10000;
1089 else if (type == ACT_SUMMON_PHANTOM) total += 12000;
1090 else if (type == ACT_SUMMON_ELEMENTAL) total += 15000;
1091 else if (type == ACT_SUMMON_DEMON) total += 20000;
1092 else if (type == ACT_SUMMON_UNDEAD) total += 20000;
1093 else if (type == ACT_CURE_LW) total += 500;
1094 else if (type == ACT_CURE_MW) total += 750;
1095 else if (type == ACT_CURE_POISON) total += 1000;
1096 else if (type == ACT_REST_LIFE) total += 7500;
1097 else if (type == ACT_REST_ALL) total += 15000;
1098 else if (type == ACT_CURE_700) total += 10000;
1099 else if (type == ACT_CURE_1000) total += 15000;
1100 else if (type == ACT_ESP) total += 1500;
1101 else if (type == ACT_BERSERK) total += 800;
1102 else if (type == ACT_PROT_EVIL) total += 5000;
1103 else if (type == ACT_RESIST_ALL) total += 5000;
1104 else if (type == ACT_SPEED) total += 15000;
1105 else if (type == ACT_XTRA_SPEED) total += 25000;
1106 else if (type == ACT_WRAITH) total += 25000;
1107 else if (type == ACT_INVULN) total += 25000;
1108 else if (type == ACT_LIGHT) total += 150;
1109 else if (type == ACT_MAP_LIGHT) total += 500;
1110 else if (type == ACT_DETECT_ALL) total += 1000;
1111 else if (type == ACT_DETECT_XTRA) total += 12500;
1112 else if (type == ACT_ID_FULL) total += 10000;
1113 else if (type == ACT_ID_PLAIN) total += 1250;
1114 else if (type == ACT_RUNE_EXPLO) total += 4000;
1115 else if (type == ACT_RUNE_PROT) total += 10000;
1116 else if (type == ACT_SATIATE) total += 2000;
1117 else if (type == ACT_DEST_DOOR) total += 100;
1118 else if (type == ACT_STONE_MUD) total += 1000;
1119 else if (type == ACT_RECHARGE) total += 1000;
1120 else if (type == ACT_ALCHEMY) total += 10000;
1121 else if (type == ACT_DIM_DOOR) total += 10000;
1122 else if (type == ACT_TELEPORT) total += 2000;
1123 else if (type == ACT_RECALL) total += 7500;
1131 * Return the "real" price of a "known" item, not including discounts
1133 * Wand and staffs get cost for each charge
1135 * Armor is worth an extra 100 gold per bonus point to armor class.
1137 * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).
1139 * Missiles are only worth 5 gold per bonus point, since they
1140 * usually appear in groups of 20, and we want the player to get
1141 * the same amount of cash for any "equivalent" item. Note that
1142 * missiles never have any of the "pval" flags, and in fact, they
1143 * only have a few of the available flags, primarily of the "slay"
1144 * and "brand" and "ignore" variety.
1146 * Armor with a negative armor bonus is worthless.
1147 * Weapons with negative hit+damage bonuses are worthless.
1149 * Every wearable item with a "pval" bonus is worth extra (see below).
1151 s32b object_value_real(object_type *o_ptr)
1155 u32b flgs[TR_FLAG_SIZE];
1157 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1160 /* Hack -- "worthless" items */
1161 if (!get_object_cost(o_ptr)) return (0L);
1164 value = get_object_cost(o_ptr);
1166 /* Extract some flags */
1167 object_flags(o_ptr, flgs);
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);
1184 else if (o_ptr->name2)
1186 ego_item_type *e_ptr = &e_info[o_ptr->name2];
1188 /* Hack -- "worthless" ego-items */
1189 if (!e_ptr->cost) return (0L);
1191 /* Hack -- Reward the ego-item with a bonus */
1192 value += e_ptr->cost;
1193 value += flag_cost(o_ptr, o_ptr->pval);
1201 for (i = 0; i < TR_FLAG_SIZE; i++)
1202 if (o_ptr->art_flags[i]) flag = TRUE;
1204 if (flag) value += flag_cost(o_ptr, o_ptr->pval);
1208 /* Analyze pval bonus */
1209 switch (o_ptr->tval)
1232 /* Hack -- Negative "pval" is always bad */
1233 if (o_ptr->pval < 0) return (0L);
1236 if (!o_ptr->pval) break;
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 * 100L);
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);
1266 /* Analyze the item */
1267 switch (o_ptr->tval)
1272 /* Pay extra for charges, depending on standard number of
1273 * charges. Handle new-style wands correctly. -LM-
1275 value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
1282 /* Pay extra for charges, depending on standard number of
1285 value += (value * o_ptr->pval / (k_ptr->pval * 2));
1295 /* Hack -- negative bonuses are bad */
1296 if (o_ptr->to_h + o_ptr->to_d + o_ptr->to_a < 0) return (0L);
1298 /* Give credit for bonuses */
1299 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
1316 /* Hack -- negative armor bonus */
1317 if (o_ptr->to_a < 0) return (0L);
1319 /* Give credit for bonuses */
1320 value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
1333 /* Hack -- negative hit/damage bonuses */
1334 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1336 /* Factor in the bonuses */
1337 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 100L);
1339 /* Hack -- Factor in extra damage dice and sides */
1340 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
1341 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
1352 /* Hack -- negative hit/damage bonuses */
1353 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1355 /* Factor in the bonuses */
1356 value += ((o_ptr->to_h + o_ptr->to_d) * 5L);
1358 /* Hack -- Factor in extra damage dice and sides */
1359 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
1360 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
1366 /* Figurines, relative to monster level */
1369 int level = r_info[o_ptr->pval].level;
1370 if (level < 20) value = level*50L;
1371 else if (level < 30) value = 1000+(level-20)*150L;
1372 else if (level < 40) value = 2500+(level-30)*350L;
1373 else if (level < 50) value = 6000+(level-40)*800L;
1374 else value = 14000+(level-50)*2000L;
1380 if (!o_ptr->pval) value = 1000L;
1381 else value = ((r_info[o_ptr->pval].level) * 50L + 1000);
1387 if (!o_ptr->pval) value = 0L;
1392 /* Return the value */
1398 * Return the price of an item including plusses (and charges)
1400 * This function returns the "value" of the given item (qty one)
1402 * Never notice "unknown" bonuses or properties, including "curses",
1403 * since that would give the player information he did not have.
1405 * Note that discounted items stay discounted forever, even if
1406 * the discount is "forgotten" by the player via memory loss.
1408 s32b object_value(object_type *o_ptr)
1413 /* Unknown items -- acquire a base value */
1414 if (object_known_p(o_ptr))
1416 /* Broken items -- worthless */
1417 if (broken_p(o_ptr)) return (0L);
1419 /* Cursed items -- worthless */
1420 if (cursed_p(o_ptr)) return (0L);
1422 /* Real value (see above) */
1423 value = object_value_real(o_ptr);
1426 /* Known items -- acquire the actual value */
1429 /* Hack -- Felt broken items */
1430 if ((o_ptr->ident & (IDENT_SENSE)) && broken_p(o_ptr)) return (0L);
1432 /* Hack -- Felt cursed items */
1433 if ((o_ptr->ident & (IDENT_SENSE)) && cursed_p(o_ptr)) return (0L);
1435 /* Base value (see above) */
1436 value = object_value_base(o_ptr);
1440 /* Apply discount (if any) */
1441 if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
1444 /* Return the final value */
1450 * Determines whether an object can be destroyed, and makes fake inscription.
1452 bool can_player_destroy_object(object_type *o_ptr)
1454 /* Artifacts cannot be destroyed */
1455 if (artifact_p(o_ptr) || o_ptr->art_name)
1457 byte feel = FEEL_SPECIAL;
1459 /* Hack -- Handle icky artifacts */
1460 if (cursed_p(o_ptr) || broken_p(o_ptr)) feel = FEEL_TERRIBLE;
1462 /* Hack -- inscribe the artifact */
1463 o_ptr->feeling = feel;
1465 /* We have "felt" it (again) */
1466 o_ptr->ident |= (IDENT_SENSE);
1468 /* Combine the pack */
1469 p_ptr->notice |= (PN_COMBINE);
1472 p_ptr->window |= (PW_INVEN | PW_EQUIP);
1483 * Distribute charges of rods or wands.
1485 * o_ptr = source item
1486 * q_ptr = target item, must be of the same type as o_ptr
1487 * amt = number of items that are transfered
1489 void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
1492 * Hack -- If rods or wands are dropped, the total maximum timeout or
1493 * charges need to be allocated between the two stacks. If all the items
1494 * are being dropped, it makes for a neater message to leave the original
1495 * stack's pval alone. -LM-
1497 if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD))
1499 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1500 if (amt < o_ptr->number) o_ptr->pval -= q_ptr->pval;
1502 /* Hack -- Rods also need to have their timeouts distributed. The
1503 * dropped stack will accept all time remaining to charge up to its
1506 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
1508 if (q_ptr->pval > o_ptr->timeout)
1509 q_ptr->timeout = o_ptr->timeout;
1511 q_ptr->timeout = q_ptr->pval;
1513 if (amt < o_ptr->number) o_ptr->timeout -= q_ptr->timeout;
1518 void reduce_charges(object_type *o_ptr, int amt)
1521 * Hack -- If rods or wand are destroyed, the total maximum timeout or
1522 * charges of the stack needs to be reduced, unless all the items are
1523 * being destroyed. -LM-
1525 if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD)) &&
1526 (amt < o_ptr->number))
1528 o_ptr->pval -= o_ptr->pval * amt / o_ptr->number;
1534 * Determine if an item can "absorb" a second item
1536 * See "object_absorb()" for the actual "absorption" code.
1538 * If permitted, we allow staffs (if they are known to have equal charges
1539 * and both are either known or confirmed empty) and wands (if both are
1540 * either known or confirmed empty) and rods (in all cases) to combine.
1541 * Staffs will unstack (if necessary) when they are used, but wands and
1542 * rods will only unstack if one is dropped. -LM-
1544 * If permitted, we allow weapons/armor to stack, if fully "known".
1546 * Missiles will combine if both stacks have the same "known" status.
1547 * This is done to make unidentified stacks of missiles useful.
1549 * Food, potions, scrolls, and "easy know" items always stack.
1551 * Chests, and activatable items, never stack (for various reasons).
1555 * Determine if an item can partly absorb a second item.
1557 static bool object_similar_part(object_type *o_ptr, object_type *j_ptr)
1561 /* Require identical object types */
1562 if (o_ptr->k_idx != j_ptr->k_idx) return (0);
1565 /* Analyze the items */
1566 switch (o_ptr->tval)
1568 /* Chests and Statues*/
1579 if ((o_ptr->sval != SV_PHOTO) || (j_ptr->sval != SV_PHOTO)) return (0);
1580 if (o_ptr->pval != j_ptr->pval) return (0);
1584 /* Figurines and Corpses*/
1589 if (o_ptr->pval != j_ptr->pval) return (0);
1595 /* Food and Potions and Scrolls */
1607 /* Require either knowledge or known empty for both staffs. */
1608 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1609 !object_known_p(o_ptr)) ||
1610 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1611 !object_known_p(j_ptr))) return(0);
1613 /* Require identical charges, since staffs are bulky. */
1614 if (o_ptr->pval != j_ptr->pval) return (0);
1623 /* Require either knowledge or known empty for both wands. */
1624 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1625 !object_known_p(o_ptr)) ||
1626 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1627 !object_known_p(j_ptr))) return(0);
1629 /* Wand charges combine in O&ZAngband. */
1635 /* Staffs and Wands and Rods */
1642 /* Weapons and Armor */
1658 /* Require permission */
1659 if (!stack_allow_items) return (0);
1664 /* Rings, Amulets, Lites */
1669 /* Require full knowledge of both items */
1670 if (!object_known_p(o_ptr) || !object_known_p(j_ptr)) return (0);
1680 /* Require identical knowledge of both items */
1681 if (object_known_p(o_ptr) != object_known_p(j_ptr)) return (0);
1683 /* Require identical "bonuses" */
1684 if (o_ptr->to_h != j_ptr->to_h) return (FALSE);
1685 if (o_ptr->to_d != j_ptr->to_d) return (FALSE);
1686 if (o_ptr->to_a != j_ptr->to_a) return (FALSE);
1688 /* Require identical "pval" code */
1689 if (o_ptr->pval != j_ptr->pval) return (FALSE);
1691 /* Require identical "artifact" names */
1692 if (o_ptr->name1 != j_ptr->name1) return (FALSE);
1694 /* Random artifacts never stack */
1695 if (o_ptr->art_name || j_ptr->art_name) return (FALSE);
1697 /* Require identical "ego-item" names */
1698 if (o_ptr->name2 != j_ptr->name2) return (FALSE);
1700 /* Require identical added essence */
1701 if (o_ptr->xtra3 != j_ptr->xtra3) return (FALSE);
1702 if (o_ptr->xtra4 != j_ptr->xtra4) return (FALSE);
1704 /* Hack -- Never stack "powerful" items */
1705 if (o_ptr->xtra1 || j_ptr->xtra1) return (FALSE);
1707 /* Hack -- Never stack recharging items */
1708 if (o_ptr->timeout || j_ptr->timeout) return (FALSE);
1710 /* Require identical "values" */
1711 if (o_ptr->ac != j_ptr->ac) return (FALSE);
1712 if (o_ptr->dd != j_ptr->dd) return (FALSE);
1713 if (o_ptr->ds != j_ptr->ds) return (FALSE);
1722 /* Require knowledge */
1723 if (!object_known_p(o_ptr) || !object_known_p(j_ptr)) return (0);
1731 /* Hack -- Identical art_flags! */
1732 for (i = 0; i < TR_FLAG_SIZE; i++)
1733 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return (0);
1735 /* Hack -- Require identical "cursed" status */
1736 if (o_ptr->curse_flags != j_ptr->curse_flags) return (0);
1738 /* Hack -- Require identical "broken" status */
1739 if ((o_ptr->ident & (IDENT_BROKEN)) != (j_ptr->ident & (IDENT_BROKEN))) return (0);
1742 /* Hack -- require semi-matching "inscriptions" */
1743 if (o_ptr->inscription && j_ptr->inscription &&
1744 (o_ptr->inscription != j_ptr->inscription))
1747 /* Hack -- normally require matching "inscriptions" */
1748 if (!stack_force_notes && (o_ptr->inscription != j_ptr->inscription)) return (0);
1750 /* Hack -- normally require matching "discounts" */
1751 if (!stack_force_costs && (o_ptr->discount != j_ptr->discount)) return (0);
1754 /* They match, so they must be similar */
1759 * Determine if an item can absorb a second item.
1761 bool object_similar(object_type *o_ptr, object_type *j_ptr)
1763 int total = o_ptr->number + j_ptr->number;
1765 if (!object_similar_part(o_ptr, j_ptr))
1768 /* Maximal "stacking" limit */
1769 if (total >= MAX_STACK_SIZE) return (0);
1772 /* They match, so they must be similar */
1779 * Allow one item to "absorb" another, assuming they are similar
1781 void object_absorb(object_type *o_ptr, object_type *j_ptr)
1783 int total = o_ptr->number + j_ptr->number;
1785 /* Add together the item counts */
1786 o_ptr->number = ((total < MAX_STACK_SIZE) ? total : (MAX_STACK_SIZE - 1));
1788 /* Hack -- blend "known" status */
1789 if (object_known_p(j_ptr)) object_known(o_ptr);
1791 /* Hack -- clear "storebought" if only one has it */
1792 if (((o_ptr->ident & IDENT_STOREB) || (j_ptr->ident & IDENT_STOREB)) &&
1793 (!((o_ptr->ident & IDENT_STOREB) && (j_ptr->ident & IDENT_STOREB))))
1795 if (j_ptr->ident & IDENT_STOREB) j_ptr->ident &= 0xEF;
1796 if (o_ptr->ident & IDENT_STOREB) o_ptr->ident &= 0xEF;
1799 /* Hack -- blend "mental" status */
1800 if (j_ptr->ident & (IDENT_MENTAL)) o_ptr->ident |= (IDENT_MENTAL);
1802 /* Hack -- blend "inscriptions" */
1803 if (j_ptr->inscription) o_ptr->inscription = j_ptr->inscription;
1805 /* Hack -- blend "feelings" */
1806 if (j_ptr->feeling) o_ptr->feeling = j_ptr->feeling;
1808 /* Hack -- could average discounts XXX XXX XXX */
1809 /* Hack -- save largest discount XXX XXX XXX */
1810 if (o_ptr->discount < j_ptr->discount) o_ptr->discount = j_ptr->discount;
1812 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1813 if (o_ptr->tval == TV_ROD)
1815 o_ptr->pval += j_ptr->pval;
1816 o_ptr->timeout += j_ptr->timeout;
1819 /* Hack -- if wands are stacking, combine the charges. -LM- */
1820 if (o_ptr->tval == TV_WAND)
1822 o_ptr->pval += j_ptr->pval;
1828 * Find the index of the object_kind with the given tval and sval
1830 s16b lookup_kind(int tval, int sval)
1837 for (k = 1; k < max_k_idx; k++)
1839 object_kind *k_ptr = &k_info[k];
1841 /* Require correct tval */
1842 if (k_ptr->tval != tval) continue;
1845 if (k_ptr->sval == sval) return (k);
1847 /* Ignore illegal items */
1848 if (sval != SV_ANY) continue;
1850 /* Apply the randomizer */
1851 if (!one_in_(++num)) continue;
1853 /* Use this value */
1857 /* Return this choice */
1866 msg_format("¥¢¥¤¥Æ¥à¤¬¤Ê¤¤ (%d,%d)", tval, sval);
1868 msg_format("No object (%d,%d)", tval, sval);
1879 * Wipe an object clean.
1881 void object_wipe(object_type *o_ptr)
1883 /* Wipe the structure */
1884 (void)WIPE(o_ptr, object_type);
1889 * Prepare an object based on an existing object
1891 void object_copy(object_type *o_ptr, object_type *j_ptr)
1893 /* Copy the structure */
1894 COPY(o_ptr, j_ptr, object_type);
1899 * Prepare an object based on an object kind.
1901 void object_prep(object_type *o_ptr, int 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 /* Hack -- worthless items are always "broken" */
1935 if (get_object_cost(o_ptr) <= 0) o_ptr->ident |= (IDENT_BROKEN);
1937 /* Hack -- cursed items are always "cursed" */
1938 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
1939 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
1940 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
1941 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
1942 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
1943 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
1948 * Help determine an "enchantment bonus" for an object.
1950 * To avoid floating point but still provide a smooth distribution of bonuses,
1951 * we simply round the results of division in such a way as to "average" the
1952 * correct floating point value.
1954 * This function has been changed. It uses "randnor()" to choose values from
1955 * a normal distribution, whose mean moves from zero towards the max as the
1956 * level increases, and whose standard deviation is equal to 1/4 of the max,
1957 * and whose values are forced to lie between zero and the max, inclusive.
1959 * Since the "level" rarely passes 100 before Morgoth is dead, it is very
1960 * rare to get the "full" enchantment on an object, even a deep levels.
1962 * It is always possible (albeit unlikely) to get the "full" enchantment.
1964 * A sample distribution of values from "m_bonus(10, N)" is shown below:
1966 * N 0 1 2 3 4 5 6 7 8 9 10
1967 * --- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
1968 * 0 66.37 13.01 9.73 5.47 2.89 1.31 0.72 0.26 0.12 0.09 0.03
1969 * 8 46.85 24.66 12.13 8.13 4.20 2.30 1.05 0.36 0.19 0.08 0.05
1970 * 16 30.12 27.62 18.52 10.52 6.34 3.52 1.95 0.90 0.31 0.15 0.05
1971 * 24 22.44 15.62 30.14 12.92 8.55 5.30 2.39 1.63 0.62 0.28 0.11
1972 * 32 16.23 11.43 23.01 22.31 11.19 7.18 4.46 2.13 1.20 0.45 0.41
1973 * 40 10.76 8.91 12.80 29.51 16.00 9.69 5.90 3.43 1.47 0.88 0.65
1974 * 48 7.28 6.81 10.51 18.27 27.57 11.76 7.85 4.99 2.80 1.22 0.94
1975 * 56 4.41 4.73 8.52 11.96 24.94 19.78 11.06 7.18 3.68 1.96 1.78
1976 * 64 2.81 3.07 5.65 9.17 13.01 31.57 13.70 9.30 6.04 3.04 2.64
1977 * 72 1.87 1.99 3.68 7.15 10.56 20.24 25.78 12.17 7.52 4.42 4.62
1978 * 80 1.02 1.23 2.78 4.75 8.37 12.04 27.61 18.07 10.28 6.52 7.33
1979 * 88 0.70 0.57 1.56 3.12 6.34 10.06 15.76 30.46 12.58 8.47 10.38
1980 * 96 0.27 0.60 1.25 2.28 4.30 7.60 10.77 22.52 22.51 11.37 16.53
1981 * 104 0.22 0.42 0.77 1.36 2.62 5.33 8.93 13.05 29.54 15.23 22.53
1982 * 112 0.15 0.20 0.56 0.87 2.00 3.83 6.86 10.06 17.89 27.31 30.27
1983 * 120 0.03 0.11 0.31 0.46 1.31 2.48 4.60 7.78 11.67 25.53 45.72
1984 * 128 0.02 0.01 0.13 0.33 0.83 1.41 3.24 6.17 9.57 14.22 64.07
1986 s16b m_bonus(int max, int level)
1988 int bonus, stand, extra, value;
1991 /* Paranoia -- enforce maximal "level" */
1992 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1995 /* The "bonus" moves towards the max */
1996 bonus = ((max * level) / MAX_DEPTH);
1998 /* Hack -- determine fraction of error */
1999 extra = ((max * level) % MAX_DEPTH);
2001 /* Hack -- simulate floating point computations */
2002 if (randint0(MAX_DEPTH) < extra) bonus++;
2005 /* The "stand" is equal to one quarter of the max */
2008 /* Hack -- determine fraction of error */
2011 /* Hack -- simulate floating point computations */
2012 if (randint0(4) < extra) stand++;
2015 /* Choose an "interesting" value */
2016 value = randnor(bonus, stand);
2018 /* Enforce the minimum value */
2019 if (value < 0) return (0);
2021 /* Enforce the maximum value */
2022 if (value > max) return (max);
2030 * Cheat -- describe a created object for the user
2032 static void object_mention(object_type *o_ptr)
2034 char o_name[MAX_NLEN];
2037 object_desc_store(o_name, o_ptr, FALSE, 0);
2040 if (artifact_p(o_ptr))
2044 msg_format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à (%s)", o_name);
2046 msg_format("Artifact (%s)", o_name);
2051 /* Random Artifact */
2052 else if (o_ptr->art_name)
2055 msg_print("¥é¥ó¥À¥à¡¦¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È");
2057 msg_print("Random artifact");
2063 else if (ego_item_p(o_ptr))
2067 msg_format("̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à (%s)", o_name);
2069 msg_format("Ego-item (%s)", o_name);
2079 msg_format("¥¢¥¤¥Æ¥à (%s)", o_name);
2081 msg_format("Object (%s)", o_name);
2089 * Mega-Hack -- Attempt to create one of the "Special Objects"
2091 * We are only called from "make_object()", and we assume that
2092 * "apply_magic()" is called immediately after we return.
2094 * Note -- see "make_artifact()" and "apply_magic()"
2096 static bool make_artifact_special(object_type *o_ptr)
2102 /* No artifacts in the town */
2103 if (!dun_level) return (FALSE);
2106 if (get_obj_num_hook) return (FALSE);
2108 /* Check the artifact list (just the "specials") */
2109 for (i = 0; i < max_a_idx; i++)
2111 artifact_type *a_ptr = &a_info[i];
2113 /* Skip "empty" artifacts */
2114 if (!a_ptr->name) continue;
2116 /* Cannot make an artifact twice */
2117 if (a_ptr->cur_num) continue;
2119 if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
2120 if (!(a_ptr->gen_flags & TRG_INSTA_ART)) continue;
2122 /* XXX XXX Enforce minimum "depth" (loosely) */
2123 if (a_ptr->level > dun_level)
2125 /* Acquire the "out-of-depth factor" */
2126 int d = (a_ptr->level - dun_level) * 2;
2128 /* Roll for out-of-depth creation */
2129 if (!one_in_(d)) continue;
2132 /* Artifact "rarity roll" */
2133 if (!one_in_(a_ptr->rarity)) continue;
2135 /* Find the base object */
2136 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
2138 /* XXX XXX Enforce minimum "object" level (loosely) */
2139 if (k_info[k_idx].level > object_level)
2141 /* Acquire the "out-of-depth factor" */
2142 int d = (k_info[k_idx].level - object_level) * 5;
2144 /* Roll for out-of-depth creation */
2145 if (!one_in_(d)) continue;
2148 /* Assign the template */
2149 object_prep(o_ptr, k_idx);
2151 /* Mega-Hack -- mark the item as an artifact */
2154 /* Hack: Some artifacts get random extra powers */
2155 random_artifact_resistance(o_ptr, a_ptr);
2167 * Attempt to change an object into an artifact
2169 * This routine should only be called by "apply_magic()"
2171 * Note -- see "make_artifact_special()" and "apply_magic()"
2173 static bool make_artifact(object_type *o_ptr)
2178 /* No artifacts in the town */
2179 if (!dun_level) return (FALSE);
2181 /* Paranoia -- no "plural" artifacts */
2182 if (o_ptr->number != 1) return (FALSE);
2184 /* Check the artifact list (skip the "specials") */
2185 for (i = 0; i < max_a_idx; i++)
2187 artifact_type *a_ptr = &a_info[i];
2189 /* Skip "empty" items */
2190 if (!a_ptr->name) continue;
2192 /* Cannot make an artifact twice */
2193 if (a_ptr->cur_num) continue;
2195 if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
2197 if (a_ptr->gen_flags & TRG_INSTA_ART) continue;
2199 /* Must have the correct fields */
2200 if (a_ptr->tval != o_ptr->tval) continue;
2201 if (a_ptr->sval != o_ptr->sval) continue;
2203 /* XXX XXX Enforce minimum "depth" (loosely) */
2204 if (a_ptr->level > dun_level)
2206 /* Acquire the "out-of-depth factor" */
2207 int d = (a_ptr->level - dun_level) * 2;
2209 /* Roll for out-of-depth creation */
2210 if (!one_in_(d)) continue;
2213 /* We must make the "rarity roll" */
2214 if (!one_in_(a_ptr->rarity)) continue;
2216 /* Hack -- mark the item as an artifact */
2219 /* Hack: Some artifacts get random extra powers */
2220 random_artifact_resistance(o_ptr, a_ptr);
2232 * Choose random ego type
2234 static byte get_random_ego(byte slot, bool good, int level)
2237 ego_item_type *e_ptr;
2241 for (i = 1; i < max_e_idx; i++)
2245 if (e_ptr->slot == slot
2246 /* && level >= e_ptr->level */
2247 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
2250 total += (255 / e_ptr->rarity);
2254 value = randint1(total);
2256 for (i = 1; i < max_e_idx; i++)
2260 if (e_ptr->slot == slot
2261 /* && level >= e_ptr->level */
2262 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
2265 value -= (255 / e_ptr->rarity);
2266 if (value <= 0L) break;
2274 * Apply magic to an item known to be a "weapon"
2276 * Hack -- note special base damage dice boosting
2277 * Hack -- note special processing for weapon/digger
2278 * Hack -- note special rating boost for dragon scale mail
2280 static void a_m_aux_1(object_type *o_ptr, int level, int power)
2282 int tohit1 = randint1(5) + m_bonus(5, level);
2283 int todam1 = randint1(5) + m_bonus(5, level);
2285 int tohit2 = m_bonus(10, level);
2286 int todam2 = m_bonus(10, level);
2288 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
2290 tohit2 = (tohit2+1)/2;
2291 todam2 = (todam2+1)/2;
2298 o_ptr->to_h += tohit1;
2299 o_ptr->to_d += todam1;
2305 o_ptr->to_h += tohit2;
2306 o_ptr->to_d += todam2;
2314 o_ptr->to_h -= tohit1;
2315 o_ptr->to_d -= todam1;
2320 /* Penalize again */
2321 o_ptr->to_h -= tohit2;
2322 o_ptr->to_d -= todam2;
2325 /* Cursed (if "bad") */
2326 if (o_ptr->to_h + o_ptr->to_d < 0) o_ptr->curse_flags |= TRC_CURSED;
2329 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)) return;
2332 switch (o_ptr->tval)
2340 create_artifact(o_ptr, FALSE);
2342 /* Special Ego-item */
2343 o_ptr->name2 = EGO_DIGGING;
2347 else if (power < -1)
2349 /* Hack -- Horrible digging bonus */
2350 o_ptr->pval = 0 - (5 + randint1(5));
2356 /* Hack -- Reverse digging bonus */
2357 o_ptr->pval = 0 - (o_ptr->pval);
2373 create_artifact(o_ptr, FALSE);
2378 /* Roll for an ego-item */
2379 o_ptr->name2 = get_random_ego(INVEN_RARM, TRUE, level);
2380 if (o_ptr->name2 == EGO_SHARPNESS && o_ptr->tval != TV_SWORD)
2382 if (o_ptr->name2 == EGO_EARTHQUAKES && o_ptr->tval != TV_HAFTED)
2387 switch (o_ptr->name2)
2390 if (one_in_(4) && (level > 40))
2391 add_flag(o_ptr->art_flags, TR_BLOWS);
2395 add_flag(o_ptr->art_flags, TR_RES_POIS);
2397 add_flag(o_ptr->art_flags, TR_WARNING);
2399 case EGO_KILL_DRAGON:
2401 add_flag(o_ptr->art_flags, TR_RES_POIS);
2405 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2407 case EGO_SLAYING_WEAPON:
2408 if (one_in_(3)) /* double damage */
2416 while (one_in_(o_ptr->dd));
2422 while (one_in_(o_ptr->ds));
2427 add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2429 if (o_ptr->tval == TV_SWORD && one_in_(3))
2431 add_flag(o_ptr->art_flags, TR_VORPAL);
2436 add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
2442 add_flag(o_ptr->art_flags, TR_HOLD_LIFE);
2444 add_flag(o_ptr->art_flags, TR_DEX);
2446 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2449 o_ptr->pval = m_bonus(5, level) + 1;
2451 case EGO_EARTHQUAKES:
2452 if (one_in_(3) && (level > 60))
2453 add_flag(o_ptr->art_flags, TR_BLOWS);
2455 o_ptr->pval = m_bonus(3, level);
2459 add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
2463 if (!o_ptr->art_name)
2465 /* Hack -- Super-charge the damage dice */
2466 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2468 /* Hack -- Lower the damage dice */
2469 if (o_ptr->dd > 9) o_ptr->dd = 9;
2474 else if (power < -1)
2476 /* Roll for ego-item */
2477 if (randint0(MAX_DEPTH) < level)
2479 o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE, level);
2480 switch (o_ptr->name2)
2483 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2499 create_artifact(o_ptr, FALSE);
2502 o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE, level);
2516 o_ptr->name2 = get_random_ego(INVEN_AMMO, TRUE, level);
2518 switch (o_ptr->name2)
2520 case EGO_SLAYING_BOLT:
2525 /* Hack -- super-charge the damage dice */
2526 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2528 /* Hack -- restrict the damage dice */
2529 if (o_ptr->dd > 9) o_ptr->dd = 9;
2533 else if (power < -1)
2535 /* Roll for ego-item */
2536 if (randint0(MAX_DEPTH) < level)
2538 o_ptr->name2 = get_random_ego(INVEN_AMMO, FALSE, level);
2548 static void dragon_resist(object_type * o_ptr)
2553 one_dragon_ele_resistance(o_ptr);
2555 one_high_resistance(o_ptr);
2561 static void add_esp_strong(object_type *o_ptr)
2563 switch (randint1(3))
2565 case 1: add_flag(o_ptr->art_flags, TR_ESP_EVIL); break;
2566 case 2: add_flag(o_ptr->art_flags, TR_ESP_NONLIVING); break;
2567 case 3: add_flag(o_ptr->art_flags, TR_TELEPATHY); break;
2572 static void add_esp_weak(object_type *o_ptr)
2575 int n = randint1(3);
2577 idx[0] = randint1(9);
2579 idx[1] = randint1(8);
2580 if (idx[1] >= idx[0]) idx[1]++;
2582 idx[2] = randint1(7);
2583 if (idx[2] >= idx[0]) idx[2]++;
2584 if (idx[2] >= idx[1]) idx[2]++;
2586 while (n--) switch (idx[n])
2588 case 1: add_flag(o_ptr->art_flags, TR_ESP_ANIMAL); break;
2589 case 2: add_flag(o_ptr->art_flags, TR_ESP_UNDEAD); break;
2590 case 3: add_flag(o_ptr->art_flags, TR_ESP_DEMON); break;
2591 case 4: add_flag(o_ptr->art_flags, TR_ESP_ORC); break;
2592 case 5: add_flag(o_ptr->art_flags, TR_ESP_TROLL); break;
2593 case 6: add_flag(o_ptr->art_flags, TR_ESP_GIANT); break;
2594 case 7: add_flag(o_ptr->art_flags, TR_ESP_DRAGON); break;
2595 case 8: add_flag(o_ptr->art_flags, TR_ESP_HUMAN); break;
2596 case 9: add_flag(o_ptr->art_flags, TR_ESP_GOOD); break;
2602 * Apply magic to an item known to be "armor"
2604 * Hack -- note special processing for crown/helm
2605 * Hack -- note special processing for robe of permanence
2607 static void a_m_aux_2(object_type *o_ptr, int level, int power)
2609 int toac1 = randint1(5) + m_bonus(5, level);
2611 int toac2 = m_bonus(10, level);
2617 o_ptr->to_a += toac1;
2623 o_ptr->to_a += toac2;
2631 o_ptr->to_a -= toac1;
2636 /* Penalize again */
2637 o_ptr->to_a -= toac2;
2640 /* Cursed (if "bad") */
2641 if (o_ptr->to_a < 0) o_ptr->curse_flags |= TRC_CURSED;
2646 switch (o_ptr->tval)
2653 create_artifact(o_ptr, FALSE);
2655 /* Mention the item */
2656 if (cheat_peek) object_mention(o_ptr);
2667 /* Hack -- Try for "Robes of the Magi" */
2668 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
2669 (o_ptr->sval == SV_ROBE) &&
2670 (randint0(100) < 15))
2674 o_ptr->name2 = EGO_YOIYAMI;
2675 o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
2676 o_ptr->sval = SV_YOIYAMI_ROBE;
2682 o_ptr->name2 = EGO_PERMANENCE;
2689 create_artifact(o_ptr, FALSE);
2695 bool okay_flag = TRUE;
2697 o_ptr->name2 = get_random_ego(INVEN_BODY, TRUE, level);
2699 switch (o_ptr->name2)
2701 case EGO_RESISTANCE:
2703 add_flag(o_ptr->art_flags, TR_RES_POIS);
2708 if (o_ptr->tval != TV_HARD_ARMOR)
2715 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2716 o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
2718 add_flag(o_ptr->art_flags, TR_CON);
2734 if (o_ptr->sval == SV_DRAGON_SHIELD)
2739 /* Mention the item */
2740 if (cheat_peek) object_mention(o_ptr);
2741 dragon_resist(o_ptr);
2742 if (!one_in_(3)) break;
2750 create_artifact(o_ptr, FALSE);
2753 o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE, level);
2755 switch (o_ptr->name2)
2758 if (!one_in_(3)) one_high_resistance(o_ptr);
2759 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_POIS);
2761 case EGO_REFLECTION:
2762 if (o_ptr->sval == SV_SHIELD_OF_DEFLECTION)
2772 if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
2777 /* Mention the item */
2778 if (cheat_peek) object_mention(o_ptr);
2779 dragon_resist(o_ptr);
2780 if (!one_in_(3)) break;
2786 create_artifact(o_ptr, FALSE);
2789 o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE, level);
2793 else if (power < -1)
2795 o_ptr->name2 = get_random_ego(INVEN_HANDS, FALSE, level);
2803 if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
2808 /* Mention the item */
2809 if (cheat_peek) object_mention(o_ptr);
2810 dragon_resist(o_ptr);
2811 if (!one_in_(3)) break;
2818 create_artifact(o_ptr, FALSE);
2821 o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE, level);
2823 switch (o_ptr->name2)
2825 case EGO_SLOW_DESCENT:
2828 one_high_resistance(o_ptr);
2834 else if (power < -1)
2836 o_ptr->name2 = get_random_ego(INVEN_FEET, FALSE, level);
2849 create_artifact(o_ptr, FALSE);
2854 bool ok_flag = TRUE;
2855 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE, level);
2857 switch (o_ptr->name2)
2860 add_esp_strong(o_ptr);
2861 add_esp_weak(o_ptr);
2865 case EGO_REGENERATION:
2866 case EGO_LORDLINESS:
2871 if (one_in_(2)) add_esp_strong(o_ptr);
2872 else add_esp_weak(o_ptr);
2875 default:/* not existing crown (wisdom,lite, etc...) */
2879 break; /* while (1) */
2885 else if (power < -1)
2887 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE, level);
2895 if (o_ptr->sval == SV_DRAGON_HELM)
2900 /* Mention the item */
2901 if (cheat_peek) object_mention(o_ptr);
2902 dragon_resist(o_ptr);
2903 if (!one_in_(3)) break;
2911 create_artifact(o_ptr, FALSE);
2916 bool ok_flag = TRUE;
2917 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE, level);
2919 switch (o_ptr->name2)
2921 case EGO_INTELLIGENCE:
2925 case EGO_INFRAVISION:
2930 if (one_in_(2)) add_esp_strong(o_ptr);
2931 else add_esp_weak(o_ptr);
2934 default:/* not existing helm (Magi, Might, etc...)*/
2938 break; /* while (1) */
2943 else if (power < -1)
2945 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE, level);
2957 create_artifact(o_ptr, FALSE);
2960 o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE, level);
2962 switch (o_ptr->name2)
2973 else if (power < -1)
2975 o_ptr->name2 = get_random_ego(INVEN_OUTER, FALSE, level);
2985 * Apply magic to an item known to be a "ring" or "amulet"
2987 * Hack -- note special rating boost for ring of speed
2988 * Hack -- note special rating boost for amulet of the magi
2989 * Hack -- note special "pval boost" code for ring of speed
2990 * Hack -- note that some items must be cursed (or blessed)
2992 static void a_m_aux_3(object_type *o_ptr, int level, int power)
2994 /* Apply magic (good or bad) according to type */
2995 switch (o_ptr->tval)
3000 switch (o_ptr->sval)
3002 case SV_RING_ATTACKS:
3005 o_ptr->pval = m_bonus(2, level);
3006 if (one_in_(15)) o_ptr->pval++;
3007 if (o_ptr->pval < 1) o_ptr->pval = 1;
3013 o_ptr->ident |= (IDENT_BROKEN);
3016 o_ptr->curse_flags |= TRC_CURSED;
3019 o_ptr->pval = 0 - (o_ptr->pval);
3030 /* Strength, Constitution, Dexterity, Intelligence */
3036 o_ptr->pval = 1 + m_bonus(5, level);
3042 o_ptr->ident |= (IDENT_BROKEN);
3045 o_ptr->curse_flags |= TRC_CURSED;
3048 o_ptr->pval = 0 - (o_ptr->pval);
3054 /* Ring of Speed! */
3057 /* Base speed (1 to 10) */
3058 o_ptr->pval = randint1(5) + m_bonus(5, level);
3060 /* Super-charge the ring */
3061 while (randint0(100) < 50) o_ptr->pval++;
3067 o_ptr->ident |= (IDENT_BROKEN);
3070 o_ptr->curse_flags |= TRC_CURSED;
3073 o_ptr->pval = 0 - (o_ptr->pval);
3081 /* Mention the item */
3082 if (cheat_peek) object_mention(o_ptr);
3087 case SV_RING_LORDLY:
3091 one_lordly_high_resistance(o_ptr);
3095 /* Bonus to armor class */
3096 o_ptr->to_a = 10 + randint1(5) + m_bonus(10, level);
3101 case SV_RING_WARNING:
3103 if (one_in_(3)) one_low_esp(o_ptr);
3108 case SV_RING_SEARCHING:
3110 /* Bonus to searching */
3111 o_ptr->pval = 1 + m_bonus(5, level);
3117 o_ptr->ident |= (IDENT_BROKEN);
3120 o_ptr->curse_flags |= TRC_CURSED;
3123 o_ptr->pval = 0 - (o_ptr->pval);
3129 /* Flames, Acid, Ice */
3130 case SV_RING_FLAMES:
3135 /* Bonus to armor class */
3136 o_ptr->to_a = 5 + randint1(5) + m_bonus(10, level);
3140 /* Weakness, Stupidity */
3141 case SV_RING_WEAKNESS:
3142 case SV_RING_STUPIDITY:
3145 o_ptr->ident |= (IDENT_BROKEN);
3148 o_ptr->curse_flags |= TRC_CURSED;
3151 o_ptr->pval = 0 - (1 + m_bonus(5, level));
3152 if (power > 0) power = 0 - power;
3157 /* WOE, Stupidity */
3161 o_ptr->ident |= (IDENT_BROKEN);
3164 o_ptr->curse_flags |= TRC_CURSED;
3167 o_ptr->to_a = 0 - (5 + m_bonus(10, level));
3168 o_ptr->pval = 0 - (1 + m_bonus(5, level));
3169 if (power > 0) power = 0 - power;
3174 /* Ring of damage */
3175 case SV_RING_DAMAGE:
3177 /* Bonus to damage */
3178 o_ptr->to_d = 1 + randint1(5) + m_bonus(16, level);
3184 o_ptr->ident |= (IDENT_BROKEN);
3187 o_ptr->curse_flags |= TRC_CURSED;
3190 o_ptr->to_d = 0 - o_ptr->to_d;
3196 /* Ring of Accuracy */
3197 case SV_RING_ACCURACY:
3200 o_ptr->to_h = 1 + randint1(5) + m_bonus(16, level);
3206 o_ptr->ident |= (IDENT_BROKEN);
3209 o_ptr->curse_flags |= TRC_CURSED;
3212 o_ptr->to_h = 0 - o_ptr->to_h;
3218 /* Ring of Protection */
3219 case SV_RING_PROTECTION:
3221 /* Bonus to armor class */
3222 o_ptr->to_a = 5 + randint1(8) + m_bonus(10, level);
3228 o_ptr->ident |= (IDENT_BROKEN);
3231 o_ptr->curse_flags |= TRC_CURSED;
3234 o_ptr->to_a = 0 - o_ptr->to_a;
3240 /* Ring of Slaying */
3241 case SV_RING_SLAYING:
3243 /* Bonus to damage and to hit */
3244 o_ptr->to_d = randint1(5) + m_bonus(12, level);
3245 o_ptr->to_h = randint1(5) + m_bonus(12, level);
3251 o_ptr->ident |= (IDENT_BROKEN);
3254 o_ptr->curse_flags |= TRC_CURSED;
3256 /* Reverse bonuses */
3257 o_ptr->to_h = 0 - o_ptr->to_h;
3258 o_ptr->to_d = 0 - o_ptr->to_d;
3264 case SV_RING_MUSCLE:
3266 o_ptr->pval = 1 + m_bonus(3, level);
3267 if (one_in_(4)) o_ptr->pval++;
3273 o_ptr->ident |= (IDENT_BROKEN);
3276 o_ptr->curse_flags |= TRC_CURSED;
3278 /* Reverse bonuses */
3279 o_ptr->pval = 0 - o_ptr->pval;
3284 case SV_RING_AGGRAVATION:
3287 o_ptr->ident |= (IDENT_BROKEN);
3290 o_ptr->curse_flags |= TRC_CURSED;
3292 if (power > 0) power = 0 - power;
3296 if (one_in_(400) && (power > 0) && !cursed_p(o_ptr) && (level > 79))
3298 o_ptr->pval = MIN(o_ptr->pval,4);
3299 /* Randart amulet */
3300 create_artifact(o_ptr, FALSE);
3302 else if ((power == 2) && one_in_(2))
3304 while(!o_ptr->name2)
3306 int tmp = m_bonus(10, level);
3307 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3308 switch(randint1(28))
3311 o_ptr->name2 = EGO_RING_THROW;
3314 if (have_flag(k_ptr->flags, TR_REGEN)) break;
3315 o_ptr->name2 = EGO_RING_REGEN;
3318 if (have_flag(k_ptr->flags, TR_LITE)) break;
3319 o_ptr->name2 = EGO_RING_LITE;
3322 if (have_flag(k_ptr->flags, TR_TELEPORT)) break;
3323 o_ptr->name2 = EGO_RING_TELEPORT;
3326 if (o_ptr->to_h) break;
3327 o_ptr->name2 = EGO_RING_TO_H;
3330 if (o_ptr->to_d) break;
3331 o_ptr->name2 = EGO_RING_TO_D;
3334 if ((o_ptr->to_h) || (o_ptr->to_d)) break;
3335 o_ptr->name2 = EGO_RING_SLAY;
3338 if ((have_flag(k_ptr->flags, TR_STR)) || o_ptr->to_h || o_ptr->to_d) break;
3339 o_ptr->name2 = EGO_RING_WIZARD;
3342 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3343 o_ptr->name2 = EGO_RING_HERO;
3346 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3347 if (tmp > 8) o_ptr->name2 = EGO_RING_MANA_BALL;
3348 else if (tmp > 4) o_ptr->name2 = EGO_RING_MANA_BOLT;
3349 else o_ptr->name2 = EGO_RING_MAGIC_MIS;
3352 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3353 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;
3354 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_F;
3355 else if (tmp > 3) o_ptr->name2 = EGO_RING_FIRE_BALL;
3356 else o_ptr->name2 = EGO_RING_FIRE_BOLT;
3359 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3360 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;
3361 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_C;
3362 else if (tmp > 3) o_ptr->name2 = EGO_RING_COLD_BALL;
3363 else o_ptr->name2 = EGO_RING_COLD_BOLT;
3366 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3367 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;
3368 if (tmp > 4) o_ptr->name2 = EGO_RING_ELEC_BALL;
3369 else o_ptr->name2 = EGO_RING_ELEC_BOLT;
3372 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3373 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;
3374 if (tmp > 4) o_ptr->name2 = EGO_RING_ACID_BALL;
3375 else o_ptr->name2 = EGO_RING_ACID_BOLT;
3377 case 21: case 22: case 23: case 24: case 25: case 26:
3378 switch (o_ptr->sval)
3381 if (!one_in_(3)) break;
3382 o_ptr->name2 = EGO_RING_D_SPEED;
3384 case SV_RING_DAMAGE:
3385 case SV_RING_ACCURACY:
3386 case SV_RING_SLAYING:
3387 if (one_in_(2)) break;
3388 if (one_in_(2)) o_ptr->name2 = EGO_RING_HERO;
3391 o_ptr->name2 = EGO_RING_BERSERKER;
3392 o_ptr->to_h -= 2+randint1(4);
3393 o_ptr->to_d += 2+randint1(4);
3396 case SV_RING_PROTECTION:
3397 o_ptr->name2 = EGO_RING_SUPER_AC;
3398 o_ptr->to_a += 7 + m_bonus(5, level);
3400 case SV_RING_RES_FEAR:
3401 o_ptr->name2 = EGO_RING_HERO;
3404 if (one_in_(2)) break;
3405 o_ptr->name2 = EGO_RING_HUNTER;
3407 case SV_RING_SEARCHING:
3408 o_ptr->name2 = EGO_RING_STEALTH;
3410 case SV_RING_TELEPORTATION:
3411 o_ptr->name2 = EGO_RING_TELE_AWAY;
3413 case SV_RING_RES_BLINDNESS:
3415 o_ptr->name2 = EGO_RING_RES_LITE;
3417 o_ptr->name2 = EGO_RING_RES_DARK;
3419 case SV_RING_LORDLY:
3420 if (!one_in_(20)) break;
3421 one_lordly_high_resistance(o_ptr);
3422 one_lordly_high_resistance(o_ptr);
3423 o_ptr->name2 = EGO_RING_TRUE;
3425 case SV_RING_SUSTAIN:
3426 if (!one_in_(4)) break;
3427 o_ptr->name2 = EGO_RING_RES_TIME;
3429 case SV_RING_FLAMES:
3430 if (!one_in_(2)) break;
3431 o_ptr->name2 = EGO_RING_DRAGON_F;
3434 if (!one_in_(2)) break;
3435 o_ptr->name2 = EGO_RING_DRAGON_C;
3437 case SV_RING_WARNING:
3438 if (!one_in_(2)) break;
3439 o_ptr->name2 = EGO_RING_M_DETECT;
3448 o_ptr->curse_flags = 0L;
3450 else if ((power == -2) && one_in_(2))
3452 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3453 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3454 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3455 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3456 o_ptr->art_flags[0] = 0;
3457 o_ptr->art_flags[1] = 0;
3458 while(!o_ptr->name2)
3460 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3464 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3465 o_ptr->name2 = EGO_RING_DRAIN_EXP;
3468 o_ptr->name2 = EGO_RING_NO_MELEE;
3471 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3472 o_ptr->name2 = EGO_RING_AGGRAVATE;
3475 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3476 o_ptr->name2 = EGO_RING_TY_CURSE;
3479 o_ptr->name2 = EGO_RING_ALBINO;
3484 o_ptr->ident |= (IDENT_BROKEN);
3487 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3495 switch (o_ptr->sval)
3497 /* Amulet of wisdom/charisma */
3498 case SV_AMULET_INTELLIGENCE:
3499 case SV_AMULET_WISDOM:
3500 case SV_AMULET_CHARISMA:
3502 o_ptr->pval = 1 + m_bonus(5, level);
3508 o_ptr->ident |= (IDENT_BROKEN);
3511 o_ptr->curse_flags |= (TRC_CURSED);
3513 /* Reverse bonuses */
3514 o_ptr->pval = 0 - o_ptr->pval;
3520 /* Amulet of brilliance */
3521 case SV_AMULET_BRILLIANCE:
3523 o_ptr->pval = 1 + m_bonus(3, level);
3524 if (one_in_(4)) o_ptr->pval++;
3530 o_ptr->ident |= (IDENT_BROKEN);
3533 o_ptr->curse_flags |= (TRC_CURSED);
3535 /* Reverse bonuses */
3536 o_ptr->pval = 0 - o_ptr->pval;
3542 case SV_AMULET_NO_MAGIC: case SV_AMULET_NO_TELE:
3546 o_ptr->curse_flags |= (TRC_CURSED);
3551 case SV_AMULET_RESISTANCE:
3553 if (one_in_(5)) one_high_resistance(o_ptr);
3554 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_RES_POIS);
3558 /* Amulet of searching */
3559 case SV_AMULET_SEARCHING:
3561 o_ptr->pval = randint1(2) + m_bonus(4, level);
3567 o_ptr->ident |= (IDENT_BROKEN);
3570 o_ptr->curse_flags |= (TRC_CURSED);
3572 /* Reverse bonuses */
3573 o_ptr->pval = 0 - (o_ptr->pval);
3579 /* Amulet of the Magi -- never cursed */
3580 case SV_AMULET_THE_MAGI:
3582 o_ptr->pval = randint1(5) + m_bonus(5, level);
3583 o_ptr->to_a = randint1(5) + m_bonus(5, level);
3585 /* gain one low ESP */
3586 add_esp_weak(o_ptr);
3588 /* Boost the rating */
3591 /* Mention the item */
3592 if (cheat_peek) object_mention(o_ptr);
3597 /* Amulet of Doom -- always cursed */
3598 case SV_AMULET_DOOM:
3601 o_ptr->ident |= (IDENT_BROKEN);
3604 o_ptr->curse_flags |= (TRC_CURSED);
3607 o_ptr->pval = 0 - (randint1(5) + m_bonus(5, level));
3608 o_ptr->to_a = 0 - (randint1(5) + m_bonus(5, level));
3609 if (power > 0) power = 0 - power;
3614 case SV_AMULET_MAGIC_MASTERY:
3616 o_ptr->pval = 1 + m_bonus(4, level);
3622 o_ptr->ident |= (IDENT_BROKEN);
3625 o_ptr->curse_flags |= (TRC_CURSED);
3627 /* Reverse bonuses */
3628 o_ptr->pval = 0 - o_ptr->pval;
3634 if (one_in_(150) && (power > 0) && !cursed_p(o_ptr) && (level > 79))
3636 o_ptr->pval = MIN(o_ptr->pval,4);
3637 /* Randart amulet */
3638 create_artifact(o_ptr, FALSE);
3640 else if ((power == 2) && one_in_(2))
3642 while(!o_ptr->name2)
3644 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3645 switch(randint1(21))
3648 if (have_flag(k_ptr->flags, TR_SLOW_DIGEST)) break;
3649 o_ptr->name2 = EGO_AMU_SLOW_D;
3652 if (o_ptr->pval) break;
3653 o_ptr->name2 = EGO_AMU_INFRA;
3656 if (have_flag(k_ptr->flags, TR_SEE_INVIS)) break;
3657 o_ptr->name2 = EGO_AMU_SEE_INVIS;
3660 if (have_flag(k_ptr->flags, TR_HOLD_LIFE)) break;
3661 o_ptr->name2 = EGO_AMU_HOLD_LIFE;
3664 if (have_flag(k_ptr->flags, TR_FEATHER)) break;
3665 o_ptr->name2 = EGO_AMU_LEVITATION;
3667 case 10: case 11: case 21:
3668 o_ptr->name2 = EGO_AMU_AC;
3671 if (have_flag(k_ptr->flags, TR_RES_FIRE)) break;
3672 if (m_bonus(10, level) > 8)
3673 o_ptr->name2 = EGO_AMU_RES_FIRE_;
3675 o_ptr->name2 = EGO_AMU_RES_FIRE;
3678 if (have_flag(k_ptr->flags, TR_RES_COLD)) break;
3679 if (m_bonus(10, level) > 8)
3680 o_ptr->name2 = EGO_AMU_RES_COLD_;
3682 o_ptr->name2 = EGO_AMU_RES_COLD;
3685 if (have_flag(k_ptr->flags, TR_RES_ELEC)) break;
3686 if (m_bonus(10, level) > 8)
3687 o_ptr->name2 = EGO_AMU_RES_ELEC_;
3689 o_ptr->name2 = EGO_AMU_RES_ELEC;
3692 if (have_flag(k_ptr->flags, TR_RES_ACID)) break;
3693 if (m_bonus(10, level) > 8)
3694 o_ptr->name2 = EGO_AMU_RES_ACID_;
3696 o_ptr->name2 = EGO_AMU_RES_ACID;
3698 case 16: case 17: case 18: case 19: case 20:
3699 switch (o_ptr->sval)
3701 case SV_AMULET_TELEPORT:
3702 if (m_bonus(10, level) > 9) o_ptr->name2 = EGO_AMU_D_DOOR;
3703 else if (one_in_(2)) o_ptr->name2 = EGO_AMU_JUMP;
3704 else o_ptr->name2 = EGO_AMU_TELEPORT;
3706 case SV_AMULET_RESIST_ACID:
3707 if ((m_bonus(10, level) > 6) && one_in_(2)) o_ptr->name2 = EGO_AMU_RES_ACID_;
3709 case SV_AMULET_SEARCHING:
3710 o_ptr->name2 = EGO_AMU_STEALTH;
3712 case SV_AMULET_BRILLIANCE:
3713 if (!one_in_(3)) break;
3714 o_ptr->name2 = EGO_AMU_IDENT;
3716 case SV_AMULET_CHARISMA:
3717 if (!one_in_(3)) break;
3718 o_ptr->name2 = EGO_AMU_CHARM;
3720 case SV_AMULET_THE_MAGI:
3721 if (one_in_(2)) break;
3722 o_ptr->name2 = EGO_AMU_GREAT;
3724 case SV_AMULET_RESISTANCE:
3725 if (!one_in_(5)) break;
3726 o_ptr->name2 = EGO_AMU_DEFENDER;
3728 case SV_AMULET_TELEPATHY:
3729 if (!one_in_(3)) break;
3730 o_ptr->name2 = EGO_AMU_DETECTION;
3736 o_ptr->curse_flags = 0L;
3738 else if ((power == -2) && one_in_(2))
3740 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3741 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3742 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3743 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3744 o_ptr->art_flags[0] = 0;
3745 o_ptr->art_flags[1] = 0;
3746 while(!o_ptr->name2)
3748 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3752 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3753 o_ptr->name2 = EGO_AMU_DRAIN_EXP;
3756 o_ptr->name2 = EGO_AMU_FOOL;
3759 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3760 o_ptr->name2 = EGO_AMU_AGGRAVATE;
3763 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3764 o_ptr->name2 = EGO_AMU_TY_CURSE;
3767 o_ptr->name2 = EGO_AMU_NAIVETY;
3772 o_ptr->ident |= (IDENT_BROKEN);
3775 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3784 * Hack -- help pick an item type
3786 static bool item_monster_okay(int r_idx)
3788 monster_race *r_ptr = &r_info[r_idx];
3791 if (r_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3792 if (r_ptr->flags7 & RF7_KAGE) return (FALSE);
3793 if (r_ptr->flags3 & RF3_RES_ALL) return (FALSE);
3794 if (r_ptr->flags7 & RF7_UNIQUE_7) return (FALSE);
3795 if (r_ptr->flags1 & RF1_FORCE_DEPTH) return (FALSE);
3796 if (r_ptr->flags7 & RF7_UNIQUE2) return (FALSE);
3804 * Apply magic to an item known to be "boring"
3806 * Hack -- note the special code for various items
3808 static void a_m_aux_4(object_type *o_ptr, int level, int power)
3810 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3812 /* Apply magic (good or bad) according to type */
3813 switch (o_ptr->tval)
3822 o_ptr->ident |= (IDENT_BROKEN);
3825 o_ptr->curse_flags |= (TRC_CURSED);
3832 o_ptr->xtra4 = o_ptr->pval;
3838 /* Hack -- Torches -- random fuel */
3839 if (o_ptr->sval == SV_LITE_TORCH)
3841 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3845 /* Hack -- Lanterns -- random fuel */
3846 if (o_ptr->sval == SV_LITE_LANTERN)
3848 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3852 if ((power == 2) || ((power == 1) && one_in_(3)))
3854 while (!o_ptr->name2)
3858 bool okay_flag = TRUE;
3860 o_ptr->name2 = get_random_ego(INVEN_LITE, TRUE, level);
3862 switch (o_ptr->name2)
3865 if (o_ptr->sval == SV_LITE_FEANOR)
3873 else if (power == -2)
3875 o_ptr->name2 = get_random_ego(INVEN_LITE, FALSE, level);
3877 switch (o_ptr->name2)
3879 case EGO_LITE_DARKNESS:
3891 /* The wand or staff gets a number of initial charges equal
3892 * to between 1/2 (+1) and the full object kind's pval. -LM-
3894 o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
3900 /* Transfer the pval. -LM- */
3901 o_ptr->pval = k_ptr->pval;
3908 object_aware(o_ptr);
3909 object_known(o_ptr);
3918 monster_race *r_ptr;
3920 /* Pick a random non-unique monster race */
3923 i = randint1(max_r_idx - 1);
3925 if (!item_monster_okay(i)) continue;
3926 if (i == MON_TSUCHINOKO) continue;
3930 check = (dun_level < r_ptr->level) ? (r_ptr->level - dun_level) : 0;
3932 /* Ignore dead monsters */
3933 if (!r_ptr->rarity) continue;
3935 /* Prefer less out-of-depth monsters */
3936 if (randint0(check)) continue;
3943 /* Some figurines are cursed */
3944 if (one_in_(6)) o_ptr->curse_flags |= TRC_CURSED;
3949 msg_format("%s¤Î¿Í·Á, ¿¼¤µ +%d%s",
3951 msg_format("Figurine of %s, depth +%d%s",
3954 r_name + r_ptr->name, check - 1,
3955 !cursed_p(o_ptr) ? "" : " {cursed}");
3968 monster_race *r_ptr;
3970 if (o_ptr->sval == SV_SKELETON)
3972 match = RF9_DROP_SKELETON;
3974 else if (o_ptr->sval == SV_CORPSE)
3976 match = RF9_DROP_CORPSE;
3979 /* Hack -- Remove the monster restriction */
3980 get_mon_num_prep(item_monster_okay, NULL);
3982 /* Pick a random non-unique monster race */
3985 i = get_mon_num(dun_level);
3989 check = (dun_level < r_ptr->level) ? (r_ptr->level - dun_level) : 0;
3991 /* Ignore dead monsters */
3992 if (!r_ptr->rarity) continue;
3994 /* Ignore corpseless monsters */
3995 if (!(r_ptr->flags9 & match)) continue;
3997 /* Prefer less out-of-depth monsters */
3998 if (randint0(check)) continue;
4008 msg_format("%s¤Î»àÂÎ,¿¼¤µ +%d",
4010 msg_format("Corpse of %s, depth +%d",
4013 r_name + r_ptr->name, check - 1);
4016 object_aware(o_ptr);
4017 object_known(o_ptr);
4025 monster_race *r_ptr;
4027 /* Pick a random monster race */
4030 i = randint1(max_r_idx - 1);
4034 /* Ignore dead monsters */
4035 if (!r_ptr->rarity) continue;
4045 msg_format("%s¤ÎÁü,", r_name + r_ptr->name);
4047 msg_format("Statue of %s", r_name + r_ptr->name);
4051 object_aware(o_ptr);
4052 object_known(o_ptr);
4059 byte obj_level = get_object_level(o_ptr);
4061 /* Hack -- skip ruined chests */
4062 if (obj_level <= 0) break;
4064 /* Hack -- pick a "difficulty" */
4065 o_ptr->pval = randint1(obj_level);
4066 if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
4068 o_ptr->xtra3 = dun_level + 5;
4070 /* Never exceed "difficulty" of 55 to 59 */
4071 if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
4080 * Complete the "creation" of an object by applying "magic" to the item
4082 * This includes not only rolling for random bonuses, but also putting the
4083 * finishing touches on ego-items and artifacts, giving charges to wands and
4084 * staffs, giving fuel to lites, and placing traps on chests.
4086 * In particular, note that "Instant Artifacts", if "created" by an external
4087 * routine, must pass through this function to complete the actual creation.
4089 * The base "chance" of the item being "good" increases with the "level"
4090 * parameter, which is usually derived from the dungeon level, being equal
4091 * to the level plus 10, up to a maximum of 75. If "good" is true, then
4092 * the object is guaranteed to be "good". If an object is "good", then
4093 * the chance that the object will be "great" (ego-item or artifact), also
4094 * increases with the "level", being equal to half the level, plus 5, up to
4095 * a maximum of 20. If "great" is true, then the object is guaranteed to be
4096 * "great". At dungeon level 65 and below, 15/100 objects are "great".
4098 * If the object is not "good", there is a chance it will be "cursed", and
4099 * if it is "cursed", there is a chance it will be "broken". These chances
4100 * are related to the "good" / "great" chances above.
4102 * Otherwise "normal" rings and amulets will be "good" half the time and
4103 * "cursed" half the time, unless the ring/amulet is always good or cursed.
4105 * If "okay" is true, and the object is going to be "great", then there is
4106 * a chance that an artifact will be created. This is true even if both the
4107 * "good" and "great" arguments are false. As a total hack, if "great" is
4108 * true, then the item gets 3 extra "attempts" to become an artifact.
4110 void apply_magic(object_type *o_ptr, int lev, bool okay, bool good, bool great, bool curse)
4113 int i, rolls, f1, f2, power;
4115 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) lev += randint0(p_ptr->lev/2+10);
4117 /* Maximum "level" for various things */
4118 if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1;
4120 /* Base chance of being "good" */
4123 /* Maximal chance of being "good" */
4124 if (f1 > d_info[dungeon_type].obj_good) f1 = d_info[dungeon_type].obj_good;
4126 /* Base chance of being "great" */
4129 /* Maximal chance of being "great" */
4130 if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[dungeon_type].obj_great))
4131 f2 = d_info[dungeon_type].obj_great;
4133 if (p_ptr->muta3 & MUT3_GOOD_LUCK)
4138 else if(p_ptr->muta3 & MUT3_BAD_LUCK)
4147 /* Roll for "good" */
4148 if (good || magik(f1))
4153 /* Roll for "great" */
4154 if (great || magik(f2)) power = 2;
4157 /* Roll for "cursed" */
4160 /* Assume "cursed" */
4163 /* Roll for "broken" */
4164 if (magik(f2)) power = -2;
4170 /* Assume 'cursed' */
4175 /* Everything else gets more badly cursed */
4182 /* Assume no rolls */
4185 /* Get one roll if excellent */
4186 if (power >= 2) rolls = 1;
4188 /* Hack -- Get four rolls if forced great */
4189 if (great) rolls = 4;
4191 /* Hack -- Get no rolls if not allowed */
4192 if (!okay || o_ptr->name1) rolls = 0;
4194 /* Roll for artifacts if allowed */
4195 for (i = 0; i < rolls; i++)
4197 /* Roll for an artifact */
4198 if (make_artifact(o_ptr)) break;
4199 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77))
4201 if (make_artifact(o_ptr)) break;
4206 /* Hack -- analyze artifacts */
4209 artifact_type *a_ptr = &a_info[o_ptr->name1];
4211 /* Hack -- Mark the artifact as "created" */
4214 /* Extract the other fields */
4215 o_ptr->pval = a_ptr->pval;
4216 o_ptr->ac = a_ptr->ac;
4217 o_ptr->dd = a_ptr->dd;
4218 o_ptr->ds = a_ptr->ds;
4219 o_ptr->to_a = a_ptr->to_a;
4220 o_ptr->to_h = a_ptr->to_h;
4221 o_ptr->to_d = a_ptr->to_d;
4222 o_ptr->weight = a_ptr->weight;
4224 /* Hack -- extract the "broken" flag */
4225 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4227 /* Hack -- extract the "cursed" flag */
4228 if (a_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4229 if (a_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4230 if (a_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4231 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4232 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4233 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4235 /* Mega-Hack -- increase the rating */
4238 /* Mega-Hack -- increase the rating again */
4239 if (a_ptr->cost > 50000L) rating += 10;
4241 /* Mega-Hack -- increase the rating again */
4242 if (a_ptr->cost > 100000L) rating += 10;
4244 /* Set the good item flag */
4245 good_item_flag = TRUE;
4247 /* Cheat -- peek at the item */
4248 if (cheat_peek) object_mention(o_ptr);
4256 switch (o_ptr->tval)
4265 if (power) a_m_aux_1(o_ptr, lev, power);
4271 if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) a_m_aux_1(o_ptr, lev, power);
4277 if (power && !(o_ptr->sval == SV_DOKUBARI)) a_m_aux_1(o_ptr, lev, power);
4291 /* Elven Cloak and Black Clothes ... */
4292 if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) ||
4293 ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
4294 o_ptr->pval = randint1(4);
4298 ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) ||
4299 ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD)) ||
4300 ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)) ||
4301 ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
4302 a_m_aux_2(o_ptr, lev, power);
4304 if (power) a_m_aux_2(o_ptr, lev, power);
4312 if (!power && (randint0(100) < 50)) power = -1;
4313 a_m_aux_3(o_ptr, lev, power);
4319 a_m_aux_4(o_ptr, lev, power);
4324 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
4325 (o_ptr->sval == SV_ABUNAI_MIZUGI) &&
4326 (p_ptr->pseikaku == SEIKAKU_SEXY))
4329 add_flag(o_ptr->art_flags, TR_STR);
4330 add_flag(o_ptr->art_flags, TR_INT);
4331 add_flag(o_ptr->art_flags, TR_WIS);
4332 add_flag(o_ptr->art_flags, TR_DEX);
4333 add_flag(o_ptr->art_flags, TR_CON);
4334 add_flag(o_ptr->art_flags, TR_CHR);
4337 if (o_ptr->art_name) rating += 30;
4339 /* Hack -- analyze ego-items */
4340 else if (o_ptr->name2)
4342 ego_item_type *e_ptr = &e_info[o_ptr->name2];
4344 /* Hack -- acquire "broken" flag */
4345 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4347 /* Hack -- acquire "cursed" flag */
4348 if (e_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4349 if (e_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4350 if (e_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4351 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4352 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4353 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4355 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN)) one_sustain(o_ptr);
4356 if (e_ptr->gen_flags & (TRG_XTRA_POWER)) one_ability(o_ptr);
4357 if (e_ptr->gen_flags & (TRG_XTRA_H_RES)) one_high_resistance(o_ptr);
4358 if (e_ptr->gen_flags & (TRG_XTRA_E_RES)) one_ele_resistance(o_ptr);
4359 if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
4360 if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
4361 if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
4363 /* Hack -- apply extra penalties if needed */
4364 if (cursed_p(o_ptr) || broken_p(o_ptr))
4366 /* Hack -- obtain bonuses */
4367 if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
4368 if (e_ptr->max_to_d) o_ptr->to_d -= randint1(e_ptr->max_to_d);
4369 if (e_ptr->max_to_a) o_ptr->to_a -= randint1(e_ptr->max_to_a);
4371 /* Hack -- obtain pval */
4372 if (e_ptr->max_pval) o_ptr->pval -= randint1(e_ptr->max_pval);
4375 /* Hack -- apply extra bonuses if needed */
4378 /* Hack -- obtain bonuses */
4379 if (e_ptr->max_to_h)
4381 if (e_ptr->max_to_h > 127)
4382 o_ptr->to_h -= randint1(256-e_ptr->max_to_h);
4383 else o_ptr->to_h += randint1(e_ptr->max_to_h);
4385 if (e_ptr->max_to_d)
4387 if (e_ptr->max_to_d > 127)
4388 o_ptr->to_d -= randint1(256-e_ptr->max_to_d);
4389 else o_ptr->to_d += randint1(e_ptr->max_to_d);
4391 if (e_ptr->max_to_a)
4393 if (e_ptr->max_to_a > 127)
4394 o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
4395 else o_ptr->to_a += randint1(e_ptr->max_to_a);
4398 /* Hack -- obtain pval */
4399 if (e_ptr->max_pval)
4401 if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS)))
4404 if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
4406 else if (o_ptr->name2 == EGO_ATTACKS)
4408 o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
4409 if (o_ptr->pval > 3) o_ptr->pval = 3;
4410 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
4411 o_ptr->pval += randint1(2);
4413 else if (o_ptr->name2 == EGO_BAT)
4415 o_ptr->pval = randint1(e_ptr->max_pval);
4416 if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
4420 o_ptr->pval += randint1(e_ptr->max_pval);
4423 if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
4425 o_ptr->pval = randint1(o_ptr->pval);
4427 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
4431 /* Hack -- apply rating bonus */
4432 rating += e_ptr->rating;
4434 /* Cheat -- describe the item */
4435 if (cheat_peek) object_mention(o_ptr);
4441 /* Examine real objects */
4444 object_kind *k_ptr = &k_info[o_ptr->k_idx];
4446 /* Hack -- acquire "broken" flag */
4447 if (!get_object_cost(o_ptr)) o_ptr->ident |= (IDENT_BROKEN);
4449 /* Hack -- acquire "cursed" flag */
4450 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
4451 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
4452 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
4453 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4454 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4455 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4461 * Hack -- determine if a template is "good"
4463 static bool kind_is_good(int k_idx)
4465 object_kind *k_ptr = &k_info[k_idx];
4467 /* Analyze the item type */
4468 switch (k_ptr->tval)
4470 /* Armor -- Good unless damaged */
4481 if (k_ptr->to_a < 0) return (FALSE);
4485 /* Weapons -- Good unless damaged */
4492 if (k_ptr->to_h < 0) return (FALSE);
4493 if (k_ptr->to_d < 0) return (FALSE);
4497 /* Ammo -- Arrows/Bolts are good */
4504 /* Books -- High level books are good (except Arcane books) */
4506 case TV_SORCERY_BOOK:
4507 case TV_NATURE_BOOK:
4511 case TV_ENCHANT_BOOK:
4512 case TV_DAEMON_BOOK:
4513 case TV_CRUSADE_BOOK:
4515 case TV_HISSATSU_BOOK:
4517 if (k_ptr->sval >= SV_BOOK_MIN_GOOD) return (TRUE);
4521 /* Rings -- Rings of Speed are good */
4524 if (k_ptr->sval == SV_RING_SPEED) return (TRUE);
4525 if (k_ptr->sval == SV_RING_LORDLY) return (TRUE);
4529 /* Amulets -- Amulets of the Magi and Resistance are good */
4532 if (k_ptr->sval == SV_AMULET_THE_MAGI) return (TRUE);
4533 if (k_ptr->sval == SV_AMULET_RESISTANCE) return (TRUE);
4538 /* Assume not good */
4544 * Attempt to make an object (normal or good/great)
4546 * This routine plays nasty games to generate the "special artifacts".
4548 * This routine uses "object_level" for the "generation level".
4550 * We assume that the given object has been "wiped".
4552 bool make_object(object_type *j_ptr, bool good, bool great)
4558 /* Chance of "special object" */
4559 prob = (good ? 10 : 1000);
4561 /* Base level for the object */
4562 base = (good ? (object_level + 10) : object_level);
4565 /* Generate a special object, or a normal object */
4566 if (!one_in_(prob) || !make_artifact_special(j_ptr))
4573 /* Activate restriction */
4574 get_obj_num_hook = kind_is_good;
4576 /* Prepare allocation table */
4580 /* Pick a random object */
4581 k_idx = get_obj_num(base);
4584 if (get_obj_num_hook)
4586 /* Clear restriction */
4587 get_obj_num_hook = NULL;
4589 /* Prepare allocation table */
4593 /* Handle failure */
4594 if (!k_idx) return (FALSE);
4596 /* Prepare the object */
4597 object_prep(j_ptr, k_idx);
4600 /* Apply magic (allow artifacts) */
4601 apply_magic(j_ptr, object_level, TRUE, good, great, FALSE);
4603 /* Hack -- generate multiple spikes/missiles */
4604 switch (j_ptr->tval)
4612 j_ptr->number = (byte)damroll(6, 7);
4616 obj_level = get_object_level(j_ptr);
4617 if (artifact_p(j_ptr)) obj_level = a_info[j_ptr->name1].level;
4619 /* Notice "okay" out-of-depth objects */
4620 if (!cursed_p(j_ptr) && !broken_p(j_ptr) &&
4621 (obj_level > dun_level))
4623 /* Rating increase */
4624 rating += (obj_level - dun_level);
4626 /* Cheat -- peek at items */
4627 if (cheat_peek) object_mention(j_ptr);
4636 * Attempt to place an object (normal or good/great) at the given location.
4638 * This routine plays nasty games to generate the "special artifacts".
4640 * This routine uses "object_level" for the "generation level".
4642 * This routine requires a clean floor grid destination.
4644 void place_object(int y, int x, bool good, bool great)
4654 /* Paranoia -- check bounds */
4655 if (!in_bounds(y, x)) return;
4657 /* Require clean floor space */
4658 if (!cave_clean_bold(y, x)) return;
4661 /* Get local object */
4664 /* Wipe the object */
4667 /* Make an object (if possible) */
4668 if (!make_object(q_ptr, good, great)) return;
4671 /* Make an object */
4679 /* Acquire object */
4680 o_ptr = &o_list[o_idx];
4682 /* Structure Copy */
4683 object_copy(o_ptr, q_ptr);
4690 c_ptr = &cave[y][x];
4693 o_ptr->next_o_idx = c_ptr->o_idx;
4695 /* Place the object */
4696 c_ptr->o_idx = o_idx;
4706 /* Hack -- Preserve artifacts */
4709 a_info[q_ptr->name1].cur_num = 0;
4716 * Make a treasure object
4718 * The location must be a legal, clean, floor grid.
4720 bool make_gold(object_type *j_ptr)
4727 /* Hack -- Pick a Treasure variety */
4728 i = ((randint1(object_level + 2) + 2) / 2) - 1;
4730 /* Apply "extra" magic */
4731 if (one_in_(GREAT_OBJ))
4733 i += randint1(object_level + 1);
4736 /* Hack -- Creeping Coins only generate "themselves" */
4737 if (coin_type) i = coin_type;
4739 /* Do not create "illegal" Treasure Types */
4740 if (i >= MAX_GOLD) i = MAX_GOLD - 1;
4742 /* Prepare a gold object */
4743 object_prep(j_ptr, OBJ_GOLD_LIST + i);
4745 /* Hack -- Base coin cost */
4746 base = k_info[OBJ_GOLD_LIST+i].cost;
4748 /* Determine how much the treasure is "worth" */
4749 j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
4757 * Places a treasure (Gold or Gems) at given location
4759 * The location must be a legal, clean, floor grid.
4761 void place_gold(int y, int x)
4771 /* Paranoia -- check bounds */
4772 if (!in_bounds(y, x)) return;
4774 /* Require clean floor space */
4775 if (!cave_clean_bold(y, x)) return;
4778 /* Get local object */
4781 /* Wipe the object */
4784 /* Make some gold */
4785 if (!make_gold(q_ptr)) return;
4788 /* Make an object */
4796 /* Acquire object */
4797 o_ptr = &o_list[o_idx];
4799 /* Copy the object */
4800 object_copy(o_ptr, q_ptr);
4807 c_ptr = &cave[y][x];
4810 o_ptr->next_o_idx = c_ptr->o_idx;
4812 /* Place the object */
4813 c_ptr->o_idx = o_idx;
4825 * Let an object fall to the ground at or near a location.
4827 * The initial location is assumed to be "in_bounds()".
4829 * This function takes a parameter "chance". This is the percentage
4830 * chance that the item will "disappear" instead of drop. If the object
4831 * has been thrown, then this is the chance of disappearance on contact.
4833 * Hack -- this function uses "chance" to determine if it should produce
4834 * some form of "description" of the drop event (under the player).
4836 * We check several locations to see if we can find a location at which
4837 * the object can combine, stack, or be placed. Artifacts will try very
4838 * hard to be placed, including "teleporting" to a useful grid if needed.
4840 s16b drop_near(object_type *j_ptr, int chance, int y, int x)
4851 s16b this_o_idx, next_o_idx = 0;
4855 char o_name[MAX_NLEN];
4860 bool plural = FALSE;
4863 /* Extract plural */
4864 if (j_ptr->number != 1) plural = TRUE;
4866 /* Describe object */
4867 object_desc(o_name, j_ptr, FALSE, 0);
4870 /* Handle normal "breakage" */
4871 if (!(j_ptr->art_name || artifact_p(j_ptr)) && (randint0(100) < chance))
4875 msg_format("%s¤Ï¾Ã¤¨¤¿¡£", o_name);
4877 msg_format("The %s disappear%s.",
4878 o_name, (plural ? "" : "s"));
4884 if (p_ptr->wizard) msg_print("(ÇË»)");
4886 if (p_ptr->wizard) msg_print("(breakage)");
4905 /* Scan local grids */
4906 for (dy = -3; dy <= 3; dy++)
4908 /* Scan local grids */
4909 for (dx = -3; dx <= 3; dx++)
4913 /* Calculate actual distance */
4914 d = (dy * dy) + (dx * dx);
4916 /* Ignore distant grids */
4917 if (d > 10) continue;
4923 /* Skip illegal grids */
4924 if (!in_bounds(ty, tx)) continue;
4926 /* Require line of sight */
4927 if (!los(y, x, ty, tx)) continue;
4930 c_ptr = &cave[ty][tx];
4932 /* Require floor space */
4933 if ((c_ptr->feat != FEAT_FLOOR) &&
4934 (c_ptr->feat != FEAT_SHAL_WATER) &&
4935 (c_ptr->feat != FEAT_GRASS) &&
4936 (c_ptr->feat != FEAT_DIRT) &&
4937 (c_ptr->feat != FEAT_FLOWER) &&
4938 (c_ptr->feat != FEAT_DEEP_GRASS) &&
4939 (c_ptr->feat != FEAT_SHAL_LAVA) &&
4940 (c_ptr->feat != FEAT_TREES)) continue;
4941 if (c_ptr->info & (CAVE_OBJECT)) continue;
4946 /* Scan objects in that grid */
4947 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4951 /* Acquire object */
4952 o_ptr = &o_list[this_o_idx];
4954 /* Acquire next object */
4955 next_o_idx = o_ptr->next_o_idx;
4957 /* Check for possible combination */
4958 if (object_similar(o_ptr, j_ptr)) comb = TRUE;
4964 /* Add new object */
4968 if (k > 99) continue;
4970 /* Calculate score */
4971 s = 1000 - (d + k * 5);
4973 /* Skip bad values */
4974 if (s < bs) continue;
4976 /* New best value */
4979 /* Apply the randomizer to equivalent values */
4980 if ((++bn >= 2) && !one_in_(bn)) continue;
4995 /* Handle lack of space */
4996 if (!flag && !(artifact_p(j_ptr) || j_ptr->art_name))
5000 msg_format("%s¤Ï¾Ã¤¨¤¿¡£", o_name);
5002 msg_format("The %s disappear%s.",
5003 o_name, (plural ? "" : "s"));
5009 if (p_ptr->wizard) msg_print("(¾²¥¹¥Ú¡¼¥¹¤¬¤Ê¤¤)");
5011 if (p_ptr->wizard) msg_print("(no floor space)");
5021 for (i = 0; !flag; i++)
5026 ty = rand_spread(by, 1);
5027 tx = rand_spread(bx, 1);
5030 /* Random locations */
5033 ty = randint0(cur_hgt);
5034 tx = randint0(cur_wid);
5038 c_ptr = &cave[ty][tx];
5040 /* Require floor space (or shallow terrain) -KMW- */
5041 if ((c_ptr->feat != FEAT_FLOOR) &&
5042 (c_ptr->feat != FEAT_SHAL_WATER) &&
5043 (c_ptr->feat != FEAT_GRASS) &&
5044 (c_ptr->feat != FEAT_DIRT) &&
5045 (c_ptr->feat != FEAT_SHAL_LAVA)) continue;
5047 /* Bounce to that location */
5051 /* Require floor space */
5052 if (!cave_clean_bold(by, bx)) continue;
5060 c_ptr = &cave[by][bx];
5062 /* Scan objects in that grid for combination */
5063 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
5067 /* Acquire object */
5068 o_ptr = &o_list[this_o_idx];
5070 /* Acquire next object */
5071 next_o_idx = o_ptr->next_o_idx;
5073 /* Check for combination */
5074 if (object_similar(o_ptr, j_ptr))
5076 /* Combine the items */
5077 object_absorb(o_ptr, j_ptr);
5087 /* Get new object */
5088 if (!done) o_idx = o_pop();
5091 if (!done && !o_idx)
5095 msg_format("%s¤Ï¾Ã¤¨¤¿¡£", o_name);
5097 msg_format("The %s disappear%s.",
5098 o_name, (plural ? "" : "s"));
5104 if (p_ptr->wizard) msg_print("(¥¢¥¤¥Æ¥à¤¬Â¿²á¤®¤ë)");
5106 if (p_ptr->wizard) msg_print("(too many objects)");
5110 /* Hack -- Preserve artifacts */
5113 a_info[j_ptr->name1].cur_num = 0;
5123 /* Structure copy */
5124 object_copy(&o_list[o_idx], j_ptr);
5126 /* Access new object */
5127 j_ptr = &o_list[o_idx];
5134 j_ptr->held_m_idx = 0;
5137 j_ptr->next_o_idx = c_ptr->o_idx;
5139 /* Place the object */
5140 c_ptr->o_idx = o_idx;
5155 /* Mega-Hack -- no message if "dropped" by player */
5156 /* Message when an object falls under the player */
5157 if (chance && (by == py) && (bx == px))
5160 msg_print("²¿¤«¤¬Â²¼¤Ëž¤¬¤Ã¤Æ¤¤¿¡£");
5162 msg_print("You feel something roll beneath your feet.");
5175 * Scatter some "great" objects near the player
5177 void acquirement(int y1, int x1, int num, bool great, bool known)
5180 object_type object_type_body;
5185 /* Get local object */
5186 i_ptr = &object_type_body;
5188 /* Wipe the object */
5191 /* Make a good (or great) object (if possible) */
5192 if (!make_object(i_ptr, TRUE, great)) continue;
5196 object_aware(i_ptr);
5197 object_known(i_ptr);
5200 /* Drop the object */
5201 (void)drop_near(i_ptr, -1, y1, x1);
5206 #define MAX_TRAPS 18
5208 static int trap_num[MAX_TRAPS] =
5212 FEAT_TRAP_SPIKED_PIT,
5213 FEAT_TRAP_POISON_PIT,
5234 * XXX XXX XXX This routine should be redone to reflect trap "level".
5235 * That is, it does not make sense to have spiked pits at 50 feet.
5236 * Actually, it is not this routine, but the "trap instantiation"
5237 * code, which should also check for "trap doors" on quest levels.
5239 byte choose_random_trap(void)
5246 /* Hack -- pick a trap */
5247 feat = trap_num[randint0(MAX_TRAPS)];
5249 /* Accept non-trapdoors */
5250 if (feat != FEAT_TRAP_TRAPDOOR) break;
5252 /* Hack -- no trap doors on special levels */
5253 if (p_ptr->inside_arena || quest_number(dun_level)) continue;
5255 /* Hack -- no trap doors on the deepest level */
5256 if (dun_level >= d_info[dungeon_type].maxdepth) continue;
5265 * Disclose an invisible trap
5267 void disclose_grid(int y, int x)
5269 cave_type *c_ptr = &cave[y][x];
5272 if (!c_ptr->mimic) return;
5274 /* No longer hidden */
5286 * Places a random trap at the given location.
5288 * The location must be a legal, naked, floor grid.
5290 * Note that all traps start out as "invisible" and "untyped", and then
5291 * when they are "discovered" (by detecting them or setting them off),
5292 * the trap is "instantiated" as a visible, "typed", trap.
5294 void place_trap(int y, int x)
5296 cave_type *c_ptr = &cave[y][x];
5298 /* Paranoia -- verify location */
5299 if (!in_bounds(y, x)) return;
5301 /* Require empty, clean, floor grid */
5302 if (!cave_naked_bold(y, x)) return;
5304 /* Place an invisible trap */
5305 c_ptr->mimic = c_ptr->feat;
5306 c_ptr->feat = choose_random_trap();
5311 * Describe the charges on an item in the inventory.
5313 void inven_item_charges(int item)
5315 object_type *o_ptr = &inventory[item];
5317 /* Require staff/wand */
5318 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5320 /* Require known item */
5321 if (!object_known_p(o_ptr)) return;
5324 if (o_ptr->pval <= 0)
5326 msg_print("¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£");
5330 msg_format("¤¢¤È %d ²óʬ¤ÎËâÎϤ¬»Ä¤Ã¤Æ¤¤¤ë¡£", o_ptr->pval);
5333 /* Multiple charges */
5334 if (o_ptr->pval != 1)
5336 /* Print a message */
5337 msg_format("You have %d charges remaining.", o_ptr->pval);
5343 /* Print a message */
5344 msg_format("You have %d charge remaining.", o_ptr->pval);
5352 * Describe an item in the inventory.
5354 void inven_item_describe(int item)
5356 object_type *o_ptr = &inventory[item];
5357 char o_name[MAX_NLEN];
5359 /* Get a description */
5360 object_desc(o_name, o_ptr, TRUE, 3);
5362 /* Print a message */
5364 /* "no more" ¤Î¾ì¹ç¤Ï¤³¤Á¤é¤Çɽ¼¨¤¹¤ë */
5365 if (o_ptr->number <= 0)
5367 /*FIRST*//*¤³¤³¤Ï¤â¤¦Ä̤é¤Ê¤¤¤«¤â */
5368 msg_format("¤â¤¦%s¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£", o_name);
5372 /* ¥¢¥¤¥Æ¥à̾¤ò±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½Âбþ */
5373 msg_format("¤Þ¤À %s¤ò»ý¤Ã¤Æ¤¤¤ë¡£", o_name);
5376 msg_format("You have %s.", o_name);
5383 * Increase the "number" of an item in the inventory
5385 void inven_item_increase(int item, int num)
5387 object_type *o_ptr = &inventory[item];
5390 num += o_ptr->number;
5393 if (num > 255) num = 255;
5394 else if (num < 0) num = 0;
5397 num -= o_ptr->number;
5399 /* Change the number and weight */
5402 /* Add the number */
5403 o_ptr->number += num;
5405 /* Add the weight */
5406 p_ptr->total_weight += (num * o_ptr->weight);
5408 /* Recalculate bonuses */
5409 p_ptr->update |= (PU_BONUS);
5411 /* Recalculate mana XXX */
5412 p_ptr->update |= (PU_MANA);
5414 /* Combine the pack */
5415 p_ptr->notice |= (PN_COMBINE);
5418 p_ptr->window |= (PW_INVEN | PW_EQUIP);
5424 * Erase an inventory slot if it has no more items
5426 void inven_item_optimize(int item)
5428 object_type *o_ptr = &inventory[item];
5430 /* Only optimize real items */
5431 if (!o_ptr->k_idx) return;
5433 /* Only optimize empty items */
5434 if (o_ptr->number) return;
5436 /* The item is in the pack */
5437 if (item < INVEN_RARM)
5444 /* Slide everything down */
5445 for (i = item; i < INVEN_PACK; i++)
5447 /* Structure copy */
5448 inventory[i] = inventory[i+1];
5451 /* Erase the "final" slot */
5452 object_wipe(&inventory[i]);
5455 p_ptr->window |= (PW_INVEN);
5458 /* The item is being wielded */
5464 /* Erase the empty slot */
5465 object_wipe(&inventory[item]);
5467 /* Recalculate bonuses */
5468 p_ptr->update |= (PU_BONUS);
5470 /* Recalculate torch */
5471 p_ptr->update |= (PU_TORCH);
5473 /* Recalculate mana XXX */
5474 p_ptr->update |= (PU_MANA);
5477 p_ptr->window |= (PW_EQUIP);
5481 p_ptr->window |= (PW_SPELL);
5486 * Describe the charges on an item on the floor.
5488 void floor_item_charges(int item)
5490 object_type *o_ptr = &o_list[item];
5492 /* Require staff/wand */
5493 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5495 /* Require known item */
5496 if (!object_known_p(o_ptr)) return;
5499 if (o_ptr->pval <= 0)
5501 msg_print("¤³¤Î¾²¾å¤Î¥¢¥¤¥Æ¥à¤Ï¡¢¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£");
5505 msg_format("¤³¤Î¾²¾å¤Î¥¢¥¤¥Æ¥à¤Ï¡¢¤¢¤È %d ²óʬ¤ÎËâÎϤ¬»Ä¤Ã¤Æ¤¤¤ë¡£", o_ptr->pval);
5508 /* Multiple charges */
5509 if (o_ptr->pval != 1)
5511 /* Print a message */
5512 msg_format("There are %d charges remaining.", o_ptr->pval);
5518 /* Print a message */
5519 msg_format("There is %d charge remaining.", o_ptr->pval);
5527 * Describe an item in the inventory.
5529 void floor_item_describe(int item)
5531 object_type *o_ptr = &o_list[item];
5532 char o_name[MAX_NLEN];
5534 /* Get a description */
5535 object_desc(o_name, o_ptr, TRUE, 3);
5537 /* Print a message */
5539 /* "no more" ¤Î¾ì¹ç¤Ï¤³¤Á¤é¤Çɽ¼¨¤òʬ¤±¤ë */
5540 if (o_ptr->number <= 0)
5542 msg_format("¾²¾å¤Ë¤Ï¡¢¤â¤¦%s¤Ï¤Ê¤¤¡£", o_name);
5546 msg_format("¾²¾å¤Ë¤Ï¡¢¤Þ¤À %s¤¬¤¢¤ë¡£", o_name);
5549 msg_format("You see %s.", o_name);
5556 * Increase the "number" of an item on the floor
5558 void floor_item_increase(int item, int num)
5560 object_type *o_ptr = &o_list[item];
5563 num += o_ptr->number;
5566 if (num > 255) num = 255;
5567 else if (num < 0) num = 0;
5570 num -= o_ptr->number;
5572 /* Change the number */
5573 o_ptr->number += num;
5578 * Optimize an item on the floor (destroy "empty" items)
5580 void floor_item_optimize(int item)
5582 object_type *o_ptr = &o_list[item];
5584 /* Paranoia -- be sure it exists */
5585 if (!o_ptr->k_idx) return;
5587 /* Only optimize empty items */
5588 if (o_ptr->number) return;
5590 /* Delete the object */
5591 delete_object_idx(item);
5596 * Check if we have space for an item in the pack without overflow
5598 bool inven_carry_okay(object_type *o_ptr)
5603 if (inven_cnt < INVEN_PACK) return (TRUE);
5606 for (j = 0; j < INVEN_PACK; j++)
5608 object_type *j_ptr = &inventory[j];
5610 /* Skip non-objects */
5611 if (!j_ptr->k_idx) continue;
5613 /* Check if the two items can be combined */
5614 if (object_similar(j_ptr, o_ptr)) return (TRUE);
5623 * Add an item to the players inventory, and return the slot used.
5625 * If the new item can combine with an existing item in the inventory,
5626 * it will do so, using "object_similar()" and "object_absorb()", else,
5627 * the item will be placed into the "proper" location in the inventory.
5629 * This function can be used to "over-fill" the player's pack, but only
5630 * once, and such an action must trigger the "overflow" code immediately.
5631 * Note that when the pack is being "over-filled", the new item must be
5632 * placed into the "overflow" slot, and the "overflow" must take place
5633 * before the pack is reordered, but (optionally) after the pack is
5634 * combined. This may be tricky. See "dungeon.c" for info.
5636 * Note that this code must remove any location/stack information
5637 * from the object once it is placed into the inventory.
5639 s16b inven_carry(object_type *o_ptr)
5647 /* Check for combining */
5648 for (j = 0; j < INVEN_PACK; j++)
5650 j_ptr = &inventory[j];
5652 /* Skip non-objects */
5653 if (!j_ptr->k_idx) continue;
5655 /* Hack -- track last item */
5658 /* Check if the two items can be combined */
5659 if (object_similar(j_ptr, o_ptr))
5661 /* Combine the items */
5662 object_absorb(j_ptr, o_ptr);
5664 /* Increase the weight */
5665 p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
5667 /* Recalculate bonuses */
5668 p_ptr->update |= (PU_BONUS);
5671 p_ptr->window |= (PW_INVEN);
5680 if (inven_cnt > INVEN_PACK) return (-1);
5682 /* Find an empty slot */
5683 for (j = 0; j <= INVEN_PACK; j++)
5685 j_ptr = &inventory[j];
5687 /* Use it if found */
5688 if (!j_ptr->k_idx) break;
5695 /* Reorder the pack */
5698 s32b o_value, j_value;
5700 /* Get the "value" of the item */
5701 o_value = object_value(o_ptr);
5703 /* Scan every occupied slot */
5704 for (j = 0; j < INVEN_PACK; j++)
5706 j_ptr = &inventory[j];
5708 /* Use empty slots */
5709 if (!j_ptr->k_idx) break;
5711 /* Hack -- readable books always come first */
5712 if ((o_ptr->tval == REALM1_BOOK) &&
5713 (j_ptr->tval != REALM1_BOOK)) break;
5714 if ((j_ptr->tval == REALM1_BOOK) &&
5715 (o_ptr->tval != REALM1_BOOK)) continue;
5717 if ((o_ptr->tval == REALM2_BOOK) &&
5718 (j_ptr->tval != REALM2_BOOK)) break;
5719 if ((j_ptr->tval == REALM2_BOOK) &&
5720 (o_ptr->tval != REALM2_BOOK)) continue;
5722 /* Objects sort by decreasing type */
5723 if (o_ptr->tval > j_ptr->tval) break;
5724 if (o_ptr->tval < j_ptr->tval) continue;
5726 /* Non-aware (flavored) items always come last */
5727 if (!object_aware_p(o_ptr)) continue;
5728 if (!object_aware_p(j_ptr)) break;
5730 /* Objects sort by increasing sval */
5731 if (o_ptr->sval < j_ptr->sval) break;
5732 if (o_ptr->sval > j_ptr->sval) continue;
5734 /* Unidentified objects always come last */
5735 if (!object_known_p(o_ptr)) continue;
5736 if (!object_known_p(j_ptr)) break;
5738 /* Hack: otherwise identical rods sort by
5739 increasing recharge time --dsb */
5740 if (o_ptr->tval == TV_ROD)
5742 if (o_ptr->pval < j_ptr->pval) break;
5743 if (o_ptr->pval > j_ptr->pval) continue;
5746 /* Determine the "value" of the pack item */
5747 j_value = object_value(j_ptr);
5749 /* Objects sort by decreasing value */
5750 if (o_value > j_value) break;
5751 if (o_value < j_value) continue;
5758 for (k = n; k >= i; k--)
5760 /* Hack -- Slide the item */
5761 object_copy(&inventory[k+1], &inventory[k]);
5764 /* Wipe the empty slot */
5765 object_wipe(&inventory[i]);
5770 object_copy(&inventory[i], o_ptr);
5772 /* Access new object */
5773 j_ptr = &inventory[i];
5776 j_ptr->next_o_idx = 0;
5778 /* Forget monster */
5779 j_ptr->held_m_idx = 0;
5781 /* Forget location */
5782 j_ptr->iy = j_ptr->ix = 0;
5784 /* No longer marked */
5787 /* Increase the weight */
5788 p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
5790 /* Count the items */
5793 /* Recalculate bonuses */
5794 p_ptr->update |= (PU_BONUS);
5796 /* Combine and Reorder pack */
5797 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
5800 p_ptr->window |= (PW_INVEN);
5802 /* Return the slot */
5808 * Take off (some of) a non-cursed equipment item
5810 * Note that only one item at a time can be wielded per slot.
5812 * Note that taking off an item when "full" may cause that item
5813 * to fall to the ground.
5815 * Return the inventory slot into which the item is placed.
5817 s16b inven_takeoff(int item, int amt)
5828 char o_name[MAX_NLEN];
5831 /* Get the item to take off */
5832 o_ptr = &inventory[item];
5835 if (amt <= 0) return (-1);
5838 if (amt > o_ptr->number) amt = o_ptr->number;
5840 /* Get local object */
5843 /* Obtain a local object */
5844 object_copy(q_ptr, o_ptr);
5846 /* Modify quantity */
5847 q_ptr->number = amt;
5849 /* Describe the object */
5850 object_desc(o_name, q_ptr, TRUE, 3);
5852 /* Took off weapon */
5853 if (item == INVEN_RARM)
5856 act = "¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤¿";
5858 act = "You were wielding";
5864 else if (item == INVEN_BOW)
5867 act = "¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤¿";
5869 act = "You were holding";
5874 /* Took off light */
5875 else if (item == INVEN_LITE)
5878 act = "¤ò¸÷¸»¤«¤é¤Ï¤º¤·¤¿";
5880 act = "You were holding";
5885 /* Took off something */
5889 act = "¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤¿";
5891 act = "You were wearing";
5896 /* Modify, Optimize */
5897 inven_item_increase(item, -amt);
5898 inven_item_optimize(item);
5900 /* Carry the object */
5901 slot = inven_carry(q_ptr);
5905 msg_format("%s(%c)%s¡£", o_name, index_to_label(slot), act);
5907 msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
5917 * Drop (some of) a non-cursed inventory/equipment item
5919 * The object will be dropped "near" the current location
5921 void inven_drop(int item, int amt)
5928 char o_name[MAX_NLEN];
5931 /* Access original object */
5932 o_ptr = &inventory[item];
5935 if (amt <= 0) return;
5938 if (amt > o_ptr->number) amt = o_ptr->number;
5941 /* Take off equipment */
5942 if (item >= INVEN_RARM)
5944 /* Take off first */
5945 item = inven_takeoff(item, amt);
5947 /* Access original object */
5948 o_ptr = &inventory[item];
5952 /* Get local object */
5955 /* Obtain local object */
5956 object_copy(q_ptr, o_ptr);
5958 /* Distribute charges of wands or rods */
5959 distribute_charges(o_ptr, q_ptr, amt);
5961 /* Modify quantity */
5962 q_ptr->number = amt;
5964 /* Describe local object */
5965 object_desc(o_name, q_ptr, TRUE, 3);
5969 msg_format("%s(%c)¤òÍî¤È¤·¤¿¡£", o_name, index_to_label(item));
5971 msg_format("You drop %s (%c).", o_name, index_to_label(item));
5975 /* Drop it near the player */
5976 (void)drop_near(q_ptr, 0, py, px);
5978 /* Modify, Describe, Optimize */
5979 inven_item_increase(item, -amt);
5980 inven_item_describe(item);
5981 inven_item_optimize(item);
5986 * Combine items in the pack
5988 * Note special handling of the "overflow" slot
5990 void combine_pack(void)
5998 /* Combine the pack (backwards) */
5999 for (i = INVEN_PACK; i > 0; i--)
6002 o_ptr = &inventory[i];
6004 /* Skip empty items */
6005 if (!o_ptr->k_idx) continue;
6007 /* Scan the items above that item */
6008 for (j = 0; j < i; j++)
6011 j_ptr = &inventory[j];
6013 /* Skip empty items */
6014 if (!j_ptr->k_idx) continue;
6016 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
6017 if (object_similar_part(j_ptr, o_ptr)
6018 && j_ptr->number < MAX_STACK_SIZE-1)
6020 if (o_ptr->number + j_ptr->number < MAX_STACK_SIZE)
6025 /* Add together the item counts */
6026 object_absorb(j_ptr, o_ptr);
6028 /* One object is gone */
6031 /* Slide everything down */
6032 for (k = i; k < INVEN_PACK; k++)
6034 /* Structure copy */
6035 inventory[k] = inventory[k+1];
6038 /* Erase the "final" slot */
6039 object_wipe(&inventory[k]);
6043 int remain = j_ptr->number + o_ptr->number - 99;
6045 o_ptr->number -= remain;
6047 /* Add together the item counts */
6048 object_absorb(j_ptr, o_ptr);
6050 o_ptr->number = remain;
6054 p_ptr->window |= (PW_INVEN);
6064 if (flag) msg_print("¥¶¥Ã¥¯¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤ò¤Þ¤È¤áľ¤·¤¿¡£");
6066 if (flag) msg_print("You combine some items in your pack.");
6073 * Reorder items in the pack
6075 * Note special handling of the "overflow" slot
6077 void reorder_pack(void)
6089 /* Re-order the pack (forwards) */
6090 for (i = 0; i < INVEN_PACK; i++)
6092 /* Mega-Hack -- allow "proper" over-flow */
6093 if ((i == INVEN_PACK) && (inven_cnt == INVEN_PACK)) break;
6096 o_ptr = &inventory[i];
6098 /* Skip empty slots */
6099 if (!o_ptr->k_idx) continue;
6101 /* Get the "value" of the item */
6102 o_value = object_value(o_ptr);
6104 /* Scan every occupied slot */
6105 for (j = 0; j < INVEN_PACK; j++)
6107 /* Get the item already there */
6108 j_ptr = &inventory[j];
6110 /* Use empty slots */
6111 if (!j_ptr->k_idx) break;
6113 /* Hack -- readable books always come first */
6114 if ((o_ptr->tval == REALM1_BOOK) &&
6115 (j_ptr->tval != REALM1_BOOK)) break;
6116 if ((j_ptr->tval == REALM1_BOOK) &&
6117 (o_ptr->tval != REALM1_BOOK)) continue;
6119 if ((o_ptr->tval == REALM2_BOOK) &&
6120 (j_ptr->tval != REALM2_BOOK)) break;
6121 if ((j_ptr->tval == REALM2_BOOK) &&
6122 (o_ptr->tval != REALM2_BOOK)) continue;
6124 /* Objects sort by decreasing type */
6125 if (o_ptr->tval > j_ptr->tval) break;
6126 if (o_ptr->tval < j_ptr->tval) continue;
6128 /* Non-aware (flavored) items always come last */
6129 if (!object_aware_p(o_ptr)) continue;
6130 if (!object_aware_p(j_ptr)) break;
6132 /* Objects sort by increasing sval */
6133 if (o_ptr->sval < j_ptr->sval) break;
6134 if (o_ptr->sval > j_ptr->sval) continue;
6136 /* Unidentified objects always come last */
6137 if (!object_known_p(o_ptr)) continue;
6138 if (!object_known_p(j_ptr)) break;
6140 /* Hack: otherwise identical rods sort by
6141 increasing recharge time --dsb */
6142 if (o_ptr->tval == TV_ROD)
6144 if (o_ptr->pval < j_ptr->pval) break;
6145 if (o_ptr->pval > j_ptr->pval) continue;
6148 /* Determine the "value" of the pack item */
6149 j_value = object_value(j_ptr);
6153 /* Objects sort by decreasing value */
6154 if (o_value > j_value) break;
6155 if (o_value < j_value) continue;
6158 /* Never move down */
6159 if (j >= i) continue;
6164 /* Get local object */
6167 /* Save a copy of the moving item */
6168 object_copy(q_ptr, &inventory[i]);
6170 /* Slide the objects */
6171 for (k = i; k > j; k--)
6173 /* Slide the item */
6174 object_copy(&inventory[k], &inventory[k-1]);
6177 /* Insert the moving item */
6178 object_copy(&inventory[j], q_ptr);
6181 p_ptr->window |= (PW_INVEN);
6186 if (flag) msg_print("¥¶¥Ã¥¯¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤òÊ¤Ùľ¤·¤¿¡£");
6188 if (flag) msg_print("You reorder some items in your pack.");
6195 * Hack -- display an object kind in the current window
6197 * Include list of usable spells for readible books
6199 void display_koff(int k_idx)
6206 char o_name[MAX_NLEN];
6209 /* Erase the window */
6210 for (y = 0; y < Term->hgt; y++)
6212 /* Erase the line */
6213 Term_erase(0, y, 255);
6219 /* Get local object */
6222 /* Prepare the object */
6223 object_prep(q_ptr, k_idx);
6226 object_desc_store(o_name, q_ptr, FALSE, 0);
6228 /* Mention the object name */
6229 Term_putstr(0, 0, -1, TERM_WHITE, o_name);
6231 /* Warriors are illiterate */
6232 if (!(p_ptr->realm1 || p_ptr->realm2)) return;
6234 /* Display spells in readible books */
6235 if ((q_ptr->tval == REALM1_BOOK) ||
6236 (q_ptr->tval == REALM2_BOOK))
6244 /* Access the item's sval */
6247 /* Extract spells */
6248 for (spell = 0; spell < 32; spell++)
6250 /* Check for this spell */
6251 if (fake_spell_flags[sval] & (1L << spell))
6253 /* Collect this spell */
6254 spells[num++] = spell;
6259 print_spells(0, spells, num, 2, 0,
6260 (q_ptr->tval == REALM1_BOOK ? p_ptr->realm1 : p_ptr->realm2));
6264 /* Choose one of items that have warning flag */
6265 object_type *choose_warning_item(void)
6268 int choices[INVEN_TOTAL-INVEN_RARM];
6271 /* Paranoia -- Player has no warning-item */
6272 if (!p_ptr->warning) return (NULL);
6274 /* Search Inventry */
6275 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
6277 u32b flgs[TR_FLAG_SIZE];
6278 object_type *o_ptr = &inventory[i];
6280 object_flags(o_ptr, flgs);
6281 if (have_flag(flgs, TR_WARNING))
6283 choices[number] = i;
6288 /* Choice one of them */
6289 return (&inventory[choices[randint0(number)]]);
6292 /* Examine the grid (xx,yy) and warn the player if there are any danger */
6293 bool process_frakir(int xx, int yy)
6297 char o_name[MAX_NLEN];
6299 #define FRAKIR_AWARE_RANGE 12
6301 static int old_damage = 0;
6303 for (mx = xx-FRAKIR_AWARE_RANGE; mx < xx+FRAKIR_AWARE_RANGE+1; mx++)
6305 for (my = yy-FRAKIR_AWARE_RANGE; my < yy+FRAKIR_AWARE_RANGE+1; my++)
6308 monster_type *m_ptr;
6309 monster_race *r_ptr;
6313 if (!in_bounds(my,mx) || (distance(my,mx,yy,xx)>FRAKIR_AWARE_RANGE)) continue;
6315 c_ptr = &cave[my][mx];
6317 if (!c_ptr->m_idx) continue;
6319 m_ptr = &m_list[c_ptr->m_idx];
6320 r_ptr = &r_info[m_ptr->r_idx];
6326 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
6328 if (m_ptr->csleep) continue;
6329 if (is_pet(m_ptr)) continue;
6331 /* Monster spells (only powerful ones)*/
6332 if(projectable(my,mx,yy,xx))
6335 #define DAMCALC(f,val,max,im,vln,res,resx,resy,op,opx,opy,dmax) \
6336 if (f){ int dam = (val)>(max)? (max):(val); \
6338 if (vln) dam *= 2; \
6339 if (res) {dam = (dam * resx) / resy;} \
6340 if (op) {dam = (dam * opx) / opy;} \
6341 if (dam>dmax) dmax = dam; \
6344 DAMCALC(f4 & (RF4_BR_FIRE), m_ptr->hp / 3, 1600,
6345 p_ptr->immune_fire, p_ptr->muta3 & MUT3_VULN_ELEM,
6346 p_ptr->resist_fire, 1, 3,
6347 p_ptr->oppose_fire, 1, 3, dam_max0);
6349 DAMCALC(f4 & (RF4_BR_COLD), m_ptr->hp / 3, 1600,
6350 p_ptr->immune_cold, p_ptr->muta3 & MUT3_VULN_ELEM,
6351 p_ptr->resist_cold, 1, 3,
6352 p_ptr->oppose_cold, 1, 3, dam_max0);
6354 DAMCALC(f4 & (RF4_BR_ELEC), m_ptr->hp / 3, 1600,
6355 p_ptr->immune_elec, p_ptr->muta3 & MUT3_VULN_ELEM,
6356 p_ptr->resist_elec, 1, 3,
6357 p_ptr->oppose_elec, 1, 3, dam_max0);
6359 DAMCALC(f4 & (RF4_BR_ACID), m_ptr->hp / 3, 1600,
6360 p_ptr->immune_acid, p_ptr->muta3 & MUT3_VULN_ELEM,
6361 p_ptr->resist_acid, 1, 3,
6362 p_ptr->oppose_acid, 1, 3, dam_max0);
6364 DAMCALC(f4 & (RF4_BR_POIS), m_ptr->hp / 3, 800,
6366 p_ptr->resist_pois, 1, 3,
6367 p_ptr->oppose_pois, 1, 3, dam_max0);
6370 DAMCALC(f4 & (RF4_BR_NETH), m_ptr->hp / 6, 550, FALSE , FALSE,
6371 p_ptr->resist_neth, 6, 9, FALSE, 1, 1, dam_max0);
6373 DAMCALC(f4 & (RF4_BR_LITE), m_ptr->hp / 6, 400, FALSE , FALSE,
6374 p_ptr->resist_lite, 4, 9, FALSE, 1, 1, dam_max0);
6376 DAMCALC(f4 & (RF4_BR_DARK), m_ptr->hp / 6, 400, FALSE , FALSE,
6377 p_ptr->resist_dark, 4, 9, FALSE, 1, 1, dam_max0);
6379 DAMCALC(f4 & (RF4_BR_CONF), m_ptr->hp / 6, 450, FALSE , FALSE,
6380 p_ptr->resist_conf, 5, 9, FALSE, 1, 1, dam_max0);
6382 DAMCALC(f4 & (RF4_BR_SOUN), m_ptr->hp / 6, 450, FALSE , FALSE,
6383 p_ptr->resist_sound, 5, 9, FALSE, 1, 1, dam_max0);
6385 DAMCALC(f4 & (RF4_BR_CHAO), m_ptr->hp / 6, 600, FALSE , FALSE,
6386 p_ptr->resist_chaos, 6, 9, FALSE, 1, 1, dam_max0);
6388 DAMCALC(f4 & (RF4_BR_DISE), m_ptr->hp / 6, 500, FALSE , FALSE,
6389 p_ptr->resist_disen, 6, 9, FALSE, 1, 1, dam_max0);
6391 DAMCALC(f4 & (RF4_BR_NEXU), m_ptr->hp / 3, 250, FALSE , FALSE,
6392 p_ptr->resist_nexus, 6, 9, FALSE, 1, 1, dam_max0);
6394 DAMCALC(f4 & (RF4_BR_TIME), m_ptr->hp / 3, 150, FALSE , FALSE,
6395 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6397 DAMCALC(f4 & (RF4_BR_INER), m_ptr->hp / 6, 200, FALSE , FALSE,
6398 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6400 DAMCALC(f4 & (RF4_BR_GRAV), m_ptr->hp / 3, 200, FALSE , FALSE,
6401 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6403 DAMCALC(f4 & (RF4_BR_SHAR), m_ptr->hp / 6, 500, FALSE , FALSE,
6404 p_ptr->resist_shard, 6, 9, FALSE, 1, 1, dam_max0);
6406 DAMCALC(f4 & (RF4_BR_PLAS), m_ptr->hp / 6, 150, FALSE , FALSE,
6407 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6409 DAMCALC(f4 & (RF4_BR_WALL), m_ptr->hp / 6, 200, FALSE , FALSE,
6410 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6412 DAMCALC(f4 & (RF4_BR_MANA), m_ptr->hp / 3, 250, FALSE , FALSE,
6413 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6415 DAMCALC(f4 & (RF4_BR_NUKE), m_ptr->hp / 3, 800, FALSE , FALSE,
6416 p_ptr->resist_pois, 2, 5,
6417 p_ptr->oppose_pois, 2, 5, dam_max0);
6419 DAMCALC(f4 & (RF4_BR_DISI), m_ptr->hp / 3, 300, FALSE , FALSE,
6420 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6423 DAMCALC(f4 & (RF4_ROCKET), m_ptr->hp / 4, 800, FALSE , FALSE,
6424 p_ptr->resist_shard, 1, 2, FALSE, 1, 1, dam_max0);
6426 DAMCALC(f5 & (RF5_BA_MANA), rlev*4 + 150, 9999, FALSE , FALSE,
6427 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6429 DAMCALC(f5 & (RF5_BA_DARK), rlev*4 + 150, 9999, FALSE , FALSE,
6430 p_ptr->resist_dark, 4, 9, FALSE, 1, 1, dam_max0);
6432 DAMCALC(f5 & (RF5_BA_LITE), rlev*4 + 150, 9999, FALSE , FALSE,
6433 p_ptr->resist_lite, 4, 9, FALSE, 1, 1, dam_max0);
6436 DAMCALC(f6 & (RF6_HAND_DOOM), p_ptr->chp*6/10, 9999, FALSE , FALSE,
6437 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6441 /* Monster melee attacks */
6442 if(mx <= xx+1 && mx >= xx-1 && my <=yy+1 && my >= yy-1)
6446 for (m = 0; m < 4; m++)
6450 /* Skip non-attacks */
6451 if (!r_ptr->blow[m].method) continue;
6453 /* Extract the attack info */
6454 d1 = r_ptr->blow[m].d_dice;
6455 d2 = r_ptr->blow[m].d_side;
6459 if(dam_melee>dam_max0)dam_max0=dam_melee;
6462 /* Contribution from this monster */
6467 /* Prevent excessive warning */
6468 if(dam_max > old_damage)
6470 old_damage=dam_max * 3 / 2;
6472 if (dam_max>(p_ptr->chp)/2)
6474 object_type *o_ptr = choose_warning_item();
6476 object_desc(o_name, o_ptr, FALSE, 0);
6478 msg_format("%s¤¬±Ô¤¯¿Ì¤¨¤¿¡ª", o_name);
6480 msg_format("Your %s pulsates sharply!", o_name);
6484 return (get_check("ËÜÅö¤Ë¤³¤Î¤Þ¤Þ¿Ê¤à¤«¡©"));
6486 return (get_check("Realy want to go ahead? "));
6490 else old_damage = old_damage/2;
6492 c_ptr = &cave[yy][xx];
6493 if (((!easy_disarm && (is_trap(c_ptr->feat) || c_ptr->feat == FEAT_INVIS))
6494 || (c_ptr->mimic && is_trap(c_ptr->feat))) && !one_in_(13))
6496 object_type *o_ptr = choose_warning_item();
6498 object_desc(o_name, o_ptr, FALSE, 0);
6500 msg_format("%s¤¬¿Ì¤¨¤¿¡ª", o_name);
6502 msg_format("Your %s pulsates!", o_name);
6506 return (get_check("ËÜÅö¤Ë¤³¤Î¤Þ¤Þ¿Ê¤à¤«¡©"));
6508 return (get_check("Realy want to go ahead? "));
6515 static bool item_tester_hook_melee_ammo(object_type *o_ptr)
6517 switch (o_ptr->tval)
6530 if (o_ptr->sval != SV_DOKUBARI) return (TRUE);
6539 * A structure for smithing
6542 int add; /* TR flag number or special essence id */
6543 cptr add_name; /* Name of this ability */
6544 int type; /* Menu number */
6545 int essence; /* Index for carrying essences */
6546 int value; /* Needed value to add this ability */
6551 * Smithing type data for Weapon smith
6554 static essence_type essence_info[] =
6556 {TR_STR, "ÏÓÎÏ", 4, TR_STR, 20},
6557 {TR_INT, "ÃÎǽ", 4, TR_INT, 20},
6558 {TR_WIS, "¸¤µ", 4, TR_WIS, 20},
6559 {TR_DEX, "´ïÍѤµ", 4, TR_DEX, 20},
6560 {TR_CON, "Âѵ×ÎÏ", 4, TR_CON, 20},
6561 {TR_CHR, "Ì¥ÎÏ", 4, TR_CHR, 20},
6562 {TR_MAGIC_MASTERY, "ËâÎÏ»ÙÇÛ", 4, TR_MAGIC_MASTERY, 20},
6563 {TR_STEALTH, "±£Ì©", 4, TR_STEALTH, 40},
6564 {TR_SEARCH, "õº÷", 4, TR_SEARCH, 15},
6565 {TR_INFRA, "ÀÖ³°Àþ»ëÎÏ", 4, TR_INFRA, 15},
6566 {TR_TUNNEL, "ºÎ·¡", 4, TR_TUNNEL, 15},
6567 {TR_SPEED, "¥¹¥Ô¡¼¥É", 4, TR_SPEED, 12},
6568 {TR_BLOWS, "Äɲù¶·â", 1, TR_BLOWS, 20},
6569 {TR_CHAOTIC, "¥«¥ª¥¹¹¶·â", 1, TR_CHAOTIC, 15},
6570 {TR_VAMPIRIC, "µÛ·ì¹¶·â", 1, TR_VAMPIRIC, 60},
6571 {TR_IMPACT, "ÃÏ¿Ìȯư", 7, TR_IMPACT, 15},
6572 {TR_BRAND_POIS, "ÆÇ»¦", 1, TR_BRAND_POIS, 20},
6573 {TR_BRAND_ACID, "Íϲò", 1, TR_BRAND_ACID, 20},
6574 {TR_BRAND_ELEC, "ÅÅ·â", 1, TR_BRAND_ELEC, 20},
6575 {TR_BRAND_FIRE, "¾Æ´þ", 1, TR_BRAND_FIRE, 20},
6576 {TR_BRAND_COLD, "Åà·ë", 1, TR_BRAND_COLD, 20},
6577 {TR_SUST_STR, "ÏÓÎÏ°Ý»ý", 3, TR_SUST_STR, 15},
6578 {TR_SUST_INT, "ÃÎǽ°Ý»ý", 3, TR_SUST_STR, 15},
6579 {TR_SUST_WIS, "¸¤µ°Ý»ý", 3, TR_SUST_STR, 15},
6580 {TR_SUST_DEX, "´ïÍѤµ°Ý»ý", 3, TR_SUST_STR, 15},
6581 {TR_SUST_CON, "Âѵ×ÎÏ°Ý»ý", 3, TR_SUST_STR, 15},
6582 {TR_SUST_CHR, "Ì¥ÎÏ°Ý»ý", 3, TR_SUST_STR, 15},
6583 {TR_IM_ACID, "»ÀÌȱÖ", 2, TR_IM_ACID, 20},
6584 {TR_IM_ELEC, "ÅÅ·âÌȱÖ", 2, TR_IM_ACID, 20},
6585 {TR_IM_FIRE, "²Ð±êÌȱÖ", 2, TR_IM_ACID, 20},
6586 {TR_IM_COLD, "Î䵤ÌȱÖ", 2, TR_IM_ACID, 20},
6587 {TR_REFLECT, "È¿¼Í", 2, TR_REFLECT, 20},
6588 {TR_FREE_ACT, "ËãáãÃΤ餺", 3, TR_FREE_ACT, 20},
6589 {TR_HOLD_LIFE, "À¸Ì¿ÎÏ°Ý»ý", 3, TR_HOLD_LIFE, 20},
6590 {TR_RES_ACID, "ÂÑ»À", 2, TR_RES_ACID, 15},
6591 {TR_RES_ELEC, "ÂÑÅÅ·â", 2, TR_RES_ELEC, 15},
6592 {TR_RES_FIRE, "ÂѲбê", 2, TR_RES_FIRE, 15},
6593 {TR_RES_COLD, "ÂÑÎ䵤", 2, TR_RES_COLD, 15},
6594 {TR_RES_POIS, "ÂÑÆÇ", 2, TR_RES_POIS, 25},
6595 {TR_RES_FEAR, "ÂѶ²ÉÝ", 2, TR_RES_FEAR, 20},
6596 {TR_RES_LITE, "ÂÑÁ®¸÷", 2, TR_RES_LITE, 20},
6597 {TR_RES_DARK, "ÂѰŹõ", 2, TR_RES_DARK, 20},
6598 {TR_RES_BLIND, "ÂÑÌÕÌÜ", 2, TR_RES_BLIND, 20},
6599 {TR_RES_CONF, "ÂѺ®Íð", 2, TR_RES_CONF, 20},
6600 {TR_RES_SOUND, "Âѹ첻", 2, TR_RES_SOUND, 20},
6601 {TR_RES_SHARDS, "ÂÑÇËÊÒ", 2, TR_RES_SHARDS, 20},
6602 {TR_RES_NETHER, "ÂÑÃϹö", 2, TR_RES_NETHER, 20},
6603 {TR_RES_NEXUS, "ÂÑ°ø²Ìº®Íð", 2, TR_RES_NEXUS, 20},
6604 {TR_RES_CHAOS, "ÂÑ¥«¥ª¥¹", 2, TR_RES_CHAOS, 20},
6605 {TR_RES_DISEN, "ÂÑÎô²½", 2, TR_RES_DISEN, 20},
6606 {TR_SH_FIRE, "", 0, -2, 0},
6607 {TR_SH_ELEC, "", 0, -2, 0},
6608 {TR_SH_COLD, "", 0, -2, 0},
6609 {TR_NO_MAGIC, "È¿ËâË¡", 3, TR_NO_MAGIC, 15},
6610 {TR_WARNING, "·Ù¹ð", 3, TR_WARNING, 20},
6611 {TR_FEATHER, "ÉâÍ·", 3, TR_FEATHER, 20},
6612 {TR_LITE, "±Êµ×¸÷¸»", 3, TR_LITE, 15},
6613 {TR_SEE_INVIS, "²Ä»ëÆ©ÌÀ", 3, TR_SEE_INVIS, 20},
6614 {TR_TELEPATHY, "¥Æ¥ì¥Ñ¥·¡¼", 6, TR_TELEPATHY, 15},
6615 {TR_SLOW_DIGEST, "Ãپò½", 3, TR_SLOW_DIGEST, 15},
6616 {TR_REGEN, "µÞ®²óÉü", 3, TR_REGEN, 20},
6617 {TR_TELEPORT, "¥Æ¥ì¥Ý¡¼¥È", 3, TR_TELEPORT, 25},
6619 {TR_SLAY_EVIL, "¼Ù°ÇÜÂÇ", 5, TR_SLAY_EVIL, 100},
6620 {TR_KILL_EVIL, "¼Ù°ÇÜÇÜÂÇ", 0, TR_SLAY_EVIL, 60},
6621 {TR_SLAY_ANIMAL, "ưʪÇÜÂÇ", 5, TR_SLAY_ANIMAL, 20},
6622 {TR_KILL_ANIMAL, "ưʪÇÜÇÜÂÇ", 5, TR_SLAY_ANIMAL, 60},
6623 {TR_SLAY_UNDEAD, "ÉÔ»àÇÜÂÇ", 5, TR_SLAY_UNDEAD, 20},
6624 {TR_KILL_UNDEAD, "ÉÔ»àÇÜÇÜÂÇ", 5, TR_SLAY_UNDEAD, 60},
6625 {TR_SLAY_DEMON, "°ËâÇÜÂÇ", 5, TR_SLAY_DEMON, 20},
6626 {TR_KILL_DEMON, "°ËâÇÜÇÜÂÇ", 5, TR_SLAY_DEMON, 60},
6627 {TR_SLAY_ORC, "¥ª¡¼¥¯ÇÜÂÇ", 5, TR_SLAY_ORC, 15},
6628 {TR_KILL_ORC, "¥ª¡¼¥¯ÇÜÇÜÂÇ", 5, TR_SLAY_ORC, 60},
6629 {TR_SLAY_TROLL, "¥È¥í¥ëÇÜÂÇ", 5, TR_SLAY_TROLL, 15},
6630 {TR_KILL_TROLL, "¥È¥í¥ëÇÜÇÜÂÇ", 5, TR_SLAY_TROLL, 60},
6631 {TR_SLAY_GIANT, "µð¿ÍÇÜÂÇ", 5, TR_SLAY_GIANT, 20},
6632 {TR_KILL_GIANT, "µð¿ÍÇÜÇÜÂÇ", 5, TR_SLAY_GIANT, 60},
6633 {TR_SLAY_DRAGON, "εÇÜÂÇ", 5, TR_SLAY_DRAGON, 20},
6634 {TR_KILL_DRAGON, "εÇÜÇÜÂÇ", 5, TR_SLAY_DRAGON, 60},
6635 {TR_SLAY_HUMAN, "¿Í´ÖÇÜÂÇ", 5, TR_SLAY_HUMAN, 20},
6636 {TR_KILL_HUMAN, "¿Í´ÖÇÜÇÜÂÇ", 5, TR_SLAY_HUMAN, 60},
6638 {TR_ESP_ANIMAL, "ưʪESP", 6, TR_SLAY_ANIMAL, 40},
6639 {TR_ESP_UNDEAD, "ÉÔ»àESP", 6, TR_SLAY_UNDEAD, 40},
6640 {TR_ESP_DEMON, "°ËâESP", 6, TR_SLAY_DEMON, 40},
6641 {TR_ESP_ORC, "¥ª¡¼¥¯ESP", 6, TR_SLAY_ORC, 40},
6642 {TR_ESP_TROLL, "¥È¥í¥ëESP", 6, TR_SLAY_TROLL, 40},
6643 {TR_ESP_GIANT, "µð¿ÍESP", 6, TR_SLAY_GIANT, 40},
6644 {TR_ESP_DRAGON, "εESP", 6, TR_SLAY_DRAGON, 40},
6645 {TR_ESP_HUMAN, "¿Í´ÖESP", 6, TR_SLAY_HUMAN, 40},
6647 {ESSENCE_ATTACK, "¹¶·â", 10, TR_ES_ATTACK, 30},
6648 {ESSENCE_AC, "Ëɸæ", 10, TR_ES_AC, 15},
6649 {ESSENCE_TMP_RES_ACID, "»ÀÂÑÀȯư", 7, TR_RES_ACID, 50},
6650 {ESSENCE_TMP_RES_ELEC, "ÅÅ·âÂÑÀȯư", 7, TR_RES_ELEC, 50},
6651 {ESSENCE_TMP_RES_FIRE, "²Ð±êÂÑÀȯư", 7, TR_RES_FIRE, 50},
6652 {ESSENCE_TMP_RES_COLD, "Î䵤ÂÑÀȯư", 7, TR_RES_COLD, 50},
6653 {ESSENCE_SH_FIRE, "²Ð±ê¥ª¡¼¥é", 7, -1, 50},
6654 {ESSENCE_SH_ELEC, "Åŷ⥪¡¼¥é", 7, -1, 50},
6655 {ESSENCE_SH_COLD, "Î䵤¥ª¡¼¥é", 7, -1, 50},
6656 {ESSENCE_RESISTANCE, "Á´ÂÑÀ", 2, -1, 150},
6657 {ESSENCE_SUSTAIN, "ÁõÈ÷ÊÝ»ý", 10, -1, 10},
6658 {ESSENCE_SLAY_GLOVE, "»¦Ù¤¤Î¾®¼ê", 1, TR_ES_ATTACK, 200},
6660 {-1, NULL, 0, -1, 0}
6663 static essence_type essence_info[] =
6665 {TR_STR, "strength", 4, TR_STR, 20},
6666 {TR_INT, "intelligence", 4, TR_INT, 20},
6667 {TR_WIS, "wisdom", 4, TR_WIS, 20},
6668 {TR_DEX, "dexterity", 4, TR_DEX, 20},
6669 {TR_CON, "constitution", 4, TR_CON, 20},
6670 {TR_CHR, "charisma", 4, TR_CHR, 20},
6671 {TR_MAGIC_MASTERY, "magic mastery", 4, TR_MAGIC_MASTERY, 20},
6672 {TR_STEALTH, "stealth", 4, TR_STEALTH, 40},
6673 {TR_SEARCH, "serching", 4, TR_SEARCH, 15},
6674 {TR_INFRA, "inflavision", 4, TR_INFRA, 15},
6675 {TR_TUNNEL, "digging", 4, TR_TUNNEL, 15},
6676 {TR_SPEED, "speed", 4, TR_SPEED, 12},
6677 {TR_BLOWS, "extra attack", 1, TR_BLOWS, 20},
6678 {TR_CHAOTIC, "chaos brand", 1, TR_CHAOTIC, 15},
6679 {TR_VAMPIRIC, "vampiric brand", 1, TR_VAMPIRIC, 60},
6680 {TR_IMPACT, "quake activation", 7, TR_IMPACT, 15},
6681 {TR_BRAND_POIS, "poison brand", 1, TR_BRAND_POIS, 20},
6682 {TR_BRAND_ACID, "acid brand", 1, TR_BRAND_ACID, 20},
6683 {TR_BRAND_ELEC, "electric brand", 1, TR_BRAND_ELEC, 20},
6684 {TR_BRAND_FIRE, "fire brand", 1, TR_BRAND_FIRE, 20},
6685 {TR_BRAND_COLD, "cold brand", 1, TR_BRAND_COLD, 20},
6686 {TR_SUST_STR, "sustain strength", 3, TR_SUST_STR, 15},
6687 {TR_SUST_INT, "sustain intelligence", 3, TR_SUST_STR, 15},
6688 {TR_SUST_WIS, "sustain wisdom", 3, TR_SUST_STR, 15},
6689 {TR_SUST_DEX, "sustain dexterity", 3, TR_SUST_STR, 15},
6690 {TR_SUST_CON, "sustain constitution", 3, TR_SUST_STR, 15},
6691 {TR_SUST_CHR, "sustain charisma", 3, TR_SUST_STR, 15},
6692 {TR_IM_ACID, "acid immunity", 2, TR_IM_ACID, 20},
6693 {TR_IM_ELEC, "electric immunity", 2, TR_IM_ACID, 20},
6694 {TR_IM_FIRE, "fire immunity", 2, TR_IM_ACID, 20},
6695 {TR_IM_COLD, "cold immunity", 2, TR_IM_ACID, 20},
6696 {TR_REFLECT, "reflection", 2, TR_REFLECT, 20},
6697 {TR_FREE_ACT, "free action", 3, TR_FREE_ACT, 20},
6698 {TR_HOLD_LIFE, "hold life", 3, TR_HOLD_LIFE, 20},
6699 {TR_RES_ACID, "resistance to acid", 2, TR_RES_ACID, 15},
6700 {TR_RES_ELEC, "resistance to electric", 2, TR_RES_ELEC, 15},
6701 {TR_RES_FIRE, "resistance to fire", 2, TR_RES_FIRE, 15},
6702 {TR_RES_COLD, "resistance to cold", 2, TR_RES_COLD, 15},
6703 {TR_RES_POIS, "resistance to poison", 2, TR_RES_POIS, 25},
6704 {TR_RES_FEAR, "resistance to fear", 2, TR_RES_FEAR, 20},
6705 {TR_RES_LITE, "resistance to light", 2, TR_RES_LITE, 20},
6706 {TR_RES_DARK, "resistance to dark", 2, TR_RES_DARK, 20},
6707 {TR_RES_BLIND, "resistance to blind", 2, TR_RES_BLIND, 20},
6708 {TR_RES_CONF, "resistance to confusion", 2, TR_RES_CONF, 20},
6709 {TR_RES_SOUND, "resistance to sound", 2, TR_RES_SOUND, 20},
6710 {TR_RES_SHARDS, "resistance to shard", 2, TR_RES_SHARDS, 20},
6711 {TR_RES_NETHER, "resistance to nether", 2, TR_RES_NETHER, 20},
6712 {TR_RES_NEXUS, "resistance to nexus", 2, TR_RES_NEXUS, 20},
6713 {TR_RES_CHAOS, "resistance to chaos", 2, TR_RES_CHAOS, 20},
6714 {TR_RES_DISEN, "resistance to disenchantment", 2, TR_RES_DISEN, 20},
6715 {TR_SH_FIRE, "", 0, -2, 0},
6716 {TR_SH_ELEC, "", 0, -2, 0},
6717 {TR_SH_COLD, "", 0, -2, 0},
6718 {TR_NO_MAGIC, "anti magic", 3, TR_NO_MAGIC, 15},
6719 {TR_WARNING, "warning", 3, TR_WARNING, 20},
6720 {TR_FEATHER, "levitation", 3, TR_FEATHER, 20},
6721 {TR_LITE, "permanent light", 3, TR_LITE, 15},
6722 {TR_SEE_INVIS, "see invisible", 3, TR_SEE_INVIS, 20},
6723 {TR_TELEPATHY, "telepathy", 6, TR_TELEPATHY, 15},
6724 {TR_SLOW_DIGEST, "slow digestion", 3, TR_SLOW_DIGEST, 15},
6725 {TR_REGEN, "regeneration", 3, TR_REGEN, 20},
6726 {TR_TELEPORT, "teleport", 3, TR_TELEPORT, 25},
6728 {TR_SLAY_EVIL, "slay evil", 5, TR_SLAY_EVIL, 100},
6729 {TR_SLAY_ANIMAL, "slay animal", 5, TR_SLAY_ANIMAL, 20},
6730 {TR_KILL_ANIMAL, "kill animal", 5, TR_SLAY_ANIMAL, 60},
6731 {TR_KILL_EVIL, "kill evil", 0, TR_SLAY_EVIL, 60},
6732 {TR_SLAY_UNDEAD, "slay undead", 5, TR_SLAY_UNDEAD, 20},
6733 {TR_KILL_UNDEAD, "kill undead", 5, TR_SLAY_UNDEAD, 60},
6734 {TR_SLAY_DEMON, "slay demon", 5, TR_SLAY_DEMON, 20},
6735 {TR_KILL_DEMON, "kill demon", 5, TR_SLAY_DEMON, 60},
6736 {TR_SLAY_ORC, "slay orc", 5, TR_SLAY_ORC, 15},
6737 {TR_KILL_ORC, "kill orc", 5, TR_SLAY_ORC, 60},
6738 {TR_SLAY_TROLL, "slay troll", 5, TR_SLAY_TROLL, 15},
6739 {TR_KILL_TROLL, "kill troll", 5, TR_SLAY_TROLL, 60},
6740 {TR_SLAY_GIANT, "slay giant", 5, TR_SLAY_GIANT, 20},
6741 {TR_KILL_GIANT, "kill giant", 5, TR_SLAY_GIANT, 60},
6742 {TR_SLAY_DRAGON, "slay dragon", 5, TR_SLAY_DRAGON, 20},
6743 {TR_KILL_DRAGON, "kill dragon", 5, TR_SLAY_DRAGON, 60},
6744 {TR_SLAY_HUMAN, "slay human", 5, TR_SLAY_HUMAN, 20},
6745 {TR_KILL_HUMAN, "kill human", 5, TR_SLAY_HUMAN, 60},
6747 {TR_ESP_ANIMAL, "sense animal", 6, TR_SLAY_ANIMAL, 40},
6748 {TR_ESP_UNDEAD, "sense undead", 6, TR_SLAY_UNDEAD, 40},
6749 {TR_ESP_DEMON, "sense demon", 6, TR_SLAY_DEMON, 40},
6750 {TR_ESP_ORC, "sense orc", 6, TR_SLAY_ORC, 40},
6751 {TR_ESP_TROLL, "sense troll", 6, TR_SLAY_TROLL, 40},
6752 {TR_ESP_GIANT, "sense giant", 6, TR_SLAY_GIANT, 40},
6753 {TR_ESP_DRAGON, "sense dragon", 6, TR_SLAY_DRAGON, 40},
6754 {TR_ESP_HUMAN, "sense human", 6, TR_SLAY_HUMAN, 40},
6756 {ESSENCE_ATTACK, "weapon enchant", 10, TR_ES_ATTACK, 30},
6757 {ESSENCE_AC, "armor enchant", 10, TR_ES_AC, 15},
6758 {ESSENCE_TMP_RES_ACID, "resist acid activation", 7, TR_RES_ACID, 50},
6759 {ESSENCE_TMP_RES_ELEC, "resist electricity activation", 7, TR_RES_ELEC, 50},
6760 {ESSENCE_TMP_RES_FIRE, "resist fire activation", 7, TR_RES_FIRE, 50},
6761 {ESSENCE_TMP_RES_COLD, "resist cold activation", 7, TR_RES_COLD, 50},
6762 {ESSENCE_SH_FIRE, "fiery sheath", 7, -1, 50},
6763 {ESSENCE_SH_ELEC, "electric sheath", 7, -1, 50},
6764 {ESSENCE_SH_COLD, "sheath of coldness", 7, -1, 50},
6765 {ESSENCE_RESISTANCE, "resistance", 2, -1, 150},
6766 {ESSENCE_SUSTAIN, "elements proof", 10, -1, 10},
6767 {ESSENCE_SLAY_GLOVE, "gauntlets of slaying", 1, TR_ES_ATTACK, 200},
6769 {-1, NULL, 0, -1, 0}
6775 * Essense names for Weapon smith
6778 static cptr essence_name[] =
6881 static cptr essence_name[] =
6984 static void display_essence(void)
6989 for (i = 1; i < 22; i++)
6994 prt("¥¨¥Ã¥»¥ó¥¹ ¸Ä¿ô ¥¨¥Ã¥»¥ó¥¹ ¸Ä¿ô ¥¨¥Ã¥»¥ó¥¹ ¸Ä¿ô", 1, 8);
6996 prt("Essence Num Essence Num Essence Num ", 1, 8);
6998 for (i = 0; essence_name[i]; i++)
7000 if (!essence_name[i][0]) continue;
7001 prt(format("%-11s %5d", essence_name[i], p_ptr->magic_num1[i]), 2+num%21, 8+num/21*22);
7005 prt("¸½ºß½ê»ý¤·¤Æ¤¤¤ë¥¨¥Ã¥»¥ó¥¹", 0, 0);
7007 prt("List of all essences you have.", 0, 0);
7014 static void drain_essence(void)
7016 int drain_value[sizeof(p_ptr->magic_num1) / sizeof(s32b)];
7019 bool observe = FALSE;
7020 int old_ds, old_dd, old_to_h, old_to_d, old_ac, old_to_a, old_pval, old_name2;
7021 u32b old_flgs[TR_FLAG_SIZE], new_flgs[TR_FLAG_SIZE];
7024 byte iy, ix, marked, number;
7025 s16b next_o_idx, weight;
7027 for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
7030 item_tester_hook = item_tester_hook_weapon_armour;
7031 item_tester_no_ryoute = TRUE;
7035 q = "¤É¤Î¥¢¥¤¥Æ¥à¤«¤éÃê½Ð¤·¤Þ¤¹¤«¡©";
7036 s = "Ãê½Ð¤Ç¤¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
7038 q = "Extract from which item? ";
7039 s = "You have nothing you can extract from.";
7042 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
7044 /* Get the item (in the pack) */
7047 o_ptr = &inventory[item];
7050 /* Get the item (on the floor) */
7053 o_ptr = &o_list[0 - item];
7056 if (object_known_p(o_ptr) && (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name || o_ptr->xtra3)) {
7057 char o_name[MAX_NLEN];
7058 object_desc(o_name, o_ptr, FALSE, 0);
7060 if (!get_check(format("ËÜÅö¤Ë%s¤«¤éÃê½Ð¤·¤Æ¤è¤í¤·¤¤¤Ç¤¹¤«¡©", o_name))) return;
7062 if (!get_check(format("Really extract from %s? ", o_name))) return;
7068 object_flags(o_ptr, old_flgs);
7069 if (have_flag(old_flgs, TR_KILL_DRAGON)) add_flag(old_flgs, TR_SLAY_DRAGON);
7070 if (have_flag(old_flgs, TR_KILL_ANIMAL)) add_flag(old_flgs, TR_SLAY_ANIMAL);
7071 if (have_flag(old_flgs, TR_KILL_EVIL)) add_flag(old_flgs, TR_SLAY_EVIL);
7072 if (have_flag(old_flgs, TR_KILL_UNDEAD)) add_flag(old_flgs, TR_SLAY_UNDEAD);
7073 if (have_flag(old_flgs, TR_KILL_DEMON)) add_flag(old_flgs, TR_SLAY_DEMON);
7074 if (have_flag(old_flgs, TR_KILL_ORC)) add_flag(old_flgs, TR_SLAY_ORC);
7075 if (have_flag(old_flgs, TR_KILL_TROLL)) add_flag(old_flgs, TR_SLAY_TROLL);
7076 if (have_flag(old_flgs, TR_KILL_GIANT)) add_flag(old_flgs, TR_SLAY_GIANT);
7077 if (have_flag(old_flgs, TR_KILL_HUMAN)) add_flag(old_flgs, TR_SLAY_HUMAN);
7079 old_to_a = o_ptr->to_a;
7081 old_to_h = o_ptr->to_h;
7082 old_to_d = o_ptr->to_d;
7085 old_pval = o_ptr->pval;
7086 old_name2 = o_ptr->name2;
7087 if (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE)) dec--;
7088 if (have_flag(old_flgs, TR_AGGRAVATE)) dec--;
7089 if (have_flag(old_flgs, TR_NO_TELE)) dec--;
7090 if (have_flag(old_flgs, TR_DRAIN_EXP)) dec--;
7091 if (have_flag(old_flgs, TR_TY_CURSE)) dec--;
7095 next_o_idx = o_ptr->next_o_idx;
7096 marked = o_ptr->marked;
7097 weight = o_ptr->weight;
7098 number = o_ptr->number;
7100 object_prep(o_ptr, o_ptr->k_idx);
7104 o_ptr->next_o_idx=next_o_idx;
7105 o_ptr->marked=marked;
7106 o_ptr->number = number;
7107 if (item >= 0) p_ptr->total_weight += (o_ptr->weight*o_ptr->number - weight*number);
7108 o_ptr->ident |= (IDENT_MENTAL);
7109 object_aware(o_ptr);
7110 object_known(o_ptr);
7112 object_flags(o_ptr, new_flgs);
7114 for (i = 0; essence_info[i].add_name; i++)
7116 essence_type *es_ptr = &essence_info[i];
7119 if (es_ptr->add < TR_FLAG_MAX && is_pval_flag(es_ptr->add) && old_pval)
7120 pval = (have_flag(new_flgs, es_ptr->add)) ? old_pval - o_ptr->pval : old_pval;
7122 if (es_ptr->add < TR_FLAG_MAX &&
7123 (!have_flag(new_flgs, es_ptr->add) || pval) &&
7124 have_flag(old_flgs, es_ptr->add))
7128 drain_value[es_ptr->essence] += 10 * pval;
7130 else if (es_ptr->essence != -2)
7132 drain_value[es_ptr->essence] += 10;
7134 else if (es_ptr->add == TR_SH_FIRE)
7136 drain_value[TR_BRAND_FIRE] += 10;
7137 drain_value[TR_RES_FIRE] += 10;
7139 else if (es_ptr->add == TR_SH_ELEC)
7141 drain_value[TR_BRAND_ELEC] += 10;
7142 drain_value[TR_RES_ELEC] += 10;
7144 else if (es_ptr->add == TR_SH_COLD)
7146 drain_value[TR_BRAND_COLD] += 10;
7147 drain_value[TR_RES_COLD] += 10;
7152 if ((have_flag(old_flgs, TR_FORCE_WEAPON)) && !(have_flag(new_flgs, TR_FORCE_WEAPON)))
7154 drain_value[TR_INT] += 5;
7155 drain_value[TR_WIS] += 5;
7157 if ((have_flag(old_flgs, TR_VORPAL)) && !(have_flag(new_flgs, TR_VORPAL)))
7159 drain_value[TR_BRAND_POIS] += 5;
7160 drain_value[TR_BRAND_ACID] += 5;
7161 drain_value[TR_BRAND_ELEC] += 5;
7162 drain_value[TR_BRAND_FIRE] += 5;
7163 drain_value[TR_BRAND_COLD] += 5;
7165 if ((have_flag(old_flgs, TR_DEC_MANA)) && !(have_flag(new_flgs, TR_DEC_MANA)))
7167 drain_value[TR_INT] += 10;
7169 if ((have_flag(old_flgs, TR_XTRA_MIGHT)) && !(have_flag(new_flgs, TR_XTRA_MIGHT)))
7171 drain_value[TR_STR] += 10;
7173 if ((have_flag(old_flgs, TR_XTRA_SHOTS)) && !(have_flag(new_flgs, TR_XTRA_SHOTS)))
7175 drain_value[TR_DEX] += 10;
7177 if (old_name2 == EGO_2WEAPON)
7179 drain_value[TR_DEX] += 20;
7181 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_SWORD) && (o_ptr->tval != TV_BOW))
7183 if (old_ds > o_ptr->ds) drain_value[TR_ES_ATTACK] += (old_ds-o_ptr->ds)*10;
7185 if (old_dd > o_ptr->dd) drain_value[TR_ES_ATTACK] += (old_dd-o_ptr->dd)*10;
7187 if (old_to_h > o_ptr->to_h) drain_value[TR_ES_ATTACK] += (old_to_h-o_ptr->to_h)*10;
7188 if (old_to_d > o_ptr->to_d) drain_value[TR_ES_ATTACK] += (old_to_d-o_ptr->to_d)*10;
7189 if (old_ac > o_ptr->ac) drain_value[TR_ES_AC] += (old_ac-o_ptr->ac)*10;
7190 if (old_to_a > o_ptr->to_a) drain_value[TR_ES_AC] += (old_to_a-o_ptr->to_a)*10;
7192 for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
7194 drain_value[i] *= number;
7195 drain_value[i] = drain_value[i] * dec / 4;
7196 drain_value[i] = MAX(drain_value[i], 0);
7197 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) drain_value[i] /= 10;
7206 msg_print("¥¨¥Ã¥»¥ó¥¹¤ÏÃê½Ð¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£");
7208 msg_print("You were not able to extract any essence.");
7214 msg_print("Ãê½Ð¤·¤¿¥¨¥Ã¥»¥ó¥¹:");
7216 msg_print("Extracted essences:");
7218 for (i = 0; essence_name[i]; i++)
7220 if (!essence_name[i][0]) continue;
7221 if (!drain_value[i]) continue;
7223 p_ptr->magic_num1[i] += drain_value[i];
7224 p_ptr->magic_num1[i] = MIN(20000, p_ptr->magic_num1[i]);
7226 msg_format("%s...%d", essence_name[i], drain_value[i]);
7230 /* Combine the pack */
7231 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
7234 p_ptr->window |= (PW_INVEN);
7239 static int choose_essence(void)
7243 int menu_line = (use_menu ? 1 : 0);
7246 cptr menu_name[] = {
7256 cptr menu_name[] = {
7266 const int mode_max = 7;
7269 if (repeat_pull(&mode) && 1 <= mode && mode <= mode_max)
7272 #endif /* ALLOW_REPEAT */
7281 for (i = 0; i < mode_max; i++)
7283 prt(format(" %s %s", (menu_line == 1+i) ? "¡Õ" : " ", menu_name[i]), 2 + i, 14);
7284 prt("¤É¤Î¼ïÎà¤Î¥¨¥Ã¥»¥ó¥¹Éղäò¹Ô¤¤¤Þ¤¹¤«¡©", 0, 0);
7286 prt(format(" %s %s", (menu_line == 1+i) ? "> " : " ", menu_name[i]), 2 + i, 14);
7287 prt("Choose from menu.", 0, 0);
7306 menu_line += mode_max - 1;
7315 if (menu_line > mode_max) menu_line -= mode_max;
7326 for (i = 0; i < mode_max; i++)
7327 prt(format(" %c) %s", 'a' + i, menu_name[i]), 2 + i, 14);
7330 if (!get_com("²¿¤òÉղä·¤Þ¤¹¤«:", &choice, TRUE))
7332 if (!get_com("Command :", &choice, TRUE))
7339 if (isupper(choice)) choice = tolower(choice);
7341 if ('a' <= choice && choice <= 'a' + (char)mode_max - 1)
7342 mode = (int)choice - 'a' + 1;
7349 #endif /* ALLOW_REPEAT */
7353 static void add_essence(int mode)
7355 int item, max_num = 0;
7364 char o_name[MAX_NLEN];
7366 essence_type *es_ptr;
7368 int menu_line = (use_menu ? 1 : 0);
7370 for (i = 0; essence_info[i].add_name; i++)
7372 es_ptr = &essence_info[i];
7374 if (es_ptr->type != mode) continue;
7379 if (!repeat_pull(&i) || i<0 || i>=max_num)
7381 #endif /* ALLOW_REPEAT */
7384 /* Nothing chosen yet */
7390 /* Build a prompt */
7392 (void) strnfmt(out_val, 78, "('*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤ÎǽÎϤòÉղä·¤Þ¤¹¤«¡©");
7394 (void)strnfmt(out_val, 78, "(*=List, ESC=exit) Add which ability? ");
7396 if (use_menu) screen_save();
7398 /* Get a spell from the user */
7400 choice = (always_show_list || use_menu) ? ESCAPE:1;
7404 if( choice==ESCAPE ) choice = ' ';
7405 else if( !get_com(out_val, &choice, FALSE) )break;
7407 if (use_menu && choice != ' ')
7422 menu_line += (max_num-1);
7445 menu_line = max_num;
7459 if (menu_line > max_num) menu_line -= max_num;
7461 /* Request redraw */
7462 if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
7465 if (!redraw || use_menu)
7469 char dummy[80], dummy2[80];
7477 /* Save the screen */
7478 if (!use_menu) screen_save();
7480 for (y = 1; y < 24; y++)
7483 /* Print header(s) */
7485 prt(format(" %-43s %6s/%s", "ǽÎÏ(ɬÍ×¥¨¥Ã¥»¥ó¥¹)", "ɬÍ׿ô", "½ê»ý¿ô"), 1, x);
7488 prt(format(" %-43s %6s/%s", "Ability (needed essence)", "Needs", "Possess"), 1, x);
7491 for (ctr = 0; ctr < max_num; ctr++)
7493 es_ptr = &essence_info[num[ctr]];
7497 if (ctr == (menu_line-1))
7499 strcpy(dummy, "¡Õ ");
7501 strcpy(dummy, "> ");
7503 else strcpy(dummy, " ");
7506 /* letter/number for power selection */
7509 sprintf(dummy, "%c) ",I2A(ctr));
7512 strcat(dummy, es_ptr->add_name);
7517 if (es_ptr->essence != -1)
7519 strcat(dummy, format("(%s)", essence_name[es_ptr->essence]));
7520 if (p_ptr->magic_num1[es_ptr->essence] < es_ptr->value) able[ctr] = FALSE;
7526 case ESSENCE_SH_FIRE:
7528 strcat(dummy, "(¾Æ´þ+ÂѲбê)");
7530 strcat(dummy, "(brand fire + res.fire)");
7532 if (p_ptr->magic_num1[TR_BRAND_FIRE] < es_ptr->value) able[ctr] = FALSE;
7533 if (p_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
7535 case ESSENCE_SH_ELEC:
7537 strcat(dummy, "(ÅÅ·â+ÂÑÅÅ·â)");
7539 strcat(dummy, "(brand elec. + res. elec.)");
7541 if (p_ptr->magic_num1[TR_BRAND_ELEC] < es_ptr->value) able[ctr] = FALSE;
7542 if (p_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
7544 case ESSENCE_SH_COLD:
7546 strcat(dummy, "(Åà·ë+ÂÑÎ䵤)");
7548 strcat(dummy, "(brand cold + res. cold)");
7550 if (p_ptr->magic_num1[TR_BRAND_COLD] < es_ptr->value) able[ctr] = FALSE;
7551 if (p_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
7553 case ESSENCE_RESISTANCE:
7555 strcat(dummy, "(ÂѲбê+ÂÑÎ䵤+ÂÑÅÅ·â+ÂÑ»À)");
7557 strcat(dummy, "(r.fire+r.cold+r.elec+r.acid)");
7559 if (p_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
7560 if (p_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
7561 if (p_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
7562 if (p_ptr->magic_num1[TR_RES_ACID] < es_ptr->value) able[ctr] = FALSE;
7564 case ESSENCE_SUSTAIN:
7566 strcat(dummy, "(ÂѲбê+ÂÑÎ䵤+ÂÑÅÅ·â+ÂÑ»À)");
7568 strcat(dummy, "(r.fire+r.cold+r.elec+r.acid)");
7570 if (p_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
7571 if (p_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
7572 if (p_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
7573 if (p_ptr->magic_num1[TR_RES_ACID] < es_ptr->value) able[ctr] = FALSE;
7578 if (!able[ctr]) col = TERM_RED;
7580 if (es_ptr->essence != -1)
7582 sprintf(dummy2, "%-49s %3d/%d", dummy, es_ptr->value, (int)p_ptr->magic_num1[es_ptr->essence]);
7586 sprintf(dummy2, "%-49s %3d/(\?\?)", dummy, es_ptr->value);
7589 c_prt(col, dummy2, ctr+2, x);
7599 /* Restore the screen */
7610 ask = (isupper(choice));
7613 if (ask) choice = tolower(choice);
7615 /* Extract request */
7616 i = (islower(choice) ? A2I(choice) : -1);
7619 /* Totally Illegal */
7620 if ((i < 0) || (i >= max_num) || !able[i])
7633 (void) strnfmt(tmp_val, 78, "%s¤òÉղä·¤Þ¤¹¤«¡© ", essence_info[num[i]].add_name);
7635 (void) strnfmt(tmp_val, 78, "Add the abilitiy of %s? ", essence_info[num[i]].add_name);
7638 /* Belay that order */
7639 if (!get_check(tmp_val)) continue;
7646 /* Restore the screen */
7647 if (redraw) screen_load();
7654 #endif /* ALLOW_REPEAT */
7656 es_ptr = &essence_info[num[i]];
7658 if (es_ptr->add == ESSENCE_SLAY_GLOVE)
7659 item_tester_tval = TV_GLOVES;
7661 item_tester_hook = item_tester_hook_melee_ammo;
7662 else if (es_ptr->add == ESSENCE_ATTACK)
7663 item_tester_hook = item_tester_hook_weapon;
7664 else if (es_ptr->add == ESSENCE_AC)
7665 item_tester_hook = item_tester_hook_armour;
7667 item_tester_hook = item_tester_hook_weapon_armour;
7668 item_tester_no_ryoute = TRUE;
7672 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò²þÎɤ·¤Þ¤¹¤«¡©";
7673 s = "²þÎɤǤ¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
7675 q = "Improve which item? ";
7676 s = "You have nothing to improve.";
7679 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
7681 /* Get the item (in the pack) */
7684 o_ptr = &inventory[item];
7687 /* Get the item (on the floor) */
7690 o_ptr = &o_list[0 - item];
7693 if ((mode != 10) && (o_ptr->name1 || o_ptr->art_name || o_ptr->xtra3))
7696 msg_print("¤½¤Î¥¢¥¤¥Æ¥à¤Ï¤³¤ì°Ê¾å²þÎɤǤ¤Ê¤¤¡£");
7698 msg_print("This item is no more able to be improved");
7703 object_desc(o_name, o_ptr, FALSE, 0);
7705 use_essence = es_ptr->value;
7706 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) use_essence = (use_essence+9)/10;
7707 if (o_ptr->number > 1)
7709 use_essence *= o_ptr->number;
7711 msg_format("%d¸Ä¤¢¤ë¤Î¤Ç¥¨¥Ã¥»¥ó¥¹¤Ï%dɬÍפǤ¹¡£", o_ptr->number, use_essence);
7713 msg_format("It will take %d essences.",use_essence);
7718 if (es_ptr->essence != -1)
7720 if (p_ptr->magic_num1[es_ptr->essence] < use_essence)
7723 msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â¤ê¤Ê¤¤¡£");
7725 msg_print("You don't have enough essences.");
7729 if (is_pval_flag(es_ptr->add))
7731 if (es_ptr->add == TR_BLOWS)
7733 if (o_ptr->pval > 1)
7736 if (!get_check("½¤ÀµÃͤÏ1¤Ë¤Ê¤ê¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) return;
7738 if (!get_check("The magic number of this weapon will become 1. Are you sure? ")) return;
7743 else if (o_ptr->pval)
7745 use_essence *= o_ptr->pval;
7747 msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
7749 msg_format("It will take %d essences.",use_essence);
7757 int limit = MIN(5, p_ptr->magic_num1[es_ptr->essence]/es_ptr->value);
7761 sprintf(tmp, "¤¤¤¯¤ÄÉղä·¤Þ¤¹¤«¡© (1-%d): ", limit);
7763 sprintf(tmp, "Enchant how many? (1-%d): ", limit);
7765 strcpy(tmp_val, "1");
7767 if (!get_string(tmp, tmp_val, 1)) return;
7768 pval = atoi(tmp_val);
7769 if (pval > limit) pval = limit;
7770 else if (pval < 1) pval = 1;
7772 use_essence *= pval;
7774 msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
7776 msg_format("It will take %d essences.",use_essence);
7779 if (p_ptr->magic_num1[es_ptr->essence] < use_essence)
7782 msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â¤ê¤Ê¤¤¡£");
7784 msg_print("You don't have enough essences.");
7789 else if (es_ptr->add == ESSENCE_SLAY_GLOVE)
7793 int get_to_h, get_to_d;
7795 strcpy(tmp_val, "1");
7797 if (!get_string(format("¤¤¤¯¤ÄÉղä·¤Þ¤¹¤«¡© (1-%d):", p_ptr->lev/7+3), tmp_val, 2)) return;
7799 if (!get_string(format("Enchant how many? (1-%d):", p_ptr->lev/7+3), tmp_val, 2)) return;
7801 val = atoi(tmp_val);
7802 if (val > p_ptr->lev/7+3) val = p_ptr->lev/7+3;
7803 else if (val < 1) val = 1;
7806 msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
7808 msg_format("It will take %d essences.",use_essence);
7810 if (p_ptr->magic_num1[es_ptr->essence] < use_essence)
7813 msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â¤ê¤Ê¤¤¡£");
7815 msg_print("You don't have enough essences");
7819 get_to_h = ((val+1)/2+randint0(val/2+1));
7820 get_to_d = ((val+1)/2+randint0(val/2+1));
7821 o_ptr->xtra4 = (get_to_h<<8)+get_to_d;
7822 o_ptr->to_h += get_to_h;
7823 o_ptr->to_d += get_to_d;
7825 p_ptr->magic_num1[es_ptr->essence] -= use_essence;
7826 if (es_ptr->add == ESSENCE_ATTACK)
7828 if ((o_ptr->to_h >= p_ptr->lev/5+5) && (o_ptr->to_d >= p_ptr->lev/5+5))
7831 msg_print("²þÎɤ˼ºÇÔ¤·¤¿¡£");
7833 msg_print("You failed to enchant.");
7840 if (o_ptr->to_h < p_ptr->lev/5+5) o_ptr->to_h++;
7841 if (o_ptr->to_d < p_ptr->lev/5+5) o_ptr->to_d++;
7844 else if (es_ptr->add == ESSENCE_AC)
7846 if (o_ptr->to_a >= p_ptr->lev/5+5)
7849 msg_print("²þÎɤ˼ºÇÔ¤·¤¿¡£");
7851 msg_print("You failed to enchant.");
7858 if (o_ptr->to_a < p_ptr->lev/5+5) o_ptr->to_a++;
7863 o_ptr->xtra3 = es_ptr->add + 1;
7868 bool success = TRUE;
7872 case ESSENCE_SH_FIRE:
7873 if ((p_ptr->magic_num1[TR_BRAND_FIRE] < use_essence) || (p_ptr->magic_num1[TR_RES_FIRE] < use_essence))
7878 p_ptr->magic_num1[TR_BRAND_FIRE] -= use_essence;
7879 p_ptr->magic_num1[TR_RES_FIRE] -= use_essence;
7881 case ESSENCE_SH_ELEC:
7882 if ((p_ptr->magic_num1[TR_BRAND_ELEC] < use_essence) || (p_ptr->magic_num1[TR_RES_ELEC] < use_essence))
7887 p_ptr->magic_num1[TR_BRAND_ELEC] -= use_essence;
7888 p_ptr->magic_num1[TR_RES_ELEC] -= use_essence;
7890 case ESSENCE_SH_COLD:
7891 if ((p_ptr->magic_num1[TR_BRAND_COLD] < use_essence) || (p_ptr->magic_num1[TR_RES_COLD] < use_essence))
7896 p_ptr->magic_num1[TR_BRAND_COLD] -= use_essence;
7897 p_ptr->magic_num1[TR_RES_COLD] -= use_essence;
7899 case ESSENCE_RESISTANCE:
7900 case ESSENCE_SUSTAIN:
7901 if ((p_ptr->magic_num1[TR_RES_ACID] < use_essence) || (p_ptr->magic_num1[TR_RES_ELEC] < use_essence) || (p_ptr->magic_num1[TR_RES_FIRE] < use_essence) || (p_ptr->magic_num1[TR_RES_COLD] < use_essence))
7906 p_ptr->magic_num1[TR_RES_ACID] -= use_essence;
7907 p_ptr->magic_num1[TR_RES_ELEC] -= use_essence;
7908 p_ptr->magic_num1[TR_RES_FIRE] -= use_essence;
7909 p_ptr->magic_num1[TR_RES_COLD] -= use_essence;
7915 msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â¤ê¤Ê¤¤¡£");
7917 msg_print("You don't have enough essences");
7921 if (es_ptr->add == ESSENCE_SUSTAIN)
7923 add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
7924 add_flag(o_ptr->art_flags, TR_IGNORE_ELEC);
7925 add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
7926 add_flag(o_ptr->art_flags, TR_IGNORE_COLD);
7930 o_ptr->xtra3 = es_ptr->add + 1;
7937 msg_format("%s¤Ë%s¤ÎǽÎϤòÉղä·¤Þ¤·¤¿¡£", o_name, es_ptr->add_name);
7939 msg_format("You have added ability of %s to %s.", es_ptr->add_name, o_name);
7942 /* Combine the pack */
7943 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
7946 p_ptr->window |= (PW_INVEN);
7950 static bool item_tester_hook_kaji(object_type *o_ptr)
7952 switch (o_ptr->tval)
7972 if (o_ptr->xtra3) return (TRUE);
7980 static void erase_essence(void)
7985 char o_name[MAX_NLEN];
7986 u32b flgs[TR_FLAG_SIZE];
7988 item_tester_hook = item_tester_hook_kaji;
7992 q = "¤É¤Î¥¢¥¤¥Æ¥à¤Î¥¨¥Ã¥»¥ó¥¹¤ò¾Ãµî¤·¤Þ¤¹¤«¡©";
7993 s = "¥¨¥Ã¥»¥ó¥¹¤òÉղä·¤¿¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
7995 q = "Remove from which item? ";
7996 s = "You have nothing to remove essence.";
7999 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
8001 /* Get the item (in the pack) */
8004 o_ptr = &inventory[item];
8007 /* Get the item (on the floor) */
8010 o_ptr = &o_list[0 - item];
8013 object_desc(o_name, o_ptr, FALSE, 0);
8015 if (!get_check(format("¤è¤í¤·¤¤¤Ç¤¹¤«¡©[%s]", o_name))) return;
8017 if (!get_check(format("Are you sure?[%s]", o_name))) return;
8022 if (o_ptr->xtra3 == 1+ESSENCE_SLAY_GLOVE)
8024 o_ptr->to_h -= (o_ptr->xtra4>>8);
8025 o_ptr->to_d -= (o_ptr->xtra4 & 0x000f);
8029 object_flags(o_ptr, flgs);
8030 if (!(have_pval_flags(flgs))) o_ptr->pval = 0;
8032 msg_print("¥¨¥Ã¥»¥ó¥¹¤ò¼è¤êµî¤Ã¤¿¡£");
8034 msg_print("You removed all essence you have added");
8037 /* Combine the pack */
8038 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
8041 p_ptr->window |= (PW_INVEN);
8044 void do_cmd_kaji(bool only_browse)
8049 int menu_line = (use_menu ? 1 : 0);
8053 if (p_ptr->confused)
8056 msg_print("º®Í𤷤Ƥ¤¤Æºî¶È¤Ç¤¤Ê¤¤¡ª");
8058 msg_print("You are too confused!");
8066 msg_print("Ìܤ¬¸«¤¨¤Ê¤¯¤Æºî¶È¤Ç¤¤Ê¤¤¡ª");
8068 msg_print("You are blind!");
8076 msg_print("¤¦¤Þ¤¯¸«¤¨¤Ê¤¯¤Æºî¶È¤Ç¤¤Ê¤¤¡ª");
8078 msg_print("You are hullcinating!");
8086 if (!(repeat_pull(&mode) && 1 <= mode && mode <= 5))
8088 #endif /* ALLOW_REPEAT */
8090 if (only_browse) screen_save();
8092 if (!only_browse) screen_save();
8098 prt(format(" %s ¥¨¥Ã¥»¥ó¥¹°ìÍ÷", (menu_line == 1) ? "¡Õ" : " "), 2, 14);
8099 prt(format(" %s ¥¨¥Ã¥»¥ó¥¹Ãê½Ð", (menu_line == 2) ? "¡Õ" : " "), 3, 14);
8100 prt(format(" %s ¥¨¥Ã¥»¥ó¥¹¾Ãµî", (menu_line == 3) ? "¡Õ" : " "), 4, 14);
8101 prt(format(" %s ¥¨¥Ã¥»¥ó¥¹ÉÕ²Ã", (menu_line == 4) ? "¡Õ" : " "), 5, 14);
8102 prt(format(" %s Éð´ï/Ëɶñ¶¯²½", (menu_line == 5) ? "¡Õ" : " "), 6, 14);
8103 prt(format("¤É¤Î¼ïÎà¤Îµ»½Ñ¤ò%s¤Þ¤¹¤«¡©", only_browse ? "Ä´¤Ù" : "»È¤¤"), 0, 0);
8105 prt(format(" %s List essences", (menu_line == 1) ? "> " : " "), 2, 14);
8106 prt(format(" %s Extract essence", (menu_line == 2) ? "> " : " "), 3, 14);
8107 prt(format(" %s Remove essence", (menu_line == 3) ? "> " : " "), 4, 14);
8108 prt(format(" %s Add essence", (menu_line == 4) ? "> " : " "), 5, 14);
8109 prt(format(" %s Enchant weapon/armor", (menu_line == 5) ? "> " : " "), 6, 14);
8110 prt(format("Choose command from menu."), 0, 0);
8137 if (menu_line > 5) menu_line -= 5;
8146 prt(" a) ¥¨¥Ã¥»¥ó¥¹°ìÍ÷", 2, 14);
8147 prt(" b) ¥¨¥Ã¥»¥ó¥¹Ãê½Ð", 3, 14);
8148 prt(" c) ¥¨¥Ã¥»¥ó¥¹¾Ãµî", 4, 14);
8149 prt(" d) ¥¨¥Ã¥»¥ó¥¹ÉÕ²Ã", 5, 14);
8150 prt(" e) Éð´ï/Ëɶñ¶¯²½", 6, 14);
8151 if (!get_com(format("¤É¤ÎǽÎϤò%s¤Þ¤¹¤«:", only_browse ? "Ä´¤Ù" : "»È¤¤"), &choice, TRUE))
8153 prt(" a) List essences", 2, 14);
8154 prt(" b) Extract essence", 3, 14);
8155 prt(" c) Remove essence", 4, 14);
8156 prt(" d) Add essence", 5, 14);
8157 prt(" e) Enchant weapon/armor", 6, 14);
8158 if (!get_com("Command :", &choice, TRUE))
8195 /* Clear lines, position cursor (really should use strlen here) */
8196 Term_erase(14, 21, 255);
8197 Term_erase(14, 20, 255);
8198 Term_erase(14, 19, 255);
8199 Term_erase(14, 18, 255);
8200 Term_erase(14, 17, 255);
8201 Term_erase(14, 16, 255);
8203 roff_to_buf( kaji_tips[mode-1],62,temp);
8204 for(j=0, line = 17;temp[j];j+=(1+strlen(&temp[j])))
8206 prt(&temp[j], line, 15);
8211 if (!only_browse) screen_load();
8212 } while (only_browse);
8216 #endif /* ALLOW_REPEAT */
8220 case 1: display_essence();break;
8221 case 2: drain_essence();break;
8222 case 3: erase_essence();break;
8224 mode = choose_essence();
8229 case 5: add_essence(10);break;