From af17f0627b259d04a7edef91d725fa666d921651 Mon Sep 17 00:00:00 2001
From: Yona-TYT <yonatan.el.amigo@gmail.com>
Date: Sat, 2 Nov 2024 00:19:20 -0400
Subject: [PATCH] Fix Pacth

---
 simutrans/script/new_scenario_template.nut |  3 ++-
 simutrans/script/scenario_base.nut         |  3 ++-
 src/simutrans/dataobj/scenario.cc          | 19 ++++++++++++++++++-
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/simutrans/script/new_scenario_template.nut b/simutrans/script/new_scenario_template.nut
index 8e79f388e..32374f638 100644
--- a/simutrans/script/new_scenario_template.nut
+++ b/simutrans/script/new_scenario_template.nut
@@ -117,9 +117,10 @@ persistent = {}
  * Does not work with waybuilding, use the rules.forbid_* functions in this case.
  *
  * @param pos is a table with coordinate { x=, y=, z=}
+ * @param tool is a table with current tool properties {coord3d start_pos, bool is_drag_tool, bool is_ctrl, bool is_shift}
  * @return null if allowed, an error message otherwise
  */
-function is_work_allowed_here(pl, tool_id, pos)
+function is_work_allowed_here(pl, tool_id, pos, tool)
 {
 	return null
 }
diff --git a/simutrans/script/scenario_base.nut b/simutrans/script/scenario_base.nut
index 9dd8200b0..6ae590726 100644
--- a/simutrans/script/scenario_base.nut
+++ b/simutrans/script/scenario_base.nut
@@ -55,9 +55,10 @@ function is_tool_allowed(pl, tool_id, wt)
  * Does not work with waybuilding etc use the rules.forbid_* functions in this case.
  *
  * @param pos is a table with coordinate { x=, y=, z=}
+ * @param tool is a table with current tool properties {coord3d start_pos, bool is_drag_tool, bool is_ctrl, bool is_shift}
  * @return null if allowed, an error message otherwise
  */
-function is_work_allowed_here(pl, tool_id, pos)
+function is_work_allowed_here(pl, tool_id, pos, tool)
 {
 	return null
 }
diff --git a/src/simutrans/dataobj/scenario.cc b/src/simutrans/dataobj/scenario.cc
index 10026573b..0d0e4ef0a 100644
--- a/src/simutrans/dataobj/scenario.cc
+++ b/src/simutrans/dataobj/scenario.cc
@@ -495,8 +495,25 @@ const char* scenario_t::is_work_allowed_here(const player_t* player, uint16 tool
 	// cannot be done for two_click_tool_t's as they depend on routefinding,
 	// which is done per client
 	if (what_scenario == SCRIPTED) {
+		koord3d start_pos = pos;
+		bool is_drag_tool = false;
+		bool is_ctrl = false;
+		bool is_shift = false;
+		uint8 player_nr = player ? player->get_player_nr() : PLAYER_UNOWNED;
+		if(player_nr != PLAYER_UNOWNED){
+			if (two_click_tool_t *two_tool = dynamic_cast<two_click_tool_t*>(welt->get_tool(player_nr))) {
+				start_pos = two_tool->get_start_pos();
+				is_drag_tool = !two_tool->is_first_click();
+				is_ctrl = two_tool->is_ctrl_pressed();
+				is_shift = two_tool->is_shift_pressed();
+			}
+			else if (tool_t *tool = dynamic_cast<tool_t*>(welt->get_tool(player_nr))) {
+				is_ctrl = tool->is_ctrl_pressed();
+				is_shift = tool->is_shift_pressed();
+			}
+		}
 		static plainstring msg;
-		const char *err = script->call_function(script_vm_t::FORCE, "is_work_allowed_here", msg, (uint8)(player ? player->get_player_nr() : PLAYER_UNOWNED), tool_id, pos);
+		const char *err = script->call_function(script_vm_t::FORCE, "is_work_allowed_here", msg, player_nr, tool_id, pos, script_api::mytool_data_t(start_pos, is_drag_tool, is_ctrl, is_shift));
 
 		return err == NULL ? msg.c_str() : NULL;
 	}
-- 
2.47.0

