Add strictmath library
[clnl] / src / main / nvm.lisp
index bf8981a2f6e359b01ab8c61787a610792c023633..018ce7e650341d7d1327163b8c0be343e4c1b8fa 100644 (file)
@@ -6,6 +6,7 @@
 (defvar *turtles* nil)
 (defvar *myself* nil)
 (defvar *self* nil)
+(defvar *model* nil)
 
 (defun show (value)
  "SHOW VALUE => RESULT
@@ -140,8 +141,12 @@ DESCRIPTION:
 
   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#forward"
  (when (not (turtle-p *self*)) (error "Gotta call fd in turtle scope, dude (~A)" *self*))
- (setf (turtle-xcor *self*) (+ (turtle-xcor *self*) (* n (sin (* pi (/ (turtle-heading *self*) 180))))))
- (setf (turtle-ycor *self*) (+ (turtle-ycor *self*) (* n (cos (* pi (/ (turtle-heading *self*) 180)))))))
+ (setf
+  (turtle-xcor *self*)
+  (+ (turtle-xcor *self*) (* n (strictmath:sin (strictmath:to-radians (turtle-heading *self*))))))
+ (setf
+  (turtle-ycor *self*)
+  (+ (turtle-ycor *self*) (* n (strictmath:cos (strictmath:to-radians (turtle-heading *self*)))))))
 
 (defun create-turtles (n)
  "CREATE-TURTLES N => RESULT
@@ -162,11 +167,12 @@ DESCRIPTION:
   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#create-turtles"
  (loop :for i :from 1 :to n :do (create-turtle)))
 
-(defun create-world ()
- "CREATE-WORLD => RESULT
+(defun create-world (model)
+ "CREATE-WORLD MODEL => RESULT
 
 ARGUMENTS AND VALUES:
 
+  MODEL: A clnl-model:model to use to initialize the vm
   RESULT: undefined
 
 DESCRIPTION:
@@ -175,6 +181,7 @@ DESCRIPTION:
 
   This should be called before using the engine in any real capacity.  If
   called when an engine is already running, it may do somethign weird."
+ (setf *model* model)
  (setf *turtles* nil)
  (setf *current-id* 0))
 
@@ -256,7 +263,10 @@ DESCRIPTION:
    (format nil "~A~A"
     "\"min-pxcor\",\"max-pxcor\",\"min-pycor\",\"max-pycor\",\"perspective\",\"subject\","
     "\"nextIndex\",\"directed-links\",\"ticks\",")
-   (format nil "\"-1\",\"1\",\"-1\",\"1\",\"0\",\"nobody\",\"~A\",\"\"\"NEITHER\"\"\",\"-1\"" *current-id*)
+   (format nil "\"~A\",\"~A\",\"~A\",\"~A\",\"0\",\"nobody\",\"~A\",\"\"\"NEITHER\"\"\",\"-1\""
+    (getf (clnl-model:world-dimensions *model*) :xmin) (getf (clnl-model:world-dimensions *model*) :xmax)
+    (getf (clnl-model:world-dimensions *model*) :ymin) (getf (clnl-model:world-dimensions *model*) :ymax)
+    *current-id*)
    ""
    (format nil "~S" "TURTLES")
    (format nil "~A~A"