[Add] Militia faction. Changed Test pilot to Militia and added ai_create
This commit is contained in:
parent
a4bca2004b
commit
4b07e86acd
@ -7,11 +7,14 @@
|
|||||||
<faction name = "Merchant">
|
<faction name = "Merchant">
|
||||||
</faction>
|
</faction>
|
||||||
<faction name = "Pirate">
|
<faction name = "Pirate">
|
||||||
|
</faction>
|
||||||
|
<faction name = "Militia">
|
||||||
</faction>
|
</faction>
|
||||||
<Alliances>
|
<Alliances>
|
||||||
<alliance name = "Neutral">
|
<alliance name = "Neutral">
|
||||||
<ally>Independent</ally>
|
<ally>Independent</ally>
|
||||||
<ally>Merchant</ally>
|
<ally>Merchant</ally>
|
||||||
|
<ally>Militia</ally>
|
||||||
</alliance>
|
</alliance>
|
||||||
</Alliances>
|
</Alliances>
|
||||||
<Enemies>
|
<Enemies>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Fleets>
|
<Fleets>
|
||||||
<fleet name="Enemy Test">
|
<fleet name="Militia Lancer">
|
||||||
<ai>test</ai>
|
<ai>militia</ai>
|
||||||
<faction>Independent</faction>
|
<faction>Militia</faction>
|
||||||
<pilots>
|
<pilots>
|
||||||
<pilot chance='100' name="Enemy Test">Lancer</pilot>
|
<pilot chance='100' name="Lancer">Lancer</pilot>
|
||||||
</pilots>
|
</pilots>
|
||||||
</fleet>
|
</fleet>
|
||||||
<fleet name="Merchant Ship">
|
<fleet name="Merchant Ship">
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
<GUI>minimal</GUI>
|
<GUI>minimal</GUI>
|
||||||
<sound>engine</sound>
|
<sound>engine</sound>
|
||||||
<class>2</class>
|
<class>2</class>
|
||||||
<price>600000</price>
|
<price>700000</price>
|
||||||
<fabricator>VLSoft</fabricator>
|
<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.
|
<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>
|
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>
|
</characteristics>
|
||||||
<outfits>
|
<outfits>
|
||||||
<outfit quantity="4">Laser</outfit>
|
<outfit quantity="4">Laser</outfit>
|
||||||
<outfit quantity='2'>Missile Launcher</outfit>
|
<outfit quantity="2">Missile Launcher</outfit>
|
||||||
<outfit quantity='20'>Missile</outfit>
|
<outfit quantity="20">Missile</outfit>
|
||||||
</outfits>
|
</outfits>
|
||||||
</ship>
|
</ship>
|
||||||
<ship name="Merchant Mule">
|
<ship name="Merchant Mule">
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<planet>KonoSphere</planet>
|
<planet>KonoSphere</planet>
|
||||||
</planets>
|
</planets>
|
||||||
<fleets>
|
<fleets>
|
||||||
<fleet chance="100">Enemy Test</fleet>
|
<fleet chance="100">Militia Lancer</fleet>
|
||||||
<fleet chance="60">Pirate</fleet>
|
<fleet chance="60">Pirate</fleet>
|
||||||
<fleet chance="60">Merchant Ship</fleet>
|
<fleet chance="60">Merchant Ship</fleet>
|
||||||
<fleet chance="50">Merchant Mule</fleet>
|
<fleet chance="50">Merchant Mule</fleet>
|
||||||
|
@ -155,7 +155,7 @@ shoot([number weapon])
|
|||||||
-- return nil.
|
-- return nil.
|
||||||
|
|
||||||
getenemy()
|
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!
|
// 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
|
if ai.parmour() == 100 then
|
||||||
-- "attack" should be called after "runaway".
|
-- "attack" should be called after "runaway".
|
||||||
ai.poptask()
|
ai.poptask()
|
||||||
|
elseif ai.dist(ai.pos(ai.targetid())) > 300 then
|
||||||
|
ai.hyperspace()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Nothing to do.
|
-- 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);
|
static void ai_freetask(Task* t);
|
||||||
// External C routines.
|
// External C routines.
|
||||||
void ai_attacked(Pilot* attacked, const unsigned int attacker); // weapon.c
|
void ai_attacked(Pilot* attacked, const unsigned int attacker); // weapon.c
|
||||||
|
void ai_create(Pilot* pilot);
|
||||||
|
|
||||||
// Ai routines for Lua.
|
// Ai routines for Lua.
|
||||||
// Tasks.
|
// Tasks.
|
||||||
static int ai_pushtask(lua_State* L); // pushtask(string, number/pointer, number)
|
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);
|
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.
|
// INTERNAL C FUNCTIONS.
|
||||||
// =====================
|
// =====================
|
||||||
|
@ -34,6 +34,7 @@ static int nfleets = 0;
|
|||||||
// External.
|
// External.
|
||||||
extern void ai_destroy(Pilot* p); // Ai.
|
extern void ai_destroy(Pilot* p); // Ai.
|
||||||
extern void ai_think(Pilot* pilot); // Ai.c
|
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_think(Pilot* pilot); // Player.c
|
||||||
extern void player_brokeHyperspace(void); // Player.c
|
extern void player_brokeHyperspace(void); // Player.c
|
||||||
extern int gui_load(const char* name); // 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 {
|
} else {
|
||||||
pilot->think = ai_think;
|
pilot->think = ai_think;
|
||||||
pilot->render = pilot_render;
|
pilot->render = pilot_render;
|
||||||
|
ai_create(pilot); // Will run the create function in ai.
|
||||||
}
|
}
|
||||||
|
// All update the same way.
|
||||||
pilot->update = pilot_update;
|
pilot->update = pilot_update;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new pilot - Params are same as pilot_init. Return pilot's id.
|
// Create a new pilot - Params are same as pilot_init. Return pilot's id.
|
||||||
|
Loading…
Reference in New Issue
Block a user