Factor out common fortress fire code into fort_fire()
This takes care of a number of bugs / inconsistencies: * sb() fired support even when there were not enough mil. * Shell resupply bugs: multifire() and quiet_bigdef() resupplied shells before checking all other requirements and could thus get more shells than actually needed. Rename landgun() to fortgun() for consistency.
This commit is contained in:
parent
3812cde100
commit
e8595066d1
8 changed files with 50 additions and 81 deletions
|
@ -41,7 +41,7 @@
|
|||
#include "ship.h"
|
||||
|
||||
double
|
||||
landgun(int effic, int guns)
|
||||
fortgun(int effic, int guns)
|
||||
{
|
||||
double d;
|
||||
double g = MIN(guns, 7);
|
||||
|
@ -77,6 +77,30 @@ landunitgun(int effic, int shots, int guns, int ammo, int shells)
|
|||
return d;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fire from fortress SP.
|
||||
* Use ammo, resupply if necessary.
|
||||
* Return damage if the fortress fires, else -1.
|
||||
*/
|
||||
int
|
||||
fort_fire(struct sctstr *sp)
|
||||
{
|
||||
int guns = sp->sct_item[I_GUN];
|
||||
int shells;
|
||||
|
||||
if (sp->sct_type != SCT_FORTR || sp->sct_effic < FORTEFF)
|
||||
return -1;
|
||||
if (sp->sct_item[I_MILIT] < 5 || guns == 0)
|
||||
return -1;
|
||||
shells = sp->sct_item[I_SHELL];
|
||||
shells += supply_commod(sp->sct_own, sp->sct_x, sp->sct_y,
|
||||
I_SHELL, 1 - shells);
|
||||
if (shells == 0)
|
||||
return -1;
|
||||
sp->sct_item[I_SHELL] = shells - 1;
|
||||
return (int)fortgun(sp->sct_effic, guns);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return effective firing range for range factor RNG at tech TLEV.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue