Production

Thalassicus

Bytes and Nibblers
Joined
Nov 9, 2005
Messages
11,057
Location
Texas
Okay, so these functions don't match their time estimates (in cities not building settlers).

Core API
Code:
city:GetUnitProductionTurnsLeft( unitID )

Custom Formula
Code:
function ModdedProdFoodOffset(city)
    local modFoodDifference = 0
    if city:IsFoodProduction() and city:IsCapital() then
        modFoodDifference = ModdedFoodDifferenceTimes100(city) / 100 - city:FoodDifferenceTimes100() / 100
    end
    return modFoodDifference
end

function ModdedGetCurrentProductionDifferenceTimes100(city, bIgnoreFood, bOverflow)
    return city:GetCurrentProductionDifferenceTimes100(bIgnoreFood, bOverflow) + ModdedProdFoodOffset(city)*100
end

function ModdedGetProductionTurnsLeft(city, bIgnoreFood, bOverflow)
    return math.ceil((city:GetProductionNeeded() - city:GetProduction()) / (ModdedGetCurrentProductionDifferenceTimes100(city, bIgnoreFood, bOverflow) / 100))
end

The API function is returning higher numbers than the custom formula:

  • GetUnitProductionTurnsLeft
  • (GetProductionNeeded - GetProduction) / GetCurrentProductionDifference

Does anyone have ideas for what I've done wrong for the formula?
 
The only obvious flaw I see is not counting overflow production. So instead of:
(GetProductionNeeded - GetProduction) / GetCurrentProductionDifference
You should do:
(GetProductionNeeded - GetProduction - GetOverflowProduction) / GetCurrentProductionDifference

EDIT: on second read, if the custom numbers are too low rather than too high, I'm sorta clueless. Could you give some examples showing exactly what these two methods are returning for a given situation?
 
Yeah, I considered overflow too but realized the same thing you did, which is why I'm puzzled. If the custom formula wasn't including overflow, it should return a longer time estimate than the API function, not a shorter estimate. I do believe it's some sort of overflow problem since the problem only occurs on the turn after another item completes construction. I'm just not sure how to properly correct the issue.

I'll keep an eye out for the next time this happens.
 
Back
Top Bottom