Page 1 of 1

[Patch] Canal tunnels

Posted: 22 Nov 2007 00:16
by d37373
I got stuck in a game this week and was inspired to make some water/canal tunnels (as mentioned in http://www.tt-forums.net/viewtopic.php? ... el#p615367 etc.)>

Features:
* New button on the dock toolbar to build water tunnels
* Ships can travel down the water tunnels.

Still needed:
* Graphical glitches at tunnel entry/exit
* Pathfinding - I don't really know where to begin making the pathfinder look down tunnels. Turning on YAPF for ships throws an assertion, but I don't understand YAPF enough to know why. This is what I'm working on now.
* Sprites - I'm using the road sprites for now. I'm no artist :)

I suspect the graphical glitches are caused by using the wrong values for _tunnel_fractcoord_n(dir) in VehicleEnter_TunnelBridge (tunnelbridge_cmd.cpp, line ~1440). Twiddling the numbers helps some, but I don't know the rationalisation for the existing numbers, so I don't know how permenent a solution that is. The correct values probably also depend on nwegrf ship sizes. Can somebody enlighten me?

Attached is a patch against r11487.

Also attached is a savegame to demonstrate the work so far.

Re: [Patch] Canal tunnels

Posted: 22 Nov 2007 05:33
by rabbit67890
wow :)

Re: [Patch] Canal tunnels

Posted: 22 Nov 2007 15:48
by thgergo
d37373 wrote:* Graphical glitches at tunnel entry/exit
I think that is caused by the tunnel is too small for the ship sizes, the road tunnel is too small for even a medium sized ship, doesnt it, or there is a bigger problem witch lies here?
The sprite witch is drawn on the top of the tunnelhead base, should be a lot bigger than the road one. And for the ship is drawn on previsious tile, the ship should appear later, if its possible.
But as you can see, a ship is bigger even a full tile, the ship should be cutted to two parts..
Anyway this is a cool patch:)

Re: [Patch] Canal tunnels

Posted: 22 Nov 2007 18:38
by Ben_K
I think you'll find the tunnel glitch is a known one all around. I can't remember the details, but I know it happens with the train tunnels too. Its a TTD problem I believe.

Re: [Patch] Canal tunnels

Posted: 22 Nov 2007 20:40
by thgergo
Ben_K wrote:I think you'll find the tunnel glitch is a known one all around. I can't remember the details, but I know it happens with the train tunnels too. Its a TTD problem I believe.
Just try george`s long vehicles...

Re: [Patch] Canal tunnels

Posted: 22 Nov 2007 22:08
by Rubidium
thgergo wrote:
Ben_K wrote:I think you'll find the tunnel glitch is a known one all around. I can't remember the details, but I know it happens with the train tunnels too. Its a TTD problem I believe.
Just try george`s long vehicles...
Only 'thing' is that in case of the long vehicles, the long vehicles are bugged and not (O)TTD(P). This because the NewGRF specs say the vehicles can have a maximum size and when that is exceeded, glitches will occur. The same as when you would make a building sprite larger than the tile itself. It is bound to give glitches.

Re: [Patch] Canal tunnels

Posted: 22 Nov 2007 23:11
by NCarlson
Probably makes more sense to do aqueducts first, seeing they're quite a bit more common.

Re: [Patch] Canal tunnels

Posted: 22 Nov 2007 23:57
by BigBB
NCarlson wrote:Probably makes more sense to do aqueducts first, seeing they're quite a bit more common.
Aqueduct are more realistic, too. I think no one in real live will make a tunnel for a super petroleum tanker :). Maybe we have anytimes seperated ships for open sea and for inland water-ways...

But this thread is for tunnels and not for "what will be better" :wink: ...
So: good idea and I hope you'll write a patch which have good chances (cooding style and so on) to get into trunk.

-BigBB

Re: [Patch] Canal tunnels

Posted: 23 Nov 2007 01:02
by athanasios
Finally someone patched this. :]
My only suggestion is make tunnels taller (>= 2 height). (Repeating myself here, requesting very hard things...)

Re: [Patch] Canal tunnels

Posted: 23 Nov 2007 13:22
by d37373
I'll probably get on to aqueducts/bridges once I've got the tunnels working to my satisfaction. Tunnels are a little simpler to code, so I started there.

@thgergo - where is that tunnel graphic from, and who made it? It looks like just what I need.

@athanasios - Making tunnels 2 high may also solve the graphical glitches. On the other hand, I'm not sure how easy it would be to code - might be simple, might not.

@ BigBB - I home that it will go into trunk too, but it's not ready yet! If anyone wants to help or has suggestions on my coding style etc. feel free.

Re: [Patch] Canal tunnels

Posted: 25 Nov 2007 00:08
by Born Acorn
BigBB wrote:Aqueduct are more realistic, too. I think no one in real live will make a tunnel for a super petroleum tanker :).
Well, you never know, if anyone with the money wanted such a piece of infrastructure, and it was proved to be economically feasible, it would most likely be done.

Re: [Patch] Canal tunnels

Posted: 26 Nov 2007 15:55
by prissi

Re: [Patch] Canal tunnels

Posted: 26 Nov 2007 17:54
by Born Acorn
Yes. It is known they exist for small narrowboats, and smaller boats in general, but not for panamax ships.

Re: [Patch] Canal tunnels

Posted: 26 Nov 2007 19:21
by Sir A. Boey
you could restrict the panama size ships from going into these tunnels...
I don't know much about coding but a coach isn't able to go into a traintunnel neither
so that's what I mean with restrictions...
Alow the small passenger ships to pass but not the cargo ships.I really like the idea
that and the one with canal bridges or the aquaducts, not very common in real life but
It would certainly make the game more enjoyable and it would look nicer 2.

Re: [Patch] Canal tunnels

Posted: 29 Nov 2007 13:47
by Bilbo
But the ships in openttd are not panama size ships - panamaxes have displacement of around 65000 tons, while ships in OpenTTD may have around 500-1000 tons (guessing by its capacities), which is much smaller than that, although still probably too large for small water tunnels as mentioned in examples above (I guess max 50 ton ship or 50 passenger ship could fit in these tunnels).

Re: [Patch] Canal tunnels

Posted: 29 Nov 2007 18:20
by charlymorton
Born Acorn wrote:Yes. It is known they exist for small narrowboats, and smaller boats in general, but not for panamax ships.
The Stad Ship Tunnel is planned in Norway and is supposed to be 1800 metres long, 33 metres high, 23 metres wide and 12 metres deep.

Not exactly panamax, but not exactly narrowboat either :)

Re: [Patch] Canal tunnels

Posted: 30 Nov 2007 00:14
by athanasios
That's interesting and valid reason for this patch. 12 meters is big depth.
But we should not introduce such tunnels prior to the date that this one is finished. For earlier days tunnels should be smaller (allowing only small ships).

Re: [Patch] Canal tunnels

Posted: 30 Nov 2007 03:05
by DaleStan
Which would be great. If only ships had a size.

Re: [Patch] Canal tunnels

Posted: 30 Nov 2007 16:43
by Bilbo
DaleStan wrote:Which would be great. If only ships had a size.
Best you can do is either add some field to the newGRF or apply some guess-o-matic function to "calculate" size given the cargo capacity (i.e. something like "anything with capacity under 150 units of cargo = small").