summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/monplace.cc
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-30 10:53:06 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-30 10:53:06 +0000
commit262b8e18ed8cb58afb40a816ac0fdedfe3a7db5f (patch)
tree681a9cbb6c22669c6e8b7ab749228a3cd691a903 /crawl-ref/source/monplace.cc
parent51d8f1fc9cc8ed4280b9c53b135ccb0521e84889 (diff)
downloadcrawl-ref-262b8e18ed8cb58afb40a816ac0fdedfe3a7db5f.tar.gz
crawl-ref-262b8e18ed8cb58afb40a816ac0fdedfe3a7db5f.zip
Massive overhaul to move towards coord_def().
This might have introduced some bugs: I now get intermittent crashes on startup (this might have to do with the changes to special_room.) Sorry about that - committing before I need to do any more big conflict resolutions. Fixes coming later. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6732 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/monplace.cc')
-rw-r--r--crawl-ref/source/monplace.cc90
1 files changed, 30 insertions, 60 deletions
diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc
index f38c036414..0d51992a83 100644
--- a/crawl-ref/source/monplace.cc
+++ b/crawl-ref/source/monplace.cc
@@ -686,17 +686,13 @@ int place_monster(mgen_data mg, bool force_pos)
switch (mg.proximity)
{
case PROX_ANYWHERE:
- if (grid_distance( you.x_pos, you.y_pos,
- mg.pos.x, mg.pos.y ) < 2 + random2(3))
- {
+ if (grid_distance( you.pos(), mg.pos ) < 2 + random2(3))
proxOK = false;
- }
break;
case PROX_CLOSE_TO_PLAYER:
case PROX_AWAY_FROM_PLAYER:
- close_to_player = (distance(you.x_pos, you.y_pos,
- mg.pos.x, mg.pos.y) < 64);
+ close_to_player = (distance(you.pos(), mg.pos) < 64);
if (mg.proximity == PROX_CLOSE_TO_PLAYER && !close_to_player
|| mg.proximity == PROX_AWAY_FROM_PLAYER && close_to_player)
@@ -753,10 +749,10 @@ int place_monster(mgen_data mg, bool force_pos)
monsters *mon = &menv[id];
if (mg.needs_patrol_point())
{
- mon->patrol_point = coord_def(mon->x, mon->y);
+ mon->patrol_point = mon->pos();
#ifdef DEBUG_PATHFIND
mprf("Monster %s is patrolling around (%d, %d).",
- mon->name(DESC_PLAIN).c_str(), mon->x, mon->y);
+ mon->name(DESC_PLAIN).c_str(), mon->pos().x, mon->pos().y);
#endif
}
@@ -873,8 +869,7 @@ static int _place_monster_aux( const mgen_data &mg,
menv[id].base_monster = mg.base_type;
menv[id].number = mg.number;
- menv[id].x = fpos.x;
- menv[id].y = fpos.y;
+ menv[id].moveto(fpos);
// Link monster into monster grid.
mgrd(fpos) = id;
@@ -2048,12 +2043,9 @@ coord_def find_newmons_square_contiguous(monster_type mons_class,
coord_def find_newmons_square(int mons_class, const coord_def &p)
{
- FixedVector < char, 2 > empty;
+ coord_def empty;
coord_def pos(-1, -1);
- empty[0] = 0;
- empty[1] = 0;
-
if (mons_class == WANDERING_MONSTER)
mons_class = RANDOM_MONSTER;
@@ -2062,11 +2054,8 @@ coord_def find_newmons_square(int mons_class, const coord_def &p)
// Might be better if we chose a space and tried to match the monster
// to it in the case of RANDOM_MONSTER, that way if the target square
// is surrounded by water or lava this function would work. -- bwr
- if (empty_surrounds( p.x, p.y, spcw, 2, true, empty ))
- {
- pos.x = empty[0];
- pos.y = empty[1];
- }
+ if (empty_surrounds( p, spcw, 2, true, empty ))
+ pos = empty;
return (pos);
}
@@ -2174,54 +2163,35 @@ int create_monster( mgen_data mg, bool fail_msg )
}
-bool empty_surrounds(int emx, int emy, dungeon_feature_type spc_wanted,
- int radius, bool allow_centre,
- FixedVector < char, 2 > &empty)
+bool empty_surrounds(const coord_def& where, dungeon_feature_type spc_wanted,
+ int radius, bool allow_centre, coord_def& empty)
{
- bool success;
-
// Assume all player summoning originates from player x,y.
- bool playerSummon = (emx == you.x_pos && emy == you.y_pos);
+ bool playerSummon = (where == you.pos());
int good_count = 0;
- int count_x, count_y;
-
- for (count_x = -radius; count_x <= radius; count_x++)
- for (count_y = -radius; count_y <= radius; count_y++)
- {
- success = false;
-
- if (!allow_centre && count_x == 0 && count_y == 0)
- continue;
-
- int tx = emx + count_x;
- int ty = emy + count_y;
-
- if (tx == you.x_pos && ty == you.y_pos)
- continue;
- if (!in_bounds(tx,ty))
- continue;
-
- if (mgrd[tx][ty] != NON_MONSTER)
- continue;
-
- // Players won't summon out of LOS, or past transparent walls.
- if (!see_grid_no_trans(tx, ty) && playerSummon)
- continue;
+ for ( radius_iterator ri(where, radius, true, false, !allow_centre);
+ ri; ++ri)
+ {
+ bool success = false;
- if (grd[tx][ty] == spc_wanted)
- success = true;
+ if ( *ri == you.pos() )
+ continue;
+
+ if (mgrd(*ri) != NON_MONSTER)
+ continue;
- if (grid_compatible(spc_wanted, grd[tx][ty]))
- success = true;
+ // Players won't summon out of LOS, or past transparent walls.
+ if (!see_grid_no_trans(*ri) && playerSummon)
+ continue;
- if (success && one_chance_in(++good_count))
- {
- empty[0] = tx;
- empty[1] = ty;
- }
- }
+ success =
+ (grd(*ri) == spc_wanted) || grid_compatible(spc_wanted, grd(*ri));
+
+ if (success && one_chance_in(++good_count))
+ empty = *ri;
+ }
return (good_count > 0);
}
@@ -2404,7 +2374,7 @@ bool monster_pathfind::start_pathfind(monsters *mon, coord_def dest, bool msg)
// We're doing a reverse search from target to monster.
start = dest;
- target = coord_def(mon->x, mon->y);
+ target = mon->pos();
pos = start;
// Easy enough. :P