diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-02-14 23:24:28 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-02-14 23:24:28 +0000 |
commit | e1fa1a06461407819062f7c5875d7a0e84fa3f09 (patch) | |
tree | c6ce98be4178f5b3136c930ba41a4c83c5424ca9 /crawl-ref | |
parent | 03e3fad75bdd74c841988ec13c8a0259aaa51a88 (diff) | |
download | crawl-ref-e1fa1a06461407819062f7c5875d7a0e84fa3f09.tar.gz crawl-ref-e1fa1a06461407819062f7c5875d7a0e84fa3f09.zip |
More mgrd elimination and moving to coord_def().
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9084 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/debug.cc | 17 | ||||
-rw-r--r-- | crawl-ref/source/dungeon.cc | 7 | ||||
-rw-r--r-- | crawl-ref/source/luadgn.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/player.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/terrain.cc | 31 | ||||
-rw-r--r-- | crawl-ref/source/terrain.h | 7 | ||||
-rw-r--r-- | crawl-ref/source/travel.cc | 80 | ||||
-rw-r--r-- | crawl-ref/source/travel.h | 4 | ||||
-rw-r--r-- | crawl-ref/source/view.cc | 6 |
9 files changed, 73 insertions, 83 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index 321b11bad3..77dadd1052 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -4640,20 +4640,21 @@ void debug_make_trap() return; strlwr(requested_trap); - std::vector<int> matches; + std::vector<trap_type> matches; std::vector<std::string> match_names; for (int t = TRAP_DART; t < NUM_TRAPS; ++t) { - if (strstr(requested_trap, - trap_name(trap_type(t)))) + const trap_type tr = static_cast<trap_type>(t); + const char* tname = trap_name(tr); + if (strstr(requested_trap, tname)) { - trap = trap_type(t); + trap = tr; break; } - else if (strstr(trap_name(trap_type(t)), requested_trap)) + else if (strstr(tname, requested_trap)) { - matches.push_back(t); - match_names.push_back(trap_name(trap_type(t))); + matches.push_back(tr); + match_names.push_back(tname); } } @@ -4666,7 +4667,7 @@ void debug_make_trap() } // Only one match, use that else if (matches.size() == 1) - trap = trap_type(matches[0]); + trap = matches[0]; else { std::string prefix = "No exact match for trap '"; diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index 923cd14248..b6218e6b6b 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -485,8 +485,7 @@ static void _dgn_register_vault(const map_def &map) static bool _is_passable_ignore_vault(const coord_def &c) { - return (is_travelsafe_square(c.x, c.y, false, true) - || grd(c) == DNGN_SECRET_DOOR); + return (is_travelsafe_square(c, false, true) || grd(c) == DNGN_SECRET_DOOR); } bool dgn_square_is_passable(const coord_def &c) @@ -497,9 +496,7 @@ bool dgn_square_is_passable(const coord_def &c) // default) because vaults may choose to create isolated regions, // or otherwise cause connectivity issues even if the map terrain // is travel-passable. - return (!(dgn_Map_Mask(c) & MMT_OPAQUE) - && (is_travelsafe_square(c.x, c.y, false, true) - || grd(c) == DNGN_SECRET_DOOR)); + return (!(dgn_Map_Mask(c) & MMT_OPAQUE) && (_is_passable_ignore_vault(c))); } static inline void _dgn_point_record_stub(const coord_def &) { } diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc index e7627ea5d4..465e9e894a 100644 --- a/crawl-ref/source/luadgn.cc +++ b/crawl-ref/source/luadgn.cc @@ -2346,7 +2346,7 @@ static int dgn_fill_disconnected_zones(lua_State *ls) static int _dgn_is_passable(lua_State *ls) { COORDS(c, 1, 2); - lua_pushboolean(ls, is_travelsafe_square(c.x, c.y, false, true)); + lua_pushboolean(ls, is_travelsafe_square(c, false, true)); return (1); } diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 2f8dbbc7ba..6250c86c09 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -203,7 +203,7 @@ bool move_player_to_grid( const coord_def& p, bool stepped, bool allow_shift, // as defined in init.txt (see trapwalk.lua) if (new_grid != DNGN_TRAP_MECHANICAL || !clua.callbooleanfn(false, "ch_cross_trap", - "s", trap_name(p.x, p.y))) + "s", trap_name(p))) #endif { std::string prompt = make_stringf( diff --git a/crawl-ref/source/terrain.cc b/crawl-ref/source/terrain.cc index 18223a8afd..11821e1e75 100644 --- a/crawl-ref/source/terrain.cc +++ b/crawl-ref/source/terrain.cc @@ -35,6 +35,15 @@ REVISION("$Rev$"); #include "traps.h" #include "view.h" +actor* actor_at(const coord_def& c) +{ + if (!in_bounds(c)) + return (NULL); + if (c == you.pos()) + return (&you); + return (monster_at(c)); +} + bool grid_is_wall(dungeon_feature_type grid) { return (grid >= DNGN_MINWALL && grid <= DNGN_MAXWALL); @@ -549,9 +558,9 @@ void _dgn_check_terrain_player(const coord_def pos) // If the monster can't stay submerged in the new terrain and // there aren't any adjacent squares where it can stay // submerged then move it. - const int midx = mgrd(you.pos()); - if ( midx != NON_MONSTER && !mons_is_submerged( &menv[midx] ) ) - monster_teleport( &menv[midx], true, false); + monsters* mon = monster_at(pos); + if (mon && !mons_is_submerged(mon)) + monster_teleport(mon, true, false); move_player_to_grid(pos, false, true, true); } else @@ -589,7 +598,7 @@ void dungeon_terrain_changed(const coord_def &pos, if (affect_player) _dgn_check_terrain_player(pos); - set_terrain_changed(pos.x, pos.y); + set_terrain_changed(pos); } static void _announce_swap_real(coord_def orig_pos, coord_def dest_pos) @@ -857,12 +866,7 @@ static bool _ok_dest_grid(const actor* orig_actor, if (is_notable_terrain(dest_feat)) return (false); - actor* dest_actor = NULL; - - if (dest_pos == you.pos()) - dest_actor = &you; - else if (mgrd(dest_pos) != NON_MONSTER) - dest_actor = &menv[mgrd(dest_pos)]; + actor* dest_actor = actor_at(dest_pos); if (orig_actor && !orig_actor->is_habitable_feat(dest_feat)) return (false); @@ -878,12 +882,7 @@ bool slide_feature_over(const coord_def &src, coord_def prefered_dest, ASSERT(in_bounds(src)); const dungeon_feature_type orig_feat = grd(src); - actor* orig_actor = NULL; - - if (src == you.pos()) - orig_actor = &you; - else if (mgrd(src) != NON_MONSTER) - orig_actor = &menv[mgrd(src)]; + const actor* orig_actor = actor_at(src); if (in_bounds(prefered_dest) && _ok_dest_grid(orig_actor, orig_feat, prefered_dest)) diff --git a/crawl-ref/source/terrain.h b/crawl-ref/source/terrain.h index 71a397f746..8de51fba08 100644 --- a/crawl-ref/source/terrain.h +++ b/crawl-ref/source/terrain.h @@ -14,10 +14,9 @@ class actor; struct coord_def; -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: acr - * *********************************************************************** */ + +actor* actor_at(const coord_def& c); + bool fall_into_a_pool( const coord_def& entry, bool allow_shift, unsigned char terrain ); diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index e0b4775bab..6452eaf2c4 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -199,9 +199,9 @@ bool is_player_seen(int grid_x, int grid_y) // Returns true if there is a known trap at (x,y). Returns false for non-trap // squares as also for undiscovered traps. // -inline bool is_trap(int x, int y) +inline bool is_trap(const coord_def& c) { - return grid_is_trap( grd[x][y] ); + return grid_is_trap(grd(c)); } // Returns an estimate for the time needed to cross this feature. @@ -254,12 +254,12 @@ static void _init_traps() traps_inited = true; } -const char *trap_name(int x, int y) +const char *trap_name(const coord_def& c) { if (!traps_inited) _init_traps(); - const int ti = curr_traps[x][y]; + const int ti = curr_traps[c.x][c.y]; if (ti != -1) { int type = env.trap[ti].type; @@ -509,9 +509,9 @@ void set_exclude(const coord_def &p, int radius) } } -static bool _is_monster_blocked(int x, int y) +static bool _is_monster_blocked(const coord_def& c) { - const monsters *mons = monster_at(coord_def(x, y)); + const monsters *mons = monster_at(c); return (mons && player_monster_visible(mons) && mons_is_stationary(mons) @@ -530,36 +530,36 @@ static bool _is_monster_blocked(int x, int y) * colour the level map. It does not affect pathing of actual * travel/explore. */ -static bool _is_reseedable(int x, int y) +static bool _is_reseedable(const coord_def& c) { - if (is_excluded(coord_def(x, y))) + if (is_excluded(c)) return (true); - dungeon_feature_type grid = grd[x][y]; + const dungeon_feature_type grid = grd(c); return (grid_is_water(grid) || grid == DNGN_LAVA - || is_trap(x, y) - || _is_monster_blocked(x, y)); + || is_trap(c) + || _is_monster_blocked(c)); } // Returns true if the square at (x,y) is okay to travel over. If ignore_hostile // is true, returns true even for dungeon features the character can normally // not cross safely (deep water, lava, traps). -bool is_travelsafe_square(int x, int y, bool ignore_hostile, +bool is_travelsafe_square(const coord_def& c, bool ignore_hostile, bool ignore_terrain_knowledge) { - if (!ignore_terrain_knowledge && !is_terrain_known(x, y)) + if (!ignore_terrain_knowledge && !is_terrain_known(c)) return (false); - const bool seen = see_grid(x,y); - const int grid = ((seen || ignore_terrain_knowledge) ? grd[x][y] - : get_envmap_obj(x,y)); + const bool seen = see_grid(c); + const int grid = ((seen || ignore_terrain_knowledge) ? grd(c) + : get_envmap_obj(c)); // FIXME: this compares to the *real* monster at the square, // even if the one we've seen is different. if (!ignore_hostile && (seen || grid > DNGN_START_OF_MONSTERS) - && _is_monster_blocked(x, y)) + && _is_monster_blocked(c)) { return (false); } @@ -568,7 +568,7 @@ bool is_travelsafe_square(int x, int y, bool ignore_hostile, // navigated over if the player is willing to take damage, or levitate. if (ignore_hostile && (seen || grid < NUM_REAL_FEATURES) - && _is_reseedable(x, y)) + && _is_reseedable(c)) { return (true); } @@ -578,28 +578,24 @@ bool is_travelsafe_square(int x, int y, bool ignore_hostile, return (is_traversable(static_cast<dungeon_feature_type>(grid)) #ifdef CLUA_BINDINGS - || (is_trap(x, y) + || (is_trap(c) && clua.callbooleanfn(false, "ch_cross_trap", - "s", trap_name(x, y))) + "s", trap_name(c))) #endif ) - && !is_excluded(coord_def(x, y)); + && !is_excluded(c); } // Returns true if the location at (x,y) is monster-free and contains no clouds. // Travel uses this to check if the square the player is about to move to is // safe. -static bool _is_safe_move(int x, int y) +static bool _is_safe_move(const coord_def& c) { - int mon = mgrd[x][y]; - if (mon != NON_MONSTER) + if (const monsters *mon = monster_at(c)) { // Stop before wasting energy on plants and fungi. - if (player_monster_visible(&menv[mon]) - && mons_class_flag( menv[mon].type, M_NO_EXP_GAIN )) - { + if (you.can_see(mon) && mons_class_flag(mon->type, M_NO_EXP_GAIN)) return (false); - } // If this is any *other* monster, it'll be visible and // a) Friendly, in which case we'll displace it, no problem. @@ -607,22 +603,22 @@ static bool _is_safe_move(int x, int y) // should have been aborted already by the checks in view.cc. } - if (is_trap(x, y) + if (is_trap(c) #ifdef CLUA_BINDINGS && !clua.callbooleanfn(false, "ch_cross_trap", - "s", trap_name(x, y)) + "s", trap_name(c)) #endif ) { return (false); } - const int cloud = env.cgrid[x][y]; + const int cloud = env.cgrid(c); if (cloud == EMPTY_CLOUD) return (true); // We can also safely run through smoke. - const cloud_type ctype = env.cloud[ cloud ].type; + const cloud_type ctype = env.cloud[cloud].type; return (!is_damaging_cloud(ctype, true)); } @@ -1021,7 +1017,7 @@ static void _explore_find_target_square() target += delta; feature = grd(target); } - while (is_travelsafe_square(target.x, target.y) + while (is_travelsafe_square(target) && is_traversable(feature) && feature_traverse_cost(feature) == 1); @@ -1548,10 +1544,10 @@ coord_def travel_pathfind::pathfind(run_mode_type rmode) // Abort run if we're trying to go someplace evil. Travel to traps is // specifically allowed here if the player insists on it. if (!floodout - && !is_travelsafe_square(start.x, start.y, false) - && !is_trap(start.x, start.y)) // player likes pain + && !is_travelsafe_square(start, false) + && !is_trap(start)) // player likes pain { - return coord_def(0, 0); + return coord_def(); } // Nothing to do? @@ -1687,7 +1683,7 @@ void travel_pathfind::check_square_greed(const coord_def &c) { if (greedy_dist == UNFOUND_DIST && is_greed_inducing_square(c) - && is_travelsafe_square(c.x, c.y, ignore_hostile)) + && is_travelsafe_square(c, ignore_hostile)) { greedy_place = c; greedy_dist = traveled_distance; @@ -1752,20 +1748,20 @@ bool travel_pathfind::path_flood(const coord_def &c, const coord_def &dc) if (dc == dest) { // Hallelujah, we're home! - if (_is_safe_move(c.x, c.y)) + if (_is_safe_move(c)) next_travel_move = c; return (true); } - else if (!is_travelsafe_square(dc.x, dc.y, ignore_hostile)) + else if (!is_travelsafe_square(dc, ignore_hostile)) { // This point is not okay to travel on, but if this is a // trap, we'll want to put it on the feature vector anyway. - if (_is_reseedable(dc.x, dc.y) + if (_is_reseedable(dc) && !point_distance[dc.x][dc.y] && dc != start) { - if (features && (is_trap(dc.x, dc.y) || is_exclude_root(dc))) + if (features && (is_trap(dc) || is_exclude_root(dc))) features->push_back(dc); if (double_flood) @@ -2954,7 +2950,7 @@ void start_travel(const coord_def& p) // Can we even travel to this square? if (!in_bounds(p)) return; - if (!is_travelsafe_square(p.x, p.y, true)) + if (!is_travelsafe_square(p, true)) return; you.running.pos = p; diff --git a/crawl-ref/source/travel.h b/crawl-ref/source/travel.h index 419d0e3a32..4dbde13a77 100644 --- a/crawl-ref/source/travel.h +++ b/crawl-ref/source/travel.h @@ -72,7 +72,7 @@ bool is_gate(dungeon_feature_type gridc); command_type direction_to_command( char x, char y ); bool is_resting( void ); #ifdef CLUA_BINDINGS -const char *trap_name(int x, int y); +const char *trap_name(const coord_def &p); #endif bool is_traversable(dungeon_feature_type grid); void explore_pickup_event(int did_pickup, int tried_pickup); @@ -81,7 +81,7 @@ bool is_excluded(const coord_def &p); void find_travel_pos(const coord_def& youpos, char *move_x, char *move_y, std::vector<coord_def>* coords = NULL); -bool is_travelsafe_square(int x, int y, bool ignore_hostile = false, +bool is_travelsafe_square(const coord_def& c, bool ignore_hostile = false, bool ignore_terrain_knowledge = false); /* *********************************************************************** diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index e3a0dac09d..c16feff26c 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -1247,11 +1247,9 @@ void monster_grid(bool do_updates) { do_updates = do_updates && !crawl_state.arena; - monsters *monster = NULL; - - for (int s = 0; s < MAX_MONSTERS; s++) + for (int s = 0; s < MAX_MONSTERS; ++s) { - monster = &menv[s]; + monsters *monster = &menv[s]; if (monster->alive() && mons_near(monster)) { |