Commit graph

4401 commits

Author SHA1 Message Date
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
da154ffd06 Fix wildcard bind to at least bind IPv4 or else IPv6 on OpenBSD
OpenBSD refuses to implement IPV6_V6ONLY, in violation of RFC 3493.
RFC 4038 frowningly recognizes this practice.  The only way to bind
both IPv4 and IPv4 there is two separate sockets.  Requires more
surgery than I can do now.

Since we can't have both IPv6 and IPv6 on OpenBSD with our single
socket, prefer IPv4, but if that doesn't work, do IPv6.

To prefer IPv6 instead, put 'listen_addr "::"' into econfig.  Document
that in listen_addr's doc string.
2013-05-08 06:57:56 +02:00
36578f463e Fix wildcard bind to bind both IPv6 and IPv4 on Windows & BSD
We rely on AF_INET6 wildcard bind() binding the AF_INET port, too,
i.e. IPV6_V6ONLY off.  This should be the default according to RFC
3493 section 5.3, but isn't on Windows and BSD.  RFC 4038 recognizes
this fact in section 4.2.

When IPV6_V6ONLY is on, an AF_INET6 wildcard bind only accepts
connections from IPv6 addresses.  Thus, IPv4 doesn't work when
getaddrinfo() returns an AF_INET6 address first (which it should do
when the system has an IPv6 address configured).

Switch off IPV6_V6ONLY explicitly instead of relying on the default.
This makes IPv6 work on systems where IPV6_V6ONLY is on by default,
such as Windows and BSD.

Except for OpenBSD, which does not support switching it off.  To be
addressed in the next commit.
2013-05-08 06:57:56 +02:00
75be45f1e4 Ignore error setting socket option SO_REUSEADDR
Shouldn't fail.  If it fails, but bind() works, the failure doesn't
matter.  If bind() fails, we can just as well report that failure
instead of setsockopt()'s.
2013-05-08 06:57:56 +02:00
8233c06317 Clean up tcp_listen()'s addrinfo loop some 2013-05-08 06:57:55 +02:00
50926766df Log the server's listening address 2013-05-08 06:57:55 +02:00
ffec91da99 Factor sockaddr_ntop() out of player_accept()
Oops on inet_ntop() failure instead of merely logging it.
2013-05-08 06:57:55 +02:00
6a0aed830c Fix a comment in tcp_connect() 2013-05-08 06:57:55 +02:00
335dd1b974 Make power sort countries of equal power predictably
How qsort() sorts members that compare equal is unspecified.  Can
upset the smoke test.  Observed under FreeBSD 8.3.

Break ties in power by comparing country numbers.  Countries equal in
power are now sorted by increasing country number.
2013-05-08 06:57:55 +02:00
c798863bd7 Change fairland island size probability distribution
Island size is randomly chosen from the interval [1..2*is+1], with
expected value is.  Use two dice to roll the size instead of one.
This makes extreme sizes much less likely.
2013-05-08 06:57:55 +02:00
afc0ef94ee Make fairland record the island number in the deity territory
Can be useful for deities when further customizing their game setup.
2013-05-08 06:57:55 +02:00
a59e496024 Make smoke test time out instead of hang when server misbehaves
The smoke test waits for the server completing startup by trying to
connect until it works.  Hangs if the server doesn't complete startup
for some reason.  Make it give up after 5s.

Likewise, The smoke test waits for the server to terminate by trying
kill -0 until it fails.  Hangs if the server doesn't terminate.  Make
it give up after 5s.
2013-05-08 06:57:55 +02:00
3f7062772d Remove superfluous #include "nuke.h" 2013-05-08 06:57:55 +02:00
375e5170e4 Simplify market time left handling in a few places 2013-05-08 06:57:55 +02:00
c5f76e5853 Fix extension of market bidding time when high bidder changes
Lots stay on the market until there's a bid and bidding time expires.

When the highest bidder changes, and less than five minutes of bidding
time are left, it gets extended by five minutes (since 4.0.7, actually
works since 4.0.9).

Normally, this ensures that the competition has at least five minutes
to react.  Except when this is the first bid, bidding time may have
expired already.  If it expired less than five minutes ago, the
competition still gets time to react, just less than it should.  If it
expired earlier, the sale is executed immediately for units.  For
commodities, the bidding time is set to expire in five minutes (since
4.2.0).

Instead of extending bidding time by five minutes, set it to expire in
five minutes, both for commodities and for units.
2013-05-08 06:57:55 +02:00
9c78e724ab Fix pre-tax unit market price loss of precision
check_trade() converts the price to float, which can lose precision,
although only for ridiculously high prices.  Has been broken since
4.0.0 introduced the market.

Avoid the conversion.  Bulletins now show pre-tax price as $N instead
of $N.00.
2013-05-08 06:57:55 +02:00