RimWorld

RimWorld

Smart Farming Continued
chembot 23 Sep, 2024 @ 9:02am
Wondering about the estimation math
Hi,

I was looking through the code to see how the nutrition estimation works, since I calculated something slightly different, and I can't figure out how it works. I was testing with corn.

I can see in the CalculateYield function, it sets num to the plant's harvestYield times the difficulty's cropYieldFactor times the zone's cell count. zoneData.nutritionCache is set to the value of the grown plant. Then zoneData.nutritionYield is set to those two multiplied together, and displayed in game.

In game info:
crop: corn
size: 25*25=625
growing period: 30/60

The stats from the corn XML:
harvestYield: 22
Nutrition: 0.4
growDays: 11.3
fertilitySensitivity: not listed, defaults to 1?

Stats from the difficulty XML:
cropYieldFactor: 0.95

Result from mod: 653.12
Result from calculating how the code seems to (the best I could):
num = 22 * 0.95 * 25*25 = 13062.5
nutritionCache = 0.4
nutritionYield = num * nutritionCache = 5225
Result from calculating by hand:
(size * harvestYield * cropYieldFactor * Nutrition * fertility * fertilitySensitivity * growPeriod) / (growDays * 2)
= (625 * 22 * 0.95 * 0.4 * 2 * 1 * (30 / 60)) / (11.3 * 2)
= 462.39

What's odd is that soil the plant's growDays and fertilitySensitivity aren't factored in. I'm also not seeing the fertility, growing period, or the factor of 2 from only growing during daytime used either. I'm sure I'm misunderstanding part of how the code works. Possibly the GetStatValueAbstract? I couldn't find much documentation, but everything seems like it's pulling a stat from the XML. Thanks!