#+(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-02* "*Agent-02*" ;;; ============================================================================== ;;; Establish control nodes that sense state... ;;; IF agent is stationary, AND IF a target can be located, THEN turn ;;; to face the target. (defsensor 2-rotate/follow *agent-02* (==> (and (target ?target ?agent) (location ?target ?x ?y ?z)) (turnto-location ?x ?y ?z 1))) ;;; IF agent is > 200 game units from a target, THEN assert that ;;; agent is NOT within range, ELSE assert that agent IS within ;;; range. (defsensor 2-assess-range *agent-02* (==> (and (target ?target ?agent) (location ?target ?tx ?ty ?tz) (location ?agent ?ax ?ay ?az) (func within-n-units? ?ax ?ay ?tx ?ty 200 ?result)) (within-range ?agent ?target ?result))) ;;; ============================================================================== ;;; Establish control nodes that evaluate state via some computation... ;;; IF target is found to NOT be within range, THEN assert an ;;; intention to strafe towards the target. (defdeliberator 2-outside-range *agent-02* (==> (and (within-range ?agent ?target no) (location ?target ?x ?y ?z)) (strafeto-target ?x ?y ?z 1 ?target))) ;;; ============================================================================== ;;; Establish control nodes that initiate action... ;;; Asserts an intention to execute a turnto-location action. (defeffector 2-turnto-location *agent-02* :r (==> (turnto-location ?x ?y ?z ?w) (upload-cmd turnto-location))) ;;; Asserts an intention to execute a strafeto-target action. (defeffector 2-strafeto-target *agent-02* :r (==> (strafeto-target ?x ?y ?z ?priority ?target) (upload-cmd strafeto-target))) ;;; ============================================================================== ;;; Establish relationships between the control nodes... (deftopology *agent-02* :basic-agent :threshold-devices ((td1 . 1)) :simple-relays (sr1 sr2) :pseudo-states (i_start i_stop fork) :lines (((i_start :pos (fork)) (fork :pos (2-rotate/follow)) (fork :pos (2-assess-range)) (2-assess-range :pos (2-outside-range)) (2-outside-range :pos (sr1)) (2-outside-range :neg (td1)) (td1 :pos (2-turnto-location)) (2-turnto-location :pos (i_stop)) (sr1 :pos (2-strafeto-target)) (2-strafeto-target :pos (i_stop)) (2-rotate/follow :pos (sr2)) (sr2 :pos (td1)))) :starts (i_start)) )