Use a container to store unique items instead of auxiliary variables

This commit is contained in:
Eddoursul 2025-03-19 22:57:38 +01:00
parent b24738aec6
commit e843ab2505
6 changed files with 40 additions and 12 deletions

1
mod/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
meta.ini

Binary file not shown.

View File

@ -10,7 +10,9 @@ long iCount
float fCount float fCount
float fRemovalChance float fRemovalChance
begin function { rCell } array_var aUniques
begin function { rCell, aUniques }
DebugPrint "Scanning cell %n for removable items" rCell DebugPrint "Scanning cell %n for removable items" rCell
@ -156,9 +158,9 @@ begin function { rCell }
continue continue
endif endif
if AuxiliaryVariableGetFloat "S" 0 rBase == 0 ; the item is encountered for the first time if eval (Ar_Find rBase aUniques) == Ar_BadNumericIndex ; the item is encountered for the first time
DebugPrint "Adding %n to ever scanned list, should only see this once" rBase DebugPrint "Adding %n to ever scanned list, should only see this once" rBase
AuxiliaryVariableSetFloat "S" 1 0 rBase UnfoundLootUniqueStorageRef.AddItem rBase 1 1
set rItem to getNextRef set rItem to getNextRef
continue continue
endif endif

View File

@ -14,8 +14,9 @@ float fCount
float fRemovalChance float fRemovalChance
array_var itemsToRemoveRefs array_var itemsToRemoveRefs
array_var itemsToRemoveCounts array_var itemsToRemoveCounts
array_var aUniques
begin function { rCell, rContainer } begin function { rCell, rContainer, aUniques }
DebugPrint "Delootifying %n..." rContainer DebugPrint "Delootifying %n..." rContainer
@ -111,9 +112,9 @@ begin function { rCell, rContainer }
continue continue
endif endif
if AuxiliaryVariableGetFloat "S" 0 rBase == 0 ; the item is encountered for the first time if eval (Ar_Find rBase aUniques) == Ar_BadNumericIndex ; the item is encountered for the first time
DebugPrint "Adding %n to ever scanned list, should only see this once" rBase DebugPrint "Adding %n to ever scanned list, should only see this once" rBase
AuxiliaryVariableSetFloat "S" 1 0 rBase UnfoundLootUniqueStorageRef.AddItem rBase 1 1
continue continue
endif endif

View File

@ -20,6 +20,8 @@ int iCount
int bDisintegrated int bDisintegrated
array_var aUniques
begin function { rNPC, bDisintegrated } begin function { rNPC, bDisintegrated }
set fBasefRemovalChance to call EULxCalculateBaseRemovalChance rNPC set fBasefRemovalChance to call EULxCalculateBaseRemovalChance rNPC
@ -31,6 +33,8 @@ begin function { rNPC, bDisintegrated }
DebugPrint "Scanning %n's inventory." rNPC DebugPrint "Scanning %n's inventory." rNPC
let aUniques := UnfoundLootUniqueStorageRef.GetAllItems
let itemsToRemoveRefs := ar_construct "array" let itemsToRemoveRefs := ar_construct "array"
let itemsToRemoveCounts := ar_construct "array" let itemsToRemoveCounts := ar_construct "array"
@ -122,6 +126,12 @@ begin function { rNPC, bDisintegrated }
continue continue
endif endif
if eval (Ar_Find rBase aUniques) == Ar_BadNumericIndex ; the item is encountered for the first time
DebugPrint "Adding %n to ever scanned list, should only see this once" rBase
UnfoundLootUniqueStorageRef.AddItem rBase 1 1
continue
endif
if ListGetFormIndex EULxDeathItems rBase != -1 if ListGetFormIndex EULxDeathItems rBase != -1
DebugPrint "Skipping death item: %n" rBase DebugPrint "Skipping death item: %n" rBase
continue continue
@ -236,17 +246,19 @@ begin function { rNPC, bDisintegrated }
printd "SCAN COMPLETE!" printd "SCAN COMPLETE!"
let aUniques := ar_null
; NB: The game will CTD if we remove items in the main loop. ; NB: The game will CTD if we remove items in the main loop.
set i to 0 let i := 0
set iLimit to ar_size itemsToRemoveRefs let iLimit := ar_size itemsToRemoveRefs
while i < iLimit while i < iLimit
let rBase := itemsToRemoveRefs[i] let rBase := itemsToRemoveRefs[i]
let iCount := itemsToRemoveCounts[i] let iCount := itemsToRemoveCounts[i]
DebugPrint "Removing %g of %n from %n" iCount rBase rNPC DebugPrint "Removing %g of %n from %n" iCount rBase rNPC
rNPC.removeItem rBase iCount 1 rNPC.removeItem rBase iCount 1
set i to i + 1 let i += 1
loop loop
let itemsToRemoveRefs := ar_null let itemsToRemoveRefs := ar_null

View File

@ -6,6 +6,9 @@ ref rItem
int iTemp int iTemp
int iPrecalc int iPrecalc
int bSkip int bSkip
int bUniquesLoaded
array_var aUniques
begin function { rCell } begin function { rCell }
@ -32,7 +35,9 @@ begin function { rCell }
if GetFirstRefInCell rCell 201 0 0 if GetFirstRefInCell rCell 201 0 0
set iPrecalc to 1 set iPrecalc to 1
call EULxPrecalculateRemovalChance call EULxPrecalculateRemovalChance
call EULxDelootifyCellItems rCell let bUniquesLoaded := 1
let aUniques := UnfoundLootUniqueStorageRef.GetAllItems
call EULxDelootifyCellItems rCell aUniques
endif endif
@ -41,7 +46,7 @@ begin function { rCell }
set iTemp to GetSourceModIndex rCell set iTemp to GetSourceModIndex rCell
set rTemp to GetFirstRefInCell rCell 27 0 0 set rTemp to GetFirstRefInCell rCell 27 0 0
while rTemp while rTemp
set bSkip to 0 set bSkip to 0
@ -97,10 +102,17 @@ begin function { rCell }
call EULxPrecalculateRemovalChance call EULxPrecalculateRemovalChance
endif endif
call EULxDelootifyContainer rCell rTemp if bUniquesLoaded == 0
let bUniquesLoaded := 1
let aUniques := UnfoundLootUniqueStorageRef.GetAllItems
endif
call EULxDelootifyContainer rCell rTemp aUniques
set rTemp to GetNextRef set rTemp to GetNextRef
loop loop
let aUniques := ar_null
end end