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]);
890 ego_item_type *e_ptr = &e_info[o_ptr->name2];
892 for (i = 0; i < TR_FLAG_SIZE; i++)
893 flgs[i] &= ~(e_ptr->flags[i]);
895 if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET))
897 object_kind *k_ptr = &k_info[o_ptr->k_idx];
899 for (i = 0; i < TR_FLAG_SIZE; i++)
900 flgs[i] &= ~(k_ptr->flags[i]);
903 else if (o_ptr->art_name)
909 if (have_flag(flgs, TR_STR)) total += (1500 * plusses);
910 if (have_flag(flgs, TR_INT)) total += (1500 * plusses);
911 if (have_flag(flgs, TR_WIS)) total += (1500 * plusses);
912 if (have_flag(flgs, TR_DEX)) total += (1500 * plusses);
913 if (have_flag(flgs, TR_CON)) total += (1500 * plusses);
914 if (have_flag(flgs, TR_CHR)) total += (750 * plusses);
915 if (have_flag(flgs, TR_MAGIC_MASTERY)) total += (600 * plusses);
916 if (have_flag(flgs, TR_STEALTH)) total += (250 * plusses);
917 if (have_flag(flgs, TR_SEARCH)) total += (100 * plusses);
918 if (have_flag(flgs, TR_INFRA)) total += (150 * plusses);
919 if (have_flag(flgs, TR_TUNNEL)) total += (175 * plusses);
920 if ((have_flag(flgs, TR_SPEED)) && (plusses > 0))
921 total += (10000 + (2500 * plusses));
922 if ((have_flag(flgs, TR_BLOWS)) && (plusses > 0))
923 total += (10000 + (2500 * plusses));
924 if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
928 if (have_flag(flgs, TR_CHAOTIC)) {total += 5000;count++;}
929 if (have_flag(flgs, TR_VAMPIRIC)) {total += 6500;count++;}
930 if (have_flag(flgs, TR_FORCE_WEAPON)) {tmp_cost += 2500;count++;}
931 if (have_flag(flgs, TR_KILL_ANIMAL)) {tmp_cost += 2800;count++;}
932 else if (have_flag(flgs, TR_SLAY_ANIMAL)) {tmp_cost += 1800;count++;}
933 if (have_flag(flgs, TR_KILL_EVIL)) {tmp_cost += 3300;count++;}
934 else if (have_flag(flgs, TR_SLAY_EVIL)) {tmp_cost += 2300;count++;}
935 if (have_flag(flgs, TR_KILL_HUMAN)) {tmp_cost += 2800;count++;}
936 else if (have_flag(flgs, TR_SLAY_HUMAN)) {tmp_cost += 1800;count++;}
937 if (have_flag(flgs, TR_KILL_UNDEAD)) {tmp_cost += 2800;count++;}
938 else if (have_flag(flgs, TR_SLAY_UNDEAD)) {tmp_cost += 1800;count++;}
939 if (have_flag(flgs, TR_KILL_DEMON)) {tmp_cost += 2800;count++;}
940 else if (have_flag(flgs, TR_SLAY_DEMON)) {tmp_cost += 1800;count++;}
941 if (have_flag(flgs, TR_KILL_ORC)) {tmp_cost += 2500;count++;}
942 else if (have_flag(flgs, TR_SLAY_ORC)) {tmp_cost += 1500;count++;}
943 if (have_flag(flgs, TR_KILL_TROLL)) {tmp_cost += 2800;count++;}
944 else if (have_flag(flgs, TR_SLAY_TROLL)) {tmp_cost += 1800;count++;}
945 if (have_flag(flgs, TR_KILL_GIANT)) {tmp_cost += 2800;count++;}
946 else if (have_flag(flgs, TR_SLAY_GIANT)) {tmp_cost += 1800;count++;}
947 if (have_flag(flgs, TR_KILL_DRAGON)) {tmp_cost += 2800;count++;}
948 else if (have_flag(flgs, TR_SLAY_DRAGON)) {tmp_cost += 1800;count++;}
950 if (have_flag(flgs, TR_VORPAL)) {tmp_cost += 2500;count++;}
951 if (have_flag(flgs, TR_IMPACT)) {tmp_cost += 2500;count++;}
952 if (have_flag(flgs, TR_BRAND_POIS)) {tmp_cost += 3800;count++;}
953 if (have_flag(flgs, TR_BRAND_ACID)) {tmp_cost += 3800;count++;}
954 if (have_flag(flgs, TR_BRAND_ELEC)) {tmp_cost += 3800;count++;}
955 if (have_flag(flgs, TR_BRAND_FIRE)) {tmp_cost += 2500;count++;}
956 if (have_flag(flgs, TR_BRAND_COLD)) {tmp_cost += 2500;count++;}
957 total += (tmp_cost * count);
959 if (have_flag(flgs, TR_SUST_STR)) total += 850;
960 if (have_flag(flgs, TR_SUST_INT)) total += 850;
961 if (have_flag(flgs, TR_SUST_WIS)) total += 850;
962 if (have_flag(flgs, TR_SUST_DEX)) total += 850;
963 if (have_flag(flgs, TR_SUST_CON)) total += 850;
964 if (have_flag(flgs, TR_SUST_CHR)) total += 250;
965 if (have_flag(flgs, TR_RIDING)) total += 0;
966 if (have_flag(flgs, TR_XXX2)) total += 0;
967 if (have_flag(flgs, TR_THROW)) total += 5000;
968 if (have_flag(flgs, TR_FREE_ACT)) total += 4500;
969 if (have_flag(flgs, TR_HOLD_LIFE)) total += 8500;
973 if (have_flag(flgs, TR_IM_ACID)) {tmp_cost += 15000;count += 2;}
974 if (have_flag(flgs, TR_IM_ELEC)) {tmp_cost += 15000;count += 2;}
975 if (have_flag(flgs, TR_IM_FIRE)) {tmp_cost += 15000;count += 2;}
976 if (have_flag(flgs, TR_IM_COLD)) {tmp_cost += 15000;count += 2;}
977 if (have_flag(flgs, TR_REFLECT)) {tmp_cost += 5000;count += 2;}
978 if (have_flag(flgs, TR_RES_ACID)) {tmp_cost += 500;count++;}
979 if (have_flag(flgs, TR_RES_ELEC)) {tmp_cost += 500;count++;}
980 if (have_flag(flgs, TR_RES_FIRE)) {tmp_cost += 500;count++;}
981 if (have_flag(flgs, TR_RES_COLD)) {tmp_cost += 500;count++;}
982 if (have_flag(flgs, TR_RES_POIS)) {tmp_cost += 1000;count += 2;}
983 if (have_flag(flgs, TR_RES_FEAR)) {tmp_cost += 1000;count += 2;}
984 if (have_flag(flgs, TR_RES_LITE)) {tmp_cost += 800;count += 2;}
985 if (have_flag(flgs, TR_RES_DARK)) {tmp_cost += 800;count += 2;}
986 if (have_flag(flgs, TR_RES_BLIND)) {tmp_cost += 900;count += 2;}
987 if (have_flag(flgs, TR_RES_CONF)) {tmp_cost += 900;count += 2;}
988 if (have_flag(flgs, TR_RES_SOUND)) {tmp_cost += 900;count += 2;}
989 if (have_flag(flgs, TR_RES_SHARDS)) {tmp_cost += 900;count += 2;}
990 if (have_flag(flgs, TR_RES_NETHER)) {tmp_cost += 900;count += 2;}
991 if (have_flag(flgs, TR_RES_NEXUS)) {tmp_cost += 900;count += 2;}
992 if (have_flag(flgs, TR_RES_CHAOS)) {tmp_cost += 1000;count += 2;}
993 if (have_flag(flgs, TR_RES_DISEN)) {tmp_cost += 2000;count += 2;}
994 total += (tmp_cost * count);
996 if (have_flag(flgs, TR_SH_FIRE)) total += 5000;
997 if (have_flag(flgs, TR_SH_ELEC)) total += 5000;
998 if (have_flag(flgs, TR_SH_COLD)) total += 5000;
999 if (have_flag(flgs, TR_NO_TELE)) total -= 10000;
1000 if (have_flag(flgs, TR_NO_MAGIC)) total += 2500;
1001 if (have_flag(flgs, TR_TY_CURSE)) total -= 15000;
1002 if (have_flag(flgs, TR_HIDE_TYPE)) total += 0;
1003 if (have_flag(flgs, TR_SHOW_MODS)) total += 0;
1004 if (have_flag(flgs, TR_FEATHER)) total += 1250;
1005 if (have_flag(flgs, TR_LITE)) total += 1250;
1006 if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
1007 if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
1008 if (have_flag(flgs, TR_ESP_ANIMAL)) total += 3000;
1009 if (have_flag(flgs, TR_ESP_UNDEAD)) total += 3000;
1010 if (have_flag(flgs, TR_ESP_DEMON)) total += 3000;
1011 if (have_flag(flgs, TR_ESP_ORC)) total += 3000;
1012 if (have_flag(flgs, TR_ESP_TROLL)) total += 3000;
1013 if (have_flag(flgs, TR_ESP_GIANT)) total += 3000;
1014 if (have_flag(flgs, TR_ESP_DRAGON)) total += 3000;
1015 if (have_flag(flgs, TR_ESP_HUMAN)) total += 3000;
1016 if (have_flag(flgs, TR_ESP_EVIL)) total += 10000;
1017 if (have_flag(flgs, TR_ESP_GOOD)) total += 6000;
1018 if (have_flag(flgs, TR_ESP_NONLIVING)) total += 6000;
1019 if (have_flag(flgs, TR_ESP_UNIQUE)) total += 10000;
1020 if (have_flag(flgs, TR_SLOW_DIGEST)) total += 750;
1021 if (have_flag(flgs, TR_REGEN)) total += 2500;
1022 if (have_flag(flgs, TR_WARNING)) total += 2000;
1023 if (have_flag(flgs, TR_XTRA_MIGHT)) total += 2250;
1024 if (have_flag(flgs, TR_XTRA_SHOTS)) total += 10000;
1025 if (have_flag(flgs, TR_IGNORE_ACID)) total += 100;
1026 if (have_flag(flgs, TR_IGNORE_ELEC)) total += 100;
1027 if (have_flag(flgs, TR_IGNORE_FIRE)) total += 100;
1028 if (have_flag(flgs, TR_IGNORE_COLD)) total += 100;
1029 if (have_flag(flgs, TR_ACTIVATE)) total += 100;
1030 if (have_flag(flgs, TR_DRAIN_EXP)) total -= 12500;
1031 if (have_flag(flgs, TR_TELEPORT))
1033 if (cursed_p(o_ptr))
1038 if (have_flag(flgs, TR_AGGRAVATE)) total -= 10000;
1039 if (have_flag(flgs, TR_BLESSED)) total += 750;
1040 if (o_ptr->curse_flags & TRC_CURSED) total -= 5000;
1041 if (o_ptr->curse_flags & TRC_HEAVY_CURSE) total -= 12500;
1042 if (o_ptr->curse_flags & TRC_PERMA_CURSE) total -= 15000;
1044 /* Also, give some extra for activatable powers... */
1045 if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
1047 int type = o_ptr->xtra2;
1049 if (type == ACT_SUNLIGHT) total += 250;
1050 else if (type == ACT_BO_MISS_1) total += 250;
1051 else if (type == ACT_BA_POIS_1) total += 300;
1052 else if (type == ACT_BO_ELEC_1) total += 250;
1053 else if (type == ACT_BO_ACID_1) total += 250;
1054 else if (type == ACT_BO_COLD_1) total += 250;
1055 else if (type == ACT_BO_FIRE_1) total += 250;
1056 else if (type == ACT_BA_COLD_1) total += 750;
1057 else if (type == ACT_BA_FIRE_1) total += 1000;
1058 else if (type == ACT_DRAIN_1) total += 500;
1059 else if (type == ACT_BA_COLD_2) total += 1250;
1060 else if (type == ACT_BA_ELEC_2) total += 1500;
1061 else if (type == ACT_DRAIN_2) total += 750;
1062 else if (type == ACT_VAMPIRE_1) total += 1000;
1063 else if (type == ACT_BO_MISS_2) total += 1000;
1064 else if (type == ACT_BA_FIRE_2) total += 1750;
1065 else if (type == ACT_BA_COLD_3) total += 2500;
1066 else if (type == ACT_BA_ELEC_3) total += 2500;
1067 else if (type == ACT_WHIRLWIND) total += 7500;
1068 else if (type == ACT_VAMPIRE_2) total += 2500;
1069 else if (type == ACT_CALL_CHAOS) total += 5000;
1070 else if (type == ACT_ROCKET) total += 5000;
1071 else if (type == ACT_DISP_EVIL) total += 4000;
1072 else if (type == ACT_DISP_GOOD) total += 3500;
1073 else if (type == ACT_BA_MISS_3) total += 5000;
1074 else if (type == ACT_CONFUSE) total += 500;
1075 else if (type == ACT_SLEEP) total += 750;
1076 else if (type == ACT_QUAKE) total += 600;
1077 else if (type == ACT_TERROR) total += 2500;
1078 else if (type == ACT_TELE_AWAY) total += 2000;
1079 else if (type == ACT_BANISH_EVIL) total += 2000;
1080 else if (type == ACT_GENOCIDE) total += 10000;
1081 else if (type == ACT_MASS_GENO) total += 10000;
1082 else if (type == ACT_CHARM_ANIMAL) total += 7500;
1083 else if (type == ACT_CHARM_UNDEAD) total += 10000;
1084 else if (type == ACT_CHARM_OTHER) total += 10000;
1085 else if (type == ACT_CHARM_ANIMALS) total += 12500;
1086 else if (type == ACT_CHARM_OTHERS) total += 17500;
1087 else if (type == ACT_SUMMON_ANIMAL) total += 10000;
1088 else if (type == ACT_SUMMON_PHANTOM) total += 12000;
1089 else if (type == ACT_SUMMON_ELEMENTAL) total += 15000;
1090 else if (type == ACT_SUMMON_DEMON) total += 20000;
1091 else if (type == ACT_SUMMON_UNDEAD) total += 20000;
1092 else if (type == ACT_CURE_LW) total += 500;
1093 else if (type == ACT_CURE_MW) total += 750;
1094 else if (type == ACT_CURE_POISON) total += 1000;
1095 else if (type == ACT_REST_LIFE) total += 7500;
1096 else if (type == ACT_REST_ALL) total += 15000;
1097 else if (type == ACT_CURE_700) total += 10000;
1098 else if (type == ACT_CURE_1000) total += 15000;
1099 else if (type == ACT_ESP) total += 1500;
1100 else if (type == ACT_BERSERK) total += 800;
1101 else if (type == ACT_PROT_EVIL) total += 5000;
1102 else if (type == ACT_RESIST_ALL) total += 5000;
1103 else if (type == ACT_SPEED) total += 15000;
1104 else if (type == ACT_XTRA_SPEED) total += 25000;
1105 else if (type == ACT_WRAITH) total += 25000;
1106 else if (type == ACT_INVULN) total += 25000;
1107 else if (type == ACT_LIGHT) total += 150;
1108 else if (type == ACT_MAP_LIGHT) total += 500;
1109 else if (type == ACT_DETECT_ALL) total += 1000;
1110 else if (type == ACT_DETECT_XTRA) total += 12500;
1111 else if (type == ACT_ID_FULL) total += 10000;
1112 else if (type == ACT_ID_PLAIN) total += 1250;
1113 else if (type == ACT_RUNE_EXPLO) total += 4000;
1114 else if (type == ACT_RUNE_PROT) total += 10000;
1115 else if (type == ACT_SATIATE) total += 2000;
1116 else if (type == ACT_DEST_DOOR) total += 100;
1117 else if (type == ACT_STONE_MUD) total += 1000;
1118 else if (type == ACT_RECHARGE) total += 1000;
1119 else if (type == ACT_ALCHEMY) total += 10000;
1120 else if (type == ACT_DIM_DOOR) total += 10000;
1121 else if (type == ACT_TELEPORT) total += 2000;
1122 else if (type == ACT_RECALL) total += 7500;
1130 * Return the "real" price of a "known" item, not including discounts
1132 * Wand and staffs get cost for each charge
1134 * Armor is worth an extra 100 gold per bonus point to armor class.
1136 * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).
1138 * Missiles are only worth 5 gold per bonus point, since they
1139 * usually appear in groups of 20, and we want the player to get
1140 * the same amount of cash for any "equivalent" item. Note that
1141 * missiles never have any of the "pval" flags, and in fact, they
1142 * only have a few of the available flags, primarily of the "slay"
1143 * and "brand" and "ignore" variety.
1145 * Armor with a negative armor bonus is worthless.
1146 * Weapons with negative hit+damage bonuses are worthless.
1148 * Every wearable item with a "pval" bonus is worth extra (see below).
1150 s32b object_value_real(object_type *o_ptr)
1154 u32b flgs[TR_FLAG_SIZE];
1156 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1159 /* Hack -- "worthless" items */
1160 if (!get_object_cost(o_ptr)) return (0L);
1163 value = get_object_cost(o_ptr);
1165 /* Extract some flags */
1166 object_flags(o_ptr, flgs);
1171 artifact_type *a_ptr = &a_info[o_ptr->name1];
1173 /* Hack -- "worthless" artifacts */
1174 if (!a_ptr->cost) return (0L);
1176 /* Hack -- Use the artifact cost instead */
1177 value = a_ptr->cost;
1178 value += flag_cost(o_ptr, o_ptr->pval);
1183 else if (o_ptr->name2)
1185 ego_item_type *e_ptr = &e_info[o_ptr->name2];
1187 /* Hack -- "worthless" ego-items */
1188 if (!e_ptr->cost) return (0L);
1190 /* Hack -- Reward the ego-item with a bonus */
1191 value += e_ptr->cost;
1192 value += flag_cost(o_ptr, o_ptr->pval);
1195 else if (o_ptr->art_flags[0] || o_ptr->art_flags[1] || o_ptr->art_flags[2])
1197 value += flag_cost(o_ptr, o_ptr->pval);
1201 /* Analyze pval bonus */
1202 switch (o_ptr->tval)
1225 /* Hack -- Negative "pval" is always bad */
1226 if (o_ptr->pval < 0) return (0L);
1229 if (!o_ptr->pval) break;
1231 /* Give credit for stat bonuses */
1232 if (have_flag(flgs, TR_STR)) value += (o_ptr->pval * 200L);
1233 if (have_flag(flgs, TR_INT)) value += (o_ptr->pval * 200L);
1234 if (have_flag(flgs, TR_WIS)) value += (o_ptr->pval * 200L);
1235 if (have_flag(flgs, TR_DEX)) value += (o_ptr->pval * 200L);
1236 if (have_flag(flgs, TR_CON)) value += (o_ptr->pval * 200L);
1237 if (have_flag(flgs, TR_CHR)) value += (o_ptr->pval * 200L);
1239 /* Give credit for stealth and searching */
1240 if (have_flag(flgs, TR_MAGIC_MASTERY)) value += (o_ptr->pval * 100L);
1241 if (have_flag(flgs, TR_STEALTH)) value += (o_ptr->pval * 100L);
1242 if (have_flag(flgs, TR_SEARCH)) value += (o_ptr->pval * 100L);
1244 /* Give credit for infra-vision and tunneling */
1245 if (have_flag(flgs, TR_INFRA)) value += (o_ptr->pval * 50L);
1246 if (have_flag(flgs, TR_TUNNEL)) value += (o_ptr->pval * 50L);
1248 /* Give credit for extra attacks */
1249 if (have_flag(flgs, TR_BLOWS)) value += (o_ptr->pval * 5000L);
1251 /* Give credit for speed bonus */
1252 if (have_flag(flgs, TR_SPEED)) value += (o_ptr->pval * 10000L);
1259 /* Analyze the item */
1260 switch (o_ptr->tval)
1265 /* Pay extra for charges, depending on standard number of
1266 * charges. Handle new-style wands correctly. -LM-
1268 value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
1275 /* Pay extra for charges, depending on standard number of
1278 value += (value * o_ptr->pval / (k_ptr->pval * 2));
1288 /* Hack -- negative bonuses are bad */
1289 if (o_ptr->to_a < 0) return (0L);
1290 if (o_ptr->to_h < 0) return (0L);
1291 if (o_ptr->to_d < 0) return (0L);
1293 /* Give credit for bonuses */
1294 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
1311 /* Hack -- negative armor bonus */
1312 if (o_ptr->to_a < 0) return (0L);
1314 /* Give credit for bonuses */
1315 value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
1328 /* Hack -- negative hit/damage bonuses */
1329 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1331 /* Factor in the bonuses */
1332 value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 100L);
1334 /* Hack -- Factor in extra damage dice and sides */
1335 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
1336 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
1347 /* Hack -- negative hit/damage bonuses */
1348 if (o_ptr->to_h + o_ptr->to_d < 0) return (0L);
1350 /* Factor in the bonuses */
1351 value += ((o_ptr->to_h + o_ptr->to_d) * 5L);
1353 /* Hack -- Factor in extra damage dice and sides */
1354 value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
1355 value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
1361 /* Figurines, relative to monster level */
1364 int level = r_info[o_ptr->pval].level;
1365 if (level < 20) value = level*50L;
1366 else if (level < 30) value = 1000+(level-20)*150L;
1367 else if (level < 40) value = 2500+(level-30)*350L;
1368 else if (level < 50) value = 6000+(level-40)*800L;
1369 else value = 14000+(level-50)*2000L;
1375 if (!o_ptr->pval) value = 1000L;
1376 else value = ((r_info[o_ptr->pval].level) * 50L + 1000);
1382 if (!o_ptr->pval) value = 0L;
1387 /* Return the value */
1393 * Return the price of an item including plusses (and charges)
1395 * This function returns the "value" of the given item (qty one)
1397 * Never notice "unknown" bonuses or properties, including "curses",
1398 * since that would give the player information he did not have.
1400 * Note that discounted items stay discounted forever, even if
1401 * the discount is "forgotten" by the player via memory loss.
1403 s32b object_value(object_type *o_ptr)
1408 /* Unknown items -- acquire a base value */
1409 if (object_known_p(o_ptr))
1411 /* Broken items -- worthless */
1412 if (broken_p(o_ptr)) return (0L);
1414 /* Cursed items -- worthless */
1415 if (cursed_p(o_ptr)) return (0L);
1417 /* Real value (see above) */
1418 value = object_value_real(o_ptr);
1421 /* Known items -- acquire the actual value */
1424 /* Hack -- Felt broken items */
1425 if ((o_ptr->ident & (IDENT_SENSE)) && broken_p(o_ptr)) return (0L);
1427 /* Hack -- Felt cursed items */
1428 if ((o_ptr->ident & (IDENT_SENSE)) && cursed_p(o_ptr)) return (0L);
1430 /* Base value (see above) */
1431 value = object_value_base(o_ptr);
1435 /* Apply discount (if any) */
1436 if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
1439 /* Return the final value */
1445 * Determines whether an object can be destroyed, and makes fake inscription.
1447 bool can_player_destroy_object(object_type *o_ptr)
1449 /* Artifacts cannot be destroyed */
1450 if (artifact_p(o_ptr) || o_ptr->art_name)
1452 byte feel = FEEL_SPECIAL;
1454 /* Hack -- Handle icky artifacts */
1455 if (cursed_p(o_ptr) || broken_p(o_ptr)) feel = FEEL_TERRIBLE;
1457 /* Hack -- inscribe the artifact */
1458 o_ptr->feeling = feel;
1460 /* We have "felt" it (again) */
1461 o_ptr->ident |= (IDENT_SENSE);
1463 /* Combine the pack */
1464 p_ptr->notice |= (PN_COMBINE);
1467 p_ptr->window |= (PW_INVEN | PW_EQUIP);
1478 * Distribute charges of rods or wands.
1480 * o_ptr = source item
1481 * q_ptr = target item, must be of the same type as o_ptr
1482 * amt = number of items that are transfered
1484 void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
1487 * Hack -- If rods or wands are dropped, the total maximum timeout or
1488 * charges need to be allocated between the two stacks. If all the items
1489 * are being dropped, it makes for a neater message to leave the original
1490 * stack's pval alone. -LM-
1492 if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD))
1494 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1495 if (amt < o_ptr->number) o_ptr->pval -= q_ptr->pval;
1497 /* Hack -- Rods also need to have their timeouts distributed. The
1498 * dropped stack will accept all time remaining to charge up to its
1501 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
1503 if (q_ptr->pval > o_ptr->timeout)
1504 q_ptr->timeout = o_ptr->timeout;
1506 q_ptr->timeout = q_ptr->pval;
1508 if (amt < o_ptr->number) o_ptr->timeout -= q_ptr->timeout;
1513 void reduce_charges(object_type *o_ptr, int amt)
1516 * Hack -- If rods or wand are destroyed, the total maximum timeout or
1517 * charges of the stack needs to be reduced, unless all the items are
1518 * being destroyed. -LM-
1520 if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD)) &&
1521 (amt < o_ptr->number))
1523 o_ptr->pval -= o_ptr->pval * amt / o_ptr->number;
1529 * Determine if an item can "absorb" a second item
1531 * See "object_absorb()" for the actual "absorption" code.
1533 * If permitted, we allow staffs (if they are known to have equal charges
1534 * and both are either known or confirmed empty) and wands (if both are
1535 * either known or confirmed empty) and rods (in all cases) to combine.
1536 * Staffs will unstack (if necessary) when they are used, but wands and
1537 * rods will only unstack if one is dropped. -LM-
1539 * If permitted, we allow weapons/armor to stack, if fully "known".
1541 * Missiles will combine if both stacks have the same "known" status.
1542 * This is done to make unidentified stacks of missiles useful.
1544 * Food, potions, scrolls, and "easy know" items always stack.
1546 * Chests, and activatable items, never stack (for various reasons).
1550 * Determine if an item can partly absorb a second item.
1552 static bool object_similar_part(object_type *o_ptr, object_type *j_ptr)
1556 /* Require identical object types */
1557 if (o_ptr->k_idx != j_ptr->k_idx) return (0);
1560 /* Analyze the items */
1561 switch (o_ptr->tval)
1563 /* Chests and Statues*/
1574 if ((o_ptr->sval != SV_PHOTO) || (j_ptr->sval != SV_PHOTO)) return (0);
1575 if (o_ptr->pval != j_ptr->pval) return (0);
1579 /* Figurines and Corpses*/
1584 if (o_ptr->pval != j_ptr->pval) return (0);
1590 /* Food and Potions and Scrolls */
1602 /* Require either knowledge or known empty for both staffs. */
1603 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1604 !object_known_p(o_ptr)) ||
1605 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1606 !object_known_p(j_ptr))) return(0);
1608 /* Require identical charges, since staffs are bulky. */
1609 if (o_ptr->pval != j_ptr->pval) return (0);
1618 /* Require either knowledge or known empty for both wands. */
1619 if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
1620 !object_known_p(o_ptr)) ||
1621 (!(j_ptr->ident & (IDENT_EMPTY)) &&
1622 !object_known_p(j_ptr))) return(0);
1624 /* Wand charges combine in O&ZAngband. */
1630 /* Staffs and Wands and Rods */
1637 /* Weapons and Armor */
1653 /* Require permission */
1654 if (!stack_allow_items) return (0);
1659 /* Rings, Amulets, Lites */
1664 /* Require full knowledge of both items */
1665 if (!object_known_p(o_ptr) || !object_known_p(j_ptr)) return (0);
1675 /* Require identical knowledge of both items */
1676 if (object_known_p(o_ptr) != object_known_p(j_ptr)) return (0);
1678 /* Require identical "bonuses" */
1679 if (o_ptr->to_h != j_ptr->to_h) return (FALSE);
1680 if (o_ptr->to_d != j_ptr->to_d) return (FALSE);
1681 if (o_ptr->to_a != j_ptr->to_a) return (FALSE);
1683 /* Require identical "pval" code */
1684 if (o_ptr->pval != j_ptr->pval) return (FALSE);
1686 /* Require identical "artifact" names */
1687 if (o_ptr->name1 != j_ptr->name1) return (FALSE);
1689 /* Random artifacts never stack */
1690 if (o_ptr->art_name || j_ptr->art_name) return (FALSE);
1692 /* Require identical "ego-item" names */
1693 if (o_ptr->name2 != j_ptr->name2) return (FALSE);
1695 /* Require identical added essence */
1696 if (o_ptr->xtra3 != j_ptr->xtra3) return (FALSE);
1697 if (o_ptr->xtra4 != j_ptr->xtra4) return (FALSE);
1699 /* Hack -- Never stack "powerful" items */
1700 if (o_ptr->xtra1 || j_ptr->xtra1) return (FALSE);
1702 /* Hack -- Never stack recharging items */
1703 if (o_ptr->timeout || j_ptr->timeout) return (FALSE);
1705 /* Require identical "values" */
1706 if (o_ptr->ac != j_ptr->ac) return (FALSE);
1707 if (o_ptr->dd != j_ptr->dd) return (FALSE);
1708 if (o_ptr->ds != j_ptr->ds) return (FALSE);
1717 /* Require knowledge */
1718 if (!object_known_p(o_ptr) || !object_known_p(j_ptr)) return (0);
1726 /* Hack -- Identical art_flags! */
1727 for (i = 0; i < TR_FLAG_SIZE; i++)
1728 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return (0);
1730 /* Hack -- Require identical "cursed" status */
1731 if (o_ptr->curse_flags != j_ptr->curse_flags) return (0);
1733 /* Hack -- Require identical "broken" status */
1734 if ((o_ptr->ident & (IDENT_BROKEN)) != (j_ptr->ident & (IDENT_BROKEN))) return (0);
1737 /* Hack -- require semi-matching "inscriptions" */
1738 if (o_ptr->inscription && j_ptr->inscription &&
1739 (o_ptr->inscription != j_ptr->inscription))
1742 /* Hack -- normally require matching "inscriptions" */
1743 if (!stack_force_notes && (o_ptr->inscription != j_ptr->inscription)) return (0);
1745 /* Hack -- normally require matching "discounts" */
1746 if (!stack_force_costs && (o_ptr->discount != j_ptr->discount)) return (0);
1749 /* They match, so they must be similar */
1754 * Determine if an item can absorb a second item.
1756 bool object_similar(object_type *o_ptr, object_type *j_ptr)
1758 int total = o_ptr->number + j_ptr->number;
1760 if (!object_similar_part(o_ptr, j_ptr))
1763 /* Maximal "stacking" limit */
1764 if (total >= MAX_STACK_SIZE) return (0);
1767 /* They match, so they must be similar */
1774 * Allow one item to "absorb" another, assuming they are similar
1776 void object_absorb(object_type *o_ptr, object_type *j_ptr)
1778 int total = o_ptr->number + j_ptr->number;
1780 /* Add together the item counts */
1781 o_ptr->number = ((total < MAX_STACK_SIZE) ? total : (MAX_STACK_SIZE - 1));
1783 /* Hack -- blend "known" status */
1784 if (object_known_p(j_ptr)) object_known(o_ptr);
1786 /* Hack -- clear "storebought" if only one has it */
1787 if (((o_ptr->ident & IDENT_STOREB) || (j_ptr->ident & IDENT_STOREB)) &&
1788 (!((o_ptr->ident & IDENT_STOREB) && (j_ptr->ident & IDENT_STOREB))))
1790 if (j_ptr->ident & IDENT_STOREB) j_ptr->ident &= 0xEF;
1791 if (o_ptr->ident & IDENT_STOREB) o_ptr->ident &= 0xEF;
1794 /* Hack -- blend "mental" status */
1795 if (j_ptr->ident & (IDENT_MENTAL)) o_ptr->ident |= (IDENT_MENTAL);
1797 /* Hack -- blend "inscriptions" */
1798 if (j_ptr->inscription) o_ptr->inscription = j_ptr->inscription;
1800 /* Hack -- blend "feelings" */
1801 if (j_ptr->feeling) o_ptr->feeling = j_ptr->feeling;
1803 /* Hack -- could average discounts XXX XXX XXX */
1804 /* Hack -- save largest discount XXX XXX XXX */
1805 if (o_ptr->discount < j_ptr->discount) o_ptr->discount = j_ptr->discount;
1807 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1808 if (o_ptr->tval == TV_ROD)
1810 o_ptr->pval += j_ptr->pval;
1811 o_ptr->timeout += j_ptr->timeout;
1814 /* Hack -- if wands are stacking, combine the charges. -LM- */
1815 if (o_ptr->tval == TV_WAND)
1817 o_ptr->pval += j_ptr->pval;
1823 * Find the index of the object_kind with the given tval and sval
1825 s16b lookup_kind(int tval, int sval)
1832 for (k = 1; k < max_k_idx; k++)
1834 object_kind *k_ptr = &k_info[k];
1836 /* Require correct tval */
1837 if (k_ptr->tval != tval) continue;
1840 if (k_ptr->sval == sval) return (k);
1842 /* Ignore illegal items */
1843 if (sval != SV_ANY) continue;
1845 /* Apply the randomizer */
1846 if (!one_in_(++num)) continue;
1848 /* Use this value */
1852 /* Return this choice */
1861 msg_format("¥¢¥¤¥Æ¥à¤¬¤Ê¤¤ (%d,%d)", tval, sval);
1863 msg_format("No object (%d,%d)", tval, sval);
1874 * Wipe an object clean.
1876 void object_wipe(object_type *o_ptr)
1878 /* Wipe the structure */
1879 (void)WIPE(o_ptr, object_type);
1884 * Prepare an object based on an existing object
1886 void object_copy(object_type *o_ptr, object_type *j_ptr)
1888 /* Copy the structure */
1889 COPY(o_ptr, j_ptr, object_type);
1894 * Prepare an object based on an object kind.
1896 void object_prep(object_type *o_ptr, int k_idx)
1898 object_kind *k_ptr = &k_info[k_idx];
1900 /* Clear the record */
1903 /* Save the kind index */
1904 o_ptr->k_idx = k_idx;
1906 /* Efficiency -- tval/sval */
1907 o_ptr->tval = k_ptr->tval;
1908 o_ptr->sval = k_ptr->sval;
1910 /* Default "pval" */
1911 o_ptr->pval = k_ptr->pval;
1913 /* Default number */
1916 /* Default weight */
1917 o_ptr->weight = k_ptr->weight;
1920 o_ptr->to_h = k_ptr->to_h;
1921 o_ptr->to_d = k_ptr->to_d;
1922 o_ptr->to_a = k_ptr->to_a;
1925 o_ptr->ac = k_ptr->ac;
1926 o_ptr->dd = k_ptr->dd;
1927 o_ptr->ds = k_ptr->ds;
1929 /* Hack -- worthless items are always "broken" */
1930 if (get_object_cost(o_ptr) <= 0) o_ptr->ident |= (IDENT_BROKEN);
1932 /* Hack -- cursed items are always "cursed" */
1933 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
1934 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
1935 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
1936 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
1937 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
1938 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
1943 * Help determine an "enchantment bonus" for an object.
1945 * To avoid floating point but still provide a smooth distribution of bonuses,
1946 * we simply round the results of division in such a way as to "average" the
1947 * correct floating point value.
1949 * This function has been changed. It uses "randnor()" to choose values from
1950 * a normal distribution, whose mean moves from zero towards the max as the
1951 * level increases, and whose standard deviation is equal to 1/4 of the max,
1952 * and whose values are forced to lie between zero and the max, inclusive.
1954 * Since the "level" rarely passes 100 before Morgoth is dead, it is very
1955 * rare to get the "full" enchantment on an object, even a deep levels.
1957 * It is always possible (albeit unlikely) to get the "full" enchantment.
1959 * A sample distribution of values from "m_bonus(10, N)" is shown below:
1961 * N 0 1 2 3 4 5 6 7 8 9 10
1962 * --- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
1963 * 0 66.37 13.01 9.73 5.47 2.89 1.31 0.72 0.26 0.12 0.09 0.03
1964 * 8 46.85 24.66 12.13 8.13 4.20 2.30 1.05 0.36 0.19 0.08 0.05
1965 * 16 30.12 27.62 18.52 10.52 6.34 3.52 1.95 0.90 0.31 0.15 0.05
1966 * 24 22.44 15.62 30.14 12.92 8.55 5.30 2.39 1.63 0.62 0.28 0.11
1967 * 32 16.23 11.43 23.01 22.31 11.19 7.18 4.46 2.13 1.20 0.45 0.41
1968 * 40 10.76 8.91 12.80 29.51 16.00 9.69 5.90 3.43 1.47 0.88 0.65
1969 * 48 7.28 6.81 10.51 18.27 27.57 11.76 7.85 4.99 2.80 1.22 0.94
1970 * 56 4.41 4.73 8.52 11.96 24.94 19.78 11.06 7.18 3.68 1.96 1.78
1971 * 64 2.81 3.07 5.65 9.17 13.01 31.57 13.70 9.30 6.04 3.04 2.64
1972 * 72 1.87 1.99 3.68 7.15 10.56 20.24 25.78 12.17 7.52 4.42 4.62
1973 * 80 1.02 1.23 2.78 4.75 8.37 12.04 27.61 18.07 10.28 6.52 7.33
1974 * 88 0.70 0.57 1.56 3.12 6.34 10.06 15.76 30.46 12.58 8.47 10.38
1975 * 96 0.27 0.60 1.25 2.28 4.30 7.60 10.77 22.52 22.51 11.37 16.53
1976 * 104 0.22 0.42 0.77 1.36 2.62 5.33 8.93 13.05 29.54 15.23 22.53
1977 * 112 0.15 0.20 0.56 0.87 2.00 3.83 6.86 10.06 17.89 27.31 30.27
1978 * 120 0.03 0.11 0.31 0.46 1.31 2.48 4.60 7.78 11.67 25.53 45.72
1979 * 128 0.02 0.01 0.13 0.33 0.83 1.41 3.24 6.17 9.57 14.22 64.07
1981 s16b m_bonus(int max, int level)
1983 int bonus, stand, extra, value;
1986 /* Paranoia -- enforce maximal "level" */
1987 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1990 /* The "bonus" moves towards the max */
1991 bonus = ((max * level) / MAX_DEPTH);
1993 /* Hack -- determine fraction of error */
1994 extra = ((max * level) % MAX_DEPTH);
1996 /* Hack -- simulate floating point computations */
1997 if (randint0(MAX_DEPTH) < extra) bonus++;
2000 /* The "stand" is equal to one quarter of the max */
2003 /* Hack -- determine fraction of error */
2006 /* Hack -- simulate floating point computations */
2007 if (randint0(4) < extra) stand++;
2010 /* Choose an "interesting" value */
2011 value = randnor(bonus, stand);
2013 /* Enforce the minimum value */
2014 if (value < 0) return (0);
2016 /* Enforce the maximum value */
2017 if (value > max) return (max);
2025 * Cheat -- describe a created object for the user
2027 static void object_mention(object_type *o_ptr)
2029 char o_name[MAX_NLEN];
2032 object_desc_store(o_name, o_ptr, FALSE, 0);
2035 if (artifact_p(o_ptr))
2039 msg_format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à (%s)", o_name);
2041 msg_format("Artifact (%s)", o_name);
2046 /* Random Artifact */
2047 else if (o_ptr->art_name)
2050 msg_print("¥é¥ó¥À¥à¡¦¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È");
2052 msg_print("Random artifact");
2058 else if (ego_item_p(o_ptr))
2062 msg_format("̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à (%s)", o_name);
2064 msg_format("Ego-item (%s)", o_name);
2074 msg_format("¥¢¥¤¥Æ¥à (%s)", o_name);
2076 msg_format("Object (%s)", o_name);
2084 * Mega-Hack -- Attempt to create one of the "Special Objects"
2086 * We are only called from "make_object()", and we assume that
2087 * "apply_magic()" is called immediately after we return.
2089 * Note -- see "make_artifact()" and "apply_magic()"
2091 static bool make_artifact_special(object_type *o_ptr)
2097 /* No artifacts in the town */
2098 if (!dun_level) return (FALSE);
2101 if (get_obj_num_hook) return (FALSE);
2103 /* Check the artifact list (just the "specials") */
2104 for (i = 0; i < max_a_idx; i++)
2106 artifact_type *a_ptr = &a_info[i];
2108 /* Skip "empty" artifacts */
2109 if (!a_ptr->name) continue;
2111 /* Cannot make an artifact twice */
2112 if (a_ptr->cur_num) continue;
2114 if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
2115 if (!(a_ptr->gen_flags & TRG_INSTA_ART)) continue;
2117 /* XXX XXX Enforce minimum "depth" (loosely) */
2118 if (a_ptr->level > dun_level)
2120 /* Acquire the "out-of-depth factor" */
2121 int d = (a_ptr->level - dun_level) * 2;
2123 /* Roll for out-of-depth creation */
2124 if (!one_in_(d)) continue;
2127 /* Artifact "rarity roll" */
2128 if (!one_in_(a_ptr->rarity)) continue;
2130 /* Find the base object */
2131 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
2133 /* XXX XXX Enforce minimum "object" level (loosely) */
2134 if (k_info[k_idx].level > object_level)
2136 /* Acquire the "out-of-depth factor" */
2137 int d = (k_info[k_idx].level - object_level) * 5;
2139 /* Roll for out-of-depth creation */
2140 if (!one_in_(d)) continue;
2143 /* Assign the template */
2144 object_prep(o_ptr, k_idx);
2146 /* Mega-Hack -- mark the item as an artifact */
2149 /* Hack: Some artifacts get random extra powers */
2150 random_artifact_resistance(o_ptr, a_ptr);
2162 * Attempt to change an object into an artifact
2164 * This routine should only be called by "apply_magic()"
2166 * Note -- see "make_artifact_special()" and "apply_magic()"
2168 static bool make_artifact(object_type *o_ptr)
2173 /* No artifacts in the town */
2174 if (!dun_level) return (FALSE);
2176 /* Paranoia -- no "plural" artifacts */
2177 if (o_ptr->number != 1) return (FALSE);
2179 /* Check the artifact list (skip the "specials") */
2180 for (i = 0; i < max_a_idx; i++)
2182 artifact_type *a_ptr = &a_info[i];
2184 /* Skip "empty" items */
2185 if (!a_ptr->name) continue;
2187 /* Cannot make an artifact twice */
2188 if (a_ptr->cur_num) continue;
2190 if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
2192 if (a_ptr->gen_flags & TRG_INSTA_ART) continue;
2194 /* Must have the correct fields */
2195 if (a_ptr->tval != o_ptr->tval) continue;
2196 if (a_ptr->sval != o_ptr->sval) continue;
2198 /* XXX XXX Enforce minimum "depth" (loosely) */
2199 if (a_ptr->level > dun_level)
2201 /* Acquire the "out-of-depth factor" */
2202 int d = (a_ptr->level - dun_level) * 2;
2204 /* Roll for out-of-depth creation */
2205 if (!one_in_(d)) continue;
2208 /* We must make the "rarity roll" */
2209 if (!one_in_(a_ptr->rarity)) continue;
2211 /* Hack -- mark the item as an artifact */
2214 /* Hack: Some artifacts get random extra powers */
2215 random_artifact_resistance(o_ptr, a_ptr);
2227 * Choose random ego type
2229 static byte get_random_ego(byte slot, bool good, int level)
2232 ego_item_type *e_ptr;
2236 for (i = 1; i < max_e_idx; i++)
2240 if (e_ptr->slot == slot
2241 /* && level >= e_ptr->level */
2242 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
2245 total += (255 / e_ptr->rarity);
2249 value = randint1(total);
2251 for (i = 1; i < max_e_idx; i++)
2255 if (e_ptr->slot == slot
2256 /* && level >= e_ptr->level */
2257 && ((good && e_ptr->rating) || (!good && !e_ptr->rating)) )
2260 value -= (255 / e_ptr->rarity);
2261 if (value <= 0L) break;
2269 * Apply magic to an item known to be a "weapon"
2271 * Hack -- note special base damage dice boosting
2272 * Hack -- note special processing for weapon/digger
2273 * Hack -- note special rating boost for dragon scale mail
2275 static void a_m_aux_1(object_type *o_ptr, int level, int power)
2277 int tohit1 = randint1(5) + m_bonus(5, level);
2278 int todam1 = randint1(5) + m_bonus(5, level);
2280 int tohit2 = m_bonus(10, level);
2281 int todam2 = m_bonus(10, level);
2283 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
2285 tohit2 = (tohit2+1)/2;
2286 todam2 = (todam2+1)/2;
2293 o_ptr->to_h += tohit1;
2294 o_ptr->to_d += todam1;
2300 o_ptr->to_h += tohit2;
2301 o_ptr->to_d += todam2;
2309 o_ptr->to_h -= tohit1;
2310 o_ptr->to_d -= todam1;
2315 /* Penalize again */
2316 o_ptr->to_h -= tohit2;
2317 o_ptr->to_d -= todam2;
2320 /* Cursed (if "bad") */
2321 if (o_ptr->to_h + o_ptr->to_d < 0) o_ptr->curse_flags |= TRC_CURSED;
2324 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)) return;
2327 switch (o_ptr->tval)
2335 create_artifact(o_ptr, FALSE);
2337 /* Special Ego-item */
2338 o_ptr->name2 = EGO_DIGGING;
2342 else if (power < -1)
2344 /* Hack -- Horrible digging bonus */
2345 o_ptr->pval = 0 - (5 + randint1(5));
2351 /* Hack -- Reverse digging bonus */
2352 o_ptr->pval = 0 - (o_ptr->pval);
2368 create_artifact(o_ptr, FALSE);
2373 /* Roll for an ego-item */
2374 o_ptr->name2 = get_random_ego(INVEN_RARM, TRUE, level);
2375 if (o_ptr->name2 == EGO_SHARPNESS && o_ptr->tval != TV_SWORD)
2377 if (o_ptr->name2 == EGO_EARTHQUAKES && o_ptr->tval != TV_HAFTED)
2382 switch (o_ptr->name2)
2385 if (one_in_(4) && (level > 40))
2386 add_flag(o_ptr->art_flags, TR_BLOWS);
2390 add_flag(o_ptr->art_flags, TR_RES_POIS);
2392 add_flag(o_ptr->art_flags, TR_WARNING);
2394 case EGO_KILL_DRAGON:
2396 add_flag(o_ptr->art_flags, TR_RES_POIS);
2400 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2402 case EGO_SLAYING_WEAPON:
2403 if (one_in_(3)) /* double damage */
2411 while (one_in_(o_ptr->dd));
2417 while (one_in_(o_ptr->ds));
2422 add_flag(o_ptr->art_flags, TR_BRAND_POIS);
2424 if (o_ptr->tval == TV_SWORD && one_in_(3))
2426 add_flag(o_ptr->art_flags, TR_VORPAL);
2431 add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
2437 add_flag(o_ptr->art_flags, TR_HOLD_LIFE);
2439 add_flag(o_ptr->art_flags, TR_DEX);
2441 add_flag(o_ptr->art_flags, TR_RES_FEAR);
2444 o_ptr->pval = m_bonus(5, level) + 1;
2446 case EGO_EARTHQUAKES:
2447 if (one_in_(3) && (level > 60))
2448 add_flag(o_ptr->art_flags, TR_BLOWS);
2450 o_ptr->pval = m_bonus(3, level);
2454 add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
2458 if (!o_ptr->art_name)
2460 /* Hack -- Super-charge the damage dice */
2461 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2463 /* Hack -- Lower the damage dice */
2464 if (o_ptr->dd > 9) o_ptr->dd = 9;
2469 else if (power < -1)
2471 /* Roll for ego-item */
2472 if (randint0(MAX_DEPTH) < level)
2474 o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE, level);
2475 switch (o_ptr->name2)
2478 if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
2494 create_artifact(o_ptr, FALSE);
2497 o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE, level);
2511 o_ptr->name2 = get_random_ego(INVEN_AMMO, TRUE, level);
2513 switch (o_ptr->name2)
2515 case EGO_SLAYING_BOLT:
2520 /* Hack -- super-charge the damage dice */
2521 while (one_in_(10L * o_ptr->dd * o_ptr->ds)) o_ptr->dd++;
2523 /* Hack -- restrict the damage dice */
2524 if (o_ptr->dd > 9) o_ptr->dd = 9;
2528 else if (power < -1)
2530 /* Roll for ego-item */
2531 if (randint0(MAX_DEPTH) < level)
2533 o_ptr->name2 = get_random_ego(INVEN_AMMO, FALSE, level);
2543 static void dragon_resist(object_type * o_ptr)
2548 one_dragon_ele_resistance(o_ptr);
2550 one_high_resistance(o_ptr);
2556 static void add_esp_strong(object_type *o_ptr)
2558 switch (randint1(3))
2560 case 1: add_flag(o_ptr->art_flags, TR_ESP_EVIL); break;
2561 case 2: add_flag(o_ptr->art_flags, TR_ESP_NONLIVING); break;
2562 case 3: add_flag(o_ptr->art_flags, TR_TELEPATHY); break;
2567 static void add_esp_weak(object_type *o_ptr)
2570 int n = randint1(3);
2572 idx[0] = randint1(9);
2574 idx[1] = randint1(8);
2575 if (idx[1] >= idx[0]) idx[1]++;
2577 idx[2] = randint1(7);
2578 if (idx[2] >= idx[0]) idx[2]++;
2579 if (idx[2] >= idx[1]) idx[2]++;
2581 while (n--) switch (idx[n])
2583 case 1: add_flag(o_ptr->art_flags, TR_ESP_ANIMAL); break;
2584 case 2: add_flag(o_ptr->art_flags, TR_ESP_UNDEAD); break;
2585 case 3: add_flag(o_ptr->art_flags, TR_ESP_DEMON); break;
2586 case 4: add_flag(o_ptr->art_flags, TR_ESP_ORC); break;
2587 case 5: add_flag(o_ptr->art_flags, TR_ESP_TROLL); break;
2588 case 6: add_flag(o_ptr->art_flags, TR_ESP_GIANT); break;
2589 case 7: add_flag(o_ptr->art_flags, TR_ESP_DRAGON); break;
2590 case 8: add_flag(o_ptr->art_flags, TR_ESP_HUMAN); break;
2591 case 9: add_flag(o_ptr->art_flags, TR_ESP_GOOD); break;
2597 * Apply magic to an item known to be "armor"
2599 * Hack -- note special processing for crown/helm
2600 * Hack -- note special processing for robe of permanence
2602 static void a_m_aux_2(object_type *o_ptr, int level, int power)
2604 int toac1 = randint1(5) + m_bonus(5, level);
2606 int toac2 = m_bonus(10, level);
2612 o_ptr->to_a += toac1;
2618 o_ptr->to_a += toac2;
2626 o_ptr->to_a -= toac1;
2631 /* Penalize again */
2632 o_ptr->to_a -= toac2;
2635 /* Cursed (if "bad") */
2636 if (o_ptr->to_a < 0) o_ptr->curse_flags |= TRC_CURSED;
2641 switch (o_ptr->tval)
2648 create_artifact(o_ptr, FALSE);
2650 /* Mention the item */
2651 if (cheat_peek) object_mention(o_ptr);
2662 /* Hack -- Try for "Robes of the Magi" */
2663 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
2664 (o_ptr->sval == SV_ROBE) &&
2665 (randint0(100) < 15))
2669 o_ptr->name2 = EGO_YOIYAMI;
2670 o_ptr->k_idx = lookup_kind(TV_SOFT_ARMOR, SV_YOIYAMI_ROBE);
2671 o_ptr->sval = SV_YOIYAMI_ROBE;
2677 o_ptr->name2 = EGO_PERMANENCE;
2684 create_artifact(o_ptr, FALSE);
2690 bool okay_flag = TRUE;
2692 o_ptr->name2 = get_random_ego(INVEN_BODY, TRUE, level);
2694 switch (o_ptr->name2)
2696 case EGO_RESISTANCE:
2698 add_flag(o_ptr->art_flags, TR_RES_POIS);
2703 if (o_ptr->tval != TV_HARD_ARMOR)
2710 o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
2711 o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
2713 add_flag(o_ptr->art_flags, TR_CON);
2729 if (o_ptr->sval == SV_DRAGON_SHIELD)
2734 /* Mention the item */
2735 if (cheat_peek) object_mention(o_ptr);
2736 dragon_resist(o_ptr);
2737 if (!one_in_(3)) break;
2745 create_artifact(o_ptr, FALSE);
2748 o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE, level);
2750 switch (o_ptr->name2)
2753 if (!one_in_(3)) one_high_resistance(o_ptr);
2754 if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_POIS);
2756 case EGO_REFLECTION:
2757 if (o_ptr->sval == SV_SHIELD_OF_DEFLECTION)
2767 if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
2772 /* Mention the item */
2773 if (cheat_peek) object_mention(o_ptr);
2774 dragon_resist(o_ptr);
2775 if (!one_in_(3)) break;
2781 create_artifact(o_ptr, FALSE);
2784 o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE, level);
2788 else if (power < -1)
2790 o_ptr->name2 = get_random_ego(INVEN_HANDS, FALSE, level);
2798 if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
2803 /* Mention the item */
2804 if (cheat_peek) object_mention(o_ptr);
2805 dragon_resist(o_ptr);
2806 if (!one_in_(3)) break;
2813 create_artifact(o_ptr, FALSE);
2816 o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE, level);
2818 switch (o_ptr->name2)
2820 case EGO_SLOW_DESCENT:
2823 one_high_resistance(o_ptr);
2829 else if (power < -1)
2831 o_ptr->name2 = get_random_ego(INVEN_FEET, FALSE, level);
2844 create_artifact(o_ptr, FALSE);
2849 bool ok_flag = TRUE;
2850 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE, level);
2852 switch (o_ptr->name2)
2855 add_esp_strong(o_ptr);
2856 add_esp_weak(o_ptr);
2860 case EGO_REGENERATION:
2861 case EGO_LORDLINESS:
2866 if (one_in_(2)) add_esp_strong(o_ptr);
2867 else add_esp_weak(o_ptr);
2870 default:/* not existing crown (wisdom,lite, etc...) */
2874 break; /* while (1) */
2880 else if (power < -1)
2882 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE, level);
2890 if (o_ptr->sval == SV_DRAGON_HELM)
2895 /* Mention the item */
2896 if (cheat_peek) object_mention(o_ptr);
2897 dragon_resist(o_ptr);
2898 if (!one_in_(3)) break;
2906 create_artifact(o_ptr, FALSE);
2911 bool ok_flag = TRUE;
2912 o_ptr->name2 = get_random_ego(INVEN_HEAD, TRUE, level);
2914 switch (o_ptr->name2)
2916 case EGO_INTELLIGENCE:
2920 case EGO_INFRAVISION:
2923 if (one_in_(7)) add_flag(o_ptr->art_flags, TR_TELEPATHY);
2925 default:/* not existing helm (Magi, Might, etc...)*/
2929 break; /* while (1) */
2934 else if (power < -1)
2936 o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE, level);
2948 create_artifact(o_ptr, FALSE);
2951 o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE, level);
2953 switch (o_ptr->name2)
2964 else if (power < -1)
2966 o_ptr->name2 = get_random_ego(INVEN_OUTER, FALSE, level);
2976 * Apply magic to an item known to be a "ring" or "amulet"
2978 * Hack -- note special rating boost for ring of speed
2979 * Hack -- note special rating boost for amulet of the magi
2980 * Hack -- note special "pval boost" code for ring of speed
2981 * Hack -- note that some items must be cursed (or blessed)
2983 static void a_m_aux_3(object_type *o_ptr, int level, int power)
2985 /* Apply magic (good or bad) according to type */
2986 switch (o_ptr->tval)
2991 switch (o_ptr->sval)
2993 case SV_RING_ATTACKS:
2996 o_ptr->pval = m_bonus(2, level);
2997 if (one_in_(15)) o_ptr->pval++;
2998 if (o_ptr->pval < 1) o_ptr->pval = 1;
3004 o_ptr->ident |= (IDENT_BROKEN);
3007 o_ptr->curse_flags |= TRC_CURSED;
3010 o_ptr->pval = 0 - (o_ptr->pval);
3021 /* Strength, Constitution, Dexterity, Intelligence */
3027 o_ptr->pval = 1 + m_bonus(5, level);
3033 o_ptr->ident |= (IDENT_BROKEN);
3036 o_ptr->curse_flags |= TRC_CURSED;
3039 o_ptr->pval = 0 - (o_ptr->pval);
3045 /* Ring of Speed! */
3048 /* Base speed (1 to 10) */
3049 o_ptr->pval = randint1(5) + m_bonus(5, level);
3051 /* Super-charge the ring */
3052 while (randint0(100) < 50) o_ptr->pval++;
3058 o_ptr->ident |= (IDENT_BROKEN);
3061 o_ptr->curse_flags |= TRC_CURSED;
3064 o_ptr->pval = 0 - (o_ptr->pval);
3072 /* Mention the item */
3073 if (cheat_peek) object_mention(o_ptr);
3078 case SV_RING_LORDLY:
3082 one_lordly_high_resistance(o_ptr);
3086 /* Bonus to armor class */
3087 o_ptr->to_a = 10 + randint1(5) + m_bonus(10, level);
3093 case SV_RING_SEARCHING:
3095 /* Bonus to searching */
3096 o_ptr->pval = 1 + m_bonus(5, level);
3102 o_ptr->ident |= (IDENT_BROKEN);
3105 o_ptr->curse_flags |= TRC_CURSED;
3108 o_ptr->pval = 0 - (o_ptr->pval);
3114 /* Flames, Acid, Ice */
3115 case SV_RING_FLAMES:
3120 /* Bonus to armor class */
3121 o_ptr->to_a = 5 + randint1(5) + m_bonus(10, level);
3125 /* Weakness, Stupidity */
3126 case SV_RING_WEAKNESS:
3127 case SV_RING_STUPIDITY:
3130 o_ptr->ident |= (IDENT_BROKEN);
3133 o_ptr->curse_flags |= TRC_CURSED;
3136 o_ptr->pval = 0 - (1 + m_bonus(5, level));
3137 if (power > 0) power = 0 - power;
3142 /* WOE, Stupidity */
3146 o_ptr->ident |= (IDENT_BROKEN);
3149 o_ptr->curse_flags |= TRC_CURSED;
3152 o_ptr->to_a = 0 - (5 + m_bonus(10, level));
3153 o_ptr->pval = 0 - (1 + m_bonus(5, level));
3154 if (power > 0) power = 0 - power;
3159 /* Ring of damage */
3160 case SV_RING_DAMAGE:
3162 /* Bonus to damage */
3163 o_ptr->to_d = 1 + randint1(5) + m_bonus(16, level);
3169 o_ptr->ident |= (IDENT_BROKEN);
3172 o_ptr->curse_flags |= TRC_CURSED;
3175 o_ptr->to_d = 0 - o_ptr->to_d;
3181 /* Ring of Accuracy */
3182 case SV_RING_ACCURACY:
3185 o_ptr->to_h = 1 + randint1(5) + m_bonus(16, level);
3191 o_ptr->ident |= (IDENT_BROKEN);
3194 o_ptr->curse_flags |= TRC_CURSED;
3197 o_ptr->to_h = 0 - o_ptr->to_h;
3203 /* Ring of Protection */
3204 case SV_RING_PROTECTION:
3206 /* Bonus to armor class */
3207 o_ptr->to_a = 5 + randint1(8) + m_bonus(10, level);
3213 o_ptr->ident |= (IDENT_BROKEN);
3216 o_ptr->curse_flags |= TRC_CURSED;
3219 o_ptr->to_a = 0 - o_ptr->to_a;
3225 /* Ring of Slaying */
3226 case SV_RING_SLAYING:
3228 /* Bonus to damage and to hit */
3229 o_ptr->to_d = randint1(5) + m_bonus(12, level);
3230 o_ptr->to_h = randint1(5) + m_bonus(12, level);
3236 o_ptr->ident |= (IDENT_BROKEN);
3239 o_ptr->curse_flags |= TRC_CURSED;
3241 /* Reverse bonuses */
3242 o_ptr->to_h = 0 - o_ptr->to_h;
3243 o_ptr->to_d = 0 - o_ptr->to_d;
3249 case SV_RING_MUSCLE:
3251 o_ptr->pval = 1 + m_bonus(3, level);
3252 if (one_in_(4)) o_ptr->pval++;
3258 o_ptr->ident |= (IDENT_BROKEN);
3261 o_ptr->curse_flags |= TRC_CURSED;
3263 /* Reverse bonuses */
3264 o_ptr->pval = 0 - o_ptr->pval;
3269 case SV_RING_AGGRAVATION:
3272 o_ptr->ident |= (IDENT_BROKEN);
3275 o_ptr->curse_flags |= TRC_CURSED;
3277 if (power > 0) power = 0 - power;
3281 if (one_in_(400) && (power > 0) && !cursed_p(o_ptr) && (level > 79))
3283 o_ptr->pval = MIN(o_ptr->pval,4);
3284 /* Randart amulet */
3285 create_artifact(o_ptr, FALSE);
3287 else if ((power == 2) && one_in_(2))
3289 while(!o_ptr->name2)
3291 int tmp = m_bonus(10, level);
3292 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3293 switch(randint1(28))
3296 o_ptr->name2 = EGO_RING_THROW;
3299 if (have_flag(k_ptr->flags, TR_REGEN)) break;
3300 o_ptr->name2 = EGO_RING_REGEN;
3303 if (have_flag(k_ptr->flags, TR_LITE)) break;
3304 o_ptr->name2 = EGO_RING_LITE;
3307 if (have_flag(k_ptr->flags, TR_TELEPORT)) break;
3308 o_ptr->name2 = EGO_RING_TELEPORT;
3311 if (o_ptr->to_h) break;
3312 o_ptr->name2 = EGO_RING_TO_H;
3315 if (o_ptr->to_d) break;
3316 o_ptr->name2 = EGO_RING_TO_D;
3319 if ((o_ptr->to_h) || (o_ptr->to_d)) break;
3320 o_ptr->name2 = EGO_RING_SLAY;
3323 if ((have_flag(k_ptr->flags, TR_STR)) || o_ptr->to_h || o_ptr->to_d) break;
3324 o_ptr->name2 = EGO_RING_WIZARD;
3327 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3328 o_ptr->name2 = EGO_RING_HERO;
3331 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3332 if (tmp > 8) o_ptr->name2 = EGO_RING_MANA_BALL;
3333 else if (tmp > 4) o_ptr->name2 = EGO_RING_MANA_BOLT;
3334 else o_ptr->name2 = EGO_RING_MAGIC_MIS;
3337 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3338 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;
3339 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_F;
3340 else if (tmp > 3) o_ptr->name2 = EGO_RING_FIRE_BALL;
3341 else o_ptr->name2 = EGO_RING_FIRE_BOLT;
3344 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3345 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;
3346 if (tmp > 7) o_ptr->name2 = EGO_RING_DRAGON_C;
3347 else if (tmp > 3) o_ptr->name2 = EGO_RING_COLD_BALL;
3348 else o_ptr->name2 = EGO_RING_COLD_BOLT;
3351 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3352 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;
3353 if (tmp > 4) o_ptr->name2 = EGO_RING_ELEC_BALL;
3354 else o_ptr->name2 = EGO_RING_ELEC_BOLT;
3357 if (have_flag(k_ptr->flags, TR_ACTIVATE)) break;
3358 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;
3359 if (tmp > 4) o_ptr->name2 = EGO_RING_ACID_BALL;
3360 else o_ptr->name2 = EGO_RING_ACID_BOLT;
3362 case 21: case 22: case 23: case 24: case 25: case 26:
3363 switch (o_ptr->sval)
3366 if (!one_in_(3)) break;
3367 o_ptr->name2 = EGO_RING_D_SPEED;
3369 case SV_RING_DAMAGE:
3370 case SV_RING_ACCURACY:
3371 case SV_RING_SLAYING:
3372 if (one_in_(2)) break;
3373 if (one_in_(2)) o_ptr->name2 = EGO_RING_HERO;
3376 o_ptr->name2 = EGO_RING_BERSERKER;
3377 o_ptr->to_h -= 2+randint1(4);
3380 case SV_RING_PROTECTION:
3381 o_ptr->name2 = EGO_RING_SUPER_AC;
3382 o_ptr->to_a += m_bonus(5, level);
3384 case SV_RING_RES_FEAR:
3385 o_ptr->name2 = EGO_RING_HERO;
3388 if (one_in_(2)) break;
3389 o_ptr->name2 = EGO_RING_HUNTER;
3391 case SV_RING_SEARCHING:
3392 o_ptr->name2 = EGO_RING_STEALTH;
3394 case SV_RING_TELEPORTATION:
3395 o_ptr->name2 = EGO_RING_TELE_AWAY;
3397 case SV_RING_RES_BLINDNESS:
3399 o_ptr->name2 = EGO_RING_RES_LITE;
3401 o_ptr->name2 = EGO_RING_RES_DARK;
3403 case SV_RING_LORDLY:
3404 if (!one_in_(20)) break;
3405 one_lordly_high_resistance(o_ptr);
3406 one_lordly_high_resistance(o_ptr);
3407 o_ptr->name2 = EGO_RING_TRUE;
3409 case SV_RING_SUSTAIN:
3410 if (!one_in_(4)) break;
3411 o_ptr->name2 = EGO_RING_RES_TIME;
3413 case SV_RING_FLAMES:
3414 if (!one_in_(2)) break;
3415 o_ptr->name2 = EGO_RING_DRAGON_F;
3418 if (!one_in_(2)) break;
3419 o_ptr->name2 = EGO_RING_DRAGON_C;
3421 case SV_RING_WARNING:
3422 if (!one_in_(2)) break;
3423 o_ptr->name2 = EGO_RING_M_DETECT;
3432 o_ptr->curse_flags = 0L;
3434 else if ((power == -2) && one_in_(2))
3436 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3437 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3438 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3439 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3440 o_ptr->art_flags[0] = 0;
3441 o_ptr->art_flags[1] = 0;
3442 while(!o_ptr->name2)
3444 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3448 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3449 o_ptr->name2 = EGO_RING_DRAIN_EXP;
3452 o_ptr->name2 = EGO_RING_NO_MELEE;
3455 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3456 o_ptr->name2 = EGO_RING_AGGRAVATE;
3459 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3460 o_ptr->name2 = EGO_RING_TY_CURSE;
3463 o_ptr->name2 = EGO_RING_ALBINO;
3468 o_ptr->ident |= (IDENT_BROKEN);
3471 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3479 switch (o_ptr->sval)
3481 /* Amulet of wisdom/charisma */
3482 case SV_AMULET_INTELLIGENCE:
3483 case SV_AMULET_WISDOM:
3484 case SV_AMULET_CHARISMA:
3486 o_ptr->pval = 1 + m_bonus(5, level);
3492 o_ptr->ident |= (IDENT_BROKEN);
3495 o_ptr->curse_flags |= (TRC_CURSED);
3497 /* Reverse bonuses */
3498 o_ptr->pval = 0 - o_ptr->pval;
3504 /* Amulet of brilliance */
3505 case SV_AMULET_BRILLIANCE:
3507 o_ptr->pval = 1 + m_bonus(3, level);
3508 if (one_in_(4)) o_ptr->pval++;
3514 o_ptr->ident |= (IDENT_BROKEN);
3517 o_ptr->curse_flags |= (TRC_CURSED);
3519 /* Reverse bonuses */
3520 o_ptr->pval = 0 - o_ptr->pval;
3526 case SV_AMULET_NO_MAGIC: case SV_AMULET_NO_TELE:
3530 o_ptr->curse_flags |= (TRC_CURSED);
3535 case SV_AMULET_RESISTANCE:
3537 if (one_in_(5)) one_high_resistance(o_ptr);
3538 if (one_in_(5)) add_flag(o_ptr->art_flags, TR_RES_POIS);
3542 /* Amulet of searching */
3543 case SV_AMULET_SEARCHING:
3545 o_ptr->pval = randint1(2) + m_bonus(4, level);
3551 o_ptr->ident |= (IDENT_BROKEN);
3554 o_ptr->curse_flags |= (TRC_CURSED);
3556 /* Reverse bonuses */
3557 o_ptr->pval = 0 - (o_ptr->pval);
3563 /* Amulet of the Magi -- never cursed */
3564 case SV_AMULET_THE_MAGI:
3566 o_ptr->pval = randint1(5) + m_bonus(5, level);
3567 o_ptr->to_a = randint1(5) + m_bonus(5, level);
3569 /* Boost the rating */
3572 /* Mention the item */
3573 if (cheat_peek) object_mention(o_ptr);
3578 /* Amulet of Doom -- always cursed */
3579 case SV_AMULET_DOOM:
3582 o_ptr->ident |= (IDENT_BROKEN);
3585 o_ptr->curse_flags |= (TRC_CURSED);
3588 o_ptr->pval = 0 - (randint1(5) + m_bonus(5, level));
3589 o_ptr->to_a = 0 - (randint1(5) + m_bonus(5, level));
3590 if (power > 0) power = 0 - power;
3595 case SV_AMULET_MAGIC_MASTERY:
3597 o_ptr->pval = 1 + m_bonus(4, level);
3603 o_ptr->ident |= (IDENT_BROKEN);
3606 o_ptr->curse_flags |= (TRC_CURSED);
3608 /* Reverse bonuses */
3609 o_ptr->pval = 0 - o_ptr->pval;
3615 if (one_in_(150) && (power > 0) && !cursed_p(o_ptr) && (level > 79))
3617 o_ptr->pval = MIN(o_ptr->pval,4);
3618 /* Randart amulet */
3619 create_artifact(o_ptr, FALSE);
3621 else if ((power == 2) && one_in_(2))
3623 while(!o_ptr->name2)
3625 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3626 switch(randint1(21))
3629 if (have_flag(k_ptr->flags, TR_SLOW_DIGEST)) break;
3630 o_ptr->name2 = EGO_AMU_SLOW_D;
3633 if (o_ptr->pval) break;
3634 o_ptr->name2 = EGO_AMU_INFRA;
3637 if (have_flag(k_ptr->flags, TR_SEE_INVIS)) break;
3638 o_ptr->name2 = EGO_AMU_SEE_INVIS;
3641 if (have_flag(k_ptr->flags, TR_HOLD_LIFE)) break;
3642 o_ptr->name2 = EGO_AMU_HOLD_LIFE;
3645 if (have_flag(k_ptr->flags, TR_FEATHER)) break;
3646 o_ptr->name2 = EGO_AMU_LEVITATION;
3648 case 10: case 11: case 21:
3649 o_ptr->name2 = EGO_AMU_AC;
3652 if (have_flag(k_ptr->flags, TR_RES_FIRE)) break;
3653 if (m_bonus(10, level) > 8)
3654 o_ptr->name2 = EGO_AMU_RES_FIRE_;
3656 o_ptr->name2 = EGO_AMU_RES_FIRE;
3659 if (have_flag(k_ptr->flags, TR_RES_COLD)) break;
3660 if (m_bonus(10, level) > 8)
3661 o_ptr->name2 = EGO_AMU_RES_COLD_;
3663 o_ptr->name2 = EGO_AMU_RES_COLD;
3666 if (have_flag(k_ptr->flags, TR_RES_ELEC)) break;
3667 if (m_bonus(10, level) > 8)
3668 o_ptr->name2 = EGO_AMU_RES_ELEC_;
3670 o_ptr->name2 = EGO_AMU_RES_ELEC;
3673 if (have_flag(k_ptr->flags, TR_RES_ACID)) break;
3674 if (m_bonus(10, level) > 8)
3675 o_ptr->name2 = EGO_AMU_RES_ACID_;
3677 o_ptr->name2 = EGO_AMU_RES_ACID;
3679 case 16: case 17: case 18: case 19: case 20:
3680 switch (o_ptr->sval)
3682 case SV_AMULET_TELEPORT:
3683 if (m_bonus(10, level) > 9) o_ptr->name2 = EGO_AMU_D_DOOR;
3684 else if (one_in_(2)) o_ptr->name2 = EGO_AMU_JUMP;
3685 else o_ptr->name2 = EGO_AMU_TELEPORT;
3687 case SV_AMULET_RESIST_ACID:
3688 if ((m_bonus(10, level) > 6) && one_in_(2)) o_ptr->name2 = EGO_AMU_RES_ACID_;
3690 case SV_AMULET_SEARCHING:
3691 o_ptr->name2 = EGO_AMU_STEALTH;
3693 case SV_AMULET_BRILLIANCE:
3694 if (!one_in_(3)) break;
3695 o_ptr->name2 = EGO_AMU_IDENT;
3697 case SV_AMULET_CHARISMA:
3698 if (!one_in_(3)) break;
3699 o_ptr->name2 = EGO_AMU_CHARM;
3701 case SV_AMULET_THE_MAGI:
3702 if (one_in_(2)) break;
3703 o_ptr->name2 = EGO_AMU_GREAT;
3705 case SV_AMULET_RESISTANCE:
3706 if (!one_in_(5)) break;
3707 o_ptr->name2 = EGO_AMU_DEFENDER;
3709 case SV_AMULET_TELEPATHY:
3710 if (!one_in_(3)) break;
3711 o_ptr->name2 = EGO_AMU_DETECTION;
3717 o_ptr->curse_flags = 0L;
3719 else if ((power == -2) && one_in_(2))
3721 if (o_ptr->to_h > 0) o_ptr->to_h = 0-o_ptr->to_h;
3722 if (o_ptr->to_d > 0) o_ptr->to_d = 0-o_ptr->to_d;
3723 if (o_ptr->to_a > 0) o_ptr->to_a = 0-o_ptr->to_a;
3724 if (o_ptr->pval > 0) o_ptr->pval = 0-o_ptr->pval;
3725 o_ptr->art_flags[0] = 0;
3726 o_ptr->art_flags[1] = 0;
3727 while(!o_ptr->name2)
3729 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3733 if (have_flag(k_ptr->flags, TR_DRAIN_EXP)) break;
3734 o_ptr->name2 = EGO_AMU_DRAIN_EXP;
3737 o_ptr->name2 = EGO_AMU_FOOL;
3740 if (have_flag(k_ptr->flags, TR_AGGRAVATE)) break;
3741 o_ptr->name2 = EGO_AMU_AGGRAVATE;
3744 if (have_flag(k_ptr->flags, TR_TY_CURSE)) break;
3745 o_ptr->name2 = EGO_AMU_TY_CURSE;
3748 o_ptr->name2 = EGO_AMU_NAIVETY;
3753 o_ptr->ident |= (IDENT_BROKEN);
3756 o_ptr->curse_flags |= (TRC_CURSED | TRC_HEAVY_CURSE);
3765 * Hack -- help pick an item type
3767 static bool item_monster_okay(int r_idx)
3769 monster_race *r_ptr = &r_info[r_idx];
3772 if (r_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3773 if (r_ptr->flags7 & RF7_KAGE) return (FALSE);
3774 if (r_ptr->flags3 & RF3_RES_ALL) return (FALSE);
3775 if (r_ptr->flags7 & RF7_UNIQUE_7) return (FALSE);
3776 if (r_ptr->flags1 & RF1_FORCE_DEPTH) return (FALSE);
3777 if (r_ptr->flags7 & RF7_UNIQUE2) return (FALSE);
3785 * Apply magic to an item known to be "boring"
3787 * Hack -- note the special code for various items
3789 static void a_m_aux_4(object_type *o_ptr, int level, int power)
3791 object_kind *k_ptr = &k_info[o_ptr->k_idx];
3793 /* Apply magic (good or bad) according to type */
3794 switch (o_ptr->tval)
3803 o_ptr->ident |= (IDENT_BROKEN);
3806 o_ptr->curse_flags |= (TRC_CURSED);
3813 o_ptr->xtra4 = o_ptr->pval;
3819 /* Hack -- Torches -- random fuel */
3820 if (o_ptr->sval == SV_LITE_TORCH)
3822 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3826 /* Hack -- Lanterns -- random fuel */
3827 if (o_ptr->sval == SV_LITE_LANTERN)
3829 if (o_ptr->pval > 0) o_ptr->xtra4 = randint1(o_ptr->pval);
3833 if ((power == 2) || ((power == 1) && one_in_(3)))
3835 while (!o_ptr->name2)
3839 bool okay_flag = TRUE;
3841 o_ptr->name2 = get_random_ego(INVEN_LITE, TRUE, level);
3843 switch (o_ptr->name2)
3846 if (o_ptr->sval == SV_LITE_FEANOR)
3854 else if (power == -2)
3856 o_ptr->name2 = get_random_ego(INVEN_LITE, FALSE, level);
3858 switch (o_ptr->name2)
3860 case EGO_LITE_DARKNESS:
3872 /* The wand or staff gets a number of initial charges equal
3873 * to between 1/2 (+1) and the full object kind's pval. -LM-
3875 o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
3881 /* Transfer the pval. -LM- */
3882 o_ptr->pval = k_ptr->pval;
3889 object_aware(o_ptr);
3890 object_known(o_ptr);
3899 monster_race *r_ptr;
3901 /* Pick a random non-unique monster race */
3904 i = randint1(max_r_idx - 1);
3906 if (!item_monster_okay(i)) continue;
3907 if (i == MON_TSUCHINOKO) continue;
3911 check = (dun_level < r_ptr->level) ? (r_ptr->level - dun_level) : 0;
3913 /* Ignore dead monsters */
3914 if (!r_ptr->rarity) continue;
3916 /* Prefer less out-of-depth monsters */
3917 if (randint0(check)) continue;
3924 /* Some figurines are cursed */
3925 if (one_in_(6)) o_ptr->curse_flags |= TRC_CURSED;
3930 msg_format("%s¤Î¿Í·Á, ¿¼¤µ +%d%s",
3932 msg_format("Figurine of %s, depth +%d%s",
3935 r_name + r_ptr->name, check - 1,
3936 !cursed_p(o_ptr) ? "" : " {cursed}");
3949 monster_race *r_ptr;
3951 if (o_ptr->sval == SV_SKELETON)
3953 match = RF9_DROP_SKELETON;
3955 else if (o_ptr->sval == SV_CORPSE)
3957 match = RF9_DROP_CORPSE;
3960 /* Hack -- Remove the monster restriction */
3961 get_mon_num_prep(item_monster_okay, NULL);
3963 /* Pick a random non-unique monster race */
3966 i = get_mon_num(dun_level);
3970 check = (dun_level < r_ptr->level) ? (r_ptr->level - dun_level) : 0;
3972 /* Ignore dead monsters */
3973 if (!r_ptr->rarity) continue;
3975 /* Ignore corpseless monsters */
3976 if (!(r_ptr->flags9 & match)) continue;
3978 /* Prefer less out-of-depth monsters */
3979 if (randint0(check)) continue;
3989 msg_format("%s¤Î»àÂÎ,¿¼¤µ +%d",
3991 msg_format("Corpse of %s, depth +%d",
3994 r_name + r_ptr->name, check - 1);
3997 object_aware(o_ptr);
3998 object_known(o_ptr);
4006 monster_race *r_ptr;
4008 /* Pick a random monster race */
4011 i = randint1(max_r_idx - 1);
4015 /* Ignore dead monsters */
4016 if (!r_ptr->rarity) continue;
4026 msg_format("%s¤ÎÁü,", r_name + r_ptr->name);
4028 msg_format("Statue of %s", r_name + r_ptr->name);
4032 object_aware(o_ptr);
4033 object_known(o_ptr);
4040 byte obj_level = get_object_level(o_ptr);
4042 /* Hack -- skip ruined chests */
4043 if (obj_level <= 0) break;
4045 /* Hack -- pick a "difficulty" */
4046 o_ptr->pval = randint1(obj_level);
4047 if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
4049 o_ptr->xtra3 = dun_level + 5;
4051 /* Never exceed "difficulty" of 55 to 59 */
4052 if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
4061 * Complete the "creation" of an object by applying "magic" to the item
4063 * This includes not only rolling for random bonuses, but also putting the
4064 * finishing touches on ego-items and artifacts, giving charges to wands and
4065 * staffs, giving fuel to lites, and placing traps on chests.
4067 * In particular, note that "Instant Artifacts", if "created" by an external
4068 * routine, must pass through this function to complete the actual creation.
4070 * The base "chance" of the item being "good" increases with the "level"
4071 * parameter, which is usually derived from the dungeon level, being equal
4072 * to the level plus 10, up to a maximum of 75. If "good" is true, then
4073 * the object is guaranteed to be "good". If an object is "good", then
4074 * the chance that the object will be "great" (ego-item or artifact), also
4075 * increases with the "level", being equal to half the level, plus 5, up to
4076 * a maximum of 20. If "great" is true, then the object is guaranteed to be
4077 * "great". At dungeon level 65 and below, 15/100 objects are "great".
4079 * If the object is not "good", there is a chance it will be "cursed", and
4080 * if it is "cursed", there is a chance it will be "broken". These chances
4081 * are related to the "good" / "great" chances above.
4083 * Otherwise "normal" rings and amulets will be "good" half the time and
4084 * "cursed" half the time, unless the ring/amulet is always good or cursed.
4086 * If "okay" is true, and the object is going to be "great", then there is
4087 * a chance that an artifact will be created. This is true even if both the
4088 * "good" and "great" arguments are false. As a total hack, if "great" is
4089 * true, then the item gets 3 extra "attempts" to become an artifact.
4091 void apply_magic(object_type *o_ptr, int lev, bool okay, bool good, bool great, bool curse)
4094 int i, rolls, f1, f2, power;
4096 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) lev += randint0(p_ptr->lev/2+10);
4098 /* Maximum "level" for various things */
4099 if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1;
4101 /* Base chance of being "good" */
4104 /* Maximal chance of being "good" */
4105 if (f1 > d_info[dungeon_type].obj_good) f1 = d_info[dungeon_type].obj_good;
4107 /* Base chance of being "great" */
4110 /* Maximal chance of being "great" */
4111 if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[dungeon_type].obj_great))
4112 f2 = d_info[dungeon_type].obj_great;
4114 if (p_ptr->muta3 & MUT3_GOOD_LUCK)
4119 else if(p_ptr->muta3 & MUT3_BAD_LUCK)
4128 /* Roll for "good" */
4129 if (good || magik(f1))
4134 /* Roll for "great" */
4135 if (great || magik(f2)) power = 2;
4138 /* Roll for "cursed" */
4141 /* Assume "cursed" */
4144 /* Roll for "broken" */
4145 if (magik(f2)) power = -2;
4151 /* Assume 'cursed' */
4156 /* Everything else gets more badly cursed */
4163 /* Assume no rolls */
4166 /* Get one roll if excellent */
4167 if (power >= 2) rolls = 1;
4169 /* Hack -- Get four rolls if forced great */
4170 if (great) rolls = 4;
4172 /* Hack -- Get no rolls if not allowed */
4173 if (!okay || o_ptr->name1) rolls = 0;
4175 /* Roll for artifacts if allowed */
4176 for (i = 0; i < rolls; i++)
4178 /* Roll for an artifact */
4179 if (make_artifact(o_ptr)) break;
4180 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && one_in_(77))
4182 if (make_artifact(o_ptr)) break;
4187 /* Hack -- analyze artifacts */
4190 artifact_type *a_ptr = &a_info[o_ptr->name1];
4192 /* Hack -- Mark the artifact as "created" */
4195 /* Extract the other fields */
4196 o_ptr->pval = a_ptr->pval;
4197 o_ptr->ac = a_ptr->ac;
4198 o_ptr->dd = a_ptr->dd;
4199 o_ptr->ds = a_ptr->ds;
4200 o_ptr->to_a = a_ptr->to_a;
4201 o_ptr->to_h = a_ptr->to_h;
4202 o_ptr->to_d = a_ptr->to_d;
4203 o_ptr->weight = a_ptr->weight;
4205 /* Hack -- extract the "broken" flag */
4206 if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4208 /* Hack -- extract the "cursed" flag */
4209 if (a_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4210 if (a_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4211 if (a_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4212 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4213 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4214 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4216 /* Mega-Hack -- increase the rating */
4219 /* Mega-Hack -- increase the rating again */
4220 if (a_ptr->cost > 50000L) rating += 10;
4222 /* Mega-Hack -- increase the rating again */
4223 if (a_ptr->cost > 100000L) rating += 10;
4225 /* Set the good item flag */
4226 good_item_flag = TRUE;
4228 /* Cheat -- peek at the item */
4229 if (cheat_peek) object_mention(o_ptr);
4237 switch (o_ptr->tval)
4246 if (power) a_m_aux_1(o_ptr, lev, power);
4252 if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) a_m_aux_1(o_ptr, lev, power);
4258 if (power && !(o_ptr->sval == SV_DOKUBARI)) a_m_aux_1(o_ptr, lev, power);
4272 /* Elven Cloak and Black Clothes ... */
4273 if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) ||
4274 ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
4275 o_ptr->pval = randint1(4);
4279 ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) ||
4280 ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD)) ||
4281 ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)) ||
4282 ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
4283 a_m_aux_2(o_ptr, lev, power);
4285 if (power) a_m_aux_2(o_ptr, lev, power);
4293 if (!power && (randint0(100) < 50)) power = -1;
4294 a_m_aux_3(o_ptr, lev, power);
4300 a_m_aux_4(o_ptr, lev, power);
4305 if ((o_ptr->tval == TV_SOFT_ARMOR) &&
4306 (o_ptr->sval == SV_ABUNAI_MIZUGI) &&
4307 (p_ptr->pseikaku == SEIKAKU_SEXY))
4310 add_flag(o_ptr->art_flags, TR_STR);
4311 add_flag(o_ptr->art_flags, TR_INT);
4312 add_flag(o_ptr->art_flags, TR_WIS);
4313 add_flag(o_ptr->art_flags, TR_DEX);
4314 add_flag(o_ptr->art_flags, TR_CON);
4315 add_flag(o_ptr->art_flags, TR_CHR);
4318 if (o_ptr->art_name) rating += 30;
4320 /* Hack -- analyze ego-items */
4321 else if (o_ptr->name2)
4323 ego_item_type *e_ptr = &e_info[o_ptr->name2];
4325 /* Hack -- acquire "broken" flag */
4326 if (!e_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
4328 /* Hack -- acquire "cursed" flag */
4329 if (e_ptr->gen_flags & TRG_CURSED) o_ptr->curse_flags |= (TRC_CURSED);
4330 if (e_ptr->gen_flags & TRG_HEAVY_CURSE) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
4331 if (e_ptr->gen_flags & TRG_PERMA_CURSE) o_ptr->curse_flags |= (TRC_PERMA_CURSE);
4332 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4333 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4334 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4336 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN)) one_sustain(o_ptr);
4337 if (e_ptr->gen_flags & (TRG_XTRA_POWER)) one_ability(o_ptr);
4338 if (e_ptr->gen_flags & (TRG_XTRA_H_RES)) one_high_resistance(o_ptr);
4339 if (e_ptr->gen_flags & (TRG_XTRA_E_RES)) one_ele_resistance(o_ptr);
4340 if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
4341 if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
4342 if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
4344 /* Hack -- apply extra penalties if needed */
4345 if (cursed_p(o_ptr) || broken_p(o_ptr))
4347 /* Hack -- obtain bonuses */
4348 if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
4349 if (e_ptr->max_to_d) o_ptr->to_d -= randint1(e_ptr->max_to_d);
4350 if (e_ptr->max_to_a) o_ptr->to_a -= randint1(e_ptr->max_to_a);
4352 /* Hack -- obtain pval */
4353 if (e_ptr->max_pval) o_ptr->pval -= randint1(e_ptr->max_pval);
4356 /* Hack -- apply extra bonuses if needed */
4359 /* Hack -- obtain bonuses */
4360 if (e_ptr->max_to_h)
4362 if (e_ptr->max_to_h > 127)
4363 o_ptr->to_h -= randint1(256-e_ptr->max_to_h);
4364 else o_ptr->to_h += randint1(e_ptr->max_to_h);
4366 if (e_ptr->max_to_d)
4368 if (e_ptr->max_to_d > 127)
4369 o_ptr->to_d -= randint1(256-e_ptr->max_to_d);
4370 else o_ptr->to_d += randint1(e_ptr->max_to_d);
4372 if (e_ptr->max_to_a)
4374 if (e_ptr->max_to_a > 127)
4375 o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
4376 else o_ptr->to_a += randint1(e_ptr->max_to_a);
4379 /* Hack -- obtain pval */
4380 if (e_ptr->max_pval)
4382 if ((o_ptr->name2 == EGO_HA) && (have_flag(o_ptr->art_flags, TR_BLOWS)))
4385 if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
4387 else if (o_ptr->name2 == EGO_ATTACKS)
4389 o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
4390 if (o_ptr->pval > 3) o_ptr->pval = 3;
4391 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
4392 o_ptr->pval += randint1(2);
4394 else if (o_ptr->name2 == EGO_BAT)
4396 o_ptr->pval = randint1(e_ptr->max_pval);
4397 if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
4401 o_ptr->pval += randint1(e_ptr->max_pval);
4404 if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
4406 o_ptr->pval = randint1(o_ptr->pval);
4408 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
4412 /* Hack -- apply rating bonus */
4413 rating += e_ptr->rating;
4415 /* Cheat -- describe the item */
4416 if (cheat_peek) object_mention(o_ptr);
4422 /* Examine real objects */
4425 object_kind *k_ptr = &k_info[o_ptr->k_idx];
4427 /* Hack -- acquire "broken" flag */
4428 if (!get_object_cost(o_ptr)) o_ptr->ident |= (IDENT_BROKEN);
4430 /* Hack -- acquire "cursed" flag */
4431 if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
4432 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
4433 if (k_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
4434 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0)) o_ptr->curse_flags |= get_curse(0, o_ptr);
4435 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
4436 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
4442 * Hack -- determine if a template is "good"
4444 static bool kind_is_good(int k_idx)
4446 object_kind *k_ptr = &k_info[k_idx];
4448 /* Analyze the item type */
4449 switch (k_ptr->tval)
4451 /* Armor -- Good unless damaged */
4462 if (k_ptr->to_a < 0) return (FALSE);
4466 /* Weapons -- Good unless damaged */
4473 if (k_ptr->to_h < 0) return (FALSE);
4474 if (k_ptr->to_d < 0) return (FALSE);
4478 /* Ammo -- Arrows/Bolts are good */
4485 /* Books -- High level books are good (except Arcane books) */
4487 case TV_SORCERY_BOOK:
4488 case TV_NATURE_BOOK:
4492 case TV_ENCHANT_BOOK:
4493 case TV_DAEMON_BOOK:
4494 case TV_CRUSADE_BOOK:
4496 case TV_HISSATSU_BOOK:
4498 if (k_ptr->sval >= SV_BOOK_MIN_GOOD) return (TRUE);
4502 /* Rings -- Rings of Speed are good */
4505 if (k_ptr->sval == SV_RING_SPEED) return (TRUE);
4506 if (k_ptr->sval == SV_RING_LORDLY) return (TRUE);
4510 /* Amulets -- Amulets of the Magi and Resistance are good */
4513 if (k_ptr->sval == SV_AMULET_THE_MAGI) return (TRUE);
4514 if (k_ptr->sval == SV_AMULET_RESISTANCE) return (TRUE);
4519 /* Assume not good */
4525 * Attempt to make an object (normal or good/great)
4527 * This routine plays nasty games to generate the "special artifacts".
4529 * This routine uses "object_level" for the "generation level".
4531 * We assume that the given object has been "wiped".
4533 bool make_object(object_type *j_ptr, bool good, bool great)
4539 /* Chance of "special object" */
4540 prob = (good ? 10 : 1000);
4542 /* Base level for the object */
4543 base = (good ? (object_level + 10) : object_level);
4546 /* Generate a special object, or a normal object */
4547 if (!one_in_(prob) || !make_artifact_special(j_ptr))
4554 /* Activate restriction */
4555 get_obj_num_hook = kind_is_good;
4557 /* Prepare allocation table */
4561 /* Pick a random object */
4562 k_idx = get_obj_num(base);
4565 if (get_obj_num_hook)
4567 /* Clear restriction */
4568 get_obj_num_hook = NULL;
4570 /* Prepare allocation table */
4574 /* Handle failure */
4575 if (!k_idx) return (FALSE);
4577 /* Prepare the object */
4578 object_prep(j_ptr, k_idx);
4581 /* Apply magic (allow artifacts) */
4582 apply_magic(j_ptr, object_level, TRUE, good, great, FALSE);
4584 /* Hack -- generate multiple spikes/missiles */
4585 switch (j_ptr->tval)
4593 j_ptr->number = (byte)damroll(6, 7);
4597 obj_level = get_object_level(j_ptr);
4598 if (artifact_p(j_ptr)) obj_level = a_info[j_ptr->name1].level;
4600 /* Notice "okay" out-of-depth objects */
4601 if (!cursed_p(j_ptr) && !broken_p(j_ptr) &&
4602 (obj_level > dun_level))
4604 /* Rating increase */
4605 rating += (obj_level - dun_level);
4607 /* Cheat -- peek at items */
4608 if (cheat_peek) object_mention(j_ptr);
4617 * Attempt to place an object (normal or good/great) at the given location.
4619 * This routine plays nasty games to generate the "special artifacts".
4621 * This routine uses "object_level" for the "generation level".
4623 * This routine requires a clean floor grid destination.
4625 void place_object(int y, int x, bool good, bool great)
4635 /* Paranoia -- check bounds */
4636 if (!in_bounds(y, x)) return;
4638 /* Require clean floor space */
4639 if (!cave_clean_bold(y, x)) return;
4642 /* Get local object */
4645 /* Wipe the object */
4648 /* Make an object (if possible) */
4649 if (!make_object(q_ptr, good, great)) return;
4652 /* Make an object */
4660 /* Acquire object */
4661 o_ptr = &o_list[o_idx];
4663 /* Structure Copy */
4664 object_copy(o_ptr, q_ptr);
4671 c_ptr = &cave[y][x];
4674 o_ptr->next_o_idx = c_ptr->o_idx;
4676 /* Place the object */
4677 c_ptr->o_idx = o_idx;
4687 /* Hack -- Preserve artifacts */
4690 a_info[q_ptr->name1].cur_num = 0;
4697 * Make a treasure object
4699 * The location must be a legal, clean, floor grid.
4701 bool make_gold(object_type *j_ptr)
4708 /* Hack -- Pick a Treasure variety */
4709 i = ((randint1(object_level + 2) + 2) / 2) - 1;
4711 /* Apply "extra" magic */
4712 if (one_in_(GREAT_OBJ))
4714 i += randint1(object_level + 1);
4717 /* Hack -- Creeping Coins only generate "themselves" */
4718 if (coin_type) i = coin_type;
4720 /* Do not create "illegal" Treasure Types */
4721 if (i >= MAX_GOLD) i = MAX_GOLD - 1;
4723 /* Prepare a gold object */
4724 object_prep(j_ptr, OBJ_GOLD_LIST + i);
4726 /* Hack -- Base coin cost */
4727 base = k_info[OBJ_GOLD_LIST+i].cost;
4729 /* Determine how much the treasure is "worth" */
4730 j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
4738 * Places a treasure (Gold or Gems) at given location
4740 * The location must be a legal, clean, floor grid.
4742 void place_gold(int y, int x)
4752 /* Paranoia -- check bounds */
4753 if (!in_bounds(y, x)) return;
4755 /* Require clean floor space */
4756 if (!cave_clean_bold(y, x)) return;
4759 /* Get local object */
4762 /* Wipe the object */
4765 /* Make some gold */
4766 if (!make_gold(q_ptr)) return;
4769 /* Make an object */
4777 /* Acquire object */
4778 o_ptr = &o_list[o_idx];
4780 /* Copy the object */
4781 object_copy(o_ptr, q_ptr);
4788 c_ptr = &cave[y][x];
4791 o_ptr->next_o_idx = c_ptr->o_idx;
4793 /* Place the object */
4794 c_ptr->o_idx = o_idx;
4806 * Let an object fall to the ground at or near a location.
4808 * The initial location is assumed to be "in_bounds()".
4810 * This function takes a parameter "chance". This is the percentage
4811 * chance that the item will "disappear" instead of drop. If the object
4812 * has been thrown, then this is the chance of disappearance on contact.
4814 * Hack -- this function uses "chance" to determine if it should produce
4815 * some form of "description" of the drop event (under the player).
4817 * We check several locations to see if we can find a location at which
4818 * the object can combine, stack, or be placed. Artifacts will try very
4819 * hard to be placed, including "teleporting" to a useful grid if needed.
4821 s16b drop_near(object_type *j_ptr, int chance, int y, int x)
4832 s16b this_o_idx, next_o_idx = 0;
4836 char o_name[MAX_NLEN];
4841 bool plural = FALSE;
4844 /* Extract plural */
4845 if (j_ptr->number != 1) plural = TRUE;
4847 /* Describe object */
4848 object_desc(o_name, j_ptr, FALSE, 0);
4851 /* Handle normal "breakage" */
4852 if (!(j_ptr->art_name || artifact_p(j_ptr)) && (randint0(100) < chance))
4856 msg_format("%s¤Ï¾Ã¤¨¤¿¡£", o_name);
4858 msg_format("The %s disappear%s.",
4859 o_name, (plural ? "" : "s"));
4865 if (p_ptr->wizard) msg_print("(ÇË»)");
4867 if (p_ptr->wizard) msg_print("(breakage)");
4886 /* Scan local grids */
4887 for (dy = -3; dy <= 3; dy++)
4889 /* Scan local grids */
4890 for (dx = -3; dx <= 3; dx++)
4894 /* Calculate actual distance */
4895 d = (dy * dy) + (dx * dx);
4897 /* Ignore distant grids */
4898 if (d > 10) continue;
4904 /* Skip illegal grids */
4905 if (!in_bounds(ty, tx)) continue;
4907 /* Require line of sight */
4908 if (!los(y, x, ty, tx)) continue;
4911 c_ptr = &cave[ty][tx];
4913 /* Require floor space */
4914 if ((c_ptr->feat != FEAT_FLOOR) &&
4915 (c_ptr->feat != FEAT_SHAL_WATER) &&
4916 (c_ptr->feat != FEAT_GRASS) &&
4917 (c_ptr->feat != FEAT_DIRT) &&
4918 (c_ptr->feat != FEAT_FLOWER) &&
4919 (c_ptr->feat != FEAT_DEEP_GRASS) &&
4920 (c_ptr->feat != FEAT_SHAL_LAVA) &&
4921 (c_ptr->feat != FEAT_TREES)) continue;
4922 if (c_ptr->info & (CAVE_TRAP | CAVE_IN_MIRROR)) continue;
4927 /* Scan objects in that grid */
4928 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4932 /* Acquire object */
4933 o_ptr = &o_list[this_o_idx];
4935 /* Acquire next object */
4936 next_o_idx = o_ptr->next_o_idx;
4938 /* Check for possible combination */
4939 if (object_similar(o_ptr, j_ptr)) comb = TRUE;
4945 /* Add new object */
4949 if (k > 99) continue;
4951 /* Calculate score */
4952 s = 1000 - (d + k * 5);
4954 /* Skip bad values */
4955 if (s < bs) continue;
4957 /* New best value */
4960 /* Apply the randomizer to equivalent values */
4961 if ((++bn >= 2) && !one_in_(bn)) continue;
4976 /* Handle lack of space */
4977 if (!flag && !(artifact_p(j_ptr) || j_ptr->art_name))
4981 msg_format("%s¤Ï¾Ã¤¨¤¿¡£", o_name);
4983 msg_format("The %s disappear%s.",
4984 o_name, (plural ? "" : "s"));
4990 if (p_ptr->wizard) msg_print("(¾²¥¹¥Ú¡¼¥¹¤¬¤Ê¤¤)");
4992 if (p_ptr->wizard) msg_print("(no floor space)");
5002 for (i = 0; !flag; i++)
5007 ty = rand_spread(by, 1);
5008 tx = rand_spread(bx, 1);
5011 /* Random locations */
5014 ty = randint0(cur_hgt);
5015 tx = randint0(cur_wid);
5019 c_ptr = &cave[ty][tx];
5021 /* Require floor space (or shallow terrain) -KMW- */
5022 if ((c_ptr->feat != FEAT_FLOOR) &&
5023 (c_ptr->feat != FEAT_SHAL_WATER) &&
5024 (c_ptr->feat != FEAT_GRASS) &&
5025 (c_ptr->feat != FEAT_DIRT) &&
5026 (c_ptr->feat != FEAT_SHAL_LAVA)) continue;
5028 /* Bounce to that location */
5032 /* Require floor space */
5033 if (!cave_clean_bold(by, bx)) continue;
5041 c_ptr = &cave[by][bx];
5043 /* Scan objects in that grid for combination */
5044 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
5048 /* Acquire object */
5049 o_ptr = &o_list[this_o_idx];
5051 /* Acquire next object */
5052 next_o_idx = o_ptr->next_o_idx;
5054 /* Check for combination */
5055 if (object_similar(o_ptr, j_ptr))
5057 /* Combine the items */
5058 object_absorb(o_ptr, j_ptr);
5068 /* Get new object */
5069 if (!done) o_idx = o_pop();
5072 if (!done && !o_idx)
5076 msg_format("%s¤Ï¾Ã¤¨¤¿¡£", o_name);
5078 msg_format("The %s disappear%s.",
5079 o_name, (plural ? "" : "s"));
5085 if (p_ptr->wizard) msg_print("(¥¢¥¤¥Æ¥à¤¬Â¿²á¤®¤ë)");
5087 if (p_ptr->wizard) msg_print("(too many objects)");
5091 /* Hack -- Preserve artifacts */
5094 a_info[j_ptr->name1].cur_num = 0;
5104 /* Structure copy */
5105 object_copy(&o_list[o_idx], j_ptr);
5107 /* Access new object */
5108 j_ptr = &o_list[o_idx];
5115 j_ptr->held_m_idx = 0;
5118 j_ptr->next_o_idx = c_ptr->o_idx;
5120 /* Place the object */
5121 c_ptr->o_idx = o_idx;
5136 /* Mega-Hack -- no message if "dropped" by player */
5137 /* Message when an object falls under the player */
5138 if (chance && (by == py) && (bx == px))
5141 msg_print("²¿¤«¤¬Â²¼¤Ëž¤¬¤Ã¤Æ¤¤¿¡£");
5143 msg_print("You feel something roll beneath your feet.");
5156 * Scatter some "great" objects near the player
5158 void acquirement(int y1, int x1, int num, bool great, bool known)
5161 object_type object_type_body;
5166 /* Get local object */
5167 i_ptr = &object_type_body;
5169 /* Wipe the object */
5172 /* Make a good (or great) object (if possible) */
5173 if (!make_object(i_ptr, TRUE, great)) continue;
5177 object_aware(i_ptr);
5178 object_known(i_ptr);
5181 /* Drop the object */
5182 (void)drop_near(i_ptr, -1, y1, x1);
5187 #define MAX_TRAPS 18
5189 static int trap_num[MAX_TRAPS] =
5193 FEAT_TRAP_SPIKED_PIT,
5194 FEAT_TRAP_POISON_PIT,
5213 * Hack -- instantiate a trap
5215 * XXX XXX XXX This routine should be redone to reflect trap "level".
5216 * That is, it does not make sense to have spiked pits at 50 feet.
5217 * Actually, it is not this routine, but the "trap instantiation"
5218 * code, which should also check for "trap doors" on quest levels.
5220 void pick_trap(int y, int x)
5224 cave_type *c_ptr = &cave[y][x];
5227 if (!(c_ptr->info & CAVE_TRAP)) return;
5228 c_ptr->info &= ~(CAVE_TRAP);
5233 /* Hack -- pick a trap */
5234 feat = trap_num[randint0(MAX_TRAPS)];
5236 /* Accept non-trapdoors */
5237 if (feat != FEAT_TRAP_TRAPDOOR) break;
5239 /* Hack -- no trap doors on special levels */
5240 if (p_ptr->inside_arena || quest_number(dun_level)) continue;
5242 /* Hack -- no trap doors on the deepest level */
5243 if (dun_level >= d_info[dungeon_type].maxdepth) continue;
5248 /* Activate the trap */
5249 cave_set_feat(y, x, feat);
5254 * Places a random trap at the given location.
5256 * The location must be a legal, naked, floor grid.
5258 * Note that all traps start out as "invisible" and "untyped", and then
5259 * when they are "discovered" (by detecting them or setting them off),
5260 * the trap is "instantiated" as a visible, "typed", trap.
5262 void place_trap(int y, int x)
5264 /* Paranoia -- verify location */
5265 if (!in_bounds(y, x)) return;
5267 /* Require empty, clean, floor grid */
5268 if (!cave_naked_bold(y, x)) return;
5270 /* Place an invisible trap */
5271 cave[y][x].info |= CAVE_TRAP;
5276 * Describe the charges on an item in the inventory.
5278 void inven_item_charges(int item)
5280 object_type *o_ptr = &inventory[item];
5282 /* Require staff/wand */
5283 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5285 /* Require known item */
5286 if (!object_known_p(o_ptr)) return;
5289 if (o_ptr->pval <= 0)
5291 msg_print("¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£");
5295 msg_format("¤¢¤È %d ²óʬ¤ÎËâÎϤ¬»Ä¤Ã¤Æ¤¤¤ë¡£", o_ptr->pval);
5298 /* Multiple charges */
5299 if (o_ptr->pval != 1)
5301 /* Print a message */
5302 msg_format("You have %d charges remaining.", o_ptr->pval);
5308 /* Print a message */
5309 msg_format("You have %d charge remaining.", o_ptr->pval);
5317 * Describe an item in the inventory.
5319 void inven_item_describe(int item)
5321 object_type *o_ptr = &inventory[item];
5322 char o_name[MAX_NLEN];
5324 /* Get a description */
5325 object_desc(o_name, o_ptr, TRUE, 3);
5327 /* Print a message */
5329 /* "no more" ¤Î¾ì¹ç¤Ï¤³¤Á¤é¤Çɽ¼¨¤¹¤ë */
5330 if (o_ptr->number <= 0)
5332 /*FIRST*//*¤³¤³¤Ï¤â¤¦Ä̤é¤Ê¤¤¤«¤â */
5333 msg_format("¤â¤¦%s¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£", o_name);
5337 /* ¥¢¥¤¥Æ¥à̾¤ò±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½Âбþ */
5338 msg_format("¤Þ¤À %s¤ò»ý¤Ã¤Æ¤¤¤ë¡£", o_name);
5341 msg_format("You have %s.", o_name);
5348 * Increase the "number" of an item in the inventory
5350 void inven_item_increase(int item, int num)
5352 object_type *o_ptr = &inventory[item];
5355 num += o_ptr->number;
5358 if (num > 255) num = 255;
5359 else if (num < 0) num = 0;
5362 num -= o_ptr->number;
5364 /* Change the number and weight */
5367 /* Add the number */
5368 o_ptr->number += num;
5370 /* Add the weight */
5371 p_ptr->total_weight += (num * o_ptr->weight);
5373 /* Recalculate bonuses */
5374 p_ptr->update |= (PU_BONUS);
5376 /* Recalculate mana XXX */
5377 p_ptr->update |= (PU_MANA);
5379 /* Combine the pack */
5380 p_ptr->notice |= (PN_COMBINE);
5383 p_ptr->window |= (PW_INVEN | PW_EQUIP);
5389 * Erase an inventory slot if it has no more items
5391 void inven_item_optimize(int item)
5393 object_type *o_ptr = &inventory[item];
5395 /* Only optimize real items */
5396 if (!o_ptr->k_idx) return;
5398 /* Only optimize empty items */
5399 if (o_ptr->number) return;
5401 /* The item is in the pack */
5402 if (item < INVEN_RARM)
5409 /* Slide everything down */
5410 for (i = item; i < INVEN_PACK; i++)
5412 /* Structure copy */
5413 inventory[i] = inventory[i+1];
5416 /* Erase the "final" slot */
5417 object_wipe(&inventory[i]);
5420 p_ptr->window |= (PW_INVEN);
5423 /* The item is being wielded */
5429 /* Erase the empty slot */
5430 object_wipe(&inventory[item]);
5432 /* Recalculate bonuses */
5433 p_ptr->update |= (PU_BONUS);
5435 /* Recalculate torch */
5436 p_ptr->update |= (PU_TORCH);
5438 /* Recalculate mana XXX */
5439 p_ptr->update |= (PU_MANA);
5442 p_ptr->window |= (PW_EQUIP);
5446 p_ptr->window |= (PW_SPELL);
5451 * Describe the charges on an item on the floor.
5453 void floor_item_charges(int item)
5455 object_type *o_ptr = &o_list[item];
5457 /* Require staff/wand */
5458 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
5460 /* Require known item */
5461 if (!object_known_p(o_ptr)) return;
5464 if (o_ptr->pval <= 0)
5466 msg_print("¤³¤Î¾²¾å¤Î¥¢¥¤¥Æ¥à¤Ï¡¢¤â¤¦ËâÎϤ¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£");
5470 msg_format("¤³¤Î¾²¾å¤Î¥¢¥¤¥Æ¥à¤Ï¡¢¤¢¤È %d ²óʬ¤ÎËâÎϤ¬»Ä¤Ã¤Æ¤¤¤ë¡£", o_ptr->pval);
5473 /* Multiple charges */
5474 if (o_ptr->pval != 1)
5476 /* Print a message */
5477 msg_format("There are %d charges remaining.", o_ptr->pval);
5483 /* Print a message */
5484 msg_format("There is %d charge remaining.", o_ptr->pval);
5492 * Describe an item in the inventory.
5494 void floor_item_describe(int item)
5496 object_type *o_ptr = &o_list[item];
5497 char o_name[MAX_NLEN];
5499 /* Get a description */
5500 object_desc(o_name, o_ptr, TRUE, 3);
5502 /* Print a message */
5504 /* "no more" ¤Î¾ì¹ç¤Ï¤³¤Á¤é¤Çɽ¼¨¤òʬ¤±¤ë */
5505 if (o_ptr->number <= 0)
5507 msg_format("¾²¾å¤Ë¤Ï¡¢¤â¤¦%s¤Ï¤Ê¤¤¡£", o_name);
5511 msg_format("¾²¾å¤Ë¤Ï¡¢¤Þ¤À %s¤¬¤¢¤ë¡£", o_name);
5514 msg_format("You see %s.", o_name);
5521 * Increase the "number" of an item on the floor
5523 void floor_item_increase(int item, int num)
5525 object_type *o_ptr = &o_list[item];
5528 num += o_ptr->number;
5531 if (num > 255) num = 255;
5532 else if (num < 0) num = 0;
5535 num -= o_ptr->number;
5537 /* Change the number */
5538 o_ptr->number += num;
5543 * Optimize an item on the floor (destroy "empty" items)
5545 void floor_item_optimize(int item)
5547 object_type *o_ptr = &o_list[item];
5549 /* Paranoia -- be sure it exists */
5550 if (!o_ptr->k_idx) return;
5552 /* Only optimize empty items */
5553 if (o_ptr->number) return;
5555 /* Delete the object */
5556 delete_object_idx(item);
5561 * Check if we have space for an item in the pack without overflow
5563 bool inven_carry_okay(object_type *o_ptr)
5568 if (inven_cnt < INVEN_PACK) return (TRUE);
5571 for (j = 0; j < INVEN_PACK; j++)
5573 object_type *j_ptr = &inventory[j];
5575 /* Skip non-objects */
5576 if (!j_ptr->k_idx) continue;
5578 /* Check if the two items can be combined */
5579 if (object_similar(j_ptr, o_ptr)) return (TRUE);
5588 * Add an item to the players inventory, and return the slot used.
5590 * If the new item can combine with an existing item in the inventory,
5591 * it will do so, using "object_similar()" and "object_absorb()", else,
5592 * the item will be placed into the "proper" location in the inventory.
5594 * This function can be used to "over-fill" the player's pack, but only
5595 * once, and such an action must trigger the "overflow" code immediately.
5596 * Note that when the pack is being "over-filled", the new item must be
5597 * placed into the "overflow" slot, and the "overflow" must take place
5598 * before the pack is reordered, but (optionally) after the pack is
5599 * combined. This may be tricky. See "dungeon.c" for info.
5601 * Note that this code must remove any location/stack information
5602 * from the object once it is placed into the inventory.
5604 s16b inven_carry(object_type *o_ptr)
5612 /* Check for combining */
5613 for (j = 0; j < INVEN_PACK; j++)
5615 j_ptr = &inventory[j];
5617 /* Skip non-objects */
5618 if (!j_ptr->k_idx) continue;
5620 /* Hack -- track last item */
5623 /* Check if the two items can be combined */
5624 if (object_similar(j_ptr, o_ptr))
5626 /* Combine the items */
5627 object_absorb(j_ptr, o_ptr);
5629 /* Increase the weight */
5630 p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
5632 /* Recalculate bonuses */
5633 p_ptr->update |= (PU_BONUS);
5636 p_ptr->window |= (PW_INVEN);
5645 if (inven_cnt > INVEN_PACK) return (-1);
5647 /* Find an empty slot */
5648 for (j = 0; j <= INVEN_PACK; j++)
5650 j_ptr = &inventory[j];
5652 /* Use it if found */
5653 if (!j_ptr->k_idx) break;
5660 /* Reorder the pack */
5663 s32b o_value, j_value;
5665 /* Get the "value" of the item */
5666 o_value = object_value(o_ptr);
5668 /* Scan every occupied slot */
5669 for (j = 0; j < INVEN_PACK; j++)
5671 j_ptr = &inventory[j];
5673 /* Use empty slots */
5674 if (!j_ptr->k_idx) break;
5676 /* Hack -- readable books always come first */
5677 if ((o_ptr->tval == REALM1_BOOK) &&
5678 (j_ptr->tval != REALM1_BOOK)) break;
5679 if ((j_ptr->tval == REALM1_BOOK) &&
5680 (o_ptr->tval != REALM1_BOOK)) continue;
5682 if ((o_ptr->tval == REALM2_BOOK) &&
5683 (j_ptr->tval != REALM2_BOOK)) break;
5684 if ((j_ptr->tval == REALM2_BOOK) &&
5685 (o_ptr->tval != REALM2_BOOK)) continue;
5687 /* Objects sort by decreasing type */
5688 if (o_ptr->tval > j_ptr->tval) break;
5689 if (o_ptr->tval < j_ptr->tval) continue;
5691 /* Non-aware (flavored) items always come last */
5692 if (!object_aware_p(o_ptr)) continue;
5693 if (!object_aware_p(j_ptr)) break;
5695 /* Objects sort by increasing sval */
5696 if (o_ptr->sval < j_ptr->sval) break;
5697 if (o_ptr->sval > j_ptr->sval) continue;
5699 /* Unidentified objects always come last */
5700 if (!object_known_p(o_ptr)) continue;
5701 if (!object_known_p(j_ptr)) break;
5703 /* Hack: otherwise identical rods sort by
5704 increasing recharge time --dsb */
5705 if (o_ptr->tval == TV_ROD)
5707 if (o_ptr->pval < j_ptr->pval) break;
5708 if (o_ptr->pval > j_ptr->pval) continue;
5711 /* Determine the "value" of the pack item */
5712 j_value = object_value(j_ptr);
5714 /* Objects sort by decreasing value */
5715 if (o_value > j_value) break;
5716 if (o_value < j_value) continue;
5723 for (k = n; k >= i; k--)
5725 /* Hack -- Slide the item */
5726 object_copy(&inventory[k+1], &inventory[k]);
5729 /* Wipe the empty slot */
5730 object_wipe(&inventory[i]);
5735 object_copy(&inventory[i], o_ptr);
5737 /* Access new object */
5738 j_ptr = &inventory[i];
5741 j_ptr->next_o_idx = 0;
5743 /* Forget monster */
5744 j_ptr->held_m_idx = 0;
5746 /* Forget location */
5747 j_ptr->iy = j_ptr->ix = 0;
5749 /* No longer marked */
5750 j_ptr->marked = FALSE;
5752 /* Increase the weight */
5753 p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
5755 /* Count the items */
5758 /* Recalculate bonuses */
5759 p_ptr->update |= (PU_BONUS);
5761 /* Combine and Reorder pack */
5762 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
5765 p_ptr->window |= (PW_INVEN);
5767 /* Return the slot */
5773 * Take off (some of) a non-cursed equipment item
5775 * Note that only one item at a time can be wielded per slot.
5777 * Note that taking off an item when "full" may cause that item
5778 * to fall to the ground.
5780 * Return the inventory slot into which the item is placed.
5782 s16b inven_takeoff(int item, int amt)
5793 char o_name[MAX_NLEN];
5796 /* Get the item to take off */
5797 o_ptr = &inventory[item];
5800 if (amt <= 0) return (-1);
5803 if (amt > o_ptr->number) amt = o_ptr->number;
5805 /* Get local object */
5808 /* Obtain a local object */
5809 object_copy(q_ptr, o_ptr);
5811 /* Modify quantity */
5812 q_ptr->number = amt;
5814 /* Describe the object */
5815 object_desc(o_name, q_ptr, TRUE, 3);
5817 /* Took off weapon */
5818 if (item == INVEN_RARM)
5821 act = "¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤¿";
5823 act = "You were wielding";
5829 else if (item == INVEN_BOW)
5832 act = "¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤¿";
5834 act = "You were holding";
5839 /* Took off light */
5840 else if (item == INVEN_LITE)
5843 act = "¤ò¸÷¸»¤«¤é¤Ï¤º¤·¤¿";
5845 act = "You were holding";
5850 /* Took off something */
5854 act = "¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤¿";
5856 act = "You were wearing";
5861 /* Modify, Optimize */
5862 inven_item_increase(item, -amt);
5863 inven_item_optimize(item);
5865 /* Carry the object */
5866 slot = inven_carry(q_ptr);
5870 msg_format("%s(%c)%s¡£", o_name, index_to_label(slot), act);
5872 msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
5882 * Drop (some of) a non-cursed inventory/equipment item
5884 * The object will be dropped "near" the current location
5886 void inven_drop(int item, int amt)
5893 char o_name[MAX_NLEN];
5896 /* Access original object */
5897 o_ptr = &inventory[item];
5900 if (amt <= 0) return;
5903 if (amt > o_ptr->number) amt = o_ptr->number;
5906 /* Take off equipment */
5907 if (item >= INVEN_RARM)
5909 /* Take off first */
5910 item = inven_takeoff(item, amt);
5912 /* Access original object */
5913 o_ptr = &inventory[item];
5917 /* Get local object */
5920 /* Obtain local object */
5921 object_copy(q_ptr, o_ptr);
5923 /* Distribute charges of wands or rods */
5924 distribute_charges(o_ptr, q_ptr, amt);
5926 /* Modify quantity */
5927 q_ptr->number = amt;
5929 /* Describe local object */
5930 object_desc(o_name, q_ptr, TRUE, 3);
5934 msg_format("%s(%c)¤òÍî¤È¤·¤¿¡£", o_name, index_to_label(item));
5936 msg_format("You drop %s (%c).", o_name, index_to_label(item));
5940 /* Drop it near the player */
5941 (void)drop_near(q_ptr, 0, py, px);
5943 /* Modify, Describe, Optimize */
5944 inven_item_increase(item, -amt);
5945 inven_item_describe(item);
5946 inven_item_optimize(item);
5951 * Combine items in the pack
5953 * Note special handling of the "overflow" slot
5955 void combine_pack(void)
5963 /* Combine the pack (backwards) */
5964 for (i = INVEN_PACK; i > 0; i--)
5967 o_ptr = &inventory[i];
5969 /* Skip empty items */
5970 if (!o_ptr->k_idx) continue;
5972 /* Scan the items above that item */
5973 for (j = 0; j < i; j++)
5976 j_ptr = &inventory[j];
5978 /* Skip empty items */
5979 if (!j_ptr->k_idx) continue;
5981 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
5982 if (object_similar_part(j_ptr, o_ptr)
5983 && j_ptr->number < MAX_STACK_SIZE-1)
5985 if (o_ptr->number + j_ptr->number < MAX_STACK_SIZE)
5990 /* Add together the item counts */
5991 object_absorb(j_ptr, o_ptr);
5993 /* One object is gone */
5996 /* Slide everything down */
5997 for (k = i; k < INVEN_PACK; k++)
5999 /* Structure copy */
6000 inventory[k] = inventory[k+1];
6003 /* Erase the "final" slot */
6004 object_wipe(&inventory[k]);
6008 int remain = j_ptr->number + o_ptr->number - 99;
6010 o_ptr->number -= remain;
6012 /* Add together the item counts */
6013 object_absorb(j_ptr, o_ptr);
6015 o_ptr->number = remain;
6019 p_ptr->window |= (PW_INVEN);
6029 if (flag) msg_print("¥¶¥Ã¥¯¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤ò¤Þ¤È¤áľ¤·¤¿¡£");
6031 if (flag) msg_print("You combine some items in your pack.");
6038 * Reorder items in the pack
6040 * Note special handling of the "overflow" slot
6042 void reorder_pack(void)
6054 /* Re-order the pack (forwards) */
6055 for (i = 0; i < INVEN_PACK; i++)
6057 /* Mega-Hack -- allow "proper" over-flow */
6058 if ((i == INVEN_PACK) && (inven_cnt == INVEN_PACK)) break;
6061 o_ptr = &inventory[i];
6063 /* Skip empty slots */
6064 if (!o_ptr->k_idx) continue;
6066 /* Get the "value" of the item */
6067 o_value = object_value(o_ptr);
6069 /* Scan every occupied slot */
6070 for (j = 0; j < INVEN_PACK; j++)
6072 /* Get the item already there */
6073 j_ptr = &inventory[j];
6075 /* Use empty slots */
6076 if (!j_ptr->k_idx) break;
6078 /* Hack -- readable books always come first */
6079 if ((o_ptr->tval == REALM1_BOOK) &&
6080 (j_ptr->tval != REALM1_BOOK)) break;
6081 if ((j_ptr->tval == REALM1_BOOK) &&
6082 (o_ptr->tval != REALM1_BOOK)) continue;
6084 if ((o_ptr->tval == REALM2_BOOK) &&
6085 (j_ptr->tval != REALM2_BOOK)) break;
6086 if ((j_ptr->tval == REALM2_BOOK) &&
6087 (o_ptr->tval != REALM2_BOOK)) continue;
6089 /* Objects sort by decreasing type */
6090 if (o_ptr->tval > j_ptr->tval) break;
6091 if (o_ptr->tval < j_ptr->tval) continue;
6093 /* Non-aware (flavored) items always come last */
6094 if (!object_aware_p(o_ptr)) continue;
6095 if (!object_aware_p(j_ptr)) break;
6097 /* Objects sort by increasing sval */
6098 if (o_ptr->sval < j_ptr->sval) break;
6099 if (o_ptr->sval > j_ptr->sval) continue;
6101 /* Unidentified objects always come last */
6102 if (!object_known_p(o_ptr)) continue;
6103 if (!object_known_p(j_ptr)) break;
6105 /* Hack: otherwise identical rods sort by
6106 increasing recharge time --dsb */
6107 if (o_ptr->tval == TV_ROD)
6109 if (o_ptr->pval < j_ptr->pval) break;
6110 if (o_ptr->pval > j_ptr->pval) continue;
6113 /* Determine the "value" of the pack item */
6114 j_value = object_value(j_ptr);
6118 /* Objects sort by decreasing value */
6119 if (o_value > j_value) break;
6120 if (o_value < j_value) continue;
6123 /* Never move down */
6124 if (j >= i) continue;
6129 /* Get local object */
6132 /* Save a copy of the moving item */
6133 object_copy(q_ptr, &inventory[i]);
6135 /* Slide the objects */
6136 for (k = i; k > j; k--)
6138 /* Slide the item */
6139 object_copy(&inventory[k], &inventory[k-1]);
6142 /* Insert the moving item */
6143 object_copy(&inventory[j], q_ptr);
6146 p_ptr->window |= (PW_INVEN);
6151 if (flag) msg_print("¥¶¥Ã¥¯¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤òÊ¤Ùľ¤·¤¿¡£");
6153 if (flag) msg_print("You reorder some items in your pack.");
6160 * Hack -- display an object kind in the current window
6162 * Include list of usable spells for readible books
6164 void display_koff(int k_idx)
6171 char o_name[MAX_NLEN];
6174 /* Erase the window */
6175 for (y = 0; y < Term->hgt; y++)
6177 /* Erase the line */
6178 Term_erase(0, y, 255);
6184 /* Get local object */
6187 /* Prepare the object */
6188 object_prep(q_ptr, k_idx);
6191 object_desc_store(o_name, q_ptr, FALSE, 0);
6193 /* Mention the object name */
6194 Term_putstr(0, 0, -1, TERM_WHITE, o_name);
6196 /* Warriors are illiterate */
6197 if (!(p_ptr->realm1 || p_ptr->realm2)) return;
6199 /* Display spells in readible books */
6200 if ((q_ptr->tval == REALM1_BOOK) ||
6201 (q_ptr->tval == REALM2_BOOK))
6209 /* Access the item's sval */
6212 /* Extract spells */
6213 for (spell = 0; spell < 32; spell++)
6215 /* Check for this spell */
6216 if (fake_spell_flags[sval] & (1L << spell))
6218 /* Collect this spell */
6219 spells[num++] = spell;
6224 print_spells(0, spells, num, 2, 0,
6225 (q_ptr->tval == REALM1_BOOK ? p_ptr->realm1 : p_ptr->realm2));
6229 /* Choose one of items that have warning flag */
6230 object_type *choose_warning_item(void)
6233 int choices[INVEN_TOTAL-INVEN_RARM];
6236 /* Paranoia -- Player has no warning-item */
6237 if (!p_ptr->warning) return (NULL);
6239 /* Search Inventry */
6240 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
6242 u32b flgs[TR_FLAG_SIZE];
6243 object_type *o_ptr = &inventory[i];
6245 object_flags(o_ptr, flgs);
6246 if (have_flag(flgs, TR_WARNING))
6248 choices[number] = i;
6253 /* Choice one of them */
6254 return (&inventory[choices[randint0(number)]]);
6257 /* Examine the grid (xx,yy) and warn the player if there are any danger */
6258 bool process_frakir(int xx, int yy)
6262 char o_name[MAX_NLEN];
6264 #define FRAKIR_AWARE_RANGE 12
6266 static int old_damage = 0;
6268 for (mx = xx-FRAKIR_AWARE_RANGE; mx < xx+FRAKIR_AWARE_RANGE+1; mx++)
6270 for (my = yy-FRAKIR_AWARE_RANGE; my < yy+FRAKIR_AWARE_RANGE+1; my++)
6273 monster_type *m_ptr;
6274 monster_race *r_ptr;
6278 if (!in_bounds(my,mx) || (distance(my,mx,yy,xx)>FRAKIR_AWARE_RANGE)) continue;
6280 c_ptr = &cave[my][mx];
6282 if (!c_ptr->m_idx) continue;
6284 m_ptr = &m_list[c_ptr->m_idx];
6285 r_ptr = &r_info[m_ptr->r_idx];
6291 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
6293 if (m_ptr->csleep) continue;
6294 if (is_pet(m_ptr)) continue;
6296 /* Monster spells (only powerful ones)*/
6297 if(projectable(my,mx,yy,xx))
6300 #define DAMCALC(f,val,max,im,vln,res,resx,resy,op,opx,opy,dmax) \
6301 if (f){ int dam = (val)>(max)? (max):(val); \
6303 if (vln) dam *= 2; \
6304 if (res) {dam = (dam * resx) / resy;} \
6305 if (op) {dam = (dam * opx) / opy;} \
6306 if (dam>dmax) dmax = dam; \
6309 DAMCALC(f4 & (RF4_BR_FIRE), m_ptr->hp / 3, 1600,
6310 p_ptr->immune_fire, p_ptr->muta3 & MUT3_VULN_ELEM,
6311 p_ptr->resist_fire, 1, 3,
6312 p_ptr->oppose_fire, 1, 3, dam_max0);
6314 DAMCALC(f4 & (RF4_BR_COLD), m_ptr->hp / 3, 1600,
6315 p_ptr->immune_cold, p_ptr->muta3 & MUT3_VULN_ELEM,
6316 p_ptr->resist_cold, 1, 3,
6317 p_ptr->oppose_cold, 1, 3, dam_max0);
6319 DAMCALC(f4 & (RF4_BR_ELEC), m_ptr->hp / 3, 1600,
6320 p_ptr->immune_elec, p_ptr->muta3 & MUT3_VULN_ELEM,
6321 p_ptr->resist_elec, 1, 3,
6322 p_ptr->oppose_elec, 1, 3, dam_max0);
6324 DAMCALC(f4 & (RF4_BR_ACID), m_ptr->hp / 3, 1600,
6325 p_ptr->immune_acid, p_ptr->muta3 & MUT3_VULN_ELEM,
6326 p_ptr->resist_acid, 1, 3,
6327 p_ptr->oppose_acid, 1, 3, dam_max0);
6329 DAMCALC(f4 & (RF4_BR_POIS), m_ptr->hp / 3, 800,
6331 p_ptr->resist_pois, 1, 3,
6332 p_ptr->oppose_pois, 1, 3, dam_max0);
6335 DAMCALC(f4 & (RF4_BR_NETH), m_ptr->hp / 6, 550, FALSE , FALSE,
6336 p_ptr->resist_neth, 6, 9, FALSE, 1, 1, dam_max0);
6338 DAMCALC(f4 & (RF4_BR_LITE), m_ptr->hp / 6, 400, FALSE , FALSE,
6339 p_ptr->resist_lite, 4, 9, FALSE, 1, 1, dam_max0);
6341 DAMCALC(f4 & (RF4_BR_DARK), m_ptr->hp / 6, 400, FALSE , FALSE,
6342 p_ptr->resist_dark, 4, 9, FALSE, 1, 1, dam_max0);
6344 DAMCALC(f4 & (RF4_BR_CONF), m_ptr->hp / 6, 450, FALSE , FALSE,
6345 p_ptr->resist_conf, 5, 9, FALSE, 1, 1, dam_max0);
6347 DAMCALC(f4 & (RF4_BR_SOUN), m_ptr->hp / 6, 450, FALSE , FALSE,
6348 p_ptr->resist_sound, 5, 9, FALSE, 1, 1, dam_max0);
6350 DAMCALC(f4 & (RF4_BR_CHAO), m_ptr->hp / 6, 600, FALSE , FALSE,
6351 p_ptr->resist_chaos, 6, 9, FALSE, 1, 1, dam_max0);
6353 DAMCALC(f4 & (RF4_BR_DISE), m_ptr->hp / 6, 500, FALSE , FALSE,
6354 p_ptr->resist_disen, 6, 9, FALSE, 1, 1, dam_max0);
6356 DAMCALC(f4 & (RF4_BR_NEXU), m_ptr->hp / 3, 250, FALSE , FALSE,
6357 p_ptr->resist_nexus, 6, 9, FALSE, 1, 1, dam_max0);
6359 DAMCALC(f4 & (RF4_BR_TIME), m_ptr->hp / 3, 150, FALSE , FALSE,
6360 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6362 DAMCALC(f4 & (RF4_BR_INER), m_ptr->hp / 6, 200, FALSE , FALSE,
6363 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6365 DAMCALC(f4 & (RF4_BR_GRAV), m_ptr->hp / 3, 200, FALSE , FALSE,
6366 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6368 DAMCALC(f4 & (RF4_BR_SHAR), m_ptr->hp / 6, 500, FALSE , FALSE,
6369 p_ptr->resist_shard, 6, 9, FALSE, 1, 1, dam_max0);
6371 DAMCALC(f4 & (RF4_BR_PLAS), m_ptr->hp / 6, 150, FALSE , FALSE,
6372 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6374 DAMCALC(f4 & (RF4_BR_WALL), m_ptr->hp / 6, 200, FALSE , FALSE,
6375 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6377 DAMCALC(f4 & (RF4_BR_MANA), m_ptr->hp / 3, 250, FALSE , FALSE,
6378 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6380 DAMCALC(f4 & (RF4_BR_NUKE), m_ptr->hp / 3, 800, FALSE , FALSE,
6381 p_ptr->resist_pois, 2, 5,
6382 p_ptr->oppose_pois, 2, 5, dam_max0);
6384 DAMCALC(f4 & (RF4_BR_DISI), m_ptr->hp / 3, 300, FALSE , FALSE,
6385 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6388 DAMCALC(f4 & (RF4_ROCKET), m_ptr->hp / 4, 800, FALSE , FALSE,
6389 p_ptr->resist_shard, 1, 2, FALSE, 1, 1, dam_max0);
6391 DAMCALC(f5 & (RF5_BA_MANA), rlev*4 + 150, 9999, FALSE , FALSE,
6392 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6394 DAMCALC(f5 & (RF5_BA_DARK), rlev*4 + 150, 9999, FALSE , FALSE,
6395 p_ptr->resist_dark, 4, 9, FALSE, 1, 1, dam_max0);
6397 DAMCALC(f5 & (RF5_BA_LITE), rlev*4 + 150, 9999, FALSE , FALSE,
6398 p_ptr->resist_lite, 4, 9, FALSE, 1, 1, dam_max0);
6401 DAMCALC(f6 & (RF6_HAND_DOOM), p_ptr->chp*6/10, 9999, FALSE , FALSE,
6402 FALSE, 1, 1, FALSE, 1, 1, dam_max0);
6406 /* Monster melee attacks */
6407 if(mx <= xx+1 && mx >= xx-1 && my <=yy+1 && my >= yy-1)
6411 for (m = 0; m < 4; m++)
6415 /* Skip non-attacks */
6416 if (!r_ptr->blow[m].method) continue;
6418 /* Extract the attack info */
6419 d1 = r_ptr->blow[m].d_dice;
6420 d2 = r_ptr->blow[m].d_side;
6424 if(dam_melee>dam_max0)dam_max0=dam_melee;
6427 /* Contribution from this monster */
6432 /* Prevent excessive warning */
6433 if(dam_max > old_damage)
6435 old_damage=dam_max * 3 / 2;
6437 if (dam_max>(p_ptr->chp)/2)
6439 object_type *o_ptr = choose_warning_item();
6441 object_desc(o_name, o_ptr, FALSE, 0);
6443 msg_format("%s¤¬±Ô¤¯¿Ì¤¨¤¿¡ª", o_name);
6445 msg_format("%s pulsates sharply!", o_name);
6449 return (get_check("ËÜÅö¤Ë¤³¤Î¤Þ¤Þ¿Ê¤à¤«¡©"));
6451 return (get_check("Realy want to go ahead? "));
6455 else old_damage = old_damage/2;
6457 c_ptr = &cave[yy][xx];
6458 if (((is_trap(c_ptr->feat) && !easy_disarm) || (c_ptr->info & CAVE_TRAP)) && !one_in_(13))
6460 object_type *o_ptr = choose_warning_item();
6462 object_desc(o_name, o_ptr, FALSE, 0);
6464 msg_format("%s¤¬¿Ì¤¨¤¿¡ª", o_name);
6466 msg_format("%s pulsates!", o_name);
6470 return (get_check("ËÜÅö¤Ë¤³¤Î¤Þ¤Þ¿Ê¤à¤«¡©"));
6472 return (get_check("Realy want to go ahead? "));
6479 typedef struct essence_type essence_type;
6490 static essence_type essence_info[MAX_ESSENCE] = {
6491 {"ÏÓÎÏ","ÏÓÎÏ", 1, 4, 20},
6492 {"ÃÎǽ","ÃÎǽ", 2, 4, 20},
6493 {"¸¤µ","¸¤µ", 3, 4, 20},
6494 {"´ïÍѤµ","´ïÍѤµ", 4, 4, 20},
6495 {"Âѵ×ÎÏ","Âѵ×ÎÏ", 5, 4, 20},
6496 {"Ì¥ÎÏ","Ì¥ÎÏ", 6, 4, 20},
6497 {"ËâÎÏ»ÙÇÛ","ËâÎÏ»ÙÇÛ", 7, 4, 20},
6499 {"±£Ì©","±£Ì©", 9, 4, 40},
6500 {"õº÷","õº÷", 10, 4, 15},
6501 {"ÀÖ³°Àþ»ëÎÏ","ÀÖ³°Àþ»ëÎÏ", 11, 4, 15},
6502 {"ºÎ·¡","ºÎ·¡", 12, 4, 15},
6503 {"¥¹¥Ô¡¼¥É","¥¹¥Ô¡¼¥É", 13, 4, 12},
6504 {"Äɲù¶·â","Äɲù¶·â", 14, 1, 20},
6505 {"¥«¥ª¥¹¹¶·â","¥«¥ª¥¹¹¶·â", 15, 1, 15},
6506 {"µÛ·ì¹¶·â","µÛ·ì¹¶·â", 16, 1, 60},
6507 {"ưʪÇÜÂÇ","ưʪÇÜÂÇ", 17, 1, 20},
6508 {"¼Ù°ÇÜÂÇ","¼Ù°ÇÜÂÇ", 18, 1, 100},
6509 {"ÉÔ»àÇÜÂÇ","ÉÔ»àÇÜÂÇ", 19, 1, 20},
6510 {"°ËâÇÜÂÇ","°ËâÇÜÂÇ", 20, 1, 20},
6511 {"¥ª¡¼¥¯ÇÜÂÇ","¥ª¡¼¥¯ÇÜÂÇ", 21, 1, 15},
6512 {"¥È¥í¥ëÇÜÂÇ","¥È¥í¥ëÇÜÂÇ", 22, 1, 15},
6513 {"µð¿ÍÇÜÂÇ","µð¿ÍÇÜÂÇ", 23, 1, 20},
6514 {"εÇÜÂÇ","εÇÜÂÇ", 24, 1, 20},
6515 {"","εÇÜÇÜÂÇ", 24, 1, 60},
6517 {"ÃÏ¿Ì","ÃÏ¿Ìȯư", 27, 5, 15},
6518 {"ÆÇ»¦","ÆÇ»¦", 28, 1, 20},
6519 {"Íϲò","Íϲò", 29, 1, 20},
6520 {"ÅÅ·â","ÅÅ·â", 30, 1, 20},
6521 {"¾Æ´þ","¾Æ´þ", 31, 1, 20},
6522 {"Åà·ë","Åà·ë", 32, 1, 20},
6523 {"ǽÎÏ°Ý»ý","ÏÓÎÏ°Ý»ý", 33, 3, 15},
6524 {"","ÃÎǽ°Ý»ý", 33, 3, 15},
6525 {"","¸¤µ°Ý»ý", 33, 3, 15},
6526 {"","´ïÍѤµ°Ý»ý", 33, 3, 15},
6527 {"","Âѵ×ÎÏ°Ý»ý", 33, 3, 15},
6528 {"","Ì¥ÎÏ°Ý»ý", 33, 3, 15},
6531 {"ÌȱÖ","»ÀÌȱÖ", 41, 2, 20},
6532 {"","ÅÅ·âÌȱÖ", 41, 2, 20},
6533 {"","²Ð±êÌȱÖ", 41, 2, 20},
6534 {"","Î䵤ÌȱÖ", 41, 2, 20},
6536 {"È¿¼Í","È¿¼Í", 46, 2, 20},
6537 {"ËãáãÃΤ餺","ËãáãÃΤ餺", 47, 3, 20},
6538 {"À¸Ì¿ÎÏ°Ý»ý","À¸Ì¿ÎÏ°Ý»ý", 48, 3, 20},
6539 {"ÂÑ»À","ÂÑ»À", 49, 2, 15},
6540 {"ÂÑÅÅ·â","ÂÑÅÅ·â", 50, 2, 15},
6541 {"ÂѲбê","ÂѲбê", 51, 2, 15},
6542 {"ÂÑÎ䵤","ÂÑÎ䵤", 52, 2, 15},
6543 {"ÂÑÆÇ","ÂÑÆÇ", 53, 2, 25},
6544 {"ÂѶ²ÉÝ","ÂѶ²ÉÝ", 54, 2, 20},
6545 {"ÂÑÁ®¸÷","ÂÑÁ®¸÷", 55, 2, 20},
6546 {"ÂѰŹõ","ÂѰŹõ", 56, 2, 20},
6547 {"ÂÑÌÕÌÜ","ÂÑÌÕÌÜ", 57, 2, 20},
6548 {"ÂѺ®Íð","ÂѺ®Íð", 58, 2, 20},
6549 {"Âѹ첻","Âѹ첻", 59, 2, 20},
6550 {"ÂÑÇËÊÒ","ÂÑÇËÊÒ", 60, 2, 20},
6551 {"ÂÑÃϹö","ÂÑÃϹö", 61, 2, 20},
6552 {"ÂÑ°ø²Ìº®Íð","ÂÑ°ø²Ìº®Íð", 62, 2, 20},
6553 {"ÂÑ¥«¥ª¥¹","ÂÑ¥«¥ª¥¹", 63, 2, 20},
6554 {"ÂÑÎô²½","ÂÑÎô²½", 64, 2, 20},
6557 {"¿Í´ÖÇÜÂÇ","¿Í´ÖÇÜÂÇ", 67, 1, 20},
6560 {"È¿ËâË¡","È¿ËâË¡", 70, 3, 15},
6563 {"·Ù¹ð","·Ù¹ð", 73, 3, 20},
6567 {"ÉâÍ·","ÉâÍ·", 77, 3, 20},
6568 {"±Êµ×¸÷¸»","±Êµ×¸÷¸»", 78, 3, 15},
6569 {"²Ä»ëÆ©ÌÀ","²Ä»ëÆ©ÌÀ", 79, 3, 20},
6570 {"¥Æ¥ì¥Ñ¥·¡¼","¥Æ¥ì¥Ñ¥·¡¼", 80, 3, 15},
6571 {"Ãپò½","Ãپò½", 81, 3, 15},
6572 {"µÞ®²óÉü","µÞ®²óÉü", 82, 3, 20},
6581 {"¥Æ¥ì¥Ý¡¼¥È","¥Æ¥ì¥Ý¡¼¥È", 91, 3, 25},
6587 {"¹¶·â","¹¶·â", 97, 6, 30},
6588 {"Ëɸæ","Ëɸæ", 98, 6, 15},
6589 {"","»ÀÂÑÀȯư", 49, 5, 50},
6590 {"","ÅÅ·âÂÑÀȯư", 50, 5, 50},
6591 {"","²Ð±êÂÑÀȯư", 51, 5, 50},
6592 {"","Î䵤ÂÑÀȯư", 52, 5, 50},
6593 {"","²Ð±ê¥ª¡¼¥é", 0, 5, 30},
6594 {"","Åŷ⥪¡¼¥é", 0, 5, 30},
6595 {"","Î䵤¥ª¡¼¥é", 0, 5, 30},
6596 {"","Á´ÂÑÀ", 0, 2, 150},
6597 {"","ÁõÈ÷ÊÝ»ý", 0, 6, 10},
6598 {"","»¦Ù¤¤Î¾®¼ê", 97, 1, 200},
6601 static essence_type essence_info[MAX_ESSENCE] = {
6602 {"strength","strength", 1, 4, 20},
6603 {"intelligen.","intelligence", 2, 4, 20},
6604 {"wisdom","wisdom", 3, 4, 20},
6605 {"dexterity","dexterity", 4, 4, 20},
6606 {"constitut.","constitution", 5, 4, 20},
6607 {"charisma","charisma", 6, 4, 20},
6608 {"magic mast.","magic mastery", 7, 4, 20},
6610 {"stealth","stealth", 9, 4, 40},
6611 {"serching","serching", 10, 4, 15},
6612 {"inflavision","inflavision", 11, 4, 15},
6613 {"digging","digging", 12, 4, 15},
6614 {"speed","speed", 13, 4, 12},
6615 {"extra atk","extra attack", 14, 1, 20},
6616 {"chaos brand","chaos brand", 15, 1, 15},
6617 {"vampiric","vampiric brand", 16, 1, 60},
6618 {"slay animal","slay animal", 17, 1, 20},
6619 {"slay evil","slay evil", 18, 1, 100},
6620 {"slay undead","slay undead", 19, 1, 20},
6621 {"slay demon","slay demon", 20, 1, 20},
6622 {"slay orc","slay orc", 21, 1, 15},
6623 {"slay troll","slay troll", 22, 1, 15},
6624 {"slay giant","slay giant", 23, 1, 20},
6625 {"slay dragon","slay dragon", 24, 1, 20},
6626 {"","kill dragon", 24, 1, 60},
6628 {"quake","quake activation", 27, 5, 15},
6629 {"pois. brand","poison brand", 28, 1, 20},
6630 {"acid brand","acid brand", 29, 1, 20},
6631 {"elec. brand","electric brand", 30, 1, 20},
6632 {"fire brand","fire brand", 31, 1, 20},
6633 {"cold brand","cold brand", 32, 1, 20},
6634 {"sustain","sustain strength", 33, 3, 15},
6635 {"","sustain intelligence", 33, 3, 15},
6636 {"","sustain wisdom", 33, 3, 15},
6637 {"","sustain dexterity", 33, 3, 15},
6638 {"","sustain constitution", 33, 3, 15},
6639 {"","sustain charisma", 33, 3, 15},
6642 {"immunity","acid immunity", 41, 2, 20},
6643 {"","electric immunity", 41, 2, 20},
6644 {"","fire immunity", 41, 2, 20},
6645 {"","cold immunity", 41, 2, 20},
6647 {"reflection","reflection", 46, 2, 20},
6648 {"free action","free action", 47, 3, 20},
6649 {"hold life","hold life", 48, 3, 20},
6650 {"res. acid","resistance to acid", 49, 2, 15},
6651 {"res. elec.","resistance to electric", 50, 2, 15},
6652 {"res. fire","resistance to fire", 51, 2, 15},
6653 {"res. cold","resistance to cold", 52, 2, 15},
6654 {"res. poison","resistance to poison", 53, 2, 25},
6655 {"res. fear","resistance to fear", 54, 2, 20},
6656 {"res. light","resistance to light", 55, 2, 20},
6657 {"res. dark","resistance to dark", 56, 2, 20},
6658 {"res. blind","resistance to blind", 57, 2, 20},
6659 {"res.confuse","resistance to confusion", 58, 2, 20},
6660 {"res. sound","resistance to sound", 59, 2, 20},
6661 {"res. shard","resistance to shard", 60, 2, 20},
6662 {"res. nether","resistance to nether", 61, 2, 20},
6663 {"res. nexus","resistance to nexus", 62, 2, 20},
6664 {"res. chaos","resistance to chaos", 63, 2, 20},
6665 {"res. disen.","resistance to disenchantment", 64, 2, 20},
6668 {"slay human","slay human", 67, 1, 20},
6671 {"anti magic","anti magic", 70, 3, 15},
6674 {"warning","warning", 73, 3, 20},
6678 {"levitation","levitation", 77, 3, 20},
6679 {"perm. light","permanent light", 78, 3, 15},
6680 {"see invis.","see invisible", 79, 3, 20},
6681 {"telepathy","telepathy", 80, 3, 15},
6682 {"slow dige.","slow digestion", 81, 3, 15},
6683 {"regen.","regeneration", 82, 3, 20},
6692 {"teleport","teleport", 91, 3, 25},
6698 {"weapon enc.","weapon enchant", 97, 6, 30},
6699 {"armor enc.","armor enchant", 98, 6, 15},
6700 {"","resist acid activation", 49, 5, 50},
6701 {"","resist electricity activation", 50, 5, 50},
6702 {"","resist fire activation", 51, 5, 50},
6703 {"","resist cold activation", 52, 5, 50},
6704 {"","fiery sheath", 0, 5, 30},
6705 {"","electric sheath", 0, 5, 30},
6706 {"","coldly sheath", 0, 5, 30},
6707 {"","resistance", 0, 2, 150},
6708 {"","elements proof", 0, 6, 10},
6709 {"","gauntlets of slay", 97, 1, 200},
6713 static bool item_tester_hook_melee_ammo(object_type *o_ptr)
6715 switch (o_ptr->tval)
6728 if (o_ptr->sval != SV_DOKUBARI) return (TRUE);
6736 static void display_essence(void)
6741 for (i = 1; i < 22; i++)
6746 prt("¥¨¥Ã¥»¥ó¥¹ ¸Ä¿ô ¥¨¥Ã¥»¥ó¥¹ ¸Ä¿ô ¥¨¥Ã¥»¥ó¥¹ ¸Ä¿ô", 1, 8);
6748 prt("Essence Num Essence Num Essence Num ", 1, 8);
6750 for (i = 0; i < MAX_ESSENCE; i++)
6752 if (!essence_info[i].drain_name[0]) continue;
6753 prt(format("%-11s %5d", essence_info[i].drain_name, p_ptr->magic_num1[i]), 2+num%20, 8+num/20*22);
6757 prt("¸½ºß½ê»ý¤·¤Æ¤¤¤ë¥¨¥Ã¥»¥ó¥¹", 0, 0);
6759 prt("List of all essences you have.", 0, 0);
6766 static void drain_essence(void)
6768 int drain_value[MAX_ESSENCE];
6771 bool observe = FALSE;
6772 int old_ds, old_dd, old_to_h, old_to_d, old_ac, old_to_a, old_pval, old_name2;
6773 u32b old_flgs[TR_FLAG_SIZE], new_flgs[TR_FLAG_SIZE];
6776 byte iy, ix, marked, number;
6777 s16b next_o_idx, weight;
6779 for (i = 0; i < MAX_ESSENCE; i++)
6782 item_tester_hook = item_tester_hook_weapon_armour;
6783 item_tester_no_ryoute = TRUE;
6787 q = "¤É¤Î¥¢¥¤¥Æ¥à¤«¤éÃê½Ð¤·¤Þ¤¹¤«¡©";
6788 s = "Ãê½Ð¤Ç¤¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
6790 q = "Extract from which item? ";
6791 s = "You have nothing you can extract from.";
6794 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
6796 /* Get the item (in the pack) */
6799 o_ptr = &inventory[item];
6802 /* Get the item (on the floor) */
6805 o_ptr = &o_list[0 - item];
6808 if (object_known_p(o_ptr) && (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name || o_ptr->xtra3)) {
6809 char o_name[MAX_NLEN];
6810 object_desc(o_name, o_ptr, FALSE, 0);
6812 if (!get_check(format("ËÜÅö¤Ë%s¤«¤éÃê½Ð¤·¤Æ¤è¤í¤·¤¤¤Ç¤¹¤«¡©", o_name))) return;
6814 if (!get_check(format("Really extract from %s? ", o_name))) return;
6820 object_flags(o_ptr, old_flgs);
6821 if (have_flag(old_flgs, TR_KILL_DRAGON)) add_flag(old_flgs, TR_SLAY_DRAGON);
6823 old_to_a = o_ptr->to_a;
6825 old_to_h = o_ptr->to_h;
6826 old_to_d = o_ptr->to_d;
6829 old_pval = o_ptr->pval;
6830 old_name2 = o_ptr->name2;
6831 if (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE)) dec--;
6832 if (have_flag(old_flgs, TR_AGGRAVATE)) dec--;
6833 if (have_flag(old_flgs, TR_NO_TELE)) dec--;
6834 if (have_flag(old_flgs, TR_DRAIN_EXP)) dec--;
6835 if (have_flag(old_flgs, TR_TY_CURSE)) dec--;
6839 next_o_idx = o_ptr->next_o_idx;
6840 marked = o_ptr->marked;
6841 weight = o_ptr->weight;
6842 number = o_ptr->number;
6844 object_prep(o_ptr, o_ptr->k_idx);
6848 o_ptr->next_o_idx=next_o_idx;
6849 o_ptr->marked=marked;
6850 o_ptr->number = number;
6851 if (item >= 0) p_ptr->total_weight += (o_ptr->weight*o_ptr->number - weight*number);
6852 o_ptr->ident |= (IDENT_MENTAL);
6853 object_aware(o_ptr);
6854 object_known(o_ptr);
6856 object_flags(o_ptr, new_flgs);
6858 for (i = 0; i < 96; i++)
6862 if (is_pval_flag(i) && old_pval) pval = (have_flag(new_flgs, i)) ? old_pval-o_ptr->pval : old_pval;
6864 if ((!(have_flag(new_flgs, i)) || pval) && (have_flag(old_flgs, i)) && essence_info[i].link)
6868 drain_value[essence_info[i].link-1] += 10 * pval;
6870 else if (essence_info[i].link != -1)
6872 drain_value[essence_info[i].link-1] += 10;
6874 else if (i == ESSENCE__SH__FIRE-1)
6876 drain_value[ESSENCE_B_FIRE-1] += 10;
6877 drain_value[ESSENCE_RES_FIRE-1] += 10;
6879 else if (i == ESSENCE__SH__ELEC-1)
6881 drain_value[ESSENCE_B_ELEC-1] += 10;
6882 drain_value[ESSENCE_RES_ELEC-1] += 10;
6884 else if (i == ESSENCE__SH__COLD-1)
6886 drain_value[ESSENCE_B_COLD-1] += 10;
6887 drain_value[ESSENCE_RES_COLD-1] += 10;
6892 if ((have_flag(old_flgs, TR_FORCE_WEAPON)) && !(have_flag(new_flgs, TR_FORCE_WEAPON)))
6894 drain_value[ESSENCE_INT-1] += 5;
6895 drain_value[ESSENCE_WIS-1] += 5;
6897 if ((have_flag(old_flgs, TR_VORPAL)) && !(have_flag(new_flgs, TR_VORPAL)))
6899 drain_value[ESSENCE_B_POIS-1] += 5;
6900 drain_value[ESSENCE_B_ACID-1] += 5;
6901 drain_value[ESSENCE_B_ELEC-1] += 5;
6902 drain_value[ESSENCE_B_FIRE-1] += 5;
6903 drain_value[ESSENCE_B_COLD-1] += 5;
6905 if ((have_flag(old_flgs, TR_DEC_MANA)) && !(have_flag(new_flgs, TR_DEC_MANA)))
6907 drain_value[ESSENCE_INT-1] += 10;
6909 if ((have_flag(old_flgs, TR_XTRA_MIGHT)) && !(have_flag(new_flgs, TR_XTRA_MIGHT)))
6911 drain_value[ESSENCE_STR-1] += 10;
6913 if ((have_flag(old_flgs, TR_XTRA_SHOTS)) && !(have_flag(new_flgs, TR_XTRA_SHOTS)))
6915 drain_value[ESSENCE_DEX-1] += 10;
6917 if (old_name2 == EGO_2WEAPON)
6919 drain_value[ESSENCE_DEX-1] += 20;
6921 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_SWORD) && (o_ptr->tval != TV_BOW))
6923 if (old_ds > o_ptr->ds) drain_value[ESSENCE_ATTACK-1] += (old_ds-o_ptr->ds)*10;
6925 if (old_dd > o_ptr->dd) drain_value[ESSENCE_ATTACK-1] += (old_dd-o_ptr->dd)*10;
6927 if (old_to_h > o_ptr->to_h) drain_value[ESSENCE_ATTACK-1] += (old_to_h-o_ptr->to_h)*10;
6928 if (old_to_d > o_ptr->to_d) drain_value[ESSENCE_ATTACK-1] += (old_to_d-o_ptr->to_d)*10;
6929 if (old_ac > o_ptr->ac) drain_value[ESSENCE_AC-1] += (old_ac-o_ptr->ac)*10;
6930 if (old_to_a > o_ptr->to_a) drain_value[ESSENCE_AC-1] += (old_to_a-o_ptr->to_a)*10;
6932 for (i = 0; i < MAX_ESSENCE; i++)
6934 drain_value[i] *= number;
6935 drain_value[i] = drain_value[i] * dec / 4;
6936 drain_value[i] = MAX(drain_value[i], 0);
6937 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) drain_value[i] /= 10;
6946 msg_print("¥¨¥Ã¥»¥ó¥¹¤ÏÃê½Ð¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£");
6948 msg_print("You were not able to extract any essence.");
6954 msg_print("Ãê½Ð¤·¤¿¥¨¥Ã¥»¥ó¥¹:");
6956 msg_print("Extracted essences:");
6958 for (i = 0; i < MAX_ESSENCE; i++)
6960 if (!drain_value[i]) continue;
6961 p_ptr->magic_num1[i] += drain_value[i];
6962 p_ptr->magic_num1[i] = MIN(20000, p_ptr->magic_num1[i]);
6964 msg_format("%s...%d", essence_info[i].drain_name, drain_value[i]);
6968 /* Combine the pack */
6969 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
6972 p_ptr->window |= (PW_INVEN);
6977 static int choose_essence(void)
6981 int menu_line = (use_menu ? 1 : 0);
6984 if (repeat_pull(&mode) && 1 <= mode && mode <= 5)
6987 #endif /* ALLOW_REPEAT */
6996 prt(format(" %s Éð´ï°À", (menu_line == 1) ? "¡Õ" : " "), 2, 14);
6997 prt(format(" %s ÂÑÀ", (menu_line == 2) ? "¡Õ" : " "), 3, 14);
6998 prt(format(" %s ǽÎÏ", (menu_line == 3) ? "¡Õ" : " "), 4, 14);
6999 prt(format(" %s ¿ôÃÍ", (menu_line == 4) ? "¡Õ" : " "), 5, 14);
7000 prt(format(" %s ¤½¤Î¾", (menu_line == 5) ? "¡Õ" : " "), 6, 14);
7001 prt("¤É¤Î¼ïÎà¤Î¥¨¥Ã¥»¥ó¥¹Éղäò¹Ô¤¤¤Þ¤¹¤«¡©", 0, 0);
7003 prt(format(" %s Brand weapon", (menu_line == 1) ? "> " : " "), 2, 14);
7004 prt(format(" %s Resistance", (menu_line == 2) ? "> " : " "), 3, 14);
7005 prt(format(" %s Ability", (menu_line == 3) ? "> " : " "), 4, 14);
7006 prt(format(" %s Magic number", (menu_line == 4) ? "> " : " "), 5, 14);
7007 prt(format(" %s Others", (menu_line == 5) ? "> " : " "), 6, 14);
7008 prt("Choose from menu.", 0, 0);
7035 if (menu_line > 5) menu_line -= 5;
7045 prt(" a) ¹¶·â°À", 2, 14);
7046 prt(" b) ÂÑÀ", 3, 14);
7047 prt(" c) ǽÎÏ", 4, 14);
7048 prt(" d) ¿ôÃÍ", 5, 14);
7049 prt(" e) ¤½¤Î¾", 6, 14);
7050 if (!get_com("²¿¤òÉղä·¤Þ¤¹¤«:", &choice, TRUE))
7052 prt(" a) Brand weapon", 2, 14);
7053 prt(" b) Resistance", 3, 14);
7054 prt(" c) Ability", 4, 14);
7055 prt(" d) Magic number", 5, 14);
7056 prt(" e) Others", 6, 14);
7057 if (!get_com("Command :", &choice, TRUE))
7093 #endif /* ALLOW_REPEAT */
7097 static void add_essence(int mode)
7099 int item, max_num = 0;
7108 char o_name[MAX_NLEN];
7111 int menu_line = (use_menu ? 1 : 0);
7113 for (i = 0; i < MAX_ESSENCE; i++)
7115 if (essence_info[i].type != mode) continue;
7120 if (!repeat_pull(&i) || i<0 || i>=max_num)
7122 #endif /* ALLOW_REPEAT */
7125 /* Nothing chosen yet */
7131 /* Build a prompt */
7133 (void) strnfmt(out_val, 78, "('*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤ÎǽÎϤòÉղä·¤Þ¤¹¤«¡©");
7135 (void)strnfmt(out_val, 78, "(*=List, ESC=exit) Add which ability? ");
7137 if (use_menu) screen_save();
7139 /* Get a spell from the user */
7141 choice = (always_show_list || use_menu) ? ESCAPE:1;
7145 if( choice==ESCAPE ) choice = ' ';
7146 else if( !get_com(out_val, &choice, FALSE) )break;
7148 if (use_menu && choice != ' ')
7163 menu_line += (max_num-1);
7186 menu_line = max_num;
7200 if (menu_line > max_num) menu_line -= max_num;
7202 /* Request redraw */
7203 if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
7206 if (!redraw || use_menu)
7210 char dummy[80], dummy2[80];
7218 /* Save the screen */
7219 if (!use_menu) screen_save();
7221 for (y = 1; y < 24; y++)
7224 /* Print header(s) */
7226 prt(" ǽÎÏ(ɬÍ×¥¨¥Ã¥»¥ó¥¹) ɬÍ׿ô/½ê»ý¿ô", 1, x);
7229 prt(" Ability(essence to need) Needs/Possess", 1, x);
7232 for (ctr = 0; ctr < max_num; ctr++)
7236 if (ctr == (menu_line-1))
7238 strcpy(dummy, "¡Õ ");
7240 strcpy(dummy, "> ");
7242 else strcpy(dummy, " ");
7245 /* letter/number for power selection */
7248 sprintf(dummy, "%c) ",I2A(ctr));
7251 strcat(dummy, essence_info[num[ctr]].add_name);
7256 if (essence_info[num[ctr]].link)
7258 strcat(dummy, format("(%s)", essence_info[essence_info[num[ctr]].link-1].drain_name));
7259 if (p_ptr->magic_num1[essence_info[num[ctr]].link-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7265 case ESSENCE_SH_FIRE:
7267 strcat(dummy, "(¾Æ´þ+ÂѲбê) ");
7269 strcat(dummy, "(brand fire + res.fire) ");
7271 if (p_ptr->magic_num1[ESSENCE_B_FIRE-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7272 if (p_ptr->magic_num1[ESSENCE_RES_FIRE-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7274 case ESSENCE_SH_ELEC:
7276 strcat(dummy, "(ÅÅ·â+ÂÑÅÅ·â) ");
7278 strcat(dummy, "(brand elec. + res. elec.) ");
7280 if (p_ptr->magic_num1[ESSENCE_B_ELEC-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7281 if (p_ptr->magic_num1[ESSENCE_RES_ELEC-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7283 case ESSENCE_SH_COLD:
7285 strcat(dummy, "(Åà·ë+ÂÑÎ䵤) ");
7287 strcat(dummy, "(brand cold + res. cold) ");
7289 if (p_ptr->magic_num1[ESSENCE_B_COLD-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7290 if (p_ptr->magic_num1[ESSENCE_RES_COLD-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7292 case ESSENCE_RESISTANCE:
7294 strcat(dummy, "(ÂѲбê+ÂÑÎ䵤+ÂÑÅÅ·â+ÂÑ»À)");
7296 strcat(dummy, "(r.fire+r.cold+r.elec+r.acid)");
7298 if (p_ptr->magic_num1[ESSENCE_RES_FIRE-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7299 if (p_ptr->magic_num1[ESSENCE_RES_COLD-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7300 if (p_ptr->magic_num1[ESSENCE_RES_ELEC-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7301 if (p_ptr->magic_num1[ESSENCE_RES_ACID-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7303 case ESSENCE_SUSTAIN:
7305 strcat(dummy, "(ÂѲбê+ÂÑÎ䵤+ÂÑÅÅ·â+ÂÑ»À)");
7307 strcat(dummy, "(r.fire+r.cold+r.elec+r.acid)");
7309 if (p_ptr->magic_num1[ESSENCE_RES_FIRE-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7310 if (p_ptr->magic_num1[ESSENCE_RES_COLD-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7311 if (p_ptr->magic_num1[ESSENCE_RES_ELEC-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7312 if (p_ptr->magic_num1[ESSENCE_RES_ACID-1] < essence_info[num[ctr]].value) able[ctr] = FALSE;
7317 if (!able[ctr]) col = TERM_RED;
7319 strcpy(dummy2, format("%-50s",dummy));
7321 if (essence_info[num[ctr]].link)
7323 strcat(dummy2, format(" %d/%d",essence_info[num[ctr]].value, p_ptr->magic_num1[essence_info[num[ctr]].link-1]));
7327 strcat(dummy2, format(" %d/(\?\?)",essence_info[num[ctr]].value));
7330 c_prt(col, dummy2, ctr+2, x);
7340 /* Restore the screen */
7351 ask = (isupper(choice));
7354 if (ask) choice = tolower(choice);
7356 /* Extract request */
7357 i = (islower(choice) ? A2I(choice) : -1);
7360 /* Totally Illegal */
7361 if ((i < 0) || (i >= max_num) || !able[i])
7374 (void) strnfmt(tmp_val, 78, "%s¤òÉղä·¤Þ¤¹¤«¡© ", essence_info[num[i]].add_name);
7376 (void) strnfmt(tmp_val, 78, "Add the abilitiy of %s? ", essence_info[num[i]].add_name);
7379 /* Belay that order */
7380 if (!get_check(tmp_val)) continue;
7387 /* Restore the screen */
7388 if (redraw) screen_load();
7395 #endif /* ALLOW_REPEAT */
7397 if (num[i] == ESSENCE_SLAY_GLOVE-1)
7398 item_tester_tval = TV_GLOVES;
7400 item_tester_hook = item_tester_hook_melee_ammo;
7401 else if (num[i] == ESSENCE_ATTACK-1)
7402 item_tester_hook = item_tester_hook_weapon;
7403 else if (num[i] == ESSENCE_AC-1)
7404 item_tester_hook = item_tester_hook_armour;
7406 item_tester_hook = item_tester_hook_weapon_armour;
7407 item_tester_no_ryoute = TRUE;
7411 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò²þÎɤ·¤Þ¤¹¤«¡©";
7412 s = "²þÎɤǤ¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
7414 q = "Improve which item? ";
7415 s = "You have nothing to improve.";
7418 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
7420 /* Get the item (in the pack) */
7423 o_ptr = &inventory[item];
7426 /* Get the item (on the floor) */
7429 o_ptr = &o_list[0 - item];
7432 if ((mode != 6) && (o_ptr->name1 || o_ptr->art_name || o_ptr->xtra3))
7435 msg_print("¤½¤Î¥¢¥¤¥Æ¥à¤Ï¤³¤ì°Ê¾å²þÎɤǤ¤Ê¤¤¡£");
7437 msg_print("This item is no more able to be improved");
7442 object_desc(o_name, o_ptr, FALSE, 0);
7444 use_essence = essence_info[num[i]].value;
7445 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) use_essence = (use_essence+9)/10;
7446 if (o_ptr->number > 1)
7448 use_essence *= o_ptr->number;
7450 msg_format("%d¸Ä¤¢¤ë¤Î¤Ç¥¨¥Ã¥»¥ó¥¹¤Ï%dɬÍפǤ¹¡£", o_ptr->number, use_essence);
7452 msg_format("It will take %d essences.",use_essence);
7457 if (essence_info[num[i]].link)
7459 if (p_ptr->magic_num1[essence_info[num[i]].link-1] < use_essence)
7462 msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â¤ê¤Ê¤¤¡£");
7464 msg_print("You don't have enough essences.");
7468 if ((num[i] < 32) && is_pval_flag(num[i]))
7470 if (num[i] == ESSENCE_BLOWS-1)
7472 if (o_ptr->pval > 1)
7475 if (!get_check("½¤ÀµÃͤÏ1¤Ë¤Ê¤ê¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) return;
7477 if (!get_check("The magic number of this weapon will become 1. Are you sure? ")) return;
7482 else if (o_ptr->pval)
7484 use_essence *= o_ptr->pval;
7486 msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
7488 msg_format("It will take %d essences.",use_essence);
7496 int limit = MIN(5, p_ptr->magic_num1[essence_info[num[i]].link-1]/essence_info[num[i]].value);
7500 sprintf(tmp, "¤¤¤¯¤ÄÉղä·¤Þ¤¹¤«¡© (1-%d): ", limit);
7502 sprintf(tmp, "Enchant how many? (1-%d): ", limit);
7504 strcpy(tmp_val, "1");
7506 if (!get_string(tmp, tmp_val, 1)) return;
7507 pval = atoi(tmp_val);
7508 if (pval > limit) pval = limit;
7509 else if (pval < 1) pval = 1;
7511 use_essence *= pval;
7513 msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
7515 msg_format("It will take %d essences.",use_essence);
7518 if (p_ptr->magic_num1[essence_info[num[i]].link-1] < use_essence)
7521 msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â¤ê¤Ê¤¤¡£");
7523 msg_print("You don't have enough essences.");
7528 else if (num[i] == ESSENCE_SLAY_GLOVE-1)
7532 int get_to_h, get_to_d;
7534 strcpy(tmp_val, "1");
7536 if (!get_string(format("¤¤¤¯¤ÄÉղä·¤Þ¤¹¤«¡© (1-%d):", p_ptr->lev/7+3), tmp_val, 2)) return;
7538 if (!get_string(format("Enchant how many? (1-%d):", p_ptr->lev/7+3), tmp_val, 2)) return;
7540 val = atoi(tmp_val);
7541 if (val > p_ptr->lev/7+3) val = p_ptr->lev/7+3;
7542 else if (val < 1) val = 1;
7545 msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
7547 msg_format("It will take %d essences.",use_essence);
7549 if (p_ptr->magic_num1[essence_info[num[i]].link-1] < use_essence)
7552 msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â¤ê¤Ê¤¤¡£");
7554 msg_print("You don't have enough essences");
7558 get_to_h = ((val+1)/2+randint0(val/2+1));
7559 get_to_d = ((val+1)/2+randint0(val/2+1));
7560 o_ptr->xtra4 = (get_to_h<<8)+get_to_d;
7561 o_ptr->to_h += get_to_h;
7562 o_ptr->to_d += get_to_d;
7564 p_ptr->magic_num1[essence_info[num[i]].link-1] -= use_essence;
7565 if (num[i] == ESSENCE_ATTACK-1)
7567 if ((o_ptr->to_h >= p_ptr->lev/5+5) && (o_ptr->to_d >= p_ptr->lev/5+5))
7570 msg_print("²þÎɤ˼ºÇÔ¤·¤¿¡£");
7572 msg_print("You failed to enchant.");
7579 if (o_ptr->to_h < p_ptr->lev/5+5) o_ptr->to_h++;
7580 if (o_ptr->to_d < p_ptr->lev/5+5) o_ptr->to_d++;
7583 else if (num[i] == ESSENCE_AC-1)
7585 if (o_ptr->to_a >= p_ptr->lev/5+5)
7588 msg_print("²þÎɤ˼ºÇÔ¤·¤¿¡£");
7590 msg_print("You failed to enchant.");
7597 if (o_ptr->to_a < p_ptr->lev/5+5) o_ptr->to_a++;
7602 o_ptr->xtra3 = num[i]+1;
7607 bool success = TRUE;
7611 case ESSENCE_SH_FIRE:
7612 if ((p_ptr->magic_num1[ESSENCE_B_FIRE-1] < use_essence) || (p_ptr->magic_num1[ESSENCE_RES_FIRE-1] < use_essence))
7617 p_ptr->magic_num1[ESSENCE_B_FIRE-1] -= use_essence;
7618 p_ptr->magic_num1[ESSENCE_RES_FIRE-1] -= use_essence;
7620 case ESSENCE_SH_ELEC:
7621 if ((p_ptr->magic_num1[ESSENCE_B_ELEC-1] < use_essence) || (p_ptr->magic_num1[ESSENCE_RES_ELEC-1] < use_essence))
7626 p_ptr->magic_num1[ESSENCE_B_ELEC-1] -= use_essence;
7627 p_ptr->magic_num1[ESSENCE_RES_ELEC-1] -= use_essence;
7629 case ESSENCE_SH_COLD:
7630 if ((p_ptr->magic_num1[ESSENCE_B_COLD-1] < use_essence) || (p_ptr->magic_num1[ESSENCE_RES_COLD-1] < use_essence))
7635 p_ptr->magic_num1[ESSENCE_B_COLD-1] -= use_essence;
7636 p_ptr->magic_num1[ESSENCE_RES_COLD-1] -= use_essence;
7638 case ESSENCE_RESISTANCE:
7639 case ESSENCE_SUSTAIN:
7640 if ((p_ptr->magic_num1[ESSENCE_RES_ACID-1] < use_essence) || (p_ptr->magic_num1[ESSENCE_RES_ELEC-1] < use_essence) || (p_ptr->magic_num1[ESSENCE_RES_FIRE-1] < use_essence) || (p_ptr->magic_num1[ESSENCE_RES_COLD-1] < use_essence))
7645 p_ptr->magic_num1[ESSENCE_RES_ACID-1] -= use_essence;
7646 p_ptr->magic_num1[ESSENCE_RES_ELEC-1] -= use_essence;
7647 p_ptr->magic_num1[ESSENCE_RES_FIRE-1] -= use_essence;
7648 p_ptr->magic_num1[ESSENCE_RES_COLD-1] -= use_essence;
7654 msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â¤ê¤Ê¤¤¡£");
7656 msg_print("You don't have enough essences");
7660 if (num[i] == ESSENCE_SUSTAIN-1)
7662 add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
7663 add_flag(o_ptr->art_flags, TR_IGNORE_ELEC);
7664 add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
7665 add_flag(o_ptr->art_flags, TR_IGNORE_COLD);
7667 else o_ptr->xtra3 = num[i]+1;
7673 msg_format("%s¤Ë%s¤ÎǽÎϤòÉղä·¤Þ¤·¤¿¡£", o_name, essence_info[num[i]].add_name);
7675 msg_format("You have added ability of %s to %s.", essence_info[num[i]].add_name, o_name);
7678 /* Combine the pack */
7679 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
7682 p_ptr->window |= (PW_INVEN);
7686 static bool item_tester_hook_kaji(object_type *o_ptr)
7688 switch (o_ptr->tval)
7708 if (o_ptr->xtra3) return (TRUE);
7716 static void erase_essence(void)
7721 char o_name[MAX_NLEN];
7722 u32b flgs[TR_FLAG_SIZE];
7724 item_tester_hook = item_tester_hook_kaji;
7728 q = "¤É¤Î¥¢¥¤¥Æ¥à¤Î¥¨¥Ã¥»¥ó¥¹¤ò¾Ãµî¤·¤Þ¤¹¤«¡©";
7729 s = "¥¨¥Ã¥»¥ó¥¹¤òÉղä·¤¿¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
7731 q = "Remove from which item? ";
7732 s = "You have nothing to remove essence.";
7735 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
7737 /* Get the item (in the pack) */
7740 o_ptr = &inventory[item];
7743 /* Get the item (on the floor) */
7746 o_ptr = &o_list[0 - item];
7749 object_desc(o_name, o_ptr, FALSE, 0);
7751 if (!get_check(format("¤è¤í¤·¤¤¤Ç¤¹¤«¡©[%s]", o_name))) return;
7753 if (!get_check(format("Are you sure?[%s]", o_name))) return;
7758 if (o_ptr->xtra3 == ESSENCE_SLAY_GLOVE)
7760 o_ptr->to_h -= (o_ptr->xtra4>>8);
7761 o_ptr->to_d -= (o_ptr->xtra4 & 0x000f);
7765 object_flags(o_ptr, flgs);
7766 if (!(have_pval_flags(flgs))) o_ptr->pval = 0;
7768 msg_print("¥¨¥Ã¥»¥ó¥¹¤ò¼è¤êµî¤Ã¤¿¡£");
7770 msg_print("You removed all essence you have added");
7773 /* Combine the pack */
7774 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
7777 p_ptr->window |= (PW_INVEN);
7780 void do_cmd_kaji(bool only_browse)
7785 int menu_line = (use_menu ? 1 : 0);
7789 if (p_ptr->confused)
7792 msg_print("º®Í𤷤Ƥ¤¤Æºî¶È¤Ç¤¤Ê¤¤¡ª");
7794 msg_print("You are too confused!");
7802 msg_print("Ìܤ¬¸«¤¨¤Ê¤¯¤Æºî¶È¤Ç¤¤Ê¤¤¡ª");
7804 msg_print("You are blind!");
7812 msg_print("¤¦¤Þ¤¯¸«¤¨¤Ê¤¯¤Æºî¶È¤Ç¤¤Ê¤¤¡ª");
7814 msg_print("You are hullcinating!");
7822 if (!(repeat_pull(&mode) && 1 <= mode && mode <= 5))
7824 #endif /* ALLOW_REPEAT */
7826 if (only_browse) screen_save();
7828 if (!only_browse) screen_save();
7834 prt(format(" %s ¥¨¥Ã¥»¥ó¥¹°ìÍ÷", (menu_line == 1) ? "¡Õ" : " "), 2, 14);
7835 prt(format(" %s ¥¨¥Ã¥»¥ó¥¹Ãê½Ð", (menu_line == 2) ? "¡Õ" : " "), 3, 14);
7836 prt(format(" %s ¥¨¥Ã¥»¥ó¥¹¾Ãµî", (menu_line == 3) ? "¡Õ" : " "), 4, 14);
7837 prt(format(" %s ¥¨¥Ã¥»¥ó¥¹ÉÕ²Ã", (menu_line == 4) ? "¡Õ" : " "), 5, 14);
7838 prt(format(" %s Éð´ï/Ëɶñ¶¯²½", (menu_line == 5) ? "¡Õ" : " "), 6, 14);
7839 prt(format("¤É¤Î¼ïÎà¤Îµ»½Ñ¤ò%s¤Þ¤¹¤«¡©", only_browse ? "Ä´¤Ù" : "»È¤¤"), 0, 0);
7841 prt(format(" %s List essences", (menu_line == 1) ? "> " : " "), 2, 14);
7842 prt(format(" %s Extract essence", (menu_line == 2) ? "> " : " "), 3, 14);
7843 prt(format(" %s Remove essence", (menu_line == 3) ? "> " : " "), 4, 14);
7844 prt(format(" %s Add essence", (menu_line == 4) ? "> " : " "), 5, 14);
7845 prt(format(" %s Enchant weapon/armor", (menu_line == 5) ? "> " : " "), 6, 14);
7846 prt(format("Choose command from menu."), 0, 0);
7873 if (menu_line > 5) menu_line -= 5;
7882 prt(" a) ¥¨¥Ã¥»¥ó¥¹°ìÍ÷", 2, 14);
7883 prt(" b) ¥¨¥Ã¥»¥ó¥¹Ãê½Ð", 3, 14);
7884 prt(" c) ¥¨¥Ã¥»¥ó¥¹¾Ãµî", 4, 14);
7885 prt(" d) ¥¨¥Ã¥»¥ó¥¹ÉÕ²Ã", 5, 14);
7886 prt(" e) Éð´ï/Ëɶñ¶¯²½", 6, 14);
7887 if (!get_com(format("¤É¤ÎǽÎϤò%s¤Þ¤¹¤«:", only_browse ? "Ä´¤Ù" : "»È¤¤"), &choice, TRUE))
7889 prt(" a) List essences", 2, 14);
7890 prt(" b) Extract essence", 3, 14);
7891 prt(" c) Remove essence", 4, 14);
7892 prt(" d) Add essence", 5, 14);
7893 prt(" e) Enchant weapon/armor", 6, 14);
7894 if (!get_com("Command :", &choice, TRUE))
7931 /* Clear lines, position cursor (really should use strlen here) */
7932 Term_erase(14, 21, 255);
7933 Term_erase(14, 20, 255);
7934 Term_erase(14, 19, 255);
7935 Term_erase(14, 18, 255);
7936 Term_erase(14, 17, 255);
7937 Term_erase(14, 16, 255);
7939 roff_to_buf( kaji_tips[mode-1],62,temp);
7940 for(j=0, line = 17;temp[j];j+=(1+strlen(&temp[j])))
7942 prt(&temp[j], line, 15);
7947 if (!only_browse) screen_load();
7948 } while (only_browse);
7952 #endif /* ALLOW_REPEAT */
7956 case 1: display_essence();break;
7957 case 2: drain_essence();break;
7958 case 3: erase_essence();break;
7960 mode = choose_essence();
7965 case 5: add_essence(6);break;