route: ensure RTM_IFINFO is sent first when bring interface down/up
[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  */
35
36 /*
37  * play.c
38  *
39  * This source herein may be modified and/or distributed by anybody who
40  * so desires, with the following restrictions:
41  *    1.)  No portion of this notice shall be removed.
42  *    2.)  Credit shall not be taken for the creation of this source.
43  *    3.)  This code is not to be traded, sold, or used for personal
44  *         gain or profit.
45  *
46  */
47
48 #include "rogue.h"
49
50 boolean interrupted = 0;
51
52 static const char unknown_command[] = "unknown command";
53
54 void
55 play_level(void)
56 {
57         short ch;
58         int count;
59
60         for (;;) {
61                 interrupted = 0;
62                 if (hit_message[0]) {
63                         message(hit_message, 1);
64                         hit_message[0] = 0;
65                 }
66                 if (trap_door) {
67                         trap_door = 0;
68                         return;
69                 }
70                 move(rogue.row, rogue.col);
71                 refresh();
72
73                 ch = rgetchar();
74 CMCH:
75                 check_message();
76                 count = 0;
77 CH:
78                 switch(ch) {
79                 case '.':
80                         rest((count > 0) ? count : 1);
81                         break;
82                 case 's':
83                         search(((count > 0) ? count : 1), 0);
84                         break;
85                 case 'i':
86                         inventory(&rogue.pack, ALL_OBJECTS);
87                         break;
88                 case 'f':
89                         fight(0);
90                         break;
91                 case 'F':
92                         fight(1);
93                         break;
94                 case 'h':
95                 case 'j':
96                 case 'k':
97                 case 'l':
98                 case 'y':
99                 case 'u':
100                 case 'n':
101                 case 'b':
102                         one_move_rogue(ch, 1);
103                         break;
104                 case 'H':
105                 case 'J':
106                 case 'K':
107                 case 'L':
108                 case 'B':
109                 case 'Y':
110                 case 'U':
111                 case 'N':
112                 case '\010':
113                 case '\012':
114                 case '\013':
115                 case '\014':
116                 case '\031':
117                 case '\025':
118                 case '\016':
119                 case '\002':
120                         multiple_move_rogue(ch);
121                         break;
122                 case 'e':
123                         eat();
124                         break;
125                 case 'q':
126                         quaff();
127                         break;
128                 case 'r':
129                         read_scroll();
130                         break;
131                 case 'm':
132                         move_onto();
133                         break;
134                 case ',':
135                         kick_into_pack();
136                         break;
137                 case 'd':
138                         drop();
139                         break;
140                 case 'P':
141                         put_on_ring();
142                         break;
143                 case 'R':
144                         remove_ring();
145                         break;
146                 case '\020':
147                         do {
148                                 remessage(count++);
149                                 ch = rgetchar();
150                         } while (ch == '\020');
151                         goto CMCH;
152                         break;
153                 case '\027':
154                         wizardize();
155                         break;
156                 case '>':
157                         if (drop_check()) {
158                                 return;
159                         }
160                         break;
161                 case '<':
162                         if (check_up()) {
163                                 return;
164                         }
165                         break;
166                 case ')':
167                 case ']':
168                         inv_armor_weapon(ch == ')');
169                         break;
170                 case '=':
171                         inv_rings();
172                         break;
173                 case '^':
174                         id_trap();
175                         break;
176                 case '/':
177                         id_type();
178                         break;
179                 case '?':
180                         id_com();
181                         break;
182                 case '!':
183                         do_shell();
184                         break;
185                 case 'o':
186                         edit_opts();
187                         break;
188                 case 'I':
189                         single_inv(0);
190                         break;
191                 case 'T':
192                         take_off();
193                         break;
194                 case 'W':
195                         wear();
196                         break;
197                 case 'w':
198                         wield();
199                         break;
200                 case 'c':
201                         call_it();
202                         break;
203                 case 'z':
204                         zapp();
205                         break;
206                 case 't':
207                         throw();
208                         break;
209                 case 'v':
210                         message("rogue-clone: Version III. (Tim Stoehr was here), tektronix!zeus!tims", 0);
211                         break;
212                 case 'Q':
213                         quit(0);
214                         /* FALLTHROUGH */
215                 case '0':
216                 case '1':
217                 case '2':
218                 case '3':
219                 case '4':
220                 case '5':
221                 case '6':
222                 case '7':
223                 case '8':
224                 case '9':
225                         move(rogue.row, rogue.col);
226                         refresh();
227                         do {
228                                 if (count < 100) {
229                                         count = (10 * count) + (ch - '0');
230                                 }
231                                 ch = rgetchar();
232                         } while (is_digit(ch));
233                         if (ch != CANCEL) {
234                                 goto CH;
235                         }
236                         break;
237                 case ' ':
238                         break;
239                 case '\011':
240                         if (wizard) {
241                                 inventory(&level_objects, ALL_OBJECTS);
242                         } else {
243                                 message(unknown_command, 0);
244                         }
245                         break;
246                 case '\023':
247                         if (wizard) {
248                                 draw_magic_map();
249                         } else {
250                                 message(unknown_command, 0);
251                         }
252                         break;
253                 case '\024':
254                         if (wizard) {
255                                 show_traps();
256                         } else {
257                                 message(unknown_command, 0);
258                         }
259                         break;
260                 case '\017':
261                         if (wizard) {
262                                 show_objects();
263                         } else {
264                                 message(unknown_command, 0);
265                         }
266                         break;
267                 case '\001':
268                         show_average_hp();
269                         break;
270                 case '\003':
271                         if (wizard) {
272                                 c_object_for_wizard();
273                         } else {
274                                 message(unknown_command, 0);
275                         }
276                         break;
277                 case '\015':
278                         if (wizard) {
279                                 show_monsters();
280                         } else {
281                                 message(unknown_command, 0);
282                         }
283                         break;
284                 case 'S':
285                         save_game();
286                         break;
287                 default:
288                         message(unknown_command, 0);
289                         break;
290                 }
291         }
292 }