Change weapon fixed rate delay not to require update every tick

This commit is contained in:
2025-01-04 21:06:07 +00:00
parent 39e3e4ae00
commit 698bb081dd
9 changed files with 877950 additions and 550608 deletions
+10 -15
View File
@@ -91,8 +91,9 @@ hammerCheck pt f it cr w = case it ^? ldtValue . itUse . heldTriggerType of
-- | Applies a world effect after an item use cooldown check.
useTimeCheck :: ChainEffect
useTimeCheck f item cr w = case item ^? ldtValue . itUse . heldDelay of
Just (FixedRate _ 0) -> f item cr $ setUseRate w
Just (FixedRate _ _) -> w
Just (FixedRate rate lastused)
| w ^. cWorld . lWorld . lClock - rate > lastused -> f item cr $ setUseRate w
Just FixedRate {} -> w
Just (WarmUpNoDelay wt wm ws)
| wt < wm ->
w
@@ -107,12 +108,11 @@ useTimeCheck f item cr w = case item ^? ldtValue . itUse . heldDelay of
where
cid = _crID cr
setUseRate =
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . rateTime
+~ userate
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itUse . heldDelay . rateTimeLastUsed
.~ w ^. cWorld . lWorld . lClock
-- the following is unsafe, but if ilInvID isn't correctly set we probably
-- will have problems elsewhere also
itRef = item ^?! ldtValue . itLocation . ilInvID
userate = fromMaybe 0 $ item ^? ldtValue . itUse . heldDelay . rateMax
heldEffectMuzzles :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
heldEffectMuzzles t cr w =
@@ -617,21 +617,16 @@ mcShootLaser _ mc = cWorld . lWorld . lasers .:~ lasRayAt yellow dam phasev pos
mcShootAuto :: Item -> Machine -> World -> World
mcShootAuto itm mc w
| Just (FixedRate x 0) <- mc ^? mcType . mctTurret . tuWeapon . itUse . heldDelay =
| Just (FixedRate rate lastused) <- mc ^? mcType . mctTurret . tuWeapon . itUse . heldDelay
, w ^. cWorld . lWorld . lClock - rate > lastused =
w
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
. itUse
. heldDelay
. rateTime
.~ x
. rateTimeLastUsed
.~ w ^. cWorld . lWorld . lClock
& makeBullet defaultBullet itm pos dir
| otherwise =
w
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
. itUse
. heldDelay
. rateTime
-~ 1
| otherwise = w
where
pos = _mcPos mc +.+ 20 *.* unitVectorAtAngle dir
dir = mc ^?! mcType . _McTurret . tuDir