Commit graph

3070 commits

Author SHA1 Message Date
321d6d74c7 Journal output lines instead of chunks
Output often arrives in chunks other than lines.  Hard to read in the
journal.  Delay journalling until we got a full line or our buffer is
exhausted.  This is less precise, but it'll do for now.
2008-07-30 08:26:34 -04:00
9398627ec4 New journal event output
To enable, set econfig key keep_journal to at least 2.  Output events
are *not* flushed to disk immediately.

Put it in Hvy Metal II now to gather real data for future testing of a
journal replay tool.
2008-07-29 20:38:48 -04:00
cb1c9f6a19 New journal event command
Redundant information, but makes the journal easier to read.  The
redundancy might help making a journal replay tool robust.

Put it in Hvy Metal II now to gather some real data.
2008-07-29 20:24:04 -04:00
a87f73a3b5 Use country number as journal thread ID when possible
Before, we used the value of empth_thread().  That can be mapped to
countries by tracking login and logout.  Easy for machines (except
when the journal is rotated while players are logged in), but tedious
for humans.

Quick version for Hvy Metal II.  Needs further work for the stock
code.
2008-07-29 07:32:36 -04:00
3afc1b1989 Fix interdiction to obey op-area for missiles
Never worked correctly.  Reported by Gregory E. Garland.
(cherry picked from commit 3eb58312b3)
2008-07-25 08:43:04 -04:00
b9b0710128 Fix treatment of EOF from player
Commit 79407e68 (v4.3.11) changed recvclient() to keep failing after
receiving EOF from player.  This was bad, because some places getting
input check player->aborted instead of recvclient() failure, and
player->aborted wasn't set on EOF.  Bugs caused by this:

* comm_bomb(), ship_bomb(), plane_bomb(), land_bomb() went into an
  infinite loop that eventually ate all memory.

* deli(), desi(), dist(), fly(), morale(), zdon(), att_prompt(),
  ask_move_in() interpreted EOF as empty input instead of no more
  input.

* cmd_sail_ship() dereferenced a null pointer.

Fix by setting player->aborted on EOF, too.
(cherry picked from commit b3a7a8ee11)
2008-07-15 06:37:05 -04:00
80b57b2f95 Simplify breaking of command loop
Change status() to check player->eof instead of io_error() and
io_eof().  Ignore value of command().
(cherry picked from commit 9c5854c8c9)
2008-07-15 06:33:45 -04:00
3c3912420b Change recvclient() to treat io_error() like io_eof()
This is for consistency with status() and player_login().
(cherry picked from commit b7153d095c)
2008-07-15 06:33:41 -04:00
18ae6c5f78 Oops when player thread keeps reading input unsuccessfully
Reading input fails after EOF and while the current command is
aborted.  Commands should detect that and fail.  If a command neglects
to do that in a loop, the loop can become infinite.  This is
especially bad after EOF, because then the client might not read
output anymore.  Output gets buffered until memory runs out.

Mitigate such bugs by counting how many calls have failed in a row,
oopsing on the 256th, and sleeping one minute from the 256th on.
(cherry picked from commit 49c24d7b78)
2008-07-13 08:07:53 -04:00
6aefeea2a1 Fix seqno mismatch in fly()
fly() reads the carrier, then passes it to pln_dropoff(), which writes
it back.  fly() also calls pln_oneway_to_carrier_ok(), which updates
the carrier when its plane summary information is incorrect.

The old code called it between reading the carrier and passing it to
pln_dropoff().  This made pln_dropoff() wipe out the plane summary
update, and triggered a seqno mismatch oops.  Broken by introduction
of pln_oneway_to_carrier_ok() in commit 1127762c, v4.2.17.

Fix by reading the carrier right before passing it to pln_dropoff().
(cherry picked from commit 42d9475d89)
2008-07-13 08:07:38 -04:00
1713f2d303 Don't fix up dead planes stuck in the air
Missile interdiction leaves behind used up missiles with the
PLN_LAUNCHED flag set.  This can lead to a bogus warning from
pln_zap_transient_flags() on server restart.

Change pln_zap_transient_flags() to ignore dead planes.
(cherry picked from commit 7a06a58bec)
2008-07-13 07:58:09 -04:00
84d40a6057 Fix flying commands not to let planes do double duty as escorts
Commit 7ca4f412 (v4.3.12) marked planes flying a sortie with
PLN_LAUNCHED, and made pln_arm() reject planes with that flag set.
This was designed to reject escorts that were already flying as
bombers.  It didn't work, because the test for PLN_LAUNCHED used a
stale copy of the plane created by pln_sel().  Fix by getting a fresh
copy.

The bug always existed, but the botched fix in commit 7ca4f412 made it
worse.  Before, ac_encounter() dropped escorts that were also bombers,
so the bug merely wasted plane fuel.  After, such planes were
effectively duplicated, and damage to one of them, usually the bomber,
was wiped out.  Abusable.
(cherry picked from commit 801780043f)
2008-06-28 13:07:52 -04:00
fbefc139f4 Fix seqno mismatch and use-after-free in shp_sweep()
The code wrote the swept sector after calling shp_check_one_mines().
This failed to use up the mine that hit the minesweeper, and triggered
a seqno mismatch oops.

The code wrote the minesweeper after calling shp_check_one_mines().
This used freed memory when the minesweeper got sunk there.

Broken in 4.0.17.  Fix by moving both calls before
shp_check_one_mines().
(cherry picked from commit b0644e822c)
2008-06-28 13:06:58 -04:00
c40dd61bf0 Don't unlimber when guns unsuccessfully try to fire
This happened when fire command failed becayse the gun lacked shells,
and when other ways to fire failed because the gun was inefficient,
embarked, lacked mil, guns or shells.

Broken in commit b8bdc32b, hvy-metal-2.4.
2008-06-27 06:53:43 -04:00
2b90a5230d Don't let non-light units board ships that can't carry them
ask_olist() let non-light land units board ships that can carry only
light units.  If the board succeeds, the non-light unit move onto the
ship and then are stuck there.
(cherry picked from commit 6d38a04930)
2008-06-17 20:20:02 +02:00
0a7437bc43 Update info BTU on Empire clock and work percentage
Work percentage should have been documented in commit 233fce87,
v4.3.0.

Empire clock should have been documented in commit d3e0597f, v4.3.10.
(cherry picked from commit 4a67080656)
2008-06-17 20:19:48 +02:00
d0210443ff Update info Citizens on census showing old owner
This was forgotten in commit 6b434ee3, v4.3.0.
(cherry picked from commit 860369ec7e)
2008-06-17 20:19:34 +02:00
a4b550a1a2 Fix ship interdiction targeting ships not at sea
perform_mission() needs to know whether it is targeting ships or
something else, because the rules differ: submarines interdict only
ships, land units get their damage reduced when interdicting ships,
and different news are generated.

The old code assumed it was targeting ships when the target sector was
sea.  Wrong when interdicting ships in harbors, bridges and such.
This has always been broken.  Except when checking a submarine's
target: there it tested argument s, which is gross, but at least it
works.  That code was added in v4.0.8.

Replace the broken test by the gross hack everywhere.  This fixes news
and damage from land units when ships get interdicted in non-sea
sectors.
(cherry picked from commit 3e251b474f)
2008-06-10 10:25:05 +02:00
07d2c38a73 Fix ground combat to report defending land units
Commit 092a52f2 (v4.3.4) removed the code to estimate defense, because
the use of the estimate had been disabled since v4.0.0.  This
accidentally removed the reporting of defending units, because
get_dlist() reported them when called for an estimate, and not when
called for real.

Fix by removing the unused estimate capability from get_dlist().  It
now reports defending units always.
(cherry picked from commit 64f44e9904)
2008-06-10 10:25:05 +02:00
b8bdc32b3c Fix unlimbering, it had no effect
Broken by mismerging the rebase of Hvy Metal I in commit 5d0f5e69,
except for fire command when the target was out of range.
2008-06-10 10:24:59 +02:00
dfcc13abdd Clarify info Railroad on track stopping at national borders 2008-06-09 20:07:28 +02:00
080e8db899 Avoid seqno mismatch oops in recursive land unit supply
Before s_commod() attempts to recursively supply a supply unit it
wants to use as supply source, it zaps the unit's load.  When
actually_doit is false, it later restores the old load by overwriting
the change with a saved copy of the unit.  That triggers a seqno
mismatch oops.

Avoid that by copying the new sequence number to the saved copy.
(cherry picked from commit aacd0fb754)
2008-05-28 22:33:36 +02:00
2410535a05 Don't run supply machinery to get zero units
Change supply_commod() and try_supply_commod() not to call s_commod()
when zero units are wanted.

This isn't just for efficiency, it's also for limiting exposure to
supply bugs a bit.
(cherry picked from commit 7f17369491)
2008-05-28 22:33:27 +02:00
d3a2130b26 Fix type of get_seqno() from int to unsigned
While there, document the seqno functions.
2008-05-28 22:32:03 +02:00
e1283b118a Fix crash bug in satellite maps
The value of diffx() had the wrong sign when the arguments differed by
WORLD_X / 2.  Same for diffy() and WORLD_Y / 2.  satmap() used them to
find the vector from map center to ship or land unit to put on the
map, and got incorrect values for ships and land units directly
opposite to the center in x or y.  The bug made satmap() read a
pointer out bounds of its malloced radbuf[], and then write through
that with unpredictable consequences.

Broken in 4.2.12.  The original bug was in Empire 1.1: it
miscalculated where to put ships on the map (no crash).  An incomplete
fix for radmap() and satmap() appeared in Chainsaw 2 (still no crash).
radmap() got fixed correctly in Chainsaw 3, but satmap() was
forgotten.  That one got "fixed" in 4.2.7, and again in 4.2.12, but
both "fixes" were flawed and could crash.

Fix by backing out the flawed fixes and adopting the fix from radmap()
instead.
(cherry picked from commit 0cc474bd6d)
2008-05-28 22:32:00 +02:00
7dc0f48868 Fix XNORM() and YNORM()
Broken in commit 5f764285 (v4.3.12) for negative multiples of WORLD_X
and WORLD_Y, respectively.

This could theoretically lead to buffer overruns and other
unpleasantness.  None have been reproduced, though.
(cherry picked from commit 7680acc39f)
2008-05-18 10:13:45 +02:00
e2eccc5740 Disable incorrect use of resupply_all() in load and lload
load_land_ship() and load_land_land() automatically resupply the land
units they load.  This can draw supplies from the sector where the
land units are.  When load() and lload() later update the sector, they
wipe out the update made for drawing supplies, and we get a seqno
mismatch oops.  Highly abusable.
2008-05-18 10:13:45 +02:00
c083a25277 Fix edit l, s, u, p not to wipe out concurrent updates
Make edit() bail out if the edited object changed while edit() slept
for input.
(cherry picked from commit a1f4dc9592)
2008-05-18 10:13:45 +02:00
6e69d6d9de Fix xdump nat for relations
Commit ee863c5d (v4.3.12) got opt_HIDDEN backwards in nstr_exec_val().
(cherry picked from commit 3dbb4dbb93)
2008-05-18 10:13:45 +02:00
5a2440c9d4 Fix origin command not to prompt twice for its argument
Broken in commit b69173ee, v4.3.0.
(cherry picked from commit 27c3466aa5)
2008-05-18 10:13:45 +02:00
45a6b9a1d7 Cover biofuel plant in info Quick-ref 2008-05-18 10:13:45 +02:00
542460c787 Fix markup in info Hvy-Metal 2008-05-18 10:13:45 +02:00
312b28f5fa Disable another incorrect use of supply_commod()
navi() reads the ships into a list.  When the ships get interdicted,
and lack flak shells, ac_shipflak() tries to get one and updates the
ship.  When the ship in the list is later written back, e.g. to apply
interdiction damage, the flak shell is wiped out, and we get a seqno
mismatch oops.

Disable automatic flak shell supply in ac_ship_flak() for now.  This
is related to commit f7d61817, which disabled automatic supply of
shells in ac_doflak() and shp_missile_defense().
2008-05-18 10:13:44 +02:00
e7aa3627c4 Fix edit command seqno oopses
Broken by commit dc9d847b.
2008-05-18 10:13:38 +02:00
8fe67826e6 Avoid compiler warning 2008-05-18 10:12:25 +02:00
05e5adfac8 Debug code to help catch the phantom nuke bug
Thu Apr 24 12:20:52 2008 Oops: bug in ../src/lib/subs/plnsub.c:1146

#3  0x080e64f4 in oops (msg=0x0, file=0x80ff1ca "../src/lib/subs/plnsub.c",
    line=1146) at ../src/lib/gen/log.c:141
#4  0x080bce6c in pln_damage (pp=0x8415b60, x=82, y=20, type=115 's',
    nukedamp=0x84158bc, noisy=1) at ../src/lib/subs/plnsub.c:1146
#5  0x080684f2 in launch_missile (pp=0x8415b60, sublaunch=0)
    at ../src/lib/commands/laun.c:281
#6  0x08067c79 in laun () at ../src/lib/commands/laun.c:111
2008-05-07 10:33:42 +02:00
cf4639fa74 Update info Hvy-Metal for Hvy Metal II 2008-05-07 10:33:42 +02:00
b707e2cca8 Permit ships to assault the sector they're in
Ships still have to be in a sea sector to assault an adjacent sector.
2008-05-07 10:33:42 +02:00
4e962406ff Let ships navigate bridge spans regardless of owner 2008-05-07 10:33:42 +02:00
f7d6181717 Disable some incorrect uses of supply_commod()
Because supply_commod() updates supply sources it used, the caller
must not cache objects that could be supply sources across a supply
call.  This is very easy to get wrong.

ac_doflak() supplies flak shells if the sector hasn't enough for its
guns.  It caches the sector that receives them.  If the sector has
some shells, but not enough, it supplies them to itself, causing it to
be updated from within supply_commod().  ac_doflak() then adds the
supplied shells to its cached sector, then writes that back.  This
doubles shells already there, and triggers a a seqno mismatch oops.

shp_missile_defense() has similar problems, only for ships.

Disable ac_doflak() and shp_missile_defense() for now, to at least
reduce the oopsing to manageable levels.

Most likely other calls of supply_commod() are also wrong.  Many of
them can't be just disabled, because supply is too relevant to
gameplay there.
2008-05-07 10:33:42 +02:00
b313b61cd4 Oops on sequence number mismatch
Old code only logged this, for fear of false positives.
2008-05-07 10:33:42 +02:00
e917a60371 Trains can no longer be loaded on land units, update info Railroad 2008-05-07 10:33:42 +02:00
12e34aeeb4 Fix info Railroad on spy and satellite reports
Fix explanation of "rl eff" value.  Mention satellite report.
2008-05-07 10:33:41 +02:00
fa5fa4abcc Don't store RAILWAYS track in sectors
Storing track in sectors is problematic, because we need to update
adjacent sectors when updating a sector in a way that changes its
capability to extend railway into its neighbors.  This invalidates
cached adjacent sectors, and calling code may not be prepared for
that.  Specifically, bridge building caches the bridge head, and
writes it back later, wiping out the track update.

Replace struct sctstr member sct_track by new sct_rail_track().  Make
selector track virtual.  Remove the code to keep sct_track up-to-date:
set_railway(), update_railway().

Unfortunately, this causes cyclic dependencies between link libraries:
the virtual selector needs to be referenced from src/lib/global/nsc.c,
and it needs to reference stuff from src/lib/common/file.c.  Hack
around it in Make.mk for now.
2008-05-07 10:33:41 +02:00
11100f23e5 Update info Hvy-Metal for Hvy Metal II 2008-05-07 10:33:41 +02:00
b437b7b5ec Make fairland record the island number in the deity territory
Can be useful for deities when further customizing their game setup.
2008-05-07 10:33:41 +02:00
95298986cc Don't produce food without work
We don't want to starve tiny populations, because that would require
players to move trivial amounts of food after explore and such.
growfood() used to simply grow at least 1f when a sector was about to
starve.  That food is almost never eaten by a tiny population, so we
effectively got some production without work.  Fix by taking away that
free food after people ate, in do_feed().
2008-05-07 10:33:41 +02:00
dc9d847b8b Add sequence numbers to game state (experimental)
This catches output dependency violations, e.g. two threads doing a
read-modify-write without synchronization.

New struct emptypedstr member seqno.  Make sure all members of unit
empobj_storage share it.  Set it in ef_blank() and ef_set_uid(), step
it in ef_write().  fairland and files don't use ef_set_uid(); need to
set it manually in files.c's main() and file_sct_init().

Factor do_read() out of fillcache() to make it available for
new get_seqno().
2008-05-07 10:33:41 +02:00
2aec870a14 New concept sector terrain
A sector type's terrain (struct dchrstr member d_terrain) is the
sector type of its underlying terrain.  Sector types occuring in
d_terrain are terrain types, and must have their own type in
d_terrain.  Players can change sector types only to those with the
same terrain.

The builtin configuration defines terrain types sea, mountain,
wasteland, wilderness and plains.  It gives bridge span and tower
terrain sea, and everything else terrain wilderness.  Hence, the stock
game remains unchanged.

Deities can use terrain to create sector types that can be developed
only in limited ways.
2008-05-07 10:33:41 +02:00
e3658ff2f0 Remove hard-coded differences between highways and bridge heads
Let highways build and support bridges.  Allow bridge heads anywhere,
not just on the coast.
2008-05-07 10:33:41 +02:00