Moved [store_villages] from C++ to Lua

This commit is contained in:
Elvish_Hunter 2012-07-21 10:03:31 +00:00
parent c8716ad799
commit 9476d796c1
3 changed files with 16 additions and 32 deletions

View file

@ -307,6 +307,7 @@ Version 1.11.0-svn:
still can, i.e. for cutscenes)
* Fixed CALL_FUNCTION macro (bug #19805)
* Added [effect] apply_to=halo
* Converted [store_villages] from C++ to Lua
* Miscellaneous and bug fixes:
* Fix wrong preferences path suffix (1.1 instead of 1.10) on Linux and other
platforms using XDG layout (no compiled-in preferences path override,

View file

@ -1130,3 +1130,18 @@ function wml_actions.store_starting_location(cfg)
end
end
end
function wml_actions.store_villages( cfg )
local villages = wesnoth.get_villages( cfg )
local variable = cfg.variable or "location"
for index, village in ipairs( villages ) do
wesnoth.set_variable( string.format( "%s[%d]", variable, index-1 ),
{ x = village[1],
y = village[2],
terrain = wesnoth.get_terrain( village[1], village[2] ),
owner_side = wesnoth.get_village_owner( village[1], village[2] ) or 0
}
)
end
end

View file

@ -2448,38 +2448,6 @@ WML_HANDLER_FUNCTION(unstore_unit, /*event_info*/, cfg)
}
}
/* [store_villages] : store villages into an array
* Keys:
* - variable (mandatory): variable to store in
* - side: if present, the village should be owned by this side (0=unowned villages)
* - terrain: if present, filter the village types against this list of terrain types
*/
WML_HANDLER_FUNCTION(store_villages, /*event_info*/, cfg)
{
log_scope("store_villages");
std::string variable = cfg["variable"];
if (variable.empty()) {
variable="location";
}
config to_store;
variable_info varinfo(variable, true, variable_info::TYPE_ARRAY);
std::vector<map_location> locs = resources::game_map->villages();
for(std::vector<map_location>::const_iterator j = locs.begin(); j != locs.end(); ++j) {
bool matches = terrain_filter(cfg, *resources::units).match(*j);
if(matches) {
config &loc_store = to_store.add_child(varinfo.key);
j->write(loc_store);
resources::game_map->write_terrain(*j, loc_store);
int side = village_owner(*j, *resources::teams) + 1;
loc_store["owner_side"] = side;
}
}
varinfo.vars->clear_children(varinfo.key);
varinfo.vars->append(to_store);
}
WML_HANDLER_FUNCTION(end_turn, /*event_info*/, /*cfg*/)
{
resources::controller->force_end_turn();