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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
/* $OpenBSD: message.c,v 1.6 2000/07/24 00:56:05 pjanzen Exp $ */
/* $NetBSD: message.c,v 1.5 1995/04/22 10:27:43 cgd Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Timothy C. Stoehr.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)message.c 8.1 (Berkeley) 5/31/93";
#else
static char rcsid[] = "$OpenBSD";
#endif
#endif /* not lint */
/*
* message.c
*
* This source herein may be modified and/or distributed by anybody who
* so desires, with the following restrictions:
* 1.) No portion of this notice shall be removed.
* 2.) Credit shall not be taken for the creation of this source.
* 3.) This code is not to be traded, sold, or used for personal
* gain or profit.
*
*/
#include <signal.h>
#include <termios.h>
#include "rogue.h"
char msgs[NMESSAGES][DCOLS] = {{0}, {0}, {0}, {0}, {0}};
short msg_col = 0, imsg = -1;
boolean msg_cleared = 1, rmsg = 0;
char hunger_str[8] = "";
char *more = "-more-";
void
message(msg, intrpt)
char *msg;
boolean intrpt;
{
cant_int = 1;
if (!save_is_interactive) {
return;
}
if (intrpt) {
interrupted = 1;
md_slurp();
}
if (!msg_cleared) {
mvaddstr(MIN_ROW-1, msg_col, more);
refresh();
wait_for_ack();
check_message();
}
if (!rmsg) {
imsg = (imsg + 1) % NMESSAGES;
(void) strcpy(msgs[imsg], msg);
}
mvaddstr(MIN_ROW-1, 0, msg);
addch(' ');
refresh();
msg_cleared = 0;
msg_col = strlen(msg);
cant_int = 0;
if (did_int) {
did_int = 0;
onintr(0);
}
}
void
remessage(c)
short c;
{
if (imsg != -1) {
check_message();
rmsg = 1;
while (c > imsg) {
c -= NMESSAGES;
}
message(msgs[((imsg - c) % NMESSAGES)], 0);
rmsg = 0;
move(rogue.row, rogue.col);
refresh();
}
}
void
check_message()
{
if (msg_cleared) {
return;
}
move(MIN_ROW-1, 0);
clrtoeol();
refresh();
msg_cleared = 1;
}
int
get_input_line(prompt, insert, buf, if_cancelled, add_blank, do_echo)
char *prompt, *buf, *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 != 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 == CANCEL) || (i == 0) || ((i == 1) && add_blank)) {
if (if_cancelled) {
message(if_cancelled, 0);
}
return(0);
}
return(i);
}
int
rgetchar()
{
int ch;
for(;;) {
ch = getchar();
switch(ch) {
case '\022':
wrefresh(curscr);
break;
#ifdef UNIX_BSD4_2
case '\032':
printf("%s", CL);
fflush(stdout);
tstp();
break;
#endif
case '&':
save_screen();
break;
case EOF:
clean_up("");
break;
default:
return(ch);
}
}
}
/*
Level: 99 Gold: 999999 Hp: 999(999) Str: 99(99) Arm: 99 Exp: 21/10000000 Hungry
0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5
*/
void
print_stats(stat_mask)
int stat_mask;
{
char buf[16];
boolean label;
short row = DROWS - 1;
label = (stat_mask & STAT_LABEL) ? 1 : 0;
if (stat_mask & STAT_LEVEL) {
if (label) {
mvaddstr(row, 0, "Level: ");
}
/* max level taken care of in make_level() */
sprintf(buf, "%d", cur_level);
mvaddstr(row, 7, buf);
pad(buf, 2);
}
if (stat_mask & STAT_GOLD) {
if (label) {
mvaddstr(row, 10, "Gold: ");
}
if (rogue.gold > MAX_GOLD) {
rogue.gold = MAX_GOLD;
}
sprintf(buf, "%ld", rogue.gold);
mvaddstr(row, 16, buf);
pad(buf, 6);
}
if (stat_mask & STAT_HP) {
if (label) {
mvaddstr(row, 23, "Hp: ");
}
if (rogue.hp_max > MAX_HP) {
rogue.hp_current -= (rogue.hp_max - MAX_HP);
rogue.hp_max = MAX_HP;
}
sprintf(buf, "%d(%d)", rogue.hp_current, rogue.hp_max);
mvaddstr(row, 27, buf);
pad(buf, 8);
}
if (stat_mask & STAT_STRENGTH) {
if (label) {
mvaddstr(row, 36, "Str: ");
}
if (rogue.str_max > MAX_STRENGTH) {
rogue.str_current -= (rogue.str_max - MAX_STRENGTH);
rogue.str_max = MAX_STRENGTH;
}
sprintf(buf, "%d(%d)", (rogue.str_current + add_strength),
rogue.str_max);
mvaddstr(row, 41, buf);
pad(buf, 6);
}
if (stat_mask & STAT_ARMOR) {
if (label) {
mvaddstr(row, 48, "Arm: ");
}
if (rogue.armor && (rogue.armor->d_enchant > MAX_ARMOR)) {
rogue.armor->d_enchant = MAX_ARMOR;
}
sprintf(buf, "%d", get_armor_class(rogue.armor));
mvaddstr(row, 53, buf);
pad(buf, 2);
}
if (stat_mask & STAT_EXP) {
if (label) {
mvaddstr(row, 56, "Exp: ");
}
if (rogue.exp_points > MAX_EXP) {
rogue.exp_points = MAX_EXP;
}
if (rogue.exp > MAX_EXP_LEVEL) {
rogue.exp = MAX_EXP_LEVEL;
}
sprintf(buf, "%d/%ld", rogue.exp, rogue.exp_points);
mvaddstr(row, 61, buf);
pad(buf, 11);
}
if (stat_mask & STAT_HUNGER) {
mvaddstr(row, 73, hunger_str);
clrtoeol();
}
refresh();
}
void
pad(s, n)
char *s;
short n;
{
short i;
for (i = strlen(s); i < n; i++) {
addch(' ');
}
}
void
save_screen()
{
FILE *fp;
short i, j;
char buf[DCOLS+2];
boolean found_non_blank;
if ((fp = fopen("rogue.screen", "w")) != NULL) {
for (i = 0; i < DROWS; i++) {
found_non_blank = 0;
for (j = (DCOLS - 1); j >= 0; j--) {
buf[j] = mvinch(i, j);
if (!found_non_blank) {
if ((buf[j] != ' ') || (j == 0)) {
buf[j + ((j == 0) ? 0 : 1)] = 0;
found_non_blank = 1;
}
}
}
fputs(buf, fp);
putc('\n', fp);
}
fclose(fp);
} else {
sound_bell();
}
}
void
sound_bell()
{
putchar(7);
fflush(stdout);
}
boolean
is_digit(ch)
short ch;
{
return((ch >= '0') && (ch <= '9'));
}
int
r_index(str, ch, last)
char *str;
int ch;
boolean last;
{
int i = 0;
if (last) {
for (i = strlen(str) - 1; i >= 0; i--) {
if (str[i] == ch) {
return(i);
}
}
} else {
for (i = 0; str[i]; i++) {
if (str[i] == ch) {
return(i);
}
}
}
return(-1);
}
|