summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/debug.cc
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-07 09:54:43 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-07 09:54:43 +0000
commitecffe9770e544d7d3df5e225d838cbe68b3bdbd1 (patch)
treea829b5b9240f59837e2be0f9d1f4ef2e1979d518 /crawl-ref/source/debug.cc
parent0ad9c71a19f44094b7108cc0d09a1b4b5ff46ad6 (diff)
downloadcrawl-ref-ecffe9770e544d7d3df5e225d838cbe68b3bdbd1.tar.gz
crawl-ref-ecffe9770e544d7d3df5e225d838cbe68b3bdbd1.zip
Organize and condense the monster list printed by the list monsters
wizard command (&"). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5531 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/debug.cc')
-rw-r--r--crawl-ref/source/debug.cc60
1 files changed, 58 insertions, 2 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index cf5340e2b9..0516fe5816 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -698,20 +698,76 @@ void wizard_interlevel_travel()
_wizard_go_to_level(pos);
}
+static bool _sort_monster_list(int a, int b)
+{
+ if (a >= MAX_MONSTERS || b >= MAX_MONSTERS)
+ {
+ mprf("a = %d, b = %d", a, b);
+ }
+
+ const monsters* m1 = &menv[a];
+ const monsters* m2 = &menv[b];
+
+ if (m1->type == m2->type)
+ {
+ if (!m1->alive() || !m2->alive())
+ return false;
+
+ return ( m1->name(DESC_PLAIN, true) < m2->name(DESC_PLAIN, true) );
+ }
+
+ if (mons_char(m1->type) < mons_char(m2->type))
+ return true;
+
+ return (m1->type < m2->type);
+}
+
void debug_list_monsters()
{
std::vector<std::string> mons;
int nfound = 0;
+ int mon_nums[MAX_MONSTERS];
+
+ for (int i = 0; i < MAX_MONSTERS; i++)
+ mon_nums[i] = i;
+
+ std::sort(mon_nums, mon_nums + MAX_MONSTERS, _sort_monster_list);
+
+ std::string prev_name = "";
+ int count = 0;
+
for (int i = 0; i < MAX_MONSTERS; ++i)
{
- const monsters *m = &menv[i];
+ const monsters *m = &menv[mon_nums[i]];
if (!m->alive())
continue;
- mons.push_back(m->name(DESC_PLAIN, true));
+ std::string name = m->name(DESC_PLAIN, true);
+
+ if (prev_name != name && count > 0)
+ {
+ char buf[80];
+ if (count > 1)
+ sprintf(buf, "%d %s", count, pluralise(prev_name).c_str());
+ else
+ sprintf(buf, "%s", prev_name.c_str());
+ mons.push_back(buf);
+
+ count = 0;
+ }
nfound++;
+ count++;
+ prev_name = name;
}
+
+ char buf[80];
+ if (count > 1)
+ sprintf(buf, "%d %s", count, pluralise(prev_name).c_str());
+ else
+ sprintf(buf, "%s", prev_name.c_str());
+ mons.push_back(buf);
+
mpr_comma_separated_list("Monsters: ", mons);
mprf("%d monsters", nfound);
}