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