Blob


1 #include <stdio.h>
3 #include "adventure.h"
5 int
6 exec_quit(void)
7 {
8 return 0;
9 }
11 int
12 exec_no_match(void)
13 {
14 struct param *par = param_by_letter('A');
16 if (par->distance != dist_no_obj_specified)
17 printf("I don't know how to %s.\n", par->tag);
18 return 1;
19 }
21 int
22 exec_look_around(void)
23 {
24 printf("You are in %s.\n", player->location->description);
25 list_objs_at_loc(player->location);
26 return 1;
27 }
29 int
30 exec_look(void)
31 {
32 struct param *par = param_by_letter('A');
33 struct object *obj = par->object;
34 enum distance dist = par->distance;
36 if (dist >= dist_unknown_obj)
37 printf("I don't understand what you want to see.\n");
38 else if (dist == dist_not_here)
39 printf("You don't see any %s here.\n", par->tag);
40 else if (dist == dist_overthere)
41 printf("You squeeze your eyes, but %s is too far away.\n",
42 par->tag);
43 else if (dist == dist_here_contained)
44 printf("Hard to see, try to get it first.\n");
45 else {
46 printf("%s\n", obj->details);
47 list_objs_at_loc(obj);
48 }
50 return 1;
51 }
53 int
54 exec_go(void)
55 {
56 struct param *par = param_by_letter('A');
57 struct object *obj = par->object;
58 enum distance dist = par->distance;
60 if (dist >= dist_unknown_obj)
61 printf("I don't understand where you want to go.\n");
62 else if (dist == dist_location)
63 printf("You are already there.\n");
64 else if (dist == dist_overthere)
65 move_player(get_passage_to(obj));
66 else if (dist == dist_here)
67 move_player(obj);
68 else if (dist < dist_not_here)
69 printf("You can't get any closer than this.\n");
70 else
71 printf("You don't see any %s here.\n", "XXX");
73 return 1;
74 }
76 int
77 exec_get_from(void)
78 {
79 return move_object(
80 param_by_letter('A'), param_by_letter('B')->object, player);
81 }
83 int
84 exec_get(void)
85 {
86 return move_object(param_by_letter('A'), player->location, player);
87 }
89 int
90 exec_drop(void)
91 {
92 return move_object(param_by_letter('A'), player, player->location);
93 }
95 int
96 exec_give(void)
97 {
98 return move_object(param_by_letter('A'), player, person_here());
99 }
101 int
102 exec_ask(void)
104 return move_object(param_by_letter('A'), person_here(), player);
107 int
108 exec_put_in(void)
110 return move_object(
111 param_by_letter('A'), player, param_by_letter('B')->object);
114 int
115 exec_inventory(void)
117 if (list_objs_at_loc(player) == 0)
118 printf("You are empty-handed.\n");
119 return 1;
122 int
123 exec_open(void)
125 struct param *par = param_by_letter('A');
126 if (object_within_reach("open", par))
127 printf("%s\n", (par->object->open)(par->object));
128 return 1;
131 int
132 exec_close(void)
134 struct param *par = param_by_letter('A');
135 if (object_within_reach("close", par))
136 printf("%s\n", (par->object->close)(par->object));
137 return 1;
140 int
141 exec_lock(void)
143 struct param *par = param_by_letter('A');
144 if (object_within_reach("lock", par))
145 printf("%s\n", (par->object->lock)(par->object));
146 return 1;
149 int
150 exec_unlock(void)
152 struct param *par = param_by_letter('A');
153 if (object_within_reach("unlock", par))
154 printf("%s\n", (par->object->unlock)(par->object));
155 return 1;
158 int
159 parseexec(const char *input)
161 static const struct command commands[] = {
162 { &exec_quit, "quit" },
163 { &exec_quit, "bye" },
164 { &exec_look_around, "look" },
165 { &exec_look_around, "look around" },
166 { &exec_look, "look at A?" },
167 { &exec_look, "look A?" },
168 { &exec_go, "go to the A?" },
169 { &exec_go, "go to A?" },
170 { &exec_go, "go A?" },
171 { &exec_get_from, "get A from B?" },
172 { &exec_get, "get the A?" },
173 { &exec_get, "get A?" },
174 { &exec_get, "pick up the A?" },
175 { &exec_get, "pick up a A?" },
176 { &exec_get, "pick up A?" },
177 { &exec_get, "pick the A?" },
178 { &exec_get, "pick a A?" },
179 { &exec_get, "pick A?" },
180 { &exec_put_in, "put A in B?" },
181 { &exec_put_in, "drop A in B?" },
182 { &exec_drop, "drop A?" },
183 { &exec_give, "give A?" },
184 { &exec_ask, "ask A?" },
185 { &exec_inventory, "inventory" },
186 { &exec_open, "open A?" },
187 { &exec_close, "close A?" },
188 { &exec_lock, "lock A?" },
189 { &exec_unlock, "unlock A?" },
190 { &exec_no_match, "A?" },
191 };
193 const struct command *cmd;
194 for (cmd = commands; !match_command(input, cmd->pattern); ++cmd)
197 return (*cmd->fn)();