Commit graph

3711 commits

Author SHA1 Message Date
3a5e23a020 Rearrange struct sctstr slightly to expose commonalities with units
Nice bonus: space needed for sectors shrinks some 4%.  Size of game
state could shrink perhaps 1-2%.
2010-01-19 08:37:05 +01:00
aa659c7754 Narrow struct sctstr member sct_mobil to char
To bring it in line with unit mobility.
2010-01-19 08:37:05 +01:00
ca2dba33f0 Make struct sctstr member sct_effic signed
To bring it in line with unit efficiency.
2010-01-19 08:37:05 +01:00
76575df96b Streamline fortgun()'s efficiency comparison
Use >= 60 instead of > 59, for consistency with similar comparisons
elsewhere.
2010-01-19 08:37:05 +01:00
da48ba6d13 Fix sloppy sanity check for mobility going negative in transport
Assignment to sct_mobil was vulnerable to integer underflow.  Should
not happen, as move_ground() never returns a cost exceeding available
mobility.
2010-01-19 08:37:05 +01:00
2fa5f65257 Generation numbers to catch write back of stale copies
Oops when a stale copy is written back, i.e. the processor was yielded
since the copy was made.  Such bugs are difficult to spot.  Sequence
numbers catch them when they do actual harm (they also catch different
bugs).  Generation numbers catch them even when they don't.

New ef_generation to count generations.  Call new ef_make_stale() to
increment it whenever the processor may be yielded.

New struct emptypedstr member generation.  To conserve space, make it
a bit-field of twelve bits, i.e. generations are only recorded modulo
2^12.  Make sure all members of unit empobj_storage share it.  It is
only used in copies; its value on disk and in the cache is
meaningless.  Copies with generation other than ef_generation are
stale.  Stale copies that are a multiple of 2^12 generations old can't
be detected, but that is sufficiently improbable.

Set generation to ef_generation by calling new ef_mark_fresh() when
making copies in ef_read() and ef_blank().  nav_ship() and
fltp_to_list() make copies without going through ef_read(), and
therefore need to call ef_mark_fresh() as well.  Also call it in
obj_changed() to make check_sect_ok() & friends freshen their argument
when it is unchanged.

New must_be_fresh() oopses when its argument is stale.  Call it in
ef_write() to catch write back of stale copies.
2010-01-19 08:36:01 +01:00
358aee203e Store sequence numbers more compactly
Store them and ef_type in bit-fields.

Allocate eight bits for ef_type.  Values range from 0 to EF_GAME
(currently 16), so this is plenty.

Allocate twelve bits for sequence numbers.  Sequence number mismatches
are now missed when the numbers are equal modulo 2^12.  Still
sufficiently improbable.

Common machines store the bit-fields in a 32 bit word.  There are
twelve bits left in that word for future use.  Total savings 16 bits,
which is exactly what the previous commit spent on wider uids on
common machines.
2010-01-19 08:31:10 +01:00
ba2044be18 Store uids as int to support more sectors and units
Before, they were stored as short.  Wider uids use more space, but the
next commit will recover it by narrowing other members.

The use of short has always limited the number of ships, planes, land
units and nukes to SHRT_MAX (commonly 32768).  Only the most extreme
games ever came close.

Commit 49780e2c (v4.3.12) added struct sctstr member sct_uid to make
struct empobj member uid work for sectors.  This made the limit apply
to sectors as well.  We've had games with more than 32768 sectors.
2010-01-19 08:26:42 +01:00
18148f03fa Fix new_seqno()'s recovery from seqno mismatch
A sequence number mismatch occurs when an invalid copy (with a stale
sequence number) gets written.  To continue after the error, we need
to use the current sequence number.  But new_seqno() used the larger
one of the two, which is correct only as long as sequence numbers do
not overflow.  Overflow is rather unlikely, though.
2010-01-19 08:26:39 +01:00
0ba61f1714 Record news more compactly
Member nws_uid is unused since the commit before previous.  Remove it.

Member nws_seqno is of marginal value, because we write news only
through ncache[], and thus aren't prone to the errors sequence numbers
can catch.  Remove it.

Make timestamp selector virtual, computing nws_when + nws_duration,
and remove member nws_timestamp.  Impact:

* In ncache(), the removed timestamp equals nws_when + nws_duration,
  both for new news and updated news.  No change.

* delete_old_news() becomes invisible.  Before, its move of unexpired
  news to the beginning of the news file touched all the timestamps.
  That was unwanted, because the move does not change news, only their
  storage.  Improvement.

* empdump no longer flags the imported news changed via the timestamp.
  This is somewhat unfortunate.  Document as bug.

With these members removed, struct nwsstr no longer matches struct
emptypedstr, so clear news table flag EFF_TYPED and remove union
empobj_storage member news.  This loses the automatic maintenance of
member ef_type via struct emptypedstr.  Remove ef_type as well.

This shrinks struct nwsstr from 20 to 12 bytes on common 32 bit
machines, and from 32 to 16 bytes on common 64 bit machines.  Since
the server doesn't map the whole news file (EFF_MAP is off), this
reduces I/O, while the table's memory use remains the same.

Historical note: struct nwsstr is now pretty much what it was back in
BSD Empire 1.1.  Members ef_type and nws_uid go back to Empire 3 (for
C_SYNC?).  v4.3.12 added member nws_timestamp, which doubled the size
on common 64 bit machines.  v4.3.15 added nws_seqno.
2010-01-19 08:21:56 +01:00
b719f39c0f New news selector duration
Backed by new struct nwsstr member nws_duration.  Time between first
and last occurence of the news recorded in this item, in seconds.
2010-01-19 08:21:55 +01:00
39114987a9 Revert "Get rid of struct newscache"
This reverts commit 832574b6de.

To prepare for removal of struct nwsstr member nws_uid.

Conflicts:

	src/lib/subs/nreport.c
2010-01-19 08:21:55 +01:00
4e895465df Remove unused members of struct lndstr, lonstr, nukstr, trtstr
struct lndstr member lnd_flags is a leftover from Empire3's C_SYNC,
which was ripped out in 4.0.0.

struct lonstr member l_sel, struct nuk_str members nuk_ship, nuk_land,
and struct trtstr member trt_bond have been there basically forever
without any use.
2010-01-19 08:21:37 +01:00
d8c940ec2c Consistently use int for sector and unit uid parameters 2009-12-31 09:45:56 +01:00
c0ed527311 Consistently use int for file type parameters and locals 2009-12-29 17:23:22 +01:00
60519b3cd0 Consistently use int for mission type parameters 2009-12-29 13:06:35 +01:00
b23c52951f Fix launch not to wipe out target sector updates
Launching ABMs updates their base, in mission_pln_equip().  The update
got wiped out when launch_missile() wrote back the target sector,
triggering a seqno mismatch oops.  Harmless with the stock game's
ABMs, because they use neither shells nor petrol.

Fix by re-reading the target sector.
2009-12-26 14:02:50 +01:00
7dc130b7ac Fix launch not to wipe out target ship updates
Ships can expend shells to defend against missiles, in
shp_missile_defense().  Any shell use by the target ship got wiped out
when launch_missile() wrote back the target ship, triggering a seqno
mismatch oops.

Fix by re-reading the target ship.
2009-12-26 11:28:25 +01:00
de5c0b1c6b Bump version to 4.3.24 2009-12-26 10:20:21 +01:00
611d349f3f Fix nightly build
Commit 5f89f8cb added pre_update.econfig with incorrect permissions.
2009-12-14 06:56:23 +01:00
5eb1250ff2 Update change log for 4.3.23 2009-12-13 17:37:13 +01:00
c528fcbe3e Update known contributors comments 2009-12-13 17:34:28 +01:00
2752c777ca Belatedly update make dependencies for standalone client build
main.$O was out of date since commit 518c8d6f.
2009-12-13 08:58:07 +01:00
Ron J Koenderink
5f89f8cba3 Don't patch constants.c for nightly, use econfig 2009-12-13 08:20:01 +01:00
c5e2c99546 Fix info navigate on missile interdiction targets
Missile interdiction targets only "valuable" ships since Empire 3.
2009-12-13 08:20:01 +01:00
a4b167eb18 Fix info Mobility not to claim missions get a bonus
Bonus was dropped in v4.0.0.
2009-12-13 08:19:54 +01:00
25d2050769 Make transport chopper not light
Capability light has no effect for choppers since commit 041ad4ce,
v4.3.11.
2009-12-13 08:19:52 +01:00
2178aa87f9 Fix messages in msl_launch() 2009-12-13 08:19:52 +01:00
22071b4edb Don't intercept tactical and marine missiles targeting planes
Missiles attacking ground targets (sectors, ships or land units) can
be intercepted, missiles targeting planes can't.  Except msl_launch()
checked the missile's capabilities instead of its target, and thus
intercepted missiles that *could* target ground even when they
targeted planes.

This broke the missile interception code's assumption that
interceptors aren't intercepted, and crashed the server through
infinite recursion: tactical abm #1 intercepts, tactical abm #2
intercepts #1, #1 intercepts #2, ...

Same bug in msl_hit() printed "incoming missile" for missiles that
could target ground but do target planes.

Broken in Empire 2.  Bug can't bite with the stock game's planes.
2009-12-13 08:13:29 +01:00
fd894d9864 Fix and enable collateral damage for missing missiles
Collateral damage was disabled, because after msl_hit() reported a
miss, the missile may or may not have reached the target.

Fix by splitting msl_launch() off msl_hit().

Drop the disabled collateral damage code for sector targets, because
sectors can't be missed.  Enable it for ships and land units.

Since msl_launch() returns whether the missile is sub-launched, drop
launch_missile() parameter sublaunch, and simplify its caller.
2009-12-13 08:05:26 +01:00
e7fec28009 News reported victim as actor for sub-launched anti-sat and ABM
If the intercepted missile was sub-launched as well, this disclosed
its owner.

The stock game's anti-sats and ABMs can't be sub-launched.
2009-12-13 08:05:25 +01:00
4dbee9a388 Clarify how perform_mission() uses missiles
Interdiction of ships and land units with missiles happens elsewhere.
Oops when perform_mission() strays on that turf.
2009-12-13 08:04:08 +01:00
0060e48ea4 Refactor missile interception code
Keep only the common part in msl_intercept(), and give it internal
linkage.  Wrap new msl_abm_intercept() and msl_asat_intercept() around
it.  They are simpler to use.
2009-12-13 08:04:07 +01:00
de2fae0ee6 Fix defense value of intercepted missiles and satellites
Use the plane's defense value, not the plane type's base value.
2009-12-13 08:04:07 +01:00
81163f9f20 Fix missiles interdicting ships outside range or op area
Ship interdiction works sector by sector.  Interdicting missiles
targeted all ships not yet interdicted, not just the ones in the
current sector.  This could lead to interdiction outside missile range
or op area.
2009-12-13 08:04:07 +01:00
eace95fab8 Get rid of msl_launch_mindam()
It's awkward, especially in shp_missile_interdiction().  Inline into
callers and simplify.
2009-12-13 08:04:07 +01:00
e043ea4531 Simplify control logic in msl_intercept() 2009-12-13 08:04:07 +01:00
0f0d785601 Don't attempt to hide owner of sub-launched satellite
The attempt was pointless, because the recipient of the message could
see the owner on skywatch, and the news reported it as well.
2009-12-13 08:03:51 +01:00
6ee75ce4e9 Fix typo in info Selector 2009-12-13 08:03:49 +01:00
f7f3178ce2 Move msl_equip() to callers, internal linkage 2009-12-13 08:03:49 +01:00
42cc4f14e0 Move "Releasing RV's" message into detonate() 2009-12-13 08:03:49 +01:00
a269cdd7e9 Limit nukes to strategic missions
Before Empire 2, nukes could be delivered only with bomb (special
mission 'n', airburst only) and launch (targeting sectors or
satellites only).

Empire 2 made nukes available for any kind of bombing, and for any
missile strike on sectors or ships.  This included interdiction and
support missions.  Nuclear-tipped anti-sats and bomb mission n were
removed.

Unfortunately, this was done in a messy way, which led to
inconsistencies and bugs.  The problem is that ordinary damage affects
just the target, while nuke damage affects an area.  Code dealing with
plane damage was designed for the former.  Instead of rewriting it to
cope with area damage cleanly, nuke damage got shoehorned into
pln_damage(), the function to compute conventional plane damage, as a
side effect: computing damage blasted sectors in the area.

If the plane carried a nuke, pln_damage() returned zero (conventional)
damage.  Without further logic, this simply bypassed the code to apply
damage to the target.  This worked out okay when the target already
got damaged correctly by the side effect.

However, some targets are immune to the side effect: when interdicting
a move or explore command, the commodities being moved are not in any
sector.

For other targets, damage has effects other than damaging the target:
offensive and defensive support don't apply the (conventional) damage
to the target sector.  Instead, they turn it into a combat bonus.
Without further logic, nuclear damage doesn't contribute to that.

To make all that work, pln_damage() returned the nuclear damage for
ground zero as well.  Because a plane does either conventional or
nuclear damage, one of them is always zero.

Most callers simply ignored the nuclear damage, and applied only the
conventional damage.

Bug: land units and ships failed to retreat when pin-bombed or
missiled with a nuke.  That's because they received zero conventional
damage.

The mission code flies planes and missiles and tallies their damage.
This mission damage included nuclear damage at ground zero (except for
missiles sometimes, see below), to make support and commodity
interdiction work.  Unfortunately, this broke other things.

Bug: when bombers interdicted ships or land units, nukes first damaged
the ships or land units by the side effect, then again through mission
damage.  Interdicting missiles had a special case to avoid this.

Bug: when interdicting move, explore or transport, nukes first damaged
the sector by the side effect, then again through mission damage's
collateral damage.

There may well be more bugs hiding in this mess.

The mess is not worth fixing.  While the idea of interdicting and
supporting with nukes sounds kind of cool, I believe it's pretty
irrelevant in actual play.

Instead, go back to a variation of the original rules: nukes can be
delivered only through bomb mission 's' and launch at sectors.

Make arm reject marine missiles in addition to satellites, ABMs and
SAMs, and clear the mission.  Make mission reject planes armed with
nukes.  Oops when they show up in mission_pln_equip() anyway.

Make pln_equip() allow planes with nukes only for missions 's' and
't'.

Clean up pln_damage() to just compute damage, without side effect.
Change strat_bomb() and launch_missile() to detonate nukes.  Simplify
the other callers.  Parameter mission of msl_launch_mindam() is now
unused, remove it.

Missiles exploding on launch no longer set off their nukes.  That was
pretty ridiculous anyway.
2009-12-13 07:46:00 +01:00
b0ba9022dc Remove unused missions from mission_pln_equip() 2009-12-12 16:30:32 +01:00
528df9acba Improve launch diagnostic messages, switch off supply
msl_equip() used mission_pln_equip(), which is for automatic defenses,
and therefore silent.  Its users launch_as(), launch_missile() and
launch_sat() printed failure diagnostics based on assumptions on what
could go wrong.

Switch to the appropriate function for commands, pln_equip(), and
remove the guesswork.  Implement mission 'i' there.  When launching
from a foreign base, its owner now gets informed.  Unimportant at this
time, as players can't easily deploy missiles in foreign bases.

This change also switches off automatic supply for launch.  Consistent
with bomb.
2009-12-12 16:28:52 +01:00
cf960a573c Make anti-sat launch consistent with interception
When a manually launched anti-sat hits, it now always destroys the
satellite.  This matches what it does when it intercepts
automatically.  Before, it only damaged the satellite.
2009-12-12 16:28:52 +01:00
3e5df7530d Fix satellite interception not to break "positioned over" line 2009-12-12 16:28:52 +01:00
3a4b50b815 Comment fix 2009-12-12 16:28:52 +01:00
7312693936 Improve message when refusing to load plane on unsuitable ship
Test more specific causes before more general ones.  Also get rid of
silly strcpy().
2009-12-12 16:28:52 +01:00
0100402e5f Don't permit nukes on satellites, ABMs and SAMs
Before, satellites could be disarmed and armed even in orbit.  Nukes
on satellites went along into orbit, where they did nothing in
particular.

Nukes on ABMs and SAMs were lost without effect when their missile
intercepted.

The stock game is not affected, because its satellites, ABMs and SAMs
all have zero load.
2009-12-12 16:28:52 +01:00
61233e47e8 Drop capabilities stealth and half-stealth
These were leftovers from Chainsaw, and their only remaining effect
was a flak bonus.

The got replaced except for flak by plane selector stealth under
Chainsaw option STEALTHV, which became mandatory in Empire 2.  It is
unclear why STEALTHV didn't cover flak.  No planes with these
capabilities have existed in the stock game since Empire 2.
2009-12-12 16:28:52 +01:00