From 49dac8ccb0261d22e87639a131fde34b9edf3573 Mon Sep 17 00:00:00 2001 From: DMD Date: Sat, 11 Mar 2017 14:29:09 +0200 Subject: [PATCH] Updated IsSpellHarmful to determine offensivity of new spells based on SpellEntry ai_type field --- TemplePlus/spell.cpp | 14 +++++++++++++- TemplePlus/spell.h | 2 +- TemplePlus/spell_structs.h | 2 +- TemplePlus/ui/ui_char.cpp | 2 +- TemplePlus/ui/ui_char_editor.h | 2 +- TemplePlus/ui/ui_item_creation.cpp | 16 ++++++++-------- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/TemplePlus/spell.cpp b/TemplePlus/spell.cpp index a6abb350f..f4df3aca2 100644 --- a/TemplePlus/spell.cpp +++ b/TemplePlus/spell.cpp @@ -691,7 +691,7 @@ const char* LegacySpellSystem::GetSpellEnumTAG(uint32_t spellEnum){ const char* LegacySpellSystem::GetSpellName(uint32_t spellEnum) const { - if (spellEnum > SPELL_ENUM_MAX || static_cast(spellEnum) <=0){ + if (spellEnum > SPELL_ENUM_MAX_VANILLA || static_cast(spellEnum) <=0){ logger->warn("Spell Enum outside expected range: {}", spellEnum); } return GetSpellMesline(spellEnum); @@ -2263,6 +2263,18 @@ BOOL LegacySpellSystem::SpellHasAiType(unsigned spellEnum, AiSpellType aiSpellTy } BOOL LegacySpellSystem::IsSpellHarmful(int spellEnum, const objHndl& caster, const objHndl& tgt){ + + if (spellEnum > SPELL_ENUM_MAX_VANILLA){ + SpellEntry spEntry(spellEnum); + if (!spEntry.spellEnum){ + logger->warn("Invalid spellEnum in IsSpellHarmfull"); + return FALSE; + } + if (spEntry.aiTypeBitmask & (1 << ai_action_offensive)) + return TRUE; + return FALSE; + } + return temple::GetRef(0x100769F0)(spellEnum, caster, tgt); } diff --git a/TemplePlus/spell.h b/TemplePlus/spell.h index fecbfb7bf..e27261497 100644 --- a/TemplePlus/spell.h +++ b/TemplePlus/spell.h @@ -55,7 +55,7 @@ struct SpellEntry{ uint32_t maxTarget; int radiusTarget; //note: if it's negative, then its absolute value is used as SpellRangeType for mode_target personal; if it's positive, it's a specified number(in feet ? ) int degreesTarget; - uint32_t aiTypeBitmask; + uint32_t aiTypeBitmask; // see AiSpellType in spell_structs.h uint32_t pad; //UiPickerType GetModeTarget() const; diff --git a/TemplePlus/spell_structs.h b/TemplePlus/spell_structs.h index 098a5b50b..2f8ba40b0 100644 --- a/TemplePlus/spell_structs.h +++ b/TemplePlus/spell_structs.h @@ -1,6 +1,6 @@ #pragma once -const uint32_t SPELL_ENUM_MAX = 802; +const uint32_t SPELL_ENUM_MAX_VANILLA = 802; const uint32_t SPELL_ENUM_MAX_EXPANDED = 3999; #define NUM_SPELL_LEVELS 10 // spells are levels 0-9 diff --git a/TemplePlus/ui/ui_char.cpp b/TemplePlus/ui/ui_char.cpp index 2070654c6..31f75ab77 100644 --- a/TemplePlus/ui/ui_char.cpp +++ b/TemplePlus/ui/ui_char.cpp @@ -30,7 +30,7 @@ struct TigTextStyle; struct SpellList { - SpellStoreData spells[SPELL_ENUM_MAX]; + SpellStoreData spells[SPELL_ENUM_MAX_VANILLA]; uint32_t count; }; diff --git a/TemplePlus/ui/ui_char_editor.h b/TemplePlus/ui/ui_char_editor.h index e85668da8..be95171e0 100644 --- a/TemplePlus/ui/ui_char_editor.h +++ b/TemplePlus/ui/ui_char_editor.h @@ -33,7 +33,7 @@ struct CharEditorSelectionPacket{ int skillPointsAdded[42]; // idx corresponds to skill enum int skillPointsSpent; int availableSkillPoints; - int spellEnums[SPELL_ENUM_MAX]; + int spellEnums[SPELL_ENUM_MAX_VANILLA]; int spellEnumsAddedCount; int spellEnumToRemove; // for sorcerers who swap out spells int wizSchool; diff --git a/TemplePlus/ui/ui_item_creation.cpp b/TemplePlus/ui/ui_item_creation.cpp index c159bfbf3..bcf1cb9f9 100644 --- a/TemplePlus/ui/ui_item_creation.cpp +++ b/TemplePlus/ui/ui_item_creation.cpp @@ -387,8 +387,8 @@ int UiItemCreation::CraftedWandSpellLevel(objHndl objHndItem) //// get data from caster - make this optional! - //uint32_t spellClassCodes[SPELL_ENUM_MAX] = { 0, }; - //uint32_t spellLevels[SPELL_ENUM_MAX] = { 0, }; + //uint32_t spellClassCodes[SPELL_ENUM_MAX_VANILLA] = { 0, }; + //uint32_t spellLevels[SPELL_ENUM_MAX_VANILLA] = { 0, }; //uint32_t spellFoundNum = 0; //int casterKnowsSpell = spellSys.spellKnownQueryGetData(itemCreationCrafter, spellData.spellEnum, spellClassCodes, spellLevels, &spellFoundNum); //if (casterKnowsSpell){ @@ -924,8 +924,8 @@ void UiItemCreation::CraftScrollWandPotionSetItemSpellData(objHndl objHndItem, o // get data from caster - make this optional! - uint32_t classCodes[SPELL_ENUM_MAX] = { 0, }; - uint32_t spellLevels[SPELL_ENUM_MAX] = { 0, }; + uint32_t classCodes[SPELL_ENUM_MAX_VANILLA] = { 0, }; + uint32_t spellLevels[SPELL_ENUM_MAX_VANILLA] = { 0, }; uint32_t spellFoundNum = 0; int casterKnowsSpell = spellSys.spellKnownQueryGetData(objHndCrafter, spellData.spellEnum, classCodes, spellLevels, &spellFoundNum); if (casterKnowsSpell){ @@ -999,8 +999,8 @@ bool UiItemCreation::CraftedWandSpellGet(objHndl item, SpellStoreData & spellDat // get data from caster - uint32_t spellClassCodes[SPELL_ENUM_MAX] = { 0, }; - uint32_t spellLevels[SPELL_ENUM_MAX] = { 0, }; + uint32_t spellClassCodes[SPELL_ENUM_MAX_VANILLA] = { 0, }; + uint32_t spellLevels[SPELL_ENUM_MAX_VANILLA] = { 0, }; uint32_t spellFoundNum = 0; int casterKnowsSpell = spellSys.spellKnownQueryGetData(itemCreationCrafter, spellData.spellEnum, spellClassCodes, spellLevels, &spellFoundNum); if (!casterKnowsSpell){ @@ -1584,8 +1584,8 @@ bool UiItemCreation::ScribedScrollSpellGet(objHndl item, SpellStoreData & spellD // get data from caster - uint32_t spellClassCodes[SPELL_ENUM_MAX] = { 0, }; - uint32_t spellLevels[SPELL_ENUM_MAX] = { 0, }; + uint32_t spellClassCodes[SPELL_ENUM_MAX_VANILLA] = { 0, }; + uint32_t spellLevels[SPELL_ENUM_MAX_VANILLA] = { 0, }; uint32_t spellFoundNum = 0; int casterKnowsSpell = spellSys.spellKnownQueryGetData(itemCreationCrafter, spellData.spellEnum, spellClassCodes, spellLevels, &spellFoundNum); if (!casterKnowsSpell) {