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
+6
View File
@@ -146,3 +146,9 @@ dbArg f x = f x x
-- TODO check whether this is simply the reader monad, flipped -- TODO check whether this is simply the reader monad, flipped
dbArgChain :: (a -> b -> b) -> (a -> b -> b) -> a -> b -> b dbArgChain :: (a -> b -> b) -> (a -> b -> b) -> a -> b -> b
dbArgChain f g x = f x . g x dbArgChain f g x = f x . g x
spreadAroundCenter :: Int -> Float -> [Float]
spreadAroundCenter i x = [x * fromIntegral j - x*fromIntegral (i-1)*0.5 | j <- [0 .. i - 1]]
spreadFromCenter :: Int -> Float -> [Float]
spreadFromCenter i x = [x * fromIntegral j - x*fromIntegral (i-1)*0.5 | j <- [0 .. i - 1]]
+19 -19
View File
@@ -48,7 +48,7 @@ data ItemParams
{ _muzVel :: Float { _muzVel :: Float
, _rifling :: Float , _rifling :: Float
, _bore :: Float , _bore :: Float
, _gunBarrels :: GunBarrels , _gunBarrels :: [GunBarrel]
, _recoil :: Float , _recoil :: Float
, _torqueAfter :: Float , _torqueAfter :: Float
, _randomOffset :: Float , _randomOffset :: Float
@@ -82,15 +82,15 @@ data GunBarrel = GunBarrel
, _barlInaccuracy :: Float , _barlInaccuracy :: Float
} }
data GunBarrels --data GunBarrels
= MultiBarrel ---- = MultiBarrel
{ _brlSpread :: BarrelSpread ---- { _brlSpread :: BarrelSpread
, _brlNum :: Int ---- , _brlNum :: Int
, _brlInaccuracy :: Float ---- , _brlInaccuracy :: Float
} ---- }
| BarrelList -- = BarrelList
{ _brlList :: [GunBarrel] -- { _brlList :: [GunBarrel]
} -- }
--deriving (Eq, Ord, Show, Read) --Generic, Flat) --deriving (Eq, Ord, Show, Read) --Generic, Flat)
data Nozzle = Nozzle data Nozzle = Nozzle
@@ -103,21 +103,21 @@ data Nozzle = Nozzle
} }
--deriving (Eq, Ord, Show, Read) --Generic, Flat) --deriving (Eq, Ord, Show, Read) --Generic, Flat)
data BarrelSpread --data BarrelSpread
= AlignedBarrels -- = AlignedBarrels
| SpreadBarrels {_spreadAngle :: Float} -- | SpreadBarrels {_spreadAngle :: Float}
| RotatingBarrels {_rotatingBarrelInaccuracy :: Float} -- | RotatingBarrels {_rotatingBarrelInaccuracy :: Float}
--deriving (Eq, Ord, Show, Read) --Generic, Flat) -- --deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''BarrelSpread --makeLenses ''BarrelSpread
makeLenses ''ItemParams makeLenses ''ItemParams
makeLenses ''Nozzle makeLenses ''Nozzle
makeLenses ''GunBarrels --makeLenses ''GunBarrels
makeLenses ''GunBarrel makeLenses ''GunBarrel
deriveJSON defaultOptions ''ShrinkGunStatus deriveJSON defaultOptions ''ShrinkGunStatus
deriveJSON defaultOptions ''PreviousArcEffect deriveJSON defaultOptions ''PreviousArcEffect
deriveJSON defaultOptions ''Nozzle deriveJSON defaultOptions ''Nozzle
deriveJSON defaultOptions ''BarrelSpread --deriveJSON defaultOptions ''BarrelSpread
deriveJSON defaultOptions ''GunBarrel deriveJSON defaultOptions ''GunBarrel
deriveJSON defaultOptions ''GunBarrels --deriveJSON defaultOptions ''GunBarrels
deriveJSON defaultOptions ''ItemParams deriveJSON defaultOptions ''ItemParams
+3 -4
View File
@@ -208,12 +208,11 @@ useMod hm = case hm of
reverse $ withPosDirWallCheck directedTelPos : useMod hm' reverse $ withPosDirWallCheck directedTelPos : useMod hm'
BangStickMod -> BangStickMod ->
[ withRecoil [ withRecoil
-- , applyInaccuracy
, spreadLoaded
, withTorqueAfter
, withMuzFlareI
, useAllAmmo , useAllAmmo
, withSoundItemChoiceStart bangStickSoundChoice , withSoundItemChoiceStart bangStickSoundChoice
, duplicateLoadedBarrels
, withTorqueAfter
, withMuzFlareI
, useTimeCheck , useTimeCheck
, ammoCheckI , ammoCheckI
, blCheck , blCheck
+5 -12
View File
@@ -118,14 +118,10 @@ ammoPosition itm hit = case hit of
rhs = Q.axisAngle (V3 1 0 0) 0 rhs = Q.axisAngle (V3 1 0 0) 0
bangStickAmmoPos :: Int -> Item -> AmmoPosition bangStickAmmoPos :: Int -> Item -> AmmoPosition
bangStickAmmoPos i itm = bangStickAmmoPos _ itm =
Bullets Bullets
[(rotate3z a (V3 5 0 3), Q.axisAngle (V3 0 0 1) a) | a <- map f [0 .. i - 1]] [(rotate3z a (V3 5 0 3), Q.axisAngle (V3 0 0 1) a)
where | a <- map _barlRot (itm ^?! itParams . gunBarrels)]
f n =
barrelspread * fromIntegral n
- 0.5 * barrelspread * fromIntegral (_brlNum (_gunBarrels (_itParams itm)) -1)
barrelspread = itm ^?! itParams . gunBarrels . brlSpread . spreadAngle
volleygunAmmoPos :: Int -> AmmoPosition volleygunAmmoPos :: Int -> AmmoPosition
volleygunAmmoPos i = volleygunAmmoPos i =
@@ -212,12 +208,9 @@ modulesSPic it _ imt = case imt of
_ -> mempty _ -> mempty
baseStickShapeX :: Item -> Int -> Shape baseStickShapeX :: Item -> Int -> Shape
baseStickShapeX it i = foldMap f [0 .. i -1] baseStickShapeX it _ = foldMap f (it ^?! itParams . gunBarrels)
where where
f j = rotateSH ang baseStickShape f brl = rotateSH (_barlRot brl) baseStickShape
where
ang = fromIntegral j * barrelspread - (fromIntegral i - 1) * barrelspread * 0.5
barrelspread = it ^?! itParams . gunBarrels . brlSpread . spreadAngle
baseStickShape :: Shape baseStickShape :: Shape
baseStickShape = colorSH green $ xCylinderST 3 10 baseStickShape = colorSH green $ xCylinderST 3 10
+6 -15
View File
@@ -7,7 +7,7 @@ module Dodge.Item.Held.Cane (
miniGunX, miniGunX,
) where ) where
import Dodge.Item.Held.SingleBarrel import Dodge.Base
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Default import Dodge.Default
import Dodge.Reloading.Action import Dodge.Reloading.Action
@@ -22,7 +22,7 @@ defaultBangCane =
{ _muzVel = 0.8 { _muzVel = 0.8
, _rifling = 0.9 , _rifling = 0.9
, _bore = 2 , _bore = 2
, _gunBarrels = singleBarrel 0.01 , _gunBarrels = [GunBarrel 0 0 0.01]
, _recoil = 50 , _recoil = 50
, _torqueAfter = 0.1 , _torqueAfter = 0.1
, _randomOffset = 0 , _randomOffset = 0
@@ -54,17 +54,13 @@ volleyGun i =
{ _muzVel = 0.8 { _muzVel = 0.8
, _rifling = 0.9 , _rifling = 0.9
, _bore = 2 , _bore = 2
, _gunBarrels = singleBarrel 0.01 , _gunBarrels = [GunBarrel 0 0 0.01]
, _recoil = 50 , _recoil = 50
, _torqueAfter = 0.1 , _torqueAfter = 0.1
, _randomOffset = 0 , _randomOffset = 0
} }
& itParams . gunBarrels & itParams . gunBarrels
.~ MultiBarrel .~ [ GunBarrel (V2 0 x) 0 0.1 | x <- spreadAroundCenter i 3]
{ _brlSpread = AlignedBarrels
, _brlNum = i
, _brlInaccuracy = 0.1
}
& itParams . torqueAfter .~ 0.48 + 0.2 * fromIntegral i & itParams . torqueAfter .~ 0.48 + 0.2 * fromIntegral i
& itType . iyBase .~ HELD (VOLLEYGUN i) & itType . iyBase .~ HELD (VOLLEYGUN i)
@@ -100,7 +96,7 @@ burstRifle :: Item
burstRifle = burstRifle =
repeater repeater
& itType . iyBase .~ HELD BURSTRIFLE & itType . iyBase .~ HELD BURSTRIFLE
& itParams . gunBarrels . brlInaccuracy .~ 0.05 & itParams . gunBarrels . ix 0 . barlInaccuracy .~ 0.05
& itUse . heldDelay . rateMax .~ 18 & itUse . heldDelay . rateMax .~ 18
& itUse . heldMods .~ BurstRifleMod & itUse . heldMods .~ BurstRifleMod
@@ -133,12 +129,7 @@ miniGunX i =
{ _muzVel = 1 { _muzVel = 1
, _rifling = 0.9 , _rifling = 0.9
, _bore = 2 , _bore = 2
, _gunBarrels = , _gunBarrels = replicate i (GunBarrel 0 0 0.05)
MultiBarrel
{ _brlSpread = RotatingBarrels 0.01
, _brlNum = i
, _brlInaccuracy = 0
}
, _recoil = 10 , _recoil = 10
, _torqueAfter = 0 , _torqueAfter = 0
, _randomOffset = 10 , _randomOffset = 10
+1 -2
View File
@@ -1,6 +1,5 @@
module Dodge.Item.Held.Cone module Dodge.Item.Held.Cone
where where
import Dodge.Item.Held.SingleBarrel
import Dodge.Default.Item import Dodge.Default.Item
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Reloading.Action import Dodge.Reloading.Action
@@ -15,7 +14,7 @@ bangCone =
{ _muzVel = 0.7 { _muzVel = 0.7
, _rifling = 0.8 , _rifling = 0.8
, _bore = 5 , _bore = 5
, _gunBarrels = singleBarrel 0.5 , _gunBarrels = [GunBarrel 0 0 0.5]
, _recoil = 150 , _recoil = 150
, _torqueAfter = 0.1 , _torqueAfter = 0.1
, _randomOffset = 12 , _randomOffset = 12
+3 -4
View File
@@ -7,7 +7,6 @@ module Dodge.Item.Held.Rod (
machineGun, machineGun,
) where ) where
import Dodge.Item.Held.SingleBarrel
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Default import Dodge.Default
import Dodge.Item.Weapon.Bullet import Dodge.Item.Weapon.Bullet
@@ -23,7 +22,7 @@ bangRod =
{ _muzVel = 0.8 { _muzVel = 0.8
, _rifling = 1 , _rifling = 1
, _bore = 2 , _bore = 2
, _gunBarrels = singleBarrel 0.1 , _gunBarrels = [GunBarrel 0 0 0.1]
, _recoil = 50 , _recoil = 50
, _torqueAfter = 0.3 , _torqueAfter = 0.3
, _randomOffset = 0 , _randomOffset = 0
@@ -48,7 +47,7 @@ elephantGun =
bangRod bangRod
& itType . iyBase .~ HELD ELEPHANTGUN & itType . iyBase .~ HELD ELEPHANTGUN
& itUse . heldAim . aimStance .~ TwoHandTwist & itUse . heldAim . aimStance .~ TwoHandTwist
& itParams . gunBarrels .~ singleBarrel 0.05 & itParams . gunBarrels .~ [GunBarrel 0 0 0.05]
& itUse . heldMods .~ ElephantGunMod & itUse . heldMods .~ ElephantGunMod
& itParams . recoil .~ 50 & itParams . recoil .~ 50
& itParams . torqueAfter .~ 0.1 & itParams . torqueAfter .~ 0.1
@@ -69,7 +68,7 @@ sniperRifle :: Item
sniperRifle = sniperRifle =
elephantGun elephantGun
& itType . iyBase .~ HELD SNIPERRIFLE & itType . iyBase .~ HELD SNIPERRIFLE
& itParams . gunBarrels .~ singleBarrel 0 & itParams . gunBarrels .~ [GunBarrel 0 0 0]
& itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5,_izFac = 1} & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5,_izFac = 1}
& itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
& itScope .~ ZoomScope (V2 0 0) 1 0.5 False & itScope .~ ZoomScope (V2 0 0) 1 0.5 False
+3 -8
View File
@@ -8,7 +8,7 @@ module Dodge.Item.Held.Stick (
revolverX, revolverX,
) where ) where
import Dodge.Item.Held.SingleBarrel import Dodge.Base
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Default.Item import Dodge.Default.Item
import Dodge.Reloading.Action import Dodge.Reloading.Action
@@ -23,12 +23,7 @@ bangStick i =
{ _muzVel = 0.8 { _muzVel = 0.8
, _rifling = 0.8 , _rifling = 0.8
, _bore = 2 , _bore = 2
, _gunBarrels = , _gunBarrels = [GunBarrel 0 a 0.01 | a <- spreadAroundCenter i baseStickSpread]
MultiBarrel
{ _brlNum = i
, _brlSpread = SpreadBarrels baseStickSpread
, _brlInaccuracy = 0.01
}
, _recoil = 25 , _recoil = 25
, _torqueAfter = 0.18 + 0.02 * fromIntegral i , _torqueAfter = 0.18 + 0.02 * fromIntegral i
, _randomOffset = 0 , _randomOffset = 0
@@ -71,7 +66,7 @@ pistol =
%~ ( (muzVel .~ 0.8) %~ ( (muzVel .~ 0.8)
. (rifling .~ 0.8) . (rifling .~ 0.8)
. (bore .~ 2) . (bore .~ 2)
. (gunBarrels .~ singleBarrel 0.05) . (gunBarrels .~ [GunBarrel 0 0 0.05])
. (recoil .~ 10) . (recoil .~ 10)
. (torqueAfter .~ 0.2) . (torqueAfter .~ 0.2)
) )
+27 -34
View File
@@ -44,8 +44,8 @@ module Dodge.Item.Weapon.TriggerType (
withSidePushAfterI, withSidePushAfterI,
withSidePushI, withSidePushI,
withWarmUp, withWarmUp,
spreadNumI, --spreadNumI,
spreadLoaded, --spreadLoaded,
repeatOnFrames, repeatOnFrames,
sideEffectOnFrame, sideEffectOnFrame,
duplicateItem, duplicateItem,
@@ -63,7 +63,6 @@ module Dodge.Item.Weapon.TriggerType (
blCheck, blCheck,
) where ) where
import Control.Applicative
import qualified SDL import qualified SDL
import Data.Foldable import Data.Foldable
import Data.Maybe import Data.Maybe
@@ -498,10 +497,7 @@ crAtMuzPos f it cr = f it (cr & crPos +.+.~ (aimingMuzzlePos cr it *.* unitVecto
applyInaccuracy :: ChainEffect applyInaccuracy :: ChainEffect
applyInaccuracy f it = withRandomDirI acc f it applyInaccuracy f it = withRandomDirI acc f it
where where
acc = fromMaybe 0 $ acc = fromMaybe 0 $ it ^? itParams . gunBarrels . ix 0 . barlInaccuracy
(it ^? itParams . gunBarrels . brlList . ix 0 . barlInaccuracy)
<|>
(it ^? itParams . gunBarrels . brlInaccuracy)
-- | Applies the effect to a randomly rotated creature. -- | Applies the effect to a randomly rotated creature.
withRandomDirI :: withRandomDirI ::
@@ -616,26 +612,26 @@ withTorqueAfter feff item cr w
(rot, g) = randomR (- torque, torque) $ _randGen w (rot, g) = randomR (- torque, torque) $ _randGen w
torque = fromMaybe 0 $ item ^? itParams . torqueAfter torque = fromMaybe 0 $ item ^? itParams . torqueAfter
spreadNumI :: ChainEffect --spreadNumI :: ChainEffect
spreadNumI eff item cr w = foldr f w dirs --spreadNumI eff item cr w = foldr f w dirs
where -- where
dirs = -- dirs =
zipWith -- zipWith
(+) -- (+)
[- spread, - spread + (2 * spread / fromIntegral numBul) .. spread] -- [- spread, - spread + (2 * spread / fromIntegral numBul) .. spread]
(randomRs (0, spread / fromIntegral numBul) (_randGen w)) -- (randomRs (0, spread / fromIntegral numBul) (_randGen w))
f dir = eff item (cr & crDir +~ dir) -- f dir = eff item (cr & crDir +~ dir)
spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item -- spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
numBul = _brlNum . _gunBarrels $ _itParams item -- numBul = _brlNum . _gunBarrels $ _itParams item
spreadLoaded :: ChainEffect --spreadLoaded :: ChainEffect
spreadLoaded eff item cr w = foldr f w dirs --spreadLoaded eff item cr w = foldr f w dirs
where -- where
cd = 0.5 * spread * fromIntegral (numBulLoaded -1) -- cd = 0.5 * spread * fromIntegral (numBulLoaded -1)
dirs = subtract cd . (spread *) . fromIntegral <$> [0 .. numBulLoaded - 1] -- dirs = subtract cd . (spread *) . fromIntegral <$> [0 .. numBulLoaded - 1]
f dir = eff item (cr & crDir +~ dir) -- f dir = eff item (cr & crDir +~ dir)
spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item -- spread = _spreadAngle . _brlSpread . _gunBarrels $ _itParams item
numBulLoaded = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded -- numBulLoaded = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
sideEffectOnFrame :: sideEffectOnFrame ::
Int -> Int ->
@@ -673,15 +669,12 @@ duplicateLoaded eff it cr w = foldr f w [1 .. numBul]
numBul = it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded numBul = it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
duplicateLoadedBarrels :: ChainEffect 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 where
cp :: Float numbul = itm ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
cp = -0.5 * (fromIntegral numBar - 1) f brl = eff itm (cr & crPos +~ _barlPos brl
poss :: [V2 Float] & crDir +~ _barlRot brl
poss = map (rotateV (_crDir cr) . V2 0 . (* 5) . (+ cp) . fromIntegral) [0 .. numBul - 1] ) -- worry about inaccuracy later
f pos = eff item (cr & crPos %~ (+.+ pos))
numBar = _brlNum . _gunBarrels $ _itParams item
numBul = item ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
duplicateOffsetsFocus :: [Float] -> ChainEffect duplicateOffsetsFocus :: [Float] -> ChainEffect
duplicateOffsetsFocus xs eff item cr w = foldr f w poss duplicateOffsetsFocus xs eff item cr w = foldr f w poss