Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Sat May 25, 2013 4:24 pm

All times are UTC




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Town Demand patch
PostPosted: Mon Oct 10, 2011 1:40 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
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:
File comment: Diff versus r23012
town_demand.diff [32.42 KiB]
Downloaded 104 times
File comment: no grfs required for play.
toyland.png
toyland.png [ 32.79 KiB | Viewed 2626 times ]
File comment: Now with license!
win32.zip [5.32 MiB]
Downloaded 106 times


Last edited by Korenn on Sat Oct 15, 2011 8:23 am, edited 11 times in total.
Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Mon Oct 10, 2011 1:40 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
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.
Attachment:
temperate with tgc grf.png
temperate with tgc grf.png [ 94.53 KiB | Viewed 2627 times ]


Attachment:
File comment: two grfs, add the industries after the cargo.
tgc grf.zip [14.24 KiB]
Downloaded 79 times


Last edited by Korenn on Mon Oct 10, 2011 10:31 pm, edited 4 times in total.

Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Mon Oct 10, 2011 1:41 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
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.
Attachment:
FIRS with conversion grf.png
FIRS with conversion grf.png [ 28.24 KiB | Viewed 2626 times ]


Attachments:
File comment: FIRS Town Demand grf
firstd.zip [12.54 KiB]
Downloaded 92 times

_________________
Abunai!
Creator of the Openttd Challenge Spinoff, Town Demand patch
Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Mon Oct 10, 2011 6:49 pm 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2219
Location: Poland
@trunk inclusion: viewtopic.php?p=912809#p912809

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


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Mon Oct 10, 2011 7:49 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
Kogut wrote:

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!

_________________
Abunai!
Creator of the Openttd Challenge Spinoff, Town Demand patch


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Mon Oct 10, 2011 7:51 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Aug 03, 2009 2:29 pm
Posts: 1374
Location: Manchester
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.

_________________
==Flickr==


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Tue Oct 11, 2011 7:21 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
So as not to exclude people who prefer ECS, I've also written a grf that makes ECS compatible with this patch:
Attachment:
ECS in tropical.png
ECS in tropical.png [ 37.51 KiB | Viewed 2445 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:
File comment: ECS Town Demand
ecstd.zip [12.54 KiB]
Downloaded 73 times

_________________
Abunai!
Creator of the Openttd Challenge Spinoff, Town Demand patch


Last edited by Korenn on Wed Oct 12, 2011 9:37 am, edited 1 time in total.
Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Tue Oct 11, 2011 7:59 am 
Offline
Engineer
Engineer

Joined: Wed Mar 04, 2009 10:55 am
Posts: 45
Location: Moscow, Russia
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 :)


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Tue Oct 11, 2011 9:09 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
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.

_________________
Abunai!
Creator of the Openttd Challenge Spinoff, Town Demand patch


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Sat Oct 15, 2011 7:07 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
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 ;)

_________________
Abunai!
Creator of the Openttd Challenge Spinoff, Town Demand patch


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Sat Oct 15, 2011 7:15 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Thu Jun 25, 2009 4:42 pm
Posts: 2241
Location: Suffolk, UK
missing lang files?

you should use 'make bundle' to stop that from happening

_________________
AroAI - A really feeble attempt at an AI

  • Unix *is* user-friendly. It is not ignorant-friendly and idiot-friendly.
  • Duct tape is like the force. It has a light side, a dark side, and it holds the universe together... -- Carl Zwanzig
  • I am always doing that which I cannot do, in order that I may learn how to do it. -- Pablo Picasso
  • Time LINE...? Ehh, time isn't made out of LINES. It is made out of circles. That is why clocks are round! -- Caboose, RvB


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Sat Oct 15, 2011 7:27 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
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.

_________________
Abunai!
Creator of the Openttd Challenge Spinoff, Town Demand patch


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Sat Oct 15, 2011 7:43 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Wed Nov 07, 2007 10:44 pm
Posts: 6980
Location: Sol d
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.

_________________
Image
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Sat Oct 15, 2011 8:04 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1625
Location: Netherlands, Enschede
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.

_________________
Abunai!
Creator of the Openttd Challenge Spinoff, Town Demand patch


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Sat Oct 15, 2011 8:51 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6117
Location: The Netherlands
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...

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Wed Nov 02, 2011 4:40 pm 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2219
Location: Poland
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


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Wed Nov 02, 2011 8:40 pm 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2219
Location: Poland
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:
      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


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Wed Nov 02, 2011 8:57 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Feb 09, 2006 7:15 pm
Posts: 3706
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).


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Thu Nov 03, 2011 9:56 am 
Offline
Tycoon
Tycoon

Joined: Tue Mar 14, 2006 12:46 pm
Posts: 1527
Location: Netherlands
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

_________________
Screenshots topic
Scenarios&Heightmaps


Top
 Profile  
 
 Post subject: Re: Town Demand patch
PostPosted: Thu Nov 03, 2011 10:04 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Wed Nov 07, 2007 10:44 pm
Posts: 6980
Location: Sol d
in a boolean case you should use the boolean specific operators and and comparisons and not the ones dedicated to int or float numbers.

_________________
Image
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000-2013 phpBB Group

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2013.
Hosted by Zernebok Hosting.