[Add] Militia faction. Changed Test pilot to Militia and added ai_create
This commit is contained in:
parent
a4bca2004b
commit
4b07e86acd
@ -8,10 +8,13 @@
|
||||
</faction>
|
||||
<faction name = "Pirate">
|
||||
</faction>
|
||||
<faction name = "Militia">
|
||||
</faction>
|
||||
<Alliances>
|
||||
<alliance name = "Neutral">
|
||||
<ally>Independent</ally>
|
||||
<ally>Merchant</ally>
|
||||
<ally>Militia</ally>
|
||||
</alliance>
|
||||
</Alliances>
|
||||
<Enemies>
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Fleets>
|
||||
<fleet name="Enemy Test">
|
||||
<ai>test</ai>
|
||||
<faction>Independent</faction>
|
||||
<fleet name="Militia Lancer">
|
||||
<ai>militia</ai>
|
||||
<faction>Militia</faction>
|
||||
<pilots>
|
||||
<pilot chance='100' name="Enemy Test">Lancer</pilot>
|
||||
<pilot chance='100' name="Lancer">Lancer</pilot>
|
||||
</pilots>
|
||||
</fleet>
|
||||
<fleet name="Merchant Ship">
|
||||
|
@ -67,7 +67,7 @@
|
||||
<GUI>minimal</GUI>
|
||||
<sound>engine</sound>
|
||||
<class>2</class>
|
||||
<price>600000</price>
|
||||
<price>700000</price>
|
||||
<fabricator>VLSoft</fabricator>
|
||||
<description>On of VLSoft's prize heavey fighters. Was originally a secret design for the Empire military, but then disclosed. Now a modified version is available for civilians, although it doesn't meet up to the original specifications.
|
||||
Used by security agencies all over the universe for it's reliability and availability. Proudly enforcing your security since STARDATE.</description>
|
||||
@ -92,8 +92,8 @@
|
||||
</characteristics>
|
||||
<outfits>
|
||||
<outfit quantity="4">Laser</outfit>
|
||||
<outfit quantity='2'>Missile Launcher</outfit>
|
||||
<outfit quantity='20'>Missile</outfit>
|
||||
<outfit quantity="2">Missile Launcher</outfit>
|
||||
<outfit quantity="20">Missile</outfit>
|
||||
</outfits>
|
||||
</ship>
|
||||
<ship name="Merchant Mule">
|
||||
|
@ -14,7 +14,7 @@
|
||||
<planet>KonoSphere</planet>
|
||||
</planets>
|
||||
<fleets>
|
||||
<fleet chance="100">Enemy Test</fleet>
|
||||
<fleet chance="100">Militia Lancer</fleet>
|
||||
<fleet chance="60">Pirate</fleet>
|
||||
<fleet chance="60">Merchant Ship</fleet>
|
||||
<fleet chance="50">Merchant Mule</fleet>
|
||||
|
@ -155,7 +155,7 @@ shoot([number weapon])
|
||||
-- return nil.
|
||||
|
||||
getenemy()
|
||||
-- return the id of the nearest enemy or -1 if none is found.
|
||||
-- return the id of the nearest enemy or 0 if none is found.
|
||||
|
||||
// ================
|
||||
// TIMERS!
|
||||
|
98
scripts/ai/militia.lua
Normal file
98
scripts/ai/militia.lua
Normal file
@ -0,0 +1,98 @@
|
||||
-- Required control rate
|
||||
control_rate = 2
|
||||
|
||||
-- Required "control" function.
|
||||
function control()
|
||||
task = ai.taskname()
|
||||
|
||||
enemy = ai.getenemy()
|
||||
if enemy ~= 0 then
|
||||
ai.pushtask(0, "attack", enemy)
|
||||
elseif ai.taskname() == "none" then
|
||||
ai.pushtask(0, "fly")
|
||||
end
|
||||
end
|
||||
|
||||
-- Required "attacked" function
|
||||
function attacked(attecker)
|
||||
task = ai.taskname()
|
||||
if task ~= "attack" and task "runaway" then
|
||||
-- Some taunting.
|
||||
taunt(attacker)
|
||||
|
||||
-- Now pilot fights back!
|
||||
ai.pushtask(0, "attack", attacker)
|
||||
|
||||
elseif task == "attack" then
|
||||
if ai.targetid() ~= attaker then
|
||||
ai.pushtack(0, "attack", attacker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function create()
|
||||
if ai.rnd(0, 2)==0 then
|
||||
ai.broadcast("This area is under survellance. Do not attemt anything funny")
|
||||
end
|
||||
end
|
||||
|
||||
-- Taunts
|
||||
function taunt(target)
|
||||
num = ai.rnd(0,4)
|
||||
if num == 0 then msg = "How dare you attack me!?"
|
||||
elseif num == 1 then msg = "YOU! ARE NOT! PREPARED!!"
|
||||
elseif num == 2 then msg = "Won't You just die already!?"
|
||||
elseif num == 3 then msg = "You won't survive!"
|
||||
end
|
||||
if msg then ai.comm(attacker, msg) end
|
||||
end
|
||||
|
||||
function runaway()
|
||||
target = ai.targetid()
|
||||
|
||||
-- Make sure pilot exists.
|
||||
if not ai.exists(target) then
|
||||
ai.poptask()
|
||||
return
|
||||
end
|
||||
|
||||
dir = ai.face(target, 1)
|
||||
ai.accel()
|
||||
end
|
||||
|
||||
function attack()
|
||||
target = ai.targetid()
|
||||
|
||||
if not ai.exists(target) then
|
||||
ai.poptask()
|
||||
return
|
||||
end
|
||||
|
||||
dir = ai.face(target)
|
||||
dist = ai.dist(ai.pos(target))
|
||||
second = ai.secondary()
|
||||
|
||||
if ai.secondary() == "Launcher" then
|
||||
ai.settarget(target)
|
||||
ai.shoot(2)
|
||||
end
|
||||
|
||||
if ai.parmour() < 70 then
|
||||
ai.poptask()
|
||||
ai.pushtask(0, "runaway", target)
|
||||
elseif dir < 10 and dist > 300 then
|
||||
ai.accel()
|
||||
elseif dir < 10 and dist < 300 then
|
||||
ai.shoot()
|
||||
end
|
||||
end
|
||||
|
||||
function fly()
|
||||
target = player
|
||||
dir = ai.face(target)
|
||||
dist = ai.dist(ai.pos(target))
|
||||
if dir < 10 and dist > 300 then
|
||||
ai.accel()
|
||||
end
|
||||
end
|
||||
|
@ -10,6 +10,8 @@ function control()
|
||||
if ai.parmour() == 100 then
|
||||
-- "attack" should be called after "runaway".
|
||||
ai.poptask()
|
||||
elseif ai.dist(ai.pos(ai.targetid())) > 300 then
|
||||
ai.hyperspace()
|
||||
end
|
||||
|
||||
-- Nothing to do.
|
||||
|
@ -1,10 +0,0 @@
|
||||
--Required control rate.
|
||||
control_rate = 2
|
||||
|
||||
-- Required "control" function.
|
||||
function control()
|
||||
end
|
||||
|
||||
-- Required "attacked" function
|
||||
function attacked(attacker)
|
||||
end
|
9
src/ai.c
9
src/ai.c
@ -92,6 +92,8 @@ static int ai_loadProfile(char* filename);
|
||||
static void ai_freetask(Task* t);
|
||||
// External C routines.
|
||||
void ai_attacked(Pilot* attacked, const unsigned int attacker); // weapon.c
|
||||
void ai_create(Pilot* pilot);
|
||||
|
||||
// Ai routines for Lua.
|
||||
// Tasks.
|
||||
static int ai_pushtask(lua_State* L); // pushtask(string, number/pointer, number)
|
||||
@ -342,6 +344,13 @@ void ai_attacked(Pilot* attacked, const unsigned int attacker) {
|
||||
lua_pcall(L, 1, 0, 0);
|
||||
}
|
||||
|
||||
// Pilot was just created.
|
||||
void ai_create(Pilot* pilot) {
|
||||
cur_pilot = pilot;
|
||||
L = cur_pilot->ai->L;
|
||||
AI_LCALL("create");
|
||||
}
|
||||
|
||||
// =====================
|
||||
// INTERNAL C FUNCTIONS.
|
||||
// =====================
|
||||
|
@ -34,6 +34,7 @@ static int nfleets = 0;
|
||||
// External.
|
||||
extern void ai_destroy(Pilot* p); // Ai.
|
||||
extern void ai_think(Pilot* pilot); // Ai.c
|
||||
extern void ai_create(Pilot* pilot); // ai.c
|
||||
extern void player_think(Pilot* pilot); // Player.c
|
||||
extern void player_brokeHyperspace(void); // Player.c
|
||||
extern int gui_load(const char* name); // Player.c
|
||||
@ -551,9 +552,10 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, Faction* faction,
|
||||
} else {
|
||||
pilot->think = ai_think;
|
||||
pilot->render = pilot_render;
|
||||
ai_create(pilot); // Will run the create function in ai.
|
||||
}
|
||||
// All update the same way.
|
||||
pilot->update = pilot_update;
|
||||
|
||||
}
|
||||
|
||||
// Create a new pilot - Params are same as pilot_init. Return pilot's id.
|
||||
|
Loading…
Reference in New Issue
Block a user