-
-
Notifications
You must be signed in to change notification settings - Fork 990
/
ca_retreat_injured.lua
46 lines (38 loc) · 1.54 KB
/
ca_retreat_injured.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
------- Retreat CA --------------
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local R = wesnoth.require "ai/lua/retreat.lua"
local retreat_unit, retreat_loc
local ca_retreat_injured = {}
function ca_retreat_injured:evaluation(cfg, data)
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'retreat_injured'
if AH.print_eval() then AH.print_ts(' - Evaluating retreat_injured CA:') end
local units = wesnoth.get_units {
side = wesnoth.current.side,
formula = 'movement_left > 0'
}
local unit, loc = R.retreat_injured_units(units)
if unit then
retreat_unit = unit
retreat_loc = loc
-- First check if attacks are possible for any unit
-- If one with > 50% chance of kill is possible, set return_value to lower than combat CA
local attacks = ai.get_attacks()
for i,a in ipairs(attacks) do
if (#a.movements == 1) and (a.chance_to_kill > 0.5) then
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
return 95000
end
end
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
return 192000
end
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
return 0
end
function ca_retreat_injured:execution(cfg, data)
if AH.print_exec() then AH.print_ts(' Executing retreat_injured CA') end
AH.robust_move_and_attack(ai, retreat_unit, retreat_loc)
retreat_unit = nil
retreat_loc = nil
end
return ca_retreat_injured