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.
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.
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.
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.
Fix SAM interception for intercepts other than the first
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().
Fix air defense and flak over sectors allied to the planes
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.
aircombat.c isn't used for intercepting missiles, simplify
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().
Fix making contact by spotting planes from sectors
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.
Fix recon and sweep not to spy after all spy planes are gone
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.
Ron Koenderink [Sun, 1 Feb 2009 12:22:26 +0000 (06:22 -0600)]
Reimplement max_idle without a separate thread
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.
Ron Koenderink [Sun, 1 Feb 2009 14:58:37 +0000 (08:58 -0600)]
Fix client to allow multiple to clients to run concurrently for WIN32
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).
Ron Koenderink [Tue, 6 Jan 2009 23:22:26 +0000 (17:22 -0600)]
Add standard checks to the assigning of a country name
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.
Fix loopholes that let you load and unload foreign commodities
The Chainsaw 3 feature to let you load/unload to a specific amount
through a negative amount argument created loopholes: it let you load
your ships in friendly sectors with the unload command, and unload
friendly ships with the load command. Likewise for land units, with
allied instead of friendly, of course.
Empire 4.0.0 fixed that for the case of loading a land unit from an
allied sector. Get rid of that check, and fix it for good in
load_comm_ok().
Fix load, unload, lload, lunload not to give away civilians
The game generally doesn't let you give away civilians. But the check
in load_comm_ok() for that compared the sector old owner to the player
instead of the ship's or land unit's owner, which is incorrect for
foreign ships or land units. Fix that.
Also make fix the message there not to assume that the civilians are
owned by the player. This can't currently happen, but will when these
commands support use by deities properly.
Make lload require own sector and lunload own land unit
This is for consistency with load and unload.
Before, you could use lunload for allied land units and lload in
allied sectors, but the command failed when stuff was loaded in allied
sectors. Doing that with lload no longer fails the command, because
the check that does that in load_comm_land() is now masked by the new
checks in lload(). Note that loading with lunload still fails the
command; that inconsistency will be removed in a later commit.
load_plane_land() already refused to load planes from foreign sectors.
This commit makes that check redundant, so remove it. Functional
change: lload now refuses to load foreign planes silently, unless both
land unit and plane were named by number. This is consistent with
load.
Make lload and lunload work on foreign lands only when named
load and unload work on foreign ships only when their argument
explicitely names them, i.e. you have to ask for them by number. When
any other syntax is used, load() ignores foreign ships. This makes
sense. Change lload() to work just like that.
Fix relation checks in load, unload, lload, lunload
The check for ship owner's relations to the player was backward: it
checked the player's relations to the ship's owner instead. Abusable:
you could load and unload any ship by declaring friendly to its owner.
Broken since Chainsaw let you load and unload friendly ships.
The check for land unit owner's relations to the player was similarly
backward, similarly abusable, and also broken since day one.
lload and lunload checked sector owner's relations to the land unit's
owner instead of to the player. Harmless, because the two must be the
same to reach the check.
Change info not to prepend a header line to the info page
The contents of the line was partly useless (repetition of the command
argument) and partly misleading (modification time of the formatted
info file, ifndef _WIN32).
Land units were erroneously charged the much lower raw path cost,
except when attacking high-mobility terrain (mountains). Broken in
commit 2673a258, v4.3.6.
Smarter identifier resolution in conditions involving strings
Conditions comparing strings behaved rather erratically: while wing=m
was smartly interpreted as wing='m' (because m is ambiguous as plane
selector), wing=e was not so smartly interpreted as wing=effic
(because e unambiguously identifies effic; this was then rejected due
to incompatible types), and wing=g was even less smartly interpreted
as wing=group.
Address this by a redesign of the identifier resolution rules in
nstr_comp(): If the condition contains just one identifier, it names a
selector. If it contains two, try to intepret either as selector or,
if the other can be interpreted as selector, as value for that.
String selectors accept any identifier as value, numeric selectors
only the ones listed in their table.
Interpret both identifiers as selectors only if their types are
compatible (makes rpath=gu work for ships) and their tables, if any,
match (makes type=spy work for land units).
If more than one interpretation makes sense, drop any value
interpretations of identifiers that are unabbreviated selector names,
and selector interpretations of those that are not (makes wing=w work
for planes).
Change nstr_match_val() to accept any identifier as value for a string
selector. Replace nstr_mkselval() by nstr_resolve_val(), to resolve
string values in addition to symbolic ones. Remove resolution to
string from nstr_resolve_id(), drop its last parameter. Remove unused
nstr_string_ok(). New nstr_is_name_of_ca(), nstr_ca_comparable().
Examples for conditions that are now interpreted differently:
condition old interpretation new interpretation
wing=g wing=group wing='g'
w=g wing=group rejected as ambiguous (1)
w=e wing=effic (2) wing='e'
(1) because both wing='g' and 'w'=group make sense
(2) rejected as incomparable later on
Drop checks whether we can get the op-sector from mission()
getsect() can fail here only when the coordinates are invalid. The
first check uses coordinates from a successful sarg_xy(), so they
can't be invalid. The second check uses coordinates of an object to
be put on the mission. If these are invalid, game state is corrupt,
and failing the mission command doesn't improve the situation a bit.
Before, the escort mission didn't support an op-area, and planes on
escort mission escorted anywhere. Change mission() to define the
op-area for escort missions as well. Show it in mission() and
show_mission(). Check it in find_escorts().
Land unit reactions are overly complex because we have two different
concepts controlling them: reaction radius (set with lrange) and
reserve mission (set with mission). You need to deal with both to set
up or query reactions.
Commit 8d0e1af5 "fixed" this by making reserve missions meaningless.
The previous commit made reserve missions meaningful again: they
support an op-area now. This brought back the problem of having to
deal with two separate commands to accomplish one thing.
Fix this for good by removing non-mission land unit reaction
alltogether. The only feature we lose by that is the ability to order
land units to react until the order is explicitely cancelled. That's
because missions are implicitely cleared by many commands and events,
while non-mission reaction wasn't. Closes #858121 and #858122.
Remove the non-mission reaction case from att_reacting_units().
Don't limit reserve missions to the land unit's reaction radius: make
lnd_reaction_range() return the type's maximum radius instead of
lnd_rad_max.
The reaction radius is now useless. Remove the lrange command, and
struct lndstr member lnd_rad_max along with its selector react.
Remove land command's column rd. Make ldump show column react as
zero. Deprecate edit key 'P' in dounit(), and don't show it in
pr_land().
Make land units on reserve mission react within op-area
Before, they always reacted to their maximum range, and the op-area
was unused. Change mission() to define the op-area for reserve
missions as well. Remove the special-case for showing reserve
missions from mission() and show_mission(). New lnd_reaction_range()
factored out of att_reacting_units(). Use it in oprange() to cover
reserve missions. Pass the mission as separate parameter to oprange()
for now, because miss() doesn't set it in the object until later.
The mission command limits op area radius to the possible range.
That's okay, as it doesn't actually restrict possible op areas. When
the mission is executed, it was limited again. Don't do that; remove
the limiting code from build_mission_list_type() and show_mission().
The removed limiting had no effect, except when the range shrunk.
Then limiting reduced the op area more than necessary. For instance,
consider an object O with initial range 3 on a mission around M with
range 3:
- - - y - - -
- - z y - -
- - z x y - -
- O x x M -
- - z x y - -
- - z y - -
- - - y - - -
Initially, all sectors not marked - are in range and in the op area.
If the range drops to two, sectors marked O, x and z are still in
range of O. But only the x are still in range of M. The O and z got
excluded.
Range can currently shrink when plane range is reduced (range
command), or a ship, plane or land unit somehow loses tech (deity
intervention).
Clean up removal of reserve mission mobility bonus
Land units on reserve missions used to pay only half the usual
mobility for combat. This bonus was commented out in the code in
4.0.0, but not in info. Remove it from both.
Fix make dist in a separate build directory without git
In that case, make copied the sources.mk from $srcdir, but unless it
existed already, the peculiar workings of VPATH did us in: make
searched for the target, found it in $srcdir, and the dependency
became circular.
Fix by keeping sources.mk in $srcdir always. We can build it there,
because its contents depends only on git state, not on anything in the
build tree. This avoids the need to copy sources.mk alltogether.
Don't let ships double-retreat first on 'i' and then on 'h'
When a ship is shelled, retreat condition 'i' (injured) applies. When
there's no return fire, 'h' (helpless) applies as well. Ships
retreated twice in that case. Fix that.
Ron Koenderink [Sun, 16 Nov 2008 14:42:42 +0000 (08:42 -0600)]
Log out player when time per day is exceeded
Commit 3da4030 already changed player_main() to log out the player
when m_m_p_d was exceeded in command(). This crept in accidentally.
Complete the job by changing status() to log out the player instead of
downgrading him to visitor status.
Also, change player_main(), command() and status() to apply the time
limit to countries in sanctuary in addition to active countries.
Leave visitors alone, because those are shared logins. Make the
disconnect message to a player consistent for all situations.
Note that commit 875a80d1 already changed player_main() to apply the
time limit only to active countries instead of all, just like status()
does, but neglected to document that.
Capital obliteration failed to charge money and report news
Commit 221e88f1 (v4.3.15) made caploss() expect the new owner in
sct_own, so it can distinguish between sack and obliteration. Commit 0d139ee1 (v4.3.17) broke that in sct_prewrite(): it moved zapping the
sector owner after caploss(), and passed 0 instead of the old owner to
caploss(). Because of that, obliterating a capital didn't make the
news and didn't cost the victim money. Fix that.
Ron Koenderink [Sat, 15 Nov 2008 19:08:19 +0000 (13:08 -0600)]
Rewrite accounting of play time
Replace daychange() and gettimeleft() by update_timeused_login(),
update_timeused() and enforce_minimum_session_time(). The new
code doesn't assume the day is always 24 hours long which can
occur when transitioning into or out of DST and such. Logging
in after more a multiple of 128 days now resets nat_timeused
properly.
Fix nat_timeused calculation on midnight rollover to include
the time since midnight.
struct natstr member nat_dayno and struct player member timeleft
are now unused, remove them.
Ron Koenderink [Mon, 10 Nov 2008 00:06:51 +0000 (18:06 -0600)]
Fix parsing of 24:00 in game_hours and update_demandtimes
daytime() rejects 24:00 as invalid. This makes daytime_range()
fail, is_daytime_allowed() ignore this and later ranges silently.
Broken in commit acdee1e3, v4.2.15.
With RAILWAYS, highway-like sectors double as rail. They need to be
at least 5% efficient to be operational, and then they additionally
extend rail into adjacent sectors that are at least 60% efficient.
New opt_RAILWAYS, SCT_HAS_RAIL(), sct_rail_track(). Update
sector_mcost(), bp_neighbors(), lnd_mar_one_sector() for RAILWAYS
mobility rules. Update sinfra(), spyline(), satdisp_sect() to show
rail track instead of rail infrastructure for RAILWAYS.
New virtual sector selector track, implemented by nsc_sct_track().
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().
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.
Ron Koenderink [Tue, 28 Oct 2008 14:48:25 +0000 (08:48 -0600)]
Represent logged in time in seconds rather than minutes
This simplifies things. In particular, it gets rid of random rounding
in getcommand(), which created a variation in the nightly build
depending on whether the update starts before or after the deity logs
out.
Replace struct natstr member nat_minused by nat_timeused, and update
cou_ca[] accordingly (this affects xdump nat). Replace player member
minleft by timeleft, and getminleft() by gettimeleft(). Update
getcommand(), daychange(), player_main(), status() accordingly, taking
care not to change player output. Change edit country key 'u' to work
in seconds.
Ron Koenderink [Sun, 26 Oct 2008 21:56:04 +0000 (15:56 -0600)]
Add more tests to nightly builds
Add Player 02 as an ally for Player 01.
Add tests for telegrams, wall, announce, relationships,
land units, wire, fire, attack, planes, autofish and autooil.