2004-04-11 17:35:06 +04:00
|
|
|
/* $NetBSD: io.c,v 1.8 2004/04/11 13:35:06 he Exp $ */
|
1995-03-24 06:58:08 +03:00
|
|
|
|
1994-10-22 00:19:39 +03:00
|
|
|
/*
|
|
|
|
* io.c - input/output routines for Phantasia
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include.h"
|
2004-04-11 17:35:06 +04:00
|
|
|
#undef bool
|
2004-04-07 21:46:47 +04:00
|
|
|
#include <curses.h>
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
getstring(cp, mx)
|
1997-10-13 06:18:06 +04:00
|
|
|
char *cp;
|
|
|
|
int mx;
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
char *inptr; /* pointer into string for next string */
|
|
|
|
int x, y; /* original x, y coordinates on screen */
|
|
|
|
int ch; /* input */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
getyx(stdscr, y, x); /* get coordinates on screen */
|
|
|
|
inptr = cp;
|
|
|
|
*inptr = '\0'; /* clear string to start */
|
|
|
|
--mx; /* reserve room in string for nul terminator */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
do
|
|
|
|
/* get characters and process */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
if (Echo)
|
|
|
|
mvaddstr(y, x, cp); /* print string on screen */
|
|
|
|
clrtoeol(); /* clear any data after string */
|
|
|
|
refresh(); /* update screen */
|
|
|
|
|
|
|
|
ch = getchar(); /* get character */
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case CH_ERASE: /* back up one character */
|
|
|
|
if (inptr > cp)
|
|
|
|
--inptr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CH_KILL: /* back up to original location */
|
|
|
|
inptr = cp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CH_NEWLINE: /* terminate string */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CH_REDRAW:/* redraw screen */
|
|
|
|
clearok(stdscr, TRUE);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default: /* put data in string */
|
|
|
|
if (ch >= ' ' || Wizard)
|
|
|
|
/* printing char; put in string */
|
|
|
|
*inptr++ = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
*inptr = '\0'; /* terminate string */
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
1997-10-13 06:18:06 +04:00
|
|
|
while (ch != CH_NEWLINE && inptr < cp + mx);
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
more(where)
|
1997-10-13 06:18:06 +04:00
|
|
|
int where;
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
mvaddstr(where, 0, "-- more --");
|
|
|
|
getanswer(" ", FALSE);
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
infloat()
|
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
double result; /* return value */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
getstring(Databuf, SZ_DATABUF);
|
|
|
|
if (sscanf(Databuf, "%lf", &result) < 1)
|
|
|
|
/* no valid number entered */
|
|
|
|
result = 0.0;
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
return (result);
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
int
|
1994-10-22 00:19:39 +03:00
|
|
|
inputoption()
|
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
++Player.p_age; /* increase age */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if (Player.p_ring.ring_type != R_SPOILED)
|
|
|
|
/* ring ok */
|
|
|
|
return (getanswer("T ", TRUE));
|
|
|
|
else
|
|
|
|
/* bad ring */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
getanswer(" ", TRUE);
|
|
|
|
return ((int) ROLL(0.0, 5.0) + '0');
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
void
|
1994-10-22 00:19:39 +03:00
|
|
|
interrupt()
|
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
char line[81]; /* a place to store data already on screen */
|
|
|
|
int loop; /* counter */
|
|
|
|
int x, y; /* coordinates on screen */
|
|
|
|
int ch; /* input */
|
|
|
|
unsigned savealarm; /* to save alarm value */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
|
|
#ifdef SYS3
|
1997-10-13 06:18:06 +04:00
|
|
|
signal(SIGINT, SIG_IGN);
|
1994-10-22 00:19:39 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SYS5
|
1997-10-13 06:18:06 +04:00
|
|
|
signal(SIGINT, SIG_IGN);
|
1994-10-22 00:19:39 +03:00
|
|
|
#endif
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
savealarm = alarm(0); /* turn off any alarms */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
getyx(stdscr, y, x); /* save cursor location */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
for (loop = 0; loop < 80; ++loop) { /* save line on screen */
|
|
|
|
move(4, loop);
|
|
|
|
line[loop] = inch();
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
1997-10-13 06:18:06 +04:00
|
|
|
line[80] = '\0'; /* nul terminate */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
if (Player.p_status == S_INBATTLE || Player.p_status == S_MONSTER)
|
|
|
|
/* in midst of fighting */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
mvaddstr(4, 0, "Quitting now will automatically kill your character. Still want to ? ");
|
|
|
|
ch = getanswer("NY", FALSE);
|
|
|
|
if (ch == 'Y')
|
|
|
|
death("Bailing out");
|
|
|
|
/* NOTREACHED */
|
|
|
|
} else {
|
|
|
|
mvaddstr(4, 0, "Do you really want to quit ? ");
|
|
|
|
ch = getanswer("NY", FALSE);
|
|
|
|
if (ch == 'Y')
|
|
|
|
leavegame();
|
|
|
|
/* NOTREACHED */
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
mvaddstr(4, 0, line); /* restore data on screen */
|
|
|
|
move(y, x); /* restore cursor */
|
|
|
|
refresh();
|
1994-10-22 00:19:39 +03:00
|
|
|
|
|
|
|
#ifdef SYS3
|
1997-10-13 06:18:06 +04:00
|
|
|
signal(SIGINT, interrupt);
|
1994-10-22 00:19:39 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SYS5
|
1997-10-13 06:18:06 +04:00
|
|
|
signal(SIGINT, interrupt);
|
1994-10-22 00:19:39 +03:00
|
|
|
#endif
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
alarm(savealarm); /* restore alarm */
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
int
|
1994-10-22 00:19:39 +03:00
|
|
|
getanswer(choices, def)
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *choices;
|
1997-10-13 06:18:06 +04:00
|
|
|
bool def;
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
int ch; /* input */
|
2004-02-08 03:32:07 +03:00
|
|
|
volatile int loop; /* counter */
|
|
|
|
volatile int oldx, oldy; /* original coordinates on screen */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
getyx(stdscr, oldy, oldx);
|
|
|
|
alarm(0); /* make sure alarm is off */
|
1994-10-22 00:19:39 +03:00
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
for (loop = 3; loop; --loop)
|
|
|
|
/* try for 3 times */
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
if (setjmp(Timeoenv) != 0)
|
|
|
|
/* timed out waiting for response */
|
|
|
|
{
|
|
|
|
if (def || loop <= 1)
|
|
|
|
/* return default answer */
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
/* prompt, and try again */
|
|
|
|
goto YELL;
|
|
|
|
} else
|
|
|
|
/* wait for response */
|
|
|
|
{
|
|
|
|
clrtoeol();
|
|
|
|
refresh();
|
1994-10-22 00:19:39 +03:00
|
|
|
#ifdef BSD41
|
1997-10-13 06:18:06 +04:00
|
|
|
sigset(SIGALRM, catchalarm);
|
1994-10-22 00:19:39 +03:00
|
|
|
#else
|
1997-10-13 06:18:06 +04:00
|
|
|
signal(SIGALRM, catchalarm);
|
1994-10-22 00:19:39 +03:00
|
|
|
#endif
|
1997-10-13 06:18:06 +04:00
|
|
|
/* set timeout */
|
|
|
|
if (Timeout)
|
|
|
|
alarm(7); /* short */
|
|
|
|
else
|
|
|
|
alarm(600); /* long */
|
|
|
|
|
|
|
|
ch = getchar();
|
|
|
|
|
|
|
|
alarm(0); /* turn off timeout */
|
|
|
|
|
|
|
|
if (ch < 0)
|
|
|
|
/* caught some signal */
|
|
|
|
{
|
|
|
|
++loop;
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
if (ch == CH_REDRAW)
|
|
|
|
/* redraw screen */
|
|
|
|
{
|
|
|
|
clearok(stdscr, TRUE); /* force clear screen */
|
|
|
|
++loop; /* don't count this input */
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
if (Echo) {
|
|
|
|
addch(ch); /* echo character */
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
if (islower(ch))
|
|
|
|
/* convert to upper case */
|
|
|
|
ch = toupper(ch);
|
|
|
|
|
|
|
|
if (def || strchr(choices, ch) != NULL)
|
|
|
|
/* valid choice */
|
|
|
|
return (ch);
|
|
|
|
else
|
|
|
|
if (!def && loop > 1)
|
|
|
|
/* bad choice; prompt, and try again */
|
|
|
|
{
|
|
|
|
YELL: mvprintw(oldy + 1, 0, "Please choose one of : [%s]\n", choices);
|
|
|
|
move(oldy, oldx);
|
|
|
|
clrtoeol();
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
/* return default answer */
|
|
|
|
break;
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-13 06:18:06 +04:00
|
|
|
return (*choices);
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-13 06:18:06 +04:00
|
|
|
catchalarm(dummy)
|
1999-09-09 01:45:25 +04:00
|
|
|
int dummy __attribute__((__unused__));
|
1994-10-22 00:19:39 +03:00
|
|
|
{
|
1997-10-13 06:18:06 +04:00
|
|
|
longjmp(Timeoenv, 1);
|
1994-10-22 00:19:39 +03:00
|
|
|
}
|