diff --git src/cmd1.c src/cmd1.c index 2e11d6d..ba877fe 100644 --- src/cmd1.c +++ src/cmd1.c @@ -43,15 +43,41 @@ bool search(bool verbose) int py = p_ptr->py; int px = p_ptr->px; - int y, x, chance; + int y, x, chance, skill2, radius2, dist; bool found = FALSE; object_type *o_ptr; + bool empty_floor; + s16b this_o_idx; + s16b next_o_idx; /* Start with base search ability */ chance = p_ptr->state.skills[SKILL_SEARCH]; + skill2 = p_ptr->state.skills[SKILL_SEARCH_FREQUENCY]; + if (skill2 < 1) + { + skill2 = 0; + } + if (skill2 < 49) + { + skill2 = skill2 * skill2; + if (p_ptr->searching) + { + skill2 *= 2; + skill2 /= 50 - p_ptr->state.skills[SKILL_SEARCH_FREQUENCY]; + } + skill2 /= 5; + } + else + { + skill2 = skill2 * skill2 * skill2; + if (p_ptr->searching) skill2 *= 2; + skill2 /= 500; + } + radius2 = p_ptr->state.skills[SKILL_SEARCH] / 10; + radius2 = (radius2 * (p_ptr->lev / 10 + 2)) / 2; /* Penalize various conditions */ if (p_ptr->timed[TMD_BLIND] || no_light()) chance = chance / 10; @@ -140,6 +166,43 @@ bool search(bool verbose) } } + /* Search the nearby cave */ + if (p_ptr->depth > 0) + for (y = (py - radius2); y <= (py + radius2); y++) { + for (x = (px - radius2); x <= (px + radius2); x++) { + if (y == py && x == px) continue; + if (!cave_in_bounds(cave, y, x)) continue; + if (cave->info[y][x] & (CAVE_MARK)) continue; + if (cave->info[y][x] & (CAVE_ICKY)) continue; + if (!(empty_floor = (cave->feat[y][x] == FEAT_FLOOR))) continue; + this_o_idx = 0; + next_o_idx = 0; + for (this_o_idx = cave->o_idx[y][x]; + this_o_idx && empty_floor; + this_o_idx = next_o_idx) + { + /* Get the object */ + o_ptr = object_byid(this_o_idx); + + /* Get the next object */ + next_o_idx = o_ptr->next_o_idx; + + /* Not dead or held objects */ + if (o_ptr->kind && !o_ptr->held_m_idx) empty_floor = false; + } + if (!empty_floor) continue; + + dist = distance(y, x, py, px); + if (randint0(20 * dist * dist * dist) <= skill2) + { + /* Memorize the floors */ + cave->info[y][x] |= (CAVE_MARK); + cave_light_spot(cave, y, x); + found = TRUE; + } + } + } + if (verbose && !found) { if (chance >= 100)