diff --git a/src/magic.cpp b/src/magic.cpp index bf34c56064ba4..30f91352ba6d0 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -1,4 +1,5 @@ #include "magic.h" +#include "magic.h" #include #include @@ -2238,6 +2239,19 @@ std::vector known_magic::get_spells() return spells; } +int known_magic::get_spell_index( const spell_id& sp ) +{ + int current_index = -1, result_index = -1; + for (auto& spell_pair : spellbook) { + current_index++; + if (spell_pair.first == sp) { + result_index = current_index; + break; + } + } + return result_index; +} + int known_magic::available_mana() const { return mana; @@ -2906,7 +2920,9 @@ int known_magic::select_spell( Character &guy ) casting_ignore = static_cast( spell_menu.callback )->casting_ignore; - return spell_menu.ret; + spell* selected_spell = known_spells_sorted[spell_menu.ret]; + int original_spell_index = get_spell_index(selected_spell->id()); + return original_spell_index; } void known_magic::on_mutation_gain( const trait_id &mid, Character &guy ) diff --git a/src/magic.h b/src/magic.h index 93b94b343f889..b50374428fb16 100644 --- a/src/magic.h +++ b/src/magic.h @@ -688,6 +688,8 @@ class known_magic std::vector spells() const; // gets the spell associated with the spell_id to be edited spell &get_spell( const spell_id &sp ); + // gets the index of a spell in the get_spells vector + int get_spell_index(const spell_id& sp); // opens up a ui that the Character can choose a spell from // returns the index of the spell in the vector of spells int select_spell( Character &guy );