[Add] First Lua template for real escorts.
This commit is contained in:
parent
d1c1619e88
commit
dd9bbfaa3b
@ -1,4 +1,4 @@
|
|||||||
include("../scripts/ai/tpl/generic.lua")
|
include("../scripts/ai/tpl/escort.lua")
|
||||||
|
|
||||||
-- Settings
|
-- Settings
|
||||||
armour_run = 40
|
armour_run = 40
|
||||||
@ -6,23 +6,6 @@ armour_return = 70
|
|||||||
aggressive = true
|
aggressive = true
|
||||||
|
|
||||||
function create()
|
function create()
|
||||||
-- Escorts have nothing on them.
|
mem.escort = ai.getPlayer()
|
||||||
end
|
|
||||||
|
|
||||||
-- When pilot is idle she'll escort the player.
|
|
||||||
function idle()
|
|
||||||
ai.pushtask(0, "escort", ai.getPlayer())
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Escort the target.
|
|
||||||
function escort()
|
|
||||||
target = ai.targetid()
|
|
||||||
|
|
||||||
dir = ai.face(target)
|
|
||||||
dist = ai.dist(ai.pos(target))
|
|
||||||
|
|
||||||
if dir < 10 and dist > 200 then
|
|
||||||
ai.accel()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
104
scripts/ai/tpl/escort.lua
Normal file
104
scripts/ai/tpl/escort.lua
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
include("../scripts/ai/tpl/generic.lua") -- Simple create function.
|
||||||
|
|
||||||
|
function create()
|
||||||
|
attack_choose()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Just tries to guard mem.escort.
|
||||||
|
function idle()
|
||||||
|
ai.pushtask(0, "escort")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Escorts the target.
|
||||||
|
function escort()
|
||||||
|
target = mem.escort
|
||||||
|
|
||||||
|
-- Will just float without a target to escort.
|
||||||
|
if target == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
dir = ai.face(target)
|
||||||
|
dist = ai.dist(ai.pos(target))
|
||||||
|
bdist = ai.mindbrakedist()
|
||||||
|
|
||||||
|
-- Brake.
|
||||||
|
if not ai.isstopped() and dist < bdist then
|
||||||
|
ai.pushtask(0, "brake")
|
||||||
|
|
||||||
|
-- Must approach.
|
||||||
|
elseif dir < 10 and dist > 200 then
|
||||||
|
ai.accel()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Just brakes.
|
||||||
|
function brake()
|
||||||
|
ai.brake()
|
||||||
|
if ai.isstopped() then
|
||||||
|
ai.poptask()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Holds position.
|
||||||
|
function hold()
|
||||||
|
if not ai.isstopped() then
|
||||||
|
ai.brake()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Tries to fly back to carrier.
|
||||||
|
function flyback()
|
||||||
|
target = mem.escort
|
||||||
|
|
||||||
|
dir = ai.face(target)
|
||||||
|
dist = ai.dist(ai.pos(target))
|
||||||
|
bdist = ai.minbrakedist()
|
||||||
|
|
||||||
|
-- Try to brake.
|
||||||
|
if not ai.isstopped() and dist < bdist then
|
||||||
|
ai.pushtask(0, "brake")
|
||||||
|
|
||||||
|
-- Try to dock.
|
||||||
|
elseif ai.isstopped() and dist < 30 then
|
||||||
|
ai.dock(target)
|
||||||
|
|
||||||
|
-- Far away, must approach.
|
||||||
|
elseif dir < 10 and dist > 200 then
|
||||||
|
ai.accel()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
-- Escort commands.
|
||||||
|
--]]
|
||||||
|
--Attack target.
|
||||||
|
function e_attack(target)
|
||||||
|
if mem.command then
|
||||||
|
ai.pushtask(0, "attack", target)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Hold position.
|
||||||
|
function e_hold()
|
||||||
|
if mem.command then
|
||||||
|
ai.pushtask(0, "hold")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Return to carrier.
|
||||||
|
function e_return()
|
||||||
|
if mem.command and mem.carrier then
|
||||||
|
ai.pushtask(0, "flyback")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clear orders.
|
||||||
|
function e_clear()
|
||||||
|
if mem.command then
|
||||||
|
while ai.taskname ~= "none" do
|
||||||
|
ai.poptask()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user