News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

Tunnel tool ignores is_work_allowed_here()

Started by Yona-TYT, December 13, 2024, 08:42:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT

There were changes to the tunnel builder a while back that caused the "is_work_allowed_here" to be ignored when ground is not suitable.

In the tutorial there is a message that says "[Ctrl] must be pressed to build the tunnel entrance", but I can no longer get this message to appear because of the above.

The code for this on tunnelbauer.cc is:
        if (const char* err = welt->get_scenario()->is_work_allowed_here(player, TOOL_BUILD_TUNNEL|GENERAL_TOOL, wegtyp, desc->get_name(), pos)) {
            if (msg) {
                *msg = err;
            }
            return koord3d::invalid;
        }

But I have no idea how to fix it.  :-[

I should also mention that there was an infinite loop issue related to this: https://forum.simutrans.com/index.php/topic,22105.msg202548.html

prissi

#1
Did you call any function in is_work_allowed_here? That function must be fast and suspending the script do to calls or long execution will crash simutrans. It is called 100,000 times for every possible tile when building long ways. Use this function only when rules does not work. And please do not call the GUI from is_work_allowed_here. The whole event loop waits for you to finish quickly.

For the same reason, the script is not called if the ground is unsuitable, as these tests fail faster.

But on which line of tunnelbuilder you are referring too which was changed?

EDIT: Indeed, the starting tile of bridges and tunnels was never checked.

Yona-TYT

Quote from: prissi on December 14, 2024, 02:43:36 AMAnd please do not call the GUI from is_work_allowed_here.
Hahaha, this is the second time I've been told that.

I currently just call gui.add_message() there just to help me with debugging.  ;)

prissi

Anyway, now the starting tiles should be checked.

Yona-TYT

#4
Quote from: prissi on December 14, 2024, 03:21:14 AMAnyway, now the starting tiles should be checked.
I did a test, but it doesn't work, it should run "is_work_allowed_here" when clicking there.

Script: test-tunnel.zip



Captura de pantalla -2024-12-13 23-31-10.png

prissi

No, as intended. It first test the grund and and only if suitable runs the scenario check because the latter takes so long. And please do not open popup from is_work_allowed_here. That function must immediately return or the game could hang. (I mean, the interaction and unloading etc. hangs until this function has returned.)

Also, this is unsuitable ground for a tunnel in any case. SO why build a tunnel there? Or change the text to "Build a tunnel portal here".

Yona-TYT

Quote from: prissi on December 14, 2024, 08:19:26 AMAlso, this is unsuitable ground for a tunnel in any case. SO why build a tunnel there? Or change the text to "Build a tunnel portal here".
The idea is to use Ctrl to build the tunnel entrance, then the popup should give that warning.

Andarix

I would rather start with the Ctrl key and not the tunnel.

If the Ctrl key is not pressed, display the message.

prissi

That could be checked in is tool allowed, probably.

Yona-TYT

I had thought about using rules, but these also don't show a popup when clicking.
The only thing I could think of was this:
label_t <- tile_x(90, 198, 6)
function is_scenario_completed(pl)
{
local lab = label_t.find_object(mo_label)
if(lab){
if(label_t.is_marked()){
lab.set_text("Press [Ctrl] to build a tunnel entrance here")
}
else{
lab.set_text("Place a Tunnel here!.")
}
}
return 0
}

function is_work_allowed_here(pl, tool_id, name, pos, tool)
{
if(tool.is_ctrl){
return null
}
else return ""
}

prissi

Why are the instructions not in the scenario page? That should be enough.

(Personally, I think this part of the scenario is very advanced stuff, and rather normal tunnel building would be better taught first.

Yona-TYT

Quote from: prissi on December 17, 2024, 04:20:28 AMWhy are the instructions not in the scenario page? That should be enough.
Yes the instructions are already in the scenario window, however I like to make it a bit more interactive by using text labels, those kinds of details make it more fun too.

Quote from: prissi on December 17, 2024, 04:20:28 AM(Personally, I think this part of the scenario is very advanced stuff, and rather normal tunnel building would be better taught first.
I agree with you that it is difficult, although a normal tunnel is already built in a previous chapter.

I have always wanted to improve this, but underground tiles are a pain.

prissi

Maybe split it into two tutorials, one for the basics and the second for special stuff like underground.

If the tutorial is too long, potential players will also use interest.

Yona-TYT

Quote from: prissi on December 17, 2024, 04:20:28 AM(Personally, I think this part of the scenario is very advanced stuff, and rather normal tunnel building would be better taught first.


I think if you follow the instructions correctly and use the slice map view, then I have hope that no one will get stuck here.

I've made a few adjustments to simplify things, please try again.

Savegame: tutorial_pak64-33.sve

Captura de pantalla -2024-12-18 02-23-45.png