Skip to content

Commit

Permalink
Fix an issue where trying to cast a spell causes
Browse files Browse the repository at this point in the history
the wrong spell to be cast
currently selecting a spell in a long sorted spell
list will cast the wrong spell due to select spell returing a sorted
spell id while handle_action.cpp looks only at the unsorted spells

fixes #76042
Fix an issue where trying to cast a spell causes
the wrong spell to be cast
  • Loading branch information
ThePotatomancer committed Sep 2, 2024
1 parent 746a170 commit 41d9795
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/magic.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "magic.h"
#include "magic.h"

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -2238,6 +2239,19 @@ std::vector<spell *> 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;
Expand Down Expand Up @@ -2906,7 +2920,9 @@ int known_magic::select_spell( Character &guy )

casting_ignore = static_cast<spellcasting_callback *>( 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 )
Expand Down
2 changes: 2 additions & 0 deletions src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ class known_magic
std::vector<spell_id> 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 );
Expand Down

0 comments on commit 41d9795

Please sign in to comment.