#**************************************************************************** #** #** File : /cdimage/lua/modules/game.lua #** Author(s): John Comes #** #** Summary : Script full of overall game functions #** #** Copyright © 2005 Gas Powered Games, Inc. All rights reserved. #**************************************************************************** # 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 'standard' unit local rate = (builder_bp.Economy.BuildRate or 1) 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 # limit maximum energy usage per second local max_energy_use = builder_bp.Economy.MaxEnergyUse if max_energy_use and (energy/time)*rate > max_energy_use then rate = max_energy_use * (time/energy) end # limit maximum mass usage per second local max_mass_use = builder_bp.Economy.MaxMassUse if max_mass_use and (mass/time)*rate > max_mass_use then rate = max_mass_use * (time/mass) end return time/rate, energy, mass end