From 0d569ecc5448bf46c397e99d28bfb4970e655851 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 9 Nov 2013 05:49:03 +0000 Subject: [PATCH] [Add] Improved ai.secondary to actually take ammo into account. --- src/ai.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ai.c b/src/ai.c index e2f44e8..d0ed28e 100644 --- a/src/ai.c +++ b/src/ai.c @@ -1038,6 +1038,11 @@ static int ai_secondary(lua_State* L) { outfit_isAmmo(co->outfit)) continue; + + /* Must have ammo. */ + if(outfit_isLauncher(co->outfit) && pilot_getAmmo(cur_pilot, co->outfit)==0) + continue; + /* Searching for type. */ if(type != NULL) { otype = outfit_getTypeBroad(co->outfit); @@ -1055,12 +1060,14 @@ static int ai_secondary(lua_State* L) { /* Just grabbing best weapon. */ else { /* 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))) po = co; /* 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)) po = co; } @@ -1074,10 +1081,17 @@ static int ai_secondary(lua_State* L) { 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; + if(outfit_isLauncher(po->outfit)) { + if((po->outfit->type != OUTFIT_TYPE_MISSILE_DUMB)) + lua_pushstring(L, "Smart"); + 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; }