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. 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.
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
32 * @(#)init.c 8.1 (Berkeley) 5/31/93
33 * $FreeBSD: src/games/rogue/init.c,v 1.4 1999/11/30 03:49:22 billf Exp $
34 * $DragonFly: src/games/rogue/init.c,v 1.3 2006/09/02 19:31:07 pavalos Exp $
40 * This source herein may be modified and/or distributed by anybody who
41 * so desires, with the following restrictions:
42 * 1.) No portion of this notice shall be removed.
43 * 2.) Credit shall not be taken for the creation of this source.
44 * 3.) This code is not to be traded, sold, or used for personal
52 static void do_args(int, char **);
53 static void do_opts(void);
54 static void env_get_value(char **, char *, boolean);
55 static void init_str(char **, const char *);
56 static void player_init(void);
59 char login_name[MAX_OPT_LEN];
60 char *nick_name = NULL;
61 char *rest_file = NULL;
65 boolean init_curses = 0;
66 boolean save_is_interactive = 1;
71 const char *error_file = "rogue.esave";
72 const char *byebye_string = "Okay, bye bye!";
75 extern char *save_file;
76 extern short party_room;
80 init(int argc, char *argv[])
85 if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) {
86 clean_up("Hey! Who are you?");
88 strcpy(login_name, pn);
93 if (!score_only && !rest_file) {
94 printf("Hello %s, just a moment while I dig the dungeon...",
100 if ((LINES < DROWS) || (COLS < DCOLS)) {
101 clean_up("must be played on 24 x 80 screen");
117 get_wand_and_ring_materials();
118 make_scroll_titles();
120 level_objects.next_object = NULL;
121 level_monsters.next_monster = NULL;
132 rogue.pack.next_object = NULL;
134 obj = alloc_object();
136 add_to_pack(obj, &rogue.pack, 1);
138 obj = alloc_object(); /* initial armor */
139 obj->what_is = ARMOR;
140 obj->which_kind = RINGMAIL;
141 obj->class = RINGMAIL+2;
142 obj->is_protected = 0;
144 add_to_pack(obj, &rogue.pack, 1);
147 obj = alloc_object(); /* initial weapons */
148 obj->what_is = WEAPON;
149 obj->which_kind = MACE;
151 obj->hit_enchant = obj->d_enchant = 1;
153 add_to_pack(obj, &rogue.pack, 1);
156 obj = alloc_object();
157 obj->what_is = WEAPON;
158 obj->which_kind = BOW;
160 obj->hit_enchant = 1;
163 add_to_pack(obj, &rogue.pack, 1);
165 obj = alloc_object();
166 obj->what_is = WEAPON;
167 obj->which_kind = ARROW;
168 obj->quantity = get_rand(25, 35);
170 obj->hit_enchant = 0;
173 add_to_pack(obj, &rogue.pack, 1);
177 clean_up(const char *estr)
179 if (save_is_interactive) {
185 printf("\n%s\n", estr);
198 md_control_keybord(0);
205 md_control_keybord(1);
215 clean_up(byebye_string);
228 message("interrupt", 1);
236 save_is_interactive = 0;
237 save_into_file(error_file);
242 do_args(int argc, char *argv[])
246 for (i = 1; i < argc; i++) {
247 if (argv[i][0] == '-') {
248 for (j = 1; argv[i][j]; j++) {
266 if ((eptr = md_getenv("ROGUEOPTS")) != NULL) {
268 while ((*eptr) == ' ') {
274 if (!strncmp(eptr, "fruit=", 6)) {
276 env_get_value(&fruit, eptr, 1);
277 } else if (!strncmp(eptr, "file=", 5)) {
279 env_get_value(&save_file, eptr, 0);
280 } else if (!strncmp(eptr, "jump", 4)) {
282 } else if (!strncmp(eptr, "name=", 5)) {
284 env_get_value(&nick_name, eptr, 0);
285 } else if (!strncmp(eptr, "noaskquit", 9)) {
287 } else if (!strncmp(eptr, "noskull", 7) ||
288 !strncmp(eptr,"notomb", 6)) {
290 } else if (!strncmp(eptr, "passgo", 6)) {
292 } else if (!strncmp(eptr, "noflush", 7)) {
295 while ((*eptr) && (*eptr != ',')) {
303 /* If some strings have not been set through ROGUEOPTS, assign defaults
304 * to them so that the options editor has data to work with.
306 init_str(&nick_name, login_name);
307 init_str(&save_file, "rogue.save");
308 init_str(&fruit, "slime-mold");
312 env_get_value(char **s, char *e, boolean add_blank)
319 while ((*e) && (*e != ',')) {
321 *e = ';'; /* ':' reserved for score file purposes */
324 if (++i >= MAX_OPT_LEN) {
328 /* note: edit_opts() in room.c depends on this being the right size */
329 *s = md_malloc(MAX_OPT_LEN + 2);
338 init_str(char **str, const char *dflt)
341 /* note: edit_opts() in room.c depends on this size */
342 *str = md_malloc(MAX_OPT_LEN + 2);