mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-07 11:12:04 +00:00
moved [store_side] to lua; added SSF support
an array is created is several sides match no backwardscompat-hack or deprecation needed since $var. ... is the same as $var[0]. ... , clearing a container variable is the same as if it was an array and side=1 automatically matches first for an empty filter :)
This commit is contained in:
parent
c1d8858c90
commit
12093d8784
@ -808,3 +808,34 @@ function wml_actions.transform_unit(cfg)
|
|||||||
wml_actions.redraw {}
|
wml_actions.redraw {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function wml_actions.store_side(cfg)
|
||||||
|
local variable = cfg.variable or "side"
|
||||||
|
local index = 0
|
||||||
|
wesnoth.set_variable(variable)
|
||||||
|
for t, side_number in helper.get_sides(cfg) do
|
||||||
|
local container = {
|
||||||
|
controller = t.controller,
|
||||||
|
recruit = table.concat(t.recruit, ","),
|
||||||
|
fog = t.fog,
|
||||||
|
shroud = t.shroud,
|
||||||
|
hidden = t.hidden,
|
||||||
|
income = t.total_income,
|
||||||
|
village_gold = t.village_gold,
|
||||||
|
name = t.name,
|
||||||
|
team_name = t.team_name,
|
||||||
|
user_team_name = t.user_team_name,
|
||||||
|
color = t.color,
|
||||||
|
colour = t.color,
|
||||||
|
gold = t.gold
|
||||||
|
}
|
||||||
|
wesnoth.set_variable(string.format("%s[%u]", variable, index), container)
|
||||||
|
index = index + 1
|
||||||
|
end
|
||||||
|
-- deprecated starting with 1.9.0
|
||||||
|
-- added message starting with 1.9.7
|
||||||
|
-- assuming that a wml author will usually be in debug mode and a player will not...
|
||||||
|
if wesnoth.game_config.debug then
|
||||||
|
wesnoth.message("warning", string.format("$%s.colour is deprecated, use $%s.color (if needed)", variable, variable))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@ -892,38 +892,6 @@ WML_HANDLER_FUNCTION(modify_side, /*event_info*/, cfg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WML_HANDLER_FUNCTION(store_side, /*event_info*/, cfg)
|
|
||||||
{
|
|
||||||
game_state *state_of_game = resources::state_of_game;
|
|
||||||
std::vector<team> &teams = *resources::teams;
|
|
||||||
|
|
||||||
std::string var_name = cfg["variable"];
|
|
||||||
if (var_name.empty()) var_name = "side";
|
|
||||||
|
|
||||||
int side_num = cfg["side"].to_int(1);
|
|
||||||
size_t team_index = side_num - 1;
|
|
||||||
if (team_index >= teams.size()) return;
|
|
||||||
|
|
||||||
config side_data;
|
|
||||||
teams[team_index].write(side_data);
|
|
||||||
state_of_game->get_variable(var_name+".controller") = side_data["controller"];
|
|
||||||
state_of_game->get_variable(var_name+".recruit") = side_data["recruit"];
|
|
||||||
state_of_game->get_variable(var_name+".fog") = side_data["fog"];
|
|
||||||
state_of_game->get_variable(var_name+".shroud") = side_data["shroud"];
|
|
||||||
state_of_game->get_variable(var_name+".hidden") = side_data["hidden"];
|
|
||||||
|
|
||||||
state_of_game->get_variable(var_name+".income") = teams[team_index].total_income();
|
|
||||||
state_of_game->get_variable(var_name+".village_gold") = teams[team_index].village_gold();
|
|
||||||
state_of_game->get_variable(var_name+".name") = teams[team_index].name();
|
|
||||||
state_of_game->get_variable(var_name+".team_name") = teams[team_index].team_name();
|
|
||||||
state_of_game->get_variable(var_name+".user_team_name") = teams[team_index].user_team_name();
|
|
||||||
state_of_game->get_variable(var_name+".color") = teams[team_index].map_color_to();
|
|
||||||
///@deprecated 1.9.2 'colour'
|
|
||||||
state_of_game->get_variable(var_name+".colour") = teams[team_index].map_color_to();
|
|
||||||
|
|
||||||
state_of_game->get_variable(var_name+".gold") = teams[team_index].gold();
|
|
||||||
}
|
|
||||||
|
|
||||||
WML_HANDLER_FUNCTION(modify_turns, /*event_info*/, cfg)
|
WML_HANDLER_FUNCTION(modify_turns, /*event_info*/, cfg)
|
||||||
{
|
{
|
||||||
config::attribute_value value = cfg["value"];
|
config::attribute_value value = cfg["value"];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user