DOff.icl 3.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
implementation module C2.Navy.Roles.DOff

import iTasks
import C2.Framework.Entity
import C2.Apps.ShipAdventure.Scripting, C2.Apps.ShipAdventure.Core, C2.Apps.ShipAdventure.Types, C2.Apps.ShipAdventure.Images, C2.Framework.Logging
from Data.Set import :: Set
import qualified Data.Set as DS
from Data.IntMap.Strict import instance Functor IntMap
import qualified Data.IntMap.Strict as DIS
import C2.Apps.ShipAdventure.Editor
11
import Data.Map.GenJSON
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

dOffRegisterEntity  :: [User -> Task Entity]
dOffRegisterEntity = []

dOffContinuousTasks :: [User [Entity] -> Task ()]
dOffContinuousTasks = []

dOffAlwaysOnTasks :: [(String, User [Entity] -> Task ())]
dOffAlwaysOnTasks = [ ("Damage control",    \_ _ -> damageControl)
                    , ("Damage prediction", \_ _ -> damagePrediction)
                    ]

dOffMap :: Task ()
dOffMap
  # me = AuthenticatedUser "doff" ["doff"] (Just "D-Officer")
  =   set me currentUser
  >>| updateMapStatus DOffMode @! ()

damageControl :: Task ()
damageControl
  = allTasks [ viewDisabledDevices @! ()
             , giveInstructions @! ()
             ] <<@ ArrangeHorizontal @! ()

damagePrediction :: Task ()
damagePrediction
  =    watch disabledSections
  -&&- (((((viewSharedInformation "Selected section" [] sharedMapAction <<@ ArrangeVertical)
       -|| showDisabledDevices <<@ ArrangeVertical) <<@ ArrangeVertical)
       -|| ((showImperiledCommandAims <<@ ArrangeHorizontal)
       -|| showCommandAims <<@ ArrangeVertical)) <<@ ArrangeHorizontal)
Bas Lijnse's avatar
Bas Lijnse committed
43 44 45
  >>* [ OnAction (Action "/Disable" ) disableSection
      , OnAction (Action "/Enable" )  enableSection
      , OnAction (Action "/Reset" )   (always resetSections)
46 47 48 49 50 51 52 53 54 55 56
      ]
  where
  disableSection (Value (disSects, FocusOnSection c3d) _)
    | not (isDisabled c3d disSects) = Just (upd ('DS'.insert c3d) disabledSections >>| damagePrediction)
  disableSection _ = Nothing
  enableSection (Value (disSects, FocusOnSection c3d) _)
    | isDisabled c3d disSects = Just (upd ('DS'.delete c3d) disabledSections >>| damagePrediction)
  enableSection _ = Nothing
  resetSections = set 'DS'.newSet disabledSections >>| damagePrediction
  isDisabled c3d disSects = 'DS'.member c3d disSects

Mart Lubbers's avatar
Mart Lubbers committed
57 58 59 60 61
derive gEditor Set
derive gDefault Set
derive gText Set
derive JSONEncode Set
derive JSONDecode Set
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

showCommandAims :: Task ()
showCommandAims = viewSharedInformation "Current Command Aims" [] commandAims @! ()

showImperiledCommandAims :: Task ()
showImperiledCommandAims
  = viewSharedInformation "Imperiled Command Aims"
      [ViewAs (\((((disSects, nw), devs), caps), cas) -> allImperiledCommandAims devs caps cas (doDisableCablesInSections disSects nw))]
      (disabledSections |*| myNetwork |*| myDevices |*| capabilityMap |*| commandAims) @! ()

showDisabledDevices :: Task ()
showDisabledDevices
  = viewSharedInformation "Disabled devices"
      [ViewAs (\((disSects, nw), devs) -> map (\d -> d.Device.description) (allDisabledDevices devs (doDisableCablesInSections disSects nw)))]
      (disabledSections |*| myNetwork |*| myDevices) @! ()

doDisableCablesInSections :: !(Set Coord3D) !Network -> Network
doDisableCablesInSections disabledSections nw = {nw & cableMapping = fmap doDisable nw.cableMapping}
  where
  doDisable xs = [(not ('DS'.member c3d` disabledSections), c3d`) \\ (operational, c3d`) <- xs]

dOffOptionalTasks :: [(String, User [Entity] -> Task ())]
dOffOptionalTasks = [("Show log", \_ _ -> showLog @! ())]