2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)init.c 8.1 (Berkeley) 5/31/93
37 * $FreeBSD: src/games/rogue/init.c,v 1.4 1999/11/30 03:49:22 billf Exp $
38 * $DragonFly: src/games/rogue/init.c,v 1.3 2006/09/02 19:31:07 pavalos Exp $
44 * This source herein may be modified and/or distributed by anybody who
45 * so desires, with the following restrictions:
46 * 1.) No portion of this notice shall be removed.
47 * 2.) Credit shall not be taken for the creation of this source.
48 * 3.) This code is not to be traded, sold, or used for personal
56 char login_name
[MAX_OPT_LEN
];
57 char *nick_name
= NULL
;
62 boolean init_curses
= 0;
63 boolean save_is_interactive
= 1;
68 const char *error_file
= "rogue.esave";
69 const char *byebye_string
= "Okay, bye bye!";
72 extern char *save_file
;
73 extern short party_room
;
76 static void player_init(void);
77 static void do_args(int, char **);
78 static void do_opts(void);
79 static void env_get_value(char **, char *, boolean
);
80 static void init_str(char **, const char *);
83 init(int argc
, char *argv
[])
89 if ((!pn
) || (strlen(pn
) >= MAX_OPT_LEN
)) {
90 clean_up("Hey! Who are you?");
92 strcpy(login_name
, pn
);
97 if (!score_only
&& !rest_file
) {
98 printf("Hello %s, just a moment while I dig the dungeon...",
104 if ((LINES
< DROWS
) || (COLS
< DCOLS
)) {
105 clean_up("must be played on 24 x 80 screen");
122 get_wand_and_ring_materials();
123 make_scroll_titles();
125 level_objects
.next_object
= NULL
;
126 level_monsters
.next_monster
= NULL
;
137 rogue
.pack
.next_object
= NULL
;
139 obj
= alloc_object();
141 add_to_pack(obj
, &rogue
.pack
, 1);
143 obj
= alloc_object(); /* initial armor */
144 obj
->what_is
= ARMOR
;
145 obj
->which_kind
= RINGMAIL
;
146 obj
->class = RINGMAIL
+2;
147 obj
->is_protected
= 0;
149 add_to_pack(obj
, &rogue
.pack
, 1);
152 obj
= alloc_object(); /* initial weapons */
153 obj
->what_is
= WEAPON
;
154 obj
->which_kind
= MACE
;
156 obj
->hit_enchant
= obj
->d_enchant
= 1;
158 add_to_pack(obj
, &rogue
.pack
, 1);
161 obj
= alloc_object();
162 obj
->what_is
= WEAPON
;
163 obj
->which_kind
= BOW
;
165 obj
->hit_enchant
= 1;
168 add_to_pack(obj
, &rogue
.pack
, 1);
170 obj
= alloc_object();
171 obj
->what_is
= WEAPON
;
172 obj
->which_kind
= ARROW
;
173 obj
->quantity
= get_rand(25, 35);
175 obj
->hit_enchant
= 0;
178 add_to_pack(obj
, &rogue
.pack
, 1);
182 clean_up(const char *estr
)
184 if (save_is_interactive
) {
190 printf("\n%s\n", estr
);
203 md_control_keybord(0);
210 md_control_keybord(1);
220 clean_up(byebye_string
);
233 message("interrupt", 1);
241 save_is_interactive
= 0;
242 save_into_file(error_file
);
247 do_args(int argc
, char *argv
[])
251 for (i
= 1; i
< argc
; i
++) {
252 if (argv
[i
][0] == '-') {
253 for (j
= 1; argv
[i
][j
]; j
++) {
271 if ((eptr
= md_getenv("ROGUEOPTS"))) {
273 while ((*eptr
) == ' ') {
279 if (!strncmp(eptr
, "fruit=", 6)) {
281 env_get_value(&fruit
, eptr
, 1);
282 } else if (!strncmp(eptr
, "file=", 5)) {
284 env_get_value(&save_file
, eptr
, 0);
285 } else if (!strncmp(eptr
, "jump", 4)) {
287 } else if (!strncmp(eptr
, "name=", 5)) {
289 env_get_value(&nick_name
, eptr
, 0);
290 } else if (!strncmp(eptr
, "noaskquit", 9)) {
292 } else if (!strncmp(eptr
, "noskull", 7) ||
293 !strncmp(eptr
,"notomb", 6)) {
295 } else if (!strncmp(eptr
, "passgo", 6)) {
297 } else if (!strncmp(eptr
, "noflush", 7)) {
300 while ((*eptr
) && (*eptr
!= ',')) {
308 /* If some strings have not been set through ROGUEOPTS, assign defaults
309 * to them so that the options editor has data to work with.
311 init_str(&nick_name
, login_name
);
312 init_str(&save_file
, "rogue.save");
313 init_str(&fruit
, "slime-mold");
317 env_get_value(char **s
, char *e
, boolean add_blank
)
324 while ((*e
) && (*e
!= ',')) {
326 *e
= ';'; /* ':' reserved for score file purposes */
329 if (++i
>= MAX_OPT_LEN
) {
333 *s
= md_malloc(MAX_OPT_LEN
+ 2);
342 init_str(char **str
, const char *dflt
)
345 *str
= md_malloc(MAX_OPT_LEN
+ 2);