--[[################################################################################
    # File      : /hook/lua/game.lua                                               #
    # Author    : John Comes + Manimal                                             #
    # Version   : 05 novembre 2008                                                 #
    # Revision  : 09 décembre 2008                                                 #
    #                                                                              #
    # Summary   : Script full of overall game functions                            #
    # Copyright : © 2005 Gas Powered Games, Inc. All rights reserved.              #
    ################################################################################]]--



local myMod_UID = "538d05e7-c1ff-49ce-9d99-5f6e111ebf88"  --UID of The Mod

--[[################################################################################
    # Manimal's Mod Locator  script                                                #    
    # The functionMyActiveModLocation = function( byName, byUID, byAuthor ) will   #
    # avoid making a list of units which is not convenient to be kept updated each #    
    # time someone creates and add a new unit in his mod.                          #    
    # This function will require the current Mod's UID ONLY in order to get the    #    
    # current active mod's location, that's more convenient as it won't change.    #    
    # It could work also by mod NAME or AUTHOR name.                               #    
    ################################################################################]]--

local GetMyActiveMod = function( byName, byUID, byAuthor )
	for i, leMod in __active_mods do
		if (byName   and ( byName   == leMod.name   )) 
		or (byUID    and ( byUID    == leMod.uid    ))
		or (byAuthor and ( byAuthor == leMod.author )) then
			--LOG("MANIMAL\'s DEBUG: Mod infos = "..repr(leMod))
			return leMod
		end
	end
	WARN("MANIMAL\'s MOD FINDER:  Unable to get Mod Infos ! Either your mod is not installed or you have mistyped its name, UID or author.")
	return {}
end

local GetMyActiveModLocation = function( leMod )
	if leMod and (type(leMod) == 'table') then
		--LOG("MANIMAL\'s DEBUG: Mod Location = " .. leMod.location)
		return leMod.location
	end
	WARN("MANIMAL\'s MOD LOCATOR:  Unable to get Mod Infos ! Either your mod is not installed or you have mistyped its name, UID or author.")
	return ""
end


# VARIABLES GLOBALES !!!
MonMod = GetMyActiveMod( false, myMod_UID, false )
MyModPath = GetMyActiveModLocation( MonMod )

	

VeteranDefault = {
    Level1 = 25,
    Level2 = 100,
    Level3 = 250,
    Level4 = 500,
    Level5 = 1000,
}

# Return the total time (in seconds), energy, and mass it will take for the given
# builder to create a unit of type target_bp.
#
# targetData may also be an "Enhancement" section of a unit's blueprint rather than
# a full blueprint.
function GetConstructEconomyModel(builder, targetData)

    local builder_bp = builder:GetBlueprint()
    
    # 'rate' here is how fast we build relative to a unit with build rate of 1
    local rate = builder:GetBuildRate()

    local time = targetData.BuildTime
    local mass = targetData.BuildCostMass
    local energy = targetData.BuildCostEnergy

    # apply penalties/bonuses to effective time
    local time_mod = builder.BuildTimeModifier or 0
    time = time * (100 + time_mod)*.01
    if time<.1 then time = .1 end

    # apply penalties/bonuses to effective energy cost
    local energy_mod = builder.EnergyModifier or 0
    energy = energy * (100 + energy_mod)*.01
    if energy<0 then energy = 0 end

    # apply penalties/bonuses to effective mass cost
    local mass_mod = builder.MassModifier or 0
    mass = mass * (100 + mass_mod)*.01
    if mass<0 then mass = 0 end

    return time/rate, energy, mass
end
