diff options
author | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-12-06 09:54:50 +0000 |
---|---|---|
committer | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-12-06 09:54:50 +0000 |
commit | 47173f1092b4f4f3bdc0da19d6dc4553f62cdee7 (patch) | |
tree | b5d87980beec66a00b2314ca94475ac2715e71ae /crawl-ref/source/mon-util.cc | |
parent | 7640ea1ef75cecb46066e956ec446038c884643c (diff) | |
download | crawl-ref-47173f1092b4f4f3bdc0da19d6dc4553f62cdee7.tar.gz crawl-ref-47173f1092b4f4f3bdc0da19d6dc4553f62cdee7.zip |
"?/" can now be used to look up items. A side effect of this is that
item descriptions have been moved to dat/descript/items.txt and
dat/descript/unident.txt.
STL maps are now used to look up exact matches for the names of monsters,
features and spells, so that looking them up with "?/" won't get too
slow if there's a large descriptions DB and each key has to be tested
if its a monster/spell/etc.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3009 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/mon-util.cc')
-rw-r--r-- | crawl-ref/source/mon-util.cc | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 2510ed4c63..3fe34bb2f7 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -162,10 +162,37 @@ monster_type random_monster_at_grid(int grid) : valid_mons[ random2(valid_mons.size()) ]; } +typedef std::map<std::string, unsigned> mon_name_map; +static mon_name_map mon_name_cache; + +void init_mon_name_cache() +{ + for (unsigned i = 0; i < sizeof(mondata) / sizeof(*mondata); ++i) + { + std::string name = mondata[i].name; + lowercase(name); + + const int mtype = mondata[i].mc; + const monster_type mon = monster_type(mtype); + + mon_name_cache[name] = mon; + } +} + monster_type get_monster_by_name(std::string name, bool exact) { lowercase(name); + if (exact) + { + mon_name_map::iterator i = mon_name_cache.find(name); + + if (i != mon_name_cache.end()) + return static_cast<monster_type>(i->second); + + return MONS_PROGRAM_BUG; + } + monster_type mon = MONS_PROGRAM_BUG; for (unsigned i = 0; i < sizeof(mondata) / sizeof(*mondata); ++i) { @@ -174,14 +201,6 @@ monster_type get_monster_by_name(std::string name, bool exact) const int mtype = mondata[i].mc; - if (exact) - { - if (name == candidate) - return monster_type(mtype); - - continue; - } - const std::string::size_type match = candidate.find(name); if (match == std::string::npos) continue; |