# Samples

# Converted function from JS Example

Given this function written in JS:

function polarToCartesian(radius, angleInDegrees) {
    let angleInRadians = (angleInDegrees-90) * Math.PI / 180.0;
    return {
      x: radius * Math.cos(angleInRadians),
      y: radius * Math.sin(angleInRadians)
    };
}

The same function, written as a macro, is as follows:

"polarToCartesian": [
	{"#comment":[
		"param - radius",
		"param - angleInDegrees"
	]},
	{"set":{"param":"angleInDegrees"}, "value": {"multiply":[ {"subtract":[ {"param":"angleInDegrees"}, -90 ]}, {"divide": [3.14159 / 180]} ]}},
	{"return": {"create_struct":{
		"x": {"multiply":[ {"param":"radius"}, {"Math.cos": {"param":"angleInDegrees"}} ]},
		"y": {"multiply":[ {"param":"radius"}, {"Math.sin": {"param":"angleInDegrees"}} ]},
	}}}
]

# Scenery detection Sample

Use fetch to query the VFS for content specific to the package that you wish to detect.

{
  "title": "Scenery detection Sample",
  "api_version": 0.1,
  "aircraft": ["H145"],
  "briefing":[
    {"image": "/VFS/ContentInfo/revelstoke-logging1-scenery/Thumbnail.jpg", "show_condition":{"require": {"local":"SCENERY_INSTALLED_1"},"eq":1}},
    {"text":"Installed: {local:SCENERY_INSTALLED_1}"},
    {"image": "/VFS/ContentInfo/revelstoke-mill1-scenery/Thumbnail.jpg", "show_condition":{"require": {"local":"SCENERY_INSTALLED_2"},"eq":1}},
    {"text":"Installed: {local:SCENERY_INSTALLED_2}"},
    {"image": "/VFS/ContentInfo/revelstoke-lakeview-scenery/Thumbnail.jpg", "show_condition":{"require": {"local":"SCENERY_INSTALLED_3"},"eq":1}},
    {"text":"Installed: {local:SCENERY_INSTALLED_3}"}
  ],
  "objectives": [
    {
      "title": "Done",
      "commands": [
        {"fetch":{"url":"/VFS/ContentInfo/revelstoke-logging1-scenery/Thumbnail.jpg"}},
        {"set":{"local":"SCENERY_INSTALLED_1"},"value":{"if":{"param":"$FETCH_STATUS"},"eq":200,"then":1,"else":0}},
        {"fetch":{"url":"/VFS/ContentInfo/revelstoke-mill1-scenery/Thumbnail.jpg"}},
        {"set":{"local":"SCENERY_INSTALLED_2"},"value":{"if":{"param":"$FETCH_STATUS"},"eq":200,"then":1,"else":0}},
        {"fetch":{"url":"/VFS/ContentInfo/revelstoke-lakeview-scenery/Thumbnail.jpg"}},
        {"set":{"local":"SCENERY_INSTALLED_3"},"value":{"if":{"param":"$FETCH_STATUS"},"eq":200,"then":1,"else":0}},

        {"sleep": "forever"}
      ]
    }
  ]
}

# Get random item from static list

Given this static data:

  "data": {
    "cars": [
      "Car Title 1",
      "Car Title 2",
      "Car Title 3",
      "Car Title 4"
    ]
  },

Then each call will have a random item from cars:

{"struct": {"static": "cars"}, "index": {"floor": {"rand": [0, {"struct":{"static":"cars"},"path":"length"} ]}}}

Example:

{
  "title": "test",
  "api_version": 0.1,
  "aircraft": ["H145"],
  "data": {
    "cars": [
      "Car Title 1",
      "Car Title 2",
      "Car Title 3",
      "Car Title 4"
    ]
  },
  "briefing":[
    {"text":"Your selected car: {0}", "params":[
      {"local":"selectedCar"}
    ]},
    {"buttonbar": [
      {"title":"Pick a new car", "commands": [
        {"set": {"local":"selectedCar"}, "value": {"struct": {"static": "cars"}, "index": {"floor": {"rand": [0, {"struct":{"static":"cars"},"path":"length"} ]}}}}
      ]}
    ]}
  ],
  "objectives": [
    {
      "title": "Done",
      "commands": [
        {"sleep": "forever"}
      ]
    }
  ]
}

# CARLS Radio Test Program

This program sends information to the radio and also handles the events for clicking the buttons.

{
  "title": "Radio test program",
  "api_version": 0.1,
  "aircraft": ["H145"],
  "macros": {
    "render": [
      {"if": {"var": ["L:MY_PAGE", "number"]}, "eq":0, "then": [
        {"set_carls_radio": {
          "LSK": ["PG1", "", ""],
          "RSK": ["", "", "INOP"],
          "Items": [
            ["Group 1", "misc contacts"],
            ["Group 2", "important"],
            ["Group 3", "other"]
          ]
        }}
      ]},
      
      {"if": {"var": ["L:MY_PAGE", "number"]}, "eq":1, "then": [
        {"set_carls_radio": {
          "LSK": ["PG2", "", ""],
          "RSK": ["", "", "INOP"],
          "Items": [
            ["Contact 1", "000-5555-1234"],
            ["Contact 2", ""],
            ["Contact 3", ""]
          ]
        }}
      ]}
      
    ]
  },
  "objectives": [
    {
      "title": "Initializing...",
      "commands": [
        {"#comment": "select keys"},
        {"create_event_handler": "MISSION_RADIO_CARLS_L1", "commands": [{"set_message": {"text": "LSK1" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_L2", "commands": [{"set_message": {"text": "LSK2" }}]}, 
        {"create_event_handler": "MISSION_RADIO_CARLS_L3", "commands": [{"set_message": {"text": "LSK3" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_R1", "commands": [{"set_message": {"text": "RSK1" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_R2", "commands": [{"set_message": {"text": "RSK2" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_R3", "commands": [{"set_message": {"text": "RSK3" }}]},
        {"#comment": "dial pad"},
        {"create_event_handler": "MISSION_RADIO_CARLS_0", "commands": [{"set_message": {"text": "Num 0" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_1", "commands": [{"set_message": {"text": "Num 1" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_2", "commands": [{"set_message": {"text": "Num 2" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_3", "commands": [{"set_message": {"text": "Num 3" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_4", "commands": [{"set_message": {"text": "Num 4" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_5", "commands": [{"set_message": {"text": "Num 5" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_6", "commands": [{"set_message": {"text": "Num 6" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_7", "commands": [{"set_message": {"text": "Num 7" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_8", "commands": [{"set_message": {"text": "Num 8" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_9", "commands": [{"set_message": {"text": "Num 9" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_STAR", "commands": [{"set_message": {"text": "Num *" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_SHARP", "commands": [{"set_message": {"text": "Num #" }}]},
        {"#comment": "phone keys"},
        {"create_event_handler": "MISSION_RADIO_CARLS_PICK", "commands": [{"set_message": {"text": "PICK" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_HANG", "commands": [{"set_message": {"text": "HANG" }}]},
        {"create_event_handler": "MISSION_RADIO_CARLS_WARNING", "commands": [{"set_message": {"text": "WARNING" }}]},
        
        {"#comment": "change page when using <- and -> arrows "},
        {"create_event_handler": "MISSION_RADIO_CARLS_LEFT", "commands": [
          {"set": {"var": ["L:MY_PAGE", "number"]}, "value": 0},
          {"sleep":0.2},
          {"call_macro":"render"}
        ]},
        {"create_event_handler": "MISSION_RADIO_CARLS_RIGHT", "commands": [
          {"set": {"var": ["L:MY_PAGE", "number"]}, "value": 1},
          {"sleep":0.2},
          {"call_macro":"render"}
        ]},
        
        {"#comment": "Use L:CARLS_LIST_SELECTED_INDEX to get the highlighted list item !!!!"},
        
        {"call_macro":"render"}
      ]
    },
    {
      "title": "Done",
      "commands": [
        {"sleep": "forever"}
      ]
    }
  ]
}

# Remote dispatcher test program

HEMS dispatcher (multiplayer only)

  1. Each user connects to the server and uploads a list of 'valid mission choices'
  2. Operator can dispatch aircraft and the aircraft can accept the dispatch.
{
  "title": "Multiplayer Dispatch Test Program V2",
  "author":"davux3",
  "api_version": 0.1,
  "aircraft": ["H145"],
  "data":{
    "server_url": "wss://5ed547d.online-server.cloud/mpserver/ws",
    "create_room_url": "https://davux.com/dispatcher/",
    "webConfig": {
      "fligihtPlans": {
        "type":"map_line",
        "source":{"static":"flightPlans"},
        "name":"Flight Plan",
        "stroke":{"no_resolve":{"color": "#d303fc", "width":2}},
        "icon":{"static":"icons.wp_blue"}
      },
      "connectedAircraftIcons": {
        "type":"map_point",
        "source":{"static":"connectedAircraft"},
        "name":"Connected Aircraft",
        "text":"{UserName}",
        "icon":{"static":"icons.h160_icon"}
      },
      "aircraftDispatches": {
        "type":"map_point",
        "source":{"static":"messagesToAircraft"},
        "name":"Dispatch Locations",
        "text":"{to}",
        "icon":{"static":"icons.wp_blue"}
      },
      "connectedAircraftList": {
        "type":"list",
        "source":{"static":"connectedAircraft"},
        "title":"Connected Aircraft",
        "emptyText":"No aircraft are connected right now",
        "rows":{
          "row0":{
            "1": {"icon":{"static":"icons.h160_icon"}},
            "2": {"text":"{UserName}"},
            "3": {"button":"Send Dispatch","commands": [ 
              {"if": {"fn":"has_selected_poi"},"eq":0,"then":[
                {"show_dialog": {
                  "title":"Send Message",
                  "content": [
                  	{"text": "POI not selected. Click on a POI on the map and try again"}
                  ]
                }}
              ], "else":[
                {"show_dialog": {
                  "title":"Send Message",
                  "content": [
                  	{"text": "Select Mission"},
                  	{"listbox": "lst_mission", "source": {"param":"MissionList"}, "text": "{id}", "value":{"param":"id"}},
                  	{"text": "Dispatcher Name:"},
                  	{"textbox": "txt_from"},
                  	{"text": "Message Text:"},
                  	{"textarea": "txt_message"},
                  	{"text": "Patient Life score (0-100%):"},
                  	{"slider":"slider_value","min":0,"max":100,"value":{"rand":[0,100]}},
                		{"button": "Send Message", "commands": [
                			{"set_shared_data": "update", "path": "messagesToAircraft.{id}", "value": {"create_struct":{
                				"from": {"param":"txt_from"},	
                				"to": {"param":"UserName"},	
                				"message": {"param":"txt_message"}, 
                				"mission": {"param": "lst_mission"}, 
                				"location": {"fn": "selected_poi_location"}, 
                				"lifeScore": {"param":"slider_value"}
                			}}},
                			{"close_dialog":1}
                		]}
                  ]
                }}
              ]}
            ]},
            "4": {"button":"View","commands": [ {"set_map_center": {"param": "location"}, "zoom": 16} ]}
          },
          "row1":{
            "1": {"text":"{0}", "params": [ {"struct":{"static":"statusMessages"}, "index":{"param":"Status"}} ]}
          }
        }
      },
      "incomingMessageList": {
        "type":"list",
        "source":{"static":"messagesToDispatcher"},
        "title":"Message Inbox",
        "emptyText":"No messages right now",
        "rows":{
          "row0":{
            "1": {"text":"{UserName}"},
            "2": {"button":"Delete","commands": [ {"set_shared_data":"delete", "path":"messagesToDispatcher.{id}"} ]}
          },
          "row1":{
            "1": {"text":"{Text}"}
          }
        }
      },
      "outgoingMessageList": {
        "type":"list",
        "source":{"static":"messagesToAircraft"},
        "title":"Recent Dispatches",
        "emptyText":"No messages right now",
        "rows":{
          "row0":{
            "1": {"text":"{from} {to} "},
            "2": {"text":"{mission}"},
            "3": {"button":"Delete","commands": [ {"set_shared_data":"delete", "path":"messagesToAircraft.{id}"} ]},
            "4": {"button":"View","commands": [ {"set_map_center": {"param": "location"}, "zoom": 16} ]}
          },
          "row1":{
            "1": {"text":"{message}"}
   
          }
        }
      }
    },
    "statusMessages": [
      "0. Dispatch accepted",
      "1. On the way to the scene",
      "2. At the scene",
      "3. On the way to the hospital",
      "4. At the hospital",
      "5. On the way back to base (Available)",
      "6. At Home base (Available)",
      "7. Unavailable for dispatch"
    ],
    "missionList1": {
      "0. Road Accident": 0,
      "1. Motorcycle Crash": 1,
      "2. Tipped over tractor": 2
    },
    "missionList2": {
      "0. Hospital": 0,
      "1. Meet Ambulance": 1
    }
  },
  "briefing":[
    {"#comment":[
      "MP_MODE ... 0: not set, 1: offline, 2: online"
    ]},
    {"title":"Mission Initial Setup", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
    
    {"buttonbar":[
      {"title":"Offline (Single player)", "commands": [ {"set":{"local":"MP_MODE"}, "value":1} ], "disabled_condition":{"require":1,"eq":1}},
      {"title":"Online (Multiplayer)", "commands": [ {"call_macro":"mp_open_login_dialog"}  ]}
    ], "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},

    {"title":"Multiplayer (Online)", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 2}},
    {"buttonbar":[
      {"title":"View Multiplayer Status", "commands": [ {"call_macro":"mp_open_login_dialog"}  ]}
    ], "show_condition": {"require":{"local":"MP_MODE"}, "eq": 2}},

    {"title":"My Status", "show_condition": {"require":{"local":"MP_MODE"},"ne":0}},
    {"text":"My status: {0}", "params": [ {"var":["L:MY_DISPATCH_STATUS","number"]}  ], "show_condition": {"require":{"local":"MP_MODE"},"ne":0}},
    {"text":"{0}", "params": [
      {"struct": {"static":"statusMessages"}, "index":{"var":["L:MY_DISPATCH_STATUS","number"]}}
    ], "show_condition": {"require":{"local":"MP_MODE"},"ne":0}},
    {"text":"Change my status:", "show_condition": {"require":{"local":"MP_MODE"},"ne":0}},
    {"buttonbar":[
      { "title":"1", "commands":[ {"set":{"var":["L:MY_DISPATCH_STATUS","number"]},"value":1}] },
      { "title":"2", "commands":[ {"set":{"var":["L:MY_DISPATCH_STATUS","number"]},"value":2}] },
      { "title":"3", "commands":[ {"set":{"var":["L:MY_DISPATCH_STATUS","number"]},"value":3}] },
      { "title":"4", "commands":[ {"set":{"var":["L:MY_DISPATCH_STATUS","number"]},"value":4}] },
      { "title":"5", "commands":[ {"set":{"var":["L:MY_DISPATCH_STATUS","number"]},"value":5}] },
      { "title":"6", "commands":[ {"set":{"var":["L:MY_DISPATCH_STATUS","number"]},"value":6}] }
    ],
    "show_condition": {"require":{"local":"MP_MODE"},"ne":0}},
    
    {"buttonbar":[
      { "title":"Send message to dispatcher", "commands":[ {"call_macro":"open_dispatcher_msg_dialog"} ]}
    ],
    "show_condition": {"require":{"local":"MP_MODE"},"ne":0}},
    {"text":"Change my avaialble missions for dispatch:", "show_condition": {"require":{"local":"MP_MODE"},"ne":0}},
    {"buttonbar":[
      { 
        "title":"Set Mission Set 1 (rescue)", 
        "commands":[
          {"set_shared_data":"update",
            "path":"connectedAircraft.{local:service_auth}.MissionList",
            "value": {"static": "missionList1"}
          },
          {"set":{"local":"ACTIVE_MISSION_SET"},"value":1}
        ],
        "select_condition": {"require":{"local":"ACTIVE_MISSION_SET"},"eq":1}
      },
      { 
        "title":"Set Mission Set 2 (hospital etc.)", 
        "commands":[
          {"set_shared_data":"update",
            "path":"connectedAircraft.{local:service_auth}.MissionList",
            "value": {"static": "missionList2"}
          },
          {"set":{"local":"ACTIVE_MISSION_SET"},"value":2}
        ],
        "select_condition": {"require":{"local":"ACTIVE_MISSION_SET"},"eq":2}
      }
    ],
    "show_condition": {"require":{"local":"MP_MODE"},"ne":0}},

    {"title":"Incoming Dispatch"},

    {"text":"Dispatcher Name: {local:DISPATCH_FROM}"},
    {"text":"Selected Mission: {local:DISPATCH_MISSION}"},
    {"text":"Location: {local:DISPATCH_LOCATION}"},
    {"text":"Text Message: {local:DISPATCH_MESSAGE}"},
    {"text":"Patient Life Score: {local:DISPATCH_LIFESCORE}"}
  ],
  "events": {
    "ON_MISSION_ABORTING": {
      "commands": [	{"call_macro":"mp_aborting_mission"}	]
    }
  },
  "macros":{
    "open_dispatcher_msg_dialog": [
      {"set_dispatch":[
        {"title":"Send message"},
        {"textbox":"mp_dispatcher_msg"},
        {"buttonbar":[
          {"title":"Send Message to dispatcher", "commands": [
            {"set":{"param":"id"}, "value": {"fn": "create_guid"}},
            {"set_shared_data":"update",
              "path":"messagesToDispatcher.{id}",
              "value": {"create_struct":{
                "Text":{"local":"mp_dispatcher_msg"},
                "UserName": {"local":"mp_userName"}
            }}},
            {"set_briefing_dialog":1}
          ]}
        ]}
      ]},
      {"set_dispatch_dialog":1}
    ],
    "mp_open_login_dialog":[
      {"#comment": "Show the login dialog dispatch (or multiplayer status"},
      {"set_dispatch":[
        {"buttonbar":[ {"title":"<- Back to briefing", "commands": [{"set_briefing_dialog":1} ]} ]},
        
        {"title":"Log in",  "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},

        {"text":"You are playing offline.", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 1}},
    
        {"text":{"text":"User Id: {0}", "params":[{"local":"service_auth"}]}, "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
        {"text":"User Name:", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
        {"textbox":"mp_userName", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
        {"text":"Room:", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
        {"textbox":"mp_room", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
        {"text":"Password:", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
        {"textbox":"mp_password", "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
        {"buttonbar":[
          {"title":"Create Room (Opens on PC)", "commands": [ {"open_url":"{static:create_room_url}?room={local:mp_room}"} ]},
          {"title":"Log In", "commands": [ {"call_macro":"mp_login"} ]}
        ], 
        "disabled_condition":{"require":{"struct":{"local":"MP_CONN"}, "path":"Status"},"eq":"Connected"},
        "show_condition": {"require":{"local":"MP_MODE"}, "eq": 0}},
        
        {"text":{"text":"MP Connection Status: {0}", "params":[
          {"struct":{"local":"MP_CONN"}, "path":"Status"}
        ]}, "show_condition": {"require":{"local":"MP_MODE"}, "ne": 1}},
        {"text":{"text":"MP Server Last Error: {local:MP_LAST_ERROR}"}, "show_condition": {"require":{"local":"MP_MODE"}, "ne": 1}},

        {"title":"Debug Info"},
        {"text":{"text":"Multiplayer Mode: {0}", "params":[
          {"switch":{"local":"MP_MODE"}, "case":{
            "0": "Undecided",
            "1": "Offline, Singleplayer",
            "2": "Multiplayer"
          }}
        ]}},

        {"#comment":{"text":"Debug MP Message: {local:MP_MSG}"}, "show_condition": {"require":{"local":"MP_MODE"}, "ne": 1}}
      ]},
      {"set_dispatch_dialog":1}
    ],
    "mp_login":[
      {"#comment":"try to make the actual connection to the server"},
      {"set":{"param":"service_auth"},"value":{"local":"service_auth"}},
      {"set":{"local":"MP_LAST_ERROR"},"value":""},
      {"set":{"local":"MP_CONN"}, "value": {"fn": "create_multiplayer_connection"}},

      {"set":{"local":"MP_CONN", "path":"OnError"}, "value":{"js:create_async_function":[
        {"set":{"local":"MP_LAST_ERROR"},"value":{"struct": {"param":"$args"}, "index": 0}}
      ]}},

      {"set":{"local":"MP_CONN", "path":"OnMessage"}, "value":{"js:create_async_function":[
        {"set":{"param":"arg0"},"value":{"struct": {"param":"$args"}, "index": 0}},
        {"call_macro":"mp_on_message","params":{"msg": {"param":"arg0"}}}
      ]}},
      
      {"set":{"param":"unused"},"value":{"struct":{"local":"MP_CONN"}, "function":"Connect", "params":[
        {"static":"server_url"}, {"param":"service_auth"}, {"local":"mp_room"}, {"local":"mp_password"}
      ]}},
      
      {"create_thread":{"commands":[
        {"wait_for":{"struct":{"local":"MP_CONN"}, "path":"Status"},"eq":"Connected"},
        
        {"#comment":"once we log in once, we're committed to muoltiplayer"},
        {"set":{"local":"MP_MODE"}, "value": 2},
        {"set_briefing_dialog":1},

        {"#comment":"First create terminationCommands with no_overwrite, then add an entry for us, and then populate with commands to clear us from connectedAircraft and terminationCommands when we become stale on the server"},
        {"set_shared_data":"update",
          "path":"terminationCommands",
          "policy":"no_overwrite",
          "value": {"create_struct":{}}
        },
        {"set_shared_data":"update",
          "path":"terminationCommands.{service_auth}",
          "value": {"create_struct":{
            "removeFromConnectedAircraft":{"create_struct":{
              "type":"delete",
              "path":"connectedAircraft.{service_auth}"
            }},
            "removeFromFlightPlans":{"create_struct":{
              "type":"delete",
              "path":"flightPlans.{service_auth}"
            }},
            "removeFromTerminationCommands":{"create_struct":{
              "type":"delete",
              "path":"terminationCommands.{service_auth}"
            }}
        }}},
        
        
        {"#comment":"make sure we have connectedAircraft table. all players must use no_overwrite when ensuring the table exists to prevent anybody from destroying the table."},
        {"set_shared_data":"update", "path":"connectedAircraft", "policy":"no_overwrite", "value": {"create_struct":{}} },
        {"set_shared_data":"update", "path":"messagesToDispatcher", "value": {"create_struct":{}} },
        {"set_shared_data":"update", "path":"messagesToAircraft", "value": {"create_struct":{}} },
        {"set":{"param":"unused"},"value":{"struct":{"local":"MP_CONN"}, "function":"Subscribe", "params":[ "messagesToAircraft" ]}},

        {"set_shared_data":"update", "path":"icons", "policy":"no_overwrite", "value": {"fn":"get_mission_icons"} },
        {"set_shared_data":"update", "path":"flightPlans", "policy":"no_overwrite", "value": {"create_struct":{}} },
        {"set_shared_data":"update", "path":"webConfig", "policy":"no_overwrite", "value": {"static":"webConfig"} },
        
        {"set_shared_data":"update", "path":"statusMessages", "policy":"no_overwrite", "value": {"static":"statusMessages"} },
        {"set_shared_data":"update",
          "path":"connectedAircraft.{service_auth}",
          "value": {"create_struct":{
            "location":{"resolve_location":"$USER"},
            "UserName": {"local":"mp_userName"},
            "Status": 0,
            "MissionList": {"static": "missionList1"}
        }}},
         {"set":{"local":"ACTIVE_MISSION_SET"}, "value":1},
        

        {"#comment":"update our location, score and flightplan (if changed) forever"},
        {"while":1,"eq":1,"do":[
          {"sleep":5},
          {"set_shared_data":"update", "path":"connectedAircraft.{service_auth}.location", "value": {"resolve_location":"$USER"} },
          {"set_shared_data":"update", "path":"connectedAircraft.{service_auth}.Status", "value": {"var":["L:MY_DISPATCH_STATUS","number"]} },
          
          {"if":{"json:stringify": {"local":"$FLIGHTPLAN"}}, "ne": {"param":"FPL"},"then":[
            {"set":{"param":"FPL"},"value":{"json:stringify": {"local":"$FLIGHTPLAN"}}},
            {"set_shared_data":"update", "path":"flightPlans.{service_auth}", "value": {"create_struct":{
                "points":{"local":"$FLIGHTPLAN"}
            }}}
          ]}
        ]}
      ]}}
    ],
    "mp_initialize":[
      {"#comment":"set up for multiplayer operations later"},
      {"set":{"local":"MP_LAST_ERROR"},"value":""},
      {"set":{"local":"MP_MODE"},"value":0},
      {"#comment":"MP_MODE 0: undecided, 1: offline, 2:online"},
      
      {"#comment":"these are for debugging only"},
      {"set":{"local":"MP_MSG"},"value":""},
      {"set":{"local":"mp_room"},"value":""},
      {"set":{"local":"mp_password"},"value":""},
      {"set":{"local":"mp_userName"},"value":{"var":["ATC AIRLINE","string"]}},
      {"#comment": "Create or access a unique ID to identify you on the server irrespective of callsign"},
      {"set":{"local":"service_auth"}, "value":{"fn":"create_guid"}},

      {"create_thread":{"commands":[
        {"wait_for":{"local":"MP_MODE"},"ne":0},
        {"call_macro":"mp_begin"}
      ]}}
    ],
    "mp_on_message":[
      {"#comment":"param - msg"},
      
      {"#comment":"handle READ, UPDATE and DELETE operations below"},
      {"set":{"param":"json"},"value":{"json:stringify":{"param":"msg"}}},
      {"switch":{"struct": {"param":"msg"}, "path": "type"}, "case": {
        "read":[
          {"set":{"local":"MP_MSG"},"value": "we got an read: {json}"}
        ],
        "update": [
          {"set":{"local":"MP_MSG"},"value": "we got an update: {json}"},

          {"#comment":"split the path into parts based on ."},
          {"set":{"param":"parts"}, "value":{"string:split":{"struct": {"param":"msg"}, "path": "path"}, "delimiter":"."}},
          
          {"#comment":"messagesToAircraft NEW MESSAGE"},
          {"if": {"and":[
            {"require": {"struct": {"param":"parts"}, "path":"length"}, "eq": 2},
            {"require": {"struct": {"param":"parts"}, "index":"0"}, "eq": "messagesToAircraft"},
            {"require": {"struct": {"param":"parts"}, "index":"1"}, "eq": "{local:service_auth}"}
          ]}, "eq":1, "then":[
            {"call_macro":"on_got_dispatch","params":{
              "dispatchInfo": {"struct": {"param":"msg"}, "path": "value"}
            }}
          ]}
          
        ],
        "delete": [
          {"set":{"local":"MP_MSG"},"value": "we got an delete: {json}"}
        ]
      }}
    ],
    "mp_begin":[
      {"#comment":"called once we decided if we are single or muliplayer. MP_MODE 1:offline, 2:online"},
      {"#comment":"offline case, manually run the logic and complete logic"},
      
      {"call_macro":"Update_RescueTrack"},
      {"set_objective_title":"Ready to play the game!"}
    ],
    "mp_aborting_mission":[
      {"#comment":"we want to clean up our multiplayer connection if it was created"},
      {"if":{"local":"MP_CONN"},"ne":null, "then":[
        {"set":{"param":"unused"},"value":{"struct":{"local":"MP_CONN"}, "function":"Close", "params":[]}}
      ]}
    ],
    "on_got_dispatch":[
      {"#comment":"param - dispatchInfo"},
      {"#comment":"this macro is called when the dispatch is received from the web"},
      
      {"set":{"local":"DISPATCH_FROM"}, "value":{"struct": {"param":"dispatchInfo"}, "path": "from"}},
      {"set":{"local":"DISPATCH_MISSION"}, "value":{"struct": {"param":"dispatchInfo"}, "path": "mission"}},
      {"set":{"local":"DISPATCH_LOCATION"}, "value":{"struct": {"param":"dispatchInfo"}, "path": "location"}},
      {"set":{"local":"DISPATCH_MESSAGE"}, "value":{"struct": {"param":"dispatchInfo"}, "path": "message"}},
      {"set":{"local":"DISPATCH_LIFESCORE"}, "value":{"struct": {"param":"dispatchInfo"}, "path": "lifeScore"}},

      {"modify_array":{"local":"Messages"},"append":{"create_struct":{
        "from": {"local":"DISPATCH_FROM"},
        "time": {"fn":"get_time_string"},
        "text": {"local":"DISPATCH_MESSAGE"},
        "mission": {"local":"DISPATCH_MISSION"},
        "waypoint": {"local":"DISPATCH_LOCATION"}
      }}},
      {"call_macro":"Update_RescueTrack"},

      {"#comment":""}
    ],
    "Update_RescueTrack":[
      {"set_rescuetrack":{
        "statusVar": "L:MY_DISPATCH_STATUS",
        "statusMessages": {"static": "statusMessages"},
        "dispatcherMessages": {"local": "Messages"},
        "activate_waypoint_commands":[
          {"#comment":"param - $index - in dispatcherMessages"},
          {"#comment":"param - $command - DIRECT-TO"},

          {"#comment":"below we set a nav line to the location, and we can select the type of mission scene to spawn there"},
          {"set_route": {"struct": {"struct":{"local": "Messages"}, "index": {"param": "$index"}}, "path":"waypoint"}},
          {"switch": {"struct": {"struct":{"local": "Messages"}, "index": {"param": "$index"}}, "path":"mission"}, "case":{
            "0. Road Accident": [ {"#comment":"TODO: Set up for 0. Road Accident"} ],
            "1. Motorcycle Crash": [ {"#comment":"TODO: Set up for 1. Motorcycle Crash"} ],
            "2. Tipped over tractor": [ {"#comment":"TODO: Set up for 2. Tipped over tractor"} ],
            "0. Hospital":  [ {"#comment":"TODO: Set up for 0. Hospital"} ],
            "1. Meet Ambulance":  [ {"#comment":"TODO: Set up for 1. Meet Ambulance"} ],
            "default": [ {"#comment":"TODO: Set up for unknown mission"} ]
          }}
        ]
      }}
    ]
  },
  "objectives": [
    {
      "title": "Setup required",
      "commands": [
        {"set":{"local":"Messages"},"value":[]},
        {"call_macro":"mp_initialize"},
        {"sleep": "forever"}
      ]
    }
  ],
  "icons":{
    "wp_bl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F0KEhqB22VOSauqGlS5v6zTqWOdClIaDZBJrwjzyNgj6eUdCp4prlNLXaK6hrlc6b8YiedCtbuOCLfmzhRq1yqSdUqOgan/Z/8Fr74U9n09mF1FnTbW32RKgW5D3Fztv+v6dovX5aeWa4cCG7uvOawLzJ093g9T48l5D/P/4VR1h0OpUuWrEQe98iUks45GFxgyKACddmUctKp4HFs9sFVs7pW3dMk5Vriv0T33fPkGEKeSq6QOCL/Ap3jTWX/GRgjAAAAAElFTkSuQmCC"
  }
}

# RescueTrack Test Program

This program shows basic usage of the RescueTrack UI.

{
  "title": "Rescue Track Test Program",
  "data":{
    "statusMessages": [
      "0. Dispatch accepted",
      "1. On the way to the scene",
      "2. At the scene",
      "3. On the way to the hospital",
      "4. At the hospital",
      "5. On the way back to base (Available)",
      "6. At Home base (Available)",
      "7. Unavailable for dispatch"
    ]
  },
  "briefing": [
    {"title":"Rescue Track Test"},
    {"text":"Enable Rescue Track (visible on DMAP STATUS):"},
    {"buttonbar":[
      {
        "title":"Enabled", 
        "commands":[ 
          {"set": {"local":"IS_RESCUE_TRACK_ENABLED"}, "value": 1},
          {"call_macro":"Update_RescueTrack"}
        ],
        "select_condition":{"require":{"local":"IS_RESCUE_TRACK_ENABLED"}, "eq":1}
      },
      {
        "title":"Disabled", 
        "commands":[ 
          {"set": {"local":"IS_RESCUE_TRACK_ENABLED"}, "value": 0},
          {"call_macro":"Update_RescueTrack"}
        ],
        "select_condition":{"require":{"local":"IS_RESCUE_TRACK_ENABLED"}, "eq":0}
      }
    ]},
    
    {"text":"My Status:"},
    
    {"buttonbar":[
      {
        "title": {"struct": {"static": "statusMessages"}, "index": 0}, 
        "commands":[ 
          {"set": {"var":["L:MISSION_RESCUETRACK_STATUS", "number"]}, "value": 0},
          {"call_macro":"Update_RescueTrack"}
        ],
        "select_condition":{"require":{"var":["L:MISSION_RESCUETRACK_STATUS", "number"]}, "eq":0}
      }
    ]},
    {"buttonbar":[
      {
        "title": {"struct": {"static": "statusMessages"}, "index": 1}, 
        "commands":[ 
          {"set": {"var":["L:MISSION_RESCUETRACK_STATUS", "number"]}, "value": 1},
          {"call_macro":"Update_RescueTrack"}
        ],
        "select_condition":{"require":{"var":["L:MISSION_RESCUETRACK_STATUS", "number"]}, "eq":1}
      }
    ]},
    {"buttonbar":[
      {
        "title": {"struct": {"static": "statusMessages"}, "index": 2}, 
        "commands":[ 
          {"set": {"var":["L:MISSION_RESCUETRACK_STATUS", "number"]}, "value": 2},
          {"call_macro":"Update_RescueTrack"}
        ],
        "select_condition":{"require":{"var":["L:MISSION_RESCUETRACK_STATUS", "number"]}, "eq":2}
      }
    ]},
    {"buttonbar":[
      {
        "title": "Other status", 
        "commands":[ 
          {"set": {"var":["L:MISSION_RESCUETRACK_STATUS", "number"]}, "value": 3},
          {"call_macro":"Update_RescueTrack"}
        ],
        "select_condition":{"require":{"var":["L:MISSION_RESCUETRACK_STATUS", "number"]}, "gt":2}
      }
    ]},
    
    {"title":"Dispatcher messages"},
    {"text":"Location:"},
    {
      "text":"You must select a location on the map prior to sending a dispatch. Go back to the map and click a location, then come back to send your message.", 
      "color":"red", 
      "show_condition": {"require": {"has_location": "$MISSION_SELECTED_POI_LOCATION"}, "eq": 0}
    },
    {
      "text":{"text":"{0:LOCATION}", "params": ["$MISSION_SELECTED_POI_LOCATION"]}, 
      "show_condition": {"require": {"has_location": "$MISSION_SELECTED_POI_LOCATION"}, "eq": 1}
    },
    
    {
      "text":"Name: (required field)", 
      "color":"red", 
      "show_condition": {"require":{"local": "dispatcher_textbox_name"}, "eq":""}
    },
    {
      "text":"Name:", 
      "show_condition": {"require":{"local": "dispatcher_textbox_name"}, "ne":""}
    },
    
    
    {"textbox":"dispatcher_textbox_name"},

    {
      "text":"Message: (required field)", 
      "color":"red", 
      "show_condition": {"require":{"local": "dispatcher_textbox_msg"}, "eq":""}
    },
    {
      "text":"Message:", 
      "show_condition": {"require":{"local": "dispatcher_textbox_msg"}, "ne":""}
    },
    {"textbox":"dispatcher_textbox_msg"},
    {"buttonbar":[
      {
        "title":"Send Message", 
        "commands":[ 
    
          {"modify_array": {"local": "Dispatcher_Messages"}, "prepend": {"create_struct": {
            "from": {"local": "dispatcher_textbox_name"},
            "time": {"fn":"get_time_string"},
            "text":{"local": "dispatcher_textbox_msg"},
            "waypoint": {"location": "$MISSION_SELECTED_POI_LOCATION"}
          }}},
          
          {"set": {"local":"dispatcher_textbox_msg"}, "value": ""},


          {"call_macro":"Update_RescueTrack"}
        ],
        "select_condition":{"and":[
          {"require":{"local": "dispatcher_textbox_msg"}, "ne":0},
          {"require": {"has_location": "$MISSION_SELECTED_POI_LOCATION"}, "eq": 1}
        ]}
      }
    ]},
    
    {"text":"outgoing messages (Dispatcher_Messages):"},
    {"text": {"json:stringify":{"local":"Dispatcher_Messages"}}},
    
    
    {"#comment":"you may add comments as needed"}
  ],
  "macros": {
    "Update_RescueTrack":[
      {"if":{"local":"IS_RESCUE_TRACK_ENABLED"}, "eq":1,"then":[
        {"set_rescuetrack":{
          "statusVar": "L:MISSION_RESCUETRACK_STATUS",
          "statusMessages": {"static": "statusMessages"},
          "dispatcherMessages": {"local": "Dispatcher_Messages"}
        }, "activate_waypoint_commands":[
          {"set":{"param":"ACTIVE_MSG"}, "value": {"struct": {"local": "Dispatcher_Messages"}, "index": {"param":"$index"}}},
          
          {"copy_query_to_location": {"struct": {"param":"ACTIVE_MSG"}, "path": "waypoint"}, "to":"temp"},
          {"set_route":"temp"},
          
          {"set_message":{"text": "Go direct: {0}<br />\n{1:LOCATION}", "params": [
            {"json:stringify":{"struct": {"param":"ACTIVE_MSG"}, "path": "waypoint"}},
            "temp"
          ]}}
        ]}
      ], "else":[
        {"set_rescuetrack": null}
      ]}
    ]
  },
  "objectives": [
    {
      "title": "Done",
      "commands": [
        {"set":{"local":"IS_RESCUE_TRACK_ENABLED"}, "value":1},
        {"set":{"local": "Dispatcher_Messages"}, "value": []},
        {"set": {"local":"dispatcher_textbox_name"}, "value": ""},
        {"set": {"local":"dispatcher_textbox_msg"}, "value": ""},
          
        {"call_macro":"Update_RescueTrack"},
        {"sleep": "forever"}
      ]
    }
  ]
}