-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathio.c
More file actions
253 lines (224 loc) · 4.35 KB
/
io.c
File metadata and controls
253 lines (224 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
* Various input/output functions
*
* @(#)io.c 4.13 (Berkeley) 2/25/82
*
* Rogue: Exploring the Dungeons of Doom
* Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <ctype.h>
#include <string.h>
#include "rogue.h"
#include <stdarg.h>
/*
* msg:
* Display a message at the top of the screen.
*/
static char msgbuf[BUFSIZ];
static int newpos = 0;
msg(char *fmt, ...)
{
va_list ap;
/*
* if the string is "", just clear the line
*/
if (*fmt == '\0')
{
move(0, 0);
clrtoeol();
mpos = 0;
return;
}
/*
* otherwise add to the message and flush it out
*/
va_start(ap,fmt);
doadd(fmt, ap);
va_end(ap);
endmsg();
}
/*
* addmsg:
* Add things to the current message
*/
addmsg(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
doadd(fmt, ap);
va_end(ap);
}
/*
* endmsg:
* Display a new msg (giving him a chance to see the previous one
* if it is up there with the --More--)
*/
endmsg()
{
if (save_msg)
{
strncpy(huh, msgbuf, 80);
huh[79] = 0;
}
if (mpos)
{
look(FALSE);
move(0, mpos);
addstr("--More--");
refresh();
wait_for(' ');
}
/*
* All messages should start with uppercase, except ones that
* start with a pack addressing character
*/
if (islower(msgbuf[0]) && msgbuf[1] != ')')
msgbuf[0] = toupper(msgbuf[0]);
mvaddstr(0, 0, msgbuf);
clrtoeol();
mpos = newpos;
newpos = 0;
refresh();
}
/*
* doadd:
* Perform an add onto the message buffer
*/
doadd(char *fmt, va_list ap)
{
vsprintf(&msgbuf[newpos], fmt, ap);
newpos = strlen(msgbuf);
}
/*
* step_ok:
* Returns true if it is ok to step on ch
*/
step_ok(ch)
{
switch (ch)
{
case ' ':
case '|':
case '-':
return FALSE;
default:
return (!isalpha(ch));
}
}
/*
* readchar:
* Flushes stdout so that screen is up to date and then returns
* getchar().
*/
readcharw(win)
WINDOW *win;
{
int ch;
ch = md_readchar(win);
if ((ch == 3) || (ch == 0))
{
quit(0);
return(27);
}
return(ch);
}
readchar()
{
return( readcharw(stdscr) );
}
char *
unctrol(ch)
char ch;
{
return( (char *) unctrl(ch) );
}
/*
* status:
* Display the important stats line. Keep the cursor where it was.
*/
status()
{
register int oy, ox, temp;
static int hpwidth = 0, s_hungry;
static int s_lvl, s_pur = -1, s_hp, s_ac = 0;
static str_t s_str;
static long s_exp = 0;
static char *state_name[] =
{
"", "Hungry", "Weak", "Faint"
};
/*
* If nothing has changed since the last status, don't
* bother.
*/
if (s_hp == pstats.s_hpt && s_exp == pstats.s_exp && s_pur == purse
&& s_ac == (cur_armor != NULL ? cur_armor->o_ac : pstats.s_arm)
&& s_str == pstats.s_str && s_lvl == level && s_hungry == hungry_state)
return;
getyx(stdscr, oy, ox);
if (s_hp != max_hp)
{
temp = s_hp = max_hp;
for (hpwidth = 0; temp; hpwidth++)
temp /= 10;
}
move(LINES - 1, 0);
printw("Level: %d Gold: %-5d Hp: %*d(%*d) Str: %2d(%d) Ac: %-2d Exp: %d/%ld %s",
level, purse, hpwidth, pstats.s_hpt, hpwidth, max_hp, pstats.s_str,
max_stats.s_str,
cur_armor != NULL ? cur_armor->o_ac : pstats.s_arm, pstats.s_lvl,
pstats.s_exp, state_name[hungry_state]);
clrtoeol();
/*
* Save old status
*/
s_lvl = level;
s_pur = purse;
s_hp = pstats.s_hpt;
s_str = pstats.s_str;
s_exp = pstats.s_exp;
s_ac = (cur_armor != NULL ? cur_armor->o_ac : pstats.s_arm);
s_hungry = hungry_state;
move(oy, ox);
}
/*
* wait_for
* Sit around until the guy types the right key
*/
wait_for(ch)
register char ch;
{
w_wait_for(stdscr, ch);
}
w_wait_for(win,ch)
WINDOW *win;
register char ch;
{
register char c;
if (ch == '\n')
while ((c = readcharw(win)) != '\n' && c != '\r')
continue;
else
while (readcharw(win) != ch)
continue;
}
/*
* show_win:
* Function used to display a window and wait before returning
*/
show_win(scr, message)
register WINDOW *scr;
char *message;
{
mvwaddstr(scr, 0, 0, message);
touchwin(scr);
wmove(scr, hero.y, hero.x);
wrefresh(scr);
w_wait_for(scr,' ');
clearok(curscr, TRUE);
touchwin(stdscr);
}