Move machine update into outside function

This commit is contained in:
2022-07-14 21:01:53 +01:00
parent ad33ddd569
commit 5463328d41
13 changed files with 130 additions and 92 deletions
+18 -2
View File
@@ -26,6 +26,7 @@ updateMachine mc
| _mcHP mc < 1 = destroyMachine mc
| otherwise = mcApplyDamage (_mcDamage mc) mc
. mcPlaySound mc
. mcSensorTriggerUpdate mc
. mcTurretUpdate mc
. mcSensorUpdate mc
@@ -100,6 +101,19 @@ updateTurret rotSpeed mc w
| closeFireAngle = machines . ix mcid . mcType . tuFireTime .~ 20
| otherwise = machines . ix mcid . mcType . tuFireTime %~ (max 0 . subtract 1)
mcSensorTriggerUpdate :: Machine -> World -> World
mcSensorTriggerUpdate mc = fromMaybe id $ do
trid <- mc ^? mcMounts . ix ObTrigger
bval <- mcTriggerVal mc
return $ triggers . ix trid .~ const bval
mcTriggerVal :: Machine -> Maybe Bool
mcTriggerVal mc = case mc ^. mcSensor of
NoSensor -> Nothing
s@ProximitySensor{} -> s ^? sensToggle
s@SensorToggleAmount{} -> Just $ (_sensAmount s) > 900
mcPlaySound :: Machine -> World -> World
mcPlaySound mc w = case _mcCloseSound mc of
Just sid | d < 200 -> soundContinueVol (1-0.005*d) (MachineSound mid) (_mcPos mc) sid (Just 2) w
@@ -109,8 +123,10 @@ mcPlaySound mc w = case _mcCloseSound mc of
mid = _mcID mc
mcApplyDamage :: [Damage] -> Machine -> World -> World
mcApplyDamage ds mc = machines . ix (_mcID mc) %~
( (mcDamage .~ []) . (mcHP -~ sum (map _dmAmount ds)) )
mcApplyDamage ds mc = case _mcSensor mc of
NoSensor -> machines . ix (_mcID mc) %~
( (mcDamage .~ []) . (mcHP -~ sum (map _dmAmount ds)) )
_ -> id
mcSensorUpdate :: Machine -> World -> World
mcSensorUpdate mc w = case _mcSensor mc of