X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=blobdiff_plain;f=src%2Fmain%2Fnvm%2Fagent.lisp;h=8e97ea002c5bdf5ff4c06e12c8cd5a2b04ef9283;hb=31f7cb6;hp=e26186e206d288f99816bf52d490e646c422f932;hpb=ef8590acac123b880b2719eaac691af310262cca;p=clnl diff --git a/src/main/nvm/agent.lisp b/src/main/nvm/agent.lisp index e26186e..8e97ea0 100644 --- a/src/main/nvm/agent.lisp +++ b/src/main/nvm/agent.lisp @@ -36,7 +36,7 @@ DESCRIPTION: (defmethod set-agent-value-inner ((,agent ,type) (,var (eql ,symb)) ,new-val) (setf (,accessor ,agent) ,new-val))))) ; Don't want the setter for :who -(defmethod agent-value-inner ((agent turtle) (var (eql :who))) (turtle-who agent)) +(defmethod agent-value-inner ((turtle turtle) (var (eql :who))) (turtle-who turtle)) (defagent-value patch :pcolor patch-color) @@ -44,3 +44,23 @@ DESCRIPTION: (defagent-value turtle :label) (defagent-value turtle :label-color) (defagent-value turtle :size) + +(defmethod agent-value-inner ((turtle turtle) var) + (when (not (find var *turtles-own-vars*)) (error "~S is not a turtle variable" var)) + (or (getf (turtle-own-vars turtle) var) 0d0)) + +(defmethod set-agent-value-inner ((turtle turtle) var new-val) + (when (not (find var *turtles-own-vars*)) (error "~S is not a turtle variable" var)) + (if (getf (turtle-own-vars turtle) var) + (setf (getf (turtle-own-vars turtle) var) new-val) + (setf (turtle-own-vars turtle) (append (list var new-val) (turtle-own-vars turtle))))) + +(defmethod agent-value-inner ((patch patch) var) + (when (not (find var *patches-own-vars*)) (error "~S is not a patch variable" var)) + (or (getf (patch-own-vars patch) var) 0d0)) + +(defmethod set-agent-value-inner ((patch patch) var new-val) + (when (not (find var *patches-own-vars*)) (error "~S is not a patch variable" var)) + (if (getf (patch-own-vars patch) var) + (setf (getf (patch-own-vars patch) var) new-val) + (setf (patch-own-vars patch) (append (list var new-val) (patch-own-vars patch)))))