diff --git a/src/Dodge/Item/Grammar.hs b/src/Dodge/Item/Grammar.hs index 603453019..0161d261d 100644 --- a/src/Dodge/Item/Grammar.hs +++ b/src/Dodge/Item/Grammar.hs @@ -33,8 +33,7 @@ import Dodge.DoubleTree import LensHelp import ListHelp -tryAttachItems :: LDTree ItemLink CItem -> LDTree ItemLink CItem -> - Maybe (LDTree ItemLink CItem) +tryAttachItems :: DTree CItem -> DTree CItem -> Maybe (DTree CItem) tryAttachItems = leftRightCombine leftIsParentCombine rightIsParentCombine --breakListAbove :: Item -> ItemStructuralFunction -> [(ItemStructuralFunction, ItemLink)] @@ -53,20 +52,20 @@ tryAttachItems = leftRightCombine leftIsParentCombine rightIsParentCombine -- [(JoystickSF, JoystickLink)] -- _ -> [] +--itemToBreakLists :: +-- Item -> +-- ItemStructuralFunction -> +-- ([(ItemStructuralFunction, ItemLink)], [(ItemStructuralFunction, ItemLink)]) +--itemToBreakLists itm itmf = (fmap f l, fmap f r) +-- where +-- f x = (x, SFLink x) +-- (l,r) = itemToBreakLists' itm itmf + itemToBreakLists :: - Item -> - ItemStructuralFunction -> - ([(ItemStructuralFunction, ItemLink)], [(ItemStructuralFunction, ItemLink)]) -itemToBreakLists itm itmf = (fmap f l, fmap f r) - where - f x = (x, SFLink x) - (l,r) = itemToBreakLists' itm itmf - -itemToBreakLists' :: Item -> ItemStructuralFunction -> ([(ItemStructuralFunction)], [(ItemStructuralFunction)]) -itemToBreakLists' itm itmf = case (itm ^. itType, itmf) of +itemToBreakLists itm itmf = case (itm ^. itType, itmf) of (HELD TORCH, _) -> (getAmmoLinks itm, []) (ATTACH UNDERBARRELSLOT, _) -> ([(UnderBarrelPlatformSF)], []) (_, HeldPlatformSF) -> @@ -179,8 +178,8 @@ itemToFunction itm = case itm ^. itType of CLICKER{} -> GadgetPlatformSF _ -> NoSF -treeToPotentialFunction :: LDTree ItemLink CItem -> S.Set ItemStructuralFunction -treeToPotentialFunction ldt = case ldt ^. ldtValue . _1 . itType of +treeToPotentialFunction :: DTree CItem -> S.Set ItemStructuralFunction +treeToPotentialFunction ldt = case ldt ^. dtValue . _1 . itType of STICKYMOD -> S.singleton GrenadeHitEffectSF ATTACH GIMBAL -> S.singleton ProjectileStabiliserSF ATTACH GYROSCOPE -> S.singleton ProjectileStabiliserSF @@ -188,52 +187,52 @@ treeToPotentialFunction ldt = case ldt ^. ldtValue . _1 . itType of HELD BURSTRIFLE -> S.singleton UnderBarrelPlatformSF HELD LASER -> S.fromList [WeaponTargetingSF,LaserWeaponSF] -- following limits items to ten ammo slots - _ | AmmoMagSF _ x <- ldt ^. ldtValue . _2 -> S.fromList [AmmoMagSF i x | i <- [0..9]] - _ -> S.singleton (ldt ^. ldtValue . _2) + _ | AmmoMagSF _ x <- ldt ^. dtValue . _2 -> S.fromList [AmmoMagSF i x | i <- [0..9]] + _ -> S.singleton (ldt ^. dtValue . _2) baseCI :: Item -> CItem baseCI itm = (itm, itemToFunction itm) -type LDTComb a b = LDTree b a -> LDTree b a -> Maybe (LDTree b a) +type DTComb a = DTree a -> DTree a -> Maybe (DTree a) -leftIsParentCombine :: LDTComb CItem ItemLink +leftIsParentCombine :: DTComb CItem leftIsParentCombine ltree rtree = do let l = rightChildList ltree - xs = dropWhile ((\s -> not $ S.member s (treeToPotentialFunction rtree)) . fst) l - (sf,linktype) <- safeHead xs - return $ ltree & ldtRight .:~ (linktype, rtree & ldtValue . _2 .~ sf) + xs = dropWhile ((\s -> not $ S.member s (treeToPotentialFunction rtree))) l + (sf) <- safeHead xs + return $ ltree & dtRight .:~ ( rtree & dtValue . _2 .~ sf) -rightIsParentCombine :: LDTComb CItem ItemLink +rightIsParentCombine :: DTComb CItem rightIsParentCombine ltree rtree = do let l = leftChildList rtree - xs = dropWhile ((\s -> not $ S.member s (treeToPotentialFunction ltree)) . fst) l - (sf,linktype) <- safeHead xs - return $ rtree & ldtLeft .:~ (linktype, ltree & ldtValue . _2 .~ sf) + xs = dropWhile ((\s -> not $ S.member s (treeToPotentialFunction ltree))) l + (sf) <- safeHead xs + return $ rtree & dtLeft .:~ ( ltree & dtValue . _2 .~ sf) -leftChildList :: LDTree ItemLink CItem -> [(ItemStructuralFunction, ItemLink)] -leftChildList t = foldl' f l (reverse $ t ^.. ldtLeft . each . _2 . ldtValue . _2) +leftChildList :: DTree CItem -> [ItemStructuralFunction] +leftChildList t = foldl' f l (reverse $ t ^.. dtLeft . each . dtValue . _2) where - l = fst $ itemToBreakLists (t ^. ldtValue . _1) (t ^. ldtValue . _2) - f x y = tail $ dropWhile ((/=y) . fst) x + l = fst $ itemToBreakLists (t ^. dtValue . _1) (t ^. dtValue . _2) + f x y = tail $ dropWhile ((/=y) ) x -rightChildList :: LDTree ItemLink CItem -> [(ItemStructuralFunction, ItemLink)] -rightChildList t = foldl' f l (reverse $ t ^.. ldtRight . each . _2 . ldtValue . _2) +rightChildList :: DTree CItem -> [ItemStructuralFunction] +rightChildList t = foldl' f l (reverse $ t ^.. dtRight . each . dtValue . _2) where - l = snd $ itemToBreakLists (t ^. ldtValue . _1) (t ^. ldtValue . _2) - f x y = tail $ dropWhile ((/=y) . fst) x + l = snd $ itemToBreakLists (t ^. dtValue . _1) (t ^. dtValue . _2) + f x y = tail $ dropWhile ((/=y)) x leftRightCombine :: - LDTComb a b -> - LDTComb a b -> - LDTree b a -> - LDTree b a -> - Maybe (LDTree b a) + DTComb a -> + DTComb a -> + DTree a -> + DTree a -> + Maybe (DTree a) leftRightCombine f f' t1 t2 = f t1 t2 <|> checkdepth t1 t2 where - checkdepth t t'@(LDT x ls rs) = fromMaybe (checktop t t') $ do - (lab, t'') <- safeHead ls + checkdepth t t'@(DT x ls rs) = fromMaybe (checktop t t') $ do + (t'') <- safeHead ls tx <- checkdepth t t'' - return $ Just $ LDT x ((lab, tx) : tail ls) rs + return $ Just $ DT x (( tx) : tail ls) rs checktop t t' = f' t t' joinItemsInList :: (a -> a -> Maybe a) -> [a] -> [a] @@ -252,9 +251,9 @@ joinItemsInList f = fst . h . ([],) -- . fmap (singleLDT . baseCI) invDT :: IM.IntMap Item -> [DTree CItem] -invDT = fmap ldtToDT . +invDT = joinItemsInList tryAttachItems . IM.elems - . fmap (singleLDT . baseCI) + . fmap (singleDT . baseCI) --invLDT' :: IM.IntMap Item -> [LDTree ItemLink OItem] --invLDT' = fmap propagateOrientation . invLDT diff --git a/tags b/tags index c7919dd9a..dd2a945ce 100644 --- a/tags +++ b/tags @@ -434,6 +434,7 @@ DRUMMAG src/Dodge/Data/Item/Combine.hs 107;" C DS src/DoubleStack.hs 3;" t DT src/Dodge/Data/DoubleTree.hs 31;" C DTBottomNode src/Dodge/Data/DoubleTree.hs 21;" C +DTComb src/Dodge/Item/Grammar.hs 196;" t DTMidAboveNode src/Dodge/Data/DoubleTree.hs 19;" C DTMidBelowNode src/Dodge/Data/DoubleTree.hs 20;" C DTRootNode src/Dodge/Data/DoubleTree.hs 17;" C @@ -969,7 +970,6 @@ Kill src/Dodge/Data/ActionPlan.hs 198;" C LASER src/Dodge/Data/Item/Combine.hs 168;" C LDT src/Dodge/Data/DoubleTree.hs 34;" C LDTBottomNode src/Dodge/Data/DoubleTree.hs 29;" C -LDTComb src/Dodge/Item/Grammar.hs 196;" t LDTMidAboveNode src/Dodge/Data/DoubleTree.hs 27;" C LDTMidBelowNode src/Dodge/Data/DoubleTree.hs 28;" C LDTRootNode src/Dodge/Data/DoubleTree.hs 25;" C @@ -3348,7 +3348,6 @@ airlockDoor src/Dodge/Room/Airlock.hs 51;" f airlockDoubleDoor src/Dodge/Room/Airlock.hs 54;" f airlockSimple src/Dodge/Room/Airlock.hs 66;" f airlockZ src/Dodge/Room/Airlock.hs 91;" f -allInvLocs src/Dodge/Item/Grammar.hs 329;" f allVisibleWalls src/Dodge/Base/Collide.hs 132;" f alongSegBy src/Geometry.hs 40;" f alteRifle src/Dodge/Item/Held/Cane.hs 22;" f @@ -3561,6 +3560,7 @@ cardList src/Dodge/Base/CardinalPoint.hs 6;" f cardVec src/Dodge/Base/CardinalPoint.hs 9;" f cardinalVectors src/Dodge/FloorItem.hs 43;" f cartePosToScreen src/Dodge/Base/Coordinate.hs 37;" f +cdtPropagateFold src/Dodge/DoubleTree.hs 407;" f cenLasTur src/Dodge/Room/LasTurret.hs 24;" f centerText src/Picture/Base.hs 184;" f centerVaultExplosiveExit src/Dodge/Room/NoNeedWeapon.hs 20;" f @@ -3621,7 +3621,7 @@ clampPath src/Dodge/Room/Procedural.hs 166;" f clang1S src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 549;" f clang2S src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 663;" f clangS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 531;" f -cldtPropagateFold src/Dodge/DoubleTree.hs 352;" f +cldtPropagateFold src/Dodge/DoubleTree.hs 358;" f cleanUpPreload src/Preload.hs 10;" f cleanUpRenderPreload src/Preload/Render.hs 217;" f cleanUpSoundPreload src/Preload.hs 15;" f @@ -4656,10 +4656,8 @@ invHead src/Dodge/Render/HUD.hs 405;" f invIMDT src/Dodge/Item/Grammar.hs 295;" f invIndents src/Dodge/Item/Grammar.hs 307;" f invItemLocUpdate src/Dodge/Creature/State.hs 153;" f -invLDT src/Dodge/Item/Grammar.hs 248;" f invRootItemEffs src/Dodge/Creature/State.hs 146;" f invRootMap src/Dodge/Item/Grammar.hs 268;" f -invRootTrees src/Dodge/Item/Grammar.hs 289;" f invSelectionItem src/Dodge/Inventory/SelectionList.hs 32;" f invSetSelection src/Dodge/Inventory.hs 185;" f invSetSelectionPos src/Dodge/Inventory.hs 193;" f @@ -4736,8 +4734,7 @@ itemScrollDisplay src/Dodge/Inventory/SelectionList.hs 121;" f itemScrollValue src/Dodge/Inventory/SelectionList.hs 148;" f itemSidePush src/Dodge/HeldUse.hs 418;" f itemString src/Dodge/Item/Display.hs 56;" f -itemToBreakLists src/Dodge/Item/Grammar.hs 55;" f -itemToBreakLists' src/Dodge/Item/Grammar.hs 64;" f +itemToBreakLists src/Dodge/Item/Grammar.hs 64;" f itemToFunction src/Dodge/Item/Grammar.hs 147;" f itemTreeSPic src/Dodge/Item/Draw/SPic.hs 24;" f itemTriggerType src/Dodge/BaseTriggerType.hs 15;" f @@ -4845,12 +4842,14 @@ loadSounds src/Dodge/SoundLogic/LoadSound.hs 18;" f loadingScreen src/Dodge/Concurrent.hs 56;" f loadingScreen src/Dodge/Menu/Loading.hs 8;" f loadme src/Dodge/Debug/Terminal.hs 139;" f -locDTGoHelp src/Dodge/DoubleTree.hs 342;" f -locDTGoLeft src/Dodge/DoubleTree.hs 323;" f -locDTGoRight src/Dodge/DoubleTree.hs 328;" f -locGoHelp src/Dodge/DoubleTree.hs 334;" f -locGoLeft src/Dodge/DoubleTree.hs 313;" f -locGoRight src/Dodge/DoubleTree.hs 318;" f +locDTGoHelp src/Dodge/DoubleTree.hs 348;" f +locDTGoLeft src/Dodge/DoubleTree.hs 329;" f +locDTGoRight src/Dodge/DoubleTree.hs 334;" f +locDTLeftmost src/Dodge/DoubleTree.hs 312;" f +locDTRightmost src/Dodge/DoubleTree.hs 315;" f +locGoHelp src/Dodge/DoubleTree.hs 340;" f +locGoLeft src/Dodge/DoubleTree.hs 319;" f +locGoRight src/Dodge/DoubleTree.hs 324;" f locLDTToLocDT src/Dodge/DoubleTree.hs 19;" f locLeftmost src/Dodge/DoubleTree.hs 306;" f locOrient src/Dodge/Item/HeldOffset.hs 57;" f @@ -5484,8 +5483,8 @@ rectXH src/Geometry/Polygon.hs 32;" f rectXY src/Geometry/Polygon.hs 35;" f rectanglePairs src/Dodge/LevelGen/DoorPane.hs 7;" f red src/Color.hs 14;" f -reduceLocDT src/Dodge/DoubleTree.hs 392;" f -reduceLocLDT src/Dodge/DoubleTree.hs 387;" f +reduceLocDT src/Dodge/DoubleTree.hs 398;" f +reduceLocLDT src/Dodge/DoubleTree.hs 393;" f reflDirWall src/Dodge/Base/Wall.hs 16;" f reflVelWall src/Dodge/Base/Wall.hs 24;" f reflVelWallDamp src/Dodge/Base/Wall.hs 20;" f @@ -6149,7 +6148,7 @@ triggerSwitchSPicLight src/Dodge/Placement/Instance/Button.hs 31;" f truncFaces src/Polyhedra/Geodesic.hs 53;" f truncate src/Polyhedra/Geodesic.hs 38;" f trunkDepth src/TreeHelp.hs 161;" f -tryAttachItems src/Dodge/Item/Grammar.hs 35;" f +tryAttachItems src/Dodge/Item/Grammar.hs 36;" f tryClickUse src/Dodge/Creature/YourControl.hs 221;" f tryCombine src/Dodge/Update/Input/InGame.hs 526;" f tryDropSelected src/Dodge/Update/Input/InGame.hs 125;" f