From 21bd0591f7d7a45eb1489034bfed4664634ee780 Mon Sep 17 00:00:00 2001
From: Yona-TYT <yonatan.el.amigo@gmail.com>
Date: Mon, 4 Nov 2024 06:33:18 -0400
Subject: [PATCH] ADD param SystemType

---
 src/simutrans/dataobj/scenario.cc      | 5 ++++-
 src/simutrans/script/api/api_simple.cc | 1 +
 src/simutrans/script/api/api_simple.h  | 5 +++--
 src/simutrans/tool/simmenu.h           | 2 ++
 src/simutrans/tool/simtool.cc          | 9 +++++++++
 src/simutrans/tool/simtool.h           | 1 +
 6 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/simutrans/dataobj/scenario.cc b/src/simutrans/dataobj/scenario.cc
index 0d0e4ef0a..f75427a41 100644
--- a/src/simutrans/dataobj/scenario.cc
+++ b/src/simutrans/dataobj/scenario.cc
@@ -499,6 +499,8 @@ const char* scenario_t::is_work_allowed_here(const player_t* player, uint16 tool
 		bool is_drag_tool = false;
 		bool is_ctrl = false;
 		bool is_shift = false;
+		uint8 st = type_all;
+		
 		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))) {
@@ -506,6 +508,7 @@ const char* scenario_t::is_work_allowed_here(const player_t* player, uint16 tool
 				is_drag_tool = !two_tool->is_first_click();
 				is_ctrl = two_tool->is_ctrl_pressed();
 				is_shift = two_tool->is_shift_pressed();
+				st = two_tool->get_systemtype();
 			}
 			else if (tool_t *tool = dynamic_cast<tool_t*>(welt->get_tool(player_nr))) {
 				is_ctrl = tool->is_ctrl_pressed();
@@ -513,7 +516,7 @@ const char* scenario_t::is_work_allowed_here(const player_t* player, uint16 tool
 			}
 		}
 		static plainstring msg;
-		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));
+		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, st));
 
 		return err == NULL ? msg.c_str() : NULL;
 	}
diff --git a/src/simutrans/script/api/api_simple.cc b/src/simutrans/script/api/api_simple.cc
index 49a29e4c5..21d0eef16 100644
--- a/src/simutrans/script/api/api_simple.cc
+++ b/src/simutrans/script/api/api_simple.cc
@@ -74,6 +74,7 @@ SQInteger param<mytool_data_t>::push(HSQUIRRELVM vm, mytool_data_t const& v)
 	create_slot<bool>(vm, "is_drag_tool",	v.is_drag_tool);
 	create_slot<bool>(vm, "is_ctrl",		v.is_ctrl);
 	create_slot<bool>(vm, "is_shift",		v.is_shift);
+	create_slot<uint8>(vm, "systemtype",		v.systemtype);
 	return 1;
 }
 
diff --git a/src/simutrans/script/api/api_simple.h b/src/simutrans/script/api/api_simple.h
index 4d94d7156..2bac6c289 100644
--- a/src/simutrans/script/api/api_simple.h
+++ b/src/simutrans/script/api/api_simple.h
@@ -65,9 +65,10 @@ namespace script_api {
 		bool is_drag_tool;
 		bool is_ctrl;
 		bool is_shift;
+		uint8 systemtype;
 
-		mytool_data_t(koord3d pos, bool drag, bool ctrl, bool shift) :
-			start_pos(pos), is_drag_tool(drag), is_ctrl(ctrl), is_shift(shift)
+		mytool_data_t(koord3d pos, bool drag, bool ctrl, bool shift, uint8 st) :
+			start_pos(pos), is_drag_tool(drag), is_ctrl(ctrl), is_shift(shift), systemtype(st)
 		{}
 	};
 
diff --git a/src/simutrans/tool/simmenu.h b/src/simutrans/tool/simmenu.h
index d8098a22c..16f9caa4a 100644
--- a/src/simutrans/tool/simmenu.h
+++ b/src/simutrans/tool/simmenu.h
@@ -368,6 +368,8 @@ public:
 	virtual bool update_pos_after_use() const { return false; }
 
 	virtual waytype_t get_waytype() const { return invalid_wt; }
+
+	virtual systemtype_t get_systemtype() const { return type_all; }
 };
 
 /*
diff --git a/src/simutrans/tool/simtool.cc b/src/simutrans/tool/simtool.cc
index 53c16d844..83c44f7b9 100644
--- a/src/simutrans/tool/simtool.cc
+++ b/src/simutrans/tool/simtool.cc
@@ -2536,6 +2536,15 @@ waytype_t tool_build_way_t::get_waytype() const
 	return invalid_wt;
 }
 
+systemtype_t tool_build_way_t::get_systemtype() const
+{
+	const way_desc_t *desc = get_desc( welt->get_timeline_year_month());
+	if (desc) {
+		return desc->get_styp();
+	}
+	return type_all;
+}
+
 void tool_build_way_t::start_at( koord3d &new_start )
 {
 	if(  is_shift_pressed()  &&  (desc->get_styp() == type_elevated  &&  desc->get_wtyp() != air_wt)  ) {
diff --git a/src/simutrans/tool/simtool.h b/src/simutrans/tool/simtool.h
index 03039b733..8a4d691f5 100644
--- a/src/simutrans/tool/simtool.h
+++ b/src/simutrans/tool/simtool.h
@@ -306,6 +306,7 @@ public:
 	bool init(player_t*) OVERRIDE;
 	bool is_init_keeps_game_state() const OVERRIDE { return true; }
 	waytype_t get_waytype() const OVERRIDE;
+	systemtype_t get_systemtype() const OVERRIDE;
 	// remove preview necessary while building elevated ways
 	bool remove_preview_necessary() const OVERRIDE { return !is_first_click()  &&  (desc  &&  (desc->get_styp() == type_elevated  &&  desc->get_wtyp() != air_wt)); }
 };
-- 
2.47.0

