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
}