#include #include "obj.h" #include "vars.h" #include "util.h" #include "pline.h" #include "format.h" #include "structs.h" #include "objtypes.h" typedef struct armor ARMOR; struct armor { unsigned int flags; #define AF_KNOWN 0x00000001 int bonus; } ; static ARMOR *armor_for_obj(OBJ *o) { if (objtypes[o->type].class != OC_ARMOR) panic("non-armor where armor needed"); return(o->private); } static OBJ *new(int type __attribute__((__unused__)), OBJ *o) { ARMOR *a; a = malloc(sizeof(ARMOR)); a->flags = 0; a->bonus = 0; o->private = a; return(o); } static void old(OBJ *o) { free(o->private); } static int cond(char ch, INVOBJ *io) { switch (ch) { case 'K': return(armor_for_obj(io->v[0])->flags&AF_KNOWN); break; } panic("invalid conditional +%c for armor",ch); } static void spec(FILE *f, char ch, INVOBJ *io) { switch (ch) { case 'P': fprintf(f,"%+d",armor_for_obj(io->v[0])->bonus); break; default: panic("invalid format %%+%c for armor",ch); break; } } static int identified(INVOBJ *io) { return(armor_for_obj(io->v[0])->flags & AF_KNOWN); } static INVOBJ *identify(INVOBJ *io) { armor_for_obj(io->v[0])->flags |= AF_KNOWN; return(io); } OBJOPS objops_armor = { &new, &old, &std_format, &cond, &spec, &never_collapsible, &never_identical, &std_split, &identified, &identify };