git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@619 c06c8d41-db1a-0410-9941-cceddc491573
IPXXB4VRVZWOU5DKQ5ZTD37LS3QNK2R6APNZUO672YEEJT6OFAYQC
3YK4G4IQBXW63HPGU5WRTV6L2FCMKAK4DOTCHFK2FNSB5B3Y3PVQC
ODNAIEJW732NG7USKQKCIP4R4DAEYXXJQX6LY7TIN32NKE75454QC
3WRAJZ5ZLOSIZHFBUH5552QC4F3GAK7AXF6VIQFVN6VY7PUO6HPQC
SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC
RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC
547JREUJXTZNYVGHNNAET5F5O5JYYGNTDQB6ABZNT7YX5EY64OHAC
TJISAZK5RWKXIIC5UTQNY4KT3UX3ASGBUQQNWZ7ZDULPRYFRZXQQC
Q2XXRX5KFUHUQC6VJ7BMLZ6FWEUTXLUUHCIC2GS5DRGZ4VAALUIAC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
// Tracks items discovered by explore in this turn.
class LevelStashes;
class explore_discoveries
{
public:
explore_discoveries();
void found_feature(const coord_def &pos, int grid);
void found_item(const coord_def &pos, const item_def &item);
// Reports discoveries and prompts the player to stop (if necessary).
bool prompt_stop() const;
private:
template <class C> void say_any(const C &coll, const char *stub) const;
std::string cleaned_feature_description(int feature) const;
private:
template <class Z> struct named_thing {
std::string name;
Z thing;
named_thing(const std::string &n, Z t) : name(n), thing(t) { }
};
int es_flags;
const LevelStashes *current_level;
std::vector< named_thing<item_def> > items;
std::vector< named_thing<int> > stairs;
std::vector< named_thing<int> > shops;
std::vector< named_thing<int> > altars;
};
}
// Determines if the level is fully explored. Clobbers you.run_x/y.
static bool fully_explored()
{
const int oldrun = you.running;
if (!you.running.is_explore())
you.running = RMODE_EXPLORE;
// Do a second floodfill to check if the level is fully explored.
// Note we're passing in a features vector to force find_travel_pos to
// reseed past traps/deep water/lava. Icky.
std::vector<coord_def> features_dummy;
find_travel_pos(you.x_pos, you.y_pos, NULL, NULL, &features_dummy);
you.running = oldrun;
return !(you.running.x > 0 && you.running.y > 0);
#define ES_shop ((Options.explore_stop & ES_SHOP) && \
es_say("a shop") && prompt_stop_explore(ES_SHOP))
#define ES_stair ((Options.explore_stop & ES_STAIR) && \
es_say("a stair") && prompt_stop_explore(ES_STAIR))
#define ES_shop (Options.explore_stop & ES_SHOP)
#define ES_stair (Options.explore_stop & ES_STAIR)
#define ES_altar (Options.explore_stop & ES_ALTAR)
if (ES_item && igrd[x + 1][y + 1] != NON_ITEM)
{
bool valid_stop = true;
if (you.running == RMODE_EXPLORE_GREEDY)
{
// The things we need to do...
const LevelStashes *lev = stashes.find_current_level();
if (lev && lev->needs_visit(x + 1, y + 1))
valid_stop = false;
}
if (valid_stop)
{
mprf("Found %s.",
item_name( mitm[ igrd[x + 1][y + 1] ], DESC_NOCAP_A ));
if (prompt_stop_explore(ES_ITEM))
return (true);
}
}
coord_def pos(x + 1, y + 1);
if (ES_item && igrd(pos) != NON_ITEM)
ed.found_item( pos, mitm[ igrd(pos) ] );
unsigned char grid = grd[x + 1][y + 1];
return (grid == DNGN_ENTER_SHOP && you.running != RMODE_EXPLORE_GREEDY
&& ES_shop)
|| (is_stair(grid) && ES_stair)
|| (is_altar(grid)
&& you.where_are_you != BRANCH_ECUMENICAL_TEMPLE
&& ES_altar);
ed.found_feature( pos, grd(pos) );
std::string explore_discoveries::cleaned_feature_description(int grid) const
{
std::string s = lowercase_first(feature_description(grid));
if (s.length() && s[s.length() - 1] == '.')
{
s.erase(s.length() - 1);
}
return (s);
}
void explore_discoveries::found_feature(const coord_def &pos, int grid)
{
if (grid == DNGN_ENTER_SHOP && ES_shop)
{
shops.push_back( named_thing<int>( shop_name(pos.x, pos.y), grid ) );
es_flags |= ES_SHOP;
}
else if (is_stair(grid) && ES_stair)
{
stairs.push_back(
named_thing<int>(
cleaned_feature_description(grid), grid ) );
es_flags |= ES_STAIR;
}
else if (is_altar(grid) && ES_altar)
{
altars.push_back(
named_thing<int>(
cleaned_feature_description(grid), grid ) );
es_flags |= ES_ALTAR;
}
}
void explore_discoveries::found_item(const coord_def &pos, const item_def &i)
{
if (you.running == RMODE_EXPLORE_GREEDY)
{
// The things we need to do...
if (!current_level)
current_level = stashes.find_current_level();
if (current_level && current_level->needs_visit(pos.x, pos.y))
return;
}
items.push_back( named_thing<item_def>(item_name(i, DESC_NOCAP_A), i) );
es_flags |= ES_ITEM;
}
template <class C> void explore_discoveries::say_any(
const C &coll, const char *stub) const
{
if (coll.empty())
return;
const std::string message = "Found " +
comma_separated_line(coll.begin(), coll.end()) + ".";
if ((int) message.length() >= get_number_of_cols())
mprf(stub, coll.size());
else
mprf("%s", message.c_str());
}
bool explore_discoveries::prompt_stop() const
{
if (!es_flags)
return (false);
say_any(items, "Found %u items.");
say_any(stairs, "Found %u stairs.");
say_any(altars, "Found %u altars.");
say_any(shops, "Found %u shops.");
return ((Options.explore_stop_prompt & es_flags) != es_flags
|| prompt_stop_explore(es_flags));
}