Example #1
0
char
readchar()
{
	int sym;

	(void) fflush(stdout);
	if((sym = getchar()) == EOF)
#ifdef NR_OF_EOFS
	{ /*
	   * Some SYSV systems seem to return EOFs for various reasons
	   * (?like when one hits break or for interrupted systemcalls?),
	   * and we must see several before we quit.
	   */
		int cnt = NR_OF_EOFS;
		while (cnt--) {
		    clearerr(stdin);	/* omit if clearerr is undefined */
		    if((sym = getchar()) != EOF) goto noteof;
		}
		end_of_input();
	     noteof:	;
	}
#else
		end_of_input();
#endif /* NR_OF_EOFS */
	if(flags.toplin == 1)
		flags.toplin = 2;
	return((char) sym);
}
Example #2
0
void run(bool verbose)
{
    while (!end_of_input())
    {
        if (0 != run_line(verbose))
        {
            puts("ignored");
        }
    }
    trie_clear();
}
Example #3
0
 coco::expected<value_type, parse_error<iterator_stream>> uncons() {
   if (begin_ == end_) {
     return end_of_input(*this);
   }
   return *begin_++;
 }
Example #4
0
void
u_init(void)
{
	int i;
	char exper = 'y', pc;

	if (flags.female)	/* should have been set in HACKOPTIONS */
		strlcpy(roles[4], "Cave-woman", sizeof(roles[4]));
	for (i = 0; i < NR_OF_ROLES; i++)
		rolesyms[i] = roles[i][0];
	rolesyms[i] = 0;

	if ((pc = pl_character[0]) != '\0') {
		if ('a' <= pc && pc <= 'z')
			pc += 'A' - 'a';
		if ((i = role_index(pc)) >= 0)
			goto got_suffix;	/* implies experienced */
		printf("\nUnknown role: %c\n", pc);
		pl_character[0] = pc = 0;
	}

	printf("\nAre you an experienced player? [ny] ");

	while (!strchr("ynYN \n\004", (exper = readchar())))
		bell();
	if (exper == '\004')	/* Give him an opportunity to get out */
		end_of_input();
	printf("%c\n", exper);	/* echo */
	if (strchr("Nn \n", exper)) {
		exper = 0;
		goto beginner;
	}

	printf("\nTell me what kind of character you are:\n");
	printf("Are you");
	for (i = 0; i < NR_OF_ROLES; i++) {
		printf(" a %s", roles[i]);
		if (i == 2)	/* %% */
			printf(",\n\t");
		else if (i < NR_OF_ROLES - 2)
			printf(",");
		else if (i == NR_OF_ROLES - 2)
			printf(" or");
	}
	printf("? [%s] ", rolesyms);

	while ((pc = readchar()) != '\0') {
		if ('a' <= pc && pc <= 'z')
			pc += 'A' - 'a';
		if ((i = role_index(pc)) >= 0) {
			printf("%c\n", pc);	/* echo */
			fflush(stdout);		/* should be seen */
			break;
		}
		if (pc == '\n')
			break;
		if (pc == '\004')	/* Give him the opportunity to get out */
			end_of_input();
		bell();
	}
	if (pc == '\n')
		pc = 0;

beginner:
	if (!pc) {
		printf("\nI'll choose a character for you.\n");
		i = rn2(NR_OF_ROLES);
		pc = rolesyms[i];
		printf("This game you will be a%s %s.\n",
		       exper ? "n experienced" : "",
		       roles[i]);
		getret();
		/* give him some feedback in case mklev takes much time */
		putchar('\n');
		fflush(stdout);
	}
	if (exper)
		roles[i][0] = pc;

got_suffix:

	strncpy(pl_character, roles[i], PL_CSIZ - 1);
	pl_character[PL_CSIZ - 1] = 0;
	flags.beginner = 1;
	u = zerou;
	u.usym = '@';
	u.ulevel = 1;
	init_uhunger();
#ifdef QUEST
	u.uhorizon = 6;
#endif /* QUEST */
	uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain =
		uleft = uright = 0;

	switch (pc) {
	case 'c':
	case 'C':
		Cave_man[2].trquan = 12 + rnd(9) * rnd(9);
		u.uhp = u.uhpmax = 16;
		u.ustr = u.ustrmax = 18;
		ini_inv(Cave_man);
		break;
	case 't':
	case 'T':
		Tourist[3].trquan = 20 + rnd(20);
		u.ugold = u.ugold0 = rnd(1000);
		u.uhp = u.uhpmax = 10;
		u.ustr = u.ustrmax = 8;
		ini_inv(Tourist);
		if (!rn2(25))
			ini_inv(Tinopener);
		break;
	case 'w':
	case 'W':
		for (i = 1; i <= 4; i++)
			if (!rn2(5))
				Wizard[i].trquan += rn2(3) - 1;
		u.uhp = u.uhpmax = 15;
		u.ustr = u.ustrmax = 16;
		ini_inv(Wizard);
		break;
	case 's':
	case 'S':
		Fast = INTRINSIC;
		Stealth = INTRINSIC;
		u.uhp = u.uhpmax = 12;
		u.ustr = u.ustrmax = 10;
		ini_inv(Speleologist);
		if (!rn2(10))
			ini_inv(Tinopener);
		break;
	case 'k':
	case 'K':
		u.uhp = u.uhpmax = 12;
		u.ustr = u.ustrmax = 10;
		ini_inv(Knight);
		break;
	case 'f':
	case 'F':
		u.uhp = u.uhpmax = 14;
		u.ustr = u.ustrmax = 17;
		ini_inv(Fighter);
		break;
	default:		/* impossible */
		u.uhp = u.uhpmax = 12;
		u.ustr = u.ustrmax = 16;
	}
	find_ac();
	if (!rn2(20)) {
		int d1 = rn2(7) - 2;	/* biased variation */
		u.ustr += d1;
		u.ustrmax += d1;
	}

#ifdef WIZARD
	if (wizard)
		wiz_inv();
#endif /* WIZARD */

	/* make sure he can carry all he has - especially for T's */
	while (inv_weight() > 0 && u.ustr < 118)
		u.ustr++, u.ustrmax++;
}