[Add] Improved ai.secondary to actually take ammo into account.

This commit is contained in:
Allanis 2013-11-09 05:49:03 +00:00
parent 9c2e35c472
commit 0d569ecc54

View File

@ -1038,6 +1038,11 @@ static int ai_secondary(lua_State* L) {
outfit_isAmmo(co->outfit)) outfit_isAmmo(co->outfit))
continue; continue;
/* Must have ammo. */
if(outfit_isLauncher(co->outfit) && pilot_getAmmo(cur_pilot, co->outfit)==0)
continue;
/* Searching for type. */ /* Searching for type. */
if(type != NULL) { if(type != NULL) {
otype = outfit_getTypeBroad(co->outfit); otype = outfit_getTypeBroad(co->outfit);
@ -1055,12 +1060,14 @@ static int ai_secondary(lua_State* L) {
/* Just grabbing best weapon. */ /* Just grabbing best weapon. */
else { else {
/* Grab first weapon or launcher it finds. */ /* Grab first weapon or launcher it finds. */
if((po == NULL) && (outfit_isWeapon(co->outfit) || if((po == NULL) && (outfit_isBolt(co->outfit) ||
outfit_isBeam(co->outfit) ||
outfit_isLauncher(co->outfit))) outfit_isLauncher(co->outfit)))
po = co; po = co;
/* Grab launcher over weapon by default. */ /* Grab launcher over weapon by default. */
else if((po != NULL) && outfit_isWeapon(po->outfit) && else if((po != NULL) && (outfit_isBolt(po->outfit) ||
outfit_isBeam(po->outfit)) &&
outfit_isLauncher(co->outfit)) outfit_isLauncher(co->outfit))
po = co; po = co;
} }
@ -1074,10 +1081,17 @@ static int ai_secondary(lua_State* L) {
lua_pushstring(L, otype); lua_pushstring(L, otype);
/* Set special flags. */ /* Set special flags. */
if((strcmp(otype, "Launcher")==0) && if(outfit_isLauncher(po->outfit)) {
(po->outfit->type != OUTFIT_TYPE_MISSILE_DUMB)) { if((po->outfit->type != OUTFIT_TYPE_MISSILE_DUMB))
lua_pushstring(L, "Smart"); lua_pushstring(L, "Smart");
return 2; else
lua_pushstring(L, "Dumb");
if(cur_pilot->ammo == NULL)
lua_pushnumber(L, 0.);
else
lua_pushnumber(L, cur_pilot->ammo->quantity);
return 3;
} }
return 1; return 1;
} }