Damage Formula

Users who are viewing this thread

Bettonio

Is possibile to know how damage calculation works?
Not the reduction fatctors against armors but the formula of damage.
thx.
 

xenoargh

Grandmaster Knight
Simply put, yes.  Damage / armor factor - armor flat protection value + very minor randomness = damage.  The armor factors  are listed in module.ini; you can't add new categories.  But...

...you can control it, and totally ignore how the engine calculates it, if you want to.  See Fancy Damage System, both what I released OSP and what will be in the next Blood and Steel source (I have made some fairly major improvements, but haven't had time to release it).
 
Something along the lines of

Code:
if hold_time >= 1.1
	hold_bonus = 1.2
elif hold_time >= 0.6:
	hold_bonus = (1.1 - hold_time) * 0.6 + 1.2
elif hold_time >= 0.5:
	hold_bonus = 1.5
else:
	hold_bonus = hold_time + 1.0

raw_damage = weapon_damage * (clamp(hold_bonus, 1.0, 2.0) * 0.5 + 0.5)

if weapon_type == 'one_handed' or weapon_type == 'two_handed' or weapon_type == 'polearm':
	raw_damage *= math.pow(melee_damage_speed_power, speed_bonus)
elif weapon_type == 'crossbow' or weapon_type == 'bow' or weapon_type == 'throwing':
	raw_damage *= math.pow(missile_damage_speed_power, speed_bonus)

if weapon_type == 'crossbow':
	if raining:
		raw_damage *= 0.75
else:
	raw_damage *= proficiency * 0.01 * 0.15 + 0.85
	
	if weapon_type == 'bow':
		raw_damage *= min(power_draw, difficulty + 4) * 0.14 + 1
		
		if mounted:
			raw_damage *= horse_archery * 0.019 + 0.8
		
		if raining:
			raw_damage *= 0.9
	elif weapon_type == 'throwing':
		raw_damage *= power_throw * 0.1 + 1.0
		
		if mounted:
			raw_damage *= horse_archery * 0.019 + 0.8
	elif weapon_type == 'one_handed' or weapon_type == 'two_handed' or weapon_type == 'polearm':
		raw_damage *= power_strike * 0.08 + 1.0

	raw_damage += strength / 5.0

	if (weapon_type == 'two_handed' or weapon_type == 'polearm') and (has_shield or mounted):
		raw_damage *= 0.85
		
		if weapon_type == 'polearm':
			raw_damage *= 0.85
		
		if weapon_flags & itp_two_handed:
			raw_damage *= 0.9

raw_damage = clamp(raw_damage, 0, 500)
 

xenoargh

Grandmaster Knight
Huh.  No random fuzz at all?  It's just variations in how the engine handles the speed bonus?  Interesting.
 

xenoargh

Grandmaster Knight
Ah.  OK, so basically, by different means.  Armor soak fuzz formula, plz?  I would like to understand that completely, if you've got that math, it might help with something in Fancy Damage System 2.0.
 
Code:
armor = appropriate_armor_value_for_hit_location

if hit_shield_on_back:
	armor += shield_resistance + 10

soak_factor = armor * module.ini_soak_factor_for_damage_type
reduction_factor = armor * module.ini_reduction_factor_for_damage_type

if item_flags & itp_extra_penetration:
	soak_factor *= module.ini_extra_penetration_soak_factor
	reduction_factor *= module.ini_extra_penetration_reduction_factor

randomized_soak = (random.random() * 0.55 + 0.45) * soak_factor
randomized_damage = (random.random() * 0.1 + 0.9) * raw_damage
soaked_damage = randomized_damage - randomized_soak

if (soaked_damage < 0.0):
	soaked_damage = 0.0

randomized_reduction = math.exp((random.random() * 0.55 + 0.45) * reduction_factor * 0.014)
reduced_damage = (1.0 - 1.0 / randomized_reduction) * soaked_damage

if (reduction_factor < 0.00001):
	reduced_damage  = 0.0

damage_difference = round(reduced_damage + randomized_soak)
effective_damage = randomized_damage - damage_difference

if hit_bone == head:
	effective_damage *= 1.2

	if item_is_ranged:
		effective_damage *= 1.75
elif hit_bone == calf or hit_bone == thigh:
	effective_damage *= 0.9

effective_damage = clamp(effective_damage, 0.0, 500.0)
 

xenoargh

Grandmaster Knight
Thank you very much.  That at least tells me where the ranges fall, I'll have to walk through that and chart it out, I guess.  Trying to deal with certain types of random damage (primarily, my implementation of explosives and AOE weapons) in a way that's a bit cleaner.
 

MadocComadrin

Water-Borne Annelid
Count
M&BWBWF&S
How many people would like me to try my hand at an app that turns all of this pseudocode into a set of nice charts?
 

Somebody

Code Pope
Baron
WBWF&S
Well, at least we now know what itp_extra_penetration does (nothing to do with hitting more than one enemy, oh well).
transcription error? said:
elif weapon_type == 'crossbow' or weapon_type == 'bow' or weapon_type == 'throwing':
raw_damage *= math.pow(melee_damage_speed_power, speed_bonus)
 

xenoargh

Grandmaster Knight
How many people would like me to try my hand at an app that turns all of this pseudocode into a set of nice charts?
I'd dig just a simple javascript calculator on a page somewhere, myself, to run numbers through.  However, it's something that can go out-of-date very easily, so it's probably a waste of time.  I just wanted to see the math to understand some of the calcs I'm doing (basically, the bug-fix Taleworlds did in 1.134 makes a newer, more-accurate Fancy Damage System possible).
 
Top Bottom