Commit graph

369 commits

Author SHA1 Message Date
f3e093e915 tend: Fail more nicely when ships can't tend
Target ships that can't be tended at all are silently ignored.  This
may leave the player guessing why the command did nothing.  Report
them, but only when explicitly named.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
55643423f6 tend ltend: Fix to skip dead ships and land units for deities
Tending to a dead ship destroys, and tending from a dead ship revives.
Has always been that way.  Not actually a problem for ltend anymore,
because the dead can't carry or be carried since commit 64a53c90f0,
v4.3.17.

Fix by checking !own in addition to !player->owner

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
18f3b84390 tend: Fix the amount tended in bulletin to recipient
The bulletin reports the total amount tended to all ships so far.
Broken in commit 1de48e53da (v4.3.0), not fixed in commit 7cc14a2c9a
(v4.3.1).  Fix the bulletin to report the amount tended to this ship.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
6035487287 tend ltend: Improve "cannot hold any" message
Report the exact ship, like

    frg  frigate (#170) cannot hold any uncompensated workers

instead of reporting just the ship type, like

    A frg  frigate cannot hold any uncompensated workers

This is a bit more useful when tending to more than one ship.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
f4dc2e1e79 tend ltend: Handle "cannot hold commodity" consistently
Transferring commodities from tenders to targets continues with the
next tender when a target can't hold this kind of commodity.
Transferring them from targets to tenders fails (ltend) or stops
tending (tend) when a tender can't hold this kind of commodity.  Has
always been that way.

Change the latter to continue with the next tender.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
3dc22e8497 tend ltend: Handle "don't have commodity" consistently
Transferring commodities from tenders to targets fails when a tender
doesn't have any.  Transferring them from targets to tenders continues
with the next target when a target doesn't have any.  Has always been
that way.

Change the former to continue with the next tender.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
1bde4df2bd tend ltend: Reject foreign tenders and land units more nicely
We silently ignore foreign ships and land units.  This may leave the
player guessing why the command did nothing.  Report explicitly named
ones like this

    You don't own ship #160!

except for tend's target ships.  Nice reporting is a bit more involved
there, because you can tend to foreign target ships as long as they're
friendly.  Left for later.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
eb5ed8802a ltend: Fail more nicely when land unit isn't on tender
Land units not on the tender are silently ignored.  This may leave the
player guessing why the command did nothing.  Reporting them all would
be annoying; I just changed tend to report only explicitly named ones.
Make ltend behave the same.

This does add a related annoyance: ltend can complain "not on ship"
when tending explicitly selected land units from multiple ships.
Tolerable.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
15a43a780a tend: Suppress "not on ship" unless land unit is selected by UID
The quickest way to tend all land units on a ship is to select all
land units with '*'.  However, tend then prints a "not on ship"
message for every land unit not on the tender, as the load-tend test
demonstrates.  Annoying.  Suppress this message unless the land unit
was explictly selected by UID.  Similar to how load and unload
suppress messages, only they get the condition wrong (to be fixed
soon).

A related annoyance remains, also visible in the load-tend test: tend
can still complain "not on ship" many times when tending explicitly
selected land units from multiple ships.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
3064731af4 tend: Don't tend land units to multiple target ships
Each land unit is tended to each target ship in turn, and ends up on
the last one that can take it..  The load-tend test demonstrates this
with command "tend land 173 s 150/165":

    spy  infiltrator #320 transferred from sbc  cargo submarine (#173) to cs   cargo ship (#150)
    spy  infiltrator #320 transferred from sbc  cargo submarine (#173) to ls   landing ship (#165)
    spy  infiltrator #321 is not on sbc  cargo submarine (#173)!
    spy  infiltrator #322 transferred from sbc  cargo submarine (#173) to cs   cargo ship (#150)
    spy  infiltrator #322 transferred from sbc  cargo submarine (#173) to ls   landing ship (#165)

Has been that way ever since Empire 2 added tending of land units.

Fix by breaking tend_land()'s loop over all target ships after a
successful transfer.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
68945c8ff8 tests/load-tend: New; exercises load and tend commands
Exercise load, unload, lload, lunload, tend, and ltend.

Notable coverage gaps:

* Effect on land unit fortification

* Effect on mission and retreat orders

* Ships, land units and planes on sale (option MARKET 1)

* Transmission of plague (option NO_PLAGUE 0)

* Land units loading and unloading civilians (need a custom land unit
  type capable of carrying civilians)

* load refusing to load x-light planes (need a custom ship type that
  can carry helo but not x-light)

* load and lload refusing to load land units carrying land units, and
  lload refusing to load land units onto land units that are being
  carried (need a custom non-heavy land unit type that can carry land
  units)

* tend refusing to tend non-light land units to non-supply ships, or
  to supply ships without room (need custom a non-light assault land
  unit type)

This test exposes bugs.  They're marked "BUG:" in the test input.
There are also oddities marked "odd:", and usability issues marked
"usability:".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:15 +01:00
fd303fc6b3 edit: Implement editing of missile fortification
The edit command doesn't support editing plane fortification.  Has
always been that way.  Implement it as key 'F'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
4746d22c3e tests/actofgod: Test integer values more thoroughly
For integer values, we test lower bound - 1, lower bound, upper bound,
upper bound + 1.  Additionally test lower bound + 1, upper bound -1.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
5363ef85d4 tests/actofgod: Fix owner of plane 7/8
Planes 7/8 aren't visible in output, because the test neglects to set
their owner.  Messed up in commit commit efec441, v4.3.33.  Correct
that oversight.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
16e565ed5f edit: Implement editing bars on ships and land units
The edit command doesn't support editing bars on ships and land units.
Has always been that way.  The stock game's ships have always been
unable to load bars.  Not the case for land units.

Unfortunately, the obvious key 'b' for bars was burned on plague time
in 4.0.17.  Use key 'B' instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
647dc66a40 tests/actofgod: Test give and edit for each item type
The test covers only 'c' and 'l' with give, 'm' and 'g' with edit.
Cover the other item types, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
2902cc22c4 edit: Print ship and land unit items with field width 5
print_items() uses field widths between 3 and 5.  They go back all the
way to Empire 1, and are fine for the stock game.  Widen the narrower
ones to 5, because a consistent field width looks tidier, and can
avoid misaligned columns with customized ships and land units.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
60429028e7 update/revolt: Fix land unit casualties
Fix the bug demonstrated by the previous commit:
take_casualties_from_lands() limits total casualties to @each.  It
should limit each land unit's casualties, and only if !may_kill.  This
can lead to fewer casualties than called for; oops in
take_casualties().  Broken in commit 025e9cc25, v4.4.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2018-04-29 10:33:48 +02:00
d111522fe8 Update copyright notice
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-04-29 10:33:19 +02:00
9fcd254538 tests/update: Demonstrate take_casualties_from_lands() bug
Tweak military in land units to demonstrate that
take_casualties_from_lands() can kill fewer military than it should.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2018-04-10 16:48:20 +02:00
5dee2b16d5 tests/update: Belatedly update for commit 35ecc008c
Commit 35ecc008c fixed take_casualties() to destroy land units only
when casualties demand it.  This test demonstrated the change: inf#29
no longer dies.  Good.  However, this lost coverage of land units
dying in a sucessful defense.  Bad.

I could tweak inf#29 to get destroyed again, but that would lose
coverage of the bug fixed by commit 35ecc008c.  Make linf#28 die
instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2018-04-10 16:47:54 +02:00
5e1b590867 Make: Support shallow git clones for testing
Since commit 1ec9b94, we derive the version number from git tags with
build-aux/git-version-gen.  When a shallow clone doesn't include a
suitable tag, this fails, and make refuses to build anything.  Since
Travis uses git-clone --depth=50, it'll break as soon as we've got
more than 50 commits since the last release.

Support arbitrarily shallow clones for limited purposes like testing
by falling back from a proper V.N-H version number to UNKNOWN-H.

To guard against use of such builds for other purposes, log a warning
on server startup, and print one on player login.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-09-02 17:51:37 +02:00
af72ecd75f tests: Normalize version numbers to 4.4.0 instead of 4.3.34
Commit 1ec9b94 normalized version numbers in test output to 4.3.34,
because that was thought to be the next version then.  4.3.34 has
become 4.4.0 meanwhile.  Update the normalization just to avoid
mention of 4.3.34.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-12 09:50:17 +02:00
a83c512dd5 Use all-caps for a few acronyms and for "OK"
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
ab004fed13 Expand a few unnecessary abbreviations in output text
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
90f5822a85 navigate march: Say "to sweep mines" instead of "to minesweep"
The choice of "to minesweep" in "`d' to drop mines, and `m' to
minesweep" is obviously intentional.  But saying it in standard
English instead is at least as clear, so do that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
c5a2d136ec Correct spelling as one word and as two words
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
b6bfc14ab2 Spell harbor consistently
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
2bcd875715 Spell BTU and ETU consistently
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
e6ce36df64 Spelling corrections
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
afe5001a23 Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 09:38:32 +02:00
92693cba65 relations: Move relations state from struct natstr to relatstr
Relations state is relatively bulky: it's a big chunk of struct
natstr, and adds 200 bytes per country to xdump nat.

Relations change rarely.  Rewriting it to disk on every nation update
and retransmitting it in every xdump nat is wasteful.

To avoid this waste, move relations state to its own struct relatstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:22 +02:00
de24545963 relations: Create EF_RELAT table of struct relatstr
New struct relatstr is basically empty so far.  The next commit will
move relations state from struct natstr to struct relatstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
eaa678c903 reject: Move reject state from struct natstr to rejectstr
Reject state is relatively bulky: it's a big chunk of struct natstr,
and adds almost 200 bytes per country to xdump nat.

Reject state changes rarely.  Rewriting it to disk on every nation
update and retransmitting it in every xdump nat is wasteful.

To avoid this waste, move reject state to its own struct rejectstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
f35f16c0a2 reject: Create EF_REJECT table of struct rejectstr
New struct rejectstr is basically empty so far.  The next commit will
move reject state from struct natstr to struct rejectstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
c8e7548f24 contact: Move contact state from struct natstr to contactstr
Contact state is relatively bulky: it's a big chunk of struct natstr,
and adds almost 200 bytes per country to xdump nat for deities.

Contact changes rarely.  Since we avoid unnecessary updates, it
doesn't change at all unless option HIDDEN is enabled.  Rewriting it
to disk on every nation update and retransmitting it in every deity
xdump nat is wasteful.

To avoid this waste, move contact state to its own struct contactstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
4b4df53485 contact: Create EF_CONTACT table of struct contactstr
New struct contactstr is basically empty so far.  The next commit will
move contact state from struct natstr to struct contactstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
cf4e9bc89d contact: Initialize contact state properly
A country must always be in contact of itself when option HIDDEN is
enabled.  The code ensures this by establishing contact whenever a
player logs in, in init_nats().  This is not the proper place.  Game
state should be initialized in empfile's oninit() callback, in this
case nat_oninit().  Do that, and drop the putcontact() from
init_nats().

Note that option LOSE_CONTACT only affects contact to other countries:
agecontact() doesn't age the country's contact to itself.

Use the opportunity to initialize contact so that getcontact() works
even when HIDDEN is disabled.  Just cleanup, it isn't actually called
then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
a89e6e73b0 tests/smoke: Omit redundant data from fairland.xdump
Belatedly update fairland.xdump for commit f4f0482, v4.3.33.

The commit made empdump omit redundant data, shortening the
final.xdump.  The matching manual update to fairland.xdump was
forgotten.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
04dddb6bd1 update/revolt: Make security bonus proportional to efficiency
Land units with capability security get a combat bonus regardless of
efficiency.  This lets players get the benefits of a security unit at
a discount: just don't build it beyond 10%.

Multiply the combat bonus by eff/100.  Together with the previous
commit, this closes bug#64.

Note that the the strength of a security unit's commando raid is
already proportional to its efficiency.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
5d3abc9917 config: Generalize infrastructure build materials storage
Infrastructure requires lcms and hcms to build.  The build materials
are exposed as infrastructure columns lcms, hcms (struct sctintrins
members in_lcms, in_hcms).  They are per point of efficiency.  In
contrast, sector and unit build materials are defined for 100%.

We want to define build materials for 100% now, for flexibility and
consistency, and we want to optionally support more build materials in
the future.  Replace members in_lcms and in_hcms by array in_mat[],
and provide selectors l_build and h_build.

Additionally provide selectors for all other item types, with value
zero, to help clients prepare for future additional materials.  Use
CA_DUMP_ONLY to keep them out of configuration tables until they
actually work.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
c8b51ec1a8 config: Define infra build cost and mobility use per 100%
Infrastructure build cost is defined by infra column dcost (struct
sctintrins member in_dcost).  It's the cost per point of efficiency.
In contrast, sector and unit build cost is defined for 100%, by
sect-chr, ship-chr, plane-chr, land-chr, nuke-chr column cost.

Switch to build cost per 100%, for flexibility and consistency:
replace struct sctintrins member in_dcost by in_cost, and selector
dcost by cost.

With cost values that aren't multiple of 100, the build cost may have
to be rounded.  Do this exactly like we round sector build cost: the
amount is limited to money * 100 / cost rounded down, but the money
charged is actual amount * money / 100 rounded randomly.

Do the same for mobility use: replace struct sctintrins member
in_mcost by in_bmobil, and selector mcost by bmobil, with similar
rounding.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
b4e9c5dcb7 show: Show infra costs in the same format as sector build costs
Use similar column headings, and show cost for 100% instead of 1%.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
2315b50e52 update/revolt: Fix guerrilla liberating old-owned sector
Guerrilla are created loyal to the old owner.  When the sector
converts, they switch their allegiance to POGO.  This is a bit of a
hack.

When guerrilla win their fight for freedom in an old-owned sector, the
old-owner duly changes to POGO.  However, the owner doesn't.  Broken
in 4.2.6.  The "Sector X,Y has been retaken!" message is still sent to
the "new" sector owner.

Simply restoring the owner change lost back then would restore a bug
that goes back to 2.3.7: takeover() doesn't run when an old-owned
sector is liberated.  So fix the bug by making that unconditional.

Land units reported captured are actually destroyed, because POGO
can't own any.  Oh well.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
35ecc008ce update/revolt: Destroy land units only when casualties demand it
take_casualties() first applies casualties without destroying land
units, and if any remain, applies them by destroying land units.  This
is wrong, because the remaining casualties may not suffice to actually
kill.  Has been that way since land units were added in Chainsaw 3.

Apply remaining casualties more carefully: destroy land units only
when efficiency falls below 10%.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
4fd1e889c8 update/revolt: Reduce under-strength land unit damage
A land unit with mil military taking N casualties loses N * 100 / mil
points of efficiency.  A 50% inf with 20m dies when it loses more than
8m.  With 100m, it dies when it loses more than 40m.  A land unit
always dies when it loses all military.

In ordinary ground combat, they lose N * 100 / maxmil points of
efficiency, where maxmil is how many military they could load.  This
is less damage when the land unit is under-strength.  A 50% inf dies
when it loses more than 40m, regardless of how many it has.

An inefficient land unit with a sufficiently high number of military
can die before its military are all killed.  A land unit with a
sufficiently low number of military can survive loss of all its
military.  Attacking land units return to their starting position.
Defending land units stay put, and get taken over by a victorious
attacker.  Neither was possible before 4.0.0 made land unit military
loadable.

The rules for ordinary ground combat may be debatable, but it's better
to be consistent: change land unit damage in guerrilla combat to match
ordinary combat.  This reduces damage to under-strength land units.

If che lose, the sector owner profits from the reduced damage.  But if
they win, they may take over land units that got all their military
killed.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
8a3eb898ce update/revolt: Don't kill land units without military
Land units without military can't contribute to the fight.  They can
still get killed, and whether they are depends on their UID.

take_casualties() kills land units in UID order until the required
number of casualties is reached.  Killing a land unit without military
provides none, but take_casualties() doesn't care.  The land unit
"dies fighting guerrillas", which makes no sense when it's doesn't
have any military.

If the rebels win, they attempt to capture any surviving land units.
Spies hide or get executed instead.  Same as for any other violent
sector takeover.

Normal ground combat ignores land units without military.  Do the same
here: ignore them in take_casualties().  This protects spies and other
land units without military from the fighting, but exposes them to
capture.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
d8e19174ae update/revolt: Spread only actual casualties to land units
To spread C casualties among N land units, take_casualties() applies
floor(C/N)+2 to each.  Bonkers.  Has been that way since land units
were added in Chainsaw 3.

Limit casualties spread to a land unit to their remaining amount.
Should really spread proportionally to military instead of evenly; add
a TODO comment for that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00
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
f0a0de54b7 update/revolt: Fix body count report
The body count reflects what take_casualties() should do, not what it
actually does.  It can be quite off, as the update test's changed
output shows.  Mostly because take_casualties() is utterly confused.
That'll be fixed next.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:19 +02:00