mail[Wesnoth-commits] r41566 - /trunk/src/scripting/lua.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on March 14, 2010 - 12:59:
Author: silene
Date: Sun Mar 14 12:59:00 2010
New Revision: 41566

URL: http://svn.gna.org/viewcvs/wesnoth?rev=41566&view=rev
Log:
Added accessor to unit movement cost.

Modified:
    trunk/src/scripting/lua.cpp

Modified: trunk/src/scripting/lua.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/scripting/lua.cpp?rev=41566&r1=41565&r2=41566&view=diff
==============================================================================
--- trunk/src/scripting/lua.cpp (original)
+++ trunk/src/scripting/lua.cpp Sun Mar 14 12:59:00 2010
@@ -1971,7 +1971,7 @@
 /**
  * Returns unit resistance against a given attack type.
  * - Arg 1: unit userdata.
- * - Arg 2: string containing attack type.
+ * - Arg 2: string containing the attack type.
  * - Arg 3: boolean indicating if attacker.
  * - Args 4/5: optional location.
  */
@@ -1989,6 +1989,22 @@
        }
 
        lua_pushinteger(L, u->resistance_against(m, a, loc));
+       return 1;
+}
+
+/**
+ * Returns unit movement cost on a given terrain.
+ * - Arg 1: unit userdata.
+ * - Arg 2: string containing the terrain type.
+ */
+static int intf_unit_movement_cost(lua_State *L)
+{
+       unit const *u = luaW_tounit(L, 1);
+       if (!u) return luaL_typerror(L, 1, "unit");
+       char const *m = luaL_checkstring(L, 2);
+
+       t_translation::t_terrain t = t_translation::read_terrain_code(m);
+       lua_pushinteger(L, u->movement_cost(t));
        return 1;
 }
 
@@ -2042,6 +2058,7 @@
                { "set_variable",             &intf_set_variable             
},
                { "set_village_owner",        &intf_set_village_owner        
},
                { "textdomain",               &intf_textdomain               
},
+               { "unit_movement_cost",       &intf_unit_movement_cost       
},
                { "unit_resistance",          &intf_unit_resistance          
},
                { NULL, NULL }
        };




Related Messages


Powered by MHonArc, Updated Sun Mar 14 13:00:18 2010