Move UseDelay out of records

This commit is contained in:
2025-06-05 11:00:17 +01:00
parent 289bbcc8a9
commit c8a04b8b1e
16 changed files with 226 additions and 217 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -31,10 +31,10 @@ import Geometry.Data
data ItemUse data ItemUse
= UseHeld = UseHeld
{ _heldDelay :: UseDelay -- { --_heldDelay :: UseDelay
-- , _heldMuzzles :: [Muzzle] ---- , _heldMuzzles :: [Muzzle]
, _heldFrame :: Int ---- _heldFrame :: Int
} -- }
| UseEquip {_uequipEffect :: EquipEffect} | UseEquip {_uequipEffect :: EquipEffect}
| UseAttach {_uaParams :: AttachParams} | UseAttach {_uaParams :: AttachParams}
| UseInt {_uInt :: Int} | UseInt {_uInt :: Int}
+1 -1
View File
@@ -23,7 +23,7 @@ defaultHeldItem =
, _itTargeting = NoItTargeting , _itTargeting = NoItTargeting
, _itAmmoSlots = mempty , _itAmmoSlots = mempty
, _itLocation = InVoid , _itLocation = InVoid
, _itUse = defaultHeldUse , _itUse = UseHeld
, _itParams = NoParams , _itParams = NoParams
, _itUseCondition = UseableWhenAimed , _itUseCondition = UseableWhenAimed
, _itScroll = NoItemScroll , _itScroll = NoItemScroll
+5 -6
View File
@@ -12,9 +12,8 @@ defaultEquipUse =
{ _uequipEffect = defaultEquip { _uequipEffect = defaultEquip
} }
defaultHeldUse :: ItemUse --defaultHeldUse :: ItemUse
defaultHeldUse = --defaultHeldUse =
UseHeld -- UseHeld
{ _heldDelay = FixedRate{_rateMax = 8} --, _rateTimeLastUsed = 0} -- { _heldFrame = 0
, _heldFrame = 0 -- }
}
+10 -9
View File
@@ -10,6 +10,7 @@ module Dodge.HeldUse (
heldEffectMuzzles, heldEffectMuzzles,
) where ) where
import Dodge.Item.UseDelay
import Dodge.Base import Dodge.Base
import Color import Color
import Control.Applicative import Control.Applicative
@@ -110,24 +111,24 @@ hammerCheck f pt it cr
-- | Applies a world effect after an item use cooldown check. -- | Applies a world effect after an item use cooldown check.
useTimeCheck :: ChainEffect useTimeCheck :: ChainEffect
useTimeCheck f item cr w = case item ^? ldtValue . itUse . heldDelay of useTimeCheck f item cr w = case useDelay $ item ^. ldtValue of
Just (FixedRate rate) FixedRate rate
| w ^. cWorld . lWorld . lClock - rate > lastused -> f item cr $ setUseRate w | w ^. cWorld . lWorld . lClock - rate > lastused -> f item cr $ setUseRate w
Just FixedRate{} -> w FixedRate{} -> w
--Just (WarmUpNoDelay wt wm ws) --Just (WarmUpNoDelay wt wm ws)
Just (WarmUpNoDelay wm ws) WarmUpNoDelay wm ws
-- | wt < wm -> -- | wt < wm ->
| _wTime (_itParams $ _ldtValue item) < wm -> | _wTime (_itParams $ _ldtValue item) < wm ->
w w
& soundContinue (CrWeaponSound cid 0) (_crPos cr) ws (Just 2) & soundContinue (CrWeaponSound cid 0) (_crPos cr) ws (Just 2)
-- & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . warmTime +~ 2 -- & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . warmTime +~ 2
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 2 & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 2
Just (WarmUpNoDelay wm _) -> WarmUpNoDelay wm _ ->
f item cr w f item cr w
-- & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . warmTime .~ (wm + 1) -- & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . warmTime .~ (wm + 1)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime .~ (wm + 1) & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime .~ (wm + 1)
Just NoDelay -> f item cr w NoDelay -> f item cr w
Nothing -> w --Nothing -> w
where where
lastused = item ^. ldtValue . itTimeLastUsed lastused = item ^. ldtValue . itTimeLastUsed
cid = _crID cr cid = _crID cr
@@ -625,7 +626,7 @@ loadMuzzle ::
Muzzle -> Muzzle ->
(LabelDoubleTree ComposeLinkType Item, Maybe (Muzzle, Int, LabelDoubleTree ComposeLinkType Item)) (LabelDoubleTree ComposeLinkType Item, Maybe (Muzzle, Int, LabelDoubleTree ComposeLinkType Item))
loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do
guard $ mz ^? mzFrame == t ^? ldtValue . itUse . heldFrame -- guard $ mz ^? mzFrame == t ^? ldtValue . itUse . heldFrame
let as = _mzAmmoSlot mz let as = _mzAmmoSlot mz
amamount = _mzAmmoPerShot mz amamount = _mzAmmoPerShot mz
(i, (_, mag)) <- findWithIx (isAmmoIntLink as . fst) l (i, (_, mag)) <- findWithIx (isAmmoIntLink as . fst) l
@@ -1171,7 +1172,7 @@ mcShootLaser _ mc =
mcShootAuto :: Item -> Machine -> World -> World mcShootAuto :: Item -> Machine -> World -> World
mcShootAuto itm mc w mcShootAuto itm mc w
| Just (FixedRate rate) <- mc ^? mcType . mctTurret . tuWeapon . itUse . heldDelay | Just (FixedRate rate) <- useDelay <$> mc ^? mcType . mctTurret . tuWeapon -- . itUse . heldDelay
, w ^. cWorld . lWorld . lClock - rate > lastused = , w ^. cWorld . lWorld . lClock - rate > lastused =
w w
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon & cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
+2 -1
View File
@@ -7,6 +7,7 @@ module Dodge.Item.Display (
itemInternalValue, itemInternalValue,
) where ) where
import Dodge.Item.UseDelay
import ShortShow import ShortShow
import Data.Maybe import Data.Maybe
import Dodge.Data.World import Dodge.Data.World
@@ -41,7 +42,7 @@ itemInternalValue itm
maybeWarmupStatus :: Item -> Maybe String maybeWarmupStatus :: Item -> Maybe String
maybeWarmupStatus it = case it ^? itUse . heldDelay . warmMax of maybeWarmupStatus it = case useDelay it ^? warmMax of
Nothing -> Nothing Nothing -> Nothing
--Just m -> case m - (_warmTime . _heldDelay $ _itUse it) of --Just m -> case m - (_warmTime . _heldDelay $ _itUse it) of
Just m -> case m - (_wTime $ _itParams it) of Just m -> case m - (_wTime $ _itParams it) of
+2 -2
View File
@@ -21,7 +21,7 @@ teslaGun =
defaultHeldItem defaultHeldItem
-- & itUse . heldParams .~ BeamShooterParams-- (Just (elecCrackleS, 2)) -- & itUse . heldParams .~ BeamShooterParams-- (Just (elecCrackleS, 2))
& itParams .~ teslaParams & itParams .~ teslaParams
& itUse . heldDelay .~ NoDelay -- & itUse . heldDelay .~ NoDelay
-- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 10 0 -- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 10 0
-- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0 -- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0
-- & itUse . heldMuzzles . ix 0 . mzFlareType .~ TeslaGunFlare -- & itUse . heldMuzzles . ix 0 . mzFlareType .~ TeslaGunFlare
@@ -43,7 +43,7 @@ laser =
defaultHeldItem defaultHeldItem
-- & itUse . heldParams .~ BeamShooterParams-- Nothing -- & itUse . heldParams .~ BeamShooterParams-- Nothing
& itAmmoSlots .~ singleAmmo ElectricalAmmo & itAmmoSlots .~ singleAmmo ElectricalAmmo
& itUse . heldDelay .~ NoDelay -- & itUse . heldDelay .~ NoDelay
-- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 6 0 -- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 6 0
-- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0 -- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0
-- & itUse . heldMuzzles . ix 0 . mzFlareType .~ LasGunFlare -- & itUse . heldMuzzles . ix 0 . mzFlareType .~ LasGunFlare
+5 -6
View File
@@ -7,7 +7,6 @@ module Dodge.Item.Held.Cane (
miniGunX, miniGunX,
) where ) where
import Dodge.SoundLogic.ExternallyGeneratedSounds
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Default import Dodge.Default
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
@@ -17,7 +16,7 @@ defaultBangCane :: Item
defaultBangCane = defaultBangCane =
defaultBulletWeapon defaultBulletWeapon
-- & itUse . heldParams . recoil .~ 50 -- & itUse . heldParams . recoil .~ 50
& itUse . heldDelay . rateMax .~ 6 -- & itUse . heldDelay . rateMax .~ 6
-- & itUse . heldMods .~ BangCaneMod -- & itUse . heldMods .~ BangCaneMod
-- & itUse . heldAim . aimHandlePos .~ 5 -- & itUse . heldAim . aimHandlePos .~ 5
@@ -56,14 +55,14 @@ burstRifle =
rifle rifle
& itType .~ HELD BURSTRIFLE & itType .~ HELD BURSTRIFLE
-- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0.05 -- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0.05
& itUse . heldDelay . rateMax .~ 6 -- & itUse . heldDelay . rateMax .~ 6
miniGunX :: Int -> Item miniGunX :: Int -> Item
miniGunX i = miniGunX i =
autoRifle autoRifle
& itUse . heldDelay .~ WarmUpNoDelay{ -- & itUse . heldDelay .~ WarmUpNoDelay{
--_warmTime = 0, -- --_warmTime = 0,
_warmMax = 100, _warmSound = crankSlowS} -- _warmMax = 100, _warmSound = crankSlowS}
& itAmmoSlots .~ singleAmmo BeltBulletAmmo & itAmmoSlots .~ singleAmmo BeltBulletAmmo
-- & itUse . heldMuzzles -- & itUse . heldMuzzles
-- .~ replicate i -- .~ replicate i
+1 -1
View File
@@ -13,7 +13,7 @@ import Dodge.Default.Item
bangCone :: Item bangCone :: Item
bangCone = bangCone =
defaultBulletWeapon defaultBulletWeapon
& itUse . heldDelay . rateMax .~ 20 -- & itUse . heldDelay . rateMax .~ 20
-- & itUse . heldMuzzles -- & itUse . heldMuzzles
-- .~ [Muzzle (V2 15 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) 0] -- .~ [Muzzle (V2 15 0) 0 0.5 0 BasicFlare MuzzleShootBullet (UseUpTo 15) 0]
& itType .~ HELD BANGCONE & itType .~ HELD BANGCONE
+1 -1
View File
@@ -14,7 +14,7 @@ import qualified IntMapHelp as IM
rLauncher :: Item rLauncher :: Item
rLauncher = rLauncher =
defaultHeldItem defaultHeldItem
& itUse . heldDelay . rateMax .~ 20 -- & itUse . heldDelay . rateMax .~ 20
-- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0 -- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0
-- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleRLauncher -- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleRLauncher
-- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 20 0 -- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 20 0
+1 -1
View File
@@ -18,7 +18,7 @@ import LensHelp
bangRod :: Item bangRod :: Item
bangRod = bangRod =
defaultBulletWeapon defaultBulletWeapon
& itUse . heldDelay . rateMax .~ 12 -- & itUse . heldDelay . rateMax .~ 12
& itType .~ HELD BANGROD & itType .~ HELD BANGROD
-- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 30 0 -- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 30 0
-- & itUse . heldMuzzles . ix 0 . mzFlareType .~ HeavySmokeFlare -- & itUse . heldMuzzles . ix 0 . mzFlareType .~ HeavySmokeFlare
+2 -2
View File
@@ -24,7 +24,7 @@ flameSpitter :: Item
flameSpitter = flameSpitter =
flameThrower flameThrower
& itType .~ HELD FLAMESPITTER & itType .~ HELD FLAMESPITTER
& itUse . heldDelay .~ FixedRate{_rateMax = 3} --, _rateTimeLastUsed = 0} -- & itUse . heldDelay .~ FixedRate{_rateMax = 3} --, _rateTimeLastUsed = 0}
-- & itUse . heldParams . weaponInvLock .~ 10 -- & itUse . heldParams . weaponInvLock .~ 10
-- & itUse . heldParams . weaponRepeat .~ [1..9] -- & itUse . heldParams . weaponRepeat .~ [1..9]
-- & itUse . heldMuzzles . ix 0 . mzEffect . nzPressure .~ UniRandFloat 3 4 -- & itUse . heldMuzzles . ix 0 . mzEffect . nzPressure .~ UniRandFloat 3 4
@@ -65,7 +65,7 @@ flameThrower :: Item
flameThrower = flameThrower =
defaultHeldItem defaultHeldItem
& itParams .~ NozzleAngle 0 & itParams .~ NozzleAngle 0
& itUse . heldDelay .~ NoDelay -- & itUse . heldDelay .~ NoDelay
-- & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 5, _izMin = 1.5} -- & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 5, _izMin = 1.5}
-- & itUse . heldMuzzles .~ [Muzzle (V2 18 0) 0 0 0 NoFlare -- & itUse . heldMuzzles .~ [Muzzle (V2 18 0) 0 0 0 NoFlare
-- MuzzleNozzle -- MuzzleNozzle
+5 -6
View File
@@ -9,7 +9,6 @@ module Dodge.Item.Held.Stick (
--import Dodge.Base --import Dodge.Base
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Default.Item import Dodge.Default.Item
import Dodge.SoundLogic.ExternallyGeneratedSounds
--import Geometry --import Geometry
import LensHelp import LensHelp
@@ -18,7 +17,7 @@ bangStick i =
defaultBulletWeapon defaultBulletWeapon
-- & itUse . heldParams . recoil .~ 25 -- & itUse . heldParams . recoil .~ 25
& itType .~ HELD (BANGSTICK i) & itType .~ HELD (BANGSTICK i)
& itUse . heldDelay . rateMax .~ 8 -- & itUse . heldDelay . rateMax .~ 8
-- & itUse . heldMuzzles -- & itUse . heldMuzzles
-- .~ [ Muzzle -- .~ [ Muzzle
-- (V2 10 0) -- (V2 10 0)
@@ -41,7 +40,7 @@ bangStick i =
pistol :: Item pistol :: Item
pistol = pistol =
bangStick 1 bangStick 1
& itUse . heldDelay . rateMax .~ 6 -- & itUse . heldDelay . rateMax .~ 6
-- & itUse . heldMuzzles . ix 0 . mzPos %~ const (V2 10 0) -- & itUse . heldMuzzles . ix 0 . mzPos %~ const (V2 10 0)
-- & itUse . heldMuzzles . ix 0 . mzInaccuracy %~ const 0.05 -- & itUse . heldMuzzles . ix 0 . mzInaccuracy %~ const 0.05
-- & itUse . heldMuzzles . ix 0 . mzFlareType %~ const BasicFlare -- & itUse . heldMuzzles . ix 0 . mzFlareType %~ const BasicFlare
@@ -53,9 +52,9 @@ autoPistol = pistol & itType .~ HELD AUTOPISTOL
machinePistol :: Item machinePistol :: Item
machinePistol = machinePistol =
autoPistol autoPistol
& itUse . heldDelay .~ WarmUpNoDelay{ -- & itUse . heldDelay .~ WarmUpNoDelay{
--_warmTime = 0, -- --_warmTime = 0,
_warmMax = 50, _warmSound = crankSlowS} -- _warmMax = 50, _warmSound = crankSlowS}
& itType .~ HELD MACHINEPISTOL & itType .~ HELD MACHINEPISTOL
& itParams .~ WarmTime 0 & itParams .~ WarmTime 0
+2 -2
View File
@@ -36,7 +36,7 @@ detector :: Detector -> Item
detector dt = detector dt =
defaultHeldItem defaultHeldItem
& itUseCondition .~ UseableAnytime & itUseCondition .~ UseableAnytime
& itUse . heldDelay . rateMax .~ 20 -- & itUse . heldDelay . rateMax .~ 20
& itAmmoSlots .~ singleAmmo ElectricalAmmo & itAmmoSlots .~ singleAmmo ElectricalAmmo
& itType .~ DETECTOR dt & itType .~ DETECTOR dt
-- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleDetector -- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleDetector
@@ -46,7 +46,7 @@ blinker :: Item
blinker = blinker =
defaultHeldItem defaultHeldItem
& itUseCondition .~ UseableAnytime & itUseCondition .~ UseableAnytime
& itUse . heldDelay . rateMax .~ 20 -- & itUse . heldDelay . rateMax .~ 20
& itAmmoSlots .~ singleAmmo ElectricalAmmo & itAmmoSlots .~ singleAmmo ElectricalAmmo
-- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleBlink -- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleBlink
-- & itUse . heldMuzzles . ix 0 . mzAmmoPerShot .~ UseExactly 10000000 -- & itUse . heldMuzzles . ix 0 . mzAmmoPerShot .~ UseExactly 10000000
+1 -1
View File
@@ -9,7 +9,7 @@ shatterGun :: Item
shatterGun = shatterGun =
defaultHeldItem defaultHeldItem
& itType .~ HELD SHATTERGUN & itType .~ HELD SHATTERGUN
& itUse . heldDelay . rateMax .~ 10 -- & itUse . heldDelay . rateMax .~ 10
& itAmmoSlots .~ singleAmmo ElectricalAmmo & itAmmoSlots .~ singleAmmo ElectricalAmmo
-- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 30 0 -- & itUse . heldMuzzles . ix 0 . mzPos .~ V2 30 0
-- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0 -- & itUse . heldMuzzles . ix 0 . mzInaccuracy .~ 0
+183 -173
View File
File diff suppressed because it is too large Load Diff