Skip to content

Commit

Permalink
WML: Support [filter_side] in [item]. (#3533)
Browse files Browse the repository at this point in the history
* 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

(cherry-picked from commit 3a3b752)
  • Loading branch information
jostephd authored and CelticMinstrel committed Oct 7, 2018
1 parent d5238ac commit e766cdc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -44,6 +44,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=
### Miscellaneous and bug fixes

## Version 1.14.4+dev
Expand Down
1 change: 1 addition & 0 deletions data/lua/wml/items.lua
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/display.cpp
Expand Up @@ -2598,8 +2598,12 @@ void display::draw_hex(const map_location& loc) {
image::light_string lt = image::get_light_string(-1, tod_col.r, tod_col.g, tod_col.b);

for( ; overlays.first != overlays.second; ++overlays.first) {
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(overlays.first->second.team_name);
if ((overlays.first->second.team_name.empty() ||
overlays.first->second.team_name.find(dc_->teams()[viewing_team()].team_name()) != std::string::npos)
std::find_first_of(team_names.begin(), team_names.end(),
current_team_names.begin(), current_team_names.end()) != team_names.end())
&& !(fogged(loc) && !overlays.first->second.visible_in_fog))
{

Expand Down
16 changes: 14 additions & 2 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -3345,11 +3345,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;
}
Expand Down

0 comments on commit e766cdc

Please sign in to comment.