empserver/src/lib/update
Markus Armbruster 75c8d9c72f update/revolt: Fix how land units take casualties
take_casualties() applies a number of casualties to sector military
and land units.  It is utterly confused about land units.

Consider a land unit with efficiency eff that has mil out of maxmil
military.  Issues:

* To apply N casualties without destroying it, take_casualties() tries
  to kill N * maxmil / mil military.  Makes no sense.  It's more than
  asked for unless mil equals maxmil.  It can even be more than mil.

  It reduces efficiency by N * 100 / mil points.  Note that ordinary
  ground combat reduces by N * 100 / maxmil points.  See
  lnd_take_casualty().

  Example: the update test's inf#25 is 100% efficient and has 20m out
  of 100m.  take_casualties() tries to apply up to 22 casualties out
  of the 60 remaining casualties to apply, but decides to apply only
  12 for now, to keep efficiency above to 40%.  It reduces efficiency
  by 12 * 100 / 20 = 60 to 40%, and tries to kill 12 * 100 / 20 = 60
  mil, which kills off the 20 that actually exist.  It nevertheless
  reduces the number of casualties still to apply only by 12.

  Example: the update test's linf#28 is 100% efficient and has 20m out
  of 25m.  take_casualties() tries to apply up to 8 casualties.  It
  reduces efficiency by 8 * 100 / 20 = 40 points to 60%, and tries to
  kill 8 * 25 / 20 = 10 military.

* When it destroys a land unit, it reduces the number of casualties
  still to apply by mil * eff/100.0 instead of mil.

  Example: the update test's inf#27 is 10% efficient and has 20m out
  of 100m.  take_casualties() still has 34 casualties to apply, so it
  destroys it, killing all 20m.  But it reduces the number of
  casualties to apply only by 2.

Broken when 4.0.0 made land unit military loadable.  Not sure it fully
worked before that, but it's definitely bonkers since.

Fix it as follows:

* To apply casualties to a land unit without destroying it, limit its
  losses to its actual number of military, and so that efficiency
  stays above 40%.  Then simply kill that number.

* Reduce the number of casualties to apply by the exact number killed.

The update test now kills only 8m in linf#28.  Still two more than it
should, but that's separate bug, to be fixed next.  The fix has no
visible effect for inf#25, because that one gets destroyed later.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
..
age.c Include "file.h" where it's needed 2017-08-06 20:08:31 +02:00
anno.c include: Move update stuff from prototypes.h to update.h 2017-08-06 19:59:59 +02:00
bp.c budget: Avoid unnecessary work 2017-08-06 20:09:06 +02:00
deliver.c update: Delivery abandons sectors incorrectly, fix it not to 2017-08-06 20:09:17 +02:00
distribute.c Include "file.h" where it's needed 2017-08-06 20:08:31 +02:00
fallout.c update: Collect fallout code in fallout.c 2017-08-06 20:09:16 +02:00
finish.c Include "file.h" where it's needed 2017-08-06 20:08:31 +02:00
human.c update: Treat sanctuaries more consistently 2017-08-06 20:08:30 +02:00
land.c update: Reorder feeding, tax & plague for consistency 2017-08-06 20:09:16 +02:00
main.c budget: Avoid unnecessary work 2017-08-06 20:09:06 +02:00
material.c include: Move update stuff from prototypes.h to update.h 2017-08-06 19:59:59 +02:00
mobility.c Include "file.h" where it's needed 2017-08-06 20:08:31 +02:00
move_sat.c Include "file.h" where it's needed 2017-08-06 20:08:31 +02:00
nat.c Include "file.h" where it's needed 2017-08-06 20:08:31 +02:00
nxtitemp.c Include "file.h" where it's needed 2017-08-06 20:08:31 +02:00
plague.c update: Reorder feeding, tax & plague for consistency 2017-08-06 20:09:16 +02:00
plane.c budget: Avoid unnecessary work 2017-08-06 20:09:06 +02:00
populace.c update: Reorder feeding, tax & plague for consistency 2017-08-06 20:09:16 +02:00
prepare.c update: Move sector type test into bank_income() 2017-08-06 20:09:17 +02:00
produce.c update: Track levels in nat_budget[] 2017-08-06 20:08:30 +02:00
removewants.c Include "file.h" where it's needed 2017-08-06 20:08:31 +02:00
revolt.c update/revolt: Fix how land units take casualties 2017-08-06 20:09:19 +02:00
sect.c update: Reorder feeding, tax & plague for consistency 2017-08-06 20:09:16 +02:00
ship.c update: Reorder feeding, tax & plague for consistency 2017-08-06 20:09:16 +02:00