Author: cazfi
Date: Sat May 20 14:28:36 2017
New Revision: 35678

URL: http://svn.gna.org/viewcvs/freeciv?rev=35678&view=rev
Log:
Add Tile:is_enemy() to scripting API

See hrm Feature #661538

Modified:
    trunk/common/scriptcore/api_game_methods.c
    trunk/common/scriptcore/api_game_methods.h
    trunk/common/scriptcore/tolua_game.pkg

Modified: trunk/common/scriptcore/api_game_methods.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_game_methods.c?rev=35678&r1=35677&r2=35678&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_methods.c  (original)
+++ trunk/common/scriptcore/api_game_methods.c  Sat May 20 14:28:36 2017
@@ -861,6 +861,28 @@
 }
 
 /*****************************************************************************
+  Is tile occupied by enemies
+*****************************************************************************/
+bool api_methods_enemy_tile(lua_State *L, Tile *ptile, Player *against)
+{
+  struct city *pcity;
+  
+  LUASCRIPT_CHECK_STATE(L, FALSE);
+  LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
+
+  if (is_non_allied_unit_tile(ptile, against)) {
+    return TRUE;
+  }
+
+  pcity = tile_city(ptile);
+  if (ptile != NULL && !pplayers_allied(against, city_owner(pcity))) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/*****************************************************************************
   Return number of units on tile
 *****************************************************************************/
 int api_methods_tile_num_units(lua_State *L, Tile *ptile)

Modified: trunk/common/scriptcore/api_game_methods.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_game_methods.h?rev=35678&r1=35677&r2=35678&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_methods.h  (original)
+++ trunk/common/scriptcore/api_game_methods.h  Sat May 20 14:28:36 2017
@@ -134,6 +134,7 @@
 bool api_methods_tile_has_extra(lua_State *L, Tile *ptile, const char *name);
 bool api_methods_tile_has_base(lua_State *L, Tile *ptile, const char *name);
 bool api_methods_tile_has_road(lua_State *L, Tile *ptile, const char *name);
+bool api_methods_enemy_tile(lua_State *L, Tile *ptile, Player *against);
 int api_methods_tile_num_units(lua_State *L, Tile *ptile);
 int api_methods_tile_sq_distance(lua_State *L, Tile *ptile1, Tile *ptile2);
 int api_methods_private_tile_next_outward_index(lua_State *L, Tile *pstart,

Modified: trunk/common/scriptcore/tolua_game.pkg
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/tolua_game.pkg?rev=35678&r1=35677&r2=35678&view=diff
==============================================================================
--- trunk/common/scriptcore/tolua_game.pkg      (original)
+++ trunk/common/scriptcore/tolua_game.pkg      Sat May 20 14:28:36 2017
@@ -289,6 +289,8 @@
     @ has_base(lua_State *L, Tile *self, const char *name);
   bool api_methods_tile_has_road
     @ has_road(lua_State *L, Tile *self, const char *name);
+  bool api_methods_enemy_tile
+    @ is_enemy(lua_State *L, Tile *self, Player *against);
   int api_methods_tile_num_units
     @ num_units (lua_State *L, Tile *self);
   int api_methods_tile_sq_distance


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to