Town DemandAs an other step towards getting a town growth challenge setting in trunk, I've written a patch that adds new town demand settings. For those of you who don't know, check the Spinoff link in my signature. In a nutshell: the aim is to add a goal to playing OpenTTD, in particular the growing of towns.
When one of the town demand patch settings is chosen, it changes the demands of towns to the given selection. The demand is enforced on all towns on the map, regardless of location or climate.
A new setting is added in Economy / Towns, called Town Demand. There are 8 settings that can be chosen, beyond the default behaviour:
- Food
- Food and Water
- Goods and Valuables
- Food, Water and Goods
- Food, Water, Goods and Valuables
- Food, Water, Goods, Valuables and TE_DEMAND1 (displayed as 'Other' in the menu)
- Food, Water, Goods, Valuables, TE_DEMAND1 and TE_DEMAND2
- TE_DEMAND1 and TE_DEMAND2
Choosing one of these settings will overwrite the town demands for all towns in the game world, regardless of climate. This means that without a cargo newgrf, only setting 3 will allow towngrowth in Temperate, and settings 2, 4 and 5 will not grow in Arctic. Settings 6, 7 and 8 are specifically added for cargo newgrfs, to allow additional complexity to towngrowth at the newgrf-author's wish. Ofcourse, the names here are just the default cargoes. By changing the town effect in a newgrf, you can change demand to any cargo you want.
Code detailsThe patch introduces three new town effect values for cargoes.
- TE_VALUABLES attributed to Valuables, Diamonds and Gold, substitute type 0x0A
- TE_DEMAND1, needs setting by a cargo newgrf, substitute type 0x19
- TE_DEMAND2, needs setting by a cargo newgrf, substitute type 0x1D
TE_DEMAND1 and TE_DEMAND2 are not usuable without a cargo newgrf. I had to pick some values to assign for the substitute type, so I chose two semi-random cargo slots beyond the default cargoes, which in FIRS map to Petrol and Building Materials. If these town effects are demanded without a suitable cargo available, it will be displayed as 'Unknown required'
Current cargo demand formulas:
- TE_FOOD: t->population / 100;
- TE_WATER: max(((population / 150) - 5), 0);
- TE_GOODS: max(((population / 200) - 10), 0);
- TE_VALUABLES: max(((population / 300) - 10), 0);
- TE_DEMAND1: max(((population / 350) - 15), 0);
- TE_DEMAND2: max(((population / 400) - 20), 0);
Eventually, the goal is to add a newgrf callback to allow grf makers to define their own formulas for a town effect, given a town (help needed). In the mean time, this implementation works a treat.
Notes:
* with town demands on, towns are limited to 6,553,500 population for settings 1,2 and 4-7. For setting 3 the limit is 13,109,000 and for setting 8 it is 22,942,500. These limits are due to the cargo amount being stored in a 16 bit unsigned integer, so delivering more cargo will just roll over to 0 and fail to meet the demand. The numbers are the maximum population that can be serviced by 65535 units of cargo delivered, using the above formulas.
* in Toyland, Toys now have effect TE_WATER, to supplement Fizzy Drinks (TE_FOOD) and Candy (TE_GOODS). This allows playing with settings 1, 2 and 4 in toyland without newgrfs. Due to the bad building zone assignments in Toyland, growing big cities there is quite a challenge!
Diff versus r23012
updated binary: now with lang files (!)