/** * Read a trap record */ static void rd_trap(struct trap *trap) { int i; char buf[80]; rd_string(buf, sizeof(buf)); if (buf[0]) { trap->kind = lookup_trap(buf); trap->t_idx = trap->kind->tidx; } rd_byte(&trap->fy); rd_byte(&trap->fx); rd_byte(&trap->power); rd_byte(&trap->timeout); for (i = 0; i < trf_size; i++) rd_byte(&trap->flags[i]); }
/** * Lock a closed door to a given power */ void square_set_door_lock(struct chunk *c, int y, int x, int power) { struct trap_kind *lock = lookup_trap("door lock"); struct trap *trap; /* Verify it's a closed door */ if (!square_iscloseddoor(c, y, x)) return; /* If there's no lock there, add one */ if (!square_trap_specific(c, y, x, lock->tidx)) place_trap(c, y, x, lock->tidx, 0); /* Set the power (of all locks - there should be only one) */ trap = c->squares[y][x].trap; while (trap) { if (trap->kind == lock) trap->xtra = power; trap = trap->next; } }
/** * Return the power of the lock on a door */ int square_door_power(struct chunk *c, int y, int x) { struct trap_kind *lock = lookup_trap("door lock"); struct trap *trap; /* Verify it's a closed door */ if (!square_iscloseddoor(c, y, x)) return 0; /* Is there a lock there? */ if (!square_trap_specific(c, y, x, lock->tidx)) return 0; /* Get the power and return it */ trap = c->squares[y][x].trap; while (trap) { if (trap->kind == lock) return trap->xtra; trap = trap->next; } return 0; }
void square_remove_ward(struct chunk *c, int y, int x) { struct trap_kind *rune = lookup_trap("glyph of warding"); assert(square_iswarded(c, y, x)); square_remove_trap(c, y, x, TRUE, rune->tidx); }
void square_add_ward(struct chunk *c, int y, int x) { struct trap_kind *rune = lookup_trap("glyph of warding"); place_trap(c, y, x, rune->tidx, 0); }
bool square_iswarded(struct chunk *c, int y, int x) { struct trap_kind *rune = lookup_trap("glyph of warding"); return square_trap_specific(c, y, x, rune->tidx); }