The International Simutrans Forum

Development => Patches & Projects => Considered Patches => Topic started by: THLeaderH on July 28, 2017, 06:40:44 AM

Title: Ribi Arrow Patch
Post by: THLeaderH on July 28, 2017, 06:40:44 AM
I made a patch that visualizes the masked direction of way. This patch is made as a support patch of OTRP, but it works independently with OTRP.
The patch file is simutrans nightly r8275 based, and the patch can be easily integrated to the nightly trunk.
The patch is uploaded here. (https://drive.google.com/open?id=0B_rSte9xAhLDNVpQSU9LRmZtUFU) Source code can be seen on git. https://github.com/teamhimeh/simutrans/tree/ribi_arrow (https://github.com/teamhimeh/simutrans/tree/ribi_arrow)

The aim of this patch is visualizing direction of way as clear and simple as possible. To do this, I made tool_show_ribi, a simple tool that shows masked ribi of way. This tool puts arrows when it is called.
The arrow is a pak and the object class of the pak is misc. Its name is Ribi_Arrow. This object is required since this is a misc object. @Takamaro (https://twitter.com/cacapo2501) made a sample arrow addon and you can download it from here. (https://drive.google.com/open?id=0B_rSte9xAhLDanhta1ZsSVcwdzg) Also, we have to edit menuconf.tab to use this function. Add

simple_tool[36]=,:
# colon key is assigned to this function.


This patch is so useful when we build oneway roads. We can check very easily whether direction is set correctly.

(http://simutrans-germany.com/files/upload/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88_2017-07-28_%E5%8D%88%E5%BE%8C3.26.40.png)

I made OTRP binary with ribi arrow patch. The binary is r8275 based. Be sure that this requires misc.RibiArrow.pak!
win:https://drive.google.com/open?id=0B_rSte9xAhLDNXJvOXpBSkNMb1E (https://drive.google.com/open?id=0B_rSte9xAhLDNXJvOXpBSkNMb1E)
mac:https://drive.google.com/open?id=0B_rSte9xAhLDMzc4eGo4YmlTTUk (https://drive.google.com/open?id=0B_rSte9xAhLDMzc4eGo4YmlTTUk)
Title: Re: Ribi Arrow Patch
Post by: Yona-TYT on July 28, 2017, 08:42:37 AM
I like the idea a lot. ;D
Title: Re: Ribi Arrow Patch
Post by: IgorEliezer on July 29, 2017, 12:17:28 AM
This is fantastic! No kidding. :D
Title: Re: Ribi Arrow Patch
Post by: THLeaderH on July 29, 2017, 02:39:21 AM
The sample addon for pak64 was not compiled correctly, so I fixed it 8)
You can download it from the same link.
Title: Re: Ribi Arrow Patch
Post by: Dwachs on July 29, 2017, 09:15:03 AM
Good idea! This could also help to trouble-shoot route-finding problems to find non-connected pieces of ways.

Could you also modify this to change ribis of overhead lines? i.e., when key ':' is pressed it cycles through the different modes.
Title: Re: Ribi Arrow Patch
Post by: THLeaderH on July 29, 2017, 01:52:46 PM
Do you mean wayobj_t::dir? OK, I'll do that, but what is this parameter used for? It seems that this parameter, wayobj_t::dir, has no effect on routing.
Title: Re: Ribi Arrow Patch
Post by: Dwachs on July 29, 2017, 02:54:15 PM
yes, true. Forget about this request :)
Title: Re: Ribi Arrow Patch
Post by: Ves on July 29, 2017, 04:32:08 PM
What about a mode where general ribis on waytiles is shown, especially concerning the long time asked solution to the two unintentional endtiles making roads and rails unconnected, creating "no route" messages?
Title: Re: Ribi Arrow Patch
Post by: Yona-TYT on July 29, 2017, 05:02:15 PM
Quote from: Ves on July 29, 2017, 04:32:08 PM
What about a mode where general ribis on waytiles is shown, especially concerning the long time asked solution to the two unintentional endtiles making roads and rails unconnected, creating "no route" messages?
I create a code in "script" to solve this problem in the tutorial, but it is very long and does not work when there are interceptions.

(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1428&y=366&a=true&file=scrip_bord.png&t=WVeQguZ8IlGNHQV&scalingup=0)

I would be very happy with a simpler solution.  8)

Code:
    function get_fullway(coora, coorb, dir, obj, tun=false)
    {
        local tilea = tile_x(coora.x,coora.y,coora.z)
        local tileb = tile_x(coorb.x,coorb.y,coorb.z)
        local way = tilea.find_object(mo_way)
        if (!way)
            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{
                    tilea.remove_object(player_x(1), mo_label)
                    way.unmark()
                }
            }
        }
         
        local r_dir = way_x(coora.x, coora.y, coora.z).get_dirs()
        if (dir == 0) dir = c_dir(coora, coorb, r_dir)
        local c_way = coora
        local c_z = false
        local ribi = 0
        local vl = array(10)
        vl[3]=3
        vl[5]=5
        vl[2]=2
        vl[6]=6
        if (dir==1){

            if (r_dir==2 || r_dir==10)
                dir=6
            else if (r_dir==4 || r_dir==5)
                dir=2
            else if (r_dir==3){
                tilea.find_object(mo_way).unmark()
                dir=2
                coora.y--
            }
            else if (r_dir==6){
                tilea.find_object(mo_way).unmark()
                dir=3
                coora.y++
            }
        }
        else if (dir==2){

            if (r_dir==1)
                coora.y--
        }
        else if (dir==3){

            if (r_dir==4)
                coora.y++
        }
        else if (dir==4){

            if (r_dir==1 || r_dir==5)
                dir=3
            else if (r_dir==8 || r_dir==10)
                dir=5
            else if (r_dir==3){
                tilea.find_object(mo_way).unmark()
                dir=5
                coora.x++
            }
            else if (r_dir==9){
                tilea.find_object(mo_way).unmark()     
                dir=6
                coora.x--
            }
        }
        else if (dir==5){

            if (r_dir==2)
                coora.x++
        }
        else if (dir==6){

            if (r_dir==8)
                coora.x--
        }
        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)
            if (t.find_object(mo_way))
                type = mo_way
            if (t.find_object(mo_tunnel))
                type = mo_tunnel
            if (t.find_object(mo_crossing))
                type = mo_crossing
            if (tun || obj)
                type = mo_way
            if (!type)
                return coora
            way = t.find_object(type)
            ribi = t.find_object(mo_way).get_dirs()
            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: Ribi Arrow Patch
Post by: TurfIt on August 01, 2017, 03:22:40 AM
Quote from: THLeaderH on July 28, 2017, 06:40:44 AM
This patch is so useful when we build oneway roads. We can check very easily whether direction is set correctly.
I'd say it's a necessity for oneway roads!

Can the illusion that Simutrans has diagonals be maintained?  i.e. Needs diagonal arrows.
The neighbouring tile checks required to do that should also make it simple to implement displaying a 'x' or something to highlight unconnected neighboring ways.

In the attached, the yellow arrow pointing the wrong way to the oneway road shouldn't be there; Depends on the order the roads are built - I guess ribis aren't always being set correctly.