]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/play.c
properly terminate after using strncpy().
[bsdgames-darwin.git] / rogue / play.c
1 /* $NetBSD: play.c,v 1.10 2019/02/03 03:19:25 mrg 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
38 static char sccsid[] = "@(#)play.c 8.1 (Berkeley) 5/31/93";
39 #else
40 __RCSID("$NetBSD: play.c,v 1.10 2019/02/03 03:19:25 mrg 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
58 #define __unreachable() __builtin_unreachable()
59
60 boolean interrupted = 0;
61
62 static const char unknown_command[] = "unknown command";
63
64 void
65 play_level(void)
66 {
67 short ch;
68 int count;
69
70 for (;;) {
71 interrupted = 0;
72 if (hit_message[0]) {
73 messagef(1, "%s", hit_message);
74 hit_message[0] = 0;
75 }
76 if (trap_door) {
77 trap_door = 0;
78 return;
79 }
80 move(rogue.row, rogue.col);
81 refresh();
82
83 ch = rgetchar();
84 CMCH:
85 check_message();
86 count = 0;
87 CH:
88 switch(ch) {
89 case '.':
90 rest((count > 0) ? count : 1);
91 break;
92 case 's':
93 search(((count > 0) ? count : 1), 0);
94 break;
95 case 'i':
96 inventory(&rogue.pack, ALL_OBJECTS);
97 break;
98 case 'f':
99 fight(0);
100 break;
101 case 'F':
102 fight(1);
103 break;
104 case 'h':
105 case 'j':
106 case 'k':
107 case 'l':
108 case 'y':
109 case 'u':
110 case 'n':
111 case 'b':
112 (void)one_move_rogue(ch, 1);
113 break;
114 case 'H':
115 case 'J':
116 case 'K':
117 case 'L':
118 case 'B':
119 case 'Y':
120 case 'U':
121 case 'N':
122 case '\010':
123 case '\012':
124 case '\013':
125 case '\014':
126 case '\031':
127 case '\025':
128 case '\016':
129 case '\002':
130 multiple_move_rogue(ch);
131 break;
132 case 'e':
133 eat();
134 break;
135 case 'q':
136 quaff();
137 break;
138 case 'r':
139 read_scroll();
140 break;
141 case 'm':
142 move_onto();
143 break;
144 case ',':
145 kick_into_pack();
146 break;
147 case 'd':
148 drop();
149 break;
150 case 'P':
151 put_on_ring();
152 break;
153 case 'R':
154 remove_ring();
155 break;
156 case '\020':
157 do {
158 remessage(count++);
159 ch = rgetchar();
160 } while (ch == '\020');
161 goto CMCH;
162 break;
163 case '\027':
164 wizardize();
165 break;
166 case '>':
167 if (drop_check()) {
168 return;
169 }
170 break;
171 case '<':
172 if (check_up()) {
173 return;
174 }
175 break;
176 case ')':
177 case ']':
178 inv_armor_weapon(ch == ')');
179 break;
180 case '=':
181 inv_rings();
182 break;
183 case '^':
184 id_trap();
185 break;
186 case '/':
187 id_type();
188 break;
189 case '?':
190 id_com();
191 break;
192 case '!':
193 do_shell();
194 break;
195 case 'o':
196 edit_opts();
197 break;
198 case 'I':
199 single_inv(0);
200 break;
201 case 'T':
202 take_off();
203 break;
204 case 'W':
205 wear();
206 break;
207 case 'w':
208 wield();
209 break;
210 case 'c':
211 call_it();
212 break;
213 case 'z':
214 zapp();
215 break;
216 case 't':
217 throw();
218 break;
219 case 'v':
220 messagef(0, "rogue-clone: Version III. (Tim Stoehr was here), tektronix!zeus!tims");
221 break;
222 case 'Q':
223 quit(0);
224 __unreachable();
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 messagef(0, "%s", unknown_command);
254 }
255 break;
256 case '\023':
257 if (wizard) {
258 draw_magic_map();
259 } else {
260 messagef(0, "%s", unknown_command);
261 }
262 break;
263 case '\024':
264 if (wizard) {
265 show_traps();
266 } else {
267 messagef(0, "%s", unknown_command);
268 }
269 break;
270 case '\017':
271 if (wizard) {
272 show_objects();
273 } else {
274 messagef(0, "%s", unknown_command);
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 messagef(0, "%s", unknown_command);
285 }
286 break;
287 case '\015':
288 if (wizard) {
289 show_monsters();
290 } else {
291 messagef(0, "%s", unknown_command);
292 }
293 break;
294 case 'S':
295 save_game();
296 break;
297 default:
298 messagef(0, "%s", unknown_command);
299 break;
300 }
301 }
302 }