Factor out common land unit fire code into lnd_fire()

This takes care of a number of bugs / inconsistencies:

* Resupply before fire: fire command did not require unit to be in
  supply, and resupplied shells.  Everywhere else (return fire,
  support and interdiction) the land unit had to be in supply after
  resupply of everything.  Unify not to resupply anything and not to
  require being in supply.  This is consistent with ships and sectors.

* Resupply after fire: fire command resupplied shells after active
  fire.  Unify not to do that.  This is consistent with ships and
  sectors.

* When a land unit returned fire to multiple attackers, quiet_bigdef()
  charged it ammo for each one.  Finally, it was charged one shell
  more by use_ammo().  Except only the first land unit got charged
  there in fact, because buggy add_to_fired_queue() entered only the
  first land unit into the defender list.  Fix add_to_fired_queue()
  and change quiet_bigdef() not to charge ammo, just like for ships
  and sectors.  This charges only one shell instead of the true ammo
  use, which is wrong, but consistent with ships.

* lnd_support() tallied support damage unrounded.  Unify to round
  before tally.
This commit is contained in:
Markus Armbruster 2008-03-03 08:29:52 +01:00
parent 652afa12de
commit f6c87d21ff
6 changed files with 92 additions and 124 deletions

View file

@ -1128,37 +1128,21 @@ lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
struct nstr_item ni;
struct lndstr land;
int rel, rel2;
double dam = 0.0;
int dam, dam2;
int dist;
int shell;
int gun;
int range;
dam = 0;
snxtitem_all(&ni, EF_LAND);
while (nxtitem(&ni, &land)) {
if (land.lnd_dam == 0)
continue;
if ((land.lnd_x == x) && (land.lnd_y == y))
continue;
if (land.lnd_ship >= 0)
continue;
if (land.lnd_land >= 0)
continue;
if (land.lnd_effic < LAND_MINFIREEFF)
continue;
/* Do we have mil? */
if (land.lnd_item[I_MILIT] <= 0)
continue;
rel = getrel(getnatp(land.lnd_own), attacker);
rel2 = getrel(getnatp(land.lnd_own), victim);
if ((land.lnd_own != attacker) &&
((rel != ALLIED) || (rel2 != AT_WAR)))
continue;
/* do we have supplies? */
if (!has_supply(&land))
continue;
/* are we in range? */
dist = mapdist(land.lnd_x, land.lnd_y, x, y);
@ -1166,31 +1150,26 @@ lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
if (dist > range)
continue;
shell = land.lnd_item[I_SHELL];
gun = land.lnd_item[I_GUN];
if (shell == 0 || gun == 0)
dam2 = lnd_fire(&land);
putland(land.lnd_uid, &land);
if (dam2 < 0)
continue;
use_supply(&land);
if (defending)
nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
else
nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
if (roll(100) < land.lnd_acc) {
dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
land.lnd_ammo, shell) / 2;
} else {
dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
land.lnd_ammo, shell);
}
if (roll(100) < land.lnd_acc)
dam2 /= 2;
dam += dam2;
if (land.lnd_own != attacker)
wu(0, land.lnd_own,
"%s supported %s at %s\n",
prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
}
return (int)dam;
return dam;
}
int
lnd_can_attack(struct lndstr *lp)
{