Commit graph

4416 commits

Author SHA1 Message Date
809a4e2321 Fix read beyond end of conditional argument on missing operand
nstr_parse_val() interprets argument "" as (empty) identifier, then
returns a pointer right beyond the end of the string.

The argument points into player->argbuf[].  If another argument
follows the conditional, it gets appended to the conditional.  Else,
whatever's left there from previous commands gets appended.  If the
argument is at the very end of player->argbuf[], we parse beyond the
buffer, until we run into a syntax error, or a zero byte.

Since player->argbuf[] is followed by a bunch of pointers, a syntax
error is almost certain.  If we somehow manage to parse all the
pointers and player->lasttime, the runaway parse will end at
player->btused, because that's definitely zero when conditionals get
parsed.
2013-05-12 18:53:29 +02:00
59a199c69d Don't put broken links in HTML info pages
Pass the valid info page names to emp2html.pl, and convert only valid
references to links there.
2013-05-12 18:53:02 +02:00
7a730be185 Tighten up emp2html's info reference recognition
Combine the two loops looking for \*QNAME\*U and "info NAME" into one.
Recognize "info NAME" only with the closing '"' to be present.

No change with current info sources.
2013-05-12 18:52:58 +02:00
955bdeb223 Fold subj2html.pl into emp2html.pl 2013-05-11 16:04:11 +02:00
320c8072fc Update change log for 4.3.31 2013-05-08 20:46:00 +02:00
9b0b0dc772 Permit ships that can drop depth charges, but not fire
No such ships exist in the stock game.
2013-05-08 20:43:54 +02:00
92a502df0b Consistently require guns for dropping depth charges
The fire command requires at least one gun for depth charging, but
missions and return fire don't.  Has always been that way, except
between 4.0.6 and commit a3ad623 (v4.3.12), when depth charging worked
exactly like gun fire, and guns were consistently required.

Require guns for all ways to drop depth charges.
2013-05-08 20:37:36 +02:00
b440ee4b84 Cover configure reporting "terminfo: no" in READMEs 2013-05-08 19:19:12 +02:00
afb4761a57 Cast time_t to long for printing with %ld
struct timeval member tv_sec used to be long, but POSIX made it
time_t.
2013-05-08 19:13:38 +02:00
2af8d77920 Include <sys/time.h> in lwp.h
Missed in commit 08b9455, v4.3.20.  Triggers compiler warnings on
NetBSD 5.1.2.
2013-05-08 14:35:04 +02:00
fded50a09c Refresh autoconf macros from autoconf-archive-2013.04.06 2013-05-08 14:35:04 +02:00
fad8e7f7b9 Move auxiliary build tools to build-aux/ 2013-05-08 14:35:04 +02:00
da7bc94a34 Refresh auxiliary build tools from automake 1.11.6 2013-05-08 14:35:04 +02:00
81a3e4c4fb Change econfig key rollover_avail_max from 0 to 50
So you don't have to micromanage workers to maximize useful work.

The previous commit made the problem a bit worse.  If you had a few
workers too many before, you perhaps produced an extra unit.  Now, you
get to keep the extra work instead.  Useless, unless it rolls over.
2013-05-08 14:35:04 +02:00
6f7c93cdad Make sector production more predictable
produce() limits production to how many units the workers can produce,
rounding randomly.  It charges work for the units actually produced,
discarding fractions.

If you get lucky with the random rounding, you may get a bit of extra
work done for free.  Else, you get to keep the unused work, and may
even be undercharged a tiny bit of work.  Has always been that way.

The production command assumes the random rounding rounds up if and
only if the probability to do so is at least 50%.  Thus, it's
frequently off by one for sectors producing at their worker limit.

The budget command runs the update code, and is therefore also off by
one, only differently.

Rather annoying for tech and research centers, where a single unit
matters.  A tech center with full civilian population can produce 37.5
units in 60 etus.  Given enough materials, it'll fluctuate between 37
and 38.  Production consistently predicts 38, and budget randomly
predicts either 37 or 38.  Both are off by one half the time.

Fix this as follows: limit production to the amount the workers can
produce (no rounding).  Work becomes a hard limit, not subject to
random fluctuations.  Randomly round the work charged for actual
production.  On average, this charges exactly the work that's used.

More importantly, production and budget now predict how much gets
produced more accurately.  They're still not exact, as the amount of
work available for production remains slightly random.

This also "fixes" the smoke test on a i686 Debian 6 box for me.  The
root problem is that floating-point subexpressions may either be
computed in double precision or extended precision.  Different
machines (or different compilers, or even different compiler flags)
may use different precision, and get different results.

Example: producing 108 units at one work per unit, sector p.e. 0.4
needs to charge 108 / 0.4 work.  Computed in double precision, this
gets rounded to 270.0, then truncated to 270.  In 80 bit extended
precision, it gets rounded to 269.999999999, then truncated to 269.

With random rounding instead of truncation, the probability for a
different result is vanishingly small.  However, this commit
introduces truncation in another place.  It just happens not to mess
up the smoke test there.  I doubt this is the last time this kind of
problem upsets the smoke test.
2013-05-08 14:23:50 +02:00
739852dd3f Rearrange produce() and prod() a bit to make them more similar 2013-05-08 06:57:58 +02:00
ba2600e7db Factor prod_resource_limit() out of produce() and prod() 2013-05-08 06:57:58 +02:00
ec60098c36 Avoid double rounding materials when limiting products made
We can make actual = roundavg(material_consume * prodeff) products.

When we reduce actual, we have to reduce material_consume, too.  Code
does that like this:

    material_consume = roundavg(actual' * material_consume / actual)

Double rounding.  Do this instead:

    material_consume = roundavg(actual' / prodeff)
2013-05-08 06:57:58 +02:00
87b29f784d Use ITEM_MAX instead of 9999 as production material limit
No functional change, as ITEM_MAX is 9999, just cleaner.
2013-05-08 06:57:58 +02:00
f0927e7f64 prod() duplicates materials_cost(), clean up
Rename materials_cost() to prod_materials_cost(), give external
linkage, use it in prod().
2013-05-08 06:57:58 +02:00
ac60160355 Clean up redundant code in prod() 2013-05-08 06:57:58 +02:00
2a1e039834 Fix "info Products" on how to query sector type p.e.
It's show sect capabilities, not stats.
2013-05-08 06:57:58 +02:00
4884eddb51 Fix xdump nat column ip for connections from "long" IPv6 addresses
Broken in commit 3a7d7fa, which enlarged struct natstr member
nat_hostaddr[] from 32 to 46 characters, but neglected to update the
ca_len in nat_ca[].  Consequently, the address is truncated in xdump.
Can also break country * ?ip=... and such, but that's exotic.
2013-05-08 06:57:58 +02:00
c016c5fe76 Fix five year old show stopper bugs on big endian hosts
emp_server and empdump refuse to start on most big endian hosts,
because ef_verify_config() chokes on mdchr_ca[]:

Config meta uid 0 field type: value 0 is not in symbol table meta-type
Config meta uid 1 field type: value 0 is not in symbol table meta-type
Config meta uid 2 field type: value 0 is not in symbol table meta-type
Config meta uid 3 field type: value 0 is not in symbol table meta-type
Config meta uid 4 field type: value 0 is not in symbol table meta-type

Broken in commit 06a0036 (v4.3.12), which changed struct castr member
ca_type from packed_nsc_type (typedef'ed to char) to enum nsc_type,
but neglected to update the ca_type in mdchr_ca[].

On little endian hosts, the selector reads the least significant byte,
with sign extension.  Happens to work, because the type values are all
sufficiently small integers.

On big endian hosts, the selector reads the most signiciant byte.
which is always zero (NSC_NOTYPE).  Makes ef_verify_config() fail.

Except when sizeof(enum nsc_notype) == 1.  Then selector type works
fine, and ef_verify_config() succeeds, but we run into the next
problem: the same commit also changed member ca_flags from nsc_flags
(typedef'ed to unsigned char) to int without updating the ca_type in
mdchr_ca[].  This breaks "only" xdump meta column flags.

v4.3.12 was released in April 2008.  Either nobody has tried to run a
game on a big endian host since, or all who did gave up quietly,
without reporting the problem.

We clearly need to test on a wider range of machines.
2013-05-08 06:57:58 +02:00
347d3f3510 Fix xdump trade column type on big endian hosts
Broken in commit 14ea670 (v4.3.8), which changed struct trdstr member
trd_type from char to short, but neglected to update the ca_type in
trade_ca[].

On little endian hosts, the selector reads the least significant byte,
with sign extension.  Happens to work, because the type values are all
sufficiently small integers.

On big endian hosts, the selector reads the most signiciant byte,
which is always zero (EF_SECTOR).  Messes up xdump trade badly.
2013-05-08 06:57:58 +02:00
c64c756eef Fix xdump lost column type on big endian hosts
Broken in commit 09248d0 (v4.3.8), which changed struct loststr member
lost_type from char to short, but neglected to update the ca_type in
lost_ca[].

On little endian hosts, the selector reads the least significant byte,
with sign extension.  Happens to work, because the type values are all
sufficiently small integers.

On big endian hosts, the selector reads the most signiciant byte,
which is always zero (EF_SECTOR).  Messes up xdump lost badly.  Also
breaks lost * ?type=..., but that's exotic.
2013-05-08 06:57:58 +02:00
3c84a8756e Improve how mksubj.pl reports malformed .SA argument 2013-05-08 06:57:57 +02:00
5d8f33f6ad .SA should come last, make mksubj.pl enforce it 2013-05-08 06:57:57 +02:00
21762a2c53 Subject pages confuse topics and subjects, fix
Confused since they were added in Empire 2.
2013-05-08 06:57:57 +02:00
bc8e3d3ffc Slightly less crude "info page is long" decision
"Unusually long" topics are marked with a "!" in subject indexes.
This should use the line count of the formatted page, but that's too
much trouble, so commit 4c0b4c0 (v4.3.27) approximated it by "source
file has more than 9999 bytes".  Change that to "source file has more
than 300 lines".
2013-05-08 06:57:57 +02:00
cd4cd8d0f7 Simplify how mksubj.pl keeps track of the subjects' topics
Extend global variable %Subjects to hold topics.  Drop global
variables %subject and %largest.
2013-05-08 06:57:57 +02:00
c8bd8202ce Simplify how mksubj.pl parses argument of .SA
Call parse_see_also() immediately.  Permits eliminating global
variables %see_also and %sanr.
2013-05-08 06:57:57 +02:00
156930c515 Make mksubj.pl touch subject files only when it needs to change
Avoids unnecessary reformatting of subject pages again.
2013-05-08 06:57:57 +02:00
890e88d149 Declare subjects instead of picking them up automatically
Since subjects were added in Empire 2, we've always picked them up
from .SA requests.  If you mistype a subject there, you get a "is a
NEW subject" warning, and incorrect subject pages.  When building a
pristine tree, you get bogus "is a NEW subject" warnings for all
subjects.  If you somehow delete the generated subjects.mk, but not
the generated subject files, the build breaks.

Declare subjects in Make variable subjects.  Drop generated makefile
subject.mk.

Treat unknown topics in .SA arguments as errors.  This replaces the
"$subj is a NEW subject" warning.

Treat subjects without member pages as errors.  This replaces the "The
subject $subj has been removed" warning.

Safer and simpler.
2013-05-08 06:57:57 +02:00
cbed134d81 Fix remaking of info subject pages
We used to do all the info indexing work in info.pl: find subjects,
create subjects.mk (to tell make the list of subjects), the subject
pages, and TOP.t.  Worked, but touching an info page triggered a full
rebuild of all subject pages and TOP.t.

Commit 2f14064 (v4.3.0) tried to avoid that by splitting info.pl into
findsubj.pl, mksubj.pl, mktop.pl.  findsubj.pl puts not just the
subjects into subjects.mk, but also make rules for the subject pages,
to guide their remaking.  mksubj.pl creates a single subject page.
mktop.pl creates TOP.t.

Unfortunately, this doesn't work so well.  Since subjects.mk doesn't
exist in a virgin tree, we use -include.  Unwanted consequence:
findsubj.pl failure doesn't stop make.  Moreover, the complex make
machinery breaks down when info sources get removed or subjects get
dropped.

Go back to the old method, except keep mktop.pl separate, as that part
works just fine, and use simpler make rules.  mksubj.pl now creates
subjects.mk and all subject pages, like info.pl did.

This effectively reverts most of commit 2f14064.  I'll address the
excessive rebuilding of subject pages in a different way shortly.
2013-05-08 06:57:57 +02:00
a2338a1db4 Pass subjects instead of subject filenames to info/mktop.pl
mktop.pl doesn't actually use the files, so this is simpler and
clearer.
2013-05-08 06:57:57 +02:00
02a18de4d4 Fix remaking of config.h and config.h.in
Remaking config.h and config.h.in updates the target only when its
contents actually changes.  This is important, because after updating
config.h we need to recompile everything.

The make rules to do that are straight from the Autoconf manual.  But
they don't work: the rules that connect config.h and config.h.in to
stamp-h and stamp-h.in don't have recipes.  Since make doesn't have an
implicit rule either, it concludes that the target remains unchanged.
It still updates the prerequisites.  The recipe for updating the stamp
files then change the the targetes behind make's back.  Make misses
the change of config.h and/or config.h.in, and we get an incomplete
rebuild.

The rules need empty recipes instead.  This Autoconf manual was fixed
accordingly in autoconf.git commit 6b42b38.
2013-05-08 06:57:57 +02:00
9760dc9d12 Update info lost example to current output
Looks like this hasn't been done since Peter Langston's days...
2013-05-08 06:57:57 +02:00
e8742793e6 Drop trailing space in output of financial 2013-05-08 06:57:57 +02:00
14b31911dc Clean up some trailing whitespace 2013-05-08 06:57:57 +02:00
e9a69b6bc9 Replace .SA Obsolete by .LV Obsolete
Mark obsolete pages with '+' in subject pages.  Drop the separate
"Obsolete" subject page: move "info Innards" to subject "Server", and
"info update" to "Updates" (where it came from in commit a5764534,
v4.3.10).
2013-05-08 06:57:56 +02:00
b372ddeab4 Suppress explanation of '*' flag in subject pages when not used 2013-05-08 06:57:56 +02:00
f66a28079b Replace 'our' by 'my' in Perl scripts 2013-05-08 06:57:56 +02:00
37990f98b2 Include <process.h> in w32/unistd.h for getpid()
getpid() is used since commit 773019e.
2013-05-08 06:57:56 +02:00
8dbda02405 Fix missing include "arpa/inet.h" in w32sockets.c
Missed in commit afedb8c.
2013-05-08 06:57:56 +02:00
62a8bb383e Define EWOULDBLOCK for w32 only if it's missing
My version of MinGW provides it.
2013-05-08 06:57:56 +02:00
372cdb136c Use IPv4 format for IPv4-mapped addresses
For instance, use "127.0.0.1" for IPv4 loopback instead of
"::ffff:127.0.0.1".

Simplifies use of econfig key privip: plain dotted decimal now just
works regardless of IPv6 use, no need to add the IPv4-mapped form.

Also affects how addresses are logged and shown to players, and nation
selector ip.  Nicer that way.
2013-05-08 06:57:56 +02:00
2d3bac803c Drop extra blank line in output of pconfig 2013-05-08 06:57:56 +02:00
1afe0a7993 Document GNU libc lossage in listen_addr doc string
Systems using GNU libc such as Linux are frequently configured in a
way getaddrinfo(NULL, ...) put the IPv4 wildcard "0.0.0.0" *before*
the IPv6 wildcard "::" in the result.  Because of that, listen_addr ""
listens only on all IPv4 addresses.  Workaround: listen_addr "::".

Document it in listen_addr's doc string.
2013-05-08 06:57:56 +02:00
c3e5fd2375 Log connection attempts 2013-05-08 06:57:56 +02:00