Types.icl 22.1 KB
Newer Older
1
implementation module C2.Apps.ShipAdventure.Types
2

3
//import iTasks
4

Bas Lijnse's avatar
Bas Lijnse committed
5 6 7 8
import iTasks.Internal.Tonic
import iTasks.Extensions.Admin.TonicAdmin
import iTasks.Extensions.SVG.SVGEditor
//import Graphics.Scalable
9 10 11
import qualified Data.List as DL
from Data.Func import mapSt
import StdArray
Bas Lijnse's avatar
Bas Lijnse committed
12
import Data.Data, Data.Either
13 14
import qualified Data.IntMap.Strict as DIS
import qualified Data.Map as DM
15
import Data.Map.GenJSON
16 17 18 19 20 21 22 23 24 25 26
import qualified Data.Set as DS
import Text.HTML

import C2.Framework.MapEnvironment
from C2.Framework.Logging import addLog
import C2.Apps.ShipAdventure.PathFinding
import C2.Apps.ShipAdventure.Images
import C2.Apps.ShipAdventure.Editor

derive gLexOrd CableType, Capability
derive class iTask ObjectType, ActorStatus, Availability, ActorHealth, ActorEnergy, DeviceType, SectionStatus
Mart Lubbers's avatar
Mart Lubbers committed
27 28 29 30 31 32 33
derive class iTask Cable, Priority, Network, Device, CableType, DeviceKind, CommandAim, Capability, CapabilityExpr

derive gEditor Set
derive gDefault Set
derive gText Set
derive JSONEncode Set
derive JSONDecode Set
34

Steffen Michels's avatar
Steffen Michels committed
35
derive JSEncode Map2D, Coord2D, Map, IntMap, Dir, User, Section, Borders, Border, MapAction, Object, Actor
Bas Lijnse's avatar
Bas Lijnse committed
36 37
derive JSEncode ObjectType, ActorStatus, Availability, ActorHealth, ActorEnergy, DeviceType, SectionStatus
derive JSEncode Cable, Priority, Network, Device, CableType, DeviceKind, CommandAim, Set, Capability, CapabilityExpr
Steffen Michels's avatar
Steffen Michels committed
38 39 40 41
derive JSDecode Map2D, Coord2D, Map, IntMap, Dir, User, Section, Borders, Border, MapAction, Object, Actor
derive JSDecode ObjectType, ActorStatus, Availability, ActorHealth, ActorEnergy, DeviceType, SectionStatus
derive JSDecode Cable, Priority, Network, Device, CableType, DeviceKind, CommandAim, Set, Capability, CapabilityExpr

Bas Lijnse's avatar
Bas Lijnse committed
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
// std overloading instances

//instance == Object      where (==) o1 o2 = o1 === o2
instance == ObjectType  where (==) o1 o2 = o1 === o2
instance == Priority    where (==) o1 o2 = o1 === o2
instance toString ObjectType where
  toString FireExtinguisher = "Extinguiser"
  toString FireBlanket      = "Blanket"
  toString Plug             = "Plug"

instance toString Device
where toString {Device | description} = description

instance toString SectionStatus where
  toString NormalStatus  = "NormalStatus"
  toString HasSomeWater  = "HasSomeWater"
  toString IsFlooded     = "IsFlooded"
  toString HasSmoke      = "HasSmoke"
  toString HasSmallFire  = "HasSmallFire"
  toString HasMediumFire = "HasMediumFire"
  toString HasBigFire    = "HasBigFire"


instance < CableType where
  (<) l r = case l =?= r of
              LT -> True
              _  -> False

instance < Capability where
  (<) l r = case l =?= r of
              LT -> True
              _  -> False

instance == CableType where
  (==) l r = l === r

instance == Device where
  (==) l r = l === r

instance == DeviceType where
  (==) l r = l === r

instance == DeviceKind where
  (==) l r = l === r

instance == Capability where
  (==) l r = l === r

// shared stores:

myUserActorMap :: UserActorShare ObjectType ActorStatus
myUserActorMap = sharedStore "myUserActorMap" 'DM'.newMap

96
myStatusMap :: SimpleSDSLens MySectionStatusMap
97 98
myStatusMap = sharedStore "myStatusMap" 'DM'.newMap

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
99
statusInSectionShare :: SDSLens Coord3D SectionStatus SectionStatus
100 101
statusInSectionShare = mapLens "statusInSectionShare" myStatusMap (Just NormalStatus)

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
102
deviceKindsForCapability :: SDSLens Capability CapabilityExpr CapabilityExpr
103 104 105
deviceKindsForCapability
  = mapLens "deviceKindsForCapability" capabilityMap Nothing

106
myInventoryMap :: SimpleSDSLens MySectionInventoryMap
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
myInventoryMap = sharedStore "myInventoryMap" 'DM'.newMap

viewDisabledDevices :: Task ()
viewDisabledDevices = viewSharedInformation "Disabled devices" [ViewAs (\(nw, ds) -> map toPPDevice (allDisabledDevices ds nw))] (myNetwork |*| myDevices) @! ()

//manageDevices :: Bool -> Task ()
//manageDevices kitchen
  //| kitchen
  //=               get myNetwork
  //>>= \network -> viewDisabledDevices
  //>>*             [  OnAction (Action (if enabled "/Cut " "/Patch " +++ mkCableDesc roomNo cable) []) (always (if enabled (cutCableTask roomNo cable) (patchCableTask roomNo cable)))
                  //\\ cable  <- 'DIS'.elems network.cables
                  //,  (enabled, roomNo) <- fromMaybe [] ('DIS'.get cable.cableId network.cableMapping)
                  //]
  //| otherwise = viewDisabledDevices
  //where
  //ppNetwork :: !Network -> ((String, [(String, [PPDevice])]), (String, [Cable]))
  //ppNetwork network = (devicesView, cablesView)
    //where
    //cablesView :: (String, [Cable])
    //cablesView = ("Cables", 'DIS'.elems network.cables)

    //devicesView :: (String, [(String, [PPDevice])])
    //devicesView = ( "Devices"
                  //, [  ("Section " +++ toString roomNo, [toPPDevice d \\ d <- devices` | not (isDetector d.Device.deviceType.DeviceType.kind)])
                    //\\ (roomNo, devices`) <- 'DIS'.toList network.devices
                    //]
                  //)
  //mkCableDesc :: !Coord3D !Cable -> String
  //mkCableDesc roomNo {Cable | cableId, description}
    //= "'" +++ description +++ " " +++ toString cableId +++ "', room " +++ toString roomNo
  //cutCableTask :: !Coord3D !Cable -> Task ()
  //cutCableTask roomNo cable
    //= upd (cutCable roomNo cable.cableId) myNetwork >>| manageDevices kitchen
  //patchCableTask :: !Coord3D !Cable -> Task ()
  //patchCableTask roomNo cable
    //= upd (patchCable roomNo cable.cableId) myNetwork >>| manageDevices kitchen

allImperiledCommandAims :: !(IntMap Device) !CapabilityToDeviceKindMap ![CommandAim] !Network -> [CommandAim]
allImperiledCommandAims deviceMap caps cas network
  # allDisabledDevs     = allDisabledDevices deviceMap network
  # allDisabledDevKinds = map (\d -> d.Device.deviceType.DeviceType.kind) allDisabledDevs
  # disabledCaps        = allDisabledCapabilities allDisabledDevKinds caps
  = [ ca \\ ca <- cas
    | isImperiled disabledCaps ca]

isImperiled :: ![Capability] !CommandAim -> Bool
isImperiled disabledCaps {requiredCapabilities} = not ('DS'.null ('DS'.intersection ('DS'.fromList requiredCapabilities) ('DS'.fromList disabledCaps)))

allDisabledCapabilities :: ![DeviceKind] !CapabilityToDeviceKindMap -> [Capability]
allDisabledCapabilities disDevKinds caps
  = [ cap \\ (cap, devAlg) <- 'DM'.toList caps
    | canProvideCapability devAlg disDevKinds]

canProvideCapability :: !CapabilityExpr ![DeviceKind] -> Bool
canProvideCapability (DeviceExpr dk)  dks = 'DL'.isMember dk dks
canProvideCapability (CapAndExpr l r) dks = canProvideCapability l dks && canProvideCapability r dks
canProvideCapability (CapOrExpr  l r) dks = canProvideCapability l dks || canProvideCapability r dks

deviceIsEnabled :: !Device !(IntMap Device) !Network -> Bool
deviceIsEnabled dev deviceMap network
  = isEmpty [ d \\ d <- allDisabledDevices deviceMap network
            | d.Device.deviceId == dev.Device.deviceId]

allDisabledDevices :: !(IntMap Device) !Network -> [Device]
allDisabledDevices deviceMap network
  = 'DL'.nub (flatten [  devicesForCable cable deviceMap network
                      \\ cable <- 'DIS'.elems network.cables
                      |  not (isOperational cable.cableId network.cableMapping)
                      ])

// TODO Make more efficient
deviceIsDisabledInSection :: !Coord3D !Device !(IntMap Device) !Network -> Bool
deviceIsDisabledInSection roomNo device deviceMap network
  #! disabledDevs = disabledDevicesForSection roomNo deviceMap network
  = not (isEmpty [0 \\ dev <- disabledDevs | dev.Device.deviceId == device.Device.deviceId])

disabledDevicesForSection :: !Coord3D !(IntMap Device) !Network -> [Device]
disabledDevicesForSection roomNo deviceMap network
  = 'DL'.nub (flatten [  devicesForCableInSection roomNo cable deviceMap network
                      \\ cable <- 'DIS'.elems network.cables
                      |  not (isOperational cable.cableId network.cableMapping)
                      ])

devicesForCable :: !Cable !(IntMap Device) !Network -> [Device]
devicesForCable cable=:{cableId} deviceMap {cableMapping, devices}
  = 'DL'.nub [  device
             \\ (_, roomNo) <- fromMaybe [] ('DIS'.get cableId cableMapping)
             ,  deviceId    <- fromMaybe [] ('DM'.get roomNo devices)
             ,  Just device <- ['DIS'.get deviceId deviceMap]
             |  requiresCable cable device
             ]
  where
  // TODO Take resource quantity and redundancy into account
  requiresCable :: !Cable !Device -> Bool
  requiresCable { Cable | cableType} device
    = isJust ('DM'.get cableType device.Device.deviceType.DeviceType.requires)

devicesForCableInSection :: !Coord3D !Cable !(IntMap Device) !Network -> [Device]
devicesForCableInSection roomNo cable=:{cableId} deviceMap {cableMapping, devices}
  = 'DL'.nub [  device
             \\ (_, roomNo`) <- fromMaybe [] ('DIS'.get cableId cableMapping)
             ,  deviceId     <- fromMaybe [] ('DM'.get roomNo` devices)
             ,  Just device <- ['DIS'.get deviceId deviceMap]
             |  roomNo == roomNo` && requiresCable cable device
             ]
  where
  // TODO Take resource quantity and redundancy into account
  requiresCable :: !Cable !Device -> Bool
  requiresCable { Cable | cableType} device = isJust ('DM'.get cableType device.Device.deviceType.DeviceType.requires)

derive class iTask PPDevice, PPDeviceType

toPPDevice :: !Device -> PPDevice
toPPDevice { Device | description, deviceType, deviceId, inCables, outCables } = { PPDevice
                                                                                 | description = description
                                                                                 , deviceType  = toPPDeviceType deviceType
                                                                                 , deviceId    = deviceId
                                                                                 , inCables    = inCables
                                                                                 , outCables   = outCables
                                                                                 }

toPPDeviceType :: !DeviceType -> PPDeviceType
toPPDeviceType { DeviceType | kind, requires, produces } = { PPDeviceType
                                                           | kind     = kind
                                                           , requires = 'DM'.toList requires
                                                           , produces = 'DM'.toList produces
                                                           }

isOperational :: !CableId !(IntMap [(!Operational, !Coord3D)]) -> Bool
isOperational cableId cableMapping = and [b \\ (b, _) <- fromMaybe [] ('DIS'.get cableId cableMapping)]

smokeDetector :: DeviceType
smokeDetector  = { DeviceType
                 | kind     = SmokeDetector
                 , requires = 'DM'.fromList []
                 , produces = 'DM'.fromList []
                 }

heatSensor :: DeviceType
heatSensor     = { DeviceType
                 | kind     = HeatSensor
                 , requires = 'DM'.fromList []
                 , produces = 'DM'.fromList []
                 }

waterSensor :: DeviceType
waterSensor    = { DeviceType
                 | kind     = WaterSensor
                 , requires = 'DM'.fromList []
                 , produces = 'DM'.fromList []
                 }

mkAllSensors :: !DeviceId !DeviceId !DeviceId -> [Device]
mkAllSensors sd hs ws
  = [ { Device
      | description = "Smoke detector " +++ toString sd
      , deviceType  = smokeDetector
      , deviceId    = sd
      , inCables    = []
      , outCables   = []
      }
    , { Device
      | description = "Heat sensor " +++ toString hs
      , deviceType  = heatSensor
      , deviceId    = hs
      , inCables    = []
      , outCables   = []
      }
    , { Device
      | description = "Water sensor " +++ toString ws
      , deviceType  = waterSensor
      , deviceId    = ws
      , inCables    = []
      , outCables   = []
      }
    ]

// my physical mapping of the devices in a network

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
287
deviceWithIdShare :: SDSLens DeviceId Device Device
288 289
deviceWithIdShare = intMapLens "deviceWithIdShare" myDevices Nothing

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
290 291
deviceIdInNetworkSectionShare :: SDSLens Coord3D [DeviceId] [DeviceId]
deviceIdInNetworkSectionShare = sdsLens "deviceIdInNetworkSectionShare" (const ()) (SDSRead read) (SDSWrite write) (SDSNotify notify) Nothing myNetwork
292 293 294 295 296 297 298 299
  where
  read :: !Coord3D !Network -> MaybeError TaskException [DeviceId]
  read c3d network = Ok (fromMaybe [] ('DM'.get c3d network.devices))

  write :: !Coord3D !Network ![DeviceId] -> MaybeError TaskException (Maybe Network)
  write c3d network devIds = Ok (Just ({network & devices = 'DM'.put c3d devIds network.devices}))

  notify :: !Coord3D !Network ![DeviceId] -> SDSNotifyPred Coord3D
Mart Lubbers's avatar
Mart Lubbers committed
300
  notify c3d network devIds = \_ idx` -> c3d == idx`
301

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
302
devicesInSectionShare :: SDSSequence Coord3D [Device] [Device]
303
devicesInSectionShare
Bas Lijnse's avatar
Bas Lijnse committed
304
  = sdsSequence "devicesInSectionShare" id mkP2 (\_ _ -> Right mkR) (SDSWrite write1) (SDSWrite write2) deviceIdInNetworkSectionShare myDevices
305 306 307 308 309 310 311 312 313 314
  where
  mkP2 :: Coord3D [DeviceId] -> ()
  mkP2 _ devIds = () // fromMaybe [] ('DM'.get c3d network.devices)
  mkR :: !(![DeviceId], !IntMap Device) -> [Device]
  mkR (devIds, allDevs) = [dev \\ devId <- devIds, Just dev <- ['DIS'.get devId allDevs]]
  write1 :: Coord3D [DeviceId] ![Device] -> MaybeError TaskException (Maybe [DeviceId])
  write1 _ _ devices = Ok (Just [dev.Device.deviceId \\ dev <- devices])
  write2 :: Coord3D !(IntMap Device) ![Device] -> MaybeError TaskException (Maybe (IntMap Device))
  write2 _ deviceMap devices = Ok (Just (foldr (\device deviceMap -> 'DIS'.put device.Device.deviceId device deviceMap) deviceMap devices))

315
myDevices :: SimpleSDSLens (IntMap Device)
316 317 318 319 320 321 322 323
myDevices = sharedStore "myDevices" devices
  where
  devices = 'DIS'.fromList [  f dt
                           \\ i <- [1,4..420]
                            , dt <- mkAllSensors i (i + 1) (i + 2)]
  f :: !Device -> (!DeviceId, !Device)
  f dev = (dev.Device.deviceId, dev)

324
commandAims :: SimpleSDSLens [CommandAim]
325 326
commandAims = sharedStore "commandAims" []

327
capabilityMap :: SimpleSDSLens CapabilityToDeviceKindMap
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
capabilityMap = sharedStore "capabilityMap" ('DM'.fromList defaultList)
  where
  defaultList
    = [ (Propulsion,         (cap GasTurbine + cap DieselEngine))
      , (AirSensors,         (cap Apar + cap Radar))
      , (SurfaceSensors,     (cap Apar + cap Radar))
      , (SubsurfaceSensors,  (cap Sonar + cap Hydrophone))
      , (RadioCommunication, cap Radio)
      ]

instance + CapabilityExpr where
  (+) l r = CapOrExpr l r

instance * CapabilityExpr where
  (*) l r = CapAndExpr l r

cap :: DeviceKind -> CapabilityExpr
cap k = DeviceExpr k

347
myNetwork :: SimpleSDSLens Network
348 349 350 351 352 353 354
myNetwork = sharedStore "myNetwork"
  { Network
  | devices      = 'DM'.newMap
  , cables       = 'DIS'.newMap
  , cableMapping = 'DIS'.newMap
  }

355
myCables :: SimpleSDSLens (IntMap Cable)
Haye Böhm's avatar
Fix CI  
Haye Böhm committed
356
myCables = sdsProject (SDSLensRead read) (SDSLensWrite write) Nothing myNetwork
357 358 359 360 361 362
  where
  read :: !Network -> MaybeError TaskException (IntMap Cable)
  read { Network | cables } = Ok cables
  write :: !Network !(IntMap Cable) -> MaybeError TaskException (Maybe Network)
  write network cables      = Ok (Just {network & cables = cables})

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
363 364
cablesInSectionShare :: SDSLens Coord3D [Cable] [Cable]
cablesInSectionShare = sdsLens "cablesInSectionShare" (const ()) (SDSRead read) (SDSWrite write) (SDSNotify notify) Nothing myNetwork
365 366 367 368 369 370 371 372 373
  where
  read :: !Coord3D !Network -> MaybeError TaskException [Cable]
  read c3d network = Ok (cablesForSection c3d network)
  write :: !Coord3D !Network ![Cable] -> MaybeError TaskException (Maybe Network)
  write c3d network cables = Ok (Just (foldr (\cable network -> let coords = fromMaybe [] ('DIS'.get cable.cableId network.cableMapping)
                                                                    inList = not (isEmpty [0 \\ (_, c3d`) <- coords | c3d === c3d`])
                                                                in  if inList network
                                                                      {network & cableMapping = 'DIS'.put cable.cableId [(True, c3d) : coords] network.cableMapping}
                                                                ) network cables))
Mart Lubbers's avatar
Mart Lubbers committed
374 375
  notify :: !Coord3D !Network ![Cable] -> SDSNotifyPred Coord3D
  notify c3d oldNetwork newCables = \_ c3d` -> c3d === c3d`
376 377 378 379 380 381 382

cablesForSection :: !Coord3D !Network -> [Cable]
cablesForSection c3d { Network | cables, cableMapping }
  = case [cid \\ (cid, ms) <- 'DIS'.toList cableMapping, (_, c3d`) <- ms | c3d == c3d`] of
      [] -> []
      xs -> [cable \\ Just cable <- (map (\cid -> 'DIS'.get cid cables) xs)]

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
383
cableWithIdShare :: SDSLens CableId Cable Cable
384 385 386 387 388 389 390 391 392 393 394
cableWithIdShare = intMapLens "cableWithIdShare" myCables Nothing

cutCable :: !Coord3D !CableId !Network -> Network
cutCable roomNo cableId network = { network & cableMapping = 'DIS'.alter (fmap (\xs -> [(if (no == roomNo) False op, no) \\ (op, no) <- xs])) cableId network.cableMapping }

patchCable :: !Coord3D !CableId !Network -> Network
patchCable roomNo cableId network = { network & cableMapping = 'DIS'.alter (fmap (\xs -> [(if (no == roomNo) True op, no) \\ (op, no) <- xs])) cableId network.cableMapping }

inventoryInSectionShare :: FocusedSectionInventoryShare ObjectType
inventoryInSectionShare = mapLens "inventoryInSectionShare" myInventoryMap (Just 'DIS'.newMap)

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
395
allAvailableActors :: SDSLens () [(!Coord3D, !MyActor)] ()
396
allAvailableActors
397
  = /*toReadOnly */ (sdsProject (SDSLensRead readActors) (SDSBlindWrite \_. Ok Nothing) Nothing (sectionUsersShare |*| myUserActorMap))
398 399 400 401 402 403 404 405
  where
  readActors :: !(SectionUsersMap, UserActorMap ObjectType ActorStatus) -> MaybeError TaskException [(!Coord3D, !MyActor)]
  readActors (sectionUsersMap, userActorMap)
    = Ok [(c3d, a) \\ us <- 'DM'.elems sectionUsersMap
                    , u  <- us
                    , Just (c3d, a) <- [findUser u sectionUsersMap userActorMap]
                    | a.actorStatus.occupied === Available]

Haye Böhm's avatar
Fix CI  
Haye Böhm committed
406
allActiveAlarms :: SDSLens () [(!Coord3D, !SectionStatus)] ()
407
allActiveAlarms
408
  = /*toReadOnly */ (sdsProject (SDSLensRead readAlarms) (SDSBlindWrite \_. Ok Nothing) Nothing myStatusMap)
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
  where
  readAlarms :: !MySectionStatusMap -> MaybeError TaskException [(!Coord3D, !SectionStatus)]
  readAlarms statusMap = Ok [ (number, status) \\ (number, status) <- 'DM'.toList statusMap
                              | isHigh status]

// detectors setting

// setting and resetting of the detection systems
setSectionDetectors :: Task ()
setSectionDetectors
  = updateMapStatus KitchenMode
    >>* [OnValue (\tv -> case tv of
                           Value (SetStatus c3d st)   _ -> Just (setSectionStatus c3d st myStatusMap >>| setSectionDetectors)
                           Value (ToggleDoor c3d d)   _ -> Just (toggleDoor c3d d >>| setSectionDetectors)
                           Value (ToggleHop c3d c3d`) _ -> Just (toggleHop c3d c3d` >>| setSectionDetectors)
                           _                            -> Nothing
                 )]

updateMapStatus :: !RenderMode -> Task (MapAction SectionStatus)
updateMapStatus mode
  = /* project (\tv _ -> case tv of
                          Value x _ -> Just x
                          _         -> Nothing) sharedMapAction */
      (updateInformationWithShared "Map Status"
        [UpdateUsing id (const snd) editor]
        (disabledSections |*| maps2DShare |*| lockedExitsShare |*| lockedHopsShare |*| myInventoryMap |*| myStatusMap |*| sectionUsersShare |*| myUserActorMap |*| myNetwork |*| myDevices)
        NoAction)
where
	editor = fromSVGEditor
		{ initView = \((((((((((_, ms2d), _), _), _), _), _), _), _), _), cl) -> (ms2d, cl)
439
		, renderImage = \((((((((((disSects, _), exitLocks), hopLocks), inventoryMap), statusMap), sectionUsersMap), userActorMap), network), allDevices), cl) (ms2d`, cl`)
440 441 442 443
			-> maps2DImage disSects cl mode ms2d` exitLocks hopLocks inventoryMap statusMap sectionUsersMap userActorMap allDevices network
		, updModel = \((((((((((disSects, _), exitLocks), hopLocks), inventoryMap), statusMap), sectionUsersMap), userActorMap), network), allDevices), _)  (ms2d`, cl`) -> ((((((((((disSects, ms2d`), exitLocks), hopLocks), inventoryMap), statusMap), sectionUsersMap), userActorMap), network), allDevices), cl`)
		}

444
disabledSections :: SimpleSDSLens (Set Coord3D)
445 446 447 448 449 450 451 452 453 454 455 456 457
disabledSections = sharedStore "disabledSections" 'DS'.newSet

updateSectionStatus :: !Coord3D -> Task (MapAction SectionStatus)
updateSectionStatus c3d=:(floorIdx, _)
  = updateInformationWithShared "Section Status"
      [UpdateUsing id (const snd) editor]
      (maps2DShare |*| lockedExitsShare |*| lockedHopsShare |*| sdsFocus c3d inventoryInSectionShare |*| sdsFocus c3d statusInSectionShare |*| sdsFocus c3d (actorsInSectionShare myUserActorMap) |*| myNetwork |*| myDevices)
      NoAction
where
	editor = fromSVGEditor
		{ initView    = \((((((((ms2d, _), _), _), _), _), _), _), cl) -> (ms2d, cl)
		, renderImage = \((((((((ms2d, exitLocks), hopLocks), inventoryMap), statusMap), actorMap), network), allDevices), cl) (ms2d`, cl`)
			-> roomImage c3d exitLocks hopLocks inventoryMap statusMap actorMap allDevices network True (fromJust (getSectionFromMap c3d ms2d`)) (ms2d !! floorIdx) cl`
458
		, updModel    = \((((((((_,    exitLocks), hopLocks), inventoryMap), statusMap), actorMap), network), allDevices), _)  (ms2d`, cl`)
459 460 461
			-> ((((((((ms2d`, exitLocks), hopLocks), inventoryMap), statusMap), actorMap), network), allDevices), cl`)
		}

462
setAlarm :: !User !(!Coord3D, !SectionStatus) !(Shared sds MySectionStatusMap) -> Task () | RWShared sds
463 464 465 466
setAlarm user (alarmLoc, status) shStatusMap
  =   setSectionStatus alarmLoc status shStatusMap
  >>| addLog user ""  ("Resets " <+++ status <+++ " in Section " <+++ alarmLoc <+++ " to False.")

467
setSectionStatus :: !Coord3D !SectionStatus !(Shared sds (SectionStatusMap SectionStatus)) -> Task () | RWShared sds
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
setSectionStatus roomNumber status statusMap
  = upd ('DM'.put roomNumber status) statusMap @! ()

hasFire :: !SectionStatus -> Bool
hasFire HasSmallFire  = True
hasFire HasMediumFire = True
hasFire HasBigFire    = True
hasFire _             = False

hasSmoke :: !SectionStatus -> Bool
hasSmoke HasSmoke = True
hasSmoke _        = False

hasWater :: !SectionStatus -> Bool
hasWater HasSomeWater = True
hasWater IsFlooded    = True
hasWater _            = False


isHigh :: !SectionStatus -> Bool
isHigh status = hasFire status || hasSmoke status || hasWater status

isDetector :: !DeviceKind -> Bool
isDetector SmokeDetector = True
isDetector HeatSensor    = True
isDetector WaterSensor   = True
isDetector _             = False