Author: jtn
Date: Mon Jan 25 19:33:25 2016
New Revision: 31594

URL: http://svn.gna.org/viewcvs/freeciv?rev=31594&view=rev
Log:
Lua: add Unit:transporter(), Unit:cargo_iterate().

See gna patch #6845.

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=31594&r1=31593&r2=31594&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_methods.c  (original)
+++ trunk/common/scriptcore/api_game_methods.c  Mon Jan 25 19:33:25 2016
@@ -899,6 +899,28 @@
 }
 
 /*****************************************************************************
+  Return Unit that transports punit, if any.
+*****************************************************************************/
+Unit *api_methods_unit_transporter(lua_State *L, Unit *punit)
+{
+  LUASCRIPT_CHECK_STATE(L, NULL);
+  LUASCRIPT_CHECK_SELF(L, punit, NULL);
+
+  return punit->transporter;
+}
+
+/*****************************************************************************
+  Return list head for cargo list for Unit
+*****************************************************************************/
+Unit_List_Link *api_methods_private_unit_cargo_list_head(lua_State *L,
+                                                         Unit *punit)
+{
+  LUASCRIPT_CHECK_STATE(L, NULL);
+  LUASCRIPT_CHECK_SELF(L, punit, NULL);
+  return unit_list_head(punit->transporting);
+}
+
+/*****************************************************************************
   Return TRUE if punit_type has flag.
 *****************************************************************************/
 bool api_methods_unit_type_has_flag(lua_State *L, Unit_Type *punit_type,

Modified: trunk/common/scriptcore/api_game_methods.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_game_methods.h?rev=31594&r1=31593&r2=31594&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_methods.h  (original)
+++ trunk/common/scriptcore/api_game_methods.h  Mon Jan 25 19:33:25 2016
@@ -140,6 +140,9 @@
 bool api_methods_unit_city_can_be_built_here(lua_State *L, Unit *punit);
 Tile *api_methods_unit_tile_get(lua_State *L, Unit * punit);
 Direction api_methods_unit_orientation_get(lua_State *L, Unit *punit);
+Unit *api_methods_unit_transporter(lua_State *L, Unit *punit);
+Unit_List_Link *api_methods_private_unit_cargo_list_head(lua_State *L,
+                                                         Unit *punit);
 
 /* Unit Type */
 bool api_methods_unit_type_has_flag(lua_State *L, Unit_Type *punit_type,

Modified: trunk/common/scriptcore/tolua_game.pkg
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/tolua_game.pkg?rev=31594&r1=31593&r2=31594&view=diff
==============================================================================
--- trunk/common/scriptcore/tolua_game.pkg      (original)
+++ trunk/common/scriptcore/tolua_game.pkg      Mon Jan 25 19:33:25 2016
@@ -215,10 +215,19 @@
       @ tile(lua_State *L, Unit *self);
   }
 
+  Unit *api_methods_unit_transporter
+    @ transporter (lua_State *L, Unit *self);
   bool api_methods_unit_city_can_be_built_here
     @ is_on_possible_city_tile (lua_State *L, Unit *self);
   Direction api_methods_unit_orientation_get
     @ facing(lua_State *L, Unit *self);
+}
+
+module methods_private {
+  module Unit {
+    Unit_List_Link *api_methods_private_unit_cargo_list_head
+      @ cargo_list_head (lua_State *L, Unit *self);
+  }
 }
 
 $[
@@ -535,6 +544,11 @@
   function Tile:units_iterate()
     return safe_iterate_list(private.Tile.unit_list_head(self))
   end
+
+  -- Safe iteration over the units transported by Unit
+  function Unit:cargo_iterate()
+    return safe_iterate_list(private.Unit.cargo_list_head(self))
+  end
 end
 
 -- ***************************************************************************


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

Reply via email to