From 95ec30837a9877cb220b8badaa2cd88dd7c45a21 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 8 Jun 2022 17:36:24 +0100 Subject: [PATCH] Move towards correcting module combinations --- src/Dodge/Combine.hs | 42 ++++++++++++++++++++++++++++++++++-------- src/Dodge/Creature.hs | 8 ++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index 2001ef5e0..e11a55bc0 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -18,6 +18,9 @@ import Dodge.Module import Multiset import SimpleTrie +import Data.Foldable +import Data.Map.Merge.Strict +import Control.Monad import Control.Lens import Data.Bifunctor import qualified Data.IntMap.Strict as IM @@ -50,7 +53,36 @@ combineItemListYou = map (first f) . lookupItems' . yourInv where f = concatMap g g (amount,i) = replicate (_toInt amount) i + +combineItemListYou' :: World -> [([Int],(Item,[String]))] +combineItemListYou' w = map (cmm (yourInv w)) $ combineItemListYou w + +cmm :: IM.IntMap Item -> ([Int],Item) -> ([Int],(Item,[String])) +cmm inv (is,itm) = (is,(itm & itType . iyModules .~ mods, s)) + where + mms = map (_iyModules . _itType . (inv IM.!)) $ is + (s,mods) = combineModuleMaps (_iyModules $ _itType itm) mms +combineModuleMaps :: M.Map ModuleSlot ItemModuleType -> [M.Map ModuleSlot ItemModuleType] + -> ([String],M.Map ModuleSlot ItemModuleType) +combineModuleMaps = foldrM cMod + +cMod :: M.Map ModuleSlot ItemModuleType + -> (M.Map ModuleSlot ItemModuleType) + -> ([String],M.Map ModuleSlot ItemModuleType) +cMod = mergeA + (filterAMissing f) + (filterAMissing f') + (zipWithAMatched g) + where + f k EMPTYMODULE = ([],False) + f k md = ([],False) + f' k EMPTYMODULE = ([],True) + f' k md = ([rm md++"SECOND"++show k],True) + g k EMPTYMODULE md = ([],md) + g k md1 md2 = ([rm md1++"BOTH"],md2) + rm md = "REMOVES "++fromJust (moduleName md) + -- this can probably be improved by going through accessing the combinations -- trie going through each combine type in your inventory in order, rather than @@ -77,14 +109,8 @@ invertListInv = IM.foldrWithKey (\k it -> ((_iyModules $ _itType it,_iyBase $ _itType it, k, itStackAmount it) :) ) [] --- gives a list of indices-item pairs. --- Note that within the pair, indices can be repeated if two or more of an item --- are needed -combineItemListYou'' :: World -> [([Int],Item)] -combineItemListYou'' = map (second fst) . combineItemListYou' - -combineItemListYou' :: World -> [([Int],(Item,[String]))] -combineItemListYou' = map addModules . concatMap lookupItems . invertListInvMult . yourInv +combineItemListYou'' :: World -> [([Int],(Item,[String]))] +combineItemListYou'' = map addModules . concatMap lookupItems . invertListInvMult . yourInv addModules :: ([(M.Map ModuleSlot ItemModuleType,Int)],Item) -> ([Int],(Item,[String])) diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index 0958e7384..8f7981b88 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -229,6 +229,14 @@ inventoryX c = case c of , makeTypeCraftNum 5 TRANSFORMER , makeTypeCraftNum 5 PRISM , makeTypeCraftNum 5 LIGHTER + , makeTypeCraftNum 5 INCENDIARYMODULE + ] + 'G' -> + [ autoPistol + , makeTypeCraftNum 2 HARDWARE + , makeTypeCraftNum 2 MAGNET + , makeTypeCraftNum 5 INCENDIARYMODULE + , makeTypeCraftNum 5 STATICMODULE ] _ -> []