/** * Set the terrain type for a square. * * This should be the only function that sets terrain, apart from the savefile * loading code. */ void square_set_feat(struct chunk *c, int y, int x, int feat) { int current_feat = c->squares[y][x].feat; assert(c); assert(y >= 0 && y < c->height); assert(x >= 0 && x < c->width); /* Track changes */ if (current_feat) c->feat_count[current_feat]--; if (feat) c->feat_count[feat]++; /* Make the change */ c->squares[y][x].feat = feat; /* Make the new terrain feel at home */ if (character_dungeon) { /* Remove traps if necessary */ if (!square_player_trap_allowed(c, y, x)) square_destroy_trap(c, y, x); square_note_spot(c, y, x); square_light_spot(c, y, x); } else { /* Make sure no incorrect wall flags set for dungeon generation */ sqinfo_off(c->squares[y][x].info, SQUARE_WALL_INNER); sqinfo_off(c->squares[y][x].info, SQUARE_WALL_OUTER); sqinfo_off(c->squares[y][x].info, SQUARE_WALL_SOLID); } }
/** * Make a new trap of the given type. Return TRUE if successful. * * We choose a player trap at random if the index is not legal. This means that * things which are not player traps must be picked by passing a valid index. * * This should be the only function that places traps in the dungeon * except the savefile loading code. */ void place_trap(struct chunk *c, int y, int x, int t_idx, int trap_level) { struct trap *new_trap; /* We've been called with an illegal index; choose a random trap */ if ((t_idx <= 0) || (t_idx >= z_info->trap_max)) { /* Require the correct terrain */ if (!square_player_trap_allowed(c, y, x)) return; t_idx = pick_trap(c->squares[y][x].feat, trap_level); } /* Failure */ if (t_idx < 0) return; /* Allocate a new trap for this grid (at the front of the list) */ new_trap = mem_zalloc(sizeof(*new_trap)); new_trap->next = c->squares[y][x].trap; c->squares[y][x].trap = new_trap; /* Set the details */ new_trap->t_idx = t_idx; new_trap->kind = &trap_info[t_idx]; new_trap->fy = y; new_trap->fx = x; trf_copy(new_trap->flags, trap_info[t_idx].flags); /* Toggle on the trap marker */ sqinfo_on(c->squares[y][x].info, SQUARE_TRAP); /* Redraw the grid */ square_light_spot(c, y, x); }