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