/** * Place a random type of door at the given location. */ void place_random_door(int y, int x) { int tmp; /* Choose an object */ tmp = randint0(1000); /* Open doors (300/1000) */ if (tmp < 300) { /* Create open door */ cave_set_feat(y, x, FEAT_OPEN); } /* Broken doors (100/1000) */ else if (tmp < 400) { /* Create broken door */ cave_set_feat(y, x, FEAT_BROKEN); } /* Secret doors (200/1000) */ else if (tmp < 600) { /* Create secret door */ cave_set_feat(y, x, FEAT_SECRET); } /* Closed, locked, or stuck doors (400/1000) */ else { /* Create closed door */ place_closed_door(y, x); } }
/* Destroy Traps (and Locks) */ static void project_feature_handler_KILL_TRAP(project_feature_handler_context_t *context) { const int x = context->x; const int y = context->y; /* Reveal secret doors */ if (square_issecretdoor(cave, y, x)) { place_closed_door(cave, y, x); /* Check line of sight */ if (square_isseen(cave, y, x)) context->obvious = true; } /* Destroy traps, unlock doors */ if (square_istrap(cave, y, x)) { /* Check line of sight */ if (square_isview(cave, y, x)) { msg("There is a bright flash of light!"); context->obvious = true; } /* Destroy the trap */ square_destroy_trap(cave, y, x); } else if (square_islockeddoor(cave, y, x)) { /* Unlock the door */ square_unlock_door(cave, y, x); /* Check line of sound */ if (square_isview(cave, y, x)) { msg("Click!"); context->obvious = true; } } }
/** * Place a random door at (x, y). * \param c current chunk * \param y co-ordinates * \param x co-ordinates * * The door generated could be closed, open, broken, or secret. */ void place_random_door(struct chunk *c, int y, int x) { int tmp = randint0(100); if (tmp < 30) square_set_feat(c, y, x, FEAT_OPEN); else if (tmp < 40) square_set_feat(c, y, x, FEAT_BROKEN); else place_closed_door(c, y, x); }
/** * Search for traps or secret doors */ static void search(void) { int py = player->py; int px = player->px; int y, x; struct object *obj; /* Various conditions mean no searching */ if (player->timed[TMD_BLIND] || no_light() || player->timed[TMD_CONFUSED] || player->timed[TMD_IMAGE]) return; /* Search the nearby grids, which are always in bounds */ for (y = (py - 1); y <= (py + 1); y++) { for (x = (px - 1); x <= (px + 1); x++) { /* Traps */ if (square_issecrettrap(cave, y, x)) { if (square_reveal_trap(cave, y, x, true)) disturb(player, 0); } /* Secret doors */ if (square_issecretdoor(cave, y, x)) { msg("You have found a secret door."); place_closed_door(cave, y, x); disturb(player, 0); } /* Traps on chests */ for (obj = square_object(cave, y, x); obj; obj = obj->next) { if (!obj->known || !is_trapped_chest(obj)) continue; if (obj->known->pval != obj->pval) { msg("You have discovered a trap on the chest!"); obj->known->pval = obj->pval; disturb(player, 0); } } } } }
/* * Search for hidden things. Returns true if a search was attempted, returns * false when the player has a 0% chance of finding anything. Prints messages * for negative confirmation when verbose mode is requested. */ bool search(bool verbose) { int py = p_ptr->py; int px = p_ptr->px; int y, x, chance; bool found = FALSE; object_type *o_ptr; /* Start with base search ability */ chance = p_ptr->state.skills[SKILL_SEARCH]; /* Penalize various conditions */ if (p_ptr->timed[TMD_BLIND] || no_light()) chance = chance / 10; if (p_ptr->timed[TMD_CONFUSED] || p_ptr->timed[TMD_IMAGE]) chance = chance / 10; /* Prevent fruitless searches */ if (chance <= 0) { if (verbose) { msg("You can't make out your surroundings well enough to search."); /* Cancel repeat */ disturb(p_ptr, 0, 0); } return FALSE; } /* Search the nearby grids, which are always in bounds */ for (y = (py - 1); y <= (py + 1); y++) { for (x = (px - 1); x <= (px + 1); x++) { /* Sometimes, notice things */ if (randint0(100) < chance) { /* Invisible trap */ if (cave->feat[y][x] == FEAT_INVIS) { found = TRUE; /* Pick a trap */ pick_trap(y, x); /* Message */ msg("You have found a trap."); /* Disturb */ disturb(p_ptr, 0, 0); } /* Secret door */ if (cave->feat[y][x] == FEAT_SECRET) { found = TRUE; /* Message */ msg("You have found a secret door."); /* Pick a door */ place_closed_door(cave, y, x); /* Disturb */ disturb(p_ptr, 0, 0); } /* Scan all objects in the grid */ for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr)) { /* Skip non-chests */ if (o_ptr->tval != TV_CHEST) continue; /* Skip disarmed chests */ if (o_ptr->pval[DEFAULT_PVAL] <= 0) continue; /* Skip non-trapped chests */ if (!chest_traps[o_ptr->pval[DEFAULT_PVAL]]) continue; /* Identify once */ if (!object_is_known(o_ptr)) { found = TRUE; /* Message */ msg("You have discovered a trap on the chest!"); /* Know the trap */ object_notice_everything(o_ptr); /* Notice it */ disturb(p_ptr, 0, 0); } } } } } if (verbose && !found) { if (chance >= 100) msg("There are no secrets here."); else msg("You found nothing."); } return TRUE; }
/* * Place a random type of door at the given location */ void place_random_door(int y, int x, bool room) { int tmp, type; s16b feat = feat_none; cave_type *c_ptr = &cave[y][x]; /* Initialize mimic info */ c_ptr->mimic = 0; /* if (dungeon_type == DUNGEON_ARENA) { place_rubble_bold(y, x); return; }*/ if (d_info[dungeon_type].flags1 & DF1_NO_DOORS) { place_floor_bold(y, x); return; } type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) && one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN : ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR); /* Choose an object */ tmp = randint0(1000); /* Open doors (300/1000) */ if (tmp < 300) { /* Create open door */ feat = feat_door[type].open; } /* Broken doors (100/1000) */ else if (tmp < 400) { /* Create broken door */ feat = feat_door[type].broken; } /* Secret doors (200/1000) */ else if (tmp < 600) { /* Create secret door */ place_closed_door(y, x, type); if (type != DOOR_CURTAIN) { /* Hide. If on the edge of room, use outer wall. */ c_ptr->mimic = room ? feat_wall_outer : fill_type[randint0(100)]; /* Floor type terrain cannot hide a door */ if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat)) { if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY)) { c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)]; } c_ptr->mimic = 0; } } } /* Closed, locked, or stuck doors (400/1000) */ else place_closed_door(y, x, type); if (tmp < 400) { if (feat != feat_none) { set_cave_feat(y, x, feat); } else { place_floor_bold(y, x); } } delete_monster(y, x); }
/** * Search for hidden things. Returns true if a search was attempted, returns * false when the player has a 0% chance of finding anything. Prints messages * for negative confirmation when verbose mode is requested. */ bool search(bool verbose) { int py = player->py; int px = player->px; int y, x, chance; bool found = false; struct object *obj; /* Start with base search ability */ chance = player->state.skills[SKILL_SEARCH]; /* Penalize various conditions */ if (player->timed[TMD_BLIND] || no_light()) chance = chance / 10; if (player->timed[TMD_CONFUSED] || player->timed[TMD_IMAGE]) chance = chance / 10; /* Prevent fruitless searches */ if (chance <= 0) { if (verbose) { msg("You can't make out your surroundings well enough to search."); /* Cancel repeat */ disturb(player, 0); } return false; } /* Search the nearby grids, which are always in bounds */ for (y = (py - 1); y <= (py + 1); y++) { for (x = (px - 1); x <= (px + 1); x++) { /* Sometimes, notice things */ if (randint0(100) < chance) { if (square_issecrettrap(cave, y, x)) { found = true; /* Reveal trap, display a message */ if (square_reveal_trap(cave, y, x, chance, true)) /* Disturb */ disturb(player, 0); } /* Secret door */ if (square_issecretdoor(cave, y, x)) { found = true; /* Message */ msg("You have found a secret door."); /* Pick a door */ place_closed_door(cave, y, x); /* Disturb */ disturb(player, 0); } /* Scan all objects in the grid */ for (obj = square_object(cave, y, x); obj; obj = obj->next) { /* Skip if not a trapped chest */ if (!is_trapped_chest(obj)) continue; /* Identify once */ if (!object_is_known(obj)) { found = true; /* Message */ msg("You have discovered a trap on the chest!"); /* Know the trap */ object_notice_everything(obj); /* Notice it */ disturb(player, 0); } } } } } if (verbose && !found) { if (chance >= 100) msg("There are no secrets here."); else msg("You found nothing."); } return true; }