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