From 53d5eb6172cdf35520ff85f62435c63914392ef6 Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 20 Mar 2013 19:21:46 +0000 Subject: [PATCH] [Add] Militia kinda scans now. --- scripts/ai/merchant.lua | 2 +- scripts/ai/militia.lua | 12 +++++++++--- src/ai.c | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/ai/merchant.lua b/scripts/ai/merchant.lua index 86d7ded..d7eb2fc 100644 --- a/scripts/ai/merchant.lua +++ b/scripts/ai/merchant.lua @@ -57,7 +57,7 @@ function runaway() target = ai.targetid() if not ai.exists(target) then - ai.pustask() + ai.pushtask() ai.pushtask(0, "hyperspace") return end diff --git a/scripts/ai/militia.lua b/scripts/ai/militia.lua index acfc0ad..34ec00a 100644 --- a/scripts/ai/militia.lua +++ b/scripts/ai/militia.lua @@ -9,7 +9,7 @@ function control() if task ~= "attack" and enemy ~= 0 then ai.pushtask(0, "attack", enemy) elseif ai.taskname() == "none" then - ai.pushtask(0, "fly") + ai.pushtask(0, "scan", ai.rndpilot()) end end @@ -88,12 +88,18 @@ function attack() end end -function fly() - target = player +function scan() + target = ai.targetid() + if not ai.exists(target) then + ai.poptask() + return + end dir = ai.face(target) dist = ai.dist(ai.pos(target)) if dir < 10 and dist > 300 then ai.accel() + elseif dist < 300 then -- Scan the target. + ai.poptask() end end diff --git a/src/ai.c b/src/ai.c index afc3834..a587037 100644 --- a/src/ai.c +++ b/src/ai.c @@ -100,6 +100,7 @@ static int ai_taskname(lua_State* L); // Number taskname. // Consult values. static int ai_gettarget(lua_State* L); // Pointer gettarget() static int ai_gettargetid(lua_State* L); // Number gettargetis() +static int ai_getrndpilot(lua_State* L); // Number getrndpilot() static int ai_armour(lua_State* L); // armour() static int ai_shield(lua_State* L); // shield() static int ai_parmour(lua_State* L); // parmour() @@ -160,6 +161,7 @@ static const luaL_Reg ai_methods[] = { { "incombat", ai_incombat }, { "target", ai_gettarget }, { "targetid", ai_gettargetid }, + { "rndpilot", ai_getrndpilot }, { "armour", ai_armour }, { "shield", ai_shield }, { "parmour", ai_parmour }, @@ -473,6 +475,11 @@ static int ai_gettargetid(lua_State* L) { return 0; } +static int ai_getrndpilot(lua_State* L) { + lua_pushnumber(L, pilot_stack[RNG(0, pilots-1)]->id); + return 1; +} + // Get the pilots armour. static int ai_armour(lua_State* L) { double d;