Allow for partial reloading

This commit is contained in:
2021-12-01 17:40:09 +00:00
parent d75ea2b252
commit 016a1faf80
21 changed files with 181 additions and 143 deletions
+5
View File
@@ -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
+15 -14
View File
@@ -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
+1 -1
View File
@@ -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
+21 -7
View File
@@ -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
+3 -3
View File
@@ -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
+15 -7
View File
@@ -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'
+5 -5
View File
@@ -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
+5 -4
View File
@@ -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
+9 -9
View File
@@ -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
+1 -1
View File
@@ -43,7 +43,7 @@ bezierGun = defaultGun
, _itEffect = rbSetTarget
-- , _itZoom = defaultItZoom
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 50
{ _ammoMax = 50
}
}
bezierGunSPic :: Item -> SPic
+5 -5
View File
@@ -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)]
+39 -33
View File
@@ -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
+3 -3
View File
@@ -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
+4 -2
View File
@@ -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
+6 -5
View File
@@ -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
+6 -6
View File
@@ -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
+6 -6
View File
@@ -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
+3 -3
View File
@@ -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)
+6 -6
View File
@@ -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
+13 -13
View File
@@ -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 :)
+10 -10
View File
@@ -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)]