Commit graph

5443 commits

Author SHA1 Message Date
883f53be74 fairland: Add print_own_map(), print_elev_map() for debugging
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:35 +01:00
89a386aa60 tests/fairland: Cover "plenty of space" better
Reduce number of islands in fairland run "plain" so there's plenty of
space for them.  Scarce space is still covered by run "stunted".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:35 +01:00
f18159fb23 tests/fairland: Improve coverage
Rename the existing fairland run to "plain".

New run "stunted" to cover larger minimal distances, islands
that can't fully grow, and islands that can't be placed.

New run "no-spike" to cover 0% spike.

New run "spike" to cover high spike percentage, mountains and -i.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:35 +01:00
c4441014e3 fairland: Show a more useful map
The map fairland shows has absolute 0,0 in the top-left corner, while
POGO's map * has it in the center.  Shift fairland's map to match
POGO's.

The map shows sea as '.', island sectors as '%', capitals as '#',
mountains as '^', and other continental sectors as a letter or digit
that encodes the continent number modulo 62.  When a continent has no
"other" sectors, its continent number is not shown.  Remove this
pathological case by using letter/digit for capitals, and '#' for
other continental sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:35 +01:00
1cc54f3625 tests/empdump: Fix to honor "make check-accept"
Delete stray EMPIRE_CHECK_ACCEPT=.  Goes back all the way to commit
5a1544f92 "tests/empdump: New; exercising the empdump utility".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:35 +01:00
ddefd7173e tests: Make "make check-accept" accept new files
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:35 +01:00
e823a4f055 tests: Drop some dead code from test-common.sh
Left behind by commit c594b6120 "tests: New helper cmp_out1".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:35 +01:00
4a1ec06364 Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:28 +01:00
7d8e2aed16 damage: Shield embarked planes and land units from sector damage
Damage to a ship or land unit, say via pinpoint bombing, doesn't
damage loaded planes and land units.

Damage to a sector, say via strategic bombing, doesn't damage ships
there, but it does damage planes, even when loaded on a land unit (but
not when loaded on a ship), and land units, even when loaded on a land
unit or a ship.

This makes no sense.  Sector damage spills over to land units that way
since Chainsaw 3 added them, and to planes since 4.0.9.

Change sectdamage() not to damage land units and planes loaded on
ships or land units.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:28 +01:00
b109430b8c load lload: Refuse to load satellites in space
Doesn't affect the stock game, because none of its satellites are
light, let alone x-light.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:28 +01:00
6ce25bdd4f launch edit: Take satellite off carrier on launch
Doesn't affect the stock game, because none of its satellites are
light, let alone x-light.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:41:05 +01:00
bf9cb33fc2 load: Move check for hardened plane into plane_loadable()
This de-duplicates the check, and skips it when unloading.  It never
made sense there, and can't happen anymore since the previous commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:40:40 +01:00
8b9ce7be43 subs: Maintain plane and land unit fortification invariant
Make lnd_prewrite() and pln_prewrite() ensure that land units and
missiles loaded on a land unit or ship are never fortified / hardened.

This takes care of edit neglecting to zap fortification on load.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:40:34 +01:00
f5514cb452 edit: Fix fortification limit of embarked planes and land units
We generally preserve the invariant "land units and missiles loaded on
a land unit or ship are never fortified / hardened": fortify and
harden refuse to touch embarked land units and missiles, load and
lload zap land unit fortification on load, and refuse to load hardened
missiles.

The exception is edit, which happily fortifies embarked land units
(edit u key 'F'), hardens embarked missiles (edit p key 'F'), loads
fortified land units (edit u keys 'S' and 'Y') and hardened planes
(edit p keys 's' and 'y').

Fix the first two by correcting the new value's upper limit to zero
for embarked land units and planes.  The next commit will take care of
the rest.

The fix is visible in tests where test setup fortifies land units with
"edit u * F ?..." without excepting embarked ones.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:38:57 +01:00
b2be5a227d tests/actofgod: Cover loading hardened missiles
Demonstrates that edit leaves a missile's hardening intact on load.

Loading fortified land units is already covered, and also leaves
fortification intact.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
31256510cc load: Factor out plane_loadable(), land_loadable()
load_plane_ship() and load_plane_land() duplicate code to check
whether a plane can be loaded, except for the phrasing of one message.
Factor out into plane_loadable().  tran_plane() has equivalent code,
but wants different messages, which makes de-duplication unattractive.

load_land_ship() and load_land_land() duplicate code to check whether
a land unit can be loaded.  Factor out into land_loadable().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
c931758307 Revert "Don't let trains load trains"
This reverts commit b1a0ff2fbd.

Land units with capability heavy can't be loaded on anything, and land
units carrying land units can't be loaded regardless of capabilities.
Commit b1a0ff2fbd additionally outlawed loading of trains on land
units, but not on ships.  Bad idea, because it complicates matters for
no good reason.  Revert it.

Doesn't affect the stock game, because its only train is heavy.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
85d8e7fcb1 market: Simplify check for dead trades and document how it fails
We fail to delete trades right away when the unit on sale dies.
Instead, we delete trades of the dead whenever we look at the market.
Doesn't work when new builds reuse the IDs of such dead.  If the new
unit's owner differs from the dead one's, we still delete the trade,
and log "Something weird".  If they are the same, the newly built unit
takes the dead one's place on the market.  Has been that way since the
market was added in 4.0.0.

I can't fix this right now, so mark as FIXME, and drop the logerror().
The first of the two trade deletions is now redundant, so drop that,
too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
6bcd72e241 buy set trade: Fix taking lots off the market
To find out whether a lot is in use, some places check for zero
trd_owner, others for negative trd_unitid.  The former is reliable,
the latter is not: set() fails to change trd_unitid when it takes a
lot off the market.  The next trade-related command then runs
check_trade(), which logs "Something weird" and cleans up the mess.
Broken in commit e16e38dfab (v4.2.18).

Replace the unreliable checks by reliable ones.

Clean up set() not to implictly rely on unused lots having negative
trd_unitid.

The trd_unitid = -1 are unnecessary now, so drop them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
5f0ddfd950 set: Use the first unused lot instead of the last
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
882fab925c load unload: Don't treat unowned sectors specially
load and unload silently skip unowned sectors, unlike lload and
lunload.  Probably goes back to Chainsaw option ALLYHARBOR.

Drop that.  Deities can now load and unload in unowned harbors and
canals.  Mortals are now notified they can't.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
3f2e59ab2f load lload unload lunload: Tweak suppression of error messages
These commands suppress some error messages when ships, planes or land
units involved aren't explicitly selected by UID.  Without this, a
command like "unload plane 80 *" would complain about every plane not
on ship#80.

Correct a few issues with this error suppression:

1. We don't suppress the error when we can't load/unload a ship or
land unit because it's on the trading block.  Do suppress it.

2. We suppress the error message when we can't load/unload due to
foreign sector ownership in all but one places.  Fix that place.

3. Messages about explicitly selected planes and land units to load
are still suppressed when the carrier isn't selected explicitly.
Change this to suppress regardless of the carrier.

3. We suppress the error when a carrier has no room.  Don't, because
it's a potentially confusing silent failure.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
93d842de20 load: Drop dead recomputation of load_spy
load_land_ship() recomputes load_spy "since [the carrier] may have
changed".  Has been that way since the feature was added in 4.2.0, but
it's nonsense.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
7c5e6e7f6d load lload: Drop dead "cannot carry land units" checks
load_land_ship() and load_land_land() fail for carriers that can't
carry any land units before prompting for land units to load.  They
then iterate over land units to load, and fail when the carrrier has
no room.  They either report "cannot carry land units" or "doesn't
have room for any more land units" then.  The former cannot happen.
Crept into load_land_ship() in Empire 2, blindly copied to
load_land_land() in 4.0.0.  load_plane_ship() and load_plane_land()
don't have this issue.

Drop the dead code.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
0851761fb9 doc/contributing: Fix a greengrocers' apostrophe
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
585e9540ce unload lunload: Fail early when carrier can't carry land units
Attempting to unload land units from a carrier that can't carry any
prompts for land units to unload, while attempting to unload planes or
load land units or planes fails without prompting.

Fix this inconsistency by making unload and lunload fail early for
land units, just like they do for planes.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
8de59d0014 ship: Drop misleading comment
Left behind by comment c0c5822, v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
607f15a6f6 load unload lload lunload: Fix for areas starting with a digit
load and lload skip foreign ships unless explicitly named, and
suppress some error messages for ships not explicitly named.  Makes
sense, except the check for "explicitly named" is flawed: it checks
whether the argument starts with a digit.  Works as intended for lists
like 1/2/3.  Broken for areas that happen to start with a digit, such
as 0:9,0:5.  Visible in the load-tend test.

Screwed up when the feature was added in Empire 2.

Fix the obvious way: test for NS_LIST instead.  While there, drop the
p && *p guard, because it's always true after snxtitem().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
581732dcd1 unload lunload: Say "Can't unload" instead of "Can't load"
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
3aa6c1b263 load: Replace variable load_unload by variable loading
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
7d2c09668c ltend: Reject zero amount more nicely
Unlike tend, ltend does nothing silently when asked to tend zero
commodities.  This may leave the player guessing why the command did
nothing.  Report the reason and fail the command, just like tend does.
While there, improve the prompt to match tend's.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
70008c1b9f tend: Fail more nicely when target can't take more commodities
We silently ignore target ships that can't take any more of the tended
commodity.  This may leave the player guessing why the command did
nothing.  Report the reason like this:

    cs   cargo ship (#150) can't hold more guns

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
be5b167ce6 tend: Report "cannot hold any" when tending to target, too
We report

    frg  frigate (#170) cannot hold any uncompensated workers

only when tending from target to tender, not for the other direction.
Report it there, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
a0dc5cbf16 tend: Refuse to give away civilians more nicely
Foreign target ships are silently ignored when tending civilians.
This may leave the player guessing why the command did nothing.
Report the reason similar to load does:

    Your civilians refuse to board cs   cargo ship (#162)!

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
2a8a6a5933 tend: Factor can_tend_to() out of tend(), tend_land()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:17 +01:00
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
333cd7d6d3 tend: Factor can_tend_to() out of tend(), tend_land()
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