diff --git a/README.md b/README.md index 9375cea..59eb55b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ spread across everywhere except the very top of the mountain. But after the flood, the waters should drain away again. Go back to [rules](rules) and add this rule at the very top: - if altitude is more than 9 and state is water then state should be grassland + if altitude is more than 9 and state is water then state should be grassland Now the world alternates between *new* and *grassland*. That's no good! Go back to [rules](rules) and delete the rule that you first added - the one that says diff --git a/resources/public/docs/mw-engine/uberdoc.html b/resources/public/docs/mw-engine/uberdoc.html index e83d53a..81e3588 100644 --- a/resources/public/docs/mw-engine/uberdoc.html +++ b/resources/public/docs/mw-engine/uberdoc.html @@ -3065,8 +3065,15 @@ further rules can be applied.
(defn- transform-cell [cell world rules] (try - (apply-rules cell world rules) - (catch Exception e (merge {:state :error :error (.getMessage e)} cell))))
Return a row derived from this row of this world by applying these rules to each cell.
+ (merge + (apply-rules cell world rules) + {:generation (+ (or (:generation cell) 0) 1)}) + (catch Exception e + (merge cell {:error + (format "%s at generation %d when in state %s" + (.getMessage e) + (:generation cell) + (:state cell))}))))Return a row derived from this row of this world by applying these rules to each cell.
(defn- transform-world-row [row world rules] (map #(transform-cell % world rules) row))
Return a world derived from this world by applying these rules to each cell.
@@ -3287,7 +3294,7 @@ ignored). Darker shades are higher. (fn [cell world] (cond (and (= (:state cell) :new) (> (get-int cell :altitude) snowline)) (merge cell {:state :snow}))) ;; in between, we have a wasteland. - (fn [cell world] (cond (= (:state cell) :new) (merge cell {:state :waste})))))(def natural-rules (flatten (list vegetation-rules @@ -3373,12 +3380,15 @@ ignored). Darker shades are higher. * `cell` a cell within that world; * `depth` an integer representing the distance from [x,y] that should be searched; -* `property` a keyword representing a property of the neighbours. -* `value` a value of that property +* `property` a keyword representing a property of the neighbours; +* `value` a value of that property; +* `op` a comparator function to use in place of `=`.+ +
It gets messy.
(defn get-neighbours-with-property-value - ([world x y depth property value comparator] - (filter #(apply comparator (list (get % property) value)) (get-neighbours world x y depth))) + ([world x y depth property value op] + (filter #(eval (list op (get % property) value)) (get-neighbours world x y depth))) ([world x y depth property value] (get-neighbours-with-property-value world x y depth property value =)) ([world cell depth property value] diff --git a/resources/public/docs/mw-parser/uberdoc.html b/resources/public/docs/mw-parser/uberdoc.html index 0c68227..7032d5b 100644 --- a/resources/public/docs/mw-parser/uberdoc.html +++ b/resources/public/docs/mw-parser/uberdoc.html @@ -3226,9 +3226,9 @@ front of the sequence of tokens it returns nil. (cond (and (= comp1 "equal") (= comp2 "to")) (gen-neighbours-condition comparator quantity property value remainder '=) (and (= comp1 "more") (= comp2 "than")) - (gen-neighbours-condition '> quantity property value remainder '>) + (gen-neighbours-condition comparator quantity property value remainder '>) (and (= comp1 "less") (= comp2 "than")) - (gen-neighbours-condition '< quantity property value remainder '<)))))))
(defn parse-some-neighbours-condition [[SOME NEIGHBOURS & rest]] (cond diff --git a/resources/public/docs/mw-ui/uberdoc.html b/resources/public/docs/mw-ui/uberdoc.html index 4a5d41a..c2cde8a 100644 --- a/resources/public/docs/mw-ui/uberdoc.html +++ b/resources/public/docs/mw-ui/uberdoc.html @@ -3124,6 +3124,7 @@ net.brehaut.ClojureTools = (function (SH) { [mw-engine.world :as world] [mw-engine.heightmap :as heightmap] [mw-engine.natural-rules :as rules] + [mw-parser.bulk :as compiler] [hiccup.core :refer [html]] [noir.session :as session]))
(defn format-css-class [statekey] @@ -3135,12 +3136,13 @@ net.brehaut.ClojureTools = (function (SH) { [statekey] (format "img/tiles/%s.png" (format-css-class statekey)))
(defn format-mouseover [cell] - (str "State " (:state cell) "; altitude: " (:altitude cell) "; fertility: " (:fertility cell)))
Render this world cell as a Hiccup table cell.
+ (str cell))Render this world cell as a Hiccup table cell.
(defn render-cell [cell] (let [state (:state cell)] [:td {:class (format-css-class state) :title (format-mouseover cell)} - [:img {:alt (world/format-cell cell) :src (format-image-path state)}]]))
Render this world row as a Hiccup table row.
+ [:a {:href (format "inspect?x=%d&y=%d" (:x cell) (:y cell))} + [:img {:alt (world/format-cell cell) :src (format-image-path state)}]]]))Render this world row as a Hiccup table row.
(defn render-world-row [row] (apply vector (cons :tr (map render-cell row))))
Render the world implied by the session as a complete HTML page.
@@ -3152,7 +3154,9 @@ net.brehaut.ClojureTools = (function (SH) { (world/make-world 20 20) "resources/public/img/20x20/hill.png") rules/init-rules)) - rules (or (session/get :rules) rules/natural-rules) + rules (or (session/get :rules) + (do (session/put! :rules (compiler/compile-file "resources/rulesets/basic.txt")) + (session/get :rules))) generation (+ (or (session/get :generation) 0) 1) w2 (engine/transform-world world rules) ] diff --git a/resources/public/img/tiles/camp.png b/resources/public/img/tiles/camp.png new file mode 100644 index 0000000..c2ecf86 Binary files /dev/null and b/resources/public/img/tiles/camp.png differ diff --git a/resources/public/img/tiles/crop.png b/resources/public/img/tiles/crop.png new file mode 100644 index 0000000..b154cdc Binary files /dev/null and b/resources/public/img/tiles/crop.png differ diff --git a/resources/public/img/tiles/error.png b/resources/public/img/tiles/error.png new file mode 100644 index 0000000..f4409bc Binary files /dev/null and b/resources/public/img/tiles/error.png differ diff --git a/resources/public/img/tiles/house.png b/resources/public/img/tiles/house.png new file mode 100644 index 0000000..222e81a Binary files /dev/null and b/resources/public/img/tiles/house.png differ diff --git a/resources/public/img/tiles/market.png b/resources/public/img/tiles/market.png new file mode 100644 index 0000000..a4f3bdb Binary files /dev/null and b/resources/public/img/tiles/market.png differ diff --git a/resources/public/img/tiles/meadow.png b/resources/public/img/tiles/meadow.png new file mode 100644 index 0000000..44453f9 Binary files /dev/null and b/resources/public/img/tiles/meadow.png differ diff --git a/resources/public/img/tiles/ploughland.png b/resources/public/img/tiles/ploughland.png new file mode 100644 index 0000000..0df26f8 Binary files /dev/null and b/resources/public/img/tiles/ploughland.png differ diff --git a/src/mw_ui/render_world.clj b/src/mw_ui/render_world.clj index a4cc30c..473eb79 100644 --- a/src/mw_ui/render_world.clj +++ b/src/mw_ui/render_world.clj @@ -3,6 +3,7 @@ [mw-engine.world :as world] [mw-engine.heightmap :as heightmap] [mw-engine.natural-rules :as rules] + [mw-parser.bulk :as compiler] [hiccup.core :refer [html]] [noir.session :as session])) @@ -19,14 +20,15 @@ (format "img/tiles/%s.png" (format-css-class statekey))) (defn format-mouseover [cell] - (str "State " (:state cell) "; altitude: " (:altitude cell) "; fertility: " (:fertility cell))) + (str cell)) (defn render-cell "Render this world cell as a Hiccup table cell." [cell] (let [state (:state cell)] [:td {:class (format-css-class state) :title (format-mouseover cell)} - [:img {:alt (world/format-cell cell) :src (format-image-path state)}]])) + [:a {:href (format "inspect?x=%d&y=%d" (:x cell) (:y cell))} + [:img {:alt (world/format-cell cell) :src (format-image-path state)}]]])) (defn render-world-row "Render this world row as a Hiccup table row." @@ -42,7 +44,9 @@ (world/make-world 20 20) "resources/public/img/20x20/hill.png") rules/init-rules)) - rules (or (session/get :rules) rules/natural-rules) + rules (or (session/get :rules) + (do (session/put! :rules (compiler/compile-file "resources/rulesets/basic.txt")) + (session/get :rules))) generation (+ (or (session/get :generation) 0) 1) w2 (engine/transform-world world rules) ]