4 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
15 * Excise a dungeon object from any stacks
17 void excise_object_idx(int o_idx
)
21 s16b this_o_idx
, next_o_idx
= 0;
27 j_ptr
= &o_list
[o_idx
];
30 if (j_ptr
->held_m_idx
)
35 m_ptr
= &mon_list
[j_ptr
->held_m_idx
];
37 /* Scan all objects in the grid */
38 for (this_o_idx
= m_ptr
->hold_o_idx
; this_o_idx
; this_o_idx
= next_o_idx
)
43 o_ptr
= &o_list
[this_o_idx
];
45 /* Get the next object */
46 next_o_idx
= o_ptr
->next_o_idx
;
49 if (this_o_idx
== o_idx
)
54 /* Remove from list */
55 m_ptr
->hold_o_idx
= next_o_idx
;
64 i_ptr
= &o_list
[prev_o_idx
];
66 /* Remove from list */
67 i_ptr
->next_o_idx
= next_o_idx
;
70 /* Forget next pointer */
71 o_ptr
->next_o_idx
= 0;
78 prev_o_idx
= this_o_idx
;
88 /* Scan all objects in the grid */
89 for (this_o_idx
= cave_o_idx
[y
][x
]; this_o_idx
; this_o_idx
= next_o_idx
)
94 o_ptr
= &o_list
[this_o_idx
];
96 /* Get the next object */
97 next_o_idx
= o_ptr
->next_o_idx
;
100 if (this_o_idx
== o_idx
)
105 /* Remove from list */
106 cave_o_idx
[y
][x
] = next_o_idx
;
114 /* Previous object */
115 i_ptr
= &o_list
[prev_o_idx
];
117 /* Remove from list */
118 i_ptr
->next_o_idx
= next_o_idx
;
121 /* Forget next pointer */
122 o_ptr
->next_o_idx
= 0;
128 /* Save prev_o_idx */
129 prev_o_idx
= this_o_idx
;
136 * Delete a dungeon object
138 * Handle "stacks" of objects correctly.
140 void delete_object_idx(int o_idx
)
145 excise_object_idx(o_idx
);
148 j_ptr
= &o_list
[o_idx
];
151 if (!(j_ptr
->held_m_idx
))
163 /* Wipe the object */
172 * Deletes all objects at given location
174 void delete_object(int y
, int x
)
176 s16b this_o_idx
, next_o_idx
= 0;
180 if (!in_bounds(y
, x
)) return;
183 /* Scan all objects in the grid */
184 for (this_o_idx
= cave_o_idx
[y
][x
]; this_o_idx
; this_o_idx
= next_o_idx
)
189 o_ptr
= &o_list
[this_o_idx
];
191 /* Get the next object */
192 next_o_idx
= o_ptr
->next_o_idx
;
194 /* Wipe the object */
201 /* Objects are gone */
202 cave_o_idx
[y
][x
] = 0;
211 * Move an object from index i1 to index i2 in the object list
213 static void compact_objects_aux(int i1
, int i2
)
221 if (i1
== i2
) return;
225 for (i
= 1; i
< o_max
; i
++)
230 /* Skip "dead" objects */
231 if (!o_ptr
->k_idx
) continue;
233 /* Repair "next" pointers */
234 if (o_ptr
->next_o_idx
== i1
)
237 o_ptr
->next_o_idx
= i2
;
247 if (o_ptr
->held_m_idx
)
251 /* Get the monster */
252 m_ptr
= &mon_list
[o_ptr
->held_m_idx
];
255 if (m_ptr
->hold_o_idx
== i1
)
258 m_ptr
->hold_o_idx
= i2
;
272 if (cave_o_idx
[y
][x
] == i1
)
275 cave_o_idx
[y
][x
] = i2
;
280 /* Hack -- move object */
281 COPY(&o_list
[i2
], &o_list
[i1
], object_type
);
283 /* Hack -- wipe hole */
289 * Compact and reorder the object list
291 * This function can be very dangerous, use with caution!
293 * When compacting objects, we first destroy gold, on the basis that by the
294 * time item compaction becomes an issue, the player really won't care.
295 * We also nuke items marked as squelch.
297 * When compacting other objects, we base the saving throw on a combination of
298 * object level, distance from player, and current "desperation".
300 * After compacting, we "reorder" the objects into a more compact order, and we
301 * reset the allocation info, and the "live" array.
303 void compact_objects(int size
)
310 int cur_lev
, cur_dis
, chance
;
313 /* Reorder objects when not passed a size */
316 /* Excise dead objects (backwards!) */
317 for (i
= o_max
- 1; i
>= 1; i
--)
319 object_type
*o_ptr
= &o_list
[i
];
321 /* Skip real objects */
322 if (o_ptr
->k_idx
) continue;
324 /* Move last object into open hole */
325 compact_objects_aux(o_max
- 1, i
);
327 /* Compress "o_max" */
336 msg_print("Compacting objects...");
339 p_ptr
->redraw
|= (PR_MAP
);
342 p_ptr
->window
|= (PW_OVERHEAD
| PW_MAP
);
347 /*** Try destroying objects ***/
350 for (i
= 1; (i
< o_max
) && (size
); i
++)
352 object_type
*o_ptr
= &o_list
[i
];
354 /* Nuke gold or squelched items */
355 if (o_ptr
->tval
== TV_GOLD
|| squelch_item_ok(o_ptr
))
357 delete_object_idx(i
);
363 /* Compact at least 'size' objects */
364 for (cnt
= 1; size
; cnt
++)
366 /* Get more vicious each iteration */
369 /* Get closer each iteration */
370 cur_dis
= 5 * (20 - cnt
);
372 /* Examine the objects */
373 for (i
= 1; (i
< o_max
) && (size
); i
++)
375 object_type
*o_ptr
= &o_list
[i
];
376 object_kind
*k_ptr
= &k_info
[o_ptr
->k_idx
];
378 /* Skip dead objects */
379 if (!o_ptr
->k_idx
) continue;
381 /* Hack -- High level objects start out "immune" */
382 if (k_ptr
->level
> cur_lev
&& !k_ptr
->squelch
)
386 if (o_ptr
->held_m_idx
)
390 /* Get the monster */
391 m_ptr
= &mon_list
[o_ptr
->held_m_idx
];
393 /* Get the location */
397 /* Monsters protect their objects */
398 if ((rand_int(100) < 90) && !k_ptr
->squelch
)
405 /* Get the location */
410 /* Nearby objects start out "immune" */
411 if ((cur_dis
> 0) && (distance(py
, px
, y
, x
) < cur_dis
) && !k_ptr
->squelch
)
418 /* Hack -- only compact artifacts in emergencies */
419 if (artifact_p(o_ptr
) && (cnt
< 1000)) chance
= 100;
421 /* Apply the saving throw */
422 if (rand_int(100) < chance
) continue;
424 /* Delete the object */
425 delete_object_idx(i
);
431 /* Reorder objects */
439 * Delete all the items when player leaves the level
441 * Note -- we do NOT visually reflect these (irrelevant) changes
443 * Hack -- we clear the "cave_o_idx[y][x]" field for every grid,
444 * and the "m_ptr->next_o_idx" field for every monster, since
445 * we know we are clearing every object. Technically, we only
446 * clear those fields for grids/monsters containing objects,
447 * and we clear it once for every such object.
449 void wipe_o_list(void)
453 /* Delete the existing objects */
454 for (i
= 1; i
< o_max
; i
++)
456 object_type
*o_ptr
= &o_list
[i
];
458 /* Skip dead objects */
459 if (!o_ptr
->k_idx
) continue;
461 /* Preserve artifacts */
462 if (!character_dungeon
|| !adult_no_preserve
)
464 /* Preserve only unknown artifacts */
465 if (artifact_p(o_ptr
) && !object_known_p(o_ptr
))
466 a_info
[o_ptr
->name1
].cur_num
= 0;
470 if (o_ptr
->held_m_idx
)
475 m_ptr
= &mon_list
[o_ptr
->held_m_idx
];
477 /* Hack -- see above */
478 m_ptr
->hold_o_idx
= 0;
484 /* Get the location */
488 /* Hack -- see above */
489 cave_o_idx
[y
][x
] = 0;
492 /* Wipe the object */
493 (void)WIPE(o_ptr
, object_type
);
505 * Get and return the index of a "free" object.
507 * This routine should almost never fail, but in case it does,
508 * we must be sure to handle "failure" of this routine.
515 /* Initial allocation */
516 if (o_max
< z_info
->o_max
)
521 /* Expand object array */
527 /* Use this object */
532 /* Recycle dead objects */
533 for (i
= 1; i
< o_max
; i
++)
540 /* Skip live objects */
541 if (o_ptr
->k_idx
) continue;
546 /* Use this object */
551 /* Warn the player (except during dungeon creation) */
552 if (character_dungeon
) msg_print("Too many objects!");
560 * Get the first object at a dungeon location
561 * or NULL if there isn't one.
563 object_type
* get_first_object(int y
, int x
)
565 s16b o_idx
= cave_o_idx
[y
][x
];
567 if (o_idx
) return (&o_list
[o_idx
]);
575 * Get the next object in a stack or
576 * NULL if there isn't one.
578 object_type
* get_next_object(const object_type
*o_ptr
)
580 if (o_ptr
->next_o_idx
) return (&o_list
[o_ptr
->next_o_idx
]);
582 /* No more objects */
588 * Apply a "object restriction function" to the "object allocation table"
590 errr
get_obj_num_prep(void)
595 alloc_entry
*table
= alloc_kind_table
;
597 /* Scan the allocation table */
598 for (i
= 0; i
< alloc_kind_size
; i
++)
600 /* Accept objects which pass the restriction, if any */
601 if (!get_obj_num_hook
|| (*get_obj_num_hook
)(table
[i
].index
))
603 /* Accept this object */
604 table
[i
].prob2
= table
[i
].prob1
;
607 /* Do not use this object */
610 /* Decline this object */
622 * Choose an object kind that seems "appropriate" to the given level
624 * This function uses the "prob2" field of the "object allocation table",
625 * and various local information, to calculate the "prob3" field of the
626 * same table, which is then used to choose an "appropriate" object, in
627 * a relatively efficient manner.
629 * It is (slightly) more likely to acquire an object of the given level
630 * than one of a lower level. This is done by choosing several objects
631 * appropriate to the given level and keeping the "hardest" one.
633 * Note that if no objects are "appropriate", then this function will
634 * fail, and return zero, but this should *almost* never happen.
636 s16b
get_obj_num(int level
)
646 alloc_entry
*table
= alloc_kind_table
;
652 /* Occasional "boost" */
653 if (rand_int(GREAT_OBJ
) == 0)
655 /* What a bizarre calculation */
656 level
= 1 + (level
* MAX_DEPTH
/ randint(MAX_DEPTH
));
664 /* Process probabilities */
665 for (i
= 0; i
< alloc_kind_size
; i
++)
667 /* Objects are sorted by depth */
668 if (table
[i
].level
> level
) break;
674 k_idx
= table
[i
].index
;
676 /* Get the actual kind */
677 k_ptr
= &k_info
[k_idx
];
679 /* Hack -- prevent embedded chests */
680 if (opening_chest
&& (k_ptr
->tval
== TV_CHEST
)) continue;
683 table
[i
].prob3
= table
[i
].prob2
;
686 total
+= table
[i
].prob3
;
689 /* No legal objects */
690 if (total
<= 0) return (0);
694 value
= rand_int(total
);
696 /* Find the object */
697 for (i
= 0; i
< alloc_kind_size
; i
++)
699 /* Found the entry */
700 if (value
< table
[i
].prob3
) break;
703 value
= value
- table
[i
].prob3
;
710 /* Try for a "better" object once (50%) or twice (10%) */
717 value
= rand_int(total
);
719 /* Find the monster */
720 for (i
= 0; i
< alloc_kind_size
; i
++)
722 /* Found the entry */
723 if (value
< table
[i
].prob3
) break;
726 value
= value
- table
[i
].prob3
;
729 /* Keep the "best" one */
730 if (table
[i
].level
< table
[j
].level
) i
= j
;
733 /* Try for a "better" object twice (10%) */
740 value
= rand_int(total
);
742 /* Find the object */
743 for (i
= 0; i
< alloc_kind_size
; i
++)
745 /* Found the entry */
746 if (value
< table
[i
].prob3
) break;
749 value
= value
- table
[i
].prob3
;
752 /* Keep the "best" one */
753 if (table
[i
].level
< table
[j
].level
) i
= j
;
758 return (table
[i
].index
);
769 * Known is true when the "attributes" of an object are "known".
771 * These attributes include tohit, todam, toac, cost, and pval (charges).
773 * Note that "knowing" an object gives you everything that an "awareness"
774 * gives you, and much more. In fact, the player is always "aware" of any
775 * item which he "knows", except items in stores.
777 * But having knowledge of, say, one "wand of wonder", does not, by itself,
778 * give you knowledge, or even awareness, of other "wands of wonder".
779 * It happens that most "identify" routines (including "buying from a shop")
780 * will make the player "aware" of the object as well as "know" it.
782 * This routine also removes any inscriptions generated by "feelings".
784 void object_known(object_type
*o_ptr
)
786 /* Remove special inscription, if any */
787 if (o_ptr
->pseudo
) o_ptr
->pseudo
= 0;
789 /* The object is not "sensed" */
790 o_ptr
->ident
&= ~(IDENT_SENSE
);
792 /* Clear the "Empty" info */
793 o_ptr
->ident
&= ~(IDENT_EMPTY
);
795 /* Now we know about the item */
796 o_ptr
->ident
|= (IDENT_KNOWN
);
804 * The player is now aware of the effects of the given object.
806 void object_aware(object_type
*o_ptr
)
808 /* Fully aware of the effects */
809 k_info
[o_ptr
->k_idx
].aware
= TRUE
;
811 /* Scrolls can change the graphics when becoming aware */
812 if (o_ptr
->tval
== TV_SCROLL
)
815 p_ptr
->redraw
|= (PR_MAP
);
818 p_ptr
->window
|= (PW_OVERHEAD
| PW_MAP
);
825 * Something has been "sampled"
827 void object_tried(object_type
*o_ptr
)
829 /* Mark it as tried (even if "aware") */
830 k_info
[o_ptr
->k_idx
].tried
= TRUE
;
835 * Determine if a weapon is 'blessed'
837 bool is_blessed(const object_type
*o_ptr
)
842 object_flags(o_ptr
, &f1
, &f2
, &f3
);
844 /* Is the object blessed? */
845 return ((f3
& TR3_BLESSED
) ? TRUE
: FALSE
);
851 * Return the "value" of an "unknown" item
852 * Make a guess at the value of non-aware items
854 static s32b
object_value_base(const object_type
*o_ptr
)
856 object_kind
*k_ptr
= &k_info
[o_ptr
->k_idx
];
858 /* Use template cost for aware objects */
859 if (object_aware_p(o_ptr
)) return (k_ptr
->cost
);
861 /* Analyze the type */
865 case TV_FOOD
: return (5L);
867 /* Un-aware Potions */
868 case TV_POTION
: return (20L);
870 /* Un-aware Scrolls */
871 case TV_SCROLL
: return (20L);
873 /* Un-aware Staffs */
874 case TV_STAFF
: return (70L);
877 case TV_WAND
: return (50L);
880 case TV_ROD
: return (90L);
883 case TV_RING
: return (45L);
885 /* Un-aware Amulets */
886 case TV_AMULET
: return (45L);
889 /* Paranoia -- Oops */
895 * Return the "real" price of a "known" item, not including discounts.
897 * Wand and staffs get cost for each charge.
899 * Armor is worth an extra 100 gold per bonus point to armor class.
901 * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).
903 * Missiles are only worth 5 gold per bonus point, since they
904 * usually appear in groups of 20, and we want the player to get
905 * the same amount of cash for any "equivalent" item. Note that
906 * missiles never have any of the "pval" flags, and in fact, they
907 * only have a few of the available flags, primarily of the "slay"
908 * and "brand" and "ignore" variety.
910 * Weapons with negative hit+damage bonuses are worthless.
912 * Every wearable item with a "pval" bonus is worth extra (see below).
914 static s32b
object_value_real(const object_type
*o_ptr
)
920 object_kind
*k_ptr
= &k_info
[o_ptr
->k_idx
];
923 /* Hack -- "worthless" items */
924 if (!k_ptr
->cost
) return (0L);
930 /* Extract some flags */
931 object_flags(o_ptr
, &f1
, &f2
, &f3
);
937 artifact_type
*a_ptr
= &a_info
[o_ptr
->name1
];
939 /* Hack -- "worthless" artifacts */
940 if (!a_ptr
->cost
) return (0L);
942 /* Hack -- Use the artifact cost instead */
947 else if (o_ptr
->name2
)
949 ego_item_type
*e_ptr
= &e_info
[o_ptr
->name2
];
951 /* Hack -- "worthless" ego-items */
952 if (!e_ptr
->cost
) return (0L);
954 /* Hack -- Reward the ego-item with a bonus */
955 value
+= e_ptr
->cost
;
959 /* Analyze pval bonus */
983 /* Hack -- Negative "pval" is always bad */
984 if (o_ptr
->pval
< 0) return (0L);
987 if (!o_ptr
->pval
) break;
989 /* Give credit for stat bonuses */
990 if (f1
& (TR1_STR
)) value
+= (o_ptr
->pval
* 200L);
991 if (f1
& (TR1_INT
)) value
+= (o_ptr
->pval
* 200L);
992 if (f1
& (TR1_WIS
)) value
+= (o_ptr
->pval
* 200L);
993 if (f1
& (TR1_DEX
)) value
+= (o_ptr
->pval
* 200L);
994 if (f1
& (TR1_CON
)) value
+= (o_ptr
->pval
* 200L);
995 if (f1
& (TR1_CHR
)) value
+= (o_ptr
->pval
* 200L);
997 /* Give credit for stealth and searching */
998 if (f1
& (TR1_STEALTH
)) value
+= (o_ptr
->pval
* 100L);
999 if (f1
& (TR1_SEARCH
)) value
+= (o_ptr
->pval
* 100L);
1001 /* Give credit for infra-vision and tunneling */
1002 if (f1
& (TR1_INFRA
)) value
+= (o_ptr
->pval
* 50L);
1003 if (f1
& (TR1_TUNNEL
)) value
+= (o_ptr
->pval
* 50L);
1005 /* Give credit for extra attacks */
1006 if (f1
& (TR1_BLOWS
)) value
+= (o_ptr
->pval
* 2000L);
1008 /* Give credit for speed bonus */
1009 if (f1
& (TR1_SPEED
)) value
+= (o_ptr
->pval
* 30000L);
1016 /* Analyze the item */
1017 switch (o_ptr
->tval
)
1023 /* Pay extra for charges, depending on standard number of charges */
1024 value
+= ((value
/ 20) * (o_ptr
->pval
/ o_ptr
->number
));
1030 /* Rings/Amulets, Lites */
1034 /* Hack -- negative bonuses are bad */
1035 if (o_ptr
->to_a
< 0) return (0L);
1036 if (o_ptr
->to_h
< 0) return (0L);
1037 if (o_ptr
->to_d
< 0) return (0L);
1039 /* Give credit for bonuses */
1040 value
+= ((o_ptr
->to_h
+ o_ptr
->to_d
+ o_ptr
->to_a
) * 100L);
1057 /* Give credit for hit bonus */
1058 value
+= ((o_ptr
->to_h
- k_ptr
->to_h
) * 100L);
1060 /* Give credit for damage bonus */
1061 value
+= ((o_ptr
->to_d
- k_ptr
->to_d
) * 100L);
1063 /* Give credit for armor bonus */
1064 value
+= (o_ptr
->to_a
* 100L);
1077 /* Hack -- negative hit/damage bonuses */
1078 if (o_ptr
->to_h
+ o_ptr
->to_d
< 0) return (0L);
1080 /* Factor in the bonuses */
1081 value
+= ((o_ptr
->to_h
+ o_ptr
->to_d
+ o_ptr
->to_a
) * 100L);
1083 /* Hack -- Factor in extra damage dice */
1084 if ((o_ptr
->dd
> k_ptr
->dd
) && (o_ptr
->ds
== k_ptr
->ds
))
1086 value
+= (o_ptr
->dd
- k_ptr
->dd
) * o_ptr
->ds
* 100L;
1098 /* Hack -- negative hit/damage bonuses */
1099 if (o_ptr
->to_h
+ o_ptr
->to_d
< 0) return (0L);
1101 /* Factor in the bonuses */
1102 value
+= ((o_ptr
->to_h
+ o_ptr
->to_d
) * 5L);
1104 /* Hack -- Factor in extra damage dice */
1105 if ((o_ptr
->dd
> k_ptr
->dd
) && (o_ptr
->ds
== k_ptr
->ds
))
1107 value
+= (o_ptr
->dd
- k_ptr
->dd
) * o_ptr
->ds
* 5L;
1115 /* No negative value */
1116 if (value
< 0) value
= 0;
1118 /* Return the value */
1124 * Return the price of an item including plusses (and charges).
1126 * This function returns the "value" of the given item (qty one).
1128 * Never notice "unknown" bonuses or properties, including "curses",
1129 * since that would give the player information he did not have.
1131 * Note that discounted items stay discounted forever.
1133 s32b
object_value(const object_type
*o_ptr
)
1138 /* Unknown items -- acquire a base value */
1139 if (object_known_p(o_ptr
))
1141 /* Broken items -- worthless */
1142 if (broken_p(o_ptr
)) return (0L);
1144 /* Cursed items -- worthless */
1145 if (cursed_p(o_ptr
)) return (0L);
1147 /* Real value (see above) */
1148 value
= object_value_real(o_ptr
);
1151 /* Known items -- acquire the actual value */
1154 /* Hack -- Felt broken items */
1155 if ((o_ptr
->ident
& (IDENT_SENSE
)) && broken_p(o_ptr
)) return (0L);
1157 /* Hack -- Felt cursed items */
1158 if ((o_ptr
->ident
& (IDENT_SENSE
)) && cursed_p(o_ptr
)) return (0L);
1160 /* Base value (see above) */
1161 value
= object_value_base(o_ptr
);
1165 /* Return the final value */
1174 * Determine if an item can "absorb" a second item
1176 * See "object_absorb()" for the actual "absorption" code.
1178 * If permitted, we allow weapons/armor to stack, if "known".
1180 * Missiles will combine if both stacks have the same "known" status.
1181 * This is done to make unidentified stacks of missiles useful.
1183 * Food, potions, scrolls, and "easy know" items always stack.
1185 * Chests, and activatable items, except rods, never stack (for various
1188 bool object_similar(const object_type
*o_ptr
, const object_type
*j_ptr
)
1190 int total
= o_ptr
->number
+ j_ptr
->number
;
1193 /* Require identical object types */
1194 if (o_ptr
->k_idx
!= j_ptr
->k_idx
) return (0);
1197 /* Analyze the items */
1198 switch (o_ptr
->tval
)
1207 /* Food and Potions and Scrolls */
1216 /* Staves and Wands */
1220 /* Require either knowledge or known empty for both wands/staves */
1221 if ((!(o_ptr
->ident
& (IDENT_EMPTY
)) &&
1222 !object_known_p(o_ptr
)) ||
1223 (!(j_ptr
->ident
& (IDENT_EMPTY
)) &&
1224 !object_known_p(j_ptr
))) return(0);
1237 /* Weapons and Armor */
1256 /* Rings, Amulets, Lites */
1261 /* Require both items to be known */
1262 if (!object_known_p(o_ptr
) || !object_known_p(j_ptr
)) return (0);
1272 /* Require identical knowledge of both items */
1273 if (object_known_p(o_ptr
) != object_known_p(j_ptr
)) return (0);
1275 /* Require identical "bonuses" */
1276 if (o_ptr
->to_h
!= j_ptr
->to_h
) return (FALSE
);
1277 if (o_ptr
->to_d
!= j_ptr
->to_d
) return (FALSE
);
1278 if (o_ptr
->to_a
!= j_ptr
->to_a
) return (FALSE
);
1280 /* Require identical "pval" code */
1281 if (o_ptr
->pval
!= j_ptr
->pval
) return (FALSE
);
1283 /* Require identical "artifact" names */
1284 if (o_ptr
->name1
!= j_ptr
->name1
) return (FALSE
);
1286 /* Require identical "ego-item" names */
1287 if (o_ptr
->name2
!= j_ptr
->name2
) return (FALSE
);
1289 /* Hack -- Never stack "powerful" items */
1290 if (o_ptr
->xtra1
|| j_ptr
->xtra1
) return (FALSE
);
1292 /* Hack - Never stack recharging items */
1293 if ((o_ptr
->timeout
|| j_ptr
->timeout
) && o_ptr
->tval
!= TV_LITE
)
1296 /* Lites must have same amount of fuel */
1297 else if(o_ptr
->timeout
!= j_ptr
->timeout
&& o_ptr
->tval
== TV_LITE
)
1300 /* Require identical "values" */
1301 if (o_ptr
->ac
!= j_ptr
->ac
) return (FALSE
);
1302 if (o_ptr
->dd
!= j_ptr
->dd
) return (FALSE
);
1303 if (o_ptr
->ds
!= j_ptr
->ds
) return (FALSE
);
1312 /* Require knowledge */
1313 if (!object_known_p(o_ptr
) || !object_known_p(j_ptr
)) return (0);
1321 /* Hack -- Require identical "cursed" and "broken" status */
1322 if (((o_ptr
->ident
& (IDENT_CURSED
)) != (j_ptr
->ident
& (IDENT_CURSED
))) ||
1323 ((o_ptr
->ident
& (IDENT_BROKEN
)) != (j_ptr
->ident
& (IDENT_BROKEN
))))
1329 /* Hack -- Require compatible inscriptions */
1330 if (o_ptr
->note
!= j_ptr
->note
)
1332 /* Never combine different inscriptions */
1333 if (o_ptr
->note
&& j_ptr
->note
) return (0);
1337 /* Different pseudo-ID statuses preclude combination */
1338 if (o_ptr
->pseudo
!= j_ptr
->pseudo
)
1342 /* Maximal "stacking" limit */
1343 if (total
>= MAX_STACK_SIZE
) return (0);
1346 /* They match, so they must be similar */
1352 * Allow one item to "absorb" another, assuming they are similar.
1354 * The blending of the "note" field assumes that either (1) one has an
1355 * inscription and the other does not, or (2) neither has an inscription.
1356 * In both these cases, we can simply use the existing note, unless the
1357 * blending object has a note, in which case we use that note.
1359 * The blending of the "discount" field assumes that either (1) one is a
1360 * special inscription and one is nothing, or (2) one is a discount and
1361 * one is a smaller discount, or (3) one is a discount and one is nothing,
1362 * or (4) both are nothing. In all of these cases, we can simply use the
1363 * "maximum" of the two "discount" fields.
1365 * These assumptions are enforced by the "object_similar()" code.
1367 void object_absorb(object_type
*o_ptr
, const object_type
*j_ptr
)
1369 object_kind
*k_ptr
= &k_info
[o_ptr
->k_idx
];
1371 int total
= o_ptr
->number
+ j_ptr
->number
;
1373 /* Add together the item counts */
1374 o_ptr
->number
= ((total
< MAX_STACK_SIZE
) ? total
: (MAX_STACK_SIZE
- 1));
1376 /* Hack -- Blend "known" status */
1377 if (object_known_p(j_ptr
)) object_known(o_ptr
);
1379 /* Hack -- Blend store status */
1380 if (j_ptr
->ident
& (IDENT_STORE
)) o_ptr
->ident
|= (IDENT_STORE
);
1382 /* Hack -- Blend "mental" status */
1383 if (j_ptr
->ident
& (IDENT_MENTAL
)) o_ptr
->ident
|= (IDENT_MENTAL
);
1385 /* Hack -- Blend "notes" */
1386 if (j_ptr
->note
!= 0) o_ptr
->note
= j_ptr
->note
;
1388 /* Mega-Hack -- Blend "discounts" */
1389 o_ptr
->pseudo
= j_ptr
->pseudo
;
1392 * Hack -- if rods are stacking, re-calculate the
1393 * pvals (maximum timeouts) and current timeouts together
1395 if (o_ptr
->tval
== TV_ROD
)
1397 o_ptr
->pval
= total
* k_ptr
->pval
;
1398 o_ptr
->timeout
+= j_ptr
->timeout
;
1401 /* Hack -- if wands or staves are stacking, combine the charges */
1402 if ((o_ptr
->tval
== TV_WAND
) || (o_ptr
->tval
== TV_STAFF
))
1404 o_ptr
->pval
+= j_ptr
->pval
;
1411 * Find the index of the object_kind with the given tval and sval
1413 s16b
lookup_kind(int tval
, int sval
)
1418 for (k
= 1; k
< z_info
->k_max
; k
++)
1420 object_kind
*k_ptr
= &k_info
[k
];
1423 if ((k_ptr
->tval
== tval
) && (k_ptr
->sval
== sval
)) return (k
);
1427 msg_format("No object (%d,%d)", tval
, sval
);
1435 * Wipe an object clean.
1437 void object_wipe(object_type
*o_ptr
)
1439 /* Wipe the structure */
1440 (void)WIPE(o_ptr
, object_type
);
1445 * Prepare an object based on an existing object
1447 void object_copy(object_type
*o_ptr
, const object_type
*j_ptr
)
1449 /* Copy the structure */
1450 COPY(o_ptr
, j_ptr
, object_type
);
1455 * Prepare an object based on an object kind.
1457 void object_prep(object_type
*o_ptr
, int k_idx
)
1459 object_kind
*k_ptr
= &k_info
[k_idx
];
1461 /* Clear the record */
1462 (void)WIPE(o_ptr
, object_type
);
1464 /* Save the kind index */
1465 o_ptr
->k_idx
= k_idx
;
1467 /* Efficiency -- tval/sval */
1468 o_ptr
->tval
= k_ptr
->tval
;
1469 o_ptr
->sval
= k_ptr
->sval
;
1471 /* Default "pval" */
1472 o_ptr
->pval
= k_ptr
->pval
;
1474 /* Default number */
1477 /* Default weight */
1478 o_ptr
->weight
= k_ptr
->weight
;
1481 o_ptr
->to_h
= k_ptr
->to_h
;
1482 o_ptr
->to_d
= k_ptr
->to_d
;
1483 o_ptr
->to_a
= k_ptr
->to_a
;
1486 o_ptr
->ac
= k_ptr
->ac
;
1487 o_ptr
->dd
= k_ptr
->dd
;
1488 o_ptr
->ds
= k_ptr
->ds
;
1490 /* Hack -- worthless items are always "broken" */
1491 if (k_ptr
->cost
<= 0) o_ptr
->ident
|= (IDENT_BROKEN
);
1493 /* Hack -- cursed items are always "cursed" */
1494 if (k_ptr
->flags3
& (TR3_LIGHT_CURSE
)) o_ptr
->ident
|= (IDENT_CURSED
);
1499 * Help determine an "enchantment bonus" for an object.
1501 * To avoid floating point but still provide a smooth distribution of bonuses,
1502 * we simply round the results of division in such a way as to "average" the
1503 * correct floating point value.
1505 * This function has been changed. It uses "Rand_normal()" to choose values
1506 * from a normal distribution, whose mean moves from zero towards the max as
1507 * the level increases, and whose standard deviation is equal to 1/4 of the
1508 * max, and whose values are forced to lie between zero and the max, inclusive.
1510 * Since the "level" rarely passes 100 before Morgoth is dead, it is very
1511 * rare to get the "full" enchantment on an object, even a deep levels.
1513 * It is always possible (albeit unlikely) to get the "full" enchantment.
1515 * A sample distribution of values from "m_bonus(10, N)" is shown below:
1517 * N 0 1 2 3 4 5 6 7 8 9 10
1518 * --- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
1519 * 0 66.37 13.01 9.73 5.47 2.89 1.31 0.72 0.26 0.12 0.09 0.03
1520 * 8 46.85 24.66 12.13 8.13 4.20 2.30 1.05 0.36 0.19 0.08 0.05
1521 * 16 30.12 27.62 18.52 10.52 6.34 3.52 1.95 0.90 0.31 0.15 0.05
1522 * 24 22.44 15.62 30.14 12.92 8.55 5.30 2.39 1.63 0.62 0.28 0.11
1523 * 32 16.23 11.43 23.01 22.31 11.19 7.18 4.46 2.13 1.20 0.45 0.41
1524 * 40 10.76 8.91 12.80 29.51 16.00 9.69 5.90 3.43 1.47 0.88 0.65
1525 * 48 7.28 6.81 10.51 18.27 27.57 11.76 7.85 4.99 2.80 1.22 0.94
1526 * 56 4.41 4.73 8.52 11.96 24.94 19.78 11.06 7.18 3.68 1.96 1.78
1527 * 64 2.81 3.07 5.65 9.17 13.01 31.57 13.70 9.30 6.04 3.04 2.64
1528 * 72 1.87 1.99 3.68 7.15 10.56 20.24 25.78 12.17 7.52 4.42 4.62
1529 * 80 1.02 1.23 2.78 4.75 8.37 12.04 27.61 18.07 10.28 6.52 7.33
1530 * 88 0.70 0.57 1.56 3.12 6.34 10.06 15.76 30.46 12.58 8.47 10.38
1531 * 96 0.27 0.60 1.25 2.28 4.30 7.60 10.77 22.52 22.51 11.37 16.53
1532 * 104 0.22 0.42 0.77 1.36 2.62 5.33 8.93 13.05 29.54 15.23 22.53
1533 * 112 0.15 0.20 0.56 0.87 2.00 3.83 6.86 10.06 17.89 27.31 30.27
1534 * 120 0.03 0.11 0.31 0.46 1.31 2.48 4.60 7.78 11.67 25.53 45.72
1535 * 128 0.02 0.01 0.13 0.33 0.83 1.41 3.24 6.17 9.57 14.22 64.07
1537 static s16b
m_bonus(int max
, int level
)
1539 int bonus
, stand
, extra
, value
;
1542 /* Paranoia -- enforce maximal "level" */
1543 if (level
> MAX_DEPTH
- 1) level
= MAX_DEPTH
- 1;
1546 /* The "bonus" moves towards the max */
1547 bonus
= ((max
* level
) / MAX_DEPTH
);
1549 /* Hack -- determine fraction of error */
1550 extra
= ((max
* level
) % MAX_DEPTH
);
1552 /* Hack -- simulate floating point computations */
1553 if (rand_int(MAX_DEPTH
) < extra
) bonus
++;
1556 /* The "stand" is equal to one quarter of the max */
1559 /* Hack -- determine fraction of error */
1562 /* Hack -- simulate floating point computations */
1563 if (rand_int(4) < extra
) stand
++;
1566 /* Choose an "interesting" value */
1567 value
= Rand_normal(bonus
, stand
);
1569 /* Enforce the minimum value */
1570 if (value
< 0) return (0);
1572 /* Enforce the maximum value */
1573 if (value
> max
) return (max
);
1583 * Cheat -- describe a created object for the user
1585 static void object_mention(const object_type
*o_ptr
)
1590 object_desc_spoil(o_name
, sizeof(o_name
), o_ptr
, FALSE
, 0);
1593 if (artifact_p(o_ptr
))
1596 msg_format("Artifact (%s)", o_name
);
1600 else if (ego_item_p(o_ptr
))
1603 msg_format("Ego-item (%s)", o_name
);
1610 msg_format("Object (%s)", o_name
);
1616 * Attempt to change an object into an ego-item -MWK-
1617 * Better only called by apply_magic().
1618 * The return value says if we picked a cursed item (if allowed) and is
1619 * passed on to a_m_aux1/2().
1620 * If no legal ego item is found, this routine returns 0, resulting in
1621 * an unenchanted item.
1623 static int make_ego_item(object_type
*o_ptr
, bool only_good
)
1631 ego_item_type
*e_ptr
;
1633 alloc_entry
*table
= alloc_ego_table
;
1636 /* Fail if object already is ego or artifact */
1637 if (o_ptr
->name1
) return (FALSE
);
1638 if (o_ptr
->name2
) return (FALSE
);
1640 level
= object_level
;
1642 /* Boost level (like with object base types) */
1645 /* Occasional "boost" */
1646 if (rand_int(GREAT_EGO
) == 0)
1648 /* The bizarre calculation again */
1649 level
= 1 + (level
* MAX_DEPTH
/ randint(MAX_DEPTH
));
1656 /* Process probabilities */
1657 for (i
= 0; i
< alloc_ego_size
; i
++)
1662 /* Objects are sorted by depth */
1663 if (table
[i
].level
> level
) continue;
1666 e_idx
= table
[i
].index
;
1668 /* Get the actual kind */
1669 e_ptr
= &e_info
[e_idx
];
1671 /* If we force good/great, don't create cursed */
1672 if (only_good
&& (e_ptr
->flags3
& TR3_LIGHT_CURSE
)) continue;
1674 /* Test if this is a legal ego-item type for this object */
1675 for (j
= 0; j
< EGO_TVALS_MAX
; j
++)
1677 /* Require identical base type */
1678 if (o_ptr
->tval
== e_ptr
->tval
[j
])
1680 /* Require sval in bounds, lower */
1681 if (o_ptr
->sval
>= e_ptr
->min_sval
[j
])
1683 /* Require sval in bounds, upper */
1684 if (o_ptr
->sval
<= e_ptr
->max_sval
[j
])
1687 table
[i
].prob3
= table
[i
].prob2
;
1694 total
+= table
[i
].prob3
;
1697 /* No legal ego-items -- create a normal unenchanted one */
1698 if (total
== 0) return (0);
1701 /* Pick an ego-item */
1702 value
= rand_int(total
);
1704 /* Find the object */
1705 for (i
= 0; i
< alloc_ego_size
; i
++)
1707 /* Found the entry */
1708 if (value
< table
[i
].prob3
) break;
1711 value
= value
- table
[i
].prob3
;
1715 e_idx
= (byte
)table
[i
].index
;
1716 o_ptr
->name2
= e_idx
;
1718 return ((e_info
[e_idx
].flags3
& TR3_LIGHT_CURSE
) ? -2 : 2);
1723 * Mega-Hack -- Attempt to create one of the "Special Objects".
1725 * We are only called from "make_object()", and we assume that
1726 * "apply_magic()" is called immediately after we return.
1728 * Note -- see "make_artifact()" and "apply_magic()".
1730 * We *prefer* to create the special artifacts in order, but this is
1731 * normally outweighed by the "rarity" rolls for those artifacts. The
1732 * only major effect of this logic is that the Phial (with rarity one)
1733 * is always the first special artifact created.
1735 static bool make_artifact_special(object_type
*o_ptr
)
1742 /* No artifacts, do nothing */
1743 if (adult_no_artifacts
) return (FALSE
);
1745 /* No artifacts in the town */
1746 if (!p_ptr
->depth
) return (FALSE
);
1748 /* Check the special artifacts */
1749 for (i
= 0; i
< ART_MIN_NORMAL
; ++i
)
1751 artifact_type
*a_ptr
= &a_info
[i
];
1753 /* Skip "empty" artifacts */
1754 if (!a_ptr
->name
) continue;
1756 /* Cannot make an artifact twice */
1757 if (a_ptr
->cur_num
) continue;
1759 /* Enforce minimum "depth" (loosely) */
1760 if (a_ptr
->level
> p_ptr
->depth
)
1762 /* Get the "out-of-depth factor" */
1763 int d
= (a_ptr
->level
- p_ptr
->depth
) * 2;
1765 /* Roll for out-of-depth creation */
1766 if (rand_int(d
) != 0) continue;
1769 /* Artifact "rarity roll" */
1770 if (rand_int(a_ptr
->rarity
) != 0) continue;
1772 /* Find the base object */
1773 k_idx
= lookup_kind(a_ptr
->tval
, a_ptr
->sval
);
1775 /* Enforce minimum "object" level (loosely) */
1776 if (k_info
[k_idx
].level
> object_level
)
1778 /* Get the "out-of-depth factor" */
1779 int d
= (k_info
[k_idx
].level
- object_level
) * 5;
1781 /* Roll for out-of-depth creation */
1782 if (rand_int(d
) != 0) continue;
1785 /* Assign the template */
1786 object_prep(o_ptr
, k_idx
);
1788 /* Mark the item as an artifact */
1801 * Attempt to change an object into an artifact
1803 * This routine should only be called by "apply_magic()"
1805 * Note -- see "make_artifact_special()" and "apply_magic()"
1807 static bool make_artifact(object_type
*o_ptr
)
1812 /* No artifacts, do nothing */
1813 if (adult_no_artifacts
) return (FALSE
);
1815 /* No artifacts in the town */
1816 if (!p_ptr
->depth
) return (FALSE
);
1818 /* Paranoia -- no "plural" artifacts */
1819 if (o_ptr
->number
!= 1) return (FALSE
);
1821 /* Check the artifact list (skip the "specials") */
1822 for (i
= ART_MIN_NORMAL
; i
< z_info
->a_max
; i
++)
1824 artifact_type
*a_ptr
= &a_info
[i
];
1826 /* Skip "empty" items */
1827 if (!a_ptr
->name
) continue;
1829 /* Cannot make an artifact twice */
1830 if (a_ptr
->cur_num
) continue;
1832 /* Must have the correct fields */
1833 if (a_ptr
->tval
!= o_ptr
->tval
) continue;
1834 if (a_ptr
->sval
!= o_ptr
->sval
) continue;
1836 /* XXX XXX Enforce minimum "depth" (loosely) */
1837 if (a_ptr
->level
> p_ptr
->depth
)
1839 /* Get the "out-of-depth factor" */
1840 int d
= (a_ptr
->level
- p_ptr
->depth
) * 2;
1842 /* Roll for out-of-depth creation */
1843 if (rand_int(d
) != 0) continue;
1846 /* We must make the "rarity roll" */
1847 if (rand_int(a_ptr
->rarity
) != 0) continue;
1849 /* Mark the item as an artifact */
1864 * Apply magic to an item known to be a "weapon"
1866 * Hack -- note special base damage dice boosting
1867 * Hack -- note special processing for weapon/digger
1868 * Hack -- note special rating boost for dragon scale mail
1870 static void a_m_aux_1(object_type
*o_ptr
, int level
, int power
)
1872 int tohit1
= randint(5) + m_bonus(5, level
);
1873 int todam1
= randint(5) + m_bonus(5, level
);
1875 int tohit2
= m_bonus(10, level
);
1876 int todam2
= m_bonus(10, level
);
1883 o_ptr
->to_h
+= tohit1
;
1884 o_ptr
->to_d
+= todam1
;
1890 o_ptr
->to_h
+= tohit2
;
1891 o_ptr
->to_d
+= todam2
;
1899 o_ptr
->to_h
-= tohit1
;
1900 o_ptr
->to_d
-= todam1
;
1905 /* Penalize again */
1906 o_ptr
->to_h
-= tohit2
;
1907 o_ptr
->to_d
-= todam2
;
1910 /* Cursed (if "bad") */
1911 if (o_ptr
->to_h
+ o_ptr
->to_d
< 0) o_ptr
->ident
|= (IDENT_CURSED
);
1916 switch (o_ptr
->tval
)
1923 /* Hack -- Horrible digging bonus */
1924 o_ptr
->pval
= 0 - (5 + randint(5));
1930 /* Hack -- Reverse digging bonus */
1931 o_ptr
->pval
= 0 - (o_ptr
->pval
);
1945 /* Hack -- Super-charge the damage dice */
1946 while ((o_ptr
->dd
* o_ptr
->ds
> 0) &&
1947 (rand_int(10L * o_ptr
->dd
* o_ptr
->ds
) == 0))
1952 /* Hack -- Lower the damage dice */
1953 if (o_ptr
->dd
> 9) o_ptr
->dd
= 9;
1967 /* Hack -- super-charge the damage dice */
1968 while ((o_ptr
->dd
* o_ptr
->ds
> 0) &&
1969 (rand_int(10L * o_ptr
->dd
* o_ptr
->ds
) == 0))
1974 /* Hack -- restrict the damage dice */
1975 if (o_ptr
->dd
> 9) o_ptr
->dd
= 9;
1985 * Apply magic to an item known to be "armor"
1987 * Hack -- note special processing for crown/helm
1988 * Hack -- note special processing for robe of permanence
1990 static void a_m_aux_2(object_type
*o_ptr
, int level
, int power
)
1992 int toac1
= randint(5) + m_bonus(5, level
);
1994 int toac2
= m_bonus(10, level
);
2001 o_ptr
->to_a
+= toac1
;
2007 o_ptr
->to_a
+= toac2
;
2015 o_ptr
->to_a
-= toac1
;
2020 /* Penalize again */
2021 o_ptr
->to_a
-= toac2
;
2024 /* Cursed (if "bad") */
2025 if (o_ptr
->to_a
< 0) o_ptr
->ident
|= (IDENT_CURSED
);
2030 switch (o_ptr
->tval
)
2037 /* Mention the item */
2038 if (cheat_peek
) object_mention(o_ptr
);
2048 * Apply magic to an item known to be a "ring" or "amulet"
2050 * Hack -- note special rating boost for ring of speed
2051 * Hack -- note special rating boost for certain amulets
2052 * Hack -- note special "pval boost" code for ring of speed
2053 * Hack -- note that some items must be cursed (or blessed)
2055 static void a_m_aux_3(object_type
*o_ptr
, int level
, int power
)
2057 /* Apply magic (good or bad) according to type */
2058 switch (o_ptr
->tval
)
2063 switch (o_ptr
->sval
)
2065 /* Strength, Constitution, Dexterity, Intelligence */
2072 o_ptr
->pval
= 1 + m_bonus(5, level
);
2078 o_ptr
->ident
|= (IDENT_BROKEN
);
2081 o_ptr
->ident
|= (IDENT_CURSED
);
2084 o_ptr
->pval
= 0 - (o_ptr
->pval
);
2090 /* Ring of Speed! */
2093 /* Base speed (1 to 10) */
2094 o_ptr
->pval
= randint(5) + m_bonus(5, level
);
2096 /* Super-charge the ring */
2097 while (rand_int(100) < 50) o_ptr
->pval
++;
2103 o_ptr
->ident
|= (IDENT_BROKEN
);
2106 o_ptr
->ident
|= (IDENT_CURSED
);
2109 o_ptr
->pval
= 0 - (o_ptr
->pval
);
2119 /* Mention the item */
2120 if (cheat_peek
) object_mention(o_ptr
);
2126 case SV_RING_SEARCHING
:
2128 /* Bonus to searching */
2129 o_ptr
->pval
= 1 + m_bonus(5, level
);
2135 o_ptr
->ident
|= (IDENT_BROKEN
);
2138 o_ptr
->ident
|= (IDENT_CURSED
);
2141 o_ptr
->pval
= 0 - (o_ptr
->pval
);
2147 /* Flames, Acid, Ice, Lightning */
2148 case SV_RING_FLAMES
:
2151 case SV_RING_LIGHTNING
:
2153 /* Bonus to armor class */
2154 o_ptr
->to_a
= 5 + randint(5) + m_bonus(10, level
);
2158 /* Weakness, Stupidity */
2159 case SV_RING_WEAKNESS
:
2160 case SV_RING_STUPIDITY
:
2163 o_ptr
->ident
|= (IDENT_BROKEN
);
2166 o_ptr
->ident
|= (IDENT_CURSED
);
2169 o_ptr
->pval
= 0 - (1 + m_bonus(5, level
));
2174 /* WOE, Stupidity */
2178 o_ptr
->ident
|= (IDENT_BROKEN
);
2181 o_ptr
->ident
|= (IDENT_CURSED
);
2184 o_ptr
->to_a
= 0 - (5 + m_bonus(10, level
));
2185 o_ptr
->pval
= 0 - (1 + m_bonus(5, level
));
2190 /* Ring of damage */
2191 case SV_RING_DAMAGE
:
2193 /* Bonus to damage */
2194 o_ptr
->to_d
= 5 + randint(3) + m_bonus(7, level
);
2200 o_ptr
->ident
|= (IDENT_BROKEN
);
2203 o_ptr
->ident
|= (IDENT_CURSED
);
2206 o_ptr
->to_d
= 0 - (o_ptr
->to_d
);
2212 /* Ring of Accuracy */
2213 case SV_RING_ACCURACY
:
2216 o_ptr
->to_h
= 5 + randint(3) + m_bonus(7, level
);
2222 o_ptr
->ident
|= (IDENT_BROKEN
);
2225 o_ptr
->ident
|= (IDENT_CURSED
);
2228 o_ptr
->to_h
= 0 - (o_ptr
->to_h
);
2234 /* Ring of Protection */
2235 case SV_RING_PROTECTION
:
2237 /* Bonus to armor class */
2238 o_ptr
->to_a
= 5 + randint(5) + m_bonus(10, level
);
2244 o_ptr
->ident
|= (IDENT_BROKEN
);
2247 o_ptr
->ident
|= (IDENT_CURSED
);
2250 o_ptr
->to_a
= 0 - (o_ptr
->to_a
);
2256 /* Ring of Slaying */
2257 case SV_RING_SLAYING
:
2259 /* Bonus to damage and to hit */
2260 o_ptr
->to_d
= randint(5) + m_bonus(5, level
);
2261 o_ptr
->to_h
= randint(5) + m_bonus(5, level
);
2267 o_ptr
->ident
|= (IDENT_BROKEN
);
2270 o_ptr
->ident
|= (IDENT_CURSED
);
2272 /* Reverse bonuses */
2273 o_ptr
->to_h
= 0 - (o_ptr
->to_h
);
2274 o_ptr
->to_d
= 0 - (o_ptr
->to_d
);
2287 switch (o_ptr
->sval
)
2289 /* Amulet of wisdom/charisma/infravision */
2290 case SV_AMULET_WISDOM
:
2291 case SV_AMULET_CHARISMA
:
2292 case SV_AMULET_INFRAVISION
:
2294 o_ptr
->pval
= 1 + m_bonus(5, level
);
2300 o_ptr
->ident
|= (IDENT_BROKEN
);
2303 o_ptr
->ident
|= (IDENT_CURSED
);
2305 /* Reverse bonuses */
2306 o_ptr
->pval
= 0 - (o_ptr
->pval
);
2312 /* Amulet of searching */
2313 case SV_AMULET_SEARCHING
:
2315 o_ptr
->pval
= randint(5) + m_bonus(5, level
);
2321 o_ptr
->ident
|= (IDENT_BROKEN
);
2324 o_ptr
->ident
|= (IDENT_CURSED
);
2326 /* Reverse bonuses */
2327 o_ptr
->pval
= 0 - (o_ptr
->pval
);
2333 /* Amulet of ESP -- never cursed */
2336 o_ptr
->pval
= randint(5) + m_bonus(5, level
);
2341 /* Amulet of the Magi -- never cursed */
2342 case SV_AMULET_THE_MAGI
:
2344 o_ptr
->pval
= 1 + m_bonus(3, level
);
2345 o_ptr
->to_a
= randint(5) + m_bonus(5, level
);
2347 /* Boost the rating */
2350 /* Mention the item */
2351 if (cheat_peek
) object_mention(o_ptr
);
2356 /* Amulet of Devotion -- never cursed */
2357 case SV_AMULET_DEVOTION
:
2359 o_ptr
->pval
= 1 + m_bonus(3, level
);
2361 /* Boost the rating */
2364 /* Mention the item */
2365 if (cheat_peek
) object_mention(o_ptr
);
2370 /* Amulet of Weaponmastery -- never cursed */
2371 case SV_AMULET_WEAPONMASTERY
:
2373 o_ptr
->to_h
= 1 + m_bonus(4, level
);
2374 o_ptr
->to_d
= 1 + m_bonus(4, level
);
2375 o_ptr
->pval
= 1 + m_bonus(2, level
);
2377 /* Boost the rating */
2380 /* Mention the item */
2381 if (cheat_peek
) object_mention(o_ptr
);
2386 /* Amulet of Trickery -- never cursed */
2387 case SV_AMULET_TRICKERY
:
2389 o_ptr
->pval
= randint(1) + m_bonus(3, level
);
2391 /* Boost the rating */
2394 /* Mention the item */
2395 if (cheat_peek
) object_mention(o_ptr
);
2400 /* Amulet of Doom -- always cursed */
2401 case SV_AMULET_DOOM
:
2404 o_ptr
->ident
|= (IDENT_BROKEN
);
2407 o_ptr
->ident
|= (IDENT_CURSED
);
2410 o_ptr
->pval
= 0 - (randint(5) + m_bonus(5, level
));
2411 o_ptr
->to_a
= 0 - (randint(5) + m_bonus(5, level
));
2424 * Apply magic to an item known to be "boring"
2426 * Hack -- note the special code for various items
2428 static void a_m_aux_4(object_type
*o_ptr
, int level
, int power
)
2430 object_kind
*k_ptr
= &k_info
[o_ptr
->k_idx
];
2432 /* Unused parameters */
2436 /* Apply magic (good or bad) according to type */
2437 switch (o_ptr
->tval
)
2441 /* Hack -- Torches & lanterns -- random fuel at 1/2 max */
2442 if (o_ptr
->sval
== SV_LITE_TORCH
)
2444 o_ptr
->timeout
= randint(FUEL_TORCH
/2);
2447 else if (o_ptr
->sval
== SV_LITE_LANTERN
)
2449 o_ptr
->timeout
= randint(FUEL_LAMP
/2);
2458 /* Charge staves and wands */
2459 o_ptr
->pval
= k_ptr
->charge_base
;
2461 if (k_ptr
->charge_dd
&& k_ptr
->charge_ds
)
2462 o_ptr
->pval
+= damroll(k_ptr
->charge_dd
, k_ptr
->charge_ds
);
2469 object_kind
*k_ptr
= &k_info
[o_ptr
->k_idx
];
2471 /* Transfer the pval. */
2472 o_ptr
->pval
= k_ptr
->pval
;
2479 /* Hack -- skip ruined chests */
2480 if (k_info
[o_ptr
->k_idx
].level
<= 0) break;
2482 /* Hack -- pick a "difficulty" */
2483 o_ptr
->pval
= randint(k_info
[o_ptr
->k_idx
].level
);
2485 /* Never exceed "difficulty" of 55 to 59 */
2486 if (o_ptr
->pval
> 55) o_ptr
->pval
= (s16b
)(55 + rand_int(5));
2496 * Complete the "creation" of an object by applying "magic" to the item
2498 * This includes not only rolling for random bonuses, but also putting the
2499 * finishing touches on ego-items and artifacts, giving charges to wands and
2500 * staffs, giving fuel to lites, and placing traps on chests.
2502 * In particular, note that "Instant Artifacts", if "created" by an external
2503 * routine, must pass through this function to complete the actual creation.
2505 * The base "chance" of the item being "good" increases with the "level"
2506 * parameter, which is usually derived from the dungeon level, being equal
2507 * to the level plus 10, up to a maximum of 75. If "good" is true, then
2508 * the object is guaranteed to be "good". If an object is "good", then
2509 * the chance that the object will be "great" (ego-item or artifact), also
2510 * increases with the "level", being equal to half the level, plus 5, up to
2511 * a maximum of 20. If "great" is true, then the object is guaranteed to be
2512 * "great". At dungeon level 65 and below, 15/100 objects are "great".
2514 * If the object is not "good", there is a chance it will be "cursed", and
2515 * if it is "cursed", there is a chance it will be "broken". These chances
2516 * are related to the "good" / "great" chances above.
2518 * Otherwise "normal" rings and amulets will be "good" half the time and
2519 * "cursed" half the time, unless the ring/amulet is always good or cursed.
2521 * If "okay" is true, and the object is going to be "great", then there is
2522 * a chance that an artifact will be created. This is true even if both the
2523 * "good" and "great" arguments are false. Objects which are forced "great"
2524 * get three extra "attempts" to become an artifact.
2526 void apply_magic(object_type
*o_ptr
, int lev
, bool okay
, bool good
, bool great
)
2528 int i
, rolls
, f1
, f2
, power
;
2531 /* Maximum "level" for various things */
2532 if (lev
> MAX_DEPTH
- 1) lev
= MAX_DEPTH
- 1;
2535 /* Base chance of being "good" */
2538 /* Maximal chance of being "good" */
2539 if (f1
> 75) f1
= 75;
2541 /* Base chance of being "great" */
2544 /* Maximal chance of being "great" */
2545 if (f2
> 20) f2
= 20;
2551 /* Roll for "good" */
2552 if (good
|| (rand_int(100) < f1
))
2557 /* Roll for "great" */
2558 if (great
|| (rand_int(100) < f2
)) power
= 2;
2561 /* Roll for "cursed" */
2562 else if (rand_int(100) < f1
)
2564 /* Assume "cursed" */
2567 /* Roll for "broken" */
2568 if (rand_int(100) < f2
) power
= -2;
2571 /* Assume no rolls */
2574 /* Get one roll if excellent */
2575 if (power
>= 2) rolls
= 1;
2577 /* Get four rolls if forced great */
2578 if (great
) rolls
= 4;
2580 /* Get no rolls if not allowed */
2581 if (!okay
|| o_ptr
->name1
) rolls
= 0;
2583 /* Roll for artifacts if allowed */
2584 for (i
= 0; i
< rolls
; i
++)
2586 /* Roll for an artifact */
2587 if (make_artifact(o_ptr
)) break;
2591 /* Hack -- analyze artifacts */
2594 artifact_type
*a_ptr
= &a_info
[o_ptr
->name1
];
2596 /* Hack -- Mark the artifact as "created" */
2599 /* Extract the other fields */
2600 o_ptr
->pval
= a_ptr
->pval
;
2601 o_ptr
->ac
= a_ptr
->ac
;
2602 o_ptr
->dd
= a_ptr
->dd
;
2603 o_ptr
->ds
= a_ptr
->ds
;
2604 o_ptr
->to_a
= a_ptr
->to_a
;
2605 o_ptr
->to_h
= a_ptr
->to_h
;
2606 o_ptr
->to_d
= a_ptr
->to_d
;
2607 o_ptr
->weight
= a_ptr
->weight
;
2609 /* Hack -- extract the "broken" flag */
2610 if (!a_ptr
->cost
) o_ptr
->ident
|= (IDENT_BROKEN
);
2612 /* Hack -- extract the "cursed" flag */
2613 if (a_ptr
->flags3
& (TR3_LIGHT_CURSE
)) o_ptr
->ident
|= (IDENT_CURSED
);
2615 /* Mega-Hack -- increase the rating */
2618 /* Mega-Hack -- increase the rating again */
2619 if (a_ptr
->cost
> 50000L) rating
+= 10;
2621 /* Set the good item flag */
2622 good_item_flag
= TRUE
;
2624 /* Cheat -- peek at the item */
2625 if (cheat_peek
) object_mention(o_ptr
);
2633 switch (o_ptr
->tval
)
2644 if ((power
> 1) || (power
< -1))
2648 ego_power
= make_ego_item(o_ptr
, (bool)(good
|| great
));
2650 if (ego_power
) power
= ego_power
;
2653 if (power
) a_m_aux_1(o_ptr
, lev
, power
);
2668 if ((power
> 1) || (power
< -1))
2672 ego_power
= make_ego_item(o_ptr
, (bool)(good
|| great
));
2674 if (ego_power
) power
= ego_power
;
2677 if (power
) a_m_aux_2(o_ptr
, lev
, power
);
2685 if (!power
&& (rand_int(100) < 50)) power
= -1;
2686 a_m_aux_3(o_ptr
, lev
, power
);
2692 if ((power
> 1) || (power
< -1))
2694 make_ego_item(o_ptr
, (bool)(good
|| great
));
2698 a_m_aux_4(o_ptr
, lev
, power
);
2704 a_m_aux_4(o_ptr
, lev
, power
);
2710 /* Hack -- analyze ego-items */
2713 ego_item_type
*e_ptr
= &e_info
[o_ptr
->name2
];
2718 o_ptr
->xtra1
= e_ptr
->xtra
;
2719 switch (o_ptr
->xtra1
)
2721 case OBJECT_XTRA_TYPE_SUSTAIN
:
2723 o_ptr
->xtra2
= (byte
)rand_int(OBJECT_XTRA_SIZE_SUSTAIN
);
2727 case OBJECT_XTRA_TYPE_RESIST
:
2729 o_ptr
->xtra2
= (byte
)rand_int(OBJECT_XTRA_SIZE_RESIST
);
2733 case OBJECT_XTRA_TYPE_POWER
:
2735 o_ptr
->xtra2
= (byte
)rand_int(OBJECT_XTRA_SIZE_POWER
);
2741 /* Hack -- acquire "broken" flag */
2742 if (!e_ptr
->cost
) o_ptr
->ident
|= (IDENT_BROKEN
);
2744 /* Hack -- acquire "cursed" flag */
2745 if (e_ptr
->flags3
& (TR3_LIGHT_CURSE
)) o_ptr
->ident
|= (IDENT_CURSED
);
2747 /* Hack -- apply extra penalties if needed */
2748 if (cursed_p(o_ptr
) || broken_p(o_ptr
))
2750 /* Hack -- obtain bonuses */
2751 if (e_ptr
->max_to_h
> 0) o_ptr
->to_h
-= randint(e_ptr
->max_to_h
);
2752 if (e_ptr
->max_to_d
> 0) o_ptr
->to_d
-= randint(e_ptr
->max_to_d
);
2753 if (e_ptr
->max_to_a
> 0) o_ptr
->to_a
-= randint(e_ptr
->max_to_a
);
2755 /* Hack -- obtain pval */
2756 if (e_ptr
->max_pval
> 0) o_ptr
->pval
-= randint(e_ptr
->max_pval
);
2759 /* Hack -- apply extra bonuses if needed */
2762 /* Hack -- obtain bonuses */
2763 if (e_ptr
->max_to_h
> 0) o_ptr
->to_h
+= randint(e_ptr
->max_to_h
);
2764 if (e_ptr
->max_to_d
> 0) o_ptr
->to_d
+= randint(e_ptr
->max_to_d
);
2765 if (e_ptr
->max_to_a
> 0) o_ptr
->to_a
+= randint(e_ptr
->max_to_a
);
2767 /* Hack -- obtain pval */
2768 if (e_ptr
->max_pval
> 0) o_ptr
->pval
+= randint(e_ptr
->max_pval
);
2771 /* Hack -- apply rating bonus */
2772 rating
+= e_ptr
->rating
;
2774 /* Cheat -- describe the item */
2775 if (cheat_peek
) object_mention(o_ptr
);
2782 /* Examine real objects */
2785 object_kind
*k_ptr
= &k_info
[o_ptr
->k_idx
];
2787 /* Hack -- acquire "broken" flag */
2788 if (!k_ptr
->cost
) o_ptr
->ident
|= (IDENT_BROKEN
);
2790 /* Hack -- acquire "cursed" flag */
2791 if (k_ptr
->flags3
& (TR3_LIGHT_CURSE
)) o_ptr
->ident
|= (IDENT_CURSED
);
2798 * Hack -- determine if a template is "good".
2800 * Note that this test only applies to the object *kind*, so it is
2801 * possible to choose a kind which is "good", and then later cause
2802 * the actual object to be cursed. We do explicitly forbid objects
2803 * which are known to be boring or which start out somewhat damaged.
2805 static bool kind_is_good(int k_idx
)
2807 object_kind
*k_ptr
= &k_info
[k_idx
];
2809 /* Analyze the item type */
2810 switch (k_ptr
->tval
)
2812 /* Armor -- Good unless damaged */
2823 if (k_ptr
->to_a
< 0) return (FALSE
);
2827 /* Weapons -- Good unless damaged */
2834 if (k_ptr
->to_h
< 0) return (FALSE
);
2835 if (k_ptr
->to_d
< 0) return (FALSE
);
2839 /* Ammo -- Arrows/Bolts are good */
2846 /* Books -- High level books are good */
2848 case TV_PRAYER_BOOK
:
2850 if (k_ptr
->sval
>= SV_BOOK_MIN_GOOD
) return (TRUE
);
2854 /* Rings -- Rings of Speed are good */
2857 if (k_ptr
->sval
== SV_RING_SPEED
) return (TRUE
);
2861 /* Amulets -- Amulets of the Magi are good */
2864 if (k_ptr
->sval
== SV_AMULET_THE_MAGI
) return (TRUE
);
2865 if (k_ptr
->sval
== SV_AMULET_DEVOTION
) return (TRUE
);
2866 if (k_ptr
->sval
== SV_AMULET_WEAPONMASTERY
) return (TRUE
);
2867 if (k_ptr
->sval
== SV_AMULET_TRICKERY
) return (TRUE
);
2871 /* Potions -- Potions of life, healing, *healing* are good,
2872 * restore mana for spell casters are good,
2873 * as are stat potions, when the stat is not maximised,
2874 * as is augmentation (acts as a potion of 'restoration' if all
2875 * stats are maximised).
2877 * XXX If we make too many useful items 'good' we may want to
2878 * consider limiting the total number of good drops to uniques
2879 * and truely nasty monsters.
2883 if (k_ptr
->sval
== SV_POTION_HEALING
) return (TRUE
);
2884 if (k_ptr
->sval
== SV_POTION_STAR_HEALING
) return (TRUE
);
2885 if (k_ptr
->sval
== SV_POTION_LIFE
) return (TRUE
);
2886 if ((k_ptr
->sval
== SV_POTION_RESTORE_MANA
) && (p_ptr
->msp
> 0)) return (TRUE
);
2887 if ((k_ptr
->sval
>= SV_POTION_INC_STR
) && (k_ptr
->sval
<= SV_POTION_INC_CHR
))
2889 if (p_ptr
->stat_cur
[k_ptr
->sval
- SV_POTION_INC_STR
] < 18+100) return (TRUE
);
2891 if (k_ptr
->sval
== SV_POTION_AUGMENTATION
) return (TRUE
);
2896 /* Assume not good */
2903 * Attempt to make an object (normal or good/great)
2905 * This routine plays nasty games to generate the "special artifacts".
2907 * This routine uses "object_level" for the "generation level".
2909 * We assume that the given object has been "wiped".
2911 bool make_object(object_type
*j_ptr
, bool good
, bool great
)
2917 /* Chance of "special object" */
2918 prob
= (good
? 10 : 1000);
2920 /* Base level for the object */
2921 base
= (good
? (object_level
+ 10) : object_level
);
2924 /* Generate a special artifact, or a normal object */
2925 if ((rand_int(prob
) != 0) || !make_artifact_special(j_ptr
))
2932 /* Activate restriction */
2933 get_obj_num_hook
= kind_is_good
;
2935 /* Prepare allocation table */
2939 /* Pick a random object */
2940 k_idx
= get_obj_num(base
);
2945 /* Clear restriction */
2946 get_obj_num_hook
= NULL
;
2948 /* Prepare allocation table */
2952 /* Handle failure */
2953 if (!k_idx
) return (FALSE
);
2955 /* Prepare the object */
2956 object_prep(j_ptr
, k_idx
);
2959 /* Apply magic (allow artifacts) */
2960 apply_magic(j_ptr
, object_level
, TRUE
, good
, great
);
2963 /* Generate multiple items */
2964 /* Imported from Steamband and Sangband */
2965 /* XXX Will probably not work so well for stacks of potions (yet) */
2966 k_ptr
= &k_info
[j_ptr
->k_idx
];
2968 if (k_ptr
->gen_mult_prob
>= 100 ||
2969 k_ptr
->gen_mult_prob
>= randint(100))
2971 j_ptr
->number
= damroll(k_ptr
->gen_dice
, k_ptr
->gen_side
);
2975 /* Notice "okay" out-of-depth objects */
2976 if (!cursed_p(j_ptr
) && !broken_p(j_ptr
) &&
2977 (k_info
[j_ptr
->k_idx
].level
> p_ptr
->depth
))
2979 /* Rating increase */
2980 rating
+= (k_info
[j_ptr
->k_idx
].level
- p_ptr
->depth
);
2982 /* Cheat -- peek at items */
2983 if (cheat_peek
) object_mention(j_ptr
);
2993 * XXX XXX XXX Do not use these hard-coded values.
2995 #define MAX_GOLD 18 /* Number of "gold" entries */
2998 * Make a treasure object
3000 * The location must be a legal, clean, floor grid.
3002 bool make_gold(object_type
*j_ptr
)
3009 /* Hack -- Pick a Treasure variety */
3010 sval
= ((randint(object_level
+ 2) + 2) / 2);
3012 /* Apply "extra" magic */
3013 if (rand_int(GREAT_OBJ
) == 0)
3015 sval
+= randint(object_level
+ 1);
3018 /* Hack -- Creeping Coins only generate "themselves" */
3019 if (coin_type
) sval
= coin_type
;
3021 /* Do not create "illegal" Treasure Types */
3022 if (sval
> MAX_GOLD
) sval
= MAX_GOLD
;
3024 k_idx
= lookup_kind(TV_GOLD
, sval
);
3026 /* Prepare a gold object */
3027 object_prep(j_ptr
, k_idx
);
3029 /* Hack -- Base coin cost */
3030 base
= k_info
[k_idx
].cost
;
3032 /* Determine how much the treasure is "worth" */
3033 j_ptr
->pval
= (base
+ (8L * randint(base
)) + randint(8));
3042 * Let the floor carry an object
3044 s16b
floor_carry(int y
, int x
, object_type
*j_ptr
)
3050 s16b this_o_idx
, next_o_idx
= 0;
3053 /* Scan objects in that grid for combination */
3054 for (this_o_idx
= cave_o_idx
[y
][x
]; this_o_idx
; this_o_idx
= next_o_idx
)
3058 /* Get the object */
3059 o_ptr
= &o_list
[this_o_idx
];
3061 /* Get the next object */
3062 next_o_idx
= o_ptr
->next_o_idx
;
3064 /* Check for combination */
3065 if (object_similar(o_ptr
, j_ptr
))
3067 /* Combine the items */
3068 object_absorb(o_ptr
, j_ptr
);
3071 return (this_o_idx
);
3078 /* The stack is already too large */
3079 if (n
> MAX_FLOOR_STACK
) return (0);
3081 /* Option -- disallow stacking */
3082 if (adult_no_stacking
&& n
) return (0);
3084 /* Make an object */
3092 /* Get the object */
3093 o_ptr
= &o_list
[o_idx
];
3095 /* Structure Copy */
3096 object_copy(o_ptr
, j_ptr
);
3102 /* Forget monster */
3103 o_ptr
->held_m_idx
= 0;
3105 /* Link the object to the pile */
3106 o_ptr
->next_o_idx
= cave_o_idx
[y
][x
];
3108 /* Link the floor to the object */
3109 cave_o_idx
[y
][x
] = o_idx
;
3124 * Let an object fall to the ground at or near a location.
3126 * The initial location is assumed to be "in_bounds_fully()".
3128 * This function takes a parameter "chance". This is the percentage
3129 * chance that the item will "disappear" instead of drop. If the object
3130 * has been thrown, then this is the chance of disappearance on contact.
3132 * Hack -- this function uses "chance" to determine if it should produce
3133 * some form of "description" of the drop event (under the player).
3135 * We check several locations to see if we can find a location at which
3136 * the object can combine, stack, or be placed. Artifacts will try very
3137 * hard to be placed, including "teleporting" to a useful grid if needed.
3139 void drop_near(object_type
*j_ptr
, int chance
, int y
, int x
)
3154 bool plural
= FALSE
;
3157 /* Extract plural */
3158 if (j_ptr
->number
!= 1) plural
= TRUE
;
3160 /* Describe object */
3161 object_desc(o_name
, sizeof(o_name
), j_ptr
, FALSE
, 0);
3164 /* Handle normal "breakage" */
3165 if (!artifact_p(j_ptr
) && (rand_int(100) < chance
))
3168 msg_format("The %s disappear%s.",
3169 o_name
, (plural
? "" : "s"));
3172 if (p_ptr
->wizard
) msg_print("Breakage (breakage).");
3189 /* Scan local grids */
3190 for (dy
= -3; dy
<= 3; dy
++)
3192 /* Scan local grids */
3193 for (dx
= -3; dx
<= 3; dx
++)
3197 /* Calculate actual distance */
3198 d
= (dy
* dy
) + (dx
* dx
);
3200 /* Ignore distant grids */
3201 if (d
> 10) continue;
3207 /* Skip illegal grids */
3208 if (!in_bounds_fully(ty
, tx
)) continue;
3210 /* Require line of sight */
3211 if (!los(y
, x
, ty
, tx
)) continue;
3213 /* Require floor space */
3214 if (cave_feat
[ty
][tx
] != FEAT_FLOOR
) continue;
3220 /* Scan objects in that grid */
3221 for (o_ptr
= get_first_object(ty
, tx
); o_ptr
; o_ptr
= get_next_object(o_ptr
))
3223 /* Check for possible combination */
3224 if (object_similar(o_ptr
, j_ptr
)) comb
= TRUE
;
3227 if (!squelch_hide_item(o_ptr
))
3233 /* Add new object */
3236 /* Option -- disallow stacking */
3237 if (adult_no_stacking
&& (k
> 1)) continue;
3240 if ((k
+ n
) > MAX_FLOOR_STACK
) continue;
3242 /* Calculate score */
3243 s
= 1000 - (d
+ k
* 5);
3245 /* Skip bad values */
3246 if (s
< bs
) continue;
3248 /* New best value */
3251 /* Apply the randomizer to equivalent values */
3252 if ((++bn
>= 2) && (rand_int(bn
) != 0)) continue;
3267 /* Handle lack of space */
3268 if (!flag
&& !artifact_p(j_ptr
))
3271 msg_format("The %s disappear%s.",
3272 o_name
, (plural
? "" : "s"));
3275 if (p_ptr
->wizard
) msg_print("Breakage (no floor space).");
3283 for (i
= 0; !flag
; i
++)
3288 ty
= rand_spread(by
, 1);
3289 tx
= rand_spread(bx
, 1);
3292 /* Random locations */
3295 ty
= rand_int(DUNGEON_HGT
);
3296 tx
= rand_int(DUNGEON_WID
);
3299 /* Require floor space */
3300 if (cave_feat
[ty
][tx
] != FEAT_FLOOR
) continue;
3302 /* Bounce to that location */
3306 /* Require floor space */
3307 if (!cave_clean_bold(by
, bx
)) continue;
3314 /* Give it to the floor */
3315 if (!floor_carry(by
, bx
, j_ptr
))
3318 msg_format("The %s disappear%s.",
3319 o_name
, (plural
? "" : "s"));
3322 if (p_ptr
->wizard
) msg_print("Breakage (too many objects).");
3324 /* Hack -- Preserve artifacts */
3325 a_info
[j_ptr
->name1
].cur_num
= 0;
3335 /* Mega-Hack -- no message if "dropped" by player */
3336 /* Message when an object falls under the player */
3337 if (chance
&& (cave_m_idx
[by
][bx
] < 0))
3339 msg_print("You feel something roll beneath your feet.");
3345 * Scatter some "great" objects near the player
3347 void acquirement(int y1
, int x1
, int num
, bool great
)
3350 object_type object_type_body
;
3355 /* Get local object */
3356 i_ptr
= &object_type_body
;
3358 /* Wipe the object */
3361 /* Make a good (or great) object (if possible) */
3362 if (!make_object(i_ptr
, TRUE
, great
)) continue;
3364 /* Drop the object */
3365 drop_near(i_ptr
, -1, y1
, x1
);
3371 * Attempt to place an object (normal or good/great) at the given location.
3373 void place_object(int y
, int x
, bool good
, bool great
)
3376 object_type object_type_body
;
3379 if (!in_bounds(y
, x
)) return;
3381 /* Hack -- clean floor space */
3382 if (!cave_clean_bold(y
, x
)) return;
3384 /* Get local object */
3385 i_ptr
= &object_type_body
;
3387 /* Wipe the object */
3390 /* Make an object (if possible) */
3391 if (make_object(i_ptr
, good
, great
))
3393 /* Give it to the floor */
3394 if (!floor_carry(y
, x
, i_ptr
))
3396 /* Hack -- Preserve artifacts */
3397 a_info
[i_ptr
->name1
].cur_num
= 0;
3404 * Places a treasure (Gold or Gems) at given location
3406 void place_gold(int y
, int x
)
3409 object_type object_type_body
;
3412 if (!in_bounds(y
, x
)) return;
3414 /* Require clean floor space */
3415 if (!cave_clean_bold(y
, x
)) return;
3417 /* Get local object */
3418 i_ptr
= &object_type_body
;
3420 /* Wipe the object */
3423 /* Make some gold */
3424 if (make_gold(i_ptr
))
3426 /* Give it to the floor */
3427 (void)floor_carry(y
, x
, i_ptr
);
3434 * Hack -- instantiate a trap
3436 * XXX XXX XXX This routine should be redone to reflect trap "level".
3437 * That is, it does not make sense to have spiked pits at 50 feet.
3438 * Actually, it is not this routine, but the "trap instantiation"
3439 * code, which should also check for "trap doors" on quest levels.
3441 void pick_trap(int y
, int x
)
3446 if (cave_feat
[y
][x
] != FEAT_INVIS
) return;
3451 /* Hack -- pick a trap */
3452 feat
= FEAT_TRAP_HEAD
+ rand_int(16);
3454 /* Hack -- no trap doors on quest levels */
3455 if ((feat
== FEAT_TRAP_HEAD
+ 0x00) && is_quest(p_ptr
->depth
)) continue;
3457 /* Hack -- no trap doors on the deepest level */
3458 if ((feat
== FEAT_TRAP_HEAD
+ 0x00) && (p_ptr
->depth
>= MAX_DEPTH
-1)) continue;
3464 /* Activate the trap */
3465 cave_set_feat(y
, x
, feat
);
3471 * Places a random trap at the given location.
3473 * The location must be a legal, naked, floor grid.
3475 * Note that all traps start out as "invisible" and "untyped", and then
3476 * when they are "discovered" (by detecting them or setting them off),
3477 * the trap is "instantiated" as a visible, "typed", trap.
3479 void place_trap(int y
, int x
)
3482 if (!in_bounds(y
, x
)) return;
3484 /* Require empty, clean, floor grid */
3485 if (!cave_naked_bold(y
, x
)) return;
3487 /* Place an invisible trap */
3488 cave_set_feat(y
, x
, FEAT_INVIS
);
3493 * Place a secret door at the given location
3495 void place_secret_door(int y
, int x
)
3497 /* Create secret door */
3498 cave_set_feat(y
, x
, FEAT_SECRET
);
3503 * Place a random type of closed door at the given location.
3505 void place_closed_door(int y
, int x
)
3509 /* Choose an object */
3510 tmp
= rand_int(400);
3512 /* Closed doors (300/400) */
3515 /* Create closed door */
3516 cave_set_feat(y
, x
, FEAT_DOOR_HEAD
+ 0x00);
3519 /* Locked doors (99/400) */
3522 /* Create locked door */
3523 cave_set_feat(y
, x
, FEAT_DOOR_HEAD
+ randint(7));
3526 /* Stuck doors (1/400) */
3529 /* Create jammed door */
3530 cave_set_feat(y
, x
, FEAT_DOOR_HEAD
+ 0x08 + rand_int(8));
3536 * Place a random type of door at the given location.
3538 void place_random_door(int y
, int x
)
3542 /* Choose an object */
3543 tmp
= rand_int(1000);
3545 /* Open doors (300/1000) */
3548 /* Create open door */
3549 cave_set_feat(y
, x
, FEAT_OPEN
);
3552 /* Broken doors (100/1000) */
3555 /* Create broken door */
3556 cave_set_feat(y
, x
, FEAT_BROKEN
);
3559 /* Secret doors (200/1000) */
3562 /* Create secret door */
3563 cave_set_feat(y
, x
, FEAT_SECRET
);
3566 /* Closed, locked, or stuck doors (400/1000) */
3569 /* Create closed door */
3570 place_closed_door(y
, x
);
3576 * Describe the charges on an item in the inventory.
3578 void inven_item_charges(int item
)
3580 object_type
*o_ptr
= &inventory
[item
];
3582 /* Require staff/wand */
3583 if ((o_ptr
->tval
!= TV_STAFF
) && (o_ptr
->tval
!= TV_WAND
)) return;
3585 /* Require known item */
3586 if (!object_known_p(o_ptr
)) return;
3588 /* Print a message */
3589 msg_format("You have %d charge%s remaining.", o_ptr
->pval
,
3590 (o_ptr
->pval
!= 1) ? "s" : "");
3595 * Describe an item in the inventory.
3597 void inven_item_describe(int item
)
3599 object_type
*o_ptr
= &inventory
[item
];
3603 if (artifact_p(o_ptr
) && object_known_p(o_ptr
))
3605 /* Get a description */
3606 object_desc(o_name
, sizeof(o_name
), o_ptr
, FALSE
, 3);
3608 /* Print a message */
3609 msg_format("You no longer have the %s (%c).", o_name
, index_to_label(item
));
3613 /* Get a description */
3614 object_desc(o_name
, sizeof(o_name
), o_ptr
, TRUE
, 3);
3616 /* Print a message */
3617 msg_format("You have %s (%c).", o_name
, index_to_label(item
));
3623 * Increase the "number" of an item in the inventory
3625 void inven_item_increase(int item
, int num
)
3627 object_type
*o_ptr
= &inventory
[item
];
3630 num
+= o_ptr
->number
;
3633 if (num
> 255) num
= 255;
3634 else if (num
< 0) num
= 0;
3637 num
-= o_ptr
->number
;
3639 /* Change the number and weight */
3642 /* Add the number */
3643 o_ptr
->number
+= num
;
3645 /* Add the weight */
3646 p_ptr
->total_weight
+= (num
* o_ptr
->weight
);
3648 /* Recalculate bonuses */
3649 p_ptr
->update
|= (PU_BONUS
);
3651 /* Recalculate mana XXX */
3652 p_ptr
->update
|= (PU_MANA
);
3654 /* Combine the pack */
3655 p_ptr
->notice
|= (PN_COMBINE
);
3658 p_ptr
->window
|= (PW_INVEN
| PW_EQUIP
);
3664 * Erase an inventory slot if it has no more items
3666 void inven_item_optimize(int item
)
3668 object_type
*o_ptr
= &inventory
[item
];
3670 /* Only optimize real items */
3671 if (!o_ptr
->k_idx
) return;
3673 /* Only optimize empty items */
3674 if (o_ptr
->number
) return;
3676 /* The item is in the pack */
3677 if (item
< INVEN_WIELD
)
3684 /* Slide everything down */
3685 for (i
= item
; i
< INVEN_PACK
; i
++)
3687 /* Hack -- slide object */
3688 COPY(&inventory
[i
], &inventory
[i
+1], object_type
);
3691 /* Hack -- wipe hole */
3692 (void)WIPE(&inventory
[i
], object_type
);
3695 p_ptr
->window
|= (PW_INVEN
);
3698 /* The item is being wielded */
3704 /* Erase the empty slot */
3705 object_wipe(&inventory
[item
]);
3707 /* Recalculate bonuses */
3708 p_ptr
->update
|= (PU_BONUS
);
3710 /* Recalculate torch */
3711 p_ptr
->update
|= (PU_TORCH
);
3713 /* Recalculate mana XXX */
3714 p_ptr
->update
|= (PU_MANA
);
3717 p_ptr
->window
|= (PW_EQUIP
| PW_PLAYER_0
| PW_PLAYER_1
);
3719 p_ptr
->redraw
|= (PR_EQUIPPY
);
3725 * Describe the charges on an item on the floor.
3727 void floor_item_charges(int item
)
3729 object_type
*o_ptr
= &o_list
[item
];
3731 /* Require staff/wand */
3732 if ((o_ptr
->tval
!= TV_STAFF
) && (o_ptr
->tval
!= TV_WAND
)) return;
3734 /* Require known item */
3735 if (!object_known_p(o_ptr
)) return;
3737 /* Print a message */
3738 msg_format("There are %d charge%s remaining.", o_ptr
->pval
,
3739 (o_ptr
->pval
!= 1) ? "s" : "");
3745 * Describe an item in the inventory.
3747 void floor_item_describe(int item
)
3749 object_type
*o_ptr
= &o_list
[item
];
3753 /* Get a description */
3754 object_desc(o_name
, sizeof(o_name
), o_ptr
, TRUE
, 3);
3756 /* Print a message */
3757 msg_format("You see %s.", o_name
);
3762 * Increase the "number" of an item on the floor
3764 void floor_item_increase(int item
, int num
)
3766 object_type
*o_ptr
= &o_list
[item
];
3769 num
+= o_ptr
->number
;
3772 if (num
> 255) num
= 255;
3773 else if (num
< 0) num
= 0;
3776 num
-= o_ptr
->number
;
3778 /* Change the number */
3779 o_ptr
->number
+= num
;
3784 * Optimize an item on the floor (destroy "empty" items)
3786 void floor_item_optimize(int item
)
3788 object_type
*o_ptr
= &o_list
[item
];
3790 /* Paranoia -- be sure it exists */
3791 if (!o_ptr
->k_idx
) return;
3793 /* Only optimize empty items */
3794 if (o_ptr
->number
) return;
3796 /* Delete the object */
3797 delete_object_idx(item
);
3802 * Check if we have space for an item in the pack without overflow
3804 bool inven_carry_okay(const object_type
*o_ptr
)
3807 if (p_ptr
->inven_cnt
< INVEN_PACK
) return TRUE
;
3809 /* Check if it can stack */
3810 if (inven_stack_okay(o_ptr
)) return TRUE
;
3817 * Check to see if an item is stackable in the inventory
3819 bool inven_stack_okay(const object_type
*o_ptr
)
3824 for (j
= 0; j
< INVEN_PACK
; j
++)
3826 object_type
*j_ptr
= &inventory
[j
];
3828 /* Skip non-objects */
3829 if (!j_ptr
->k_idx
) continue;
3831 /* Check if the two items can be combined */
3832 if (object_similar(j_ptr
, o_ptr
)) return (TRUE
);
3841 * Add an item to the players inventory, and return the slot used.
3843 * If the new item can combine with an existing item in the inventory,
3844 * it will do so, using "object_similar()" and "object_absorb()", else,
3845 * the item will be placed into the "proper" location in the inventory.
3847 * This function can be used to "over-fill" the player's pack, but only
3848 * once, and such an action must trigger the "overflow" code immediately.
3849 * Note that when the pack is being "over-filled", the new item must be
3850 * placed into the "overflow" slot, and the "overflow" must take place
3851 * before the pack is reordered, but (optionally) after the pack is
3852 * combined. This may be tricky. See "dungeon.c" for info.
3854 * Note that this code must remove any location/stack information
3855 * from the object once it is placed into the inventory.
3857 s16b
inven_carry(object_type
*o_ptr
)
3864 /* Apply an autoinscription */
3865 apply_autoinscription(o_ptr
);
3867 /* Check for combining */
3868 for (j
= 0; j
< INVEN_PACK
; j
++)
3870 j_ptr
= &inventory
[j
];
3872 /* Skip non-objects */
3873 if (!j_ptr
->k_idx
) continue;
3875 /* Hack -- track last item */
3878 /* Check if the two items can be combined */
3879 if (object_similar(j_ptr
, o_ptr
))
3881 /* Combine the items */
3882 object_absorb(j_ptr
, o_ptr
);
3884 /* Increase the weight */
3885 p_ptr
->total_weight
+= (o_ptr
->number
* o_ptr
->weight
);
3887 /* Recalculate bonuses */
3888 p_ptr
->update
|= (PU_BONUS
);
3891 p_ptr
->window
|= (PW_INVEN
);
3900 if (p_ptr
->inven_cnt
> INVEN_PACK
) return (-1);
3903 /* Find an empty slot */
3904 for (j
= 0; j
<= INVEN_PACK
; j
++)
3906 j_ptr
= &inventory
[j
];
3908 /* Use it if found */
3909 if (!j_ptr
->k_idx
) break;
3916 /* Reorder the pack */
3919 s32b o_value
, j_value
;
3921 /* Get the "value" of the item */
3922 o_value
= object_value(o_ptr
);
3924 /* Scan every occupied slot */
3925 for (j
= 0; j
< INVEN_PACK
; j
++)
3927 j_ptr
= &inventory
[j
];
3929 /* Use empty slots */
3930 if (!j_ptr
->k_idx
) break;
3932 /* Hack -- readable books always come first */
3933 if ((o_ptr
->tval
== cp_ptr
->spell_book
) &&
3934 (j_ptr
->tval
!= cp_ptr
->spell_book
)) break;
3935 if ((j_ptr
->tval
== cp_ptr
->spell_book
) &&
3936 (o_ptr
->tval
!= cp_ptr
->spell_book
)) continue;
3938 /* Objects sort by decreasing type */
3939 if (o_ptr
->tval
> j_ptr
->tval
) break;
3940 if (o_ptr
->tval
< j_ptr
->tval
) continue;
3942 /* Non-aware (flavored) items always come last */
3943 if (!object_aware_p(o_ptr
)) continue;
3944 if (!object_aware_p(j_ptr
)) break;
3946 /* Objects sort by increasing sval */
3947 if (o_ptr
->sval
< j_ptr
->sval
) break;
3948 if (o_ptr
->sval
> j_ptr
->sval
) continue;
3950 /* Unidentified objects always come last */
3951 if (!object_known_p(o_ptr
)) continue;
3952 if (!object_known_p(j_ptr
)) break;
3954 /* Lites sort by decreasing fuel */
3955 if (o_ptr
->tval
== TV_LITE
)
3957 if (o_ptr
->pval
> j_ptr
->pval
) break;
3958 if (o_ptr
->pval
< j_ptr
->pval
) continue;
3961 /* Determine the "value" of the pack item */
3962 j_value
= object_value(j_ptr
);
3964 /* Objects sort by decreasing value */
3965 if (o_value
> j_value
) break;
3966 if (o_value
< j_value
) continue;
3973 for (k
= n
; k
>= i
; k
--)
3975 /* Hack -- Slide the item */
3976 object_copy(&inventory
[k
+1], &inventory
[k
]);
3979 /* Wipe the empty slot */
3980 object_wipe(&inventory
[i
]);
3985 object_copy(&inventory
[i
], o_ptr
);
3987 /* Get the new object */
3988 j_ptr
= &inventory
[i
];
3991 j_ptr
->next_o_idx
= 0;
3993 /* Forget monster */
3994 j_ptr
->held_m_idx
= 0;
3996 /* Forget location */
3997 j_ptr
->iy
= j_ptr
->ix
= 0;
3999 /* No longer marked */
4000 j_ptr
->marked
= FALSE
;
4002 /* Increase the weight */
4003 p_ptr
->total_weight
+= (j_ptr
->number
* j_ptr
->weight
);
4005 /* Count the items */
4008 /* Recalculate bonuses */
4009 p_ptr
->update
|= (PU_BONUS
);
4011 /* Combine and Reorder pack */
4012 p_ptr
->notice
|= (PN_COMBINE
| PN_REORDER
);
4015 p_ptr
->window
|= (PW_INVEN
);
4017 /* Return the slot */
4023 * Take off (some of) a non-cursed equipment item
4025 * Note that only one item at a time can be wielded per slot.
4027 * Note that taking off an item when "full" may cause that item
4028 * to fall to the ground.
4030 * Return the inventory slot into which the item is placed.
4032 s16b
inven_takeoff(int item
, int amt
)
4039 object_type object_type_body
;
4046 /* Get the item to take off */
4047 o_ptr
= &inventory
[item
];
4050 if (amt
<= 0) return (-1);
4053 if (amt
> o_ptr
->number
) amt
= o_ptr
->number
;
4055 /* Get local object */
4056 i_ptr
= &object_type_body
;
4058 /* Obtain a local object */
4059 object_copy(i_ptr
, o_ptr
);
4061 /* Modify quantity */
4062 i_ptr
->number
= amt
;
4064 /* Describe the object */
4065 object_desc(o_name
, sizeof(o_name
), i_ptr
, TRUE
, 3);
4067 /* Took off weapon */
4068 if (item
== INVEN_WIELD
)
4070 act
= "You were wielding";
4074 else if (item
== INVEN_BOW
)
4076 act
= "You were holding";
4079 /* Took off light */
4080 else if (item
== INVEN_LITE
)
4082 act
= "You were holding";
4085 /* Took off something */
4088 act
= "You were wearing";
4091 /* Modify, Optimize */
4092 inven_item_increase(item
, -amt
);
4093 inven_item_optimize(item
);
4095 /* Carry the object */
4096 slot
= inven_carry(i_ptr
);
4100 msg_format("%s %s (%c).", act
, o_name
, index_to_label(slot
));
4108 * Drop (some of) a non-cursed inventory/equipment item
4110 * The object will be dropped "near" the current location
4112 void inven_drop(int item
, int amt
)
4120 object_type object_type_body
;
4125 /* Get the original object */
4126 o_ptr
= &inventory
[item
];
4129 if (amt
<= 0) return;
4132 if (amt
> o_ptr
->number
) amt
= o_ptr
->number
;
4135 /* Take off equipment */
4136 if (item
>= INVEN_WIELD
)
4138 /* Take off first */
4139 item
= inven_takeoff(item
, amt
);
4141 /* Get the original object */
4142 o_ptr
= &inventory
[item
];
4146 /* Get local object */
4147 i_ptr
= &object_type_body
;
4149 /* Obtain local object */
4150 object_copy(i_ptr
, o_ptr
);
4152 /* Distribute charges of wands, staves, or rods */
4153 distribute_charges(o_ptr
, i_ptr
, amt
);
4155 /* Modify quantity */
4156 i_ptr
->number
= amt
;
4158 /* Describe local object */
4159 object_desc(o_name
, sizeof(o_name
), i_ptr
, TRUE
, 3);
4162 msg_format("You drop %s (%c).", o_name
, index_to_label(item
));
4164 /* Drop it near the player */
4165 drop_near(i_ptr
, 0, py
, px
);
4167 /* Modify, Describe, Optimize */
4168 inven_item_increase(item
, -amt
);
4169 inven_item_describe(item
);
4170 inven_item_optimize(item
);
4176 * Combine items in the pack
4177 * Also "pick up" any gold in the inventory by accident
4179 * Note special handling of the "overflow" slot
4181 void combine_pack(void)
4191 /* Combine the pack (backwards) */
4192 for (i
= INVEN_PACK
; i
> 0; i
--)
4197 o_ptr
= &inventory
[i
];
4199 /* Skip empty items */
4200 if (!o_ptr
->k_idx
) continue;
4203 if (o_ptr
->tval
== TV_GOLD
)
4205 /* Count the gold */
4207 p_ptr
->au
+= o_ptr
->pval
;
4210 /* Scan the items above that item */
4211 else for (j
= 0; j
< i
; j
++)
4214 j_ptr
= &inventory
[j
];
4216 /* Skip empty items */
4217 if (!j_ptr
->k_idx
) continue;
4219 /* Can we drop "o_ptr" onto "j_ptr"? */
4220 if (object_similar(j_ptr
, o_ptr
))
4223 flag
= slide
= TRUE
;
4225 /* Add together the item counts */
4226 object_absorb(j_ptr
, o_ptr
);
4233 /* Compact the inventory */
4236 /* One object is gone */
4239 /* Slide everything down */
4240 for (k
= i
; k
< INVEN_PACK
; k
++)
4242 /* Hack -- slide object */
4243 COPY(&inventory
[k
], &inventory
[k
+1], object_type
);
4246 /* Hack -- wipe hole */
4247 object_wipe(&inventory
[k
]);
4250 p_ptr
->window
|= (PW_INVEN
);
4255 if (flag
) msg_print("You combine some items in your pack.");
4260 * Reorder items in the pack
4262 * Note special handling of the "overflow" slot
4264 void reorder_pack(void)
4275 object_type object_type_body
;
4280 /* Re-order the pack (forwards) */
4281 for (i
= 0; i
< INVEN_PACK
; i
++)
4283 /* Mega-Hack -- allow "proper" over-flow */
4284 if ((i
== INVEN_PACK
) && (p_ptr
->inven_cnt
== INVEN_PACK
)) break;
4287 o_ptr
= &inventory
[i
];
4289 /* Skip empty slots */
4290 if (!o_ptr
->k_idx
) continue;
4292 /* Get the "value" of the item */
4293 o_value
= object_value(o_ptr
);
4295 /* Scan every occupied slot */
4296 for (j
= 0; j
< INVEN_PACK
; j
++)
4298 /* Get the item already there */
4299 j_ptr
= &inventory
[j
];
4301 /* Use empty slots */
4302 if (!j_ptr
->k_idx
) break;
4304 /* Hack -- readable books always come first */
4305 if ((o_ptr
->tval
== cp_ptr
->spell_book
) &&
4306 (j_ptr
->tval
!= cp_ptr
->spell_book
)) break;
4307 if ((j_ptr
->tval
== cp_ptr
->spell_book
) &&
4308 (o_ptr
->tval
!= cp_ptr
->spell_book
)) continue;
4310 /* Objects sort by decreasing type */
4311 if (o_ptr
->tval
> j_ptr
->tval
) break;
4312 if (o_ptr
->tval
< j_ptr
->tval
) continue;
4314 /* Non-aware (flavored) items always come last */
4315 if (!object_aware_p(o_ptr
)) continue;
4316 if (!object_aware_p(j_ptr
)) break;
4318 /* Objects sort by increasing sval */
4319 if (o_ptr
->sval
< j_ptr
->sval
) break;
4320 if (o_ptr
->sval
> j_ptr
->sval
) continue;
4322 /* Unidentified objects always come last */
4323 if (!object_known_p(o_ptr
)) continue;
4324 if (!object_known_p(j_ptr
)) break;
4326 /* Lites sort by decreasing fuel */
4327 if (o_ptr
->tval
== TV_LITE
)
4329 if (o_ptr
->pval
> j_ptr
->pval
) break;
4330 if (o_ptr
->pval
< j_ptr
->pval
) continue;
4333 /* Determine the "value" of the pack item */
4334 j_value
= object_value(j_ptr
);
4336 /* Objects sort by decreasing value */
4337 if (o_value
> j_value
) break;
4338 if (o_value
< j_value
) continue;
4341 /* Never move down */
4342 if (j
>= i
) continue;
4347 /* Get local object */
4348 i_ptr
= &object_type_body
;
4350 /* Save a copy of the moving item */
4351 object_copy(i_ptr
, &inventory
[i
]);
4353 /* Slide the objects */
4354 for (k
= i
; k
> j
; k
--)
4356 /* Slide the item */
4357 object_copy(&inventory
[k
], &inventory
[k
-1]);
4360 /* Insert the moving item */
4361 object_copy(&inventory
[j
], i_ptr
);
4364 p_ptr
->window
|= (PW_INVEN
);
4368 if (flag
) msg_print("You reorder some items in your pack.");
4373 * Distribute charges of rods, staves, or wands.
4375 * o_ptr = source item
4376 * q_ptr = target item, must be of the same type as o_ptr
4377 * amt = number of items that are transfered
4379 void distribute_charges(object_type
*o_ptr
, object_type
*q_ptr
, int amt
)
4382 * Hack -- If rods, staves, or wands are dropped, the total maximum
4383 * timeout or charges need to be allocated between the two stacks.
4384 * If all the items are being dropped, it makes for a neater message
4385 * to leave the original stack's pval alone. -LM-
4387 if ((o_ptr
->tval
== TV_WAND
) ||
4388 (o_ptr
->tval
== TV_STAFF
) ||
4389 (o_ptr
->tval
== TV_ROD
))
4391 q_ptr
->pval
= o_ptr
->pval
* amt
/ o_ptr
->number
;
4393 if (amt
< o_ptr
->number
) o_ptr
->pval
-= q_ptr
->pval
;
4396 * Hack -- Rods also need to have their timeouts distributed.
4398 * The dropped stack will accept all time remaining to charge up to
4401 if ((o_ptr
->tval
== TV_ROD
) && (o_ptr
->timeout
))
4403 if (q_ptr
->pval
> o_ptr
->timeout
)
4404 q_ptr
->timeout
= o_ptr
->timeout
;
4406 q_ptr
->timeout
= q_ptr
->pval
;
4408 if (amt
< o_ptr
->number
)
4409 o_ptr
->timeout
-= q_ptr
->timeout
;
4415 void reduce_charges(object_type
*o_ptr
, int amt
)
4418 * Hack -- If rods or wand are destroyed, the total maximum timeout or
4419 * charges of the stack needs to be reduced, unless all the items are
4420 * being destroyed. -LM-
4422 if (((o_ptr
->tval
== TV_WAND
) ||
4423 (o_ptr
->tval
== TV_STAFF
) ||
4424 (o_ptr
->tval
== TV_ROD
)) &&
4425 (amt
< o_ptr
->number
))
4427 o_ptr
->pval
-= o_ptr
->pval
* amt
/ o_ptr
->number
;