Continue refactor of bullet gun effect chain

This commit is contained in:
2024-09-16 23:34:54 +01:00
parent 40378d3de4
commit e23c7a0154
23 changed files with 404 additions and 396 deletions
+1 -1
View File
@@ -1 +1 @@
All good (616 modules, at 19:05:45)
All good (617 modules, at 23:34:46)
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+7 -2
View File
@@ -69,13 +69,18 @@ shootBullet itm cr w = fromMaybe (error "cannot find bullet ammo when expected t
& buPos .~ _crPos cr
& buTrajectory %~ settrajectory
& buVel %~ (rotateV dir . (muzvel *.*))
& buDrag *~ _rifling (_heldParams $ _itUse it)
& buDrag *~ drag
)
where
it = itm ^. ldtValue
sp = _crPos cr +.+ (muzlength ^?! _head . _x) *.* unitVectorAtAngle dir
dir = _crDir cr
muzvel = _muzVel $ _heldParams $ _itUse it
drag = case _rifling (_heldParams $ _itUse it) of
ConstFloat x -> x
UniRandFloat x y -> fst . randomR (x,y) $ _randGen w
muzvel = case _muzVel $ _heldParams $ _itUse it of
ConstFloat x -> x
UniRandFloat x y -> fst . randomR (x,y) $ _randGen w
muzlength = aimingMuzzlePos cr it
settrajectory traj = case traj of
BasicBulletTrajectory -> BasicBulletTrajectory
+2
View File
@@ -269,6 +269,8 @@ testInventory =
stackedInventory :: [Item]
stackedInventory =
[ burstRifle
, bangCone
, megaTinMag
, volleyGun 3
, tinMag
, tinMag
-1
View File
@@ -168,7 +168,6 @@ data HeldItemType
| GRAPECANNON {_xNum :: Int}
| MINIGUNX {_xNum :: Int}
| VOLLEYGUN {_xNum :: Int}
| MULTIGUN {_xNum :: Int}
| RIFLE
-- | REPEATER
| AUTORIFLE
+3 -3
View File
@@ -82,8 +82,8 @@ data HeldMod
-- | AmmoUseCheckMod
-- | AmmoHammerTimeUseOneMod
-- | BangCaneMod
| VolleyGunMod
| MultiGunMod
-- | VolleyGunMod
-- | MultiGunMod
-- | AutoRifleMod
| BangRodMod
| ElephantGunMod
@@ -98,7 +98,7 @@ data HeldMod
| BurstRifleRepeatMod
| MiniGunMod Int
-- | SmgMod
| BangConeMod
-- | BangConeMod
| TractorMod --apply with AmmoCheckMod
| FireRemoteShellMod
| ExplodeRemoteShellMod
+4 -2
View File
@@ -11,8 +11,10 @@ module Dodge.Data.Item.Use (
module Dodge.Data.Item.Use.Consumption,
module Dodge.Data.Hammer,
module Dodge.Data.Item.Targeting,
module Dodge.Data.GenFloat
) where
import Dodge.Data.GenFloat
import Sound.Data
import qualified Data.IntMap.Strict as IM
import Geometry.Data
@@ -74,8 +76,8 @@ data HeldParams
| GasSprayParams
{_gasCreation :: GasCreate}
| BulletShooterParams
{ _muzVel :: Float
, _rifling :: Float
{ _muzVel :: GenFloat
, _rifling :: GenFloat
, _recoil :: Float
, _torqueAfter :: Float
, _randomOffset :: Float
+1
View File
@@ -143,6 +143,7 @@ data LWorld = LWorld
, _selLocation :: Int
, _distortions :: [Distortion]
, _lClock :: Int
, _lTestString :: [String]
}
data WorldBeams = WorldBeams
{ _blockingBeams :: [Beam]
+2 -2
View File
@@ -36,8 +36,8 @@ defaultHeldUse =
, _heldAim = defaultAimParams
, _heldAmmoTypes = mempty
, _heldParams = BulletShooterParams
{ _muzVel = 0.8
, _rifling = 0.8
{ _muzVel = ConstFloat 0.8
, _rifling = ConstFloat 0.8
, _recoil = 10
, _torqueAfter = 0.2
, _randomOffset = 0
+1
View File
@@ -143,6 +143,7 @@ defaultLWorld =
, _foregroundShapes = mempty
, _distortions = []
, _lClock = 0
, _lTestString = []
}
defaultHUD :: HUD
+94 -92
View File
@@ -138,28 +138,28 @@ heldEffect effecttype = case effecttype of
-- , ammoCheckI
-- , blCheck
-- ]
VolleyGunMod -> bulletGunEffect
[ withRecoil
, withFlare
, duplicateLoadedBarrels
, withTorqueAfter
, useAllAmmo
, withSoundItemChoiceStart caneStickSoundChoice
, useTimeCheck
, ammoCheckI
, blCheck
]
MultiGunMod -> bulletGunEffect
[ withRecoil
, withFlare
, duplicateLoadedBarrels
, withTorqueAfter
, useAllAmmo
, withSoundItemChoiceStart caneStickSoundChoice
, useTimeCheck
, ammoCheckI
, blCheck
]
-- VolleyGunMod -> bulletGunEffect
-- [ withRecoil
-- , withFlare
-- , duplicateLoadedBarrels
-- , withTorqueAfter
-- , useAllAmmo
-- , withSoundItemChoiceStart caneStickSoundChoice
-- , useTimeCheck
-- , ammoCheckI
-- , blCheck
-- ]
-- MultiGunMod -> bulletGunEffect
-- [ withRecoil
-- , withFlare
-- , duplicateLoadedBarrels
-- , withTorqueAfter
-- , useAllAmmo
-- , withSoundItemChoiceStart caneStickSoundChoice
-- , useTimeCheck
-- , ammoCheckI
-- , blCheck
-- ]
-- AutoRifleMod -> bulletGunEffect
-- -- note this is the same as BangCanemMod with the first changed
-- [ withFlare
@@ -297,21 +297,21 @@ heldEffect effecttype = case effecttype of
-- , useTimeCheck
-- , ammoCheckI
-- ]
BangConeMod -> bulletGunEffect
[ withRandomItem coneRandItemParams
, withRandomItemUpdate coneRandItemUpdate
, withRandomOffset
, duplicateLoadedBarrels
, duplicateLoaded
, withMuzFlare
, withRecoil
, withTorqueAfter
, useAllAmmo
, withSoundStart bangEchoS
, useTimeCheck
, ammoCheckI
, blCheck
]
-- BangConeMod -> bulletGunEffect
-- [ withRandomItem coneRandItemParams
-- , withRandomItemUpdate coneRandItemUpdate
-- , withRandomOffset
-- , duplicateLoadedBarrels
-- , duplicateLoaded
-- , withMuzFlare
-- , withRecoil
-- , withTorqueAfter
-- , useAllAmmo
-- , withSoundStart bangEchoS
-- , useTimeCheck
-- , ammoCheckI
-- , blCheck
-- ]
TractorMod -> foldl' (&) (aTractorBeam . _ldtValue) [ammoCheckI]
FireRemoteShellMod -> undefined
ExplodeRemoteShellMod -> undefined
@@ -355,11 +355,9 @@ bulGunEffect' :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> Wo
bulGunEffect' t cr w = fromMaybe (error "error in bulGunEffect") $ do
muzzles <- t ^? ldtValue . itUse . heldAim . aimMuzzles
let (_,loadedmuzzles) = mapAccumR loadMuzzle t muzzles
-- let (_,loadedmuzzles) = ((),[])
--cmew = foldl' (useLoadedAmmo (_ldtValue t) cr) (CME 0 0 False,w) loadedmuzzles
cmew = foldl' (useLoadedAmmo (_ldtValue t) cr) (CME 0 0 False,w) $ loadedmuzzles
return $ uncurry (applyCME (_ldtValue t) cr) cmew
-- return $ snd cmew
& cWorld . lWorld . lTestString .~ map (show . _mzAmmoSlot) muzzles
applyCME :: Item -> Creature -> CumulativeMuzzleEffect -> World -> World
applyCME itm cr cme
@@ -416,7 +414,6 @@ applyTorqueCME itm cr w
-- (Muzzle,Int,Int) = (muzzle, amountloaded, id of mag taken from)
loadMuzzle :: LabelDoubleTree ComposeLinkType Item
-> Muzzle -> (LabelDoubleTree ComposeLinkType Item,(Muzzle, Int,Maybe Int))
--loadMuzzle t@(LDT _ l _) mz = (t,(mz, 0,Nothing))
loadMuzzle t@(LDT _ l _) mz = fromMaybe (t,(mz, 0,Nothing)) $ do
let as = _mzAmmoSlot mz
amamount = 1
@@ -454,9 +451,7 @@ isAmmoIntLink _ _ = False
useLoadedAmmo :: Item -> Creature -> (CumulativeMuzzleEffect,World) -> (Muzzle,Int,Maybe Int)
-> (CumulativeMuzzleEffect,World)
--useLoadedAmmo _ cr (cme,w) (_,0,_) = (cme,failsound w)
useLoadedAmmo _ _ (cme,w) (_,0,_) = (cme, w)
--useLoadedAmmo itm cr (cme,w) (mz,x,mid) = (cme,w)
useLoadedAmmo itm cr (cme,w) (mz,x,mid) = fromMaybe (cme,w) $ do
magid <- mid
-- should be able to pass the magazine in from elsewhere?
@@ -470,6 +465,7 @@ useLoadedAmmo itm cr (cme,w) (mz,x,mid) = fromMaybe (cme,w) $ do
where
cid = _crID cr
-- the random generator is not updated here, not sure if that is a problem
makeBullet :: Bullet -> Item -> Creature -> Muzzle -> World -> World
makeBullet thebullet itm cr mz w =
w & randGen .~ g
@@ -478,14 +474,22 @@ makeBullet thebullet itm cr mz w =
& buPos .~ bulpos
-- & buTrajectory .~ BasicBulletTrajectory
& buVel %~ (rotateV dir . (muzvel *.*))
& buDrag *~ _rifling (_heldParams $ _itUse itm)
& buDrag *~ drag
)
where
bulpos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
bulpos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm + V2 0 offset)
(a,g) = randomR (-inacc,inacc) $ _randGen w
inacc = _mzInaccuracy mz
muzvel = _muzVel $ _heldParams $ _itUse itm
drag = case _rifling (_heldParams $ _itUse itm) of
ConstFloat x -> x
UniRandFloat x y -> fst . randomR (x,y) $ _randGen w
muzvel = case _muzVel $ _heldParams $ _itUse itm of
ConstFloat x -> x
UniRandFloat x y -> fst . randomR (x,y) $ _randGen w
dir = _crDir cr + _mzRot mz + a
offset = case itm ^? itUse . heldParams . randomOffset of
Just x | x /= 0 -> fst . randomR (-x,x) $ _randGen w
_ -> 0
bulletGunEffect :: [(LabelDoubleTree ComposeLinkType Item
-> Creature -> World -> World)
@@ -624,28 +628,28 @@ useMod hm = case hm of
-- , ammoCheckI
-- , blCheck
-- ]
VolleyGunMod ->
[ withRecoil
, withFlare
, duplicateLoadedBarrels
, withTorqueAfter
, useAllAmmo
, withSoundItemChoiceStart caneStickSoundChoice
, useTimeCheck
, ammoCheckI
, blCheck
]
MultiGunMod ->
[ withRecoil
, withFlare
, duplicateLoadedBarrels
, withTorqueAfter
, useAllAmmo
, withSoundItemChoiceStart caneStickSoundChoice
, useTimeCheck
, ammoCheckI
, blCheck
]
-- VolleyGunMod ->
-- [ withRecoil
-- , withFlare
-- , duplicateLoadedBarrels
-- , withTorqueAfter
-- , useAllAmmo
-- , withSoundItemChoiceStart caneStickSoundChoice
-- , useTimeCheck
-- , ammoCheckI
-- , blCheck
-- ]
-- MultiGunMod ->
-- [ withRecoil
-- , withFlare
-- , duplicateLoadedBarrels
-- , withTorqueAfter
-- , useAllAmmo
-- , withSoundItemChoiceStart caneStickSoundChoice
-- , useTimeCheck
-- , ammoCheckI
-- , blCheck
-- ]
-- AutoRifleMod ->
-- -- note this is the same as BangCanemMod with the first changed
-- [ withFlare
@@ -785,21 +789,21 @@ useMod hm = case hm of
-- , useTimeCheck
-- , ammoCheckI
-- ]
BangConeMod ->
[ withRandomItem coneRandItemParams
, withRandomItemUpdate coneRandItemUpdate
, withRandomOffset
, duplicateLoadedBarrels
, duplicateLoaded
, withMuzFlare
, withRecoil
, withTorqueAfter
, useAllAmmo
, withSoundStart bangEchoS
, useTimeCheck
, ammoCheckI
, blCheck
]
-- BangConeMod ->
-- [ withRandomItem coneRandItemParams
-- , withRandomItemUpdate coneRandItemUpdate
-- , withRandomOffset
-- , duplicateLoadedBarrels
-- , duplicateLoaded
-- , withMuzFlare
-- , withRecoil
-- , withTorqueAfter
-- , useAllAmmo
-- , withSoundStart bangEchoS
-- , useTimeCheck
-- , ammoCheckI
-- , blCheck
-- ]
where
f = do
nzpres <- state $ randomR (3, 4)
@@ -968,19 +972,17 @@ caneStickSoundChoice _ = tap3S
bangStickSoundChoice :: Item -> SoundID
bangStickSoundChoice = caneStickSoundChoice
coneRandItemUpdate :: State StdGen (Item -> Item)
coneRandItemUpdate = return id
-- do
-- wth <- state $ randomR (1, 5)
-- return (itUse . heldConsumption . laAmmoType . amBullet . buWidth .~ wth)
coneRandItemParams :: State StdGen (Item -> Item)
coneRandItemParams = do
muzv <- state $ randomR (0.5, 1)
rifl <- state $ randomR (0.3, 0.9)
return $ \it ->
it & itUse . heldParams . muzVel .~ muzv
& itUse . heldParams . rifling .~ rifl
--coneRandItemParams :: State StdGen (Item -> Item)
--coneRandItemParams = do
-- muzv <- state $ randomR (0.5, 1)
-- rifl <- state $ randomR (0.3, 0.9)
-- return $ \it ->
-- it & itUse . heldParams . muzVel .~ muzv
-- & itUse . heldParams . rifling .~ rifl
mcShootLaser :: Item -> Machine -> World -> World
mcShootLaser it mc = cWorld . lWorld . lasers .:~ lasRayAt (_lasColor $ _itParams it) dam phasev pos dir
+5
View File
@@ -5,6 +5,11 @@ import Dodge.Data.World
import Dodge.Default.Item
import Dodge.Item.Weapon.Bullet
megaTinMag :: Item
megaTinMag = tinMag
& itUse . amagLoadStatus . iaMax .~ 150000
& itUse . amagLoadStatus . iaLoaded .~ 150000
tinMag :: Item
tinMag =
defaultHeldItem & itType . iyBase .~ AMMOMAG TINMAG
-1
View File
@@ -168,7 +168,6 @@ heldItemSPic ht it = case ht of
GRAPECANNON _ -> noPic $ bangConeShape 20
MINIGUNX i -> miniGunXPictItem i it
VOLLEYGUN i -> noPic $ volleyGunShape i -- <> addBullets it
MULTIGUN i -> noPic $ volleyGunShape i -- <> addBullets it
RIFLE -> noPic $ baseRifleShape -- <> addBullets it
-- REPEATER -> noPic $ baseRifleShape <> addTinClip it
AUTORIFLE -> noPic $ baseRifleShape <> addTinClip it
-1
View File
@@ -37,7 +37,6 @@ itemFromHeldType ht = case ht of
GRAPECANNON i -> grapeCannon i
MINIGUNX i -> miniGunX i
VOLLEYGUN i -> volleyGun i
MULTIGUN i -> multiGun i
RIFLE -> rifle
-- REPEATER -> repeater
AUTORIFLE -> autoRifle
+9 -18
View File
@@ -1,6 +1,5 @@
module Dodge.Item.Held.Cane (
volleyGun,
multiGun,
rifle,
autoRifle,
burstRifle,
@@ -15,14 +14,15 @@ import qualified Data.IntMap.Strict as IM
--import Dodge.Reloading.Action
import Geometry.Data
import LensHelp
import Control.Applicative
defaultBangCane :: Item
defaultBangCane =
defaultBulletWeapon
& itUse . heldParams
.~ BulletShooterParams
{ _muzVel = 0.8
, _rifling = 0.9
{ _muzVel = ConstFloat 0.8
, _rifling = ConstFloat 0.9
, _recoil = 50
, _torqueAfter = 0.1
, _randomOffset = 0
@@ -45,25 +45,16 @@ volleyGun i =
& itUse . heldAim . aimRange .~ 1
& itUse . heldAim . aimStance .~ TwoHandFlat
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5}
& itUse . heldAim . aimMuzzles .~
take i ([Muzzle (V2 15 x) 0 0.01 | x <- spreadAroundCenter i 3] <*> [0..] <*> repeat PistolFlare)
& itUse . heldAim . aimMuzzles .~ getZipList
(ZipList [Muzzle (V2 15 x) 0 0.01 | x <- spreadAroundCenter i 6]
<*> ZipList [0..i-1]
<*> pure PistolFlare
)
& itUse . heldParams . torqueAfter .~ 0.15 + 0.05 * fromIntegral i
& itUse . heldParams . recoil .~ 10 + 5 * fromIntegral i
& itType . iyBase .~ HELD (VOLLEYGUN i)
& itUse . heldAmmoTypes .~ IM.fromList (zip [0..i-1] $ repeat BulletAmmo)
multiGun :: Int -> Item
multiGun i =
defaultBangCane
& itUse . heldMods .~ MultiGunMod
& itUse . heldAim . aimWeight .~ 6
& itUse . heldAim . aimRange .~ 1
& itUse . heldAim . aimStance .~ TwoHandFlat
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5}
& itUse . heldAim . aimMuzzles .~
([Muzzle (V2 15 x) 0 0.01 | x <- spreadAroundCenter i 3] <*> [0..] <*> repeat DefaultFlareType)
& itUse . heldParams . torqueAfter .~ 0.15 + 0.05 * fromIntegral i
& itType . iyBase .~ HELD (MULTIGUN i)
rifle :: Item
rifle =
defaultBangCane
+4 -4
View File
@@ -14,12 +14,12 @@ bangCone =
& itDimension . dimRad .~ 8
& itDimension . dimCenter .~ V3 5 0 0
& itUse . heldDelay . rateMax .~ 20
& itUse . heldMods .~ BangConeMod
& itUse . heldMods .~ PistolMod
-- & itUse . heldAim . aimHandlePos .~ 5
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 0) 0 0.5 0 DefaultFlareType]
& itUse . heldAim . aimMuzzles .~ replicate 15 (Muzzle (V2 15 0) 0 0.5 0 DefaultFlareType)
& itUse . heldParams .~ BulletShooterParams
{ _muzVel = 0.7
, _rifling = 0.8
{ _muzVel = UniRandFloat 0.5 0.8
, _rifling = UniRandFloat 0.3 0.9
, _recoil = 150
, _torqueAfter = 0.1
, _randomOffset = 12
+2 -2
View File
@@ -20,8 +20,8 @@ bangRod =
defaultBulletWeapon
& itUse . heldParams
.~ BulletShooterParams
{ _muzVel = 0.8
, _rifling = 1
{ _muzVel = ConstFloat 0.8
, _rifling = ConstFloat 1
, _recoil = 50
, _torqueAfter = 0.3
, _randomOffset = 0
+4 -4
View File
@@ -19,8 +19,8 @@ bangStick i =
defaultBulletWeapon
& itUse . heldParams
.~ BulletShooterParams
{ _muzVel = 0.8
, _rifling = 0.8
{ _muzVel = ConstFloat 0.8
, _rifling = ConstFloat 0.8
, _recoil = 25
, _torqueAfter = 0.18 + 0.02 * fromIntegral i
, _randomOffset = 0
@@ -49,8 +49,8 @@ pistol =
& itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy %~ const 0.05
& itUse . heldAim . aimMuzzles . ix 0 . mzFlareType %~ const PistolFlare
& itUse . heldParams
%~ ( (muzVel .~ 0.8)
. (rifling .~ 0.8)
%~ ( (muzVel .~ ConstFloat 0.8)
. (rifling .~ ConstFloat 0.8)
. (recoil .~ 10)
. (torqueAfter .~ 0.2)
. (sidePush .~ 50)
+1 -2
View File
@@ -71,8 +71,7 @@ heldInfo hit = case hit of
GRAPECANNON 1 -> "A large container for debris on the end of a stick. Explosive action propels the debris away from the user."
GRAPECANNON i -> "An " ++ replicate (i -1) 'X' ++ "L container for debris on the end of a stick. Explosive action propels the debris away from the user."
MINIGUNX i -> over _head toUpper (showInt i) ++ " gun barrels that revolve rapidly around a central stick. Requires considerable time to warm up, but has an extremely rapid rate of fire. It is also extremely difficult to stabilise."
VOLLEYGUN i -> over _head toUpper (showInt i) ++ " gun barrels lined up to be roughly parallel. Draws bullets from a single magazine. All loaded barrels discharge simultaneously."
MULTIGUN i -> over _head toUpper (showInt i) ++ " gun barrels lined up to be roughly parallel. Each barrel requires a separate magazine. All barrels must be loaded to fire."
VOLLEYGUN i -> over _head toUpper (showInt i) ++ " gun barrels lined up to be roughly parallel. Each barrel requires a separate magazine. All barrels must be loaded to fire."
RIFLE -> "A firearm with a mid length barrel that requires reloading after each shot."
-- REPEATER -> "A firearm fed by a magazine. The entire magazine must be replaced when reloading the weapon."
AUTORIFLE -> "A firearm automatically fed by a magazine. The entire magazine must be replaced when reloading the weapon."
-1
View File
@@ -36,7 +36,6 @@ heldBounds hit = case hit of
GRAPECANNON _ -> bbs
MINIGUNX _ -> minis
VOLLEYGUN _ -> undefined
MULTIGUN _ -> undefined
RIFLE -> rs
-- REPEATER -> rs
AUTORIFLE -> rs
+2
View File
@@ -20,6 +20,8 @@ fixedCoordPictures u =
<> drawConcurrentMessage u
<> customMouseCursor u
<> toTopLeft cfig (translate (halfWidth cfig) 0 $ drawList (map text (_uvTestString u u)))
<> toTopLeft cfig (translate (0.5 * halfWidth cfig) (- halfHeight cfig)
$ drawList (map text (u ^. uvWorld . cWorld . lWorld . lTestString)))
<> displayFrameTicks u
where
cfig = _uvConfig u
+260 -258
View File
File diff suppressed because it is too large Load Diff