Move towards a non-stacking inventory
This commit is contained in:
+19
-1
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user