DemonEmperor
Chieftain
- Joined
- Jan 17, 2017
- Messages
- 57
Question: Where can I see employment figures? and how they affect manufacturing output?
- prevent a few dead end on the tech tree by tweaking prerequisites
- tweak Food status icons on the City Banner in relation to rationing
- fix the "Monitor" function that was not using pcall with the correct syntax
- bug fix: sometime a newly created unit failed to register
- bug fix: unsynchronized UI/Gameplay could cause a call to a nil city for the banner
- log calls to the orderedNext function in case a script fails midway
- bug fix: unlock Government at the prereqTech now that it exists
- bug fix: don't try to collect resources for an unit on a nil plot (ie removed from map)
function DoCitiesTurn( playerID )
--GCO.Monitor(CitiesTurn, {playerID}, "Cities Turn Player#".. tostring(playerID))
CitiesTurn( playerID )
end
function DoCitiesTurn( playerID )
GCO.Monitor(CitiesTurn, {playerID}, "Cities Turn Player#".. tostring(playerID))
--CitiesTurn( playerID )
end
function DoUnitsTurn( playerID )
--GCO.Monitor(UnitsTurn, {playerID}, "Units Turn Player#".. tostring(playerID))
UnitsTurn( playerID )
end
function DoUnitsTurn( playerID )
GCO.Monitor(UnitsTurn, {playerID}, "Units Turn Player#".. tostring(playerID))
--UnitsTurn( playerID )
end
thanks, have you tested it, a divide by 0 was causing this issue too, not just the save corruption.View attachment 554558
Got a Divide by 0 Error. attached Lua log below
Edit: It appears to be caused by someone running out of food, causing the migration value calculation to bug out
Edit 2: Appears to be usage of "Div" utility function in PlotScripts, lines 2681 - 2686
Recommend replacing with standard division. Divide by 0 is good, since then you get infinite push in case you have no food left, and nan in case no food, and no food demand.
In case of nan, the following if statement won't trigger, which is good, since no food need means food is no motivation to migrate.
In case of inf, assuming it's always inf, since negative stock values shouldn't happen
Case foodNeeded = 0 (shouldn't be possible, but here for completeness):
migration.Push.Food remains 0, no change necessary (again no migration trigger)
Case foodstock = 0 (empirically possible):
migration pull goes to 0, migration push goes to inf
thus, starving popnum = pop - (pop / inf) = pop - 0 = pop
which is good, because no food ==> literally everyone is starving
-- Starvation
-- Todo : get values per population class from NeedsEffects instead of global values here
local consumptionRatio = 1
local foodNeeded = self:GetFoodConsumption(consumptionRatio)
local foodstock = self:GetFoodStock()
cityMigration.Pull.Food[populationID] = Div(foodstock, foodNeeded)
cityMigration.Push.Food[populationID] = Div(foodNeeded, foodstock)
cityMigration.Migrants.Food[populationID] = 0
if cityMigration.Push.Food[populationID] > 1 then
local motivationWeight = cityMigration.Push.Food[populationID] * migrationClassMotivation.Food[populationID]
if motivationWeight >= bestMotivationWeight then
cityMigration.Motivation[populationID] = "Food"
bestMotivationWeight = motivationWeight
end
local starving = population - Div(population, cityMigration.Push.Food[populationID])
cityMigration.Migrants.Food[populationID] = math.floor(starving * classesRatio[populationID] * math.min(1, migrationClassMotivation.Food[populationID]))
end
Question: Where can I see employment figures? and how they affect manufacturing output?
thanks, complete new one, tested a bit, may handle more cases, but seems slower:Personally I would be fine with leaving select / 0 things in, as illustrated in my earlier population migration case, but yeah divide by 0s are generally useful for highlighting logic errors
In regards to the serializer, got a version working - no idea if it works on such cases or not. Going to start a new game with that foodstock/foodNeeds div check disabled to see if it handles it properly
The serializer has been tested to work on next turn (comparing initial to final tables after serialize/deserialize), and reloading an earlier turn. Have not tested past turn 10, so any exotic effects like NaN/nil/inf, as stated above, hasn't been tested yet.
File has been attached for reference.
GCO_CityScript: WARNING : Serialize and Save CityData timer = 0.6489999294281 seconds at line 799
GCO_CityScript: WARNING : Saving And Checking CityData timer = 0.99399995803833 seconds at line 799
GCO_PlotScript: WARNING : Saving And Checking Map timer = 1.2349998950958 seconds at line 799
GCO_UnitScript: WARNING : Saving And Checking UnitData timer = 0.5460000038147 seconds at line 799
GCO_CityScript: WARNING : Serialize and Save CityData timer = 0.64199995994568 seconds at line 799
GCO_CityScript: WARNING : Saving And Checking CityData timer = 1.0309998989105 seconds at line 799
GCO_PlotScript: WARNING : Saving And Checking Map timer = 1.1829998493195 seconds at line 799
GCO_UnitScript: WARNING : Saving And Checking UnitData timer = 0.53799986839294 seconds at line 799
GCO_CityScript: WARNING : Serialize and Save CityData timer = 0.61199998855591 seconds at line 799
GCO_CityScript: WARNING : Saving And Checking CityData timer = 0.98100018501282 seconds at line 799
GCO_PlotScript: WARNING : Saving And Checking Map timer = 1.1059999465942 seconds at line 799
GCO_UnitScript: WARNING : Saving And Checking UnitData timer = 0.52100014686584 seconds at line 799
GCO_CityScript: WARNING : Saving And Checking CityData timer = 0.63800001144409 seconds at line 799
GCO_PlotScript: WARNING : Saving And Checking Map timer = 0.87400007247925 seconds at line 799
GCO_CityScript: WARNING : Saving And Checking CityData timer = 0.68099999427795 seconds at line 799
GCO_PlotScript: WARNING : Saving And Checking Map timer = 0.84600019454956 seconds at line 799
GCO_CityScript: WARNING : Saving And Checking CityData timer = 0.53600001335144 seconds at line 799
GCO_PlotScript: WARNING : Saving And Checking Map timer = 0.80100011825562 seconds at line 799
-- Starvation
-- Todo : get values per population class from NeedsEffects instead of global values here
local consumptionRatio = 1
local foodNeeded = self:GetFoodConsumption(consumptionRatio)
local foodstock = self:GetFoodStock()
if foodstock == 0 then
if foodNeeded == 0 then
print( "DETECTED NAN" )
else
print( "DETECTED INFINITE PUSH" )
end
elseif foodNeeded == 0 then
print("DETECTED INFINITE PULL")
end
cityMigration.Pull.Food[populationID] = foodstock / foodNeeded
cityMigration.Push.Food[populationID] = foodNeeded / foodstock
cityMigration.Migrants.Food[populationID] = 0
if cityMigration.Push.Food[populationID] > 1 then
local motivationWeight = cityMigration.Push.Food[populationID] * migrationClassMotivation.Food[populationID]
if motivationWeight >= bestMotivationWeight then
cityMigration.Motivation[populationID] = "Food"
bestMotivationWeight = motivationWeight
end
local starving = population - (population / cityMigration.Push.Food[populationID])
cityMigration.Migrants.Food[populationID] = math.floor(starving * classesRatio[populationID] * math.min(1, migrationClassMotivation.Food[populationID]))
end
I don't know if that behavior is also in vanilla, but my island city, that I expected to be able to work the wheat farms, can't work the wheat farms
Anyone have the generated harbor graphics bug out for them? One of mine is in the wrong position.