From 4de15d2c211c391addc24c119e7ef9b089a26e60 Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 8 Sep 2024 20:33:18 +0100 Subject: [PATCH] Allow item combination to use non-stacking items --- ghcidOutput | 14 +++++++------- src/Dodge/Combine.hs | 18 +++++++++++++----- tags | 44 +++++++++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ghcidOutput b/ghcidOutput index 50279faf6..bb56f26e8 100644 --- a/ghcidOutput +++ b/ghcidOutput @@ -8,16 +8,16 @@ | 43 | splitItAmounts = concatMap f | ^^^^^^^^^^^^^^ -/home/justin/Haskell/loop/src/Dodge/Combine.hs:53:1-11: warning: [-Wunused-top-binds] +/home/justin/Haskell/loop/src/Dodge/Combine.hs:48:1-21: warning: [-Wunused-top-binds] + Defined but not used: ‘groupSplitItemAmounts’ + | +48 | groupSplitItemAmounts = M.foldrWithKey f [] + | ^^^^^^^^^^^^^^^^^^^^^ +/home/justin/Haskell/loop/src/Dodge/Combine.hs:58:1-11: warning: [-Wunused-top-binds] Defined but not used: ‘lookupItems’ | -53 | lookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . splitItAmounts . invertInventory +58 | lookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . splitItAmounts . invertInventory | ^^^^^^^^^^^ -/home/justin/Haskell/loop/src/Dodge/Combine.hs:63:1-20: warning: [-Wunused-top-binds] - Defined but not used: ‘combineItemListYouX'’ - | -63 | combineItemListYouX' = map (first $ concatMap g) . lookupItems . yourInv - | ^^^^^^^^^^^^^^^^^^^^ /home/justin/Haskell/loop/src/Dodge/Combine/Combinations.hs:9:1-21: warning: [-Wunused-imports] The import of ‘Data.Bifunctor’ is redundant | diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index 5c8b5a088..b9bb11bf9 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -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 diff --git a/tags b/tags index 7d323021f..6e88014d8 100644 --- a/tags +++ b/tags @@ -4471,7 +4471,7 @@ axisInt src/Geometry/Intersect.hs 227;" f azure src/Color.hs 22;" f bQuadToF src/Geometry/Bezier.hs 37;" f bQuadToLine src/Geometry/Bezier.hs 30;" f -backpackCombinations src/Dodge/Combine/Combinations.hs 24;" f +backpackCombinations src/Dodge/Combine/Combinations.hs 25;" f backpackShape src/Dodge/Item/Draw/SPic.hs 69;" f backspaceInputted src/Dodge/Update/Input/Text.hs 26;" f bangCone src/Dodge/Item/Held/Cone.hs 10;" f @@ -4520,7 +4520,7 @@ basicMachineUpdate src/Dodge/Machine.hs 13;" f basicPerceptionUpdateR src/Dodge/Creature/AlertLevel.hs 17;" f basicTerminal src/Dodge/Terminal.hs 32;" f battery src/Dodge/Item/Ammo.hs 61;" f -batteryGuns src/Dodge/Combine/Combinations.hs 226;" f +batteryGuns src/Dodge/Combine/Combinations.hs 227;" f batteryModules src/Dodge/Item/Held/BatteryGuns.hs 111;" f batteryPack src/Dodge/Item/Equipment.hs 58;" f belowNumX src/Dodge/Combine/Graph.hs 77;" f @@ -4599,10 +4599,10 @@ bulletBeltBracer src/Dodge/Item/Equipment.hs 83;" f bulletBeltPack src/Dodge/Item/Equipment.hs 74;" f bulletBodyCraft src/Dodge/Item/Craftable.hs 24;" f bulletCombinations src/Dodge/Combine/Graph.hs 35;" f -bulletMagazines src/Dodge/Combine/Combinations.hs 238;" f +bulletMagazines src/Dodge/Combine/Combinations.hs 239;" f bulletSpawn src/Dodge/Bullet.hs 91;" f bulletTypes src/Dodge/TweakBullet.hs 26;" f -bulletWeapons src/Dodge/Combine/Combinations.hs 246;" f +bulletWeapons src/Dodge/Combine/Combinations.hs 247;" f burstRifle src/Dodge/Item/Held/Cane.hs 86;" f burstRifle src/Dodge/Item/Weapon/BulletGun/Cane.hs 105;" f buzzS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 502;" f @@ -4714,7 +4714,7 @@ clsNearRect src/Dodge/Zoning/Cloud.hs 15;" f clsNearSeg src/Dodge/Zoning/Cloud.hs 12;" f clusterFormatting src/Dodge/Combine/Graph.hs 113;" f clusterFunc src/Dodge/Combine/Graph.hs 107;" f -cmm src/Dodge/Combine.hs 79;" f +cmm src/Dodge/Combine.hs 91;" f cogRaised src/Dodge/Creature/Perception.hs 101;" f colCrWall src/Dodge/WallCreatureCollisions.hs 26;" f colCrsWalls src/Dodge/WallCreatureCollisions.hs 17;" f @@ -4745,15 +4745,15 @@ combineBeams src/Dodge/Update.hs 466;" f combineCounts src/Dodge/Render/HUD.hs 236;" f combineFloors src/Dodge/Room/Procedural.hs 171;" f combineInventoryExtra src/Dodge/Render/HUD.hs 181;" f -combineItemListYouX src/Dodge/Combine.hs 50;" f -combineList src/Dodge/Combine.hs 55;" f -combineList' src/Dodge/Combine.hs 60;" f -combineListInfo src/Dodge/Combine.hs 73;" f -combineModuleMaps src/Dodge/Combine.hs 84;" f +combineItemListYouX src/Dodge/Combine.hs 59;" f +combineList src/Dodge/Combine.hs 67;" f +combineList' src/Dodge/Combine.hs 72;" f +combineListInfo src/Dodge/Combine.hs 85;" f +combineModuleMaps src/Dodge/Combine.hs 96;" f combineRooms src/Dodge/Room/Procedural.hs 151;" f combineS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 344;" f combineTree src/Dodge/Tree/Compose.hs 66;" f -combineTwoModuleMaps src/Dodge/Combine.hs 90;" f +combineTwoModuleMaps src/Dodge/Combine.hs 102;" f commandColor src/Dodge/Terminal.hs 130;" f commandFutureLines src/Dodge/Terminal.hs 252;" f commandsCommand src/Dodge/Terminal.hs 91;" f @@ -5464,9 +5464,11 @@ flameWall src/Dodge/Item/Weapon/SprayGuns.hs 54;" f flamerPic src/Dodge/Item/Draw/SPic.hs 416;" f flareCircleAt src/Dodge/WorldEvent/Flash.hs 46;" f flatCombinationsTrie src/Dodge/Combine/Trie.hs 10;" f -flatItemCombinations src/Dodge/Combine/Combinations.hs 48;" f +flatItemCombinations src/Dodge/Combine/Combinations.hs 49;" f +flatLookupItems src/Dodge/Combine.hs 55;" f flatShield src/Dodge/Item/Held/Utility.hs 9;" f flatShieldEquipSPic src/Dodge/Item/Draw/SPic.hs 489;" f +flatSplitItAmounts src/Dodge/Combine.hs 47;" f flatV2 src/Picture/Data.hs 65;" f flatV3 src/Picture/Data.hs 68;" f flatV4 src/Picture/Data.hs 71;" f @@ -5528,7 +5530,7 @@ fromV3 src/Geometry/Data.hs 43;" f frontArmour src/Dodge/Item/Equipment.hs 43;" f fstV2 src/Geometry/Data.hs 50;" f fuelPack src/Dodge/Item/Equipment.hs 66;" f -fullModuleName src/Dodge/Combine.hs 109;" f +fullModuleName src/Dodge/Combine.hs 121;" f functionalUpdate src/Dodge/Update.hs 230;" f fuseFunc src/Dodge/Path.hs 150;" f fusePairs src/Dodge/Path.hs 153;" f @@ -5652,7 +5654,7 @@ hasFrontArmour src/Dodge/Creature/Test.hs 112;" f hasLOS src/Dodge/Base/Collide.hs 200;" f hasLOSIndirect src/Dodge/Base/Collide.hs 214;" f hat src/Dodge/Item/Equipment.hs 105;" f -hatCombinations src/Dodge/Combine/Combinations.hs 32;" f +hatCombinations src/Dodge/Combine/Combinations.hs 33;" f head src/DoubleStack.hs 14;" f headLamp src/Dodge/Item/Equipment.hs 118;" f headLampShape src/Dodge/Item/Draw/SPic.hs 495;" f @@ -5684,7 +5686,7 @@ hitSound src/Dodge/SoundLogic/Synonyms.hs 4;" f holdForm src/Dodge/Creature/Boid.hs 136;" f holsterWeapon src/Dodge/Creature/Volition.hs 14;" f holsterWeaponSound src/Dodge/SoundLogic/Synonyms.hs 4;" f -homingLaunchers src/Dodge/Combine/Combinations.hs 223;" f +homingLaunchers src/Dodge/Combine/Combinations.hs 224;" f horPipe src/Dodge/Placement/Instance/Pipe.hs 9;" f hotkeyToScancode src/Dodge/Creature/YourControl.hs 55;" f hotkeyToString src/Dodge/Inventory/SelectionList.hs 35;" f @@ -5829,7 +5831,7 @@ itUseCharge src/Dodge/Item/Weapon/TriggerType.hs 156;" f itemBaseName src/Dodge/Item/Display.hs 75;" f itemBlips src/Dodge/Item/Weapon/UseEffect.hs 38;" f itemBlips src/Dodge/RadarSweep.hs 74;" f -itemCombinations src/Dodge/Combine/Combinations.hs 53;" f +itemCombinations src/Dodge/Combine/Combinations.hs 54;" f itemCombinationsEdges src/Dodge/Combine/Graph.hs 55;" f itemDisplay src/Dodge/Item/Display.hs 47;" f itemDisplayOffset src/Dodge/Item/Display.hs 21;" f @@ -5996,7 +5998,7 @@ longRoomRunPast src/Dodge/Room/LongRoom.hs 47;" f longestCommonPrefix src/Dodge/Debug/Terminal.hs 138;" f lookLookup src/Dodge/Base/Zone.hs 203;" f lookLookups src/Dodge/Base/Zone.hs 208;" f -lookupItems src/Dodge/Combine.hs 47;" f +lookupItems src/Dodge/Combine.hs 52;" f lookupTrie src/SimpleTrie.hs 24;" f loopPairs src/ListHelp.hs 28;" f lootRoom src/Dodge/Room/Treasure.hs 58;" f @@ -6019,7 +6021,7 @@ machineUpdateLiveDieEff src/Dodge/Machine.hs 16;" f magShield src/Dodge/Item/Equipment.hs 29;" f magV src/Geometry/Vector.hs 160;" f magV3 src/Geometry/Vector3D.hs 78;" f -magazineCombinations src/Dodge/Combine/Combinations.hs 40;" f +magazineCombinations src/Dodge/Combine/Combinations.hs 41;" f magenta src/Color.hs 19;" f main appDodge/Main.hs 37;" f main appHetris/Hetris.hs 15;" f @@ -6202,7 +6204,7 @@ modClock src/Dodge/Item/Weapon/TriggerType.hs 447;" f modTo src/Geometry/Zone.hs 10;" f modifierKey src/Dodge/Config/KeyConfig.hs 34;" f moduleAttachPosition src/Dodge/Item/Module.hs 6;" f -moduleCombinations src/Dodge/Combine/Combinations.hs 134;" f +moduleCombinations src/Dodge/Combine/Combinations.hs 135;" f moduleInfo src/Dodge/Item/Info.hs 273;" f moduleModification src/Dodge/Combine/Module.hs 10;" f moduleName src/Dodge/Module.hs 22;" f @@ -7359,7 +7361,7 @@ telRoomLev src/Dodge/Room/Teleport.hs 14;" f teleS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 378;" f teleSound src/Dodge/SoundLogic/Synonyms.hs 4;" f teleportModule src/Dodge/Item/Craftable.hs 32;" f -teleportableWeapons src/Dodge/Combine/Combinations.hs 235;" f +teleportableWeapons src/Dodge/Combine/Combinations.hs 236;" f termButton src/Dodge/Placement/Instance/Terminal.hs 51;" f termSoundLine src/Dodge/Terminal.hs 109;" f termTextColor src/Dodge/Terminal.hs 112;" f @@ -7815,7 +7817,7 @@ wasdM src/Dodge/WASD.hs 9;" f wasdMovement src/Dodge/Creature/YourControl.hs 176;" f wasdTwist src/Dodge/Creature/YourControl.hs 155;" f wasdWithAiming src/Dodge/Creature/YourControl.hs 136;" f -watchCombinations src/Dodge/Combine/Combinations.hs 14;" f +watchCombinations src/Dodge/Combine/Combinations.hs 15;" f watchUpdateStrat src/Dodge/Creature/ReaderUpdate.hs 177;" f wdth src/Dodge/Machine/Sensor.hs 54;" f wdth src/Dodge/Placements/Sensor.hs 53;" f