xref: /netbsd/games/rogue/play.c (revision bf9ec67e)
1 /*	$NetBSD: play.c,v 1.5 1998/11/10 13:01:32 hubertf Exp $	*/
2 
3 /*
4  * Copyright (c) 1988, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Timothy C. Stoehr.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 #ifndef lint
41 #if 0
42 static char sccsid[] = "@(#)play.c	8.1 (Berkeley) 5/31/93";
43 #else
44 __RCSID("$NetBSD: play.c,v 1.5 1998/11/10 13:01:32 hubertf Exp $");
45 #endif
46 #endif /* not lint */
47 
48 /*
49  * play.c
50  *
51  * This source herein may be modified and/or distributed by anybody who
52  * so desires, with the following restrictions:
53  *    1.)  No portion of this notice shall be removed.
54  *    2.)  Credit shall not be taken for the creation of this source.
55  *    3.)  This code is not to be traded, sold, or used for personal
56  *         gain or profit.
57  *
58  */
59 
60 #include "rogue.h"
61 
62 boolean interrupted = 0;
63 const char *unknown_command = "unknown command";
64 
65 void
66 play_level()
67 {
68 	short ch;
69 	int count;
70 
71 	for (;;) {
72 		interrupted = 0;
73 		if (hit_message[0]) {
74 			message(hit_message, 1);
75 			hit_message[0] = 0;
76 		}
77 		if (trap_door) {
78 			trap_door = 0;
79 			return;
80 		}
81 		move(rogue.row, rogue.col);
82 		refresh();
83 
84 		ch = rgetchar();
85 CMCH:
86 		check_message();
87 		count = 0;
88 CH:
89 		switch(ch) {
90 		case '.':
91 			rest((count > 0) ? count : 1);
92 			break;
93 		case 's':
94 			search(((count > 0) ? count : 1), 0);
95 			break;
96 		case 'i':
97 			inventory(&rogue.pack, ALL_OBJECTS);
98 			break;
99 		case 'f':
100 			fight(0);
101 			break;
102 		case 'F':
103 			fight(1);
104 			break;
105 		case 'h':
106 		case 'j':
107 		case 'k':
108 		case 'l':
109 		case 'y':
110 		case 'u':
111 		case 'n':
112 		case 'b':
113 			(void) one_move_rogue(ch, 1);
114 			break;
115 		case 'H':
116 		case 'J':
117 		case 'K':
118 		case 'L':
119 		case 'B':
120 		case 'Y':
121 		case 'U':
122 		case 'N':
123 		case '\010':
124 		case '\012':
125 		case '\013':
126 		case '\014':
127 		case '\031':
128 		case '\025':
129 		case '\016':
130 		case '\002':
131 			multiple_move_rogue(ch);
132 			break;
133 		case 'e':
134 			eat();
135 			break;
136 		case 'q':
137 			quaff();
138 			break;
139 		case 'r':
140 			read_scroll();
141 			break;
142 		case 'm':
143 			move_onto();
144 			break;
145 		case ',':
146 			kick_into_pack();
147 			break;
148 		case 'd':
149 			drop();
150 			break;
151 		case 'P':
152 			put_on_ring();
153 			break;
154 		case 'R':
155 			remove_ring();
156 			break;
157 		case '\020':
158 			do {
159 				remessage(count++);
160 				ch = rgetchar();
161 			} while (ch == '\020');
162 			goto CMCH;
163 			break;
164 		case '\027':
165 			wizardize();
166 			break;
167 		case '>':
168 			if (drop_check()) {
169 				return;
170 			}
171 			break;
172 		case '<':
173 			if (check_up()) {
174 				return;
175 			}
176 			break;
177 		case ')':
178 		case ']':
179 			inv_armor_weapon(ch == ')');
180 			break;
181 		case '=':
182 			inv_rings();
183 			break;
184 		case '^':
185 			id_trap();
186 			break;
187 		case '/':
188 			id_type();
189 			break;
190 		case '?':
191 			id_com();
192 			break;
193 		case '!':
194 			do_shell();
195 			break;
196 		case 'o':
197 			edit_opts();
198 			break;
199 		case 'I':
200 			single_inv(0);
201 			break;
202 		case 'T':
203 			take_off();
204 			break;
205 		case 'W':
206 			wear();
207 			break;
208 		case 'w':
209 			wield();
210 			break;
211 		case 'c':
212 			call_it();
213 			break;
214 		case 'z':
215 			zapp();
216 			break;
217 		case 't':
218 			throw();
219 			break;
220 		case 'v':
221 			message("rogue-clone: Version III. (Tim Stoehr was here), tektronix!zeus!tims", 0);
222 			break;
223 		case 'Q':
224 			quit(0);
225 		case '0':
226 		case '1':
227 		case '2':
228 		case '3':
229 		case '4':
230 		case '5':
231 		case '6':
232 		case '7':
233 		case '8':
234 		case '9':
235 			move(rogue.row, rogue.col);
236 			refresh();
237 			do {
238 				if (count < 100) {
239 					count = (10 * count) + (ch - '0');
240 				}
241 				ch = rgetchar();
242 			} while (is_digit(ch));
243 			if (ch != CANCEL) {
244 				goto CH;
245 			}
246 			break;
247 		case ' ':
248 			break;
249 		case '\011':
250 			if (wizard) {
251 				inventory(&level_objects, ALL_OBJECTS);
252 			} else {
253 				message(unknown_command, 0);
254 			}
255 			break;
256 		case '\023':
257 			if (wizard) {
258 				draw_magic_map();
259 			} else {
260 				message(unknown_command, 0);
261 			}
262 			break;
263 		case '\024':
264 			if (wizard) {
265 				show_traps();
266 			} else {
267 				message(unknown_command, 0);
268 			}
269 			break;
270 		case '\017':
271 			if (wizard) {
272 				show_objects();
273 			} else {
274 				message(unknown_command, 0);
275 			}
276 			break;
277 		case '\001':
278 			show_average_hp();
279 			break;
280 		case '\003':
281 			if (wizard) {
282 				c_object_for_wizard();
283 			} else {
284 				message(unknown_command, 0);
285 			}
286 			break;
287 		case '\015':
288 			if (wizard) {
289 				show_monsters();
290 			} else {
291 				message(unknown_command, 0);
292 			}
293 			break;
294 		case 'S':
295 			save_game();
296 			break;
297 		default:
298 			message(unknown_command, 0);
299 			break;
300 		}
301 	}
302 }
303