News:

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

[Scenario / Script] Process type_elevated as ignore_wt to use with forbid rules

Started by Yona-TYT, August 27, 2021, 01:33:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT

I have had a problem with "type_elevated" for a long time since there is no way to create a rule that allows me to remove them from the toolbar.

I was trying to create a new rule like "forbid_way_tool" to include the system types, but this is too difficult for me and I couldn't get it to work (at least not together, waytype and systemtype).

I decided to try something simpler, process the "type_elevated" as if they were an "ignore_wt" and excluding the waytypes would also exclude the "elevated" ones.

I have already tried it and it works well, it is not the best solution but it is the best I can make functional.

 

prissi

I am not sure if the key is happy that it cannot use elec\vated ways. Why not add the system type as second parameter.

A little offtopic:
Personally, I found it confusing that the toolbar is shrinking depending on the command. I would rather just print "Please select the xxx" message when the player chooses the wrong tool. That is much more helpful.

Yona-TYT

Quote from: prissi on August 27, 2021, 02:38:31 PMI am not sure if the key is happy that it cannot use elec\vated ways. Why not add the system type as second parameter.

I would like that, but getting it is out of my reach, I'm afraid.

In my attempt I managed to make the rules work for systemtype but removing the waytype rules, if I try to put them together it becomes a disaster since I did not find a logic that would make them work well together.

Quote from: prissi on August 27, 2021, 02:38:31 PMA little offtopic: Personally, I found it confusing that the toolbar is shrinking depending on the command. I would rather just print "Please select the xxx" message when the player chooses the wrong tool. That is much more helpful

At least for pak128, the intention is to reduce the number of icons in the toolbar so as not to confuse players (in pak128 there are many and it can be confusing).

Yona-TYT

Quote from: prissi on August 27, 2021, 02:38:31 PMI am not sure if the key is happy that it cannot use elec\vated ways. Why not add the system type as second parameter.
I will leave attached my attempt to achieve this, where I leave the commented lines is the logic that I could not solve, I do not understand well how it works.  :-[


Edit.Changing the systemtype like this will work but the waytype is removed:

--- /home/yonatyt/simu-git/simutrans-master/dataobj/scenario.cc    2021-08-27 14:15:54.972579000 -0400
+++ /home/yonatyt/simu-git/files/scenario.cc    2021-08-27 14:10:27.415688000 -0400
@@ -216,10 +216,10 @@
             diff = (sint32)toolnr - (sint32)other.toolnr;
         }
         if (diff == 0) {
-            //diff =   (sint32)system_type - (sint32)other.system_type;
+            diff =   (sint32)system_type - (sint32)other.system_type;
         }
         if (diff == 0) {
-            diff = ((sint32)waytype - (sint32)other.waytype );
+            //diff = ((sint32)waytype - (sint32)other.waytype );
         }
     
         lt = diff < 0;
@@ -425,16 +425,16 @@
         uint8 player_nr = player  ?  player->get_player_nr() :  PLAYER_UNOWNED;
         // first test waytype invalid_wt, then wt
         // .. and all players then specific player
-        for(uint32 wti = 0; wti<5; wti++) {
+        for(uint32 wti = 0; wti<4; wti++) {
             if (find_first(test) < forbidden_tools.get_count()) {
                 // there is something, hence forbidden
                 return false;
             }
             // logic to test all possible four cases
-            sim::swap<sint16>( wt, test.waytype );
-            if (test.waytype == invalid_wt) {
-                //sim::swap<sint16>( styp, test.system_type );
-                //if (test.system_type == type_invalid)
+            //sim::swap<sint16>( wt, test.waytype );
+            //if (test.waytype == invalid_wt) {
+            sim::swap<sint16>( styp, test.system_type );
+            if (test.system_type == type_invalid){
                 sim::swap<uint8>( player_nr, test.player_nr );
                 if (test.player_nr == PLAYER_UNOWNED) {
                     break;
@@ -446,7 +446,7 @@
     // then call script if available
     if (what_scenario == SCRIPTED) {
         bool ok = true;
-        const char* err = script->call_function(script_vm_t::FORCE, "is_tool_allowed", ok, (uint8)(player  ?  player->get_player_nr() : PLAYER_UNOWNED), tool_id, wt);
+        const char* err = script->call_function(script_vm_t::FORCE, "is_tool_allowed", ok, (uint8)(player  ?  player->get_player_nr() : PLAYER_UNOWNED), tool_id, wt );
         return err != NULL  ||  ok;
     }

Dwachs

This implementation does not look like a good idea.

You could also create a tutorial pakset, to easier limit available objects.
Parsley, sage, rosemary, and maggikraut.