News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

Problems using "get_dirs ()" at the entrance of a tunnel.

Started by Yona-TYT, June 06, 2018, 12:55:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT


Dwachs

There is no mistake. It correctly reports directions. Direction bits in tunnel portal are not correct, if anything. If your script fails because it does not find a tile, you could add a check if the tile exists, before using it.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

The problem is that my script assumes that it is a via taramo when detecting "ribi = 5 or ribi = 10" and therefore it continues until getting a rib dei: 1, 2, 4, or 8 but these are never conquered.

I need to indicate in some way the end of the road when it is entered at the entrance of a tunnel.


        while(true){
            local til = tile_x(coora.x,coora.y,coora.z)
            local tunnel = til.find_object(mo_tunnel)
            local bridge = til.find_object(mo_bridge)
            local slope = til.get_slope()
            local type = false
            local t_type = false
            local way = false
            local ribi = false

            if (!tunnel && !bridge){
                coora.z = square_x(coora.x,coora.y).get_ground_tile().z       
            }

            if (tun){
                type = mo_tunnel
                local height_min = -3
                local height_max = my_tile(coord(coora.x, coora.y)).z
                for(;height_max>=height_min;height_max--){
                    local tile = tile_x(coora.x, coora.y, height_max)
                    if (tile.is_tunnel()){
                        coora.z = height_max   
                        break
                    }
                }
            }
            local t = tile_x(coora.x, coora.y, coora.z)
           
            foreach(obj in t.get_objects()){
                type = obj.get_type()
                if (type == mo_tunnel)
                    break
                else if (type == mo_crossing)
                    break
            }

            if (!type)
                return coora

            way = t.find_object(type)

            try {
                ribi = t.find_object(mo_way).get_dirs()
            }
            catch(ev) {
                return coora
            }
            if (obj){
                if (obj == mo_wayobj){
                    if(!way.is_electrified()){
                        way.mark()
                        if (!tun)
                            label_x.create(coora, player_x(1), translate("Connect here!."))

                        return coora
                    }
                    else{
                        t.remove_object(player_x(1), mo_label)
                        way.unmark()
                    }
                }
            }
            if(coora.x==coorb.x && coora.y==coorb.y && coora.z==coorb.z){
                if (t_type)
                    way.unmark()
                return 0
            }

            if ((ribi==1)||(ribi==2)||(ribi==4)||(ribi==8)){
                local waymark =    tile_x(glmark.x, glmark.y, glmark.z).find_object(type)
                    if (waymark){
                        waymark.unmark()
                    }
                glmark = coord3d(coora.x, coora.y, coora.z)   
                way.mark()           
                return coora
            }
            else
                way.unmark()   

            if (dir==2){
                if (t.is_bridge()){
                    coora.y -= way_is_bridge(coora, 5)
                    continue
                }

                if (ribi==5){
                   
                    coora.y--
                    continue
                }

                else if (ribi==6){
                    dir = vl[5]
                   
                    coora.x++
                    continue
                }
                else if (ribi==12){
                    dir = vl[6]
                    coora.x--
                   
                    continue
                }

                else if (ribi==14){
                    dir = vl[5]
                    coora.x++
                    continue
                }

                else if ((ribi==7 || ribi==11 || ribi==13 || ribi==15)){
                    coora.y--
                    continue
                }
                               
            }
           
            else if (dir==3){
                if (t.is_bridge()){
                    coora.y += way_is_bridge(coora, 5)
                    continue
                }

                if (ribi==5){
                   
                    coora.y++
                    continue
                }

                else if (ribi==3){
                    dir = vl[5]
                   
                    coora.x++
                    continue
                }

                else if (ribi==9){
                    dir = vl[6]
                   
                    coora.x--
                    continue
                }
               
                else if (ribi==11){
                    dir = vl[5]
                    coora.x++
                    continue
                }

                else if ((ribi==7 || ribi==13 || ribi==14 || ribi==15)){
                    coora.y++
                    continue
                }               
            }
            else if (dir==5){
                if (t.is_bridge()){
                    coora.x += way_is_bridge(coora, 10)
                    continue
                }

                if (ribi==10){
                    coora.x++
                   
                    continue
                }
                else if (ribi==12){
                    dir = vl[3]
                   
                    coora.y++
                    continue
                }
                else if (ribi==9){
                    dir = vl[2]
                    coora.y--
                    continue
                }
                else if (ribi==13){
                    dir = vl[2]
                    coora.y--
                    continue
                }
                else if ((ribi==7 || ribi==11 || ribi==14 || ribi==15)){
                    coora.x++
                    continue
                }               
            }
            else if (dir==6){
                if (t.is_bridge()){
                    coora.x -= way_is_bridge(coora, 10)
                    continue
                }

                if (ribi==10){
                    coora.x--
                   
                    continue
                }

                else if (ribi==3){
                    dir = vl[2]
                    coora.y--
                   
                    continue
                }
                else if (ribi==6){
                    dir = vl[3]
                   
                    coora.y++
                    continue
                }

                else if (ribi==7){
                    dir = vl[3]
                    coora.y++
                    continue
                }

                else if ((ribi==11 || ribi==14 || ribi==15)){
                    coora.x--
                    continue
                }           
            }
            return coora
        }

Yona-TYT

I'm still stuck with this.  :-[
for logic the ribi must be different to 10 and 5.  :o

Dwachs

you could check with

if (til.is_valid())

whether the tile exists. Also you could use dir::t_coord to replace the large if-block.
Parsley, sage, rosemary, and maggikraut.

Dwachs

There was a problem with the tunnel builder, which did set some wrong ribis. This is fixed in r8551.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Thank you very much, I will try that soon, many greetings! .  ;D ;D ;D ;D

Yona-TYT

Quote from: Dwachs on August 06, 2018, 08:03:46 PM
There was a problem with the tunnel builder, which did set some wrong ribis. This is fixed in r8551.

I'm using the r8555, but I'm afraid the problem is still precent.  :-[



Dwachs

Did you build the tunnel with r8555? Or is the tunnel already present in the savegame?
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Quote from: Dwachs on August 13, 2018, 06:20:53 AMDid you build the tunnel with r8555? Or is the tunnel already present in the savegame?
The tunnel was already in the savegame.

edit.Now if it works, I just had to build a new tunnel, thank you very much!.  ;D ;D ;D ;D