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