[Change] AI now use more weapon types and uses them more wisely.
[Add] Draktharr gets mace rockets.
This commit is contained in:
parent
74c0297b02
commit
01b3f2f77b
10
dat/ship.xml
10
dat/ship.xml
@ -338,8 +338,8 @@
|
||||
</characteristics>
|
||||
<outfits>
|
||||
<outfit quantity="4">Laser Turret</outfit>
|
||||
<outfit quantity="2">Missile Launcher</outfit>
|
||||
<outfit quantity="40">Missile</outfit>
|
||||
<outfit quantity="2">Mace Launcher</outfit>
|
||||
<outfit quantity="20">Mace Rocket</outfit>
|
||||
</outfits>
|
||||
</ship>
|
||||
<ship name="Admonisher">
|
||||
@ -511,6 +511,8 @@
|
||||
</characteristics>
|
||||
<outfits>
|
||||
<outfit quantity="6">Laser Cannon</outfit>
|
||||
<outfit quantity="1">Mace Launcher</outfit>
|
||||
<outfit quantity="5">Mace Rocket</outfit>
|
||||
</outfits>
|
||||
</ship>
|
||||
<ship name="Pirate Vendetta">
|
||||
@ -613,8 +615,8 @@
|
||||
</characteristics>
|
||||
<outfits>
|
||||
<outfit quantity="3">Laser Cannon</outfit>
|
||||
<outfit quantity="1">Missile Launcher</outfit>
|
||||
<outfit quantity="8">Missile</outfit>
|
||||
<outfit quantity="2">Mace Launcher</outfit>
|
||||
<outfit quantity="10">Mace Rocket</outfit>
|
||||
</outfits>
|
||||
</ship>
|
||||
<ship name="Pirate Ancestor">
|
||||
|
@ -28,10 +28,19 @@ function attack()
|
||||
if dist > range then
|
||||
dir = ai.face(target) -- Normal face the target.
|
||||
|
||||
secondary, special = ai.secondary("Launcher")
|
||||
|
||||
-- Shoot missiles if in range.
|
||||
if ai.secondary() == "Launcher" and
|
||||
dist < ai.getweaprange(1) and dir < 30 then -- More leniant with aiming.
|
||||
if secondary == "Launcher" and
|
||||
dist < ai.getweaprange(1) then
|
||||
-- More lenient with aiming.
|
||||
if special == "Smart" and dir < 30 then
|
||||
ai.shoot(2)
|
||||
|
||||
-- Non-smart miss more.
|
||||
elseif dir < 10 then
|
||||
ai.shoot(2)
|
||||
end
|
||||
end
|
||||
|
||||
if dir < 10 then
|
||||
@ -40,8 +49,18 @@ function attack()
|
||||
|
||||
-- Close enough to melee.
|
||||
else
|
||||
secondary, special = ai.secondary("Weapon")
|
||||
dir = ai.aim(target) -- we aim instead of face.
|
||||
if (dir < 10 or ai.hasturret()) then
|
||||
|
||||
-- Fire non-smart secondary weapons.
|
||||
if(secondary == "Launcher" and special ~= "Smart") or
|
||||
secondary == "Weapon" then
|
||||
if dir < 10 then -- Need good acuracy.
|
||||
ai.shoot(2)
|
||||
end
|
||||
end
|
||||
|
||||
if dir < 10 or ai.hasturrets() then
|
||||
ai.shoot()
|
||||
end
|
||||
end
|
||||
|
80
src/ai.c
80
src/ai.c
@ -939,31 +939,83 @@ static int ai_settarget(lua_State* L) {
|
||||
|
||||
/* Set the secondary weapon. Biassed towards launchers.. */
|
||||
static int ai_secondary(lua_State* L) {
|
||||
PilotOutfit* po;
|
||||
PilotOutfit* co, *po;
|
||||
int i;
|
||||
char* type;
|
||||
const char* otype;
|
||||
|
||||
if(cur_pilot->secondary) {
|
||||
lua_pushstring(L, outfit_getTypeBroad(cur_pilot->secondary->outfit));
|
||||
return 1;
|
||||
/* Search for a type. */
|
||||
type = NULL;
|
||||
if(lua_isstring(L, 1))
|
||||
type = (char*) lua_tostring(L, 1);
|
||||
|
||||
/* Pilot has secondary selected - use that. */
|
||||
if(cur_pilot->secondary != NULL) {
|
||||
co = cur_pilot->secondary;
|
||||
otype = outfit_getTypeBroad(co->outfit);
|
||||
|
||||
/* If we aren't looking for a type or if it matches what we want. */
|
||||
if((type == NULL) || (strcmp(otype, type) == 0))
|
||||
po = co;
|
||||
}
|
||||
|
||||
/* Need to get new secondary. */
|
||||
if(po == NULL) {
|
||||
/* Iterate over the list. */
|
||||
po = NULL;
|
||||
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];
|
||||
co = &cur_pilot->outfits[i];
|
||||
|
||||
/* Not a secondary weapon. */
|
||||
if(!outfit_isProp(co->outfit, OUTFIT_PROP_WEAP_SECONDARY) ||
|
||||
outfit_isAmmo(co->outfit))
|
||||
continue;
|
||||
|
||||
/* Searching for type. */
|
||||
if(type != NULL) {
|
||||
otype = outfit_getTypeBroad(co->outfit);
|
||||
if(strcmp(otype, type)==0) {
|
||||
po = co;
|
||||
break;
|
||||
}
|
||||
if(po) {
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Just grabbing best weapon. */
|
||||
else {
|
||||
/* Grab first weapon or launcher it finds. */
|
||||
if((po == NULL) && (outfit_isWeapon(co->outfit) ||
|
||||
outfit_isLauncher(co->outfit)))
|
||||
po = co;
|
||||
|
||||
/* Grab launcher over weapon by default. */
|
||||
else if((po != NULL) && outfit_isWeapon(po->outfit) &&
|
||||
outfit_isLauncher(co->outfit))
|
||||
po = co;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(po != NULL) {
|
||||
cur_pilot->secondary = po;
|
||||
pilot_setAmmo(cur_pilot);
|
||||
lua_pushstring(L, outfit_getTypeBroad(po->outfit));
|
||||
otype = outfit_getTypeBroad(po->outfit);
|
||||
lua_pushstring(L, otype);
|
||||
|
||||
/* Set special flags. */
|
||||
if((strcmp(otype, "Launcher")==0) &&
|
||||
(po->outfit->type != OUTFIT_TYPE_MISSILE_DUMB)) {
|
||||
lua_pushstring(L, "Smart");
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
lua_pushstring(L, "None");
|
||||
return 1;
|
||||
/* Nothing found. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ai_hasturrets(lua_State* L) {
|
||||
|
@ -18,8 +18,6 @@
|
||||
#define OUTFIT_DATA "../dat/outfit.xml"
|
||||
#define OUTFIT_GFX "../gfx/outfit/"
|
||||
|
||||
extern SDL_mutex* sound_lock; /* Sound.c */
|
||||
|
||||
/* The Stack. */
|
||||
static Outfit* outfit_stack = NULL;
|
||||
static int outfit_nstack = 0;
|
||||
|
@ -349,7 +349,7 @@ void pilot_setSecondary(Pilot* p, const char* secondary) {
|
||||
/* Find the secondary and set ammo appropriately. */
|
||||
for(i = 0; i < p->noutfits; i++) {
|
||||
if(strcmp(secondary, p->outfits[i].outfit->name)==0) {
|
||||
p->secondary = &p->outfits[i];;
|
||||
p->secondary = &p->outfits[i];
|
||||
pilot_setAmmo(p);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user