#include #include "obj.h" #include "vars.h" #include "util.h" #include "pline.h" #include "format.h" #include "structs.h" #include "objtypes.h" #include "obj-wand.h" typedef struct wand WAND; struct wand { unsigned int flags; #define WF_KNOWN 0x00000001 int charges; } ; static WAND *wand_for_obj(OBJ *o) { if (objtypes[o->type].class != OC_WAND) panic("non-wand where wand needed"); return(o->private); } void zap_it(INVOBJ *io) { OBJ *o; WAND *w; if (io->n > 1) abort(); o = io->v[0]; w = wand_for_obj(o); if (w->charges < 1) { pline("Nothing happens."); return; } w->charges --; switch (o->type) { case OBJ_WAND_OF_LIGHT: objtypes[o->type].flags |= OTF_KNOWN; break; } } static OBJ *new(int type __attribute__((__unused__)), OBJ *o) { WAND *w; w = malloc(sizeof(WAND)); w->flags = 0; w->charges = 0; o->private = w; return(o); } static void old(OBJ *o) { free(o->private); } static int identified(INVOBJ *io) { return( (objtypes[io->v[0]->type].flags & OTF_KNOWN) && (wand_for_obj(io->v[0])->flags & WF_KNOWN) ); } static INVOBJ *identify(INVOBJ *io) { objtypes[io->v[0]->type].flags |= OTF_KNOWN; wand_for_obj(io->v[0])->flags |= WF_KNOWN; return(io); } OBJOPS objops_wand = { &new, &old, &std_format, 0, 0, &never_collapsible, &never_identical, &std_split, &identified, &identify };