summaryrefslogtreecommitdiff
path: root/games/hunt/huntd/draw.c
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>1999-01-29 07:30:38 +0000
committerDavid Leonard <d@cvs.openbsd.org>1999-01-29 07:30:38 +0000
commit9fd17607ee9aca36de862c448a6c22177b84d215 (patch)
tree33e448e38134371bc7ad1ae1faeeadb9936e5ab9 /games/hunt/huntd/draw.c
parent26b686ad51fb59b91e320e0bb8a394b6670ea667 (diff)
major changes: security, curses, config
Diffstat (limited to 'games/hunt/huntd/draw.c')
-rw-r--r--games/hunt/huntd/draw.c285
1 files changed, 137 insertions, 148 deletions
diff --git a/games/hunt/huntd/draw.c b/games/hunt/huntd/draw.c
index 2262407a989..ac6c32ba148 100644
--- a/games/hunt/huntd/draw.c
+++ b/games/hunt/huntd/draw.c
@@ -1,13 +1,24 @@
+/* $OpenBSD: draw.c,v 1.3 1999/01/29 07:30:35 d Exp $ */
/* $NetBSD: draw.c,v 1.2 1997/10/10 16:33:04 lukem Exp $ */
-/* $OpenBSD: draw.c,v 1.2 1999/01/21 05:47:40 d Exp $ */
/*
* Hunt
* Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
* San Francisco, California
*/
-# include "hunt.h"
+#include "hunt.h"
+#include "server.h"
+#include "conf.h"
+static char translate __P((char));
+static int player_sym __P((PLAYER *, int, int));
+static void drawstatus __P((PLAYER *));
+static void see __P((PLAYER *, int));
+
+/*
+ * drawmaze:
+ * Draw the entire maze on a player's screen.
+ */
void
drawmaze(pp)
PLAYER *pp;
@@ -17,21 +28,26 @@ drawmaze(pp)
int y;
char *endp;
+ /* Clear the client's screen: */
clrscr(pp);
+ /* Draw the top row of the maze: */
outstr(pp, pp->p_maze[0], WIDTH);
for (y = 1; y < HEIGHT - 1; y++) {
endp = &pp->p_maze[y][WIDTH];
for (x = 0, sp = pp->p_maze[y]; sp < endp; x++, sp++)
if (*sp != SPACE) {
cgoto(pp, y, x);
+ /* Draw the player as themselves */
if (pp->p_x == x && pp->p_y == y)
outch(pp, translate(*sp));
+ /* Possibly draw other players as team nrs */
else if (isplayer(*sp))
outch(pp, player_sym(pp, y, x));
else
outch(pp, *sp);
}
}
+ /* Draw the last row of the maze: */
cgoto(pp, HEIGHT - 1, 0);
outstr(pp, pp->p_maze[HEIGHT - 1], WIDTH);
drawstatus(pp);
@@ -41,58 +57,46 @@ drawmaze(pp)
* drawstatus - put up the status lines (this assumes the screen
* size is 80x24 with the maze being 64x24)
*/
-void
+static void
drawstatus(pp)
PLAYER *pp;
{
int i;
PLAYER *np;
- cgoto(pp, STAT_AMMO_ROW, STAT_LABEL_COL);
- outstr(pp, "Ammo:", 5);
- (void) sprintf(Buf, "%3d", pp->p_ammo);
- cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
- outstr(pp, Buf, 3);
-
- cgoto(pp, STAT_GUN_ROW, STAT_LABEL_COL);
- outstr(pp, "Gun:", 4);
- cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
- outstr(pp, (pp->p_ncshot < MAXNCSHOT) ? " ok" : " ", 3);
-
- cgoto(pp, STAT_DAM_ROW, STAT_LABEL_COL);
- outstr(pp, "Damage:", 7);
- (void) sprintf(Buf, "%2d/%2d", pp->p_damage, pp->p_damcap);
- cgoto(pp, STAT_DAM_ROW, STAT_VALUE_COL);
- outstr(pp, Buf, 5);
-
- cgoto(pp, STAT_KILL_ROW, STAT_LABEL_COL);
- outstr(pp, "Kills:", 6);
- (void) sprintf(Buf, "%3d", (pp->p_damcap - MAXDAM) / 2);
- cgoto(pp, STAT_KILL_ROW, STAT_VALUE_COL);
- outstr(pp, Buf, 3);
-
- cgoto(pp, STAT_PLAY_ROW, STAT_LABEL_COL);
- outstr(pp, "Player:", 7);
- for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++) {
- (void) sprintf(Buf, "%5.2f%c%-10.10s %c", np->p_ident->i_score,
- stat_char(np), np->p_ident->i_name,
- np->p_ident->i_team);
- cgoto(pp, i++, STAT_NAME_COL);
- outstr(pp, Buf, STAT_NAME_LEN);
- }
+ outyx(pp, STAT_AMMO_ROW, STAT_LABEL_COL, "Ammo:");
+ ammo_update(pp);
+
+ outyx(pp, STAT_GUN_ROW, STAT_LABEL_COL, "Gun:");
+ outyx(pp, STAT_GUN_ROW, STAT_VALUE_COL, "%3s",
+ (pp->p_ncshot < conf_maxncshot) ? "ok" : "");
-# ifdef MONITOR
- cgoto(pp, STAT_MON_ROW, STAT_LABEL_COL);
- outstr(pp, "Monitor:", 8);
- for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++) {
- (void) sprintf(Buf, "%5.5s %-10.10s %c", " ",
+ outyx(pp, STAT_DAM_ROW, STAT_LABEL_COL, "Damage:");
+ outyx(pp, STAT_DAM_ROW, STAT_VALUE_COL, "%2d/%2d",
+ pp->p_damage, pp->p_damcap);
+
+ outyx(pp, STAT_KILL_ROW, STAT_LABEL_COL, "Kills:");
+ outyx(pp, STAT_KILL_ROW, STAT_VALUE_COL, "%3d",
+ (pp->p_damcap - conf_maxdam) / 2);
+
+ outyx(pp, STAT_PLAY_ROW, STAT_LABEL_COL, "Player:");
+ for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++, i++) {
+ outyx(pp, i, STAT_NAME_COL, "%5.2f%c%-10.10s %c",
+ np->p_ident->i_score, stat_char(np),
np->p_ident->i_name, np->p_ident->i_team);
- cgoto(pp, i++, STAT_NAME_COL);
- outstr(pp, Buf, STAT_NAME_LEN);
}
-# endif
+
+ outyx(pp, STAT_MON_ROW, STAT_LABEL_COL, "Monitor:");
+ for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++, i++) {
+ outyx(pp, i++, STAT_NAME_COL, "%5.5s %-10.10s %c",
+ " ", np->p_ident->i_name, np->p_ident->i_team);
+ }
}
+/*
+ * look
+ * check and update the visible area around the player
+ */
void
look(pp)
PLAYER *pp;
@@ -102,6 +106,10 @@ look(pp)
x = pp->p_x;
y = pp->p_y;
+ /*
+ * The player is aware of all objects immediately adjacent to
+ * their position:
+ */
check(pp, y - 1, x - 1);
check(pp, y - 1, x );
check(pp, y - 1, x + 1);
@@ -113,6 +121,7 @@ look(pp)
check(pp, y + 1, x + 1);
switch (pp->p_face) {
+ /* The player can see down corridors in directions except behind: */
case LEFTS:
see(pp, LEFTS);
see(pp, ABOVE);
@@ -133,101 +142,62 @@ look(pp)
see(pp, LEFTS);
see(pp, RIGHT);
break;
-# ifdef FLY
+ /* But they don't see too far when they are flying about: */
case FLYER:
break;
-# endif
}
+
+ /* Move the cursor back over the player: */
cgoto(pp, y, x);
}
-void
+/*
+ * see
+ * Look down a corridor, or towards an open space. This
+ * is a simulation of visibility from the player's perspective.
+ */
+static void
see(pp, face)
PLAYER *pp;
int face;
{
char *sp;
- int y, x, i, cnt;
+ int y, x;
+ /* Start from the player's position: */
x = pp->p_x;
y = pp->p_y;
+ #define seewalk(dx, dy) \
+ x += (dx); \
+ y += (dy); \
+ sp = &Maze[y][x]; \
+ while (See_over[(int)*sp]) { \
+ x += (dx); \
+ y += (dy); \
+ sp += ((dx) + (dy) * sizeof Maze[0]); \
+ check(pp, y + dx, x + dy); \
+ check(pp, y, x); \
+ check(pp, y - dx, x - dy); \
+ }
+
switch (face) {
case LEFTS:
- sp = &Maze[y][x];
- for (i = 0; See_over[(int)*--sp]; i++)
- continue;
-
- if (i == 0)
- break;
-
- cnt = i;
- x = pp->p_x - 1;
- --y;
- while (i--)
- check(pp, y, --x);
- i = cnt;
- x = pp->p_x - 1;
- ++y;
- while (i--)
- check(pp, y, --x);
- i = cnt;
- x = pp->p_x - 1;
- ++y;
- while (i--)
- check(pp, y, --x);
- break;
+ seewalk(-1, 0); break;
case RIGHT:
- sp = &Maze[y][++x];
- for (i = 0; See_over[(int)*sp++]; i++)
- continue;
-
- if (i == 0)
- break;
-
- cnt = i;
- x = pp->p_x + 1;
- --y;
- while (i--)
- check(pp, y, ++x);
- i = cnt;
- x = pp->p_x + 1;
- ++y;
- while (i--)
- check(pp, y, ++x);
- i = cnt;
- x = pp->p_x + 1;
- ++y;
- while (i--)
- check(pp, y, ++x);
- break;
+ seewalk(1, 0); break;
case ABOVE:
- sp = &Maze[--y][x];
- if (!See_over[(int)*sp])
- break;
- do {
- --y;
- sp -= sizeof Maze[0];
- check(pp, y, x - 1);
- check(pp, y, x );
- check(pp, y, x + 1);
- } while (See_over[(int)*sp]);
- break;
+ seewalk(0, -1); break;
case BELOW:
- sp = &Maze[++y][x];
- if (!See_over[(int)*sp])
- break;
- do {
- y++;
- sp += sizeof Maze[0];
- check(pp, y, x - 1);
- check(pp, y, x );
- check(pp, y, x + 1);
- } while (See_over[(int)*sp]);
- break;
+ seewalk(0, 1); break;
}
}
+/*
+ * check
+ * The player is aware of a cell in the maze.
+ * Ensure it is shown properly on their screen.
+ */
void
check(pp, y, x)
PLAYER *pp;
@@ -237,6 +207,14 @@ check(pp, y, x)
int ch;
PLAYER *rpp;
+ if (pp == ALL_PLAYERS) {
+ for (pp = Player; pp < End_player; pp++)
+ check(pp, y, x);
+ for (pp = Monitor; pp < End_monitor; pp++)
+ check(pp, y, x);
+ return;
+ }
+
index = y * sizeof Maze[0] + x;
ch = ((char *) Maze)[index];
if (ch != ((char *) pp->p_maze)[index]) {
@@ -254,34 +232,24 @@ check(pp, y, x)
/*
* showstat
- * Update the status of players
+ * Update the status of a player on everyone's screen
*/
void
showstat(pp)
PLAYER *pp;
{
- PLAYER *np;
- int y;
- char c;
-
- y = STAT_PLAY_ROW + 1 + (pp - Player);
- c = stat_char(pp);
-# ifdef MONITOR
- for (np = Monitor; np < End_monitor; np++) {
- cgoto(np, y, STAT_SCAN_COL);
- outch(np, c);
- }
-# endif
- for (np = Player; np < End_player; np++) {
- cgoto(np, y, STAT_SCAN_COL);
- outch(np, c);
- }
+
+ outyx(ALL_PLAYERS,
+ STAT_PLAY_ROW + 1 + (pp - Player), STAT_SCAN_COL,
+ "%c", stat_char(pp));
}
/*
* drawplayer:
* Draw the player on the screen and show him to everyone who's scanning
* unless he is cloaked.
+ * The 'draw' flag when false, causes the 'saved under' character to
+ * be drawn instead of the player; effectively un-drawing the player.
*/
void
drawplayer(pp, draw)
@@ -293,34 +261,54 @@ drawplayer(pp, draw)
x = pp->p_x;
y = pp->p_y;
+
+ /* Draw or un-draw the player into the master map: */
Maze[y][x] = draw ? pp->p_face : pp->p_over;
-# ifdef MONITOR
+ /* The monitors can always see this player: */
for (newp = Monitor; newp < End_monitor; newp++)
check(newp, y, x);
-# endif
+ /* Check if other players can see this player: */
for (newp = Player; newp < End_player; newp++) {
- if (!draw || newp == pp) {
+ if (!draw) {
+ /* When un-drawing, show everyone what was under */
+ check(newp, y, x);
+ continue;
+ }
+ if (newp == pp) {
+ /* The player can always see themselves: */
check(newp, y, x);
continue;
}
+ /* Check if the other player just run out of scans */
if (newp->p_scan == 0) {
+ /* The other player is no longer scanning: */
newp->p_scan--;
showstat(newp);
- }
- else if (newp->p_scan > 0) {
+ /* Check if the other play is scannning */
+ } else if (newp->p_scan > 0) {
+ /* If this player's not cloacked, draw him: */
if (pp->p_cloak < 0)
check(newp, y, x);
+ /* And this uses up a scan. */
newp->p_scan--;
}
}
- if (!draw || pp->p_cloak < 0)
- return;
- if (pp->p_cloak-- == 0)
- showstat(pp);
+
+ /* Use up one point of cloak time when drawing: */
+ if (draw && pp->p_cloak >= 0) {
+ pp->p_cloak--;
+ /* Check if we ran out of cloak: */
+ if (pp->p_cloak < 0)
+ showstat(pp);
+ }
}
+/*
+ * message:
+ * Write a message at the bottom of the screen.
+ */
void
message(pp, s)
PLAYER *pp;
@@ -333,10 +321,10 @@ message(pp, s)
/*
* translate:
- * Turn a character into the right direction character if we are
- * looking at the current player.
+ * Turn a player character into a more personal player character.
+ * ie: {,},!,i becomes <,>,v,^
*/
-char
+static char
translate(ch)
char ch;
{
@@ -355,9 +343,12 @@ translate(ch)
/*
* player_sym:
- * Return the player symbol
+ * Return the symbol for the player at (y,x) when viewed by player 'pp'.
+ * ie: - unteamed players appear as {,},!,i
+ * - unteamed monitors see all players as team digits
+ * - teamed players see other players on their team, as a digit
*/
-int
+static int
player_sym(pp, y, x)
PLAYER *pp;
int y, x;
@@ -367,10 +358,8 @@ player_sym(pp, y, x)
npp = play_at(y, x);
if (npp->p_ident->i_team == ' ')
return Maze[y][x];
-#ifdef MONITOR
if (pp->p_ident->i_team == '*')
return npp->p_ident->i_team;
-#endif
if (pp->p_ident->i_team != npp->p_ident->i_team)
return Maze[y][x];
return pp->p_ident->i_team;