1module CharMap where
2
3import qualified Data.Map as M
4import qualified Data.Set as S
5import Data.Char
6import Data.Tuple
7
8import Types
9
10import Spell.Enum
11import Poison.Enum
12
13data CharUse
14	= CharControl Control
15	| IngredientFor SpellEnum Int
16	| Poison PoisonEnum
17	deriving (Show, Eq, Ord)
18
19data Control
20	= Movement Direction
21	| Inventory
22	| Help
23	| Quit
24	| Wait
25	deriving (Show, Eq, Ord)
26
27-- Every character that has special meaning in the game is kept here
28-- in one place.
29charSet :: S.Set (Char, CharUse)
30charSet = S.fromList $ concat
31	-- movement
32	[ use 'h' $ CharControl (Movement DLeft)
33	, use 'j' $ CharControl (Movement DDown)
34	, use 'k' $ CharControl (Movement DUp)
35	, use 'l' $ CharControl (Movement DRight)
36	, use 'd' $ CharControl (Movement DDive)
37
38	-- specials
39	, use 'i' $ CharControl Inventory
40	, use '?' $ CharControl Help
41	, use 'Q' $ CharControl Quit
42	, use '.' $ CharControl Wait
43
44	-- spell ingredients
45	, ingredient 'v' SpellVomit
46	, ingredient 'p' SpellWhiteout
47	, ingredient 'b' SpellBerzerk
48	, ingredients "re" SpellReverse
49	, ingredients "new" SpellNew
50	, ingredients "gen" SpellGenocide
51	, ingredients "ogo" SpellDream
52	, ingredients "ws" SpellWish
53
54	-- poisons
55	, poison 'm' PoisonMold
56	, poison 'c' PoisonStunner
57	, poison 'f' PoisonFungus
58	]
59  where
60	use c u = [(c, u)]
61
62	ingredient c s = ingredient' 0 c s
63	ingredient' n c s = bothcases c (IngredientFor s n)
64	ingredients cs s = concatMap (\(c, n) -> ingredient' n c s) (zip cs [0..])
65
66	poison c = bothcases c . Poison
67
68	bothcases c v = [(toLower c, v), (toUpper c, v)]
69
70charMap :: M.Map Char CharUse
71charMap = M.fromList $ S.toList charSet
72
73charUseMap :: M.Map CharUse Char
74charUseMap = M.fromList $ map swap $ S.toList charSet
75