Work towards adding external ammo sources

This commit is contained in:
2023-05-17 11:01:52 +01:00
parent 63c71c852d
commit 7df81559d9
30 changed files with 246 additions and 196 deletions
+20 -20
View File
@@ -18,7 +18,7 @@ crCancelReloading cr =
where
updateProgress = fromMaybe id $ do
InInventory (SelItem i _) <- cr ^? crManipulation . manObject
return $ crInv . ix i . itUse . heldConsumption . laProgress %~ const Nothing
return $ crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress %~ const Nothing
stepReloading :: Creature -> Creature
stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
@@ -27,14 +27,14 @@ stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
cr & crManipulation . manObject . inInventory . iselAction . actionProgress -~ 1
| otherwise ->
cr
& crInv . ix i . itUse . heldConsumption %~ doLoadAction la
& crInv . ix i . itUse . heldConsumption %~ rotateActionProgress
& crInv . ix i . itUse . heldConsumption . laSource . _InternalSource %~ doLoadAction la
& crInv . ix i . itUse . heldConsumption . laSource . _InternalSource %~ rotateActionProgress
& tryNextLoadAction
_ -> cr
tryNextLoadAction :: Creature -> Creature
tryNextLoadAction cr = case cr ^? crManipulation . manObject . inInventory of
Just (SelItem i _) -> case cr ^? crInv . ix i . itUse . heldConsumption . laProgress . _Just . ix 0 of
Just (SelItem i _) -> case cr ^? crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress . _Just . ix 0 of
Nothing -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
Just la ->
cr & crManipulation . manObject . inInventory . iselAction . actionProgress .~ _actionTime la
@@ -49,37 +49,37 @@ crToggleReloading cr = case cr ^? crManipulation . manObject . inInventory . ise
tryStartLoading :: Creature -> Creature
tryStartLoading cr = fromMaybe cr $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
hc <- cr ^? crInv . ix i . itUse . heldConsumption
hc <- cr ^? crInv . ix i . itUse . heldConsumption . laSource . _InternalSource
return $ startLoading hc cr
startLoading :: HeldConsumption -> Creature -> Creature
startLoading ic cr = case ic ^? laProgress . _Just . ix 0 of
startLoading :: InternalAmmo -> Creature -> Creature
startLoading ic cr = case ic ^? iaProgress . _Just . ix 0 of
Just la -> cr & startLoadingStep la
Nothing -> case ic ^? laCycle of
Nothing -> case ic ^? iaCycle of
Nothing -> cr
Just [] -> error "item has empty load cycle"
Just _ | _laLoaded ic >= _laMax ic -> cr
Just _ | _iaLoaded ic >= _iaMax ic -> cr
Just (la : las) -> fromMaybe (error "item loading error") $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
return $ cr & startLoadingStep la
& crInv . ix i . itUse . heldConsumption . laProgress ?~ (la : las)
& crInv . ix i . itUse . heldConsumption . laSource . _InternalSource . iaProgress ?~ (la : las)
startLoadingStep :: LoadAction -> Creature -> Creature
startLoadingStep la cr = cr & crManipulation . manObject . inInventory . iselAction .~ ReloadAction (_actionTime la) la
rotateActionProgress :: HeldConsumption -> HeldConsumption
rotateActionProgress ic = case ic ^? laProgress . _Just of
Just (_ : la : las) -> ic & laProgress . _Just .~ (la : las)
_ | _laLoaded ic < _laMax ic -> ic & laProgress ?~ _laCycle ic
_ -> ic & laProgress .~ Nothing
rotateActionProgress :: InternalAmmo -> InternalAmmo
rotateActionProgress ic = case ic ^? iaProgress . _Just of
Just (_ : la : las) -> ic & iaProgress . _Just .~ (la : las)
_ | _iaLoaded ic < _iaMax ic -> ic & iaProgress ?~ _iaCycle ic
_ -> ic & iaProgress .~ Nothing
doLoadAction :: LoadAction -> HeldConsumption -> HeldConsumption
doLoadAction :: LoadAction -> InternalAmmo -> InternalAmmo
doLoadAction la ic = case la of
LoadEject{} -> ic & laLoaded .~ 0 & laPrimed .~ False
LoadInsert{} -> ic & laLoaded .~ _laMax ic
LoadEject{} -> ic & iaLoaded .~ 0 & iaPrimed .~ False
LoadInsert{} -> ic & iaLoaded .~ _iaMax ic
LoadAdd{_insertMax = x} ->
ic & laLoaded +~ min x (_laMax ic - _laLoaded ic)
LoadPrime{} -> ic & laPrimed .~ True
ic & iaLoaded +~ min x (_iaMax ic - _iaLoaded ic)
LoadPrime{} -> ic & iaPrimed .~ True
--{- | Start reloading if clip is empty. -}
--crAutoReload :: Creature -> Creature