diff options
author | Aj Adamson <aj.k.adamson@gmail.com> | 2014-06-23 12:23:14 -0600 |
---|---|---|
committer | Neil Moore <neil@s-z.org> | 2014-07-01 22:55:21 -0400 |
commit | 6f411d1547278c84dff7c0003e4ffe350d566e50 (patch) | |
tree | 0f371951d5ab886463078843ca6708286728fa38 /crawl-ref/source/mon-util.cc | |
parent | 18cebf10d87e656198b010574d219ade9a37df8e (diff) | |
download | crawl-ref-6f411d1547278c84dff7c0003e4ffe350d566e50.tar.gz crawl-ref-6f411d1547278c84dff7c0003e4ffe350d566e50.zip |
Add getting monster spells to clua m:spells() (#8737)
[Committer's note: squashed two commits. The second commit's message
was:
changed clua moninfo:spells() to return book sets/string tables like
describe.cc monster_info has_spells based on mostly on spellbooks.
describe and clua moninfo:spells's shared code moves to
mon-book.h/mon-util.cc
-neil]
Diffstat (limited to 'crawl-ref/source/mon-util.cc')
-rw-r--r-- | crawl-ref/source/mon-util.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 8b6cfd753f..b102e0473b 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -2303,6 +2303,43 @@ vector<mon_spellbook_type> get_spellbooks(const monster_info &mon) return books; } +// get a list of unique spells from a monster's preset spellbooks +// or in the case of ghosts their actual spells. +unique_books get_unique_spells(const monster_info &mi) +{ + const vector<mon_spellbook_type> books = get_spellbooks(mi); + const size_t num_books = books.size(); + + unique_books result; + for (size_t i = 0; i < num_books; ++i) + { + mon_spellbook_type book = books[i]; + vector<spell_type> spells; + + for (int j = 0; j < NUM_MONSTER_SPELL_SLOTS; ++j) + { + spell_type spell; + if (book == MST_GHOST) + spell = mi.spells[j]; + else + spell = mspell_list[book].spells[j]; + + bool match = false; + + for (size_t k = 0; k < spells.size(); ++k) + if (spell == spells[k]) + match = true; + + if (!match && spell != SPELL_NO_SPELL && spell != SPELL_MELEE) + spells.push_back(spell); + } + + result.push_back(spells); + } + + return result; +} + static void _mons_load_spells(monster* mon) { vector<mon_spellbook_type> books = _mons_spellbook_list(mon->type); |