Simplify how fire command encodes lists of firing objects
Use file type rather than enum targ_type for struct flist member type. Clean up natid vs. int sloppiness while there.
This commit is contained in:
parent
d741c45560
commit
292f92f705
1 changed files with 20 additions and 25 deletions
|
@ -44,11 +44,11 @@ enum targ_type {
|
||||||
|
|
||||||
struct flist {
|
struct flist {
|
||||||
struct emp_qelem queue; /* list of fired things */
|
struct emp_qelem queue; /* list of fired things */
|
||||||
int type; /* ship? otherwise sector */
|
short type; /* EF_SECTOR, EF_SHIP or EF_LAND */
|
||||||
int uid; /* ship uid */
|
short uid; /* ship or land unit uid */
|
||||||
coord x, y; /* sector coords */
|
coord x, y; /* sector coords */
|
||||||
int defdam; /* damage defenders did */
|
int defdam; /* damage defenders did */
|
||||||
int victim; /* who I was shooting at */
|
natid victim;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void add_to_fired_queue(struct emp_qelem *, struct emp_qelem *);
|
static void add_to_fired_queue(struct emp_qelem *, struct emp_qelem *);
|
||||||
|
@ -605,17 +605,10 @@ defend(struct emp_qelem *al, struct emp_qelem *dl,
|
||||||
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 (attgp->ef_type) {
|
fp->type = attgp->ef_type;
|
||||||
case EF_SECTOR:
|
fp->uid = attgp->uid;
|
||||||
fp->x = attgp->x;
|
fp->x = attgp->x;
|
||||||
fp->y = attgp->y;
|
fp->y = attgp->y;
|
||||||
fp->type = targ_land;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fp->type = targ_ship;
|
|
||||||
fp->uid = attgp->uid;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
emp_insque(&fp->queue, al);
|
emp_insque(&fp->queue, al);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,7 +619,8 @@ static void
|
||||||
do_defdam(struct emp_qelem *list, double odds)
|
do_defdam(struct emp_qelem *list, double odds)
|
||||||
{
|
{
|
||||||
|
|
||||||
int dam, vict, first = 1;
|
int dam, first = 1;
|
||||||
|
natid vict;
|
||||||
struct flist *fp;
|
struct flist *fp;
|
||||||
struct shpstr ship;
|
struct shpstr ship;
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
|
@ -635,7 +629,7 @@ do_defdam(struct emp_qelem *list, double odds)
|
||||||
for (qp = list->q_forw; qp != list; qp = next) {
|
for (qp = list->q_forw; qp != list; qp = next) {
|
||||||
next = qp->q_forw;
|
next = qp->q_forw;
|
||||||
fp = (struct flist *)qp;
|
fp = (struct flist *)qp;
|
||||||
if (fp->type == targ_ship) {
|
if (fp->type == EF_SHIP) {
|
||||||
if (!getship(fp->uid, &ship) || !ship.shp_own)
|
if (!getship(fp->uid, &ship) || !ship.shp_own)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -646,7 +640,7 @@ do_defdam(struct emp_qelem *list, double odds)
|
||||||
}
|
}
|
||||||
dam = odds * fp->defdam;
|
dam = odds * fp->defdam;
|
||||||
|
|
||||||
if (fp->type == targ_ship) {
|
if (fp->type == EF_SHIP) {
|
||||||
vict = fp->victim;
|
vict = fp->victim;
|
||||||
pr("Return fire hit %s in %s for %d damage.\n",
|
pr("Return fire hit %s in %s for %d damage.\n",
|
||||||
prship(&ship),
|
prship(&ship),
|
||||||
|
@ -658,6 +652,7 @@ do_defdam(struct emp_qelem *list, double odds)
|
||||||
shipdamage(&ship, dam);
|
shipdamage(&ship, dam);
|
||||||
putship(ship.shp_uid, &ship);
|
putship(ship.shp_uid, &ship);
|
||||||
} else {
|
} else {
|
||||||
|
CANT_HAPPEN(fp->type != EF_SECTOR);
|
||||||
getsect(fp->x, fp->y, §);
|
getsect(fp->x, fp->y, §);
|
||||||
vict = fp->victim;
|
vict = fp->victim;
|
||||||
pr("Return fire hit sector %s for %d damage.\n",
|
pr("Return fire hit sector %s for %d damage.\n",
|
||||||
|
@ -729,7 +724,7 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
|
||||||
(*nfiring)++;
|
(*nfiring)++;
|
||||||
fp = malloc(sizeof(struct flist));
|
fp = malloc(sizeof(struct flist));
|
||||||
memset(fp, 0, sizeof(struct flist));
|
memset(fp, 0, sizeof(struct flist));
|
||||||
fp->type = targ_ship;
|
fp->type = EF_SHIP;
|
||||||
fp->uid = ship.shp_uid;
|
fp->uid = ship.shp_uid;
|
||||||
add_to_fired_queue(&fp->queue, list);
|
add_to_fired_queue(&fp->queue, list);
|
||||||
dam += dam2;
|
dam += dam2;
|
||||||
|
@ -760,7 +755,7 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
|
||||||
(*nfiring)++;
|
(*nfiring)++;
|
||||||
fp = malloc(sizeof(struct flist));
|
fp = malloc(sizeof(struct flist));
|
||||||
memset(fp, 0, sizeof(struct flist));
|
memset(fp, 0, sizeof(struct flist));
|
||||||
fp->type = targ_unit;
|
fp->type = EF_LAND;
|
||||||
fp->uid = land.lnd_uid;
|
fp->uid = land.lnd_uid;
|
||||||
add_to_fired_queue(&fp->queue, list);
|
add_to_fired_queue(&fp->queue, list);
|
||||||
nreport(land.lnd_own, N_FIRE_BACK, player->cnum, 1);
|
nreport(land.lnd_own, N_FIRE_BACK, player->cnum, 1);
|
||||||
|
@ -801,7 +796,7 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
|
||||||
memset(fp, 0, sizeof(struct flist));
|
memset(fp, 0, sizeof(struct flist));
|
||||||
fp->x = firing.sct_x;
|
fp->x = firing.sct_x;
|
||||||
fp->y = firing.sct_y;
|
fp->y = firing.sct_y;
|
||||||
fp->type = targ_land;
|
fp->type = EF_SECTOR;
|
||||||
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);
|
||||||
dam += dam2;
|
dam += dam2;
|
||||||
|
@ -826,7 +821,7 @@ use_ammo(struct emp_qelem *list)
|
||||||
for (qp = list->q_forw; qp != list; qp = next) {
|
for (qp = list->q_forw; qp != list; qp = next) {
|
||||||
next = qp->q_forw;
|
next = qp->q_forw;
|
||||||
fp = (struct flist *)qp;
|
fp = (struct flist *)qp;
|
||||||
if (fp->type == targ_ship) {
|
if (fp->type == EF_SHIP) {
|
||||||
getship(fp->uid, &ship);
|
getship(fp->uid, &ship);
|
||||||
item = ship.shp_item;
|
item = ship.shp_item;
|
||||||
if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
|
if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
|
||||||
|
@ -839,7 +834,7 @@ use_ammo(struct emp_qelem *list)
|
||||||
/* mob cost = 1/2 a sect's mob */
|
/* mob cost = 1/2 a sect's mob */
|
||||||
ship.shp_mobil -= shp_mobcost(&ship) / 2.0;
|
ship.shp_mobil -= shp_mobcost(&ship) / 2.0;
|
||||||
}
|
}
|
||||||
} else if (fp->type == targ_land) {
|
} else if (fp->type == EF_SECTOR) {
|
||||||
getsect(fp->x, fp->y, §);
|
getsect(fp->x, fp->y, §);
|
||||||
item = sect.sct_item;
|
item = sect.sct_item;
|
||||||
} else {
|
} else {
|
||||||
|
@ -851,9 +846,9 @@ use_ammo(struct emp_qelem *list)
|
||||||
if (shell < 0)
|
if (shell < 0)
|
||||||
shell = 0;
|
shell = 0;
|
||||||
item[I_SHELL] = shell;
|
item[I_SHELL] = shell;
|
||||||
if (fp->type == targ_ship)
|
if (fp->type == EF_SHIP)
|
||||||
putship(ship.shp_uid, &ship);
|
putship(ship.shp_uid, &ship);
|
||||||
else if (fp->type == targ_land)
|
else if (fp->type == EF_SECTOR)
|
||||||
putsect(§);
|
putsect(§);
|
||||||
else
|
else
|
||||||
putland(land.lnd_uid, &land);
|
putland(land.lnd_uid, &land);
|
||||||
|
@ -874,7 +869,7 @@ add_to_fired_queue(struct emp_qelem *elem, struct emp_qelem *list)
|
||||||
/* Don't put them on the list if they're already there */
|
/* Don't put them on the list if they're already there */
|
||||||
for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
|
for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
|
||||||
fp = (struct flist *)qp;
|
fp = (struct flist *)qp;
|
||||||
if (fp->type == targ_land
|
if (fp->type == EF_SECTOR
|
||||||
? fp->x == ep->x && fp->y == ep->y
|
? fp->x == ep->x && fp->y == ep->y
|
||||||
: fp->uid == ep->uid) {
|
: fp->uid == ep->uid) {
|
||||||
free(ep);
|
free(ep);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue