src/project-obj.c
int inven_damage(struct player *p, int type, int cperc)
{
	int j, k, amt;
	struct object *obj = p->gear;
	char o_name[80];
	bool damage;

	/* No chance means no damage */
	if (cperc <= 0)
		return 0;

	/* Count the casualties */
	k = 0;

	/* Scan through the gear */
	while (obj) {
		struct object *next = obj->next;
		if (object_is_equipped(p->body, obj)) {
			obj = next;
			continue;
		}

		/* Hack -- for now, skip artifacts */
		if (obj->artifact) {
			obj = next;
			continue;
		}

		/* Give this item slot a shot at death if it is vulnerable */
		if ((obj->el_info[type].flags & EL_INFO_HATES) &&
			!(obj->el_info[type].flags & EL_INFO_IGNORE)) {
			/* Chance to destroy this item */
			int chance = cperc;

			/* Track if it is damaged instead of destroyed */
			damage = FALSE;

			/* Analyze the type to see if we just damage it
			 * - we also check for rods to reduce chance */
			if (tval_is_weapon(obj) && !tval_is_ammo(obj)) {
				/* Chance to damage it */
				if (randint0(10000) < cperc) {
					/* Damage the item */
					obj->to_h--;
					obj->to_d--;

					/* Damaged! */
					damage = TRUE;
				} else {
					obj = next;
					continue;
				}
			} else if (tval_is_armor(obj)) {
				/* Chance to damage it */
				if (randint0(10000) < cperc) {
					/* Damage the item */
					obj->to_a--;

					/* Damaged! */
					damage = TRUE;
				} else {
					obj = next;
					continue;
				}
			} else if (tval_is_rod(obj)) {
				chance = (chance / 4);
			}


			/* Damage instead of destroy */
			if (damage) {
				p->upkeep->update |= (PU_BONUS);
				p->upkeep->redraw |= (PR_EQUIP);

				/* Casualty count */
				amt = obj->number;
			} else
				/* ... or count the casualties */
				for (amt = j = 0; j < obj->number; ++j)
					if (randint0(10000) < chance) amt++;

			/* Some casualities */
			if (amt) {
				struct object *destroyed;
				bool none_left = FALSE;

				/* Get a description */
				object_desc(o_name, sizeof(o_name), obj, ODESC_BASE);

				/* Message */
				msgt(MSG_DESTROY, "%sour %s (%c) %s %s!",
				           ((obj->number > 1) ?
				            ((amt == obj->number) ? "All of y" :
				             (amt > 1 ? "Some of y" : "One of y")) : "Y"),
				           o_name, gear_to_label(obj),
				           ((amt > 1) ? "were" : "was"),
					   (damage ? "damaged" : "destroyed"));

				/* Damage already done? */
				if (damage)
					continue;

				/* Destroy "amt" items */
				destroyed = gear_object_for_use(obj, amt, FALSE, &none_left);
				object_delete(&destroyed);

				/* Count the casualties */
				k += amt;
			}
		}
		obj = next;
	}

	/* Return the casualty count */
	return (k);
}
/**
 * Destroys a type of item on a given percent chance.
 * The chance 'cperc' is in hundredths of a percent (1-in-10000)
 * Note that missiles are no longer necessarily all destroyed
 *
 * Returns number of items destroyed.
 */
Destroys a type of item on a given percent chance.
The chance 'cperc' is in hundredths of a percent (1-in-10000)
Note that missiles are no longer necessarily all destroyed

Returns number of items destroyed.
Destroys a type of item on a given percent chance . The chance ' cperc ' is in hundredths of a percent ( 1 - in - 10000 ) Note that missiles are no longer necessarily all destroyed Returns number of items destroyed .
int inven_damage(struct player *p, int type, int cperc)
{
	int j, k, amt;
	struct object *obj = p->gear;
	char o_name[80];
	bool damage;
	if (cperc <= 0)
		return 0;
	k = 0;
	while (obj) {
		struct object *next = obj->next;
		if (object_is_equipped(p->body, obj)) {
			obj = next;
			continue;
		}
		if (obj->artifact) {
			obj = next;
			continue;
		}
		if ((obj->el_info[type].flags & EL_INFO_HATES) &&
			!(obj->el_info[type].flags & EL_INFO_IGNORE)) {
			int chance = cperc;
			damage = FALSE;
			if (tval_is_weapon(obj) && !tval_is_ammo(obj)) {
				if (randint0(10000) < cperc) {
					obj->to_h--;
					obj->to_d--;
					damage = TRUE;
				} else {
					obj = next;
					continue;
				}
			} else if (tval_is_armor(obj)) {
				if (randint0(10000) < cperc) {
					obj->to_a--;
					damage = TRUE;
				} else {
					obj = next;
					continue;
				}
			} else if (tval_is_rod(obj)) {
				chance = (chance / 4);
			}
			if (damage) {
				p->upkeep->update |= (PU_BONUS);
				p->upkeep->redraw |= (PR_EQUIP);
				amt = obj->number;
			} else
				for (amt = j = 0; j < obj->number; ++j)
					if (randint0(10000) < chance) amt++;
			if (amt) {
				struct object *destroyed;
				bool none_left = FALSE;
				object_desc(o_name, sizeof(o_name), obj, ODESC_BASE);
				msgt(MSG_DESTROY, "%sour %s (%c) %s %s!",
				           ((obj->number > 1) ?
				            ((amt == obj->number) ? "All of y" :
				             (amt > 1 ? "Some of y" : "One of y")) : "Y"),
				           o_name, gear_to_label(obj),
				           ((amt > 1) ? "were" : "was"),
					   (damage ? "damaged" : "destroyed"));
				if (damage)
					continue;
				destroyed = gear_object_for_use(obj, amt, FALSE, &none_left);
				object_delete(&destroyed);
				k += amt;
			}
		}
		obj = next;
	}
	return (k);
}
int inven_damage ( struct player * p , int type , int cperc ) { int j , k , amt ; struct object * obj = p -> gear ; char o_name [ 80 ] ; bool damage ; if ( cperc <= 0 ) return 0 ; k = 0 ; while ( obj ) { struct object * next = obj -> next ; if ( object_is_equipped ( p -> body , obj ) ) { obj = next ; continue ; } if ( obj -> artifact ) { obj = next ; continue ; } if ( ( obj -> el_info [ type ] . flags & EL_INFO_HATES ) && ! ( obj -> el_info [ type ] . flags & EL_INFO_IGNORE ) ) { int chance = cperc ; damage = FALSE ; if ( tval_is_weapon ( obj ) && ! tval_is_ammo ( obj ) ) { if ( randint0 ( 10000 ) < cperc ) { obj -> to_h -- ; obj -> to_d -- ; damage = TRUE ; } else { obj = next ; continue ; } } else if ( tval_is_armor ( obj ) ) { if ( randint0 ( 10000 ) < cperc ) { obj -> to_a -- ; damage = TRUE ; } else { obj = next ; continue ; } } else if ( tval_is_rod ( obj ) ) { chance = ( chance / 4 ) ; } if ( damage ) { p -> upkeep -> update |= ( PU_BONUS ) ; p -> upkeep -> redraw |= ( PR_EQUIP ) ; amt = obj -> number ; } else for ( amt = j = 0 ; j < obj -> number ; ++ j ) if ( randint0 ( 10000 ) < chance ) amt ++ ; if ( amt ) { struct object * destroyed ; bool none_left = FALSE ; object_desc ( o_name , sizeof ( o_name ) , obj , ODESC_BASE ) ; msgt ( MSG_DESTROY , " " , ( ( obj -> number > 1 ) ? ( ( amt == obj -> number ) ? " " : ( amt > 1 ? " " : " " ) ) : " " ) , o_name , gear_to_label ( obj ) , ( ( amt > 1 ) ? " " : " " ) , ( damage ? " " : " " ) ) ; if ( damage ) continue ; destroyed = gear_object_for_use ( obj , amt , FALSE , & none_left ) ; object_delete ( & destroyed ) ; k += amt ; } } obj = next ; } return ( k ) ; }
Destroys a type of item on a given percent chance.
Destroys a type of item on a given percent chance .
/* No chance means no damage */ /* Count the casualties */ /* Scan through the gear */ /* Hack -- for now, skip artifacts */ /* Give this item slot a shot at death if it is vulnerable */ /* Chance to destroy this item */ /* Track if it is damaged instead of destroyed */ /* Analyze the type to see if we just damage it
			 * - we also check for rods to reduce chance */ /* Chance to damage it */ /* Damage the item */ /* Damaged! */ /* Chance to damage it */ /* Damage the item */ /* Damaged! */ /* Damage instead of destroy */ /* Casualty count */ /* ... or count the casualties */ /* Some casualities */ /* Get a description */ /* Message */ /* Damage already done? */ /* Destroy "amt" items */ /* Count the casualties */ /* Return the casualty count */