Hi Anhilnine! That's interesting that you can correct the rounding error in the FAF code base. I assumed that since no one ever bothered to fix it (in the mouse-over tooltip for the units) that the rounding was done in the FA exe.
The solution that I came up with is actually a UI-only work-around (its still not 100% accurate, but it does improve accuracy significantly). Basically the approach is to work out mass consumption by looking at energy consumption. It only gets a little hairy when you consider eg ACU upgrades and radar energy consumption. But I believe I've got it working reasonably. I want to test it a bit longer before I upload a patched version though. Anyway, relevant code below in case you're interested.
Thanks for that information about v2.1. I did noticed yesterday that I had some intolerable UI lag with the EM edition when I put it on +10 speed. I did a diff on the v2.1 and the EM edition. It looks like v2.1 is retrieving unit data a bit differently (presumably to reduce lag), whereas the EM edition looks like someone has changed it to use the Common Mod tools to retrieve unit data.
I'm looking forward to seeing your competitor mod, hopefully I can ditch Supreme Economy and use yours instead when its released!
- Code: Select all
econData = unit:GetEconData()
...
local blueprint = unitToGetDataFrom:GetBlueprint()
-- econData.energyConsumed generally has more significant figures than econData.massConsumed
-- so here we use energyConsumed to work out a more precise massConsumed
local energyAdjusted = 0.5+econData.energyConsumed
local massAdjusted = 0.5+econData.massConsumed
local candidateMassCosts = { }
candidateMassCosts["upkeep"] = 0
candidateMassCosts["unit"] = energyAdjusted*blueprint.Economy.BuildCostMass/blueprint.Economy.BuildCostEnergy
if blueprint.Enhancements then
for k,v in pairs(blueprint.Enhancements) do
if v.BuildCostEnergy > 0 then
candidateMassCosts[k] = energyAdjusted*v.BuildCostMass/v.BuildCostEnergy
end
end
end
local bestFitDesc = false
local bestFitMass = false
for k,v in pairs(candidateMassCosts) do
if (not bestFitMass) or math.abs(v-massAdjusted) < math.abs(bestFitMass-massAdjusted) then
bestFitDesc = k
bestFitMass = v
end
end
if bestFitMass then
econData = { energyConsumed=energyAdjusted, massConsumed=bestFitMass }
end