1 /* $NetBSD: message.c,v 1.13 2008/01/14 03:50:01 dholland Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)message.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: message.c,v 1.13 2008/01/14 03:50:01 dholland Exp $");
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
60 #include "pathnames.h"
62 static char msgs
[NMESSAGES
][DCOLS
] = {"", "", "", "", ""};
63 static short msg_col
= 0, imsg
= -1;
64 static boolean rmsg
= 0;
66 boolean msg_cleared
= 1;
67 char hunger_str
[HUNGER_STR_LEN
] = "";
68 const char *more
= "-more-";
72 message(const char *msg
, boolean intrpt
)
76 if (!save_is_interactive
) {
85 mvaddstr(MIN_ROW
-1, msg_col
, more
);
91 imsg
= (imsg
+ 1) % NMESSAGES
;
92 (void)strlcpy(msgs
[imsg
], msg
, sizeof(msgs
[imsg
]));
94 mvaddstr(MIN_ROW
-1, 0, msg
);
98 msg_col
= strlen(msg
);
109 messagef(boolean intrpt
, const char *fmt
, ...)
115 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
118 message(buf
, intrpt
);
130 message(msgs
[((imsg
- c
) % NMESSAGES
)], 0);
132 move(rogue
.row
, rogue
.col
);
150 get_input_line(const char *prompt
, const char *insert
,
151 char *buf
, size_t buflen
,
152 const char *if_cancelled
,
153 boolean add_blank
, boolean do_echo
)
162 mvaddstr(0, n
+ 1, insert
);
163 (void)strlcpy(buf
, insert
, buflen
);
165 move(0, (n
+ i
+ 1));
169 while (((ch
= rgetchar()) != '\r') && (ch
!= '\n') && (ch
!= CANCEL
)) {
170 if ((ch
>= ' ') && (ch
<= '~') && (i
< buflen
-2)) {
171 if ((ch
!= ' ') || (i
> 0)) {
178 if ((ch
== '\b') && (i
> 0)) {
180 mvaddch(0, i
+ n
, ' ');
181 move(MIN_ROW
-1, i
+n
);
191 while ((i
> 0) && (buf
[i
-1] == ' ')) {
198 if ((ch
== CANCEL
) || (i
== 0) || ((i
== 1) && add_blank
)) {
200 message(if_cancelled
, 0);
216 case '\022': /* ^R */
220 case '\032': /* ^Z */
236 Level: 99 Gold: 999999 Hp: 999(999) Str: 99(99) Arm: 99 Exp: 21/10000000 Hungry
237 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5
241 print_stats(int stat_mask
)
247 label
= (stat_mask
& STAT_LABEL
) ? 1 : 0;
249 if (stat_mask
& STAT_LEVEL
) {
251 mvaddstr(row
, 0, "Level: ");
253 /* max level taken care of in make_level() */
254 mvprintw(row
, 7, "%-2d", cur_level
);
256 if (stat_mask
& STAT_GOLD
) {
258 mvaddstr(row
, 10, "Gold: ");
260 if (rogue
.gold
> MAX_GOLD
) {
261 rogue
.gold
= MAX_GOLD
;
263 mvprintw(row
, 16, "%-6ld", rogue
.gold
);
265 if (stat_mask
& STAT_HP
) {
267 mvaddstr(row
, 23, "Hp: ");
269 if (rogue
.hp_max
> MAX_HP
) {
270 rogue
.hp_current
-= (rogue
.hp_max
- MAX_HP
);
271 rogue
.hp_max
= MAX_HP
;
273 snprintf(buf
, sizeof(buf
), "%d(%d)",
274 rogue
.hp_current
, rogue
.hp_max
);
275 mvprintw(row
, 27, "%-8s", buf
);
277 if (stat_mask
& STAT_STRENGTH
) {
279 mvaddstr(row
, 36, "Str: ");
281 if (rogue
.str_max
> MAX_STRENGTH
) {
282 rogue
.str_current
-= (rogue
.str_max
- MAX_STRENGTH
);
283 rogue
.str_max
= MAX_STRENGTH
;
285 snprintf(buf
, sizeof(buf
), "%d(%d)",
286 (rogue
.str_current
+ add_strength
), rogue
.str_max
);
287 mvprintw(row
, 41, "%-6s", buf
);
289 if (stat_mask
& STAT_ARMOR
) {
291 mvaddstr(row
, 48, "Arm: ");
293 if (rogue
.armor
&& (rogue
.armor
->d_enchant
> MAX_ARMOR
)) {
294 rogue
.armor
->d_enchant
= MAX_ARMOR
;
296 mvprintw(row
, 53, "%-2d", get_armor_class(rogue
.armor
));
298 if (stat_mask
& STAT_EXP
) {
300 mvaddstr(row
, 56, "Exp: ");
302 if (rogue
.exp_points
> MAX_EXP
) {
303 rogue
.exp_points
= MAX_EXP
;
305 if (rogue
.exp
> MAX_EXP_LEVEL
) {
306 rogue
.exp
= MAX_EXP_LEVEL
;
308 snprintf(buf
, sizeof(buf
), "%d/%ld",
309 rogue
.exp
, rogue
.exp_points
);
310 mvprintw(row
, 61, "%-11s", buf
);
312 if (stat_mask
& STAT_HUNGER
) {
313 mvaddstr(row
, 73, hunger_str
);
326 if ((fp
= fopen(_PATH_SCREENDUMP
, "w")) != NULL
) {
327 for (i
= 0; i
< DROWS
; i
++) {
328 for (j
=0; j
<DCOLS
; j
++) {
329 buf
[j
] = mvinch(i
, j
);
331 /*buf[DCOLS] = 0; -- redundant */
332 for (j
=DCOLS
; j
>0 && buf
[j
-1]==' '; j
--);
354 return((ch
>= '0') && (ch
<= '9'));
358 r_index(const char *str
, int ch
, boolean last
)
363 for (i
= strlen(str
) - 1; i
>= 0; i
--) {
369 for (i
= 0; str
[i
]; i
++) {