]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/landgun.c
Factor out common ship gun fire code into shp_fire()
[empserver] / src / lib / subs / landgun.c
index bd66b7f631d4bfebbe4e94c40009e9242531c179..7d463fd450d40ca79e7962237f231951afd81fc0 100644 (file)
@@ -101,6 +101,33 @@ fort_fire(struct sctstr *sp)
     return (int)fortgun(sp->sct_effic, guns);
 }
 
+/*
+ * Fire from ship SP.
+ * Use ammo, resupply if necessary.
+ * Return damage if the ship fires, else -1.
+ */
+int
+shp_fire(struct shpstr *sp)
+{
+    int guns, shells;
+
+    if (sp->shp_effic < 60)
+       return -1;
+    guns = sp->shp_glim;
+    guns = MIN(guns, sp->shp_item[I_GUN]);
+    guns = MIN(guns, (sp->shp_item[I_MILIT] + 1) / 2);
+    if (guns == 0)
+       return -1;
+    shells = sp->shp_item[I_SHELL];
+    shells += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
+                           I_SHELL, (guns + 1) / 2 - shells);
+    guns = MIN(guns, shells * 2);
+    if (guns == 0)
+       return -1;
+    sp->shp_item[I_SHELL] = shells - (guns + 1) / 2;
+    return (int)seagun(sp->shp_effic, guns);
+}
+
 /*
  * Drop depth-charges from ship SP.
  * Use ammo, resupply if necessary.