Whiping a granary

omnimirage

Chieftain
Joined
Mar 4, 2012
Messages
37
Is it better to wait until maximum hammer overflow has been reached before whipping out a granary, or is it best to whip the granary as soon as one can?
 
Getting the granary as soon as possible is the correct move in the vast majority of cases.
There are some special situations but even in those, if you don't know what you are doing and aren't careful you are likely to hurt yourself by delaying the granary.
 
If one is simply wanting to maximise total food/hammer output, is it best to whip the granary as soon as possible?
 
Yes, thats correct. In the vast majority of cases. Like 90% of the time you get it spot on by just following the rule "Get the granary build asap."
If you want to be 99% correct, you can add "Get the granary built asap, but also try to get it done when the food bar is half-full".

If you want to get the remaning 1% of optimization, you more or less have to learn the inner mechanics of food/growth and the granarys inner storage.
 
So since the granary stores 50% of it's food, it's optimal to whip so that the total food is at 50% before it's whipped, so that 50% of that food "overflows" next turn?
 
The ingame text is misleadning and doesn't say anything about how the granary really works.
The granary does not store 50% of it's food. It stores all food surplus and saves it in a secred invisible inner storage.

Once you grow a population, the game will check how much food there is in the inner storage and add that to your food bar. How much it will add is capped at half the food bar. (which food bar I don't know, the one prior to growth or after?)

After a while, all granaries in all cities will be way over half the food bar, as the inner storage is never depleted by this process, the game only checks how much there is there, it does not subtract.
So it's really just for the process of one population of growth, that we really care or really benefit from optimizing when to build the granary.
Are we at pop4, we are optimizing at most how fast we can reach pop6 after we have reached pop5.

So if you delay and complicate things to optimize that growth, you are most probably delaying pop7, pop8 etc and hurting yourself in the process.
 
We still don't know exacly how the granary works.
There are situations that are so obscure and so uncommon that not even we who are obsessed about micro bother about it.

https://forums.civfanatics.com/threads/where-is-my-granary-bonus.646692/page-2#post-15471739

One area of exploration that is available is how to root out how the inner storage is affected by starvation, what happends if a city starves down?
The only circumstance that plays a role, is how to optimize the construction of a new granary if the old once has been sabotaged prior to or after, you starving the city down.
 
Is it better to wait until maximum hammer overflow has been reached before whipping out a granary, or is it best to whip the granary as soon as one can?
I think it's good to stop to think what exactly overflow is.

Spoiler :
Overflow is stored :hammers:. A bit like putting money to a bank, but with 0% interest. Let that sink in. :)

Storing :hammers: with 0% interest can only be beneficial if you are about to reach a tech that let's you put those stored :hammers: into something very beneficial. So I'd say overflow has absolutely no impact on the decision on when to whip the granary.


So since the granary stores 50% of it's food, it's optimal to whip so that the total food is at 50% before it's whipped, so that 50% of that food "overflows" next turn?
A granary stores :food: up to 50% of the size of the :food:-bar. You get this extra :food: when you grow to the next size.

At size 2 the :food:-bar is 24 :food: long. That means that in order to get the max benefit from the granary you should generate at least 12 :food: after the granary is built while still at size 2. That means that with +4:food: per turn your :food:-bar should have 12-15:food:. With +6:food: it's 12-17:food:. Not how much clumsier +5:food: is as it's multipliers don't hit 12. To gain the full +12:food: the :food:-bar should be at 9-13:food:.

Same goes for finishing it at size 1 (bar 22:food:), size 3 (bar 26:food:) and so on. If you aren't able to finish the granary with the optimal :food: bar, it's often best to keep on growing, working max food but clicking "avoid growth" on for 1 turn. Then you grow 1T slower but the granary stores the maximum amount of :food:, thus you win some :food:.
 
Last edited:
I never realized how complicated the issue really is :)
I usually try to whip it 1 turn before it grows, that's a miscalculation then I take it ?

That sounds wrong, yepp.
And thank you for asking, seems like there been a while since there was a thread about the granary. Refreshing this subject is good for all lurkers out there too. :)
 
I usually try to whip it 1 turn before it grows, that's a miscalculation then I take it ?
Yep, that's the worst time to finish the granary. Whip and turn on avoid growth for 1T is a huge improvement over that, winning sometimes +10:food:.

Also note that after you have a granary, your aim should be to fluctuate in size as much as possible to gain benefit from the granary. In practice this means whipping settlers/workers. When you stagnate, the granary does nothing. This means that with low :)-cap a granary can be close to useless, thus you shouldn't even build it and instead slow build your settlers/workers. Also if you have a city where you are planning to run specialists in, consider whether a granary can be delayed. This is often the case at least with CRE leaders (easy library).
 
Great topic, not easy to learn but actually not complicated..here's what i use:

* With a granary, half of the :food: needed for a city's next population point gets added after they grow. 11 for 22, 12 for 24 and so on (never changes)
* For that one moment in time where a granary gets completed, an optimal result can be achieved by gathering at least 50% of the :food: (11 at size 1 again, 12 for size 2 etc.) after you are asked "what would you like to build next"?
* So the whipping turn does not count yet, granary must be finished. Example..if we whip at 12/22 and work tiles giving +6:food:, we start at 18/22 (not 12).
* Excess food will be added, we land at 24/22 if we continue with +6:food: tiles. Without tricks, our granary bonus here will be 24-18=6:food:.
* Hold Growth extends the city's stay at size 1, and our granary can gather an addition 6:food:. The maximum of 50% or 11/22 can now be reached, and what looks like 2:food: lost will actually be 4:food: gained.
 
One area of exploration that is available is how to root out how the inner storage is affected by starvation, what happends if a city starves down?

It's all handled in CvCity.cpp, CvCity::doGrowth(), which is a reasonably straightforward function. In unmodded BtS, it will:

  • Figure out how much surplus food the city is making (this could be a negative number, if the city is eating more than it produces).
  • Add that value to the city's storage (city storage could, at the point, be negative).
  • Also add that value to the city's hidden m_iFoodKept variable, the granary variable.
  • If the city has no granary, set m_iFoodKept to 0 and otherwise limit it to the range [0, growthThreshold / 2]. So if m_iFoodKept was 16, but the city only needed 26 to grow (and half of that would be 13), m_iFoodKept is immediately pushed back down to 13. If you had 20 food kept, the granary was destroyed by spies, and you immediately whipped or bought a replacement granary, it's too late; doProduction() is after doGrowth() in the turn order, so m_iFoodKept is going to be zeroed out before the new granary completes.
  • Grow the city, if "avoid growth" is not on and the city has more food than the threshold. This will decrease the city's food by (growth threshold - m_iFoodKept), but will not change m_iFoodKept itself.
  • Shrink the city: if the city has negative food, set food to 0 and decrease pop by one. This has no impact at all on m_iFoodKept.
So if a city starves down, it has no direct affect at all on m_iFoodKept. It's hard to see how you could end up with m_iFoodKept being non-zero though if a city is starving - I can't see any way you could end up with the city having a higher "food kept" value than its actual food.

Let's walk through a simple city example. It's size-3 with 15/26 food, and +3 food per turn. It has 60/60 hammers in the granary.

Next turn it finishes the granary; it now has 18/26 food and 0 "food kept" (because growth happens before production in the turn order).

It goes 3 turns at 3 food surplus. 27/26 food and 9 "food kept." It grows to size 4; this means it loses (26 - 9) food, so now it has 10/28 food with, still, 9 "food kept."

It goes 2 more turns at 3 food surplus. 16/28 food; 15 "food kept" gets capped down to 14, half of 28.

You two-pop whip something. 16/24 food; 14 "food kept" gets capped down to 12.

It goes 3 turns at 3 food surplus. 25/24 food, still 12 "food kept" (the cap). It grows to size-3, losing (24 - 12) food, so now it has 13/26 with 12 "food kept."

You start starving it; it's losing 6 food per turn.

It goes 2 turns at -6 food per turn. 1/26 food, 0 "food kept."

One more turn. -5/26 food, -6 food kept. Food kept gets pushed to 0. City food is pushed to 0 and pop decreased by 1; 0/24 food and 0 food kept.
 
Last edited:
Reading this thread is a bit :crazyeye: but I think this is the main point to consider:
For that one moment in time where a granary gets completed, an optimal result can be achieved by gathering at least 50% of the :food: (11 at size 1 again, 12 for size 2 etc.) after you are asked "what would you like to build next"?
In other words, the granary starts collecting food when it has been built (makes sense! :D). Let's say you have 1-pop whipped the granary from size 2>1, and the food bar shows 11/22 the turn after (so when the granary shows up in the list of buildings in the city), you have done things right.
 
and the food bar shows 11/22 the turn after (so when the granary shows up in the list of buildings in the city), you have done things right.
To nitpick - it doesn't need to be at 11/22 to be optimal. You need to be able to put at least 11 :food: to the bin at size 1 for the granary completion to be optimal. This is why the :food:-surplus is important. 12/22 or 13/22 is also optimal if :food:-surplus is 4 or 6, but with :food:-surplus 5 the granary stores only 10:food:. Maybe this is the :crazyeye: part.
 
Test game concerning avoid growth.

T64
Spoiler :
Granary completed this turn, turning on avoid growth.

Civ4ScreenShot0297.JPG


T65
Spoiler :
Food bar is now full at 22/22, turning growth back on.

Civ4ScreenShot0298.JPG


Before opening the next spoiler, try to think where the :food:-bar will be at.

T66
Spoiler :
15/24. Why? Because 10:food: was stored into the granary (5+5) and the third 5:food: is from overflow from the last turn.

Civ4ScreenShot0299.JPG



Without avoid growth (corrected)
Spoiler :

T65 0/24
T66 5/24

Thus, avoid growth wins 10:food: at the expense of being at size 1 1T longer (loses 1:hammers:).

edit: realized now I screwed this up, correct is

T65 5/24
T66 10/24

so "only" a 5:food: difference.
 
Last edited:
It depends on whether you need the Hammers (I. e. when overflowing into a Settler) or if you have enough Settlers / Workers and want Commerce.
 
Back
Top Bottom