Commit graph

409 commits

Author SHA1 Message Date
602e536524 tests/fire: Clean up setup a bit
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:27 +01:00
862ad614c1 tests/actofgod: Switch setup from deprecated setsect to edit
Clean it up a bit while there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:27 +01:00
ff826d2582 retreat: Don't consume a retreat direction that wasn't followed
When a retreating ship or land unit runs into a sector it can't enter,
it stops.  The direction character that led it there is consumed, even
though it could not be followed.  The next retreat will then attempt
to follow the rest of the path.  Don't do that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
40ec33b099 retreat: Reject invalid retreat paths
Undocumented misfeature: retreat and lretreat accept anything as
retreat path.  The paths' actual consumers retreat_ship1() and
retread_land1() silently ignore invalid direction characters.

The retreat paths are in xdump, and invalid ones could conceivably
confuse smart clients.

Change the commands to reject invalid paths, and the consumers to oops
on invalid direction characters.

Note that invalid paths get rejected even when they're not actually
used because the conditions argument contains a "c" for "cancel".
Requiring the user give a new path so he can cancel the old one is
comically bad design.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
b3453efdfc retreat: Don't charge mobility for retreating in direction 'h'
Obscure feature: 'h' in a retreat path stops the current retreat.  The
code treats that as entering the current sector again, thus charges
mobility for staying put.  It also reports "could not retreat to" for
a ship or land unit that can retreat out of, but could not retreat
into its current sector, e.g. a ship in an unfriendly harbor.

Fix by cleaning up the tortuous control flow.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
d1c3529009 retreat: Don't retreat the current player's ships or land units
The retreat code happily retreats anything, without considering who
owns it.  It reports retreat to the owner by bulletin, even when the
owner is the current player.

Commands shouldn't report to the current player by bulletin, they
should print directly.  Fixable.  However, your ships and land units
retreating from your own actions makes little sense.  Suppress it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
df8a1ffc1b retreat: Don't report a destroyed ship/land unit couldn't retreat
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
b860123590 retreat: Retreat groups in a more sensible order
A group retreat is executed in increasing UID order.  The resulting
bulletin can be confusing.

Instead, retreat the ship that had its retreat conditions satisfied
first, and only then its group, if any.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
e7949e20f3 retreat: Clear mission only when ship or land unit moves
The mission gets cleared whenever a retreat is triggered, even for
ships and land units that are unable to retreat.

Clear it only when the ship or land unit actually retreats.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
2cc0664e3e retreat: Fix stack smash in land unit group retreat
retreat_land() reads ships instead of land units, overrunning local
variable land.  On lucky systems such as mine, this clobbers ni, and
triggers an oops.  On unlucky systems, it crashes.  On really unlucky
systems, it corrupts the land units file.

Broken since land unit retreat was added in Chainsaw 3.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
a963b4e703 tests/fire: Drop test of ship retreat
Now covered in tests/retreat.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
58cd269bed tests/retreat: New; exercising retreat
Does not cover land unit retreat after a failed morale check.

The test exposes bugs.  They're marked "BUG:" in the test input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
c7af9bd955 edit: Keep missions centered on unit centered when teleporting
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
10f6322594 tests/actofgod: Show moving units with edit doesn't affect mission
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
c2683e5b58 tests: Save diff -u between expected and actual output
"diff -q" isn't blessed by POSIX anyway.  Neither is -u, but it should
be widely available.  -c is blessed, but I find its output hard to
read.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
b7bcf8fde2 tests/fire: Drop test of falling bridges
Now covered in tests/bridgefall.  Damage perturbed, because deleting
the bridges from the setup makes defend() roll fewer dice.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
2da09bc4b0 tests/fire: Drop test of units tumbling down with bridges
Now covered in tests/bridgefall.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
57f53293e6 tests/fire: Protect against unintended shelling to deity
Sector 0,2 takes a lot of damage.  When it gets shot to deity, the
rest of the test can be upset.  Avoid by putting more civilians there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
e2c8b7d145 tests/bridgefall: Cover units tumbling down with bridges
There's now even more overlap with tests/fire.  To be cleaned up next.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
ae595ec430 edit: Fix edit s key 'U' to preserve "does not follow"
Copying the ship copies the ship to follow.  When the source ship
doesn't follow a ship, the target ship is made to follow the source.
Screwed up since Chainsaw added the means to copy a ship.  Fix it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
e604c6e737 edit: Make edit l key 'L' preserve "no dist center"
Copying the sector copies its distribution center.  When the source
sector has none, the target sector is made to distribute to the
source.  Unexpected.  Zap the distribution center then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
3c7d9da3ab edit: Fix edit l key 'L' not to mess up coastal flag
Screwed up since Chainsaw added the means to copy a sector.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
321f6161c9 tests/actofgod: Show edit l key 'L' mess up coastal flag
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
582ad80d75 Suppress duplicates in output of git ls-files
Happens during merges; can mess up tests badly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
1b7b5b09e3 tests/fire: Use build command for setup
Setup uses edit to build units.  Stupid idea, because that misses unit
initialization normally done by build, directly or via
unit_wipe_orders().  Use build instead.

Changes test output harmlessly: ship xbuilt, ybuilt go from 0,0 to the
building sector, ship#0's builder goes from 98 to 0, all ships'
cargostart and cargoend go from 0 to -1, jhb range from 0 to 35, and
land unit retreat percentage from 0 to 42.

Setup no longer needs country 98.  Drop it.

Setup no longer copies 2,0 to 0,0 messing up its distribution center.
Harmless.

Setup doesn't need POGO's tech level anymore, so don't set it to 400.
Nukes are now built at their required tech level.  Also harmless.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
b5e155f101 tests/bridgefall: Use build command for setup
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:20 +01:00
893f9f3eb8 tests/actofgod: Use build command for setup
final.xdump changes, because setup no longer copies 3,-1 to 1,-1,
messing up its distribution center.  Harmless.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 12:00:31 +01:00
3270b69a98 tests/build: Use build command for setup
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 12:00:31 +01:00
15e3309297 build: Reword bridge next to land messages to mention the sector
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 12:00:31 +01:00
05f1844ca1 build: Deities build ex nihilo
Let deities build in any sector.  If the deity's tech level is too
low, use the required tech level instead.  Don't require or use
materials, work or money.  Bridge spans still require support.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 12:00:19 +01:00
4824648978 bridgefall: Fix loss of bridge support with EASY_BRIDGES off
With EASY_BRIDGES off, bridge spans need to be next to a bridge tower
or a bridge head that is at least 20% efficient to remain standing.

When a bridge tower or head gets damaged below 20%, adjacent spans may
lose support.  Bug: they don't fall when they're next to another
bridge head below 20%.

Has always been broken.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 12:00:18 +01:00
292bfac797 bridgefall: Fix support loss with EASY_BRIDGES and BRIDGETOWERS on
With EASY_BRIDGES on, bridge spans need to be next to land or a bridge
tower to remain standing.

Land can't go away, but a bridge tower can fall.  Bridge spans next to
it may lose support then.  Bug: they don't fall when they lose support
that way.  Fix that.

Broken in commit 40eb78e, v4.3.12.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 12:00:18 +01:00
21b8add73e tests/bridgefall: New; exercising splashing of bridges
Stuff sitting on bridges isn't covered, yet.  tests/fire has some.  To
be moved here eventually.

The test exposes bugs.  They're marked "BUG:" in the test input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:51:50 +01:00
964f55794c edit: Fix reporting of no-op unit location change
Report "unchanged" instead of "changed from X,Y to X,Y".  Screwed up
in v4.3.32.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:51:50 +01:00
caf239b3ed tests: Zap setup's news and lost items, like telegrams
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:51:50 +01:00
e44578038f build: Report missing stuff more nicely for bridges
By switching build_nuke() to sector_can_build(), build_charge().

Report missing available work, or else missing materials, or else
missing money, for consistency with the other things you can build.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:51:50 +01:00
1c0315048a build: Report missing stuff more nicely for nukes
By switching build_nuke() to sector_can_build(), build_charge().
Changes reporting of missing stuff to be like for ships, planes and
land units:

* Report missing available work, or else missing materials, or else
  missing money instead of materials, or else money, or else work.

* Report what materials are missing instead of how much materials have
  to be there.

* Clean up stray ';' in reporting of missing work.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:51:50 +01:00
eeb62ab280 build scrap: Redo 4.2.3's fix for manufacturing military
scrap has always returned the scrapped planes' full crew, regardless
of efficiency.  build, however, charged only 10%.  If you built ten
planes with one crew each, you used up one military.  Or none, if you
abused random rounding.  If you scrapped them again, you got ten back.
Pretty pricey way to manufacture military, but wrong all the same.

4.2.3 plugged this hole by making build never round military to zero.
Ugly special case, and not documented.  Also doesn't prevent abuse of
random rounding for planes requiring more than 10 crew, but such
planes don't exist in the stock game.

Redo this fix:

1. Make scrap return crew proportional to efficiency, randomly
rounded.  Note that scrap returns only two thirds of the other
materials, rounded down.  Recycling materials isn't perfect, but
recycling aircrew is.

2. Drop the special case from build: treat military just like other
materials.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:48:34 +01:00
e2d176fd8a build: Report missing stuff more nicely for ship, plane, land units
If both materials and avail are missing, report missing avail instead
of materials, to avoid tempting the player to move in materials only
to discover avail is lacking, too.

Report what materials are missing instead of just "Not enough
materials".  Does not yet include military for planes, but that's
next.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:48:34 +01:00
1227d2c931 build: Stop abuse of construction material random rounding
Construction materials required for building a ship, plane or land
unit are rounded randomly.  Crafty players exploit this to save
materials: they put just enough materials there so that build succeeds
when it rounds down.  Then they simply keep trying until it succeeds.

Planes and land units are built at 10%, so rounding happens when
materials for 100% aren't multiples of ten.  If they're below ten, you
can even build without materials.  In the stock game, this is the case
for linf, and many plane types.

Ships are built at 20%, so multiples of five aren't rounded.  Ship
building never rounds in the stock game.

Prevent the abuse of random rounding by requiring the required
fractional amount rounded up to be present.  Don't change the actual
charging of materials; that's still randomly rounded.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:43 +01:00
bcf11b1371 tests/fire: Rename test scripts for clarity
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:43 +01:00
cdfcc1a165 tests/build: New; exercises build command
drnuke_const is not covered, yet.

Random rounding causes some complications: sometimes build succeeds
without materials.  Troublesome spots are clearly marked in the test
input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:42 +01:00
370b9d1c07 tests: Don't leak telegram counters from setup into test
Moving the telegram files away isn't enough, we also have to reset
nat_tgms.  actofgod/setup-POGO does it already, but fire/setup-POGO
doesn't.  Do it in begin_test instead, right where the telegram files
are moved away.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:42 +01:00
a109de948b Remove option TREATIES
TREATIES has issues:

* Treaties can cover attack, assault, paradrop, board, lboard, fire,
  build (s|p|l|n) and enlist, but not bomb, launch, torpedo and
  enlistment centers.

* Usability is very poor.  While a treaty is in effect, every player
  action that violates a treaty condition triggers a prompt like this:

    This action is in contravention of  treaty #0 (with Curmudgeon)
    Do you wish to go ahead anyway? [yn]

  If you decline, the action is not executed.  If you accept, it is.
  In both cases, your decision is reported in the news.

  You cannot get rid of these prompts until the treaty expires.

* Virtually nobody uses them.

* Virtually unused code is buggy code.  There is at least one race
  condition: multifire() reads the firing sector, ship or land unit
  before the treaty prompt, and writes it back after, triggering a
  generation oops.  Any updates made by other threads while trechk()
  waits for input are wiped out, triggering a seqno mismatch oops.

* The treaty prompts could confuse smart clients that aren't prepared
  for them.  WinACE isn't, but is reported to work anyway at least
  common usage.  Ron Koenderink (the WinACE maintainer) suspects there
  could be a few situations where it will fail.

This feature is not earning its keep.  Remove it.  Drop command
treaty, consider treaty, offer treaty, xdump treaty, reject treaties.
Output of accept changed, obviously.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:14 +01:00
6d2244093a fire: Fix ship retreat when helpless
Two bugs.  First, multifire() checks the condition only for surface
ships, not for submarines.  Second, multifire() neglects to write back
the ship after retreating it.  The player is told the ship retreats,
but it actually stays where it is.

Broken since retreat was added in Chainsaw.  Previous fixes (commit
8065fe8, v4.3.1 and commit de2651e, v4.3.19) "fixed" only the
bulletin.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:24:23 +01:00
30ce78d6df fire: Report which ship or land unit is ready to fire
Just like for sectors.  Useful when multiple ships or land units fire.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:23:13 +01:00
cb05f13c93 fire: Change "Sector X,Y firing" to "Sector X,Y ready to fire"
It's not firing, yet.

While there, trim an unwanted blank line before reporting the first
sector ready.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:19:07 +01:00
196a1292b0 fire: Suppress bulletin when player shells his own ship
Has always been suppressed for shelling own sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:17:00 +01:00
e0cf0c5519 tests/fire: Give all land unit targets SAM cargo
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:16:59 +01:00
96fcb7aa32 tests/fire: Add another salvo at own ship
The existing one does no damage.  Add one that does.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:16:59 +01:00