From 42638764f022e46361efb8163c8b93765410a70b Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 17 May 2025 01:51:00 +0300
Subject: [PATCH 48/48] Lua: Add Plr:has_embassy() and Plr:has_team_embassy()

Requested by Dean Brown

See RM #1237

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/scriptcore/api_game_methods.c | 26 ++++++++++++++++++++++++++
 common/scriptcore/api_game_methods.h |  7 ++++++-
 common/scriptcore/tolua_game.pkg     |  6 +++++-
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/common/scriptcore/api_game_methods.c b/common/scriptcore/api_game_methods.c
index 5015d06e61..08b0b403d0 100644
--- a/common/scriptcore/api_game_methods.c
+++ b/common/scriptcore/api_game_methods.c
@@ -817,6 +817,32 @@ const char *api_methods_get_diplstate(lua_State *L, Player *pplayer1,
   return Qn_(diplstate_type_name(player_diplstate_get(pplayer1, pplayer2)->type));
 }
 
+/**********************************************************************//**
+  Return whether player has an embassy with target player.
+**************************************************************************/
+bool api_methods_player_has_embassy(lua_State *L, Player *pplayer,
+                                    Player *target)
+{
+  LUASCRIPT_CHECK_STATE(L, FALSE);
+  LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
+  LUASCRIPT_CHECK_ARG_NIL(L, target, 3, Player, FALSE);
+
+  return player_has_embassy(pplayer, target);
+}
+
+/**********************************************************************//**
+  Return whether player's team has an embassy with target player.
+**************************************************************************/
+bool api_methods_player_has_team_embassy(lua_State *L, Player *pplayer,
+                                         Player *target)
+{
+  LUASCRIPT_CHECK_STATE(L, FALSE);
+  LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
+  LUASCRIPT_CHECK_ARG_NIL(L, target, 3, Player, FALSE);
+
+  return team_has_embassy(pplayer->team, target);
+}
+
 /**********************************************************************//**
   Return if a unit can upgrade considering where it is now.
   If is_free is FALSE, considers local city and the owner's treasury.
diff --git a/common/scriptcore/api_game_methods.h b/common/scriptcore/api_game_methods.h
index cf75ff86e8..e2314b8b82 100644
--- a/common/scriptcore/api_game_methods.h
+++ b/common/scriptcore/api_game_methods.h
@@ -128,7 +128,12 @@ bool api_methods_player_can_build_impr_direct(lua_State *L, Player *pplayer,
 
 City *api_methods_player_primary_capital(lua_State *L, Player *pplayer);
 
-const char *api_methods_get_diplstate(lua_State *L, Player *pplayer1, Player *pplayer2);
+const char *api_methods_get_diplstate(lua_State *L, Player *pplayer1,
+                                      Player *pplayer2);
+bool api_methods_player_has_embassy(lua_State *L, Player *pplayer,
+                                    Player *target);
+bool api_methods_player_has_team_embassy(lua_State *L, Player *pplayer,
+                                         Player *target);
 
 /* Tech Type */
 const char *api_methods_tech_type_rule_name(lua_State *L, Tech_Type *ptech);
diff --git a/common/scriptcore/tolua_game.pkg b/common/scriptcore/tolua_game.pkg
index 8110cc4313..8c43ef8352 100644
--- a/common/scriptcore/tolua_game.pkg
+++ b/common/scriptcore/tolua_game.pkg
@@ -12,7 +12,7 @@
 *****************************************************************************/
 
 /*****************************************************************************
-  ADVERTISEMENT: do not attempt to change the name of the API functions.
+  ADVERTISEMENT: Do not attempt to change the name of the API functions.
   They may be in use in Lua scripts in savefiles, so once released, the
   name and signature cannot change shape even in new major versions of
   Freeciv, until the relevant save format version can no longer be loaded.
@@ -236,6 +236,10 @@ module Player {
 
   const char *api_methods_get_diplstate
     @ diplstate(lua_State *L, Player *pplayer1, Player *pplayer2);
+  bool api_methods_player_has_embassy
+    @ has_embassy(lua_State *L, Player *pplayer, Player *target);
+  bool api_methods_player_has_team_embassy
+    @ has_team_embassy(lua_State *L, Player *pplayer, Player *target);
 }
 
 module methods_private {
-- 
2.47.2

