forked from abbottk/Zorkell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Action.hs
86 lines (73 loc) · 3.25 KB
/
Action.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module Zorkell.Action where
-- | Sentance constructors to receive actions. Transitive verb structure makes the actions fairly simple to sort from the rest of the sentance, but Phrasal verb structures require a form and phrasal part that necessarily change the meaning.
--
data Command = Transitive { actionType :: Action, form :: String, preposition :: [String], complement :: [String] }
| Phrasal { actionType :: Action, form :: String, phrasal :: String, preposition :: [String], complement :: [String] }
deriving (Eq,Show)
-- | Player action data type and constructors. Uses the default eq and show instances.
--
data PlayerAction = SimpleAction Action
| Interaction Action String
| Complex Action String String
deriving (Eq,Show)
-- | Action data type and contructors. Uses the default eq, ord, and show instances.
--
data Action = Close
| Consume
| Drop
| Examine
| Inventory
| Go
| Kill
| Move
| Open
| Put
| Quit
| Search
| Take
| Talk
| TurnOff
| TurnOn
| Zilch
deriving (Eq,Ord,Show)
-- | Commands used in completing/processing action phrases.
--
close = Transitive Close "close" [] []
shut = Transitive Close "shut" [] []
eat = Transitive Consume "eat" [] []
drink = Transitive Consume "drink" [] []
dropIt = Transitive Drop "drop" [] []
examine = Transitive Examine "examine" [] []
look = Transitive Examine "look" ["at", "for"] ["with"]
readIt = Transitive Examine "read" [] []
go = Transitive Go "go" [] []
getInv = Transitive Inventory "inventory" [] []
hit = Transitive Kill "hit" [] ["with"]
kill = Transitive Kill "kill" [] ["with"]
move = Transitive Move "move" [] []
open = Transitive Open "open" [] []
putIt = Transitive Put "put" [] []
quit = Transitive Quit "quit" [] []
takeIt = Transitive Take "take" [] []
getIt = Transitive Take "get" [] []
pick = Phrasal Take "pick" "up" ["with"] []
speak = Transitive Talk "speak" ["with", "to"] ["about"]
talk = Transitive Talk "talk" ["with", "to"] ["about"]
ask = Transitive Talk "ask" [] ["about"]
turnOff = Phrasal TurnOff "turn" "off" [] []
turnOn = Phrasal TurnOn "turn" "on" [] []
-- | Command definitions for use in the Adventure Engine module.
--
commands = [close, shut, eat, drink, dropIt, examine, look, readIt, go, getInv, kill, move, open, putIt, quit, takeIt, getIt, pick, speak, talk, ask]
-- | Parse the command from the user provided input.
--
getCommandAction :: Command -> Action
getCommandAction (Transitive cmd _ _ _) = cmd
getCommandAction (Phrasal cmd _ _ _ _) = cmd
-- | Transform the command into an action if possible, otherwise return the default response.
--
commandIntoAction :: Maybe Command -> Maybe String -> Maybe String -> PlayerAction
commandIntoAction Nothing _ _ = SimpleAction Zilch
commandIntoAction (Just cmd) Nothing _ = SimpleAction (getCommandAction cmd)
commandIntoAction (Just cmd) (Just obj) Nothing = Interaction (getCommandAction cmd) obj
commandIntoAction (Just cmd) (Just obj) (Just obj') = Complex (getCommandAction cmd) obj obj'