Page 1 of 3
Town growth patch
Posted: 21 Oct 2005 17:23
by scrooge
After posting this:
http://tt-forums.net/viewtopic.php?t=21257 I decided to take matters into my own hands. I have never really written anything in C (except from something simple, like Hello World), so this is my first real try on it.
After few hours of mostly reading and a little of coding I had this nice little patch that forces towns to build roads with at least 3 squares between them. Now, any experienced TTD player can see that this would only lead to a lot of unused tiles in the cities, so I also made it possible to build two rows of hoses on each side of a road.
Please comment on the patch, it is probably not very well written but keep in mind that it's my first real C programming.
[edit] Upgraded the diffs after learning to use the svn, this should work better.
Posted: 21 Oct 2005 18:12
by MeusH
Great patch, this is a must for OTTD, altough I'd enchance the house building algorythm:
Your patch:
if tile distance from road <= 2
continue house building procedure on tile
My proposal:
if tile distance from road == 1
continue house building procedure on tile
if tile distance from road == 2
and 5 houses surround the tile //fix: was 4
continue house building procedure on tile
No C here, I want everyone to understand and comment this
This way, houses can be built in 3x3 or bigger blocks, but
Code: Select all
HHHHH H - House
HHHHH
RRRRR R - Road
will not happen
Posted: 21 Oct 2005 18:25
by DaleStan
MeusH wrote:This way, houses can be built in 3x3 or bigger blocks
Or bigger? How would a 4x4 block of houses get built? Or even just 3x4?
I can get to
Code: Select all
RRRRR RRRRRR
RHHHR RHHHHR
RH HR and RH HR
RH HR RH HR
RHHHR RHHHHR
RRRRR RRRRRR
But after that, no more houses will be built, because there are no spaces where all 4 sides are by a house.
Posted: 21 Oct 2005 19:24
by MeusH
DaleStan wrote:MeusH wrote:This way, houses can be built in 3x3 or bigger blocks
Or bigger? How would a 4x4 block of houses get built? Or even just 3x4?
I can get to
Code: Select all
RRRRR RRRRRR
RHHHR RHHHHR
RH HR and RH HR
RH HR RH HR
RHHHR RHHHHR
RRRRR RRRRRR
But after that, no more houses will be built, because there are no spaces where all 4 sides are by a house.
Code: Select all
RRRRR RRRRRR
RHHHR RHHHHR
RHTHR and RHTTHR
RHTHR RHTTHR
RHHHR RHHHHR
RRRRR RRRRRR
Let T be a free tile. According to my proposal, let's make checks:
Is tile distance from road 2? Yes, it is
Are 5 houses surrounding the tile? Yes, even 7 //fix: 5 was 4
Houses can be built there.
Posted: 21 Oct 2005 19:25
by scrooge
MeusH wrote:
This way, houses can be built in 3x3 or bigger blocks, but
Code: Select all
HHHHH H - House
HHHHH
RRRRR R - Road
will not happen
Why do you think this shouldn't happen?

Posted: 21 Oct 2005 19:29
by MeusH
It won't happen if just three houses are close to the tile. Five (fix: was "four") houses in the neighbourhood would allow next house to be built.
This would prevent two lines of houses be built near straight long piece of road
Posted: 21 Oct 2005 19:44
by MeusH
Take a look at the attached images:
Yellow tiles - possible house positions in (O)TTD
Blue tiles - possible house positions via this patch
Green tiles - possible house positions via 5 tile check I've proposed
In my method, each tile that is two squares away from the road will make a check whether at least five surrounding tiles are houses. You can see, there will be more houses in town, but there will be no double levels on a straight line. More realistic IMO
Posted: 21 Oct 2005 19:54
by DaleStan
MeusH wrote:Are 5 houses surrounding the tile? Yes, even 7 //fix: 5 was 4
Ah. You're counting the 8 surrounding tiles. I was as counting 4 out of 4.
There's a slight difference there.
Posted: 21 Oct 2005 21:23
by scrooge
Although I don't see very much use in having this restriction it took only few minutes to do, so why not...

But I would like to know why you think this is necessary. The odds of a town building a road in just one direction are very little, and I think that there will be more unbuilt tiles if you use this version (but that may also be because of something I have done in a wrong way).
[edit] Upgraded the diff, should now work with svn.
Posted: 21 Oct 2005 22:08
by nicfer
I can't download the executable, I'm using FireFox and WinXpSp2
Posted: 21 Oct 2005 22:53
by scrooge
To download the .tar.gz file in Firefox you'll have to right click on it and chose "Save Link As", but although you would download it it would be pretty useless to you because it's a
Linux build

But it would be great if someone would provide a windows version.
Posted: 22 Oct 2005 09:02
by webfreakz.nl
if i try to apply the patch on WinXP with TortoiseSVN it sais something like 'no index found'...
Posted: 22 Oct 2005 16:08
by MeusH
That's right. Take a look at the diff (first post in this thread)
Notice there is no +++ nor ---, just !. There is also no revision number. This is probably because of two different merging applications
Posted: 22 Oct 2005 17:52
by nicfer
Does this patch prevents towns from building lots of statues/fountains? It will be nice because I hate them because:
- 1. Decreases town population
2. Less passengers and mail will be atracted to my stations.
3. Sometimes, the statues and fountaines are builded above big buildings, that sometimes causes that my stations don't acept mail, goods, or even passengers.
Posted: 22 Oct 2005 18:22
by scrooge
@SLaY3r:
No, it doesn't reduce the number of statues and fountains. But this patch does partly cover your issues, because there will be less roads and more houses, and therefore higher density. It would be nice though to get rid of some of the statues and fountains.
@MeusH:
I used the 'diff' command in linux to produce the patch, is some other application prefered?
Posted: 22 Oct 2005 18:24
by webfreakz.nl
scrooge wrote:
@MeusH:
I used the 'diff' command in linux to produce the patch, is some other application prefered?
yes, TortoiseSVN needs a line in the diff which contains something like "Index:". Yours doesn't have this. Therefore I cannot merge your patch with the source

Posted: 22 Oct 2005 18:33
by Sacro
If your developing against the svn version, then i belive "svn diff > patch.diff" does the trick.
Posted: 23 Oct 2005 00:24
by Gorfob
Very promising looking patch, love to see it aded to the nightlies.
If this works 100% I would be the father (or mother if you so desire) of your babies.
Posted: 23 Oct 2005 02:39
by scrooge
Thank you for your response, it's nice to see you like it
But about this diff problem: I browsed the forum and google a little, and found out that most of the patches are made against svn. I would like to do that also, but I don't know a thing about svn, other that it is something fancy to get the latest version of a source code
I would appreciate it if some good sole would write a line or two about how I can use this svn, so I can be hip and cool like everybody else
[edit] Never mind, I figured it out right after posting this (how typical). I have also updated the diffs
Posted: 23 Oct 2005 03:31
by DaleStan
webfreakz.nl wrote:Therefore I cannot merge your patch with the source

Yes you can. Get
cygwin and use patch ("cd $OTTD_SRC_DIR && patch < $PATCHFILE"). Works beautifully.