diff --git a/mod/.gitignore b/mod/.gitignore new file mode 100644 index 0000000..8a1034d --- /dev/null +++ b/mod/.gitignore @@ -0,0 +1 @@ +meta.ini \ No newline at end of file diff --git a/mod/Unfound Loot.esp b/mod/Unfound Loot.esp index fbafa34..a00fe74 100644 Binary files a/mod/Unfound Loot.esp and b/mod/Unfound Loot.esp differ diff --git a/src/EULxDelootifyCellItems.gek b/src/EULxDelootifyCellItems.gek index 6fdfe07..68f4f50 100644 --- a/src/EULxDelootifyCellItems.gek +++ b/src/EULxDelootifyCellItems.gek @@ -10,7 +10,9 @@ long iCount float fCount float fRemovalChance -begin function { rCell } +array_var aUniques + +begin function { rCell, aUniques } DebugPrint "Scanning cell %n for removable items" rCell @@ -156,9 +158,9 @@ begin function { rCell } continue 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 - AuxiliaryVariableSetFloat "S" 1 0 rBase + UnfoundLootUniqueStorageRef.AddItem rBase 1 1 set rItem to getNextRef continue endif diff --git a/src/EULxDelootifyContainer.gek b/src/EULxDelootifyContainer.gek index 139e7b2..f6f44ca 100644 --- a/src/EULxDelootifyContainer.gek +++ b/src/EULxDelootifyContainer.gek @@ -14,8 +14,9 @@ float fCount float fRemovalChance array_var itemsToRemoveRefs array_var itemsToRemoveCounts +array_var aUniques -begin function { rCell, rContainer } +begin function { rCell, rContainer, aUniques } DebugPrint "Delootifying %n..." rContainer @@ -111,9 +112,9 @@ begin function { rCell, rContainer } continue 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 - AuxiliaryVariableSetFloat "S" 1 0 rBase + UnfoundLootUniqueStorageRef.AddItem rBase 1 1 continue endif diff --git a/src/EULxDelootifyNPC.gek b/src/EULxDelootifyNPC.gek index 6c94c34..c243b19 100644 --- a/src/EULxDelootifyNPC.gek +++ b/src/EULxDelootifyNPC.gek @@ -20,6 +20,8 @@ int iCount int bDisintegrated +array_var aUniques + begin function { rNPC, bDisintegrated } set fBasefRemovalChance to call EULxCalculateBaseRemovalChance rNPC @@ -31,6 +33,8 @@ begin function { rNPC, bDisintegrated } DebugPrint "Scanning %n's inventory." rNPC + let aUniques := UnfoundLootUniqueStorageRef.GetAllItems + let itemsToRemoveRefs := ar_construct "array" let itemsToRemoveCounts := ar_construct "array" @@ -122,6 +126,12 @@ begin function { rNPC, bDisintegrated } continue 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 DebugPrint "Skipping death item: %n" rBase continue @@ -236,17 +246,19 @@ begin function { rNPC, bDisintegrated } printd "SCAN COMPLETE!" + let aUniques := ar_null + ; NB: The game will CTD if we remove items in the main loop. - set i to 0 - set iLimit to ar_size itemsToRemoveRefs + let i := 0 + let iLimit := ar_size itemsToRemoveRefs while i < iLimit let rBase := itemsToRemoveRefs[i] let iCount := itemsToRemoveCounts[i] DebugPrint "Removing %g of %n from %n" iCount rBase rNPC rNPC.removeItem rBase iCount 1 - set i to i + 1 + let i += 1 loop let itemsToRemoveRefs := ar_null diff --git a/src/EULxOnSeen.gek b/src/EULxOnSeen.gek index 9fdc4d1..717c9dd 100644 --- a/src/EULxOnSeen.gek +++ b/src/EULxOnSeen.gek @@ -6,6 +6,9 @@ ref rItem int iTemp int iPrecalc int bSkip +int bUniquesLoaded + +array_var aUniques begin function { rCell } @@ -32,7 +35,9 @@ begin function { rCell } if GetFirstRefInCell rCell 201 0 0 set iPrecalc to 1 call EULxPrecalculateRemovalChance - call EULxDelootifyCellItems rCell + let bUniquesLoaded := 1 + let aUniques := UnfoundLootUniqueStorageRef.GetAllItems + call EULxDelootifyCellItems rCell aUniques endif @@ -41,7 +46,7 @@ begin function { rCell } set iTemp to GetSourceModIndex rCell set rTemp to GetFirstRefInCell rCell 27 0 0 - + while rTemp set bSkip to 0 @@ -97,10 +102,17 @@ begin function { rCell } call EULxPrecalculateRemovalChance 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 loop + let aUniques := ar_null + end