[Add] AI Lua API calls for secondary weapons.
This commit is contained in:
parent
92cea4a1b5
commit
7e013e5b91
@ -140,6 +140,15 @@ combat([number b])
|
||||
-- b - if 0 set the pilot to be in combat, if 1 or ommitted sets it to be in combat.
|
||||
-- return nil
|
||||
|
||||
settarget(number target)
|
||||
-- Set the target for the pilot, should be called each frame.
|
||||
-- target - Pilot to be targeted.
|
||||
-- return nil.
|
||||
|
||||
secondary()
|
||||
-- Tries to set the best secondary weapon (defaults to launchers).
|
||||
-- return the type of secondary weapon set ("None", "Weapon", "Launcher")
|
||||
|
||||
shoot([number weapon])
|
||||
-- Make the pilot shoot weapons.
|
||||
-- weapon to shoot, 1 if primary, 2 if secondary, 3 if both. Defaults to 1.
|
||||
|
@ -20,7 +20,7 @@ function control()
|
||||
-- Taunts.
|
||||
num = rng(0,4)
|
||||
if num == 0 then msg "Prepare to be boarded!"
|
||||
elseif num == 1 then msg = "Whoa! Lookie we I found here!"
|
||||
elseif num == 1 then msg = "Whoa! Lookie what we found here!"
|
||||
elseif num == 2 then msg = "What's a ship like you doing in a place like this?"
|
||||
end
|
||||
comm(enemy,msg)
|
||||
@ -44,7 +44,7 @@ function attacked(attacker)
|
||||
|
||||
-- Pirate isn't fighting or fleeing already.
|
||||
if task ~= "attack" and task ~= "runaway" then
|
||||
taunt()
|
||||
taunt(attacker)
|
||||
pushtask(0, "attack", attacker)
|
||||
-- Pirate is fighting bit switches to new target (doesn't forget the old on though).
|
||||
elseif task == "attack" then
|
||||
@ -54,14 +54,14 @@ function attacked(attacker)
|
||||
end
|
||||
end
|
||||
|
||||
function taunt()
|
||||
function taunt(target)
|
||||
num = rng(0,4)
|
||||
if num == 0 then msg = "How dare you attack me?!"
|
||||
elseif num == 1 then msg = "Aha! You think you can best ME?!"
|
||||
elseif num == 2 then msg = "JUST! DIE!"
|
||||
elseif num == 3 then msg = "Ohh, You're not going to enjoy this!"
|
||||
end
|
||||
if msg then comm(attacker, msg) end
|
||||
if msg then comm(target, msg) end
|
||||
end
|
||||
|
||||
-- Run away from the target.
|
||||
|
@ -13,6 +13,19 @@ function attacked(attacker)
|
||||
task = taskname()
|
||||
if task ~= "attack" and task ~= "runaway" then
|
||||
-- Let's have some taunts.
|
||||
taunt(attacker)
|
||||
|
||||
-- Now pilot fights back.
|
||||
pushtask(0, "attack", attacker)
|
||||
elseif task == "attack" then
|
||||
if gettargetid() ~= attacker then
|
||||
pushtask(0, "attack", attacker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Taunts.
|
||||
function taunt(target)
|
||||
num = rng(0,4)
|
||||
if num == 0 then msg = "You will never kill me!"
|
||||
elseif num == 1 then msg = "DIE!"
|
||||
@ -20,9 +33,6 @@ function attacked(attacker)
|
||||
elseif num == 3 then msg = "I hate you!"
|
||||
end
|
||||
if msg then comm(attacker, msg) end
|
||||
|
||||
pushtask(0, "attack", attacker)
|
||||
end
|
||||
end
|
||||
|
||||
-- Runs away.
|
||||
@ -51,6 +61,12 @@ function attack()
|
||||
|
||||
dir = face(target)
|
||||
dist = getdist(getpos(target))
|
||||
second = secondary()
|
||||
|
||||
if secondary() == "Launcher" then
|
||||
settarget(target)
|
||||
shoot(2)
|
||||
end
|
||||
|
||||
if parmour() < 70 then
|
||||
poptask()
|
||||
|
29
src/ai.c
29
src/ai.c
@ -124,6 +124,7 @@ static int ai_hyperspace(lua_State* L); // [number] hyperspace()
|
||||
// Combat.
|
||||
static int ai_combat(lua_State* L); // combat(number)
|
||||
static int ai_settarget(lua_State* L); // settarget(number)
|
||||
static int ai_secondary(lua_State* L); // string secondary()
|
||||
static int ai_shoot(lua_State* L); // shoot(number) number = 1,2,3.
|
||||
static int ai_getenemy(lua_State* L); // number getenemy().
|
||||
static int ai_hostile(lua_State* L); // hostile(number).
|
||||
@ -232,6 +233,7 @@ static int ai_loadProfile(char* filename) {
|
||||
// Combat.
|
||||
lua_regfunc(L, "combat", ai_combat);
|
||||
lua_regfunc(L, "settarget", ai_settarget);
|
||||
lua_regfunc(L, "secondary", ai_secondary);
|
||||
lua_regfunc(L, "shoot", ai_shoot);
|
||||
lua_regfunc(L, "getenemy", ai_getenemy);
|
||||
lua_regfunc(L, "hostile", ai_hostile);
|
||||
@ -699,6 +701,33 @@ static int ai_settarget(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set the secondary weapon. Biassed towards launchers..
|
||||
static int ai_secondary(lua_State* L) {
|
||||
if(cur_pilot->secondary) {
|
||||
lua_pushstring(L, outfit_getTypeBroad(cur_pilot->secondary->outfit));
|
||||
return 1;
|
||||
}
|
||||
|
||||
PilotOutfit* po = NULL;
|
||||
int i;
|
||||
for(i = 0; i < cur_pilot->noutfits; i++) {
|
||||
if((po == NULL) && (outfit_isWeapon(cur_pilot->outfits[i].outfit) ||
|
||||
outfit_isLauncher(cur_pilot->outfits[i].outfit)))
|
||||
po = &cur_pilot->outfits[i];
|
||||
else if((po != NULL) && outfit_isWeapon(po->outfit) &&
|
||||
outfit_isLauncher(cur_pilot->outfits[i].outfit))
|
||||
po = &cur_pilot->outfits[i];
|
||||
}
|
||||
if(po) {
|
||||
cur_pilot->secondary = po;
|
||||
pilot_setAmmo(cur_pilot);
|
||||
lua_pushstring(L, outfit_getTypeBroad(po->outfit));
|
||||
return 1;
|
||||
}
|
||||
lua_pushstring(L, "None");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Pew pew.. Says the pilot.
|
||||
static int ai_shoot(lua_State* L) {
|
||||
int n = 1;
|
||||
|
12
src/outfit.c
12
src/outfit.c
@ -37,6 +37,18 @@ int outfit_isWeapon(const Outfit* o) {
|
||||
return ((o->type == OUTFIT_TYPE_BOLT) || (o->type == OUTFIT_TYPE_BEAM));
|
||||
}
|
||||
|
||||
// Return the broad outfit type.
|
||||
const char* outfit_typenamebroad[] = { "NULL", "Weapon", "Launcher", "Ammo" };
|
||||
|
||||
const char* outfit_getTypeBroad(const Outfit* o) {
|
||||
int i = 0;
|
||||
if(outfit_isWeapon(o)) i = 1;
|
||||
else if(outfit_isLauncher(o)) i = 2;
|
||||
else if(outfit_isAmmo(0)) i = 3;
|
||||
|
||||
return outfit_typenamebroad[i];
|
||||
}
|
||||
|
||||
// Return 1 if outfit is a launcher.
|
||||
int outfit_isLauncher(const Outfit* o) {
|
||||
return((o->type == OUTFIT_TYPE_MISSILE_DUMB) ||
|
||||
|
@ -69,6 +69,7 @@ int outfit_isWeapon(const Outfit* o);
|
||||
int outfit_isLauncher(const Outfit* o);
|
||||
int outfit_isAmmo(const Outfit* o);
|
||||
const char* outfit_getType(const Outfit* o);
|
||||
const char* outfit_getTypeBroad(const Outfit* o);
|
||||
|
||||
// Load/free outfit stack.
|
||||
int outfit_load(void);
|
||||
|
Loading…
Reference in New Issue
Block a user