Make "wc2_fix_colors" work with 4 player sides
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.
This commit is contained in:
parent
4b454053c2
commit
2183cd5b8f
2 changed files with 18 additions and 5 deletions
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue