--------------------- Polite Notice ---------------------
-- YaLB was created by Daniel Astbury (jnz)            --
-- The source is avaliable to anyone, however          --
-- please do not take it can claim it yours.           --
-- Please follow my example and release your own.      --
-----------------------Thank you-------------------------


Cost_Block = nil
Damage_CoEfficient = 0.01
Repair_CoEfficient = 0.005

function Load_Ranks()
	Cost_Block = Find_Block("Ranks", "Cost")
end

function Get_Vet_Cost(Object)
	if Cost_Block == nil then
		return 1
	end
	local name = Get_Preset_Name(Object)
	local ret = tonumber(Cost_Block.Keys[name])
	ret = ret or Get_Cost(name)
	if ret == 0 then
		return 1
	end
	return ret
end

function Vet_Award_Points(o, Points)
	local ID = Get_Player_ID(o)
	if Players[ID].Points == nil then
		Players[ID].Points = 0
	end
	Players[ID].Points = Players[ID].Points + Points
end

function Vet_Killed(Killer, Victim)
	local vCost = Get_Vet_Cost(Victim)
	local kCost = 1
	local kVehicle = Get_Vehicle(Killer)
	if kVehicle ~= 0 then
		kCost = Get_Vet_Cost(kVehicle)	
	else
		kCost = Get_Vet_Cost(Killer)
	end
	
	Vet_Award_Points(Killer, (Get_Max_Health(Victim) + Get_Max_Shield_Strength(Victim)) * 0.5 * Damage_CoEfficient * math.sqrt(vCost / kCost))
end

function Vet_Damaged(Killer, Victim, Damage)
	if Get_Object_Type(Killer) == Get_Object_Type(Victim) then
		return
	end
	 
	local vCost = Get_Vet_Cost(Victim)
	local kCost = 1
	local kVehicle = Get_Vehicle(Killer)
	if kVehicle ~= 0 then
		kCost = Get_Vet_Cost(kVehicle)	
	else
		kCost = Get_Vet_Cost(Killer)
	end

	if Damage > 0 then
		Vet_Award_Points(Killer, Damage * Damage_CoEfficient * math.sqrt(vCost / kCost))
	else
		Vet_Award_Points(Killer, (Damage*-1) * Repair_CoEfficient * math.sqrt(vCost / kCost))
	end
end