[Change] Improved AI's secondary weapon handling.
This commit is contained in:
parent
ad5f1d4464
commit
19292edd68
@ -31,7 +31,7 @@ function atk_b()
|
|||||||
dist = ai.dist(ai.pos(target)) -- Get distance.
|
dist = ai.dist(ai.pos(target)) -- Get distance.
|
||||||
|
|
||||||
-- Get bombing tool.
|
-- Get bombing tool.
|
||||||
secondary, special = ai.secondary("Launcher")
|
secondary, special = ai.secondary("ranged")
|
||||||
if secondary ~= "Launcher" or special == "Dumb" then -- No launcher, must melee.
|
if secondary ~= "Launcher" or special == "Dumb" then -- No launcher, must melee.
|
||||||
range = ai.getweaprange()
|
range = ai.getweaprange()
|
||||||
|
|
||||||
|
@ -66,10 +66,13 @@ end
|
|||||||
-- ]]
|
-- ]]
|
||||||
function atk_g_ranged(target, dist)
|
function atk_g_ranged(target, dist)
|
||||||
dir = ai.face(target) -- Normal face the target.
|
dir = ai.face(target) -- Normal face the target.
|
||||||
secondary, special, ammo = ai.secondary("Launcher")
|
secondary, special, ammo = ai.secondary("ranged")
|
||||||
|
|
||||||
|
-- Always use figher bay.
|
||||||
|
if secondary == "" then
|
||||||
|
|
||||||
-- Shoot missiles if in range.
|
-- Shoot missiles if in range.
|
||||||
if secondary == "Launcher" and
|
elseif secondary == "Launcher" and
|
||||||
dist < ai.getweaprange(1) then
|
dist < ai.getweaprange(1) then
|
||||||
-- More lenient with aiming.
|
-- More lenient with aiming.
|
||||||
if special == "Smart" and dir < 30 then
|
if special == "Smart" and dir < 30 then
|
||||||
@ -98,7 +101,7 @@ end
|
|||||||
-- Melee the target.
|
-- Melee the target.
|
||||||
--]]
|
--]]
|
||||||
function atk_g_melee(target, dist)
|
function atk_g_melee(target, dist)
|
||||||
secondary, special = ai.secondary("Beam Weapon")
|
secondary, special = ai.secondary("melee")
|
||||||
dir = ai.aim(target) -- We aim instead of face.
|
dir = ai.aim(target) -- We aim instead of face.
|
||||||
|
|
||||||
-- Fire non-smart secondary weapons.
|
-- Fire non-smart secondary weapons.
|
||||||
|
80
src/ai.c
80
src/ai.c
@ -1260,27 +1260,49 @@ static int ai_settarget(lua_State* L) {
|
|||||||
LLUA_INVALID_PARAMETER();
|
LLUA_INVALID_PARAMETER();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int outfit_isMelee(Pilot* p, PilotOutfit* o) {
|
||||||
|
(void)p;
|
||||||
|
if(outfit_isBolt(o->outfit) || outfit_isBeam(o->outfit))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int outfit_isRanged(Pilot* p, PilotOutfit* o) {
|
||||||
|
if(outfit_isFighterBay(o->outfit) || outfit_isLauncher(o->outfit)) {
|
||||||
|
/* Must have ammo. */
|
||||||
|
if(pilot_getAmmo(p, o->outfit) <= 0)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the secondary weapon. Biassed towards launchers.. */
|
/* Set the secondary weapon. Biassed towards launchers.. */
|
||||||
static int ai_secondary(lua_State* L) {
|
static int ai_secondary(lua_State* L) {
|
||||||
PilotOutfit* co, *po;
|
PilotOutfit* co, *po;
|
||||||
int i;
|
int i, melee;
|
||||||
char* type;
|
char* str;
|
||||||
const char* otype;
|
const char* otype;
|
||||||
|
|
||||||
po = NULL;
|
po = NULL;
|
||||||
|
|
||||||
/* Search for a type. */
|
/* Parse the parameters. */
|
||||||
type = NULL;
|
if(lua_isstring(L, 1)) {
|
||||||
if(lua_isstring(L, 1))
|
str = (char*)lua_tostring(L, 1);
|
||||||
type = (char*) lua_tostring(L, 1);
|
if(strcmp(str, "melee")==0)
|
||||||
|
melee = 1;
|
||||||
|
else if(strcmp(str, "ranged")==0)
|
||||||
|
melee = 0;
|
||||||
|
else LLUA_INVALID_PARAMETER();
|
||||||
|
}
|
||||||
|
else LLUA_INVALID_PARAMETER();
|
||||||
|
|
||||||
/* Pilot has secondary selected - use that. */
|
/* Pilot has secondary selected - use that. */
|
||||||
if(cur_pilot->secondary != NULL) {
|
if(cur_pilot->secondary != NULL) {
|
||||||
co = cur_pilot->secondary;
|
co = cur_pilot->secondary;
|
||||||
otype = outfit_getTypeBroad(co->outfit);
|
if(melee && outfit_isMelee(cur_pilot, co))
|
||||||
|
po = co;
|
||||||
/* If we aren't looking for a type or if it matches what we want. */
|
else if(!melee && outfit_isRanged(cur_pilot, co))
|
||||||
if((type == NULL) || (strcmp(otype, type) == 0))
|
|
||||||
po = co;
|
po = co;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1296,38 +1318,14 @@ static int ai_secondary(lua_State* L) {
|
|||||||
outfit_isAmmo(co->outfit))
|
outfit_isAmmo(co->outfit))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* Get the first match. */
|
||||||
/* Must have ammo. */
|
if(melee && outfit_isMelee(cur_pilot, co)) {
|
||||||
if(outfit_isLauncher(co->outfit) && pilot_getAmmo(cur_pilot, co->outfit)==0)
|
po = co;
|
||||||
continue;
|
break;
|
||||||
|
|
||||||
/* Searching for type. */
|
|
||||||
if(type != NULL) {
|
|
||||||
otype = outfit_getTypeBroad(co->outfit);
|
|
||||||
if(strcmp(otype, type)==0) {
|
|
||||||
po = co;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We'll grab the first weapon in case we don't find what we want. */
|
|
||||||
if((po == NULL) && (outfit_isWeapon(co->outfit) ||
|
|
||||||
outfit_isLauncher(co->outfit)))
|
|
||||||
po = co;
|
|
||||||
}
|
}
|
||||||
|
else if(!melee && outfit_isRanged(cur_pilot, co)) {
|
||||||
/* Just grabbing best weapon. */
|
po = co;
|
||||||
else {
|
break;
|
||||||
/* Grab first weapon or launcher it finds. */
|
|
||||||
if((po == NULL) && (outfit_isBolt(co->outfit) ||
|
|
||||||
outfit_isBeam(co->outfit) ||
|
|
||||||
outfit_isLauncher(co->outfit)))
|
|
||||||
po = co;
|
|
||||||
|
|
||||||
/* Grab launcher over weapon by default. */
|
|
||||||
else if((po != NULL) && (outfit_isBolt(po->outfit) ||
|
|
||||||
outfit_isBeam(po->outfit)) &&
|
|
||||||
outfit_isLauncher(co->outfit))
|
|
||||||
po = co;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user