fix github issue #587 - incompatible save files

Save files from before the 'disambiguate WHACK' patch were not
necessarily compatible with ones after it, leading to potential
restore problems.

Comments in objclass.h (from before the patch) suggested that
inappropriate assumptions were being made about field layout.
This deliberately introduces new incompatibility and increments
EDITLEVEL to caused earlier save and bones files to be thrown
away.

Fixes #587
This commit is contained in:
PatR
2021-09-12 05:31:01 -07:00
parent d118ac52af
commit 583fb60835
4 changed files with 49 additions and 34 deletions

View File

@@ -803,6 +803,8 @@ if an invisible monster put on or took off armor while out of hero's sight
an item thrown or dropped while swallowed was treated as being picked up by an
unseen monster so object fields {known, dknown, bknown} got cleared
segfault if gremlin fled weaponless hero wearing gold dragon scales/mail
'disambiguate WHACK' patch affected field layout of objects[] but EDITLEVEL
wasn't incremented, allowing incompatable save files to be restored
curses: 'msg_window' option wasn't functional for curses unless the binary
also included tty support

View File

@@ -50,11 +50,11 @@ struct objclass {
Bitfield(oc_name_known, 1); /* discovered */
Bitfield(oc_merge, 1); /* merge otherwise equal objects */
Bitfield(oc_uses_known, 1); /* obj->known affects full description;
otherwise, obj->dknown and obj->bknown
tell all, and obj->known should always
be set for proper merging behavior. */
Bitfield(oc_pre_discovered, 1); /* Already known at start of game;
won't be listed as a discovery. */
* otherwise, obj->dknown and obj->bknown
* tell all, and obj->known should always
* be set for proper merging behavior. */
Bitfield(oc_pre_discovered, 1); /* already known at start of game; flagged
* as such when discoveries are listed */
Bitfield(oc_magic, 1); /* inherently magical object */
Bitfield(oc_charged, 1); /* may have +n or (n) charges */
Bitfield(oc_unique, 1); /* special one-of-a-kind object */
@@ -65,6 +65,10 @@ struct objclass {
#define oc_bulky oc_big /* for armor */
Bitfield(oc_tough, 1); /* hard gems/rings */
Bitfield(oc_spare1, 6); /* padding to align oc_dir + oc_material;
* can be canabalized for other use;
* aka 6 free bits */
Bitfield(oc_dir, 3);
/* oc_dir: zap style for wands and spells */
#define NODIR 1 /* non-directional */
@@ -74,31 +78,8 @@ struct objclass {
#define PIERCE 01 /* pointed weapon punctures target */
#define SLASH 02 /* sharp weapon cuts target */
#define WHACK 04 /* blunt weapon bashes target */
/* 3 free bits */
Bitfield(oc_material, 5); /* one of obj_material_types */
#define is_organic(otmp) (objects[otmp->otyp].oc_material <= WOOD)
#define is_metallic(otmp) \
(objects[otmp->otyp].oc_material >= IRON \
&& objects[otmp->otyp].oc_material <= MITHRIL)
/* primary damage: fire/rust/--- */
/* is_flammable(otmp), is_rottable(otmp) in mkobj.c */
#define is_rustprone(otmp) (objects[otmp->otyp].oc_material == IRON)
/* secondary damage: rot/acid/acid */
#define is_corrodeable(otmp) \
(objects[otmp->otyp].oc_material == COPPER \
|| objects[otmp->otyp].oc_material == IRON)
#define is_damageable(otmp) \
(is_rustprone(otmp) || is_flammable(otmp) || is_rottable(otmp) \
|| is_corrodeable(otmp))
/* 3 free bits */
schar oc_subtyp;
#define oc_skill oc_subtyp /* Skills of weapons, spellbooks, tools, gems */
#define oc_armcat oc_subtyp /* for armor (enum obj_armor_types) */
@@ -200,4 +181,21 @@ extern NEARDATA struct objdescr obj_descr[NUM_OBJECTS + 1];
#define OBJ_NAME(obj) (obj_descr[(obj).oc_name_idx].oc_name)
#define OBJ_DESCR(obj) (obj_descr[(obj).oc_descr_idx].oc_descr)
#define is_organic(otmp) (objects[otmp->otyp].oc_material <= WOOD)
#define is_metallic(otmp) \
(objects[otmp->otyp].oc_material >= IRON \
&& objects[otmp->otyp].oc_material <= MITHRIL)
/* primary damage: fire/rust/--- */
/* is_flammable(otmp), is_rottable(otmp) in mkobj.c */
#define is_rustprone(otmp) (objects[otmp->otyp].oc_material == IRON)
/* secondary damage: rot/acid/acid */
#define is_corrodeable(otmp) \
(objects[otmp->otyp].oc_material == COPPER \
|| objects[otmp->otyp].oc_material == IRON)
/* subject to any damage */
#define is_damageable(otmp) \
(is_rustprone(otmp) || is_flammable(otmp) \
|| is_rottable(otmp) || is_corrodeable(otmp))
#endif /* OBJCLASS_H */

View File

@@ -21,6 +21,13 @@
#define HARDGEM(n) (0)
#endif
/*
* Note...
* OBJECTS() currently has 15 parameters; it more become needed, some
* will need to be combined the way BITS() is used, because compilers
* are allowed to impose a limit of 15.
*/
#if defined(OBJECTS_DESCR_INIT)
#define OBJ(name,desc) name, desc
#define OBJECT(obj,bits,prp,sym,prob,dly,wt, \
@@ -28,21 +35,28 @@
#elif defined(OBJECTS_INIT)
#define COLOR_FIELD(X) X,
/* notes: 'sub' was once a bitfield but got changed to separate schar when
it was overloaded to hold negative weapon skill indices; the first zero
is padding for oc_prediscovered which has variable init at run-time;
the second zero is oc_spare1 for padding between oc_tough and oc_dir */
#define BITS(nmkn,mrg,uskn,ctnr,mgc,chrg,uniq,nwsh,big,tuf,dir,sub,mtrl) \
nmkn,mrg,uskn,0,mgc,chrg,uniq,nwsh,big,tuf,dir,mtrl,sub /*SCO cpp fodder*/
#define OBJECT(obj,bits,prp,sym,prob,dly,wt,cost,sdam,ldam,oc1,oc2,nut,color,sn) \
nmkn,mrg,uskn,0,mgc,chrg,uniq,nwsh,big,tuf,0,dir,mtrl,sub /*cpp fodder*/
#define OBJECT(obj,bits,prp,sym,prob,dly,wt, \
cost,sdam,ldam,oc1,oc2,nut,color,sn) \
{ 0, 0, (char *) 0, bits, prp, sym, dly, COLOR_FIELD(color) prob, wt, \
cost, sdam, ldam, oc1, oc2, nut }
#elif defined(OBJECTS_ENUM)
#define OBJ(name,desc)
#define OBJECT(obj,bits,prp,sym,prob,dly,wt,cost,sdam,ldam,oc1,oc2,nut,color,sn) \
#define OBJECT(obj,bits,prp,sym,prob,dly,wt, \
cost,sdam,ldam,oc1,oc2,nut,color,sn) \
sn
#elif defined(DUMP_ENUMS)
#define OBJ(name,desc)
#define OBJECT(obj,bits,prp,sym,prob,dly,wt,cost,sdam,ldam,oc1,oc2,nut,color,sn) \
{sn, #sn}
#define OBJECT(obj,bits,prp,sym,prob,dly,wt, \
cost,sdam,ldam,oc1,oc2,nut,color,sn) \
{ sn, #sn }
#else
#error Unproductive inclusion of objects.h
@@ -75,6 +89,7 @@ OBJECT(OBJ("strange object", NoDes),
/* Note: for weapons that don't do an even die of damage (ex. 2-7 or 3-18)
the extra damage is added on in weapon.c, not here! */
/* weapon strike mode overloads the oc_dir field */
#define P PIERCE
#define S SLASH
#define B WHACK

View File

@@ -17,7 +17,7 @@
* Incrementing EDITLEVEL can be used to force invalidation of old bones
* and save files.
*/
#define EDITLEVEL 39
#define EDITLEVEL 40
/*
* Development status possibilities.