Ejemplo n.º 1
0
/**
 * Describe damage.
 */
static bool describe_damage(textblock *tb, const struct object *obj)
{
	bool nonweap_slay = false;
	int normal_damage;
	struct brand *brand, *brands = NULL;
	struct slay *slay, *slays = NULL;
	bool has_brands_or_slays;

	/* Collect brands and slays */
	has_brands_or_slays = obj_known_damage(obj, &normal_damage, &brands, &slays,
										   &nonweap_slay);

	/* Mention slays and brands from other items */
	if (nonweap_slay)
		textblock_append(tb, "This weapon may benefit from one or more off-weapon brands or slays.\n");

	textblock_append(tb, "Average damage/round: ");

	/* Output damage for creatures effected by the brands */
	brand = brands;
	while (brand) {
		if (brand->damage <= 0)
			textblock_append_c(tb, COLOUR_L_RED, "%d", 0);
		else if (brand->damage % 10)
			textblock_append_c(tb, COLOUR_L_GREEN, "%d.%d",
							   brand->damage / 10, brand->damage % 10);
		else
			textblock_append_c(tb, COLOUR_L_GREEN, "%d",brand->damage / 10);

		textblock_append(tb, " vs. creatures not resistant to %s, ",
						 brand->name);
		brand = brand->next;
	}

	/* Output damage for creatures effected by the slays */
	slay = slays;
	while (slay) {
		if (slay->damage <= 0)
			textblock_append_c(tb, COLOUR_L_RED, "%d", 0);
		else if (slay->damage % 10)
			textblock_append_c(tb, COLOUR_L_GREEN, "%d.%d",
							   slay->damage / 10, slay->damage % 10);
		else
			textblock_append_c(tb, COLOUR_L_GREEN, "%d", slay->damage / 10);

		textblock_append(tb, " vs. %s, ", slay->name);
		slay = slay->next;
	}

	if (has_brands_or_slays) textblock_append(tb, "and ");

	if (normal_damage <= 0)
		textblock_append_c(tb, COLOUR_L_RED, "%d", 0);
	else if (normal_damage % 10)
		textblock_append_c(tb, COLOUR_L_GREEN, "%d.%d",
			   normal_damage / 10, normal_damage % 10);
	else
		textblock_append_c(tb, COLOUR_L_GREEN, "%d", normal_damage / 10);

	if (has_brands_or_slays) textblock_append(tb, " vs. others");
	textblock_append(tb, ".\n");

	free_brand(brands);
	free_slay(slays);
	return true;
}
Ejemplo n.º 2
0
/**
 * Describe damage.
 */
static bool describe_damage(textblock *tb, const struct object *obj)
{
	int i;
	bool nonweap_slay = false;
	int normal_damage = 0;
	int *brand_damage = mem_zalloc(z_info->brand_max * sizeof(int));
	int *slay_damage = mem_zalloc(z_info->slay_max * sizeof(int));

	/* Collect brands and slays */
	bool has_brands_or_slays = obj_known_damage(obj, &normal_damage,
												brand_damage, slay_damage,
												&nonweap_slay);

	/* Mention slays and brands from other items */
	if (nonweap_slay)
		textblock_append(tb, "This weapon may benefit from one or more off-weapon brands or slays.\n");

	textblock_append(tb, "Average damage/round: ");

	if (has_brands_or_slays) {
		/* Output damage for creatures effected by the brands */
		for (i = 0; i < z_info->brand_max; i++) {
			if (brand_damage[i] <= 0) {
				continue;
			} else if (brand_damage[i] % 10) {
				textblock_append_c(tb, COLOUR_L_GREEN, "%d.%d",
								   brand_damage[i] / 10, brand_damage[i] % 10);
			} else {
				textblock_append_c(tb, COLOUR_L_GREEN, "%d",
								   brand_damage[i] / 10);
			}
			textblock_append(tb, " vs. creatures not resistant to %s, ",
							 brands[i].name);
		}

		/* Output damage for creatures effected by the slays */
		for (i = 0; i < z_info->slay_max; i++) {
			if (slay_damage[i] <= 0) {
				continue;
			} else if (slay_damage[i] % 10) {
				textblock_append_c(tb, COLOUR_L_GREEN, "%d.%d",
								   slay_damage[i] / 10, slay_damage[i] % 10);
			} else {
				textblock_append_c(tb, COLOUR_L_GREEN, "%d",
								   slay_damage[i] / 10);
			}
			textblock_append(tb, " vs. %s, ", slays[i].name);
		}

		textblock_append(tb, "and ");
	}

	if (normal_damage <= 0)
		textblock_append_c(tb, COLOUR_L_RED, "%d", 0);
	else if (normal_damage % 10)
		textblock_append_c(tb, COLOUR_L_GREEN, "%d.%d",
			   normal_damage / 10, normal_damage % 10);
	else
		textblock_append_c(tb, COLOUR_L_GREEN, "%d", normal_damage / 10);

	if (has_brands_or_slays) textblock_append(tb, " vs. others");
	textblock_append(tb, ".\n");

	mem_free(brand_damage);
	mem_free(slay_damage);
	return true;
}