Improve sensor terminal messages

This commit is contained in:
2025-09-18 10:18:53 +01:00
parent 1564b1c721
commit 4494e47b43
9 changed files with 176 additions and 156 deletions
+3 -4
View File
@@ -3,7 +3,7 @@
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module Dodge.Data.Machine.Sensor (module Dodge.Data.Machine.Sensor) where
module Dodge.Data.Machine.Sensor where
import Control.Lens
import Data.Aeson
@@ -18,7 +18,6 @@ data SensorType
| PhysicalSensor
deriving (Eq, Ord, Show, Read, Bounded, Enum)
data DamageSensor = DamSensor
{ _sensAmount :: Int
, _sensType :: SensorType
@@ -27,10 +26,10 @@ data DamageSensor = DamSensor
data ProximitySensor = ProxSensor
{ _proxSensorType :: ProximitySensorType
, _proxToggle :: Bool
, _proxToggle :: Maybe Bool
}
data ProximitySensorType
data ProximitySensorType
= SensorWithRequirement ProximityRequirement
| NoItemZone [Point2]
+1
View File
@@ -54,6 +54,7 @@ data TCom
data TmWdWd
= TmWdId
| TmWdWdPowerDownTerminal
| TmWdWdLeaveTerminal
| TmWdWdDeactivateTerminal
| TmWdWdfromWdWd WdWd
| TmWdWdTermSound SoundID
+1 -1
View File
@@ -66,5 +66,5 @@ defaultProximitySensor :: ProximitySensor
defaultProximitySensor =
ProxSensor
{ _proxSensorType = SensorWithRequirement $ RequireHealth 0
, _proxToggle = False
, _proxToggle = Nothing
}
-2
View File
@@ -20,8 +20,6 @@ textInputFocus w = case w ^. hud . subInventory of
DisplayTerminal{_termID = tmid} -> case w ^? cWorld . lWorld . terminals . ix tmid . tmStatus . tiText of
Just _ -> return $ cWorld . lWorld . terminals . ix tmid . tmStatus . tiText
Nothing -> Nothing
-- DisplayTerminal{_termID = tmid} -> return
-- $ cWorld . lWorld . terminals . ix tmid . tmStatus . tiText
_ -> Nothing
where
he = w ^. hud
+23 -9
View File
@@ -103,7 +103,7 @@ mcDamSensorTriggerUpdate se mc = fromMaybe id $ do
mcProxSensorTriggerUpdate :: ProximitySensor -> Machine -> World -> World
mcProxSensorTriggerUpdate se mc = fromMaybe id $ do
trid <- mc ^? mcMounts . ix OTTrigger
bval <- se ^? proxToggle
bval <- se ^? proxToggle . _Just
return $ cWorld . lWorld . triggers . at trid ?~ bval
mcTriggerVal :: DamageSensor -> Maybe Bool
@@ -142,18 +142,25 @@ mcProxSensorUpdate se mc = case se ^. proxSensorType of
mcNoItemsTest :: Machine -> [Point2] -> World -> World
mcNoItemsTest mc ps w
| t && not (mc ^?! mcType . _McProxSensor . proxToggle) =
w & mcsenslens . proxToggle .~ True
| t && (falsetog || notog) =
w & mcsenslens . proxToggle ?~ True
& playsound dedaS
| not t && (mc ^?! mcType . _McProxSensor . proxToggle) =
w & mcsenslens . proxToggle .~ False
& mctermlens . tmFutureLines .:~ makeTermLine "SENSOR SUCCESS: ZONE CLEAR"
| not t && (truetog || notog) =
w & mcsenslens . proxToggle ?~ False
& playsound dedumS
& mctermlens . tmFutureLines .:~ makeTermLine "SENSOR FAIL: ITEM IN ZONE"
| otherwise = w
where
truetog = mc ^? mcType . _McProxSensor . proxToggle . _Just == Just True
falsetog = mc ^? mcType . _McProxSensor . proxToggle . _Just == Just False
notog = null (mc ^? mcType . _McProxSensor . proxToggle . _Just)
&& pointInPoly (cr ^. crPos) qs
t = ((cr ^. crInv == mempty) || not (pointInPoly (cr ^. crPos) qs))
&& not (any ((`pointInPoly` qs) . _flItPos) (w ^. cWorld . lWorld . floorItems))
cr = w ^?! cWorld . lWorld . creatures . ix 0
mcsenslens = cWorld . lWorld . machines . ix (_mcID mc) . mcType . _McProxSensor
mctermlens = cWorld . lWorld . terminals . ix (mc ^?! mcMounts . ix OTTerminal)
playsound sid = soundContinue (MachineAltSound (_mcID mc)) (_mcPos mc) sid Nothing
qs = f ps
f = fmap ((+ _mcPos mc) . rotateV (_mcDir mc))
@@ -161,17 +168,24 @@ mcNoItemsTest mc ps w
mcProximitySensorUpdate
:: Machine -> ProximitySensor -> ProximityRequirement -> World -> World
mcProximitySensorUpdate mc sens pr w
| sens ^. proxToggle || dist (_crPos ycr) (_mcPos mc) > 40 = w
| truetog || dist (_crPos ycr) (_mcPos mc) > 40 = w
| mcProxTest w pr =
w
& mcsenslens . proxToggle .~ True
& mcsenslens . proxToggle ?~ True
& playsound dedaS
& mctermlens . tmFutureLines .:~ makeTermLine "SENSOR SUCCESS!"
| otherwise =
& mctermlens . tmFutureLines <>~
[makeTermLine "SENSOR SUCCESS, DEACTIVATED" ]
<> tlSetStatus (TerminalPressTo "QUIT")
<> tlDoEffect TmWdWdLeaveTerminal
| notog =
w & playsound dedumS
& mcsenslens . proxToggle ?~ False
& mctermlens . tmFutureLines
.:~ makeTermLine ( "SENSOR FAIL: REQUIRES " ++ sensorReqToString pr)
| otherwise = w
where
truetog = sens ^? proxToggle . _Just == Just True
notog = null (sens ^? proxToggle . _Just)
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
+1 -1
View File
@@ -20,4 +20,4 @@ analyser pst pslight psmc = extTrigLitPos pslight $ \tp ->
defaultMachine & mcColor .~ aquamarine
& mcType .~ McTerminal
& mcHP .~ 100
& mcType .~ McProxSensor (ProxSensor pst False)
& mcType .~ McProxSensor (ProxSensor pst Nothing)
+8
View File
@@ -6,6 +6,7 @@ module Dodge.WorldEffect (
doTmWdWd,
) where
import Dodge.Terminal
import NewInt
import Control.Monad
import Data.Foldable
@@ -93,6 +94,7 @@ doTmWdWd tmwdwd = case tmwdwd of
TmWdId -> const id
TmWdWdPowerDownTerminal -> resetTerminal TerminalOff
TmWdWdDeactivateTerminal -> resetTerminal TerminalDeactivated
TmWdWdLeaveTerminal -> leaveResetQuitTerminal
TmWdWdTermSound sid -> \tm w -> fromMaybe w $ do
tpos <- w ^? cWorld . lWorld . buttons . ix (_tmButtonID tm) . btPos
return $ soundStart TerminalSound tpos sid Nothing w
@@ -105,6 +107,12 @@ resetTerminal x tm =
. (cWorld . lWorld . terminals . ix (_tmID tm) . tmDisplayedLines .~ [])
. exitTerminalSubInv
leaveResetQuitTerminal :: Terminal -> World -> World
leaveResetQuitTerminal tm =
(cWorld . lWorld . terminals . ix (_tmID tm) . tmFutureLines
.~ (tlSetStatus (TerminalPressTo "QUIT")) <> tlDoEffect TmWdWdLeaveTerminal)
. exitTerminalSubInv
exitTerminalSubInv :: World -> World
exitTerminalSubInv w = case w ^? hud . subInventory . termID of
Just _ -> w & hud . subInventory .~ NoSubInventory