Factor out common ship gun fire code into shp_fire()
This takes care of a number of bugs / inconsistencies: * Ships with zero firing range could return fire and fire support, but not fire actively or interdict. Fix by testing for gun limit instead in multifire() and mission(). No ships in the stock game are affected. * Required gun crew was inconsistent: multifire() let N military fire max(1,floor(N/2)) guns for active fire. Ditto perform_mission() for interdiction. quiet_bigdef() let them fire N guns for returning gun fire. Ditto sd() for firing support and firing at boarding parties. fire_dchrg() let them fire floor(N/2) for returning fire to torpedoes. Unify to let N military fire floor((N+1)/2) guns. * Shell use was inconsistent: sd() and perform_mission() used one shell per gun, everything else one per two guns. Unify to one shell per two guns. * Shell resupply bugs: multifire() got two shells regardless of actual ammo use. quiet_bigdef() got one shell (but use_ammo() uses only one, which is a bug). sd() and perform_mission() resupplied before checking all other requirements and could thus get more shells than actually needed.
This commit is contained in:
parent
a3ad623b2a
commit
22c6fd8bf6
7 changed files with 65 additions and 109 deletions
|
@ -319,30 +319,12 @@ static void
|
|||
fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
|
||||
{
|
||||
int dam;
|
||||
int shells;
|
||||
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);
|
||||
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;
|
||||
dam = shp_fire(sp);
|
||||
putship(sp->shp_uid, sp);
|
||||
|
||||
guneff = seagun(sp->shp_effic, gun);
|
||||
dam = (int)guneff;
|
||||
if (dam < 0)
|
||||
return;
|
||||
if (ntargets > 2)
|
||||
dam /= ntargets / 2;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue