Remove the distinction between items and creatures. ALL THING ARE ENTITY.
(defprocotol Entity
(tick [this game])
(get-location [this game?])
(get-id [this]))
(def Entity
(with-meta Entity :default-fns
{:tick (fn [this game] game)
:get-location (fn [this game] (:location this))
:get-id (fn [this] (:id this))}))
Individual things will implement the protocol:
(defrecord Pixie [id location])
(extend-entity Pixie
(tick [this game]
(do-stuff game)))
(extend Pixie Entity
(merge {:tick (fn [this game] game)
:get-location (fn [this game] (:location this))
:get-id (fn [this] (:id this))}
{:tick (fn [this game]
(do-stuff game))}))
(defmacro extend-entity [cls & fns]
(let [fnmap (into {}
(for [[fn-name & fn-tail] fns]
[(keyword fn-name) fn-tail]))]
`(extend ~cls Entity
(merge default-entity-fns
~fnmap))))
The Entity protocol should be very sparse. Most functionality will come from other protocols that can be "added in" on a case-by-case basis. Like mixins, but without the monkeypatching clusterfuck.
A Fungus might look like:
(extend' Fungus Destructible ...)
(extend' Fungus Metabolizer ...)
Funguses don't do much. They do draw nutrition from the soil though, so their nutritional value should grow over time until they split.
Goblins:
(extend' Goblin Mobile ...)
(extend' Goblin Destructible ...)
(extend' Goblin Attacker ...)
(extend' Goblin AI ...)
(extend' Goblin Container ...)
(extend' Goblin Wearer ...)
(extend' Goblin Wielder ...)
(extend' Goblin Eater ...)
(extend' Goblin Metabolizer ...)
Goblines are mobs that can walk around, be killed, kill things, have an inventory, wear armor and wield weapons, eat food, and burn their eaten food.
Pixies:
(extend' Pixie Mobile ...)
(extend' Pixie Destructible ...)
(extend' Pixie Attacker ...)
(extend' Pixie AI ...)
(extend' Pixie Item ...)
(extend' Pixie Applicable ...)
(extend' Pixie Edible ...)
Here Pixies are entities that move around, can be destroyed (i.e. killed), can attack other entities, have an AI to decide actions (put this in tick?). Sounds like a normal monster, but they can also function as an item if you pick them up. They can then be applied or eaten.
Base protocol. All entities must implement this.
Basically it's implementation-related stuff that's not gameplay-related.
Exception: materials?
Can move autonomously.
Can be placed in a container.
Can be worn as armor by wearers.
Can be used as a weapon by wielders.
Can hold things that implement Item. Creatures can be Containers -- this effectively means they have an inventory.
Can be eaten by Eaters (maybe).
Can be drunk by drinkers.
Can eat Food (maybe).
Can drink Quaffables (maybe).
Has a notion of "energy" that either decreases over time (hunger) or increases over time (photosynthesis).
Can be destroyed by physical (or magical) trauma. Usually handled through HP counts.
Can transform to something else (or nothing) over a period of time.
Can physically attack other creatures.
Can use other entities as weapons if they implement Weapon.
Can use other entities as armor if they implement Armor.
Has an alignment. Not sure about this one.