2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)message.c 8.1 (Berkeley) 5/31/93
37 * $FreeBSD: src/games/rogue/message.c,v 1.7.2.1 2000/07/20 10:35:07 kris Exp $
38 * $DragonFly: src/games/rogue/message.c,v 1.4 2006/09/02 19:31:07 pavalos Exp $
44 * This source herein may be modified and/or distributed by anybody who
45 * so desires, with the following restrictions:
46 * 1.) No portion of this notice shall be removed.
47 * 2.) Credit shall not be taken for the creation of this source.
48 * 3.) This code is not to be traded, sold, or used for personal
56 char msgs
[NMESSAGES
][DCOLS
] = {"", "", "", "", ""};
57 short msg_col
= 0, imsg
= -1;
58 boolean msg_cleared
= 1, rmsg
= 0;
59 char hunger_str
[HUNGER_STR_LEN
] = "";
60 const char *more
= "-more-";
62 extern boolean cant_int
, did_int
, interrupted
, save_is_interactive
, flush
;
63 extern short add_strength
;
64 extern short cur_level
;
66 static void pad(const char *, short);
67 static void save_screen(void);
70 message(const char *msg
, boolean intrpt
)
74 if (!save_is_interactive
) {
84 mvaddstr(MIN_ROW
-1, msg_col
, more
);
90 imsg
= (imsg
+ 1) % NMESSAGES
;
91 strcpy(msgs
[imsg
], msg
);
93 mvaddstr(MIN_ROW
-1, 0, msg
);
97 msg_col
= strlen(msg
);
116 message(msgs
[((imsg
- c
) % NMESSAGES
)], 0);
118 move(rogue
.row
, rogue
.col
);
136 get_input_line(const char *prompt
, const char *insert
, char *buf
,
137 const char *if_cancelled
, boolean add_blank
, boolean do_echo
)
146 mvaddstr(0, n
+ 1, insert
);
149 move(0, (n
+ i
+ 1));
153 while (((ch
= rgetchar()) != '\r') && (ch
!= '\n') && (ch
!= CANCEL
)) {
154 if ((ch
>= ' ') && (ch
<= '~') && (i
< MAX_TITLE_LENGTH
-2)) {
155 if ((ch
!= ' ') || (i
> 0)) {
162 if ((ch
== '\b') && (i
> 0)) {
164 mvaddch(0, i
+ n
, ' ');
165 move(MIN_ROW
-1, i
+n
);
175 while ((i
> 0) && (buf
[i
-1] == ' ')) {
182 if ((ch
== CANCEL
) || (i
== 0) || ((i
== 1) && add_blank
)) {
184 message(if_cancelled
, 0);
219 Level: 99 Gold: 999999 Hp: 999(999) Str: 99(99) Arm: 99 Exp: 21/10000000 Hungry
220 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5
224 print_stats(int stat_mask
)
230 label
= (stat_mask
& STAT_LABEL
) ? 1 : 0;
232 if (stat_mask
& STAT_LEVEL
) {
234 mvaddstr(row
, 0, "Level: ");
236 /* max level taken care of in make_level() */
237 sprintf(buf
, "%d", cur_level
);
238 mvaddstr(row
, 7, buf
);
241 if (stat_mask
& STAT_GOLD
) {
243 mvaddstr(row
, 10, "Gold: ");
245 if (rogue
.gold
> MAX_GOLD
) {
246 rogue
.gold
= MAX_GOLD
;
248 sprintf(buf
, "%ld", rogue
.gold
);
249 mvaddstr(row
, 16, buf
);
252 if (stat_mask
& STAT_HP
) {
254 mvaddstr(row
, 23, "Hp: ");
256 if (rogue
.hp_max
> MAX_HP
) {
257 rogue
.hp_current
-= (rogue
.hp_max
- MAX_HP
);
258 rogue
.hp_max
= MAX_HP
;
260 sprintf(buf
, "%d(%d)", rogue
.hp_current
, rogue
.hp_max
);
261 mvaddstr(row
, 27, buf
);
264 if (stat_mask
& STAT_STRENGTH
) {
266 mvaddstr(row
, 36, "Str: ");
268 if (rogue
.str_max
> MAX_STRENGTH
) {
269 rogue
.str_current
-= (rogue
.str_max
- MAX_STRENGTH
);
270 rogue
.str_max
= MAX_STRENGTH
;
272 sprintf(buf
, "%d(%d)", (rogue
.str_current
+ add_strength
),
274 mvaddstr(row
, 41, buf
);
277 if (stat_mask
& STAT_ARMOR
) {
279 mvaddstr(row
, 48, "Arm: ");
281 if (rogue
.armor
&& (rogue
.armor
->d_enchant
> MAX_ARMOR
)) {
282 rogue
.armor
->d_enchant
= MAX_ARMOR
;
284 sprintf(buf
, "%d", get_armor_class(rogue
.armor
));
285 mvaddstr(row
, 53, buf
);
288 if (stat_mask
& STAT_EXP
) {
290 mvaddstr(row
, 56, "Exp: ");
292 if (rogue
.exp_points
> MAX_EXP
) {
293 rogue
.exp_points
= MAX_EXP
;
295 if (rogue
.exp
> MAX_EXP_LEVEL
) {
296 rogue
.exp
= MAX_EXP_LEVEL
;
298 sprintf(buf
, "%d/%ld", rogue
.exp
, rogue
.exp_points
);
299 mvaddstr(row
, 61, buf
);
302 if (stat_mask
& STAT_HUNGER
) {
303 mvaddstr(row
, 73, hunger_str
);
310 pad(const char *s
, short n
)
314 for (i
= strlen(s
); i
< n
; i
++) {
325 boolean found_non_blank
;
327 if ((fp
= fopen("rogue.screen", "w")) != NULL
) {
328 for (i
= 0; i
< DROWS
; i
++) {
330 for (j
= (DCOLS
- 1); j
>= 0; j
--) {
331 buf
[j
] = mvinch(i
, j
);
332 if (!found_non_blank
) {
333 if ((buf
[j
] != ' ') || (j
== 0)) {
334 buf
[j
+ ((j
== 0) ? 0 : 1)] = 0;
358 return((ch
>= '0') && (ch
<= '9'));
362 r_index(const char *str
, int ch
, boolean last
)
367 for (i
= strlen(str
) - 1; i
>= 0; i
--) {
373 for (i
= 0; str
[i
]; i
++) {