Town Demand patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Town Demand patch

Post by Korenn » 10 Oct 2011 13:40

Town Demand
As 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 details
The 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 (!)
Attachments
town_demand.diff
Diff versus r23012
(32.42 KiB) Downloaded 228 times
toyland.png
no grfs required for play.
toyland.png (32.79 KiB) Viewed 6775 times
win32.zip
Now with license!
(5.32 MiB) Downloaded 201 times
Last edited by Korenn on 15 Oct 2011 08:23, edited 11 times in total.

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Re: Town Demand patch

Post by Korenn » 10 Oct 2011 13:40

A while back, I wrote an industry grf that matches the OCS industries. I've updated those to map to the right town effects, allowing play up to setting 5 in any climate.
temperate with tgc grf.png
temperate with tgc grf.png (94.53 KiB) Viewed 6776 times
tgc grf.zip
two grfs, add the industries after the cargo.
(14.24 KiB) Downloaded 159 times
Last edited by Korenn on 10 Oct 2011 22:31, edited 4 times in total.

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Re: Town Demand patch

Post by Korenn » 10 Oct 2011 13:41

Personally I play a lot with FIRS, so I've also written a small FIRS conversion grf that changes the FIRS cargo substitute types to the above values. Include this one after FIRS and it will allow play up to setting 6.
FIRS with conversion grf.png
FIRS with conversion grf.png (28.24 KiB) Viewed 6775 times
Attachments
firstd.zip
FIRS Town Demand grf
(12.54 KiB) Downloaded 186 times
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.

Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Town Demand patch

Post by Kogut » 10 Oct 2011 18:49

Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Re: Town Demand patch

Post by Korenn » 10 Oct 2011 19:49

I know, I've had considerable discussion about that with the devs already :)

But even if its present form doesn't make it into trunk, if enough people like the current patch that might motivate the devs to finish the features needed to rewrite this patch to newgrf support.

If people play this patch, please give feedback!
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.

User avatar
lawton27
Tycoon
Tycoon
Posts: 1418
Joined: 03 Aug 2009 14:29
Location: Manchester

Re: Town Demand patch

Post by lawton27 » 10 Oct 2011 19:51

Korenn wrote:But even if its present form doesn't make it into trunk, if enough people like the current patch that might motivate the devs to finish the features needed to rewrite this patch to newgrf support.
Allow me to show my approval of this patch :) A good idea indeed.

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Re: Town Demand patch

Post by Korenn » 11 Oct 2011 07:21

So as not to exclude people who prefer ECS, I've also written a grf that makes ECS compatible with this patch:
ECS in tropical.png
ECS in tropical.png (37.51 KiB) Viewed 6594 times
6 Cargoes are defined, which means all settings can be played. It requires the Town, Chemical and Agricultural Vectors so that the cargoes are valid, and Houses so that there is somewhere they can be shipped. Include after the ECS grfs.

Unfortunately it appears that in George's Vectors 'Water Supplies' are only spawned in Tropical, which means any setting that includes water will not allow town growth in Temperate or Arctic in random games. Addendum: apparently they do spawn, but only at the highest elevation level, which doesn't normally occur enough.
Attachments
ecstd.zip
ECS Town Demand
(12.54 KiB) Downloaded 162 times
Last edited by Korenn on 12 Oct 2011 09:37, edited 1 time in total.
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.

ziond
Engineer
Engineer
Posts: 50
Joined: 04 Mar 2009 10:55
Location: Moscow, Russia

Re: Town Demand patch

Post by ziond » 11 Oct 2011 07:59

Korenn wrote:... Unfortunately it appears that in George's Vectors 'Water Supplies' are only spawned in Tropical, which means any setting that includes water will not allow town growth in Temperate or Arctic in random games.
As wiki says:
http://www.tt-wiki.net/wiki/ECS_Town_Vector._Water_supply wrote:Build at least 15 levels above sea level
So you need to have a mountain :)

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Re: Town Demand patch

Post by Korenn » 11 Oct 2011 09:09

ziond wrote:
http://www.tt-wiki.net/wiki/ECS_Town_Vector._Water_supply wrote:Build at least 15 levels above sea level
So you need to have a mountain :)
Oh, really? That's... curious, to say the least. That won't really happen in practice unless you play with a heightmap.
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Re: Town Demand patch

Post by Korenn » 15 Oct 2011 07:07

I updated the windows binary package, it was missing the lang files! Curious how 11 people downloaded it but didn't say a word about it not working ;)
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2365
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Town Demand patch

Post by Lord Aro » 15 Oct 2011 07:15

missing lang files?

you should use 'make bundle' to stop that from happening
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Re: Town Demand patch

Post by Korenn » 15 Oct 2011 07:27

Lord Aro wrote:missing lang files?

you should use 'make bundle' to stop that from happening
No I shouldn't, because that involves installing and setting up MingW or similar. Unless you know of a way to do that from VS.
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9276
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Town Demand patch

Post by planetmaker » 15 Oct 2011 07:43

Korenn wrote:
Lord Aro wrote:missing lang files?

you should use 'make bundle' to stop that from happening
No I shouldn't, because that involves installing and setting up MingW or similar. Unless you know of a way to do that from VS.
Lord Aro is totally right. Lang files are specific for each version and should to be part of distributions. And also building and shipping a bundle you make sure you don't violate the licenses by not shipping the required license information.

User avatar
Korenn
Tycoon
Tycoon
Posts: 1628
Joined: 26 Mar 2004 01:27
Location: Netherlands, Enschede
Contact:

Re: Town Demand patch

Post by Korenn » 15 Oct 2011 08:04

planetmaker wrote:Lord Aro is totally right. Lang files are specific for each version and should to be part of distributions.
... what? I just uploaded a new version because I forgot the lang files. I wasn't claiming I shouldn't add them.

I'll add the GPL files to the zip.
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.

User avatar
FooBar
Tycoon
Tycoon
Posts: 6559
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Town Demand patch

Post by FooBar » 15 Oct 2011 08:51

Whenever I build in MSVS I use a virtual linux to do the make bundle.
But then I already had the virtual linux for grf development. Still, if you don't want mingw or msys...

Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Town Demand patch

Post by Kogut » 02 Nov 2011 16:40

Unfortunately towns are still growing without deliveries, also in game using binary from first post, without newgrfs. (for example with food required in arctic)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Town Demand patch

Post by Kogut » 02 Nov 2011 20:40

This problem was caused by "t->act_food - GetTownCargoDemand(t, TE_FOOD)) < 0" checks. "t->act_food - GetTownCargoDemand(t, TE_FOOD))" is unsigned int :roll:!

So I added conversion to int in following places:

Code: Select all

		if (IsTownEffectRequired(TE_FOOD) && int(t->act_food - GetTownCargoDemand(t, TE_FOOD)) < 0) return;
		if (IsTownEffectRequired(TE_WATER) && int(t->act_water - GetTownCargoDemand(t, TE_WATER)) < 0) return;
		if (IsTownEffectRequired(TE_GOODS) && int(t->act_goods - GetTownCargoDemand(t, TE_GOODS)) < 0) return;
		if (IsTownEffectRequired(TE_VALUABLES) && int(t->act_valuables - GetTownCargoDemand(t, TE_VALUABLES)) < 0) return;
		if (IsTownEffectRequired(TE_DEMAND1) && int(t->act_demand1 - GetTownCargoDemand(t, TE_DEMAND1)) < 0) return;
		if (IsTownEffectRequired(TE_DEMAND2) && int(t->act_demand2 - GetTownCargoDemand(t, TE_DEMAND2)) < 0) return;
Now it works. On demand I will upload binary (merged with cargodist).
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Town Demand patch

Post by Rubidium » 02 Nov 2011 20:57

A construct such as "a - b < 0" can also be rewritten to "a < b" which is both shorter and easier to understand (at least for me).

ZxBiohazardZx
Tycoon
Tycoon
Posts: 1534
Joined: 14 Mar 2006 12:46
Location: Netherlands
Contact:

Re: Town Demand patch

Post by ZxBiohazardZx » 03 Nov 2011 09:56

Rubidium wrote:A construct such as "a - b < 0" can also be rewritten to "a < b" which is both shorter and easier to understand (at least for me).
only if both a and b are real or int, in a bool case this is not always the case?

1 - 0 < 0 is an OR construct, not an AND, he checks for true in a AND b if im not mistaken in a weird way

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9276
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Town Demand patch

Post by planetmaker » 03 Nov 2011 10:04

in a boolean case you should use the boolean specific operators and and comparisons and not the ones dedicated to int or float numbers.

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: le_harv and 4 guests