/* * 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_armour(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_armour(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 fmt_cond_armour(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 fmt_spec_armour(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_armour(INVOBJ *io) { return(armour_for_obj(io->v[0])->flags & AF_KNOWN); } /* * Identify a piece of armour. */ static INVOBJ *identify_armour(INVOBJ *io) { armour_for_obj(io->v[0])->flags |= AF_KNOWN; return(io); } /* * The OBJOPS for armour. */ #define format_armour std_format #define collapsible_armour never_collapsible #define identical_armour never_identical #define split_armour std_split #define moved_armour noop_moved OBJOPS objops_armour = OBJOPS_INIT(armour);