Commit graph

3148 commits

Author SHA1 Message Date
726a8e3dae Make xundump catch extraneous fields
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.
2008-03-14 20:25:43 +01:00
c2a687e357 Fix stmtch() for exact match after multiple partial matches
Keep looking for exact match after finding the second partial match.
2008-03-14 20:25:43 +01:00
3c39479333 New timestamp selectors
New timestamp selector for commodity, country, game, loan, nation,
news, trade, treaty.
2008-03-14 20:25:43 +01:00
f33b96b1d1 Set timestamp automatically on write
Do it in do_write().  Remove the setting of timestamps elsewhere.

This fixes empdump to set timestamps to the current time instead of
zero on import.
2008-03-14 20:25:43 +01:00
a680c81110 Put a timestamp into struct emptypedstr
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.
2008-03-14 20:25:43 +01:00
e1a68c721d Factor common code out of add() and new() into nat_reset()
The common nation wipe code is not quite identical, and it doesn't
wipe the nation thoroughly enough.  The new code does.

Changes to both commands:

* Wipe nat_update, nat_ann, nat_access, and nat_contact.  Bug: should
  set nat_ann to the number of announcements.

Changes to add command:

* Don't wipe for status active and god.  Before, nat_relate and
  nat_flags where wiped then.

Changes to newcap command:

* Wipe nat_hostaddr, nat_hostname, nat_userid, nat_dayno, nat_minused,
  nat_reserve, nat_last_login, nat_last_logout, nat_newstim,
  nat_annotim, nat_relate, nat_rejects, nat_flags.
2008-03-14 20:25:43 +01:00
d1d0b0a414 Update indent-emp for removed typedef names, belatedly. 2008-03-14 20:25:43 +01:00
06a0036c63 Replace some typedef names by enum tags.
Also get rid of some mildly silly manual packing of enum types.
2008-03-14 20:25:42 +01:00
7ec0f0c0d0 New utility program empdump
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.
2008-03-14 20:25:42 +01:00
ed0c98d3c8 Implement human-readable dialect for xdump
This is for the forthcoming empdump utility program.  The xdump
command still does not support the human-readable dialect.

xundump has supported the human-readable dialect for a long time
(commit 4871a10a).
2008-03-14 20:25:42 +01:00
f9e28d0491 Make xundump interpret escapes in identifiers
We need this because we have symbols with spaces, e.g. missions[].
2008-03-14 20:25:42 +01:00
5ef6559c6a Minor xdump documentation edit 2008-03-14 20:25:42 +01:00
4c746b5e73 Make xdump code available for future use outside the server
Move the bits useful there from src/lib/commands/xdump.c to new
include/xdump.h and src/lib/common/xdump.c.
2008-03-14 20:25:42 +01:00
761d631816 Prepare some xdump code for future use outside the server
We don't have player->cnum, player->god and pr() there.  Pass
parameters instead.
2008-03-14 20:25:42 +01:00
c75d19b082 Don't store land unit stats in struct lndstr, part 2
struct lndstr members lnd_spy, lnd_rad, lnd_ammo, lnd_fuelc,
lnd_fuelu, lnd_maxlight, lnd_maxlight are mere copies of struct
lchrstr members l_spy, l_rad, l_ammo, l_fuelc, l_fuelu, l_nxlight,
l_nland.  Remove them.

Make land unit selectors spy, rmax, ammo, fuelc, fuelu, maxlight
virtual.
2008-03-14 20:25:41 +01:00
cdf1bcfa22 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.
2008-03-14 20:25:41 +01:00
f86d726406 Don't store ship stats in struct shpstr
New shp_armor(), shp_speed(), shp_visib(), shp_frnge(), shp_glim()
replace the struct shpstr members with the same names.
2008-03-14 20:25:41 +01:00
ffc5d0cfd7 Don't store plane stats in struct plnstr
New pln_att(), pln_def(), pln_acc(), pln_range_max(), pln_load()
replace the struct plnstr members with the same names.

Make plane selectors att and def virtual.
2008-03-14 20:25:41 +01:00
d1a193ff07 New nstr_mksymval() to create symbolic values 2008-03-14 20:25:41 +01:00
da8a1daeef Virtual selectors
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.
2008-03-14 20:25:41 +01:00
38047a62f7 Reorder members of struct castr to make nsc.c easier to read 2008-03-14 20:25:40 +01:00
bc0ced464b Make nstr_exec oops on bad operator 2008-03-14 20:25:40 +01:00
93a5779e66 Make nstr_exec_val() return its first argument 2008-03-14 20:25:40 +01:00
0bcb047806 Make nstr_exec_val() more robust
Oops on bad argument, and make a better error value then.
2008-03-14 20:25:40 +01:00
422cd52209 Move nstr_promote() to src/lib/common/, external linkage 2008-03-14 20:25:40 +01:00
9eab865c38 Document nsc.h more completely 2008-03-14 20:25:40 +01:00
66a74125da Fix documentation of empfile[] contents 2008-03-14 20:25:40 +01:00
d3345ce66c Make xdprval() oops on bad argument 2008-03-14 20:25:40 +01:00
f3e9526472 Fix oops recovery in xdprval()
Failed to print the separator, which could run fields together.
2008-03-14 20:25:39 +01:00
504f035450 Factor out torpedo hit chance into shp_torp_hitchance() 2008-03-14 20:25:39 +01:00
4849600cd5 Factor out ship usable gun calculation into shp_usable_gun() 2008-03-14 20:25:39 +01:00
ffab089c61 Give effrange() internal linkage. 2008-03-14 20:25:39 +01:00
76830b5b98 Factor out land unit firing range calculation into lnd_fire_range() 2008-03-14 20:25:39 +01:00
ad5f8e8904 Factor out ship firing range calculation into shp_fire_range() 2008-03-14 20:25:39 +01:00
b3c5ba2f75 Tighten gcc warning options
Suppress only unused parameters, not all unused stuff.
2008-03-14 20:25:38 +01:00
5a2e64ef1a Remove an unused variable in fit_plane_off_land() 2008-03-14 20:25:38 +01:00
66406d8385 Remove dead code for estimating defense
Clean up of intelligence_report().  Should have been done in commit
092a52f2.
2008-03-14 20:25:38 +01:00
055c80a41f use_supply() is now unused, remove 2008-03-14 20:25:38 +01:00
f6c87d21ff 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.
2008-03-14 20:25:38 +01:00
652afa12de Simplify torpedo return fire logic
Don't bother checking capabilities that will be checked again later,
just try torpedo, then depth charge / gun fire.
2008-03-14 20:25:38 +01:00
6d83090aad 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.
2008-03-14 20:25:38 +01:00
21733d1473 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.
2008-03-14 20:25:37 +01:00
69f441ef39 Change test whether a land unit is artillery
Test for land unit firing damage instead of range, for consistency
with ships.
2008-03-14 20:25:37 +01:00
22c6fd8bf6 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.
2008-03-14 20:25:37 +01:00
a3ad623b2a Make depth-charging code and documentation match
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().
2008-03-14 20:25:37 +01:00
e8595066d1 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.

Rename landgun() to fortgun() for consistency.
2008-03-14 20:25:37 +01:00
3812cde100 Include system headers before ours 2008-03-14 20:25:11 +01:00
61d632fc96 Give logx() internal linkage 2008-03-14 20:25:10 +01:00
0219bf086a New unit stat development functions
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.
2008-03-14 20:25:10 +01:00
3d0e083aec Convert a CANT_HAPPEN() to CANT_REACH() 2008-03-14 20:25:10 +01:00