From 230329f868bdb36633416b68ba2ebc93f768801e Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Wed, 21 May 2014 00:09:43 +0100
Subject: [PATCH] [Change] Better handling of secondary weapons.

---
 src/ai.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/ai.c b/src/ai.c
index 4cd2e05..14de13a 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -1298,6 +1298,7 @@ static int ai_aim(lua_State* L) {
   Vec2 tv;
   double dist, diff;
   double mod;
+  double speed;
   LLUA_MIN_ARGS(1);
 
   /* Only acceptable parameter is pilot id. */
@@ -1316,8 +1317,16 @@ static int ai_aim(lua_State* L) {
   /* Get the  distance. */
   dist = vect_dist(&cur_pilot->solid->pos, &p->solid->pos);
 
+  /* Check if we should recalculate weapon speed with secondary weapon. */
+  if((cur_pilot->secondary != NULL) &&
+      outfit_isBolt(cur_pilot->secondary->outfit) &&
+      (cur_pilot->secondary->outfit->type == OUTFIT_TYPE_MISSILE_DUMB)) {
+    speed = cur_pilot->weap_speed + outfit_speed(cur_pilot->secondary->outfit);
+    speed /= 2.;
+  }
+
   /* Time for shots to reach distance. */
-  t = dist / cur_pilot->weap_speed;
+  t = dist / speed;
 
   /* Position is calculated on where it should be. */
   x = p->solid->pos.x + p->solid->vel.x*t
@@ -1369,7 +1378,8 @@ static int ai_settarget(lua_State* L) {
  */
 static int outfit_isMelee(Pilot* p, PilotOutfit* o) {
   (void)p;
-  if(outfit_isBolt(o->outfit) || outfit_isBeam(o->outfit))
+  if(outfit_isBolt(o->outfit) || outfit_isBeam(o->outfit) ||
+      (o->outfit->type == OUTFIT_TYPE_MISSILE_DUMB))
     return 1;
   return 0;
 }
@@ -1380,7 +1390,9 @@ static int outfit_isMelee(Pilot* p, PilotOutfit* o) {
  *    @param o Outfit to check.
  */
 static int outfit_isRanged(Pilot* p, PilotOutfit* o) {
-  if(outfit_isFighterBay(o->outfit) || outfit_isLauncher(o->outfit)) {
+  if(outfit_isFighterBay(o->outfit) ||
+      (outfit_isLauncher(o->outfit) &&
+      (o->outfit->type != OUTFIT_TYPE_MISSILE_DUMB))) {
     /* Must have ammo. */
     if(pilot_getAmmo(p, o->outfit) <= 0)
       return 0;