From 7124f889e3c585947d594aa38be346bc87c08069 Mon Sep 17 00:00:00 2001 From: dolorous Date: Mon, 26 Jan 2009 04:43:58 +0000 Subject: Simplify checks for grids containing water. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8763 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/directn.cc | 12 +++++------- crawl-ref/source/dungeon.cc | 15 ++++++--------- crawl-ref/source/mon-util.cc | 2 +- crawl-ref/source/monplace.cc | 5 ++--- crawl-ref/source/monstuff.cc | 11 ++++++----- crawl-ref/source/player.cc | 16 ++++++++-------- crawl-ref/source/spells2.cc | 4 +--- crawl-ref/source/terrain.cc | 24 +++++++++++++----------- crawl-ref/source/terrain.h | 8 ++++---- crawl-ref/source/tilepick.cc | 2 +- crawl-ref/source/travel.cc | 13 +++++++------ crawl-ref/source/xom.cc | 6 +++--- 12 files changed, 57 insertions(+), 61 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc index dc6584537b..ae1d8a0811 100644 --- a/crawl-ref/source/directn.cc +++ b/crawl-ref/source/directn.cc @@ -2259,6 +2259,7 @@ void describe_floor() std::string prefix = "There is "; std::string feat; std::string suffix = " here."; + switch (grid) { case DNGN_FLOOR: @@ -2281,12 +2282,9 @@ void describe_floor() msg_channel_type channel = MSGCH_EXAMINE; // Water is not terribly important if you don't mind it. - if ((grd(you.pos()) == DNGN_DEEP_WATER - || grd(you.pos()) == DNGN_SHALLOW_WATER) - && player_likes_water()) - { + if (grid_is_water(grid) && player_likes_water()) channel = MSGCH_EXAMINE_FILTER; - } + mpr((prefix + feat + suffix).c_str(), channel); if (grid == DNGN_ENTER_LABYRINTH && you.is_undead != US_UNDEAD) mpr("Beware, for starvation awaits!", MSGCH_EXAMINE); @@ -3247,11 +3245,11 @@ static void _describe_cell(const coord_def& where, bool in_range) msg_channel_type channel = MSGCH_EXAMINE; if (feat == DNGN_FLOOR || feat == DNGN_FLOOR_SPECIAL - || feat == DNGN_SHALLOW_WATER - || feat == DNGN_DEEP_WATER) + || grid_is_water(feat)) { channel = MSGCH_EXAMINE_FILTER; } + mpr(feature_desc.c_str(), channel); } #endif diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index bceb9bbda7..6eb255ee36 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -1849,10 +1849,7 @@ static int _count_connected(int margin) for (int i = margin; i < GXM - margin; ++i) for (int j = margin; j < GYM - margin; ++j) - { - taken[i][j] = (grd[i][j] == DNGN_DEEP_WATER - || grd[i][j] == DNGN_SHALLOW_WATER); - } + taken[i][j] = grid_is_water(grd[i][j]); int count = 0; @@ -2022,11 +2019,11 @@ static void _prepare_shoals(int level_number) _replace_in_grid(margin, margin, GXM-margin, GYM-margin, DNGN_SHALLOW_WATER, DNGN_WATER_STUCK); - for ( int iteration = 0; iteration < 6; ++iteration ) + for (int iteration = 0; iteration < 6; ++iteration) { - for ( int x = margin; x < GXM - margin; ++x ) - for ( int y = margin; y < GYM - margin; ++y ) - if ( grd[x][y] == DNGN_DEEP_WATER ) + for (int x = margin; x < GXM - margin; ++x) + for (int y = margin; y < GYM - margin; ++y) + if (grd[x][y] == DNGN_DEEP_WATER) { int badness = count_neighbours(x, y, DNGN_WATER_STUCK); if (random2(badness) >= 2 && coinflip()) @@ -3419,7 +3416,7 @@ static void _place_aquatic_monsters(int level_number, char level_type) if (grd[x][y] == DNGN_LAVA) lava_spaces++; - if (grd[x][y] == DNGN_DEEP_WATER || grd[x][y] == DNGN_SHALLOW_WATER) + if (grid_is_water(grd[x][y])) water_spaces++; } diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 573f2af381..bbb97d149c 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -8353,7 +8353,7 @@ std::string do_mon_str_replacements(const std::string &in_msg, msg = replace_all(msg, "@surface@", "buggy surface"); else if (feat == DNGN_LAVA) msg = replace_all(msg, "@surface@", "lava"); - else if (feat == DNGN_DEEP_WATER || feat == DNGN_SHALLOW_WATER) + else if (grid_is_water(feat)) msg = replace_all(msg, "@surface@", "water"); else if (feat >= DNGN_ALTAR_FIRST_GOD && feat <= DNGN_ALTAR_LAST_GOD) msg = replace_all(msg, "@surface@", "altar"); diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc index f0abe5b778..5684e4d70f 100644 --- a/crawl-ref/source/monplace.cc +++ b/crawl-ref/source/monplace.cc @@ -77,8 +77,6 @@ static int _place_monster_aux(const mgen_data &mg, bool first_band_member, bool grid_compatible(dungeon_feature_type grid_wanted, dungeon_feature_type actual_grid) { - // XXX What in Xom's name is DNGN_WATER_STUCK? It looks like an artificial - // device to slow down fiery monsters flying over water. if (grid_wanted == DNGN_FLOOR) { return (actual_grid >= DNGN_FLOOR @@ -764,7 +762,8 @@ int place_monster(mgen_data mg, bool force_pos) // For some cases disallow monsters on stairs. if (mons_class_is_stationary(mg.cls) || (pval == 2 // Stairs occupied by player. - && (mons_speed(mg.cls) == 0 || grd(mg.pos) == DNGN_LAVA + && (mons_speed(mg.cls) == 0 + || grd(mg.pos) == DNGN_LAVA || grd(mg.pos) == DNGN_DEEP_WATER))) { mg.proximity = PROX_AWAY_FROM_PLAYER; diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index fc8389a058..97c3dcf24b 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -7965,13 +7965,15 @@ static bool _mon_can_move_to_pos(const monsters *monster, if (!inside_level_bounds(targ)) return (false); - // Non-friendly and non-good neutral monsters won't enter sanctuaries. + // Non-friendly and non-good neutral monsters won't enter + // sanctuaries. if (!mons_wont_attack(monster) && is_sanctuary(targ) && !is_sanctuary(monster->pos())) { return (false); } + // Inside a sanctuary don't attack anything! if (is_sanctuary(monster->pos()) && (targ == you.pos() || mgrd(targ) != NON_MONSTER)) @@ -8007,12 +8009,11 @@ static bool _mon_can_move_to_pos(const monsters *monster, return (false); } else if (!monster->can_pass_through_feat(target_grid) - || no_water && target_grid >= DNGN_DEEP_WATER - && target_grid <= DNGN_WATER_STUCK) + || no_water && grid_is_water(target_grid)) { return (false); } - else if (!_habitat_okay( monster, target_grid )) + else if (!_habitat_okay(monster, target_grid)) { // If the monster somehow ended up in this habitat (and is // not dead by now), give it a chance to get out again. @@ -8038,7 +8039,7 @@ static bool _mon_can_move_to_pos(const monsters *monster, return (false); } - // Fire elementals avoid water and cold + // Fire elementals avoid water and cold. if (monster->type == MONS_FIRE_ELEMENTAL && (grid_is_watery(target_grid) || targ_cloud_type == CLOUD_COLD)) diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 83436001bf..0830998366 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -375,7 +375,7 @@ bool is_grid_dangerous(int grid) { return (!player_is_airborne() && (grid == DNGN_LAVA - || (grid == DNGN_DEEP_WATER && !player_likes_water()) )); + || (grid == DNGN_DEEP_WATER && !player_likes_water()))); } bool player_in_mappable_area( void ) @@ -2671,19 +2671,19 @@ bool player_monster_visible(const monsters *mon) if (!player_see_invis() && mon->invisible()) return (false); - // Treat monsters who are submerged due to drowning as visible, so - // we get proper messages when they die. if (!mons_is_submerged(mon)) return (true); const dungeon_feature_type feat = grd(mon->pos()); - // Monsters can only drown in lava or water, so monsters that are - // "submerged" in other features (air elementals in air, trapdoor - // spiders in the floor) are exempt from this check. - if (feat < DNGN_LAVA || feat > DNGN_WATER_STUCK) + // Treat monsters who are submerged due to drowning as visible, so + // we get proper messages when they die. Monsters can only drown in + // lava or deep water, so monsters that are "submerged" in other + // features (air elementals in air, trapdoor spiders in the floor) + // are exempt from this check. + if (feat != DNGN_LAVA && feat != DNGN_DEEP_WATER) return (false); - + return (mon->can_drown()); } diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index 57f399338f..2b4f7c7641 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -1400,9 +1400,7 @@ bool cast_summon_elemental(int pow, god_type god, { mon = MONS_FIRE_ELEMENTAL; } - else if ((grd(targ) == DNGN_DEEP_WATER - || grd(targ) == DNGN_SHALLOW_WATER - || grd(targ) == DNGN_FOUNTAIN_BLUE) + else if (grid_is_watery(grd(targ)) && (any_elemental || restricted_type == MONS_WATER_ELEMENTAL)) { mon = MONS_WATER_ELEMENTAL; diff --git a/crawl-ref/source/terrain.cc b/crawl-ref/source/terrain.cc index 4b3019835a..84d1a2ec1a 100644 --- a/crawl-ref/source/terrain.cc +++ b/crawl-ref/source/terrain.cc @@ -165,17 +165,17 @@ command_type grid_stair_direction(dungeon_feature_type grid) } } -bool grid_is_opaque( dungeon_feature_type grid ) +bool grid_is_opaque(dungeon_feature_type grid) { return (grid < DNGN_MINSEE); } -bool grid_is_solid( dungeon_feature_type grid ) +bool grid_is_solid(dungeon_feature_type grid) { return (grid < DNGN_MINMOVE); } -bool grid_is_solid( int x, int y ) +bool grid_is_solid(int x, int y) { return (grid_is_solid(grd[x][y])); } @@ -211,27 +211,29 @@ bool grid_is_water(dungeon_feature_type grid) return (grid == DNGN_SHALLOW_WATER || grid == DNGN_DEEP_WATER); } -bool grid_is_watery( dungeon_feature_type grid ) +bool grid_is_watery(dungeon_feature_type grid) { return (grid_is_water(grid) || grid == DNGN_FOUNTAIN_BLUE); } -bool grid_destroys_items( dungeon_feature_type grid ) +bool grid_destroys_items(dungeon_feature_type grid) { return (grid == DNGN_LAVA || grid == DNGN_DEEP_WATER); } -// Returns 0 if grid is not an altar, else it returns the GOD_* type. -god_type grid_altar_god( dungeon_feature_type grid ) +// Returns GOD_NO_GOD if grid is not an altar, otherwise returns the +// GOD_* type. +god_type grid_altar_god(dungeon_feature_type grid) { if (grid >= DNGN_ALTAR_FIRST_GOD && grid <= DNGN_ALTAR_LAST_GOD) - return (static_cast( grid - DNGN_ALTAR_FIRST_GOD + 1 )); + return (static_cast(grid - DNGN_ALTAR_FIRST_GOD + 1)); return (GOD_NO_GOD); } -// Returns DNGN_FLOOR for non-gods, otherwise returns the altar for the god. -dungeon_feature_type altar_for_god( god_type god ) +// Returns DNGN_FLOOR for non-gods, otherwise returns the altar for the +// god. +dungeon_feature_type altar_for_god(god_type god) { if (god == GOD_NO_GOD || god >= NUM_GODS) return (DNGN_FLOOR); // Yeah, lame. Tell me about it. @@ -1058,7 +1060,7 @@ std::string grid_preposition(dungeon_feature_type grid, bool active, else return "inside"; } - else if (!airborne && grid >= DNGN_LAVA && grid <= DNGN_WATER_STUCK) + else if (!airborne && grid_can_be_drowned_in(grid)) { if (active) return "around"; diff --git a/crawl-ref/source/terrain.h b/crawl-ref/source/terrain.h index d4c7bfc812..71a397f746 100644 --- a/crawl-ref/source/terrain.h +++ b/crawl-ref/source/terrain.h @@ -43,11 +43,11 @@ std::string stair_climb_verb(dungeon_feature_type grid); bool grid_is_water(dungeon_feature_type grid); bool grid_is_watery(dungeon_feature_type grid); -god_type grid_altar_god( dungeon_feature_type grid ); -dungeon_feature_type altar_for_god( god_type god ); -bool grid_is_branch_stairs( dungeon_feature_type grid ); +god_type grid_altar_god(dungeon_feature_type grid); +dungeon_feature_type altar_for_god(god_type god); +bool grid_is_branch_stairs(dungeon_feature_type grid); void find_connected_identical(coord_def d, dungeon_feature_type ft, - std::set& out); + std::set& out); void find_connected_range(coord_def d, dungeon_feature_type ft_min, dungeon_feature_type ft_max, std::set& out); diff --git a/crawl-ref/source/tilepick.cc b/crawl-ref/source/tilepick.cc index d6beec8f86..acf9bbfd3e 100644 --- a/crawl-ref/source/tilepick.cc +++ b/crawl-ref/source/tilepick.cc @@ -118,7 +118,7 @@ static int _bow_offset(const monsters *mon) static int _tileidx_monster_base(const monsters *mon, bool detected) { int grid = grd(mon->pos()); - bool in_water = (grid == DNGN_SHALLOW_WATER || grid == DNGN_DEEP_WATER); + bool in_water = grid_is_water(grid); int type = mon->type; diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 6d569f1462..70eb8e867c 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -536,8 +536,10 @@ static bool _is_reseedable(int x, int y) return (true); int grid = grd[x][y]; - return (grid == DNGN_DEEP_WATER || grid == DNGN_SHALLOW_WATER - || grid == DNGN_LAVA || is_trap(x, y) || _is_monster_blocked(x, y)); + return (grid_is_water(grid) + || grid == DNGN_LAVA + || is_trap(x, y) + || _is_monster_blocked(x, y)); } // Returns true if the square at (x,y) is okay to travel over. If ignore_hostile @@ -702,9 +704,9 @@ void initialise_travel() int get_feature_type(const std::string &feature) { if (feature.find("deep water") != std::string::npos) - return DNGN_DEEP_WATER; + return (DNGN_DEEP_WATER); if (feature.find("shallow water") != std::string::npos) - return DNGN_SHALLOW_WATER; + return (DNGN_SHALLOW_WATER); return -1; } @@ -1794,8 +1796,7 @@ bool travel_pathfind::path_flood(const coord_def &c, const coord_def &dc) if (dc != start && (feature != DNGN_FLOOR - && feature != DNGN_SHALLOW_WATER - && feature != DNGN_DEEP_WATER + && grid_is_water(feature) && feature != DNGN_LAVA || is_waypoint(dc) || is_stash(ls, dc.x, dc.y))) diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc index 73b2c2e14b..b06a91be40 100644 --- a/crawl-ref/source/xom.cc +++ b/crawl-ref/source/xom.cc @@ -1262,7 +1262,7 @@ static void _xom_zero_miscast() if (in_view[DNGN_LAVA]) messages.push_back("The lava spits out sparks!"); - if (in_view[DNGN_DEEP_WATER] || in_view[DNGN_SHALLOW_WATER]) + if (in_view[DNGN_SHALLOW_WATER] || in_view[DNGN_DEEP_WATER]) { messages.push_back("The water briefly bubbles."); messages.push_back("The water briefly swirls."); @@ -1342,11 +1342,11 @@ static void _xom_zero_miscast() + " seems to fall away from under you!"); vec->push_back(feat_name + " seems to rush up at you!"); - if (feat == DNGN_DEEP_WATER || feat == DNGN_SHALLOW_WATER) + if (grid_is_water(feat)) priority.push_back("Something invisible splashes into the " "water beneath you!"); } - else if (feat == DNGN_DEEP_WATER || feat == DNGN_SHALLOW_WATER) + else if (grid_is_water(feat)) { priority.push_back("The water briefly recedes away from you."); priority.push_back("Something invisible splashes into the water " -- cgit v1.2.3-54-g00ecf