News:

Simutrans Forum Archive
A complete record of the old Simutrans Forum.

Connected roads

Started by Yona-TYT, December 24, 2016, 10:51:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT


Is it possible to know whether a section of road is connected ?, it would be helpful for the tutorial.


Yona-TYT

I suppose it is very difficult to achieve.  ???

Leartin

There was a patch some time ago, which basically allowed to look for a route that almost exists...

http://forum.simutrans.com/index.php?topic=13376.0

I guess the original creator of the patch did not complete it, but it seemed to generally work (did not test myself), and only needed some cleanup. Maybe you can find someone to pick it up - if that was implemented in general, using it in scripting should be the easier part...

Yona-TYT

At the moment it is not possible (for me) to differentiate between a connected and another that is not. It would be a good idea to identify the ends of the ways, so you can get their type. The crosses are a good example of my idea. ;)

An_dz

Can't you get the ribi of a way? Dead end roads have ribis 1, 2, 4, and 8. I guess it's with way_x::get_dirs().

The Ribis are the directions the road is connected to. It's a 4 bit digit, each bit is one direction (NESW).

Yona-TYT

#5
It works fine thanks  :P

Test: http://www.mediafire.com/file/5h5ua53npbappnf/Tutorial-pak128.zip



local c_way
for(local j=0;j<18;j++){


c_way = coord3d(67,23+j,0)
      if (c_way.y>29)
         c_way.z=-1

      if (tile_x(c_way.x, c_way.y, 0).find_object(mo_tunnel)){
         coorbord = label1
         continue
      }     

      if (!tile_x(c_way.x, c_way.y, -1).find_object(mo_way))break
      if ((way_x(c_way.x, c_way.y, c_way.z).get_dirs()==1) || (way_x(c_way.x, c_way.y, c_way.z).get_dirs()==2) || (way_x(c_way.x, c_way.y, c_way.z).get_dirs()==4)||(way_x(c_way.x, c_way.y, c_way.z).get_dirs()==8)){
      coorbord = c_way
      if (c_way.y!=23 && c_way.y!=40)break
      }

if(j==17){
   this.next_step()

   reset_pot()


               }

An_dz

Why don't you save way_x(c_way.x, c_way.y, c_way.z).get_dirs() in a variable?


local ribi = way_x(c_way.x, c_way.y, c_way.z).get_dirs()
if (ribi == 1 || ribi == 2 || ribi == 4 || ribi == 8) {

Yona-TYT

Quote from: An_dz on December 30, 2016, 08:50:55 PM
Why don't you save way_x(c_way.x, c_way.y, c_way.z).get_dirs() in a variable?


local ribi = way_x(c_way.x, c_way.y, c_way.z).get_dirs()
if (ribi == 1 || ribi == 2 || ribi == 4 || ribi == {

Ready, now you can try here:
www.mediafire.com/file/p6qnv8f6gssf4gy/Tutorial-stable.zip