]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/init.c
Change the riggings to ints, so that comparisons against negative
[bsdgames-darwin.git] / rogue / init.c
1 /* $NetBSD: init.c,v 1.4 1995/04/28 23:49:19 mycroft 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 #ifndef lint
40 #if 0
41 static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
42 #else
43 static char rcsid[] = "$NetBSD: init.c,v 1.4 1995/04/28 23:49:19 mycroft Exp $";
44 #endif
45 #endif /* not lint */
46
47 /*
48 * init.c
49 *
50 * This source herein may be modified and/or distributed by anybody who
51 * so desires, with the following restrictions:
52 * 1.) No portion of this notice shall be removed.
53 * 2.) Credit shall not be taken for the creation of this source.
54 * 3.) This code is not to be traded, sold, or used for personal
55 * gain or profit.
56 *
57 */
58
59 #include <stdio.h>
60 #include "rogue.h"
61
62 char login_name[MAX_OPT_LEN];
63 char *nick_name = (char *) 0;
64 char *rest_file = 0;
65 boolean cant_int = 0;
66 boolean did_int = 0;
67 boolean score_only;
68 boolean init_curses = 0;
69 boolean save_is_interactive = 1;
70 boolean ask_quit = 1;
71 boolean no_skull = 0;
72 boolean passgo = 0;
73 char *error_file = "rogue.esave";
74 char *byebye_string = "Okay, bye bye!";
75
76 extern char *fruit;
77 extern char *save_file;
78 extern short party_room;
79 extern boolean jump;
80
81 init(argc, argv)
82 int argc;
83 char *argv[];
84 {
85 char *pn;
86 int seed;
87
88 pn = md_gln();
89 if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) {
90 clean_up("Hey! Who are you?");
91 }
92 (void) strcpy(login_name, pn);
93
94 do_args(argc, argv);
95 do_opts();
96
97 if (!score_only && !rest_file) {
98 printf("Hello %s, just a moment while I dig the dungeon...",
99 nick_name);
100 fflush(stdout);
101 }
102
103 initscr();
104 if ((LINES < DROWS) || (COLS < DCOLS)) {
105 clean_up("must be played on 24 x 80 screen");
106 }
107 start_window();
108 init_curses = 1;
109
110 md_heed_signals();
111
112 if (score_only) {
113 put_scores((object *) 0, 0);
114 }
115 seed = md_gseed();
116 (void) srrandom(seed);
117 if (rest_file) {
118 restore(rest_file);
119 return(1);
120 }
121 mix_colors();
122 get_wand_and_ring_materials();
123 make_scroll_titles();
124
125 level_objects.next_object = (object *) 0;
126 level_monsters.next_monster = (object *) 0;
127 player_init();
128 ring_stats(0);
129 return(0);
130 }
131
132 player_init()
133 {
134 object *obj;
135
136 rogue.pack.next_object = (object *) 0;
137
138 obj = alloc_object();
139 get_food(obj, 1);
140 (void) add_to_pack(obj, &rogue.pack, 1);
141
142 obj = alloc_object(); /* initial armor */
143 obj->what_is = ARMOR;
144 obj->which_kind = RINGMAIL;
145 obj->class = RINGMAIL+2;
146 obj->is_protected = 0;
147 obj->d_enchant = 1;
148 (void) add_to_pack(obj, &rogue.pack, 1);
149 do_wear(obj);
150
151 obj = alloc_object(); /* initial weapons */
152 obj->what_is = WEAPON;
153 obj->which_kind = MACE;
154 obj->damage = "2d3";
155 obj->hit_enchant = obj->d_enchant = 1;
156 obj->identified = 1;
157 (void) add_to_pack(obj, &rogue.pack, 1);
158 do_wield(obj);
159
160 obj = alloc_object();
161 obj->what_is = WEAPON;
162 obj->which_kind = BOW;
163 obj->damage = "1d2";
164 obj->hit_enchant = 1;
165 obj->d_enchant = 0;
166 obj->identified = 1;
167 (void) add_to_pack(obj, &rogue.pack, 1);
168
169 obj = alloc_object();
170 obj->what_is = WEAPON;
171 obj->which_kind = ARROW;
172 obj->quantity = get_rand(25, 35);
173 obj->damage = "1d2";
174 obj->hit_enchant = 0;
175 obj->d_enchant = 0;
176 obj->identified = 1;
177 (void) add_to_pack(obj, &rogue.pack, 1);
178 }
179
180 clean_up(estr)
181 char *estr;
182 {
183 if (save_is_interactive) {
184 if (init_curses) {
185 move(DROWS-1, 0);
186 refresh();
187 stop_window();
188 }
189 printf("\n%s\n", estr);
190 }
191 md_exit(0);
192 }
193
194 start_window()
195 {
196 crmode();
197 noecho();
198 #ifndef BAD_NONL
199 nonl();
200 #endif
201 }
202
203 stop_window()
204 {
205 endwin();
206 }
207
208 void
209 byebye()
210 {
211 md_ignore_signals();
212 if (ask_quit) {
213 quit(1);
214 } else {
215 clean_up(byebye_string);
216 }
217 md_heed_signals();
218 }
219
220 void
221 onintr()
222 {
223 md_ignore_signals();
224 if (cant_int) {
225 did_int = 1;
226 } else {
227 check_message();
228 message("interrupt", 1);
229 }
230 md_heed_signals();
231 }
232
233 void
234 error_save()
235 {
236 save_is_interactive = 0;
237 save_into_file(error_file);
238 clean_up("");
239 }
240
241 do_args(argc, argv)
242 int argc;
243 char *argv[];
244 {
245 short i, j;
246
247 for (i = 1; i < argc; i++) {
248 if (argv[i][0] == '-') {
249 for (j = 1; argv[i][j]; j++) {
250 switch(argv[i][j]) {
251 case 's':
252 score_only = 1;
253 break;
254 }
255 }
256 } else {
257 rest_file = argv[i];
258 }
259 }
260 }
261
262 do_opts()
263 {
264 char *eptr;
265
266 if (eptr = md_getenv("ROGUEOPTS")) {
267 for (;;) {
268 while ((*eptr) == ' ') {
269 eptr++;
270 }
271 if (!(*eptr)) {
272 break;
273 }
274 if (!strncmp(eptr, "fruit=", 6)) {
275 eptr += 6;
276 env_get_value(&fruit, eptr, 1);
277 } else if (!strncmp(eptr, "file=", 5)) {
278 eptr += 5;
279 env_get_value(&save_file, eptr, 0);
280 } else if (!strncmp(eptr, "jump", 4)) {
281 jump = 1;
282 } else if (!strncmp(eptr, "name=", 5)) {
283 eptr += 5;
284 env_get_value(&nick_name, eptr, 0);
285 } else if (!strncmp(eptr, "noaskquit", 9)) {
286 ask_quit = 0;
287 } else if (!strncmp(eptr, "noskull", 5) ||
288 !strncmp(eptr,"notomb", 6)) {
289 no_skull = 1;
290 } else if (!strncmp(eptr, "passgo", 5)) {
291 passgo = 1;
292 }
293 while ((*eptr) && (*eptr != ',')) {
294 eptr++;
295 }
296 if (!(*(eptr++))) {
297 break;
298 }
299 }
300 }
301 /* If some strings have not been set through ROGUEOPTS, assign defaults
302 * to them so that the options editor has data to work with.
303 */
304 init_str(&nick_name, login_name);
305 init_str(&save_file, "rogue.save");
306 init_str(&fruit, "slime-mold");
307 }
308
309 env_get_value(s, e, add_blank)
310 char **s, *e;
311 boolean add_blank;
312 {
313 short i = 0;
314 char *t;
315
316 t = e;
317
318 while ((*e) && (*e != ',')) {
319 if (*e == ':') {
320 *e = ';'; /* ':' reserved for score file purposes */
321 }
322 e++;
323 if (++i >= MAX_OPT_LEN) {
324 break;
325 }
326 }
327 *s = md_malloc(MAX_OPT_LEN + 2);
328 (void) strncpy(*s, t, i);
329 if (add_blank) {
330 (*s)[i++] = ' ';
331 }
332 (*s)[i] = '\0';
333 }
334
335 init_str(str, dflt)
336 char **str, *dflt;
337 {
338 if (!(*str)) {
339 *str = md_malloc(MAX_OPT_LEN + 2);
340 (void) strcpy(*str, dflt);
341 }
342 }