diff --git src/cmd1.c src/cmd1.c index d3ae01b..ef59d92 100644 --- src/cmd1.c +++ src/cmd1.c @@ -43,15 +43,22 @@ bool search(bool verbose) int py = p_ptr->py; int px = p_ptr->px; - int y, x, skill, radius; + int y, x, skill, radius, skill2, radius2, dist; bool found = FALSE; monster_type *m_ptr; + bool empty_floor; + s16b this_o_idx; + s16b next_o_idx; + object_type *o_ptr; + /* Start with base search ability */ skill = p_ptr->state.skills[SKILL_SEARCH]; radius = p_ptr->state.skills[SKILL_SEARCH_RADIUS]; + skill2 = skill * skill * skill / 1000; + radius2 = (radius * (p_ptr->lev / 10 + 2)) / 2; /* Boost skill if player used (s)earch and isn't in (S)earching mode * (Searching mode already passively boosts skill and radius.) @@ -59,6 +66,8 @@ bool search(bool verbose) if (verbose && !p_ptr->searching) { skill += 10; radius += 2; + skill2 += 1; + radius2 += 5; } /* Penalize various conditions */ @@ -70,6 +79,8 @@ bool search(bool verbose) if (p_ptr->timed[TMD_CONFUSED] || p_ptr->timed[TMD_IMAGE]) { skill = skill / 10; radius = radius / 2; + skill2 = skill2 / 10; + radius2 = radius2 / 2; } /* Prevent fruitless searches */ @@ -142,6 +153,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) msg("You found nothing.");