diff --git a/src/Dodge/Barreloid.hs b/src/Dodge/Barreloid.hs index 6af720c0d..a08d32e25 100644 --- a/src/Dodge/Barreloid.hs +++ b/src/Dodge/Barreloid.hs @@ -18,7 +18,7 @@ updateBarreloid cr = case cr ^?! crType . barrelType of -- should generate the sparks externally using new random generators updateExpBarrel :: Creature -> World -> World updateExpBarrel cr w - | _crHP cr > 0 = foldr ($) (hiss w & cWorld . creatures . at (_crID cr) .~ newCr) pierceSparks + | _crHP cr > 0 = foldl' (flip ($)) (hiss w & cWorld . creatures . at (_crID cr) .~ newCr) pierceSparks | otherwise = makeExplosionAt (_crPos cr) $ stopSounds w & cWorld . creatures . at (_crID cr) .~ Nothing where g = _randGen w @@ -33,7 +33,7 @@ updateExpBarrel cr w as = randomRs (-0.7, 0.7) g colids = randomRs (0, 11) g poss = _piercedPoints $ _csSpState $ _crState cr - newCr = Just $ applyFuseDamage $ set (crState . csDamage) [] $ damToExpBarrel damages cr + newCr = Just $ applyFuseDamage $ set (crState . csDamage) [] $ damsToExpBarrel damages cr applyFuseDamage cr' = cr' & crHP %~ subtract (length . _piercedPoints . _csSpState $ _crState cr') @@ -47,15 +47,15 @@ updateBarrel cr | _crHP cr > 0 = doDamage cr | otherwise = cWorld . creatures . at (_crID cr) .~ Nothing -damToExpBarrel :: [Damage] -> Creature -> Creature -damToExpBarrel ds cr = foldr damToExpBarrel' (foldr damToExpBarrel' cr pierceDam) otherDam +damsToExpBarrel :: [Damage] -> Creature -> Creature +damsToExpBarrel ds cr = foldl' damToExpBarrel (foldl' damToExpBarrel cr pierceDam) otherDam where (pierceDam, otherDam) = partition isPierce ds isPierce Damage{_dmType = PIERCING{}} = True isPierce _ = False -damToExpBarrel' :: Damage -> Creature -> Creature -damToExpBarrel' dm cr = case _dmType dm of +damToExpBarrel :: Creature -> Damage -> Creature +damToExpBarrel cr dm = case _dmType dm of PIERCING -> over (crState . csSpState . piercedPoints) ((:) $ int -.- _crPos cr) $ cr & crHP -~ div amount 200 diff --git a/src/Dodge/Block.hs b/src/Dodge/Block.hs index 3b6efbe41..5d7919191 100644 --- a/src/Dodge/Block.hs +++ b/src/Dodge/Block.hs @@ -23,7 +23,7 @@ import RandomHelp splinterBlock :: Block -> World -> World splinterBlock bl w = - foldr unshadowBlock w (_blShadows bl) -- foldr shiftTowardCen w (_blWallIDs bl) + foldl' unshadowBlock w (_blShadows bl) -- foldr shiftTowardCen w (_blWallIDs bl) & originsIDsAt [MaterialSound bm 0, MaterialSound bm 1, MaterialSound bm 2] (weakenMatS bm) @@ -34,8 +34,8 @@ splinterBlock bl w = (wlid, _) <- IS.minView wlids w ^? cWorld . walls . ix wlid . wlMaterial -unshadowBlock :: Int -> World -> World -unshadowBlock wlid w = case w ^? cWorld . walls . ix wlid of +unshadowBlock :: World -> Int -> World +unshadowBlock w wlid = case w ^? cWorld . walls . ix wlid of Just wl -> w & cWorld . walls . ix wlid . wlUnshadowed .~ True @@ -50,13 +50,13 @@ checkBlockHP bl destroyBlock :: Block -> World -> World destroyBlock bl w = w - & flip (foldr unshadowBlock) (_blShadows bl) + & flip (foldl' unshadowBlock) (_blShadows bl) & makeBlockDebris bl & deleteWallIDs wlids & maybeClearPaths (_blObstructs bl) -- must happen after the walls are deleted & cWorld . blocks %~ IM.delete (_blID bl) -- & matDesSound (_blMaterial bl) pos - & flip (foldr (wlDustAt awl)) (map (pos +.+) ps) + & flip (foldl' $ flip (wlDustAt awl)) (map (pos +.+) ps) where wlids = _blWallIDs bl awl = _walls (_cWorld w) IM.! IS.findMin wlids @@ -79,7 +79,7 @@ destroyDoor dr w = & doDrWdWd (_drDeath dr) dr & deleteWallIDs wlids & cWorld . doors %~ IM.delete (_drID dr) - & flip (foldr (wlDustAt awl)) (map (pos +.+) ps) + & flip (foldl' (flip $ wlDustAt awl)) (map (pos +.+) ps) & stopPushing (_drPushes dr) & destroyMounts (_drMounts dr) where @@ -89,7 +89,7 @@ destroyDoor dr w = ps = replicateM 25 (randInCirc 20) & evalState $ _randGen w destroyMounts :: [MountedObject] -> World -> World -destroyMounts mos w = foldr destroyMount w mos +destroyMounts mos w = foldl' (flip destroyMount) w mos destroyMount :: MountedObject -> World -> World destroyMount mo = case mo of diff --git a/src/Dodge/Block/Debris.hs b/src/Dodge/Block/Debris.hs index 548e71242..ccbb8c558 100644 --- a/src/Dodge/Block/Debris.hs +++ b/src/Dodge/Block/Debris.hs @@ -26,7 +26,7 @@ makeDoorDebris dr w = w & makeDebris mt col p return (_wlMaterial wl, _wlColor wl) makeBlockDebris :: Block -> World -> World -makeBlockDebris bl w = foldr (makeDebris mt col) w ps +makeBlockDebris bl w = foldl' (flip $ makeDebris mt col) w ps where dsize = debrisSize mt ps = gridInPolygon dsize $ shrinkPolyOnEdges dsize $ reverse (_blFootprint bl) diff --git a/src/Dodge/Bullet.hs b/src/Dodge/Bullet.hs index beef6b15b..f638c00ba 100644 --- a/src/Dodge/Bullet.hs +++ b/src/Dodge/Bullet.hs @@ -3,6 +3,7 @@ module Dodge.Bullet ( useAmmoParams, ) where +import Data.Foldable import Data.Maybe import Dodge.Base.Coordinate import Dodge.Creature.HandPos @@ -39,7 +40,7 @@ mvBullet x w bu applyMagnetsToBul :: Bullet -> World -> Bullet applyMagnetsToBul bu = - foldr (\mg -> doMagnetBuBu (_mgField mg) mg) bu . _magnets . _cWorld + foldl' (flip doMagnetBuBu) bu . _magnets . _cWorld updateBulVel :: Bullet -> Bullet updateBulVel bt = case _buTrajectory bt of diff --git a/src/Dodge/Combine/Module.hs b/src/Dodge/Combine/Module.hs index 55f53feab..13ba85f8a 100644 --- a/src/Dodge/Combine/Module.hs +++ b/src/Dodge/Combine/Module.hs @@ -1,9 +1,9 @@ module Dodge.Combine.Module where +import Data.Foldable import Dodge.Item.Targeting import Dodge.Data.Beam import Dodge.Data.Item ---import Dodge.Item.Weapon.ExtraEffect import Dodge.Tesla import Geometry import LensHelp @@ -53,4 +53,4 @@ moduleModification imt = case imt of -- a = argV (mouseWorldPos w -.- p) applyModules :: Item -> Item -applyModules it = foldr moduleModification it (_iyModules (_itType it)) +applyModules it = foldl' (flip moduleModification) it (it ^. itType . iyModules) diff --git a/src/Dodge/Creature/Impulse.hs b/src/Dodge/Creature/Impulse.hs index 1a5622a36..11fe32e53 100644 --- a/src/Dodge/Creature/Impulse.hs +++ b/src/Dodge/Creature/Impulse.hs @@ -4,6 +4,7 @@ module Dodge.Creature.Impulse ( impulsiveAIBefore, ) where +import Data.Foldable import Control.Monad.State import Data.Bifunctor import Dodge.Creature.Impulse.Movement @@ -29,7 +30,7 @@ impulsiveAIBefore f cr w = g w & cWorld . creatures . ix (_crID cr) .~ cr' (g, cr') = followImpulses w $ f w cr followImpulses :: World -> Creature -> (World -> World, Creature) -followImpulses w cr = foldr f (id, cr) (_apImpulse $ _crActionPlan cr) +followImpulses w cr = foldl' (flip f) (id, cr) (reverse $ _apImpulse $ _crActionPlan cr) where f imp (theupdate, cr') = first (. theupdate) $ followImpulse cr' w imp diff --git a/src/Dodge/Creature/Impulse/UseItem.hs b/src/Dodge/Creature/Impulse/UseItem.hs index a86e2e5e5..1df721444 100644 --- a/src/Dodge/Creature/Impulse/UseItem.hs +++ b/src/Dodge/Creature/Impulse/UseItem.hs @@ -4,6 +4,7 @@ module Dodge.Creature.Impulse.UseItem ( itemEffect, ) where +import Data.Foldable import Control.Lens import qualified Data.Map.Strict as M import Data.Maybe @@ -29,7 +30,7 @@ useItem cr' w = fromMaybe (f w) $ do itemEffect :: Creature -> Item -> World -> World itemEffect cr it w = case it ^. itUse of HeldUse{_heldUse = eff, _heldMods = usemods} -> - hammerTest $ tryReload cr it w $ foldr ($) (useHeld eff) (useMod usemods) it cr + hammerTest $ tryReload cr it w $ foldl' (flip ($)) (useHeld eff) (reverse $ useMod usemods) it cr LeftUse{} -> doequipmentchange EquipUse{} -> doequipmentchange -- ConsumeUse will cause problems if the item is not selected diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index cd7615e50..d1c18b047 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -3,6 +3,7 @@ module Dodge.Creature.State ( doDamage, ) where +import Data.Foldable import Dodge.Base import Dodge.Corpse.Make import Dodge.Creature.Action @@ -34,9 +35,9 @@ foldCr :: World -> World --foldCr xs cr w = foldr ($ cr) w xs -foldCr xs cr w = foldr f w xs +foldCr xs cr w = foldl' f w $ reverse xs where - f g w' = case w' ^? cWorld . creatures . ix (_crID cr) of + f w' g = case w' ^? cWorld . creatures . ix (_crID cr) of Just cr' -> g cr' w' Nothing -> w' @@ -216,13 +217,13 @@ upInv cr = cWorld . creatures . ix (_crID cr) . crInv %~ IM.mapWithKey (itemUpda -- a loop going over equipped items equipmentEffects :: Creature -> World -> World -equipmentEffects cr = flip (foldr $ useEquipment cr) (IM.keys $ _crInvEquipped cr) +equipmentEffects cr = flip (foldl' $ flip $ useEquipment cr) (IM.keys $ _crInvEquipped cr) -- a loop going over all inventory items invSideEff :: Creature -> World -> World -invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr) +invSideEff cr w = weaponReloadSounds cr $ IM.foldlWithKey' f w (_crInv cr) where - f i it w' = + f w' i it = itemInvSideEffect cr it $ doItemTargeting i cr w' & maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv) diff --git a/src/Dodge/Creature/YourControl.hs b/src/Dodge/Creature/YourControl.hs index e3a36c904..ca5a68812 100644 --- a/src/Dodge/Creature/YourControl.hs +++ b/src/Dodge/Creature/YourControl.hs @@ -2,6 +2,7 @@ module Dodge.Creature.YourControl ( yourControl, ) where +import Data.Foldable import qualified Data.Map.Strict as M import Dodge.Base.Coordinate import Dodge.Creature.Impulse.Movement @@ -72,7 +73,7 @@ wasdM scancode = case scancode of _ -> V2 0 0 wasdDir :: World -> Point2 -wasdDir = foldr ((+.+) . wasdM) (V2 0 0) . _keys +wasdDir = foldl' (flip $ (+.+) . wasdM) (V2 0 0) . _keys -- | Set posture according to mouse presses. mouseActionsCr :: M.Map SDL.MouseButton Bool -> Creature -> Creature diff --git a/src/Dodge/Damage.hs b/src/Dodge/Damage.hs index 9a2958fdb..24994aa9f 100644 --- a/src/Dodge/Damage.hs +++ b/src/Dodge/Damage.hs @@ -30,7 +30,7 @@ damageDirection ds = do safeArgV (_dmTo dm -.- _dmFrom dm) collectDamageTypes :: [Damage] -> M.Map DamageType Int -collectDamageTypes = foldr f M.empty +collectDamageTypes = foldl' (flip f) M.empty where f dm = M.insertWith (+) (_dmType dm) (_dmAmount dm) diff --git a/src/Dodge/MagnetBuBu.hs b/src/Dodge/MagnetBuBu.hs index adfb8fd98..42b5dbfc0 100644 --- a/src/Dodge/MagnetBuBu.hs +++ b/src/Dodge/MagnetBuBu.hs @@ -4,8 +4,8 @@ import Dodge.Magnet import Dodge.Data.Bullet import Dodge.Data.Magnet -doMagnetBuBu :: MagnetBuBu -> Magnet -> Bullet -> Bullet -doMagnetBuBu mbb = case mbb of - MagnetBuId -> const id - MagnetBuBuCurveAroundField x y -> curveAroundField x y +doMagnetBuBu :: Magnet -> Bullet -> Bullet +doMagnetBuBu mg = case _mgField mg of + MagnetBuId -> id + MagnetBuBuCurveAroundField x y -> curveAroundField x y mg