summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-06 11:03:21 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-06 11:03:21 +0000
commit960323c5b08a5431ac60b72c7de65a40ef203183 (patch)
tree6571ec0d182fd5a597968a0415f80a15bbea3680
parent6efc5c639a0ba48559c2fad77376a210b503256c (diff)
downloadcrawl-ref-960323c5b08a5431ac60b72c7de65a40ef203183.tar.gz
crawl-ref-960323c5b08a5431ac60b72c7de65a40ef203183.zip
Fix 1945389: Detect Creatures not clearing monsters detected on changed
terrain. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6419 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/monstuff.cc21
-rw-r--r--crawl-ref/source/spells2.cc29
-rw-r--r--crawl-ref/source/spl-cast.cc13
-rw-r--r--crawl-ref/source/view.cc15
-rw-r--r--crawl-ref/source/view.h2
5 files changed, 51 insertions, 29 deletions
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index 1b513cf5cd..9633e0c81c 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -5668,22 +5668,22 @@ static bool _swap_monsters(const int mover_idx, const int moved_idx)
// Can't swap with a stationary monster.
if (mons_is_stationary(moved))
- return false;
+ return (false);
// Swapping is a purposeful action.
if (mover->confused())
- return false;
+ return (false);
// Right now just happens in sanctuary.
if (!is_sanctuary(mover->x, mover->y) || !is_sanctuary(moved->x, moved->y))
- return false;
+ return (false);
// A friendly or good-neutral monster moving past a fleeing hostile
// or neutral monster, or vice versa.
if (mons_wont_attack(mover) == mons_wont_attack(moved)
|| mons_is_fleeing(mover) == mons_is_fleeing(moved))
{
- return false;
+ return (false);
}
// Don't swap places if the player explicitly ordered their pet to
@@ -5691,19 +5691,19 @@ static bool _swap_monsters(const int mover_idx, const int moved_idx)
if ((mons_friendly(mover) || mons_friendly(moved))
&& you.pet_target != MHITYOU && you.pet_target != MHITNOT)
{
- return false;
+ return (false);
}
if (!mover->can_pass_through(moved->x, moved->y)
|| !moved->can_pass_through(mover->x, mover->y))
{
- return false;
+ return (false);
}
if (!monster_habitable_grid(mover, grd[moved->x][moved->y])
|| !monster_habitable_grid(moved, grd[mover->x][mover->y]))
{
- return false;
+ return (false);
}
// Okay, we can do the swap.
@@ -5725,8 +5725,8 @@ static bool _swap_monsters(const int mover_idx, const int moved_idx)
moved->name(DESC_NOCAP_THE).c_str());
}
- return true;
-} // bool _swap_monsters()
+ return (true);
+}
static void _swim_or_move_energy(monsters *mon)
{
@@ -5826,7 +5826,8 @@ static void _handle_monster_move(int i, monsters *monster)
entry->energy_usage.swim);
while (monster->has_action_energy())
- { // The continues & breaks are WRT this.
+ {
+ // The continues & breaks are WRT this.
if (!monster->alive())
break;
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index a8ec9cab63..fa7bfee000 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -98,15 +98,21 @@ unsigned char detect_items( int pow )
pow = 50;
unsigned char items_found = 0;
- const int map_radius = 8 + random2(8) + pow;
+ const int map_radius = 8 + random2(8) + pow;
for (int i = you.x_pos - map_radius; i < you.x_pos + map_radius; i++)
- {
for (int j = you.y_pos - map_radius; j < you.y_pos + map_radius; j++)
{
if (!in_bounds(i, j))
continue;
+ // Don't expose new dug out areas:
+ // Note: assumptions are being made here about how
+ // terrain can change (eg it used to be solid, and
+ // thus item free).
+ if (is_terrain_changed(i, j))
+ continue;
+
if (igrd[i][j] != NON_ITEM
&& (!get_envmap_obj(i, j) || !is_envmap_item(i, j)))
{
@@ -121,7 +127,6 @@ unsigned char detect_items( int pow )
#endif
}
}
- }
return (items_found);
}
@@ -159,12 +164,25 @@ static bool _mark_detected_creature(int gridx, int gridy, const monsters *mon,
const int fuzz_diam = 2 * fuzz_radius + 1;
int gx, gy;
+ // Try five times to find a valid placement, else we attempt to place
+ // the monster where it really is (and may fail).
for (int itry = 0; itry < 5; ++itry)
{
gx = gridx + random2(fuzz_diam) - fuzz_radius;
gy = gridy + random2(fuzz_diam) - fuzz_radius;
- if (map_bounds(gx, gy)
+ // If the player would be able to see a monster at this location
+ // don't place it there.
+ if (see_grid(gx, gy))
+ continue;
+
+ // Try not to overwrite another detected monster.
+ if (is_envmap_detected_mons(gx, gy))
+ continue;
+
+ // Don't print monsters on terrain they cannot pass through,
+ // not even if said terrain has since changed.
+ if (map_bounds(gx, gy) && !is_terrain_changed(gx, gy)
&& mon->can_pass_through_feat(grd[gx][gy]))
{
found_good = true;
@@ -217,9 +235,6 @@ int detect_creatures( int pow, bool telepathic )
monsters *mon = &menv[ mgrd[i][j] ];
creatures_found++;
- // This only returns whether a valid "fuzzy" place has been
- // found for the monster. In any case, the monster gets
- // printed on the screen.
_mark_detected_creature(i, j, mon, fuzz_chance, fuzz_radius);
// Assuming that highly intelligent spellcasters can
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index 0e552e784c..225018a140 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -2006,13 +2006,20 @@ spret_type your_spells(spell_type spell, int powc, bool allow_fail)
case SPELL_DETECT_CREATURES:
{
- int known_plants = count_detected_plants();
- int num_creatures = detect_creatures(powc);
+ const int prev_detected = count_detected_mons();
+ const int num_creatures = detect_creatures(powc);
if (!num_creatures)
mpr("You detect nothing.");
- else if (num_creatures == known_plants)
+ else if (num_creatures == prev_detected)
+ {
+ // This is not strictly true. You could have cast
+ // Detect Creatures with a big enough fuzz that the detected
+ // glyph is still on the map when the original one has been
+ // killed. Then another one is spawned, so the number is
+ // the same as before. There's no way we can check this however.
mpr("You detect no further creatures.");
+ }
else
mpr("You detect creatures!");
break;
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 2a4176acc1..a8a070e17d 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -668,7 +668,7 @@ screen_buffer_t colour_code_map( int x, int y, bool item_colour,
return real_colour(tc);
}
-int count_detected_plants()
+int count_detected_mons()
{
int count = 0;
for (int y = Y_BOUND_1; y <= Y_BOUND_2; ++y)
@@ -681,11 +681,7 @@ int count_detected_plants()
if (is_terrain_changed(x, y))
continue;
- unsigned envc = get_envmap_char(x, y);
- if (!envc)
- continue;
-
- if (envc == 'P' || envc == 'f')
+ if (is_envmap_detected_mons(x, y))
count++;
}
@@ -701,8 +697,11 @@ void clear_map(bool clear_detected_items, bool clear_detected_monsters)
// Note: assumptions are being made here about how
// terrain can change (eg it used to be solid, and
// thus monster/item free).
- if (is_terrain_changed(x, y))
- continue;
+
+ // This reasoning doesn't make sense when it comes to *clearing*
+ // the map! (jpeg)
+// if (is_terrain_changed(x, y))
+// continue;
unsigned envc = get_envmap_char(x, y);
if (!envc)
diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h
index b00365cdf2..e154b6f854 100644
--- a/crawl-ref/source/view.h
+++ b/crawl-ref/source/view.h
@@ -127,7 +127,7 @@ void setLOSRadius(int newLR);
* *********************************************************************** */
bool check_awaken(monsters* monster);
-int count_detected_plants(void);
+int count_detected_mons(void);
void clear_map(bool clear_items = true, bool clear_mons = true);