//Logarithm
//by : Vexorian
//"Will * try to guess * the Logarithm it does have good results but it is not as good as having a native Logarithm though."
function Logarithm takes real x, real base returns real
local real inc=1
local real n=0
local real dif1=x-1
local real dif2=0
local integer f=1
if x<=0 or x==1 then
return 0.0
elseif x<1 then
set f=-1
set x=1/x
set dif1=x-1
endif
loop
set n=n+inc
set dif2 = dif1
set dif1 = x-Pow(base,n)
exitwhen dif1 == 0
if dif1 > dif2 or dif1 < 0 then
set n = n - inc
set dif1=dif2
set inc = inc / 10
endif
endloop
return n*f
endfunction
//Calculates the armor of an unit
//by: Natac & Mueslirocker
//requires:
// - Chaos- deals 100% damage to all types of armor.
// - The ability 'AIl1' increases hp by 200
// - Logarithm function
function GetUnitArmor takes unit checkingUnit returns real
// Variablen initialisieren
local real life = GetUnitState(checkingUnit, UNIT_STATE_LIFE)
local real armor = 0.00
local real damage = 0.00
local boolean lowlife = false
//increase life by 200 so that units with hp <200 wont die
if( GetUnitState(checkingUnit, UNIT_STATE_MAX_LIFE) < 200 ) then
call UnitAddAbility(checkingUnit, 'AIl1')
set lowlife = true
endif
//set unit life to 100% so it wont die
call SetUnitState(checkingUnit, UNIT_STATE_LIFE, GetUnitState(checkingUnit, UNIT_STATE_MAX_LIFE) )
//deal 100 Chaos damage
call UnitDamageTarget(checkingUnit, checkingUnit, 100.00, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
//Save damage
set damage = GetUnitState(checkingUnit, UNIT_STATE_MAX_LIFE) - GetUnitState(checkingUnit, UNIT_STATE_LIFE)
//Remove Life Bonus
if ( lowlife == true ) then
call UnitRemoveAbility(checkingUnit, 'AIl1')
set lowlife = false
endif
//restore hp before testing
call SetUnitState(checkingUnit, UNIT_STATE_LIFE, life)
//100% reduction -> 10000 armor
if ( damage == 0 ) then
set checkingUnit = null
return 10000.00
endif
//100% reduction -> -233.28 armor
if ( damage == 200) then
set checkingUnit = null
return -233.28
endif
//calculate armor
if ( damage <= 100.00 ) then // < 100% damage: armor >= 0
set armor = ((100.00-damage)/damage) /0.06
else // > 100% damage: armor < 0
set armor = Logarithm( 100/(200-damage), bj_E ) / -0.061
endif
//Clear
set checkingUnit = null
set life = 0.00
set damage = 0.00
return armor
endfunction