mail[Wesnoth-commits] r44709 - /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 July 26, 2010 - 14:24:
Author: silene
Date: Mon Jul 26 14:24:51 2010
New Revision: 44709

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44709&view=rev
Log:
Added a Lua function for synchronizing values between clients.

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=44709&r1=44708&r2=44709&view=diff
==============================================================================
--- trunk/src/scripting/lua.cpp (original)
+++ trunk/src/scripting/lua.cpp Mon Jul 26 14:24:51 2010
@@ -51,6 +51,7 @@
 #include "map.hpp"
 #include "pathfind/pathfind.hpp"
 #include "play_controller.hpp"
+#include "replay.hpp"
 #include "resources.hpp"
 #include "terrain_translation.hpp"
 #include "sound.hpp"
@@ -2234,6 +2235,39 @@
        resources::screen->scroll_to_tile(map_location(x, y),
                game_display::SCROLL, check_fogged);
        return 0;
+}
+
+struct lua_synchronize : mp_sync::user_choice
+{
+       lua_State *L;
+       lua_synchronize(lua_State *l): L(l) {}
+
+       virtual config query_user() const
+       {
+               config cfg;
+               if (luaW_pcall(L, 0, 1, false))
+                       luaW_toconfig(L, -1, cfg);
+               return cfg;
+       }
+
+       virtual config random_choice(rand_rng::simple_rng &) const
+       {
+               return config();
+       }
+};
+
+/**
+ * Ensures a value is synchronized among all the clients.
+ * - Arg 1: function to compute the value, called if the client is the 
master.
+ * - Ret 1: WML table returned by the function.
+ */
+static int intf_synchronize_choice(lua_State *L)
+{
+       lua_settop(L, 1);
+       config cfg = mp_sync::get_user_choice("input", lua_synchronize(L));
+       lua_newtable(L);
+       table_of_wml_config(L, cfg);
+       return 1;
 }
 
 LuaKernel::LuaKernel()
@@ -2288,6 +2322,7 @@
                { "set_variable",             &intf_set_variable             
},
                { "set_village_owner",        &intf_set_village_owner        
},
                { "simulate_combat",          &intf_simulate_combat          
},
+               { "synchronize_choice",       &intf_synchronize_choice       
},
                { "textdomain",               &intf_textdomain               
},
                { "tovconfig",                &intf_tovconfig                
},
                { "unit_defense",             &intf_unit_defense             
},




Related Messages


Powered by MHonArc, Updated Mon Jul 26 14:40:15 2010