Continue weapon refactor, gas combinations

This commit is contained in:
2024-09-19 09:49:56 +01:00
parent 6f972bb316
commit bb18831393
21 changed files with 489 additions and 379 deletions
+189 -166
View File
@@ -44,42 +44,42 @@ import Sound.Data
heldEffect :: HeldMod -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffect effecttype = case effecttype of
-- HeldModNothing -> const $ const id
PoisonSprayerMod -> gasEffect
[ useAmmoAmount 1
, withSoundForI foamSprayLoopS 5
, ammoCheckI
]
FlameSpitterMod -> gasEffect
[ withSidePushAfterI 20
, withSidePushI 5
, useAmmoAmount 1
, withRandomItemParams f
, repeatOnFrames [1 .. 9] FlameSpitterRepeatMod
, lockInvFor 10
, useTimeCheck
, ammoCheckI
]
FlameSpitterRepeatMod -> gasEffect
[ withSidePushAfterI 20
, withSidePushI 5
, useAmmoAmount 1
, withRandomItemParams f
, ammoCheckI
]
FlameThrowerMod -> gasEffect
[ withSidePushAfterI 20
, --, withTempLight 1 100 (V3 1 0 0)
withSidePushI 5
, useAmmoAmount 1
, ammoCheckI
]
LauncherMod -> foldl' (&) usePjCreation
--[ useAmmoAmount 1
-- , withSoundStart tap4S
[ useTimeCheck
-- PoisonSprayerMod -> gasEffect
-- [ useAmmoAmount 1
-- , withSoundForI foamSprayLoopS 5
-- , ammoCheckI
, blCheck
]
-- ]
-- FlameSpitterMod -> gasEffect
-- [ withSidePushAfterI 20
-- , withSidePushI 5
-- , useAmmoAmount 1
-- , withRandomItemParams f
-- , repeatOnFrames [1 .. 9] FlameSpitterRepeatMod
-- , lockInvFor 10
-- , useTimeCheck
-- , ammoCheckI
-- ]
-- FlameSpitterRepeatMod -> gasEffect
-- [ withSidePushAfterI 20
-- , withSidePushI 5
-- , useAmmoAmount 1
-- , withRandomItemParams f
-- , ammoCheckI
-- ]
-- FlameThrowerMod -> gasEffect
-- [ withSidePushAfterI 20
-- , --, withTempLight 1 100 (V3 1 0 0)
-- withSidePushI 5
-- , useAmmoAmount 1
-- , ammoCheckI
-- ]
-- LauncherMod -> foldl' (&) usePjCreation
-- --[ useAmmoAmount 1
---- , withSoundStart tap4S
-- [ useTimeCheck
---- , ammoCheckI
-- , blCheck
-- ]
-- TeslaMod -> foldl' (&) (shootTeslaArc . _ldtValue)
-- [ useAmmoAmount 1
-- , withSoundForI elecCrackleS 1
@@ -107,21 +107,21 @@ heldEffect effecttype = case effecttype of
, withItem $ \it -> withCrPosShift (V2 0 (thegapDualBeam it)) $ flareCircleAt (_lasColor $ _itParams it) 0.8
, ammoCheckI
]
LasMod -> foldl' (&) (shootLaser . _ldtValue)
[ useAmmoAmount 1
, withItem $ \it -> withCrPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withSoundForI tone440sawtoothquietS 2
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
, duplicateLoadedBarrels
, ammoCheckI
]
LauncherXMod _ -> foldl' (&) usePjCreationX
--[ useAmmoAmount i
--, withSoundStart tap4S
[ useTimeCheck
--, ammoCheckI
, blCheck
]
-- LasMod -> foldl' (&) (shootLaser . _ldtValue)
-- [ useAmmoAmount 1
-- , withItem $ \it -> withCrPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
-- , withSoundForI tone440sawtoothquietS 2
-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
-- , duplicateLoadedBarrels
-- , ammoCheckI
-- ]
-- LauncherXMod _ -> foldl' (&) usePjCreationX
-- --[ useAmmoAmount i
-- --, withSoundStart tap4S
-- [ useTimeCheck
-- --, ammoCheckI
-- , blCheck
-- ]
ShatterMod -> foldl' (&) (shootShatter . _ldtValue)
[ useAmmoAmount 1
, -- , withSoundStart tap3S
@@ -315,16 +315,16 @@ heldEffect effecttype = case effecttype of
-- , ammoCheckI
-- , blCheck
-- ]
TractorMod -> foldl' (&) (aTractorBeam . _ldtValue) [ammoCheckI]
-- TractorMod -> foldl' (&) (aTractorBeam . _ldtValue) [ammoCheckI]
FireRemoteShellMod -> undefined
ExplodeRemoteShellMod -> undefined
DoNothingMod -> const $ const id
ForceFieldMod -> undefined
DetectorMod _ -> undefined
where
f = do
nzpres <- state $ randomR (3, 4)
return $ sprayNozzles . ix 0 . nzPressure .~ nzpres
-- f = do
-- nzpres <- state $ randomR (3, 4)
-- return $ sprayNozzles . ix 0 . nzPressure .~ nzpres
increasecycleLasWide n it = case _heldHammer (_itUse it) of
HammerUp -> it & itParams . lasCycle .~ 1
_ -> it & itParams . lasCycle %~ (min (n * lasWideRate) . (+ 1))
@@ -339,17 +339,17 @@ heldEffect effecttype = case effecttype of
-- & crPos %~ alongSegBy x (_crOldPos cr)
-- & crInv . ix (invid + 1) . itUse . amagParams . ampBullet . buDelayFraction .~ x
gasEffect :: [(LabelDoubleTree ComposeLinkType Item
-> Creature -> World -> World)
-> LabelDoubleTree ComposeLinkType Item
-> Creature
-> World
-> World]
-> LabelDoubleTree ComposeLinkType Item
-> Creature
-> World
-> World
gasEffect = foldl' (&) (overNozzles useGasParams)
--gasEffect :: [(LabelDoubleTree ComposeLinkType Item
-- -> Creature -> World -> World)
-- -> LabelDoubleTree ComposeLinkType Item
-- -> Creature
-- -> World
-- -> World]
-- -> LabelDoubleTree ComposeLinkType Item
-- -> Creature
-- -> World
-- -> World
--gasEffect = foldl' (&) (overNozzles useGasParams)
bulGunEffect :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
bulGunEffect = hammerCheck $ useTimeCheck bulGunEffect'
@@ -392,7 +392,7 @@ applyInvLock itm cr = case itm ^? itUse . heldParams . weaponInvLock of
applySoundCME :: Item -> Creature -> World -> World
applySoundCME itm cr = fromMaybe id $ do
(soundid,x) <- itm ^? itUse . heldParams . bulGunSound
(soundid,x) <- itm ^? itUse . heldParams . bulGunSound . _Just
if x > 0
then return $ soundContinue (CrWeaponSound (_crID cr) 0) (_crPos cr) soundid (Just x)
else return $ soundMultiFrom [CrWeaponSound cid j | j <- [0..5]] (_crPos cr) soundid Nothing
@@ -455,6 +455,8 @@ makeMuzzleFlare mz itm cr = case mz ^. mzFlareType of
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
HeavySmokeFlare -> basicMuzFlare pos dir
LasGunFlare -> flareCircleAt (_lasColor $ _itParams itm) 0.8 (pos `v2z` 20)
. (cWorld . lWorld . tempLightSources .:~
tlsTimeRadColPos 1 100 (xyzV4 . _lasColor $ _itParams itm) (pos `v2z` 10))
TeslaGunFlare -> cWorld . lWorld . tempLightSources .:~
tlsTimeRadColPos 1 100 (V3 0 0 1) (pos `v2z` 10)
where
@@ -496,6 +498,17 @@ useLoadedAmmo itm cr (cme,w) (mz,x,mid) = (,) (cme & cmeSound .~ True) $
MuzzleTesla -> shootTeslaArc itm cr mz w
MuzzleTractor -> shootTractorBeam itm cr w
MuzzleLauncher -> createProjectile' mid mz itm cr w
MuzzleNozzle {} -> useGasParams mid mz itm cr $ walkNozzle mz itm cr w
walkNozzle mz itm cr w = w
& randGen .~ g
where
nz = _mzEffect mz
(walkamount, g) = randomR (- aspeed, aspeed) (_randGen w)
aspeed = _nzWalkSpeed nz
maxa = _nzMaxWalkAngle nz
wa = min maxa $ max (negate maxa) (_nzCurrentWalkAngle nz + walkamount)
shootTractorBeam :: Item -> Creature -> World -> World
shootTractorBeam _ cr w = w & cWorld . lWorld . tractorBeams .:~ tractorBeamAt' spos outpos dir power
@@ -600,42 +613,42 @@ useMod hm = case hm of
ForceFieldMod -> undefined
DetectorMod _ -> undefined
-- HeldModNothing -> []
PoisonSprayerMod ->
[ useAmmoAmount 1
, withSoundForI foamSprayLoopS 5
, ammoCheckI
]
FlameSpitterMod ->
[ withSidePushAfterI 20
, withSidePushI 5
, useAmmoAmount 1
, withRandomItemParams f
, repeatOnFrames [1 .. 9] FlameSpitterRepeatMod
, lockInvFor 10
, useTimeCheck
, ammoCheckI
]
FlameSpitterRepeatMod ->
[ withSidePushAfterI 20
, withSidePushI 5
, useAmmoAmount 1
, withRandomItemParams f
, ammoCheckI
]
FlameThrowerMod ->
[ withSidePushAfterI 20
, --, withTempLight 1 100 (V3 1 0 0)
withSidePushI 5
, useAmmoAmount 1
, ammoCheckI
]
LauncherMod ->
--[ useAmmoAmount 1
-- , withSoundStart tap4S
[ useTimeCheck
-- PoisonSprayerMod ->
-- [ useAmmoAmount 1
-- , withSoundForI foamSprayLoopS 5
-- , ammoCheckI
, blCheck
]
-- ]
-- FlameSpitterMod ->
-- [ withSidePushAfterI 20
-- , withSidePushI 5
-- , useAmmoAmount 1
-- , withRandomItemParams f
-- , repeatOnFrames [1 .. 9] FlameSpitterRepeatMod
-- , lockInvFor 10
-- , useTimeCheck
-- , ammoCheckI
-- ]
-- FlameSpitterRepeatMod ->
-- [ withSidePushAfterI 20
-- , withSidePushI 5
-- , useAmmoAmount 1
-- , withRandomItemParams f
-- , ammoCheckI
-- ]
-- FlameThrowerMod ->
-- [ withSidePushAfterI 20
-- , --, withTempLight 1 100 (V3 1 0 0)
-- withSidePushI 5
-- , useAmmoAmount 1
-- , ammoCheckI
-- ]
-- LauncherMod ->
-- --[ useAmmoAmount 1
---- , withSoundStart tap4S
-- [ useTimeCheck
---- , ammoCheckI
-- , blCheck
-- ]
-- TeslaMod ->
-- [ useAmmoAmount 1
-- , withSoundForI elecCrackleS 1
@@ -672,21 +685,21 @@ useMod hm = case hm of
, withItem $ \it -> withCrPosShift (V2 0 (thegapDualBeam it)) $ flareCircleAt (_lasColor $ _itParams it) 0.8
, ammoCheckI
]
LasMod ->
[ useAmmoAmount 1
, withItem $ \it -> withCrPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withSoundForI tone440sawtoothquietS 2
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
, duplicateLoadedBarrels
, ammoCheckI
]
LauncherXMod _ ->
--[ useAmmoAmount i
--, withSoundStart tap4S
[ useTimeCheck
--, ammoCheckI
, blCheck
]
-- LasMod ->
-- [ useAmmoAmount 1
-- , withItem $ \it -> withCrPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
-- , withSoundForI tone440sawtoothquietS 2
-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
-- , duplicateLoadedBarrels
-- , ammoCheckI
-- ]
-- LauncherXMod _ ->
-- --[ useAmmoAmount i
-- --, withSoundStart tap4S
-- [ useTimeCheck
-- --, ammoCheckI
-- , blCheck
-- ]
ShatterMod ->
[ useAmmoAmount 1
, -- , withSoundStart tap3S
@@ -891,9 +904,9 @@ useMod hm = case hm of
-- , blCheck
-- ]
where
f = do
nzpres <- state $ randomR (3, 4)
return $ sprayNozzles . ix 0 . nzPressure .~ nzpres
-- f = do
-- nzpres <- state $ randomR (3, 4)
-- return $ sprayNozzles . ix 0 . nzPressure .~ nzpres
--increasecycleLasCircle it = it & itParams . lasCycle %~ (flip mod 2000 . (+ 1))
----f it = [it & itParams . lasCycle +~ x | x <- [0,100 .. 1900] ]
--fLasCircle it = [it & itParams . lasCycle +~ x | x <- [0, 50 .. 1999]]
@@ -923,7 +936,7 @@ useHeld :: Huse -> LabelDoubleTree ComposeLinkType Item -> Creature -> World ->
useHeld hu = case hu of
HeldDoNothing -> const $ const id
-- HeldUseAmmoParams -> shootBullet
HeldOverNozzlesUseGasParams -> overNozzles useGasParams
-- HeldOverNozzlesUseGasParams -> overNozzles useGasParams
HeldPJCreation -> usePjCreation
HeldPJCreationX _ -> usePjCreationX
HeldFireRemoteShell -> fireRemoteShell
@@ -956,45 +969,45 @@ usePjCreationX = undefined
-- where
-- f (muz,am) = (createProjectile am muz itm cr .)
overNozzles ::
(Nozzle -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World) ->
LabelDoubleTree ComposeLinkType Item ->
Creature ->
World ->
World
overNozzles = overNozzles' . overNozzle
--overNozzles ::
-- (Nozzle -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World) ->
-- LabelDoubleTree ComposeLinkType Item ->
-- Creature ->
-- World ->
-- World
--overNozzles = overNozzles' . overNozzle
overNozzles' ::
(LabelDoubleTree ComposeLinkType Item -> Creature -> World -> Nozzle -> (World, Nozzle)) ->
LabelDoubleTree ComposeLinkType Item ->
Creature ->
World ->
World
overNozzles' eff itm cr w = neww
& cWorld . lWorld . creatures . ix cid . crInv . ix i . itParams . sprayNozzles .~ newNozzles
where
it = itm ^. ldtValue
cid = _crID cr
i = w ^?! cWorld . lWorld . creatures . ix cid . crManipulation . manObject . inInventory . ispItem
(neww, newNozzles) = mapAccumR (eff itm cr) w $ _sprayNozzles (_itParams it)
--overNozzles' ::
-- (LabelDoubleTree ComposeLinkType Item -> Creature -> World -> Nozzle -> (World, Nozzle)) ->
-- LabelDoubleTree ComposeLinkType Item ->
-- Creature ->
-- World ->
-- World
--overNozzles' eff itm cr w = neww
-- & cWorld . lWorld . creatures . ix cid . crInv . ix i . itParams . sprayNozzles .~ newNozzles
-- where
-- it = itm ^. ldtValue
-- cid = _crID cr
-- i = w ^?! cWorld . lWorld . creatures . ix cid . crManipulation . manObject . inInventory . ispItem
-- (neww, newNozzles) = mapAccumR (eff itm cr) w $ _sprayNozzles (_itParams it)
overNozzle ::
(Nozzle -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World) ->
LabelDoubleTree ComposeLinkType Item ->
Creature ->
World ->
Nozzle ->
(World, Nozzle)
overNozzle eff itm cr w nz =
( eff nz itm (cr & crDir +~ wa + na) w & randGen .~ g
, nz & nzCurrentWalkAngle .~ wa
)
where
na = _nzDir nz
(walkamount, g) = randomR (- aspeed, aspeed) (_randGen w)
aspeed = _nzWalkSpeed nz
maxa = _nzMaxWalkAngle nz
wa = min maxa $ max (negate maxa) (_nzCurrentWalkAngle nz + walkamount)
--overNozzle ::
-- (Nozzle -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World) ->
-- LabelDoubleTree ComposeLinkType Item ->
-- Creature ->
-- World ->
-- Nozzle ->
-- (World, Nozzle)
--overNozzle eff itm cr w nz =
-- ( eff nz itm (cr & crDir +~ wa + na) w & randGen .~ g
-- , nz & nzCurrentWalkAngle .~ wa
-- )
-- where
-- na = _nzDir nz
-- (walkamount, g) = randomR (- aspeed, aspeed) (_randGen w)
-- aspeed = _nzWalkSpeed nz
-- maxa = _nzMaxWalkAngle nz
-- wa = min maxa $ max (negate maxa) (_nzCurrentWalkAngle nz + walkamount)
getAmmoMagazine :: Item -> Creature -> Maybe ItemUse
getAmmoMagazine itm cr = do
@@ -1005,22 +1018,32 @@ getAmmoMagazine itm cr = do
guard $ amtype == magtype
return mag
useGasParams :: Nozzle -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
useGasParams nz itm cr =
useGasParams :: Maybe Int -> Muzzle -> Item -> Creature -> World -> World
useGasParams mmagid mz itm cr w =
createGas
gastype
(_nzPressure nz)
pressure
pos
dir
cr
w & randGen .~ g'
where
(pressure,g) = doGenFloat (_nzPressure $ _mzEffect mz) (_randGen w)
gastype = fromMaybe (error "cannot find gas ammo") $ do
atype <- itm ^? ldtValue . itUse . heldAmmoTypes . ix 0
leftitms <- itm ^? ldtLeft
mag <- lookup (AmmoInLink 0 atype) leftitms
mag ^? ldtValue . itUse . amagParams . ampCreateGas
dir = _crDir cr
pos = _crPos cr +.+ (_nzLength nz *.* unitVectorAtAngle (_crDir cr))
magid <- mmagid
fueltype <- cr ^? crInv . ix magid . itUse . amagParams . ampCreateGas
gc <- itm ^? itUse . heldParams . gasCreation
return $ gasCreate fueltype gc
pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
(a,g') = randomR (-inacc,inacc) g
inacc = _mzInaccuracy mz
dir = _crDir cr + _mzRot mz + a
gasCreate :: GasFuel -> GasCreate -> GasCreate
gasCreate = flip const
doGenFloat (ConstFloat x) g = (x,g)
doGenFloat (UniRandFloat x y) g = randomR (x,y) g
fireRemoteShell :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
fireRemoteShell = undefined