FAForever Forums
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login

    Economy problem

    Scheduled Pinned Locked Moved Modding & Tools
    3 Posts 2 Posters 138 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      Resin_Smoker
      last edited by

      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.

      Kykhu Oss https://youtu.be/JUgyGTgeZb8
      Unit Thrower https://youtu.be/iV8YBXVxxeI
      Beam Tentacle https://youtu.be/le5SNwHvC4c
      Blackhole https://www.youtube.com/watch?v=D9NGQC5rr0c
      Resurection https://www.youtube.com/watch?v=WdbIQ4vHkMs

      R JipJ 2 Replies Last reply Reply Quote 0
      • R Offline
        Resin_Smoker @Resin_Smoker
        last edited by Resin_Smoker

        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.

        Kykhu Oss https://youtu.be/JUgyGTgeZb8
        Unit Thrower https://youtu.be/iV8YBXVxxeI
        Beam Tentacle https://youtu.be/le5SNwHvC4c
        Blackhole https://www.youtube.com/watch?v=D9NGQC5rr0c
        Resurection https://www.youtube.com/watch?v=WdbIQ4vHkMs

        1 Reply Last reply Reply Quote 1
        • JipJ Offline
          Jip @Resin_Smoker
          last edited by Jip

          @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.

          A work of art is never finished, merely abandoned

          1 Reply Last reply Reply Quote 0
          • First post
            Last post