-- Statistics of "bodies", the various embodiments of creatures in the -- game, including the player's character. All creatures have a Body -- and a Mind, with separate stats for each. They are kept separate -- in order to support spells for mind transfer and polymorphing. module Body ( BodyPart(..) , Condition(..) , Shape(..) , Body(..) , flatten_shape , human_body ) where import BodyParts data Condition = Okay | Wounded | Crippled | Gone data Shape a = Shape BodyPart a [Shape a] instance Functor Shape where fmap f (Shape part x shapes) = Shape part (f x) (map (fmap f) shapes) data Body = Body { body_shape :: Shape Condition } hand_shape :: Int -> a -> Shape a hand_shape fingers x = Shape Hand x (take fingers (repeat (Shape Finger x []))) humanoid_shape :: a -> Shape a humanoid_shape x = Shape Torso x [ Shape Waist x [ Shape Leg x [Shape Foot x []] , Shape Leg x [Shape Foot x []] ] , Shape Shoulder x [Shape Arm x [hand_shape 4 x]] , Shape Shoulder x [Shape Arm x [hand_shape 4 x]] , Shape Neck x [Shape Head x [Shape Ear x [], Shape Ear x []]] ] human_body :: Body human_body = Body { body_shape = humanoid_shape Okay } flatten_shape :: Shape a -> [(BodyPart, a)] flatten_shape (Shape part x shapes) = ((part, x) : concat (map flatten_shape shapes))