Explicitly store list of barrels for weapons

This commit is contained in:
2023-05-20 17:48:51 +01:00
parent 03611c6b95
commit 4cfb7d431a
9 changed files with 73 additions and 98 deletions
+27 -34
View File
@@ -44,8 +44,8 @@ module Dodge.Item.Weapon.TriggerType (
withSidePushAfterI,
withSidePushI,
withWarmUp,
spreadNumI,
spreadLoaded,
--spreadNumI,
--spreadLoaded,
repeatOnFrames,
sideEffectOnFrame,
duplicateItem,
@@ -63,7 +63,6 @@ module Dodge.Item.Weapon.TriggerType (
blCheck,
) where
import Control.Applicative
import qualified SDL
import Data.Foldable
import Data.Maybe
@@ -498,10 +497,7 @@ crAtMuzPos f it cr = f it (cr & crPos +.+.~ (aimingMuzzlePos cr it *.* unitVecto
applyInaccuracy :: ChainEffect
applyInaccuracy f it = withRandomDirI acc f it
where
acc = fromMaybe 0 $
(it ^? itParams . gunBarrels . brlList . ix 0 . barlInaccuracy)
<|>
(it ^? itParams . gunBarrels . brlInaccuracy)
acc = fromMaybe 0 $ it ^? itParams . gunBarrels . ix 0 . barlInaccuracy
-- | Applies the effect to a randomly rotated creature.
withRandomDirI ::
@@ -616,26 +612,26 @@ withTorqueAfter feff item cr w
(rot, g) = randomR (- torque, torque) $ _randGen w
torque = fromMaybe 0 $ item ^? itParams . torqueAfter
spreadNumI :: ChainEffect
spreadNumI eff item cr w = foldr f w dirs
where
dirs =
zipWith
(+)
[- spread, - spread + (2 * spread / fromIntegral numBul) .. spread]
(randomRs (0, spread / fromIntegral numBul) (_randGen w))
f dir = eff item (cr & crDir +~ dir)
spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
numBul = _brlNum . _gunBarrels $ _itParams item
--spreadNumI :: ChainEffect
--spreadNumI eff item cr w = foldr f w dirs
-- where
-- dirs =
-- zipWith
-- (+)
-- [- spread, - spread + (2 * spread / fromIntegral numBul) .. spread]
-- (randomRs (0, spread / fromIntegral numBul) (_randGen w))
-- f dir = eff item (cr & crDir +~ dir)
-- spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
-- numBul = _brlNum . _gunBarrels $ _itParams item
spreadLoaded :: ChainEffect
spreadLoaded eff item cr w = foldr f w dirs
where
cd = 0.5 * spread * fromIntegral (numBulLoaded -1)
dirs = subtract cd . (spread *) . fromIntegral <$> [0 .. numBulLoaded - 1]
f dir = eff item (cr & crDir +~ dir)
spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
numBulLoaded = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
--spreadLoaded :: ChainEffect
--spreadLoaded eff item cr w = foldr f w dirs
-- where
-- cd = 0.5 * spread * fromIntegral (numBulLoaded -1)
-- dirs = subtract cd . (spread *) . fromIntegral <$> [0 .. numBulLoaded - 1]
-- f dir = eff item (cr & crDir +~ dir)
-- spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
-- numBulLoaded = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
sideEffectOnFrame ::
Int ->
@@ -673,15 +669,12 @@ duplicateLoaded eff it cr w = foldr f w [1 .. numBul]
numBul = it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
duplicateLoadedBarrels :: ChainEffect
duplicateLoadedBarrels eff item cr w = foldr f w poss
duplicateLoadedBarrels eff itm cr w = foldr f w (take numbul $ itm ^?! itParams . gunBarrels)
where
cp :: Float
cp = -0.5 * (fromIntegral numBar - 1)
poss :: [V2 Float]
poss = map (rotateV (_crDir cr) . V2 0 . (* 5) . (+ cp) . fromIntegral) [0 .. numBul - 1]
f pos = eff item (cr & crPos %~ (+.+ pos))
numBar = _brlNum . _gunBarrels $ _itParams item
numBul = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
numbul = itm ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
f brl = eff itm (cr & crPos +~ _barlPos brl
& crDir +~ _barlRot brl
) -- worry about inaccuracy later
duplicateOffsetsFocus :: [Float] -> ChainEffect
duplicateOffsetsFocus xs eff item cr w = foldr f w poss