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
|
@ -459,7 +459,7 @@ extern int lnd_postread(int, void *);
|
||||||
extern int lnd_prewrite(int, void *);
|
extern int lnd_prewrite(int, void *);
|
||||||
/* landgun.c */
|
/* landgun.c */
|
||||||
extern double seagun(int, int);
|
extern double seagun(int, int);
|
||||||
extern double landgun(int, int);
|
extern double fortgun(int, int);
|
||||||
extern double landunitgun(int, int, int, int, int);
|
extern double landunitgun(int, int, int, int, int);
|
||||||
extern double effrange(int, double);
|
extern double effrange(int, double);
|
||||||
extern double torprange(struct shpstr *);
|
extern double torprange(struct shpstr *);
|
||||||
|
|
|
@ -214,4 +214,6 @@ struct sctintrins {
|
||||||
|
|
||||||
extern struct sctintrins intrchr[INT_DEF + 2];
|
extern struct sctintrins intrchr[INT_DEF + 2];
|
||||||
|
|
||||||
|
extern int fort_fire(struct sctstr *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -419,25 +419,20 @@ multifire(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attacker = targ_land;
|
attacker = targ_land;
|
||||||
if ((gun = fsect.sct_item[I_GUN]) == 0) {
|
if (fsect.sct_item[I_GUN] == 0) {
|
||||||
pr("Insufficient arms.\n");
|
pr("Insufficient arms.\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
shell = fsect.sct_item[I_SHELL];
|
|
||||||
if (shell <= 0)
|
|
||||||
shell += supply_commod(fsect.sct_own,
|
|
||||||
fsect.sct_x, fsect.sct_y,
|
|
||||||
I_SHELL, 1);
|
|
||||||
if (shell <= 0) {
|
|
||||||
pr("Klick! ...\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (fsect.sct_item[I_MILIT] < 5) {
|
if (fsect.sct_item[I_MILIT] < 5) {
|
||||||
pr("Not enough military for firing crew.\n");
|
pr("Not enough military for firing crew.\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (gun > 7)
|
dam = fort_fire(&fsect);
|
||||||
gun = 7;
|
putsect(&fsect);
|
||||||
|
if (dam < 0) {
|
||||||
|
pr("Klick! ...\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
range = fortrange(&fsect);
|
range = fortrange(&fsect);
|
||||||
range2 = roundrange(range);
|
range2 = roundrange(range);
|
||||||
pr("range is %d.00 (%.2f)\n", range2, range);
|
pr("range is %d.00 (%.2f)\n", range2, range);
|
||||||
|
@ -445,11 +440,6 @@ multifire(void)
|
||||||
/* Don't tell it's a sub */
|
/* Don't tell it's a sub */
|
||||||
range2 = -1;
|
range2 = -1;
|
||||||
}
|
}
|
||||||
guneff = landgun((int)fsect.sct_effic, gun);
|
|
||||||
dam = (int)guneff;
|
|
||||||
shell--;
|
|
||||||
fsect.sct_item[I_SHELL] = shell;
|
|
||||||
putsect(&fsect);
|
|
||||||
}
|
}
|
||||||
trange = mapdist(x, y, fx, fy);
|
trange = mapdist(x, y, fx, fy);
|
||||||
if (trange > range2) {
|
if (trange > range2) {
|
||||||
|
@ -904,14 +894,9 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
||||||
if (roundrange(erange) < ns.curdist)
|
if (roundrange(erange) < ns.curdist)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
gun = firing.sct_item[I_GUN];
|
dam2 = fort_fire(&firing);
|
||||||
shell = firing.sct_item[I_SHELL];
|
/* no putsect(&firing) because ammo is charged in use_ammo() */
|
||||||
|
if (dam2 < 0)
|
||||||
if (shell < 1)
|
|
||||||
shell += supply_commod(firing.sct_own,
|
|
||||||
firing.sct_x, firing.sct_y,
|
|
||||||
I_SHELL, 1);
|
|
||||||
if (gun == 0 || firing.sct_item[I_MILIT] < 5 || shell == 0)
|
|
||||||
continue;
|
continue;
|
||||||
(*nfiring)++;
|
(*nfiring)++;
|
||||||
fp = malloc(sizeof(struct flist));
|
fp = malloc(sizeof(struct flist));
|
||||||
|
@ -921,9 +906,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
||||||
fp->type = targ_land;
|
fp->type = targ_land;
|
||||||
add_to_fired_queue(&fp->queue, list);
|
add_to_fired_queue(&fp->queue, list);
|
||||||
nreport(firing.sct_own, N_FIRE_BACK, player->cnum, 1);
|
nreport(firing.sct_own, N_FIRE_BACK, player->cnum, 1);
|
||||||
if (gun > 7)
|
dam += dam2;
|
||||||
gun = 7;
|
|
||||||
dam += landgun((int)firing.sct_effic, gun);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ sabo(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
dam = landgun(3 * land.lnd_effic, 7);
|
dam = fortgun(3 * land.lnd_effic, 7);
|
||||||
if (sect.sct_item[I_SHELL] > 20)
|
if (sect.sct_item[I_SHELL] > 20)
|
||||||
dam += seagun(land.lnd_effic,
|
dam += seagun(land.lnd_effic,
|
||||||
random() % (sect.sct_item[I_SHELL] / 10));
|
random() % (sect.sct_item[I_SHELL] / 10));
|
||||||
|
|
|
@ -181,9 +181,7 @@ sb(natid att, natid def, struct sctstr *sp, coord tx, coord ty, int noisy,
|
||||||
{
|
{
|
||||||
int damage;
|
int damage;
|
||||||
natid own;
|
natid own;
|
||||||
int shell;
|
int range, range2;
|
||||||
int range;
|
|
||||||
int range2, gun;
|
|
||||||
|
|
||||||
own = sp->sct_own;
|
own = sp->sct_own;
|
||||||
if (own == 0)
|
if (own == 0)
|
||||||
|
@ -194,18 +192,10 @@ sb(natid att, natid def, struct sctstr *sp, coord tx, coord ty, int noisy,
|
||||||
range2 = mapdist(sp->sct_x, sp->sct_y, tx, ty);
|
range2 = mapdist(sp->sct_x, sp->sct_y, tx, ty);
|
||||||
if (range < range2)
|
if (range < range2)
|
||||||
return 0;
|
return 0;
|
||||||
gun = sp->sct_item[I_GUN];
|
damage = fort_fire(sp);
|
||||||
if (gun == 0)
|
|
||||||
return 0;
|
|
||||||
shell = sp->sct_item[I_SHELL];
|
|
||||||
if (shell <= 0)
|
|
||||||
shell += supply_commod(sp->sct_own, sp->sct_x, sp->sct_y,
|
|
||||||
I_SHELL, 1);
|
|
||||||
if (shell <= 0)
|
|
||||||
return 0;
|
|
||||||
sp->sct_item[I_SHELL] = shell - 1;
|
|
||||||
putsect(sp);
|
putsect(sp);
|
||||||
damage = landgun((int)sp->sct_effic, gun);
|
if (damage < 0)
|
||||||
|
return 0;
|
||||||
if (sp->sct_own != def)
|
if (sp->sct_own != def)
|
||||||
wu(0, sp->sct_own,
|
wu(0, sp->sct_own,
|
||||||
"%s fired on %s in %s in defense of %s, doing %d damage!\n",
|
"%s fired on %s in %s in defense of %s, doing %d damage!\n",
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
|
|
||||||
double
|
double
|
||||||
landgun(int effic, int guns)
|
fortgun(int effic, int guns)
|
||||||
{
|
{
|
||||||
double d;
|
double d;
|
||||||
double g = MIN(guns, 7);
|
double g = MIN(guns, 7);
|
||||||
|
@ -77,6 +77,30 @@ landunitgun(int effic, int shots, int guns, int ammo, int shells)
|
||||||
return d;
|
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.
|
* Return effective firing range for range factor RNG at tech TLEV.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -846,28 +846,14 @@ lnd_fort_interdiction(struct emp_qelem *list,
|
||||||
continue;
|
continue;
|
||||||
if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
|
if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
|
||||||
continue;
|
continue;
|
||||||
gun = fsect.sct_item[I_GUN];
|
|
||||||
if (gun < 1)
|
|
||||||
continue;
|
|
||||||
range = roundrange(fortrange(&fsect));
|
range = roundrange(fortrange(&fsect));
|
||||||
trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
|
trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
|
||||||
if (trange > range)
|
if (trange > range)
|
||||||
continue;
|
continue;
|
||||||
if (fsect.sct_item[I_MILIT] < 5)
|
dam = fort_fire(&fsect);
|
||||||
continue;
|
|
||||||
shell = fsect.sct_item[I_SHELL];
|
|
||||||
if (shell < 1)
|
|
||||||
shell += supply_commod(fsect.sct_own, fsect.sct_x, fsect.sct_y,
|
|
||||||
I_SHELL, 1);
|
|
||||||
if (shell < 1)
|
|
||||||
continue;
|
|
||||||
shell--;
|
|
||||||
fsect.sct_item[I_SHELL] = shell;
|
|
||||||
putsect(&fsect);
|
putsect(&fsect);
|
||||||
if (gun > 7)
|
if (dam < 0)
|
||||||
gun = 7;
|
continue;
|
||||||
guneff = landgun((int)fsect.sct_effic, gun);
|
|
||||||
dam = (int)guneff;
|
|
||||||
totdam += dam;
|
totdam += dam;
|
||||||
mpr(victim, "Incoming fire does %d damage!\n", dam);
|
mpr(victim, "Incoming fire does %d damage!\n", dam);
|
||||||
wu(0, fsect.sct_own,
|
wu(0, fsect.sct_own,
|
||||||
|
|
|
@ -587,8 +587,6 @@ shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
struct sctstr fsect;
|
struct sctstr fsect;
|
||||||
int trange, range;
|
int trange, range;
|
||||||
double guneff;
|
|
||||||
int shell, gun;
|
|
||||||
int dam;
|
int dam;
|
||||||
int totdam = 0;
|
int totdam = 0;
|
||||||
signed char notified[MAXNOC];
|
signed char notified[MAXNOC];
|
||||||
|
@ -625,28 +623,14 @@ shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
|
||||||
while (nxtsct(&ns, &fsect)) {
|
while (nxtsct(&ns, &fsect)) {
|
||||||
if (!notified[fsect.sct_own])
|
if (!notified[fsect.sct_own])
|
||||||
continue;
|
continue;
|
||||||
gun = fsect.sct_item[I_GUN];
|
|
||||||
if (gun < 1)
|
|
||||||
continue;
|
|
||||||
range = roundrange(fortrange(&fsect));
|
range = roundrange(fortrange(&fsect));
|
||||||
trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
|
trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
|
||||||
if (trange > range)
|
if (trange > range)
|
||||||
continue;
|
continue;
|
||||||
if (fsect.sct_item[I_MILIT] < 5)
|
dam = fort_fire(&fsect);
|
||||||
continue;
|
|
||||||
shell = fsect.sct_item[I_SHELL];
|
|
||||||
if (shell < 1)
|
|
||||||
shell += supply_commod(fsect.sct_own, fsect.sct_x, fsect.sct_y,
|
|
||||||
I_SHELL, 1);
|
|
||||||
if (shell < 1)
|
|
||||||
continue;
|
|
||||||
shell--;
|
|
||||||
fsect.sct_item[I_SHELL] = shell;
|
|
||||||
putsect(&fsect);
|
putsect(&fsect);
|
||||||
if (gun > 7)
|
if (dam < 0)
|
||||||
gun = 7;
|
continue;
|
||||||
guneff = landgun((int)fsect.sct_effic, gun);
|
|
||||||
dam = (int)guneff;
|
|
||||||
totdam += dam;
|
totdam += dam;
|
||||||
mpr(victim, "Incoming fire does %d damage!\n", dam);
|
mpr(victim, "Incoming fire does %d damage!\n", dam);
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue