]> git.pond.sub.org Git - empserver/log
empserver
9 years agonavigate: Fix buffer overrun for impossibly long paths taken
Markus Armbruster [Mon, 22 Dec 2014 14:29:17 +0000 (15:29 +0100)]
navigate: Fix buffer overrun for impossibly long paths taken

When a player moves more than 1023 sectors in a single navigate
command, we overrun the buffer holding the path taken.  Remote hole,
but it requires a ship that can go that far, and even a ship with
speed 1000 would need a tech level well in excess of 1000 for that.
Thus, the hole is purely theoretical for even remotely sane game
configurations.

First known version with the flaw is 4.0.0.

Fix by going back the older behavior: don't print the total path
taken, but do print what the path finder does.  Context diff of an
example:

     [0:634] Command : nav 3 6,0
     Flagship is od   oil derrick (#3)
    +Using path 'n'
      h =
     k . .
      j d
     <67.2:67.2: 6,0> h
     od   oil derrick (#3) stopped at 6,0
    -Path taken: n

This is how march works.

Removes the only use of shp_nav_one_sector()'s unusual return value 2.
Return 1 instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests/navi-march: New; exercises navigate and march command
Markus Armbruster [Sun, 28 Dec 2014 07:03:28 +0000 (08:03 +0100)]
tests/navi-march: New; exercises navigate and march command

Does not cover scattered navigate and march, RAILWAYS 0, enemy action
while sitting at the prompt, and interdiction.

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

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: New helper customize
Markus Armbruster [Sun, 28 Dec 2014 07:01:35 +0000 (08:01 +0100)]
tests: New helper customize

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests/fire: Drop a stale comment
Markus Armbruster [Mon, 22 Dec 2014 09:06:24 +0000 (10:06 +0100)]
tests/fire: Drop a stale comment

Should have been dropped in commit b7bcf8f.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agodoc/econfig: Belatedly drop paragraph on holes in tables
Markus Armbruster [Mon, 22 Dec 2014 09:03:38 +0000 (10:03 +0100)]
doc/econfig: Belatedly drop paragraph on holes in tables

Holes work since commit 7457573, v4.3.28.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Polish error messages
Markus Armbruster [Tue, 18 Feb 2014 19:21:26 +0000 (20:21 +0100)]
xundump: Polish error messages

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoClean up extra semicolon after block
Markus Armbruster [Sun, 16 Feb 2014 08:10:42 +0000 (09:10 +0100)]
Clean up extra semicolon after block

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoempdump: Omit redundant data from export, new -c includes it
Markus Armbruster [Sun, 9 Feb 2014 16:48:36 +0000 (17:48 +0100)]
empdump: Omit redundant data from export, new -c includes it

Cuts size of export files in test suite by a factor of four.  Not a
big deal for disk usage, as export files compress very well, and disk
space is cheap anyway.  Export files are simply easier to work with
when they aren't full of redundant crap.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agofile: New ef_typedstr_eq(), factored out of obj_changed()
Markus Armbruster [Sun, 9 Feb 2014 16:26:44 +0000 (17:26 +0100)]
file: New ef_typedstr_eq(), factored out of obj_changed()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agofile: Rename struct emptypedstr to ef_typedstr
Markus Armbruster [Sun, 9 Feb 2014 16:24:10 +0000 (17:24 +0100)]
file: Rename struct emptypedstr to ef_typedstr

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Permit omitting non-trailing realms
Markus Armbruster [Sun, 9 Feb 2014 09:20:15 +0000 (10:20 +0100)]
xundump: Permit omitting non-trailing realms

This involves computing the realm ID from fields cnum, realm.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Permit omitting non-trailing sectors
Markus Armbruster [Sun, 9 Feb 2014 09:01:59 +0000 (10:01 +0100)]
xundump: Permit omitting non-trailing sectors

This involves computing the sector ID from fields xloc, yloc.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Eliminate global cur_obj
Markus Armbruster [Sat, 8 Feb 2014 18:28:30 +0000 (19:28 +0100)]
xundump: Eliminate global cur_obj

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Code motion to clean up after previous commit
Markus Armbruster [Sat, 8 Feb 2014 17:25:49 +0000 (18:25 +0100)]
xundump: Code motion to clean up after previous commit

The previous commit avoided code motion to ease review.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Don't require ID field to come first
Markus Armbruster [Sat, 8 Feb 2014 16:51:37 +0000 (17:51 +0100)]
xundump: Don't require ID field to come first

The code needs it first so it can store field values into the object
right away.  Save the values instead, and store them when the row is
complete.

The improvement is hardly worth the trouble by itself, but it'll
simplify supporting keys consisting of multiple fields, like sector
xloc, yloc or realm cnum, realm, so we can omit rows in those tables,
too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Eliminate global may_trunc, may_omit_id
Markus Armbruster [Sat, 8 Feb 2014 15:52:14 +0000 (16:52 +0100)]
xundump: Eliminate global may_trunc, may_omit_id

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Permit omitting trailing sectors and realms
Markus Armbruster [Sat, 8 Feb 2014 14:11:51 +0000 (15:11 +0100)]
xundump: Permit omitting trailing sectors and realms

We currently require all rows to be present for tables item, sect-chr,
infrastructure, sect, realm.

The first three make sense: the code hard-codes indexes for them, and
malfunctions when entries are blank, so we want to make it hard to
leave any blank by accident.

The last two don't: blank sectors and realms work fine.  There, the
restriction is arbitrary.  Drop it.

Sectors and realms still can't be omitted "in the middle" (can do that
only with an ID selector), but that's coming soon.

See also commit 4a4ec91.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Support splitting any table
Markus Armbruster [Sat, 8 Feb 2014 11:16:34 +0000 (12:16 +0100)]
xundump: Support splitting any table

Each part of a split table needs to supply rows for the same objects.
We currently require each part to name its objects explicitly, with an
object ID field, and don't support splitting tables that don't have
such IDs.  These restrictions became arbitrary when commit 4e23c45
implemented checking each partial table supplies the same rows.  Relax
them.

Affects tables sect, news, lost, realm, game, infrastructure.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxundump: Report all missing fields, not just first one
Markus Armbruster [Sun, 2 Feb 2014 11:24:22 +0000 (12:24 +0100)]
xundump: Report all missing fields, not just first one

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agonsc: Turn NSC_HIDDEN into a flag
Markus Armbruster [Sun, 2 Feb 2014 11:09:18 +0000 (12:09 +0100)]
nsc: Turn NSC_HIDDEN into a flag

More general, and fewer places need to know about it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agonsc: Reject array selectors in conditions
Markus Armbruster [Sun, 2 Feb 2014 09:29:18 +0000 (10:29 +0100)]
nsc: Reject array selectors in conditions

Array selectors were introduced for xdump (commit 612f2da, v4.2.18).
Since there is no syntax for subscripting arrays in conditions and
survey, we silently assume index zero.  Unclean.  Reject the selector
instead.

Affects ship selectors cargostart, cargoend, amtstart, amtend (since
commit 32011f1, v4.2.19), nat selectors relations (commit 0a44c48,
v4.3.0), contacts (commit c345ab8, v4.3.0), rejects (commit 6844c94,
v4.3.4).  The other array selectors aren't visible in conditions.  No
array selectors are visible in survey.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agonsc: Turn common patterns into CA_IS_ARRAY() and CA_ARRAY_LEN()
Markus Armbruster [Sun, 2 Feb 2014 09:13:41 +0000 (10:13 +0100)]
nsc: Turn common patterns into CA_IS_ARRAY() and CA_ARRAY_LEN()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agonsc: Rename nstr_exec_val() to nstr_eval() and tighten contract
Markus Armbruster [Sun, 2 Feb 2014 08:39:35 +0000 (09:39 +0100)]
nsc: Rename nstr_exec_val() to nstr_eval() and tighten contract

nstr_exec_val() can produce three different error values: NSC_NOTYPE
on invalid category, invalid type with zero val_as.lng on invalid type
(this is a bug), and the wanted type with zero val_s when it can't
coerce.  None of these should ever happen.

Fix it to always produce an NSC_NOTYPE error value.  Fix up callers to
check for it.

Specify the result's type is promoted on success.  Ensure it is even
when the argument is NSC_VAL with an unpromoted type, which is
invalid.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
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>