Split item consumables from item use

This commit is contained in:
2024-12-18 19:35:39 +00:00
parent db8e26b99d
commit 5600b29714
8 changed files with 63 additions and 59 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+12 -12
View File
@@ -201,7 +201,7 @@ trySynthBullet loc w = fromMaybe w $ do
then do
bat <- loc ^? locLDT . ldtLeft . ix 0 . _2 . ldtValue . _1
j <- bat ^? itLocation . ilInvID
y <- bat ^? itUse . amagLoadStatus . iaLoaded
y <- bat ^? itConsumables . magLoadStatus . iaLoaded
guard $ y > 0
return $
w
@@ -217,15 +217,15 @@ trySynthBullet loc w = fromMaybe w $ do
. ix 0
. crInv
. ix j
. itUse
. amagLoadStatus
. itConsumables
. magLoadStatus
. iaLoaded
-~ 1
else do
mag <- loc ^? locLdtContext . cldtParent . _1
j <- mag ^? itLocation . ilInvID
y <- mag ^? itUse . amagLoadStatus . iaLoaded
ymax <- mag ^? itUse . amagLoadStatus . iaMax
y <- mag ^? itConsumables . magLoadStatus . iaLoaded
ymax <- mag ^? itConsumables . magLoadStatus . iaMax
guard $ y < ymax
return $
w
@@ -241,8 +241,8 @@ trySynthBullet loc w = fromMaybe w $ do
. ix 0
. crInv
. ix j
. itUse
. amagLoadStatus
. itConsumables
. magLoadStatus
. iaLoaded
+~ 1
where
@@ -306,7 +306,7 @@ shineTargetLaser ::
shineTargetLaser cr itmtree (p, q) w = fromMaybe (w & pointittarg . itTgPos .~ Nothing) $ do
guard (crIsAiming cr)
(_, mag) <- find (isammolink . _iatType . fst) (itmtree ^. ldtLeft)
i <- mag ^? ldtValue . _1 . itUse . amagLoadStatus . iaLoaded
i <- mag ^? ldtValue . _1 . itConsumables . magLoadStatus . iaLoaded
guard $ i >= x
maginvid <- mag ^? ldtValue . _1 . itLocation . ilInvID
return $
@@ -315,8 +315,8 @@ shineTargetLaser cr itmtree (p, q) w = fromMaybe (w & pointittarg . itTgPos .~ N
& cWorld . lWorld . creatures . ix (_crID cr)
. crInv
. ix maginvid
. itUse
. amagLoadStatus
. itConsumables
. magLoadStatus
. iaLoaded
-~ x
& cWorld . lWorld . lasers
@@ -347,14 +347,14 @@ shineTorch ::
World
shineTorch cr itmtree (p, q) = fromMaybe id $ do
(_, mag) <- find (isammolink . _iatType . fst) (itmtree ^. ldtLeft)
i <- mag ^? ldtValue . _1 . itUse . amagLoadStatus . iaLoaded
i <- mag ^? ldtValue . _1 . itConsumables . magLoadStatus . iaLoaded
guard $ crIsAiming cr
guard $ i >= x
invid <- mag ^? ldtValue . _1 . itLocation . ilInvID
return $
--(cWorld . lWorld . tempLightSources .:~ tlsTimeRadColPos 1 250 0.7 pos'')
(cWorld . lWorld . lights .:~ LSParam pos'' 250 0.7)
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . amagLoadStatus . iaLoaded -~ x)
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itConsumables . magLoadStatus . iaLoaded -~ x)
where
x = 10
isammolink AmmoInLink{} = True
+4 -9
View File
@@ -53,16 +53,11 @@ data ItemUse
| UseCraft
| UseAttach {_uaParams :: AttachParams}
| UseAmmoMag
{ _amagLoadStatus :: ReloadStatus
, _amagParams :: AmmoParams
, _amagType :: AmmoType
}
| UseScope { _uScope :: Scope }
-- | UseTargeting
-- { _tgPos :: Maybe Point2
-- , _tgID :: Maybe Int
-- , _tgActive :: Bool
-- { _amagLoadStatus :: ReloadStatus
-- , _amagParams :: AmmoParams
-- , _amagType :: AmmoType
-- }
| UseScope { _uScope :: Scope }
| UseBulletMod { _ubMod :: BulletMod }
deriving (Eq, Show, Read)
+8 -7
View File
@@ -142,7 +142,7 @@ loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do
let as = _mzAmmoSlot mz
amamount = _mzAmmoPerShot mz
(i, (_, mag)) <- findWithIx (isAmmoIntLink as . fst) l
availableammo <- mag ^? ldtValue . itUse . amagLoadStatus . iaLoaded
availableammo <- mag ^? ldtValue . itConsumables . magLoadStatus . iaLoaded
let usedammo = case amamount of
UseUpTo x -> min x availableammo
UseExactly x
@@ -150,7 +150,8 @@ loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do
| otherwise -> 0
guard $ usedammo > 0
return
( t & ldtLeft . ix i . _2 . ldtValue . itUse . amagLoadStatus . iaLoaded -~ usedammo
( t & ldtLeft . ix i . _2 . ldtValue . itConsumables . magLoadStatus . iaLoaded
-~ usedammo
, Just (mz, usedammo, mag)
)
@@ -337,8 +338,8 @@ removeAmmoFromMag x mid cr = fromMaybe id $ do
. ix (_crID cr)
. crInv
. ix magid
. itUse
. amagLoadStatus
. itConsumables
. magLoadStatus
. iaLoaded
-~ x
@@ -350,7 +351,7 @@ getBulletType ::
World ->
Maybe Bullet
getBulletType itmtree magtree mz cr w =
magtree ^? ldtValue . itUse . amagParams . ampBullet
magtree ^? ldtValue . itConsumables . magParams . ampBullet
<&> buTrajectory .~ btraj
<&> buPayload .~ bpayload
<&> buEffect .~ beffect
@@ -453,7 +454,7 @@ useGasParams mmagid mz itm cr w =
(pressure, g) = doGenFloat (_nzPressure $ _mzEffect mz) (_randGen w)
gastype = fromMaybe (error "cannot find gas ammo") $ do
magid <- mmagid
fueltype <- cr ^? crInv . ix magid . itUse . amagParams . ampCreateGas
fueltype <- cr ^? crInv . ix magid . itConsumables . magParams . ampCreateGas
gc <- itm ^? itUse . heldParams . gasCreation
return $ gasCreate fueltype gc
--pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
@@ -533,7 +534,7 @@ createProjectile magtree muz itmtree cr = fromMaybe failsound $ do
magid <- magtree ^? ldtValue . itLocation . ilInvID
ammoitem <- cr ^? crInv . ix magid
let homing = determineProjectileTracking magtree itmtree
aparams <- ammoitem ^? itUse . amagParams . ampPayload
aparams <- ammoitem ^? itConsumables . magParams . ampPayload
return $
createShell homing aparams muz cr
. startthesound
+32 -25
View File
@@ -21,17 +21,18 @@ import Dodge.Item.Weapon.Bullet
megaTinMag :: Int -> Item
megaTinMag x =
tinMag
& itUse . amagLoadStatus . iaMax .~ x
& itUse . amagLoadStatus . iaLoaded .~ x
& itConsumables . magLoadStatus . iaMax .~ x
& itConsumables . magLoadStatus . iaLoaded .~ x
tinMag :: Item
tinMag =
defaultHeldItem & itType .~ AMMOMAG TINMAG
& itUse
.~ UseAmmoMag
{ _amagParams = BulletParams defaultBullet
, _amagType = BulletAmmo
, _amagLoadStatus =
& itConsumables .~ AmmoMag
{ _magParams = BulletParams defaultBullet
, _magType = BulletAmmo
, _magLoadStatus =
ReloadStatus
{ _iaMax = 15
, _iaLoaded = 15
@@ -48,59 +49,63 @@ tinMag =
drumMag :: Item
drumMag =
tinMag & itType . ibtAmmoMag .~ DRUMMAG
& itUse . amagLoadStatus . iaLoaded .~ 30
& itUse . amagLoadStatus . iaMax .~ 30
& itConsumables . magLoadStatus . iaLoaded .~ 30
& itConsumables . magLoadStatus . iaMax .~ 30
beltMag :: Item
beltMag =
tinMag & itType . ibtAmmoMag .~ BELTMAG
& itUse . amagLoadStatus . iaLoaded .~ 10000
& itUse . amagLoadStatus . iaMax .~ 20000
& itUse . amagType .~ BeltBulletAmmo
& itConsumables . magLoadStatus . iaLoaded .~ 10000
& itConsumables . magLoadStatus . iaMax .~ 20000
& itConsumables . magType .~ BeltBulletAmmo
megaShellMag :: Item
megaShellMag =
shellMag
& itUse . amagLoadStatus . iaMax .~ 1000000
& itUse . amagLoadStatus . iaLoaded .~ 1000000
& itConsumables . magLoadStatus . iaMax .~ 1000000
& itConsumables . magLoadStatus . iaLoaded .~ 1000000
shellMag :: Item
shellMag =
defaultHeldItem & itType .~ AMMOMAG SHELLMAG
& itUse
.~ UseAmmoMag
{ _amagParams =
& itConsumables
.~ AmmoMag
{ _magParams =
ProjectileParams
{ _ampPayload = ExplosionPayload
}
, _amagLoadStatus =
, _magLoadStatus =
ReloadStatus
{ _iaMax = 1
, _iaLoaded = 1
}
, _amagType = LauncherAmmo
, _magType = LauncherAmmo
}
megaBattery :: Item
megaBattery =
battery
& itUse . amagLoadStatus . iaMax .~ 1000000
& itUse . amagLoadStatus . iaLoaded .~ 1000000
& itConsumables . magLoadStatus . iaMax .~ 1000000
& itConsumables . magLoadStatus . iaLoaded .~ 1000000
smallBattery :: Item
smallBattery =
battery
& itUse . amagLoadStatus . iaMax .~ 999
& itUse . amagLoadStatus . iaLoaded .~ 999
& itConsumables . magLoadStatus . iaMax .~ 999
& itConsumables . magLoadStatus . iaLoaded .~ 999
battery :: Item
battery =
defaultHeldItem & itType .~ AMMOMAG BATTERY
& itUse
.~ UseAmmoMag
{ _amagParams = BulletParams defaultBullet
, _amagType = ElectricalAmmo
, _amagLoadStatus =
& itConsumables
.~ AmmoMag
{ _magParams = BulletParams defaultBullet
, _magType = ElectricalAmmo
, _magLoadStatus =
ReloadStatus
{ _iaMax = 10 ^ (9 :: Int)
, _iaLoaded = 10 ^ (9 :: Int)
@@ -112,9 +117,11 @@ chemFuelPouch =
defaultHeldItem & itType .~ AMMOMAG CHEMFUELPOUCH
& itUse
.~ UseAmmoMag
{ _amagParams = GasParams ChemFuel
, _amagType = GasAmmo
, _amagLoadStatus =
& itConsumables
.~ AmmoMag
{ _magParams = GasParams ChemFuel
, _magType = GasAmmo
, _magLoadStatus =
ReloadStatus
{ _iaMax = 1000
, _iaLoaded = 1000
+2 -1
View File
@@ -91,7 +91,8 @@ itemNumberDisplay cr ci = case (ci ^. _2, itm ^?! itUse, itm ^. itType) of
(_,UseConsume {},_) -> []
(_,UseAttach (APInt i),_) -> [show i]
(_,UseAttach {},_) -> []
(_,UseAmmoMag {},_) -> [maybe "" shortShow $ itm ^? itUse . amagLoadStatus . iaLoaded]
(_,UseAmmoMag {},_) -> [maybe "" shortShow
$ itm ^? itConsumables . magLoadStatus . iaLoaded]
(_,UseScope OpticScope {_opticZoom = x},_) -> [shortShow x]
(_,UseBulletMod {},_) -> mempty
where
+2 -2
View File
@@ -53,8 +53,8 @@ ammoMagSPic it = \case
_ -> noPic $ upperPrismPolyTS 1 (rectNSWE 0 (- y) (-1) 1)
where
y = fromIntegral y' * 0.3
y' = fromMaybe 0 $ it ^? itUse . amagLoadStatus . iaLoaded
am = fractionLoadedAmmo (it ^?! itUse . amagLoadStatus)
y' = fromMaybe 0 $ it ^? itConsumables . magLoadStatus . iaLoaded
am = fractionLoadedAmmo (it ^?! itConsumables . magLoadStatus)
fractionLoadedAmmo :: ReloadStatus -> Float
fractionLoadedAmmo rs = fromIntegral (_iaLoaded rs) / fromIntegral (_iaMax rs)
+2 -2
View File
@@ -62,7 +62,7 @@ itemToBreakLists itm itmf = case (itm ^. itType, itmf) of
, [(TriggerSF,TriggerLink),(WeaponTargetingSF, WeaponTargetingLink), (WeaponScopeSF, WeaponScopeLink)]
)
(_, AmmoMagSF{}) -> fromMaybe ([], []) $ do
atype <- itm ^? itUse . amagType
atype <- itm ^? itConsumables . magType
return
(
[ (AmmoModifierSF atype, AmmoModLink)
@@ -89,7 +89,7 @@ itemToFunction itm = case itm ^. itType of
HELD DETECTOR{} -> GadgetPlatformSF
HELD LASER -> WeaponTargetingSF
HELD{} -> HeldPlatformSF
AMMOMAG{} -> maybe UncomposableIsolateSF AmmoMagSF $ itm ^? itUse . amagType
AMMOMAG{} -> maybe UncomposableIsolateSF AmmoMagSF $ itm ^? itConsumables . magType
ATTACH REMOTESCREEN -> RemoteScreenSF
ATTACH BULLETSYNTH -> AmmoModifierSF BulletAmmo
ATTACH ZOOMSCOPE -> WeaponScopeSF