Commit graph

2952 commits

Author SHA1 Message Date
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
93d8c53f21 Use ef_blank for new ships, planes, land units and nukes
Fixes commit 6cd3d55c, which broke initialization of ef_type.
2008-03-14 20:24:58 +01:00
c21c4ff9a7 New ef_blank()
It performs the same initialization as ef_extend().
2008-03-05 22:48:24 +01:00
a71f01585f empfile's init callback is now unused, remove 2008-03-05 22:48:24 +01:00
6b89127d5b shp_init(), lnd_init(), pln_init(), nuk_init() are now empty, remove 2008-03-05 22:48:24 +01:00
6cd3d55c4e Initialize ef_type and uid automatically in ef_extend()
New struct emptypedstr to avoid depending on empobj.h there.

Remove now superfluous manual initializations elsewhere.

This doesn't fix any missing initializations.
2008-03-05 22:48:23 +01:00
d628679a24 New empfile flag EFF_TYPED to signal struct empobj support
Elements of tables with EFF_TYPED set share the common header of
struct empobj.
2008-03-05 22:48:23 +01:00
49780e2c6c Extend the common header of struct empobj to include uid
Make sure all members of unit empobj_storage share uid in addition to
ef_type.

Add matching uid member to struct gamestr, struct natstr and struct
sctstr, and set them.

Swap struct empobj members uid and own to make that easier, and update
struct comstr, struct lndstr, struct lonstr, struct loststr, struct
nwsstr, struct nukstr, struct plnstr, struct realmstr, struct shpstr,
struct trdstr, struct trtstr accordingly.

Note that the uid isn't properly set for struct nwsstr, struct lonstr,
struct trdstr, struct comstr and struct loststr.  To be fixed.
2008-03-05 22:48:20 +01:00
aef790f7f3 Document tables EF_COMM, EF_TRADE and EF_COUNTRY have an owner
xdvisible() relies on that.

Set EFF_OWNER in the table definitions.  EFF_OWNER is not actually
used right now, so this doesn't fix anything broken.
2008-02-26 21:07:59 +01:00
0a570bc4bf Simplify unit_put() 2008-02-26 21:07:59 +01:00
333dd8585c 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.
2008-02-26 21:07:58 +01:00
7bbbcc8643 Define common get/put macros for empobj
This turns existing functions get_empobjp() and put_empobj() into
equivalent macros.
2008-02-26 21:07:58 +01:00
7819ce7fa1 Fix get_empobjp() not to reject EF_SECTOR
There's no technical reason for rejecting sector access by id.  It's
unusual, but not wrong.

Also remove the superfluous test for EF_BAD; ef_ptr() covers that.
2008-02-26 21:07:58 +01:00
59c65239f7 Fix put_empobj() for types other than units
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.
2008-02-26 21:07:58 +01:00
dd2d2d361a Give unit_map() internal linkage 2008-02-26 21:07:58 +01:00
8745929ea7 New realm selector timestamp
The timestamp always existed, but the selector was missing.  It's
needed for incremental xdumps.
2008-02-26 21:07:58 +01:00
0a3c347bba Clean up ugly line break 2008-02-26 21:07:58 +01:00
46ff332ae9 Fix test for water in explore
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".
2008-02-26 21:07:58 +01:00
74e873e96c Make sector types signed
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.
2008-02-26 21:07:57 +01:00
c36cae7a64 Make xundump capable of extending tables
Use ef_ensure_space() in getobj().  This also makes sure objects are
properly initialized before undumping writes to them.

Clean up how sentinels are appended: instead of keeping its slot
reserved while undumping, keep it in the table, and strip it off when
done.
2008-02-26 21:07:57 +01:00
2eb8672b5e Generalize ef_extend() to non-file-backed tables
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().
2008-02-26 21:07:55 +01:00
f8dcb7b07b Replace EFF_RDONLY by EFF_PRIVATE
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.
2008-02-26 20:40:59 +01:00
ef71897051 Remove obsolete comment
Obsolete since ef_open() locks the file (commit de124108).
2008-02-26 20:40:59 +01:00
Ron Koenderink
1e65d1eb0d Remove unused local variable in desi.c
Left behind by commit d3a3aa43.
2008-02-26 20:39:02 +01:00
8d4b959a0c Define and use NATID_BAD instead of literal 255 2008-02-19 20:25:08 +01:00
00bb086d2a Fix spelling of symbol PLN_AIRBURST in plane_flags[] 2008-02-17 19:54:41 +01:00
e58d3206bb Clean up trailing whitespace-space in manual pages 2008-02-17 19:50:38 +01:00