|
|
1.1 root 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 are permitted
9: * provided that: (1) source distributions retain this entire copyright
10: * notice and comment, and (2) distributions including binaries display
11: * the following acknowledgement: ``This product includes software
12: * developed by the University of California, Berkeley and its contributors''
13: * in the documentation or other materials provided with the distribution
14: * and in all advertising materials mentioning features or use of this
15: * software. Neither the name of the University nor the names of its
16: * contributors may be used to endorse or promote products derived
17: * from this software without specific prior written permission.
18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21: */
22:
23: #ifndef lint
24: static char sccsid[] = "@(#)init.c 5.3 (Berkeley) 6/1/90";
25: #endif /* not lint */
26:
27: /*
28: * init.c
29: *
30: * This source herein may be modified and/or distributed by anybody who
31: * so desires, with the following restrictions:
32: * 1.) No portion of this notice shall be removed.
33: * 2.) Credit shall not be taken for the creation of this source.
34: * 3.) This code is not to be traded, sold, or used for personal
35: * gain or profit.
36: *
37: */
38:
39: #include <stdio.h>
40: #include "rogue.h"
41:
42: char login_name[MAX_OPT_LEN];
43: char *nick_name = (char *) 0;
44: char *rest_file = 0;
45: boolean cant_int = 0;
46: boolean did_int = 0;
47: boolean score_only;
48: boolean init_curses = 0;
49: boolean save_is_interactive = 1;
50: boolean ask_quit = 1;
51: boolean no_skull = 0;
52: boolean passgo = 0;
53: char *error_file = "rogue.esave";
54: char *byebye_string = "Okay, bye bye!";
55:
56: extern char *fruit;
57: extern char *save_file;
58: extern short party_room;
59: extern boolean jump;
60:
61: init(argc, argv)
62: int argc;
63: char *argv[];
64: {
65: char *pn;
66: int seed;
67:
68: pn = md_gln();
69: if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) {
70: clean_up("Hey! Who are you?");
71: }
72: (void) strcpy(login_name, pn);
73:
74: do_args(argc, argv);
75: do_opts();
76:
77: if (!score_only && !rest_file) {
78: printf("Hello %s, just a moment while I dig the dungeon...",
79: nick_name);
80: fflush(stdout);
81: }
82:
83: initscr();
84: if ((LINES < DROWS) || (COLS < DCOLS)) {
85: clean_up("must be played on 24 x 80 screen");
86: }
87: start_window();
88: init_curses = 1;
89:
90: md_heed_signals();
91:
92: if (score_only) {
93: put_scores((object *) 0, 0);
94: }
95: seed = md_gseed();
96: (void) srrandom(seed);
97: if (rest_file) {
98: restore(rest_file);
99: return(1);
100: }
101: mix_colors();
102: get_wand_and_ring_materials();
103: make_scroll_titles();
104:
105: level_objects.next_object = (object *) 0;
106: level_monsters.next_monster = (object *) 0;
107: player_init();
108: ring_stats(0);
109: return(0);
110: }
111:
112: player_init()
113: {
114: object *obj;
115:
116: rogue.pack.next_object = (object *) 0;
117:
118: obj = alloc_object();
119: get_food(obj, 1);
120: (void) add_to_pack(obj, &rogue.pack, 1);
121:
122: obj = alloc_object(); /* initial armor */
123: obj->what_is = ARMOR;
124: obj->which_kind = RINGMAIL;
125: obj->class = RINGMAIL+2;
126: obj->is_protected = 0;
127: obj->d_enchant = 1;
128: (void) add_to_pack(obj, &rogue.pack, 1);
129: do_wear(obj);
130:
131: obj = alloc_object(); /* initial weapons */
132: obj->what_is = WEAPON;
133: obj->which_kind = MACE;
134: obj->damage = "2d3";
135: obj->hit_enchant = obj->d_enchant = 1;
136: obj->identified = 1;
137: (void) add_to_pack(obj, &rogue.pack, 1);
138: do_wield(obj);
139:
140: obj = alloc_object();
141: obj->what_is = WEAPON;
142: obj->which_kind = BOW;
143: obj->damage = "1d2";
144: obj->hit_enchant = 1;
145: obj->d_enchant = 0;
146: obj->identified = 1;
147: (void) add_to_pack(obj, &rogue.pack, 1);
148:
149: obj = alloc_object();
150: obj->what_is = WEAPON;
151: obj->which_kind = ARROW;
152: obj->quantity = get_rand(25, 35);
153: obj->damage = "1d2";
154: obj->hit_enchant = 0;
155: obj->d_enchant = 0;
156: obj->identified = 1;
157: (void) add_to_pack(obj, &rogue.pack, 1);
158: }
159:
160: clean_up(estr)
161: char *estr;
162: {
163: if (save_is_interactive) {
164: if (init_curses) {
165: move(DROWS-1, 0);
166: refresh();
167: stop_window();
168: }
169: printf("\n%s\n", estr);
170: }
171: md_exit(0);
172: }
173:
174: start_window()
175: {
176: crmode();
177: noecho();
178: #ifndef BAD_NONL
179: nonl();
180: #endif
181: md_control_keybord(0);
182: }
183:
184: stop_window()
185: {
186: endwin();
187: md_control_keybord(1);
188: }
189:
190: byebye()
191: {
192: md_ignore_signals();
193: if (ask_quit) {
194: quit(1);
195: } else {
196: clean_up(byebye_string);
197: }
198: md_heed_signals();
199: }
200:
201: onintr()
202: {
203: md_ignore_signals();
204: if (cant_int) {
205: did_int = 1;
206: } else {
207: check_message();
208: message("interrupt", 1);
209: }
210: md_heed_signals();
211: }
212:
213: error_save()
214: {
215: save_is_interactive = 0;
216: save_into_file(error_file);
217: clean_up("");
218: }
219:
220: do_args(argc, argv)
221: int argc;
222: char *argv[];
223: {
224: short i, j;
225:
226: for (i = 1; i < argc; i++) {
227: if (argv[i][0] == '-') {
228: for (j = 1; argv[i][j]; j++) {
229: switch(argv[i][j]) {
230: case 's':
231: score_only = 1;
232: break;
233: }
234: }
235: } else {
236: rest_file = argv[i];
237: }
238: }
239: }
240:
241: do_opts()
242: {
243: char *eptr;
244:
245: if (eptr = md_getenv("ROGUEOPTS")) {
246: for (;;) {
247: while ((*eptr) == ' ') {
248: eptr++;
249: }
250: if (!(*eptr)) {
251: break;
252: }
253: if (!strncmp(eptr, "fruit=", 6)) {
254: eptr += 6;
255: env_get_value(&fruit, eptr, 1);
256: } else if (!strncmp(eptr, "file=", 5)) {
257: eptr += 5;
258: env_get_value(&save_file, eptr, 0);
259: } else if (!strncmp(eptr, "jump", 4)) {
260: jump = 1;
261: } else if (!strncmp(eptr, "name=", 5)) {
262: eptr += 5;
263: env_get_value(&nick_name, eptr, 0);
264: } else if (!strncmp(eptr, "noaskquit", 9)) {
265: ask_quit = 0;
266: } else if (!strncmp(eptr, "noskull", 5) ||
267: !strncmp(eptr,"notomb", 6)) {
268: no_skull = 1;
269: } else if (!strncmp(eptr, "passgo", 5)) {
270: passgo = 1;
271: }
272: while ((*eptr) && (*eptr != ',')) {
273: eptr++;
274: }
275: if (!(*(eptr++))) {
276: break;
277: }
278: }
279: }
280: /* If some strings have not been set through ROGUEOPTS, assign defaults
281: * to them so that the options editor has data to work with.
282: */
283: init_str(&nick_name, login_name);
284: init_str(&save_file, "rogue.save");
285: init_str(&fruit, "slime-mold");
286: }
287:
288: env_get_value(s, e, add_blank)
289: char **s, *e;
290: boolean add_blank;
291: {
292: short i = 0;
293: char *t;
294:
295: t = e;
296:
297: while ((*e) && (*e != ',')) {
298: if (*e == ':') {
299: *e = ';'; /* ':' reserved for score file purposes */
300: }
301: e++;
302: if (++i >= MAX_OPT_LEN) {
303: break;
304: }
305: }
306: *s = md_malloc(MAX_OPT_LEN + 2);
307: (void) strncpy(*s, t, i);
308: if (add_blank) {
309: (*s)[i++] = ' ';
310: }
311: (*s)[i] = '\0';
312: }
313:
314: init_str(str, dflt)
315: char **str, *dflt;
316: {
317: if (!(*str)) {
318: *str = md_malloc(MAX_OPT_LEN + 2);
319: (void) strcpy(*str, dflt);
320: }
321: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.