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.
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.
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.
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.
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.
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().
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.
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.
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.
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.
A country's SAMs launched only in the first interception of a sortie.
That was because ac_intercept() made sam_intercept() delete all SAMs
from the list of available interceptors. sam_intercept() also deleted
any SAMs out of range. Don't do that, delete unused SAMs along with
other unused interceptors on return from ac_encounter().
Planes were not subject to air defense and flak over allied sectors.
Air defense was broken when Empire 2 changed it to happen after
spotting.
Flak was broken when 4.2.8 made ships and land units fire flak in
every sector, not just the target sector. Although an allied sector
doesn't fire flak, it may still contain hostile ships and land units.
Also makes use of ilist[] more robust: before, if relations somehow
went sour after unfriendly[] was initialized, the sector intercept
would run with an invalid interceptor list, and crash.
Chainsaw had missiles flying missions together with planes, and to
make that work, aircombat.c got code for coping with missiles. Since
Empire 2, missiles fly separately and don't go through aircombat.c
anymore. The missile code there has been useless for more than a
decade. Remove it.
This simplifies ac_encounter(), sam_intercept(), ac_intercept(),
ac_airtoair(), and gets rid of count_non_missiles(), all_missiles().
ac_encounter() passed MAXNOC instead of the sector owner to setcont(),
and setcont() does nothing for such an argument. Screwed up from the
start, in commit 144c7cb5, v4.2.22.
ac_encounter() lets all owners of ships and land units in the target
sector intercept, but not more than once.
Move the interception code behind reporting of both ships and land
units. Before, it was duplicated for ships and land units. Land
units didn't get reported when no bombers got through interception
triggered by ships.
Since the previous two commits, ac_encounter() checks its
mission_flags argument only for proper mission flags PM_R and PM_S,
not for plane flags P_A, P_S, P_I.
This makes the code to put plane flags into mission flags useless.
Remove it from bomb(), drop(), fly(), para(), reco(),
perform_mission(), mission_pln_arm(), air_defense(), pln_arm().
Much of that code was useless even before: P_X and P_H since Chainsaw
3 option STEALTHV became mandatory in Empire 2, and P_MINE since
commit cc0c3e4f (v4.3.0) cleaned up mine drops.
A reconnaissance patrol (recon and sweep) uses sonar when ASW planes
participate. ac_encounter() enabled sonar when P_A was in
mission_flags. These get computed by pln_arm() and callers. However,
they set P_A only when *all* planes were capable, including escorts.
Fix by checking actual plane capabilities instead. Closes#1389451.
A reconnaissance patrol (recon and sweep) reports much more detail
when spy planes participate. However, ac_encounter() didn't stop
doing that after all spy planes were shot down or aborted.
Fix by recalculating plane capabilities for every sector.
Remove the KillIdle thread. Add timeout to struct iop, initialized in
io_open(). Obey it in io_input() by passing it to empth_select(). If
empth_select() times out, report that back through io_input() to
recvclient() and player_login(). If player_login() receives a timeout
indication, print a message and terminate the session. If
recvclient() receives a timeout indication, flash a message to the
player and initiate a shut down the player's session.
Create WIN32 sys/time.h to define struct timeval. This creates some
conflicts with WIN32 windows.h definitions. Including windows.h in
show.c and info.c creates conflicts, so remove that. Modify service.c
to include sys/socket.h instead of windows.h to remove the conflict
with sys/time.h.
Remove the names for the bounce_empty, bounce_full and ctrl_c_event
events. The named events were being shared between all clients running
on a WIN32 machine which created the affect of disconnecting a client
when an input event occurred in another client. Broken in commit
f082ef9f (v4.3.11).
Add check to ensure a country by that name does not exist.
Ensure the length is not too long. Note this is a change
behaviour for edit and change commands which used to silently
truncate long names. Enforce that a country name can not have
control characters in it. Ensure that a country name is not
blank or just spaces.