From c68ef2df6780db4bd3b16a50de06f7f528a31336 Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Mon, 4 May 2009 19:20:28 +0000 Subject: * Some more tweaks to the spellcasting interface. * Colour items out of range darkgrey, like we do for floor/monsters. * Fix berserk monsters choosing one of the nearest monsters randomly. (Seriously, I must have been half asleep when I wrote that.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9733 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/directn.cc | 21 ++++++++++++++++++--- crawl-ref/source/directn.h | 1 + crawl-ref/source/monstuff.cc | 38 ++++++++++++++++++-------------------- crawl-ref/source/spl-cast.cc | 4 ++-- crawl-ref/source/view.cc | 5 +++-- 5 files changed, 42 insertions(+), 27 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc index 6ce2cd4fb0..4a98350a56 100644 --- a/crawl-ref/source/directn.cc +++ b/crawl-ref/source/directn.cc @@ -881,13 +881,22 @@ range_view_annotator::range_view_annotator(int range) { // Save and replace grid colours. -1 means unchanged. orig_colours.init(-1); + orig_item_colours.init(-1); const coord_def offset(ENV_SHOW_OFFSET, ENV_SHOW_OFFSET); for (radius_iterator ri(you.pos(), LOS_RADIUS); ri; ++ri) { if (grid_distance(you.pos(), *ri) > range) { - orig_colours(*ri - you.pos() + offset) = env.grid_colours(*ri); + const coord_def showpos = *ri - you.pos() + offset; + + orig_colours(showpos) = env.grid_colours(*ri); env.grid_colours(*ri) = DARKGREY; + + if (igrd(*ri) != NON_ITEM) + { + orig_item_colours(showpos) = mitm[igrd(*ri)].colour; + mitm[igrd(*ri)].colour = DARKGREY; + } } } @@ -927,9 +936,15 @@ void range_view_annotator::restore_state() for (c.x = 0; c.x < ENV_SHOW_DIAMETER; ++c.x) for (c.y = 0; c.y < ENV_SHOW_DIAMETER; ++c.y) { - const int old_colour = orig_colours(c); + const coord_def pos = you.pos() + c - offset; + + int old_colour = orig_colours(c); if (old_colour != -1) - env.grid_colours(you.pos() + c - offset) = old_colour; + env.grid_colours(pos) = old_colour; + + old_colour = orig_item_colours(c); + if (old_colour != -1 && igrd(pos) != NON_ITEM) + mitm[igrd(pos)].colour = old_colour; } // Restore monster colours. diff --git a/crawl-ref/source/directn.h b/crawl-ref/source/directn.h index a465565e87..94d48de4a5 100644 --- a/crawl-ref/source/directn.h +++ b/crawl-ref/source/directn.h @@ -26,6 +26,7 @@ public: private: bool do_anything; FixedArray orig_colours; + FixedArray orig_item_colours; int orig_mon_colours[MAX_MONSTERS]; }; diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 1c3be21281..125739af66 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -4408,32 +4408,30 @@ static bool _mons_check_set_foe(monsters *mon, const coord_def& p, return (false); } -// Choose nearest monster as a foe. (Used for berserking monsters.) +// Choose random nearest monster as a foe. (Used for berserking monsters.) void _set_nearest_monster_foe(monsters *mon) { const bool friendly = mons_friendly_real(mon); const bool neutral = mons_neutral(mon); - std::vector d; - d.push_back(coord_def(-1,-1)); - d.push_back(coord_def( 0,-1)); - d.push_back(coord_def( 1,-1)); - d.push_back(coord_def(-1, 0)); - d.push_back(coord_def( 1, 0)); - d.push_back(coord_def(-1, 1)); - d.push_back(coord_def( 0, 1)); - d.push_back(coord_def( 1, 1)); - - // Search the eight possible directions in random order, with increasing - // distance from the monster. - std::random_shuffle(d.begin(), d.end(), random2); for (int k = 1; k <= LOS_RADIUS; ++k) - for (unsigned int i = 0; i < d.size(); i++) - { - const coord_def p = mon->pos() + coord_def(k*d[i].x, k*d[i].y); - if (_mons_check_set_foe(mon, p, friendly, neutral)) - return; - } + { + int count = 0; + bool success = false; + for (int i = -k; i <= k; ++i) + for (int j = -k; j <= k; (abs(i) == k ? j++ : j += 2*k)) + { + const coord_def p = mon->pos() + coord_def(i, j); + if (one_chance_in(++count) + && _mons_check_set_foe(mon, p, friendly, neutral)) + { + success = true; + } + } + + if (success) + break; + } } // The default suitable() function for choose_random_nearby_monster(). diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 7d8a5784b9..619b67d864 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -670,7 +670,7 @@ bool cast_a_spell(bool check_range) return (false); } - const int minRange = (check_range ? _get_dist_to_nearest_monster() : -1); + const int minRange = _get_dist_to_nearest_monster(); int keyin = (check_range ? 0 : '?'); @@ -730,7 +730,7 @@ bool cast_a_spell(bool check_range) return (false); } - if (_spell_no_hostile_in_range(spell, minRange)) + if (check_range && _spell_no_hostile_in_range(spell, minRange)) { mpr("There are no visible monsters within range! (Use Z to cast anyway.)"); return (false); diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 3e4b047e75..e5b31c63ab 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -1462,7 +1462,7 @@ static int _get_item_dngn_code(const item_def &item) inline static void _update_item_grid(const coord_def &gp, const coord_def &ep) { const item_def &eitem = mitm[igrd(gp)]; - unsigned short &ecol = env.show_col(ep); + unsigned short &ecol = env.show_col(ep); const dungeon_feature_type grid = grd(gp); if (Options.feature_item_brand && is_critical_feature(grid)) @@ -1491,11 +1491,12 @@ inline static void _update_item_grid(const coord_def &gp, const coord_def &ep) void item_grid() { const coord_def c(crawl_view.glosc()); + const coord_def offset(ENV_SHOW_OFFSET, ENV_SHOW_OFFSET); for (radius_iterator ri(c, LOS_RADIUS, true, false); ri; ++ri) { if (igrd(*ri) != NON_ITEM) { - const coord_def ep = *ri - c + coord_def(9, 9); + const coord_def ep = *ri - c + offset; if (env.show(ep)) _update_item_grid(*ri, ep); } -- cgit v1.2.3-54-g00ecf