(quiet_bigdef): Work directly on item arrays instead of copies made by

getvec().  This is safe, because the old code made single copies and
always flushed them back into the unit structures before flushing
those, in use_ammo(), or discarded both the copy and the unit
structure.
This commit is contained in:
Markus Armbruster 2004-03-10 12:52:24 +00:00
parent 7a59ab4784
commit 364f452a3c

View file

@ -775,13 +775,12 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
struct shpstr ship; struct shpstr ship;
struct lndstr land; struct lndstr land;
struct nstr_item ni; struct nstr_item ni;
int vec[I_MAX + 1];
int dam, dam2, rel, rel2; int dam, dam2, rel, rel2;
double tech; double tech;
struct sctstr firing; struct sctstr firing;
struct nstr_sect ns; struct nstr_sect ns;
struct flist *fp; struct flist *fp;
int gun; int gun, shell;
if (own == 0) if (own == 0)
return 0; return 0;
@ -804,20 +803,20 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
continue; continue;
if (ship.shp_effic < 60) if (ship.shp_effic < 60)
continue; continue;
if (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 0)
continue;
if (vec[I_MILIT] < 1) gun = ship.shp_item[I_GUN];
shell = ship.shp_item[I_SHELL];
if (ship.shp_item[I_MILIT] < 1)
continue; continue;
if (mchr[(int)ship.shp_type].m_flags & M_SUB) { if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
if (vec[I_SHELL] < 3) if (shell < 3)
vec[I_SHELL] += supply_commod(ship.shp_own, shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
ship.shp_x, ship.shp_y, I_SHELL, 3 - shell);
I_SHELL, 3 - vec[I_SHELL]); if (shell < 3)
if (vec[I_SHELL] < 3)
continue; continue;
if (vec[I_GUN] < 1) if (gun < 1)
continue; continue;
/* /*
if (ship.shp_mobil <= 0) if (ship.shp_mobil <= 0)
@ -854,14 +853,13 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
if (range < ni.curdist) if (range < ni.curdist)
continue; continue;
/* must have gun, shell, and milit to fire */ /* must have gun, shell, and milit to fire */
if (vec[I_SHELL] < 1) if (shell < 1)
vec[I_SHELL] += supply_commod(ship.shp_own, shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
ship.shp_x, ship.shp_y, I_SHELL, 1);
I_SHELL, 1);
/* only need 1 shell, so don't check that */ /* only need 1 shell, so don't check that */
if (vec[I_SHELL] < 1) if (shell < 1)
continue; continue;
nshot = min(vec[I_GUN], vec[I_MILIT]); nshot = min(gun, ship.shp_item[I_MILIT]);
nshot = min(nshot, ship.shp_glim); nshot = min(nshot, ship.shp_glim);
if (nshot == 0) if (nshot == 0)
continue; continue;
@ -909,14 +907,14 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
if (!has_supply(&land)) if (!has_supply(&land))
continue; continue;
if (getvec(VT_ITEM, vec, (caddr_t)&land, EF_LAND) < 0) gun = land.lnd_item[I_GUN];
shell = land.lnd_item[I_SHELL];
if (land.lnd_item[I_MILIT] == 0 || shell == 0 || gun == 0)
continue; continue;
if (vec[I_MILIT] == 0 || vec[I_SHELL] == 0 || vec[I_GUN] == 0) dam2 = (int)landunitgun(land.lnd_effic, land.lnd_dam, gun,
continue; land.lnd_ammo, shell);
dam2 = (int)landunitgun(land.lnd_effic, land.lnd_dam, vec[I_GUN],
land.lnd_ammo, vec[I_SHELL]);
(*nfiring)++; (*nfiring)++;
fp = (struct flist *)malloc(sizeof(struct flist)); fp = (struct flist *)malloc(sizeof(struct flist));
@ -961,13 +959,15 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
range = (double)roundrange(range); range = (double)roundrange(range);
if (range < ns.curdist) if (range < ns.curdist)
continue; continue;
if (getvec(VT_ITEM, vec, (caddr_t)&firing, EF_SECTOR) < 0)
continue; gun = firing.sct_item[I_GUN];
if (vec[I_SHELL] < 1) shell = firing.sct_item[I_SHELL];
vec[I_SHELL] += supply_commod(firing.sct_own,
firing.sct_x, firing.sct_y, if (shell < 1)
I_SHELL, 1); shell += supply_commod(firing.sct_own,
if (vec[I_GUN] == 0 || vec[I_MILIT] < 5 || vec[I_SHELL] == 0) 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 = (struct flist *)malloc(sizeof(struct flist)); fp = (struct flist *)malloc(sizeof(struct flist));
@ -977,7 +977,6 @@ 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);
gun = vec[I_GUN];
if (gun > 7) if (gun > 7)
gun = 7; gun = 7;
dam += landgun((int)firing.sct_effic, gun); dam += landgun((int)firing.sct_effic, gun);