Permalink
Browse files

WML: Support [filter_side] in [item]. (#3533)

* WML: Support [filter_side] in [item].

If [filter_side] is present then "team_name" is ignored.

Fixes #1477.

* WML: Compare [item]team_name to [side]team_name using intersection.

Fixes problems with substrings and when one or the other is a
comma-separated list. See #3533

* WML: Rename [item][filter_side] to [item][filter_team]

* Add changelog entry
  • Loading branch information...
jostephd authored and CelticMinstrel committed Sep 22, 2018
1 parent b64f4b4 commit 3a3b752881f50ad34742c5962d40d96556adf1a1
Showing with 21 additions and 3 deletions.
  1. +1 −0 changelog.md
  2. +1 −0 data/lua/wml/items.lua
  3. +5 −1 src/display.cpp
  4. +14 −2 src/scripting/game_lua_kernel.cpp
View
@@ -48,6 +48,7 @@
* Support male_voice and female_voice in [message]
* Support [break], [continue], and [return] in [random_placement]
* [remove_sound_source] now accepts a comma-separated ID list
* Support [filter_team] in [side] in addition to team_name=
## Version 1.14.4+dev
### AI
View
@@ -16,6 +16,7 @@ local function add_overlay(x, y, cfg)
image = cfg.image,
halo = cfg.halo,
team_name = cfg.team_name,
filter_team = cfg.filter_team,
visible_in_fog = cfg.visible_in_fog,
redraw = cfg.redraw,
name = cfg.name
View
@@ -1691,8 +1691,12 @@ void display::draw_gamemap()
const overlay& item = overlay_record.second;
const std::string& current_team_name = get_teams()[viewing_team()].team_name();
const std::vector<std::string>& current_team_names = utils::split(current_team_name);
const std::vector<std::string>& team_names = utils::split(item.team_name);
if((item.team_name.empty() || item.team_name.find(current_team_name) != std::string::npos) &&
if((item.team_name.empty() ||
std::find_first_of(team_names.begin(), team_names.end(),
current_team_names.begin(), current_team_names.end()) != team_names.end()) &&
(!fogged(o_loc) || item.visible_in_fog))
{
const texture tex = item.image.find("~NO_TOD_SHIFT()") == std::string::npos
@@ -3325,11 +3325,23 @@ static int intf_add_known_unit(lua_State *L)
int game_lua_kernel::intf_add_tile_overlay(lua_State *L)
{
map_location loc = luaW_checklocation(L, 1);
config cfg = luaW_checkconfig(L, 2);
vconfig cfg = luaW_checkvconfig(L, 2);
const vconfig &ssf = cfg.child("filter_team");
std::string team_name;
if (!ssf.null()) {
const std::vector<int>& teams = side_filter(ssf, &game_state_).get_teams();
std::vector<std::string> team_names;
std::transform(teams.begin(), teams.end(), std::back_inserter(team_names),
[&](int team) { return game_state_.get_disp_context().get_team(team).team_name(); });
team_name = utils::join(team_names);
} else {
team_name = cfg["team_name"].str();
}
if (game_display_) {
game_display_->add_overlay(loc, cfg["image"], cfg["halo"],
cfg["team_name"], cfg["name"], cfg["visible_in_fog"].to_bool(true));
team_name, cfg["name"], cfg["visible_in_fog"].to_bool(true));
}
return 0;
}

0 comments on commit 3a3b752

Please sign in to comment.