Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --PL_kolek's MicroAI for mirroring recruitment
- return {
- init = function(ai)
- local AH = wesnoth.require("~add-ons/AI-demos/lua/ai_helper.lua")
- local recruit_cas = {}
- local internal_recruit_cas = {}
- local internal_params = {}
- wesnoth.require("~add-ons/AI-demos/lua/generic-recruit_engine.lua").init(ai, internal_recruit_cas, internal_params)
- local recruit
- function recruit_cas:recruit_test_eval(cfg)
- -- Check if leader is on keep
- local leader = wesnoth.get_units { side = wesnoth.current.side, canrecruit = 'yes' }[1]
- if (not leader) or (not wesnoth.get_terrain_info(wesnoth.get_terrain(leader.x, leader.y)).keep) then
- return 0
- end
- -- Check if there is space left for recruiting
- local width, height, border = wesnoth.get_map_size()
- local castle = {
- locs = wesnoth.get_locations {
- x = "1-"..width, y = "1-"..height,
- { "and", {
- x = leader.x, y = leader.y, radius = 200,
- { "filter_radius", { terrain = 'C*^*,K*^*,*^Kov,*^Cov' } }
- }}
- }
- }
- local no_space = true
- for i,c in ipairs(castle.locs) do
- local unit = wesnoth.get_unit(c[1], c[2])
- if (not unit) then
- no_space = false
- break
- end
- end
- if no_space then return 0 end
- --get other player units
- local other_side
- if(wesnoth.current.side == 1) then
- other_side =2
- else
- other_side=1
- end
- local other_units=wesnoth.get_units{ side = other_side, canrecruit = 'no'}
- local my_units=wesnoth.get_units{ side = wesnoth.current.side, canrecruit = 'no'}
- local found_units={}
- for i, other_unit in ipairs(other_units) do
- local found=false
- for j, my_unit in ipairs(my_units) do
- if my_unit.type == other_unit.type and not found_units[my_unit.id] then
- found_units[my_unit.id] = true
- found = true
- break
- end
- end
- if not found then
- for k,recruit_type in ipairs(wesnoth.sides[wesnoth.current.side].recruit) do
- if (recruit_type == other_unit.type) then
- recruit=recruit_type
- return 180000
- end
- end
- end
- end
- return 0
- end
- function recruit_cas:recruit_test_exec(cfg)
- if wesnoth.unit_types[recruit].cost <= wesnoth.sides[wesnoth.current.side].gold then
- ai.recruit(recruit)
- end
- end
- return recruit_cas
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement