Move towards a non-stacking inventory

This commit is contained in:
2024-09-08 20:13:43 +01:00
parent 86795f1a10
commit 3dcf8de3c3
5 changed files with 118 additions and 55 deletions
+19 -1
View File
@@ -33,16 +33,34 @@ invertInventory =
(\k it -> ((_iyBase $ _itType it, itStackAmount it, k) :))
[]
invertInventoryToMap :: IM.IntMap Item -> M.Map ItemBaseType [Int]
invertInventoryToMap =
IM.foldrWithKey
(\k it -> (M.insertWith (++) (_iyBase $ _itType it) [k]))
mempty
splitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), (ItAmount, Int))]
splitItAmounts = concatMap f
where
f (x, n, y) = [((i, x), (i, y)) | i <- [1 .. n]]
flatSplitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), [Int])]
flatSplitItAmounts = concatMap f
where
f (x, n, y) = [((i, x), replicate (fromIntegral i) y) | i <- [1 .. n]]
lookupItems :: IM.IntMap Item -> [([(ItAmount, Int)], Item)]
lookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . splitItAmounts . invertInventory
flatLookupItems :: IM.IntMap Item -> [([[Int]],Item)]
flatLookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . flatSplitItAmounts
. invertInventory
combineItemListYouX :: World -> [([Int], Item)]
combineItemListYouX = map (first $ concatMap g) . lookupItems . yourInv
combineItemListYouX = map (first $ concat) . flatLookupItems . yourInv
combineItemListYouX' :: World -> [([Int], Item)]
combineItemListYouX' = map (first $ concatMap g) . lookupItems . yourInv
where
g (amount, i) = replicate (_getItAmount amount) i