syscons - Untangle device attachement from isa?, attach to nexus? instead.
[dragonfly.git] / games / rogue / init.c
blobd6cbfe3f5a782cb9a97a00f6ad588ba51d1ad776
1 /*-
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
6 * Timothy C. Stoehr.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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
30 * SUCH DAMAGE.
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 $
37 * init.c
39 * This source herein may be modified and/or distributed by anybody who
40 * so desires, with the following restrictions:
41 * 1.) No portion of this notice shall be removed.
42 * 2.) Credit shall not be taken for the creation of this source.
43 * 3.) This code is not to be traded, sold, or used for personal
44 * gain or profit.
48 #include <stdio.h>
49 #include "rogue.h"
51 static void do_args(int, char **);
52 static void do_opts(void);
53 static void env_get_value(char **, char *, boolean);
54 static void init_str(char **, const char *);
55 static void player_init(void);
58 char login_name[MAX_OPT_LEN];
59 char *nick_name = NULL;
60 char *rest_file = NULL;
61 boolean cant_int = 0;
62 boolean did_int = 0;
63 boolean score_only;
64 boolean init_curses = 0;
65 boolean save_is_interactive = 1;
66 boolean ask_quit = 1;
67 boolean no_skull = 0;
68 boolean passgo = 0;
69 boolean flush = 1;
70 const char *error_file = "rogue.esave";
71 const char *byebye_string = "Okay, bye bye!";
73 extern char *fruit;
74 extern char *save_file;
75 extern short party_room;
76 extern boolean jump;
78 boolean
79 init(int argc, char *argv[])
81 const char *pn;
83 pn = md_gln();
84 if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) {
85 clean_up("Hey! Who are you?");
87 strcpy(login_name, pn);
89 do_args(argc, argv);
90 do_opts();
92 if (!score_only && !rest_file) {
93 printf("Hello %s, just a moment while I dig the dungeon...",
94 nick_name);
95 fflush(stdout);
98 initscr();
99 if ((LINES < DROWS) || (COLS < DCOLS)) {
100 clean_up("must be played on 24 x 80 screen");
102 start_window();
103 init_curses = 1;
105 md_heed_signals();
107 if (score_only) {
108 put_scores(NULL, 0);
110 srandomdev();
111 if (rest_file) {
112 restore(rest_file);
113 return(1);
115 mix_colors();
116 get_wand_and_ring_materials();
117 make_scroll_titles();
119 level_objects.next_object = NULL;
120 level_monsters.next_monster = NULL;
121 player_init();
122 ring_stats(0);
123 return(0);
126 static void
127 player_init(void)
129 object *obj;
131 rogue.pack.next_object = NULL;
133 obj = alloc_object();
134 get_food(obj, 1);
135 add_to_pack(obj, &rogue.pack, 1);
137 obj = alloc_object(); /* initial armor */
138 obj->what_is = ARMOR;
139 obj->which_kind = RINGMAIL;
140 obj->class = RINGMAIL+2;
141 obj->is_protected = 0;
142 obj->d_enchant = 1;
143 add_to_pack(obj, &rogue.pack, 1);
144 do_wear(obj);
146 obj = alloc_object(); /* initial weapons */
147 obj->what_is = WEAPON;
148 obj->which_kind = MACE;
149 obj->damage = "2d3";
150 obj->hit_enchant = obj->d_enchant = 1;
151 obj->identified = 1;
152 add_to_pack(obj, &rogue.pack, 1);
153 do_wield(obj);
155 obj = alloc_object();
156 obj->what_is = WEAPON;
157 obj->which_kind = BOW;
158 obj->damage = "1d2";
159 obj->hit_enchant = 1;
160 obj->d_enchant = 0;
161 obj->identified = 1;
162 add_to_pack(obj, &rogue.pack, 1);
164 obj = alloc_object();
165 obj->what_is = WEAPON;
166 obj->which_kind = ARROW;
167 obj->quantity = get_rand(25, 35);
168 obj->damage = "1d2";
169 obj->hit_enchant = 0;
170 obj->d_enchant = 0;
171 obj->identified = 1;
172 add_to_pack(obj, &rogue.pack, 1);
175 void
176 clean_up(const char *estr)
178 if (save_is_interactive) {
179 if (init_curses) {
180 move(DROWS-1, 0);
181 refresh();
182 stop_window();
184 printf("\n%s\n", estr);
186 md_exit(0);
189 void
190 start_window(void)
192 cbreak();
193 noecho();
194 #ifndef BAD_NONL
195 nonl();
196 #endif
197 md_control_keybord(0);
200 void
201 stop_window(void)
203 endwin();
204 md_control_keybord(1);
207 void
208 byebye(__unused int sig)
210 md_ignore_signals();
211 if (ask_quit) {
212 quit(1);
213 } else {
214 clean_up(byebye_string);
216 md_heed_signals();
219 void
220 onintr(__unused int sig)
222 md_ignore_signals();
223 if (cant_int) {
224 did_int = 1;
225 } else {
226 check_message();
227 message("interrupt", 1);
229 md_heed_signals();
232 void
233 error_save(__unused int sig)
235 save_is_interactive = 0;
236 save_into_file(error_file);
237 clean_up("");
240 static void
241 do_args(int argc, char *argv[])
243 short i, j;
245 for (i = 1; i < argc; i++) {
246 if (argv[i][0] == '-') {
247 for (j = 1; argv[i][j]; j++) {
248 switch(argv[i][j]) {
249 case 's':
250 score_only = 1;
251 break;
254 } else {
255 rest_file = argv[i];
260 static void
261 do_opts(void)
263 char *eptr;
265 if ((eptr = md_getenv("ROGUEOPTS")) != NULL) {
266 for (;;) {
267 while ((*eptr) == ' ') {
268 eptr++;
270 if (!(*eptr)) {
271 break;
273 if (!strncmp(eptr, "fruit=", 6)) {
274 eptr += 6;
275 env_get_value(&fruit, eptr, 1);
276 } else if (!strncmp(eptr, "file=", 5)) {
277 eptr += 5;
278 env_get_value(&save_file, eptr, 0);
279 } else if (!strncmp(eptr, "jump", 4)) {
280 jump = 1;
281 } else if (!strncmp(eptr, "name=", 5)) {
282 eptr += 5;
283 env_get_value(&nick_name, eptr, 0);
284 } else if (!strncmp(eptr, "noaskquit", 9)) {
285 ask_quit = 0;
286 } else if (!strncmp(eptr, "noskull", 7) ||
287 !strncmp(eptr,"notomb", 6)) {
288 no_skull = 1;
289 } else if (!strncmp(eptr, "passgo", 6)) {
290 passgo = 1;
291 } else if (!strncmp(eptr, "noflush", 7)) {
292 flush = 0;
294 while ((*eptr) && (*eptr != ',')) {
295 eptr++;
297 if (!(*(eptr++))) {
298 break;
302 /* If some strings have not been set through ROGUEOPTS, assign defaults
303 * to them so that the options editor has data to work with.
305 init_str(&nick_name, login_name);
306 init_str(&save_file, "rogue.save");
307 init_str(&fruit, "slime-mold");
310 static void
311 env_get_value(char **s, char *e, boolean add_blank)
313 short i = 0;
314 const char *t;
316 t = e;
318 while ((*e) && (*e != ',')) {
319 if (*e == ':') {
320 *e = ';'; /* ':' reserved for score file purposes */
322 e++;
323 if (++i >= MAX_OPT_LEN) {
324 break;
327 /* note: edit_opts() in room.c depends on this being the right size */
328 *s = md_malloc(MAX_OPT_LEN + 2);
329 strncpy(*s, t, i);
330 if (add_blank) {
331 (*s)[i++] = ' ';
333 (*s)[i] = '\0';
336 static void
337 init_str(char **str, const char *dflt)
339 if (!(*str)) {
340 /* note: edit_opts() in room.c depends on this size */
341 *str = md_malloc(MAX_OPT_LEN + 2);
342 strcpy(*str, dflt);