The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Yona-TYT on June 06, 2018, 12:55:16 PM

Title: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Yona-TYT on June 06, 2018, 12:55:16 PM
I already mentioned that problem here: https://forum.simutrans.com/index.php/topic,18238.msg173493.html#msg173493

Look at this:(https://www.mediafire.com/convkey/fd29/cczyp9swz9wdemk6g.jpg)
(https://www.mediafire.com/convkey/86e0/1shzbuzrkwpbdnc6g.jpg)

(https://www.mediafire.com/convkey/6251/8s8kuj8esb2hqtr6g.jpg)
(https://www.mediafire.com/convkey/a238/s9d4i968nx72zqa6g.jpg)
I think this is a mistake, do not you think?.
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Dwachs on June 06, 2018, 09:24:29 PM
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.
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Yona-TYT on June 06, 2018, 09:34:06 PM
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
        }
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Yona-TYT on June 22, 2018, 05:27:26 PM
I'm still stuck with this.  :-[
for logic the ribi must be different to 10 and 5.  :o
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Dwachs on June 22, 2018, 05:34:54 PM
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.
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: 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.
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Yona-TYT on August 07, 2018, 12:16:00 AM
Thank you very much, I will try that soon, many greetings! .  ;D ;D ;D ;D
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Yona-TYT on August 12, 2018, 04:43:20 PM
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.  :-[

(https://www.mediafire.com/convkey/13f8/1e5lr014uldghyy6g.jpg)
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Dwachs on August 13, 2018, 06:20:53 AM
Did you build the tunnel with r8555? Or is the tunnel already present in the savegame?
Title: Re: Problems using "get_dirs ()" at the entrance of a tunnel.
Post by: Yona-TYT on August 13, 2018, 09:49:07 AM
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