diff --git a/Creep_War_Dev/lua/ai_menu_upgrades.lua b/Creep_War_Dev/lua/ai_menu_upgrades.lua new file mode 100755 index 0000000..55920d8 --- /dev/null +++ b/Creep_War_Dev/lua/ai_menu_upgrades.lua @@ -0,0 +1,49 @@ +-- << ai_menu_upgrades | Creep_War_Dev + +local wesnoth = wesnoth +local addon = creepwars + +local loop_limit = nil +local current_side = nil + +local function ai_answer_dialog(settings) + ilua._pretty_print("ai_answer_dialog", settings) + local gold = wesnoth.sides[wesnoth.current.side].gold + + if current_side ~= wesnoth.current.side then + loop_limit = 20 + current_side = wesnoth.current.side + end + loop_limit = loop_limit - 1 + + if loop_limit < 0 then + print("out of loop_limit") + return { is_ok = false, index = 1 } + end + + local function answer_main_dialog(options) + if gold >= 50 then + return { is_ok = true, index = 1 } + end + end + + local options = settings.options + -- TODO 1.19 only starts_with + if stringx.starts_with(settings.label, "Shop.") then + -- main menu + if gold >= 50 then + return { is_ok = true, index = 1 } + end + end + if stringx.starts_with(settings.label, "Hero Upgrade.") then + -- regular upgrade menu + if gold >= 50 then + return { is_ok = true, index = 1 } + end + end + + return { is_ok = false, index = 1 } +end + +addon.ai_answer_dialog = ai_answer_dialog +-- >> diff --git a/Creep_War_Dev/lua/dialog.lua b/Creep_War_Dev/lua/dialog.lua index 412bd80..b36da8e 100644 --- a/Creep_War_Dev/lua/dialog.lua +++ b/Creep_War_Dev/lua/dialog.lua @@ -105,10 +105,15 @@ local function show_dialog_unsynchronized(settings) return { is_ok = is_ok, index = item_result } end - local function show_dialog(settings) local func = function() return show_dialog_unsynchronized(settings) end - return wesnoth.sync.evaluate_single(func) + if stringx.starts_with then + -- 1.19.4+ + local ai_func = function() return creepwars.ai_answer_dialog(settings) end + return wesnoth.sync.evaluate_single(func, ai_func) + else + return wesnoth.sync.evaluate_single(func) + end end diff --git a/Creep_War_Dev/lua/leader_limbo.lua b/Creep_War_Dev/lua/leader_limbo.lua index a1d03e0..7913f2f 100644 --- a/Creep_War_Dev/lua/leader_limbo.lua +++ b/Creep_War_Dev/lua/leader_limbo.lua @@ -45,13 +45,37 @@ local function leader_restore_limbo() unit.variables.limbo_turns = 0 unit.status.petrified = false show_limbo_text(side, "") + creepwars.move_ai_to_shop() end end end +local function move_ai_to_shop() + -- if setting to ai after game start, use droid full + if wesnoth.sides[wesnoth.current.side].controller ~= "ai" then + return + end + local current_side_shops = creepwars.team_shop_array[creepwars.side_to_team[wesnoth.current.side]] + for _, loc in ipairs(current_side_shops) do + if not wesnoth.units.get(loc) then + local unit = wesnoth.units.find{side=wesnoth.current.side, canrecruit=true}[1] + -- Ideally unit should go to closest shop, not just first + -- AI teleports to shop with single movement point, bug of wesnoth engine, but for this use case it is suitable + wesnoth.wml_actions.do_command{ + wml.tag.move{ + x=unit.x .. "," .. loc.x, + y=unit.y .. "," .. loc.y + } + } + return + end + end +end + creepwars.leader_died_event = leader_died_event creepwars.leader_restore_limbo = leader_restore_limbo +creepwars.move_ai_to_shop = move_ai_to_shop -- >> diff --git a/Creep_War_Dev/lua/lua_events.cfg b/Creep_War_Dev/lua/lua_events.cfg index 44c15d6..c8ad970 100644 --- a/Creep_War_Dev/lua/lua_events.cfg +++ b/Creep_War_Dev/lua/lua_events.cfg @@ -18,6 +18,10 @@ name = memoize_sides code = << wesnoth.dofile("~add-ons/Creep_War_Dev/lua/map/memoize_sides.lua") >> [/lua] + [lua] + name = ai_menu_upgrades + code = << wesnoth.dofile("~add-ons/Creep_War_Dev/lua/ai_menu_upgrades.lua") >> + [/lua] [lua] name = dialog code = << wesnoth.dofile("~add-ons/Creep_War_Dev/lua/dialog.lua") >> @@ -71,6 +75,10 @@ name = memoize_sides code = {./map/memoize_sides.lua} [/lua] + [lua] + name = ai_menu_upgrades + code = {./ai_menu_upgrades.lua} + [/lua] [lua] name = dialog code = {./dialog.lua} @@ -208,6 +216,15 @@ end [/lua] [/event] +[event] + name=side turn 1 + first_time_only=no + [lua] + name = move_ai_to_shop + code = << creepwars.move_ai_to_shop() >> + [/lua] +[/event] + #### helpers for local development. Should not affect public games. #ifhave ~add-ons/Creep_War_Dev/lua/local_test.lua diff --git a/Creep_War_Dev/lua/shop/shop_heal.lua b/Creep_War_Dev/lua/shop/shop_heal.lua index 6956753..0703b20 100644 --- a/Creep_War_Dev/lua/shop/shop_heal.lua +++ b/Creep_War_Dev/lua/shop/shop_heal.lua @@ -11,7 +11,9 @@ local side_to_team = creepwars.side_to_team local T = wml.tag local team_shop_set = {} +local team_shop_array = {} for team_index, team_arr in ipairs(creepwars.shop_coordinates) do + table.insert(team_shop_array, {}) local set = {} local cumulative_x_coords = {} local cumulative_y_coords = {} @@ -39,6 +41,7 @@ for team_index, team_arr in ipairs(creepwars.shop_coordinates) do cumulative_x_coords[#cumulative_x_coords + 1] = xy[1] cumulative_y_coords[#cumulative_y_coords + 1] = xy[2] set[xy[1] .. "," .. xy[2]] = true + table.insert(team_shop_array[#team_shop_array], {xy[1], xy[2], x=xy[1], y=xy[2]}) end for side_number, _ in ipairs(wesnoth.sides) do @@ -114,4 +117,6 @@ creepwars.heal_static = heal_static creepwars_unit_at_shop = unit_at_shop +creepwars.team_shop_array = team_shop_array + -- >> diff --git a/Creep_War_Dev/maps/human_ai_sides_macros.cfg b/Creep_War_Dev/maps/human_ai_sides_macros.cfg index c6dc0fe..342e71e 100644 --- a/Creep_War_Dev/maps/human_ai_sides_macros.cfg +++ b/Creep_War_Dev/maps/human_ai_sides_macros.cfg @@ -6,6 +6,16 @@ income=-2 team_lock=yes team_name={TEAM} + [ai] + leader_aggression=0.90 + aggression=0.90 + caution=0.10 + village_value=0.0 + leader_value=5.0 + leader_ignores_keep=yes + retreat_factor=0 + simple_targeting=yes + [/ai] [/side] #enddef