Simplify how fire command passes attacker to defend()
Pass attacker empobj instead of attacker's targ_type, sector (used for targ_land), ship (used otherwise) and coordinates (used in either case).
This commit is contained in:
parent
7b2574c167
commit
7f4a5d0630
1 changed files with 18 additions and 28 deletions
|
@ -52,12 +52,8 @@ struct flist {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void add_to_fired_queue(struct emp_qelem *, struct emp_qelem *);
|
static void add_to_fired_queue(struct emp_qelem *, struct emp_qelem *);
|
||||||
static int defend(struct emp_qelem *al,
|
static int defend(struct emp_qelem *, struct emp_qelem *,
|
||||||
struct emp_qelem *dl,
|
struct empobj *, natid, int *);
|
||||||
natid,
|
|
||||||
enum targ_type attacker,
|
|
||||||
struct sctstr *fsect,
|
|
||||||
struct shpstr *fship, int fx, int fy, int *nd);
|
|
||||||
static void do_defdam(struct emp_qelem *, double);
|
static void do_defdam(struct emp_qelem *, double);
|
||||||
static int quiet_bigdef(int, struct emp_qelem *, natid, natid, coord,
|
static int quiet_bigdef(int, struct emp_qelem *, natid, natid, coord,
|
||||||
coord, int *);
|
coord, int *);
|
||||||
|
@ -93,6 +89,7 @@ multifire(void)
|
||||||
struct natstr *natp;
|
struct natstr *natp;
|
||||||
struct nstr_item nbst;
|
struct nstr_item nbst;
|
||||||
int type;
|
int type;
|
||||||
|
struct empobj *attgp;
|
||||||
char *p;
|
char *p;
|
||||||
int nfiring = 0;
|
int nfiring = 0;
|
||||||
int ndefending = 0;
|
int ndefending = 0;
|
||||||
|
@ -550,13 +547,13 @@ multifire(void)
|
||||||
just continue on, since there is no defender. */
|
just continue on, since there is no defender. */
|
||||||
if (target == targ_bogus)
|
if (target == targ_bogus)
|
||||||
continue;
|
continue;
|
||||||
|
attgp = &item.gen;
|
||||||
if (attacker == targ_unit) {
|
if (attacker == targ_unit) {
|
||||||
attacker = targ_land;
|
attacker = targ_land;
|
||||||
getsect(fland.lnd_x, fland.lnd_y, &fsect);
|
getsect(fland.lnd_x, fland.lnd_y, &fsect);
|
||||||
|
attgp = (struct empobj *)&fsect;
|
||||||
}
|
}
|
||||||
totaldefdam =
|
totaldefdam = defend(&fired, &defended, attgp, vict, &ndefending);
|
||||||
defend(&fired, &defended, vict, attacker,
|
|
||||||
&fsect, &fship, fx, fy, &ndefending);
|
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case targ_land:
|
case targ_land:
|
||||||
putsect(&vsect);
|
putsect(&vsect);
|
||||||
|
@ -593,38 +590,32 @@ multifire(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
defend(struct emp_qelem *al, struct emp_qelem *dl, natid vict,
|
defend(struct emp_qelem *al, struct emp_qelem *dl,
|
||||||
enum targ_type attacker, struct sctstr *fsect,
|
struct empobj *attgp, natid vict, int *nd)
|
||||||
struct shpstr *fship, int fx, int fy, int *nd)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
int dam;
|
int dam;
|
||||||
int nfiring = 0;
|
int nfiring = 0;
|
||||||
struct flist *fp;
|
struct flist *fp;
|
||||||
int aown;
|
|
||||||
|
|
||||||
if (attacker == targ_land)
|
dam = quiet_bigdef(attgp->ef_type, dl, vict,
|
||||||
aown = fsect->sct_own;
|
attgp->own, attgp->x, attgp->y, &nfiring);
|
||||||
else
|
if (dam) {
|
||||||
aown = fship->shp_own;
|
|
||||||
|
|
||||||
if (0 !=
|
|
||||||
(dam = quiet_bigdef(attacker, dl, vict, aown, fx, fy, &nfiring))) {
|
|
||||||
if (nfiring > *nd)
|
if (nfiring > *nd)
|
||||||
*nd = nfiring;
|
*nd = nfiring;
|
||||||
fp = malloc(sizeof(struct flist));
|
fp = malloc(sizeof(struct flist));
|
||||||
memset(fp, 0, sizeof(struct flist));
|
memset(fp, 0, sizeof(struct flist));
|
||||||
fp->defdam = dam;
|
fp->defdam = dam;
|
||||||
fp->victim = vict;
|
fp->victim = vict;
|
||||||
switch (attacker) {
|
switch (attgp->ef_type) {
|
||||||
case targ_land:
|
case EF_SECTOR:
|
||||||
fp->x = fsect->sct_x;
|
fp->x = attgp->x;
|
||||||
fp->y = fsect->sct_y;
|
fp->y = attgp->y;
|
||||||
fp->type = targ_land;
|
fp->type = targ_land;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fp->type = targ_ship;
|
fp->type = targ_ship;
|
||||||
fp->uid = fship->shp_uid;
|
fp->uid = attgp->uid;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
emp_insque(&fp->queue, al);
|
emp_insque(&fp->queue, al);
|
||||||
|
@ -685,7 +676,7 @@ do_defdam(struct emp_qelem *list, double odds)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
|
||||||
coord ax, coord ay, int *nfiring)
|
coord ax, coord ay, int *nfiring)
|
||||||
{
|
{
|
||||||
double erange;
|
double erange;
|
||||||
|
@ -705,8 +696,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
|
||||||
if (ship.shp_own == 0)
|
if (ship.shp_own == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((mchr[(int)ship.shp_type].m_flags & M_SUB) &&
|
if ((mchr[ship.shp_type].m_flags & M_SUB) && type != EF_SHIP)
|
||||||
(attacker == targ_land))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rel = getrel(getnatp(ship.shp_own), own);
|
rel = getrel(getnatp(ship.shp_own), own);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue