Example #1
0
void
id_trap(void)
{
	short dir, row, col, d, t;

	messagef(0, "direction? ");

	while (!is_direction(dir = rgetchar(), &d)) {
		beep();
	}
	check_message();

	if (dir == CANCEL) {
		return;
	}
	row = rogue.row;
	col = rogue.col;

	get_dir_rc(d, &row, &col, 0);

	if ((dungeon[row][col] & TRAP) && (!(dungeon[row][col] & HIDDEN))) {
		t = trap_at(row, col);
		messagef(0, "%s", trap_strings[t*2]);
	} else {
		messagef(0, "no trap there");
	}
}
Example #2
0
int
get_direction(void)
{
    int dir;

    message(mesg[55], 0);
    while (!is_direction(dir = rgetchar())) {
	sound_bell();
    }
    check_message();
    return dir;
}
Example #3
0
void
fight(boolean to_the_death)
{
	short ch, c, d;
	short row, col;
	boolean first_miss = 1;
	short possible_damage;
	object *monster;

	while (!is_direction(ch = rgetchar(), &d)) {
		sound_bell();
		if (first_miss) {
			message("direction?", 0);
			first_miss = 0;
		}
	}
	check_message();
	if (ch == CANCEL) {
		return;
	}
	row = rogue.row; col = rogue.col;
	get_dir_rc(d, &row, &col, 0);

	c = mvinch(row, col);
	if (((c < 'A') || (c > 'Z')) ||
		(!can_move(rogue.row, rogue.col, row, col))) {
		message("I see no monster there", 0);
		return;
	}
	if (!(fight_monster = object_at(&level_monsters, row, col))) {
		return;
	}
	if (!(fight_monster->m_flags & STATIONARY)) {
		possible_damage = ((get_damage(fight_monster->m_damage, 0) * 2) / 3);
	} else {
		possible_damage = fight_monster->stationary_damage - 1;
	}
	while (fight_monster) {
		one_move_rogue(ch, 0);
		if (((!to_the_death) && (rogue.hp_current <= possible_damage)) ||
			interrupted || (!(dungeon[row][col] & MONSTER))) {
			fight_monster = NULL;
		} else {
			monster = object_at(&level_monsters, row, col);
			if (monster != fight_monster) {
				fight_monster = NULL;
			}
		}
	}
}
Example #4
0
int
do_input_line(boolean is_msg, int row, int col, char *prompt, char *insert,
	      char *buf, char *if_cancelled, boolean add_blank,
	      boolean do_echo, int first_ch)
{
    short ch;
    short i = 0, n = 0;
#if defined( JAPAN )
    short k;
    char kanji[MAX_TITLE_LENGTH];
#endif /* JAPAN */

    if (is_msg) {
	message(prompt, 0);
	n = strlen(prompt) + 1;
    } else {
	mvaddstr_rogue(row, col, prompt);
    }

    if (insert[0]) {
	mvaddstr_rogue(row, col + n, insert);
	(void) strcpy(buf, insert);
	i = strlen(insert);
#if defined( JAPAN )
	k = 0;
	while (k < i) {
	    ch = insert[k];
#if defined( EUC )
	    if (ch & 0x80) {	/* for EUC code by Yasha */
		kanji[k] = kanji[k + 1] = 1;
		k += 2;
	    } else {
		kanji[k] = 0;
		k++;
	    }
#else /* not EUC */
	    if (ch >= 0x81 && ch <= 0x9f || ch >= 0xe0 && ch <= 0xfc) {
		kanji[k] = kanji[k + 1] = 1;
		k += 2;
	    } else {
		kanji[k] = 0;
		k++;
	    }
#endif /* not EUC */
	}
#endif /* JAPAN */
	move(row, col + n + i);
	refresh();
    }
#if defined( JAPAN )
    for (;;) {
	if (first_ch) {
	    ch = first_ch;
	    first_ch = 0;
	} else {
	    ch = rgetchar();
	}
	if (ch == '\r' || ch == '\n' || ch == CANCEL) {
	    break;
	}
	if ((ch == '\b') && (i > 0)) {
	    i -= kanji[i - 1] ? 2 : 1;
	    if (do_echo) {
		mvaddstr_rogue(row, col + n + i, "  ");
		move(row, col + n + i);
	    }
	} else if (
#if defined( EUC )
	    (ch >= ' ' && !(ch & 0x80)) && (i < MAX_TITLE_LENGTH - 2)
#else /* Shift JIS */
	    (ch >= ' ' && ch <= '~' || ch >= 0xa0 && ch <= 0xde) && (i < MAX_TITLE_LENGTH - 2)
#endif /* not EUC */
	    ) {
	    if ((ch != ' ') || (i > 0)) {
		buf[i] = ch;
		kanji[i] = 0;
		if (do_echo) {
		    addch(ch);
		}
		i++;
	    }
	} else if (
#if defined( EUC )
	    (ch & 0x80) && (i < MAX_TITLE_LENGTH - 3)
#else /* Shift JIS */
	    (ch >= 0x81 && ch <= 0x9f || ch >= 0xe0 && ch <= 0xfc) && (i < MAX_TITLE_LENGTH - 3)
#endif /* not EUC */
	    ) {
	    buf[i] = ch;
	    buf[i + 1] = rgetchar();
	    kanji[i] = kanji[i + 1] = 1;
	    if (do_echo) {
		addch_rogue(buf[i]);
		addch_rogue(buf[i + 1]);
	    }
	    i += 2;
	}
	refresh();
    }
    if (is_msg) {
	check_message();
    }
    while ((i > 0) && (buf[i - 1] == ' ') && (kanji[i - 1] == 0)) {
	i--;
    }
    if (add_blank) {
	buf[i++] = ' ';
    }
#else /* not JAPAN */
	while (((ch = rgetchar()) != '\r') && (ch != '\n') && (ch != CANCEL)) {
	if ((ch >= ' ') && (ch <= '~') && (i < MAX_TITLE_LENGTH - 2)) {
	    if ((ch != ' ') || (i > 0)) {
		buf[i++] = ch;
		if (do_echo) {
		    addch_rogue(ch);
		}
	    }
	}
	if ((ch == '\b') && (i > 0)) {
	    i--;
	    if (do_echo) {
		mvaddch_rogue(row, col + n + i, ' ');
		move(row, col + n + i);
	    }
	}
	refresh();
    }
    if (is_msg) {
	check_message();
    }
    if (add_blank) {
	buf[i++] = ' ';
    } else {
	while ((i > 0) && (buf[i - 1] == ' ')) {
	    i--;
	}
    }
#endif /* not JAPAN */
	buf[i] = 0;

    if ((ch == CANCEL) || (i == 0) || ((i == 1) && add_blank)) {
	if (is_msg && if_cancelled) {
	    message(if_cancelled, 0);
	}
	return ((ch == CANCEL) ? -1 : 0);
    }
    return i;
}
Example #5
0
char inv_sel(object *pack, unsigned short mask, char *prompt, char *term)
{
	object *obj;
	short i = 0, j, maxlen = 0, n;
	char descs[MAX_PACK_COUNT+1][DCOLS];
	char retc = 0;
	short row, col;

	obj = pack->next_object;

	if (!obj)
	{
		message("Your pack is empty.", 0);
		return;
	}
	while (obj)
	{
		if (obj->what_is & mask)
		{
			descs[i][0] = ' ' ;
			descs[i][1] = obj->ichar;
			descs[i][2] = ')' ;
			descs[i][3] = ' ' ;
			get_desc( obj, descs[i] + 4, 1 ) ;
			if ((n = strlen(descs[i])) > maxlen)
			{
				maxlen = n;
			}
			i++;
		}
		obj = obj->next_object;
	}
	qsort(descs, i, sizeof(*descs), strcmp);
	(void) strcpy(descs[i++], prompt);
	if (maxlen < 27) maxlen = 27;
	col = DCOLS - (maxlen + 2);

	for (row = 0; ((row < i) && (row < DROWS)); row++)
	{
		if (row > 0)
		{
			for (j = col; j < DCOLS; j++)
			{
				descs[row - 1][j - col] = mvinch(row, j);
			}
			descs[row - 1][j - col] = 0;
		}
		mvaddstr(row, col, descs[row]);
		clrtoeol();
	}
	refresh();
	do
	{
		retc = rgetchar();
	} while (!retc || !strchr(term, retc));

	move(0, 0);
	clrtoeol();

	for (j = 1; ((j < i) && (j < DROWS)); j++)
	{
		mvaddstr(j, col, descs[j - 1]);
	}
	return retc;
}
Example #6
0
short get_input_line(char *prompt, char *buf, char *insert, char *if_cancelled,
                     boolean add_blank, boolean do_echo)
{
	short ch;
	short i = 0, n;

	message(prompt, 0);
	n = strlen(prompt);

	if (insert[0])
	{
		mvaddstr(0, n + 1, insert);
		(void) strcpy(buf, insert);
		i = strlen(insert);
		move(0, (n + i + 1));
		refresh();
	}

	while (((ch = rgetchar()) != '\r') && (ch != '\n') && (ch != ROGUE_KEY_CANCEL))
	{
		if ((ch >= ' ') && (ch <= '~') && (i < MAX_TITLE_LENGTH-2))
		{
			if ((ch != ' ') || (i > 0))
			{
				buf[i++] = ch;
				if (do_echo)
				{
					addch(ch);
				}
			}
		}
		if ((ch == '\b') && (i > 0))
		{
			if (do_echo)
			{
				mvaddch(0, i + n, ' ');
				move(MIN_ROW-1, i+n);
			}
			i--;
		}
		refresh();
	}
	check_message();
	if (add_blank)
	{
		buf[i++] = ' ';
	}
	else
	{
		while ((i > 0) && (buf[i-1] == ' '))
		{
			i--;
		}
	}

	buf[i] = 0;

	if ((ch == ROGUE_KEY_CANCEL) || (i == 0) || ((i == 1) && add_blank))
	{
		if (if_cancelled)
		{
			message(if_cancelled, 0);
		}
		return(0);
	}
	return(i);
}