     (run-every-n-seconds f n)))
 
 (defn run-randomly [f min max]
-  (future (Thread/sleep (+ min (rand-int (- max min))))
-    (f)
-    (run-randomly f min max)))
+  (.start (Thread.
+    (fn []
+      (while true (do
+                    (Thread/sleep (+ min (rand-int (- max min))))
+                    (f)))))))
 
 (defn init []
   (run-every-n-seconds pop-balancer 10))

            (update-settlement-pop id-settlement 0)
            (update-biome-map)
            (record-event (str "Village " (.name s) " is now a ghost town") nil))
          (when (and (> (.pop s) 500) (chance 0.1))
            (println "Spawning a new village")
            (update-biome-map)
            ))))))

(def fastness 1000)

(defn- create-tribe-in-game [game]
  (let [id-tribe (.next-id game)
        game (assoc game :next-id (inc id-tribe))
        id-settlement (.next-id game)
        game (assoc game :next-id (inc id-settlement))
        language (generate-language)
        name-tribe (.name language)
        name-settlement (.name language)
        pos (free-random-land)
        settlement (Settlement. id-settlement name-settlement 100 id-tribe pos)
        tribe (Tribe. id-tribe name-tribe language [id-settlement])
        game (assoc-in game [:tribes id-tribe] tribe)
        game (assoc-in game [:settlements id-settlement] settlement)]
      (run-randomly (update-tribe-fun id-tribe) 3000 10000)
      (run-randomly (update-settlement-fun id-settlement) (* fastness 3) (* fastness 10))
      (record-event (str "Creating tribe " name-tribe) pos)
      (record-event (str "Creating village " name-settlement) pos)
      (update-biome-map)
    game))

(defn create-tribe []
  (swap! game create-tribe-in-game))

; --------------------------------------
; Game functions

    (if (land? rp)
      rp
      (free-random-land))))

(defn free-random-land-near [center]
  (let [cx (:x center)
        cy (:y center)
        all-cells-around (for [dx (range -5 5) dy (range -5 5)]
                            {:x (+ cx dx) :y (+ cy dy)})
        land-cells-around (filter land? all-cells-around)
        free-land-cells-around (filter free-cell? land-cells-around)]
    (if (empty? free-land-cells-around)
      nil
      (rand-nth free-land-cells-around))))

(defn chance [p]
  (< (rand) p))
