Improve click detectors

Introduce "gadgets" as a structural function, for items that can be used
when held and when not held. Click detectors are such an item. Make
click detectors correctly attach and use up batteries when used.
This commit is contained in:
2024-12-18 13:34:05 +00:00
parent 4d6d255893
commit c4e8046332
17 changed files with 119 additions and 79 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ inventoryX :: Char -> [Item]
inventoryX c = case c of
'A' ->
[ clickDetector x | x <- [minBound .. maxBound]
] <> [pulseChecker] <> fold
] <> [pulseChecker,battery] <> fold
[ makeTypeCraftNum 1 TRANSFORMER
, makeTypeCraftNum 2 CAN
, makeTypeCraftNum 2 PIPE
+4
View File
@@ -32,6 +32,10 @@ useRootItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w
return $
heldEffect (bimap _iatType fst3 itmtree) cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
GadgetPlatformSF ->
return $
heldEffect (bimap _iatType fst3 itmtree) cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
EquipmentPlatformSF -> do
guard (_crHammerPosition cr == HammerUp)
invid <- itm ^? itLocation . ilInvID
+2
View File
@@ -14,6 +14,7 @@ import Linear.Quaternion (Quaternion (..))
data ComposeLinkType
= AmmoInLink Int AmmoType
| TriggerLink
| AmmoModLink
| AmmoTargetingLink
| AmmoPayloadLink
@@ -31,6 +32,7 @@ data ItemStructuralFunction
| GadgetPlatformSF
| WeaponScopeSF
| WeaponTargetingSF
| TriggerSF
| AugmentedHUDSF
| AmmoMagSF AmmoType
| RemoteScreenSF
+8
View File
@@ -153,6 +153,11 @@ data MuzzleEffect
| MuzzleDetector
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data AmmoPerShot
= UseExactly {_useExactly :: Int}
| UseUpTo {_useUpTo :: Int}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data Muzzle = Muzzle
{ _mzPos :: V2 Float
, _mzRot :: Float
@@ -160,6 +165,7 @@ data Muzzle = Muzzle
, _mzAmmoSlot :: Int
, _mzFlareType :: FlareType
, _mzEffect :: MuzzleEffect
, _mzAmmoPerShot :: AmmoPerShot
-- , _mzChargeRequirement :: Maybe Int
-- , _mzRecoil :: Float
-- , _mzTorque :: Float
@@ -194,11 +200,13 @@ makeLenses ''HeldParams
makeLenses ''AttachParams
makeLenses ''AmmoParams
makeLenses ''MuzzleEffect
makeLenses ''AmmoPerShot
deriveJSON defaultOptions ''MuzzleEffect
deriveJSON defaultOptions ''FlareType
deriveJSON defaultOptions ''TriggerType
deriveJSON defaultOptions ''AmmoParams
deriveJSON defaultOptions ''HeldParams
deriveJSON defaultOptions ''AmmoPerShot
deriveJSON defaultOptions ''Muzzle
deriveJSON defaultOptions ''AimStance
+1 -1
View File
@@ -38,7 +38,7 @@ singleAmmo x = IM.insert 0 x mempty
defaultBulletWeapon :: Item
defaultBulletWeapon = defaultHeldItem
& itAmmoSlots .~ singleAmmo BulletAmmo
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 0) 0 0.01 0 PistolFlare MuzzleShootBullet]
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 0) 0 0.01 0 PistolFlare MuzzleShootBullet (UseExactly 1)]
defaultConsumable :: Item
defaultConsumable = defaultHeldItem & itUse .~ UseConsume CDoNothing
+1
View File
@@ -23,6 +23,7 @@ defaultAimParams =
, _mzAmmoSlot = 0
, _mzFlareType = DefaultFlareType
, _mzEffect = MuzzleShootBullet
, _mzAmmoPerShot = UseExactly 1
}
]
}
+13 -4
View File
@@ -44,7 +44,7 @@ hammerCheck f it cr w = case it ^? ldtValue . itUse . heldTriggerType of
heldEffectMuzzles :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffectMuzzles t cr w =
uncurry (applyCME (_ldtValue t) cr) cmew
& cWorld . lWorld . lTestString .~ map (show . _mzAmmoSlot) muzzles
-- & cWorld . lWorld . lTestString .~ map (show . _mzAmmoSlot) muzzles
& doWeaponRepetitions upitm cr
where
muzzles = t ^. ldtValue . itUse . heldAim . aimMuzzles
@@ -63,7 +63,12 @@ doWeaponRepetitions itm cr = case itm ^? ldtValue . itUse . heldParams . weaponR
applyCME :: Item -> Creature -> CumulativeMuzzleEffect -> World -> World
applyCME itm cr cme
| _cmeSound cme = applyInvLock itm cr . applySoundCME itm cr . applySidePush spush cr . applyTorqueCME itm cr . applyRecoil itm cr
| _cmeSound cme =
applyInvLock itm cr
. applySoundCME itm cr
. applySidePush spush cr
. applyTorqueCME itm cr
. applyRecoil itm cr
| otherwise = failsound
where
spush = fromMaybe 0 $ itm ^? itUse . heldParams . sidePush
@@ -131,10 +136,14 @@ loadMuzzle ::
(LabelDoubleTree ComposeLinkType Item, Maybe (Muzzle, Int, LabelDoubleTree ComposeLinkType Item))
loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do
let as = _mzAmmoSlot mz
amamount = 1
amamount = _mzAmmoPerShot mz
(i, (_, mag)) <- findWithIx (isAmmoIntLink as . fst) l
availableammo <- mag ^? ldtValue . itUse . amagLoadStatus . iaLoaded
let usedammo = min amamount availableammo
let usedammo = case amamount of
UseUpTo x -> min x availableammo
UseExactly x
| x <= availableammo -> x
| otherwise -> 0
guard $ usedammo > 0
return
( t & ldtLeft . ix i . _2 . ldtValue . itUse . amagLoadStatus . iaLoaded -~ usedammo
+6
View File
@@ -57,6 +57,10 @@ itemToBreakLists itm itmf = case (itm ^. itType, itmf) of
( getAmmoLinks itm
, [(WeaponTargetingSF, WeaponTargetingLink), (WeaponScopeSF, WeaponScopeLink)]
)
(_, GadgetPlatformSF) ->
( getAmmoLinks itm
, [(TriggerSF,TriggerLink),(WeaponTargetingSF, WeaponTargetingLink), (WeaponScopeSF, WeaponScopeLink)]
)
(_, AmmoMagSF{}) -> fromMaybe ([], []) $ do
atype <- itm ^? itUse . amagType
return
@@ -82,6 +86,7 @@ getAmmoLinks itm =
itemToFunction :: Item -> ItemStructuralFunction
itemToFunction itm = case itm ^. itType of
HELD DETECTOR{} -> GadgetPlatformSF
HELD LASER -> WeaponTargetingSF
HELD{} -> HeldPlatformSF
AMMOMAG{} -> maybe UncomposableIsolateSF AmmoMagSF $ itm ^? itUse . amagType
@@ -95,6 +100,7 @@ itemToFunction itm = case itm ^. itType of
BULLETMOD BulletModEffect{} -> AmmoEffectSF BulletAmmo
TARGETING{} -> WeaponTargetingSF
LEFT{} -> EquipmentPlatformSF
EQUIP WRIST_ECG -> TriggerSF
EQUIP{} -> EquipmentPlatformSF
_ -> UncomposableIsolateSF
+3 -1
View File
@@ -40,6 +40,7 @@ volleyGun i =
<*> ZipList [0..i-1]
<*> pure PistolFlare
<*> pure MuzzleShootBullet
<*> pure (UseExactly 1)
)
& itUse . heldParams . torqueAfter .~ 0.15 + 0.05 * fromIntegral i
& itUse . heldParams . recoil .~ 20 + 10 * fromIntegral i
@@ -88,7 +89,8 @@ miniGunX i =
& itUse . heldParams . bulGunSound ?~ (mini1S,2)
& itUse . heldAim . aimTurnSpeed .~ 0.5
& itUse . heldAim . aimMuzzles
.~ replicate i (Muzzle (V2 30 0) 0 0.05 0 MiniGunFlare MuzzleShootBullet)
.~ replicate i
(Muzzle (V2 30 0) 0 0.05 0 MiniGunFlare MuzzleShootBullet (UseExactly 1))
& itUse . heldParams . recoil .~ 10 * fromIntegral i
& itUse . heldParams . torqueAfter .~ 0.04 + 0.02 * fromIntegral i
& itUse . heldParams . sidePush .~ 10 * fromIntegral i
+2 -1
View File
@@ -13,7 +13,8 @@ bangCone =
defaultBulletWeapon
& itUse . heldDelay . rateMax .~ 20
& itUse . heldAim . aimMuzzles
.~ replicate 15 (Muzzle (V2 15 0) 0 0.5 0 DefaultFlareType MuzzleShootBullet)
.~ replicate 15
(Muzzle (V2 15 0) 0 0.5 0 DefaultFlareType MuzzleShootBullet (UseExactly 1))
& itUse . heldParams . muzVel .~ UniRandFloat 0.5 0.8
& itUse . heldParams . rifling .~ UniRandFloat 0.3 0.8
& itUse . heldParams . recoil .~ 150
+1
View File
@@ -35,6 +35,7 @@ launcherX i =
<*> ZipList [0..]
<*> pure DefaultFlareType
<*> pure MuzzleLauncher
<*> pure (UseExactly 1)
)
& itAmmoSlots .~ IM.fromList [(j,LauncherAmmo) | j <- [0..i-1]]
where
+1
View File
@@ -84,6 +84,7 @@ flameThrower =
, _nzWalkSpeed = 0.01
, _nzCurrentWalkAngle = 0
}
(UseExactly 1)
]
& itAmmoSlots .~ singleAmmo GasAmmo
& itType .~ HELD FLAMETHROWER
+2 -1
View File
@@ -22,7 +22,8 @@ bangStick i =
& itType .~ HELD (BANGSTICK i)
& itUse . heldDelay . rateMax .~ 8
& itUse . heldAim . aimMuzzles
.~ [Muzzle (V2 10 0) a 0.01 0 DefaultFlareType MuzzleShootBullet | a <- spreadAroundCenter i baseStickSpread]
.~ [Muzzle (V2 10 0) a 0.01 0 DefaultFlareType MuzzleShootBullet (UseExactly 1)
| a <- spreadAroundCenter i baseStickSpread]
baseStickSpread :: Float
baseStickSpread = 0.2
+3
View File
@@ -38,5 +38,8 @@ clickDetector dt =
& itUse . heldDelay . rateMax .~ 20
& itUse . heldAim . aimRange .~ 1
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1}
& itAmmoSlots .~ singleAmmo ElectricalAmmo
& itUse . heldParams .~ DefaultHeldParams
& itType .~ HELD (DETECTOR dt)
& itUse . heldAim . aimMuzzles . ix 0 . mzEffect .~ MuzzleDetector
& itUse . heldAim . aimMuzzles . ix 0 . mzAmmoPerShot .~ UseExactly 100
+2 -1
View File
@@ -12,7 +12,8 @@ itemInvColor :: ComposedItem -> Color
itemInvColor ci = case ci ^. _2 of
HeldPlatformSF -> white
EquipmentPlatformSF -> yellow
GadgetPlatformSF -> blue
GadgetPlatformSF -> white
TriggerSF -> yellow
WeaponScopeSF -> chartreuse
WeaponTargetingSF -> green
AugmentedHUDSF -> rose