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