From c38c79b12b60b4b52a9d275b72c3fc682acf8d08 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 18 Jan 2025 16:02:53 -0600 Subject: [PATCH] no default repeat spells & buf message when none stored Fix #535 --- src/game/boe.main.cpp | 2 +- src/game/boe.party.cpp | 37 +++++++++++++++++++++++++++++-------- src/universe/pc.hpp | 2 +- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/game/boe.main.cpp b/src/game/boe.main.cpp index 9145ae5c..d96bd930 100644 --- a/src/game/boe.main.cpp +++ b/src/game/boe.main.cpp @@ -147,7 +147,7 @@ eStatMode stat_screen_mode; short anim_step = -1; // Spell casting globals -eSpell store_mage = eSpell::LIGHT, store_priest = eSpell::BLESS_MINOR; +eSpell store_mage = eSpell::NONE, store_priest = eSpell::NONE; short store_mage_lev = 0, store_priest_lev = 0; short store_spell_target = 6,pc_casting; short num_targets_left = 0; diff --git a/src/game/boe.party.cpp b/src/game/boe.party.cpp index 5684fc8e..138aa48a 100644 --- a/src/game/boe.party.cpp +++ b/src/game/boe.party.cpp @@ -52,6 +52,11 @@ short combat_percent[20] = { 70,70,67,62,57,52,47,42,40,40}; short who_cast,which_pc_displayed; +// Light can be cast in or out of combat +const eSpell DEFAULT_SELECTED_MAGE = eSpell::LIGHT; +// Bless can only be cast in combat, so separate defaults are needed +const eSpell DEFAULT_SELECTED_PRIEST = eSpell::HEAL_MINOR; +const eSpell DEFAULT_SELECTED_PRIEST_COMBAT = eSpell::BLESS_MINOR; eSpell town_spell; extern bool spell_freebie; extern eSpecCtxType spec_target_type; @@ -490,6 +495,13 @@ bool repeat_cast_ok(eSkill type) { what_spell = univ.party[who_would_cast].last_cast[type]; else what_spell = type == eSkill::MAGE_SPELLS ? store_mage : store_priest; + if(what_spell == eSpell::NONE){ + std::ostringstream sout; + sout << "Repeat cast: No " << (type == eSkill::MAGE_SPELLS ? "mage" : "priest") << " spell stored."; + add_string_to_buf(sout.str()); + return false; + } + if(!pc_can_cast_spell(univ.party[who_would_cast],what_spell)) { add_string_to_buf("Repeat cast: Can't cast."); return false; @@ -1947,7 +1959,7 @@ static bool finish_pick_spell(cDialog& me, bool spell_toast, const short store_s //short situation; // 0 - out 1 - town 2 - combat eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num using namespace std::placeholders; - eSpell store_spell = type == eSkill::MAGE_SPELLS ? store_mage : store_priest; + eSpell default_spell = type == eSkill::MAGE_SPELLS ? store_mage : store_priest; short former_target = store_spell_target; short dark = 6; @@ -1995,29 +2007,38 @@ eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num // If in combat, make the spell being cast this PCs most recent spell if(is_combat()) { if(type == eSkill::MAGE_SPELLS) - store_spell = univ.party[pc_casting].last_cast[eSkill::MAGE_SPELLS]; - else store_spell = univ.party[pc_casting].last_cast[eSkill::PRIEST_SPELLS]; + default_spell = univ.party[pc_casting].last_cast[eSkill::MAGE_SPELLS]; + else{ + default_spell = univ.party[pc_casting].last_cast[eSkill::PRIEST_SPELLS]; + if(default_spell == eSpell::NONE){ + default_spell = DEFAULT_SELECTED_PRIEST_COMBAT; + } + } } + if(default_spell == eSpell::NONE){ + default_spell = type == eSkill::MAGE_SPELLS ? DEFAULT_SELECTED_MAGE : DEFAULT_SELECTED_PRIEST; + } + // Keep the stored spell, if it's still castable - if(!pc_can_cast_spell(univ.party[pc_casting],store_spell)) { + if(!pc_can_cast_spell(univ.party[pc_casting],default_spell)) { if(type == eSkill::MAGE_SPELLS) { - store_spell = eSpell::LIGHT; + default_spell = DEFAULT_SELECTED_MAGE; } else { - store_spell = eSpell::HEAL_MINOR; + default_spell = DEFAULT_SELECTED_PRIEST; } } // If a target is needed, keep the same target if that PC still targetable if(store_spell_target < 6) { - if((*store_spell).need_select != SELECT_NO) { + if((*default_spell).need_select != SELECT_NO) { if(univ.party[store_spell_target].main_status != eMainStatus::ALIVE) store_spell_target = 6; } else store_spell_target = 6; } - short former_spell = int(store_spell) % 100; + short former_spell = int(default_spell) % 100; // Set the spell page, based on starting spell if(former_spell >= 38) on_which_spell_page = 1; else on_which_spell_page = 0; diff --git a/src/universe/pc.hpp b/src/universe/pc.hpp index cd6b69c2..037536b1 100644 --- a/src/universe/pc.hpp +++ b/src/universe/pc.hpp @@ -105,7 +105,7 @@ public: eRace race; long unique_id; // transient stuff - std::map last_cast; + std::map last_cast = {{ eSkill::MAGE_SPELLS, eSpell::NONE}, { eSkill::PRIEST_SPELLS, eSpell::NONE }}; location combat_pos; short parry = 0; iLiving* last_attacked = nullptr; // Note: Currently this is assigned but never read