handle C++ vs enum arithmatic differently
The cast to (int) was much simpler but this seems better overall.
This commit is contained in:
@@ -181,14 +181,10 @@
|
|||||||
*
|
*
|
||||||
* Respectively return a random monster or object.
|
* Respectively return a random monster or object.
|
||||||
* random_object() won't return STRANGE_OBJECT or the generic objects.
|
* random_object() won't return STRANGE_OBJECT or the generic objects.
|
||||||
* -/+ MAXOCLASSES is used to skip it and them.
|
* -/+ FIRST_OBJECT is used to skip it and them.
|
||||||
* NUM_OBJECTS and MAXOCLASSES are from different enum lists and recent C++
|
|
||||||
* (for the Qt interface) complains about mixing them in arithmatic so cast
|
|
||||||
* them to int here. Doesn't impact compiling random_object() with C.
|
|
||||||
*/
|
*/
|
||||||
#define random_monster(rng) ((*rng)(NUMMONS))
|
#define random_monster(rng) ((*rng)(NUMMONS))
|
||||||
#define random_object(rng) \
|
#define random_object(rng) ((*rng)(NUM_OBJECTS - FIRST_OBJECT) + FIRST_OBJECT)
|
||||||
((*rng)((int) NUM_OBJECTS - (int) MAXOCLASSES) + (int) MAXOCLASSES)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* what_obj()
|
* what_obj()
|
||||||
@@ -861,22 +857,22 @@ enum glyph_offsets {
|
|||||||
#define glyph_is_statue(glyph) \
|
#define glyph_is_statue(glyph) \
|
||||||
(glyph_is_male_statue(glyph) || glyph_is_fem_statue(glyph))
|
(glyph_is_male_statue(glyph) || glyph_is_fem_statue(glyph))
|
||||||
/* generic objects are after strange object (GLYPH_OBJ_OFF) and before
|
/* generic objects are after strange object (GLYPH_OBJ_OFF) and before
|
||||||
other objects (GLYPH_OBJ_OFF + MAXOCLASSES) */
|
other objects (GLYPH_OBJ_OFF + FIRST_OBJECT) */
|
||||||
#define glyph_is_normal_generic_obj(glyph) \
|
#define glyph_is_normal_generic_obj(glyph) \
|
||||||
((glyph) > GLYPH_OBJ_OFF && (glyph) < GLYPH_OBJ_OFF + MAXOCLASSES)
|
((glyph) > GLYPH_OBJ_OFF && (glyph) < GLYPH_OBJ_OFF + FIRST_OBJECT)
|
||||||
#define glyph_is_piletop_generic_obj(glyph) \
|
#define glyph_is_piletop_generic_obj(glyph) \
|
||||||
((glyph) > GLYPH_OBJ_PILETOP_OFF \
|
((glyph) > GLYPH_OBJ_PILETOP_OFF \
|
||||||
&& (glyph) < GLYPH_OBJ_PILETOP_OFF + MAXOCLASSES)
|
&& (glyph) < GLYPH_OBJ_PILETOP_OFF + FIRST_OBJECT)
|
||||||
#define glyph_is_generic_object(glyph) \
|
#define glyph_is_generic_object(glyph) \
|
||||||
(glyph_is_normal_generic_obj(glyph) \
|
(glyph_is_normal_generic_obj(glyph) \
|
||||||
|| glyph_is_piletop_generic_obj(glyph))
|
|| glyph_is_piletop_generic_obj(glyph))
|
||||||
#define glyph_is_normal_piletop_obj(glyph) \
|
#define glyph_is_normal_piletop_obj(glyph) \
|
||||||
((glyph) == GLYPH_OBJ_PILETOP_OFF \
|
((glyph) == GLYPH_OBJ_PILETOP_OFF \
|
||||||
|| ((glyph) > GLYPH_OBJ_PILETOP_OFF + MAXOCLASSES \
|
|| ((glyph) > GLYPH_OBJ_PILETOP_OFF + FIRST_OBJECT \
|
||||||
&& (glyph) < (GLYPH_OBJ_PILETOP_OFF + NUM_OBJECTS)))
|
&& (glyph) < (GLYPH_OBJ_PILETOP_OFF + NUM_OBJECTS)))
|
||||||
#define glyph_is_normal_object(glyph) \
|
#define glyph_is_normal_object(glyph) \
|
||||||
((glyph) == GLYPH_OBJ_OFF \
|
((glyph) == GLYPH_OBJ_OFF \
|
||||||
|| ((glyph) >= GLYPH_OBJ_OFF + MAXOCLASSES \
|
|| ((glyph) >= GLYPH_OBJ_OFF + FIRST_OBJECT \
|
||||||
&& (glyph) < (GLYPH_OBJ_OFF + NUM_OBJECTS)) \
|
&& (glyph) < (GLYPH_OBJ_OFF + NUM_OBJECTS)) \
|
||||||
|| glyph_is_normal_piletop_obj(glyph))
|
|| glyph_is_normal_piletop_obj(glyph))
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,14 @@ GENERIC("iron ball", BALL_CLASS, GENERIC_BALL), /* [15] */
|
|||||||
GENERIC("iron chain", CHAIN_CLASS, GENERIC_CHAIN), /* [16] */
|
GENERIC("iron chain", CHAIN_CLASS, GENERIC_CHAIN), /* [16] */
|
||||||
GENERIC("venom", VENOM_CLASS, GENERIC_VENOM), /* [17] */
|
GENERIC("venom", VENOM_CLASS, GENERIC_VENOM), /* [17] */
|
||||||
#undef GENERIC
|
#undef GENERIC
|
||||||
|
/* FIRST_OBJECT: it would be simpler just to use MARKER(FIRST_OBJECT,ARROW)
|
||||||
|
below but that is vulnerable to neglecting to update the marker enum
|
||||||
|
after inserting something in front of arrow */
|
||||||
|
MARKER(LAST_GENERIC, GENERIC_VENOM)
|
||||||
|
MARKER(FIRST_OBJECT, LAST_GENERIC + 1)
|
||||||
|
/* this definition of FIRST_OBJECT advances the default value for next enum;
|
||||||
|
backtrack to fix that, otherwise ARROW and the rest would be off by 1 */
|
||||||
|
MARKER(OBJCLASS_HACK, FIRST_OBJECT - 1)
|
||||||
|
|
||||||
/* weapons ... */
|
/* weapons ... */
|
||||||
#define WEAPON(name,desc,kn,mg,bi,prob,wt, \
|
#define WEAPON(name,desc,kn,mg,bi,prob,wt, \
|
||||||
@@ -810,9 +818,9 @@ MARKER(FIRST_AMULET, AMULET_OF_ESP)
|
|||||||
AMULET("amulet of life saving", "spherical", LIFESAVED, 75,
|
AMULET("amulet of life saving", "spherical", LIFESAVED, 75,
|
||||||
AMULET_OF_LIFE_SAVING),
|
AMULET_OF_LIFE_SAVING),
|
||||||
AMULET("amulet of strangulation", "oval", STRANGLED, 115,
|
AMULET("amulet of strangulation", "oval", STRANGLED, 115,
|
||||||
AMULET_OF_STRANGULATION),
|
AMULET_OF_STRANGULATION),
|
||||||
AMULET("amulet of restful sleep", "triangular", SLEEPY, 115,
|
AMULET("amulet of restful sleep", "triangular", SLEEPY, 115,
|
||||||
AMULET_OF_RESTFUL_SLEEP),
|
AMULET_OF_RESTFUL_SLEEP),
|
||||||
AMULET("amulet versus poison", "pyramidal", POISON_RES, 115,
|
AMULET("amulet versus poison", "pyramidal", POISON_RES, 115,
|
||||||
AMULET_VERSUS_POISON),
|
AMULET_VERSUS_POISON),
|
||||||
AMULET("amulet of change", "square", 0, 115,
|
AMULET("amulet of change", "square", 0, 115,
|
||||||
|
|||||||
@@ -1127,6 +1127,9 @@ dump_enums(void)
|
|||||||
};
|
};
|
||||||
#define dump_om(om) { om, #om }
|
#define dump_om(om) { om, #om }
|
||||||
static const struct enum_dump omdump[] = {
|
static const struct enum_dump omdump[] = {
|
||||||
|
dump_om(LAST_GENERIC),
|
||||||
|
dump_om(OBJCLASS_HACK),
|
||||||
|
dump_om(FIRST_OBJECT),
|
||||||
dump_om(FIRST_AMULET),
|
dump_om(FIRST_AMULET),
|
||||||
dump_om(LAST_AMULET),
|
dump_om(LAST_AMULET),
|
||||||
dump_om(FIRST_SPELL),
|
dump_om(FIRST_SPELL),
|
||||||
|
|||||||
Reference in New Issue
Block a user