132689Sbostic /* 236704Sbostic * Copyright (c) 1988 The Regents of the University of California. 336704Sbostic * All rights reserved. 436704Sbostic * 536704Sbostic * This code is derived from software contributed to Berkeley by 636704Sbostic * Timothy C. Stoehr. 736704Sbostic * 8*42592Sbostic * %sccs.include.redist.c% 936704Sbostic */ 1036704Sbostic 1136704Sbostic #ifndef lint 12*42592Sbostic static char sccsid[] = "@(#)init.c 5.3 (Berkeley) 06/01/90"; 1336704Sbostic #endif /* not lint */ 1436704Sbostic 1536704Sbostic /* 1632689Sbostic * init.c 1732689Sbostic * 1832689Sbostic * This source herein may be modified and/or distributed by anybody who 1932689Sbostic * so desires, with the following restrictions: 2032689Sbostic * 1.) No portion of this notice shall be removed. 2132689Sbostic * 2.) Credit shall not be taken for the creation of this source. 2232689Sbostic * 3.) This code is not to be traded, sold, or used for personal 2332689Sbostic * gain or profit. 2432689Sbostic * 2532689Sbostic */ 2632689Sbostic 2732689Sbostic #include <stdio.h> 2832689Sbostic #include "rogue.h" 2932689Sbostic 3032689Sbostic char login_name[MAX_OPT_LEN]; 3132689Sbostic char *nick_name = (char *) 0; 3232689Sbostic char *rest_file = 0; 3332689Sbostic boolean cant_int = 0; 3432689Sbostic boolean did_int = 0; 3532689Sbostic boolean score_only; 3632689Sbostic boolean init_curses = 0; 3732689Sbostic boolean save_is_interactive = 1; 3832689Sbostic boolean ask_quit = 1; 3932689Sbostic boolean no_skull = 0; 4032689Sbostic boolean passgo = 0; 4132689Sbostic char *error_file = "rogue.esave"; 4232689Sbostic char *byebye_string = "Okay, bye bye!"; 4332689Sbostic 4432689Sbostic extern char *fruit; 4532689Sbostic extern char *save_file; 4632689Sbostic extern short party_room; 4732689Sbostic extern boolean jump; 4832689Sbostic 4932689Sbostic init(argc, argv) 5032689Sbostic int argc; 5132689Sbostic char *argv[]; 5232689Sbostic { 5332689Sbostic char *pn; 5432689Sbostic int seed; 5532689Sbostic 5632689Sbostic pn = md_gln(); 5732689Sbostic if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) { 5832689Sbostic clean_up("Hey! Who are you?"); 5932689Sbostic } 6032689Sbostic (void) strcpy(login_name, pn); 6132689Sbostic 6232689Sbostic do_args(argc, argv); 6332689Sbostic do_opts(); 6432689Sbostic 6532689Sbostic if (!score_only && !rest_file) { 6632689Sbostic printf("Hello %s, just a moment while I dig the dungeon...", 6732689Sbostic nick_name); 6832689Sbostic fflush(stdout); 6932689Sbostic } 7032689Sbostic 7132689Sbostic initscr(); 7232689Sbostic if ((LINES < DROWS) || (COLS < DCOLS)) { 7332689Sbostic clean_up("must be played on 24 x 80 screen"); 7432689Sbostic } 7532689Sbostic start_window(); 7632689Sbostic init_curses = 1; 7732689Sbostic 7832689Sbostic md_heed_signals(); 7932689Sbostic 8032689Sbostic if (score_only) { 8132689Sbostic put_scores((object *) 0, 0); 8232689Sbostic } 8332689Sbostic seed = md_gseed(); 8432689Sbostic (void) srrandom(seed); 8532689Sbostic if (rest_file) { 8632689Sbostic restore(rest_file); 8732689Sbostic return(1); 8832689Sbostic } 8932689Sbostic mix_colors(); 9032689Sbostic get_wand_and_ring_materials(); 9132689Sbostic make_scroll_titles(); 9232689Sbostic 9332689Sbostic level_objects.next_object = (object *) 0; 9432689Sbostic level_monsters.next_monster = (object *) 0; 9532689Sbostic player_init(); 9632689Sbostic ring_stats(0); 9732689Sbostic return(0); 9832689Sbostic } 9932689Sbostic 10032689Sbostic player_init() 10132689Sbostic { 10232689Sbostic object *obj; 10332689Sbostic 10432689Sbostic rogue.pack.next_object = (object *) 0; 10532689Sbostic 10632689Sbostic obj = alloc_object(); 10732689Sbostic get_food(obj, 1); 10832689Sbostic (void) add_to_pack(obj, &rogue.pack, 1); 10932689Sbostic 11032689Sbostic obj = alloc_object(); /* initial armor */ 11132689Sbostic obj->what_is = ARMOR; 11232689Sbostic obj->which_kind = RINGMAIL; 11332689Sbostic obj->class = RINGMAIL+2; 11432689Sbostic obj->is_protected = 0; 11532689Sbostic obj->d_enchant = 1; 11632689Sbostic (void) add_to_pack(obj, &rogue.pack, 1); 11732689Sbostic do_wear(obj); 11832689Sbostic 11932689Sbostic obj = alloc_object(); /* initial weapons */ 12032689Sbostic obj->what_is = WEAPON; 12132689Sbostic obj->which_kind = MACE; 12232689Sbostic obj->damage = "2d3"; 12332689Sbostic obj->hit_enchant = obj->d_enchant = 1; 12432689Sbostic obj->identified = 1; 12532689Sbostic (void) add_to_pack(obj, &rogue.pack, 1); 12632689Sbostic do_wield(obj); 12732689Sbostic 12832689Sbostic obj = alloc_object(); 12932689Sbostic obj->what_is = WEAPON; 13032689Sbostic obj->which_kind = BOW; 13132689Sbostic obj->damage = "1d2"; 13232689Sbostic obj->hit_enchant = 1; 13332689Sbostic obj->d_enchant = 0; 13432689Sbostic obj->identified = 1; 13532689Sbostic (void) add_to_pack(obj, &rogue.pack, 1); 13632689Sbostic 13732689Sbostic obj = alloc_object(); 13832689Sbostic obj->what_is = WEAPON; 13932689Sbostic obj->which_kind = ARROW; 14032689Sbostic obj->quantity = get_rand(25, 35); 14132689Sbostic obj->damage = "1d2"; 14232689Sbostic obj->hit_enchant = 0; 14332689Sbostic obj->d_enchant = 0; 14432689Sbostic obj->identified = 1; 14532689Sbostic (void) add_to_pack(obj, &rogue.pack, 1); 14632689Sbostic } 14732689Sbostic 14832689Sbostic clean_up(estr) 14932689Sbostic char *estr; 15032689Sbostic { 15132689Sbostic if (save_is_interactive) { 15232689Sbostic if (init_curses) { 15332689Sbostic move(DROWS-1, 0); 15432689Sbostic refresh(); 15532689Sbostic stop_window(); 15632689Sbostic } 15732689Sbostic printf("\n%s\n", estr); 15832689Sbostic } 15932689Sbostic md_exit(0); 16032689Sbostic } 16132689Sbostic 16232689Sbostic start_window() 16332689Sbostic { 16432689Sbostic crmode(); 16532689Sbostic noecho(); 16632689Sbostic #ifndef BAD_NONL 16732689Sbostic nonl(); 16832689Sbostic #endif 16932689Sbostic md_control_keybord(0); 17032689Sbostic } 17132689Sbostic 17232689Sbostic stop_window() 17332689Sbostic { 17432689Sbostic endwin(); 17532689Sbostic md_control_keybord(1); 17632689Sbostic } 17732689Sbostic 17832689Sbostic byebye() 17932689Sbostic { 18032689Sbostic md_ignore_signals(); 18132689Sbostic if (ask_quit) { 18232689Sbostic quit(1); 18332689Sbostic } else { 18432689Sbostic clean_up(byebye_string); 18532689Sbostic } 18632689Sbostic md_heed_signals(); 18732689Sbostic } 18832689Sbostic 18932689Sbostic onintr() 19032689Sbostic { 19132689Sbostic md_ignore_signals(); 19232689Sbostic if (cant_int) { 19332689Sbostic did_int = 1; 19432689Sbostic } else { 19532689Sbostic check_message(); 19632689Sbostic message("interrupt", 1); 19732689Sbostic } 19832689Sbostic md_heed_signals(); 19932689Sbostic } 20032689Sbostic 20132689Sbostic error_save() 20232689Sbostic { 20332689Sbostic save_is_interactive = 0; 20432689Sbostic save_into_file(error_file); 20532689Sbostic clean_up(""); 20632689Sbostic } 20732689Sbostic 20832689Sbostic do_args(argc, argv) 20932689Sbostic int argc; 21032689Sbostic char *argv[]; 21132689Sbostic { 21232689Sbostic short i, j; 21332689Sbostic 21432689Sbostic for (i = 1; i < argc; i++) { 21532689Sbostic if (argv[i][0] == '-') { 21632689Sbostic for (j = 1; argv[i][j]; j++) { 21732689Sbostic switch(argv[i][j]) { 21832689Sbostic case 's': 21932689Sbostic score_only = 1; 22032689Sbostic break; 22132689Sbostic } 22232689Sbostic } 22332689Sbostic } else { 22432689Sbostic rest_file = argv[i]; 22532689Sbostic } 22632689Sbostic } 22732689Sbostic } 22832689Sbostic 22932689Sbostic do_opts() 23032689Sbostic { 23132689Sbostic char *eptr; 23232689Sbostic 23332689Sbostic if (eptr = md_getenv("ROGUEOPTS")) { 23432689Sbostic for (;;) { 23532689Sbostic while ((*eptr) == ' ') { 23632689Sbostic eptr++; 23732689Sbostic } 23832689Sbostic if (!(*eptr)) { 23932689Sbostic break; 24032689Sbostic } 24132689Sbostic if (!strncmp(eptr, "fruit=", 6)) { 24232689Sbostic eptr += 6; 24332689Sbostic env_get_value(&fruit, eptr, 1); 24432689Sbostic } else if (!strncmp(eptr, "file=", 5)) { 24532689Sbostic eptr += 5; 24632689Sbostic env_get_value(&save_file, eptr, 0); 24732689Sbostic } else if (!strncmp(eptr, "jump", 4)) { 24832689Sbostic jump = 1; 24932689Sbostic } else if (!strncmp(eptr, "name=", 5)) { 25032689Sbostic eptr += 5; 25132689Sbostic env_get_value(&nick_name, eptr, 0); 25232689Sbostic } else if (!strncmp(eptr, "noaskquit", 9)) { 25332689Sbostic ask_quit = 0; 25432689Sbostic } else if (!strncmp(eptr, "noskull", 5) || 25532689Sbostic !strncmp(eptr,"notomb", 6)) { 25632689Sbostic no_skull = 1; 25732689Sbostic } else if (!strncmp(eptr, "passgo", 5)) { 25832689Sbostic passgo = 1; 25932689Sbostic } 26032689Sbostic while ((*eptr) && (*eptr != ',')) { 26132689Sbostic eptr++; 26232689Sbostic } 26332689Sbostic if (!(*(eptr++))) { 26432689Sbostic break; 26532689Sbostic } 26632689Sbostic } 26732689Sbostic } 26832689Sbostic /* If some strings have not been set through ROGUEOPTS, assign defaults 26932689Sbostic * to them so that the options editor has data to work with. 27032689Sbostic */ 27132689Sbostic init_str(&nick_name, login_name); 27232689Sbostic init_str(&save_file, "rogue.save"); 27332689Sbostic init_str(&fruit, "slime-mold"); 27432689Sbostic } 27532689Sbostic 27632689Sbostic env_get_value(s, e, add_blank) 27732689Sbostic char **s, *e; 27832689Sbostic boolean add_blank; 27932689Sbostic { 28032689Sbostic short i = 0; 28132689Sbostic char *t; 28232689Sbostic 28332689Sbostic t = e; 28432689Sbostic 28532689Sbostic while ((*e) && (*e != ',')) { 28632689Sbostic if (*e == ':') { 28732689Sbostic *e = ';'; /* ':' reserved for score file purposes */ 28832689Sbostic } 28932689Sbostic e++; 29032689Sbostic if (++i >= MAX_OPT_LEN) { 29132689Sbostic break; 29232689Sbostic } 29332689Sbostic } 29432689Sbostic *s = md_malloc(MAX_OPT_LEN + 2); 29532689Sbostic (void) strncpy(*s, t, i); 29632689Sbostic if (add_blank) { 29732689Sbostic (*s)[i++] = ' '; 29832689Sbostic } 29932689Sbostic (*s)[i] = '\0'; 30032689Sbostic } 30132689Sbostic 30232689Sbostic init_str(str, dflt) 30332689Sbostic char **str, *dflt; 30432689Sbostic { 30532689Sbostic if (!(*str)) { 30632689Sbostic *str = md_malloc(MAX_OPT_LEN + 2); 30732689Sbostic (void) strcpy(*str, dflt); 30832689Sbostic } 30932689Sbostic } 310