diff options
-rw-r--r-- | crawl-ref/source/abyss.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/acr.cc | 45 | ||||
-rw-r--r-- | crawl-ref/source/clua.cc | 69 | ||||
-rw-r--r-- | crawl-ref/source/externs.h | 4 | ||||
-rw-r--r-- | crawl-ref/source/mon-util.cc | 5 | ||||
-rw-r--r-- | crawl-ref/source/monstuff.cc | 72 | ||||
-rw-r--r-- | crawl-ref/source/player.cc | 34 | ||||
-rw-r--r-- | crawl-ref/source/tags.cc | 7 | ||||
-rw-r--r-- | crawl-ref/source/terrain.cc | 4 | ||||
-rw-r--r-- | crawl-ref/source/transfor.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/view.cc | 14 |
11 files changed, 102 insertions, 156 deletions
diff --git a/crawl-ref/source/abyss.cc b/crawl-ref/source/abyss.cc index b77e4bfd3f..416515d1e9 100644 --- a/crawl-ref/source/abyss.cc +++ b/crawl-ref/source/abyss.cc @@ -1,6 +1,6 @@ /* * File: abyss.cc - * Summary: Misc functions (most of which don't appear to be related to priests). + * Summary: Misc abyss specific functions. * Written by: Linley Henzell * * Modified for Crawl Reference by $Author$ on $Date$ diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 8017232801..b935f664e1 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -1364,34 +1364,6 @@ static bool _cmd_is_repeatable(command_type cmd, bool is_again = false) return false; } -static void _check_lava_water_in_sight() -{ - // Check the player's vision for lava or deep water, - // to avoid unnecessary pathfinding later. - you.lava_in_sight = you.water_in_sight = false; - coord_def gp; - for (gp.y = (you.y_pos - 8); (gp.y <= you.y_pos + 8); gp.y++) - for (gp.x = (you.x_pos - 8); (gp.x <= you.x_pos + 8); gp.x++) - { - if (!in_bounds(gp)) - continue; - - const coord_def ep = gp - you.pos() + coord_def(9, 9); - if (env.show(ep)) - { - dungeon_feature_type feat = grd[gp.x][gp.y]; - if (feat == DNGN_LAVA) - you.lava_in_sight = true; - else if (feat == DNGN_DEEP_WATER) - you.water_in_sight = true; - - if (you.lava_in_sight && you.water_in_sight) - break; - } - } -} - - // Used to determine whether to apply the berserk penalty at end of round. bool apply_berserk_penalty = false; @@ -1429,8 +1401,8 @@ static void _input() { if (Options.tutorial_left) { - if ( 2*you.hp < you.hp_max - || 2*you.magic_points < you.max_magic_points ) + if (2 * you.hp < you.hp_max + || 2 * you.magic_points < you.max_magic_points) { tutorial_healing_reminder(); } @@ -1461,7 +1433,7 @@ static void _input() learned_something_new(TUT_RETREAT_CASTER); } - if ( you.cannot_act() ) + if (you.cannot_act()) { crawl_state.cancel_cmd_repeat("Cannot move, cancelling command " "repetition."); @@ -1492,9 +1464,6 @@ static void _input() you.attribute[ATTR_WEAPON_SWAP_INTERRUPTED] = 0; } - if (!you.turn_is_over) - _check_lava_water_in_sight(); - handle_delay(); const coord_def cwhere = grid2view(you.pos()); @@ -3082,7 +3051,7 @@ static void _world_reacts() stealth = check_stealth(); #if 0 - // too annoying for regular diagnostics + // Too annoying for regular diagnostics. mprf(MSGCH_DIAGNOSTICS, "stealth: %d", stealth ); #endif @@ -3947,7 +3916,7 @@ static bool _initialise(void) you.unique_creatures.init(false); you.unique_items.init(UNIQ_NOT_EXISTS); - // set up the Lua interpreter for the dungeon builder. + // Set up the Lua interpreter for the dungeon builder. init_dungeon_lua(); // Read special levels and vaults. @@ -4040,6 +4009,10 @@ static bool _initialise(void) trackers_init_new_level(false); + // Reset lava/water nearness check to unknown, so it'll be + // recalculated for the next monster that tries to reach us. + you.lava_in_sight = you.water_in_sight = -1; + // set vision radius to player's current vision setLOSRadius( you.current_vision ); diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 149aeb44fa..23828d33f8 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -1269,73 +1269,6 @@ static int l_item_subtype(lua_State *ls) return (2); } -// Used to divide a given potion into one of four categories: -// 0 : unknown potion -// 1 : always beneficial -// 2 : always bad -// 3 : depends on species etc. -static int l_item_potion_type(lua_State *ls) -{ - LUA_ITEM(item, 1); - int val = 99; - - if (item && item->base_type == OBJ_POTIONS) - { - if (!item_type_known(*item)) - { - val = 0; - } - else - { - switch(item->sub_type) - { - // good potions: - case POT_HEALING: - case POT_HEAL_WOUNDS: - case POT_SPEED: - case POT_MIGHT: - case POT_LEVITATION: - case POT_INVISIBILITY: - case POT_EXPERIENCE: - case POT_MAGIC: - case POT_RESTORE_ABILITIES: - case POT_RESISTANCE: - val = 1; - break; - - // bad potions: - case POT_POISON: - case POT_STRONG_POISON: - case POT_SLOWING: - case POT_PARALYSIS: - case POT_CONFUSION: - case POT_DEGENERATION: - case POT_DECAY: - case POT_MUTATION: - val = 2; - break; - - // Need more refined handling: - // for eating habits - case POT_BLOOD: - case POT_BLOOD_COAGULATED: - case POT_WATER: - case POT_PORRIDGE: - // for undead - case POT_BERSERK_RAGE: - case POT_GAIN_STRENGTH: - case POT_GAIN_DEXTERITY: - case POT_GAIN_INTELLIGENCE: - case POT_CURE_MUTATION: - default: - val = 3; - } - } - } - lua_pushnumber(ls, val); - return (1); -} - static int l_item_cursed(lua_State *ls) { LUA_ITEM(item, 1); @@ -1345,7 +1278,6 @@ static int l_item_cursed(lua_State *ls) return (1); } - static int l_item_worn(lua_State *ls) { LUA_ITEM(item, 1); @@ -1526,7 +1458,6 @@ static const struct luaL_reg item_lib[] = { "branded", l_item_branded }, { "class", l_item_class }, { "subtype", l_item_subtype }, - { "potion_type", l_item_potion_type }, { "cursed", l_item_cursed }, { "worn", l_item_worn }, { "name", l_item_name }, diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index b193f6f7ad..dc30418f83 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -743,8 +743,8 @@ public: // failures dungeon_feature_type transit_stair; bool entering_level; - bool lava_in_sight; // Is there lava in LoS? - bool water_in_sight; // Is there deep water in LoS? + int lava_in_sight; // Is there lava in LoS? + int water_in_sight; // Is there deep water in LoS? // Warning: these two are quite different. // diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 3e6ffac5db..faec32cacc 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -4124,7 +4124,10 @@ void monsters::wield_melee_weapon(int near) if (!weap || (!weap->cursed() && is_range_weapon(*weap))) { const item_def *alt = mslot_item(MSLOT_ALT_WEAPON); - if (alt && (!weap || !is_range_weapon(*alt))) + + // Switch to the alternate weapon if it's not a ranged weapon, too, + // or switch away from our main weapon if it's a ranged weapon. + if (alt && !is_range_weapon(*alt) || weap && !alt) swap_weapons(near); } } diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 5f48b208f1..9b3bdbba94 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -2299,6 +2299,44 @@ static bool _choose_random_patrol_target_grid(monsters *mon) //#define DEBUG_PATHFIND +// Check all grids in LoS and mark lava and/or water as seen if the +// appropriate grids are encountered, so we later only need to do the +// visibility check for monsters that can't pass a feature potentially in +// the way. We don't care about shallow water as most monsters can safely +// cross that, and fire elementals alone aren't really worth the extra +// hassle. :) +static void _check_lava_water_in_sight() +{ + // Check the player's vision for lava or deep water, + // to avoid unnecessary pathfinding later. + you.lava_in_sight = you.water_in_sight = 0; + coord_def gp; + for (gp.y = (you.y_pos - 8); (gp.y <= you.y_pos + 8); gp.y++) + for (gp.x = (you.x_pos - 8); (gp.x <= you.x_pos + 8); gp.x++) + { + if (!in_bounds(gp)) + continue; + + const coord_def ep = gp - you.pos() + coord_def(9, 9); + if (env.show(ep)) + { + dungeon_feature_type feat = grd[gp.x][gp.y]; + if (feat == DNGN_LAVA) + { + you.lava_in_sight = 1; + if (you.water_in_sight > 0) + break; + } + else if (feat == DNGN_DEEP_WATER) + { + you.water_in_sight = 1; + if (you.lava_in_sight > 0) + break; + } + } + } +} + // If a monster can see but not directly reach the player, and then fails to // find a path to get him, mark all surrounding (in a radius of 2) monsters // of the same (or greater) movement restrictions as also being unable to @@ -2355,7 +2393,7 @@ static void _mark_neighbours_player_unreachable(monsters *mon) continue; // Same for a swimming one, around water. - if (you.water_in_sight && !amphibious && mons_amphibious(m)) + if (you.water_in_sight > 0 && !amphibious && mons_amphibious(m)) continue; if (m->travel_target == MTRAV_NONE) @@ -2666,14 +2704,21 @@ static void _handle_behaviour(monsters *mon) bool potentially_blocking = trans_wall_block; // Smart monsters that can fire through walls won't use - // pathfinding. + // pathfinding, and it's also not necessary if the monster + // is already adjacent to you. if (potentially_blocking && mons_intel(mon->type) >= I_NORMAL - && mons_has_los_ability(mon->type)) + && mons_has_los_ability(mon->type) + || grid_distance(mon->x, mon->y, you.x_pos, you.y_pos) == 1) { potentially_blocking = false; } else { + // If we don't already know whether there's water or lava + // in LoS of the player, find out now. + if (you.lava_in_sight == -1 || you.water_in_sight == -1) + _check_lava_water_in_sight(); + // Flying monsters don't see water/lava as obstacle. // Also don't use pathfinding if the monster can shoot // across the blocking terrain, and is smart enough to @@ -2684,9 +2729,9 @@ static void _handle_behaviour(monsters *mon) && !mons_has_ranged_attack(mon))) { const habitat_type habit = mons_habitat(mon); - if (you.lava_in_sight && habit != HT_LAVA - || you.water_in_sight && habit != HT_WATER - && !mons_amphibious(mon)) + if (you.lava_in_sight > 0 && habit != HT_LAVA + || you.water_in_sight > 0 && habit != HT_WATER + && can_move != DNGN_DEEP_WATER) { potentially_blocking = true; } @@ -6539,7 +6584,7 @@ bool _mon_can_move_to_pos(const monsters *monster, const int count_x, const int targ_cloud_num = env.cgrid[ targ_x ][ targ_y ]; const int targ_cloud_type = targ_cloud_num == EMPTY_CLOUD ? CLOUD_NONE - : env.cloud[targ_cloud_num].type; + : env.cloud[targ_cloud_num].type; const int curr_cloud_num = env.cgrid[ monster->x ][ monster->y ]; const int curr_cloud_type = @@ -6731,7 +6776,6 @@ static bool _monster_move(monsters *monster) { FixedArray < bool, 3, 3 > good_move; int count_x, count_y, count; - int okmove = DNGN_SHALLOW_WATER; // what does this actually do? const habitat_type habitat = mons_habitat(monster); bool deep_water_available = false; @@ -6805,13 +6849,6 @@ static bool _monster_move(monsters *monster) if (mmov_x == 0 && mmov_y == 0) return (false); - if (mons_flies(monster) != FL_NONE - || habitat != HT_LAND - || mons_amphibious(monster)) - { - okmove = DNGN_MINMOVE; - } - for (count_x = 0; count_x < 3; count_x++) for (count_y = 0; count_y < 3; count_y++) { @@ -6840,9 +6877,8 @@ static bool _monster_move(monsters *monster) // Normal/smart monsters know about secret doors // (they _live_ in the dungeon!) if (grd(newpos) == DNGN_CLOSED_DOOR - || (grd(newpos) == DNGN_SECRET_DOOR - && (mons_intel(monster_index(monster)) == I_HIGH - || mons_intel(monster_index(monster)) == I_NORMAL))) + || grd(newpos) == DNGN_SECRET_DOOR + && mons_intel(monster_index(monster)) >= I_NORMAL) { if (mons_is_zombified(monster)) { diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index dac568679c..5bd01e2ff6 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -118,10 +118,10 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift, : grd[you.x_pos][you.y_pos]; const dungeon_feature_type new_grid = grd[x][y]; - // really must be clear + // Really must be clear. ASSERT( you.can_pass_through_feat( new_grid ) ); - // better not be an unsubmerged monster either: + // Better not be an unsubmerged monster either. ASSERT(mgrd[x][y] == NON_MONSTER || mons_is_submerged( &menv[ mgrd[x][y] ] )); @@ -199,7 +199,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift, } else #ifdef CLUA_BINDINGS - // prompt for any trap where you might not have enough hp + // Prompt for any trap where you might not have enough hp // as defined in init.txt (see trapwalk.lua) if (new_grid != DNGN_TRAP_MECHANICAL || !clua.callbooleanfn(false, "ch_cross_trap", @@ -222,7 +222,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift, } } - // only consider terrain if player is not levitating + // Only consider terrain if player is not levitating. if (!player_is_airborne()) { // XXX: at some point we're going to need to fix the swimming @@ -239,18 +239,18 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift, return (false); } - // have to move now so fall_into_a_pool will work + // Have to move now so fall_into_a_pool will work. you.moveto(x, y); viewwindow( true, false ); - // if true, we were shifted and so we're done. + // If true, we were shifted and so we're done. if (fall_into_a_pool( entry_x, entry_y, allow_shift, new_grid )) return (true); } else if (new_grid == DNGN_SHALLOW_WATER || new_grid == DNGN_DEEP_WATER) { - // safer water effects + // Safer water effects. if (you.species == SP_MERFOLK) { if (old_grid != DNGN_SHALLOW_WATER @@ -264,7 +264,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift, merfolk_start_swimming(); } } - else if ( !player_likes_water() ) + else if (!player_likes_water()) { ASSERT( new_grid != DNGN_DEEP_WATER ); @@ -293,7 +293,7 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift, } } - // move the player to location + // Move the player to new location. you.moveto(x, y); #ifdef USE_TILE @@ -310,15 +310,15 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift, viewwindow( true, false ); // Other Effects: - // clouds -- do we need this? (always seems to double up with acr.cc call) + // Clouds -- do we need this? (always seems to double up with acr.cc call) // if (is_cloud( you.x_pos, you.y_pos )) // in_a_cloud(); - // icy shield goes down over lava + // Icy shield goes down over lava. if (new_grid == DNGN_LAVA) expose_player_to_element( BEAM_LAVA ); - // traps go off: + // Traps go off. if (new_grid >= DNGN_TRAP_MECHANICAL && new_grid <= DNGN_UNDISCOVERED_TRAP) { id = trap_at_xy( you.x_pos, you.y_pos ); @@ -5421,8 +5421,8 @@ void player::init() banished_by.clear(); entering_level = false; - lava_in_sight = false; - water_in_sight = false; + lava_in_sight = -1; + water_in_sight = -1; transit_stair = DNGN_UNSEEN; berserk_penalty = 0; @@ -6553,7 +6553,7 @@ void player::moveto(int x, int y) void player::moveto(const coord_def &c) { - const bool real_move = c != pos(); + const bool real_move = (c != pos()); x_pos = c.x; y_pos = c.y; crawl_view.set_player_at(c); @@ -6562,6 +6562,10 @@ void player::moveto(const coord_def &c) { you.reset_prev_move(); dungeon_events.fire_position_event(DET_PLAYER_MOVED, c); + + // Reset lava/water nearness check to unknown, so it'll be + // recalculated for the next monster that tries to reach us. + you.lava_in_sight = you.water_in_sight = -1; } } diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index dc0932e8d5..d9e574c477 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -997,7 +997,7 @@ static void tag_construct_you(writer &th) marshallByte(th, you.entering_level); // lava_in_sight and water_in_sight don't need to be saved as they can - // be recalculated on game start + // be recalculated on game start. // List of currently beholding monsters (usually empty). marshallByte(th, you.beheld_by.size()); @@ -1386,9 +1386,10 @@ static void tag_read_you(reader &th, char minorVersion) you.transit_stair = static_cast<dungeon_feature_type>(unmarshallShort(th)); you.entering_level = unmarshallByte(th); + // These two need not be saved. - you.lava_in_sight = false; - you.water_in_sight = false; + you.lava_in_sight = -1; + you.water_in_sight = -1; // List of currently beholding monsters (usually empty). count_c = unmarshallByte(th); diff --git a/crawl-ref/source/terrain.cc b/crawl-ref/source/terrain.cc index fd4a204617..5a9587f8c4 100644 --- a/crawl-ref/source/terrain.cc +++ b/crawl-ref/source/terrain.cc @@ -537,7 +537,7 @@ void dungeon_terrain_changed(const coord_def &pos, set_terrain_changed(pos.x, pos.y); } -// returns true if we manage to scramble free. +// Returns true if we manage to scramble free. bool fall_into_a_pool( int entry_x, int entry_y, bool allow_shift, unsigned char terrain ) { @@ -646,7 +646,7 @@ bool fall_into_a_pool( int entry_x, int entry_y, bool allow_shift, ouch( INSTANT_DEATH, 0, KILLED_BY_WATER ); return (false); -} // end fall_into_a_pool() +} typedef std::map<std::string, dungeon_feature_type> feat_desc_map; static feat_desc_map feat_desc_cache; diff --git a/crawl-ref/source/transfor.cc b/crawl-ref/source/transfor.cc index d2f7bd9051..de89e0c9f7 100644 --- a/crawl-ref/source/transfor.cc +++ b/crawl-ref/source/transfor.cc @@ -661,7 +661,7 @@ void untransform(void) modify_stat(STAT_STRENGTH, -10, true, "losing the dragon transformation" ); - // re-check terrain now that be may no longer be flying. + // Re-check terrain now that be may no longer be flying. move_player_to_grid( you.x_pos, you.y_pos, false, true, true ); hp_downscale = 16; diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 84be11376f..3e2c847ca6 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -5232,14 +5232,12 @@ void crawl_view_geometry::set_player_at(const coord_def &c, bool centre) else { const coord_def oldc = vgrdc; - const int xmarg = - Options.scroll_margin_x + LOS_RADIUS <= viewhalfsz.x - ? Options.scroll_margin_x - : viewhalfsz.x - LOS_RADIUS; - const int ymarg = - Options.scroll_margin_y + LOS_RADIUS <= viewhalfsz.y - ? Options.scroll_margin_y - : viewhalfsz.y - LOS_RADIUS; + const int xmarg = Options.scroll_margin_x + LOS_RADIUS <= viewhalfsz.x + ? Options.scroll_margin_x + : viewhalfsz.x - LOS_RADIUS; + const int ymarg = Options.scroll_margin_y + LOS_RADIUS <= viewhalfsz.y + ? Options.scroll_margin_y + : viewhalfsz.y - LOS_RADIUS; if (Options.view_lock_x) vgrdc.x = c.x; |