]> git.pond.sub.org Git - empserver/log
empserver
9 years agotests/empdump: New; exercising the empdump utility
Markus Armbruster [Wed, 29 Jan 2014 19:24:26 +0000 (20:24 +0100)]
tests/empdump: New; exercising the empdump utility

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: New helper cmp_out1
Markus Armbruster [Wed, 29 Jan 2014 20:09:04 +0000 (21:09 +0100)]
tests: New helper cmp_out1

Factor out of cmp_out, then make it optionally take an explicit
expected result.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests/files tests/fairland: Check stderr and exit status
Markus Armbruster [Wed, 29 Jan 2014 19:12:18 +0000 (20:12 +0100)]
tests/files tests/fairland: Check stderr and exit status

New helper run_and_cmp to automate the job: run a program capturing
its standard output, standard error and exit status, then compare the
actual with the expected results.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Fix missing local in feed_files and cmp_out
Markus Armbruster [Wed, 29 Jan 2014 19:11:25 +0000 (20:11 +0100)]
tests: Fix missing local in feed_files and cmp_out

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Simplify running cmp_out more than once
Markus Armbruster [Wed, 29 Jan 2014 18:56:38 +0000 (19:56 +0100)]
tests: Simplify running cmp_out more than once

When cmp_out detects a test failure, it returns non-zero status, which
terminates the test script unless caught.

Accumulate failures in a global variable checked at exit instead, so
running it multiple times in a test script just works.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Feed only logs and xdump to normalize.pl
Markus Armbruster [Tue, 28 Jan 2014 19:33:19 +0000 (20:33 +0100)]
tests: Feed only logs and xdump to normalize.pl

Feeding other test output files (right now tests/files/files.out
tests/fairland/fairland.out fairland/newcap_script) works, but it's
odd, and might not work as well for all future output files.  Only
strip trailing white space there.

There used to be other output files that required normalize.pl: client
output.  Gone since commit 9ca3fa9.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Define and use some abbreviations
Markus Armbruster [Tue, 28 Jan 2014 18:29:11 +0000 (19:29 +0100)]
tests: Define and use some abbreviations

No functional change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agofile: Provide EF_WITH_CADEF_MAX_ENTRY_SIZE to clean up xditem()
Markus Armbruster [Mon, 27 Jan 2014 19:57:20 +0000 (20:57 +0100)]
file: Provide EF_WITH_CADEF_MAX_ENTRY_SIZE to clean up xditem()

xditem() needs a buffer that can hold entries of any xdumpable table.
It's been 2048 bytes and marked FIXME since day one.  Clean it up so
that if anyone ever goes crazy with entry sizes, we fail an assertion
during startup instead of overrunning the buffer during play.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoplayer: Drop long-disabled code to resolve IP addresses
Markus Armbruster [Mon, 27 Jan 2014 19:28:39 +0000 (20:28 +0100)]
player: Drop long-disabled code to resolve IP addresses

Disabled since commit 32fac04 (v4.2.13) because it could at the time
use more stack space than we provided.  Additional issues: code still
uses obsolete gethostbyaddr() rather than getnameinfo(), and we
provide only 512 bytes for host names instead of the customary
NI_MAXHOST (1025) bytes.

All three issues would be easy enough to fix.  What's not so easy is
to avoid blocking on the synchronous DNS lookup.  Without that,
connecting repeatedly from a range of addresses with slow reverse
lookup could conceivably be employed as a denial of service attack.

We've been living without reverse lookup for close to ten years.  Bury
the corpse, and move on.

Bonus: sizeof(struct natstr) is cut in half.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agonat: Deprecate selector hostname, fix value to ""
Markus Armbruster [Mon, 27 Jan 2014 19:03:29 +0000 (20:03 +0100)]
nat: Deprecate selector hostname, fix value to ""

Its value has always been "", unless the deity recompiled with
RESOLVE_IPADDRESS defined, or imported another value with empdump.

I'm going to drop the RESOLVE_IPADDRESS code, including struct natstr
member nat_hostname.  To prepare for that, fix the selector's value to
"", so it doesn't need nat_hostname, and deprecate it.

This changes its "len" in xdump meta nat from 512 to 0.  Unlikely to
upset clients.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Clean up lazy coding limiting string length to 65536
Markus Armbruster [Mon, 27 Jan 2014 18:44:44 +0000 (19:44 +0100)]
xundump: Clean up lazy coding limiting string length to 65536

Can't just replace the literal 65536 by INT_MAX, because my system's
vfprintf() rejects that with EOVERFLOW.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxdump: Avoid undefined pointer arithmetic
Markus Armbruster [Mon, 27 Jan 2014 17:56:05 +0000 (18:56 +0100)]
xdump: Avoid undefined pointer arithmetic

s + n is defined only as long as it points into or just beyond the
same array as s.  Thus, our use of INT_MAX for "unlimited" relies on
undefined behavior.  Works fine in practice, but avoiding undefined
pointer arithmetic isn't hard here, so let's do it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Refuse to undump strings too long for terminating null
Markus Armbruster [Mon, 27 Jan 2014 16:52:32 +0000 (17:52 +0100)]
xundump: Refuse to undump strings too long for terminating null

We're dealing with three kinds of string storage: char * pointing to a
null-terminated string, char[] holding a null-terminated string, and
char holding a string of length 0 or 1.

Unfortunately, xdump meta data doesn't distinguish the latter two:
both are NSC_STRINGY.  Because of that, xundump happily fills char[]
to the limit, producing strings that aren't null-terminated, resulting
in read beyond buffer and possibly worse.

Affects struct shpstr members shp_path, shp_name, shp_rpath, struct
lndstr member lnd_rpath, and struct natstr members nat_cnam, nat_pnam,
nat_hostaddr, nat_hostname, nat_userid.  Since these are all in game
state, only the empdump utility program is affected, not the
configuration table reader.

We clearly need to require null-termination for char[] values.  Since
using char[1] for null-terminated strings makes no sense, we can still
make NSC_STRINGY with length 1 serve char values as before, by
permitting non-null-terminated strings only when length is 1.  Ugly
wart, but it fixes the bug without a possibly awkward change xdump
meta-data.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Factor out lnd_mar_put_one()
Markus Armbruster [Sat, 25 Jan 2014 15:38:34 +0000 (16:38 +0100)]
subs: Factor out lnd_mar_put_one()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Factor out shp_nav_put_one()
Markus Armbruster [Sat, 25 Jan 2014 15:14:53 +0000 (16:14 +0100)]
subs: Factor out shp_nav_put_one()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Use lnd_put_one() in lnd_put(), lnd_mar_put()
Markus Armbruster [Sat, 25 Jan 2014 15:13:52 +0000 (16:13 +0100)]
subs: Use lnd_put_one() in lnd_put(), lnd_mar_put()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Rename lnd_delete() to lnd_put_one()
Markus Armbruster [Sat, 25 Jan 2014 15:11:53 +0000 (16:11 +0100)]
subs: Rename lnd_delete() to lnd_put_one()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Rename shp_put() to shp_nav_put()
Markus Armbruster [Sat, 25 Jan 2014 15:05:07 +0000 (16:05 +0100)]
subs: Rename shp_put() to shp_nav_put()

For consistency with lnd_mar_put().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Split lnd_mar_put() off lnd_put() and specialize
Markus Armbruster [Sat, 25 Jan 2014 14:57:12 +0000 (15:57 +0100)]
subs: Split lnd_mar_put() off lnd_put() and specialize

lnd_put() serves two masters: march, which wants it to report
"stopped" and write back struct ulist member mobility to
unit.land.lnd_mobil, and ground combat, which doesn't.

lnd_put() assumes march when actor is non-zero.  Correct (but see
commit 8c502d4).  Dates back to Empire 2.

Too ugly for my taste.  Specialize for each master instead:
lnd_mar_put() for march, and lnd_put() for ground combat.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Split unit_put() into shp_put() and lnd_put() again
Markus Armbruster [Sat, 25 Jan 2014 14:41:58 +0000 (15:41 +0100)]
subs: Split unit_put() into shp_put() and lnd_put() again

Commit d94d269 combined them into unit_put(), but that has turned out
not to be useful.  Split them again.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Factor lnd_insque() out of lnd_sel(), ask_olist(), ...
Markus Armbruster [Sat, 25 Jan 2014 09:44:50 +0000 (10:44 +0100)]
subs: Factor lnd_insque() out of lnd_sel(), ask_olist(), ...

... get_dlist(), att_reacting_units().

This loses malloc() error checking in ask_olist() and get_dlist().  No
great loss, because we don't check in so many other places, including
att_reacting_units().  We should use a wrapper that terminates on
error, though.  Left for another day.

ask_olist(), get_dlist() and att_reacting_units() zero the struct
ulist with memset().  lnd_insque() doesn't, so these functions need to
zero any members not otherwise initialized explicitly now.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Set struct ulist member supplied properly for attackers
Markus Armbruster [Sat, 25 Jan 2014 09:42:22 +0000 (10:42 +0100)]
subs: Set struct ulist member supplied properly for attackers

It's set to zero via memset().  Incorrect, but harmless, because it's
not actually used.  Correct it anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agounit: Fix comments on struct ulist member use
Markus Armbruster [Sat, 25 Jan 2014 09:18:04 +0000 (10:18 +0100)]
unit: Fix comments on struct ulist member use

Members x, y, eff, supplied are not "LAND only", they're used only by
ground combat.  They're not used by march.

In ground combat, member mobil is not how much the land unit has left,
it's how much it still needs to be charged.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs: Factor shp_insque() out of shp_sel(), shp_missdef(), ...
Markus Armbruster [Sat, 25 Jan 2014 07:49:02 +0000 (08:49 +0100)]
subs: Factor shp_insque() out of shp_sel(), shp_missdef(), ...

... nav_ship(), fltp_to_list().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoRemove superfluous override directive in make check
Gerd Flaig [Fri, 2 Jan 2015 18:29:41 +0000 (19:29 +0100)]
Remove superfluous override directive in make check

Travis CI and OS X system make on 10.9.x at least don't have GNU make
>=3.82 which contains a parser enhancement that allows multiple
directives.

Signed-off-by: Gerd Flaig <gefla@pond.sub.org>
Here's why removing override is a good idea.  The variable assignment
should already override anything Make may find in its environment.
All "override" does is protect against unwise make arguments.

"info make" says:

    The `override' directive was not invented for escalation in the war
    between makefiles and command arguments.  It was invented so you can
    alter and add to values that the user specifies with command
    arguments.

Thus, override is ill-advised here.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/build: Clean up setup a bit
Markus Armbruster [Sun, 26 Jan 2014 09:47:53 +0000 (10:47 +0100)]
tests/build: Clean up setup a bit

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/fire: Clean up setup a bit
Markus Armbruster [Sun, 26 Jan 2014 09:43:57 +0000 (10:43 +0100)]
tests/fire: Clean up setup a bit

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/actofgod: Switch setup from deprecated setsect to edit
Markus Armbruster [Sun, 26 Jan 2014 09:23:00 +0000 (10:23 +0100)]
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>
10 years agoattsub: Clean up take_casualty() a bit
Markus Armbruster [Sat, 25 Jan 2014 10:40:04 +0000 (11:40 +0100)]
attsub: Clean up take_casualty() a bit

Giving biggest the appropriate type saves a type cast.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotrade: Clean up type of trdswitchown()'s second parameter
Markus Armbruster [Sat, 25 Jan 2014 10:28:05 +0000 (11:28 +0100)]
trade: Clean up type of trdswitchown()'s second parameter

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoClean up casts from union empobj_storage * to struct empobj *
Markus Armbruster [Sat, 25 Jan 2014 10:25:43 +0000 (11:25 +0100)]
Clean up casts from union empobj_storage * to struct empobj *

Take the address of member gen instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoClean up casts from struct FOO * to struct emp_qelem *
Markus Armbruster [Sat, 25 Jan 2014 10:17:09 +0000 (11:17 +0100)]
Clean up casts from struct FOO * to struct emp_qelem *

Take the address of the queue member instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agopathfind: Fix up comment for commit 92e64d7
Markus Armbruster [Sat, 25 Jan 2014 10:08:43 +0000 (11:08 +0100)]
pathfind: Fix up comment for commit 92e64d7

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoClean up superfluous includes
Markus Armbruster [Wed, 22 Jan 2014 20:27:32 +0000 (21:27 +0100)]
Clean up superfluous includes

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoretreat: Move function declarations to retreat.h
Markus Armbruster [Wed, 22 Jan 2014 20:24:36 +0000 (21:24 +0100)]
retreat: Move function declarations to retreat.h

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoretreat: Clean up interface between retreat_FOO(), retreat_FOO1()
Markus Armbruster [Wed, 22 Jan 2014 19:56:53 +0000 (20:56 +0100)]
retreat: Clean up interface between retreat_FOO(), retreat_FOO1()

Move clearing of retreat flags from retreat_ship(), retreat_land() to
retreat_ship1(), retreat_land1(), so it's where the retreat path is
shortened.

Move putship(), putland() from retreat_ship1(), retreat_land1() to
retreat_ship(), retreat_land(), so it's where the nxtitem() is, and
doesn't need a "if (!orig)" guard.  Requires making retreat_ship1()
and retreat_land() return non-zero when they modified their argument.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoretreat: Don't consume a retreat direction that wasn't followed
Markus Armbruster [Wed, 22 Jan 2014 19:46:53 +0000 (20:46 +0100)]
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>
10 years agoretreat: Reject invalid retreat paths
Markus Armbruster [Wed, 22 Jan 2014 18:26:24 +0000 (19:26 +0100)]
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>
10 years agoretreat: Fail without charging BTUs when given no conditions
Markus Armbruster [Tue, 21 Jan 2014 21:07:12 +0000 (22:07 +0100)]
retreat: Fail without charging BTUs when given no conditions

Return RET_SYN instead of RET_FAIL then.  Also drop the error message;
the usage help printed for RET_SYN should do.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoretreat: Fix infinite loop when third argument contains '?'
Markus Armbruster [Tue, 21 Jan 2014 20:05:50 +0000 (21:05 +0100)]
retreat: Fix infinite loop when third argument contains '?'

Broken in commit bb5dfd8, v4.3.16.  Fix by recognizing '?' only when
getting the argument interactively.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoretreat: Don't charge mobility for retreating in direction 'h'
Markus Armbruster [Tue, 21 Jan 2014 19:04:20 +0000 (20:04 +0100)]
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>
10 years agoretreat: Drop useless write back on failed retreat
Markus Armbruster [Mon, 20 Jan 2014 22:15:29 +0000 (23:15 +0100)]
retreat: Drop useless write back on failed retreat

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoretreat: Don't retreat the current player's ships or land units
Markus Armbruster [Mon, 20 Jan 2014 22:12:31 +0000 (23:12 +0100)]
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>
10 years agoretreat: Don't report a destroyed ship/land unit couldn't retreat
Markus Armbruster [Mon, 20 Jan 2014 21:51:11 +0000 (22:51 +0100)]
retreat: Don't report a destroyed ship/land unit couldn't retreat

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoretreat: Oops on retreating ghosts
Markus Armbruster [Mon, 20 Jan 2014 21:44:54 +0000 (22:44 +0100)]
retreat: Oops on retreating ghosts

Code never actually retreated them, but it could zap their mission and
retreat flags.  Harmless, but avoid it anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoshpsub: Make shp_check_nav() return more useful information
Markus Armbruster [Mon, 20 Jan 2014 21:34:17 +0000 (22:34 +0100)]
shpsub: Make shp_check_nav() return more useful information

Some callers have to second-guess shp_check_nav() to figure out
whether CN_LANDLOCKED means "too big to fit into the canal" or "can't
go there at all".

Fix that by returning d_navigation.  CN_LANDLOCKED becomes either
NAV_CANAL or NAV_NONE, CN_CONSTRUCTION becomes either NAV_02 or
NAV_60, and CN_NAVIGABLE becomes NAVOK.

The CN_NAVIGABLE, ... codes are now unused.  Drop them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoDelete trivial instances of /*NOTREACHED*/
Markus Armbruster [Mon, 20 Jan 2014 21:30:56 +0000 (22:30 +0100)]
Delete trivial instances of /*NOTREACHED*/

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoshpsub: Move declarations to ship.h
Markus Armbruster [Mon, 20 Jan 2014 21:20:21 +0000 (22:20 +0100)]
shpsub: Move declarations to ship.h

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoretreat: Retreat groups in a more sensible order
Markus Armbruster [Mon, 20 Jan 2014 20:47:17 +0000 (21:47 +0100)]
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>
10 years agoretreat: Clear mission only when ship or land unit moves
Markus Armbruster [Mon, 20 Jan 2014 20:05:57 +0000 (21:05 +0100)]
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>
10 years agoretreat: Fix stack smash in land unit group retreat
Markus Armbruster [Mon, 20 Jan 2014 19:28:17 +0000 (20:28 +0100)]
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>
10 years agotests/fire: Drop test of ship retreat
Markus Armbruster [Mon, 20 Jan 2014 18:56:30 +0000 (19:56 +0100)]
tests/fire: Drop test of ship retreat

Now covered in tests/retreat.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/retreat: New; exercising retreat
Markus Armbruster [Sun, 19 Jan 2014 18:51:22 +0000 (19:51 +0100)]
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>
10 years agoedit: Keep missions centered on unit centered when teleporting
Markus Armbruster [Sun, 19 Jan 2014 15:41:50 +0000 (16:41 +0100)]
edit: Keep missions centered on unit centered when teleporting

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/actofgod: Show moving units with edit doesn't affect mission
Markus Armbruster [Sun, 19 Jan 2014 15:28:17 +0000 (16:28 +0100)]
tests/actofgod: Show moving units with edit doesn't affect mission

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests: Save diff -u between expected and actual output
Markus Armbruster [Sun, 19 Jan 2014 09:39:00 +0000 (10:39 +0100)]
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>
10 years agotests/fire: Drop test of falling bridges
Markus Armbruster [Sat, 18 Jan 2014 15:54:51 +0000 (16:54 +0100)]
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>
10 years agotests/fire: Drop test of units tumbling down with bridges
Markus Armbruster [Sat, 18 Jan 2014 15:34:07 +0000 (16:34 +0100)]
tests/fire: Drop test of units tumbling down with bridges

Now covered in tests/bridgefall.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/fire: Protect against unintended shelling to deity
Markus Armbruster [Sat, 18 Jan 2014 15:32:39 +0000 (16:32 +0100)]
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>
10 years agotests/bridgefall: Cover units tumbling down with bridges
Markus Armbruster [Sat, 18 Jan 2014 12:23:46 +0000 (13:23 +0100)]
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>
10 years agoedit: Fix edit s key 'U' to preserve "does not follow"
Markus Armbruster [Sat, 18 Jan 2014 11:24:29 +0000 (12:24 +0100)]
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>
10 years agoedit: Make edit l key 'L' preserve "no dist center"
Markus Armbruster [Sat, 18 Jan 2014 11:20:11 +0000 (12:20 +0100)]
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>
10 years agoedit: Fix edit l key 'L' not to mess up coastal flag
Markus Armbruster [Sat, 18 Jan 2014 11:14:02 +0000 (12:14 +0100)]
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>
10 years agotests/actofgod: Show edit l key 'L' mess up coastal flag
Markus Armbruster [Sat, 18 Jan 2014 11:12:10 +0000 (12:12 +0100)]
tests/actofgod: Show edit l key 'L' mess up coastal flag

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoSuppress duplicates in output of git ls-files
Markus Armbruster [Sat, 18 Jan 2014 11:10:50 +0000 (12:10 +0100)]
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>
10 years agotests/fire: Use build command for setup
Markus Armbruster [Sat, 18 Jan 2014 10:17:49 +0000 (11:17 +0100)]
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>
10 years agotests/bridgefall: Use build command for setup
Markus Armbruster [Sat, 18 Jan 2014 11:33:11 +0000 (12:33 +0100)]
tests/bridgefall: Use build command for setup

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/actofgod: Use build command for setup
Markus Armbruster [Sat, 18 Jan 2014 09:58:57 +0000 (10:58 +0100)]
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>
10 years agotests/build: Use build command for setup
Markus Armbruster [Sat, 18 Jan 2014 09:56:56 +0000 (10:56 +0100)]
tests/build: Use build command for setup

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agobuild: Reword bridge next to land messages to mention the sector
Markus Armbruster [Sat, 18 Jan 2014 09:50:16 +0000 (10:50 +0100)]
build: Reword bridge next to land messages to mention the sector

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agobuild: Deities build ex nihilo
Markus Armbruster [Sat, 18 Jan 2014 09:26:49 +0000 (10:26 +0100)]
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>
10 years agobridgefall: Factor bridge_support_at() out of bridgefall()
Markus Armbruster [Sat, 18 Jan 2014 08:10:21 +0000 (09:10 +0100)]
bridgefall: Factor bridge_support_at() out of bridgefall()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agobridgefall: Fix loss of bridge support with EASY_BRIDGES off
Markus Armbruster [Fri, 17 Jan 2014 19:54:27 +0000 (20:54 +0100)]
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>
10 years agobridgefall: Fix support loss with EASY_BRIDGES and BRIDGETOWERS on
Markus Armbruster [Fri, 17 Jan 2014 19:50:58 +0000 (20:50 +0100)]
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>
10 years agoRevert "Remove dead EASY_BRIDGES code from bridgefall()"
Markus Armbruster [Fri, 17 Jan 2014 19:31:32 +0000 (20:31 +0100)]
Revert "Remove dead EASY_BRIDGES code from bridgefall()"

This reverts commit df62b8604d7607947131a9d4c04a92d08954ca34.

The next commit will revive that code.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agobridgefall: Fix harmless coordinate normalization bug
Markus Armbruster [Fri, 17 Jan 2014 18:28:03 +0000 (19:28 +0100)]
bridgefall: Fix harmless coordinate normalization bug

bridgefall() wants to do this:

    for all possible pairs of directions (i, j)
        if i and j cancel out
    continue
do stuff

It does it by adding direction offsets to start coordinates, and
comparing the resulting coordinates to the start coordinates.  Fine,
except it neglects to normalize the resulting coordinates.

Harmless in practice, because you can get an incorrect result only
when the path goes around the world, which it can do only in a 4x2
world.

Fix it anyway, by testing "directions cancel out" directly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agopath: New DIR_BACK()
Markus Armbruster [Fri, 17 Jan 2014 17:49:48 +0000 (18:49 +0100)]
path: New DIR_BACK()

Actually pathfind.c's rev_dir() turned into a macro, to make it
available elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/bridgefall: New; exercising splashing of bridges
Markus Armbruster [Thu, 16 Jan 2014 20:59:41 +0000 (21:59 +0100)]
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>
10 years agoedit: Fix reporting of no-op unit location change
Markus Armbruster [Tue, 14 Jan 2014 22:26:06 +0000 (23:26 +0100)]
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>
10 years agotests: Zap setup's news and lost items, like telegrams
Markus Armbruster [Tue, 14 Jan 2014 20:48:38 +0000 (21:48 +0100)]
tests: Zap setup's news and lost items, like telegrams

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agobuild: Report missing stuff more nicely for bridges
Markus Armbruster [Mon, 13 Jan 2014 08:23:26 +0000 (09:23 +0100)]
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>
10 years agobuild: Report missing stuff more nicely for nukes
Markus Armbruster [Sun, 12 Jan 2014 22:00:38 +0000 (23:00 +0100)]
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>
10 years agobuild scrap: Redo 4.2.3's fix for manufacturing military
Markus Armbruster [Sun, 12 Jan 2014 17:40:45 +0000 (18:40 +0100)]
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>
10 years agobuild: Report missing stuff more nicely for ship, plane, land units
Markus Armbruster [Sun, 12 Jan 2014 17:33:13 +0000 (18:33 +0100)]
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>
10 years agobuild: Stop abuse of construction material random rounding
Markus Armbruster [Sun, 12 Jan 2014 17:24:06 +0000 (18:24 +0100)]
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>
10 years agobuild: Factor code out of build_ship(), build_plane(), build_land()
Markus Armbruster [Sun, 12 Jan 2014 17:13:15 +0000 (18:13 +0100)]
build: Factor code out of build_ship(), build_plane(), build_land()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/fire: Rename test scripts for clarity
Markus Armbruster [Sun, 12 Jan 2014 15:00:13 +0000 (16:00 +0100)]
tests/fire: Rename test scripts for clarity

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agotests/build: New; exercises build command
Markus Armbruster [Sun, 12 Jan 2014 14:57:22 +0000 (15:57 +0100)]
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>
10 years agotests: Don't leak telegram counters from setup into test
Markus Armbruster [Sun, 12 Jan 2014 08:30:54 +0000 (09:30 +0100)]
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>
10 years agoRemove option TREATIES
Markus Armbruster [Sat, 11 Jan 2014 17:02:53 +0000 (18:02 +0100)]
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>
10 years agoconsider: Clean up "either treaty or loan" assumptions
Markus Armbruster [Sat, 11 Jan 2014 16:10:20 +0000 (17:10 +0100)]
consider: Clean up "either treaty or loan" assumptions

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoconsider: Clean up recovery from an impossible error
Markus Armbruster [Sat, 11 Jan 2014 16:03:49 +0000 (17:03 +0100)]
consider: Clean up recovery from an impossible error

Drop the unhelpful message to the player, and fail the command.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agoaccept: rejectname() makes no sense outside acce(); inline
Markus Armbruster [Sat, 11 Jan 2014 14:23:26 +0000 (15:23 +0100)]
accept: rejectname() makes no sense outside acce(); inline

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agofire: Fix ship retreat when helpless
Markus Armbruster [Wed, 8 Jan 2014 18:16:21 +0000 (19:16 +0100)]
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>
10 years agofire: Report which ship or land unit is ready to fire
Markus Armbruster [Wed, 8 Jan 2014 07:14:43 +0000 (08:14 +0100)]
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>
10 years agofire: Change "Sector X,Y firing" to "Sector X,Y ready to fire"
Markus Armbruster [Wed, 8 Jan 2014 07:11:27 +0000 (08:11 +0100)]
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>
10 years agofire: Drop useless special case "shp_fire() returns zero"
Markus Armbruster [Tue, 7 Jan 2014 20:52:32 +0000 (21:52 +0100)]
fire: Drop useless special case "shp_fire() returns zero"

Can't actually happen with the current damage formulas.  If it could,
then the special treatment would be inconsistent with sectors and land
units.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agofire: Check land unit guns earlier, drop useless checks
Markus Armbruster [Tue, 7 Jan 2014 20:48:37 +0000 (21:48 +0100)]
fire: Check land unit guns earlier, drop useless checks

We check all necessary conditions for being able to fire before
prompting for a target.  Except for land unit guns.  Clean that up.

fort_fire(), shp_fire() or lnd_fire() fail only when the fort, ship or
land unit can't fire.  If that happens, our checking is incomplete.
Oops then.

We recheck some of the necessary conditions after getting the target.
However, because the command fails when the firing sector, ship or
land unit has changed since the first check, these rechecks can't
fail.  Drop them.

Note that the rechecks were just as useless before commit 66165f3
fixed fire to fail on change, because they rechecked the unchanged
cached copy instead of the possibly changed original.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
10 years agofire: Suppress bulletin when player shells his own ship
Markus Armbruster [Tue, 7 Jan 2014 19:50:42 +0000 (20:50 +0100)]
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>
10 years agotests/fire: Give all land unit targets SAM cargo
Markus Armbruster [Tue, 7 Jan 2014 19:49:26 +0000 (20:49 +0100)]
tests/fire: Give all land unit targets SAM cargo

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>