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.
delete_old_news() and init_nreport() tested for non-zero nws_when,
which is breaks for news at the epoch. Not likely to happen, but
still wrong.
ncache() tested nws_uid, which breaks for the first entry in the news
file. This made ncache() overlook that entry in the cache, and create
a new news item instead of incrementing nws_ntm. Was always broken
that way.
The call of ef_ensure_space() serves no purpose: the blank records it
adds are ignored on read, and overwritten (not updated) by new news.
Get rid of it.
Use ef_blank() when extending treaty, loan, comm and trade file
Only treaty extension initialized ef_type and uid properly. None of
them zeroed unused members and holes in the struct. comm and trade
extension called ef_extend(), which had no effect, so remove that.
Use get_empobj() instead of get_empobjp() in unit_map()
The get_FOOp() macros are generally avoided outside the update,
because direct access to the sector cache needs synchronization to be
safe. unit_map() didn't access the cache directly until it was
converted from get_ship() & friends to get_empobjp() in commit fec9878c. Switching to get_empobj() reverts the change to direct
access while keeping the simplification.
put_empobj() used struct empobj member uid, which is valid only for
units. Existing users pass only units, fortunately. Fix by making it
take type and uid parameters.
This led to a bogus message when an interactive explore moved onto a
bridge and got prompted, the bridge was destroyed, and the player
stopped the explore "on the water".
get_empobj_chr() and emp_obj_chr_name() access struct sctstr member
sct_type through struct empobj member type. This is technically
non-portable, because the two differ in signedness. It was also
undocumented. Fix by making sct_type signed. sct_newtype as well,
for consistency.
map_char() uses unsigned char for a sector type argument. Change that
to int. Matches how this is done elsewhere.
ef_extend() extended the file bypassing the cache, which screws up the
cache if it's EFF_MEM. It fixed that by closing and reopening the
table. Cheesy, and worked only for file-backed tables.
Rewrite ef_extend() to remap the cache properly for EFF_MEM. While
there, simplify the !EFF_MEM case: steal a cache slot instead of
allocating a buffer.
Factor cache mapping out of ef_open() and ef_extend() into new
ef_realloc_cache().
Read-only was a bit of a misnomer: you could write to the table by
obtaining a pointer into it from ef_ptr(), you just couldn't write to
the backing file.
Semantic changes:
* ef_flush() is now allowed when the table is file-backed or privately
mapped. Before, it had to be file-backed. Flushing a privately
mapped table does nothing, just like flushing a read-only table did.
* ef_write() is now allowed when the table is file-backed or fully
cached. Before, it had to be file-backed and not read-only.
Writing to a privately mapped file-backed table doesn't write to the
file.
* ef_extend() is not implemented for privately mapped tables, just
like it wasn't implemented for read-only tables.
Don't let designate check total cost before doing anything
desi() ran the designate code twice, first for adding up the cost,
then for changing designation. However, the checking pass already
changed the sector when that cost nothing. The checking pass also
suppressed messages. There was at least one message that never got
printed because it was suppressed in the checking pass, and the
condition for it was no longer true in the changing pass, due to the
premature sector change: when a deity changed a non-coastal sector to
harbor or bridge head.
The total cost check is of limited value: designate costing money is a
bad idea, and the stock game has no such sectors. Not enough value to
justify keeping and fixing this disgusting mess. Remove it instead.
Fix mobility cost for marines assaulting from non-landing ships
Always charge land units at least as much mobility for assaulting from
non-landing ships as for landing ships. Before, marines lost all
mobility when assaulting from a non-landing ship, which could be less
than what the same assault costs from a landing ship (half an update's
worth).
Actually, this isn't just simplification. When mobility gain per
update was configured to be greater than 128, mobility could go from 1
to less than -127 when assaulting from a landing ship, and thus
overflow. Make it saturate at -127. Note that you can expect plenty
of trouble elsewhere with such a silly configuration.
With -s, LWP initializes thread stacks to track stack use. It did
that after makecontext(), with disastrous results on systems where
makecontext() writes something to the stack that swapcontext() expects
to find there. Makes FreeBSD 6.2 crash in swapcontext().
Factor stack allocation out of lwpNewContext() into lwpNewStack().
Move call of lwpStackCheckInit() into lwpNewStack().
A bridge (span or tower) must be splashed when it gets damaged below
SCT_MINEFF. Likewise when its last supporting sector (bridge head or
tower) gets damaged below SCT_MINEFF, unless EASY_BRIDGES is enabled.
We need to check this whenever a bridge head, span or tower gets
damaged. This is done in three places, and all of them screw up:
* checksect() ignores damage to bridge heads. It also leaves writing
back the sector it checks to the caller, which never happens when
it's called from sct_postread().
Note that checksect() drowns all planes on bridges it splashes.
Functions that need to exempt flying planes from such a fate have to
splash bridges themselves.
* sect_damage() ignores damage to bridge towers, and damage to bridge
spans unless EASY_BRIDGES is enabled. It then runs checksect(),
which compensates for these omissions, but happily drowns the planes
sect_damage() attempts to protect.
* eff_bomb() ignores damage to bridge heads. Collateral damage makes
sect_damage() run, which compensates for the omission.
This causes the following bugs:
* Efficiency damage going through sect_damage() can drown planes it
shouldn't. This affects pinpoint bombing when collateral damage
splashes a bridge, and strategic bombing. The drowned planes then
crash and burn when they attempt to land at their (just splashed)
base.
* Efficiency damage to bridge heads not going through sect_damage()
fails to collapse unsupported bridges. This affects pin-bombing
efficiency without collateral damage, and ground combat. Also deity
commands edit, setsector and add, but that could be regarded as a
feature.
* If the sector file somehow ends up with an inefficient bridge span,
it collapses on every read again and again, until it collapses on a
write. Related problems exist with other actions of checksect(),
and they're not addressed here.
* If the sector file somehow ends up with adjacent inefficient bridge
towers, checksect() on any of them recurses infinitely:
- checksect() inefficient tower T1
- knockdown() T1, but don't write that back to the sector file
- bridgefall() T1; this reads all adjacent sectors, including
inefficient towert T2
- checksect() T2
- knockdown() T2, but don't write that back to the sector file
- bridgefall() T1; this reads adjacent sectors including T1
- checksect() T1
...
This commit creates a new function bridge_damaged() to splash any
bridges that became inefficient or unsupported after damage to a
sector. To avoid the inifinite recursion, we call it in
sct_prewrite() instead of checksect().
No uses knockdown() outside bridgefall.c remain, so give it internal
linkage.