Commit graph

3448 commits

Author SHA1 Message Date
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
2b7163f10a Remove special case supply of land units from ships carrying them
The common supply code does not supply a land unit from the ship
carrying it, only resupply_all() does that, since 4.3.14.  It would be
nice to fix the inconsistency by always supplying land units that way,
but that's relatively costly now, because of the supply code's design.
Just drop it for now.

Affects load and lload (except resupply is disabled there because it's
buggy), supply, assault and board.
2009-02-17 19:30:35 +01:00
d58b306780 Don't suggest only supply ships can tend in info tend and ltend 2009-02-17 19:30:35 +01:00
c42c96f976 Don't lie about shell supply in info fire
It claimed ships and land units don't need shells if they can draw
them from a supply source.  That was never true for ships, I believe,
and became wrong for land units in commit f6c87d21.
2009-02-17 19:30:35 +01:00
9dd9679377 Clean up info lmine a bit 2009-02-17 19:30:34 +01:00
fbaef4794e Fix lmine for engineers that don't use ammo
landmine() used resupply_commod() to get shells, but that doesn't get
any unless the engineer uses ammo.  Use supply_commod() instead.
2009-02-17 19:30:13 +01:00
bc2989a3b3 Don't permit landmine laying in foreign sectors 2009-02-17 19:28:33 +01:00
8fa4f6d507 Fix lmine's "out of" messages
Don't claim "now out of supply" when actually out of mobility.

Don't claim "out of supply" when actually out of shells.  A land unit
is out of supply when out of shells, but not necessarily the other way
round.
2009-02-17 19:24:10 +01:00
a302d7613e Make sure lmine can't lay seamines even when sector changes
Reading the sector again invalidates the sector type check.  Bug can
currently bite only when the deity redesignates the sector.  Call
check_sect_ok() instead.
2009-02-16 20:57:26 +01:00
82ddc64e35 Make lmine report lack of mobility more nicely 2009-02-15 12:54:19 +01:00
41f3e67e8b Don't let engineer mine while it is on a ship or land unit 2009-02-15 12:54:19 +01:00
7da69c92e0 Don't use automatic supply to avoid starvation at the update
Food supply during update adds complexity to the update.  How much
good it does to players is highly doubtful; certainly nobody can rely
on it.  It isn't covered by the starvation command.  Starving ships or
land units can steal enough food from their sector to make it starve,
too.  Finally, the supply code is notoriously hard to use correctly.
We don't know of issues with the update's use, but we haven't
convinced ourselves that there aren't any either.
2009-02-15 12:51:05 +01:00
c0b300d875 Sectors and ships no longer need shells to fire flak
4.0.9 changed flak not to use up shells, but they still had to be
present.  Drop that, because it doesn't really provide any value.
Moreover, this gets rid of the buggy flak shell supply code (seqno
mismatch oopses, lost supplies).
2009-02-14 14:17:44 +01:00
7cce3124bf Use IPv4 and v6 only when suitable interfaces are configured
Only on systems supporting AI_ADDRCONFIG.
2009-02-12 07:41:13 +01:00
00b5cb2b8a Update info Interception for air defense integration
Was missed in commit 6564ff22.  While there, delete details on fuel
use that became wrong in Empire 3.
2009-02-11 20:10:01 +01:00
8b6540eecb Fix info turn not to suggest that turn off just disables login
Basically a rewrite.
2009-02-08 20:49:42 +01:00
72a25644a8 Restructure turn() for simpler control flow
Also make it less chatty, and don't suggest that turn off just
disables login.
2009-02-08 20:49:42 +01:00
421119e1f1 Fix turn off for empty message
Always failed with an empty message, due to misuse of fwrite().
Broken in commit df7dc203, v4.2.20.
2009-02-08 20:49:42 +01:00
cfa0838977 Fix the previous commit to clear PF_DOWN 2009-02-08 20:49:42 +01:00
9ff2c62309 Avoid repeated hours and game down status notifications
may_play_now() tells deities about hours restriction and game down
status.  It runs at login and before and after each command.  Getting
notified that often is annoying.

Avoid repetition by remembering notification in new player flags
PF_HOURS and PF_DOWN.  Add a notification when hours restriction has
been lifted.  Ensure the notification is printed before the prompt,
not before the command, by calling may_play_now() from command() only
for mortals.  Safe, because may_play_now() always returns true for
deities anyway.
2009-02-08 14:59:26 +01:00
b404216dbe Inline gamedown() into only user may_play_now() and simplify 2009-02-08 14:24:45 +01:00
e8926559d1 Move show_first_tel() from player.c to rea.c 2009-02-08 14:21:15 +01:00
87b7330805 Don't check MAXTELSIZE in typed_wu()
The previous commit lifted the MAXTELSIZE restriction for telegram
files.  Note that getele() is still limited by it.
2009-02-08 14:21:15 +01:00
4238323d63 Factor out code to read mailboxes, and make read more robust
New tel_read_header(), tel_read_body().  Use them in rea(),
show_first_tel(), copy_and_expire().

rea() now stops when it encounters a corrupt telegram, and logs the
problem.  Before, error detection was incomplete, and errors were not
logged.  Corrupt mailboxes could make it crash.

show_first_tel() and copy_and_expire() can now cope with telegrams of
arbitrary length, like rea(), and sanity-check the header fields they
don't actually use.
2009-02-08 14:21:15 +01:00
6f1e669bea Remove superflous #include "tel.h" 2009-02-08 14:21:15 +01:00
4c81ca34cb Make struct telstr members tel_type and tel_length unsigned
They are simpler to use that way.
2009-02-08 14:21:15 +01:00
d2cd46ce20 Don't log out deity when gamedown() can't read downfil
Broken in commit c7e2442d.  Fix by factoring show_first_tel() out of
gamedown() and show_motd().
2009-02-08 14:21:15 +01:00
1dba1fccee Don't fail motd command when motdfil can't be read
Not the player's business.  Simply treat it as no MOTD.
2009-02-08 14:18:04 +01:00
f465b1e1e2 Don't write junk to unused bytes of downfil and motdfil
These files don't use all members of struct telstr.  turn() neglected
to initialized the unused ones and struct telstr's holes.  Fix that.
2009-02-08 14:18:04 +01:00
fe9f02ccfb Store game down flag in the game table
This avoids the silly opening of downfil all the time.

For what it's worth, it also makes the information visible in xdump,
as new game selector down.
2009-02-08 14:18:04 +01:00
f1d89514a5 Move update_timeused() from may_play_now() back to callers
This backs out a small part of commit d1ff2a60, for clarity.

While there, oops when may_play_now() is called with incorrect natp
argument.
2009-02-08 14:16:57 +01:00
6a1078f8a0 Fix reject accept
Instead of accepting the listed nations, rejected the nation listed
last, and accepted all the others.  Broken in commit 6844c94b, v4.3.4.
2009-02-08 09:33:19 +01:00
35ef345ecb Update copyright notice 2009-02-08 09:33:18 +01:00
7e104531dd Streamline copyright notice in lwp.h
Should have been done along with the rest of LWP, in commit 2aea9269.
2009-02-08 09:33:18 +01:00
Ron Koenderink
4c32aac832 Fix update thread not successfully waking up with LWP
Commit 08b945568 broke empth_sleep() for LWP: it returned zero even
when woken up early.
2009-02-07 20:09:30 -06:00
Ron Koenderink
c7e2442d3a Prevent command from executing after game is down
Move the gamedown() check from status to may_play_now() so it is
checked upon login, before a command is executed and after command
completion.  This fixes the situation where a player to could execute
one more command after the game was down.

Report to the deities that the game is down.

Remove to duplicate gamedown message.
2009-02-04 20:53:26 -06:00
48cec49fbf Fix empth_select() for funny flag arguments
EMPTH_POSIX and EMPTH_W32 implementations rejected values other than a
single flag.  Such values aren't used now, but it violates the
contract all the same.
2009-02-02 08:08:38 +01:00
Ron Koenderink
cd740c1b63 Add maximum logged in time check for nation state NEW 2009-02-01 11:43:22 -06:00
6144a363d6 Fix pthread's empth_select() not to change the timeout
Commit 08b94556 introduced the timeout parameter.  The empthread
implementation could change it, at least on some systems, and its user
worked around a possible change.  However, that behavior was not
documented, and it's inconvenient.  Fix the pthread implementation,
and remove the workaround.
2009-02-01 18:06:09 +01:00
6564ff2240 Integrate air defense missions into interception
The ancients designed interception dead simple: when you overfly a
sector, you get intercepted by the sector owner.  Fine print
interception rules govern which planes intercept.

Then complexity got piled on top of it.

Chainsaw 2 added an extra interception by surface ship owners, in the
target sector only.

Chainsaw 3 added an extra interception by land unit owners, in the
target sector only (Empire 4 later merged this extra land unit
interception with the extra surface ship interception).

Chainsaw 3 added an entirely separate kind of interception: air
defense missions.  When you enter a sector in some air defense op
area, you get intercepted.  Fine print air defense rules govern which
planes intercept.  These rules differ significantly from the
interception fine print.

Additional complexity comes from these facts:

* Air defense mission interception happens in addition to non-mission
  interception.  You can boost your total interception by setting up
  air defense.  Which means you must set it up, or forgo an advantage.

* Air defense planes are not available for non-mission interception
  duty.  You need to decide on a split.

* In contrast to non-mission interception, interceptors flying air
  defense get intercepted.

Moreover, the air defense code breaks one of the plane code's design
assumptions, namely that just one plane sortie is active at a time.
The air defense sortie runs while the sortie it intercepts is in
progress.  This leads to two interceptions being active at the same
time: the one intercepting the original sortie, and the one
intercepting the air defense sortie.  The same plane can fly in both
interceptions, and damage received in the interception of the air
defense sortie is wiped out, triggering a seqno mismatch oops.

The previous commit already simplified non-mission interception: you
get intercepted by anyone who owns the sector, or a surface ship or a
land unit there, whether it's the target sector or not.

Now simplify mission interception, by merging air defense back into
ordinary interception: when you overfly a sector, you get intercepted
by anyone who owns the sector, or a surface ship or land unit there,
or has an air defense mission covering the sector.  That's all.  No
multiple interceptions, no separate air defense rules.

Remove air_defense().  Simplify ac_encounter() and sam_intercept()
accordingly; both lose their last parameter.

Change sam_intercept() and ac_intercept() to intercept in mission op
areas.  New parameter only_mission to suppress non-mission
interception.  Pass zero when the intercepting country owns the sector
or a surface ship or land unit in the sector.

ac_encounter() can't efficiently predict whether a country intercepts,
so it needs to call ac_intercept() unconditionally.  This kills the
optimization to collect interceptors only when needed; simplify
accordingly, replacing getilist() by getilists().
2009-02-01 17:14:39 +01:00
d1490b9ba5 Intercept the same all along the flight path
In each sector, any country owning the sector, a surface ship or a
land unit gets to intercept.

Before, only the sector owner got to intercept, except for the target
sector.  There, any country owning surface ships or land units got to
intercept in addition to the sector owner.  Thus, a sector owner with
surface ships or land units there got to intercept twice.

Info Intercept claimed you get to intercept once for ships and once
again for land units, which was wrong since 4.0.9.

Info bomb suggested that flak fires only in the target sector, which
was wrong since 4.2.8.  Drop that.
2009-02-01 17:14:39 +01:00
5de052e411 Make ships and land units spot planes along the flight path
Sectors already spotted overflying planes in every sector along the
flight path, but ships and land units did that only in the target
sector, once if you got any ships there, in ac_encounter(), once if
you got any land units there, in ac_encounter(), once for ships firing
flak, in ac_shipflak(), and once for land units firing flak, in
ac_landflak().  Remove all that, and generalize ac_encounter()'s code
for sectors to spot planes to include ships and land units.  Unlike
before, ships and land units don't spot allied planes.
2009-02-01 17:14:39 +01:00
2ab91d8b6b Change when planes spot ships and land units
Planes now spot ships and land units only when flying recon or sweep,
and along all of their flight path instead of just the target sector.
It still takes a spy plane to identify ships and land units.

Before, non-spy planes spotted ships and land units only in the target
sector, regardless of type of sortie, once for all ships and land
units, in ac_encounter(), once for ships firing flak, in
ac_shipflak(), and once for land units firing flak, in ac_landflak().
Remove all that.
2009-02-01 17:14:39 +01:00
831bd63071 Replace unfriendly[] by rel[] in ac_encounter()
Use it to replace the getrel() in the check for allied.
2009-02-01 17:14:39 +01:00
b5cb3cb37b Intercept planes at their assembly point
Change ac_encounter() to start intercepting and running air defense
missions at the assembly point instead of the first sector entered
from there.

This also fixes a coding bug: when the flight path was empty, evaded
was used uninitialized when checking whether to intercept over the
target.  The compiler even warned about that.  Since the uninitialized
evaded typically read non-zero, interception triggered by ships and
land units didn't work.  Abusable: if you managed to make your target
sector an assembly point, e.g. by placing an own or allied ship there,
you could bomb it without getting intercepted or taking flak.
2009-02-01 17:14:39 +01:00