recruit_rushers CA: check if castle_switch CA is present
So that it is possible to use the recruit_rushers CA without the castle_switch CA.
(cherry-picked from commit 0bcb98cf50
)
This commit is contained in:
parent
89c633fdaa
commit
aea3a4f7cb
1 changed files with 19 additions and 6 deletions
|
@ -1,11 +1,23 @@
|
|||
-- Make the generic_recruit_engine functions work as external CAs
|
||||
|
||||
local ca_castle_switch
|
||||
for ai_tag in wml.child_range(wesnoth.sides[wesnoth.current.side].__cfg, 'ai') do
|
||||
for stage in wml.child_range(ai_tag, 'stage') do
|
||||
for ca in wml.child_range(stage, 'candidate_action') do
|
||||
if ca.location and string.find(ca.location, 'ca_castle_switch') then
|
||||
ca_castle_switch = wesnoth.require("ai/lua/ca_castle_switch.lua")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local dummy_engine = { data = {} }
|
||||
local ca_castle_switch = wesnoth.require("ai/lua/ca_castle_switch.lua")
|
||||
local params = {
|
||||
score_function = (function() return 300000 end),
|
||||
min_turn_1_recruit = (function() return ca_castle_switch:evaluation({}, dummy_engine.data) > 0 end),
|
||||
leader_takes_village = (function()
|
||||
|
||||
local params = { score_function = (function() return 300000 end) }
|
||||
if ca_castle_switch then
|
||||
params.min_turn_1_recruit = (function() return ca_castle_switch:evaluation({}, dummy_engine.data) > 0 end)
|
||||
params.leader_takes_village = (function()
|
||||
if ca_castle_switch:evaluation({}, dummy_engine.data) > 0 then
|
||||
local take_village = #(wesnoth.get_villages {
|
||||
x = dummy_engine.data.leader_target[1],
|
||||
|
@ -16,7 +28,8 @@ local params = {
|
|||
return true
|
||||
end
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
wesnoth.require("ai/lua/generic_recruit_engine.lua").init(dummy_engine, params)
|
||||
|
||||
local ca_recruit_rushers = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue