From 6c00f2564e886b3d6d6bd89a1674ebb35a45b776 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 14 Sep 2024 21:36:50 +0300
Subject: [PATCH 30/30] Lua: Add edit.change_citizen_nationality()

See RM #856

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/scripting/api_server_edit.c | 15 +++++++++++++++
 server/scripting/api_server_edit.h |  2 ++
 server/scripting/tolua_server.pkg  |  7 +++++++
 3 files changed, 24 insertions(+)

diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c
index 03616a2104..5ab0b2124b 100644
--- a/server/scripting/api_server_edit.c
+++ b/server/scripting/api_server_edit.c
@@ -19,6 +19,7 @@
 #include "rand.h"
 
 /* common */
+#include "citizens.h"
 #include "map.h"
 #include "movement.h"
 #include "research.h"
@@ -1317,3 +1318,17 @@ void api_edit_change_city_size(lua_State *L, City *pcity, int change,
 
   city_change_size(pcity, city_size_get(pcity) + change, nationality, "script");
 }
+
+/**********************************************************************//**
+  Change nationality of the city citizens.
+**************************************************************************/
+void api_edit_change_citizen_nationality(lua_State *L, City *pcity,
+                                         Player *from, Player *to, int amount)
+{
+  LUASCRIPT_CHECK_STATE(L);
+  LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
+  LUASCRIPT_CHECK_ARG_NIL(L, from, 3, Player);
+  LUASCRIPT_CHECK_ARG_NIL(L, to, 4, Player);
+
+  citizens_nation_move(pcity, from->slot, to->slot, amount);
+}
diff --git a/server/scripting/api_server_edit.h b/server/scripting/api_server_edit.h
index 51672bea49..59c7ead2f0 100644
--- a/server/scripting/api_server_edit.h
+++ b/server/scripting/api_server_edit.h
@@ -122,5 +122,7 @@ void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount,
 
 bool api_edit_create_trade_route(lua_State *L, City *from, City *to);
 void api_edit_change_city_size(lua_State *L, City *pcity, int change, Player *nationality);
+void api_edit_change_citizen_nationality(lua_State *L, City *pcity,
+                                         Player *from, Player *to, int amount);
 
 #endif /* API_SERVER_EDIT_H */
diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg
index 35263887ee..5f38e372ba 100644
--- a/server/scripting/tolua_server.pkg
+++ b/server/scripting/tolua_server.pkg
@@ -251,6 +251,9 @@ module edit {
 
   void api_edit_change_city_size
     @ change_city_size(lua_State *L, City *pcity, int change, Player *nationality);
+  void api_edit_change_citizen_nationality
+    @ change_citizen_nationality(lua_State *L, City *pcity,
+                                 Player *from, Player *to, int amount);
 }
 
 /* Luadata module. */
@@ -433,6 +436,10 @@ function City:change_size(change, nationality)
   edit.change_city_size(self, change, nationality)
 end
 
+function City:change_nationality(from, to, amount)
+  edit.change_citizen_nationality(self, from, to, amount)
+end
+
 -- Server functions for Unit module
 function Unit:teleport(dest,
                        embark_to, allow_disembark,
-- 
2.45.2

