]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/display.c
1 /* $NetBSD: display.c,v 1.4 1997/10/18 20:03:15 christos Exp $ */
3 /* display.c Larn is copyrighted 1986 by Noah Morgan. */
6 __RCSID("$NetBSD: display.c,v 1.4 1997/10/18 20:03:15 christos Exp $");
11 #define makecode(_a,_b,_c) (((_a)<<16) + ((_b)<<8) + (_c))
13 static void botsub
__P((int, char *));
15 static int minx
, maxx
, miny
, maxy
, k
, m
;
16 static char bot1f
= 0, bot2f
= 0, bot3f
= 0;
21 now for the bottom line of the display
46 bot3f
= bot1f
= bot2f
= 0;
64 if (cbak
[SPELLS
] <= -50 || (always
)) {
67 lprintf("Spells:%3d(%3d)", (long) c
[SPELLS
], (long) c
[SPELLMAX
]);
69 lprintf("Spells:%3d(%2d) ", (long) c
[SPELLS
], (long) c
[SPELLMAX
]);
70 lprintf(" AC: %-3d WC: %-3d Level", (long) c
[AC
], (long) c
[WCLASS
]);
72 lprintf("%3d", (long) c
[LEVEL
]);
74 lprintf(" %-2d", (long) c
[LEVEL
]);
75 lprintf(" Exp: %-9d %s\n", (long) c
[EXPERIENCE
], class[c
[LEVEL
] - 1]);
76 lprintf("HP: %3d(%3d) STR=%-2d INT=%-2d ",
77 (long) c
[HP
], (long) c
[HPMAX
], (long) (c
[STRENGTH
] + c
[STREXTRA
]), (long) c
[INTELLIGENCE
]);
78 lprintf("WIS=%-2d CON=%-2d DEX=%-2d CHA=%-2d LV:",
79 (long) c
[WISDOM
], (long) c
[CONSTITUTION
], (long) c
[DEXTERITY
], (long) c
[CHARISMA
]);
81 if ((level
== 0) || (wizard
))
86 lprcat(levelname
[level
]);
87 lprintf(" Gold: %-6d", (long) c
[GOLD
]);
90 c
[TMP
] = c
[STRENGTH
] + c
[STREXTRA
];
91 for (i
= 0; i
< 100; i
++)
95 botsub(makecode(SPELLS
, 8, 18), "%3d");
97 botsub(makecode(SPELLMAX
, 12, 18), "%3d)");
99 botsub(makecode(SPELLMAX
, 12, 18), "%2d) ");
100 botsub(makecode(HP
, 5, 19), "%3d");
101 botsub(makecode(HPMAX
, 9, 19), "%3d");
102 botsub(makecode(AC
, 21, 18), "%-3d");
103 botsub(makecode(WCLASS
, 30, 18), "%-3d");
104 botsub(makecode(EXPERIENCE
, 49, 18), "%-9d");
105 if (c
[LEVEL
] != cbak
[LEVEL
]) {
107 lprcat(class[c
[LEVEL
] - 1]);
110 botsub(makecode(LEVEL
, 40, 18), "%3d");
112 botsub(makecode(LEVEL
, 40, 18), " %-2d");
113 c
[TMP
] = c
[STRENGTH
] + c
[STREXTRA
];
114 botsub(makecode(TMP
, 18, 19), "%-2d");
115 botsub(makecode(INTELLIGENCE
, 25, 19), "%-2d");
116 botsub(makecode(WISDOM
, 32, 19), "%-2d");
117 botsub(makecode(CONSTITUTION
, 39, 19), "%-2d");
118 botsub(makecode(DEXTERITY
, 46, 19), "%-2d");
119 botsub(makecode(CHARISMA
, 53, 19), "%-2d");
120 if ((level
!= cbak
[CAVELEVEL
]) || (c
[TELEFLAG
] != cbak
[TELEFLAG
])) {
121 if ((level
== 0) || (wizard
))
123 cbak
[TELEFLAG
] = c
[TELEFLAG
];
124 cbak
[CAVELEVEL
] = level
;
129 lprcat(levelname
[level
]);
131 botsub(makecode(GOLD
, 69, 19), "%-6d");
136 special subroutine to update only the gold number on the bottomlines
142 botsub(makecode(GOLD
, 69, 19), "%-6d");
143 /* botsub(GOLD,"%-6d",69,19); */
147 special routine to update hp and level fields on bottom lines
148 called in monster.c hitplayer() and spattack()
153 if (c
[EXPERIENCE
] != cbak
[EXPERIENCE
]) {
157 botsub(makecode(HP
, 5, 19), "%3d");
161 special routine to update number of spells called from regen()
166 botsub(makecode(SPELLS
, 9, 18), "%2d");
170 common subroutine for a more economical bottomline()
172 static struct bot_side_def
{
178 { STEALTH
, "stealth"},
179 { UNDEADPRO
, "undead pro" },
180 { SPIRITPRO
, "spirit pro" },
181 { CHARMCOUNT
, "Charm"},
182 { TIMESTOP
, "Time Stop" },
183 { HOLDMONST
, "Hold Monst" },
184 { GIANTSTR
, "Giant Str"},
185 { FIRERESISTANCE
, "Fire Resit" },
186 { DEXCOUNT
, "Dexterity" },
187 { STRCOUNT
, "Strength"},
188 { SCAREMONST
, "Scare" },
189 { HASTESELF
, "Haste Self" },
190 { CANCELLATION
, "Cancel"},
191 { INVISIBILITY
, "Invisible" },
192 { ALTPRO
, "Protect 3" },
193 { PROTECTIONTIME
, "Protect 2"},
201 for (i
= 0; i
< 17; i
++) {
202 idx
= bot_data
[i
].typ
;
203 if ((always
) || (c
[idx
] != cbak
[idx
])) {
204 if ((always
) || (cbak
[idx
] == 0)) {
207 lprcat(bot_data
[i
].string
);
209 } else if (c
[idx
] == 0) {
226 x
= (idx
>> 8) & 0xff;
228 if (c
[idx
] != cbak
[idx
]) {
231 lprintf(str
, (long) c
[idx
]);
236 * subroutine to draw only a section of the screen
237 * only the top section of the screen is updated.
238 * If entire lines are being drawn, then they will be cleared first.
240 /* for limited screen drawing */
241 int d_xmin
= 0, d_xmax
= MAXX
, d_ymin
= 0, d_ymax
= MAXY
;
244 draws(xmin
, xmax
, ymin
, ymax
)
245 int xmin
, xmax
, ymin
, ymax
;
248 if (xmin
== 0 && xmax
== MAXX
) { /* clear section of screen as
253 for (i
= ymin
; i
< ymin
; i
++)
260 d_ymax
= ymax
; /* for limited screen drawing */
262 if (xmin
<= 0 && xmax
== MAXX
) { /* draw stuff on right side
263 * of screen as needed */
264 for (i
= ymin
; i
< ymax
; i
++) {
265 idx
= bot_data
[i
].typ
;
268 lprcat(bot_data
[i
].string
);
278 subroutine to redraw the whole screen as the player knows it
280 u_char screen
[MAXX
][MAXY
], d_flag
; /* template for the screen */
285 int lastx
, lasty
; /* variables used to optimize the
287 if (d_xmin
== 0 && d_xmax
== MAXX
&& d_ymin
== 0 && d_ymax
== MAXY
) {
289 clear(); /* clear the screen */
295 d_xmin
= 0; /* d_xmin=-1 means display all without
298 for (i
= d_ymin
; i
< d_ymax
; i
++)
299 for (j
= d_xmin
; j
< d_xmax
; j
++)
302 else if ((k
= mitem
[j
][i
]) != 0)
303 screen
[j
][i
] = monstnamelist
[k
];
304 else if ((k
= item
[j
][i
]) == OWALL
)
309 for (i
= d_ymin
; i
< d_ymax
; i
++) {
311 while ((screen
[j
][i
] == ' ') && (j
< d_xmax
))
315 m
= d_xmin
; /* don't search backwards if blank
317 else { /* search backwards for end of line */
319 while ((screen
[m
][i
] == ' ') && (m
> d_xmin
))
322 cursor(j
+ 1, i
+ 1);
328 for (k
= j
; k
<= j
+ 3; k
++)
329 if (screen
[k
][i
] != ' ')
332 while (screen
[j
][i
] == ' ' && j
<= m
)
334 cursor(j
+ 1, i
+ 1);
337 lprc(screen
[j
++][i
]);
340 setbold(); /* print out only bold objects now */
342 for (lastx
= lasty
= 127, i
= d_ymin
; i
< d_ymax
; i
++)
343 for (j
= d_xmin
; j
< d_xmax
; j
++) {
344 if ((k
= item
[j
][i
]) != 0)
346 if ((know
[j
][i
]) && (mitem
[j
][i
] == 0))
347 if (objnamelist
[k
] != ' ') {
348 if (lasty
!= i
+ 1 || lastx
!= j
)
349 cursor(lastx
= j
+ 1, lasty
= i
+ 1);
352 lprc(objnamelist
[k
]);
364 d_xmin
= 0, d_xmax
= MAXX
, d_ymin
= 0, d_ymax
= MAXY
; /* for limited screen
372 subroutine to display a cell location on the screen
380 return; /* see nothing if blind */
402 for (j
= miny
; j
<= maxy
; j
++)
403 for (m
= minx
; m
<= maxx
; m
++)
404 if (know
[m
][j
] == 0) {
405 cursor(m
+ 1, j
+ 1);
409 for (i
= m
; i
<= x
; i
++) {
410 if ((k
= mitem
[i
][j
]) != 0)
411 lprc(monstnamelist
[k
]);
413 switch (k
= item
[i
][j
]) {
420 lprc(objnamelist
[k
]);
425 lprc(objnamelist
[k
]);
435 this routine shows only the spot that is given it. the spaces around
436 these coordinated are not shown
437 used in godirect() in monster.c for missile weapons display
444 return; /* see nothing if blind */
445 cursor(x
+ 1, y
+ 1);
446 if ((k
= mitem
[x
][y
]) != 0)
447 lprc(monstnamelist
[k
]);
449 switch (k
= item
[x
][y
]) {
456 lprc(objnamelist
[k
]);
461 lprc(objnamelist
[k
]);
464 know
[x
][y
] |= 1; /* we end up knowing about it */
470 subroutine to show where the player is on the screen
471 cursor values start from 1 up
476 cursor(playerx
+ 1, playery
+ 1);
484 subroutine to move the player from one room to another
485 returns 0 if can't move in that direction or hit a monster or on an object
487 nomove is set to 1 to stop the next move (inadvertent monsters hitting
488 players when walking into walls) if player walks off screen or into wall
490 short diroffx
[] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
491 short diroffy
[] = {0, 1, 0, -1, 0, -1, -1, 1, 1};
494 int dir
; /* from = present room # direction =
495 * [1-north] [2-east] [3-south] [4-west]
496 * [5-northeast] [6-northwest] [7-southeast]
497 * [8-southwest] if direction=0, don't
498 * move--just show where he is */
502 if (c
[LEVEL
] < rnd(30))
503 dir
= rund(9); /* if confused any dir */
504 k
= playerx
+ diroffx
[dir
];
505 m
= playery
+ diroffy
[dir
];
506 if (k
< 0 || k
>= MAXX
|| m
< 0 || m
>= MAXY
) {
508 return (yrepcount
= 0);
512 if (i
== OWALL
&& c
[WTW
] == 0) {
514 return (yrepcount
= 0);
516 if (k
== 33 && m
== MAXY
- 1 && level
== 1) {
518 for (k
= 0; k
< MAXX
; k
++)
519 for (m
= 0; m
< MAXY
; m
++)
520 if (item
[k
][m
] == OENTRANCE
) {
530 return (yrepcount
= 0);
531 } /* hit a monster */
536 if (i
&& i
!= OTRAPARROWIV
&& i
!= OIVTELETRAP
&& i
!= OIVDARTRAP
&& i
!= OIVTRAPDOOR
)
537 return (yrepcount
= 0);
544 * function to show what magic items have been discovered thus far
545 * enter with -1 for just spells, anything else will give scrolls & potions
547 static int lincount
, count
;
553 count
= lincount
= 0;
556 if (arg
== -1) { /* if display spells while casting one */
557 for (number
= i
= 0; i
< SPNUM
; i
++)
560 number
= (number
+ 2) / 3 + 4; /* # lines needed to display */
568 lprcat("The magic spells you have discovered thus far:\n\n");
569 for (i
= 0; i
< SPNUM
; i
++)
571 lprintf("%s %-20s ", spelcode
[i
], spelname
[i
]);
578 draws(0, MAXX
, 0, number
);
586 lprcat("\nThe magic scrolls you have found to date are:\n\n");
588 for (i
= 0; i
< MAXSCROLL
; i
++)
589 if (scrollname
[i
][0])
590 if (scrollname
[i
][1] != ' ') {
591 lprintf("%-26s", &scrollname
[i
][1]);
599 lprcat("\nThe magic potions you have found to date are:\n\n");
601 for (i
= 0; i
< MAXPOTION
; i
++)
602 if (potionname
[i
][0])
603 if (potionname
[i
][1] != ' ') {
604 lprintf("%-26s", &potionname
[i
][1]);
615 * subroutine to paginate the seemagic function