From e2d1b5dfa2a106a40db5ab6a23e6eb19e3aae8ca Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Sat, 9 Aug 2008 12:27:44 +0000 Subject: Rework xx and V to use monster_pane_info() to benefit from the difficulty comparison and sorting functions. Make V work as a shortcut for xx, but keep the original monster listing (now repaired) for the dump. Most of the monster_pane_function struct and functions are now also included in Tiles compiles, even though the monster list itself is still not available. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6800 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 2 +- crawl-ref/source/directn.cc | 31 ++++++------ crawl-ref/source/directn.h | 2 + crawl-ref/source/output.cc | 120 +++++++++++++++----------------------------- crawl-ref/source/output.h | 4 +- 5 files changed, 59 insertions(+), 100 deletions(-) diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 754da29a37..cb9454e8c8 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -2048,7 +2048,7 @@ void process_command( command_type cmd ) break; case CMD_FULL_VIEW: - mpr(mpr_monster_list().c_str()); + full_describe_view(); break; case CMD_WIELD_WEAPON: diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc index 095f917f1d..8a7cdd856d 100644 --- a/crawl-ref/source/directn.cc +++ b/crawl-ref/source/directn.cc @@ -448,34 +448,27 @@ static void _direction_again(dist& moves, targeting_type restricts, static void _describe_monster(const monsters *mon); // Lists all the monsters and items currently in view by the player. -// Internals: -// Menu items have meaningful tags. 'i' means item and 'm' means monster. -// -void _full_describe_view() +// TODO: Allow sorting of items lists. +void full_describe_view() { const coord_def start = view2grid(coord_def(1,1)); const coord_def end(start.x + crawl_view.viewsz.x, start.y + crawl_view.viewsz.y); - std::vector list_mons; + std::vector list_mons; std::vector list_items; coord_def p; - // Iterate over viewport and get all the items and monsters in view. - // TODO: Allow sorting of monster and items lists. + // Iterate over viewport and get all the itemsin view. for (p.x = start.x; p.x < end.x; p.x++) for (p.y = start.y; p.y < end.y; p.y++) { if (!in_bounds(p.x,p.y) || !see_grid(p.x,p.y)) continue; - const int mid = mgrd(p); const int oid = igrd(p); - if (mid != NON_MONSTER && player_monster_visible(&menv[mid])) - list_mons.push_back(&menv[mid]); - if (oid != NON_ITEM) { std::vector items; @@ -484,6 +477,14 @@ void _full_describe_view() } } + // Get monsters via the monster_pane_info, sorted by difficulty. + std::vector mons; + get_monster_pane_info(mons); + std::sort(mons.begin(), mons.end(), monster_pane_info::less_than_wrapper); + + for (unsigned int i = 0; i < mons.size(); i++) + list_mons.push_back(mons[i].m_mon); + if (!list_mons.size() && !list_items.size()) { mprf("Neither monsters nor items are visible."); @@ -508,7 +509,7 @@ void _full_describe_view() for (unsigned int i = 0; i < list_mons.size(); ++i) { // List monsters in the form - // (g) A goblin (hostile) wielding an orcish dagger + // (A) An angel (neutral), wielding a glowing long sword ++menu_index; const char letter = index_to_letter(menu_index); @@ -1316,9 +1317,7 @@ void direction(dist& moves, targeting_type restricts, break; case CMD_TARGET_ALL_DESCRIBE: - _full_describe_view(); - //TODO: Check if this is neccesary - //force_redraw = true; + full_describe_view(); break; case CMD_TARGET_HELP: @@ -2796,8 +2795,6 @@ std::string get_monster_desc(const monsters *mon, bool full_desc, desc += " (friendly)"; else if (mons_neutral(mon)) desc += " (neutral)"; - else - desc += " (hostile)"; } } diff --git a/crawl-ref/source/directn.h b/crawl-ref/source/directn.h index b7912fa4c1..65b28778fd 100644 --- a/crawl-ref/source/directn.h +++ b/crawl-ref/source/directn.h @@ -180,6 +180,8 @@ std::string feature_description(dungeon_feature_type grid, std::vector features_by_desc(const base_pattern &pattern); +void full_describe_view(void); + inline int view2gridX(int vx) { return (crawl_view.vgrdc.x + vx - crawl_view.view_centre().x); diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc index 117418492b..13ba0540c2 100644 --- a/crawl-ref/source/output.cc +++ b/crawl-ref/source/output.cc @@ -1010,9 +1010,11 @@ static bool _mons_hostile(const monsters *mon) return (!mons_friendly(mon) && !mons_neutral(mon)); } -static std::string _get_monster_name(const monsters *mon, bool list_a = false) +static std::string _get_monster_name(const monster_pane_info& m, + int count) { std::string desc = ""; + const monsters *mon = m.m_mon; bool adj = false; if (mons_friendly(mon)) @@ -1026,29 +1028,23 @@ static std::string _get_monster_name(const monsters *mon, bool list_a = false) adj = true; } - if (adj && list_a) - { - desc = (mon->is_named() ? "the " : "a ") + desc; - list_a = false; - } + std::string monpane_desc; + int col; + m.to_string(count, monpane_desc, col); - if (mons_is_mimic(mon->type)) - { - if (list_a) - desc += "a "; - desc += "mimic"; - } - else + if (count == 1) { - desc += mon->name(list_a ? DESC_NOCAP_A : DESC_PLAIN); - if (!(mon->mname).empty()) + if (!mon->is_named()) { - desc += " ("; - desc += mons_type_name(mon->type, DESC_PLAIN); - desc += ")"; + desc = ((!adj && is_vowel(monpane_desc[0])) ? "an " + : "a ") + + desc; } + else if (adj) + desc = "the " + desc; } + desc += monpane_desc; return (desc); } @@ -1056,7 +1052,7 @@ static std::string _get_monster_name(const monsters *mon, bool list_a = false) // hostile/neutral/friendly) than the second, or, if both monsters share the // same attitude, if the first monster has a lower type. // If monster type and attitude are the same, return false. -static bool _compare_monsters_attitude( const monsters *m1, const monsters *m2 ) +bool compare_monsters_attitude( const monsters *m1, const monsters *m2 ) { if (_mons_hostile(m1) && !_mons_hostile(m2)) return (true); @@ -1077,77 +1073,39 @@ static bool _compare_monsters_attitude( const monsters *m1, const monsters *m2 ) return (m1->type < m2->type); } -static void _get_visible_monsters(std::vector& describe) +// If past is true, the messages should be printed in the past tense +// because they're needed for the morgue dump. +std::string mpr_monster_list(bool past) { - std::vector mons; + // Get monsters via the monster_pane_info, sorted by difficulty. + std::vector mons; + get_monster_pane_info(mons); - // monster check - for (radius_iterator ri(you.pos(), LOS_RADIUS); ri; ++ri ) + std::string msg = ""; + if (mons.empty()) { - if ( mgrd(*ri) != NON_MONSTER ) - { - const monsters *mon = &menv[mgrd(*ri)]; - if (player_monster_visible(mon) - && !mons_is_submerged(mon) - && (!mons_is_mimic(mon->type) - || testbits(mon->flags, MF_KNOWN_MIMIC))) - { - mons.push_back(mon); - } - } - } + msg = "There "; + msg += (past ? "were" : "are"); + msg += " no monsters in sight!"; - if (mons.empty()) - return; + return (msg); + } - std::sort( mons.begin(), mons.end(), _compare_monsters_attitude ); + std::sort(mons.begin(), mons.end(), monster_pane_info::less_than_wrapper); + std::vector describe; int count = 0; - int size = mons.size(); - for (int i = 0; i < size; ++i) + for (unsigned int i = 0; i < mons.size(); ++i) { - if (i > 0 && _compare_monsters_attitude(mons[i-1], mons[i])) + if (i > 0 && monster_pane_info::less_than(mons[i-1], mons[i])) { - if (count == 1) - describe.push_back(_get_monster_name(mons[i-1], true).c_str()); - else - { - describe.push_back(number_in_words(count) + " " - + pluralise(_get_monster_name(mons[i-1]).c_str())); - } + describe.push_back(_get_monster_name(mons[i-1], count).c_str()); count = 0; } count++; } - // handle last monster - if (mons.size() == 1 - || _compare_monsters_attitude(mons[size-2], mons[size-1])) - { - describe.push_back(_get_monster_name(mons[size-1], true).c_str()); - } - else - { - describe.push_back(number_in_words(count) + " " - + pluralise(_get_monster_name(mons[size-1]).c_str())); - } -} -// If past is true, the messages should be printed in the past tense -// because they're needed for the morgue dump. -std::string mpr_monster_list(bool past) -{ - std::vector describe; - _get_visible_monsters(describe); - - std::string msg = ""; - if (describe.empty()) - { - msg = "There "; - msg += (past ? "were" : "are"); - msg += " no monsters in sight!"; - - return (msg); - } + describe.push_back(_get_monster_name(mons[mons.size()-1], count).c_str()); msg = "You "; msg += (past ? "could" : "can"); @@ -1165,7 +1123,6 @@ std::string mpr_monster_list(bool past) return (msg); } -#ifndef USE_TILE monster_pane_info::monster_pane_info(const monsters *m) : m_mon(m), m_attitude(ATT_HOSTILE), m_difficulty(0), m_brands(0), m_fullname(true) @@ -1177,7 +1134,7 @@ monster_pane_info::monster_pane_info(const monsters *m) m_attitude = mons_attitude(m); int mtype = m->type; - if ( mtype == MONS_RAKSHASA_FAKE ) + if (mtype == MONS_RAKSHASA_FAKE) mtype = MONS_RAKSHASA; // Currently, difficulty is defined as "average hp". Leaks too much info? @@ -1213,9 +1170,9 @@ bool monster_pane_info::less_than(const monster_pane_info& m1, int m2type = m2.m_mon->type; // Don't differentiate real rakshasas from fake ones. - if ( m1type == MONS_RAKSHASA_FAKE ) + if (m1type == MONS_RAKSHASA_FAKE) m1type = MONS_RAKSHASA; - if ( m2type == MONS_RAKSHASA_FAKE ) + if (m2type == MONS_RAKSHASA_FAKE) m2type = MONS_RAKSHASA; // Force plain but different coloured draconians to be treated like the @@ -1360,6 +1317,7 @@ void monster_pane_info::to_string( int count, std::string& desc, desc = out.str(); } +#ifndef USE_TILE static char _mlist_index_to_letter(int index) { index += 'a'; @@ -1484,6 +1442,7 @@ static void _print_next_monster_desc(const std::vector& mons, start = end; textcolor(LIGHTGREY); } +#endif void get_monster_pane_info(std::vector& mons) { @@ -1500,6 +1459,7 @@ void get_monster_pane_info(std::vector& mons) std::sort(mons.begin(), mons.end(), monster_pane_info::less_than_wrapper); } +#ifndef USE_TILE #define BOTTOM_JUSTIFY_MONSTER_LIST 0 // Returns -1 if the monster list is empty, 0 if there are so many monsters // they have to be consolidated, and 1 otherwise. diff --git a/crawl-ref/source/output.h b/crawl-ref/source/output.h index 61e524a732..a762edb19d 100644 --- a/crawl-ref/source/output.h +++ b/crawl-ref/source/output.h @@ -51,6 +51,8 @@ void update_turn_count(void); void print_stats(void); void print_stats_level(void); void draw_border(void); +bool compare_monsters_attitude( const monsters *m1, const monsters *m2 ); + std::string mpr_monster_list(bool past = false); void redraw_skill(const std::string &your_name, const std::string &class_name); int update_monster_pane(void); @@ -65,7 +67,6 @@ void print_overview_screen(void); std::string dump_overview_screen(bool full_id); -#ifndef USE_TILE // Monster info used by the pane; precomputes some data // to help with sorting and rendering. class monster_pane_info @@ -89,6 +90,5 @@ class monster_pane_info }; void get_monster_pane_info(std::vector& mons); -#endif #endif -- cgit v1.2.3-54-g00ecf