[crossfire] useful macros in crossfire

Alex Schultz alex_sch at telus.net
Sun Oct 1 18:26:54 CDT 2006


Often when looking through code, I notice that that many code snippets
are repeated in many places, often with variations on how to do the same
task. The best example is iterating through stacks of objects, because
loops for that are implemented in many different places, with quite a
few needless variations. Another example is "if ob->head ob=ob->head;"
while not complex, might be more readable as something like "ob =
GET_HEAD(ob);". I propose that we add the following macros or similar to
the crossfire code to make things cleaner:

#define TRANSVERSE_STACK_DOWN(ob, tmp) for((tmp)=(ob); (tmp),
(tmp)=(tmp)->below)

#define TRANSVERSE_STACK_UP(ob, tmp) for((tmp)=(ob); (tmp),
(tmp)=(tmp)->above)

#define TRANSVERSE_INV(ob, tmp) TRANSVERSE_STACK_DOWN((ob)->inv, (tmp))

#define TRANSVERSE_FLOOR(m, x, y, tmp)
TRANSVERSE_STACK_UP(GET_MAP_OB((m), (x), (y)), (tmp))

#define GET_HEAD(ob) ((ob)->head ? (ob)->head : (ob))

#define TRANSVERSE_MULTITILE(ob, tmp) for((tmp) = GET_HEAD(ob)->arch;
(tmp); (tmp) = (tmp)->more)

#define TRANSVERSE_ARCHETYPES(tmp) for((tmp)=first_archetype; (tmp);
(tmp)=(tmp)->next)

#define TRANSVERSE_OBJECTS(tmp) for((tmp)=objects; (tmp); (tmp)=(tmp)->next)

#define GET_NROF(ob) ((ob)->nrof ? (ob)->nrof : 1)

I'm not sure how useful the last four are, however I know they're used
in some places and would be good for convenience. Anyone have any
objections to making macros for these? Also, does anyone have any other
ideas for good macros?

Alex Schultz



More information about the crossfire mailing list