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