Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Creep_War_Dev/lua/ai_menu_upgrades.lua
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will not work if only one side is droided

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
-- >>
9 changes: 7 additions & 2 deletions Creep_War_Dev/lua/dialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
24 changes: 24 additions & 0 deletions Creep_War_Dev/lua/leader_limbo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


-- >>
17 changes: 17 additions & 0 deletions Creep_War_Dev/lua/lua_events.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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") >>
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Creep_War_Dev/lua/shop/shop_heal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -114,4 +117,6 @@ creepwars.heal_static = heal_static

creepwars_unit_at_shop = unit_at_shop

creepwars.team_shop_array = team_shop_array

-- >>
10 changes: 10 additions & 0 deletions Creep_War_Dev/maps/human_ai_sides_macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down