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-info.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-info.cc')
-rw-r--r-- | crawl-ref/source/mon-info.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/crawl-ref/source/mon-info.cc b/crawl-ref/source/mon-info.cc index 6a80d96f9f..9f0941fcf5 100644 --- a/crawl-ref/source/mon-info.cc +++ b/crawl-ref/source/mon-info.cc @@ -23,6 +23,7 @@ #include "los.h" #include "message.h" #include "misc.h" +#include "mon-book.h" #include "mon-chimera.h" #include "mon-util.h" #include "monster.h" @@ -1805,6 +1806,34 @@ bool monster_info::ground_level() const return !airborne() && !is(MB_CLINGING); } +// Only checks for spells from preset monster spellbooks. +// Use monster.h's has_spells for knowing a monster has spells +bool monster_info::has_spells() const +{ + const vector<mon_spellbook_type> books = get_spellbooks(*this); + + const size_t num_books = books.size(); + + // Random pan lords don't display their spells. + if (num_books == 0 || books[0] == MST_NO_SPELLS || this->type == MONS_PANDEMONIUM_LORD) + return false; + + // Ghosts have a special book but may not have any spells anyways. + if (books[0] == MST_GHOST) + { + bool has_spell = false; + for (int i = 0; i < NUM_MONSTER_SPELL_SLOTS; ++i) + { + if (this->spells[i] != SPELL_NO_SPELL) + has_spell = true; + } + if (!has_spell) + return false; + } + + return true; +} + void get_monster_info(vector<monster_info>& mons) { vector<monster* > visible; |