News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

[bug r2614] Can't build underground way over other way

Started by z9999, August 26, 2009, 07:38:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

z9999

There are 2 problems.

[Slice view mode]
If there was a way on lower undeground level, I can't build underground way crossing it on upper undeground level.

[Underground view mode]
If there was a way on lower undeground level, Building crossing way will  strangely connect to way on lower level.

Note:
These problems might be solved by gerw's patch.

gerw

Quote from: z9999 on August 26, 2009, 07:38:16 AM
These problems might be solved by gerw's patch.
Which patch do you refer to? I don't think it's fixed by the tunnel-preview.

The bug lies in wegbauer::intern_calc_straight_route, I guess. But I think there was a revision after prissi's U slopes, which doesn't have this problem. Has anyone a guess, which revision introduced this bug?

Dwachs

Imho, the routine intern-calc-straight-route should be splitted in a tunnel and a normal version. I will prepare a patch.

Parsley, sage, rosemary, and maggikraut.

gerw

I've also found the problem:


Index: bauer/wegbauer.cc
===================================================================
--- bauer/wegbauer.cc   (revision 2614)
+++ bauer/wegbauer.cc   (working copy)
@@ -1338,15 +1339,19 @@
                        grund_t *bd_von = welt->lookup(pos);
                        if(  bd_von  ) {
                                // if we have a slope, we must adjust height correspondingly
-                               if(  bd_von->get_weg_hang()!=hang_t::flach  ) {
-                                       if(  ribi_typ(bd_von->get_weg_hang())==ribi_typ(diff)  ) {
+                               if(  bd_von->get_weg_hang() != hang_t::flach  ) {
+                                       if(  ribi_typ(bd_von->get_weg_hang()) == ribi_typ(diff)  ) {
                                                // upwards
                                                pos.z += Z_TILE_STEP;
                                        }
+                                       else {
+                                               ok = false;
+                                       }
                                }
                        }
                        else {
                                // check for slope down ...
                                bd_von = welt->lookup(pos+koord3d(0,0,-Z_TILE_STEP));
                                if(  bd_von  &&  bd_von->get_weg_hang()!=hang_t::flach) {
                                        route[route.get_count()-1].z -= 1;
@@ -1363,6 +1368,18 @@
                        if(  !bd_nach  ) {
                                // check for slope down ...
                                bd_nach = welt->lookup(pos + diff + koord3d(0,0,-Z_TILE_STEP));
+                               if(  bd_nach  &&  bd_nach->get_weg_hang() == hang_t::flach  ) {
+                                       // Don't care about _flat_ tunnels below.
+                                       bd_nach = NULL;
+                               }
+                               if( bd_nach ) {
+                                       // Correct slope on ground below?
+                                       if(  ribi_typ(bd_nach->get_weg_hang()) == ribi_typ(-diff)  ) {
+                                       }
+                                       else {
+                                               ok = false;
+                                       }
+                               }
                        }
                        if(  bd_nach == NULL  ){
                                bd_nach = new tunnelboden_t(welt, pos + diff, hang_t::flach);

z9999


gerw

Quote from: z9999 on August 26, 2009, 08:45:25 AM
Dragging tunnel tool ?
This wouldn't solve the problem, since it doesn't touch wegbauer.cc (I think).


This patch will solve the problems described in this thread:
Index: bauer/wegbauer.cc
===================================================================
--- bauer/wegbauer.cc   (revision 2614)
+++ bauer/wegbauer.cc   (working copy)
@@ -1338,21 +1338,13 @@
                        grund_t *bd_von = welt->lookup(pos);
                        if(  bd_von  ) {
                                // if we have a slope, we must adjust height correspondingly
-                               if(  bd_von->get_weg_hang()!=hang_t::flach  ) {
-                                       if(  ribi_typ(bd_von->get_weg_hang())==ribi_typ(diff)  ) {
+                               if(  bd_von->get_weg_hang() != hang_t::flach  ) {
+                                       if(  ribi_typ(bd_von->get_weg_hang()) == ribi_typ(diff)  ) {
                                                // upwards
                                                pos.z += Z_TILE_STEP;
                                        }
                                }
                        }
-                       else {
-                               // check for slope down ...
-                               bd_von = welt->lookup(pos+koord3d(0,0,-Z_TILE_STEP));
-                               if(  bd_von  &&  bd_von->get_weg_hang()!=hang_t::flach) {
-                                       route[route.get_count()-1].z -= 1;
-                                       pos.z -= Z_TILE_STEP;
-                               }
-                       }
                        if(  bd_von == NULL ) {
                                bd_von = new tunnelboden_t(welt, pos, hang_t::flach);
                                bd_von_new = true;
@@ -1363,6 +1355,18 @@
                        if(  !bd_nach  ) {
                                // check for slope down ...
                                bd_nach = welt->lookup(pos + diff + koord3d(0,0,-Z_TILE_STEP));
+                               if(  bd_nach  &&  bd_nach->get_weg_hang() == hang_t::flach  ) {
+                                       // Don't care about _flat_ tunnels below.
+                                       bd_nach = NULL;
+                               }
+                               if( bd_nach ) {
+                                       // Correct slope on ground below?
+                                       if(  ribi_typ(bd_nach->get_weg_hang()) != ribi_typ(-diff)  ) {
+                                               ok = false;
+                                       }
+                               }
                        }
                        if(  bd_nach == NULL  ){
                                bd_nach = new tunnelboden_t(welt, pos + diff, hang_t::flach);
@@ -1410,7 +1414,7 @@
                route.append(pos);
DBG_MESSAGE("wegbauer_t::calc_straight_route()","step %i,%i = %i",diff.x,diff.y,ok);
        }
-       ok = ok && (bautyp&tunnel_flag && grund_t::underground_mode!=grund_t::ugm_level ? pos.get_2d()==ziel.get_2d() : pos==ziel);
+       ok = ok && ( ((bautyp&tunnel_flag) && grund_t::underground_mode!=grund_t::ugm_level) ? pos.get_2d()==ziel.get_2d() : pos==ziel );

        // we can built a straight route?
        if(ok) {

We can delete these 8 lines, since the position with an slope below is already changed in line 1387: 'pos = bd_nach->get_pos();'.

z9999

Thank you, I will try your patch.
@gerw
Can you write a patch with "tab" instead of "space" in the future ?
Your patch always failes and I need to apply it manually.
I don't know how to solve this, sorry.

Quote
Hunk #1 FAILED at 1338.
patch: **** malformed patch at line 46: @@ -1410,7 +1414,7 @@

(And also, some of your patch files don't match number of "tabs" and sometimes fails to apply.)

gerw

Mmh. The spaces get lost, while copying from the console. Can you apply this one:

Index: bauer/wegbauer.cc
===================================================================
--- bauer/wegbauer.cc (revision 2614)
+++ bauer/wegbauer.cc (working copy)
@@ -1338,21 +1338,13 @@
grund_t *bd_von = welt->lookup(pos);
if(  bd_von  ) {
// if we have a slope, we must adjust height correspondingly
- if(  bd_von->get_weg_hang()!=hang_t::flach  ) {
- if(  ribi_typ(bd_von->get_weg_hang())==ribi_typ(diff)  ) {
+ if(  bd_von->get_weg_hang() != hang_t::flach  ) {
+ if(  ribi_typ(bd_von->get_weg_hang()) == ribi_typ(diff)  ) {
// upwards
pos.z += Z_TILE_STEP;
}
}
}
- else {
- // check for slope down ...
- bd_von = welt->lookup(pos+koord3d(0,0,-Z_TILE_STEP));
- if(  bd_von  &&  bd_von->get_weg_hang()!=hang_t::flach) {
- route[route.get_count()-1].z -= 1;
- pos.z -= Z_TILE_STEP;
- }
- }
if(  bd_von == NULL ) {
bd_von = new tunnelboden_t(welt, pos, hang_t::flach);
bd_von_new = true;
@@ -1363,6 +1355,16 @@
if(  !bd_nach  ) {
// check for slope down ...
bd_nach = welt->lookup(pos + diff + koord3d(0,0,-Z_TILE_STEP));
+ if(  bd_nach  &&  bd_nach->get_weg_hang() == hang_t::flach  ) {
+ // Don't care about _flat_ tunnels below.
+ bd_nach = NULL;
+ }
+ if( bd_nach ) {
+ // Correct slope on ground below?
+ if(  ribi_typ(bd_nach->get_weg_hang()) != ribi_typ(-diff)  ) {
+ ok = false;
+ }
+ }
}
if(  bd_nach == NULL  ){
bd_nach = new tunnelboden_t(welt, pos + diff, hang_t::flach);
@@ -1410,7 +1412,7 @@
route.append(pos);
DBG_MESSAGE("wegbauer_t::calc_straight_route()","step %i,%i = %i",diff.x,diff.y,ok);
}
- ok = ok && (bautyp&tunnel_flag && grund_t::underground_mode!=grund_t::ugm_level ? pos.get_2d()==ziel.get_2d() : pos==ziel);
+ ok = ok && ( ((bautyp&tunnel_flag) && grund_t::underground_mode!=grund_t::ugm_level) ? pos.get_2d()==ziel.get_2d() : pos==ziel );

// we can built a straight route?
if(ok) {


Quote from: z9999 on August 26, 2009, 02:45:19 PM
(And also, some of your patch files don't match number of "tabs" and sometimes fails to apply.)
This is maybe the same problem? Or are there tabs in these patches?

z9999

Quote from: gerw on August 26, 2009, 04:16:06 PM
Can you apply this one:

Yes, thank you. And it solved the problem.

Quote
This is maybe the same problem? Or are there tabs in these patches?

No, patch itself had no problem, but some part of code had mismatch indent problem.
But sorry, I forgot which patch had a problem.

Dwachs

should be solved in 2618. I used grund_t::get_vmove() to get the z-coordinates right, ribis of slopes are checked in is_allowed_step() anyway.
Parsley, sage, rosemary, and maggikraut.

gerw

Quote from: Dwachs on August 27, 2009, 06:59:17 PM
ribis of slopes are checked in is_allowed_step() anyway.
But not all kind of slopes. It is only checked, if they have the right direction, but they could have the wrong offset (or instead of a nordhang there could be a südhang). This should be fixed by the vmove-stuff now.

Edit: Nice fix :)

Edit2: One little thing: Imho, calculating the back-route should be disabled in normal underground mode, since it doesn't respect the z-value of the starting point.

Index: bauer/wegbauer.cc
===================================================================
--- bauer/wegbauer.cc (revision 2621)
+++ bauer/wegbauer.cc (working copy)
@@ -1400,7 +1400,7 @@
route.append(pos);
DBG_MESSAGE("wegbauer_t::calc_straight_route()","step %i,%i = %i",diff.x,diff.y,ok);
}
- ok = ok && (bautyp&tunnel_flag && grund_t::underground_mode!=grund_t::ugm_level ? pos.get_2d()==ziel.get_2d() : pos==ziel);
+ ok = ok && ( ((bautyp&tunnel_flag) && grund_t::underground_mode!=grund_t::ugm_level) ? pos.get_2d()==ziel.get_2d() : pos==ziel );

// we can built a straight route?
if(ok) {
@@ -1490,7 +1490,7 @@
}
else {
intern_calc_straight_route(start,ziel);
- if(max_n==-1) {
+ if(  max_n == -1  &&  ( !(bautyp&tunnel_flag)  ||  grund_t::underground_mode == grund_t::ugm_level  )  ) {
intern_calc_straight_route(ziel,start);
}
}


If you have (in cross section):

A                         B
___              ______
             ___/

if you build A->B, it won't find a route, but the back-route from B to A will end a level below A.

Dwachs

Quote from: gerw on August 28, 2009, 06:26:50 AM
If you have (in cross section):

A                         B
___              ______
             ___/

if you build A->B, it won't find a route, but the back-route from B to A will end a level below A.
Thanks for pointing this out!

However, I would suggest to change the termination conditoin in intern_calc_straight_route:

if (no tunnel building) || (sliced mode) || (ground at target exists) then compare 3d-coordinates else compare 2d-coordinates.

This will rule out the situation you described: the reverse route cannot be built since the ground at 'A' exists but cannot be reached.

The calculation of reverse routes can be helpful, where one part of the route is diagonal. Then it can happen that the forward route cannot be built but the reverse route is buildable since the curve is placed at a different position. Ie route calculation is not symmetric with respect to start and target ;)
Parsley, sage, rosemary, and maggikraut.