This method makes it easier to solve the bridge problem in the tutorial.
0001-Script-API-add-get_cursor_pos.patch
function bridgeConstructionHandler(coord_a, coord_b){
local cursor_pos = world.get_cursor_pos()
//gui.add_message(cursor_pos.tostring()+" "+coord_a.tostring()+" "+coord_b.tostring() )
if( ( cursor_pos.x == coord_a.x && cursor_pos.y == coord_a.y )|| ( cursor_pos.x == coord_b.x && cursor_pos.y == coord_b.y ) ){
return null
}
else {
local pointer_a = my_tile(coord_a).find_object(mo_pointer)
local pointer_b = my_tile(coord_b).find_object(mo_pointer)
if ( pointer_a || pointer_b ){
return null
}
}
return ""
}
This would only return the end tile, dragging would still work the other way round.
Quote from: prissi on March 24, 2026, 01:32:23 PMThis would only return the end tile, dragging would still work the other way round.
Exactly, the idea is to allow dragging to work but restrict the tiles in the middle to prevent the bridge from being built with a smaller size than required. I've tested it and it works very well.
Why then not exclude all intermediate tiles with the forbid rect routines? That should do the same but is just an additional line.
Quote from: prissi on March 25, 2026, 12:05:01 PMWhy then not exclude all intermediate tiles with the forbid rect routines? That should do the same but is just an additional line.
The problem is that it seems impossible to lock multiple map areas.
So, you have to lock the tool for the entire map. Then you unlock the area where building is allowed. But then you have the problem of locking fields within that unlocked area. And that's precisely what doesn't seem to work.
Even enabling the two end fields individually doesn't work.
Therefore, the default behavior should be that when a range is allowed, the area outside it is automatically locked. Then, fields within the allowed range could be locked using a prohibition rule.
Currently, there is only one allow and one block option. However, it's not possible to define multiple ranges with multiple calls.
Believe me, I've tried many combinations, but haven't achieved the desired result.
Quote from: Yona-TYT on March 23, 2026, 11:09:21 PMThis method makes it easier to solve the bridge problem in the tutorial.
0001-Script-API-add-get_cursor_pos.patch
function bridgeConstructionHandler(coord_a, coord_b){
local cursor_pos = world.get_cursor_pos()
//gui.add_message(cursor_pos.tostring()+" "+coord_a.tostring()+" "+coord_b.tostring() )
if( ( cursor_pos.x == coord_a.x && cursor_pos.y == coord_a.y )|| ( cursor_pos.x == coord_b.x && cursor_pos.y == coord_b.y ) ){
return null
}
else {
local pointer_a = my_tile(coord_a).find_object(mo_pointer)
local pointer_b = my_tile(coord_b).find_object(mo_pointer)
if ( pointer_a || pointer_b ){
return null
}
}
return ""
}
I still believe this solution is fine; it allows building from both ends (a or b), dragging the cursor works without problems, and the restriction on the middle coordinates is perfect and is restricted only when the click is released.
I also think that "world.get_cursor_pos()" can be useful in other places
@Yona
They decide what ends up in the main.
Quote from: Andarix on March 25, 2026, 03:45:37 PMCurrently, there is only one allow and one block option. However, it's not possible to define multiple ranges with multiple calls.
Here is a preliminary, untested WIP patch that allows tool rules to be stacked. However, I am not sure whether this will work for bridges specifically because I believe the dragged end of the bridge will need is_work_allowed_here = true for the preview to be visible.
I Fail to see why stacked rules are needed. Forbid everywhere, allow start tile allow end tile only. No stacking needed, should already working. In the worst case, one need 5 forbidden rectangles, but it should work with rather 2 allowed ones, only allowing the start and end tiles.
Quote from: prissi on March 26, 2026, 12:41:27 PM.... Forbid everywhere, allow start tile allow end tile only. ....
Because that's precisely what doesn't work. At least, I couldn't get it to work.
Since you disagree, then define it in a way that does work. Feel free to use the test code I attached (https://forum.simutrans.com/index.php?msg=212300).
That worked for my first coding attempt. However, you could build bridges on the rest of the map.