;; -*- Mode: LISP; Syntax: Common-Lisp; Package: (USER); -*-

(in-package 'USER)


;********************************
;* Testing (Simulation routines)
;********************************


(defun simulate-gesture (counter)
  (princ #\newline) (princ "counter:")(print counter)
  (case counter
    (1 (progn
	 (setf (state speaking) T)
         (post speaking)
	 (princ "turned speaking on")))
    (2 (progn
         (print 'hello1)
         (setf (state rhand-in-gest-space) T)
	 (post rhand-in-gest-space)
	 (princ "turned rhand-in-gest-space on")
	 (print 'hello2)
         (setf (state looking-at-hands) T)
	 (post looking-at-hands)
	 (princ "turned looking-at-hands on")
	 ))
    (3 (progn
	 (setf (state speaking) nil)
	 (post speaking)
	 (princ "turned speaking off")))
    (4 (princ "nothing happened here"))
    (5 (progn
	 (setf (state speaking) T)
	 (post speaking)
	 (princ "turned speaking on")))
    (6 (setf (state rhand-in-gest-space) nil
             (state looking-at-hands) nil)
       (post rhand-in-gest-space)
       (post looking-at-hands))
    (7 (progn (setf (state speaking) nil)
         (post speaking)
         (setf (state complete-utter) t)
         (post complete-utter)
	 (setf (state looking-at-me) T)
         (post looking-at-me)))
    (8 (setf counter 0)))
  )

(setf pause 30)

(defun run ()
  (unless (boundp 'speaking)
    (make-all))
  (reset-read-file *read-file*)
  (initialize-all)
  (setf *now* (reactive-time-base)
        counter 1)
;  (initialize *sensors*)     ;This is a list with ALL data.
;  (initialize *descriptors*)
  (if *display-on* (redraw))
  (loop
    (if (< pause (- (rtb) *now*))
      (progn 
        (princ "calling simulate")
        (simulate-gesture counter)
;        (print-history *turn-history*)
;        (dolist (obj *ext-turn-beh*) (print (name obj)) (print (done obj)))
        (setf *now* (rtb)
              counter (+ counter 1))))
    (update *sensors*)        ;lists of the objects themselves....
    (refresh-body-data)
    (DESCRIBE *body*)
    (update *descriptors*)
;    (print *descriptors*)
    (update *int-turn-beh*)
    (update *ext-turn-beh*)
;    (print (state wanting-turn))
;    (princ "PENDING: ")(print *pending-behaviors*)
    (if *pending-behaviors* (execute *pending-behaviors*))
;    (if (find-window "NETWORK GRAPH") (show-state *gw*))
;    (if (find-window "NETWORK GRAPH") (show-active *gw*))
;    (print *turn-history*)
;    (if *display-on* (redraw))
    ))

(defun print-history (a-list-of-lists)
  (dolist (a-list (reverse a-list-of-lists))
    (print a-list)))
