From 016a1faf80416cc31c378c1bb52d2ba3f974ff38 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 1 Dec 2021 17:40:09 +0000 Subject: [PATCH] Allow for partial reloading --- src/Dodge/Base.hs | 5 ++ src/Dodge/Creature/Action.hs | 29 ++++----- src/Dodge/Creature/ReaderUpdate.hs | 2 +- src/Dodge/Creature/State.hs | 28 ++++++--- src/Dodge/Creature/Test.hs | 6 +- src/Dodge/Data.hs | 22 ++++--- src/Dodge/Default/Weapon.hs | 10 ++-- src/Dodge/Item/Weapon/AmmoParams.hs | 9 +-- src/Dodge/Item/Weapon/BatteryGuns.hs | 18 +++--- src/Dodge/Item/Weapon/Bezier.hs | 2 +- src/Dodge/Item/Weapon/Booster.hs | 10 ++-- src/Dodge/Item/Weapon/BulletGuns.hs | 72 ++++++++++++----------- src/Dodge/Item/Weapon/Drone.hs | 6 +- src/Dodge/Item/Weapon/ExtraEffect.hs | 6 +- src/Dodge/Item/Weapon/InventoryDisplay.hs | 11 ++-- src/Dodge/Item/Weapon/Launcher.hs | 12 ++-- src/Dodge/Item/Weapon/Radar.hs | 12 ++-- src/Dodge/Item/Weapon/Spawn.hs | 6 +- src/Dodge/Item/Weapon/SprayGuns.hs | 12 ++-- src/Dodge/Item/Weapon/TriggerType.hs | 26 ++++---- src/Dodge/Item/Weapon/Utility.hs | 20 +++---- 21 files changed, 181 insertions(+), 143 deletions(-) diff --git a/src/Dodge/Base.hs b/src/Dodge/Base.hs index acabbe814..5efdae37c 100644 --- a/src/Dodge/Base.hs +++ b/src/Dodge/Base.hs @@ -38,6 +38,11 @@ takeUntil p = foldr (\x xs -> x : if p x then [] else xs) [] decreaseToZero :: Int -> Int decreaseToZero x = max 0 (x - 1) +decreaseToNothing' :: (Num a, Ord a) => Maybe' a -> Maybe' a +decreaseToNothing' ma = case ma of + Just' x | x > 0 -> Just' (x - 1) + _ -> Nothing' + safeHead :: [a] -> Maybe a safeHead (x:_) = Just x safeHead _ = Nothing diff --git a/src/Dodge/Creature/Action.hs b/src/Dodge/Creature/Action.hs index ab7bc8863..4487b8b55 100644 --- a/src/Dodge/Creature/Action.hs +++ b/src/Dodge/Creature/Action.hs @@ -145,27 +145,28 @@ performAction cr w ac = case ac of NoAction -> ([],Nothing) startReloadingWeapon :: Creature -> World -> Maybe World -startReloadingWeapon cr w = - let cid = _crID cr - it = _crInv cr IM.! _crInvSel cr - itRef = creatures . ix cid . crInv . ix (_crInvSel cr) - in case it of - Weapon {_itConsumption = LoadableAmmo {_wpMaxAmmo=maxA,_wpLoadedAmmo=lA ,_wpReloadState=rS,_wpReloadTime=rT}} - | lA < maxA && rS == 0 -> Just $ set ( itRef . itConsumption . wpLoadedAmmo) maxA - $ set ( itRef . itConsumption . wpReloadState) rT w - _ -> Nothing +startReloadingWeapon cr w = case it of + Weapon {_itConsumption = LoadableAmmo {_ammoMax=maxA,_ammoLoaded=lA ,_reloadState=rS,_reloadTime=rT}} + | lA < maxA && rS == Nothing' -> + Just -- $ set ( itRef . itConsumption . ammoLoaded) maxA + $ set ( itRef . itConsumption . reloadState) (Just' rT) w + _ -> Nothing + where + cid = _crID cr + it = _crInv cr IM.! _crInvSel cr + itRef = creatures . ix cid . crInv . ix (_crInvSel cr) {- | Start reloading if clip is empty. -} crAutoReload :: Creature -> Creature -crAutoReload cr = case cr ^? ptrItConsumption' . wpLoadedAmmo of +crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of Just 0 | _posture (_crStance cr) /= Aiming - -> cr & ptrItConsumption . wpReloadState %~ (`fromMaybe` reloadT) - & ptrItConsumption . wpLoadedAmmo %~ (`fromMaybe` maxA) + -> cr & ptrItConsumption . reloadState .~ (strictify reloadT) + & ptrItConsumption . ammoLoaded %~ (`fromMaybe` maxA) _ -> cr where ptrItConsumption = crInv . ix (_crInvSel cr) . itConsumption ptrItConsumption' = crInv . ix (_crInvSel cr) . itConsumption - reloadT = cr ^? ptrItConsumption' . wpReloadTime - maxA = cr ^? ptrItConsumption' . wpMaxAmmo + reloadT = cr ^? ptrItConsumption' . reloadTime + maxA = cr ^? ptrItConsumption' . ammoMax {- | Teleport a creature to the mouse position -} blinkAction :: Creature diff --git a/src/Dodge/Creature/ReaderUpdate.hs b/src/Dodge/Creature/ReaderUpdate.hs index d51132174..1c65ce19f 100644 --- a/src/Dodge/Creature/ReaderUpdate.hs +++ b/src/Dodge/Creature/ReaderUpdate.hs @@ -122,7 +122,7 @@ reloadOverrideR :: Creature -> Reader World Creature reloadOverrideR cr - | cr ^? crInv . ix (_crInvSel cr) . itConsumption . wpLoadedAmmo == Just 0 + | cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded == Just 0 && cr ^. crStance . posture == Aiming = return $ cr & crActionPlan . crStrategy .~ StrategyActions Reload reloadActions | otherwise = return cr diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 326389bf6..cd12030b1 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -45,7 +45,8 @@ stateUpdate :: CRUpdate -> CRUpdate stateUpdate u cr w = case u (updateMovement cr) w of (f, maybeCr) -> ( Endo $ invSideEff (fromMaybe cr maybeCr) . movementSideEff cr . deathEff . appEndo f - , fmap (stepReloading . doDamage . crAutoReload) $ crOrCorpse =<< maybeCr + --, fmap (stepReloading . doDamage . crAutoReload) $ crOrCorpse =<< maybeCr + , fmap (stepReloading . doDamage) $ crOrCorpse =<< maybeCr ) where crOrCorpse cr' @@ -145,13 +146,16 @@ invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr) weaponReloadSounds :: Creature -> World -> World weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption of - Just am@LoadableAmmo{} -> case _wpReloadType am of - PassiveReload stype |_wpReloadTime am ==_wpReloadState am + Just am@LoadableAmmo{} -> case _reloadType am of + PassiveReload stype |Just' (_reloadTime am) == _reloadState am -> soundContinue (CrReloadSound 0) (_crPos cr) stype Nothing w PassiveReload _ -> w - ActiveReload | _wpReloadState am == 1 -> stopSoundFrom (CrReloadSound cid) w - ActiveReload | _wpReloadState am == 0 -> w + ActiveReload | _reloadState am == Just' 0 -> stopSoundFrom (CrReloadSound cid) w + ActiveReload | _reloadState am == Nothing' -> w ActiveReload -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w + PartialActive{} | _reloadState am == Just' 0 -> stopSoundFrom (CrReloadSound cid) w + PartialActive{} | _reloadState am == Nothing' -> w + PartialActive{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w Just ChargeableAmmo {} -> w Just ItemItselfConsumable {} -> w Nothing -> w @@ -186,8 +190,18 @@ isFrictionless cr = case cr ^? crStance . carriage of _ -> False stepReloading :: Creature -> Creature -stepReloading cr = over (crInv . ix iSel . itConsumption . wpReloadState) decreaseToZero cr +stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of + Just 0 -> cr & crInv . ix isel . itConsumption . reloadState .~ Nothing' + & crInv . ix isel . itConsumption %~ doload + Just _ -> cr & crInv . ix isel . itConsumption . reloadState . _Just' %~ decreaseToZero + Nothing -> cr where - iSel = _crInvSel cr + isel = _crInvSel cr + doload itcon = itcon & ammoLoaded %~ (min (_ammoMax itcon) . (+ amount)) + where + amount = case _reloadType itcon of + PartialActive x -> x + _ -> _ammoMax itcon + diff --git a/src/Dodge/Creature/Test.hs b/src/Dodge/Creature/Test.hs index ca610d721..12ac0e7b1 100644 --- a/src/Dodge/Creature/Test.hs +++ b/src/Dodge/Creature/Test.hs @@ -35,12 +35,12 @@ onBoth :: (a -> b -> c) -> (d -> a) -> (d -> b) -> d -> c onBoth f g h x = f (g x) (h x) crIsReloading :: (World, Creature) -> Bool -crIsReloading (_,cr) = case cr ^? crInv . ix (_crInvSel cr) . itConsumption . wpReloadState of +crIsReloading (_,cr) = case cr ^? crInv . ix (_crInvSel cr) . itConsumption . reloadState . _Just' of Just t -> t > 0 _ -> False crIsReloadingR :: Creature -> Reader World Bool -crIsReloadingR cr = return $ case cr ^? crInv . ix (_crInvSel cr) . itConsumption . wpReloadState of +crIsReloadingR cr = return $ case cr ^? crInv . ix (_crInvSel cr) . itConsumption . reloadState . _Just' of Just t -> t > 0 _ -> False @@ -114,7 +114,7 @@ crAwayFromPostR cr = return $ case find sentinelGoal $ _crGoal $ _crActionPlan c sentinelGoal _ = False crHasAmmo :: (World,Creature) -> Bool -crHasAmmo (_,cr) = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . wpLoadedAmmo +crHasAmmo (_,cr) = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded crCanShoot :: (World,Creature) -> Bool crCanShoot p = crIsAiming p && crHasAmmo p diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 415353bae..e18f0d5f3 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -314,11 +314,11 @@ _itUseAimStance = _aimStance . _useAim . _itUse data ItemConsumption = LoadableAmmo { _aoType :: AmmoType - , _wpMaxAmmo :: Int - , _wpLoadedAmmo :: Int - , _wpReloadTime :: Int - , _wpReloadState :: Int - , _wpReloadType :: ReloadType + , _ammoMax :: Int + , _ammoLoaded :: Int + , _reloadTime :: Int + , _reloadState :: Maybe' Int + , _reloadType :: ReloadType } | ChargeableAmmo { _wpMaxCharge :: Int @@ -424,7 +424,10 @@ data ItemDimension = ItemDimension , _muzzleLength :: Float } -data ReloadType = ActiveReload | PassiveReload SoundID +data ReloadType + = ActiveReload + | PartialActive Int + | PassiveReload SoundID -- I believe this is called every frame, not sure when though data ItEffect @@ -721,7 +724,11 @@ data WallStructure , _wlStDamCreature :: DamageType -> Wall -> Int -> World -> World } -- | Strict maybe -data Maybe' a = Just' a | Nothing' +data Maybe' a = Just' {__Just' :: a} | Nothing' + deriving (Eq,Ord,Show) +strictify :: Maybe a -> Maybe' a +strictify Nothing = Nothing' +strictify (Just x) = Just' x data ActionPlan = Inanimate @@ -921,3 +928,4 @@ makeLenses ''Universe makeLenses ''LSParam makeLenses ''ItemParams makeLenses ''ItemTweaks +makeLenses ''Maybe' diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index 1b49f618c..2cda4ca54 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -16,11 +16,11 @@ import Control.Lens defaultAmmo :: ItemConsumption defaultAmmo = LoadableAmmo { _aoType = GenericAmmo - , _wpMaxAmmo = 15 - , _wpLoadedAmmo = 15 - , _wpReloadTime = 40 - , _wpReloadState = 0 - , _wpReloadType = ActiveReload + , _ammoMax = 15 + , _ammoLoaded = 15 + , _reloadTime = 40 + , _reloadState = Nothing' + , _reloadType = ActiveReload } ruseRate :: Int diff --git a/src/Dodge/Item/Weapon/AmmoParams.hs b/src/Dodge/Item/Weapon/AmmoParams.hs index e5d837845..04ec26cfd 100644 --- a/src/Dodge/Item/Weapon/AmmoParams.hs +++ b/src/Dodge/Item/Weapon/AmmoParams.hs @@ -1,7 +1,7 @@ module Dodge.Item.Weapon.AmmoParams ( useAmmoParams , useAmmoParamsRate - , loadedAmmo +-- , loadedAmmo , useAmmoParamsVelMod , fractionLoadedAmmo , fractionLoadedAmmo2 @@ -73,13 +73,14 @@ withDelayedVelWthHiteff vfact vel width hiteff cr = over particles (newbul : ) dir = _crDir cr pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) +-- this shouldn't really be used loadedAmmo :: Item -> Int loadedAmmo it - | _wpReloadState (_itConsumption it) == 0 = _wpLoadedAmmo (_itConsumption it) + | _reloadState (_itConsumption it) == Nothing' = _ammoLoaded (_itConsumption it) | otherwise = 0 fractionLoadedAmmo :: Item -> Float -fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (_wpMaxAmmo (_itConsumption it)) +fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (_ammoMax (_itConsumption it)) fractionLoadedAmmo2 :: Item -> Float -fractionLoadedAmmo2 it = 1 - (1 - fromIntegral (loadedAmmo it) / fromIntegral (_wpMaxAmmo (_itConsumption it)))**2 +fractionLoadedAmmo2 it = 1 - (1 - fromIntegral (loadedAmmo it) / fromIntegral (_ammoMax (_itConsumption it)))**2 diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index 29d27c65d..c749aeeda 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -38,9 +38,9 @@ teslaGun = defaultGun { _itName = "TESLA" , _itIdentity = TeslaGun , _itConsumption = defaultAmmo - { _wpMaxAmmo = 200 - , _wpLoadedAmmo = 200 - , _wpReloadTime = 80 + { _ammoMax = 200 + , _ammoLoaded = 200 + , _reloadTime = 80 } , _itUse = ruseInstant (const aTeslaArc) NoHammer [ ammoCheckI @@ -65,9 +65,9 @@ lasGun = defaultAutoGun { _itName = "LASGUN ////" , _itIdentity = LasGun , _itConsumption = defaultAmmo - { _wpMaxAmmo = 200 - , _wpLoadedAmmo = 200 - , _wpReloadTime = 80 + { _ammoMax = 200 + , _ammoLoaded = 200 + , _reloadTime = 80 } , _itUse = ruseInstant (const aLaser) NoHammer [ ammoCheckI @@ -121,9 +121,9 @@ tractorGun = defaultAutoGun { _itName = "TRACTORGUN" , _itIdentity = TractorGun , _itConsumption = defaultAmmo - { _wpMaxAmmo = 10000 - , _wpLoadedAmmo = 10000 - , _wpReloadTime = 40 + { _ammoMax = 10000 + , _ammoLoaded = 10000 + , _reloadTime = 40 } , _itUse = ruseInstant aTractorBeam NoHammer [ ammoCheckI diff --git a/src/Dodge/Item/Weapon/Bezier.hs b/src/Dodge/Item/Weapon/Bezier.hs index 439451c44..0fa83eb6b 100644 --- a/src/Dodge/Item/Weapon/Bezier.hs +++ b/src/Dodge/Item/Weapon/Bezier.hs @@ -43,7 +43,7 @@ bezierGun = defaultGun , _itEffect = rbSetTarget -- , _itZoom = defaultItZoom , _itConsumption = defaultAmmo - { _wpMaxAmmo = 50 + { _ammoMax = 50 } } bezierGunSPic :: Item -> SPic diff --git a/src/Dodge/Item/Weapon/Booster.hs b/src/Dodge/Item/Weapon/Booster.hs index eb1cd2ef5..581230d67 100644 --- a/src/Dodge/Item/Weapon/Booster.hs +++ b/src/Dodge/Item/Weapon/Booster.hs @@ -37,8 +37,8 @@ boostSelfL -> World -> World boostSelfL x cr invid w = case boostPoint x cr w of - Left p -> crEff p (itConsumption . wpLoadedAmmo .~ 0) - Right p -> crEff p (itConsumption . wpLoadedAmmo -~ 1) + Left p -> crEff p (itConsumption . ammoLoaded .~ 0) + Right p -> crEff p (itConsumption . ammoLoaded -~ 1) where cid = _crID cr cpos = _crPos cr @@ -114,9 +114,9 @@ boosterGun = defaultGun { _itName = "BOOSTER" , _itIdentity = Blinker , _itConsumption = defaultAmmo - { _wpMaxAmmo = 100 - , _wpLoadedAmmo = 100 - , _wpReloadTime = 20 + { _ammoMax = 100 + , _ammoLoaded = 100 + , _reloadTime = 20 } , _itUse = luseInstantNoH $ boostSelfL 10 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)] diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index 353e7ca0e..8f8c91e64 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -39,9 +39,9 @@ autoGun = defaultAutoGun , _itIdentity = AutoGun , _itConsumption = defaultAmmo { _aoType = basicBullet - , _wpMaxAmmo = 30 - , _wpLoadedAmmo = 30 - , _wpReloadTime = 80 + , _ammoMax = 30 + , _ammoLoaded = 30 + , _reloadTime = 80 } , _itUse = useAmmoParamsRate 4 NoHammer [ ammoCheckI @@ -85,7 +85,7 @@ autoGunPic it = noPic $ ) <> translateSHf 0 (-1) (rotateSHx (negate $ pi/4) . upperPrismPoly 2 $ rectNESW (negate $ 3 + 0.25 * x) 0 3 (-5)) where - x = fromIntegral $ loadedAmmo it + x = fromIntegral $ _ammoLoaded $ _itConsumption it pistol :: Item pistol = defaultGun @@ -93,9 +93,10 @@ pistol = defaultGun , _itIdentity = Pistol , _itConsumption = defaultAmmo { _aoType = basicBullet - , _wpMaxAmmo = 15 - , _wpLoadedAmmo = 15 - , _wpReloadTime = 40 + , _ammoMax = 15 + , _ammoLoaded = 15 + , _reloadTime = 10 + , _reloadType = PartialActive 1 } , _itUse = useAmmoParamsRate 8 upHammer [ ammoCheckI @@ -127,7 +128,7 @@ pistolPic it = noPic $ colorSH green (prismPoly ) <> translateSH (V3 (-4) 5.5 4) (rotateSH pi $ bulletClip am) where - am = loadedAmmo it + am = _ammoLoaded $ _itConsumption it bulletClip :: Int -> Shape bulletClip x = rotateSHx (negate $ pi/4) . upperPrismPoly 2 $ rectNESW 3 0 (3 - 0.25 * am) (-5) @@ -140,9 +141,9 @@ hvAutoGun = defaultAutoGun , _itIdentity = HvAutoGun , _itConsumption = defaultAmmo { _aoType = hvBullet - , _wpMaxAmmo = 100 - , _wpLoadedAmmo = 100 - , _wpReloadTime = 200 + , _ammoMax = 100 + , _ammoLoaded = 100 + , _reloadTime = 200 } , _itUse = useAmmoParamsRate 25 NoHammer [ ammoCheckI @@ -157,6 +158,11 @@ hvAutoGun = defaultAutoGun & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} & useDelay .~ VariableRate {_rateMax = 25, _rateMaxMax = 24, _rateMinMax = 7, _rateTime = 0} , _itFloorPict = hvAutoGunPic + , _itInvSize = 3 + , _itInvDisplay = \it -> basicWeaponDisplay it ++ + ["* FRATE: *" + ,"* " ++ fromMaybe " " (maybeRateStatus it) ++ " *" + ] } hvAutoGunPic :: Item -> SPic hvAutoGunPic it = @@ -168,16 +174,16 @@ hvAutoGunPic it = , mempty ) where - am = loadedAmmo it + am = _ammoLoaded $ _itConsumption it ltAutoGun :: Item ltAutoGun = defaultAutoGun { _itName = "AUTO-LT" , _itIdentity = LtAutoGun , _itConsumption = defaultAmmo { _aoType = ltBullet - , _wpMaxAmmo = 25 - , _wpLoadedAmmo = 25 - , _wpReloadTime = 80 + , _ammoMax = 25 + , _ammoLoaded = 25 + , _reloadTime = 80 } , _itUse = useAmmoParamsRate 2 NoHammer [ ammoCheckI @@ -207,16 +213,16 @@ ltAutoGunPic it = , mempty ) where - am = loadedAmmo it + am = _ammoLoaded $ _itConsumption it miniGun :: Item miniGun = defaultAutoGun { _itName = "MINI-G" , _itIdentity = MiniGun , _itConsumption = defaultAmmo { _aoType = basicBullet - , _wpMaxAmmo = 1500 - , _wpLoadedAmmo = 1500 - , _wpReloadTime = 200 + , _ammoMax = 1500 + , _ammoLoaded = 1500 + , _reloadTime = 200 } , _itUse = ruseInstant (useAmmoParamsVelMod vm4) NoHammer [ ammoCheckI @@ -281,9 +287,9 @@ miniGun = defaultAutoGun --[ 0.75, 0.5, 0.25] --[ 0, 0, 0] miniGunPictItem :: Item -> SPic -miniGunPictItem it = miniGunPict spin (loadedAmmo it) +miniGunPictItem it = miniGunPict spin (_ammoLoaded $ _itConsumption it) where - spin = (-10) * _wpLoadedAmmo (_itConsumption it) + _warmTime (_useDelay $ _itUse it) + spin = (-10) * _ammoLoaded (_itConsumption it) + _warmTime (_useDelay $ _itUse it) miniGunPict :: Int -> Int -> SPic miniGunPict spin am = @@ -313,9 +319,9 @@ spreadGun = defaultGun , _itIdentity = SpreadGun , _itConsumption = defaultAmmo { _aoType = basicBullet - , _wpMaxAmmo = 5 - , _wpLoadedAmmo = 5 - , _wpReloadTime = 80 + , _ammoMax = 5 + , _ammoLoaded = 5 + , _reloadTime = 80 } , _itUse = useAmmoParamsRate 20 upHammer [ ammoCheckI @@ -345,16 +351,16 @@ spreadGunPic it = , mempty ) where - am = loadedAmmo it + am = _ammoLoaded $ _itConsumption it multGun :: Item multGun = defaultGun { _itName = "MULTGUN" , _itIdentity = MultGun , _itConsumption = defaultAmmo { _aoType = basicBullet - , _wpMaxAmmo = 2 - , _wpLoadedAmmo = 2 - , _wpReloadTime = 40 + , _ammoMax = 2 + , _ammoLoaded = 2 + , _reloadTime = 40 } , _itUse = useAmmoParamsRate 20 upHammer [ ammoCheckI @@ -395,17 +401,17 @@ multGunSPic it = barrel y = prismPoly (map (addZ 5) $ rectNSEW y (y-4) 2 0 ) (map (addZ 0) $ rectNSEW y (y-4) 2 (-2)) - am = loadedAmmo it + am = _ammoLoaded $ _itConsumption it longGun :: Item longGun = defaultGun { _itName = "LONGGUN" , _itIdentity = LongGun , _itConsumption = defaultAmmo { _aoType = hvBullet - , _wpMaxAmmo = 1 - , _wpLoadedAmmo = 1 - , _wpReloadTime = 100 - , _wpReloadType = PassiveReload skwareFadeTwoSecS + , _ammoMax = 1 + , _ammoLoaded = 1 + , _reloadTime = 100 + , _reloadType = PassiveReload skwareFadeTwoSecS } , _itUse = useAmmoParamsRate 100 upHammer [ ammoCheckI diff --git a/src/Dodge/Item/Weapon/Drone.hs b/src/Dodge/Item/Weapon/Drone.hs index 3a3c71faa..1d9032d02 100644 --- a/src/Dodge/Item/Weapon/Drone.hs +++ b/src/Dodge/Item/Weapon/Drone.hs @@ -24,9 +24,9 @@ lasDrones = defaultGun , _itIdentity = Generic , _itConsumption = defaultAmmo { _aoType = DroneAmmo { _amString = "LASDRONE" } - , _wpMaxAmmo = 2 - , _wpLoadedAmmo = 2 - , _wpReloadTime = 80 + , _ammoMax = 2 + , _ammoLoaded = 2 + , _reloadTime = 80 } , _itUse = ruseRate 20 aDroneWithItemParams upHammer [ ammoCheckI diff --git a/src/Dodge/Item/Weapon/ExtraEffect.hs b/src/Dodge/Item/Weapon/ExtraEffect.hs index 8353fd35c..eb9229af9 100644 --- a/src/Dodge/Item/Weapon/ExtraEffect.hs +++ b/src/Dodge/Item/Weapon/ExtraEffect.hs @@ -81,8 +81,10 @@ itemLaserScopeEffect -- _ -> ep -.- 2 *.* unitVectorAtAngle d wpammo = _itConsumption $ (cr ^. crInv) IM.! invid reloadFrac - | _wpLoadedAmmo wpammo == 0 = 1 - | otherwise = fromIntegral (_wpReloadState wpammo) / fromIntegral (_wpReloadTime wpammo) + | _ammoLoaded wpammo == 0 = 1 + | otherwise = case _reloadState wpammo of + Just' rs -> fromIntegral rs / fromIntegral (_reloadTime wpammo) + Nothing' -> 1 --col = mixColors reloadFrac (1-reloadFrac) red green {- | Automatically send out radar pulses that detect walls. -} autoRadarEffect :: ItEffect diff --git a/src/Dodge/Item/Weapon/InventoryDisplay.hs b/src/Dodge/Item/Weapon/InventoryDisplay.hs index 66362b47c..236b479aa 100644 --- a/src/Dodge/Item/Weapon/InventoryDisplay.hs +++ b/src/Dodge/Item/Weapon/InventoryDisplay.hs @@ -4,6 +4,7 @@ Display of weapon strings in the inventory. module Dodge.Item.Weapon.InventoryDisplay ( basicWeaponDisplay , maybeWarmupStatus + , maybeRateStatus ) where import Dodge.Data import Padding @@ -17,9 +18,9 @@ basicWeaponDisplay it = [midPadL 10 ' ' thename (' ' : thenumber) ++ theparam] where thename = _itName it thenumber = case it ^? itConsumption of - Just am@LoadableAmmo{} -> case _wpReloadState am of - 0 -> show $ _wpLoadedAmmo am - x -> "R" ++ show x + Just am@LoadableAmmo{} -> case _reloadState am of + Nothing' -> show (_ammoLoaded am) + Just' x -> show x ++ "R" ++ show (_ammoLoaded am) Just am@ChargeableAmmo{} -> show $ _wpCharge am Just x@ItemItselfConsumable{} -> show $ _itMaxStack' x Nothing -> "" @@ -28,7 +29,7 @@ basicWeaponDisplay it = [midPadL 10 ' ' thename (' ' : thenumber) ++ theparam] $ mapMaybe ($ it) [ maybeModeStatus -- , maybeWarmupStatus - , maybeRateStatus +-- , maybeRateStatus ] maybeModeStatus :: Item -> Maybe String @@ -40,7 +41,7 @@ maybeModeStatus it = case it ^? itAttachment of maybeRateStatus :: Item -> Maybe String maybeRateStatus it = case it ^? itUse . useDelay . rateMaxMax of Nothing -> Nothing - _ -> Just $ ' ' : "T" ++ leftPad 3 ' ' (show (_rateMax . _useDelay $ _itUse it)) + _ -> Just $ ' ' : " " ++ leftPad 4 ' ' (show (_rateMax . _useDelay $ _itUse it)) maybeWarmupStatus :: Item -> Maybe String maybeWarmupStatus it = case it ^? itUse . useDelay . warmMax of diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index 1398f2c61..47889837c 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -44,9 +44,9 @@ launcher = defaultGun , _amString = "EXPLOSIVE SHELL" , _amPjDraw = shellPic } - , _wpMaxAmmo = 30 - , _wpLoadedAmmo = 30 - , _wpReloadTime = 80 + , _ammoMax = 30 + , _ammoLoaded = 30 + , _reloadTime = 80 } , _itUse = ruseRate 20 aRocketWithItemParams upHammer [ ammoCheckI @@ -267,9 +267,9 @@ remoteLauncher = defaultGun , _amString = "" , _amPjDraw = shellPic } - , _wpMaxAmmo = 30 - , _wpLoadedAmmo = 30 - , _wpReloadTime = 80 + , _ammoMax = 30 + , _ammoLoaded = 30 + , _reloadTime = 80 } , _itUse = ruseRate 10 (const fireRemoteLauncher) upHammer [ ammoCheckI diff --git a/src/Dodge/Item/Weapon/Radar.hs b/src/Dodge/Item/Weapon/Radar.hs index f718ca7fb..3defccf5b 100644 --- a/src/Dodge/Item/Weapon/Radar.hs +++ b/src/Dodge/Item/Weapon/Radar.hs @@ -22,9 +22,9 @@ radar = defaultGun { _itName = "RADAR" , _itIdentity = Generic , _itConsumption = defaultAmmo - { _wpMaxAmmo = 100 - , _wpLoadedAmmo = 100 - , _wpReloadTime = 200 + { _ammoMax = 100 + , _ammoLoaded = 100 + , _reloadTime = 200 } , _itUse = ruseRate 120 (const aRadarPulse) upHammer [ ammoUseCheck @@ -42,9 +42,9 @@ sonar = defaultGun { _itName = "SONAR" , _itIdentity = Generic , _itConsumption = defaultAmmo - { _wpMaxAmmo = 100 - , _wpLoadedAmmo = 100 - , _wpReloadTime = 200 + { _ammoMax = 100 + , _ammoLoaded = 100 + , _reloadTime = 200 } , _itUse = ruseRate 120 (const aSonarPulse) upHammer [ ammoUseCheck diff --git a/src/Dodge/Item/Weapon/Spawn.hs b/src/Dodge/Item/Weapon/Spawn.hs index 19e8d4580..9e0633e61 100644 --- a/src/Dodge/Item/Weapon/Spawn.hs +++ b/src/Dodge/Item/Weapon/Spawn.hs @@ -18,9 +18,9 @@ spawnGun :: Creature -> Item spawnGun cr = defaultGun { _itName = "SPAWNER" , _itConsumption = defaultAmmo - { _wpMaxAmmo = 1 - , _wpLoadedAmmo = 1 - , _wpReloadTime = 80 + { _ammoMax = 1 + , _ammoLoaded = 1 + , _reloadTime = 80 } , _itUse = ruseRate 100 (\_ -> spawnCrNextTo cr) diff --git a/src/Dodge/Item/Weapon/SprayGuns.hs b/src/Dodge/Item/Weapon/SprayGuns.hs index d24bb4feb..1a068c5cb 100644 --- a/src/Dodge/Item/Weapon/SprayGuns.hs +++ b/src/Dodge/Item/Weapon/SprayGuns.hs @@ -35,9 +35,9 @@ poisonSprayer = defaultAutoGun { _itName = "POISON" , _itIdentity = PoisonSprayer , _itConsumption = defaultAmmo - { _wpMaxAmmo = 500 - , _wpLoadedAmmo = 500 - , _wpReloadTime = 100 + { _ammoMax = 500 + , _ammoLoaded = 500 + , _reloadTime = 100 } , _itUse = ruseInstant (const aGasCloud) NoHammer [ ammoCheckI @@ -59,9 +59,9 @@ flamer = defaultAutoGun { _itName = "FLAMER" , _itIdentity = Flamethrower , _itConsumption = defaultAmmo - { _wpMaxAmmo = 250 - , _wpLoadedAmmo = 250 - , _wpReloadTime = 100 + { _ammoMax = 250 + , _ammoLoaded = 250 + , _reloadTime = 100 } , _itUse = ruseInstant (\_ -> randWalkAngle aFlame) NoHammer [ ammoCheckI diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index e841c2d7a..8b02586d0 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -95,12 +95,12 @@ withThickSmokeI eff item cr w = eff item cr -- fire. ammoCheckI :: ChainEffect ammoCheckI eff item cr w - | _wpLoadedAmmo (_itConsumption item) <= 0 = fromMaybe w (startReloadingWeapon cr w) - | _wpReloadState (_itConsumption item) > 0 = w + | _ammoLoaded (_itConsumption item) <= 0 = fromMaybe w (startReloadingWeapon cr w) + | _reloadState (_itConsumption item) /= Nothing' = w | otherwise = eff item cr w itUseAmmo :: Int -> Item -> Item -itUseAmmo x = itConsumption . wpLoadedAmmo %~ (max 0 . subtract x) +itUseAmmo x = itConsumption . ammoLoaded %~ (max 0 . subtract x) {- | Fires at an increasing rate. Has different effect after first fire. @@ -128,15 +128,15 @@ rateIncAB exeffFirst exeffCont eff item cr w itRef = _crInvSel cr pointItem = creatures . ix cid . crInv . ix itRef currentRate = _rateMax (_useDelay (_itUse item)) - repeatFire = _wpReloadState (_itConsumption item) == 0 && _rateTime (_useDelay (_itUse item)) == 1 - firstFire = _wpReloadState (_itConsumption item) == 0 && _rateTime (_useDelay (_itUse item)) == 0 + repeatFire = _reloadState (_itConsumption item) == Nothing' && _rateTime (_useDelay (_itUse item)) == 1 + firstFire = _reloadState (_itConsumption item) == Nothing' && _rateTime (_useDelay (_itUse item)) == 0 {- | Apply effect after a warm up. -} -- note this is quite unsafe, requires the item to have the correct delay type withWarmUp :: SoundID -- ^ warm up sound id -> ChainEffect withWarmUp soundID f item cr w - | _wpReloadState (_itConsumption item) /= 0 = w + | _reloadState (_itConsumption item) /= Nothing' = w | curWarmUp < maxWarmUp = w & pointerToItem . itUse . useDelay . warmTime +~ 2 & soundContinue (CrWeaponSound cid 0) (_crPos cr) soundID (Just 2) @@ -221,7 +221,7 @@ useAmmo :: Int -- ^ amount of ammo to use -> ChainEffect useAmmo amAmount eff item cr = eff item cr - . (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . itConsumption . wpLoadedAmmo -~ amAmount) + . (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . itConsumption . ammoLoaded -~ amAmount) {- | Applies a world effect after an item use cooldown check. -} useTimeCheck :: ChainEffect @@ -254,10 +254,10 @@ ammoUseCheck f item cr w cid = _crID cr itRef = _crInvSel cr pointerToItem = creatures . ix cid . crInv . ix itRef - fireCondition = _wpReloadState (_itConsumption item) == 0 + fireCondition = _reloadState (_itConsumption item) == Nothing' && _rateTime (_useDelay (_itUse item)) == 0 - && _wpLoadedAmmo (_itConsumption item) > 0 - reloadCondition = _wpLoadedAmmo (_itConsumption item) == 0 + && _ammoLoaded (_itConsumption item) > 0 + reloadCondition = _ammoLoaded (_itConsumption item) == 0 {- | Applies a world effect after a hammer position check. Arbitrary inventory position. -} hammerCheckL @@ -289,10 +289,10 @@ shootL f cr invid w cid = _crID cr item = _crInv cr IM.! invid pointerToItem = creatures . ix cid . crInv . ix invid - fireCondition = _wpReloadState (_itConsumption item) == 0 + fireCondition = _reloadState (_itConsumption item) == Nothing' && _rateTime (_useDelay (_itUse item)) == 0 - && _wpLoadedAmmo (_itConsumption item) > 0 - reloadCondition = _wpLoadedAmmo (_itConsumption item) == 0 + && _ammoLoaded (_itConsumption item) > 0 + reloadCondition = _ammoLoaded (_itConsumption item) == 0 withTempLight :: Int -> Float -> V3 Float -> ChainEffect withTempLight time rad col eff item cr = eff item cr . over tempLightSources (theTLS :) diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index 363f7a793..6741d45ac 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -57,9 +57,9 @@ shrinkGun = defaultGun { _itName = "SHRINKER" , _itIdentity = Generic , _itConsumption = defaultAmmo - { _wpMaxAmmo = 100 - , _wpLoadedAmmo = 100 - , _wpReloadTime = 20 + { _ammoMax = 100 + , _ammoLoaded = 100 + , _reloadTime = 20 } , _itUse = defaultlUse {_lUse = hammerCheckL useShrinkGun} & useHammer .~ upHammer @@ -87,9 +87,9 @@ blinkGun = defaultGun { _itName = "BLINKER" , _itIdentity = Blinker , _itConsumption = defaultAmmo - { _wpMaxAmmo = 100 - , _wpLoadedAmmo = 100 - , _wpReloadTime = 20 + { _ammoMax = 100 + , _ammoLoaded = 100 + , _reloadTime = 20 } , _itUse = defaultlUse {_lUse = hammerCheckL $ shootL aSelfL @@ -119,10 +119,10 @@ forceFieldGun = defaultGun { _itName = "FORCEFIELD" , _itIdentity = ForceFieldGun , _itConsumption = defaultAmmo - { _wpMaxAmmo = 100 - , _wpLoadedAmmo = 100 - , _wpReloadTime = 40 - , _wpReloadState = 0 + { _ammoMax = 100 + , _ammoLoaded = 100 + , _reloadTime = 40 + , _reloadState = Nothing' } , _itUse = undefined , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)]