]> git.pond.sub.org Git - empserver/log
empserver
3 years agofairland: Eliminate sectc[][], use adj_land[] instead
Markus Armbruster [Fri, 21 Aug 2020 11:25:16 +0000 (13:25 +0200)]
fairland: Eliminate sectc[][], use adj_land[] instead

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Replace distance_to_land(), distance_to_sea()
Markus Armbruster [Sun, 16 Aug 2020 12:01:32 +0000 (14:01 +0200)]
fairland: Replace distance_to_land(), distance_to_sea()

distance_to_land() searches for closest land sector, and
distance_to_sea() for the closest sea sector.  We already have a more
efficient alternative: the breadth-first search recently added for
spheres of influence can precompute these distances.  Put it to use,
and retire distance_to_land() and distance_to_sea().

distance_to_what() could now be simplified.  Don't bother, because
it'll soon be deleted entirely.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Eliminate macro ELEV, it's an abomination
Markus Armbruster [Mon, 17 Aug 2020 06:39:22 +0000 (08:39 +0200)]
fairland: Eliminate macro ELEV, it's an abomination

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Prefer placing islands away from the edge of the sphere
Markus Armbruster [Mon, 14 Sep 2020 05:27:45 +0000 (07:27 +0200)]
fairland: Prefer placing islands away from the edge of the sphere

When an island gets placed too close to the edge of the sphere of
influence, its side facing the edge will likely be formed by the edge.
Looks unnatural, and can give a clue on the location of the other
continent.

Make place_island() prefer sectors away from the edge: instead of
picking one of the admissible sectors with equal probability, reduce
the probability as we get closer to the edge.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Try harder to deliver the requested amount of land
Markus Armbruster [Tue, 11 Aug 2020 15:58:23 +0000 (17:58 +0200)]
fairland: Try harder to deliver the requested amount of land

Planned island sizes are random with an expected value that matches
the average size requested by the user.  Can be off quite a bit when
the number of islands is small.  Also, actual island size can be
smaller than planned size when space is tight.

Instead of picking random island sizes independently, pick a random
split of their requested total size.

To reduce the probability of islands not growing to their planned
size, grow large islands before smaller ones.

To compensate for inability to grow, carry the difference over to the
next island size.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Make actual island sizes fair
Markus Armbruster [Tue, 11 Aug 2020 14:41:20 +0000 (16:41 +0200)]
fairland: Make actual island sizes fair

The previous commit reduced the difference in island size within the
same batch of islands to at most one.  Eliminate the remaining
difference by shrinking the bigger islands by one sector.

This invalidates the precomputed exclusive zones, so recompute them.

fairland-test needs a tweak to avoid loss of test coverage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Grow islands interleaved
Markus Armbruster [Tue, 11 Aug 2020 14:16:30 +0000 (16:16 +0200)]
fairland: Grow islands interleaved

The previous commits changed grow_island() to create islands in
batches consisting of one island per continent, all of the same
planned size.  grow_island() still places and grows one island after
the other.  When an island can't grow to the actual size, the others
in the same batch are not affected.  Island size can therefore differ
a lot within the same batch.

Change grow_island() to interleave the work on a batch's island: first
place them all, then add one sector to each in turn.  Stop after all
reached the planned size, or one or more could not be grown further.

This is similar to how we grow continents: drift() places them all,
and grow_continent() adds one sector to each continent in turn.

Island size within the same batch can now differ at most by one
sector.  The next commit will eliminate that remaining difference.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Make planned island sizes fair
Markus Armbruster [Tue, 11 Aug 2020 13:39:31 +0000 (15:39 +0200)]
fairland: Make planned island sizes fair

The previous two commits put the same number of islands closest to
each continent.  This one makes their planned sizes match: instead of
rolling dice separately for each island's size, we roll dice only for
the first continent's islands.  The other continent's islands get the
same sizes.

Actual island sizes still differ when islands can't be grown to their
planned size.  To be addressed next.

fairland-test needs a tweak to avoid loss of test coverage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Fail when island can't be placed, for fairness
Markus Armbruster [Tue, 11 Aug 2020 14:16:30 +0000 (16:16 +0200)]
fairland: Fail when island can't be placed, for fairness

The previous commit made island distribution more fair by placing
islands close to a continent in turn.  This is still unfair when
fairland can't place all the islands.

Make grow_islands() fail when it can't place all islands, and main()
start over then, just like it does when grow_continents() fails.

Deities can no longer fill the world with islands by asking for a
impossibly high number of islands.  Tolerable loss, I think.

fairland-test needs a tweak to avoid loss of test coverage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Distribute islands more fairly among continents
Markus Armbruster [Mon, 10 Aug 2020 06:22:21 +0000 (08:22 +0200)]
fairland: Distribute islands more fairly among continents

fairland places islands of random size in random places, subject to
minimum distances.  Results are often less than fair, in particular
when the number of islands per continent is low: some continents have
more land nearby than others.  Increasing distances between islands
doesn't help much.  Deities commonly run fairland until they find the
result acceptable.

The next few commits will tackle this issue.  As a first step, this
one places islands closest to continents in turn, so that each
continent is closest to the same number of islands.  A continent is
closest to an island when it is closest to each of its sectors.

The number of islands must be a multiple of the number of continents
now.

Since fairland may be unable to place all islands, a continent may
still get fewer islands than it should.  The next commit will address
that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Compute spheres of influence
Markus Armbruster [Sun, 9 Aug 2020 15:13:33 +0000 (17:13 +0200)]
fairland: Compute spheres of influence

A continent's sphere of influence is the set of sectors closer to it
than to any other continent.  The next commit needs this.  Compute the
spheres with a breadth-first search.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Eliminate dirx[], diry[]
Markus Armbruster [Tue, 18 Aug 2020 20:20:56 +0000 (22:20 +0200)]
fairland: Eliminate dirx[], diry[]

dirx[] and diry[] are redundant with diroff[][].  Convert the
remaining uses, and drop the arrays.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Fix island growth and correct its bias
Markus Armbruster [Thu, 13 Aug 2020 06:10:37 +0000 (08:10 +0200)]
fairland: Fix island growth and correct its bias

grow_one_sector() picks a coastal start sector, then moves along the
coast trying to add an adjacent sector to the island.

It operates in spiking mode with a chance of @sp percent.

When spiking, the neighbors with sea on both sides are preferred.  For
instance, when the area around the sector being considered looks like
this

     - .
    - - .
     - .

then the neighbor in direction j is preferred, because it has sea in
directions u and n.  No other neighbor is preferred.

The start sector is the first coastal sector found in a linear search
in growth order, starting at the last sector grown when spiking, or
else at a random sector.  This is new_try().

grow_one_sector() tries adding a neighbor in clockwise order, starting
with a random direction.  When spiking, it goes around the clock two
times, trying only preferred sectors in the first round.

When it can't add a neighbor, it moves to the next coastal sector with
next_coast().

Taken together, this randomly picks one element from the set of
pairs (S, D) where the sector in direction D off base sector S can be
added to the island.  How does the probability distribution look like?

Bias: a sector's probability to be added to the island land increases
with the number of base sectors it is adjacent to.  This tends to fill
in bays and lakes, which is fine.

Bias: coastal sectors following runs of non-coastal ones are more
likely to be picked as start sector.  Perhaps less of an issue when
spiking, where the pick is not intended to be random.

Bias: a pair (S, D) is more likely to be picked when base sector S
follows a run of coastal sectors that aren't base sectors, or
direction D follows a a run of directions that don't permit growth.

The impact of these two biases is not obvious.  I suspect they are the
reason behind the tendency of large islands to curve around obstacles
in a counterclockwise direction.  This can result in multiple islands
wrapping around a central one like layers of an onion.

Bug: the move along the coast is broken.  next_coast() searches for
the first adjacent sea in clockwise order, starting in direction g,
then from there clockwise for a sector belonging to the island.
Amazingly, this does move along the coast in a clockwise direction.
It can get caught in a loop, though.  Consider this island:

        -
     - - -
      -

If we start at the central sector (marked 0), the search along the
coast progresses like this:

        1
     - 0 2
      -

It reaches the central sector again after three moves (to 1, to 2,
back to 0), and stops without having reached the two sectors on the
left.

If we start with the leftmost sector, the search loops: 0, 1, 2, 3, 1,
...

        2
     0 1 3
      -

grow_one_sector() ensures termination by giving up after 200 moves.
Nuts!

Because of this, grow_one_sector() can fail when it shouldn't, either
because the search along the coast stops early, or goes into a loop,
or simply because there's too much coast.  The latter should not
happen in common usage, where island sizes are in the tens, not the
hundreds.

Clean up this hot mess by rewriting grow_one_sector() to pick a sector
adjacent to the island with a clearly defined probability, as follows.

Use weighted random sampling to pick one sector from the set of
possible adjacent sectors.

When spiking, a sector's weight increases with number of adjacent sea
sectors.  This directs the growth away from land, resulting in spikes.

When not spiking, the weight increases with the number of adjacent
land sectors.  This makes the island more rounded.

To visit the adjacent sectors, grow_one_sector() iterates over the
neighbors of all island sectors, skipping neighbors that have been
visited already.

This produces comparable results for low spike percentages.  The weird
onions are gone, though.

Noticeable differences emerge as the spike percentage grows.  Whereas
the old one produces long snakes that tend to curve into themselves,
the new one produces shorter spikes extending from a core, a bit like
tentacles.  Moreover, islands are more centered on their first sector
now.  The probability for coastal capitals is lower, in particular for
moderate spike percentages.

I consider this improvements.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Track adjacent land sectors
Markus Armbruster [Sun, 6 Sep 2020 06:44:09 +0000 (08:44 +0200)]
fairland: Track adjacent land sectors

The next commit will put it to use.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Drop try_to_grow() parameter @extra_dist
Markus Armbruster [Sun, 9 Aug 2020 16:01:19 +0000 (18:01 +0200)]
fairland: Drop try_to_grow() parameter @extra_dist

The previous commit removed the only call passing non-zero
@extra_dist.  Drop the parameter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Correct island placement bias
Markus Armbruster [Sun, 9 Aug 2020 15:38:36 +0000 (17:38 +0200)]
fairland: Correct island placement bias

A sector is admissible for island placement when land can be grown in
every sector within a certain distance.

place_island() picks a random start sector, then searches linearly for
an admissible sector.  If it finds one, it places the island there.
Else, it reduces the distance by one and tries again.  It fails when
none is found even for distance zero.

Trying with extra distance is obviously meant to reduce the risk of
islands from running into each other without need.  Initial distance
is @di, the minimum distance between continents, which doesn't really
make sense, and is undocumented.

Bug: place_island() never tries the start sector.

Bias: placement probability is higher for sectors immediately
following inadmissible sectors.  Because of that, islands are more
often placed to the right of existing islands.  Players could exploit
that to guide their search for land.

Rewrite place_island() to pick sectors with equal probability,
dropping the undocumented extra distance feature.  If it's missed, we
can bring it back.

The new code visits each sector once.  The old code visits only one
sector in the best case, but each sector several times in the worst
case.  fairland performance improves measurably for crowded setups
with large @di, else it suffers.  For instance, Hvy Fever example
given in the commit before previous runs seven times faster for me.
With @di reduced to 2, its run time more than doubles.  Not that it
matters.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Drop place_island() parameters @xp, @yp
Markus Armbruster [Sun, 9 Aug 2020 15:13:33 +0000 (17:13 +0200)]
fairland: Drop place_island() parameters @xp, @yp

There is no need to pass coordinates back to the caller.  Replace
parameters @xp, @yp by local variables @x, @y.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Precompute "exclusive zone" for speed
Markus Armbruster [Sun, 2 Aug 2020 15:46:26 +0000 (17:46 +0200)]
fairland: Precompute "exclusive zone" for speed

grow_one_sector() and place_island() pass candidate sectors to
try_to_grow() until it succeeds.

try_to_grow() fails when the candidate isn't water, or there are
sectors belonging to other islands within a minimum distance.
It does that the obvious way: it searches for such sectors.

When there is plenty of space, try_to_grow() rarely fails when it
searches.  For each land sector, we visit the sectors within minimum
distance, plus a little extra work for the rare failures.

In a more crowded setup, however, try_to_grow() fails a lot, and we
visit sectors many times more.

Example: Hvy Fever

    8 continents
    continent size: 60
    number of islands: 64
    average size of islands: 10
    spike: 0%
    0% of land is mountain (each continent will have 0 mountains)
    minimum distance between continents: 6
    minimum distance from islands to continents: 3
    World dimensions: 140x68

This is a crowded setup.  With -R 1, try_to_grow() fails almost
750,000 times due to minimum distance, and takes more than 18 Million
iterations.

With default minimum distances 2 and 1, it fails less than 700 times,
taking less than 14,000 iterations.

Instead of searching the surrounding sectors every time we check a
candidate, precompute an "exclusive zone" around each island where
only this island may grow the obvious way: when adding a sector, visit
the sectors within minimum distance and add them to the island's
exclusive zone.

When @extra_distance is non-zero, try_to_grow() still has to search,
Only place_island() passes non-zero @extra_distance.  The next few
commits will get rid of that.

Complication: since the minimum distance for growing islands may
differ from the minimum distance for growing continents, we have to
recompute exclusive zones between growing continents and islands.

For the Hvy Fever example above, this reduces the number of sector
visits by more than 90%, and run time by more than 70% for me.  With
default distances, it's a wash.

Of course, fairland performance is hardly an issue on today's
machines: it takes fairly impractical setups to push run time over a
second.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Change try_to_grow()'s last argument to extra_dist
Markus Armbruster [Sun, 2 Aug 2020 15:38:29 +0000 (17:38 +0200)]
fairland: Change try_to_grow()'s last argument to extra_dist

Callers pass @di for continents, @id for islands, possibly plus some
extra distance.  Pass just the extra distance, and compute the rest in
try_to_grow().  This  prepares for the next commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Rename INFINITY to INFINITE_ELEVATION
Markus Armbruster [Sat, 8 Aug 2020 11:59:37 +0000 (13:59 +0200)]
fairland: Rename INFINITY to INFINITE_ELEVATION

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Simplify search for next wilderness to elevate
Markus Armbruster [Sun, 16 Aug 2020 15:42:02 +0000 (17:42 +0200)]
fairland: Simplify search for next wilderness to elevate

To find the wilderness sector to elevate next, elevate_land() searches
the non-mountain, non-capital sectors of the island for one that
maximizes a function of its distance to mountains and to sea.

The search ignores already elevated sectors in a less than obvious
way: 1. it never picks a sector where the function yields -INFINITY or
less, and 2. when elevating a wilderness, its (cached) distances get
reset to values that make the function return a more negative value.

Use a more direct check of "not yet elevated": elevation is still the
initial -INFINITY.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Use INT_MAX as initial minimal distance in iso()
Markus Armbruster [Sun, 26 Jul 2020 05:30:58 +0000 (07:30 +0200)]
fairland: Use INT_MAX as initial minimal distance in iso()

Simpler and more obviously correct than WORLD_X + WORLD_Y.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Nicer & much faster replacement for next_vector()
Markus Armbruster [Sat, 25 Jul 2020 12:08:38 +0000 (14:08 +0200)]
fairland: Nicer & much faster replacement for next_vector()

next_vector() is kind of cute, but it is also unobvious, cumbersome to
use, and slow for arguments greater than one.

Replace it by hexagon_first(), hexagon_next().  The new code takes
O(1) time, whereas the old code takes O(n).  Iterating over a hexagon
changes from

       for (i = 0; i < n; ++i)
           vector[i] = 0;
       do {
           x = x0;
           y = y0;
           for (i = 0; i < n; ++i) {
               x = new_x(x + dirx[vector[i]]);
               y = new_y(y + diry[vector[i]]);
           }
   do stuff with @x, @y...
       } while (next_vector(n));

to

       hexagon_first(&hexit, x0, y0, n, &x, &y);
       do {
   do stuff with @x, @y...
       } while (hexagon_next(&hexit, &x, &y));

In my measurements, it's ~8% slower for n == 1, 25% faster for n == 2,
and more than three times faster for n == 6.

fairland's performance is dominated by it.  Creating worlds for the
Common Fever blitz (distance arguments 3 and 2) and the Hvy Fever
Blitz (distance arguments 6 and 3) on my machine speeds up by a factor
of 1.6 and 2.1, respectively.

Of course, fairland performance is hardly an issue on today's
machines: it takes fairly impractical setups to push run time over a
second.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Report missing and stunted islands
Markus Armbruster [Sat, 25 Jul 2020 06:13:54 +0000 (08:13 +0200)]
fairland: Report missing and stunted islands

fairland can create fewer and smaller islands than the user requested.
Report like this:

    No room for island #13
    6 stunted islands

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Check first two continent sectors properly
Markus Armbruster [Tue, 11 Aug 2020 05:52:45 +0000 (07:52 +0200)]
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>
3 years agofairland: Move "is water" check into try_to_grow()
Markus Armbruster [Tue, 11 Aug 2020 05:51:30 +0000 (07:51 +0200)]
fairland: Move "is water" check into try_to_grow()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Move capital initialization to drift() & simplify
Markus Armbruster [Mon, 10 Aug 2020 15:55:15 +0000 (17:55 +0200)]
fairland: Move capital initialization to drift() & simplify

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Move initialization of elev into create_elevations()
Markus Armbruster [Mon, 10 Aug 2020 15:48:21 +0000 (17:48 +0200)]
fairland: Move initialization of elev into create_elevations()

Move it so the next commit can inline init() into drift().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Move global variables mc[] into stable(), eliminate mcc
Markus Armbruster [Sun, 26 Jul 2020 10:35:15 +0000 (12:35 +0200)]
fairland: Move global variables mc[] into stable(), eliminate mcc

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Fix "Only managed to grow" error message off by one
Markus Armbruster [Sat, 25 Jul 2020 07:20:09 +0000 (09:20 +0200)]
fairland: Fix "Only managed to grow" error message off by one

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Eliminate global variable @fl_status
Markus Armbruster [Sat, 25 Jul 2020 07:01:56 +0000 (09:01 +0200)]
fairland: Eliminate global variable @fl_status

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>
3 years agofairland: Eliminate global variable @secs
Markus Armbruster [Sat, 25 Jul 2020 15:40:19 +0000 (17:40 +0200)]
fairland: Eliminate global variable @secs

Move global variable @secs into grow_islands() and grow_continents().
Its other users can use isecs[c] instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Move global variable @spike into grow_one_sector()
Markus Armbruster [Sat, 25 Jul 2020 15:30:51 +0000 (17:30 +0200)]
fairland: Move global variable @spike into grow_one_sector()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Global variable @mind is write-only, drop
Markus Armbruster [Sat, 25 Jul 2020 07:22:35 +0000 (09:22 +0200)]
fairland: Global variable @mind is write-only, drop

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Set isecs[] for continents as well & simplify
Markus Armbruster [Sat, 25 Jul 2020 05:28:28 +0000 (07:28 +0200)]
fairland: Set isecs[] for continents as well & simplify

isecs[] is left zero for continents.  Set it to @sc instead, and
simplify two loops over land sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: De-duplicate map from elevation to sector type
Markus Armbruster [Sat, 8 Aug 2020 11:26:43 +0000 (13:26 +0200)]
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>
3 years agofairland: Fix checking of distance arguments
Markus Armbruster [Mon, 10 Aug 2020 13:39:45 +0000 (15:39 +0200)]
fairland: Fix checking of distance arguments

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>
3 years agoRevert "Make fairland finish argument parsing before reading econfig"
Markus Armbruster [Mon, 10 Aug 2020 13:39:45 +0000 (15:39 +0200)]
Revert "Make fairland finish argument parsing before reading econfig"

This reverts commit d2a7bb6b6fed02d2cf48682d7d2a52a16d5d90e9.

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>
3 years agofairland: Reject continent size 1
Markus Armbruster [Sun, 26 Jul 2020 11:47:44 +0000 (13:47 +0200)]
fairland: Reject continent size 1

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>
3 years agofairland: Simplify defaulting optional positional arguments
Markus Armbruster [Mon, 10 Aug 2020 13:24:30 +0000 (15:24 +0200)]
fairland: Simplify defaulting optional positional arguments

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Check positional arguments more thoroughly
Markus Armbruster [Mon, 10 Aug 2020 13:24:30 +0000 (15:24 +0200)]
fairland: Check positional arguments more thoroughly

fairland silently "corrects" some bad arguments.  Reject them instead.
It neglects to check others completely.  Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Consistent error message format
Markus Armbruster [Sun, 26 Jul 2020 11:15:03 +0000 (13:15 +0200)]
fairland: Consistent error message format

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>
3 years agofairland: Report errors to stderr, not stdout
Markus Armbruster [Sun, 26 Jul 2020 11:15:03 +0000 (13:15 +0200)]
fairland: Report errors to stderr, not stdout

fairland reports some errors to stdout instead of stderr.  Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Tweak progress messages
Markus Armbruster [Sat, 8 Aug 2020 11:34:02 +0000 (13:34 +0200)]
fairland: Tweak progress messages

"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>
3 years agofairland: Drop "might be too small to fit continents" warning
Markus Armbruster [Sun, 2 Aug 2020 05:02:20 +0000 (07:02 +0200)]
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>
3 years agofairland: Collect command line global variables in one place
Markus Armbruster [Sun, 2 Aug 2020 06:23:16 +0000 (08:23 +0200)]
fairland: Collect command line global variables in one place

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoman/fairland: Fix typos, polish markup, clarify text
Markus Armbruster [Sun, 26 Jul 2020 15:24:24 +0000 (17:24 +0200)]
man/fairland: Fix typos, polish markup, clarify text

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Drop option -o
Markus Armbruster [Tue, 11 Aug 2020 11:11:15 +0000 (13:11 +0200)]
fairland: Drop option -o

With -o, fairland doesn't add resources.  This is pretty redundant;
the deity can unset resources with "edit l * i 0 g 0 f 0 c 0 u 0".
Drop the option.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Drop option -a
Markus Armbruster [Sun, 26 Jul 2020 15:29:09 +0000 (17:29 +0200)]
fairland: Drop option -a

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>
3 years agofairland: Make write_newcap_script() failure fatal
Markus Armbruster [Sat, 25 Jul 2020 07:03:03 +0000 (09:03 +0200)]
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>
3 years agofairland: Move #include to the beginning where they belong
Markus Armbruster [Sun, 26 Jul 2020 11:48:26 +0000 (13:48 +0200)]
fairland: Move #include to the beginning where they belong

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Add a comment describing how fairland works
Markus Armbruster [Sat, 25 Jul 2020 06:06:19 +0000 (08:06 +0200)]
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>
3 years agofairland: Add print_own_map(), print_elev_map() for debugging
Markus Armbruster [Tue, 11 Aug 2020 06:26:36 +0000 (08:26 +0200)]
fairland: Add print_own_map(), print_elev_map() for debugging

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agotests/fairland: Cover "plenty of space" better
Markus Armbruster [Wed, 29 Jul 2020 04:49:39 +0000 (06:49 +0200)]
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>
3 years agotests/fairland: Improve coverage
Markus Armbruster [Tue, 28 Jul 2020 04:44:08 +0000 (06:44 +0200)]
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>
3 years agofairland: Show a more useful map
Markus Armbruster [Mon, 17 Aug 2020 10:39:04 +0000 (12:39 +0200)]
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>
3 years agotests/empdump: Fix to honor "make check-accept"
Markus Armbruster [Tue, 28 Jul 2020 04:41:41 +0000 (06:41 +0200)]
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>
3 years agotests: Make "make check-accept" accept new files
Markus Armbruster [Tue, 28 Jul 2020 04:24:17 +0000 (06:24 +0200)]
tests: Make "make check-accept" accept new files

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agotests: Drop some dead code from test-common.sh
Markus Armbruster [Tue, 28 Jul 2020 04:21:46 +0000 (06:21 +0200)]
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>
3 years agoUpdate copyright notice
Markus Armbruster [Sun, 19 Jul 2020 06:37:48 +0000 (08:37 +0200)]
Update copyright notice

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agodamage: Shield embarked planes and land units from sector damage
Markus Armbruster [Thu, 10 May 2018 15:55:50 +0000 (17:55 +0200)]
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>
3 years agoload lload: Refuse to load satellites in space
Markus Armbruster [Sat, 12 May 2018 07:50:17 +0000 (09:50 +0200)]
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>
3 years agolaunch edit: Take satellite off carrier on launch
Markus Armbruster [Sat, 12 May 2018 07:46:51 +0000 (09:46 +0200)]
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>
3 years agoload: Move check for hardened plane into plane_loadable()
Markus Armbruster [Fri, 11 May 2018 16:58:51 +0000 (18:58 +0200)]
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>
3 years agosubs: Maintain plane and land unit fortification invariant
Markus Armbruster [Fri, 11 May 2018 05:58:34 +0000 (07:58 +0200)]
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>
3 years agoedit: Fix fortification limit of embarked planes and land units
Markus Armbruster [Thu, 10 May 2018 16:32:54 +0000 (18:32 +0200)]
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>
3 years agotests/actofgod: Cover loading hardened missiles
Markus Armbruster [Fri, 11 May 2018 06:27:12 +0000 (08:27 +0200)]
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>
3 years agoload: Factor out plane_loadable(), land_loadable()
Markus Armbruster [Sun, 3 Sep 2017 15:58:42 +0000 (17:58 +0200)]
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>
3 years agoRevert "Don't let trains load trains"
Markus Armbruster [Thu, 10 May 2018 15:00:24 +0000 (17:00 +0200)]
Revert "Don't let trains load trains"

This reverts commit b1a0ff2fbd87d3c332de1e0a41b3ddea133c77b1.

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>
3 years agomarket: Simplify check for dead trades and document how it fails
Markus Armbruster [Thu, 10 May 2018 09:15:29 +0000 (11:15 +0200)]
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>
3 years agobuy set trade: Fix taking lots off the market
Markus Armbruster [Thu, 10 May 2018 08:28:49 +0000 (10:28 +0200)]
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 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>
3 years agoset: Use the first unused lot instead of the last
Markus Armbruster [Thu, 10 May 2018 08:16:10 +0000 (10:16 +0200)]
set: Use the first unused lot instead of the last

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoload unload: Don't treat unowned sectors specially
Markus Armbruster [Tue, 1 May 2018 16:54:14 +0000 (18:54 +0200)]
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>
3 years agoload lload unload lunload: Tweak suppression of error messages
Markus Armbruster [Tue, 1 May 2018 08:59:33 +0000 (10:59 +0200)]
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>
3 years agoload: Drop dead recomputation of load_spy
Markus Armbruster [Tue, 1 May 2018 08:03:30 +0000 (10:03 +0200)]
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>
3 years agoload lload: Drop dead "cannot carry land units" checks
Markus Armbruster [Tue, 1 May 2018 07:19:43 +0000 (09:19 +0200)]
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>
3 years agodoc/contributing: Fix a greengrocers' apostrophe
Markus Armbruster [Mon, 4 Dec 2017 18:38:27 +0000 (19:38 +0100)]
doc/contributing: Fix a greengrocers' apostrophe

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agounload lunload: Fail early when carrier can't carry land units
Markus Armbruster [Sun, 17 Sep 2017 04:53:37 +0000 (06:53 +0200)]
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>
3 years agoship: Drop misleading comment
Markus Armbruster [Sun, 17 Sep 2017 03:05:02 +0000 (05:05 +0200)]
ship: Drop misleading comment

Left behind by comment c0c5822, v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoload unload lload lunload: Fix for areas starting with a digit
Markus Armbruster [Sat, 16 Sep 2017 15:07:10 +0000 (17:07 +0200)]
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>
3 years agounload lunload: Say "Can't unload" instead of "Can't load"
Markus Armbruster [Sat, 16 Sep 2017 07:59:55 +0000 (09:59 +0200)]
unload lunload: Say "Can't unload" instead of "Can't load"

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoload: Replace variable load_unload by variable loading
Markus Armbruster [Sat, 16 Sep 2017 07:46:47 +0000 (09:46 +0200)]
load: Replace variable load_unload by variable loading

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoltend: Reject zero amount more nicely
Markus Armbruster [Sat, 16 Sep 2017 07:30:07 +0000 (09:30 +0200)]
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>
3 years agotend: Fail more nicely when target can't take more commodities
Markus Armbruster [Fri, 15 Sep 2017 14:58:10 +0000 (16:58 +0200)]
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>
3 years agotend: Report "cannot hold any" when tending to target, too
Markus Armbruster [Fri, 15 Sep 2017 14:51:46 +0000 (16:51 +0200)]
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>
3 years agotend: Refuse to give away civilians more nicely
Markus Armbruster [Fri, 15 Sep 2017 14:47:51 +0000 (16:47 +0200)]
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>
3 years agotend: Factor can_tend_to() out of tend(), tend_land()
Markus Armbruster [Fri, 15 Sep 2017 14:30:41 +0000 (16:30 +0200)]
tend: Factor can_tend_to() out of tend(), tend_land()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agotend: Fail more nicely when ships can't tend
Markus Armbruster [Fri, 15 Sep 2017 08:12:36 +0000 (10:12 +0200)]
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>
3 years agotend ltend: Fix to skip dead ships and land units for deities
Markus Armbruster [Fri, 15 Sep 2017 07:49:01 +0000 (09:49 +0200)]
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>
3 years agotend: Factor can_tend_to() out of tend(), tend_land()
Markus Armbruster [Fri, 15 Sep 2017 06:32:10 +0000 (08:32 +0200)]
tend: Factor can_tend_to() out of tend(), tend_land()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agotend: Fix the amount tended in bulletin to recipient
Markus Armbruster [Thu, 14 Sep 2017 14:08:22 +0000 (16:08 +0200)]
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>
3 years agotend ltend: Improve "cannot hold any" message
Markus Armbruster [Thu, 14 Sep 2017 10:18:56 +0000 (12:18 +0200)]
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>
3 years agotend ltend: Handle "cannot hold commodity" consistently
Markus Armbruster [Thu, 14 Sep 2017 10:14:14 +0000 (12:14 +0200)]
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>
3 years agotend ltend: Handle "don't have commodity" consistently
Markus Armbruster [Thu, 14 Sep 2017 10:10:07 +0000 (12:10 +0200)]
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>
3 years agotend ltend: Reject foreign tenders and land units more nicely
Markus Armbruster [Wed, 13 Sep 2017 16:41:00 +0000 (18:41 +0200)]
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>
3 years agoltend: Fail more nicely when land unit isn't on tender
Markus Armbruster [Tue, 12 Sep 2017 08:04:25 +0000 (10:04 +0200)]
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>
3 years agotend: Suppress "not on ship" unless land unit is selected by UID
Markus Armbruster [Tue, 12 Sep 2017 07:32:40 +0000 (09:32 +0200)]
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>
3 years agotend: Don't tend land units to multiple target ships
Markus Armbruster [Mon, 11 Sep 2017 05:37:49 +0000 (07:37 +0200)]
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>
3 years agotests/load-tend: New; exercises load and tend commands
Markus Armbruster [Mon, 28 Aug 2017 17:48:27 +0000 (19:48 +0200)]
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>
3 years agoedit: Implement editing of missile fortification
Markus Armbruster [Sun, 27 Aug 2017 12:47:31 +0000 (14:47 +0200)]
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>