Partial removal of reloading

This commit is contained in:
2024-09-08 10:21:35 +01:00
parent 581d2494dc
commit e03c8dd830
16 changed files with 256 additions and 187 deletions
+86 -1
View File
@@ -1 +1,86 @@
All good (615 modules, at 22:22:36) /home/justin/Haskell/loop/src/Dodge/Creature/State.hs:26:1-22: warning: [-Wunused-imports]
The import of Dodge.Reloading is redundant
|
26 | import Dodge.Reloading
| ^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Creature/Impulse/UseItem.hs:20:1-22: warning: [-Wunused-imports]
The import of Dodge.Reloading is redundant
|
20 | import Dodge.Reloading
| ^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Creature/Impulse/UseItem.hs:118:5-14: warning: [-Wunused-local-binds]
Defined but not used: hammerTest
|
118 | hammerTest f = case _crHammerPosition cr of
| ^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Creature/Impulse/UseItem.hs:121:5-15: warning: [-Wunused-local-binds]
Defined but not used: setuhamdown
|
121 | setuhamdown = cWorld . lWorld . creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
| ^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Inventory.hs:28:1-22: warning: [-Wunused-imports]
The import of Dodge.Reloading is redundant
|
28 | import Dodge.Reloading
| ^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Item/Ammo.hs:7:1-29: warning: [-Wunused-imports]
The import of Dodge.Reloading.Action is redundant
|
7 | import Dodge.Reloading.Action
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Reloading/Action.hs:3:1-49: warning: [-Wunused-imports]
The import of Dodge.Data.Item.Use.Consumption.LoadAction is redundant
|
3 | import Dodge.Data.Item.Use.Consumption.LoadAction
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Reloading/Action.hs:4:1-49: warning: [-Wunused-imports]
The import of Dodge.SoundLogic.ExternallyGeneratedSounds is redundant
|
4 | import Dodge.SoundLogic.ExternallyGeneratedSounds
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/CreatureEffect.hs:(50,13)-(54,28): warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: CrIsReloading
|
50 | doCrBl cb = case cb of
| ^^^^^^^^^^...
/home/justin/Haskell/loop/src/Dodge/Creature/Statistics.hs:8:1-26: warning: [-Wunused-imports]
The import of Dodge.Creature.Test is redundant
|
8 | import Dodge.Creature.Test
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Item/Weapon/TriggerType.hs:72:1-22: warning: [-Wunused-imports]
The import of Dodge.Reloading is redundant
|
72 | import Dodge.Reloading
| ^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Projectile/Create.hs:4:1-22: warning: [-Wunused-imports]
The import of Dodge.Reloading is redundant
|
4 | import Dodge.Reloading
| ^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Reloading.hs:7:1-19: warning: [-Wunused-imports]
The import of Control.Lens is redundant
|
7 | import Control.Lens
| ^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Reloading.hs:8:1-17: warning: [-Wunused-imports]
The import of Data.Maybe is redundant
|
8 | import Data.Maybe
| ^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Reloading.hs:9:1-26: warning: [-Wunused-imports]
The import of Dodge.Data.Creature is redundant
|
9 | import Dodge.Data.Creature
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Reloading.hs:10:1-20: warning: [-Wunused-imports]
The import of Control.Monad is redundant
|
10 | import Control.Monad
| ^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Data/Item/Use/Consumption/LoadAction.hs:11:1-17: warning: [-Wunused-imports]
The import of Sound.Data is redundant
|
11 | import Sound.Data
| ^^^^^^^^^^^^^^^^^
+4 -2
View File
@@ -106,11 +106,13 @@ useItemLeftClick cr w = fromMaybe w $ do
invid <- cr ^? crManipulation . manObject . inInventory . ispItem invid <- cr ^? crManipulation . manObject . inInventory . ispItem
ituse <- cr ^? crInv . ix invid . itUse ituse <- cr ^? crInv . ix invid . itUse
case ituse of case ituse of
HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle) --HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle)
HeldUse{} -> return w
ConsumeUse{} -> return $ useItemRightClick cr w ConsumeUse{} -> return $ useItemRightClick cr w
EquipUse{} -> return $ useItemRightClick cr w EquipUse{} -> return $ useItemRightClick cr w
LeftUse{} -> return $ useItemRightClick cr w LeftUse{} -> return $ useItemRightClick cr w
AmmoMagUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle) AmmoMagUse{} -> return w
--AmmoMagUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle)
_ -> Nothing _ -> Nothing
where where
hammerTest f = case _crHammerPosition cr of hammerTest f = case _crHammerPosition cr of
+14 -14
View File
@@ -145,7 +145,7 @@ internalHammerUpdate :: Creature -> World -> World
internalHammerUpdate cr = internalHammerUpdate cr =
cWorld . lWorld . creatures . ix (_crID cr) cWorld . lWorld . creatures . ix (_crID cr)
%~ ( (crHammerPosition %~ moveHammerUp) %~ ( (crHammerPosition %~ moveHammerUp)
. stepReloading -- . stepReloading
. updateMovement . updateMovement
) )
@@ -233,7 +233,7 @@ equipmentEffects cr = flip (foldl' $ flip $ useEquipment cr) (IM.keys $ _crInvEq
invSideEff :: Creature -> World -> World invSideEff :: Creature -> World -> World
invSideEff cr w = invSideEff cr w =
updateTargeting (crGetTargeting cr) cr $ updateTargeting (crGetTargeting cr) cr $
weaponReloadSounds cr $ -- weaponReloadSounds cr $
IM.foldl' f w (_crInv cr) IM.foldl' f w (_crInv cr)
where where
-- be careful with side effects that affect creature targeting -- be careful with side effects that affect creature targeting
@@ -288,18 +288,18 @@ crGetTargeting cr = do
guard (canAttachTargeting tt itm) guard (canAttachTargeting tt itm)
return tt return tt
weaponReloadSounds :: Creature -> World -> World --weaponReloadSounds :: Creature -> World -> World
weaponReloadSounds cr w = case cr ^? crManipulation . manObject . inInventory . iselAction of --weaponReloadSounds cr w = case cr ^? crManipulation . manObject . inInventory . iselAction of
Just ReloadAction{_reloadAction = la} -> -- Just ReloadAction{_reloadAction = la} ->
soundContinue -- soundContinue
(CrReloadSound cid) -- (CrReloadSound cid)
(_crPos cr) -- (_crPos cr)
(_actionSound la) -- (_actionSound la)
(Just 1) -- (Just 1)
w -- w
_ -> w -- _ -> w
where -- where
cid = _crID cr -- cid = _crID cr
updateMovement :: Creature -> Creature updateMovement :: Creature -> Creature
updateMovement cr updateMovement cr
+2 -1
View File
@@ -36,7 +36,8 @@ crCurrentEquipment cr =
strFromHeldItem :: Creature -> Int strFromHeldItem :: Creature -> Int
strFromHeldItem cr strFromHeldItem cr
| _posture (_crStance cr) == Aiming || crIsReloading cr = negate $ fromMaybe 0 $ do --x--- | _posture (_crStance cr) == Aiming || crIsReloading cr = negate $ fromMaybe 0 $ do
| _posture (_crStance cr) == Aiming = negate $ fromMaybe 0 $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem i <- cr ^? crManipulation . manObject . inInventory . ispItem
cr ^? crInv . ix i . itUse . heldAim . aimWeight cr ^? crInv . ix i . itUse . heldAim . aimWeight
| otherwise = 0 | otherwise = 0
+5 -5
View File
@@ -7,7 +7,7 @@ in fact a creature with that id need not exist.
-} -}
module Dodge.Creature.Test ( module Dodge.Creature.Test (
crIsAiming, crIsAiming,
crIsReloading, -- crIsReloading,
crIsArmouredFrom, crIsArmouredFrom,
oneH, oneH,
twists, twists,
@@ -33,10 +33,10 @@ import Dodge.Base.Collide
import Dodge.Data.World import Dodge.Data.World
import Geometry import Geometry
crIsReloading :: Creature -> Bool --crIsReloading :: Creature -> Bool
crIsReloading cr = case cr ^? crManipulation . manObject . inInventory . iselAction of --crIsReloading cr = case cr ^? crManipulation . manObject . inInventory . iselAction of
Just ReloadAction{} -> True -- Just ReloadAction{} -> True
_ -> False -- _ -> False
-- Assumes the ammotype below the selected item is correct -- Assumes the ammotype below the selected item is correct
crWeaponReady :: Creature -> Bool crWeaponReady :: Creature -> Bool
+1 -1
View File
@@ -49,7 +49,7 @@ doWdCrBl wcb = case wcb of
doCrBl :: CrBl -> Creature -> Bool doCrBl :: CrBl -> Creature -> Bool
doCrBl cb = case cb of doCrBl cb = case cb of
CrCanShoot -> crCanShoot CrCanShoot -> crCanShoot
CrIsReloading -> crIsReloading -- CrIsReloading -> crIsReloading
CrIsAiming -> crIsAiming CrIsAiming -> crIsAiming
CrIsAnimate -> isAnimate CrIsAnimate -> isAnimate
+1 -3
View File
@@ -20,9 +20,7 @@ import Dodge.Data.Item.Use.Consumption.LoadAction
data ReloadStatus = ReloadStatus data ReloadStatus = ReloadStatus
{ _iaMax :: Int { _iaMax :: Int
, _iaLoaded :: Int , _iaLoaded :: Int
, _iaPrimed :: Bool -- , _iaPrimed :: Bool
, _iaCycle :: [LoadAction]
, _iaProgress :: Maybe [LoadAction]
} }
deriving (Eq, Show, Read) --Generic, Flat) deriving (Eq, Show, Read) --Generic, Flat)
@@ -10,13 +10,6 @@ import Data.Aeson
import Data.Aeson.TH import Data.Aeson.TH
import Sound.Data import Sound.Data
data LoadAction
= LoadEject {_actionTime :: Int, _actionSound :: SoundID}
| LoadInsert {_actionTime :: Int, _actionSound :: SoundID}
| LoadAdd {_actionTime :: Int, _actionSound :: SoundID, _insertMax :: Int}
| LoadPrime {_actionTime :: Int, _actionSound :: SoundID}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data Manipulation -- should be ManipulatedObject? data Manipulation -- should be ManipulatedObject?
-- = InvSel {_isel :: SelPos} -- = InvSel {_isel :: SelPos}
= Manipulator {_manObject :: ManipulatedObject = Manipulator {_manObject :: ManipulatedObject
@@ -42,16 +35,13 @@ data InventoryManipulation
data InvSelAction data InvSelAction
= NoInvSelAction = NoInvSelAction
| ReloadAction {_actionProgress :: Int, _reloadAction :: LoadAction, _reloadInvID :: Int}
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''LoadAction
makeLenses ''ManipulatedObject makeLenses ''ManipulatedObject
makeLenses ''Manipulation makeLenses ''Manipulation
makeLenses ''InventoryManipulation makeLenses ''InventoryManipulation
makeLenses ''NearbyManipulation makeLenses ''NearbyManipulation
makeLenses ''InvSelAction makeLenses ''InvSelAction
deriveJSON defaultOptions ''LoadAction
deriveJSON defaultOptions ''InvSelAction deriveJSON defaultOptions ''InvSelAction
deriveJSON defaultOptions ''InventoryManipulation deriveJSON defaultOptions ''InventoryManipulation
deriveJSON defaultOptions ''NearbyManipulation deriveJSON defaultOptions ''NearbyManipulation
+1 -1
View File
@@ -50,7 +50,7 @@ rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount
& worldEventFlags . at InventoryChange ?~ () & worldEventFlags . at InventoryChange ?~ ()
_ -> _ ->
w w
& pointcid %~ crCancelReloading -- & pointcid %~ crCancelReloading
& doanyitemeffect & doanyitemeffect
& dounequipfunction --the ordering of these is & dounequipfunction --the ordering of these is
& pointcid . crInv %~ f -- important & pointcid . crInv %~ f -- important
-10
View File
@@ -19,9 +19,6 @@ tinMag =
ReloadStatus ReloadStatus
{ _iaMax = 15 { _iaMax = 15
, _iaLoaded = 15 , _iaLoaded = 15
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
} }
} }
@@ -31,7 +28,6 @@ revolveMag =
& itType . iyBase .~ AMMOMAG REVOLVEMAG & itType . iyBase .~ AMMOMAG REVOLVEMAG
& itUse . amagLoadStatus . iaMax .~ 6 & itUse . amagLoadStatus . iaMax .~ 6
& itUse . amagLoadStatus . iaLoaded .~ 6 & itUse . amagLoadStatus . iaLoaded .~ 6
& itUse . amagLoadStatus . iaCycle .~ [loadPartialInsert 10 1]
drumMag :: Item drumMag :: Item
drumMag = drumMag =
@@ -59,9 +55,6 @@ shellMag =
ReloadStatus ReloadStatus
{ _iaMax = 1 { _iaMax = 1
, _iaLoaded = 1 , _iaLoaded = 1
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
} }
, _amagType = ProjectileAmmo , _amagType = ProjectileAmmo
} }
@@ -77,8 +70,5 @@ battery =
ReloadStatus ReloadStatus
{ _iaMax = 100 { _iaMax = 100
, _iaLoaded = 100 , _iaLoaded = 100
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
} }
} }
+19 -16
View File
@@ -123,8 +123,8 @@ itemNumberDisplay cr itm = case iu of
EquipUse{} -> showEquipmentNumber cr itm EquipUse{} -> showEquipmentNumber cr itm
CraftUse x -> [show $ x ^. getItAmount] CraftUse x -> [show $ x ^. getItAmount]
ConsumeUse {_useAmount = x} -> [show $ x ^. getItAmount] ConsumeUse {_useAmount = x} -> [show $ x ^. getItAmount]
AttachUse {} -> [showReloadProgress cr itm] AttachUse {} -> [] --[showReloadProgress cr itm]
AmmoMagUse {} -> [showReloadProgress cr itm] AmmoMagUse {} -> [showLoadedAmount itm]
-- this could be cleaner here... -- this could be cleaner here...
where where
iu = itm ^?! itUse iu = itm ^?! itUse
@@ -152,12 +152,15 @@ showEquipmentNumber _ itm = case _eeUse ee of
-- ) -- )
-- <|> Just [x] -- <|> Just [x]
showReloadProgress :: Creature -> Item -> String showLoadedAmount :: Item -> String
showReloadProgress _ itm = fromMaybe [] $ do showLoadedAmount itm = fromMaybe [] $ fmap show $ itm ^? itUse . amagLoadStatus . iaLoaded
ia <- itm ^? itUse . amagLoadStatus
return $ case ia ^? iaProgress . _Just . ix 0 of --showReloadProgress :: Creature -> Item -> String
Nothing -> maybe "" show $ ia ^? iaLoaded --showReloadProgress _ itm = fromMaybe [] $ do
Just la -> showLoadActionType la ia -- ia <- itm ^? itUse . amagLoadStatus
-- return $ case ia ^? iaProgress . _Just . ix 0 of
-- Nothing -> maybe "" show $ ia ^? iaLoaded
-- Just la -> showLoadActionType la ia
--showReloadProgress :: Creature -> Item -> String --showReloadProgress :: Creature -> Item -> String
--showReloadProgress cr itm = case ic ^? laSource of --showReloadProgress cr itm = case ic ^? laSource of
-- Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of -- Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of
@@ -171,14 +174,14 @@ showReloadProgress _ itm = fromMaybe [] $ do
-- where -- where
-- ic = itm ^?! itUse . heldConsumption -- ic = itm ^?! itUse . heldConsumption
showLoadActionType :: LoadAction -> ReloadStatus -> String --showLoadActionType :: LoadAction -> ReloadStatus -> String
showLoadActionType la as = case la of --showLoadActionType la as = case la of
LoadEject{} -> "E" -- LoadEject{} -> "E"
LoadInsert{} -> "L" -- LoadInsert{} -> "L"
LoadAdd{} -> "A" ++ x -- LoadAdd{} -> "A" ++ x
LoadPrime{} -> "P" -- LoadPrime{} -> "P"
where -- where
x = maybe "" show $ as ^? iaLoaded -- x = maybe "" show $ as ^? iaLoaded
maybeWarmupStatus :: Item -> Maybe String maybeWarmupStatus :: Item -> Maybe String
maybeWarmupStatus it = case it ^? itUse . heldDelay . warmMax of maybeWarmupStatus it = case it ^? itUse . heldDelay . warmMax of
+1 -1
View File
@@ -148,7 +148,7 @@ ammoCheckI eff ams itm cr w = fromMaybe (failsound w) $ do
matype <- ams ^? ix 0 . itUse . amagType matype <- ams ^? ix 0 . itUse . amagType
iatype <- itm ^? itUse . heldConsumption . ix 0 iatype <- itm ^? itUse . heldConsumption . ix 0
guard $ matype == iatype guard $ matype == iatype
return $ eff ams itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading return $ eff ams itm cr $ w -- & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
where where
failsound = case w ^? input . mouseButtons . ix SDL.ButtonLeft of failsound = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
Just 0 -> soundStart (CrReloadSound (_crID cr)) (_crPos cr) click1S Nothing Just 0 -> soundStart (CrReloadSound (_crID cr)) (_crPos cr) click1S Nothing
+3 -2
View File
@@ -22,10 +22,11 @@ createProjectile ammoitem muz itm cr = fromMaybe failsound $ do
CreateShell -> fireShell ammoitem muz itm cr . extrafuncs j CreateShell -> fireShell ammoitem muz itm cr . extrafuncs j
CreateTrackingShell -> fireTrackingShell ammoitem muz itm cr . extrafuncs j CreateTrackingShell -> fireTrackingShell ammoitem muz itm cr . extrafuncs j
where where
extrafuncs j = cancelanyreloading . startthesound . useammo j --extrafuncs j = cancelanyreloading . startthesound . useammo j
extrafuncs j = startthesound . useammo j
useammo j = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix j . itUse . amagLoadStatus . iaLoaded -~ 1 useammo j = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix j . itUse . amagLoadStatus . iaLoaded -~ 1
cancelanyreloading = cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading --cancelanyreloading = cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
-- the sound should be moved to the projectile firing -- the sound should be moved to the projectile firing
startthesound = soundMultiFrom [CrWeaponSound (_crID cr) j | j <- [0..3]] (_crPos cr) tap4S Nothing startthesound = soundMultiFrom [CrWeaponSound (_crID cr) j | j <- [0..3]] (_crPos cr) tap4S Nothing
failsound w' = case w' ^? input . mouseButtons . ix SDL.ButtonLeft of failsound w' = case w' ^? input . mouseButtons . ix SDL.ButtonLeft of
+107 -107
View File
@@ -1,7 +1,7 @@
module Dodge.Reloading ( module Dodge.Reloading (
crCancelReloading, -- crCancelReloading,
crReloadToggle, -- crReloadToggle,
stepReloading, -- stepReloading,
) where ) where
import Control.Lens import Control.Lens
@@ -10,108 +10,108 @@ import Dodge.Data.Creature
import Control.Monad import Control.Monad
--import Data.Monoid --import Data.Monoid
crCancelReloading :: Creature -> Creature ----crCancelReloading :: Creature -> Creature
crCancelReloading cr = --crCancelReloading cr =
cr -- cr
& updateProgress -- & updateProgress
& crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction -- & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
where
updateProgress = fromMaybe id $ do
InInventory (SelItem i _) <- cr ^? crManipulation . manObject
return $
crInv . ix (i + 1) . itUse . amagLoadStatus . iaProgress
%~ const Nothing
stepReloading :: Creature -> Creature
stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
Just (SelItem _ (ReloadAction x la j))
| x > 0 ->
cr & crManipulation . manObject . inInventory . iselAction . actionProgress -~ 1
| otherwise ->
cr
& crInv . ix j . itUse . amagLoadStatus %~ doLoadAction la
& crInv . ix j . itUse . amagLoadStatus %~ rotateActionProgress
& tryNextLoadAction
_ -> cr
tryNextLoadAction :: Creature -> Creature
tryNextLoadAction cr = case cr ^? crManipulation . manObject . inInventory of
Just (SelItem i _) -> case cr ^? crInv . ix (i + 1) . itUse . amagLoadStatus . iaProgress . _Just . ix 0 of
Nothing -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
Just la ->
cr & crManipulation . manObject . inInventory . iselAction . actionProgress .~ _actionTime la
& crManipulation . manObject . inInventory . iselAction . reloadAction .~ la
_ -> cr
crReloadToggle :: Creature -> Creature
crReloadToggle cr = case cr ^? crManipulation . manObject . inInventory . iselAction of
Just NoInvSelAction -> cr & tryStartLoading
_ -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
tryStartLoading :: Creature -> Creature
tryStartLoading cr = fromMaybe cr $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
magtypes <- cr ^? crInv . ix i . itUse . heldConsumption
--let mags = cr ^.. crInv . dropping (i + 1) traverse -- note this gets all items below the manipulated
let mags = cr ^.. crInv . dropping i traverse
iaj <- listToMaybe . catMaybes $ zipWith tryStartLoadMagazine mags magtypes
return $ startLoading iaj cr
tryStartLoadMagazine :: Item -> AmmoType -> Maybe (ReloadStatus, Int)
tryStartLoadMagazine mag atype = do
magat <- mag ^? itUse . amagType
guard $ magat == atype
ia <- mag ^? itUse . amagLoadStatus
maxammo <- ia ^? iaMax
loadedammo <- ia ^? iaLoaded
guard $ loadedammo < maxammo
j <- mag ^? itLocation . ipInvID
return (ia, j)
-- case as of
-- InternalSource ia -> return $ startLoading ia cr
-- AboveSource -> return cr
startLoading :: (ReloadStatus,Int) -> Creature -> Creature
startLoading (ic,j) cr = case ic ^? iaProgress . _Just . ix 0 of
Just la -> cr & startLoadingStep la j
Nothing -> case ic ^. iaCycle of
[] -> error "item has empty load cycle"
_ | _iaLoaded ic >= _iaMax ic -> cr -- THIS SHOULD TRY PUSHING TO THE NEXT MAGAZINE
(la : las) -> fromMaybe (error "item loading error") $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
return $
cr & startLoadingStep la i
& crInv . ix i . itUse . amagLoadStatus . iaProgress ?~ (la : las)
startLoadingStep :: LoadAction
-> Int -- i think this is the inventory position?
-> Creature -> Creature
startLoadingStep la j cr = cr & crManipulation . manObject . inInventory . iselAction .~ ReloadAction (_actionTime la) la j
rotateActionProgress :: ReloadStatus -> ReloadStatus
rotateActionProgress ic = case ic ^. iaProgress of
Just (_ : la : las) -> ic & iaProgress . _Just .~ (la : las)
_ | _iaLoaded ic < _iaMax ic -> ic & iaProgress ?~ _iaCycle ic
_ -> ic & iaProgress .~ Nothing
doLoadAction :: LoadAction -> ReloadStatus -> ReloadStatus
doLoadAction la ic = case la of
LoadEject{} -> ic & iaLoaded .~ 0 & iaPrimed .~ False
LoadInsert{} -> ic & iaLoaded .~ _iaMax ic
LoadAdd{_insertMax = x} ->
ic & iaLoaded +~ min x (_iaMax ic - _iaLoaded ic)
LoadPrime{} -> ic & iaPrimed .~ True
--{- | Start reloading if clip is empty. -}
--crAutoReload :: Creature -> Creature
--crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of
-- Just 0 | _posture (_crStance cr) /= Aiming
-- -> cr & ptrItConsumption . reloadState .~ strictify reloadT
-- & ptrItConsumption . ammoLoaded %~ (`fromMaybe` maxA)
-- _ -> cr
-- where -- where
-- ptrItConsumption = crInv . ix (_crInvSel cr) . itConsumption -- updateProgress = fromMaybe id $ do
-- ptrItConsumption' = crInv . ix (_crInvSel cr) . itConsumption -- InInventory (SelItem i _) <- cr ^? crManipulation . manObject
-- reloadT = cr ^? ptrItConsumption' . reloadTime -- return $
-- maxA = fmap itMaxAmmo $ cr ^? crInv . ix (_crInvSel cr) -- crInv . ix (i + 1) . itUse . amagLoadStatus . iaProgress
-- %~ const Nothing
--
--stepReloading :: Creature -> Creature
--stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
-- Just (SelItem _ (ReloadAction x la j))
-- | x > 0 ->
-- cr & crManipulation . manObject . inInventory . iselAction . actionProgress -~ 1
-- | otherwise ->
-- cr
-- & crInv . ix j . itUse . amagLoadStatus %~ doLoadAction la
-- & crInv . ix j . itUse . amagLoadStatus %~ rotateActionProgress
-- & tryNextLoadAction
-- _ -> cr
--
--tryNextLoadAction :: Creature -> Creature
--tryNextLoadAction cr = case cr ^? crManipulation . manObject . inInventory of
-- Just (SelItem i _) -> case cr ^? crInv . ix (i + 1) . itUse . amagLoadStatus . iaProgress . _Just . ix 0 of
-- Nothing -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
-- Just la ->
-- cr & crManipulation . manObject . inInventory . iselAction . actionProgress .~ _actionTime la
-- & crManipulation . manObject . inInventory . iselAction . reloadAction .~ la
-- _ -> cr
--
--crReloadToggle :: Creature -> Creature
--crReloadToggle cr = case cr ^? crManipulation . manObject . inInventory . iselAction of
-- Just NoInvSelAction -> cr & tryStartLoading
-- _ -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
--
--tryStartLoading :: Creature -> Creature
--tryStartLoading cr = fromMaybe cr $ do
-- i <- cr ^? crManipulation . manObject . inInventory . ispItem
-- magtypes <- cr ^? crInv . ix i . itUse . heldConsumption
-- --let mags = cr ^.. crInv . dropping (i + 1) traverse -- note this gets all items below the manipulated
-- let mags = cr ^.. crInv . dropping i traverse
-- iaj <- listToMaybe . catMaybes $ zipWith tryStartLoadMagazine mags magtypes
-- return $ startLoading iaj cr
--
--tryStartLoadMagazine :: Item -> AmmoType -> Maybe (ReloadStatus, Int)
--tryStartLoadMagazine mag atype = do
-- magat <- mag ^? itUse . amagType
-- guard $ magat == atype
-- ia <- mag ^? itUse . amagLoadStatus
-- maxammo <- ia ^? iaMax
-- loadedammo <- ia ^? iaLoaded
-- guard $ loadedammo < maxammo
-- j <- mag ^? itLocation . ipInvID
-- return (ia, j)
--
---- case as of
---- InternalSource ia -> return $ startLoading ia cr
---- AboveSource -> return cr
--
--startLoading :: (ReloadStatus,Int) -> Creature -> Creature
--startLoading (ic,j) cr = case ic ^? iaProgress . _Just . ix 0 of
-- Just la -> cr & startLoadingStep la j
-- Nothing -> case ic ^. iaCycle of
-- [] -> error "item has empty load cycle"
-- _ | _iaLoaded ic >= _iaMax ic -> cr -- THIS SHOULD TRY PUSHING TO THE NEXT MAGAZINE
-- (la : las) -> fromMaybe (error "item loading error") $ do
-- i <- cr ^? crManipulation . manObject . inInventory . ispItem
-- return $
-- cr & startLoadingStep la i
-- & crInv . ix i . itUse . amagLoadStatus . iaProgress ?~ (la : las)
--
--startLoadingStep :: LoadAction
-- -> Int -- i think this is the inventory position?
-- -> Creature -> Creature
--startLoadingStep la j cr = cr & crManipulation . manObject . inInventory . iselAction .~ ReloadAction (_actionTime la) la j
--
--rotateActionProgress :: ReloadStatus -> ReloadStatus
--rotateActionProgress ic = case ic ^. iaProgress of
-- Just (_ : la : las) -> ic & iaProgress . _Just .~ (la : las)
-- _ | _iaLoaded ic < _iaMax ic -> ic & iaProgress ?~ _iaCycle ic
-- _ -> ic & iaProgress .~ Nothing
--
--doLoadAction :: LoadAction -> ReloadStatus -> ReloadStatus
--doLoadAction la ic = case la of
-- LoadEject{} -> ic & iaLoaded .~ 0 & iaPrimed .~ False
-- LoadInsert{} -> ic & iaLoaded .~ _iaMax ic
-- LoadAdd{_insertMax = x} ->
-- ic & iaLoaded +~ min x (_iaMax ic - _iaLoaded ic)
-- LoadPrime{} -> ic & iaPrimed .~ True
--
----{- | Start reloading if clip is empty. -}
----crAutoReload :: Creature -> Creature
----crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of
---- Just 0 | _posture (_crStance cr) /= Aiming
---- -> 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' . reloadTime
---- maxA = fmap itMaxAmmo $ cr ^? crInv . ix (_crInvSel cr)
+11 -11
View File
@@ -3,14 +3,14 @@ module Dodge.Reloading.Action where
import Dodge.Data.Item.Use.Consumption.LoadAction import Dodge.Data.Item.Use.Consumption.LoadAction
import Dodge.SoundLogic.ExternallyGeneratedSounds import Dodge.SoundLogic.ExternallyGeneratedSounds
loadInsert :: Int -> LoadAction --loadInsert :: Int -> LoadAction
loadInsert x = LoadInsert x insertS --loadInsert x = LoadInsert x insertS
--
loadPartialInsert :: Int -> Int -> LoadAction --loadPartialInsert :: Int -> Int -> LoadAction
loadPartialInsert x = LoadAdd x insertOneS --loadPartialInsert x = LoadAdd x insertOneS
--
loadEject :: Int -> LoadAction --loadEject :: Int -> LoadAction
loadEject x = LoadEject x ejectS --loadEject x = LoadEject x ejectS
--
loadPrime :: Int -> LoadAction --loadPrime :: Int -> LoadAction
loadPrime x = LoadPrime x primeS --loadPrime x = LoadPrime x primeS
+1 -2
View File
@@ -19,7 +19,6 @@ import Dodge.InputFocus
import Dodge.Inventory import Dodge.Inventory
import Dodge.Inventory.Add import Dodge.Inventory.Add
import Dodge.Menu import Dodge.Menu
import Dodge.Reloading
import Dodge.Save import Dodge.Save
import Dodge.SelectionSections import Dodge.SelectionSections
import Dodge.Terminal.LeftButton import Dodge.Terminal.LeftButton
@@ -116,7 +115,7 @@ updateInitialPressInGame uv sc = case sc of
ScancodeP -> pauseGame uv ScancodeP -> pauseGame uv
ScancodeF -> over uvWorld youDropItem uv ScancodeF -> over uvWorld youDropItem uv
ScancodeM -> toggleMap uv ScancodeM -> toggleMap uv
ScancodeR -> over (uvWorld . cWorld . lWorld . creatures . ix 0) crReloadToggle uv -- ScancodeR -> over (uvWorld . cWorld . lWorld . creatures . ix 0) crReloadToggle uv
ScancodeT -> over uvWorld testEvent uv ScancodeT -> over uvWorld testEvent uv
ScancodeX -> uv & uvWorld %~ toggleTweakInv ScancodeX -> uv & uvWorld %~ toggleTweakInv
ScancodeC -> toggleCombineInv uv ScancodeC -> toggleCombineInv uv