1 /* $NetBSD: init.c,v 1.13 2003/08/07 09:37:38 agc Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: init.c,v 1.13 2003/08/07 09:37:38 agc Exp $");
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
61 char login_name
[MAX_OPT_LEN
];
62 char *nick_name
= (char *) 0;
67 boolean init_curses
= 0;
68 boolean save_is_interactive
= 1;
72 const char *error_file
= "rogue.esave";
73 const char *byebye_string
= "Okay, bye bye!";
88 /* Check for dirty tricks with closed fds 0, 1, 2 */
89 fd
= open("/dev/null", O_RDONLY
);
96 if ((!pn
) || (strlen(pn
) >= MAX_OPT_LEN
)) {
97 clean_up("Hey! Who are you?");
99 (void) strcpy(login_name
, pn
);
104 if (!score_only
&& !rest_file
) {
105 printf("Hello %s, just a moment while I dig the dungeon...",
111 if ((LINES
< DROWS
) || (COLS
< DCOLS
)) {
112 clean_up("must be played on 24 x 80 screen");
120 put_scores((object
*) 0, 0);
123 (void) srrandom(seed
);
129 get_wand_and_ring_materials();
130 make_scroll_titles();
132 level_objects
.next_object
= (object
*) 0;
133 level_monsters
.next_monster
= (object
*) 0;
144 rogue
.pack
.next_object
= (object
*) 0;
146 obj
= alloc_object();
148 (void) add_to_pack(obj
, &rogue
.pack
, 1);
150 obj
= alloc_object(); /* initial armor */
151 obj
->what_is
= ARMOR
;
152 obj
->which_kind
= RINGMAIL
;
153 obj
->class = RINGMAIL
+2;
154 obj
->is_protected
= 0;
156 (void) add_to_pack(obj
, &rogue
.pack
, 1);
159 obj
= alloc_object(); /* initial weapons */
160 obj
->what_is
= WEAPON
;
161 obj
->which_kind
= MACE
;
163 obj
->hit_enchant
= obj
->d_enchant
= 1;
165 (void) add_to_pack(obj
, &rogue
.pack
, 1);
168 obj
= alloc_object();
169 obj
->what_is
= WEAPON
;
170 obj
->which_kind
= BOW
;
172 obj
->hit_enchant
= 1;
175 (void) add_to_pack(obj
, &rogue
.pack
, 1);
177 obj
= alloc_object();
178 obj
->what_is
= WEAPON
;
179 obj
->which_kind
= ARROW
;
180 obj
->quantity
= get_rand(25, 35);
182 obj
->hit_enchant
= 0;
185 (void) add_to_pack(obj
, &rogue
.pack
, 1);
192 if (save_is_interactive
) {
198 printf("\n%s\n", estr
);
221 int dummy
__attribute__((__unused__
));
227 clean_up(byebye_string
);
234 int dummy
__attribute__((__unused__
));
241 message("interrupt", 1);
248 int dummy
__attribute__((__unused__
));
250 save_is_interactive
= 0;
251 save_into_file(error_file
);
262 for (i
= 1; i
< argc
; i
++) {
263 if (argv
[i
][0] == '-') {
264 for (j
= 1; argv
[i
][j
]; j
++) {
282 if ((eptr
= md_getenv("ROGUEOPTS")) != NULL
) {
284 while ((*eptr
) == ' ') {
290 if (!strncmp(eptr
, "fruit=", 6)) {
292 env_get_value(&fruit
, eptr
, 1);
293 } else if (!strncmp(eptr
, "file=", 5)) {
295 env_get_value(&save_file
, eptr
, 0);
296 } else if (!strncmp(eptr
, "jump", 4)) {
298 } else if (!strncmp(eptr
, "name=", 5)) {
300 env_get_value(&nick_name
, eptr
, 0);
301 } else if (!strncmp(eptr
, "noaskquit", 9)) {
303 } else if (!strncmp(eptr
, "noskull", 5) ||
304 !strncmp(eptr
,"notomb", 6)) {
306 } else if (!strncmp(eptr
, "passgo", 5)) {
309 while ((*eptr
) && (*eptr
!= ',')) {
317 /* If some strings have not been set through ROGUEOPTS, assign defaults
318 * to them so that the options editor has data to work with.
320 init_str(&nick_name
, login_name
);
321 init_str(&save_file
, "rogue.save");
322 init_str(&fruit
, "slime-mold");
326 env_get_value(s
, e
, add_blank
)
335 while ((*e
) && (*e
!= ',')) {
337 *e
= ';'; /* ':' reserved for score file purposes */
340 if (++i
>= MAX_OPT_LEN
) {
344 *s
= md_malloc(MAX_OPT_LEN
+ 2);
346 clean_up("out of memory");
347 (void) strncpy(*s
, t
, i
);
360 *str
= md_malloc(MAX_OPT_LEN
+ 2);
362 clean_up("out of memory");
363 (void) strcpy(*str
, dflt
);