;This code written in Franz Allegro Prolog (matching Lisp-style syntax)
;
;Original design pattern: MissionExecutionEngine.pl
;Prof. Robert B. McGhee (robertbmcghee@gmail.com) at the Naval Postgraduate School, Monterey, CA 93943.

; Description: this is the RBM Strategic Level task sequencing algorithm that is the basis
; of the Mission Execution Engine (MEE), see Figure 2 in the IEEE JOE paper (TODO link this).

;Start Prolog.
(require :prolog) (shadowing-import '(prolog:==)) (use-package :prolog)


;Mission specification

;;;;;;;;;;;;;;;;;;;;;; Begin PiratesSeizingMerchantDefense.xml Mission Orders ;;;;;;;;;;;;;;;;;;;;;;

(<-- (execute_goal 'PSMD11.0) (command "Goal PSMD11.0: Deploy, Launch - Commit to robot support") (update_outcome) ; initial goal, by default
                           (current_goal_outcome s) (change_goal 'PSMD11.0 'PSMD12.0))
(<- (execute_goal 'PSMD11.0) (current_goal_outcome f) (change_goal 'PSMD11.0 'PSMD99.0))
(<- (execute_goal 'PSMD11.0) (current_goal_outcome x) (change_goal 'PSMD11.0 'PSMD99.0))
(<- (execute_goal 'PSMD12.0) (command "Goal PSMD12.0: Transit to hostile area - Proceed to estimated position") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD12.0 'PSMD13.0))
(<- (execute_goal 'PSMD12.0) (current_goal_outcome f) (change_goal 'PSMD12.0 'PSMD99.0))
(<- (execute_goal 'PSMD12.0) (current_goal_outcome x) (change_goal 'PSMD12.0 'PSMD99.0))
(<- (execute_goal 'PSMD13.0) (command "Goal PSMD13.0: Locate Merchant - Use best search pattern, then follow moving ship and boats") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD13.0 'PSMD13.1))
(<- (execute_goal 'PSMD13.0) (current_goal_outcome f) (change_goal 'PSMD13.0 'PSMD21.0))
(<- (execute_goal 'PSMD13.0) (current_goal_outcome x) (change_goal 'PSMD13.0 'PSMD99.0))
(<- (execute_goal 'PSMD13.1) (command "Goal PSMD13.1: Report position - Alerts updated") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD13.1 'PSMD13.2))
(<- (execute_goal 'PSMD13.1) (current_goal_outcome f) (change_goal 'PSMD13.1 'PSMD13.2))
(<- (execute_goal 'PSMD13.1) (current_goal_outcome x) (change_goal 'PSMD13.1 'PSMD99.0))
(<- (execute_goal 'PSMD13.2) (command "Goal PSMD13.2: Mark with Beacon - Monitor wind effects and ocean current") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD13.2 'PSMD14.0))
(<- (execute_goal 'PSMD13.2) (current_goal_outcome f) (change_goal 'PSMD13.2 'PSMD21.0))
(<- (execute_goal 'PSMD13.2) (current_goal_outcome x) (change_goal 'PSMD13.2 'PSMD99.0))
(<- (execute_goal 'PSMD14.0) (command "Goal PSMD14.0: Track Merchant - Monitor and communicate") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD14.0 'PSMD14.1))
(<- (execute_goal 'PSMD14.0) (current_goal_outcome f) (change_goal 'PSMD14.0 'PSMD14.1))
(<- (execute_goal 'PSMD14.0) (current_goal_outcome x) (change_goal 'PSMD14.0 'PSMD99.0))
(<- (execute_goal 'PSMD14.1) (command "Goal PSMD14.1: Maintain proximity - Beyond range of small arms") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD14.1 'PSMD14.2))
(<- (execute_goal 'PSMD14.1) (current_goal_outcome f) (change_goal 'PSMD14.1 'PSMD14.2))
(<- (execute_goal 'PSMD14.1) (current_goal_outcome x) (change_goal 'PSMD14.1 'PSMD99.0))
(<- (execute_goal 'PSMD14.2) (command "Goal PSMD14.2: Periodic reports - Situation reports, changing status") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD14.2 'PSMD14.3))
(<- (execute_goal 'PSMD14.2) (current_goal_outcome f) (change_goal 'PSMD14.2 'PSMD14.3))
(<- (execute_goal 'PSMD14.2) (current_goal_outcome x) (change_goal 'PSMD14.2 'PSMD99.0))
(<- (execute_goal 'PSMD14.3) (command "Goal PSMD14.3: Continue until further orders - Repeat until conditions change") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD14.3 'PSMD14.9))
(<- (execute_goal 'PSMD14.3) (current_goal_outcome f) (change_goal 'PSMD14.3 'PSMD21.0))
(<- (execute_goal 'PSMD14.3) (current_goal_outcome x) (change_goal 'PSMD14.3 'PSMD99.0))
(<- (execute_goal 'PSMD14.9) (command "Goal PSMD14.9: Check posture changed? Task update received?") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD14.9 'PSMD30.0))
(<- (execute_goal 'PSMD14.9) (current_goal_outcome f) (change_goal 'PSMD14.9 'PSMD14.0))
(<- (execute_goal 'PSMD14.9) (current_goal_outcome x) (change_goal 'PSMD14.9 'PSMD99.0))
(<- (execute_goal 'PSMD21.0) (command "Goal PSMD21.0: Request Guidance? Need updated position") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD21.0 'PSMD12.0))
(<- (execute_goal 'PSMD21.0) (current_goal_outcome f) (change_goal 'PSMD21.0 'PSMD99.0))
(<- (execute_goal 'PSMD21.0) (current_goal_outcome x) (change_goal 'PSMD21.0 'PSMD99.0))
(<- (execute_goal 'PSMD22.0) (command "Goal PSMD22.0: Low Fuel - Make best effort possible") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD22.0 'PSMD22.1))
(<- (execute_goal 'PSMD22.0) (current_goal_outcome f) (change_goal 'PSMD22.0 'PSMD22.1))
(<- (execute_goal 'PSMD22.0) (current_goal_outcome x) (change_goal 'PSMD22.0 'PSMD99.0))
(<- (execute_goal 'PSMD22.1) (command "Goal PSMD22.1: Remain with Merchant? Choices: land on boat, attach to boat, or adrift nearby") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD22.1 'PSMD22.2))
(<- (execute_goal 'PSMD22.1) (current_goal_outcome f) (change_goal 'PSMD22.1 'PSMD22.2))
(<- (execute_goal 'PSMD22.1) (current_goal_outcome x) (change_goal 'PSMD22.1 'PSMD99.0))
(<- (execute_goal 'PSMD22.2) (command "Goal PSMD22.2: Beacon? While power remains") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD22.2 'PSMD99.0))
(<- (execute_goal 'PSMD22.2) (current_goal_outcome f) (change_goal 'PSMD22.2 'PSMD99.0))
(<- (execute_goal 'PSMD22.2) (current_goal_outcome x) (change_goal 'PSMD22.2 'PSMD99.0))
(<- (execute_goal 'PSMD30.0) (command "Goal PSMD30.0: Warning Phase - Close interaction with pirates, merchant ship") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD30.0 'PSMD31.0))
(<- (execute_goal 'PSMD30.0) (current_goal_outcome f) (change_goal 'PSMD30.0 'PSMD31.0))
(<- (execute_goal 'PSMD30.0) (current_goal_outcome x) (change_goal 'PSMD30.0 'PSMD99.0))
(<- (execute_goal 'PSMD31.0) (command "Goal PSMD31.0: Confirm Mission Authorities - Check constraints and defensive responses") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD31.0 'PSMD32.0))
(<- (execute_goal 'PSMD31.0) (current_goal_outcome f) (change_goal 'PSMD31.0 'PSMD32.0))
(<- (execute_goal 'PSMD31.0) (current_goal_outcome x) (change_goal 'PSMD31.0 'PSMD99.0))
(<- (execute_goal 'PSMD32.0) (command "Goal PSMD32.0: IFFNU - Identify Friend Foe Neutral Unknown") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD32.0 'PSMD32.1))
(<- (execute_goal 'PSMD32.0) (current_goal_outcome f) (change_goal 'PSMD32.0 'PSMD32.1))
(<- (execute_goal 'PSMD32.0) (current_goal_outcome x) (change_goal 'PSMD32.0 'PSMD99.0))
(<- (execute_goal 'PSMD32.1) (command "Goal PSMD32.1: Photograph all close contacts - Pass within range of small arms") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD32.1 'PSMD32.2))
(<- (execute_goal 'PSMD32.1) (current_goal_outcome f) (change_goal 'PSMD32.1 'PSMD32.2))
(<- (execute_goal 'PSMD32.1) (current_goal_outcome x) (change_goal 'PSMD32.1 'PSMD99.0))
(<- (execute_goal 'PSMD32.2) (command "Goal PSMD32.2: Classify, send contact reports - Based on target behavior or signal/image match") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD32.2 'PSMD32.3))
(<- (execute_goal 'PSMD32.2) (current_goal_outcome f) (change_goal 'PSMD32.2 'PSMD32.3))
(<- (execute_goal 'PSMD32.2) (current_goal_outcome x) (change_goal 'PSMD32.2 'PSMD99.0))
(<- (execute_goal 'PSMD32.3) (command "Goal PSMD32.3: Confirm IFFNU classifications - Requires approval by human commander before proceeding further") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD32.3 'PSMD33.0))
(<- (execute_goal 'PSMD32.3) (current_goal_outcome f) (change_goal 'PSMD32.3 'PSMD14.0))
(<- (execute_goal 'PSMD32.3) (current_goal_outcome x) (change_goal 'PSMD32.3 'PSMD99.0))
(<- (execute_goal 'PSMD33.0) (command "Goal PSMD33.0: Commence Warnings - May provoke pirate response") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD33.0 'PSMD33.1))
(<- (execute_goal 'PSMD33.0) (current_goal_outcome f) (change_goal 'PSMD33.0 'PSMD14.0))
(<- (execute_goal 'PSMD33.0) (current_goal_outcome x) (change_goal 'PSMD33.0 'PSMD99.0))
(<- (execute_goal 'PSMD33.1) (command "Goal PSMD33.1: Notify Merchant - Keep crew informed, even if they cannot transmit") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD33.1 'PSMD34.0))
(<- (execute_goal 'PSMD33.1) (current_goal_outcome f) (change_goal 'PSMD33.1 'PSMD14.0))
(<- (execute_goal 'PSMD33.1) (current_goal_outcome x) (change_goal 'PSMD33.1 'PSMD99.0))
(<- (execute_goal 'PSMD34.0) (command "Goal PSMD34.0: Send Warning Messages - Communicate to pirates, all parties") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD34.0 'PSMD34.1))
(<- (execute_goal 'PSMD34.0) (current_goal_outcome f) (change_goal 'PSMD34.0 'PSMD34.1))
(<- (execute_goal 'PSMD34.0) (current_goal_outcome x) (change_goal 'PSMD34.0 'PSMD99.0))
(<- (execute_goal 'PSMD34.1) (command "Goal PSMD34.1: Send multiple message paths - Loudspeaker, flashing light, siren, drop smoke, bridge-bridge radio") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD34.1 'PSMD34.2))
(<- (execute_goal 'PSMD34.1) (current_goal_outcome f) (change_goal 'PSMD34.1 'PSMD34.2))
(<- (execute_goal 'PSMD34.1) (current_goal_outcome x) (change_goal 'PSMD34.1 'PSMD99.0))
(<- (execute_goal 'PSMD34.2) (command "Goal PSMD34.2: Maintain proximity - Just outside range of small arms") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD34.2 'PSMD34.3))
(<- (execute_goal 'PSMD34.2) (current_goal_outcome f) (change_goal 'PSMD34.2 'PSMD34.3))
(<- (execute_goal 'PSMD34.2) (current_goal_outcome x) (change_goal 'PSMD34.2 'PSMD99.0))
(<- (execute_goal 'PSMD34.3) (command "Goal PSMD34.3: Periodic reports - Situation reports, changing status") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD34.3 'PSMD34.4))
(<- (execute_goal 'PSMD34.3) (current_goal_outcome f) (change_goal 'PSMD34.3 'PSMD34.4))
(<- (execute_goal 'PSMD34.3) (current_goal_outcome x) (change_goal 'PSMD34.3 'PSMD99.0))
(<- (execute_goal 'PSMD34.4) (command "Goal PSMD34.4: Continue until further orders - First repeat for all designated pirates") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD34.4 'PSMD35.0))
(<- (execute_goal 'PSMD34.4) (current_goal_outcome f) (change_goal 'PSMD34.4 'PSMD14.0))
(<- (execute_goal 'PSMD34.4) (current_goal_outcome x) (change_goal 'PSMD34.4 'PSMD99.0))
(<- (execute_goal 'PSMD35.0) (command "Goal PSMD35.0: Observe pirate response - Monitor and report back to own ship") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD35.0 'PSMD35.1))
(<- (execute_goal 'PSMD35.0) (current_goal_outcome f) (change_goal 'PSMD35.0 'PSMD35.1))
(<- (execute_goal 'PSMD35.0) (current_goal_outcome x) (change_goal 'PSMD35.0 'PSMD99.0))
(<- (execute_goal 'PSMD35.1) (command "Goal PSMD35.1: Pirates retreat? Stay with merchant, report if response changes") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD35.1 'PSMD14.0))
(<- (execute_goal 'PSMD35.1) (current_goal_outcome f) (change_goal 'PSMD35.1 'PSMD35.2))
(<- (execute_goal 'PSMD35.1) (current_goal_outcome x) (change_goal 'PSMD35.1 'PSMD99.0))
(<- (execute_goal 'PSMD35.2) (command "Goal PSMD35.2: Pirates attack? Stay with merchant, counterattack if response changes") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD35.2 'PSMD40.0))
(<- (execute_goal 'PSMD35.2) (current_goal_outcome f) (change_goal 'PSMD35.2 'PSMD35.3))
(<- (execute_goal 'PSMD35.2) (current_goal_outcome x) (change_goal 'PSMD35.2 'PSMD99.0))
(<- (execute_goal 'PSMD35.3) (command "Goal PSMD35.3: Maintain proximity - Just outside range of small arms") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD35.3 'PSMD35.4))
(<- (execute_goal 'PSMD35.3) (current_goal_outcome f) (change_goal 'PSMD35.3 'PSMD35.4))
(<- (execute_goal 'PSMD35.3) (current_goal_outcome x) (change_goal 'PSMD35.3 'PSMD99.0))
(<- (execute_goal 'PSMD35.4) (command "Goal PSMD35.4: Periodic reports - Situation reports, changing status - note ship may have EMCON radio silence") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD35.4 'PSMD35.5))
(<- (execute_goal 'PSMD35.4) (current_goal_outcome f) (change_goal 'PSMD35.4 'PSMD35.5))
(<- (execute_goal 'PSMD35.4) (current_goal_outcome x) (change_goal 'PSMD35.4 'PSMD99.0))
(<- (execute_goal 'PSMD35.5) (command "Goal PSMD35.5: Continue until further orders - Repeat until conditions change") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD35.5 'PSMD36.0))
(<- (execute_goal 'PSMD35.5) (current_goal_outcome f) (change_goal 'PSMD35.5 'PSMD36.0))
(<- (execute_goal 'PSMD35.5) (current_goal_outcome x) (change_goal 'PSMD35.5 'PSMD99.0))
(<- (execute_goal 'PSMD36.0) (command "Goal PSMD36.0: Check posture changed? Task update received") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD36.0 'PSMD37.0))
(<- (execute_goal 'PSMD36.0) (current_goal_outcome f) (change_goal 'PSMD36.0 'PSMD35.0))
(<- (execute_goal 'PSMD36.0) (current_goal_outcome x) (change_goal 'PSMD36.0 'PSMD14.0))
(<- (execute_goal 'PSMD37.0) (command "Goal PSMD37.0: Fire Warning Shot - Warning shots remain an available option for human commanders. Lethal force is authorized.") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD37.0 'PSMD31.0))
(<- (execute_goal 'PSMD37.0) (current_goal_outcome f) (change_goal 'PSMD37.0 'PSMD31.0))
(<- (execute_goal 'PSMD37.0) (current_goal_outcome x) (change_goal 'PSMD37.0 'PSMD99.0))
(<- (execute_goal 'PSMD40.0) (command "Goal PSMD40.0: Attack - Close interaction with pirates, merchant ship") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD40.0 'PSMD41.0))
(<- (execute_goal 'PSMD40.0) (current_goal_outcome f) (change_goal 'PSMD40.0 'PSMD41.0))
(<- (execute_goal 'PSMD40.0) (current_goal_outcome x) (change_goal 'PSMD40.0 'PSMD99.0))
(<- (execute_goal 'PSMD41.0) (command "Goal PSMD41.0: Attack Pirate Boats in priority order - Rapidly engage, shoot to disable or kill. Lethal force still authorized.") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD41.0 'PSMD41.1))
(<- (execute_goal 'PSMD41.0) (current_goal_outcome f) (change_goal 'PSMD41.0 'PSMD41.1))
(<- (execute_goal 'PSMD41.0) (current_goal_outcome x) (change_goal 'PSMD41.0 'PSMD99.0))
(<- (execute_goal 'PSMD41.1) (command "Goal PSMD41.1: Pirates retreat? Stay with merchant, report if response changes") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD41.1 'PSMD14.0))
(<- (execute_goal 'PSMD41.1) (current_goal_outcome f) (change_goal 'PSMD41.1 'PSMD41.2))
(<- (execute_goal 'PSMD41.1) (current_goal_outcome x) (change_goal 'PSMD41.1 'PSMD99.0))
(<- (execute_goal 'PSMD41.2) (command "Goal PSMD41.2: Pirates attacking? Stay with merchant, counterattack if response changes") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD41.2 'PSMD41.3))
(<- (execute_goal 'PSMD41.2) (current_goal_outcome f) (change_goal 'PSMD41.2 'PSMD41.3))
(<- (execute_goal 'PSMD41.2) (current_goal_outcome x) (change_goal 'PSMD41.2 'PSMD42.0))
(<- (execute_goal 'PSMD41.3) (command "Goal PSMD41.3: Maintain proximity - Just outside range of small arms") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD41.3 'PSMD41.4))
(<- (execute_goal 'PSMD41.3) (current_goal_outcome f) (change_goal 'PSMD41.3 'PSMD41.4))
(<- (execute_goal 'PSMD41.3) (current_goal_outcome x) (change_goal 'PSMD41.3 'PSMD99.0))
(<- (execute_goal 'PSMD41.4) (command "Goal PSMD41.4: Periodic reports - Situation reports, changing status - note ship may have EMCON radio silence") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD41.4 'PSMD41.5))
(<- (execute_goal 'PSMD41.4) (current_goal_outcome f) (change_goal 'PSMD41.4 'PSMD41.5))
(<- (execute_goal 'PSMD41.4) (current_goal_outcome x) (change_goal 'PSMD41.4 'PSMD99.0))
(<- (execute_goal 'PSMD41.5) (command "Goal PSMD41.5: Continue until further orders - Repeat until conditions change") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD41.5 'PSMD36.0))
(<- (execute_goal 'PSMD41.5) (current_goal_outcome f) (change_goal 'PSMD41.5 'PSMD36.0))
(<- (execute_goal 'PSMD41.5) (current_goal_outcome x) (change_goal 'PSMD41.5 'PSMD99.0))
(<- (execute_goal 'PSMD42.0) (command "Goal PSMD42.0: Low or no ammunition: need to disengage? Hold ammunition in reseve, or else fight to the finish") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD42.0 'PSMD14.0))
(<- (execute_goal 'PSMD42.0) (current_goal_outcome f) (change_goal 'PSMD42.0 'PSMD41.3))
(<- (execute_goal 'PSMD42.0) (current_goal_outcome x) (change_goal 'PSMD42.0 'PSMD90.0))
(<- (execute_goal 'PSMD43.0) (command "Goal PSMD43.0: Check for guidance, resume tracking or continue attacking? Humans monitoring attack can interrupt or override") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD43.0 'PSMD14.0))
(<- (execute_goal 'PSMD43.0) (current_goal_outcome f) (change_goal 'PSMD43.0 'PSMD41.0))
(<- (execute_goal 'PSMD43.0) (current_goal_outcome x) (change_goal 'PSMD43.0 'PSMD90.0))
(<- (execute_goal 'PSMD90.0) (command "Goal PSMD90.0: Check relieved by other asset - Continue tracking merchant unless further task update recieved") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD90.0 'PSMD14.0))
(<- (execute_goal 'PSMD90.0) (current_goal_outcome f) (change_goal 'PSMD90.0 'PSMD14.0))
(<- (execute_goal 'PSMD90.0) (current_goal_outcome x) (change_goal 'PSMD90.0 'PSMD99.0))
(<- (execute_goal 'PSMD99.0) (command "Goal PSMD99.0: Proceed to recovery - Mission complete, prepare for pickup") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD99.0 'PSMD99.1))
(<- (execute_goal 'PSMD99.0) (current_goal_outcome f) (change_goal 'PSMD99.0 'PSMD99.2))
(<- (execute_goal 'PSMD99.0) (current_goal_outcome x) (change_goal 'PSMD99.0 'PSMD99.3))
(<- (execute_goal 'PSMD99.1) (command "Goal PSMD99.1: Halt and prepare for recovery - Operations completed, final success state") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD99.1 'mission_complete))
(<- (execute_goal 'PSMD99.1) (current_goal_outcome f) (change_goal 'PSMD99.1 'mission_abort))
(<- (execute_goal 'PSMD99.1) (current_goal_outcome x) (change_goal 'PSMD99.1 'mission_abort))
(<- (execute_goal 'PSMD99.2) (command "Goal PSMD99.2: Halt and deploy recovery beacon - Unable to operate, final failure state") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD99.2 'mission_complete))
(<- (execute_goal 'PSMD99.2) (current_goal_outcome f) (change_goal 'PSMD99.2 'mission_abort))
(<- (execute_goal 'PSMD99.2) (current_goal_outcome x) (change_goal 'PSMD99.2 'mission_abort))
(<- (execute_goal 'PSMD99.3) (command "Goal PSMD99.3: Halt and await further orders - Unplanned failure, final exception state") (update_outcome)
                           (current_goal_outcome s) (change_goal 'PSMD99.3 'mission_complete))
(<- (execute_goal 'PSMD99.3) (current_goal_outcome f) (change_goal 'PSMD99.3 'mission_abort))
(<- (execute_goal 'PSMD99.3) (current_goal_outcome x) (change_goal 'PSMD99.3 'mission_abort))

;;;;;;;;;;;;;;;;;;;;;; End PiratesSeizingMerchantDefense.xml Mission Orders ;;;;;;;;;;;;;;;;;;;;;;

;Facts
(<-- (current_goal 'PSMD11.0)) ; initialGoal
(<-- (current_goal_outcome s))
     
;Mission execution rule set  
(<-- (execute_mission) (initialize_mission) (repeat) (execute_current_goal) (done) !)
(<-- (initialize_mission) (abolish current_goal 'PSMD11.0) (asserta ((current_goal 'PSMD11.0)))) ; initialGoal
(<-- (execute_current_goal) (current_goal ?x) (execute_goal ?x) !)
(<-- (done) (current_goal 'mission_complete))
(<- (done) (current_goal 'mission_abort))

; Human external agent communication functions

(<-- (negative nil)) (<- (negative n))
(<-- (affirmative ?x) (not (negative ?x)))
(<-- (report ?C) (princ ?C) (princ ".") (nl))
(<-- (command ?C) (princ ?C) (princ "!") (nl))
(<-- (ask ?Q ?A) (princ ?Q) (princ "?") (read ?A))
(<-- (ask_outcome ?A) (ask "Did goal succeed (s), fail (f), or abort (x)" ?A))

; Utility functions
(<-- (change_goal ?old ?new) (retract ((current_goal ?old))) (asserta ((current_goal ?new))))
(<-- (update_outcome) (ask_outcome ?A) (abolish current_goal_outcome 1) (asserta ((current_goal_outcome ?A))))

; Test functions (illustrate format for calling predicates from Lisp)
(defun run () (?- (execute_mission)))
(defun update () (?- (update_outcome)))
(defun mission-goal () (?- (current_goal ?X)))
(defun outcome () (?- (current_goal_outcome ?X)))
