(sd, shp_missile_defense): Replace getvec() by direct, read-only item

access.  This is correct, because the old code doesn't use the copy
after it changes the original in the unit structure.
(dd): Remove call of getvec() that has no effect.
This commit is contained in:
Markus Armbruster 2004-03-10 13:16:46 +00:00
parent 364f452a3c
commit 522f1cdf9a
2 changed files with 17 additions and 24 deletions

View file

@ -73,7 +73,7 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
double eff; double eff;
struct shpstr ship; struct shpstr ship;
struct nstr_item ni; struct nstr_item ni;
int vec[I_MAX + 1]; int shell;
int dam, rel, rel2; int dam, rel, rel2;
if (own == 0) if (own == 0)
@ -102,17 +102,15 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
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 (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 3) shell = ship.shp_item[I_SHELL];
continue; if (shell < ship.shp_glim)
if (vec[I_SHELL] < ship.shp_glim) shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
vec[I_SHELL] += supply_commod(ship.shp_own, ship.shp_x, I_SHELL, shell - ship.shp_glim);
ship.shp_y, I_SHELL, nshot = min(min(ship.shp_item[I_GUN], shell), ship.shp_item[I_MILIT]);
vec[I_SHELL] - ship.shp_glim);
nshot = min(min(vec[I_GUN], vec[I_SHELL]), vec[I_MILIT]);
nshot = min(nshot, ship.shp_glim); nshot = min(nshot, ship.shp_glim);
if (nshot <= 0) if (nshot <= 0)
continue; continue;
ship.shp_item[I_SHELL] = vec[I_SHELL] - nshot; ship.shp_item[I_SHELL] = shell - nshot;
putship(ship.shp_uid, &ship); putship(ship.shp_uid, &ship);
if (defending) if (defending)
nreport(ship.shp_own, N_FIRE_BACK, att, 1); nreport(ship.shp_own, N_FIRE_BACK, att, 1);
@ -177,7 +175,6 @@ dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
double range; double range;
struct sctstr firing; struct sctstr firing;
struct nstr_sect ns; struct nstr_sect ns;
int vec[I_MAX + 1];
if (opt_NO_FORT_FIRE) /* Forts can't fire! */ if (opt_NO_FORT_FIRE) /* Forts can't fire! */
return 0; return 0;
@ -200,8 +197,6 @@ dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
if ((firing.sct_own != def_own) && if ((firing.sct_own != def_own) &&
((rel != ALLIED) || (rel2 != AT_WAR))) ((rel != ALLIED) || (rel2 != AT_WAR)))
continue; continue;
if (getvec(VT_ITEM, vec, (caddr_t)&firing, EF_SECTOR) < 0)
continue;
range = tfactfire(def_own, 7.0); range = tfactfire(def_own, 7.0);
if (firing.sct_effic > 59) if (firing.sct_effic > 59)

View file

@ -927,7 +927,7 @@ shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
struct nstr_item ni; struct nstr_item ni;
struct shpstr ship; struct shpstr ship;
int hitchance; int hitchance;
int vec[I_MAX + 1]; int shell;
double gun, eff, teff; double gun, eff, teff;
snxtitem_dist(&ni, EF_SHIP, dx, dy, 1); snxtitem_dist(&ni, EF_SHIP, dx, dy, 1);
@ -945,22 +945,20 @@ shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
if (ship.shp_effic < 60) if (ship.shp_effic < 60)
continue; continue;
if (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 0) shell = ship.shp_item[I_SHELL];
if (ship.shp_item[I_MILIT] < 1) /* do we have mil? */
continue; continue;
if (vec[I_MILIT] < 1) /* do we have mil? */ if (shell < 2) { /* do we need shells */
continue; shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
if (vec[I_SHELL] < 2) { /* do we need shells */ I_SHELL, 2);
vec[I_SHELL] += supply_commod(ship.shp_own, if (shell < 2)
ship.shp_x, ship.shp_y,
I_SHELL, 2);
if (vec[I_SHELL] < 2)
continue; continue;
} }
if (vec[I_GUN] < 1) /* we need at least 1 gun */ if (ship.shp_item[I_GUN] < 1) /* we need at least 1 gun */
continue; continue;
/* now calculate the odds */ /* now calculate the odds */
gun = ((double)min(vec[I_GUN], ship.shp_glim)); gun = min(ship.shp_item[I_GUN], ship.shp_glim);
eff = (double)ship.shp_effic / 100.0; eff = (double)ship.shp_effic / 100.0;
teff = teff =
(((double)ship.shp_tech) / (((double)ship.shp_tech) + 200.0)); (((double)ship.shp_tech) / (((double)ship.shp_tech) + 200.0));
@ -977,7 +975,7 @@ shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
ship.shp_uid); ship.shp_uid);
mpr(ship.shp_own, "%d%% hitchance...", hitchance); mpr(ship.shp_own, "%d%% hitchance...", hitchance);
/* use ammo */ /* use ammo */
ship.shp_item[I_SHELL] = vec[I_SHELL] - 2; ship.shp_item[I_SHELL] = shell - 2;
putship(ship.shp_uid, &ship); putship(ship.shp_uid, &ship);
if (roll(100) <= hitchance) { if (roll(100) <= hitchance) {