--[[################################################################################
#  File     :  /hook/lua/game.lua
#  Author(s):  John Comes
#  Summary  :  Script full of overall game functions
#  -----------------------------
#  Modif.by :  Manimal
#  Mod.Date :  05 novembre 2008
#  -----------------------------
#  Revis.by :  Manimal
#  Rev.Date :  27 mai 2010
#  -----------------------------
#  Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
################################################################################]]--

# NBR LIGNES ORIGINAL = 52


# =============================================================================
# AJOUT PAR MANIMAL : MOD LOCATOR
# =============================================================================

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local myMod_UID = "06f49650-9502-11df-981c-0800200c9a66"  --UID of The Mod
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--[[################################################################################
# Manimal's Mod Locator script
# The function MyActiveModLocation = function( byName, byUID, byAuthor ) will
# avoid making a list of units which is not convenient to maintain up-to-date
# each time someone creates and adds 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, but this is not accurate.
################################################################################]]--

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 )
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--local mesUtiles = import( MyModPath .. '/schook/lua/system/mesUtiles.lua' )
--local TraceurTable = mesUtiles.table.AfficheTraceur

# =============================================================================
# FIN AJOUT PAR MANIMAL : MOD LOCATOR
# =============================================================================



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



# =============================================================================
# AJOUT PAR MANIMAL : 
# =============================================================================

-- À AMÉLIORER : RETROUVER LE Niveau Max de Veteran PAR UN AUTRE MOYEN ?
NiveauVetMax = table.getsize( VeteranDefault )

# =============================================================================
# FIN AJOUT PAR MANIMAL : 
# =============================================================================




#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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

