Build roads up to obstacles [In trunk: r18803]

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

Post Reply
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Build roads up to obstacles [In trunk: r18803]

Post by Terkhen »

The feature implemented by this patch is simple: when building roads and finding an obstacle, the road will be built up to that obstacle instead of not being built at all. This patch implements the feature suggested at FS #3318. As I mentioned at the Flyspray task, the patch code needs a review and some advice on how to implement it in a cleaner way. Any thoughts?

Version history
  • v05-r18798: Removed some parts included in trunk, code cleanup.
  • v04-r18762: Code cleanup, added some comments.
  • v03-r18683: Use DiagDir instead of a boolean value to check road direction (by Hirundo).
  • v02-r18483: Code cleanup.
  • v01-r18413: Initial release
Attachments
build_road_obstacles_v05-r18798.diff
(4.54 KiB) Downloaded 138 times
Last edited by Terkhen on 14 Jan 2010 23:12, edited 8 times in total.
petert
Tycoon
Tycoon
Posts: 3008
Joined: 02 Apr 2009 22:43
Location: Massachusetts, USA

Re: Build roads up to obstacles [v1-r18413]

Post by petert »

Terkhen wrote:The feature implemented by this patch is simple: when building roads and finding an obstacle, the road will be built up to that obstacle instead of not being built at all.
This is a great idea. It has been very annoying having to carefully replace the road so it doesn't interfere/touch the obstacle. I'm wondering, does the same thing happen for rails?
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Build roads up to obstacles [v1-r18413]

Post by Eddi »

may i request that exact same feature also for rivers in the scenario editor?
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Build roads up to obstacles [v1-r18413]

Post by Terkhen »

I'll implement it in v2. Besides canals and rivers, is there any other tool missing this feature?
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: Build roads up to obstacles [v1-r18413]

Post by Hirundo »

Is there any specific reason why the start_tile and end_tile parameters have to be swapped? Or why cost is renamed to total_cost?
Terkhen wrote:I'll implement it in v2. Besides canals and rivers, is there any other tool missing this feature?
Please keep separate features in separate patch files, though, for the sake of clarity.
Create your own NewGRF? Check out this tutorial!
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Build roads up to obstacles [v1-r18413]

Post by Terkhen »

There is no reason for renaming total_cost besides copy pasting from the rail code: I'll revert the name and remove other unneeded modifications to the source code at the next version. start_tile and end_tile have been swapped because the cost always appear above the tile at the first parameter. If they weren't changed, the cost would appear above the end_tile selected by the user by dragging, which is not the final tile of the road actually built. This is the same solution implemented at the rail code.
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Build roads up to obstacles [v03-r18683]

Post by Terkhen »

New version uploaded, you can find it at the first post.

There is nothing new besides removing all unneeded changes to source code and updating the patch to current trunk. Since rivers can be created as rectangles (as opposed to only as lines) deciding when to continue building is not trivial. Canals are only built as lines ingame, but since they can be built as rectangles in the scenario editor, they share the same problem.

Edit: v03 released.
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Build roads up to obstacles [v04-r18762]

Post by Terkhen »

Version v04 released. IMO the patch is complete. Any thoughts?
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: Build roads up to obstacles [v04-r18762]

Post by belugas »

I guess version v05 will be a bit smaller...
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
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Build roads up to obstacles [v05-r18798]

Post by Terkhen »

A smaller new version, after some parts of the code (including parts of Hirundo's code) made it to trunk. Get the diff at the first post or at the flyspray task.

Edit: Patch in trunk since r18803
Last edited by Terkhen on 14 Jan 2010 23:59, edited 1 time in total.
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: Build roads up to obstacles [In trunk: r18803]

Post by HackaLittleBit »

Terkhen wrote:Edit: Patch in trink since r18803
Trunk :wink:

EDIT:Drunk :mrgreen:
Last edited by HackaLittleBit on 02 Mar 2010 12:06, edited 1 time in total.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Build roads up to obstacles [In trunk: r18803]

Post by Eddi »

pherhaps he meant that he wanted a drink on it :p
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 35 guests