summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-02-13 00:47:33 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-02-13 00:47:33 +0000
commit412bcd6e779cd3883bc5c6ce29a8e79ad32c63f4 (patch)
tree45316891325a63a834b5baef43896e464ed8fedb /crawl-ref
parent2dd4fe4a7f0b809a9f3a565f64ed6b5dcb1ab814 (diff)
downloadcrawl-ref-412bcd6e779cd3883bc5c6ce29a8e79ad32c63f4.tar.gz
crawl-ref-412bcd6e779cd3883bc5c6ce29a8e79ad32c63f4.zip
Remove a great many cases where mgrd is accessed directly in favour
of monster_at(). The hope is to eventually remove mgrd completely (in favour of scanning through the monster list, or a different datastructure which gets updated automatically when monsters move), and thus fix all the mgrd-out-of-sync bugs in one fell swoop. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9056 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/abl-show.cc26
-rw-r--r--crawl-ref/source/abyss.cc5
-rw-r--r--crawl-ref/source/acr.cc38
-rw-r--r--crawl-ref/source/beam.cc28
-rw-r--r--crawl-ref/source/debug.cc5
-rw-r--r--crawl-ref/source/decks.cc12
-rw-r--r--crawl-ref/source/delay.cc19
-rw-r--r--crawl-ref/source/describe.cc6
-rw-r--r--crawl-ref/source/describe.h6
-rw-r--r--crawl-ref/source/directn.cc177
-rw-r--r--crawl-ref/source/effects.cc40
-rw-r--r--crawl-ref/source/files.cc5
-rw-r--r--crawl-ref/source/it_use3.cc24
-rw-r--r--crawl-ref/source/misc.cc27
-rw-r--r--crawl-ref/source/mtransit.cc2
-rw-r--r--crawl-ref/source/religion.cc10
-rw-r--r--crawl-ref/source/spells1.cc9
-rw-r--r--crawl-ref/source/spells2.cc13
-rw-r--r--crawl-ref/source/spells3.cc41
-rw-r--r--crawl-ref/source/spells4.cc232
-rw-r--r--crawl-ref/source/spl-util.cc2
-rw-r--r--crawl-ref/source/stuff.cc14
-rw-r--r--crawl-ref/source/travel.cc10
-rw-r--r--crawl-ref/source/tutorial.cc36
24 files changed, 336 insertions, 451 deletions
diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc
index 927eb987ed..dc3bee5714 100644
--- a/crawl-ref/source/abl-show.cc
+++ b/crawl-ref/source/abl-show.cc
@@ -2418,32 +2418,34 @@ static int _find_ability_slot( ability_type which_ability )
static int _lugonu_warp_monster(coord_def where, int pow, int, actor *)
{
- if (!in_bounds(where) || mgrd(where) == NON_MONSTER)
+ if (!in_bounds(where))
return (0);
- monsters &mon = menv[ mgrd(where) ];
+ monsters* mon = monster_at(where);
+ if (mon == NULL)
+ return (0);
- if (!mons_friendly(&mon))
- behaviour_event( &mon, ME_ANNOY, MHITYOU );
+ if (!mons_friendly(mon))
+ behaviour_event(mon, ME_ANNOY, MHITYOU);
- if (check_mons_resist_magic(&mon, pow * 2))
+ if (check_mons_resist_magic(mon, pow * 2))
{
mprf("%s %s.",
- mon.name(DESC_CAP_THE).c_str(), mons_resist_string(&mon));
+ mon->name(DESC_CAP_THE).c_str(), mons_resist_string(mon));
return (1);
}
const int damage = 1 + random2(pow / 6);
- if (mon.type == MONS_BLINK_FROG)
- mon.heal(damage, false);
- else if (!check_mons_resist_magic(&mon, pow))
+ if (mon->type == MONS_BLINK_FROG)
+ mon->heal(damage, false);
+ else if (!check_mons_resist_magic(mon, pow))
{
- mon.hurt(&you, damage);
- if (!mon.alive())
+ mon->hurt(&you, damage);
+ if (!mon->alive())
return (1);
}
- mon.blink();
+ mon->blink();
return (1);
}
diff --git a/crawl-ref/source/abyss.cc b/crawl-ref/source/abyss.cc
index 352caeb7e2..b5eaa2ecbb 100644
--- a/crawl-ref/source/abyss.cc
+++ b/crawl-ref/source/abyss.cc
@@ -21,6 +21,7 @@ REVISION("$Rev$");
#include "mapmark.h"
#include "message.h"
#include "misc.h"
+#include "mon-util.h"
#include "monplace.h"
#include "mtransit.h"
#include "player.h"
@@ -467,8 +468,8 @@ void area_shift(void)
#endif
lose_item_stack( *ri );
- if (mgrd(*ri) != NON_MONSTER)
- _abyss_lose_monster( menv[ mgrd(*ri) ] );
+ if (monsters* m = monster_at(*ri))
+ _abyss_lose_monster(*m);
}
// Shift all monsters and items to new area.
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 4777fde84a..79d4b72cba 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -2960,26 +2960,26 @@ static void _open_door(coord_def move, bool check_confused)
{
doorpos = you.pos() + move;
- const int mon = mgrd(doorpos);
+ monsters* mon = monster_at(doorpos);
- if (mon != NON_MONSTER && player_can_hit_monster(&menv[mon]))
+ if (mon && player_can_hit_monster(mon))
{
- if (mons_is_caught(&menv[mon]))
+ if (mons_is_caught(mon))
{
- std::string prompt = "Do you want to try to take the net off ";
- prompt += (&menv[mon])->name(DESC_NOCAP_THE);
- prompt += '?';
+ const std::string prompt =
+ make_stringf("Do you want to try to take the net off %s?",
+ mon->name(DESC_NOCAP_THE).c_str());
if (yesno(prompt.c_str(), true, 'n'))
{
- remove_net_from(&menv[mon]);
+ remove_net_from(mon);
return;
}
}
you.turn_is_over = true;
- you_attack(mgrd(doorpos), true);
+ you_attack(mon->mindex(), true);
if (you.berserk_penalty != NO_BERSERK_PENALTY)
you.berserk_penalty = 0;
@@ -3172,11 +3172,11 @@ static void _close_door(coord_def move)
i != all_door.end(); ++i)
{
const coord_def& dc = *i;
- if (mgrd(dc) != NON_MONSTER)
+ if (monsters* mon = monster_at(dc))
{
// Need to make sure that turn_is_over is set if creature is
// invisible.
- if (!player_monster_visible(&menv[mgrd(dc)]))
+ if (!player_monster_visible(mon))
{
mprf("Something is blocking the %sway!", noun);
you.turn_is_over = true;
@@ -3575,14 +3575,14 @@ static void _move_player(coord_def move)
const coord_def& targ = you.pos() + move;
const dungeon_feature_type targ_grid = grd(targ);
- const unsigned short targ_monst = mgrd(targ);
+ monsters* targ_monst = monster_at(targ);
const bool targ_pass = you.can_pass_through(targ);
// You can swap places with a friendly or good neutral monster if
// you're not confused, or if both of you are inside a sanctuary.
- const bool can_swap_places = targ_monst != NON_MONSTER
- && !mons_is_stationary(&menv[targ_monst])
- && (mons_wont_attack(&menv[targ_monst])
+ const bool can_swap_places = targ_monst
+ && !mons_is_stationary(targ_monst)
+ && (mons_wont_attack(targ_monst)
&& !you.confused()
|| is_sanctuary(you.pos())
&& is_sanctuary(targ));
@@ -3615,13 +3615,11 @@ static void _move_player(coord_def move)
coord_def mon_swap_dest;
- if (targ_monst != NON_MONSTER && !mons_is_submerged(&menv[targ_monst]))
+ if (targ_monst && !mons_is_submerged(targ_monst))
{
- monsters *mon = &menv[targ_monst];
-
if (can_swap_places && !beholder)
{
- if (swap_check(mon, mon_swap_dest))
+ if (swap_check(targ_monst, mon_swap_dest))
swap = true;
else
moving = false;
@@ -3634,7 +3632,7 @@ static void _move_player(coord_def move)
// the player to figure out which adjacent wall an invis
// monster is in "for free".
you.turn_is_over = true;
- you_attack( targ_monst, true );
+ you_attack(targ_monst->mindex(), true);
// We don't want to create a penalty if there isn't
// supposed to be one.
@@ -3653,7 +3651,7 @@ static void _move_player(coord_def move)
return;
if (swap)
- swap_places(&menv[targ_monst], mon_swap_dest);
+ swap_places(targ_monst, mon_swap_dest);
you.prev_move = move;
move.reset();
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index adc278cc61..c8238fbe86 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -1504,13 +1504,13 @@ void bolt::initialize_fire()
if (!seen && see_grid(source) && range > 0 && !invisible() )
{
seen = true;
- const int midx = mgrd(source);
+ const monsters* mon = monster_at(source);
if (flavour != BEAM_VISUAL
&& !is_tracer
&& !YOU_KILL(thrower)
&& !crawl_state.is_god_acting()
- && (midx == NON_MONSTER || !you.can_see(&menv[midx])))
+ && (!mon || !you.can_see(mon)))
{
mprf("%s appears from out of thin air!",
article_a(name, false).c_str());
@@ -1796,8 +1796,8 @@ void bolt::hit_wall()
else
{
// Affect a creature in the wall, if any.
- if (!invalid_monster_index(mgrd(pos())))
- affect_monster(&menv[mgrd(pos())]);
+ if (monsters* m = monster_at(pos()))
+ affect_monster(m);
// Regress for explosions: blow up in an open grid (if regressing
// makes any sense). Also regress when dropping items.
@@ -1827,12 +1827,9 @@ void bolt::affect_cell()
const bool was_solid = grid_is_solid(grd(pos()));
if (was_solid)
{
- const int mid = mgrd(pos());
-
// Some special casing.
- if (!invalid_monster_index(mid))
+ if (monsters* mon = monster_at(pos()))
{
- monsters* const mon = &menv[mid];
if (can_affect_wall_monster(mon))
affect_monster(mon);
else
@@ -1850,8 +1847,9 @@ void bolt::affect_cell()
// We don't want to hit a monster in a wall square twice.
const bool still_wall = (was_solid && old_pos == pos());
- if (!still_wall && !invalid_monster_index(mgrd(pos())))
- affect_monster(&menv[mgrd(pos())]);
+ if (!still_wall)
+ if (monsters* m = monster_at(pos()))
+ affect_monster(m);
// If the player can ever walk through walls, this will
// need special-casing too.
@@ -2882,10 +2880,10 @@ void bolt::drop_object()
{
if (item->sub_type == MI_THROWING_NET)
{
+ monsters* m = monster_at(pos());
// Player or monster on position is caught in net.
if (you.pos() == pos() && you.attribute[ATTR_HELD]
- || mgrd(pos()) != NON_MONSTER &&
- mons_is_caught(&menv[mgrd(pos())]))
+ || m && mons_is_caught(m))
{
// If no trapping net found mark this one.
if (get_trapping_net(pos(), true) == NON_ITEM)
@@ -3103,7 +3101,7 @@ void bolt::affect_place_explosion_clouds()
place_cloud( CLOUD_FIRE, p, duration, whose_kill(), killer() );
- if (grd(p) == DNGN_FLOOR && mgrd(p) == NON_MONSTER
+ if (grd(p) == DNGN_FLOOR && !monster_at(p)
&& one_chance_in(4))
{
const god_type god =
@@ -3325,8 +3323,8 @@ void bolt::reflect()
if (pos() == you.pos())
reflector = NON_MONSTER;
- else if (mgrd(pos()) != NON_MONSTER)
- reflector = mgrd(source);
+ else if (monsters* m = monster_at(pos()))
+ reflector = m->mindex();
else
{
reflector = -1;
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 56ca4312e6..321b11bad3 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -5599,10 +5599,7 @@ static void _move_monster(const coord_def& where, int mid1)
monsters* mon1 = &menv[mid1];
const int mid2 = mgrd(moves.target);
- monsters* mon2 = NULL;
-
- if (mid2 != NON_MONSTER)
- mon2 = &menv[mid2];
+ monsters* mon2 = monster_at(moves.target);
mon1->moveto(moves.target);
mgrd(moves.target) = mid1;
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index c5b56ffa0c..8e9ca93b77 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -1738,14 +1738,12 @@ static int _drain_monsters(coord_def where, int pow, int, actor *)
drain_exp();
else
{
- const int mnstr = mgrd(where);
- if (mnstr == NON_MONSTER)
+ monsters* mon = monster_at(where);
+ if (mon == NULL)
return (0);
- monsters& mon = menv[mnstr];
-
- if (!mon.drain_exp(&you, false, pow / 50))
- simple_monster_message(&mon, " is unaffected.");
+ if (mon->drain_exp(&you, false, pow / 50))
+ simple_monster_message(mon, " is unaffected.");
}
return (1);
@@ -2533,7 +2531,7 @@ static bool _trowel_card(int power, deck_rarity_type rarity)
{
// Do-nothing (effectively): create a cosmetic feature
const coord_def pos = pick_adjacent_free_square(you.pos());
- if (pos.x >= 0 && pos.y >= 0)
+ if (in_bounds(pos))
{
const dungeon_feature_type statfeat[] = {
DNGN_GRANITE_STATUE, DNGN_ORCISH_IDOL
diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc
index 08a7e92d9f..b8caa84917 100644
--- a/crawl-ref/source/delay.cc
+++ b/crawl-ref/source/delay.cc
@@ -83,11 +83,11 @@ static bool _recite_mons_useless(const monsters *mon)
// Power is maximum 50.
static int _recite_to_monsters(coord_def where, int pow, int, actor *)
{
- const int mon = mgrd(where);
- if (mon == NON_MONSTER)
- return (0);
- monsters *mons = &menv[mon];
+ monsters *mons = monster_at(where);
+
+ if (mons == NULL)
+ return (0);
if (_recite_mons_useless(mons))
return (0);
@@ -676,13 +676,14 @@ int check_recital_audience()
for ( radius_iterator ri(you.pos(), 8); ri; ++ri )
{
- if ( mgrd(*ri) == NON_MONSTER )
+ monsters* mons = monster_at(*ri);
+ if (mons == NULL)
continue;
found_monsters = true;
// Check if audience can listen.
- if (!_recite_mons_useless( &menv[mgrd(*ri)] ) )
+ if (!_recite_mons_useless(mons))
return (1);
}
@@ -1139,13 +1140,11 @@ static void _finish_delay(const delay_queue_item &delay)
}
// Move any monsters out of the way:
- int mon = mgrd(pass);
- if (mon != NON_MONSTER)
+ if (monsters* m = monster_at(pass))
{
- monsters* m = &menv[mon];
// One square, a few squares, anywhere...
if (!shift_monster(m) && !monster_blink(m))
- monster_teleport( m, true, true );
+ monster_teleport(m, true, true);
}
move_player_to_grid(pass, false, true, true);
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index 374348e8cb..39987ff426 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -2159,10 +2159,8 @@ void get_feature_desc(const coord_def &pos, describe_info &inf)
inf.quote = getQuoteString(db_name);
}
-void describe_feature_wide(int x, int y)
+void describe_feature_wide(const coord_def& pos)
{
- const coord_def pos(x, y);
-
describe_info inf;
get_feature_desc(pos, inf);
print_description(inf);
@@ -2170,7 +2168,7 @@ void describe_feature_wide(int x, int y)
mouse_control mc(MOUSE_MODE_MORE);
if (Options.tutorial_left)
- tutorial_describe_pos(x, y);
+ tutorial_describe_pos(pos.x, pos.y);
if (getch() == 0)
getch();
diff --git a/crawl-ref/source/describe.h b/crawl-ref/source/describe.h
index 647816ab57..893fbff53c 100644
--- a/crawl-ref/source/describe.h
+++ b/crawl-ref/source/describe.h
@@ -59,11 +59,7 @@ std::string get_item_description( const item_def &item, bool verbose,
* *********************************************************************** */
void describe_god( god_type which_god, bool give_title );
-// last updated 12 Jun 2008 {jpeg}
-/* ***********************************************************************
- * called from: directn
- * *********************************************************************** */
-void describe_feature_wide(int x, int y);
+void describe_feature_wide(const coord_def& pos);
void get_feature_desc(const coord_def &gc, describe_info &inf);
// last updated 24 Dec 2008 {mpc}
diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc
index 4ba3d94528..80077397b1 100644
--- a/crawl-ref/source/directn.cc
+++ b/crawl-ref/source/directn.cc
@@ -263,10 +263,8 @@ static void draw_ray_glyph(const coord_def &pos, int colour,
#ifdef USE_TILE
tile_place_ray(pos, in_range);
#else
- int mid = mgrd(pos);
- if (mid != NON_MONSTER)
+ if (const monsters *mons = monster_at(pos))
{
- const monsters *mons = &menv[mid];
if (mons->alive() && player_monster_visible(mons))
{
glych = get_screen_glyph(pos.x, pos.y);
@@ -1057,7 +1055,7 @@ void direction(dist& moves, targeting_type restricts,
if (skip_iter)
old_target.x += 500; // hmmm...hack
- int i, mid;
+ int i;
#ifndef USE_TILE
if (key_command >= CMD_TARGET_CYCLE_MLIST
@@ -1269,11 +1267,11 @@ void direction(dist& moves, targeting_type restricts,
}
// intentional fall-through
case CMD_TARGET_SELECT: // finalize current choice
- if (!moves.isEndpoint
- && mgrd(moves.target) != NON_MONSTER
- && _mon_submerged_in_water(&menv[mgrd(moves.target)]))
+ if (!moves.isEndpoint)
{
- moves.isEndpoint = true;
+ const monsters* m = monster_at(moves.target);
+ if (m && _mon_submerged_in_water(m))
+ moves.isEndpoint = true;
}
moves.isValid = true;
moves.isTarget = true;
@@ -1282,10 +1280,8 @@ void direction(dist& moves, targeting_type restricts,
you.prev_grd_targ.reset();
// Maybe we should except just_looking here?
- mid = mgrd(moves.target);
-
- if (mid != NON_MONSTER)
- you.prev_targ = mid;
+ if (const monsters* m = monster_at(moves.target))
+ you.prev_targ = m->mindex();
else if (moves.target == you.pos())
you.prev_targ = MHITYOU;
else
@@ -1343,13 +1339,13 @@ void direction(dist& moves, targeting_type restricts,
if (!you.wizard || !in_bounds(moves.target))
break;
- mid = mgrd(moves.target);
- if (mid == NON_MONSTER) // can put in terrain description here
- break;
-
{
- monsters &m = menv[mid];
- mon_attitude_type att = m.attitude;
+ monsters* m = monster_at(moves.target);
+
+ if (m == NULL)
+ break;
+
+ mon_attitude_type att = m->attitude;
// During arena mode, skip directly from friendly to hostile.
if (crawl_state.arena_suspended && att == ATT_FRIENDLY)
@@ -1357,24 +1353,22 @@ void direction(dist& moves, targeting_type restricts,
switch (att)
{
- case ATT_FRIENDLY:
- m.attitude = ATT_GOOD_NEUTRAL;
- m.flags &= ~MF_CREATED_FRIENDLY;
- m.flags |= MF_WAS_NEUTRAL;
- break;
- case ATT_GOOD_NEUTRAL:
- m.attitude = ATT_NEUTRAL;
- break;
- case ATT_NEUTRAL:
- m.attitude = ATT_HOSTILE;
- m.flags &= ~MF_WAS_NEUTRAL;
- break;
- case ATT_HOSTILE:
- m.attitude = ATT_FRIENDLY;
- m.flags |= MF_CREATED_FRIENDLY;
- break;
- default:
- break;
+ case ATT_FRIENDLY:
+ m->attitude = ATT_GOOD_NEUTRAL;
+ m->flags &= ~MF_CREATED_FRIENDLY;
+ m->flags |= MF_WAS_NEUTRAL;
+ break;
+ case ATT_GOOD_NEUTRAL:
+ m->attitude = ATT_NEUTRAL;
+ break;
+ case ATT_NEUTRAL:
+ m->attitude = ATT_HOSTILE;
+ m->flags &= ~MF_WAS_NEUTRAL;
+ break;
+ case ATT_HOSTILE:
+ m->attitude = ATT_FRIENDLY;
+ m->flags |= MF_CREATED_FRIENDLY;
+ break;
}
// To update visual branding of friendlies. Only
@@ -1387,32 +1381,22 @@ void direction(dist& moves, targeting_type restricts,
case CMD_TARGET_WIZARD_BLESS_MONSTER:
if (!you.wizard || !in_bounds(moves.target))
break;
- mid = mgrd(moves.target);
- if (mid == NON_MONSTER) // can put in terrain description here
- break;
-
- wizard_apply_monster_blessing(&menv[mid]);
+ if (monsters* m = monster_at(moves.target))
+ wizard_apply_monster_blessing(m);
break;
case CMD_TARGET_WIZARD_MAKE_SHOUT:
- // Maybe we can skip this check...but it can't hurt
if (!you.wizard || !in_bounds(moves.target))
break;
- mid = mgrd(moves.target);
- if (mid == NON_MONSTER) // can put in terrain description here
- break;
-
- debug_make_monster_shout(&menv[mid]);
+ if (monsters* m = monster_at(moves.target))
+ debug_make_monster_shout(m);
break;
case CMD_TARGET_WIZARD_GIVE_ITEM:
if (!you.wizard || !in_bounds(moves.target))
break;
- mid = mgrd(moves.target);
- if (mid == NON_MONSTER) // can put in terrain description here
- break;
-
- wizard_give_monster_item(&menv[mid]);
+ if (monsters* m = monster_at(moves.target))
+ wizard_give_monster_item(m);
break;
case CMD_TARGET_WIZARD_MOVE:
@@ -1428,11 +1412,9 @@ void direction(dist& moves, targeting_type restricts,
case CMD_TARGET_WIZARD_PATHFIND:
if (!you.wizard || !in_bounds(moves.target))
break;
- mid = mgrd(moves.target);
- if (mid == NON_MONSTER)
- break;
- debug_pathfind(mid);
+ if (monsters* m = monster_at(moves.target))
+ debug_pathfind(m->mindex());
break;
case CMD_TARGET_WIZARD_GAIN_LEVEL:
@@ -1441,31 +1423,24 @@ void direction(dist& moves, targeting_type restricts,
case CMD_TARGET_WIZARD_MISCAST:
if (!you.wizard || !in_bounds(moves.target))
break;
- mid = mgrd(moves.target);
- if (mid == NON_MONSTER && you.pos() != moves.target)
- break;
-
- debug_miscast(mid);
+ if (you.pos() == moves.target)
+ debug_miscast(NON_MONSTER);
+ if (monsters* m = monster_at(moves.target))
+ debug_miscast(m->mindex());
break;
case CMD_TARGET_WIZARD_MAKE_SUMMONED:
if (!you.wizard || !in_bounds(moves.target))
break;
- mid = mgrd(moves.target);
- if (mid == NON_MONSTER) // can put in terrain description here
- break;
-
- wizard_make_monster_summoned(&menv[mid]);
+ if (monsters* m = monster_at(moves.target))
+ wizard_make_monster_summoned(m);
break;
case CMD_TARGET_WIZARD_POLYMORPH:
if (!you.wizard || !in_bounds(moves.target))
break;
- mid = mgrd(moves.target);
- if (mid == NON_MONSTER) // can put in terrain description here
- break;
-
- wizard_polymorph_monster(&menv[mid]);
+ if (monsters* m = monster_at(moves.target))
+ wizard_polymorph_monster(m);
break;
#endif
@@ -1629,9 +1604,9 @@ std::string get_terse_square_desc(const coord_def &gc)
else
desc = unseen_desc;
}
- else if (mgrd(gc) != NON_MONSTER && you.can_see(&menv[mgrd(gc)]))
+ else if (monster_at(gc) && you.can_see(monster_at(gc)))
{
- const monsters &mons = menv[mgrd(gc)];
+ const monsters& mons = *monster_at(gc);
if (mons_is_mimic(mons.type) && !(mons.flags & MF_KNOWN_MIMIC))
{
@@ -1663,16 +1638,16 @@ void get_square_desc(const coord_def &c, describe_info &inf)
// NOTE: Keep this function in sync with full_describe_square.
// Don't give out information for things outside LOS
- if (!see_grid(c.x, c.y))
+ if (!see_grid(c))
return;
- const int mid = mgrd(c);
+ const monsters* mons = monster_at(c);
const int oid = igrd(c);
- if (mid != NON_MONSTER && player_monster_visible(&menv[mid]))
+ if (mons && player_monster_visible(mons))
{
// First priority: monsters.
- get_monster_desc(menv[mid], inf);
+ get_monster_desc(*mons, inf);
}
else if (oid != NON_ITEM)
{
@@ -1691,16 +1666,16 @@ void full_describe_square(const coord_def &c)
// NOTE: Keep this function in sync with get_square_desc.
// Don't give out information for things outside LOS
- if (!see_grid(c.x, c.y))
+ if (!see_grid(c))
return;
- const int mid = mgrd(c);
+ const monsters* mons = monster_at(c);
const int oid = igrd(c);
- if (mid != NON_MONSTER && player_monster_visible(&menv[mid]))
+ if (mons && player_monster_visible(mons))
{
// First priority: monsters.
- describe_monsters(menv[mid]);
+ describe_monsters(*mons);
}
else if (oid != NON_ITEM)
{
@@ -1710,7 +1685,7 @@ void full_describe_square(const coord_def &c)
else
{
// Third priority: features.
- describe_feature_wide(c.x, c.y);
+ describe_feature_wide(c);
}
redraw_screen();
@@ -1782,7 +1757,7 @@ bool in_los(const coord_def& pos)
return (in_vlos(grid2view(pos)));
}
-static bool _mons_is_valid_target(monsters *mon, int mode, int range)
+static bool _mons_is_valid_target(const monsters *mon, int mode, int range)
{
// Unknown mimics don't count as monsters, either.
if (mons_is_mimic(mon->type)
@@ -1810,18 +1785,18 @@ static bool _mons_is_valid_target(monsters *mon, int mode, int range)
static bool _find_mlist( const coord_def& where, int idx, bool need_path,
int range = -1)
{
- if ((int) mlist.size() <= idx)
+ if (static_cast<int>(mlist.size()) <= idx)
return (false);
if (!_is_target_in_range(where, range) || !in_los(where))
return (false);
- const int targ_mon = mgrd(where);
- if (targ_mon == NON_MONSTER)
+ const monsters* mon = monster_at(where);
+ if (mon == NULL)
return (false);
int real_idx = 0;
- for (unsigned int i = 0; i < mlist.size()-1; i++)
+ for (unsigned int i = 0; i+1 < mlist.size(); i++)
{
if (real_idx == idx)
{
@@ -1836,8 +1811,6 @@ static bool _find_mlist( const coord_def& where, int idx, bool need_path,
real_idx++;
}
- monsters *mon = &menv[targ_mon];
-
if (!_mons_is_valid_target(mon, TARG_ANY, range))
return (false);
@@ -1878,18 +1851,16 @@ static bool _find_monster( const coord_def& where, int mode, bool need_path,
if (!_is_target_in_range(where, range))
return (false);
- const int targ_mon = mgrd(where);
+ const monsters* mon = monster_at(where);
// No monster or outside LOS.
- if (targ_mon == NON_MONSTER || !in_los(where))
+ if (mon == NULL || !in_los(where))
return (false);
// Monster in LOS but only via glass walls, so no direct path.
if (need_path && !see_grid_no_trans(where))
return (false);
- monsters *mon = &menv[targ_mon];
-
if (!_mons_is_valid_target(mon, mode, range))
return (false);
@@ -1898,15 +1869,15 @@ static bool _find_monster( const coord_def& where, int mode, bool need_path,
return (true);
if (mode == TARG_FRIEND)
- return (mons_friendly(&menv[targ_mon] ));
+ return (mons_friendly(mon));
ASSERT(mode == TARG_ENEMY);
- if (mons_friendly(&menv[targ_mon]))
+ if (mons_friendly(mon))
return (false);
// Don't target zero xp monsters, unless target_zero_exp is set.
return (Options.target_zero_exp
- || !mons_class_flag( menv[targ_mon].type, M_NO_EXP_GAIN ));
+ || !mons_class_flag(mon->type, M_NO_EXP_GAIN));
}
static bool _find_feature( const coord_def& where, int mode,
@@ -1924,11 +1895,11 @@ static bool _find_object(const coord_def& where, int mode,
{
// First, check for mimics.
bool is_mimic = false;
- const int mons = mgrd(where);
- if (mons != NON_MONSTER
- && player_monster_visible( &(menv[mons]) )
- && mons_is_mimic(menv[mons].type)
- && !(menv[mons].flags & MF_KNOWN_MIMIC))
+ const monsters* m = monster_at(where);
+ if (m
+ && player_monster_visible(m)
+ && mons_is_mimic(m->type)
+ && !(m->flags & MF_KNOWN_MIMIC))
{
is_mimic = true;
}
@@ -3124,10 +3095,8 @@ static void _describe_cell(const coord_def& where, bool in_range)
if (where == you.pos() && !crawl_state.arena_suspended)
mpr("You.", MSGCH_EXAMINE_FILTER);
- if (mgrd(where) != NON_MONSTER)
+ if (const monsters* mon = monster_at(where))
{
- const monsters* mon = &menv[mgrd(where)];
-
if (_mon_submerged_in_water(mon))
{
mpr("There is a strange disturbance in the water here.",
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 300a5a8ded..b5766f12e1 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -122,13 +122,10 @@ int holy_word_monsters(coord_def where, int pow, int caster,
retval = holy_word_player(pow, caster, attacker);
// Is a monster in this cell?
- const int mon = mgrd(where);
-
- if (mon == NON_MONSTER)
+ monsters *monster = monster_at(where);
+ if (monster == NULL)
return (retval);
- monsters *monster = &menv[mon];
-
if (!monster->alive() || !mons_is_unholy(monster))
return (retval);
@@ -265,13 +262,10 @@ int torment_monsters(coord_def where, int pow, int caster, actor *attacker)
retval = torment_player(0, caster);
// Is a monster in this cell?
- const int mon = mgrd(where);
-
- if (mon == NON_MONSTER)
+ monsters *monster = monster_at(where);
+ if (monster == NULL)
return (retval);
- monsters *monster = &menv[mon];
-
if (!monster->alive() || mons_res_negative_energy(monster) == 3)
return (retval);
@@ -2231,7 +2225,7 @@ void yell(bool force)
}
mpr("Gang up on whom?", MSGCH_PROMPT);
- direction( targ, DIR_TARGET, TARG_ENEMY, -1, false, false );
+ direction(targ, DIR_TARGET, TARG_ENEMY, -1, false, false);
if (targ.isCancel)
{
@@ -2239,14 +2233,22 @@ void yell(bool force)
return;
}
- if (!targ.isValid || mgrd(targ.target) == NON_MONSTER
- || !player_monster_visible(&env.mons[mgrd(targ.target)]))
{
- mpr("Yeah, whatever.");
- return;
- }
+ bool cancel = !targ.isValid;
+ if (!cancel)
+ {
+ const monsters* m = monster_at(targ.target);
+ cancel = (m == NULL || !you.can_see(m));
+ if (!cancel)
+ mons_targd = m->mindex();
+ }
- mons_targd = mgrd(targ.target);
+ if (cancel)
+ {
+ mpr("Yeah, whatever.");
+ return;
+ }
+ }
break;
default:
@@ -2795,7 +2797,7 @@ void change_labyrinth(bool msg)
continue;
// We don't want to deal with monsters being shifted around.
- if (mgrd(p) != NON_MONSTER)
+ if (monster_at(p))
continue;
// Do not pick a grid right next to the original wall.
@@ -3555,7 +3557,7 @@ static void _catchup_monster_moves(monsters *mon, int turns)
const coord_def next(pos + inc);
const dungeon_feature_type feat = grd(next);
if (grid_is_solid(feat)
- || mgrd(next) != NON_MONSTER
+ || monster_at(next)
|| !monster_habitable_grid(mon, feat))
{
break;
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index ae58bc66d8..10833e6141 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -962,11 +962,10 @@ static void _grab_followers()
// Handle nearby ghosts.
for (adjacent_iterator ai; ai; ++ai)
{
- if (mgrd(*ai) == NON_MONSTER)
+ monsters *fmenv = monster_at(*ai);
+ if (fmenv == NULL)
continue;
- monsters *fmenv = &menv[mgrd(*ai)];
-
if (fmenv->type == MONS_PLAYER_GHOST
&& fmenv->hit_points < fmenv->max_hit_points / 2)
{
diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc
index 460059ad27..21e50531bc 100644
--- a/crawl-ref/source/it_use3.cc
+++ b/crawl-ref/source/it_use3.cc
@@ -268,6 +268,7 @@ static bool _reaching_weapon_attack(const item_def& wpn)
const coord_def delta = beam.target - you.pos();
const int x_distance = abs(delta.x);
const int y_distance = abs(delta.y);
+ monsters* mons = monster_at(beam.target);
if (x_distance > 2 || y_distance > 2)
{
@@ -279,12 +280,10 @@ static bool _reaching_weapon_attack(const item_def& wpn)
mpr("There's a wall in the way.");
return (false);
}
- else if (mgrd(beam.target) == NON_MONSTER)
+ else if (mons == NULL)
{
// Must return true, otherwise you get a free discovery
- // of invisible monsters. Maybe we shouldn't do practice
- // here to prevent scumming...but that would just encourage
- // finding popcorn monsters.
+ // of invisible monsters.
mpr("You attack empty space.");
return (true);
}
@@ -310,7 +309,7 @@ static bool _reaching_weapon_attack(const item_def& wpn)
if (x_chance_in_y(5 + (3 * skill), 40))
{
mpr("You reach to attack!");
- success = you_attack(mgrd(beam.target), false);
+ success = you_attack(mons->mindex(), false);
}
else
{
@@ -321,22 +320,19 @@ static bool _reaching_weapon_attack(const item_def& wpn)
else
{
mpr("You reach to attack!");
- success = you_attack(mgrd(beam.target), false);
+ success = you_attack(mons->mindex(), false);
}
if (success)
{
- int mid = mgrd(beam.target);
- if (mid != NON_MONSTER)
- {
- monsters *mon = &menv[mgrd(beam.target)];
- if (mons_is_mimic( mon->type ))
- mimic_alert(mon);
- }
+ // Monster might have died or gone away.
+ if (monsters* m = monster_at(beam.target))
+ if (mons_is_mimic(m->type))
+ mimic_alert(m);
}
}
else
- you_attack(mgrd(beam.target), false);
+ you_attack(mons->mindex(), false);
return (true);
}
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index e419a646fc..a3c77d2036 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -2669,10 +2669,8 @@ std::vector<monsters*> get_nearby_monsters(bool want_move,
// Sweep every visible square within range.
for (radius_iterator ri(you.pos(), range); ri; ++ri)
{
- const unsigned short targ_monst = env.mgrid(*ri);
- if (targ_monst != NON_MONSTER)
+ if (monsters* mon = monster_at(*ri))
{
- monsters *mon = &menv[targ_monst];
if (mon->alive()
&& (!require_visible || player_monster_visible(mon))
&& !mons_is_submerged(mon)
@@ -2682,7 +2680,7 @@ std::vector<monsters*> get_nearby_monsters(bool want_move,
{
mons.push_back(mon);
if (just_check) // stop once you find one
- return mons;
+ break;
}
}
}
@@ -2908,23 +2906,12 @@ coord_def pick_adjacent_free_square(const coord_def& p)
{
int num_ok = 0;
coord_def result(-1, -1);
- for ( int ux = p.x-1; ux <= p.x+1; ++ux )
- {
- for ( int uy = p.y-1; uy <= p.y+1; ++uy )
- {
- if ( ux == p.x && uy == p.y )
- continue;
- if ( in_bounds(ux, uy)
- && grd[ux][uy] == DNGN_FLOOR
- && mgrd[ux][uy] == NON_MONSTER )
- {
- ++num_ok;
- if ( one_chance_in(num_ok) )
- result.set(ux, uy);
- }
- }
- }
+ for (adjacent_iterator ai(p); ai; ++ai)
+ if (grd(*ai) == DNGN_FLOOR && monster_at(*ai) == NULL)
+ if (one_chance_in(++num_ok))
+ result = *ai;
+
return result;
}
diff --git a/crawl-ref/source/mtransit.cc b/crawl-ref/source/mtransit.cc
index 14f37c4d66..9d99782177 100644
--- a/crawl-ref/source/mtransit.cc
+++ b/crawl-ref/source/mtransit.cc
@@ -270,7 +270,7 @@ bool follower::place(bool near_player)
near_player = true;
else
{
- mgrd[where_to_go.x][where_to_go.y] = monster_index(&m);
+ mgrd(where_to_go) = m.mindex();
placed = true;
}
}
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 71836b9561..8987d02123 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -5354,11 +5354,10 @@ static bool _yred_slaves_abandon_you()
{
for (radius_iterator ri(you.pos(), 9); ri; ++ri)
{
- if (mgrd(*ri) == NON_MONSTER)
+ monsters *monster = monster_at(*ri);
+ if (monster == NULL)
continue;
- monsters *monster = &menv[mgrd(*ri)];
-
if (_is_yred_enslaved_body_and_soul(monster)
|| is_yred_undead_slave(monster))
{
@@ -5432,11 +5431,10 @@ static bool _beogh_followers_abandon_you()
{
for (radius_iterator ri(you.pos(), 9); ri; ++ri)
{
- if (mgrd(*ri) == NON_MONSTER)
+ monsters *monster = monster_at(*ri);
+ if (monster == NULL)
continue;
- monsters *monster = &menv[mgrd(*ri)];
-
if (is_orcish_follower(monster))
{
num_followers++;
diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc
index a520d86637..c807b6445c 100644
--- a/crawl-ref/source/spells1.cc
+++ b/crawl-ref/source/spells1.cc
@@ -162,8 +162,7 @@ int blink(int pow, bool high_level_controlled_blink, bool wizard_blink)
if (wizard_blink && grid_is_solid(grd(beam.target)))
grd(beam.target) = DNGN_FLOOR;
- if (grid_is_solid(grd(beam.target))
- || mgrd(beam.target) != NON_MONSTER)
+ if (grid_is_solid(grd(beam.target)) || monster_at(beam.target))
{
mpr("Oops! Maybe something was there already.");
random_blink(false);
@@ -532,9 +531,9 @@ bool conjure_flame(int pow)
const int cloud = env.cgrid(spelld.target);
- if (grid_is_solid(grd(spelld.target)) ||
- mgrd(spelld.target) != NON_MONSTER ||
- (cloud != EMPTY_CLOUD && env.cloud[cloud].type != CLOUD_FIRE))
+ if (grid_is_solid(grd(spelld.target))
+ || monster_at(spelld.target)
+ || (cloud != EMPTY_CLOUD && env.cloud[cloud].type != CLOUD_FIRE))
{
mpr( "There's already something there!" );
continue;
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index 508a83cb94..7188bc8bf4 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -198,9 +198,8 @@ int detect_creatures( int pow, bool telepathic )
for (radius_iterator ri(you.pos(), map_radius, true, false); ri; ++ri)
{
- if (mgrd(*ri) != NON_MONSTER)
+ if (monsters *mon = monster_at(*ri))
{
- monsters *mon = &menv[ mgrd(*ri) ];
creatures_found++;
_mark_detected_creature(*ri, mon, fuzz_chance, fuzz_radius);
@@ -758,16 +757,14 @@ void drain_life(int pow)
bool vampiric_drain(int pow, const dist &vmove)
{
- int mgr = mgrd(you.pos() + vmove.delta);
+ monsters *monster = monster_at(you.pos() + vmove.delta);
- if (mgr == NON_MONSTER)
+ if (monster == NULL)
{
mpr("There isn't anything there!");
return (false);
}
- monsters *monster = &menv[mgr];
-
god_conduct_trigger conducts[3];
disable_attack_conducts(conducts);
@@ -1350,9 +1347,9 @@ bool cast_summon_elemental(int pow, god_type god,
targ = you.pos() + smove.delta;
- if (mgrd(targ) != NON_MONSTER)
+ if (const monsters *m = monster_at(targ))
{
- if (player_monster_visible(&menv[mgrd(targ)]))
+ if (you.can_see(m))
mpr("There's something there already!");
else
{
diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc
index ce60981602..145d90aa63 100644
--- a/crawl-ref/source/spells3.cc
+++ b/crawl-ref/source/spells3.cc
@@ -186,7 +186,9 @@ bool detect_curse(bool suppress_msg)
bool cast_smiting(int power, const coord_def& where)
{
- if (invalid_monster_index(mgrd(where)))
+ monsters *m = monster_at(where);
+
+ if (m == NULL)
{
mpr("There's nothing there!");
// Counts as a real cast, due to victory-dancing and
@@ -194,22 +196,20 @@ bool cast_smiting(int power, const coord_def& where)
return (true);
}
- monsters& m = menv[mgrd(where)];
-
god_conduct_trigger conducts[3];
disable_attack_conducts(conducts);
- const bool success = !stop_attack_prompt(&m, false, false);
+ const bool success = !stop_attack_prompt(m, false, false);
if (success)
{
- set_attack_conducts(conducts, &m);
+ set_attack_conducts(conducts, m);
- mprf("You smite %s!", m.name(DESC_NOCAP_THE).c_str());
+ mprf("You smite %s!", m->name(DESC_NOCAP_THE).c_str());
- behaviour_event(&m, ME_ANNOY, MHITYOU);
- if (mons_is_mimic(m.type))
- mimic_alert(&m);
+ behaviour_event(m, ME_ANNOY, MHITYOU);
+ if (mons_is_mimic(m->type))
+ mimic_alert(m);
}
enable_attack_conducts(conducts);
@@ -219,9 +219,9 @@ bool cast_smiting(int power, const coord_def& where)
// Maxes out at around 40 damage at 27 Invocations, which is
// plenty in my book (the old max damage was around 70,
// which seems excessive).
- m.hurt(&you, 7 + (random2(power) * 33 / 191));
- if (m.alive())
- print_wounds(&m);
+ m->hurt(&you, 7 + (random2(power) * 33 / 191));
+ if (m->alive())
+ print_wounds(m);
}
return (success);
@@ -231,12 +231,12 @@ int airstrike(int power, dist &beam)
{
bool success = false;
- if (mgrd(beam.target) == NON_MONSTER || beam.isMe)
+ monsters *monster = monster_at(beam.target);
+
+ if (monster == NULL)
canned_msg(MSG_SPELL_FIZZLES);
else
{
- monsters *monster = &menv[mgrd(beam.target)];
-
god_conduct_trigger conducts[3];
disable_attack_conducts(conducts);
@@ -1330,7 +1330,7 @@ static bool _teleport_player( bool allow_control, bool new_abyss_area )
if (grd(you.pos()) != DNGN_FLOOR
&& grd(you.pos()) != DNGN_SHALLOW_WATER
- || mgrd(you.pos()) != NON_MONSTER
+ || monster_at(you.pos())
|| env.cgrid(you.pos()) != EMPTY_CLOUD)
{
is_controlled = false;
@@ -1382,7 +1382,7 @@ static bool _teleport_player( bool allow_control, bool new_abyss_area )
}
while (grd(newpos) != DNGN_FLOOR
&& grd(newpos) != DNGN_SHALLOW_WATER
- || mgrd(newpos) != NON_MONSTER
+ || monster_at(newpos)
|| env.cgrid(newpos) != EMPTY_CLOUD
|| need_distance_check && (newpos - centre).abs() < 34*34);
@@ -1444,7 +1444,7 @@ bool entomb(int powc)
for ( adjacent_iterator ai; ai; ++ai )
{
// Tile already occupied by monster
- if (mgrd(*ai) != NON_MONSTER)
+ if (monster_at(*ai))
continue;
// This is where power comes in.
@@ -1703,11 +1703,8 @@ bool cast_sanctuary(const int power)
// scare all attacking monsters inside sanctuary, and make
// all friendly monsters inside sanctuary stop attacking and
// move towards the player.
- int monster = mgrd(pos);
- if (monster != NON_MONSTER)
+ if (monsters* mon = monster_at(pos))
{
- monsters* mon = &menv[monster];
-
if (mons_friendly(mon))
{
mon->foe = MHITYOU;
diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc
index ef1c31ffb9..5d18ebabb0 100644
--- a/crawl-ref/source/spells4.cc
+++ b/crawl-ref/source/spells4.cc
@@ -393,33 +393,30 @@ void cast_detect_secret_doors(int pow)
static int _sleep_monsters(coord_def where, int pow, int, actor *)
{
- const int mnstr = mgrd(where);
-
- if (mnstr == NON_MONSTER)
- return 0;
-
- monsters& mon = menv[mnstr];
+ monsters *monster = monster_at(where);
+ if (monster == NULL)
+ return (0);
- if (mons_holiness(&mon) != MH_NATURAL)
- return 0;
- if (check_mons_resist_magic( &mon, pow ))
- return 0;
+ if (mons_holiness(monster) != MH_NATURAL)
+ return (0);
+ if (check_mons_resist_magic(monster, pow))
+ return (0);
// Works on friendlies too, so no check for that.
//jmf: Now that sleep == hibernation:
- const int res = mons_res_cold( &mon );
+ const int res = mons_res_cold(monster);
if (res > 0 && one_chance_in(std::max(4 - res, 1)))
- return 0;
- if (mon.has_ench(ENCH_SLEEP_WARY) && !one_chance_in(3))
- return 0;
+ return (0);
+ if (monster->has_ench(ENCH_SLEEP_WARY) && !one_chance_in(3))
+ return (0);
- mon.put_to_sleep();
+ monster->put_to_sleep();
- if (mons_class_flag( mon.type, M_COLD_BLOOD ) && coinflip())
- mon.add_ench(ENCH_SLOW);
+ if (mons_class_flag( monster->type, M_COLD_BLOOD ) && coinflip())
+ monster->add_ench(ENCH_SLOW);
- return 1;
+ return (1);
}
void cast_mass_sleep(int pow)
@@ -451,13 +448,10 @@ static bool _is_domesticated_animal(int type)
static int _tame_beast_monsters(coord_def where, int pow, int, actor *)
{
- const int which_mons = mgrd(where);
-
- if (which_mons == NON_MONSTER)
+ monsters *monster = monster_at(where);
+ if (monster == NULL)
return 0;
- monsters *monster = &menv[which_mons];
-
if (!_is_domesticated_animal(monster->type) || mons_friendly(monster)
|| player_will_anger_monster(monster))
{
@@ -561,14 +555,12 @@ static int _ignite_poison_monsters(coord_def where, int pow, int, actor *)
bolt beam;
beam.flavour = BEAM_FIRE; // This is dumb, only used for adjust!
- dice_def dam_dice( 0, 5 + pow / 7 ); // Dice added below if applicable.
+ dice_def dam_dice(0, 5 + pow/7); // Dice added below if applicable.
- const int mon_index = mgrd(where);
- if (mon_index == NON_MONSTER)
+ monsters *mon = monster_at(where);
+ if (mon == NULL)
return (0);
- struct monsters *const mon = &menv[ mon_index ];
-
// Monsters which have poison corpses or poisonous attacks.
if (mons_is_poisoner(mon))
dam_dice.num = 3;
@@ -595,7 +587,7 @@ static int _ignite_poison_monsters(coord_def where, int pow, int, actor *)
dam_dice.num, dam_dice.size, damage );
#endif
- if (!_player_hurt_monster( mon_index, damage ))
+ if (!_player_hurt_monster(mon->mindex(), damage))
{
// Monster survived, remove any poison.
mon->del_ench(ENCH_POISON);
@@ -776,7 +768,7 @@ void cast_silence(int pow)
static int _discharge_monsters(coord_def where, int pow, int, actor *)
{
- const int mon = mgrd(where);
+ monsters *monster = monster_at(where);
int damage = 0;
bolt beam;
@@ -791,20 +783,20 @@ static int _discharge_monsters(coord_def where, int pow, int, actor *)
damage /= 2;
ouch(damage, NON_MONSTER, KILLED_BY_WILD_MAGIC);
}
- else if (mon == NON_MONSTER)
+ else if (monster == NULL)
return (0);
- else if (mons_res_elec(&menv[mon]) > 0 || mons_flies(&menv[mon]))
+ else if (mons_res_elec(monster) > 0 || mons_flies(monster))
return (0);
else
{
- damage = 3 + random2( 5 + pow / 10 );
- damage = mons_adjust_flavoured( &menv[mon], beam, damage );
+ damage = 3 + random2(5 + pow/10);
+ damage = mons_adjust_flavoured(monster, beam, damage );
if (damage)
{
mprf("%s is struck by lightning.",
- menv[mon].name(DESC_CAP_THE).c_str());
- _player_hurt_monster(mon, damage);
+ monster->name(DESC_CAP_THE).c_str());
+ _player_hurt_monster(*monster, damage);
}
}
@@ -880,13 +872,11 @@ static int _distortion_monsters(coord_def where, int pow, int, actor *)
return (1);
}
- int monster_attacked = mgrd(where);
-
- if (monster_attacked == NON_MONSTER)
- return 0;
+ monsters *defender = monster_at(where);
+ if (defender == NULL)
+ return (0);
int specdam = 0;
- monsters *defender = &menv[monster_attacked];
if (defender->type == MONS_BLINK_FROG
|| defender->type == MONS_PRINCE_RIBBIT) // any others resist?
@@ -938,7 +928,7 @@ static int _distortion_monsters(coord_def where, int pow, int, actor *)
return 1;
}
- _player_hurt_monster(monster_attacked, specdam);
+ _player_hurt_monster(*defender, specdam);
return (specdam);
}
@@ -953,13 +943,10 @@ void cast_bend(int pow)
// the insane damage potential. -- bwr
int disperse_monsters(coord_def where, int pow, int, actor *)
{
- const int monster_attacked = mgrd(where);
-
- if (monster_attacked == NON_MONSTER)
+ monsters *defender = monster_at(where);
+ if (defender == NULL)
return 0;
- monsters *defender = &menv[monster_attacked];
-
if (defender->type == MONS_BLINK_FROG
|| defender->type == MONS_PRINCE_RIBBIT)
{
@@ -996,12 +983,9 @@ void cast_dispersal(int pow)
static int _spell_swap_func(coord_def where, int pow, int, actor *)
{
- int monster_attacked = mgrd(where);
-
- if (monster_attacked == NON_MONSTER)
- return 0;
-
- monsters *defender = &menv[monster_attacked];
+ monsters *defender = monster_at(where);
+ if (defender == NULL)
+ return (0);
if (defender->type == MONS_BLINK_FROG
|| defender->type == MONS_PRINCE_RIBBIT
@@ -1158,17 +1142,16 @@ static int _intoxicate_monsters(coord_def where, int pow, int, actor *)
{
UNUSED( pow );
- int mon = mgrd(where);
-
- if (mon == NON_MONSTER
- || mons_intel(&menv[mon]) < I_NORMAL
- || mons_holiness(&menv[mon]) != MH_NATURAL
- || mons_res_poison(&menv[mon]) > 0)
+ monsters *monster = monster_at(where);
+ if (monster == NULL
+ || mons_intel(monster) < I_NORMAL
+ || mons_holiness(monster) != MH_NATURAL
+ || mons_res_poison(monster) > 0)
{
return 0;
}
- menv[mon].add_ench(mon_enchant(ENCH_CONFUSION, 0, KC_YOU));
+ monster->add_ench(mon_enchant(ENCH_CONFUSION, 0, KC_YOU));
return 1;
}
@@ -1191,38 +1174,37 @@ bool backlight_monsters(coord_def where, int pow, int garbage)
UNUSED( pow );
UNUSED( garbage );
- int mon = mgrd(where);
-
- if (mon == NON_MONSTER)
+ monsters *monster = monster_at(where);
+ if (monster == NULL)
return (false);
// Already glowing.
- if (mons_class_flag(menv[mon].type, M_GLOWS))
+ if (mons_class_flag(monster->type, M_GLOWS))
return (false);
- mon_enchant bklt = menv[mon].get_ench(ENCH_BACKLIGHT);
+ mon_enchant bklt = monster->get_ench(ENCH_BACKLIGHT);
const int lvl = bklt.degree;
// This enchantment overrides invisibility (neat).
- if (menv[mon].has_ench(ENCH_INVIS))
+ if (monster->has_ench(ENCH_INVIS))
{
- if (!menv[mon].has_ench(ENCH_BACKLIGHT))
+ if (!monster->has_ench(ENCH_BACKLIGHT))
{
- menv[mon].add_ench(
+ monster->add_ench(
mon_enchant(ENCH_BACKLIGHT, 1, KC_OTHER, random_range(30, 50)));
- simple_monster_message( &menv[mon], " is lined in light." );
+ simple_monster_message(monster, " is lined in light.");
}
return (true);
}
- menv[mon].add_ench(mon_enchant(ENCH_BACKLIGHT, 1));
+ monster->add_ench(mon_enchant(ENCH_BACKLIGHT, 1));
if (lvl == 0)
- simple_monster_message( &menv[mon], " is outlined in light." );
+ simple_monster_message(monster, " is outlined in light.");
else if (lvl == 4)
- simple_monster_message( &menv[mon], " glows brighter for a moment." );
+ simple_monster_message(monster, " glows brighter for a moment.");
else
- simple_monster_message( &menv[mon], " glows brighter." );
+ simple_monster_message(monster, " glows brighter.");
return (true);
}
@@ -1524,39 +1506,36 @@ void cast_fulsome_distillation( int powc )
static int _rot_living(coord_def where, int pow, int, actor *)
{
- const int mon = mgrd(where);
- int ench;
-
- if (mon == NON_MONSTER)
- return 0;
+ monsters *monster = monster_at(where);
+ if (monster == NULL)
+ return (0);
- if (mons_holiness(&menv[mon]) != MH_NATURAL)
- return 0;
+ if (mons_holiness(monster) != MH_NATURAL)
+ return (0);
- if (check_mons_resist_magic(&menv[mon], pow))
- return 0;
+ if (check_mons_resist_magic(monster, pow))
+ return (0);
- ench = ((random2(pow) + random2(pow) + random2(pow) + random2(pow)) / 4);
+ int ench = ((random2(pow) + random2(pow) + random2(pow) + random2(pow))/4);
ench = 1 + (ench >= 20) + (ench >= 35) + (ench >= 50);
- menv[mon].add_ench( mon_enchant(ENCH_ROT, ench, KC_YOU) );
+ monster->add_ench(mon_enchant(ENCH_ROT, ench, KC_YOU));
- return 1;
+ return (1);
}
static int _rot_undead(coord_def where, int pow, int, actor *)
{
- const int mon = mgrd(where);
- int ench;
+ monsters *monster = monster_at(where);
- if (mon == NON_MONSTER)
- return 0;
+ if (monster == NULL)
+ return (0);
- if (mons_holiness(&menv[mon]) != MH_UNDEAD)
- return 0;
+ if (mons_holiness(monster) != MH_UNDEAD)
+ return (0);
- if (check_mons_resist_magic(&menv[mon], pow))
- return 0;
+ if (check_mons_resist_magic(monster, pow))
+ return (0);
// This does not make sense -- player mummies are
// immune to rotting (or have been) -- so what is
@@ -1569,7 +1548,7 @@ static int _rot_undead(coord_def where, int pow, int, actor *)
// insist that monsters get the same treatment as
// players, I demand my player mummies get to worship
// the evil mummy & orc gods.
- switch (menv[mon].type)
+ switch (monster->type)
{
case MONS_ZOMBIE_SMALL:
case MONS_ZOMBIE_LARGE:
@@ -1592,12 +1571,12 @@ static int _rot_undead(coord_def where, int pow, int, actor *)
return 0; // Immune (no flesh) or already rotting.
}
- ench = ((random2(pow) + random2(pow) + random2(pow) + random2(pow)) / 4);
+ int ench = ((random2(pow) + random2(pow) + random2(pow) + random2(pow))/4);
ench = 1 + (ench >= 20) + (ench >= 35) + (ench >= 50);
- menv[mon].add_ench( mon_enchant(ENCH_ROT, ench, KC_YOU) );
+ monster->add_ench(mon_enchant(ENCH_ROT, ench, KC_YOU));
- return 1;
+ return (1);
}
static int _rot_corpses(coord_def where, int pow, int, actor *)
@@ -1624,24 +1603,23 @@ void do_monster_rot(int mon)
}
_player_hurt_monster( mon, damage );
- return;
}
static int _snake_charm_monsters(coord_def where, int pow, int, actor *)
{
- const int mon = mgrd(where);
+ monsters* monster = monster_at(where);
- if (mon == NON_MONSTER
+ if (monster == NULL
|| one_chance_in(4)
- || mons_friendly(&menv[mon])
- || mons_char(menv[mon].type) != 'S'
- || check_mons_resist_magic(&menv[mon], pow))
+ || mons_friendly(monster)
+ || mons_char(monster->type) != 'S'
+ || check_mons_resist_magic(monster, pow))
{
return 0;
}
- menv[mon].attitude = ATT_FRIENDLY;
- mprf("%s sways back and forth.", menv[mon].name(DESC_CAP_THE).c_str());
+ monster->attitude = ATT_FRIENDLY;
+ mprf("%s sways back and forth.", monster->name(DESC_CAP_THE).c_str());
return 1;
}
@@ -2009,8 +1987,10 @@ bool cast_fragmentation(int pow, const dist& spd)
bool cast_twist(int pow, const coord_def& where)
{
+ monsters *monster = monster_at(where);
+
// Anything there?
- if (invalid_monster_index(mgrd(where)))
+ if (monster == NULL)
{
mpr("There is no monster there!");
// This counts as a real cast, in order not to leak invisible
@@ -2018,16 +1998,14 @@ bool cast_twist(int pow, const coord_def& where)
return (true);
}
- monsters& m = menv[mgrd(where)];
-
// Identify mimics, if necessary.
- if (mons_is_mimic(m.type))
- m.flags |= MF_KNOWN_MIMIC;
+ if (mons_is_mimic(monster->type))
+ monster->flags |= MF_KNOWN_MIMIC;
// Monster can magically save vs attack.
- if (check_mons_resist_magic(&m, pow * 2))
+ if (check_mons_resist_magic(monster, pow * 2))
{
- simple_monster_message(&m, mons_resist_string(&m));
+ simple_monster_message(monster, mons_resist_string(monster));
return (true);
}
@@ -2038,10 +2016,9 @@ bool cast_twist(int pow, const coord_def& where)
const int damage = 1 + random2(3 + pow / 5);
// Inflict the damage.
- _player_hurt_monster(m, damage);
-
- if (mons_is_mimic(m.type))
- mimic_alert(&m);
+ if (!_player_hurt_monster(*monster, damage))
+ if (mons_is_mimic(monster->type))
+ mimic_alert(monster);
return (true);
}
@@ -2100,7 +2077,7 @@ void cast_far_strike(int pow)
return;
// Get the target monster...
- if (mgrd(targ.target) == NON_MONSTER || targ.isMe)
+ if (monster_at(targ.target) == NULL)
{
mpr("There is no monster there!");
return;
@@ -2173,8 +2150,7 @@ void cast_far_strike(int pow)
damage *= dammod;
damage /= 78;
- const int midx = mgrd(targ.target);
- monsters *monster = &menv[midx];
+ monsters *monster = monster_at(targ.target);
// Apply monster's AC.
if (monster->ac > 0)
@@ -2193,7 +2169,7 @@ void cast_far_strike(int pow)
}
// Inflict the damage.
- _player_hurt_monster(midx, damage);
+ _player_hurt_monster(*monster, damage);
}
bool cast_apportation(int pow, const coord_def& where)
@@ -2216,15 +2192,13 @@ bool cast_apportation(int pow, const coord_def& where)
if (item_idx == NON_ITEM)
{
// Maybe the player *thought* there was something there (a mimic.)
- const int mon = mgrd(where);
- if (!invalid_monster_index(mon))
+ if (monsters* m = monster_at(where))
{
- monsters& m = menv[mon];
- if (mons_is_mimic(m.type) && you.can_see(&m))
+ if (mons_is_mimic(m->type) && you.can_see(m))
{
- mprf("%s twitches.", m.name(DESC_CAP_THE).c_str());
+ mprf("%s twitches.", m->name(DESC_CAP_THE).c_str());
// Nothing else gives this message, so identify the mimic.
- m.flags |= MF_KNOWN_MIMIC;
+ m->flags |= MF_KNOWN_MIMIC;
return (true); // otherwise you get free mimic ID
}
}
@@ -2267,10 +2241,8 @@ bool cast_apportation(int pow, const coord_def& where)
&& item_is_stationary(item))
{
remove_item_stationary(item);
-
- const int mon = mgrd(where);
- if (!invalid_monster_index(mon))
- menv[mon].del_ench(ENCH_HELD, true);
+ if (monsters *monster = monster_at(where))
+ monster->del_ench(ENCH_HELD, true);
}
// Actually move the item.
diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc
index 9886c334fa..4f892d6f4e 100644
--- a/crawl-ref/source/spl-util.cc
+++ b/crawl-ref/source/spl-util.cc
@@ -529,7 +529,7 @@ int apply_random_around_square(cell_func cf, const coord_def& where,
for (adjacent_iterator ai(where, exclude_center); ai; ++ai)
{
- if (mgrd(*ai) == NON_MONSTER && *ai != you.pos())
+ if (monster_at(*ai) == NULL && *ai != you.pos())
continue;
// Found target
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index b4a86f9614..22726b562f 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -343,11 +343,10 @@ static bool _tag_follower_at(const coord_def &pos)
if (!in_bounds(pos) || pos == you.pos())
return (false);
- if (mgrd(pos) == NON_MONSTER)
+ monsters *fmenv = monster_at(pos);
+ if (fmenv == NULL)
return (false);
- monsters *fmenv = &menv[mgrd(pos)];
-
if (fmenv->type == MONS_PLAYER_GHOST
|| !fmenv->alive()
|| fmenv->incapacitated()
@@ -1657,8 +1656,6 @@ void zap_los_monsters()
if (g == you.pos())
continue;
- int imon = mgrd(g);
-
// At tutorial beginning disallow items in line of sight.
if (Options.tutorial_events[TUT_SEEN_FIRST_OBJECT])
{
@@ -1668,12 +1665,11 @@ void zap_los_monsters()
destroy_item(item);
}
- if (imon == NON_MONSTER || imon == MHITYOU)
- continue;
-
// If we ever allow starting with a friendly monster,
// we'll have to check here.
- monsters *mon = &menv[imon];
+ monsters *mon = monster_at(g);
+ if (mon == NULL)
+ continue;
if (mons_class_flag( mon->type, M_NO_EXP_GAIN ))
continue;
diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc
index caba8bb6ce..584e6c5e63 100644
--- a/crawl-ref/source/travel.cc
+++ b/crawl-ref/source/travel.cc
@@ -844,14 +844,12 @@ inline static void _check_interesting_square(int x, int y,
if (ES_item || ES_greedy || ES_glow || ES_art || ES_rune)
{
- if (mgrd(pos) != NON_MONSTER)
+ if (const monsters *mons = monster_at(pos))
{
- const monsters *mons = &menv[ mgrd(pos) ];
if (mons_is_mimic(mons->type) && !mons_is_known_mimic(mons))
{
item_def item;
get_mimic_item(mons, item);
-
ed.found_item(pos, item);
}
}
@@ -1416,10 +1414,8 @@ static bool _is_greed_inducing_square(const LevelStashes *ls,
if (ls && ls->needs_visit(c.x, c.y))
return (true);
- const int m_ind = mgrd(c);
- if (m_ind != NON_MONSTER)
+ if (const monsters *mons = monster_at(c))
{
- const monsters *mons = &menv[ m_ind ];
if (mons_is_mimic(mons->type)
&& mons_was_seen(mons)
&& !mons_is_known_mimic(mons))
@@ -4028,7 +4024,7 @@ bool runrest::run_grids_changed() const
if (env.cgrid(you.pos() + pos) != EMPTY_CLOUD)
return (true);
- if (mgrd(you.pos() + pos) != NON_MONSTER)
+ if (monster_at(you.pos() + pos))
return (true);
for (int i = 0; i < 3; i++)
diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc
index d12e781346..027635cae1 100644
--- a/crawl-ref/source/tutorial.cc
+++ b/crawl-ref/source/tutorial.cc
@@ -1313,7 +1313,7 @@ void tutorial_first_monster(const monsters &mon)
void tutorial_first_item(const item_def &item)
{
// Happens if monster is standing on dropped corpse or item.
- if (mgrd(item.pos) != NON_MONSTER)
+ if (monster_at(item.pos))
return;
if (!Options.tutorial_events[TUT_SEEN_FIRST_OBJECT]
@@ -1323,7 +1323,7 @@ void tutorial_first_item(const item_def &item)
// corpse, TUT_SEEN_CARRION is done when a corpse is first seen.
if (!Options.tut_just_triggered
&& item.base_type == OBJ_CORPSES
- && mgrd(item.pos) == NON_MONSTER)
+ && monster_at(item.pos) == NULL)
{
learned_something_new(TUT_SEEN_CARRION, item.pos);
}
@@ -1783,7 +1783,7 @@ void learned_something_new(tutorial_event_type seen_what, coord_def gc)
text << "These ";
#ifndef USE_TILE
// Is a monster blocking the view?
- if (mgrd(gc) != NON_MONSTER)
+ if (monster_at(gc))
DELAY_EVENT;
object = env.show(e);
@@ -1811,7 +1811,7 @@ void learned_something_new(tutorial_event_type seen_what, coord_def gc)
DELAY_EVENT;
// monsters standing on stairs
- if (mgrd(gc) != NON_MONSTER)
+ if (monster_at(gc))
DELAY_EVENT;
text << "These ";
@@ -1840,7 +1840,7 @@ void learned_something_new(tutorial_event_type seen_what, coord_def gc)
text << "This ";
#ifndef USE_TILE
// Is a monster blocking the view?
- if (mgrd(gc) != NON_MONSTER)
+ if (monster_at(gc))
DELAY_EVENT;
// FIXME: Branch entrance character is not being colored yellow.
@@ -1873,7 +1873,7 @@ void learned_something_new(tutorial_event_type seen_what, coord_def gc)
return;
#else
// Monster or player standing on stairs.
- if (mgrd(gc) != NON_MONSTER || (you.pos() == gc))
+ if (monster_at(gc) || (you.pos() == gc))
DELAY_EVENT;
text << "If any items are covering stairs or an escape hatch then "
@@ -2643,11 +2643,8 @@ void learned_something_new(tutorial_event_type seen_what, coord_def gc)
case TUT_MONSTER_BRAND:
#ifdef USE_TILE
tiles.place_cursor(CURSOR_TUTORIAL, gc);
- if (mgrd(gc) != NON_MONSTER)
- {
- tiles.add_text_tag(TAG_TUTORIAL, menv[mgrd(gc)].name(DESC_CAP_A),
- gc);
- }
+ if (const monsters *m = monster_at(gc))
+ tiles.add_text_tag(TAG_TUTORIAL, m->name(DESC_CAP_A), gc);
#endif
text << "That monster looks a bit unusual. You might wish to examine "
"it a bit more closely by "
@@ -2661,11 +2658,8 @@ void learned_something_new(tutorial_event_type seen_what, coord_def gc)
case TUT_MONSTER_FRIENDLY:
#ifdef USE_TILE
tiles.place_cursor(CURSOR_TUTORIAL, gc);
- if (mgrd(gc) != NON_MONSTER)
- {
- tiles.add_text_tag(TAG_TUTORIAL, menv[mgrd(gc)].name(DESC_CAP_A),
- gc);
- }
+ if (const monsters *m = monster_at(gc))
+ tiles.add_text_tag(TAG_TUTORIAL, m->name(DESC_CAP_A), gc);
#endif
text << "That monster is friendly to you and will attack your "
"enemies, though you'll get only half the experience for "
@@ -3812,15 +3806,11 @@ static void _tutorial_describe_disturbance(int x, int y)
static bool _water_is_disturbed(int x, int y)
{
- int mon_num = mgrd[x][y];
+ const coord_def c(x,y);
+ const monsters *mon = monster_at(c);
- if (mon_num == NON_MONSTER || grd[x][y] != DNGN_SHALLOW_WATER
- || !see_grid(x, y))
- {
+ if (mon == NULL || grd(c) != DNGN_SHALLOW_WATER || !see_grid(c))
return (false);
- }
-
- const monsters *mon = &menv[mon_num];
return (!player_monster_visible(mon) && !mons_flies(mon));
}