common_damage_system = (ti_on_agent_hit, 0, 0, [],
[
(store_trigger_param_1, ":agent"),
(store_trigger_param_2, ":attacker"),
(store_trigger_param_3, ":damage"),
(store_trigger_param_3, ":orig_damage"),
(agent_get_troop_id, ":troop", ":agent"),
(agent_get_troop_id, ":attacker_troop", ":attacker"),
#Damage is lowered 5% per point of Ironflesh.
(try_begin),
(agent_is_human, ":agent"),#stop if not human
(store_skill_level, ":ironflesh", "skl_ironflesh", ":troop"),
(gt, ":ironflesh", 0),
(val_mul, ":ironflesh", 5),
(assign, ":mod_damage", ":damage"),
(val_mul, ":mod_damage", ":ironflesh"),
(val_div, ":mod_damage", 100),#Rounded here, but whatever.
(val_sub, ":damage", ":mod_damage"),
(try_end),
#Damage is avoided 5% per point of Athletics
(try_begin),
(agent_is_human, ":agent"),#stop if not human
(store_skill_level, ":athletics", "skl_athletics", ":troop"),
(gt, ":athletics", 0),
(val_mul, ":athletics", 5),
(store_random_in_range, ":random_no", 1, 100),
(try_begin),
(le, ":random_no", ":athletics"),
(assign, ":damage", 1),
(try_begin),
(eq, ":troop", "trp_player"),
(display_message, "@You dodge the attack!"),
(else_try),
(eq, ":attacker_troop", "trp_player"),
(display_message, "@{He/She} dodges the attack!"),
(try_end),
(try_end),
(try_end),
#Critical hits for missiles
(try_begin),
(is_between, reg0, "itm_missile_weapons_start", "itm_missile_weapons_end"),#special def in Blood and Steel source
(store_random_in_range, ":random_no", 1, 100),
(try_begin),
(le, ":random_no", 5),
(val_min, ":damage", 20),
(try_end),
(try_end),
#Random knockdown, with STR used to test
(try_begin),
(store_attribute_level,":strength",":attacker_troop",ca_strength),
(store_attribute_level,":enemy_strength",":troop",ca_strength),
(store_sub, ":strength_test", ":strength", ":enemy_strength"),
(val_min, ":strength_test", 2),#2 percent knockdown, for weaker characters.
(store_random_in_range, ":random", 1, 100),
(try_begin),
(neg|agent_is_ally,":agent"),#don't knock down allies
(agent_is_human, ":agent"),#stop if not human
(agent_is_active,":agent"),#stop accidental CTD
(agent_is_alive,":agent"),#same diff
(agent_get_horse, ":horse", ":agent"),
(eq, ":horse", -1),#don't knock down riders, maybe write some "lose yer horse" code later
(le, ":random", ":strength_test"),
(agent_set_animation, ":agent","anim_shield_strike"),#see module_animations from Blood and Steel source for this anim definition
(try_end),
(try_end),
(store_sub, ":diff_damage", ":damage", ":orig_damage"),
(val_mul, ":diff_damage", -1),
(store_agent_hit_points, ":hitpoints" , ":agent", 1),
(val_add, ":hitpoints", ":diff_damage"),
(agent_set_hit_points,":agent",":hitpoints",1),
])