Commit graph

3028 commits

Author SHA1 Message Date
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
70522157bf Remove edit keys deprecated in 4.3.3
These are: land 'C', plane 'a' and 'd', unit 'X', ship 'H', 'P', 'X'
and 'Y'.
2008-03-14 20:25:10 +01:00
6af2ad7c56 Implement xundump table truncation 2008-03-14 20:25:10 +01:00
cf16c74a3d New ef_truncate() 2008-03-14 20:25:10 +01:00
3c5fa553bb POSIX compatible ftruncate() for Windows 2008-03-14 20:25:09 +01:00
adbcdf4335 Clean up dependencies after failed compile
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.
2008-03-14 20:25:09 +01:00
4a0732375d Remove redundant initializations from fairland's fl_sct_init() 2008-03-14 20:25:09 +01:00
191c5bea0f Clean up confusing loop control in fairland 2008-03-14 20:25:09 +01:00
e38ba07426 Replace unit_type_name() by empobj_chr_name() 2008-03-14 20:25:09 +01:00
966b881667 Simplify empobj_chr_name() oops recovery
Return something usable instead of null.  Matches obj_nameof().  Fixes
those callers that neglected to check the value.
2008-03-14 20:25:09 +01:00
f99adf4b3c Rename emp_obj_chr_name() to empobj_chr_name() 2008-03-14 20:25:09 +01:00
9b8683736b Make ef_verify() check ef_type and uid 2008-03-14 20:25:09 +01:00
99594c1898 Oops when bad ef_type or uid is written to disk 2008-03-14 20:25:08 +01:00
5490782db3 Check ef_type before dereferencing struct empobj
Such manual checking is error prone, but the best we can do right now.
2008-03-14 20:25:08 +01:00
990b39edec Check subscript of rpt[]
Make nws_vrb unsigned to simplify that.
2008-03-14 20:25:08 +01:00
5fda9462bd Fix tests for unused news slots
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.

Fix by testing nws_vrb instead.
2008-03-14 20:25:08 +01:00
832574b6de Get rid of struct newscache
Just use struct nwsstr, it has the uid now.
2008-03-14 20:25:08 +01:00
b18f410e30 Fix news expiry not to screw up nws_uid
delete_old_news() moves unexpired news.  Update nws_uid accordingly.
It then zaps the slots no longer in use.  Don't zap ef_type and
nws_uid.
2008-03-14 20:25:08 +01:00
7dafbada4e Use ef_blank() when extending news file
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.
2008-03-14 20:25:08 +01:00
da2a0c5ef2 Use ef_blank() when extending lost file, and simplify 2008-03-14 20:25:07 +01:00
2da8d0c796 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.
2008-03-14 20:25:07 +01:00