;****************************************************
;*
;*  ENVELOPE  (=P5.lisp) "Smart Agent"
;*
;*  PROTOTYPE INTERNAL AND EXTERNAL BEHAVIORS
;* 
;*  Character "Envelope"
;*  Experiment, May 1996
;*
;****************************************************

(in-package 'USER)

; Prototype files contain all the necessary commands to make
; objects, initialize states and run the proper main routine.


; Indices into the *input-buffer* datarecord
; Constants for positions and orientations for turn-taking system.
;Indexes are really functions

;************ Virtual Sensors **************

(defparameter *turn-sensors*  
  ;there are not *only* turn sensors here anymore 3/10/96
  ;Sensors receive raw data and do simple computations.
  ; TEMPLATE: (name object-type 
  ;                       data1 data2 
  ;                       (index1) (index2)  ;indexes are in prens if functions
  ;                       func state) 
    '((facing-domain bs-fix-ref
		     nil work-screen
		     (get-head-dir) nil
                     facing nil)
      (looking-at-me bs-fix-ref 
                     nil agent-screen
                     (get-gaze-dir) nil
                     looking-me nil)
      (facing-me bs-fix-ref 
                 nil agent-screen 
                 (get-head-dir) nil 
                 facing nil)
      (turned-to-me bs-fix-ref 
                    nil agent-screen
                    (get-trunk-dir) nil 
                    turned-to nil)
      (looking-at-r-hand bs-var-ref 
                         nil nil 
		        (get-gaze-dir) (get-r-wrist-pos) 
                        looking-hands nil)
      (looking-at-l-hand bs-var-ref 
                         nil nil 
		        (get-gaze-dir) (get-l-wrist-pos) 
                        looking-hands nil)
;      (looking-at-gest-space bs-var-ref 
;                         nil nil
;                         (get-gaze-dir) (get-trunk-dir) 
;                         looking-gest-space nil)
      (rhand-in-gest-space bs-var-ref 
                           nil nil 
			  (get-trunk-dir) (get-r-wrist-pos) 
                          hand-in-gesture-space nil) 
      (lhand-in-gest-space bs-var-ref 
                           nil nil 
			  (get-trunk-dir) (get-l-wrist-pos) 
                          hand-in-gesture-space nil)
;      (complete-inton inton-sensor nil nil ind1 nil nil nil) 
;      (filler inton-sensor nil nil ind1 nil nil nil)           
      (speaking inton-sensor 
                nil nil 
                speech-on-idx nil 
                speaking? nil)
      (greeting speech-sensor
                9 nil   ;9 stands for region of speech
                nil nil
                region-equal nil)
      (saying-my-name speech-sensor
                      8 nil
                      nil nil
                      region-equal nil)
      (see-user socket-sensor
	        *socket-obj1* nil
		nil nil
		body-status  nil) ;need something more powerful later...
; very simplified for now... 4/12/96
      (complete-pragm speech-sensor 
                      nil nil 
                      ind1 nil 
                      pragmatically-complete nil)
      (complete-gram speech-sensor 
                     nil nil 
                     ind1 ind2 
                     grammar-complete nil)
      (complete-synt speech-sensor 
                     nil nil 
                     ind1 nil 
                     syntax-complete nil)
;      (cl-act-avail speech-sensor ;notice that this should not be done! DKB & TKB
;                    nil nil       ;communicate directly through their own *KB-msgs*.
;                    nil nil
;                    cl-act-available? nil)
  ; TEMPLATE: (name object-type 
  ;                       data1 data2 
  ;                       (index1) (index2)  ;indexes are in prens if functions
  ;                       func state)                     
  ))

; Note: "filler" is really an analysis question and 
; shouldn't be in the descriptor list.
; Or should it? It is crucial for the reactive 
; behavior of the system, so perhaps it should.

; Combining hand-in-gest-space and looking-at-hands 
; could be a reactive predictor's conditions
; to predict iconic gesture.  Or, it's really an 
; "assumption's" conditions because it's not
; anticipating anything; it's assuming after the 
; fact but with very meager evidence.


;************ Multimodal Descriptors **************

;notice: if added to, change list in function descr-type in file mmrecorder!
(defparameter *turn-descriptors*  ;Descriptors dealing with turn analysis.
  ; TEMPLATE: (name pos-cond neg-cond thresh state) 
  '((giving-turn (;(complete-utter 0.5)            ;pos-cond
                  (looking-at-me 0.3)
		  (facing-me 0.3))                
                 ((gesturing 0.3) (speaking 0.4)) ;neg-cond
                 1  nil)                          ;thresh ;state
    (taking-turn ((gesturing 1.0)      ;pos
                  (speaking 1.0))
                 ((looking-at-me 0.5)) ;neg
                 1 nil) ;for neg-cond we could also have (not self-adjustor)
    (want-back-ch-feedb ((looking-at-me 0.5) 
                         (speaking 0.5))
                        ()
                        1 nil)
    (looking-at-hands ((looking-at-r-hand 1.0) 
                       (looking-at-l-hand 1.0))
		       () 1 nil)
    (hand-in-gest-space ((lhand-in-gest-space 1.0)
                         (rhand-in-gest-space 1.0))
                        () 1 nil)
    (is-active ((hand-in-gest-space 1.0)(speaking 1.0)) 
               () 1 nil)
    (gesturing ((hand-in-gest-space 0.5)(speaking 0.6))
	       () 1 nil)
    (complete-utter ((complete-inton 0.5) 
		     (complete-gram 0.5) 
                     (complete-pragm 0.5))
                    () 1 nil)
    (addressing-me ((turned-to-me 1.0)(facing-me 1.0)(facing-domain 1.0))
                   () 1 nil)
    (wanting-turn ((speaking 0.5)
                   (hand-in-gest-space 0.6))
                  () 1 nil)
    (concluding () 
                () 1 nil)
    (saying-goodbye () 
                    () 1 nil)
;    (saying-my-name ()
;                    () 1 nil)
;not sure we need greeting here....
;    (greeting ()
;              () 1 nil)
    ))


;************ define the internal turn behaviors **************

; To create, call (make-turn-state-beh *turn-state-behaviors*)

; language use: agent has "take/give", user is "taking/giving":

(defparameter *turn-state-behaviors*    
  ;These behaviors change the turn state and are thus internal.
  ;TEMPLATE: nodename msgs next-state pos-cond neg-cond active-descr thresh state
    '(
      (take-turn1 take-turn       ; name of node and what to post in turn-history.
                  (give-turn dial-on)     ; next states that should be active-the ones that should follow.
		  (addressing-me  wanting-turn)   ; pos cond that make next-state active/t
                                  ; (=transition conds to cancel curr state)
		  (KB-exe-act spch-data-avail)    ; neg-cond that make next-state active
                ; active-descr...should include giving-back-ch-feedb.
                   (taking-turn   ; descriptors that will enable transition to next state
                    wanting-turn  ; and should therefore be active *now*.
		    gesturing 
                    addressing-me
                    saying-goodbye
                    concluding
		    hand-in-gest-space 
;;		   is-active 
                    looking-at-hands)
                    1  nil)       ; thresh       ; state
      (take-turn2 take-turn       ; name of node and what to post in turn-history.
                  (give-turn dial-on)     ; next states that should be active-the one that should follow.
		  (addressing-me  taking-turn)   ; pos cond that make next-state active/t
                                  ; (=transition conds to cancel curr state)
		  (KB-exe-act)    ; neg-cond that make next-state active
                ; active-descr...should include giving-back-ch-feedb.
                   (taking-turn   ; descriptors that will enable transition to next state
                    wanting-turn  ; and should therefore be active *now*.
		    gesturing 
                    addressing-me
                    saying-goodbye
                    concluding
		    hand-in-gest-space 
;;		   is-active 
                    looking-at-hands)
                    1  nil)       ; thresh       ; state
 ;     (take-turn3 take-turn       ; name of node and what to post in turn-history.
 ;                 (give-turn dial-on)     ; next states that should be active-the one that should follow.
;		  (facing-me (time-since facing-me 300)) ; pos cond that make next-state active/t
 ;;                                 ; (=transition conds to cancel curr state)
;		  (KB-exe-act spch-data-avail)         ; neg-cond that make next-state active
 ;;               ; active-descr...
;		  (taking-turn   ; descriptors that will enable transition to *next* state(s)
;		   wanting-turn  ; and should therefore be active *now*.
;		   gesturing 
 ;                  addressing-me
;		   saying-goodbye
;		   concluding
;		   hand-in-gest-space 
;;		   is-active 
;		   looking-at-hands)
;		  1  nil)       ; thresh       ; state
;      (give-turn1 give-turn       ; what to post.
;		  (take-turn dial-on)            ; next states that should be active.
;                  (giving-turn (time-since 'give-turn 200))  ; pos-conds  (=transition rule)
;                  (speaking)                     ; neg-conds 
;                  (gesturing                     ; active descriptors
;                   taking-turn 
;      ;             giving-turn 
;;                filler 
;                   looking-at-hands
;                   complete-utter 
;                   want-back-ch-feedb 
;                   saying-goodbye
;                   concluding
;                   is-active) ;active-descr
;                   1 nil)       ;thresh  ;state        

;    (take-turn3 take-turn                   ; what to post.
;                ((time-since speaking 400)) ; pos-conds
;                (speaking)                  ; neg-conds
;                (taking-turn wanting-turn gesturing) ; These updated during this state.
;                all  nil)
      
    ;Perhaps there should be a give-turn-by-free-will 
    ;and then give-turn-bec-user-interrupt;the 
    ;latter would not have goal-list-empty as a condition. In fact, when give-turn is set to
    ;true when goal-list is not empty, there is a different method for 
    ;giving the turn, like "I'm sorry, what was that?" 
      
      (give-turn2 give-turn      ; node name and posting (state) name.
		  (take-turn dial-on)         ; next states that should be active.
		  ((time-since 'speaking 50) giving-turn)  ; pos-cond that make next-state active
                  (taking-turn)    ;neg-cond
                  (gesturing 
                   addressing-me
                   taking-turn 
                   giving-turn 
;                filler 
                   saying-goodbye
                   concluding
                   looking-at-hands
                   complete-utter 
                   want-back-ch-feedb 
                   is-active) ;active-descr
                   1 nil)       ;thresh  ;state         
    ;TEMPLATE: nodename what-to-post next-state pos-cond neg-cond active-descr thresh state
      ))


;************ define external turn behaviors **************
;
; These are actually communicating with the TKB, or part
; of it, because they control the sensory apparatus and
; semantic functions.
;

;************ external turn behaviors **************

; To create, call (make-ext-Rea-Beh *Ext-rea-behaviors*)
; ALL TIME VALUES IN CENTISECONDS

(defparameter *ext-rea-behaviors*
  ;These behaviors control the external behavior of the agent.
  ;TEMPLATE: name extent  [=centiseconds]
  ;               type 
  ;               posconds 
  ;               negconds 
  ;               pos-restore-conds - conds that will make the beh on the outlook for its conds
  ;               neg-restore-conds 
  ;               actions [slot name = msgs]
  ;               initial state [=T or NIL]
    '((show-take-turn1 500                   ;name & extent
                       ext-one-shot-rea-beh  ;type
                       (take-turn)           ;positive trigger conditions.
                       nil                   ;negative trigger conditions.
                       nil                   ;positive restore conditions [not used for cont beh]
                       (take-turn)           ;negative restore conditions [not used for cont beh]
                       (Show-Take-Turn)      ;actions
                       nil)                  ;initial state = is the beh allowed to be executed?
;    (be-impatient  200
;		   ext-one-shot-rea-beh  ;type
;		   (give-turn (time-since speaking 300))
;		   (speaking)
;		   nil               ;positive restore conditions
;		   (take-turn)       ;negative restore conditions
;		   (slow-cube1)
;		   nil)
;    (show-idle 200
;	       ext-one-shot-rea-beh  ;type
;	       (give-turn (time-since speaking 500))  ;pos cond
;	       (speaking)                             ;neg cond
;	       nil               ;positive restore conditions
;	       (give-turn)       ;negative restore conditions
;	       (slow-cube2)
;	       nil)
;    (surprised 500
;	       ext-one-shot-rea-beh  ;type
;               (take-turn hand-in-gest-space) ;pos conds
;               (speaking)                                      ;neg conds
;	       nil               ;positive restore conditions
;	       (take-turn)       ;negative restore conditions
;               (speed-cube)
;               nil)
;    (pay-attention 10000
;		   ext-one-shot-rea-beh  ;type
;		   (give-turn)
;		   nil
;		   nil              ;positive restore conditions
;		   (give-turn)      ;negative restore conditions
;		   (speed-cube)  ;specifies the constituents of action (+ options?).
;		   nil)             ; (or, the actions' constituents 
                                    ; could be specified somewhere else.)
 ;   (show-not-participating 10000 ;instead of "forever" 
 ;                           dialogue-not-started
 ;                           nil
 ;                           nil
 ;                           (make-dot-red) ;actions
 ;                           nil)           
      
;    (displ-speaking forever     ;this beh is just to show delay of user-speaking->motor act
;		    ext-one-shot-rea-beh  ;type
;                    (speaking)
;                    nil
;		    (t)               ;positive restore conditions
;		    nil               ;negative restore conditions
;                    (displ-speaking)
;                    nil)
;    (displ-silent forever
;                  ext-one-shot-rea-beh
;                  nil
;                  (speaking)
;                  (t)
;                  nil
;                  (displ-silent)
;                  nil)
;      (show-eager 1000                    
;		  ext-one-shot-rea-beh
;		  (turned-to-me facing-me)
;		  nil
;		  nil
;		  (turned-to-me)
;		  (head-at-zero-zero) ;second element indicates which object to reference.
;		  nil)
;      (show-eager2 1000                   
;		   ext-one-shot-rea-beh
;		   (turned-to-me facing-me)
;		   nil
;		   nil
;		   (turned-to-me)
;		   (gaze-at-zero-zero) ;second element indicates which object to reference.
;		   nil)
;      (show-addressing-user1 1000
;                             ext-one-shot-rea-beh
;                             (DKB-exe-act)
;                             nil
;                             (take-turn)
;                             nil
;                             (head-at-zero-zero)
;                             Nil)
  ;    (show-addr-me3 20 ;centiseconds
  ;                   ext-one-shot-rea-beh
;		     (turned-to-me facing-me)
 ;                    nil
  ;                   nil
   ;                  (turned-to-me) ;if not turned to me, restore
;		     (smile)
 ;                    nil)
  ;    (show-addr-me4 20 ;centiseconds
  ;                   ext-one-shot-rea-beh
;		     (turned-to-me facing-me speaking)
 ;                    nil
  ;                   nil
   ;                  (facing-me) ;if not facing me, restore
;		     (turn-to user)
 ;                    nil)
      (show-addr-me5 20 ;lifetime in centiseconds
                     ext-one-shot-rea-beh
		     (saying-my-name turned-to-me facing-me)
                     nil
                     nil
                     (turned-to-me)  ;if not turned to me, restore
		     (eyebrow-greet)
                     nil)
      (show-listen 20 ;lifetime in centiseconds
		   ext-one-shot-rea-beh
		   (saying-my-name turned-to-me facing-me)
		   nil
		   nil
		   (turned-to-me)
		   (brows-in-pensive-shape)
		   nil)
      (initialize   20 ;lifetime in centiseconds
		    ext-one-shot-rea-beh
		    (dial-off)
		    nil
                    (dial-on)
		    nil
                    (face-neutral)
		    nil)
 ;     (look-puzzled 100 ; 1 sec
;		    ext-one-shot-rea-beh
;		    (turned-to-me facing-me (time-since 'facing-me 400))
;		    nil
;		    nil
;		    (turned-to-me)
;		    (look-puzzled)
;		    nil)
      (look-aloof 100 ;centiseconds
		  ext-one-shot-rea-beh
		  (turned-to-me facing-me (time-since 'facing-me 800) dial-off)
		  (speaking kb-parsing)
		  nil
		  (turned-to-me)
		  (look-aloof)
		  nil)
;    (show-addr-me5 200
;		   ext-one-shot-rea-beh
;		   (turned-to-me facing-me)
;                  nil
;                   (turned-to-me)
;                   nil
;		   (turn-to user)
;                   nil)
      (show-not-addr-me 100
                        spatial-rea-beh
                        (dial-off)
                        (turned-to-me)
                        (taking-turn) ;pos restr cond
                        nil
                        (turn-to big-screen)
                        nil)
      (show-give-turn1 200                   ;name & extent
                       ext-one-shot-rea-beh  ;type
                       (give-turn)
                       nil
                       nil               ;positive reset conditions
                       (give-turn)       ;negative reset conditions
                       (show-give-turn)
                       nil)
      (show-give-turn2 200               ;name & extent
                       ext-one-shot-rea-beh  ;type
                       (give-turn)
                       nil
                       nil               ;positive reset conditions
                       (give-turn)       ;negative reset conditions
                       (gaze-at-zero-zero)
                       nil)
   ;   (show-give-turn3 200               ;name & extent
   ;                    ext-one-shot-rea-beh  ;type
   ;                    (give-turn)
   ;                    nil
   ;                    nil               ;positive reset conditions
   ;                    (give-turn)       ;negative reset conditions
   ;                    (turn-to user)
   ;                    nil)
      )
  )


;*********** EXTERNAL CONTINUOUS REACTIVE BEHAVIORS ***********

(defparameter *ext-cont-rea-behaviors*  
  ;These behaviors control the external behavior of the agent.
  ; All values in centiseconds.
  ;TEMPLATE: name extent 
  ;               type 
  ;               posconds  ;if t = forever on
  ;               negconds 
  ;               actions (slot name = msgs)
  ;               initial state (T or NIL)
  ;               period
    '((blink-slowly 10000
                    ext-cont-rea-beh
                    (dial-off)  
                    nil
                    (blink-slowly)
                    t
                    300)
      (blink 10000
             ext-cont-rea-beh
             (dial-on)   ;if t = forever on
             nil
             (blink)
             t
             300)
;      (show-addr-me2 10000                     ;2/19/96 new action!
;		 spatial-rea-beh          ;If the motor sys had direct access to spatial data,
;		 (turned-to-me facing-me)  ;we wouldn't need to duplicate show-addr-me in this way.
;		 nil
;		 (look-at user)
;		 nil
;		 600) ;look at user every 6 seconds while talking.
;      (cont-look-at-user 10000
;                         spatial-rea-beh
;                         (DKB-exe-beh)
;                         nil
;                         (turn-to user)
;                         nil
;                         500)
      ))




(defparameter *int-rea-behaviors*
      ;TEMPLATE: name extent type posconds negconds pos-res neg-res msgs
    '(
;      (one-shot-listen forever
;                       int-one-shot-rea-beh  ;type
;                       (give-turn)           ;pos firing conds
;                       nil                   ;neg firing conds
;                       nil                   ;pos reset
;                       (give-turn)           ;neg reset
;                       (one-shot-spch)       ;msgs
;                       )
;      (cont-listen forever
;                   int-one-shot-rea-beh
;                   (see-user)
;                   ()
;                   nil
;                   nil
;                   (cont-speech)
;                   )
 ;     (clear-buffs 10000
;		   int-one-shot-rea-beh
;		   (give-turn)
;		   nil
;		   (take-turn)
;		   nil
;		   (clear-spch-buffs)
;		   )
      )
  )
      


;******************************************
;*   PROCESS CONTROL LAYER Behaviors
;******************************************

; These are actually communicating with the TKB, or part
; of it, because they control the sensory apparatus and
; semantic functions.

; These should perhaps all be moved to a file named
; after the character they belong to.

; A neat way to make actions that won't occur for a long
; time after they have been done is to include a long
; time-delay, plus some event, in their restore conditions.

;NOTICE: only DESCRIPTORS may appear in conditions (neg/pos)
;why?

(defparameter *PCL-state-behaviors* 
    ;TEMPLATE 
      ;name type message pos-c neg-c init-state
    '((dial-on1 PCL-state-beh         ;to start dialogue with user
                dial-on               ;what to post (=what state is it now)
	        (dial-off)            ;next states that should be active
	        (saying-goodbye concluding) ;pos-conds that make transition possible
                (dial-off)            ;neg-conds that make transition possible
                (saying-goodbye       ;desciptors that make transition from this state possible
                 concluding)
                nil)
      (dial-off1 PCL-state-beh   ;this one requires the user to say the agent's name
                 dial-off
                 (dial-on give-turn) ;probably HAVE to have give-turn in both ...
                 (saying-my-name)
                 (dial-off)
                 (addressing-me gesturing)
                 nil)
      (dial-off2 PCL-state-beh
                 dial-off                 ;what to post (=what state is it now)
                 (dial-on give-turn)      ;next state(s) that should be active
                 (addressing-me)          ;pos-conds that make transition posible
                 ()                       ;neg-conds that make this state true
                 (addressing-me)          ;descr that enable transition to next
                 nil)
      )
  )


; Here we would update speech through a node...
(defparameter *int-PCL-behaviors* 
    ;Here are actions like excusing delay; asking about missing info, etc.
    ;TEMPLATE 
      ;name type extent msgs pos-c neg-c pos-restr neg-restr init-state
    '((parse-speech int-PCL-beh 200
                    (parse-speech)
		    (giving-turn spch-data-avail)              ;pos-cond
		    ()  ;neg-cond
		    (give-turn)                                ;pos-restr conds
		    ()                                         ;neg-restr-conds
		    nil)
  ;    (rem-spch-addr-to-others int-PCL-beh 200
;			       (rem-spch-to-others)
;			       ((time-since 'speaking 50))
;			       (addressing-me KB-exe-act)
;			       (speaking)
;			       ()
;			       nil)
;      (remove-partial-parses int-PCL-beh 100
 ;                            (rem-part-parses)
 ;                            (KB-succ-parse KB-exe-act)
 ;                            (addressing-me)
 ;                            ()
 ;                            (KB-exe-act)
 ;                            nil)
   ;   (report-no-words int-PCL-beh 50
   ;                    (compose-DKB-trouble-report 'no-words)
   ;                    ((kb-time-since 'RCV-spch 350) addressing-me giving-turn)
   ;                    (CL-act-avail KB-succ-parse KB-exe-act speaking)
   ;                    (give-turn)
   ;                    ()
   ;                    nil)
      )
  )

(defparameter *ext-PCL-behaviors* 
    ;Here are actions like excusing delay; asking about missing info, etc.
    ;TEMPLATE 
      ;name type extent msgs pos-c neg-c pos-restr neg-restr init-state
        ;2/27/96 ? NOTICE: if msgs is a list, first element should be a 
        ;function that takes the rest of msgs in the form of a list as parameters
    '((hesitate1 ext-PCL-beh 100
                 hesitate                                       ;action
		 (dial-on take-turn SPCH-data-avail (time-since speaking 70))   ;pos-cond
		 (CL-act-avail speaking)                        ;neg-cond
		 (give-turn)                                    ;pos-restr conds
		 ()                                             ;neg-restr-cond
                 nil)
      (turn-to-user ext-spatial-PCL-beh 2000
                    (turn-to user)
                    (TKB-exe-speech-act)
		    ()
                    ()
                    (TKB-exe-speech-act)
                    nil)
      (show-content-delivery ext-spatial-PCL-beh 2000
                             (look-at user)
                             (DKB-exe-act looking-at-me)
		             ()
                             (take-turn)
                             ()
                             nil)
      (pay-attention-to-act ext-spatial-PCL-beh 2000
                            (turn-to big-screen)      ;msgs
                            (TKB-exe-world-act)       ;pos-cond
                            ()                        ;neg-cond
                            nil
                            (TKB-exe-world-act)       ;neg-restr-cond
                            nil)
 ;     (show-busy ext-PCL-beh 200
 ;                manual-hold-it-signal
 ;                (speaking facing-me TKB-exe-world-act)
 ;                ()
 ;                ()
 ;                (TKB-exe-world-act)
 ;                nil)
      (show-done-exe ext-spatial-PCL-beh 2000
		     (look-at user)      ;msgs
		     ()                        ;pos-cond
		     (TKB-exe-world-act)       ;neg-cond
		     (TKB-exe-world-act)       ;pos-restr-cond
		     nil
		     nil)
      (show-done-exe2 ext-spatial-PCL-beh 2000
		      (turn-to user)      ;msgs
		      ()                        ;pos-cond
		      (TKB-exe-world-act)       ;neg-cond
		      (TKB-exe-world-act)       ;pos-restr-cond
		      nil
		      nil)
      (show-know-addressing ext-spatial-PCL-beh 2000
                            (look-at 'user)
                            (TKB-exe-world-act looking-at-me facing-me speaking)
                            ()
                            ()
                            (TKB-exe-world-act)
                            nil)
      (show-idle ext-PCL-beh 2000
                 restless
                 ()
                 (facing-me)
                 (facing-me)
                 ()
                 nil)
      (look-at-domain ext-spatial-PCL-beh 2000
                      (turn-to big-screen)
                      (facing-domain take-turn)
                      (speaking)
                      (taking-turn)
                      ()
                      nil)
      (look-relaxed ext-PCL-beh 2000
                    face-neutral
                    (TKB-exe-world-act)
                    ()
                    ()
                    (TKB-exe-world-act)
                    nil)
      (show-listening ext-spatial-PCL-beh 1000
                      (turn-to user)
                      (speaking addressing-me)
                      ()
                      (take-turn)
                      ()
                      nil)
      (show-listening2 ext-spatial-PCL-beh 1000
                       (look-at user)
                       (speaking addressing-me)
                       ()
                       (take-turn)
                       ()
                       nil)
;      (look-at-big-screen2 ext-spatial-PCL-beh 2000
;                           (look-at big-screen)     ;msgs
;                           (TKB-exe-world-act)      ;pos-cond
;                           ()                       ;neg-cond
;                           (give-turn)
;                           ()
;                           nil)
;      (deliver-CL-problem ext-PCL-beh
;                          
      )
  )


;************* CONTENT LAYER BEHAVIORS **************

; When a 'problem report' is received from TKB (reported on KB-msgs)
; an ext-PCL-beh is created with the correct slots filled.

(defparameter *ext-CL-behaviors* 
    ;TEMPLATE
      ;name type func pos-c neg-c pos-restr neg-restr init-state
    '((do-TKB-act ext-CL-beh 2000
	          (post-TKB-act)
	          (dial-on TKB-act-avail take-turn) ;pos-cond
	          ()                                ;neg-cond
	          (CL-act-avail) ;pos-restr conds
	          () ;neg-restr-conds
	          nil
	          )
      (do-DKB-act ext-CL-beh 2000
	          (post-DKB-act)
	          (dial-on DKB-act-avail take-turn) ;pos-cond
	          ()                                ;neg-cond
	          (CL-act-avail) ;pos-restr conds
	          () ;neg-restr-conds
	          nil
	          )
 ;     (turn-to-big-screen3 ext-spatial-PCL-beh 2000    ;perhaps allow this later...????
 ;                          (turn-to big-screen)        ;msgs
 ;                          (TKB-exe-world-act)         ;pos-cond
 ;                          ()                          ;neg-cond
 ;                          (give-turn)
 ;                          ()
 ;                         nil)
      )
  )


(defmethod compose-manual-gesture ()
  (let ((rnd (random (length manual-beats))))
    (nth rnd manual-beats)
    ))

;Automatically makes all these behaviors
;when the file is eval'd

(make-all)