fairland: Check first two continent sectors properly
grow_continents() places the first two continent sectors without
checking for collisions or minimum distance. Unlikely to be an issue
in practice, as growing such a continent will almost certainly fail.
Fix it anyway.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
grow_one_sector() sets @fl_status when it fails to grow a continent.
grow_continents() uses @fl_status to find out whether
grow_one_sector() succeeded, and main() uses it to find out whether
grow_continents() succeeded.
Change grow_continents() to return success / failure.
grow_one_sector() already does. Use the return values, and eliminate
@fl_status.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
fairland: De-duplicate map from elevation to sector type
Both write_sects() and map_symbol() map from elevation to sector type.
Factor out as elev_to_sct_type(). Inline map_symbol() into output()
and simplify.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
main() rejects the distance between continents when it exceeds WORLD_X
/ 2 and WORLD_Y / 2, and the distance between continents and islands
when it exceeds WORLD_Y and WORLD_Y. Nuts. Has always been that way.
Reject either when it exceeds the maximum distance between sectors.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
parse_args() uses WORLD_X and WORLD_Y to check the distance arguments.
Calling it before reading econfig is wrong, because at that time
WORLD_X and WORLD_Y still have the compiled-in default values instead
of the actual ones set in econfig.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
fairland creates continents of size 1 just fine, but the newcap_script
it emits doesn't work: the newcap command requires a second wilderness
sector to the right of the first sector.
Reject continent size 1.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
fairland prefixes error messages with several variations of "fairland:
error -- ", but also with "ERROR: " and nothing at all. Consistently
prefix them with just the program name.
Some error messages end with a period, most don't. Drop the periods.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
"fairland: unstable drift -- try increasing DRIFT_MAX" is confusing:
it looks like an error, but isn't, and increasing DRIFT_MAX requires a
recompile. I'm not sure it can happen. Replace by just "unstable
drift".
"fairland: error -- continent %c had no room to grow!" is pretty
redundant: it's always followed by "Only managed to grow %d out of %d
sectors." and then "ERROR: World not large enough to hold
continents". All it adds is which of the continents failed to grow,
and that's not actionable. Drop the message.
The message sequence "designating sectors...", "adding resources...",
"setting coastal flags...", and "writing to sectors file..." is a bit
of a lie as these four tasks aren't actually done one after the other.
Replace by just "writing to sectors file..."
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
fairland: Drop "might be too small to fit continents" warning
Commit de81e4e20 "Change fairland not to reject small worlds without
trying" (v4.3.25) downgraded it from error to warning, pointing out it
the size may well work, and when it doesn't, fairland fails cleanly.
When it works, the warning is pointless. When it doesn't, it's
redundant. Drop it.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
With -a, fairland makes the capital sector an airfield to "mark the
continents [...] so that you can tell them from the islands". This is
pretty redundant since commit afc0ef94e "Make fairland record the
island number in the deity territory", v4.3.31. Drop it.
The map fairland prints is not affected. The continents are clearly
visible there.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
fairland: Make write_newcap_script() failure fatal
When write_newcap_script() fails, it complains to stderr and fails.
main() doesn't bother to check for failure. Has always been that way.
Fix main() to check. Also adjust write_newcap_script() to return one
on success, zero on failure, like the other functions do.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
fairland: Add a comment describing how fairland works
A comment describing how fairland works was lost some time after
Chainsaw 3.31. This is the last known version:
The algorithm starts out by placing the "capitols" on the torus in
such a way so as to maximize their distances from one another (this
uses the perterbation technique of calculus of variations). Then from
these seeds, the continents are grown. The kind of shape they grow
into is determined by the "spike" argument <sp>--the higher the spike,
the more spindly they will be. If you lower the spike, the continents
will be more round. The continents never touch one another, the
argument <di> specifies how many sectors of water should be between
the continents at all times. The continents grow to the size you
specify with <sc> and they all get the same number of mountains
(specified by <pm>). The other arguments should be self explanitory.
If #define ORE 1, then resources will be placed in the sectors as well.
You can alter the #define ORE_MAX, IRON_MIN, GOLD_MIN, FERT_MAX and
URAN_MIN to affect what kind of resources the world gets.
It leaves much to be desired. Add a more thorough one.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
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>
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>
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>
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>
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 b1a0ff2fbd8 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>
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>
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 e16e38dfabc (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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
info/retreat info/lretreat: Fix truncated glossary list items
Text after the first space is missing in the formatted output. That's
because .L takes just one argument, but we pass several. Broken in
commit 4e0d02b, v4.3.33. Fix by quoting the argument text.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
The test for -x uses non-portable operator ==. Screwed up in commit 63c6dd6. Fix by using getopts instead.
Missing mandatory arguments aren't diagnosed. Screwed up in initial
commit 1991652, v4.3.0. Fix by checking shift's return status.
The error message for missing argument of -C neglects to print $0 and
uses echo in a non-portable way. Also screwed up in commit 1991652.
Fix the obvious way.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
configure: Fix botched fix of .tarball-version access
Commit ece998e fixed .tarball-version access from separate build tree
by adding $srcdir/ to it. That's wrong in m4_esyscmd(), because there
it runs at autoconf time, where $srcdir isn't necessary and doesn't
exist. Revert that part.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
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>