diff --git a/include/ship.h b/include/ship.h index 42278132..99f945de 100644 --- a/include/ship.h +++ b/include/ship.h @@ -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 shp_dchrg(struct shpstr *); + #endif diff --git a/info/Damage.t b/info/Damage.t index ca2cc8f1..be509228 100644 --- a/info/Damage.t +++ b/info/Damage.t @@ -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)) - 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. diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index b4ff03b7..632847f3 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -308,21 +308,6 @@ multifire(void) 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); @@ -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); - if (target == targ_sub) { - if ((mchr[(int)fship.shp_type].m_flags & M_DCH) == 0) { - /* Don't tell it's a sub */ - range2 = -1; - } else if (shell < 2) { + 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; + 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; + } + 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); - 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"); diff --git a/src/lib/commands/torp.c b/src/lib/commands/torp.c index efec0d8e..9a10dbf5 100644 --- a/src/lib/commands/torp.c +++ b/src/lib/commands/torp.c @@ -240,9 +240,6 @@ anti_torp(int f, int ntorping, int vshipown) continue; if (dd.shp_own != vshipown) continue; - if (dd.shp_effic < 60) - continue; - if (!canshoot(&dd, &sub)) continue; @@ -326,29 +323,29 @@ fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets) 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); - - 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; - - /* 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; - 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); + + 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); + + guneff = seagun(sp->shp_effic, gun); + dam = (int)guneff; + if (ntargets > 2) + dam /= ntargets / 2; + 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 { + 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, diff --git a/src/lib/subs/landgun.c b/src/lib/subs/landgun.c index 87e60cb4..bd66b7f6 100644 --- a/src/lib/subs/landgun.c +++ b/src/lib/subs/landgun.c @@ -101,6 +101,29 @@ fort_fire(struct sctstr *sp) 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. */ diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index aaf00c61..1d82a552 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -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; - 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 @@ -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)); - - sp->shp_item[I_SHELL] = shell - gun; - putship(sp->shp_uid, sp); } } else if (glp->thing->ef_type == EF_PLANE) { pcp = glp->cp;