/* * Implementation of armour. */ #include #include "obj.h" #include "vars.h" #include "util.h" #include "pline.h" #include "format.h" #include "structs.h" #include "objtypes.h" typedef struct armour ARMOUR; /* * Private data for a piece of armour. */ struct armour { unsigned int flags; #define AF_KNOWN 0x00000001 int bonus; } ; /* * Return the ARMOUR for an OBJ (or, if the OBJ isn't armour, panic.) */ static ARMOUR *armour_for_obj(OBJ *o) { if (objtypes[o->type].class != OC_ARMOUR) panic("non-armour where armour needed"); return(o->private); } /* * The new method for armour. */ static OBJ *new(int type __attribute__((__unused__)), OBJ *o) { ARMOUR *a; a = malloc(sizeof(ARMOUR)); a->flags = 0; a->bonus = 0; o->private = a; return(o); } /* * The old method for armour. */ static void old(OBJ *o) { free(o->private); } /* * The cond method for armour. The only conditional here is K, for * testing whether a piece of armour has its plusses known. */ static int cond(char ch, INVOBJ *io) { switch (ch) { case 'K': return(armour_for_obj(io->v[0])->flags&AF_KNOWN); break; } panic("invalid conditional +%c for armour",ch); } /* * The spec method for armour. The only format here is P, for printing * a piece of armour's plusses. */ static void spec(FILE *f, char ch, INVOBJ *io) { switch (ch) { case 'P': fprintf(f,"%+d",armour_for_obj(io->v[0])->bonus); break; default: panic("invalid format %%+%c for armour",ch); break; } } /* * Return true iff a piece of armour has its plusses known. */ static int identified(INVOBJ *io) { return(armour_for_obj(io->v[0])->flags & AF_KNOWN); } /* * Identify a piece of armour. */ static INVOBJ *identify(INVOBJ *io) { armour_for_obj(io->v[0])->flags |= AF_KNOWN; return(io); } /* * The OBJOPS for armour. */ OBJOPS objops_armour = { &new, &old, &std_format, &cond, &spec, &never_collapsible, &never_identical, &std_split, &identified, &identify };