Planes normally sit in their base (sector or carrier), where they can
be spied, damaged, captured, loaded, unloaded, upgraded and so forth.
All this must not be possible while they fly. There are two kinds of
flying planes: satellites in orbit, and planes flying a sortie.
Satellites in orbit have always been marked with flag PLN_LAUNCHED.
Works. What didn't work was tracking planes flying a sortie.
If you look at one sortie in isolation, up to three groups of planes
can be flying at any point of time: the primary group, which carries
out the sortie's mission (bomb, transport, ...), their escorts, and a
group of hostile planes flying interception or air defense.
The old code attempted to track these planes by passing those groups
to the places that need to know whether a plane is flying. This was
complex and incomplete, and broke down completely for the pin-bombing
command.
It was complex, because the plane code needs to keep track of all the
call chains that can lead to a place that needs to know whether a
plane flies, and pass the groups down the call chains. This leads to
a rather ugly passing of plane groups all over the place.
It was incomplete, because it generally failed to pass the escorts.
And the whole scheme broke down for the pin-bombing command. That's
because pin-bombing asks the player for targets while his planes are
loitering above the target sector. This yields the processor and lets
other code run. Which does not get the flying planes passed.
The new code marks planes and SAMs (but not other missiles) flying a
sortie with flag PLN_LAUNCHED (the previous commit laid the groundwork
for that), and does away with passing around groups of flying planes.
This fixes the following bugs:
* Many commands could interact with foreign planes flying for a
pin-bombing command as if they were sitting in their base. This
includes spying, damaging, capturing, loading, or upgrading them,
and even getting intercepted by them. Any changes to those planes
were wiped out when they landed. Abusable.
* The bomb command could bomb its own escorts, directly (pin-bomb
planes) or through collateral damage, strategic sector damage,
collapsing bridges or nuke damage. The damage to the escorts was
wiped out when they landed.
* If you asked for a plane to fly both in the primary group and the
escort group, you got charged fuel for two sorties instead of one.
* pln_put1() and pln_put() now recognize planes that didn't take off,
and refrain from making them land. Intercept (since commit c64e2149) and air defense can do that. Making them land had no
ill-effects, but it was still wrong.
There's one new problem: if PLN_LAUNCHED doesn't get reset properly,
due to game crash during flight or some other bug, the plane gets
stuck in the air. Catch and fix that on game start in ef_verify().
Distinguish between planes "in orbit" and "launched"
Use new pln_is_in_orbit() when we want to test for orbit specifically,
and test PLN_LAUNCHED when we want to test whether the plane not
sitting in the sector (because it is flying). This distinction is
pointless at this time, because the only way PLN_LAUNCHED gets set is
when a satellite goes into orbit. It will become useful in a later
commit, which will use PLN_LAUNCHED to mark flying planes.
Factor out a single plane's end of sortie into new pln_put1()
Use it in pln_put() and ac_planedamage().
This changes ac_planedamage() to deal with a destroyed airbase.
Before, aborted planes happily landed there. This bug could not
actually bite, because the code neither yields nor does damage to
potential airbases between checking the landing airbase before takeoff
and aborting planes in ac_planedamage().
It changes pln_put() to cope with dead planes. Before, it made them
land as if they lived, fortunately without ill effects (complaints
about not being able to land were suppressed for dead planes).
ac_planedamage() removes dead planes, but pinflak_planedamage()
doesn't, and these end up in pln_put(). pinflak_planedamage() no
longer has to take shot down planes off their carriers, because
pln_put() now takes care of that.
Interception builds lists of planes that could intercept. Only list
nodes for missiles were freed. Broken since BSD Empire 1.1.
The fix frees interceptors that actually intercepted when
ac_intercept() returns, and the interceptors that didn't when
ac_encounter() returns.
The latter introduces a small bug: it passes planes that didn't fly to
pln_put(). pln_put() expects only planes that actually took off.
Same bug exists in air defense missions. Luckily, it has no ill
effects. To be fixed soon.
Fix trade to enforce destination rules for satellites and asats
Trade teleports planes to a destination chosen by the buyer, except
for satellites in orbit. trad() failed to enforce the usual rules on
destinations for satellites (not in orbit) and asat missiles: they
could be teleported anywhere. Abusable, because abms intercept from
anywhere, and satellites can be launched from unowned sectors, even
sea. Broken since BSD Empire 1.1.
multifire() used shots to print either shell or shells. 4.2.3 removed
its initialization for land unit fire, and commit 22c6fd8b removed it
for ship fire. Fix by just printing shells always.
Ron Koenderink [Sun, 16 Mar 2008 23:09:00 +0000 (17:09 -0600)]
Remove pre_update_hook decoration
Improve the portability. The Windows version of "echo" does
not support single quotes as a quoting character and therefore
fails and prevents updates in the Windows nightly build.
The old code let each defender fire on each target separately. To
avoid charging ammo multiple times, it didn't update the defenders
after fire; it charged them in use_ammo() instead. Bugs: not updating
the defender lost any shells fetched by automatic resupply, and
use_ammo() always charged one shell for gun fire, which was wrong for
most ships and land units.
Rewrite to let each defender fire once, updating it normally. Reuse
the damage for the other targets. This also yields the proper
probability distribution for damage.
add_to_fired_queue() adds a defender at most once. It neglects to
free the defender flist nodes it doesn't add. Broken since option
MULTIFIRE appeared in Chainsaw.
Make deffld() reject fields whose selector has flag NSC_EXTRA set.
Since xundump() doesn't provides space for these, the bug could lead
to buffer overruns.
Make sure all members of unit empobj_storage share it.
Add matching timestamp member to struct comstr, struct empobj, struct
gamestr, struct lonstr, struct natstr, struct nwsstr, struct trdstr,
struct trtstr. The timestamp isn't yet set for these. To be fixed.
Move the timestamp member to the right place in struct lndstr, struct
loststr, struct realmstr, struct nukstr, struct plnstr, struct sctstr,
struct shpstr.
empdump exports and imports game state as plain text. Limitations: it
currently can't export player bmaps, power report, telegrams,
announcements, message of the day, no-login message and log files.
Exported floating-point values may be inexact. Importing an exported
game state may not result in identical data files; besides the loss of
floating-point precision just mentioned, coordinates are normalized,
and characters beyond a string's terminating zero in a character array
are lost. Bug: importing resets timestamps to zero. It should set
them to the current time.
Don't store land unit stats in struct lndstr, part 1
New lnd_att(), lnd_def(), lnd_vul(), lnd_spd(), lnd_vis(), lnd_frg(),
lnd_acc(), lnd_dam(), lnd_aaf() replace the struct lndstr members with
the same names.
Make land unit selectors att, def, vul, spd, vis, frg, acc, dam, aaf
virtual.
Where ordinary selectors specify a value stored in some object,
virtual selectors specify a function to call to compute a value
associated with some object.
Use them to replace the special case xdump ver by new table
EF_VERSION.
Move configkeys[] to lib/common because nsc_init() needs it to
initialize empfile[EF_VERSION].cadef.
Factor out common land unit fire code into lnd_fire()
This takes care of a number of bugs / inconsistencies:
* Resupply before fire: fire command did not require unit to be in
supply, and resupplied shells. Everywhere else (return fire,
support and interdiction) the land unit had to be in supply after
resupply of everything. Unify not to resupply anything and not to
require being in supply. This is consistent with ships and sectors.
* Resupply after fire: fire command resupplied shells after active
fire. Unify not to do that. This is consistent with ships and
sectors.
* When a land unit returned fire to multiple attackers, quiet_bigdef()
charged it ammo for each one. Finally, it was charged one shell
more by use_ammo(). Except only the first land unit got charged
there in fact, because buggy add_to_fired_queue() entered only the
first land unit into the defender list. Fix add_to_fired_queue()
and change quiet_bigdef() not to charge ammo, just like for ships
and sectors. This charges only one shell instead of the true ammo
use, which is wrong, but consistent with ships.
* lnd_support() tallied support damage unrounded. Unify to round
before tally.
Factor out common torpedo fire code into shp_torp()
This takes care of a number of bugs / inconsistencies:
* Submarines with zero mobility could interdict. Change to require
positive mobility.
* Submarines with zero firing range could not interdict. Fix by
dropping the test from perform_mission(). No ships in the stock
game are affected.
* Submarines without capability torp could fire return torpedoes and
interdict. Stock sbc, nm and msb were affected by the return fire
bug. Closes bug#950936.
* Shell resupply bugs: quiet_bigdef(), fire_torp() and
perform_mission() resupplied before checking all other requirements
and could thus get more shells than actually needed.
torp() no longer resupplies shells. It's hardly worth the bother, and
fire doesn't do it either.
Fix torpedo return fire line of sight requirement and range
anti_torp() required line of sight and used gun range for all kinds of
return fire. Require line of sight only for torpedoes, not for gun
fire and depth charges. Use torpedo range for torpedoes, gun range
for gun fire and depth charges.
Factor out common ship gun fire code into shp_fire()
This takes care of a number of bugs / inconsistencies:
* Ships with zero firing range could return fire and fire support, but
not fire actively or interdict. Fix by testing for gun limit
instead in multifire() and mission(). No ships in the stock game
are affected.
* Required gun crew was inconsistent: multifire() let N military fire
max(1,floor(N/2)) guns for active fire. Ditto perform_mission() for
interdiction. quiet_bigdef() let them fire N guns for returning gun
fire. Ditto sd() for firing support and firing at boarding parties.
fire_dchrg() let them fire floor(N/2) for returning fire to
torpedoes. Unify to let N military fire floor((N+1)/2) guns.
* Shell use was inconsistent: sd() and perform_mission() used one
shell per gun, everything else one per two guns. Unify to one shell
per two guns.
* Shell resupply bugs: multifire() got two shells regardless of actual
ammo use. quiet_bigdef() got one shell (but use_ammo() uses only
one, which is a bug). sd() and perform_mission() resupplied before
checking all other requirements and could thus get more shells than
actually needed.
Before 4.0.6, depth charges required no guns, one military, did damage
like shell fire from two guns, and used two shells. Missions were not
quite consistent with that (bug). 4.0.6 changed depth charges to work
exactly like shell fire (but without updating documentation
accordingly): require guns and gun crew, non-zero firing range, scale
damage and ammunition use with guns.
Go back to the old model, but with damage like three guns, to avoid
changing the stock game's dd now (three gun damage for two shells).
Stock game's af changes from two gun damage for one shell, and nas
from four gun damage for two shells.
Factor out common depth-charging code into shp_dchrg().
Factor out common fortress fire code into fort_fire()
This takes care of a number of bugs / inconsistencies:
* sb() fired support even when there were not enough mil.
* Shell resupply bugs: multifire() and quiet_bigdef() resupplied
shells before checking all other requirements and could thus get
more shells than actually needed.
The macros defining unit stat development in tech are somewhat
inconvenient to use. Define more convenient functions, and hide away
the macros near the function definitions.
If gcc's preprocessor chokes, it leaves an empty dependency file
behind, and doesn't touch the object file. If an old object file
exists, and is newer than the .c file, make will then consider the
object file up-to-date. This can lead to nasty version errors.