Economy problem
-
Or rather I flaw in the game design that has persisted for years. Such that the game can't handle a unit with two economy draws.
Example: A shielded unit that can also build...
Which is further compounded by thing that must build ammo to fire. Applying shielding to such a unit is impossible without breaking the economy draw of that unit.
-
Added a small change to a snippet I've taken from FAF's Unit.lua to allow a shielded unit to build silo ammo when keeping accurate build costs. The below script is running within a single unit only, so this isnt hook'd into the whole game.
UpdateConsumptionValues = function(self) local energy_rate = 0 local mass_rate = 0 if self.ActiveConsumption then local focus = self:GetFocusUnit() local time = 1 local mass = 0 local energy = 0 local targetData local baseData local repairRatio = 0.75 if focus then -- Always inherit work status of focus self:InheritWork(focus) end if self.WorkItem then -- Enhancement targetData = self.WorkItem elseif focus then -- Handling upgrades if self:IsUnitState('Upgrading') then baseData = self.Blueprint.Economy -- Upgrading myself, subtract ev. baseCost elseif focus.originalBuilder and not focus.originalBuilder.Dead and focus.originalBuilder:IsUnitState('Upgrading') and focus.originalBuilder:GetFocusUnit() == focus then baseData = focus.originalBuilder:GetBlueprint().Economy end if baseData then targetData = focus:GetBlueprint().Economy end end if targetData then -- Upgrade/enhancement time, energy, mass = Game.GetConstructEconomyModel(self, targetData, baseData) elseif focus then -- Building/repairing something if focus:IsUnitState('SiloBuildingAmmo') then local siloBuildRate = focus:GetBuildRate() or 1 time, energy, mass = focus:GetBuildCosts(focus.SiloProjectile) energy = ( (energy / siloBuildRate) * (self:GetBuildRate() or 0) ) + focus:GetConsumptionPerSecondEnergy() mass = ( (mass / siloBuildRate) * (self:GetBuildRate() or 0) ) + focus:GetConsumptionPerSecondMass() else time, energy, mass = self:GetBuildCosts(focus:GetBlueprint()) if self:IsUnitState('Repairing') and focus.isFinishedUnit then energy = energy * repairRatio mass = mass * repairRatio end end end energy = math.max(0, energy * (self.EnergyBuildAdjMod or 1)) mass = math.max(0, mass * (self.MassBuildAdjMod or 1)) energy_rate = energy / time mass_rate = mass / time end local myBlueprint = self.Blueprint if self.MaintenanceConsumption then local mai_energy = (self.EnergyMaintenanceConsumptionOverride or myBlueprint.Economy.MaintenanceConsumptionPerSecondEnergy) or 0 local mai_mass = myBlueprint.Economy.MaintenanceConsumptionPerSecondMass or 0 -- Apply economic bonuses mai_energy = mai_energy * (100 + (self.EnergyModifier or 0)) * (self.EnergyMaintAdjMod or 1) * 0.01 mai_mass = mai_mass * (100 + (self.MassModifier or 0)) * (self.MassMaintAdjMod or 1) * 0.01 energy_rate = energy_rate + mai_energy mass_rate = mass_rate + mai_mass end -- Apply minimum rates energy_rate = math.max(energy_rate, myBlueprint.Economy.MinConsumptionPerSecondEnergy or 0) mass_rate = math.max(mass_rate, myBlueprint.Economy.MinConsumptionPerSecondMass or 0) self:SetConsumptionPerSecondEnergy(energy_rate) self:SetConsumptionPerSecondMass(mass_rate) self:SetConsumptionActive(energy_rate > 0 or mass_rate > 0) end,This is just a quick fix and is by no means perfect... Will mess with this more as time allows.
-
@resin_smoker said in Economy problem:
Or rather I flaw in the game design that has persisted for years. Such that the game can't handle a unit with two economy draws.
You're right - it was known from the start too. Extractors have the same problem, and it is why this code exists even in the Steam distribution.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login