 (defn points-to-corridor
   "Convert a sequence of points `[x y]` into `[x y {:type :corridor}]`."
   [points]
-  (map (fn [[x y]] [x y {:type :corridor}]) points))
+  (let [moss-noise (rn/create-noise (rr/create-random 3))]
+    (map (fn [[x y]] 
+           (let [moss-probability (rn/noise moss-noise (/ x 10.0) (/ y 10.0))
+                 cell-type        (cond
+                                    (> moss-probability 0.7)
+                                      :moss-corridor
+                                    (< moss-probability 0.2)
+                                      :white-corridor
+                                    :else
+                                      :corridor)]
+             [x y {:type cell-type}]))
+         points)))
+
+(defn add-room-features
+  [cells-xy]
+  (let [xy->cell      (into {} (map (fn [[x y cell]] [[x y] cell]) cells-xy))
+        xy->cell-type (fn xy->cell-type [x y] (-> [x y] xy->cell (get :type)))
+        seed          1
+        vine-noise    (rn/create-noise (rr/create-random seed))
+        water-noise   (rn/create-noise (rr/create-random (inc seed)))
+        grass-noise   (rn/create-noise (rr/create-random (+ seed 2)))
+        moss-noise    (rn/create-noise (rr/create-random (+ seed 2)))]
+    (map (fn [[x y cell]]
+           (let [moss-probability (rn/noise grass-noise (/ x 10.0) (/ y 10.0))]
+             (case (get cell :type)
+               :floor
+                 (let [vine-probability  (rn/noise vine-noise (/ x 10.0) (/ y 10.0))
+                       water-probability (rn/noise water-noise (/ x 10.0) (/ y 10.0))
+                       grass-probability (rn/noise grass-noise (/ x 10.0) (/ y 10.0))
+                       [max-type max-p]  (reduce (fn [[max-type max-p] [cell-type p]]
+                                                   (if (> p max-p)
+                                                     [cell-type p]
+                                                     [max-type max-p]))
+                                                 [:vine vine-probability]
+                                                 [[:shallow-water water-probability]
+                                                  [:grass grass-probability]])]
+                   (if (or (and (= max-type :vine) (> max-p 0.85))
+                           (> max-p 0.8))
+                     [x y (assoc cell :type max-type)]
+                     [x y cell]))
+               (cond
+                 (> moss-probability 0.7)
+                   [x y (assoc cell :type (case (get cell :type)
+                                            :vertical-wall       :moss-vertical-wall
+                                            :horizontal-wall     :moss-horizontal-wall 
+                                            :vertical-wall-alt   :moss-vertical-wall-alt 
+                                            :horizontal-wall-alt :moss-horizontal-wall-alt 
+                                            :upper-left-1        :moss-upper-left-1 
+                                            :upper-right-1       :moss-upper-right-1 
+                                            :bottom-left-1       :moss-bottom-left-1 
+                                            :bottom-right-1      :moss-bottom-right-1 
+                                            :upper-left-2        :moss-upper-left-2 
+                                            :upper-right-2       :moss-upper-right-2 
+                                            :bottom-left-2       :moss-bottom-left-2 
+                                            :bottom-right-2      :moss-bottom-right-2
+                                            (get cell :type)))]
+                 (< moss-probability 0.2)
+                   [x y (assoc cell :type (case (get cell :type)
+                                            :vertical-wall       :white-vertical-wall
+                                            :horizontal-wall     :white-horizontal-wall 
+                                            :vertical-wall-alt   :white-vertical-wall-alt 
+                                            :horizontal-wall-alt :white-horizontal-wall-alt 
+                                            :upper-left-1        :white-upper-left-1 
+                                            :upper-right-1       :white-upper-right-1 
+                                            :bottom-left-1       :white-bottom-left-1 
+                                            :bottom-right-1      :white-bottom-right-1 
+                                            :upper-left-2        :white-upper-left-2 
+                                            :upper-right-2       :white-upper-right-2 
+                                            :bottom-left-2       :white-bottom-left-2 
+                                            :bottom-right-2      :white-bottom-right-2
+                                            (get cell :type)))]
+                 :else
+                   [x y cell]))))
+         cells-xy)))
 
 (defn room-to-cellsxy
   "Convert the bounds of a room into a list of points that represent the room."

;; Functions for randomly generating maps.
(ns robinson.dungeons.temple
  (:require [robinson.common :as rc]
            [robinson.lineofsight :as rlos]
            [clojure.math.combinatorics :as combo]
            [algotools.algos.graph :as graph]

  (let [cell1-type (get cell1 :type)
        cell2-type (get cell2 :type)]
    (cond
      (or (and (contains? #{:corridor :moss-corridor :white-corridor} cell1-type)
               (contains? #{:horizontal-wall :horizontal-wall-alt :vertical-wall :vertical-wall-alt :close-door
                            :moss-horizontal-wall :moss-horizontal-wall-alt :moss-vertical-wall :moss-vertical-wall-alt
                            :white-horizontal-wall :white-horizontal-wall-alt :white-vertical-wall :white-vertical-wall-alt} cell2-type))
          (and (contains? #{:corridor :moss-corridor :white-corridor} cell2-type)
               (contains? #{:horizontal-wall :horizontal-wall-alt :vertical-wall :vertical-wall-alt :close-door
                            :moss-horizontal-wall :moss-horizontal-wall-alt :moss-vertical-wall :moss-vertical-wall-alt
                            :white-horizontal-wall :white-horizontal-wall-alt :white-vertical-wall :white-vertical-wall-alt} cell2-type)))
        :close-door
      (= cell1-type :nil)
        cell2-type
