First implementation of no-item-zone sensor
This commit is contained in:
+41
-17
@@ -111,9 +111,15 @@ mcTriggerVal se = Just $ _sensAmount se > _sensThreshold se
|
||||
|
||||
mcPlaySound :: Machine -> World -> World
|
||||
mcPlaySound mc w = case _mcType mc of
|
||||
McTerminal | d < 100 ->
|
||||
soundContinueVol (1 -0.01 * d)
|
||||
(MachineSound mid) (_mcPos mc) fridgeHumS (Just 2) w
|
||||
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)
|
||||
@@ -121,23 +127,37 @@ mcPlaySound mc w = case _mcType mc of
|
||||
|
||||
mcApplyDamage :: [Damage] -> Machine -> World -> World
|
||||
mcApplyDamage ds mc = case mc ^? mcType . _McDamSensor of
|
||||
Nothing ->
|
||||
mcpointer
|
||||
%~ ((mcDamage .~ []) . (mcHP -~ sum (map _dmAmount ds)))
|
||||
_ ->
|
||||
mcpointer
|
||||
%~ (mcDamage .~ [])
|
||||
Nothing -> mcpointer %~ ((mcDamage .~ []) . (mcHP -~ sum (map _dmAmount ds)))
|
||||
_ -> mcpointer %~ (mcDamage .~ [])
|
||||
where
|
||||
mcpointer = cWorld . lWorld . machines . ix (_mcID mc)
|
||||
|
||||
mcDamSensorUpdate :: DamageSensor -> Machine -> World -> World
|
||||
mcDamSensorUpdate se mc w = senseDamage (_sensThreshold se) (_sensType se) mc w
|
||||
mcDamSensorUpdate se = senseDamage (_sensThreshold se) (_sensType se)
|
||||
|
||||
mcProxSensorUpdate :: ProximitySensor -> Machine -> World -> World
|
||||
mcProxSensorUpdate se mc = case se ^. proxRequirement of
|
||||
RequireNoItems xs -> id
|
||||
RequireNoItems xs -> mcNoItemsTest mc xs
|
||||
_ -> mcProximitySensorUpdate mc se
|
||||
|
||||
mcNoItemsTest :: Machine -> [Point2] -> World -> World
|
||||
mcNoItemsTest mc ps w
|
||||
| t && not (mc ^?! mcType . _McProxSensor . proxToggle) =
|
||||
w & mcsenslens . proxToggle .~ True
|
||||
& playsound dedaS
|
||||
| not t && (mc ^?! mcType . _McProxSensor . proxToggle) =
|
||||
w & mcsenslens . proxToggle .~ False
|
||||
& playsound dedumS
|
||||
| otherwise = w
|
||||
where
|
||||
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
|
||||
playsound sid = soundContinue (MachineAltSound (_mcID mc)) (_mcPos mc) sid Nothing
|
||||
qs = f ps
|
||||
f = fmap ((+ _mcPos mc) . rotateV (_mcDir mc))
|
||||
|
||||
mcProximitySensorUpdate :: Machine -> ProximitySensor -> World -> World
|
||||
mcProximitySensorUpdate mc sens w
|
||||
| sens ^. proxToggle || dist (_crPos ycr) (_mcPos mc) > 40 = w
|
||||
@@ -146,10 +166,13 @@ mcProximitySensorUpdate mc sens w
|
||||
& mcsenslens . proxToggle .~ True
|
||||
& playsound dedaS
|
||||
& mctermlens . tmFutureLines .:~ makeTermLine "SENSOR SUCCESS!"
|
||||
| otherwise = w & playsound dedumS
|
||||
& mctermlens . tmFutureLines
|
||||
.:~ makeTermLine ("SENSOR FAIL: REQUIRES "
|
||||
++ sensorReqToString (mc ^?! mcType . _McProxSensor . proxRequirement))
|
||||
| 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
|
||||
@@ -169,8 +192,9 @@ mcProxTest mc w = \case
|
||||
any
|
||||
(\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 ((`pointInPoly` f ps) . _flItPos) (w ^. cWorld . lWorld . floorItems) )
|
||||
RequireNoItems ps ->
|
||||
(w ^?! cWorld . lWorld . creatures . ix 0 . crInv == mempty)
|
||||
&& not (any ((`pointInPoly` f ps) . _flItPos) (w ^. cWorld . lWorld . floorItems))
|
||||
where
|
||||
cr = you w
|
||||
f = fmap ((+ _mcPos mc) . rotateV (_mcDir mc))
|
||||
|
||||
Reference in New Issue
Block a user