Allow item combination to use non-stacking items
This commit is contained in:
+13
-5
@@ -36,7 +36,7 @@ invertInventory =
|
||||
invertInventoryToMap :: IM.IntMap Item -> M.Map ItemBaseType [Int]
|
||||
invertInventoryToMap =
|
||||
IM.foldrWithKey
|
||||
(\k it -> (M.insertWith (++) (_iyBase $ _itType it) [k]))
|
||||
(\k it -> (M.insertWith (++) (_iyBase $ _itType it) (replicate (fromIntegral $ itStackAmount it) k)))
|
||||
mempty
|
||||
|
||||
splitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), (ItAmount, Int))]
|
||||
@@ -44,6 +44,11 @@ splitItAmounts = concatMap f
|
||||
where
|
||||
f (x, n, y) = [((i, x), (i, y)) | i <- [1 .. n]]
|
||||
|
||||
groupSplitItemAmounts :: M.Map ItemBaseType [Int] -> [((ItAmount, ItemBaseType), [Int])]
|
||||
groupSplitItemAmounts = M.foldrWithKey f []
|
||||
where
|
||||
f ibt is = (++) [((fromIntegral i, ibt), take i is) | i <- [1..length is]]
|
||||
|
||||
flatSplitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), [Int])]
|
||||
flatSplitItAmounts = concatMap f
|
||||
where
|
||||
@@ -52,6 +57,9 @@ flatSplitItAmounts = concatMap f
|
||||
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 . groupSplitItemAmounts
|
||||
-- . invertInventoryToMap
|
||||
flatLookupItems :: IM.IntMap Item -> [([[Int]],Item)]
|
||||
flatLookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . flatSplitItAmounts
|
||||
. invertInventory
|
||||
@@ -59,10 +67,10 @@ flatLookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . flatSpli
|
||||
combineItemListYouX :: World -> [([Int], Item)]
|
||||
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
|
||||
--combineItemListYouX' :: World -> [([Int], Item)]
|
||||
--combineItemListYouX' = map (first $ concatMap g) . lookupItems . yourInv
|
||||
-- where
|
||||
-- g (amount, i) = replicate (_getItAmount amount) i
|
||||
|
||||
combineList :: World -> [SelectionItem CombinableItem]
|
||||
combineList w = case combineList' w of
|
||||
|
||||
Reference in New Issue
Block a user