]> git.pond.sub.org Git - empserver/commitdiff
Make depth-charging code and documentation match
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 2 Mar 2008 10:01:42 +0000 (11:01 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 14 Mar 2008 19:25:37 +0000 (20:25 +0100)
Before 4.0.6, depth charges required no guns, one military, did damage
like shell fire from two guns, and used two shells.  Missions were not
quite consistent with that (bug).  4.0.6 changed depth charges to work
exactly like shell fire (but without updating documentation
accordingly): require guns and gun crew, non-zero firing range, scale
damage and ammunition use with guns.

Go back to the old model, but with damage like three guns, to avoid
changing the stock game's dd now (three gun damage for two shells).
Stock game's af changes from two gun damage for one shell, and nas
from four gun damage for two shells.

Factor out common depth-charging code into shp_dchrg().

include/ship.h
info/Damage.t
src/lib/commands/mfir.c
src/lib/commands/torp.c
src/lib/subs/landgun.c
src/lib/subs/mission.c

index 422781327dab98304d6ec260da61c58efc549568..99f945deeca30082f1788cea4f5f700b0c63ac8d 100644 (file)
@@ -183,4 +183,6 @@ extern int m_visib(struct mchrstr *, int);
 extern int m_frnge(struct mchrstr *, int);
 extern int m_glim(struct mchrstr *, int);
 
 extern int m_frnge(struct mchrstr *, int);
 extern int m_glim(struct mchrstr *, int);
 
+extern int shp_dchrg(struct shpstr *);
+
 #endif
 #endif
index ca2cc8f18e052d4acf38ea954352bec84b2296fc..be5092286717a59bef7e2458a8b2024dda59fdd3 100644 (file)
@@ -17,7 +17,7 @@ You can be shelled by a fort, artillery unit, ship, depth-charge, or torpedo:
        fort damage = guns * eff * (random(30) + 20) / 7
        unit damage = guns * eff * (5 + random(6))
        ship damage = guns * eff * (10 + random(6))
        fort damage = guns * eff * (random(30) + 20) / 7
        unit damage = guns * eff * (5 + random(6))
        ship damage = guns * eff * (10 + random(6))
-      depth damage =    2 * eff * (10 + random(6))
+      depth damage =    3 * eff * (10 + random(6))
        torp damage = 40 + random(40) + random(40)
 Note that for forts, a maximum of 7 guns may be fired.
 
        torp damage = 40 + random(40) + random(40)
 Note that for forts, a maximum of 7 guns may be fired.
 
index b4ff03b7d92d2e2f9d6b69dd75f6fb316408eefa..632847f3f4279d4ea15ac1884ef31ee75e6ffdb8 100644 (file)
@@ -308,21 +308,6 @@ multifire(void)
                pr("Not enough military for firing crew.\n");
                continue;
            }
                pr("Not enough military for firing crew.\n");
                continue;
            }
-           gun = fship.shp_item[I_GUN];
-           gun = MIN(gun, fship.shp_glim);
-           if (fship.shp_frnge == 0 || gun == 0) {
-               pr("Insufficient arms.\n");
-               continue;
-           }
-           shell = fship.shp_item[I_SHELL];
-           if (shell < 2)
-               shell += supply_commod(fship.shp_own,
-                                      fship.shp_x, fship.shp_y,
-                                      I_SHELL, 2 - shell);
-           if (shell <= 0) {
-               pr("Klick!     ...\n");
-               continue;
-           }
            if (fship.shp_effic < 60) {
                pr("Ship #%d is crippled (%d%%)\n",
                   fshipno, fship.shp_effic);
            if (fship.shp_effic < 60) {
                pr("Ship #%d is crippled (%d%%)\n",
                   fshipno, fship.shp_effic);
@@ -331,26 +316,46 @@ multifire(void)
            range = effrange(fship.shp_frnge, fship.shp_tech);
            range2 = roundrange(range);
            pr("range is %d.00 (%.2f)\n", range2, range);
            range = effrange(fship.shp_frnge, fship.shp_tech);
            range2 = roundrange(range);
            pr("range is %d.00 (%.2f)\n", range2, range);
-           if (target == targ_sub) {
-               if ((mchr[(int)fship.shp_type].m_flags & M_DCH) == 0) {
+           if (target == targ_sub
+               && (mchr[(int)fship.shp_type].m_flags & M_DCH)) {
+               dam = shp_dchrg(&fship);
+               putship(fship.shp_uid, &fship);
+               if (dam < 0) {
+                   pr("Not enough shells for depth charge!\n");
+                   continue;
+               }
+           } else {
+               if (target == targ_sub)
                    /* Don't tell it's a sub */
                    range2 = -1;
                    /* Don't tell it's a sub */
                    range2 = -1;
-               } else if (shell < 2) {
-                   pr("Not enough shells for depth charge!\n");
+               gun = fship.shp_item[I_GUN];
+               gun = MIN(gun, fship.shp_glim);
+               if (fship.shp_frnge == 0 || gun == 0) {
+                   pr("Insufficient arms.\n");
+                   continue;
+               }
+               shell = fship.shp_item[I_SHELL];
+               shell += supply_commod(fship.shp_own,
+                                      fship.shp_x, fship.shp_y,
+                                      I_SHELL, 2 - shell);
+               if (shell <= 0) {
+                   pr("Klick!     ...\n");
                    continue;
                }
                    continue;
                }
+               gun = MIN(gun, shell * 2);
+               gun = MIN(gun, mil / 2);
+               gun = MAX(gun, 1);
+               shots = gun;
+               guneff = seagun(fship.shp_effic, shots);
+               dam = (int)guneff;
+               shell -= ldround(shots / 2.0, 1);
+               fship.shp_item[I_SHELL] = shell;
+               putship(fship.shp_uid, &fship);
            }
            }
-           gun = MIN(gun, shell * 2);
-           gun = MIN(gun, mil / 2);
-           gun = MAX(gun, 1);
-           shots = gun;
-           guneff = seagun(fship.shp_effic, shots);
-           dam = (int)guneff;
-           shell -= ldround(shots / 2.0, 1);
-           fship.shp_item[I_SHELL] = shell;
-           if (opt_NOMOBCOST == 0)
+           if (opt_NOMOBCOST == 0) {
                fship.shp_mobil = MAX(fship.shp_mobil - 15, -100);
                fship.shp_mobil = MAX(fship.shp_mobil - 15, -100);
-           putship(fship.shp_uid, &fship);
+               putship(fship.shp_uid, &fship);
+           }
        } else if (attacker == targ_unit) {
            if (fland.lnd_own != player->cnum) {
                pr("Not your unit!\n");
        } else if (attacker == targ_unit) {
            if (fland.lnd_own != player->cnum) {
                pr("Not your unit!\n");
index efec0d8e0ae289838520525c09689b973c4f477f..9a10dbf556dd452c369f3c7761b145c77d332ecb 100644 (file)
@@ -240,9 +240,6 @@ anti_torp(int f, int ntorping, int vshipown)
            continue;
        if (dd.shp_own != vshipown)
            continue;
            continue;
        if (dd.shp_own != vshipown)
            continue;
-       if (dd.shp_effic < 60)
-           continue;
-
        if (!canshoot(&dd, &sub))
            continue;
 
        if (!canshoot(&dd, &sub))
            continue;
 
@@ -326,29 +323,29 @@ fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
     int gun;
     double guneff;
 
     int gun;
     double guneff;
 
-    shells = sp->shp_item[I_SHELL];
-    gun = sp->shp_item[I_GUN];
-    gun = MIN(gun, sp->shp_glim);
-    gun = MIN(gun, sp->shp_item[I_MILIT] / 2);
+    if ((mchr[(int)targ->shp_type].m_flags & M_SUB) == 0) {
+       shells = sp->shp_item[I_SHELL];
+       gun = sp->shp_item[I_GUN];
+       gun = MIN(gun, sp->shp_glim);
+       gun = MIN(gun, sp->shp_item[I_MILIT] / 2);
 
 
-    shells += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
-                           I_SHELL, (gun + 1) / 2 - shells);
+       shells += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
+                               I_SHELL, (gun + 1) / 2 - shells);
 
 
-    gun = MIN(gun, shells * 2);
-    if (gun == 0)
-       return;
+       gun = MIN(gun, shells * 2);
+       if (gun == 0)
+           return;
 
 
-    /* ok, all set.. now, we shoot */
-    shells -= ldround(gun / 2.0, 1);
-    sp->shp_item[I_SHELL] = shells;
-    putship(sp->shp_uid, sp);
+       /* ok, all set.. now, we shoot */
+       shells -= ldround(gun / 2.0, 1);
+       sp->shp_item[I_SHELL] = shells;
+       putship(sp->shp_uid, sp);
 
 
-    guneff = seagun(sp->shp_effic, gun);
-    dam = (int)guneff;
-    if (ntargets > 2)
-       dam /= ntargets / 2;
+       guneff = seagun(sp->shp_effic, gun);
+       dam = (int)guneff;
+       if (ntargets > 2)
+           dam /= ntargets / 2;
 
 
-    if ((mchr[(int)targ->shp_type].m_flags & M_SUB) == 0) {
        pr_beep();
        pr("Kaboom!!! Incoming shells!\n");
        if (sp->shp_own != 0)
        pr_beep();
        pr("Kaboom!!! Incoming shells!\n");
        if (sp->shp_own != 0)
@@ -359,6 +356,13 @@ fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
        shipdamage(targ, dam);
        putship(targ->shp_uid, targ);
     } else {
        shipdamage(targ, dam);
        putship(targ->shp_uid, targ);
     } else {
+       dam = shp_dchrg(sp);
+       putship(sp->shp_uid, sp);
+       if (dam < 0)
+           return;
+       if (ntargets > 2)
+           dam /= ntargets / 2;
+
        pr("\nCAPTAIN!  !!Depth charges!!...\n");
        if (sp->shp_own != 0)
            wu(0, sp->shp_own,
        pr("\nCAPTAIN!  !!Depth charges!!...\n");
        if (sp->shp_own != 0)
            wu(0, sp->shp_own,
index 87e60cb4ee2b422b356e2b73a7f2a4bad4e4d984..bd66b7f631d4bfebbe4e94c40009e9242531c179 100644 (file)
@@ -101,6 +101,29 @@ fort_fire(struct sctstr *sp)
     return (int)fortgun(sp->sct_effic, guns);
 }
 
     return (int)fortgun(sp->sct_effic, guns);
 }
 
+/*
+ * Drop depth-charges from ship SP.
+ * Use ammo, resupply if necessary.
+ * Return damage if the ship drops depth-charges, else -1.
+ */
+int
+shp_dchrg(struct shpstr *sp)
+{
+    int shells;
+
+    if (sp->shp_effic < 60 || (mchr[sp->shp_type].m_flags & M_DCH) == 0)
+       return -1;
+    if (sp->shp_item[I_MILIT] == 0)
+       return -1;
+    shells = sp->shp_item[I_SHELL];
+    shells += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
+                           I_SHELL, 2 - shells);
+    if (shells < 2)
+       return -1;
+    sp->shp_item[I_SHELL] = shells - 2;
+    return (int)seagun(sp->shp_effic, 3);
+}
+
 /*
  * Return effective firing range for range factor RNG at tech TLEV.
  */
 /*
  * Return effective firing range for range factor RNG at tech TLEV.
  */
index aaf00c61ffa5b7ad77c246e3419dc091719c9756..1d82a55238f262479b873e8f8887dfc568c52f15 100644 (file)
@@ -569,19 +569,28 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
                range = roundrange(effrange(sp->shp_frnge, sp->shp_tech));
                if (md > range)
                    continue;
                range = roundrange(effrange(sp->shp_frnge, sp->shp_tech));
                if (md > range)
                    continue;
-               gun = sp->shp_item[I_GUN];
-               gun = MIN(gun, sp->shp_glim);
-               shell = sp->shp_item[I_SHELL];
-               if (shell < gun)
-                   shell += supply_commod(sp->shp_own,
-                                          sp->shp_x, sp->shp_y, I_SHELL,
-                                          gun - shell);
-               gun = MIN(gun, shell);
-               gun = MIN(gun, sp->shp_item[I_MILIT] / 2.0);
-               if (gun == 0)
-                   continue;
-               gun = MAX(gun, 1);
-               dam2 = seagun(sp->shp_effic, gun);
+               if (mission == MI_SINTERDICT) {
+                   dam2 = shp_dchrg(sp);
+                   putship(sp->shp_uid, sp);
+                   if (dam2 < 0)
+                       continue;
+               } else {
+                   gun = sp->shp_item[I_GUN];
+                   gun = MIN(gun, sp->shp_glim);
+                   shell = sp->shp_item[I_SHELL];
+                   if (shell < gun)
+                       shell += supply_commod(sp->shp_own,
+                                              sp->shp_x, sp->shp_y, I_SHELL,
+                                              gun - shell);
+                   gun = MIN(gun, shell);
+                   gun = MIN(gun, sp->shp_item[I_MILIT] / 2.0);
+                   if (gun == 0)
+                       continue;
+                   gun = MAX(gun, 1);
+                   dam2 = seagun(sp->shp_effic, gun);
+                   sp->shp_item[I_SHELL] = shell - gun;
+                   putship(sp->shp_uid, sp);
+               }
                if (range == 0.0)
                    prb = 1.0;
                else
                if (range == 0.0)
                    prb = 1.0;
                else
@@ -600,9 +609,6 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
 
                mpr(victim, "%s %s fires at you at %s\n",
                    cname(sp->shp_own), prship(sp), xyas(x, y, victim));
 
                mpr(victim, "%s %s fires at you at %s\n",
                    cname(sp->shp_own), prship(sp), xyas(x, y, victim));
-
-               sp->shp_item[I_SHELL] = shell - gun;
-               putship(sp->shp_uid, sp);
            }
        } else if (glp->thing->ef_type == EF_PLANE) {
            pcp = glp->cp;
            }
        } else if (glp->thing->ef_type == EF_PLANE) {
            pcp = glp->cp;