[Change] AI now use more weapon types and uses them more wisely.

[Add] Draktharr gets mace rockets.
This commit is contained in:
Allanis 2013-08-28 15:08:22 +01:00
parent 74c0297b02
commit 01b3f2f77b
5 changed files with 99 additions and 28 deletions

View File

@ -338,8 +338,8 @@
</characteristics> </characteristics>
<outfits> <outfits>
<outfit quantity="4">Laser Turret</outfit> <outfit quantity="4">Laser Turret</outfit>
<outfit quantity="2">Missile Launcher</outfit> <outfit quantity="2">Mace Launcher</outfit>
<outfit quantity="40">Missile</outfit> <outfit quantity="20">Mace Rocket</outfit>
</outfits> </outfits>
</ship> </ship>
<ship name="Admonisher"> <ship name="Admonisher">
@ -510,7 +510,9 @@
<cap_cargo>5</cap_cargo> <cap_cargo>5</cap_cargo>
</characteristics> </characteristics>
<outfits> <outfits>
<outfit quantity="6">Laser Cannon</outfit> <outfit quantity="6">Laser Cannon</outfit>
<outfit quantity="1">Mace Launcher</outfit>
<outfit quantity="5">Mace Rocket</outfit>
</outfits> </outfits>
</ship> </ship>
<ship name="Pirate Vendetta"> <ship name="Pirate Vendetta">
@ -613,8 +615,8 @@
</characteristics> </characteristics>
<outfits> <outfits>
<outfit quantity="3">Laser Cannon</outfit> <outfit quantity="3">Laser Cannon</outfit>
<outfit quantity="1">Missile Launcher</outfit> <outfit quantity="2">Mace Launcher</outfit>
<outfit quantity="8">Missile</outfit> <outfit quantity="10">Mace Rocket</outfit>
</outfits> </outfits>
</ship> </ship>
<ship name="Pirate Ancestor"> <ship name="Pirate Ancestor">

View File

@ -28,10 +28,19 @@ function attack()
if dist > range then if dist > range then
dir = ai.face(target) -- Normal face the target. dir = ai.face(target) -- Normal face the target.
secondary, special = ai.secondary("Launcher")
-- Shoot missiles if in range. -- Shoot missiles if in range.
if ai.secondary() == "Launcher" and if secondary == "Launcher" and
dist < ai.getweaprange(1) and dir < 30 then -- More leniant with aiming. dist < ai.getweaprange(1) then
ai.shoot(2) -- 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 end
if dir < 10 then if dir < 10 then
@ -40,8 +49,18 @@ function attack()
-- Close enough to melee. -- Close enough to melee.
else else
secondary, special = ai.secondary("Weapon")
dir = ai.aim(target) -- we aim instead of face. 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() ai.shoot()
end end
end end

View File

@ -939,31 +939,83 @@ static int ai_settarget(lua_State* L) {
/* 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* po; PilotOutfit* co, *po;
int i; int i;
char* type;
const char* otype;
if(cur_pilot->secondary) { /* Search for a type. */
lua_pushstring(L, outfit_getTypeBroad(cur_pilot->secondary->outfit)); type = NULL;
return 1; 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;
} }
po = NULL; /* Need to get new secondary. */
for(i = 0; i < cur_pilot->noutfits; i++) { if(po == NULL) {
if((po == NULL) && (outfit_isWeapon(cur_pilot->outfits[i].outfit) || /* Iterate over the list. */
outfit_isLauncher(cur_pilot->outfits[i].outfit))) po = NULL;
po = &cur_pilot->outfits[i]; for(i = 0; i < cur_pilot->noutfits; i++) {
else if((po != NULL) && outfit_isWeapon(po->outfit) && co = &cur_pilot->outfits[i];
outfit_isLauncher(cur_pilot->outfits[i].outfit))
po = &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;
}
/* 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) {
if(po != NULL) {
cur_pilot->secondary = po; cur_pilot->secondary = po;
pilot_setAmmo(cur_pilot); 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; return 1;
} }
lua_pushstring(L, "None"); /* Nothing found. */
return 1; return 0;
} }
static int ai_hasturrets(lua_State* L) { static int ai_hasturrets(lua_State* L) {

View File

@ -18,8 +18,6 @@
#define OUTFIT_DATA "../dat/outfit.xml" #define OUTFIT_DATA "../dat/outfit.xml"
#define OUTFIT_GFX "../gfx/outfit/" #define OUTFIT_GFX "../gfx/outfit/"
extern SDL_mutex* sound_lock; /* Sound.c */
/* The Stack. */ /* The Stack. */
static Outfit* outfit_stack = NULL; static Outfit* outfit_stack = NULL;
static int outfit_nstack = 0; static int outfit_nstack = 0;

View File

@ -349,7 +349,7 @@ void pilot_setSecondary(Pilot* p, const char* secondary) {
/* Find the secondary and set ammo appropriately. */ /* Find the secondary and set ammo appropriately. */
for(i = 0; i < p->noutfits; i++) { for(i = 0; i < p->noutfits; i++) {
if(strcmp(secondary, p->outfits[i].outfit->name)==0) { if(strcmp(secondary, p->outfits[i].outfit->name)==0) {
p->secondary = &p->outfits[i];; p->secondary = &p->outfits[i];
pilot_setAmmo(p); pilot_setAmmo(p);
return; return;
} }