Extend trigger type to apply to full item location

This commit is contained in:
2025-07-03 23:08:28 +01:00
parent 978823c87c
commit d8e811c050
7 changed files with 131 additions and 124 deletions
+8 -2
View File
@@ -2,15 +2,21 @@
module Dodge.BaseTriggerType (
itemTriggerType,
baseItemTriggerType,
module Dodge.Data.TriggerType,
) where
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Control.Lens
import Dodge.Data.Item
import Dodge.Data.TriggerType
itemTriggerType :: Item -> TriggerType
itemTriggerType itm = case itm ^. itType of
itemTriggerType :: LocationLDT ItemLink OItem -> TriggerType
itemTriggerType loc = baseItemTriggerType $ loc ^. locLDT . ldtValue . _1
baseItemTriggerType :: Item -> TriggerType
baseItemTriggerType itm = case itm ^. itType of
HELD hit -> heldTriggerType hit
_ -> NoTrigger
+6 -5
View File
@@ -165,27 +165,28 @@ invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
| otherwise ->
w & pointerToItem itm . itParams . wTime
%~ (max 0 . subtract 1)
-- hard code values?
HELD MACHINEPISTOL{}
| fromMaybe 0 (itm ^? itParams . wTime) >= _coolEnd (itemTriggerType itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) >= _coolEnd (baseItemTriggerType itm) ->
w & pointerToItem itm . itParams . wTime
.~ 0
& pointerToItem itm . itParams . coolSound .~ Nothing
| fromMaybe 0 (itm ^? itParams . wTime) == _coolStart (itemTriggerType itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) == _coolStart (baseItemTriggerType itm) ->
w
& randGen .~ g
& pointerToItem itm . itParams . wTime +~ 1
& pointerToItem itm . itParams . coolSound ?~ sid
& soundContinue (CrWeaponSound (_crID cr) (fromIntegral $ _itID itm)) (_crPos cr) sid (Just 1)
| fromMaybe 0 (itm ^? itParams . wTime) > _coolStart (itemTriggerType itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) > _coolStart (baseItemTriggerType itm) ->
w
& pointerToItem itm . itParams . wTime +~ 1
& soundContinue (CrWeaponSound (_crID cr) (fromIntegral $ _itID itm)) (_crPos cr) (fromMaybe undefined (itm ^? itParams . coolSound . _Just)) (Just 1)
| itm ^? itParams . isWarming == Just True ->
w
& pointerToItem itm . itParams . isWarming .~ False
| fromMaybe 0 (itm ^? itParams . wTime) >= _warmStart (itemTriggerType itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) >= _warmStart (baseItemTriggerType itm) ->
w & pointerToItem itm . itParams . wTime
.~ _coolStart (itemTriggerType itm)
.~ _coolStart (baseItemTriggerType itm)
| otherwise ->
w & pointerToItem itm . itParams . wTime
.~ 0
+33 -32
View File
@@ -4,7 +4,6 @@
module Dodge.HeldUse (
gadgetEffect,
-- heldEffect,
mcUseHeld,
heldEffectMuzzles,
) where
@@ -48,7 +47,7 @@ gadgetEffect pt loc
| UseHeld{} <- loc ^. locLDT . ldtValue . _1 . itUse =
heldEffect
pt
(loc ^. locLDT)
loc
| DROPPER x <- loc ^. locLDT . ldtValue . _1 . itType
, Just i <- loc ^? locLDT . ldtValue . _1 . itUse . uInt
, pt == InitialPress =
@@ -58,79 +57,81 @@ gadgetEffect pt loc
useInventoryPath pt i x loc
| otherwise = const id
heldEffect :: PressType -> LDTree ItemLink OItem -> Creature -> World -> World
heldEffect :: PressType -> LocationLDT ItemLink OItem -> Creature -> World -> World
heldEffect = hammerCheck heldEffectMuzzles
hammerCheck ::
(LDTree ItemLink OItem -> Creature -> World -> World) ->
(LocationLDT ItemLink OItem -> Creature -> World -> World) ->
PressType ->
LDTree ItemLink OItem ->
LocationLDT ItemLink OItem ->
Creature ->
World ->
World
hammerCheck f pt it cr w = case itemTriggerType $ it ^. ldtValue . _1 of
hammerCheck f pt loc cr w = case itemTriggerType loc of
WarmUpNoDelay wm
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < wm ->
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) tree) < wm ->
w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. ldtValue . _1 . itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
WarmUpNoDelay{} -> f it cr w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . wTime +~ 1
WarmUpNoDelay{} -> f loc cr w & setwarming
WarmUpCoolDown ws _ _
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < ws ->
-- UNSAFE:
| _wTime (_itParams $ it) < ws ->
w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. ldtValue . _1 . itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . wTime +~ 1
WarmUpCoolDown _ cs _
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < cs ->
f it cr w & setwarming
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
| _wTime (_itParams $ it) < cs ->
f loc cr w & setwarming
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . wTime +~ 1
WarmUpCoolDown{} -> w & setwarming
BurstTrigger is t
| w ^. cWorld . lWorld . lClock - t > timelastused
, pt == InitialPress ->
w & f it cr & cWorld . lWorld . delayedEvents .++~ map g is
BurstTrigger{} -> w
w & f loc cr & cWorld . lWorld . delayedEvents .++~ map g is
VolleyGunTrigger i t
| w ^. cWorld . lWorld . lClock - t > timelastused
, pt == InitialPress ->
let (is, gen) = getVolleyBurst i (w ^. randGen)
in w & f it cr
in w & f loc cr
& cWorld . lWorld . delayedEvents .++~ map g is
& randGen .~ gen
VolleyGunTrigger{} -> w
HammerTrigger t
| w ^. cWorld . lWorld . lClock - t > timelastused
, isNothing $ lookup MakeAutoLink (it ^. ldtRight)
, isNothing $ lookup MakeAutoLink (tree ^. ldtRight)
, pt == InitialPress ->
f it cr w
f loc cr w
AutoTrigger t
| w ^. cWorld . lWorld . lClock - t > timelastused ->
f it cr w
NoTrigger -> f it cr w
f loc cr w
NoTrigger -> f loc cr w
_ -> w
where
tree = loc ^. locLDT
it = loc ^. locLDT . ldtValue . _1
cid = _crID cr
-- the following is unsafe, but if ilInvID isn't correctly set we probably
-- will have problems elsewhere also
itRef = it ^?! ldtValue . _1 . itLocation . ilInvID
invid = it ^?! itLocation . ilInvID
setwarming =
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . isWarming
cWorld . lWorld . creatures . ix cid . crInv . ix invid . itParams . isWarming
%~ const True
timelastused = it ^. ldtValue . _1 . itTimeLastUsed
g x = (x, WdWdBurstFireRepetition (_crID cr) (it ^?! ldtValue . _1 . itLocation . ilInvID))
timelastused = it ^. itTimeLastUsed
g x = (x, WdWdBurstFireRepetition (_crID cr) invid)
getVolleyBurst :: (Random a, RandomGen b, Num a) => Int -> b -> ([a], b)
getVolleyBurst i g =
let (is, g') = runState (replicateM (i -1) (state $ randomR (0, 6))) g
in (scanl1 (+) is, g')
heldEffectMuzzles :: LDTree ItemLink OItem -> Creature -> World -> World
heldEffectMuzzles t cr w =
heldEffectMuzzles :: LocationLDT ItemLink OItem -> Creature -> World -> World
heldEffectMuzzles loc cr w =
setusetime . doHeldUseEffect t cr
. uncurry (applyCME (_ldtValue t ^. _1) cr)
. foldl' (useLoadedAmmo t cr) (False, w)
$ loadedmuzzles
where
t = loc ^. locLDT
(_, loadedmuzzles) = mapAccumR loadMuzzle t . itemMuzzles $ t ^. ldtValue . _1
setusetime =
cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itid . itTimeLastUsed
@@ -404,7 +405,7 @@ applyCME itm cr cme
-- the above is quite hacky for now
_ -> failsound
where
coolstart = fromMaybe 0 $ itemTriggerType itm ^? coolStart
coolstart = fromMaybe 0 $ baseItemTriggerType itm ^? coolStart
itid = itm ^?! itLocation . ilInvID -- unsafe
spush = maybe 0 itemSidePush $ itm ^? itType . ibtHeld
failsound w = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
@@ -1218,7 +1219,7 @@ mcShootLaser _ mc =
mcShootAuto :: Item -> Machine -> World -> World
mcShootAuto itm mc w
| Just (AutoTrigger rate) <- itemTriggerType <$> mc ^? mcType . mctTurret . tuWeapon -- . itUse . heldDelay
| Just (AutoTrigger rate) <- baseItemTriggerType <$> mc ^? mcType . mctTurret . tuWeapon -- . itUse . heldDelay
, w ^. cWorld . lWorld . lClock - rate > lastused =
w
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
+1 -1
View File
@@ -43,7 +43,7 @@ itemInternalValue itm
maybeWarmupStatus :: Item -> Maybe String
maybeWarmupStatus it = case itemTriggerType it ^? warmMax of
maybeWarmupStatus it = case baseItemTriggerType it ^? warmMax of
Nothing -> Nothing
--Just m -> case m - (_warmTime . _heldDelay $ _itUse it) of
Just m -> case m - _wTime (_itParams it) of
+1 -1
View File
@@ -91,7 +91,7 @@ itemToBreakLists itm itmf = case (itm ^. itType, itmf) of
_ -> ([], [])
getAutoSpringLinks :: Item -> [(ItemStructuralFunction, ItemLink)]
getAutoSpringLinks itm = case itemTriggerType itm of
getAutoSpringLinks itm = case baseItemTriggerType itm of
HammerTrigger _ -> [(MakeAutoSF, MakeAutoLink)]
_ -> []
+3 -3
View File
@@ -9,7 +9,6 @@ import Dodge.Item.Grammar
import Dodge.Creature.Impulse.UseItem
import Dodge.BlBl
import Dodge.HeldUse
import Dodge.Data.DoubleTree
import Data.Foldable
import qualified Data.Map.Strict as M
import Data.Maybe
@@ -45,8 +44,9 @@ doWdWd we = case we of
UseInvItem invid pt -> \w -> fromMaybe w (useItem invid pt w)
WdWdBurstFireRepetition cid invid -> \w -> fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix cid
itree <- allInvLocs (cr ^. crInv) ^? ix invid . _2 . locLDT
return $ heldEffectMuzzles itree cr w
--itree <- allInvLocs (cr ^. crInv) ^? ix invid . _2 . locLDT
loc <- allInvLocs (cr ^. crInv) ^? ix invid . _2
return $ heldEffectMuzzles loc cr w
accessTerminal :: Maybe Int -> World -> World
accessTerminal mtmid w = fromMaybe w $ do