Replace some foldr with foldl'
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user