#
# This script is called for each attack (spear thrust). It is called for both hits and misses
#

#Input variables for hit or miss
#missed - 0 if attack hit, 1 if attack missed
#attack - attacker's attack value
#defend - attacker's defend value
#health - attacker's health
#energy - attacker's energy
#social - attacker's social slider, 0 - 10

#Input variables for hit only
#attacker_herd_size - the number of creatures in the attacking group (including the leader)
#defender_herd_size - the number of creatures in the group being attacked (including the leader)
#hit_angle - angle in degrees between attacker's facing and line to opponent (in 2D top-down view)
#hit_distance - distance between attacker and point of contact
#max_hit_distance - attacker's range (see combat_attack_length in CreatureGame.ini)
#max_hit_angle - attacker's field of attack (see combat_max_angle in CreatureGame.ini)
#other_attack - opponent's attack value
#other_defend - opponent's defend value
#other_health - opponent's health
#other_social - defender's social slider, 0 - 10

#Output variables for hit or miss
#energy - new attacker energy

#Output variables for hit only
#damage - health points lost (must be > 0)
#other_health - new health value for opponent (you must deduct yourself)
#sound - set to 1 if you want a sound to play
#critical_hit - 0 = no, 1 = yes (affects particles)

##########

#energy drain on attacker
energy = energy - 25
if (energy < 0) energy = 0 endif

#this doesn't work
#if (energy < 0.1) health = health - 5 endif

if (missed ~= 1) # if hit
    sound = 1
    damage = (attack / other_attack) * 10 * (energy/100)
    if (damage < 0) damage = 0 endif

    # health hit on attackee
    other_health  = other_health - damage

    critical_hit = 1
endif