Remove old ammo code, add magazines to some test loadouts

This commit is contained in:
2024-06-21 23:24:26 +01:00
parent ecefba21d6
commit 944b40cb56
12 changed files with 182 additions and 165 deletions
+11
View File
@@ -22,6 +22,7 @@ module Dodge.Creature (
module Dodge.Creature.YourControl,
) where
import Dodge.Item.Ammo
import Dodge.Item.Scope
import Control.Lens
import Dodge.Creature.Action
@@ -124,8 +125,11 @@ inventoryX c = case c of
, wristArmour
, wristArmour
, autoRifle
, tinMag
, smg
, tinMag
, machinePistol
, tinMag
, makeTypeCraftNum 4 MICROCHIP
, makeTypeCraftNum 2 TIN
, makeTypeCraftNum 2 HARDWARE
@@ -174,7 +178,9 @@ inventoryX c = case c of
]
'G' ->
[ autoPistol
, tinMag
, pistol
, tinMag
, makeTypeCraftNum 2 HARDWARE
, makeTypeCraftNum 2 MAGNET
, makeTypeCraftNum 5 (ENERGYBALLCRAFT IncBall)
@@ -199,6 +205,7 @@ inventoryX c = case c of
]
'K' ->
[ autoRifle
, tinMag
, targetingHat TargetRBPress
, makeTypeCraftNum 7 MICROCHIP
, makeTypeCraftNum 4 HARDWARE
@@ -246,16 +253,20 @@ testInventory =
stackedInventory :: [Item]
stackedInventory =
[ burstRifle
, tinMag
, pipe
, scrollWatch
, rewindWatch
, stopWatch
, tractorGun
, autoPistol
, tinMag
, pistol
, tinMag
, teslaGun
, blinkGun
, miniGunX 3
, beltMag
, boosterGun
, remoteLauncher
, flatShield
+1 -1
View File
@@ -174,7 +174,7 @@ reloadOverride :: Creature -> Creature
reloadOverride cr = fromMaybe cr $ do
guard $ cr ^. crStance . posture == Aiming
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
guard $ cr ^? crInv . ix (itRef + 1) . itUse . attachParams . ammoAttachParams . iaLoaded == Just 0
guard $ cr ^? crInv . ix (itRef + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded == Just 0
return $ cr & crActionPlan . apStrategy .~ StrategyActions Reload reloadActions
where
reloadActions =
+1 -1
View File
@@ -42,7 +42,7 @@ crIsReloading cr = case cr ^? crManipulation . manObject . inInventory . iselAct
crWeaponReady :: Creature -> Bool
crWeaponReady cr = fromMaybe False $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
x <- cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoAttachParams . iaLoaded
x <- cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded
return (x > 0)
crCanSeeCr :: Creature -> (World, Creature) -> Bool
+8 -1
View File
@@ -58,9 +58,14 @@ data ItemUse
data AttachParams
= ScrollAttachParams {_scrollAttachParams :: ScrollAttachParams}
| AmmoAttachParams {_ammoAttachParams :: InternalAmmo}
| AmmoAttachParams
{_ammoLoadStatus :: InternalAmmo
,_ammoParams :: AmmoParams
}
| TargetAttachParams
data AmmoParams = DefaultAmmoParams
data ScrollAttachParams
= ZoomScrollParams
{ -- | a camera offset
@@ -123,6 +128,8 @@ makeLenses ''ItZoom
makeLenses ''Muzzle
makeLenses ''AttachParams
makeLenses ''ScrollAttachParams
makeLenses ''AmmoParams
deriveJSON defaultOptions ''AmmoParams
deriveJSON defaultOptions ''Muzzle
deriveJSON defaultOptions ''AimStance
deriveJSON defaultOptions ''ScrollAttachParams
-5
View File
@@ -32,11 +32,6 @@ data AmmoSource
| EitherSource
deriving (Eq, Show, Read) --Generic, Flat)
data ExternalSourceType = BulletClip
| BulletBelt
| ElectricPower
deriving (Eq, Show, Read) --Generic, Flat)
data InternalAmmo = InternalAmmo
{ _iaMax :: Int
, _iaLoaded :: Int
@@ -42,7 +42,6 @@ data InventoryManipulation
data InvSelAction
= NoInvSelAction
| AttachLoadSourceAction {_actionProgress :: Int}
| ReloadAction {_actionProgress :: Int, _reloadAction :: LoadAction}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
+41 -25
View File
@@ -1,38 +1,54 @@
module Dodge.Item.Ammo where
import Dodge.Reloading.Action
import Control.Lens
import Dodge.Data.World
import Dodge.Default.Item
import Dodge.Reloading.Action
revolveMag :: Item
revolveMag = defaultHeldItem & itType . iyBase .~ ATTACH (AMMOATTACH REVOLVEMAG)
& itUse .~ AttachUse {_attachParams = AmmoAttachParams {_ammoAttachParams = InternalAmmo
{ _iaMax = 6
, _iaLoaded = 6
, _iaPrimed = True
, _iaCycle = [loadPartialInsert 10 1]
, _iaProgress = Nothing
}
}
}
revolveMag =
defaultHeldItem & itType . iyBase .~ ATTACH (AMMOATTACH REVOLVEMAG)
& itUse
.~ AttachUse
{ _attachParams =
AmmoAttachParams
{ _ammoParams = DefaultAmmoParams
, _ammoLoadStatus =
InternalAmmo
{ _iaMax = 6
, _iaLoaded = 6
, _iaPrimed = True
, _iaCycle = [loadPartialInsert 10 1]
, _iaProgress = Nothing
}
}
}
tinMag :: Item
tinMag = defaultHeldItem & itType . iyBase .~ ATTACH (AMMOATTACH TINMAG)
& itUse .~ AttachUse {_attachParams = AmmoAttachParams {_ammoAttachParams = InternalAmmo
{ _iaMax = 15
, _iaLoaded = 15
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
}
}
}
tinMag =
defaultHeldItem & itType . iyBase .~ ATTACH (AMMOATTACH TINMAG)
& itUse
.~ AttachUse
{ _attachParams =
AmmoAttachParams
{ _ammoParams = DefaultAmmoParams
, _ammoLoadStatus =
InternalAmmo
{ _iaMax = 15
, _iaLoaded = 15
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
}
}
}
drumMag :: Item
drumMag = tinMag & itType . iyBase .~ ATTACH (AMMOATTACH DRUMMAG)
& itUse . attachParams . ammoAttachParams . iaMax .~ 30
drumMag =
tinMag & itType . iyBase .~ ATTACH (AMMOATTACH DRUMMAG)
& itUse . attachParams . ammoLoadStatus . iaMax .~ 30
beltMag :: Item
beltMag = tinMag & itType . iyBase .~ ATTACH (AMMOATTACH BULLETBELT)
beltMag =
tinMag & itType . iyBase .~ ATTACH (AMMOATTACH BULLETBELT)
& itUse . attachParams . ammoLoadStatus . iaMax .~ 2000
+1 -1
View File
@@ -153,7 +153,7 @@ showEquipmentNumber _ itm = case _eeUse ee of
showReloadProgress :: Creature -> Item -> String
showReloadProgress _ itm = fromMaybe [] $ do
ia <- itm ^? itUse . attachParams . ammoAttachParams
ia <- itm ^? itUse . attachParams . ammoLoadStatus
return $ case ia ^? iaProgress . _Just . ix 0 of
Nothing -> maybe "" show $ ia ^? iaLoaded
Just la -> showLoadActionType la ia
+6 -6
View File
@@ -142,7 +142,7 @@ withThickSmokeI eff item cr w =
ammoCheckI :: ChainEffect
ammoCheckI eff itm cr w = fromMaybe (failsound w) $ do
invid <- itm ^? itLocation . ipInvID
x <- cr ^? crInv . ix (invid + 1) . itUse . attachParams . ammoAttachParams . iaLoaded
x <- cr ^? crInv . ix (invid + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded
guard $ x > 0
return $ eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
where
@@ -340,13 +340,13 @@ useAllAmmo eff item cr = fromMaybe id $ do
invid <- item ^? itLocation . ipInvID
return $ eff item cr
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix (invid + 1)
. itUse . attachParams . ammoAttachParams . iaLoaded .~ 0)
. itUse . attachParams . ammoLoadStatus . iaLoaded .~ 0)
useAmmoUpTo :: Int -> ChainEffect
useAmmoUpTo amAmount eff itm cr = fromMaybe id $ do
invid <- itm ^? itLocation . ipInvID
return $ eff itm cr
. ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix (invid + 1) . itUse . attachParams . ammoAttachParams . iaLoaded
. ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix (invid + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded
%~ (max 0 . subtract amAmount)
)
@@ -358,7 +358,7 @@ useAmmoAmount amAmount eff item cr =
itref = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
useAmmoAmount' :: Int -> Int -> IM.IntMap Item -> IM.IntMap Item
useAmmoAmount' itref x inv = inv & ix (itref + 1) . itUse . attachParams . ammoAttachParams . iaLoaded -~ x
useAmmoAmount' itref x inv = inv & ix (itref + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded -~ x
-- . crInv . ix itRef . itUse . heldConsumption . laSource
@@ -659,7 +659,7 @@ duplicateLoaded eff it cr w = foldr f w (take numbul [1::Int .. ])
f _ = eff it cr
numbul = fromMaybe 0 $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
cr ^? crInv . ix (i+1) . itUse . attachParams . ammoAttachParams . iaLoaded
cr ^? crInv . ix (i+1) . itUse . attachParams . ammoLoadStatus . iaLoaded
duplicateNumBarrels :: Int -> ChainEffect
duplicateNumBarrels n eff itm cr w = foldr f w (take n $ itm ^?! itUse . heldAim . aimMuzzles)
@@ -681,7 +681,7 @@ duplicateLoadedBarrels eff itm cr = duplicateNumBarrels numbul eff itm cr
numbul :: Int
numbul = fromMaybe 0 $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
cr ^? crInv . ix (i+1) . itUse . attachParams . ammoAttachParams . iaLoaded
cr ^? crInv . ix (i+1) . itUse . attachParams . ammoLoadStatus . iaLoaded
duplicateOffsetsFocus :: [Float] -> ChainEffect
duplicateOffsetsFocus xs eff item cr w = foldr f w poss
+6 -6
View File
@@ -17,7 +17,7 @@ crCancelReloading cr =
updateProgress = fromMaybe id $ do
InInventory (SelItem i _) <- cr ^? crManipulation . manObject
return $
crInv . ix (i + 1) . itUse . attachParams . ammoAttachParams . iaProgress
crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus . iaProgress
%~ const Nothing
stepReloading :: Creature -> Creature
@@ -27,14 +27,14 @@ stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
cr & crManipulation . manObject . inInventory . iselAction . actionProgress -~ 1
| otherwise ->
cr
& crInv . ix (i + 1) . itUse . attachParams . ammoAttachParams %~ doLoadAction la
& crInv . ix (i + 1) . itUse . attachParams . ammoAttachParams %~ rotateActionProgress
& crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus %~ doLoadAction la
& crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus %~ rotateActionProgress
& tryNextLoadAction
_ -> cr
tryNextLoadAction :: Creature -> Creature
tryNextLoadAction cr = case cr ^? crManipulation . manObject . inInventory of
Just (SelItem i _) -> case cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoAttachParams . iaProgress . _Just . ix 0 of
Just (SelItem i _) -> case cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus . iaProgress . _Just . ix 0 of
Nothing -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
Just la ->
cr & crManipulation . manObject . inInventory . iselAction . actionProgress .~ _actionTime la
@@ -49,7 +49,7 @@ crReload cr = case cr ^? crManipulation . manObject . inInventory . iselAction o
tryStartLoading :: Creature -> Creature
tryStartLoading cr = fromMaybe cr $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
ia <- cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoAttachParams
ia <- cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus
return $ startLoading ia cr
-- case as of
@@ -66,7 +66,7 @@ startLoading ic cr = case ic ^? iaProgress . _Just . ix 0 of
i <- cr ^? crManipulation . manObject . inInventory . ispItem
return $
cr & startLoadingStep la
& crInv . ix i . itUse . attachParams . ammoAttachParams . iaProgress ?~ (la : las)
& crInv . ix i . itUse . attachParams . ammoLoadStatus . iaProgress ?~ (la : las)
startLoadingStep :: LoadAction -> Creature -> Creature
startLoadingStep la cr = cr & crManipulation . manObject . inInventory . iselAction .~ ReloadAction (_actionTime la) la