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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
--[[
AI entry point. Run at the start of the AI's turn.
--]]
function think()
-- Look around for potential targets. We prioritize phalanx.
phalanx = ai.see("all","phalanx")
-- Choose proper action
if #phalanx < 1 then
civilian = ai.see("all","civilian")
if #civilian < 1 then
search()
else
engage( civilian[1] )
end
else
engage( phalanx[1] )
end
end
--[[
Try to find a suitable target by wandering around.
--]]
function search ()
end
--[[
Attempts to approach the target.
--]]
function approach( target )
ai.print("Can't get to shoot position.")
end
--[[
Engages target in combat.
Currently attempts to see target, shoot then hide.
--]]
function engage( target )
-- Move until target in sight
shoot_pos = ai.positionshoot(target) -- Get a shoot position
if not shoot_pos then -- No position available
approach(target)
else
-- Go shoot
shoot_pos:goto()
end
hide_tu = 4 -- Crouch + face
-- Shoot
target:shoot(ai.TU() - hide_tu)
-- Hide
hide_pos = ai.positionhide()
if not hide_pos then -- No position available
else
hide_pos:goto()
end
ai.crouch()
target:face()
end
|