Skip to main content
Topic: [patch] wegbauer and bridges, tunnels (Read 4806 times) previous topic - next topic

[patch] wegbauer and bridges, tunnels

The current implementation of the wegbauer wrt. bridges and tunnels is very buggy (you can notice this if you play with AIs). I've mainly rewritten wegbauer_t::check_for_bridge.

Let me comment some parts of the patch:
simconst.h: new: AUTOMATIC_TUNNELS, almost same as AUTOMATIC_BRIDGES
wegbauer.cc:
line 570: since curves in tunnels are allowed, we have to alter this checks.
line 799: check_for_bridges uses now tunnel- and brueckenbauer to check if you can built bridges. The checks at the begining aren't needed, since intern_calc_route searches already over existing tunnels and bridges.
line 1247, 1623: this checks was wrong
line 1755: Cost calculation was wrong, the way directly under the bridge wasn't considered.
line 1868: Don't built same tunnel again.

Re: [patch] wegbauer and bridges, tunnels

Reply #1
brueckenbauer Line 241 seems to allow road bridges ending on track?!? What is the purpose of that? That was added recently to avoid errors?

Otherwise there are many great ideas in this.

THird edit: I adjusted it a little to have the AI try for longer bridges first which have less slopes.

 

Re: [patch] wegbauer and bridges, tunnels

Reply #2
thumbs up! the Ai's like this patch :)
Parsley, sage, rosemary, and maggikraut.

Re: [patch] wegbauer and bridges, tunnels

Reply #3
brueckenbauer Line 241 seems to allow road bridges ending on track?!?
This prevents tram (track) bridges ending on a tile with tram and road.

Quote
THird edit: I adjusted it a little to have the AI try for longer bridges first which have less slopes.
But the change in r2422 is only my patch with small style changes, isn't it? Can you post/commit your patch?

Re: [patch] wegbauer and bridges, tunnels

Reply #4
@ gerw

Excellent patch indeed ;) ! I can see that AI now builds noticeably more bridges at reasonable places. And they also build long bridges too. (Please see the 1st and 2nd images)

However, I also observe some back-to-back tunnels which could better be avoided by using landscaping tool to flatten the land instead. (Please see the 3rd image) Such tunnels look a bit odd, and will incur regular maintenance costs which could be avoided by one-off landscaping.

Re: [patch] wegbauer and bridges, tunnels

Reply #5
The first one were built previously, the second one were less possible. Addin terraforming to the wayfinder will explode the possibilities and is thus not really very likely to occur, as the AI needs to find long ways two.

@gerw
I just added some lines in wegbauer.cc:
Code: [Select]
		// first: add long bridge
koord3d end = brueckenbauer_t::finde_ende( welt, from->get_pos(), zv, bruecke_besch, error, false );
if(  error == NULL  &&  end != ziel  &&  brueckenbauer_t::ist_ende_ok(sp, welt->lookup(end)) ) {
uint32 length = koord_distance(from->get_pos(), end);
next_gr.append(next_gr_t(welt->lookup(end), length * cost_difference + 2*welt->get_einstellungen()->way_count_slope ));
}
// then: add shortest possible bridge
end = brueckenbauer_t::finde_ende( welt, from->get_pos(), zv, bruecke_besch, error, true );
if(  error == NULL  &&  end != ziel  &&  brueckenbauer_t::ist_ende_ok(sp, welt->lookup(end)) ) {
uint32 length = koord_distance(from->get_pos(), end);
next_gr.append(next_gr_t(welt->lookup(end), length * cost_difference + 2*welt->get_einstellungen()->way_count_slope ));
}

This will add both tiles (the next slope and the first flat suitable tile) and thus make more natural bridges.

Re: [patch] wegbauer and bridges, tunnels

Reply #6
This will add both tiles (the next slope and the first flat suitable tile) and thus make more natural bridges.
But I think, simutrans will always prefer the shortest possible bridge. Do you have a situation, where simutrans build the "long" bridge?

Re: [patch] wegbauer and bridges, tunnels

Reply #7
Plenty, see below

Re: [patch] wegbauer and bridges, tunnels

Reply #8
This is, of course, very nice!

However, bridge building will fail, if you have a river, one tile free and an other river, maybe on flat land. Then there will be no "long" bridge, and the short bridge ends between both rivers. Have you any idea on that? Maybe add bridges to all free tiles (or at least the first ten or so)? I will try this, if you don't contradict heavily ;)

Re: [patch] wegbauer and bridges, tunnels

Reply #9
The old routine added several possible ending tiles. It is probably not very diffisult to do, but then you would end up with something, that would look suspiciously like the old routine, I fear. I think it is good enough, there are other big problems of AI wayfinding (like braindead station placements and so on).