Commit graph

3742 commits

Author SHA1 Message Date
d1b39676e2 Change mine command not to work under bridges for now
This is for consistency with aerial mining.  Seamines don't work under
bridges anyway (they did a long time ago, until Empire 2).

Making seamines work under bridges again wouldn't be hard, but it
would make the 'X' in bmaps ambiguous.
2009-03-31 23:03:41 +02:00
3ea4e1ac60 Simplify retreat_ship1() and retreat_land1() slightly
No functional change.
2009-03-31 23:03:41 +02:00
3722bafaf7 Fix confusion of landmines with seamines
Seamines and landmines share storage.  Sea and bridge span sectors can
hold only sea mines, other sector types only landmines.  Sector type
checks were missing or incorrect in several places:

* Seamines under bridge spans were mistaken for landmines in several
  places:

  - ground combat mine defense bonus, in get_mine_dsupport() and
    stre(),

  - land units retreating from bombs, in retreat_land1(),

  - non-land unit ground movement (commands explore, move, transport,
    and INTERDICT_ATT of military), in check_lmines(),

  Fix them to check the sector type with new SCT_MINES_ARE_SEAMINES(),
  SCT_LANDMINES().

* plane_sweep() mistook landmines for seamines in harbors.  Bug could
  not bite, because it's only called for sea sectors.  Drop the bogus
  check for harbor.

* Collapsing a bridge tower magically converted landmines into
  seamines.  Make knockdown() clear landmines.

Also use SCT_MINES_ARE_SEAMINES() and SCT_LANDMINES() in mine(),
landmine(), lnd_sweep() and lnd_check_mines().  No functional change
there.

Keep checking only for sea in pln_mine(), plane_sweep(),
retreat_ship1(), shp_sweep() and shp_check_one_mines().  This means
seamines continue not to work under bridges.  Making them work there
is tempting, but as long as finding seamines clobbers the sector
designation in the bmap, it's better to have them in sea sectors only.

Historical notes:

Mines started out simple enough: you could mine sea and bridge spans,
and ships hit and swept mines in foreign sectors.

Chainsaw 2 introduced aerial mining and sweeping.  Unlike ships,
planes could not mine bridge spans.  plane_sweep() could sweep
harbors, which was wrong, but it was never called there, so the bug
could not bite.

Chainsaw 3 introduced landmines.  The idea was to permit only seamines
in some sector types, and only landmines in the others, so they can
share storage.  To figure out whether a sector has a particular kind
of mines, you need to check the sector type.  Such checks already
existed in mine, drop and sweep, and they were kept unchanged.  The
new lmine command also got the check.  Everything else did not.
Ground movement and combat could hit and sweep seamines in bridge
spans.  Ships could hit and sweep landmines in harbors.

Empire 2 fixed land unit movement (march, INTERDICT_ATT) not to
mistake seamines for landmines on bridge spans.  It fixed ships not to
mistake landmines for seamines.  The fix also neutered seamines under
bridge spans: ships could neither hit nor sweep them anymore.  Both
fixes missed retreat.

Commit 5663713b (v4.3.1) made ship retreat consistent with other ship
movement.
2009-03-31 22:52:03 +02:00
8cbcfefda1 Clean up useless declarations
Commit fbf9f15b removed SO, SE, but left their declarations behind.
Ditto commit 3aea20e1 for bigcity_dchr, and commit 08b94556 for
player_kill_idle.

Commit afa65c8f accidentally added a declaration for xedit().
2009-03-28 13:04:48 +01:00
6ae4eca045 Don't use 0 as null pointer constant, part 3
This part replaces E == 0 by !E, where E has pointer type.
2009-03-24 21:46:01 +01:00
90f8f2b099 Don't use 0 as null pointer constant, part 2
This part replaces E != 0 by E, where E has pointer type.
2009-03-24 21:46:01 +01:00
615681ce16 Don't use 0 as null pointer constant, part 1
Use NULL instead of 0, for clarity.  Except in pointer comparisons;
leave that to the next two commits.
2009-03-24 21:45:44 +01:00
a2ed975ec2 Clean up more unreadable assignments within if conditionals 2009-03-23 23:11:14 +01:00
6459cfce7b Simplify explain()
No functional change.
2009-03-23 23:09:03 +01:00
696dea759c Clean up non-ANSI definition of ef_verify()
Harmless, because declaration is fine.
2009-03-22 18:02:57 +01:00
ebdd9620f5 Give fairland's variables internal linkage 2009-03-22 17:55:00 +01:00
d1b801b90b Make non-static function definitions match static declarations
Just to avoid confusion.
2009-03-22 17:47:14 +01:00
5dcd748f9d Don't advertize ^D as means to end a telegram
getele() aborts the telegram on EOF since commit bc8a4432 (v4.2.21).
Besides, ^D may not work with some clients.
2009-03-22 09:52:06 +01:00
475f518be1 Don't log out player when he interrupts a command
Broken in commit 3da4030a, v4.3.19.
2009-03-22 09:01:57 +01:00
57717b5bc1 Clean up unreadable assignments within if conditionals
Pinpointed assignments within if conditionals with spatch -sp_file
tests/bad_assign.cocci (from coccinelle-0.1.4).  Cherry-picked diff
hunks affecting conditionals split over multiple lines, and cleaned
them up.
2009-03-21 09:24:45 +01:00
7c6e56bd02 Fix assault not to send bogus telex to country 0
Happened when a spy got caught sneaking ashore and shot.
2009-03-10 20:50:47 +01:00
c16ed9c405 Bump version to 4.3.22 2009-03-10 20:50:01 +01:00
2fb427b676 Fix distclean to remove generated files distributed in client tarball 2009-03-10 13:08:15 +01:00
82b5e3c29a Really fix bomb not to wipe out plane updates
Commit f07e6901 didn't fix it completely.
2009-03-10 12:51:44 +01:00
009fc1403c Update change log again for 4.3.21 2009-03-09 22:35:18 +01:00
d0db465382 Fix swapsector not to wipe out concurrent updates.
Make swaps() bail out if any of the sectors changed while edit() slept
for input.
2009-03-09 22:32:10 +01:00
8df262bada Update change log again for 4.3.21 2009-03-09 21:33:30 +01:00
aa734fa7b1 Fix outdated comment 2009-03-09 21:33:23 +01:00
b510ee5345 Fix crash dump not to mess up streams
Crash dump forks a child to call abort().  abort() may flush or close
streams.  This is unwelcome, because it can mess up streams in the
parent.  Observed with the journal.  Could theoretically also affect
commands info, read, turn, and wire; announcement expiry, and reading
of econfig and schedule.

Fix by using SIGABRT instead.

Note that flushing streams before fork() is not a sufficient fix,
because closing a stream can still move the file descriptor's file
position.  Do it anyway, to ensure any buffered output is visible to
post_crash_dump_hook.
2009-03-09 21:25:46 +01:00
84008cf870 Update change log again for 4.3.21 2009-03-08 18:24:32 +01:00
f07e6901cb Fix bomb not to wipe out plane updates while asking for targets
The commands to fly planes read the planes into a plane list, and
write them back when they land.  If a plane changes in the file while
it is in that plane list, the changes get wiped out when the plane
lands, triggering a seqno oops.

This is not an issue as long as the complete sortie runs
uninterrupted, because that code takes care to update flying planes
only through the appropriate plane list.

However, the bomb command suspends the planes on a pinpoint bombing
run mid-air over the target sector to let the player choose targets.
This lets code run that *can* update flying planes, for instance the
edit command.

Fix by aborting changed planes, taking care not to clobber the
changes.
2009-03-08 18:19:25 +01:00
f10af4dea0 Fix bombing of submarines with mixed force
When bombing ships with a force containing both planes with and
without capability ASW, pin_bomb() could fail to report presence of
submarines, and could refuse to bomb ships when there were only
submarines.  The culprit is pin_bomb()'s check for capability ASW: it
checked whether the first plane in the plane list was capable instead
of checking whether any plane in the list was capable.
2009-03-08 17:36:37 +01:00
f760150d8f Rename plane_caps() to pln_caps() and give it external linkage 2009-03-08 17:14:59 +01:00
fa03ba9aad Update change log for 4.3.21 2009-03-08 14:44:29 +01:00
e03eaeae23 Fix a bug in attack that could wipe out land unit updates
A victorious attacker can move attacking land units into the newly
conquered sector or leave them behind.  Normally, the player is asked
what to do, but when the land unit's army has already been told to
stay behind, or the command has been aborted, the land unit stays
behind without asking.  In that case, a copy of the land unit made
right after the victory was written back.  Any updates since the
victory were wiped out, triggering a seqno mismatch oops.

Fix by moving the re-read of the land unit in ask_move_in() out of the
prompt conditional.
2009-03-08 11:54:04 +01:00
6b75c21e3c Factor obj_changed() out of check_sect_ok() & friends 2009-03-08 09:01:56 +01:00
940092ffb9 Ignore timestamps in check_loan_ok() & friends
check_loan_ok(), check_comm_ok() and check_trade_ok() should have been
changed to ignore timestamps when timestamps were added to their files
in commit a680c811, v4.3.12.
2009-03-08 09:01:40 +01:00
eea9e76bf8 Don't log out player when update aborts a command with pthreads
pthread.c's empth_select() returned -1 when empth_wakeup() interrupted
select().  The failure then got propagated all the way up, and the
player got logged out.  Fix by returning 0 in that case.  While there,
retry on EINTR, to match LWP.  Also clarify comments.
2009-03-01 13:04:48 +01:00
5073b022fd Remove unused empth_terminate()
Unused since 4.3.10.  Can be used safely only in very special
circumstances.

Removal allows simplifying pthread.c and ntthread.c some.  liblwp left
alone.
2009-03-01 10:49:48 +01:00
3e4894c7f5 Don't log out player when update aborts a command
recvclient() confused command abortion with an idle timeout.  Broken
in commit 08b94556, v4.3.20.
2009-02-25 22:53:33 +01:00
12b432163c Bump version to 4.3.21 2009-02-21 15:18:55 +01:00
d87a9eb61b Update change log again for 4.3.20 2009-02-20 19:15:01 +01:00
6d8a53f9d9 Disable LOANS and enable RAILWAYS by default 2009-02-19 22:06:41 +01:00
ee20a9cd34 Update known contributors comments 2009-02-18 21:11:33 +01:00
dd8921218b Fix make dist in a separate build directory without git, really
Make didn't remake sources.mk even though it was a phony target.  I
don't understand why.  But we can just as well create it in its only
user, dist-source.
2009-02-17 23:00:07 +01:00
6d6301afe8 Update change log for 4.3.20 2009-02-17 20:14:32 +01:00
2c0e7df5ea Fix a few inaccuracies in info supply 2009-02-17 19:32:14 +01:00
59c3913b2f Take care not to supply from self
Change s_commod() not to use the supply sink as source.  As explained
in the message of the commit before the previous one, using the sink
as source makes it impossible for callers to safely keep a copy of the
sink across a supply call.  All current users do that.  Some were safe
anyway, some were not:

* fort_fire() was safe, because a fort draws shells only when it has
  none.

* shp_fire() was unsafe for ships with capability supply and ammo use
  greater than 1.  No such ship exists in the stock game.

* shp_dchrg() was unsafe for ships with both capabilities dchrg and
  supply.  Same for shp_torp() and capability torp, and
  shp_missile_defense() and capability anti-missile.  No such ship
  exists in the stock game.

* lnd_fire(), supp() and get_dlist() were safe, because they draw
  shells only when they have less than their ammo need, and then they
  don't supply any.

* mission_pln_equip() was unsafe when equipping planes with shells in
  supply sources.

* landmine() was unsafe for land units with both capability engineer
  and supply.  No such land units exist in the stock game.

* load() and lload() were unsafe for loadable supply units, but the
  supply use there was disabled in commit 65410d16 because of another
  bug.

* ask_olist() and att_reacting_units() were safe, because
  lnd_can_attack() excludes supply units.

In the stock game, planes flying interception or support missions,
abms intercepting ballistic missiles, launch of missiles or anti-sats
could conjure up shells, triggering a seqno mismatch oops.

In games with unusual customizations, this could also happen with
supply ships firing guns or torpedoes, dropping depth charges, or
shooting down marine missiles, and in the lmine command.
2009-02-17 19:32:14 +01:00
98f24d5cf9 Redesign s_commod()
To implement the supply from self avoidance described in the previous
commit's message, s_commod() needs to be redesigned along the same
principles: take the sink as argument, update and put it.  Also take
an item limit argument, and return whether supply request was fully
met.

Update sct_supply(), shp_supply(), lnd_supply() and
lnd_could_be_supplied().  The former three become straighforward
wrappers.

supply_commod() and try_supply_commod() are now unused, remove them.
2009-02-17 19:32:14 +01:00
322f96ecb7 Redesign automatic supply interface
The automatic supply interface has design flaws that make it hard to
use correctly.  Its current uses are in fact all wrong (until commit
0179fd86, the update had a few uses that might have been correct).
Some of the bugs can only bite with land unit capability combinations
that don't exist in the stock game, though.

Automatic supply draws supplies from supply sources in range.  Since
that can update any supply source in range, all copies of potential
supply sources a caller may keep can get invalidated.  Writing back
such an invalid copy wipes out the deduction of supplies and mobility
from a source, triggering a seqno mismatch oops.

This commit redesigns the interface so that callers can safely keep a
copy of the object drawing the supplies (the "supply sink").  The idea
is to pass the sink to the supply code, so it can avoid using it as
source.  The actual avoiding will be implemented in a later commit.

Copies other than the supply sink still need to be eliminated.  See
commit 65410d16 for an example.

Other improvements to help avoid common errors:

* Supply functions are commonly used to ensure the sink has a certain
  amount of supplies.  A common error is to fetch that amount
  regardless of how many the sink already has.  It's more convenient
  for such users to pass how many they need to have instead of how
  many to get.

* A common use of supply functions is to get supplies for immediate
  use.  If that use turns out not to be possible after all, the
  supplies need to be added somewhere, which is all too easy to
  forget.  Many bugs of this kind have been fixed over time, and there
  are still some left.  This class of bugs can be avoided by adding
  the supplies to the sink automatically.

In fact, this commit fixes precisely such bugs in mission_pln_equip()
and shp_missile_defense(): plane interception and support missions,
missile interception (abms), launch of ballistic missiles and
anti-sats could all lose shells, or supply more than needed.

Replace supply_commod() by new sct_supply(), shp_supply(),
lnd_supply(), and resupply_all() by new lnd_supply_all().  Simplify
users accordingly.

There's just one use of resupply_commod() left, in landmine().  Use
lnd_supply_all() there, and remove resupply_commod().
2009-02-17 19:31:37 +01:00
6ac9ad66e1 Don't let automatic supply starve the sector containing the sink
Automatic supply always leaves enough food to avoid starvation in
supply sources, except for one case: when drawing supplies from the
sector containing the sink.

This behavior contradicted info supply.  However, do_feed() used to
rely on it (it would have wiped out food without it).  Supply use
there was removed in commit 7da69c92, so we can now fix this.

Affected by this is the automatic food supply of land units in combat,
and the food supply in commands supply, load and lload.  Except supply
is disabled due to bugs in the last two.
2009-02-17 19:30:35 +01:00
c4a0f99573 Fix mobility cost of automatic supply from remote sector
When a supply request got served completely from a remote sector after
some other source had already provided some of it, the sector was
charged mobility for the complete amount instead of just the part it
actually provided.
2009-02-17 19:30:35 +01:00
ed5ca70cb2 Disable recursive supply of land units
Its implementation in s_commod() increases lnd_seqno even when
!actually_doit, which can cause spurious seqno oopses in callers of
lnd_could_be_supplied().  I can't be bothered to clean up this mess
right now, because recursive resupply is too dumb to be really useful
anyway: each step uses the first source it finds, without
consideration of mobility cost.
2009-02-17 19:30:35 +01:00
5ea0d19c20 Fix automatic supply of defending and reacting units
Being in supply is relevant for defending and reacting units.  The
code used has_supply() to check that.

Contrary to its name, has_supply() does not check whether the land
unit has enough supplies to be in supply, but whether it has or could
draw enough.  So, defending and reacting units did not actually draw
any missing supplies.

Fix that in get_dlist() and att_reacting_units() by calling
resupply_all(), then checking with new lnd_in_supply() instead of
has_supply().  The fix of att_reacting_units() is complicated by the
fact that it is also used in the strength command, and should keep not
drawing supplies there.

Rename has_supply() to lnd_could_be_supplied().  Replace its uses
immediately after resupply_all() by lnd_in_supply().
2009-02-17 19:30:35 +01:00
07561b4772 Don't resupply supply unit after use as supply source
Running supply recursively here is problematic, because it can draw
supplies from the outer supply's destination, which can then end up
with less than it asked for.

Serving as supply source never puts a unit that is in supply out of
supply.  So, the recursive supply here denies the sink its supplies to
put a supply unit somewhere else back in supply.  That's robbing Peter
to pay Paul.  Drop it.
2009-02-17 19:30:35 +01:00