mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-22 17:51:39 +00:00
Pick Advance: merge moveto event into turn_refresh, closes #8954
This commit is contained in:
parent
b0e9ac1947
commit
1f0ffe0058
@ -200,29 +200,20 @@ on_event("start", function()
|
|||||||
wml.variables.pickadvance_force_choice = wml.variables.pickadvance_force_choice or not map_has_recruits
|
wml.variables.pickadvance_force_choice = wml.variables.pickadvance_force_choice or not map_has_recruits
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- set "fresh_turn" for the moveto event at the start of each side turn
|
-- check if there are any new units that need to be forced to make an advancement choice
|
||||||
on_event("turn refresh", function()
|
on_event("turn refresh", function()
|
||||||
wml.variables.pa_fresh_turn = true
|
if not wesnoth.sides[wesnoth.current.side].__cfg.allow_player then return end
|
||||||
end)
|
for _, unit in ipairs(wesnoth.units.find_on_map { side = wesnoth.current.side }) do
|
||||||
|
if #unit.advances_to > 1 and wml.variables.pickadvance_force_choice and wesnoth.current.turn > 1 then
|
||||||
-- the first time a unit moves at the start of each side's turn, check if there are any new units that need to be forced to make an advancement choice
|
pickadvance.pick_advance(unit)
|
||||||
on_event("moveto", function()
|
if #unit.advances_to > 1 then
|
||||||
if wml.variables.pa_fresh_turn then
|
local len = #unit.advances_to
|
||||||
wml.variables.pa_fresh_turn = nil
|
local rand = mathx.random(len)
|
||||||
if not wesnoth.sides[wesnoth.current.side].__cfg.allow_player then return end
|
unit.advances_to = { unit.advances_to[rand] }
|
||||||
for _, unit in ipairs(wesnoth.units.find_on_map { side = wesnoth.current.side }) do
|
|
||||||
if #unit.advances_to > 1 and wml.variables.pickadvance_force_choice and wesnoth.current.turn > 1 then
|
|
||||||
pickadvance.pick_advance(unit)
|
|
||||||
if #unit.advances_to > 1 then
|
|
||||||
local len = #unit.advances_to
|
|
||||||
local rand = mathx.random(len)
|
|
||||||
unit.advances_to = { unit.advances_to[rand] }
|
|
||||||
end
|
|
||||||
else
|
|
||||||
initialize_unit(unit)
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
initialize_unit(unit)
|
||||||
end
|
end
|
||||||
wesnoth.allow_undo(false)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user