Remove consumable records

This commit is contained in:
2025-06-05 21:15:20 +01:00
parent 816ab4222f
commit 10ca82c4d5
16 changed files with 258 additions and 321 deletions
+10 -12
View File
@@ -3,6 +3,7 @@ module Dodge.Creature.State (
doDamage,
) where
import Dodge.Item.MaxAmmo
import Control.Applicative
import Dodge.HeldUse
import Control.Monad
@@ -208,7 +209,7 @@ trySynthBullet loc w = fromMaybe w $ do
then do
bat <- loc ^? locLDT . ldtLeft . ix 0 . _2 . ldtValue . _1
j <- bat ^? itLocation . ilInvID
y <- bat ^? itConsumables . magLoadStatus . iaLoaded
y <- bat ^. itConsumables
guard $ y > 0
return $
w
@@ -225,14 +226,13 @@ trySynthBullet loc w = fromMaybe w $ do
. crInv
. ix j
. itConsumables
. magLoadStatus
. iaLoaded
. _Just
-~ 1
else do
mag <- loc ^? locLdtContext . cldtParent . _1
j <- mag ^? itLocation . ilInvID
y <- mag ^? itConsumables . magLoadStatus . iaLoaded
ymax <- mag ^? itConsumables . magLoadStatus . iaMax
y <- mag ^. itConsumables
ymax <- maxAmmo mag-- ^? itConsumables . magLoadStatus . iaMax
guard $ y < ymax
return $
w
@@ -249,8 +249,7 @@ trySynthBullet loc w = fromMaybe w $ do
. crInv
. ix j
. itConsumables
. magLoadStatus
. iaLoaded
. _Just
+~ 1
where
itm = loc ^. locLDT . ldtValue . _1
@@ -314,7 +313,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 . itConsumables . magLoadStatus . iaLoaded
i <- mag ^. ldtValue . _1 . itConsumables
guard $ i >= x
maginvid <- mag ^? ldtValue . _1 . itLocation . ilInvID
return $
@@ -324,8 +323,7 @@ shineTargetLaser cr itmtree (p, q) w = fromMaybe (w & pointittarg . itTgPos .~ N
. crInv
. ix maginvid
. itConsumables
. magLoadStatus
. iaLoaded
. _Just
-~ x
& cWorld . lWorld . lasers
.:~ Laser
@@ -355,14 +353,14 @@ shineTorch ::
World
shineTorch cr itmtree (p, q) = fromMaybe id $ do
(_, mag) <- find (isammolink . _iatType . fst) (itmtree ^. ldtLeft)
i <- mag ^? ldtValue . _1 . itConsumables . magLoadStatus . iaLoaded
i <- mag ^. ldtValue . _1 . itConsumables
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 . itConsumables . magLoadStatus . iaLoaded -~ x)
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itConsumables . _Just -~ x)
where
x = 10
isammolink AmmoInLink{} = True
+1 -5
View File
@@ -33,21 +33,17 @@ data Consumables
= NoConsumables
| AmmoMag
{ _magLoadStatus :: ReloadStatus
, _magParams :: AmmoParams
-- , _magType :: AmmoType
}
deriving (Eq, Show, Read)
data Item = Item
{ _itUse :: ItemUse
-- , _itUseCondition :: UseCondition
, _itConsumables :: Consumables
, _itConsumables :: Maybe Int
, _itType :: ItemType
, _itID :: NewInt ItmInt
, _itLocation :: ItemLocation
, _itEffect :: ItEffect
, _itTargeting :: ItemTargeting
-- , _itAmmoSlots :: IM.IntMap AmmoType
, _itParams :: ItemParams
, _itScroll :: ItemScroll
, _itTimeLastUsed :: Int
+2 -10
View File
@@ -39,11 +39,6 @@ data ItemUse
}
deriving (Eq, Show, Read)
data UseFocus
= UseFromRoot
| UseFromLocation
deriving (Eq, Show, Read)
data AttachParams
= APProjectiles {_apProjectiles :: [Int]}
| APInt {_apInt :: Int}
@@ -60,10 +55,7 @@ data AmmoParams
makeLenses ''ItemUse
makeLenses ''AttachParams
makeLenses ''AmmoParams
--makeLenses ''UseCondition
makeLenses ''UseFocus
--deriveJSON defaultOptions ''UseFocus
--deriveJSON defaultOptions ''UseCondition
deriveJSON defaultOptions ''AmmoParams
--makeLenses ''UseFocus
--deriveJSON defaultOptions ''AmmoParams
deriveJSON defaultOptions ''AttachParams
deriveJSON defaultOptions ''ItemUse
+1 -2
View File
@@ -18,8 +18,7 @@ import Dodge.Data.Item.Use.Consumption.Ammo
import Dodge.Data.Item.Use.Consumption.LoadAction
data ReloadStatus = ReloadStatus
{ _iaMax :: Int
, _iaLoaded :: Int
{ _iaLoaded :: Int
}
deriving (Eq, Show, Read) --Generic, Flat)
+5 -3
View File
@@ -1,6 +1,5 @@
{-# LANGUAGE StrictData #-}
module Dodge.Data.UseCondition
where
module Dodge.Data.UseCondition where
data UseCondition
= UseableWhenAimed
@@ -9,4 +8,7 @@ data UseCondition
| NeverUsable
deriving (Eq, Show, Read)
data UseFocus
= UseFromRoot
| UseFromLocation
deriving (Eq, Show, Read)
+1 -1
View File
@@ -10,7 +10,7 @@ defaultHeldItem :: Item
defaultHeldItem =
Item
{ _itType = HELD PISTOL
, _itConsumables = NoConsumables
, _itConsumables = Nothing
, _itEffect = defaultItEffect
, _itID = 0 -- should this return an error ? const $ error "itID not correctly initialised" ?
, _itTargeting = NoItTargeting
+26 -8
View File
@@ -632,7 +632,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 . itConsumables . magLoadStatus . iaLoaded
availableammo <- mag ^. ldtValue . itConsumables
let usedammo = case amamount of
UseUpTo x -> min x availableammo
UseExactly x
@@ -640,8 +640,7 @@ loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do
| otherwise -> 0
guard $ usedammo > 0
return
( t & ldtLeft . ix i . _2 . ldtValue . itConsumables . magLoadStatus . iaLoaded
-~ usedammo
( t & ldtLeft . ix i . _2 . ldtValue . itConsumables . _Just -~ usedammo
, Just (mz, usedammo, mag)
)
@@ -873,13 +872,13 @@ removeAmmoFromMag x mid cr = fromMaybe id $ do
. crInv
. ix magid
. itConsumables
. magLoadStatus
. iaLoaded
. _Just
-~ x
getBulletType :: LabelDoubleTree ComposeLinkType Item -> Maybe Bullet
getBulletType magtree =
magtree ^? ldtValue . itConsumables . magParams . ampBullet
--magtree ^? ldtValue . itConsumables . magParams . ampBullet
(magtree ^? ldtValue >>= magAmmoParams >>= (^? ampBullet))
-- <&> buTrajectory .~ btraj
<&> buPayload .~ bpayload
<&> buEffect .~ beffect
@@ -897,6 +896,23 @@ getBulletType magtree =
attree <- lookup AmmoEffectLink (magtree ^. ldtLeft)
attree ^? ldtValue . itUse . ubMod . bmEffect
magAmmoParams :: Item -> Maybe AmmoParams
magAmmoParams itm = case itm ^. itType of
EQUIP BATTERYPACK -> Just NoAmmoParams
EQUIP FUELPACK -> Just $ GasParams ChemFuel
AMMOMAG CHEMFUELPOUCH -> Just $ GasParams ChemFuel
EQUIP BULLETBELTPACK -> Just $ BulletParams defaultBullet
EQUIP BULLETBELTBRACER -> Just $ BulletParams defaultBullet
AMMOMAG TINMAG -> Just $ BulletParams defaultBullet
AMMOMAG DRUMMAG -> Just $ BulletParams defaultBullet
AMMOMAG BELTMAG -> Just $ BulletParams defaultBullet
AMMOMAG SHELLMAG -> Just $
ProjectileParams
{ _ampPayload = ExplosionPayload
}
AMMOMAG BATTERY -> Just NoAmmoParams
_ -> Nothing
--getBulletTrajectory ::
-- Muzzle ->
-- Item ->
@@ -1107,7 +1123,8 @@ useGasParams mmagid mz itm cr w =
gastype = fromMaybe (error "cannot find gas ammo") $ do
magid <- mmagid
hit <- itm ^? itType . ibtHeld
fueltype <- cr ^? crInv . ix magid . itConsumables . magParams . ampCreateGas
--fueltype <- cr ^? crInv . ix magid . itConsumables . magParams . ampCreateGas
fueltype <- cr ^? crInv . ix magid >>= magAmmoParams >>= (^? ampCreateGas)
gasType hit fueltype
--pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz) (_mzRot mz)
@@ -1274,7 +1291,8 @@ createProjectile pjtype magtree stab muz cr = fromMaybe failsound $ do
<$> lookup RemoteScreenLink (magtree ^. ldtLeft)
aparams <-
((magtree ^? ldtLeft) >>= lookup AmmoPayloadLink >>= (^? ldtValue . itType . ibtAttach . shellPayload))
<|> ammoitem ^? itConsumables . magParams . ampPayload
-- <|> ammoitem ^? itConsumables . magParams . ampPayload
<|> magAmmoParams ammoitem ^? _Just . ampPayload
return $
createShell rdetonate rscreen stab pjtype aparams muz cr
. startthesound
+20 -62
View File
@@ -16,103 +16,61 @@ import Control.Lens
import Dodge.Data.World
import Dodge.Default.Item
import Dodge.Item.Attach
import Dodge.Item.Weapon.Bullet
--import Dodge.Item.Weapon.Bullet
megaTinMag :: Int -> Item
megaTinMag x =
tinMag
& itConsumables . magLoadStatus . iaMax .~ x
& itConsumables . magLoadStatus . iaLoaded .~ x
& itConsumables ?~ x
tinMag :: Item
tinMag =
defaultHeldItem & itType .~ AMMOMAG TINMAG
& itUse .~ UseNothing
& itConsumables
.~ AmmoMag
{ _magParams = BulletParams defaultBullet
-- , _magType = BulletAmmo
, _magLoadStatus =
ReloadStatus
{ _iaMax = 15
, _iaLoaded = 15
}
}
& itConsumables ?~ 15
drumMag :: Item
drumMag = tinMag & itType . ibtAmmoMag .~ DRUMMAG
& itConsumables . magLoadStatus . iaLoaded .~ 30
& itConsumables . magLoadStatus . iaMax .~ 30
drumMag =
tinMag & itType . ibtAmmoMag .~ DRUMMAG
& itConsumables ?~ 30
beltMag :: Item
beltMag = tinMag & itType . ibtAmmoMag .~ BELTMAG
& itConsumables . magLoadStatus . iaLoaded .~ 10000
& itConsumables . magLoadStatus . iaMax .~ 20000
-- & itConsumables . magType .~ BeltBulletAmmo
beltMag =
tinMag & itType . ibtAmmoMag .~ BELTMAG
& itConsumables ?~ 10000
megaShellMag :: Item
megaShellMag = shellMag
& itConsumables . magLoadStatus . iaMax .~ 1000000
& itConsumables . magLoadStatus . iaLoaded .~ 1000000
megaShellMag =
shellMag
& itConsumables ?~ 1000000
shellMag :: Item
shellMag =
defaultHeldItem & itType .~ AMMOMAG SHELLMAG
& itUse .~ UseNothing
& itConsumables
.~ AmmoMag
{ _magParams =
ProjectileParams
{ _ampPayload = ExplosionPayload
}
, _magLoadStatus =
ReloadStatus
{ _iaMax = 1
, _iaLoaded = 1
}
-- , _magType = LauncherAmmo
}
& itConsumables ?~ 1
megaBattery :: Item
megaBattery = battery
& itConsumables . magLoadStatus . iaMax .~ 1000000
& itConsumables . magLoadStatus . iaLoaded .~ 1000000
megaBattery =
battery
& itConsumables ?~ 1000000
smallBattery :: Item
smallBattery =
battery
& itConsumables . magLoadStatus . iaMax .~ 999
& itConsumables . magLoadStatus . iaLoaded .~ 999
smallBattery = battery & itConsumables ?~ 999
battery :: Item
battery =
defaultHeldItem & itType .~ AMMOMAG BATTERY
& itUse .~ UseNothing
& itConsumables
.~ AmmoMag
{ _magParams = NoAmmoParams
-- , _magType = ElectricalAmmo
, _magLoadStatus =
ReloadStatus
{ _iaMax = 10 ^ (9 :: Int)
, _iaLoaded = 10 ^ (9 :: Int)
}
}
& itConsumables ?~ 10 ^ (9 :: Int)
chemFuelPouch :: Item
chemFuelPouch =
defaultHeldItem & itType .~ AMMOMAG CHEMFUELPOUCH
& itUse .~ UseNothing
& itConsumables
.~ AmmoMag
{ _magParams = GasParams ChemFuel
-- , _magType = GasAmmo
, _magLoadStatus =
ReloadStatus
{ _iaMax = 1000
, _iaLoaded = 1000
}
}
?~ 1000
bulletSynthesizer :: Item
bulletSynthesizer = makeAttach BULLETSYNTH & itUse .~ UseAttach (APInt 0)
+1 -1
View File
@@ -35,7 +35,7 @@ itemInternalValue itm
| Just x <- itm ^? itUse . uInt = Just (Left x)
| Just x <- itm ^? itUse . useToggle = Just (Right $ show x)
| isJust $ itm ^? itTargeting . itTgPos . _Just = Just $ Right "!TARGETING"
| Just x <- itm ^? itConsumables . magLoadStatus . iaLoaded = Just $ Left x
| Just x <- itm ^. itConsumables = Just $ Left x
| UseAttach (APInt i) <- itm ^. itUse = Just $ Left i
| UseAttach (APProjectiles x) <- itm ^. itUse = Just . Right $ show x
| v <- itm ^? itUse . uValue = v
+9 -4
View File
@@ -5,6 +5,7 @@ module Dodge.Item.Draw.SPic (
itemTreeSPic,
) where
import Dodge.Item.MaxAmmo
import Color
import Data.Maybe
import Data.Strict.Tuple
@@ -131,11 +132,15 @@ ammoMagSPic it = \case
_ -> noPic $ upperPrismPolyTS 1 (rectNSWE 0 (- y) (-1) 1)
where
y = fromIntegral y' * 0.3
y' = fromMaybe 0 $ it ^? itConsumables . magLoadStatus . iaLoaded
am = fractionLoadedAmmo (it ^?! itConsumables . magLoadStatus)
y' = fromMaybe 0 $ it ^. itConsumables
am = fractionLoadedAmmo it -- (it ^?! itConsumables . magLoadStatus)
fractionLoadedAmmo :: Item -> Float
fractionLoadedAmmo itm = fromMaybe 0 $ do
m <- maxAmmo itm
return $ fromIntegral (itm ^?! itConsumables . _Just)
/ fromIntegral m
fractionLoadedAmmo :: ReloadStatus -> Float
fractionLoadedAmmo rs = fromIntegral (_iaLoaded rs) / fromIntegral (_iaMax rs)
--
--fractionLoadedAmmo2 :: ReloadStatus -> Float
--fractionLoadedAmmo2 rs =
+13 -44
View File
@@ -18,16 +18,16 @@ module Dodge.Item.Equipment (
) where
import Dodge.Data.Equipment.Misc
import Dodge.Data.Magnet
import Dodge.Item.Weapon.Bullet
--import Dodge.Item.Weapon.Bullet
import Dodge.Data.Item
import Dodge.Data.Magnet
import Dodge.Default
import LensHelp
magShield :: MagnetBuBu -> Item
magShield mt =
defaultEquipment
-- & itUse . uequipEffect . eeUse .~ EMagShield MagnetRepulse
-- & itUse . uequipEffect . eeUse .~ EMagShield MagnetRepulse
& itType .~ EQUIP (MAGSHIELD mt)
flameShield :: Item
@@ -44,61 +44,30 @@ wristArmour :: Item
wristArmour = defaultEquipment & itType .~ EQUIP WRISTARMOUR
batteryPack :: Item
batteryPack = defaultEquipment
batteryPack =
defaultEquipment
& itConsumables
.~ AmmoMag
{ _magParams = NoAmmoParams
, _magLoadStatus =
ReloadStatus
{ _iaMax = 10000000
, _iaLoaded = 10000000
}
}
?~ 10000000
& itType .~ EQUIP BATTERYPACK
fuelPack :: Item
fuelPack =
defaultEquipment
-- & itUse . uequipEffect . eeUse .~ EFuelSource 10000 10000
-- & itUse . uequipEffect . eeUse .~ EFuelSource 10000 10000
& itType .~ EQUIP FUELPACK
& itConsumables
.~ AmmoMag
{ _magParams = GasParams ChemFuel
, _magLoadStatus =
ReloadStatus
{ _iaMax = 100000
, _iaLoaded = 100000
}
}
?~ 100000
bulletBeltPack :: Item
bulletBeltPack =
defaultEquipment
-- & itUse . uequipEffect . eeUse .~ EDoNothing
& itConsumables
.~ AmmoMag
{ _magParams = BulletParams defaultBullet
, _magLoadStatus =
ReloadStatus
{ _iaMax = 10000000
, _iaLoaded = 10000000
}
}
& itConsumables ?~ 10000000
& itType .~ EQUIP BULLETBELTPACK
bulletBeltBracer :: Item
bulletBeltBracer =
defaultEquipment
-- & itUse . uequipEffect . eeUse .~ EDoNothing
& itConsumables
.~ AmmoMag
{ _magParams = BulletParams defaultBullet
, _magLoadStatus =
ReloadStatus
{ _iaMax = 100000
, _iaLoaded = 100000
}
}
& itConsumables ?~ 100000
& itType .~ EQUIP BULLETBELTBRACER
brainHat :: Item
@@ -110,7 +79,7 @@ hat = defaultEquipment & itType .~ EQUIP HAT
headLamp :: Item
headLamp =
defaultEquipment
-- & itUse . uequipEffect . eeUse .~ EHeadLamp
-- & itUse . uequipEffect . eeUse .~ EHeadLamp
& itType .~ EQUIP HEADLAMP
powerLegs :: Item
@@ -127,8 +96,8 @@ jumpLegs = powerLegs & itType .~ EQUIP JUMPLEGS
wristInvisibility :: Item
wristInvisibility =
defaultEquipment
-- & itUse . uequipEffect . eeOnEquip .~ ECamouflage Invisible
-- & itUse . uequipEffect . eeOnRemove .~ ECamouflage FullyVisible
-- & itUse . uequipEffect . eeOnEquip .~ ECamouflage Invisible
-- & itUse . uequipEffect . eeOnRemove .~ ECamouflage FullyVisible
& itType .~ EQUIP (INVISIBILITYEQUIPMENT GoesOnWrist)
pulseChecker :: Item
+1 -1
View File
@@ -7,5 +7,5 @@ itUseCondition :: Item -> UseCondition
itUseCondition itm = case _itType itm of
DETECTOR _ -> UseableAnytime
HELD BLINKER -> UseableAnytime
HELD UNSAFEBLINKER -> UseableAnytime
HELD BLINKERUNSAFE -> UseableAnytime
_ -> UseableWhenAimed