Make depth-charging code and documentation match

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().
This commit is contained in:
Markus Armbruster 2008-03-02 11:01:42 +01:00
parent e8595066d1
commit a3ad623b2a
6 changed files with 112 additions and 72 deletions

View 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 shp_dchrg(struct shpstr *);
#endif

View 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))
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.

View file

@ -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,14 +316,31 @@ 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);
@ -348,9 +350,12 @@ multifire(void)
dam = (int)guneff;
shell -= ldround(shots / 2.0, 1);
fship.shp_item[I_SHELL] = shell;
if (opt_NOMOBCOST == 0)
putship(fship.shp_uid, &fship);
}
if (opt_NOMOBCOST == 0) {
fship.shp_mobil = MAX(fship.shp_mobil - 15, -100);
putship(fship.shp_uid, &fship);
}
} else if (attacker == targ_unit) {
if (fland.lnd_own != player->cnum) {
pr("Not your unit!\n");

View file

@ -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,6 +323,7 @@ fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
int gun;
double guneff;
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);
@ -348,7 +346,6 @@ fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
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)
@ -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,

View file

@ -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.
*/

View file

@ -569,6 +569,12 @@ 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;
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];
@ -582,6 +588,9 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
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;