#+(and :allegro :allegro-ide) (in-package :common-graphics-user) #+(and :allegro (not :allegro-ide)) (in-package :common-lisp-user) #+(or :mcl :lispworks4.2 :cmu18 :sbcl) (in-package :common-lisp-user) (defagent *agent-03* "*Agent-03*" ;;; ============================================================================== ;;; Establish control nodes that sense state... ;;; If a target is <= 120 game units away, THEN assert that target is ;;; within range, ELSE assert that target is not within range. (defsensor 3-assess-range *agent-03* (==> (and (target ?target ?agent) (location ?target ?tx ?ty ?tz) (location ?agent ?ax ?ay ?az) (func within-n-units? ?ax ?ay ?tx ?ty 120 ?result)) (within-range ?agent ?target ?result))) ;;; IF target is visible, THEN strafe towards the target. (defsensor 3-strafe/target *agent-03* (==> (and (target ?target ?agent) (location ?target ?tx ?ty ?tz)) (strafeto-target ?tx ?ty ?tz 1 ?target))) ;;; IF agent is stationary, AND IF a target can be located, THEN turn ;;; to face the target. (defsensor 3-rotate/follow *agent-03* (==> (and (target ?target ?agent) (velocity ?agent 0.0 0.0 ?zv) (location ?target ?x ?y ?z)) (turnto-location ?x ?y ?z 1))) ;;; ============================================================================== ;;; Establish control nodes that evaluate state via some computation... ;;; IF target is found to be within range, THEN assert an intention ;;; to stop moving towards the target. (defdeliberator 3-in-range *agent-03* (==> (within-range ?agent ?target yes) (stop-moving now))) ;;; ============================================================================== ;;; Establish control nodes that initiate action... ;;; Asserts an intention to execute a stop-moving action. (defeffector 3-stop-moving *agent-03* :r (==> (stop-moving ?when) (upload-cmd stop-moving))) ;;; Asserts an intention to execute a strafeto-target action. (defeffector 3-strafeto-target *agent-03* :r (==> (strafeto-target ?x ?y ?z ?priority ?target) (upload-cmd strafeto-target))) ;;; Asserts an intention to execute a turnto-location action. (defeffector 3-turnto-location *agent-03* :r (==> (turnto-location ?x ?y ?z ?w) (upload-cmd turnto-location))) ;;; ============================================================================== ;;; Establish relationships between the control nodes... (deftopology *agent-03* :basic-agent :threshold-devices ((td1 . 1) (td2 . 1) (td3 . 1)) :simple-relays (sr1 sr2 sr3 sr4 sr5) :pseudo-states (i_start i_stop fork) :lines (((i_start :pos (fork)) (fork :pos (3-assess-range)) (fork :pos (3-strafe/target)) (fork :pos (3-rotate/follow)) (3-rotate/follow :pos (sr1)) (sr1 :pos (sr2)) (sr2 :pos (td1)) (sr2 :neg (td3)) (td3 :pos (3-stop-moving)) (3-stop-moving :pos (i_stop)) (td1 :pos (3-turnto-location)) (3-turnto-location :pos (i_stop)) (3-strafe/target :pos (sr3)) (sr3 :pos (td2)) (td2 :pos (sr4)) (td2 :neg (td1)) (sr4 :pos (3-strafeto-target)) (3-strafeto-target :pos (i_stop)) (3-assess-range :pos (3-in-range)) (3-in-range :pos (sr5)) (3-in-range :neg (td2)) (sr5 :pos (td3)))) :starts (i_start)) )