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.
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?
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.