Commit graph

3416 commits

Author SHA1 Message Date
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
da363d621e Remove useless strncpy() in ac_encounter() 2009-02-01 17:14:39 +01:00
7b4c0d171f 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().
2009-02-01 17:14:39 +01:00
b54454fbc4 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.
2009-02-01 17:14:38 +01:00
80cf1b5be0 Simplify ac_encounter()'s logic for stealthy evasion 2009-02-01 17:14:38 +01:00
e8adf2dafb 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().
2009-02-01 17:14:38 +01:00
ee1e0ab0e1 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.
2009-02-01 17:14:38 +01:00
99cf705530 Refactor interception over ships and land units
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.
2009-02-01 17:14:38 +01:00
2030decb99 Make planes report non-hostile ships and lands in target sector
Before, ac_encounter() reported only ships and land units hostile to
the planes.
2009-02-01 17:14:38 +01:00
b624ce30dd Pass only PM_* mission flags to ac_encounter()
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.
2009-02-01 17:14:38 +01:00
4ea1d3acff Fix mixed ASW patrols
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.
2009-02-01 17:14:38 +01:00
e3d4bb0080 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.
2009-02-01 17:14:38 +01:00
Ron Koenderink
08b9455682 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.
2009-02-01 17:06:33 +01:00
Ron Koenderink
a7ee69d112 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).
2009-02-01 08:58:37 -06:00
Ron Koenderink
d1ff2a6089 Factor out gamehours and max minutes per day checks
Combine the checks from player_main(), command() and status() into
may_play_now().
2009-02-01 06:29:57 -06:00
Ron Koenderink
a499a5d8f2 Prevent command from executing outside of game hours
If a player is at a prompt when game hours restrictions start,
they can enter one more command.  Not fixed in commit 3da4030a,
v4.3.19.
2009-01-24 10:25:57 -06:00
Ron Koenderink
a3c991bcce Fix enforcing game hours for players already logged in
Broken in commit 875a80d1, v4.3.19.
2009-01-24 10:21:19 -06:00
Ron Koenderink
b976d11884 Suppress the git checkout information for nightlybuilds 2009-01-20 19:50:33 -06:00
Ron Koenderink
8b12839565 Update windows configuration for nightlybuild 2009-01-20 19:35:17 -06:00
Ron Koenderink
c8688dbe01 Simplify the time() replacement for nightlybuilds
Move the time() replacement from emptime.c.patch file
to nightlybuild.sh.
2009-01-13 19:20:34 -06:00
Ron Koenderink
d0f3847d1d Prevent distribution from abandoning the distribution center
If there are no civilians in the distribution center, distribution
could abandon the sector by distributing out all the military.
2009-01-07 07:57:37 -06:00
Ron Koenderink
afdd0b00c8 Cleaned up check_nat_name() function
No functional changes.  Rename temp to p and nonb to allblank.
2009-01-06 17:48:37 -06:00
Ron Koenderink
aa5861d10b 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.
2009-01-06 17:22:26 -06:00
17ad9fc5f2 Simplify load() and lload()
Also make them more similar.  No functional change.
2009-01-06 18:54:44 +01:00
2e6f971b6c Make load, unload, lload and lunload usable for deities
Fix ownership tests in load(), lload(), load_plane_ship(),
load_land_ship(), load_plane_land(), load_land_land().
2009-01-06 18:51:27 +01:00
c4c7cac6fe Check for unit on trading block last in load() and lload()
This is to make them more similar, and to get the market code out of
the way.
2009-01-06 18:49:39 +01:00
5cbab82dcf Factor move_amount() out of load_comm_ship() and load_comm_land() 2009-01-06 18:48:26 +01:00
a78f71ff99 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().
2009-01-06 18:48:04 +01:00
92a366ce24 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.
2009-01-06 18:48:04 +01:00
430ce903d3 Factor load_comm_ok() out of load_comm_ship() and load_comm_land()
Functional change: attempting to load or unload foreign civilians no
longer fails command.
2009-01-06 18:48:04 +01:00
bf2fd042ab 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.
2009-01-06 18:43:07 +01:00
17d19266dc 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.
2009-01-06 16:02:51 +01:00
afb512fad7 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.
2009-01-06 14:59:01 +01:00