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
+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