Patch: Minimum Town Distance

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

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Patch: Minimum Town Distance

Post by wleader » 15 Aug 2007 09:26

Well its been a while since I've done anything with the OpenTTD Code. I still have my subsidy distance patch to work on, but I thought I would create this quick patch first. For those that don't know I like to play with Very Low towns because it makes the towns more spread out. The trouble is that this is not always the case, I often get random maps that have open areas with no towns, and other spots with 3, 4, or sometimes 5 towns all close together. In order to get the towns spread out more evenly on the Low and Very Low town settings I have created this patch.

Revision 2 of this patch makes things configurable, and allows the original behavior of the game if desired. Also I have added the ability to set a minimum distance between industries. Previously, industries had to be a minimum distance from related industries, setting this value sets a distance requirement between all industries.

Revision 3 of this patch disables the distance check on industries that need to be built in a town like Water Towers and Banks.
Attachments
Minimum_Town_Distance_r3.patch
A patch to configure the minimum distance between towns and between industries.
(4.96 KiB) Downloaded 656 times
Last edited by wleader on 17 Aug 2007 13:07, edited 2 times in total.

finesse
Engineer
Engineer
Posts: 24
Joined: 07 Aug 2007 21:10

Re: Patch: Minimum Town Distance

Post by finesse » 15 Aug 2007 12:22

Great, I would love to see this in ChrisIN or even trunk. I've found on very large maps even with towns on Very Low theres still way too many around, will this also reduce the number of towns on very large maps as a side effect of the distance limit?
Image
Currently running: Bigos Patch Pack (forum link) with custom GRF pack.
win32 binary: bigos_pack_1.2.rar | patch file: 12.patch | GRF's: finessegrfv3.rar

chrissicom
Route Supervisor
Route Supervisor
Posts: 415
Joined: 07 Oct 2004 10:05

Re: Patch: Minimum Town Distance

Post by chrissicom » 15 Aug 2007 14:36

I also like this :) although cluttered city areas are realistic, it is not so nice for gaming :) I'll give this patch a try!

User avatar
PouncingAnt
Transport Coordinator
Transport Coordinator
Posts: 357
Joined: 09 Nov 2004 22:33

Re: Patch: Minimum Town Distance

Post by PouncingAnt » 15 Aug 2007 14:57

Good job, I've been looking for something like this for a while.
NB: the below challenges are still open for submission, so feel free to perform necromancy on them!
Try the PouncingAnt National Monopoly Challenge
Or even better, the PouncingAnt National Monopoly Challenge 2
Or better still, the PouncingAnt National Monopoly Challenge 3
Or, the PouncingAnt National Monopoly Challenge 4

Or try my scenario instead!

-(A lazy) OpenTTD Japanese Translator-
-(A lazy) PNGcodec user-
"You get what you pay for, so pay attention!"

Patches:
Company Station Stats

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Re: Patch: Minimum Town Distance

Post by wleader » 15 Aug 2007 15:57

finesse wrote:will this also reduce the number of towns on very large maps as a side effect of the distance limit?
If the limit was too high, then it might cause problems finding locations for new maps during generation. If that happened then the number of towns might be reduced. The numbers I selected should not be great enough for this to happen. The only effect this patch is supposed to have is to make the towns spread out on the map more evenly.

User avatar
athanasios
Tycoon
Tycoon
Posts: 3138
Joined: 23 Jun 2005 00:09
Contact:

Re: Patch: Minimum Town Distance

Post by athanasios » 15 Aug 2007 23:19

Can you put a slider to choose even higher numbers (>200)?
I am interested to see the effects of this patch on huge maps (4096).
http://members.fortunecity.com/gamesart
"If no one is a fool I am also a fool." -The TTD maniac.


I prefer to be contacted through PMs. Thanks.

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Re: Patch: Minimum Town Distance

Post by wleader » 16 Aug 2007 08:24

athanasios wrote:Can you put a slider to choose even higher numbers (>200)?
I am interested to see the effects of this patch on huge maps (4096).
My choice was to either make the distance a configurable value on the patch configuration window, or use constants like I did. If it were configurable then it would apply to all town density settings, which I suppose is OK. Imagine setting it to 50, but with towns on High. On the other hand its not always a good thing to just add more stuff to the patches window. Its already pretty cluttered.

I guess the real problem is that if this patch is to be considered for including in the trunk, there must be away to disable it. So if it were configurable, then setting it to 20 (the default value) would effectively retain the original play. That being said I guess a configurable option is the way to go.

I'll see if I can find some time to make this change later today.

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Re: Patch: Minimum Town Distance

Post by wleader » 16 Aug 2007 11:26

athanasios wrote:Can you put a slider to choose even higher numbers (>200)?
I am interested to see the effects of this patch on huge maps (4096).
Revision 2 of the patch (at the top of the thread) allows you to configure the distance. It also allows you to set a minimum distance between industries.

chrissicom
Route Supervisor
Route Supervisor
Posts: 415
Joined: 07 Oct 2004 10:05

Re: Patch: Minimum Town Distance

Post by chrissicom » 16 Aug 2007 16:49

Is the minimum distance between industries only valid for generating maps (which would the way I prefer it) or also when constructing industries during a game even with close industries enabled?

User avatar
Krysole
Engineer
Engineer
Posts: 1
Joined: 17 Feb 2006 22:51
Location: Australia

Re: Patch: Minimum Town Distance

Post by Krysole » 16 Aug 2007 17:28

Depending on how far you go with this, it could be nice to allow users to change the maximum number of towns within the limit as well. This way you still get those clusters, but only between 2 or 3 cities, rather than 7 or 8.

Either way, a great idea. Nice work :)

sc79
Director
Director
Posts: 586
Joined: 22 Feb 2005 09:51

Re: Patch: Minimum Town Distance

Post by sc79 » 17 Aug 2007 08:37

On the other hand its not always a good thing to just add more stuff to the patches window. Its already pretty cluttered.
Just because the patches window is pretty crowded isn't a reason to eliminate configuration options. The config file contains a huge number of settings that aren't available to change in game. Yes, its not quite as user friendly as the in game window, but hard coded (or simply excluded) settings aren't that user friendly either :)

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Re: Patch: Minimum Town Distance

Post by wleader » 17 Aug 2007 09:11

chrissicom wrote:Is the minimum distance between industries only valid for generating maps (which would the way I prefer it) or also when constructing industries during a game even with close industries enabled?
The code that checks distance from other industries is in PlaceInitialIndustry which as best I can tell is only called from GenerateIndustries. GenerateIndustries is called when a new map is generated or the Many Random Industries button is clicked in the Scenario Editor. A player can still fund a new industry anywhere they like, and random industries created by MaybeNewIndustry can spawn anywhere.
Krysole wrote:it could be nice to allow users to change the maximum number of towns within the limit as well. This way you still get those clusters, but only between 2 or 3 cities, rather than 7 or 8.
I did some thinking about this, and my first thought was that I could count the number of nearby towns, and then check the count of nearby towns. But then I realized that this has the potential to create a string of towns. Imagine town A is placed first, then town B is placed East of Town A. Finally Town C is placed West of Town A. Placing town C is ok, because its near to A but not B. Instead of being a cluster of two as the user might have originally wanted, its now a cluster of three. So to do this right, there would need to be a bit of code more clever than I am up for to determine what towns are in what clusters, and how many towns are in the cluster. Sorry, I just to plan on adding anything like this to the patch.
sc79 wrote:Just because the patches window is pretty crowded isn't a reason to eliminate configuration options.
Certainly. My thinking is that I might as well add the configuration option to make it easier to people testing the patch. If it does get included into ChrisIN or the Trunk, then I am sure someone will make an 'executive decision' about where the configuration stuff should go. I'm not really worried about it.

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Re: Patch: Minimum Town Distance

Post by wleader » 17 Aug 2007 13:06

I have found that with this patch applied, Water Towers never get created in the tropical climate (or are very likely to not be created) I think this is because the locations in towns are too near other industries, and it can't find suitable locations for them. This results in there being fewer Water Towers and Banks than originally intended. To correct this, I have disabled the distance check when the industry type is a water tower or bank.

Revision 3 of the patch is at the top of this thread.

User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: Patch: Minimum Town Distance

Post by belugas » 17 Aug 2007 13:26

You would be better off using something like :

Code: Select all

			for (i = 0; i < 2000; i++) {
+				tile = RandomTile();
+
+				if (_patches.industry_minimum_distance > 0 && 
+						!HASBIT(indspec->behaviour, INDUSTRYBEH_ONLY_INTOWN) &&
+						IsCloseToIndustry(tile, _patches.industry_minimum_distance))
+					continue;
+
+				if (CreateNewIndustry(tile, type) != NULL) break;
			}
		} while (--num);
Uncompiled code, just proof of concept.
Personnally, i don't like the idea of what you've just added. I do not know the reason of the INDUSTRYBEH_ONLY_INTOWN industries behaving like you just mentionned, but i think it is something else to check then this. Doing what you did is a hack, and not the cure to the real problem.

And i think that the idea of this patch is wrong. Somebody (another dev) mentionned that the whole idea of the IsCloseToTown(tile, 20) is due to the fact that a town is 19x19 big and 19/2 + 19/2 ~= 20 and that you have to deliver goods within 9 tiles of the city center to be paid, which leads to conclude that the town is 19x19 (9 + 9 + the center tile) max upon creation. Therefore, it would be wrong to change these values, no matter how attractive it would look to have towns evenly dispersed on the map. Don't forget that it is done by random...

You did a much better job with your other patches, if i may say so. Although I do understand that this is the very first versions of this one ;)
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Re: Patch: Minimum Town Distance

Post by wleader » 17 Aug 2007 16:06

belugas wrote:You would be better off using something like : (code removed)
Uncompiled code, just proof of concept.
Personnally, i don't like the idea of what you've just added. I do not know the reason of the INDUSTRYBEH_ONLY_INTOWN industries behaving like you just mentionned, but i think it is something else to check then this. Doing what you did is a hack, and not the cure to the real problem.
To be honest this just shows my unfamiliarity with the code, and c++. INDUSTRYBEH_ONLY_INTOWN isn't even something I was aware of. I also don't think in terms of bitmasks. That being said I'm not against being shown new things, as OpenTTD is the only c++ code that I even look at on a semi-regular basis. I like getting feedback like this because I means someone is looking at my code, which is way more gratifying then posting something and getting no responses.
belugas wrote: And i think that the idea of this patch is wrong. Somebody (another dev) mentionned that the whole idea of the IsCloseToTown(tile, 20) is due to the fact that a town is 19x19 big and 19/2 + 19/2 ~= 20 and that you have to deliver goods within 9 tiles of the city center to be paid, which leads to conclude that the town is 19x19 (9 + 9 + the center tile) max upon creation. Therefore, it would be wrong to change these values, no matter how attractive it would look to have towns evenly dispersed on the map. Don't forget that it is done by random...
I've been sitting here thinking about what you are saying for probably a half an hour, and I do not understand why it is wrong to increase the distance between town. Is there something I'm not seeing that it breaks. I could see things might get ugly if the value were reduced below 20. Clearly it is OK for towns to grow up against each other as they will do that in the natural progression of the game. Additionally they can also grow outside of initial boundaries of the local authority. Its not unfair in multi-player since everyone still plays on the same map.

Could you explain to my just why you think its wrong?
belugas wrote:You did a much better job with your other patches, if i may say so. Although I do understand that this is the very first versions of this one ;)
Thanks, I feel like a lot of the time I am stumbling around in the dark, So I must have been lucky in the past. Like I mentioned above c++ is not the language I use everyday.

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Re: Patch: Minimum Town Distance

Post by wleader » 04 Mar 2008 00:11

It looks like my hiatus is coming to an end now that the busy season at work is ending. So to get back into things I spent some time this afternoon making this patch work on a server. Anyone that wants to should be able to connect to it using 6.0 beta 4. Its an advertised server so just look for a server named 'Minimum Distance'. Enjoy.

wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Re: Patch: Minimum Town Distance

Post by wleader » 04 Jul 2008 17:19

And another update.

Update Aug 3: Wow, no one noticed that the code to enforce town distance wasn't working at all?
Attachments
Minumum Distance Patch r13979.patch
Updated to 13979, and fixed town distance bug.
(6.19 KiB) Downloaded 321 times

User avatar
Octopuss
Traffic Manager
Traffic Manager
Posts: 137
Joined: 08 Mar 2004 20:20
Location: Czech republic

Re: Patch: Minimum Town Distance

Post by Octopuss » 22 Sep 2008 12:13

I finally found this. Since I am not into coding/compiling/playing with code at all, I got no idea how to apply this to my current OpenTTD installation. Could you provide an .exe like I saw elsewhere a few times, please?

User avatar
Timitry
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 01 Oct 2004 15:28
Contact:

Re: Patch: Minimum Town Distance

Post by Timitry » 22 Sep 2008 14:25

If you're using windows, have a look at the Build-OTTD-sticky, it's really easy to use!

User avatar
Octopuss
Traffic Manager
Traffic Manager
Posts: 137
Joined: 08 Mar 2004 20:20
Location: Czech republic

Re: Patch: Minimum Town Distance

Post by Octopuss » 22 Sep 2008 19:59

Ok I believe I managed to get it to work using Tortoise. Last question though: I got the latest nightly source downloaded, I think it's 14384. When I did the "patch all" it started to give me messages about catching something and r13979. am I to understand these patches are all made for one specific version, or can I use them with newer builds as well?

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 7 guests