Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated InvalidateItem() to find multiple appearances #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 68 additions & 27 deletions dist/Data/Scripts/Source/SKI_FavoritesManager.psc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import Math
; 2: - Added check for vampire lord
;
; 3: - Less eagerly clearing of invalid entries
;
; 4: - EDC - Added repeat find to InvalidateItem()

int function GetVersion()
return 3
return 4
endFunction


Expand Down Expand Up @@ -221,6 +223,11 @@ event OnVersionUpdate(int a_version)
_itemInvalidFlags1 = new bool[128]
_itemInvalidFlags2 = new bool[128]
endIf

; Version 4
if (a_version >= 4 && CurrentVersion < 4)
Debug.Trace(self + ": Updating to script version 4")
endIf

endEvent

Expand Down Expand Up @@ -804,7 +811,8 @@ bool function ProcessItem(Form a_item, int a_itemType, bool a_allowDeferring = t

; It's two-handed and both hands are free
elseIf (weaponType > 4 && !_usedRightHand && !_usedLeftHand)
if (a_item == PlayerREF.GetEquippedObject(0) && a_itemId != PlayerREF.GetEquippedItemId(0))
; EDC - Changed this line from GetEquippedItemId(0) to GetEquippedItemId(1) since two-handed weapons don't seem to appear in left hand
if (a_item == PlayerREF.GetEquippedObject(0) && a_itemId != PlayerREF.GetEquippedItemId(1))
UnequipHand(0)
endIf
PlayerREF.EquipItemById(itemWeapon, a_itemId, equipSlot = 0, equipSound = _silenceEquipSounds)
Expand Down Expand Up @@ -960,41 +968,74 @@ bool function ProcessItem(Form a_item, int a_itemType, bool a_allowDeferring = t
endFunction

function InvalidateItem(int a_itemId, bool redrawIcon = false)
;EDC - Version 3 implementation only invalidates the first appearance of an itemID. Any subsequent
; use in other groups is missed.
; This version recursively searches for additional items beyond the first
int index

; GroupData
index = _itemIds1.Find(a_itemId)
if (index != -1)
_itemInvalidFlags1[index] = true
endIf

index = _itemIds2.Find(a_itemId)
if (index != -1)
_itemInvalidFlags2[index] = true
endIf
index = 0
while index < 128
index = _itemIds1.Find(a_itemId, index)
if (index != -1)
_itemInvalidFlags1[index] = true
index += 1
else
index = 128
endIf
endWhile

index = 0
while index < 128
index = _itemIds2.Find(a_itemId, index)
if (index != -1)
_itemInvalidFlags2[index] = true
index += 1
else
index = 128
endIf
endWhile

; Main hand
index = _groupMainHandItemIds.Find(a_itemId)
if (index != -1)
_groupMainHandItems[index] = none
_groupMainHandItemIds[index] = 0
endIf
index = 0
while index < 8
index = _groupMainHandItemIds.Find(a_itemId, index)
if (index != -1)
_groupMainHandItems[index] = none
_groupMainHandItemIds[index] = 0
index += 1
else
index = 8
endIf
endWhile

; Off hand
index = _groupOffHandItemIds.Find(a_itemId)
if (index != -1)
_groupOffHandItems[index] = none
_groupOffHandItemIds[index] = 0
endIf
index = 0
while index < 8
index = _groupOffHandItemIds.Find(a_itemId, index)
if (index != -1)
_groupOffHandItems[index] = none
_groupOffHandItemIds[index] = 0
index += 1
else
index = 8
endIf
endWhile

; Icon
index = _groupIconItemIds.Find(a_itemId)
if (index != -1)
ReplaceGroupIcon(index)
if (redrawIcon)
UpdateMenuGroupData(index)
index = 0
while index < 8
index = _groupIconItemIds.Find(a_itemId, index)
if (index != -1)
ReplaceGroupIcon(index)
if (redrawIcon)
UpdateMenuGroupData(index)
endIf
index += 1
else
index = 8
endIf
endIf
endWhile
endFunction

int function FindFreeIndex(int[] a_itemIds, bool[] a_itemInvalidFlags, int offset)
Expand Down