source: scenarios/GerminationX/oak/src/oak/remote_agent.clj @ 1706

Revision 1596, 2.6 KB checked in by dave, 9 years ago (diff)

summons sorted out, diagnosis and helpers fixed, different plant spirit personalities

Line 
1;; Copyright (C) 2010 FoAM vzw
2;; This program is free software: you can redistribute it and/or modify
3;; it under the terms of the GNU Affero General Public License as
4;; published by the Free Software Foundation, either version 3 of the
5;; License, or (at your option) any later version.
6;;
7;; This program is distributed in the hope that it will be useful,
8;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10;; GNU Affero General Public License for more details.
11;;
12;; You should have received a copy of the GNU Affero General Public License
13;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
15(ns oak.remote-agent
16  (:use
17   oak.vec2
18   oak.io)
19  (:import
20   java.net.Socket
21   java.io.File
22   java.io.IOException
23   java.util.Random
24   java.io.BufferedReader
25   java.io.InputStreamReader))
26
27(defn remote-agent-properties [remote-agent] (:properties remote-agent))
28(defn remote-agent-name [remote-agent] (:name remote-agent))
29(defn remote-agent-role [remote-agent] (:role remote-agent))
30(defn remote-agent-display-name [remote-agent] (:display-name remote-agent))
31(defn remote-agent-socket [remote-agent] (:socket remote-agent))
32(defn remote-agent-relations [remote-agent] (:relations remote-agent))
33(defn remote-agent-emotions [remote-agent] (:emotions remote-agent))
34(defn remote-agent-said [remote-agent] (:said remote-agent))
35(defn remote-agent-done [remote-agent] (:done remote-agent))
36(defn remote-agent-random [remote-agent] (:random remote-agent))
37(defn remote-agent-reader [remote-agent] (:reader remote-agent))
38(defn remote-agent-tile [remote-agent] (:tile remote-agent))
39
40(defn remote-agent-add-property [agent property]
41  (merge agent {:properties (cons property (remote-agent-properties agent))}))
42
43(defn make-remote-agent [socket world]
44  ;(.configureBlocking socket false)
45  ;(. (AutobiographicalMemory/GetInstance) setSelf name)
46
47  (let [reader (BufferedReader.
48                (InputStreamReader.
49                 (.getInputStream (.socket socket))))
50        toks (.split (read-msg socket) " ")]
51    (send-msg socket "OK")
52    (hash-map
53     :properties (reduce
54                  (fn [r prop]
55                    (let [tv (.split prop ":")]
56                      (assoc r (first tv) (second tv))))
57                  {}
58                  (nthnext toks 3))
59     :name (nth toks 0)
60     :role (nth toks 1)
61     :display-name (nth toks 2)
62     :socket socket
63     :relations "none yet"
64     :emotions "none yet"
65     :said '()
66     :done '()
67     :random (new java.util.Random)
68     :reader reader
69     :tile (make-vec2 0 0)
70     :last-summons 0
71     :delayed-msgs [])))
72
Note: See TracBrowser for help on using the repository browser.