Town growth 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
scrooge
Engineer
Engineer
Posts: 51
Joined: 13 Jun 2004 12:06
Location: Iceland
Contact:

Town growth patch

Post 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.
Attachments
OTTD.tar.gz
Linux build (r3073)
(1.12 MiB) Downloaded 332 times
How it looks
How it looks
screenshot.png (70.51 KiB) Viewed 10835 times
town_growth.1.diff
r3077
original version
(2.14 KiB) Downloaded 409 times
Last edited by scrooge on 23 Oct 2005 03:13, edited 1 time in total.
MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Post 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
Last edited by MeusH on 21 Oct 2005 19:44, edited 2 times in total.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Post 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.
Last edited by MeusH on 21 Oct 2005 19:45, edited 3 times in total.
User avatar
scrooge
Engineer
Engineer
Posts: 51
Joined: 13 Jun 2004 12:06
Location: Iceland
Contact:

Post 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? :?
MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Post 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
Last edited by MeusH on 21 Oct 2005 19:46, edited 1 time in total.
MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Post 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
Attachments
Green tiles - possible house positions via 5 tile check I've proposed
Green tiles - possible house positions via 5 tile check I've proposed
Fivetiles_check.png (80.19 KiB) Viewed 1466 times
Blue tiles - possible house positions via this patch
Blue tiles - possible house positions via this patch
Yourpatch.png (78.84 KiB) Viewed 1477 times
Yellow tiles - possible house positions in (O)TTD
Yellow tiles - possible house positions in (O)TTD
TTD.png (83.46 KiB) Viewed 1471 times
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
scrooge
Engineer
Engineer
Posts: 51
Joined: 13 Jun 2004 12:06
Location: Iceland
Contact:

Post 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.
Attachments
town_growth.2.diff
r3077
MeusH's algorythm
(3.19 KiB) Downloaded 362 times
Last edited by scrooge on 23 Oct 2005 03:18, edited 1 time in total.
User avatar
nicfer
Director
Director
Posts: 529
Joined: 03 May 2005 20:50
Location: Somewhere in a country called Argentina

Post by nicfer »

I can't download the executable, I'm using FireFox and WinXpSp2
Sorry for my english I am argentinian
TTO don't crashes in Windows XP; XP crashes TTO

Formerly known as UnderBuilder.

MyMiniCity
User avatar
scrooge
Engineer
Engineer
Posts: 51
Joined: 13 Jun 2004 12:06
Location: Iceland
Contact:

Post 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 :wink:
But it would be great if someone would provide a windows version.
Last edited by scrooge on 22 Oct 2005 18:14, edited 1 time in total.
User avatar
webfreakz.nl
Director
Director
Posts: 627
Joined: 11 Aug 2005 08:22
Location: Localhost, 127.0.0.1, [The Netherlands: South Holland-> Westland]
Contact:

Post by webfreakz.nl »

if i try to apply the patch on WinXP with TortoiseSVN it sais something like 'no index found'...
# Programming is like sex, one mistake and you have to support it for the rest of your life. (Michael Sinz)
MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Post 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
User avatar
nicfer
Director
Director
Posts: 529
Joined: 03 May 2005 20:50
Location: Somewhere in a country called Argentina

Post 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.
Sorry for my english I am argentinian
TTO don't crashes in Windows XP; XP crashes TTO

Formerly known as UnderBuilder.

MyMiniCity
User avatar
scrooge
Engineer
Engineer
Posts: 51
Joined: 13 Jun 2004 12:06
Location: Iceland
Contact:

Post 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?
User avatar
webfreakz.nl
Director
Director
Posts: 627
Joined: 11 Aug 2005 08:22
Location: Localhost, 127.0.0.1, [The Netherlands: South Holland-> Westland]
Contact:

Post 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 :)
# Programming is like sex, one mistake and you have to support it for the rest of your life. (Michael Sinz)
Sacro
Tycoon
Tycoon
Posts: 1145
Joined: 18 Jun 2005 21:08
Location: Here
Contact:

Post by Sacro »

If your developing against the svn version, then i belive "svn diff > patch.diff" does the trick.
We Am De Best

Host of ThroughTheTube site
Gorfob
Engineer
Engineer
Posts: 22
Joined: 23 May 2004 00:00

Post 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.
User avatar
scrooge
Engineer
Engineer
Posts: 51
Joined: 13 Jun 2004 12:06
Location: Iceland
Contact:

Post by scrooge »

Thank you for your response, it's nice to see you like it :D
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 :P

[edit] Never mind, I figured it out right after posting this (how typical). I have also updated the diffs
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Google [Bot] and 43 guests