Skip to content

Commit

Permalink
Updated IsSpellHarmful to determine offensivity of new spells based o…
Browse files Browse the repository at this point in the history
…n SpellEntry ai_type field
  • Loading branch information
DMD authored and DMD committed Mar 11, 2017
1 parent a589c99 commit 49dac8c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
14 changes: 13 additions & 1 deletion TemplePlus/spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(spellEnum) <=0){
if (spellEnum > SPELL_ENUM_MAX_VANILLA || static_cast<int>(spellEnum) <=0){
logger->warn("Spell Enum outside expected range: {}", spellEnum);
}
return GetSpellMesline(spellEnum);
Expand Down Expand Up @@ -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<BOOL(__cdecl)(int, objHndl, objHndl)>(0x100769F0)(spellEnum, caster, tgt);
}

Expand Down
2 changes: 1 addition & 1 deletion TemplePlus/spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion TemplePlus/spell_structs.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion TemplePlus/ui/ui_char.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct TigTextStyle;

struct SpellList
{
SpellStoreData spells[SPELL_ENUM_MAX];
SpellStoreData spells[SPELL_ENUM_MAX_VANILLA];
uint32_t count;
};

Expand Down
2 changes: 1 addition & 1 deletion TemplePlus/ui/ui_char_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions TemplePlus/ui/ui_item_creation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 49dac8c

Please sign in to comment.