Simplify analyser machines somewhat

This commit is contained in:
2025-09-16 21:41:26 +01:00
parent 203919933c
commit 81d6727d8e
21 changed files with 418 additions and 464 deletions
+9 -5
View File
@@ -17,12 +17,16 @@ drawMachine lw mc = case _mcType mc of
McStatic -> mempty
McTerminal -> terminalSPic lw mc
McTurret tu -> drawBaseMachine 20 mc <> drawTurret lw tu mc
McSensor se -> drawBaseMachine 25 mc <> drawSensor se mc
McDamSensor se -> drawBaseMachine 25 mc <> drawDamSensor se mc
McProxSensor se -> drawBaseMachine 25 mc <> drawProxSensor se mc
drawSensor :: Sensor -> Machine -> SPic
drawSensor sens = case sens of
DamageSensor{_sensDraw = pcds} -> sensorSPic pcds
ProximitySensor{} -> const mempty
drawDamSensor :: DamageSensor -> Machine -> SPic
drawDamSensor sens = case sens of
DamSensor{_sensDraw = pcds} -> sensorSPic pcds
drawProxSensor :: ProximitySensor -> Machine -> SPic
drawProxSensor sens = case sens of
ProxSensor{} -> const mempty
terminalSPic :: LWorld -> Machine -> SPic
terminalSPic lw = noPic . terminalShape lw
+42 -42
View File
@@ -24,14 +24,15 @@ updateMachine mc
| otherwise =
mcApplyDamage (_mcDamage mc) mc
. mcPlaySound mc
. mcTypeUpdate mc
. mcTypeUpdate mc (_mcType mc)
mcTypeUpdate :: Machine -> World -> World
mcTypeUpdate mc = case mc ^. mcType of
mcTypeUpdate :: Machine -> MachineType -> World -> World
mcTypeUpdate mc = \case
McStatic -> id
McTerminal -> terminalScreenGlow mc
McTurret tu -> updateTurret (_tuTurnSpeed tu) mc
McSensor se -> mcSensorTriggerUpdate se mc . mcSensorUpdate se mc
McDamSensor se -> mcDamSensorTriggerUpdate se mc . mcDamSensorUpdate se mc
McProxSensor se -> mcProxSensorTriggerUpdate se mc . mcProxSensorUpdate se mc
terminalScreenGlow :: Machine -> World -> World
terminalScreenGlow mc w = fromMaybe w $ do
@@ -93,29 +94,33 @@ mcUseItem mc w = fromMaybe w $ do
guard (_tuFireTime tu > 0)
return $ mcUseHeld hit it mc w
mcSensorTriggerUpdate :: Sensor -> Machine -> World -> World
mcSensorTriggerUpdate se mc = fromMaybe id $ do
mcDamSensorTriggerUpdate :: DamageSensor -> Machine -> World -> World
mcDamSensorTriggerUpdate se mc = fromMaybe id $ do
trid <- mc ^? mcMounts . ix OTTrigger
bval <- mcTriggerVal se
return $ cWorld . lWorld . triggers . ix trid ||~ bval
mcTriggerVal :: Sensor -> Maybe Bool
mcTriggerVal se = case se of
ProximitySensor{} -> se ^? sensToggle
DamageSensor{} -> Just $ _sensAmount se > _sensThreshold se
mcProxSensorTriggerUpdate :: ProximitySensor -> Machine -> World -> World
mcProxSensorTriggerUpdate se mc = fromMaybe id $ do
trid <- mc ^? mcMounts . ix OTTrigger
bval <- se ^? proxToggle
return $ cWorld . lWorld . triggers . at trid ?~ bval
mcTriggerVal :: DamageSensor -> Maybe Bool
mcTriggerVal se = Just $ _sensAmount se > _sensThreshold se
mcPlaySound :: Machine -> World -> World
mcPlaySound mc w = case _mcCloseSound mc of
Just sid
| d < 100 ->
soundContinueVol (1 -0.01 * d) (MachineSound mid) (_mcPos mc) sid (Just 2) w
mcPlaySound mc w = case _mcType mc of
McTerminal | d < 100 ->
soundContinueVol (1 -0.01 * d)
(MachineSound mid) (_mcPos mc) fridgeHumS (Just 2) w
_ -> w
where
d = max 0 (dist (_crPos $ you w) (_mcPos mc) - 100)
mid = _mcID mc
mcApplyDamage :: [Damage] -> Machine -> World -> World
mcApplyDamage ds mc = case mc ^? mcType . _McSensor of
mcApplyDamage ds mc = case mc ^? mcType . _McDamSensor of
Nothing ->
mcpointer
%~ ((mcDamage .~ []) . (mcHP -~ sum (map _dmAmount ds)))
@@ -125,36 +130,31 @@ mcApplyDamage ds mc = case mc ^? mcType . _McSensor of
where
mcpointer = cWorld . lWorld . machines . ix (_mcID mc)
mcSensorUpdate :: Sensor -> Machine -> World -> World
mcSensorUpdate se mc w = case se of
s@DamageSensor{} -> senseDamage (_sensThreshold se) (_sensType s) mc w
ProximitySensor {_proxRequirement = x} -> mcProximitySensorUpdate mc x w
mcDamSensorUpdate :: DamageSensor -> Machine -> World -> World
mcDamSensorUpdate se mc w = senseDamage (_sensThreshold se) (_sensType se) mc w
mcProximitySensorUpdate :: Machine -> ProximityRequirement -> World -> World
mcProximitySensorUpdate mc x w = case ( _proxStatus sens
, _sensToggle sens
, mcProxTest mc w x
, dist (_crPos ycr) (_mcPos mc) < _proxDist sens
) of
(_, True, _, _) -> w
(_, False, True, True) ->
mcProxSensorUpdate :: ProximitySensor -> Machine -> World -> World
mcProxSensorUpdate se mc = case se ^. proxRequirement of
RequireNoItems xs -> id
_ -> mcProximitySensorUpdate mc se
mcProximitySensorUpdate :: Machine -> ProximitySensor -> World -> World
mcProximitySensorUpdate mc sens w
| sens ^. proxToggle || dist (_crPos ycr) (_mcPos mc) > 40 = w
| mcProxTest mc w (sens ^. proxRequirement) =
w
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . _McSensor . sensToggle .~ True
& mcsenslens . proxToggle .~ True
& playsound dedaS
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . _McSensor . proxStatus .~ IsClose
& cWorld . lWorld . terminals . ix (mc ^?! mcMounts . ix OTTerminal) . tmFutureLines .:~ makeTermLine "SENSOR SUCCESS!"
(NotClose, _, False, True) ->
w & playsound dedumS
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . _McSensor . proxStatus .~ IsClose
& cWorld . lWorld . terminals . ix (mc ^?! mcMounts . ix OTTerminal) . tmFutureLines
.:~ makeTermLine ("SENSOR FAIL: REQUIRES " ++ sensorReqToString (mc ^?! mcType . _McSensor . proxRequirement))
(_, _, _, False) ->
w & cWorld . lWorld . machines . ix (_mcID mc) . mcType . _McSensor . proxStatus .~ NotClose
_ -> w
& mctermlens . tmFutureLines .:~ makeTermLine "SENSOR SUCCESS!"
| otherwise = w & playsound dedumS
& mctermlens . tmFutureLines
.:~ makeTermLine ("SENSOR FAIL: REQUIRES "
++ sensorReqToString (mc ^?! mcType . _McProxSensor . proxRequirement))
where
mctermlens = cWorld . lWorld . terminals . ix (mc ^?! mcMounts . ix OTTerminal)
mcsenslens = cWorld . lWorld . machines . ix (_mcID mc) . mcType . _McProxSensor
playsound sid = soundContinue (MachineAltSound (_mcID mc)) (_mcPos mc) sid Nothing
ycr = you w
sens = mc ^?! mcType . _McSensor
sensorReqToString :: ProximityRequirement -> String
sensorReqToString = \case
@@ -170,7 +170,7 @@ mcProxTest mc w = \case
(\itm -> _itType itm == ct)
((\k -> w ^?! cWorld . lWorld . items . ix k) <$> _crInv cr)
RequireNoItems ps -> (w ^?! cWorld . lWorld . creatures . ix 0 . crInv == mempty)
&& not (any ((`pointInPolygon` f ps) . _flItPos) (w ^. cWorld . lWorld . floorItems) )
&& not (any ((`pointInPoly` f ps) . _flItPos) (w ^. cWorld . lWorld . floorItems) )
where
cr = you w
f = fmap ((+ _mcPos mc) . rotateV (_mcDir mc))
@@ -180,7 +180,7 @@ senseDamage threshold dt mc =
(cWorld . lWorld . machines . ix mcid %~ upmc)
. updatels
where
upmc = mcType . _McSensor . sensAmount %~ min (100 * threshold) . max 0 . (+ newsense)
upmc = mcType . _McDamSensor . sensAmount %~ min (100 * threshold) . max 0 . (+ newsense)
mcid = _mcID mc
newsense
| x > 0 = x
@@ -188,7 +188,7 @@ senseDamage threshold dt mc =
where
f = sensorTypeDamages dt
x = sum . map _dmAmount $ filter f (_mcDamage mc)
ni = fromIntegral (mc ^?! mcType . _McSensor . sensAmount) / fromIntegral threshold
ni = fromIntegral (mc ^?! mcType . _McDamSensor . sensAmount) / fromIntegral threshold
updatels = fromMaybe id $ do
lsid <- mc ^? mcMounts . ix OTLightSource
return $ cWorld . lWorld . lightSources . ix lsid . lsParam . lsCol .~ V3 ni ni ni