Skip to content

Commit

Permalink
Make "wc2_fix_colors" work with 4 player sides
Browse files Browse the repository at this point in the history
This is the only place, where it mattered, that there is no reserved empty side for side 4.
For the dual role of side 4 being either an AI or a player side, it uses a workaround.
  • Loading branch information
sevu committed Oct 22, 2021
1 parent 983352d commit 1307eed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion data/campaigns/World_Conquest/lua/campaign_main.lua
Expand Up @@ -18,7 +18,7 @@ wesnoth.dofile("./campaign/enemy_themed.lua")
on_event("prestart", function(cx)
wesnoth.wml_actions.wc2_fix_colors {
wml.tag.player_sides {
side="1,2,3",
side="1,2,3,4",
wml.tag.has_unit {
canrecruit = true,
}
Expand Down
21 changes: 17 additions & 4 deletions data/campaigns/World_Conquest/lua/game_mechanics/color.lua
Expand Up @@ -48,14 +48,27 @@ function wesnoth.wml_actions.wc2_fix_colors(cfg)
local taken_colors = {}

for i, side in ipairs(player_sides) do
if side.variables.wc2_color then
side.color = side.variables.wc2_color

-- Side 4 is the only side which can be played by either AI or players.
-- Like all player_sides, it is listed among them to handle the case
-- that a player chooses the same color as an AI side.
-- The case that a player chooses the same color as the
-- (potentially an AI) side 4 needs a workaround and is handled here:
if side.side == 4 and taken_colors[side.color] then
table.insert(other_sides, side)
else
side.variables.wc2_color = side.color

if side.variables.wc2_color then
side.color = side.variables.wc2_color
else
side.variables.wc2_color = side.color
end
taken_colors[side.color] = true

end
taken_colors[side.color] = true
end

-- Give the remaining colors to AI sides
local color_num = 1
for i, side in ipairs(other_sides) do
while taken_colors[available_colors[color_num]] == true do
Expand Down

0 comments on commit 1307eed

Please sign in to comment.