Refactor reloading to use list of required steps

This commit is contained in:
2022-06-20 19:06:02 +01:00
parent a85cf4d1fb
commit 37eb69c661
16 changed files with 79 additions and 118 deletions
+2 -2
View File
@@ -231,8 +231,8 @@ doItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of
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 am ^? laLoadType . loadProgress of Just am@LoadableAmmo{} -> case am ^? laProgress of
Just NoTransfer -> w -- stopSoundFrom (CrReloadSound cid) w Just FinishedLoading -> w -- stopSoundFrom (CrReloadSound cid) w
Just _ -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w Just _ -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
Nothing -> w Nothing -> w
-- PassiveReload stype | Just (_laReloadTime am) == am ^? laTransfer . transferTime -- PassiveReload stype | Just (_laReloadTime am) == am ^? laTransfer . transferTime
+18 -13
View File
@@ -487,7 +487,8 @@ data ItemConsumption
{ _laAmmoType :: AmmoType { _laAmmoType :: AmmoType
, _laMax :: Int , _laMax :: Int
, _laLoaded :: Int , _laLoaded :: Int
, _laLoadType :: LoadType , _laCycle :: [LoadAction]
, _laProgress :: LoadProgress
} }
| ChargeableAmmo | ChargeableAmmo
{ _wpMaxCharge :: Int { _wpMaxCharge :: Int
@@ -545,19 +546,22 @@ data ItemPortage
| WornItem | WornItem
| NoPortage | NoPortage
data LoadProgress data LoadActionProgress = LoadActionProgress
= NoTransfer { _actionProgress :: Int
| Eject {_ejectProgress :: Int} , _actionType :: LoadAction
| Insert {_insertProgress :: Int, _insertAmount :: Int } }
deriving (Eq,Ord,Show) deriving (Eq,Ord,Show)
data LoadType data LoadProgress
= ActiveEject = InProgress { _lastAction :: Maybe LoadAction, _futureActions :: [LoadActionProgress] }
{_ejectTime :: Int, _insertTime :: Int,_loadProgress :: LoadProgress } | FinishedLoading
| ActivePartial deriving (Eq,Ord,Show)
{_insertTime :: Int, _loadAmount :: Int, _loadProgress :: LoadProgress }
| PassiveReload SoundID data LoadAction
deriving Eq = Eject {_actionTime :: Int}
| Insert {_actionTime :: Int, _insertMax :: Maybe Int }
| Prime {_actionTime :: Int}
deriving (Eq,Ord,Show)
-- 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
@@ -1482,7 +1486,8 @@ makeLenses ''ItEffect
makeLenses ''FloorItem makeLenses ''FloorItem
makeLenses ''ItemConsumption makeLenses ''ItemConsumption
makeLenses ''AmmoType makeLenses ''AmmoType
makeLenses ''LoadType makeLenses ''LoadAction
makeLenses ''LoadActionProgress
makeLenses ''LoadProgress makeLenses ''LoadProgress
makeLenses ''TweakParam makeLenses ''TweakParam
makeLenses ''Prop makeLenses ''Prop
+2 -1
View File
@@ -19,7 +19,8 @@ defaultLoadable = LoadableAmmo
{ _laAmmoType = GenericAmmo { _laAmmoType = GenericAmmo
, _laMax = 15 , _laMax = 15
, _laLoaded = 0 , _laLoaded = 0
, _laLoadType = ActiveEject 20 20 NoTransfer , _laCycle = [Eject 10, Insert 10 Nothing, Prime 10]
, _laProgress = FinishedLoading
} }
defaultBulletLoadable :: ItemConsumption defaultBulletLoadable :: ItemConsumption
defaultBulletLoadable = defaultLoadable & laAmmoType .~ basicBullet defaultBulletLoadable = defaultLoadable & laAmmoType .~ basicBullet
+10 -6
View File
@@ -31,16 +31,20 @@ itemDisplay it = Prelude.take (itSlotsTaken it) $
showConsumption :: ItemConsumption -> String showConsumption :: ItemConsumption -> String
showConsumption ic = case ic of showConsumption ic = case ic of
am@LoadableAmmo{} -> showLoading (_laLoadType ic) ++ show (_laLoaded am) am@LoadableAmmo{} -> showLoading (_laProgress ic) ++ show (_laLoaded am)
am@ChargeableAmmo{} -> show $ _wpCharge am am@ChargeableAmmo{} -> show $ _wpCharge am
x@ItemItselfConsumable{} -> show (_icAmount x) x@ItemItselfConsumable{} -> show (_icAmount x)
NoConsumption -> "" NoConsumption -> ""
showLoading :: LoadType -> String showLoading :: LoadProgress -> String
showLoading lt = case lt ^? loadProgress of showLoading lt = case lt ^? futureActions . ix 0 of
Just (Eject t) -> show t ++ "E" Just lap -> show (_actionTime (_actionType lap) - _actionProgress lap)
Just (Insert t _) -> show t ++ "R" ++ showLoadActionType (_actionType lap)
Just NoTransfer -> ""
Nothing -> "" Nothing -> ""
showLoadActionType :: LoadAction -> String
showLoadActionType la = case la of
Eject {} -> "E"
Insert {} -> "L"
Prime {} -> "P"
-- & itInvDisplay .~ \it -> head (basicItemDisplay it) : -- & itInvDisplay .~ \it -> head (basicItemDisplay it) :
-- ["*FIRERATE:" ++ fromMaybe "" (maybeRateStatus it) -- ["*FIRERATE:" ++ fromMaybe "" (maybeRateStatus it)
+3 -6
View File
@@ -74,8 +74,7 @@ teslaGun :: Item
teslaGun = defaultBatteryGun teslaGun = defaultBatteryGun
{ _itConsumption = defaultLoadable { _itConsumption = defaultLoadable
& laMax .~ 200 & laMax .~ 200
& laLoadType . ejectTime .~ 40 & laCycle .~ [Eject 10, Insert 10 Nothing, Prime 60]
& laLoadType . insertTime .~ 40
, _itUse = ruseInstant shootTeslaArc NoHammer , _itUse = ruseInstant shootTeslaArc NoHammer
[ ammoCheckI [ ammoCheckI
, withTempLight 1 100 (V3 0 0 1) , withTempLight 1 100 (V3 0 0 1)
@@ -254,8 +253,7 @@ lasGun :: Item
lasGun = defaultAutoBatteryGun lasGun = defaultAutoBatteryGun
{ _itConsumption = defaultLoadable { _itConsumption = defaultLoadable
& laMax .~ 200 & laMax .~ 200
& laLoadType . ejectTime .~ 40 & laCycle .~ [Eject 10, Insert 10 Nothing, Prime 60]
& laLoadType . insertTime .~ 40
, _itUse = ruseInstant shootLaser NoHammer , _itUse = ruseInstant shootLaser NoHammer
[ ammoCheckI [ ammoCheckI
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
@@ -320,8 +318,7 @@ tractorGun :: Item
tractorGun = lasGun tractorGun = lasGun
{ _itConsumption = defaultLoadable { _itConsumption = defaultLoadable
& laMax .~ 10000 & laMax .~ 10000
& laLoadType . ejectTime .~ 20 & laCycle .~ [Eject 10, Insert 10 Nothing, Prime 60]
& laLoadType . insertTime .~ 20
, _itUse = ruseInstant aTractorBeam NoHammer , _itUse = ruseInstant aTractorBeam NoHammer
[ ammoCheckI [ ammoCheckI
] ]
+4 -6
View File
@@ -73,7 +73,7 @@ bangCane = defaultBulletWeapon
} & itUse . useAim . aimStance .~ OneHand } & itUse . useAim . aimStance .~ OneHand
& itType . iyBase .~ BANGCANE & itType . iyBase .~ BANGCANE
& itConsumption . laMax .~ 1 & itConsumption . laMax .~ 1
& itConsumption . laLoadType .~ ActivePartial 10 1 NoTransfer & itConsumption . laCycle .~ [Insert 10 (Just 1)]
bangCaneX :: Int -> Item bangCaneX :: Int -> Item
bangCaneX i = bangCane bangCaneX i = bangCane
{ _itUse = ruseAmmoParamsRate 6 upHammer { _itUse = ruseAmmoParamsRate 6 upHammer
@@ -139,7 +139,7 @@ rifle = bangCane
& itUse . useAim . aimStance .~ TwoHandTwist & itUse . useAim . aimStance .~ TwoHandTwist
& itType . iyBase .~ RIFLE & itType . iyBase .~ RIFLE
& itConsumption . laMax .~ 1 & itConsumption . laMax .~ 1
& itConsumption . laLoadType .~ ActiveEject 5 5 NoTransfer & itConsumption . laCycle .~ [Eject 5, Insert 5 Nothing,Prime 5]
& itUse . useAim . aimWeight .~ 6 & itUse . useAim . aimWeight .~ 6
& itUse . useAim . aimRange .~ 1 & itUse . useAim . aimRange .~ 1
-- & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} -- & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5}
@@ -148,8 +148,7 @@ repeater :: Item
repeater = rifle repeater = rifle
& itType . iyModules . at ModRifleMag ?~ EMPTYMODULE & itType . iyModules . at ModRifleMag ?~ EMPTYMODULE
& itType . iyBase .~ REPEATER & itType . iyBase .~ REPEATER
& itConsumption . laLoadType . ejectTime .~ 40 & itConsumption . laCycle .~ [Eject 5, Insert 15 Nothing,Prime 15]
& itConsumption . laLoadType . insertTime .~ 40
& itConsumption . laMax .~ 15 & itConsumption . laMax .~ 15
& itDimension . dimSPic .~ (\it -> noPic $ baseRifleShape & itDimension . dimSPic .~ (\it -> noPic $ baseRifleShape
<> makeTinClipAt 0 (V3 10 (-2) 0) it <> makeTinClipAt 0 (V3 10 (-2) 0) it
@@ -252,8 +251,7 @@ miniGunX i = defaultAutoGun
{ _laMax = 1500 { _laMax = 1500
, _laLoaded = 1500 , _laLoaded = 1500
} }
& laLoadType . ejectTime .~ 60 & laCycle .~ [Eject 40, Insert 40 Nothing,Prime 40]
& laLoadType . insertTime .~ 60
, _itUse = miniGunUse i , _itUse = miniGunUse i
& useDelay .~ WarmUpNoDelay {_warmTime = 0,_warmMax = 100} & useDelay .~ WarmUpNoDelay {_warmTime = 0,_warmMax = 100}
& useAim . aimWeight .~ 6 & useAim . aimWeight .~ 6
+2 -4
View File
@@ -70,8 +70,7 @@ bangRod = defaultBulletWeapon
} }
} }
& itConsumption . laMax .~ 1 & itConsumption . laMax .~ 1
& itConsumption . laLoadType . ejectTime .~ 10 & itConsumption . laCycle .~ [Eject 5, Insert 10 Nothing, Prime 5]
& itConsumption . laLoadType . insertTime .~ 10
& itType . iyBase .~ BANGROD & itType . iyBase .~ BANGROD
& itUse . useAim . aimWeight .~ 8 & itUse . useAim . aimWeight .~ 8
& itUse . useAim . aimRange .~ 1 & itUse . useAim . aimRange .~ 1
@@ -142,7 +141,6 @@ machineGun = bangRod
& useDelay .~ VariableRate {_rateMax = 25, _rateMaxMax = 24, _rateMinMax = 7, _rateTime = 0} & useDelay .~ VariableRate {_rateMax = 25, _rateMaxMax = 24, _rateMinMax = 7, _rateTime = 0}
) )
& itConsumption . laMax .~ 100 & itConsumption . laMax .~ 100
& itConsumption . laLoadType . ejectTime .~ 25 & itConsumption . laCycle .~ [Eject 10, Insert 40 Nothing, Prime 10]
& itConsumption . laLoadType . insertTime .~ 25
& itInvSize .~ 3 & itInvSize .~ 3
& itParams. torqueAfter .~ 0.2 -- not sure if this is necessary? & itParams. torqueAfter .~ 0.2 -- not sure if this is necessary?
+3 -4
View File
@@ -78,7 +78,7 @@ bangStick i = defaultBulletWeapon
} }
& itType . iyBase .~ BANGSTICK i & itType . iyBase .~ BANGSTICK i
& itConsumption . laMax .~ i & itConsumption . laMax .~ i
& itConsumption . laLoadType .~ ActivePartial 10 1 NoTransfer & itConsumption . laCycle .~ [Insert 10 (Just 1)]
baseStickShapeX :: Int -> Shape baseStickShapeX :: Int -> Shape
baseStickShapeX i = foldMap f [0..i-1] baseStickShapeX i = foldMap f [0..i-1]
where where
@@ -108,7 +108,7 @@ revolver = pistol
& itConsumption .~ & itConsumption .~
(defaultBulletLoadable (defaultBulletLoadable
& laMax .~ 6 & laMax .~ 6
& laLoadType .~ ActivePartial 10 1 NoTransfer ) & laCycle .~ [Insert 10 (Just 1)] )
& itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> revolverClip it) & itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> revolverClip it)
& itType . iyBase .~ REVOLVER & itType . iyBase .~ REVOLVER
@@ -157,8 +157,7 @@ pistol :: Item
pistol = (bangStick 1) pistol = (bangStick 1)
& itConsumption .~ ( defaultBulletLoadable & itConsumption .~ ( defaultBulletLoadable
& laMax .~ 15 & laMax .~ 15
& laLoadType . ejectTime .~ 20 & laCycle .~ [Eject 5, Insert 5 Nothing, Prime 5] )
& laLoadType . insertTime .~ 20 )
& itUse .~ ruseAmmoParamsRate 6 upHammer (ammoHammerCheck : pistolAfterHamMods) & itUse .~ ruseAmmoParamsRate 6 upHammer (ammoHammerCheck : pistolAfterHamMods)
& itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> makeTinClipAt pi (V3 5 2 0) it) & itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> makeTinClipAt pi (V3 5 2 0) it)
& itParams %~ & itParams %~
+6 -12
View File
@@ -44,8 +44,7 @@ autoGun = defaultAutoGun
{ _laMax = 30 { _laMax = 30
, _laLoaded = 30 , _laLoaded = 30
} }
& laLoadType . ejectTime .~ 40 & laCycle .~ [Eject 30, Insert 30 Nothing, Prime 10]
& laLoadType . insertTime .~ 40
, _itUse = ruseAmmoParamsRate 4 NoHammer , _itUse = ruseAmmoParamsRate 4 NoHammer
[ ammoCheckI [ ammoCheckI
, charFiringStratI , charFiringStratI
@@ -132,8 +131,7 @@ bangCone = defaultBulletWeapon
} }
& itType . iyBase .~ BANGCONE & itType . iyBase .~ BANGCONE
& itConsumption . laMax .~ 5 & itConsumption . laMax .~ 5
& itConsumption . laLoadType . ejectTime .~ 10 & itConsumption . laCycle .~ [Eject 5, Insert 20 Nothing, Prime 5]
& itConsumption . laLoadType . insertTime .~ 10
coneRandItemUpdate :: State StdGen (Item -> Item) coneRandItemUpdate :: State StdGen (Item -> Item)
coneRandItemUpdate = do coneRandItemUpdate = do
wth <- state $ randomR (1,5) wth <- state $ randomR (1,5)
@@ -161,8 +159,7 @@ blunderbuss = bangCone
} }
} }
& itConsumption . laMax .~ 25 & itConsumption . laMax .~ 25
& itConsumption . laLoadType . ejectTime .~ 15 & itConsumption . laCycle .~ [Eject 5, Insert 30 Nothing, Prime 5]
& itConsumption . laLoadType . insertTime .~ 15
& itUse . useAim . aimStance .~ TwoHandTwist & itUse . useAim . aimStance .~ TwoHandTwist
& itUse . useAim . aimWeight .~ 6 & itUse . useAim . aimWeight .~ 6
& itType . iyBase .~ BLUNDERBUSS & itType . iyBase .~ BLUNDERBUSS
@@ -170,8 +167,7 @@ bigBlunderbuss :: Item
bigBlunderbuss = blunderbuss bigBlunderbuss = blunderbuss
& itType . iyBase .~ BIGBLUNDERBUSS & itType . iyBase .~ BIGBLUNDERBUSS
& itConsumption . laMax .~ 50 & itConsumption . laMax .~ 50
& itConsumption . laLoadType . ejectTime .~ 18 & itConsumption . laCycle .~ [Eject 5, Insert 40 Nothing, Prime 5]
& itConsumption . laLoadType . insertTime .~ 18
& itParams . recoil .~ 200 & itParams . recoil .~ 200
& itParams . torqueAfter .~ 0.3 & itParams . torqueAfter .~ 0.3
& itParams . randomOffset .~ 16 & itParams . randomOffset .~ 16
@@ -179,8 +175,7 @@ biggerBlunderbuss :: Item
biggerBlunderbuss = bigBlunderbuss biggerBlunderbuss = bigBlunderbuss
& itType . iyBase .~ BIGGERBLUNDERBUSS & itType . iyBase .~ BIGGERBLUNDERBUSS
& itConsumption . laMax .~ 75 & itConsumption . laMax .~ 75
& itConsumption . laLoadType . ejectTime .~ 20 & itConsumption . laCycle .~ [Eject 5, Insert 50 Nothing, Prime 5]
& itConsumption . laLoadType . insertTime .~ 20
& itParams . recoil .~ 250 & itParams . recoil .~ 250
& itParams . torqueAfter .~ 0.5 & itParams . torqueAfter .~ 0.5
& itParams . randomOffset .~ 20 & itParams . randomOffset .~ 20
@@ -188,8 +183,7 @@ biggestBlunderbuss :: Item
biggestBlunderbuss = biggerBlunderbuss biggestBlunderbuss = biggerBlunderbuss
& itType . iyBase .~ BIGGESTBLUNDERBUSS & itType . iyBase .~ BIGGESTBLUNDERBUSS
& itConsumption . laMax .~ 100 & itConsumption . laMax .~ 100
& itConsumption . laLoadType . ejectTime .~ 25 & itConsumption . laCycle .~ [Eject 5, Insert 60 Nothing, Prime 5]
& itConsumption . laLoadType . insertTime .~ 25
& itParams . recoil .~ 300 & itParams . recoil .~ 300
& itParams . torqueAfter .~ 0.7 & itParams . torqueAfter .~ 0.7
& itParams . randomOffset .~ 24 & itParams . randomOffset .~ 24
-2
View File
@@ -33,8 +33,6 @@ droneLauncher = defaultWeapon
} }
& itConsumption . laAmmoType .~ DroneAmmo { _amString = "LASDRONE" } & itConsumption . laAmmoType .~ DroneAmmo { _amString = "LASDRONE" }
& itConsumption . laMax .~ 2 & itConsumption . laMax .~ 2
& itConsumption . laLoadType . ejectTime .~ 40
& itConsumption . laLoadType . insertTime .~ 40
& itType . iyBase .~ DRONELAUNCHER & itType . iyBase .~ DRONELAUNCHER
lasDronesPic :: Item -> SPic lasDronesPic :: Item -> SPic
+1 -2
View File
@@ -44,8 +44,7 @@ launcher = defaultWeapon
} }
& laMax .~ 1 & laMax .~ 1
& laLoaded .~ 1 & laLoaded .~ 1
& laLoadType . ejectTime .~ 40 & laCycle .~ [Eject 30, Insert 30 Nothing, Prime 10]
& laLoadType . insertTime .~ 40
, _itUse = ruseRate 20 usePjCreation upHammer , _itUse = ruseRate 20 usePjCreation upHammer
[ hammerCheckI [ hammerCheckI
, ammoCheckI , ammoCheckI
+1 -2
View File
@@ -32,8 +32,7 @@ sonicGun :: Item
sonicGun = defaultAutoGun sonicGun = defaultAutoGun
{ _itConsumption = defaultLoadable { _itConsumption = defaultLoadable
& laMax .~ 10 & laMax .~ 10
& laLoadType . ejectTime .~ 40 & laCycle .~ [Eject 10, Insert 10 Nothing, Prime 60]
& laLoadType . insertTime .~ 40
, _itUse = ruseRate 8 aSonicWave (HasHammer HammerUp) , _itUse = ruseRate 8 aSonicWave (HasHammer HammerUp)
[ ammoHammerCheck [ ammoHammerCheck
, useTimeCheck , useTimeCheck
-3
View File
@@ -17,9 +17,6 @@ Creates a creature next to the creature using the item. -}
spawnGun :: Creature -> Item spawnGun :: Creature -> Item
spawnGun cr = defaultWeapon spawnGun cr = defaultWeapon
{ _itConsumption = defaultLoadable { _itConsumption = defaultLoadable
& laMax .~ 1
& laLoadType . ejectTime .~ 40
& laLoadType . insertTime .~ 40
, _itUse = ruseRate 100 , _itUse = ruseRate 100
(\_ -> spawnCrNextTo cr) (\_ -> spawnCrNextTo cr)
upHammer upHammer
+2 -4
View File
@@ -68,8 +68,7 @@ flameSpitter :: Item
flameSpitter = flameThrower flameSpitter = flameThrower
& itType . iyBase .~ FLAMESPITTER & itType . iyBase .~ FLAMESPITTER
& itConsumption . laMax .~ 10 & itConsumption . laMax .~ 10
& itConsumption . laLoadType . ejectTime .~ 10 & itConsumption . laCycle .~ [Eject 5, Insert 10 Nothing, Prime 20]
& itConsumption . laLoadType . insertTime .~ 10
& itParams . sprayNozzles . ix 0 . nzPressure .~ 4 & itParams . sprayNozzles . ix 0 . nzPressure .~ 4
& itUse . useAim . aimStance .~ OneHand & itUse . useAim . aimStance .~ OneHand
& itUse . useDelay .~ FixedRate {_rateMax =12,_rateTime = 0} & itUse . useDelay .~ FixedRate {_rateMax =12,_rateTime = 0}
@@ -123,8 +122,7 @@ flameThrower = defaultAutoGun
{_amString = "FLAME" {_amString = "FLAME"
,_amCreateGas = aFlame ,_amCreateGas = aFlame
} }
& laLoadType . ejectTime .~ 40 & laCycle .~ [Eject 5, Insert 10 Nothing, Prime 20]
& laLoadType . insertTime .~ 40
, _itUse = ruseInstant (overNozzles useGasParams) NoHammer , _itUse = ruseInstant (overNozzles useGasParams) NoHammer
[ ammoCheckI [ ammoCheckI
, useAmmoAmount 1 , useAmmoAmount 1
+5 -5
View File
@@ -173,15 +173,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 = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 1 repeatFire = _laProgress (_itConsumption item) == FinishedLoading && _rateTime (_useDelay (_itUse item)) == 1
firstFire = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 0 firstFire = _laProgress (_itConsumption item) == FinishedLoading && _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
| _loadProgress (_laLoadType $ _itConsumption item) /= NoTransfer = w | _laProgress (_itConsumption item) /= FinishedLoading = 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)
@@ -323,7 +323,7 @@ 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 = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer fireCondition = _laProgress (_itConsumption item) == FinishedLoading
&& _rateTime (_useDelay (_itUse item)) == 0 && _rateTime (_useDelay (_itUse item)) == 0
&& _laLoaded (_itConsumption item) > 0 && _laLoaded (_itConsumption item) > 0
-- reloadCondition = _laLoaded (_itConsumption item) == 0 -- reloadCondition = _laLoaded (_itConsumption item) == 0
@@ -359,7 +359,7 @@ shootL f item cr w
cid = _crID cr cid = _crID cr
invid = fromJust $ _itInvPos item invid = fromJust $ _itInvPos item
pointerToItem = creatures . ix cid . crInv . ix invid pointerToItem = creatures . ix cid . crInv . ix invid
fireCondition = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer fireCondition = _laProgress (_itConsumption item) == FinishedLoading
&& _rateTime (_useDelay (_itUse item)) == 0 && _rateTime (_useDelay (_itUse item)) == 0
&& _laLoaded (_itConsumption item) > 0 && _laLoaded (_itConsumption item) > 0
-- reloadCondition = _laLoaded (_itConsumption item) == 0 -- reloadCondition = _laLoaded (_itConsumption item) == 0
+20 -46
View File
@@ -11,41 +11,12 @@ import Dodge.Data
import Control.Lens import Control.Lens
import Data.Maybe import Data.Maybe
---- TODO clean this up, rethink datatypes
--icTryStartReloading :: Item -> Maybe Item
--icTryStartReloading it = do
-- am <- it ^? itConsumption
-- amloaded <- am ^? laLoaded
-- ammax <- am ^? laMax
-- rstate <- am ^? laReloadState
-- if amloaded < ammax && rstate == Nothing'
-- then Just $ it
-- & itConsumption . laReloadState .~ Just' (_laReloadTime am)
-- & if _laReloadType am == ActiveClear
-- then itConsumption . laLoaded .~ 0
-- else id
-- else Nothing
crStartReloading :: Creature -> World -> World crStartReloading :: Creature -> World -> World
crStartReloading cr = creatures . ix (_crID cr) . crStance . posture .~ Reloading crStartReloading cr = creatures . ix (_crID cr) . crStance . posture .~ Reloading
crStopReloading :: Creature -> Creature crStopReloading :: Creature -> Creature
crStopReloading cr = cr & crStance . posture .~ AtEase crStopReloading cr = cr & crStance . posture .~ AtEase
startInsertAmmo :: ItemConsumption -> ItemConsumption
startInsertAmmo ic = ic & laLoadType . loadProgress .~ Insert intime inamount
where
intime = _insertTime (_laLoadType ic)
inamount = maybe id min (ic ^? laLoadType . loadAmount) (_laMax ic - _laLoaded ic)
startEjectAmmo :: ItemConsumption -> ItemConsumption
startEjectAmmo ic = ic & laLoadType . loadProgress .~ Eject (_ejectTime $ _laLoadType ic)
loadAmmo :: Int -> ItemConsumption -> ItemConsumption
loadAmmo inamount ic = ic
& laLoaded +~ inamount
& laLoadType . loadProgress .~ NoTransfer
stepReloading :: Creature -> Creature stepReloading :: Creature -> Creature
stepReloading cr = case _posture (_crStance cr) of stepReloading cr = case _posture (_crStance cr) of
Reloading -> fromMaybe (cr & crStance . posture .~ AtEase) Reloading -> fromMaybe (cr & crStance . posture .~ AtEase)
@@ -53,23 +24,26 @@ stepReloading cr = case _posture (_crStance cr) of
_ -> cr _ -> cr
stepReloading' :: ItemConsumption -> Maybe ItemConsumption stepReloading' :: ItemConsumption -> Maybe ItemConsumption
stepReloading' ic = do stepReloading' ic = case _laProgress ic of
ltype <- ic ^? laLoadType FinishedLoading
lprog <- ltype ^? loadProgress | _laLoaded ic >= _laMax ic -> Nothing
case lprog of | otherwise -> Just $ ic & laProgress
Eject x .~ InProgress Nothing (map toLoadProgress (_laCycle ic))
| x > 0 -> Just $ ic & laLoadType . loadProgress . ejectProgress -~ 1 InProgress _ [] -> Just $ ic & laProgress .~ FinishedLoading
| otherwise -> Just $ ic & startInsertAmmo InProgress _ (a:_)
Insert x inamount | _actionProgress a > 0 -> Just $ ic & laProgress . futureActions . ix 0 . actionProgress -~ 1
| x > 0 -> Just $ ic & laLoadType . loadProgress . insertProgress -~ 1 | otherwise -> Just $ ic & doLoadAction (_actionType a)
| otherwise -> Just $ ic & loadAmmo inamount & laProgress . futureActions %~ tail
NoTransfer & laProgress . lastAction ?~ (_actionType a)
| _laLoaded ic >= _laMax ic
-> Nothing toLoadProgress :: LoadAction -> LoadActionProgress
| otherwise -> case ltype of toLoadProgress la = LoadActionProgress (_actionTime la) la
ActiveEject {} -> Just $ ic & startEjectAmmo
ActivePartial {} -> Just $ ic & startInsertAmmo doLoadAction :: LoadAction -> ItemConsumption -> ItemConsumption
_ -> Nothing doLoadAction la ic = case la of
Eject {} -> ic & laLoaded .~ 0
Insert {_insertMax = mx} -> ic & laLoaded +~ maybe id min mx (_laMax ic - _laLoaded ic)
Prime {} -> ic
--{- | Start reloading if clip is empty. -} --{- | Start reloading if clip is empty. -}
--crAutoReload :: Creature -> Creature --crAutoReload :: Creature -> Creature