Author: cazfi
Date: Tue Nov 18 22:15:46 2014
New Revision: 27081

URL: http://svn.gna.org/viewcvs/freeciv?rev=27081&view=rev
Log:
Added lua scripting functions direction.opposite(dir), direction.next_cw(dir), 
and direction.ccw(dir)

See patch #5415

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

Modified: trunk/common/scriptcore/api_common_utilities.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_common_utilities.c?rev=27081&r1=27080&r2=27081&view=diff
==============================================================================
--- trunk/common/scriptcore/api_common_utilities.c      (original)
+++ trunk/common/scriptcore/api_common_utilities.c      Tue Nov 18 22:15:46 2014
@@ -78,3 +78,47 @@
 
   return direction8_by_name(dir, fc_strcasecmp);
 }
+
+/**************************************************************************
+  Previous (counter-clockwise) valid direction
+**************************************************************************/
+Direction api_utilities_dir_ccw(lua_State *L, Direction dir)
+{
+  Direction new_dir = dir;
+
+  LUASCRIPT_CHECK_STATE(L, direction8_invalid());
+
+  do {
+    new_dir = dir_ccw(new_dir);
+  } while (!is_valid_dir(new_dir));
+
+  return new_dir;
+}
+
+/**************************************************************************
+  Next (clockwise) valid direction
+**************************************************************************/
+Direction api_utilities_dir_cw(lua_State *L, Direction dir)
+{
+  Direction new_dir = dir;
+
+  LUASCRIPT_CHECK_STATE(L, direction8_invalid());
+
+  do {
+    new_dir = dir_cw(new_dir);
+  } while (!is_valid_dir(new_dir));
+
+  return new_dir;
+}
+
+/**************************************************************************
+  Opposite direction - validity not checked, but it's valid iff
+  original direction is.
+**************************************************************************/
+Direction api_utilities_opposite_dir(lua_State *L, Direction dir)
+{
+  LUASCRIPT_CHECK_STATE(L, direction8_invalid());
+
+  return opposite_direction(dir);
+}
+

Modified: trunk/common/scriptcore/api_common_utilities.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_common_utilities.h?rev=27081&r1=27080&r2=27081&view=diff
==============================================================================
--- trunk/common/scriptcore/api_common_utilities.h      (original)
+++ trunk/common/scriptcore/api_common_utilities.h      Tue Nov 18 22:15:46 2014
@@ -26,6 +26,9 @@
 int api_utilities_random(lua_State *L, int min, int max);
 
 Direction api_utilities_str2dir(lua_State *L, const char *dir);
+Direction api_utilities_dir_ccw(lua_State *L, Direction dir);
+Direction api_utilities_dir_cw(lua_State *L, Direction dir);
+Direction api_utilities_opposite_dir(lua_State *L, Direction dir);
 
 const char *api_utilities_fc_version(lua_State *L);
 

Modified: trunk/common/scriptcore/tolua_game.pkg
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/tolua_game.pkg?rev=27081&r1=27080&r2=27081&view=diff
==============================================================================
--- trunk/common/scriptcore/tolua_game.pkg      (original)
+++ trunk/common/scriptcore/tolua_game.pkg      Tue Nov 18 22:15:46 2014
@@ -215,7 +215,6 @@
 function Unit:get_homecity()
   return find.city(self.owner, self.homecity)
 end
-
 $]
 
 /* Module Tile. */
@@ -459,7 +458,13 @@
 /* Direction module */
 module direction {
  Direction api_utilities_str2dir
-   @ str2dir (lua_State *L, const char *str);
+   @ str2dir(lua_State *L, const char *str);
+ Direction api_utilities_dir_ccw
+   @ next_ccw(lua_State *L, Direction self);
+ Direction api_utilities_dir_cw
+   @ next_cw(lua_State *L, Direction self);
+ Direction api_utilities_opposite_dir
+   @ opposite(lua_State *L, Direction self);
 }
 
 $[


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

Reply via email to