]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/init.c
Convert to -mandoc macros.
[bsdgames-darwin.git] / rogue / init.c
1 /*
2 * Copyright (c) 1988 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Timothy C. Stoehr.
7 *
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. 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.
23 *
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
34 * SUCH DAMAGE.
35 */
36
37 #ifndef lint
38 /*static char sccsid[] = "from: @(#)init.c 5.4 (Berkeley) 2/28/91";*/
39 static char rcsid[] = "$Id: init.c,v 1.2 1993/08/01 18:52:30 mycroft Exp $";
40 #endif /* not lint */
41
42 /*
43 * init.c
44 *
45 * This source herein may be modified and/or distributed by anybody who
46 * so desires, with the following restrictions:
47 * 1.) No portion of this notice shall be removed.
48 * 2.) Credit shall not be taken for the creation of this source.
49 * 3.) This code is not to be traded, sold, or used for personal
50 * gain or profit.
51 *
52 */
53
54 #include <stdio.h>
55 #include "rogue.h"
56
57 char login_name[MAX_OPT_LEN];
58 char *nick_name = (char *) 0;
59 char *rest_file = 0;
60 boolean cant_int = 0;
61 boolean did_int = 0;
62 boolean score_only;
63 boolean init_curses = 0;
64 boolean save_is_interactive = 1;
65 boolean ask_quit = 1;
66 boolean no_skull = 0;
67 boolean passgo = 0;
68 char *error_file = "rogue.esave";
69 char *byebye_string = "Okay, bye bye!";
70
71 extern char *fruit;
72 extern char *save_file;
73 extern short party_room;
74 extern boolean jump;
75
76 init(argc, argv)
77 int argc;
78 char *argv[];
79 {
80 char *pn;
81 int seed;
82
83 pn = md_gln();
84 if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) {
85 clean_up("Hey! Who are you?");
86 }
87 (void) strcpy(login_name, pn);
88
89 do_args(argc, argv);
90 do_opts();
91
92 if (!score_only && !rest_file) {
93 printf("Hello %s, just a moment while I dig the dungeon...",
94 nick_name);
95 fflush(stdout);
96 }
97
98 initscr();
99 if ((LINES < DROWS) || (COLS < DCOLS)) {
100 clean_up("must be played on 24 x 80 screen");
101 }
102 start_window();
103 init_curses = 1;
104
105 md_heed_signals();
106
107 if (score_only) {
108 put_scores((object *) 0, 0);
109 }
110 seed = md_gseed();
111 (void) srrandom(seed);
112 if (rest_file) {
113 restore(rest_file);
114 return(1);
115 }
116 mix_colors();
117 get_wand_and_ring_materials();
118 make_scroll_titles();
119
120 level_objects.next_object = (object *) 0;
121 level_monsters.next_monster = (object *) 0;
122 player_init();
123 ring_stats(0);
124 return(0);
125 }
126
127 player_init()
128 {
129 object *obj;
130
131 rogue.pack.next_object = (object *) 0;
132
133 obj = alloc_object();
134 get_food(obj, 1);
135 (void) add_to_pack(obj, &rogue.pack, 1);
136
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 (void) add_to_pack(obj, &rogue.pack, 1);
144 do_wear(obj);
145
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 (void) add_to_pack(obj, &rogue.pack, 1);
153 do_wield(obj);
154
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 (void) add_to_pack(obj, &rogue.pack, 1);
163
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 (void) add_to_pack(obj, &rogue.pack, 1);
173 }
174
175 clean_up(estr)
176 char *estr;
177 {
178 if (save_is_interactive) {
179 if (init_curses) {
180 move(DROWS-1, 0);
181 refresh();
182 stop_window();
183 }
184 printf("\n%s\n", estr);
185 }
186 md_exit(0);
187 }
188
189 start_window()
190 {
191 crmode();
192 noecho();
193 #ifndef BAD_NONL
194 nonl();
195 #endif
196 md_control_keybord(0);
197 }
198
199 stop_window()
200 {
201 endwin();
202 md_control_keybord(1);
203 }
204
205 void
206 byebye()
207 {
208 md_ignore_signals();
209 if (ask_quit) {
210 quit(1);
211 } else {
212 clean_up(byebye_string);
213 }
214 md_heed_signals();
215 }
216
217 void
218 onintr()
219 {
220 md_ignore_signals();
221 if (cant_int) {
222 did_int = 1;
223 } else {
224 check_message();
225 message("interrupt", 1);
226 }
227 md_heed_signals();
228 }
229
230 void
231 error_save()
232 {
233 save_is_interactive = 0;
234 save_into_file(error_file);
235 clean_up("");
236 }
237
238 do_args(argc, argv)
239 int argc;
240 char *argv[];
241 {
242 short i, j;
243
244 for (i = 1; i < argc; i++) {
245 if (argv[i][0] == '-') {
246 for (j = 1; argv[i][j]; j++) {
247 switch(argv[i][j]) {
248 case 's':
249 score_only = 1;
250 break;
251 }
252 }
253 } else {
254 rest_file = argv[i];
255 }
256 }
257 }
258
259 do_opts()
260 {
261 char *eptr;
262
263 if (eptr = md_getenv("ROGUEOPTS")) {
264 for (;;) {
265 while ((*eptr) == ' ') {
266 eptr++;
267 }
268 if (!(*eptr)) {
269 break;
270 }
271 if (!strncmp(eptr, "fruit=", 6)) {
272 eptr += 6;
273 env_get_value(&fruit, eptr, 1);
274 } else if (!strncmp(eptr, "file=", 5)) {
275 eptr += 5;
276 env_get_value(&save_file, eptr, 0);
277 } else if (!strncmp(eptr, "jump", 4)) {
278 jump = 1;
279 } else if (!strncmp(eptr, "name=", 5)) {
280 eptr += 5;
281 env_get_value(&nick_name, eptr, 0);
282 } else if (!strncmp(eptr, "noaskquit", 9)) {
283 ask_quit = 0;
284 } else if (!strncmp(eptr, "noskull", 5) ||
285 !strncmp(eptr,"notomb", 6)) {
286 no_skull = 1;
287 } else if (!strncmp(eptr, "passgo", 5)) {
288 passgo = 1;
289 }
290 while ((*eptr) && (*eptr != ',')) {
291 eptr++;
292 }
293 if (!(*(eptr++))) {
294 break;
295 }
296 }
297 }
298 /* If some strings have not been set through ROGUEOPTS, assign defaults
299 * to them so that the options editor has data to work with.
300 */
301 init_str(&nick_name, login_name);
302 init_str(&save_file, "rogue.save");
303 init_str(&fruit, "slime-mold");
304 }
305
306 env_get_value(s, e, add_blank)
307 char **s, *e;
308 boolean add_blank;
309 {
310 short i = 0;
311 char *t;
312
313 t = e;
314
315 while ((*e) && (*e != ',')) {
316 if (*e == ':') {
317 *e = ';'; /* ':' reserved for score file purposes */
318 }
319 e++;
320 if (++i >= MAX_OPT_LEN) {
321 break;
322 }
323 }
324 *s = md_malloc(MAX_OPT_LEN + 2);
325 (void) strncpy(*s, t, i);
326 if (add_blank) {
327 (*s)[i++] = ' ';
328 }
329 (*s)[i] = '\0';
330 }
331
332 init_str(str, dflt)
333 char **str, *dflt;
334 {
335 if (!(*str)) {
336 *str = md_malloc(MAX_OPT_LEN + 2);
337 (void) strcpy(*str, dflt);
338 }
339 }