src/caves/entities/aspects/receiver.clj @ 1a3a4f8d5d85
Refactor the world code into separate files.
This pulls out the world generation code into its own file. It was
getting a bit crowded in there.
author |
Steve Losh <steve@stevelosh.com> |
date |
Wed, 01 Aug 2012 21:13:37 -0400 |
parents |
d8b58bf5f166 |
children |
(none) |
(ns caves.entities.aspects.receiver
(:use [caves.entities.core :only [defaspect]]
[caves.world.core :only [get-entities-around]]))
(defaspect Receiver
(receive-message [this message world]
(update-in world [:entities (:id this) :messages] conj message)))
(defn send-message [entity message args world]
(if (satisfies? Receiver entity)
(receive-message entity (apply format message args) world)
world))
(defn send-message-nearby [coord message world]
(let [entities (get-entities-around world coord 7)
sm (fn [world entity]
(send-message entity message [] world))]
(reduce sm world entities)))