How changing unit build time in real time ?

Everything about mods can be found here.

Moderator: Morax

How changing unit build time in real time ?

Postby Franck83 » 03 Jan 2017, 23:46

Hi all,

There is something that seems simple but i was not able to do is changing build time :roll:. I'm not talking about unit blueprint editing, but changing the buildtime during game.

I succeed in changing mass and energy unit cost by hooking game.lua :idea:. So i can do some unit upgrades that modify the unit cost. But how to change the buildtime ?

The following function in game.lua just give the mass and energy rate consumption used in unit.lua consumption states, but the unit still build itself at the same speed.


Code: Select all
function GetConstructEconomyModel(builder, targetData)

    local builder_bp = builder:GetBlueprint()
   
   targetData.BuildTime = targetData.BuildTime
    # 'rate' here is how fast we build relative to a unit with build rate of 1
    local rate = builder:GetBuildRate() -- NO IMPACT on construction speed
    local time = targetData.BuildTime -- DO NOT CHANGE the build time but only the consumption rate
    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


I gave a deep look in unit.lua where the previous function is called, but there is nothing for the build construction time.

I started to debug to check what are all the functions called when we just create a unit with the commander. This is the LOG result :

INFO: BuildManipulatorSetEnabled
INFO: SetWeaponEnabledByLabel
INFO: GetWeaponByLabel
INFO: OnLostTarget
INFO: ChangeState
INFO: SetWeaponEnabled
INFO: AimManipulatorSetEnabled
INFO: GetWeaponManipulatorByLabel
INFO: TrashBag
INFO: PlayUnitSound
INFO: PlayUnitAmbientSound
INFO: CreateLayerChangeEffects
INFO: OnCreate
INFO: HideLandBones
INFO: GetUnitSizes
INFO: SetCanTakeDamage
INFO: SetCanBeKilled
INFO: FlattenSkirt
INFO: GetSkirtRect
INFO: StartBeingBuiltEffects
INFO: ForkThread
INFO: Add
INFO: OnStartBuild
INFO: StartBuildingEffects
INFO: DoOnStartBuildCallbacks
INFO: SetActiveConsumptionActive
INFO: UpdateConsumptionValues
INFO: GetBuildCosts
INFO: Entity
INFO: initfn
INFO: postinitfn
INFO: HasTarmac
INFO: CreateTarmac
INFO: GetTarmac
INFO: CreateAeonCommanderBuildingEffects
INFO: Class
INFO: SetupClassFields
INFO: InsertIndexFields
INFO: IsDerived
INFO: StateProxiesToClasses
INFO: ManageDamageEffects
INFO: DestroyAllDamageEffects
INFO: OnStopBeingBuilt
INFO: SetupIntel
INFO: EnableUnitIntel
INFO: DoUnitCallbacks
INFO: CreateIdleEffects
INFO: PlayActiveAnimation
INFO: OnStopBuild
INFO: StopBuildingEffects
INFO: Destroy
INFO: SetActiveConsumptionInactive
INFO: DoOnUnitBuiltCallbacks
INFO: StopUnitAmbientSound
INFO: ShouldWatchIntel
INFO: PlayWeaponSound
INFO: PlayWeaponAmbientSound
INFO: StopWeaponAmbientSound
INFO: StopBeingBuiltEffects


The solution is somewhere in theses functions.

Anyone got an idea :( ?
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest