Home | History | Annotate | Line # | Download | only in huntd
draw.c revision 1.2
      1  1.2  lukem /*	$NetBSD: draw.c,v 1.2 1997/10/10 16:33:04 lukem Exp $	*/
      2  1.1    mrg /*
      3  1.1    mrg  *  Hunt
      4  1.1    mrg  *  Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
      5  1.1    mrg  *  San Francisco, California
      6  1.1    mrg  */
      7  1.1    mrg 
      8  1.2  lukem #include <sys/cdefs.h>
      9  1.2  lukem #ifndef lint
     10  1.2  lukem __RCSID("$NetBSD: draw.c,v 1.2 1997/10/10 16:33:04 lukem Exp $");
     11  1.2  lukem #endif /* not lint */
     12  1.2  lukem 
     13  1.1    mrg # include	"hunt.h"
     14  1.1    mrg 
     15  1.2  lukem void
     16  1.1    mrg drawmaze(pp)
     17  1.2  lukem 	PLAYER	*pp;
     18  1.1    mrg {
     19  1.2  lukem 	int	x;
     20  1.2  lukem 	char	*sp;
     21  1.2  lukem 	int	y;
     22  1.2  lukem 	char	*endp;
     23  1.1    mrg 
     24  1.1    mrg 	clrscr(pp);
     25  1.1    mrg 	outstr(pp, pp->p_maze[0], WIDTH);
     26  1.1    mrg 	for (y = 1; y < HEIGHT - 1; y++) {
     27  1.1    mrg 		endp = &pp->p_maze[y][WIDTH];
     28  1.1    mrg 		for (x = 0, sp = pp->p_maze[y]; sp < endp; x++, sp++)
     29  1.1    mrg 			if (*sp != SPACE) {
     30  1.1    mrg 				cgoto(pp, y, x);
     31  1.1    mrg 				if (pp->p_x == x && pp->p_y == y)
     32  1.1    mrg 					outch(pp, translate(*sp));
     33  1.1    mrg 				else if (isplayer(*sp))
     34  1.1    mrg 					outch(pp, player_sym(pp, y, x));
     35  1.1    mrg 				else
     36  1.1    mrg 					outch(pp, *sp);
     37  1.1    mrg 			}
     38  1.1    mrg 	}
     39  1.1    mrg 	cgoto(pp, HEIGHT - 1, 0);
     40  1.1    mrg 	outstr(pp, pp->p_maze[HEIGHT - 1], WIDTH);
     41  1.1    mrg 	drawstatus(pp);
     42  1.1    mrg }
     43  1.1    mrg 
     44  1.1    mrg /*
     45  1.1    mrg  * drawstatus - put up the status lines (this assumes the screen
     46  1.1    mrg  *		size is 80x24 with the maze being 64x24)
     47  1.1    mrg  */
     48  1.2  lukem void
     49  1.1    mrg drawstatus(pp)
     50  1.2  lukem 	PLAYER	*pp;
     51  1.1    mrg {
     52  1.2  lukem 	int	i;
     53  1.2  lukem 	PLAYER	*np;
     54  1.1    mrg 
     55  1.1    mrg 	cgoto(pp, STAT_AMMO_ROW, STAT_LABEL_COL);
     56  1.1    mrg 	outstr(pp, "Ammo:", 5);
     57  1.1    mrg 	(void) sprintf(Buf, "%3d", pp->p_ammo);
     58  1.1    mrg 	cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
     59  1.1    mrg 	outstr(pp, Buf, 3);
     60  1.1    mrg 
     61  1.1    mrg 	cgoto(pp, STAT_GUN_ROW, STAT_LABEL_COL);
     62  1.1    mrg 	outstr(pp, "Gun:", 4);
     63  1.1    mrg 	cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
     64  1.1    mrg 	outstr(pp, (pp->p_ncshot < MAXNCSHOT) ? " ok" : "   ", 3);
     65  1.1    mrg 
     66  1.1    mrg 	cgoto(pp, STAT_DAM_ROW, STAT_LABEL_COL);
     67  1.1    mrg 	outstr(pp, "Damage:", 7);
     68  1.1    mrg 	(void) sprintf(Buf, "%2d/%2d", pp->p_damage, pp->p_damcap);
     69  1.1    mrg 	cgoto(pp, STAT_DAM_ROW, STAT_VALUE_COL);
     70  1.1    mrg 	outstr(pp, Buf, 5);
     71  1.1    mrg 
     72  1.1    mrg 	cgoto(pp, STAT_KILL_ROW, STAT_LABEL_COL);
     73  1.1    mrg 	outstr(pp, "Kills:", 6);
     74  1.1    mrg 	(void) sprintf(Buf, "%3d", (pp->p_damcap - MAXDAM) / 2);
     75  1.1    mrg 	cgoto(pp, STAT_KILL_ROW, STAT_VALUE_COL);
     76  1.1    mrg 	outstr(pp, Buf, 3);
     77  1.1    mrg 
     78  1.1    mrg 	cgoto(pp, STAT_PLAY_ROW, STAT_LABEL_COL);
     79  1.1    mrg 	outstr(pp, "Player:", 7);
     80  1.1    mrg 	for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++) {
     81  1.1    mrg 		(void) sprintf(Buf, "%5.2f%c%-10.10s %c", np->p_ident->i_score,
     82  1.1    mrg 			stat_char(np), np->p_ident->i_name,
     83  1.1    mrg 			np->p_ident->i_team);
     84  1.1    mrg 		cgoto(pp, i++, STAT_NAME_COL);
     85  1.1    mrg 		outstr(pp, Buf, STAT_NAME_LEN);
     86  1.1    mrg 	}
     87  1.1    mrg 
     88  1.1    mrg # ifdef MONITOR
     89  1.1    mrg 	cgoto(pp, STAT_MON_ROW, STAT_LABEL_COL);
     90  1.1    mrg 	outstr(pp, "Monitor:", 8);
     91  1.1    mrg 	for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++) {
     92  1.1    mrg 		(void) sprintf(Buf, "%5.5s %-10.10s %c", " ",
     93  1.1    mrg 			np->p_ident->i_name, np->p_ident->i_team);
     94  1.1    mrg 		cgoto(pp, i++, STAT_NAME_COL);
     95  1.1    mrg 		outstr(pp, Buf, STAT_NAME_LEN);
     96  1.1    mrg 	}
     97  1.1    mrg # endif
     98  1.1    mrg }
     99  1.1    mrg 
    100  1.2  lukem void
    101  1.1    mrg look(pp)
    102  1.2  lukem 	PLAYER	*pp;
    103  1.1    mrg {
    104  1.2  lukem 	int	x, y;
    105  1.1    mrg 
    106  1.1    mrg 	x = pp->p_x;
    107  1.1    mrg 	y = pp->p_y;
    108  1.1    mrg 
    109  1.1    mrg 	check(pp, y - 1, x - 1);
    110  1.1    mrg 	check(pp, y - 1, x    );
    111  1.1    mrg 	check(pp, y - 1, x + 1);
    112  1.1    mrg 	check(pp, y    , x - 1);
    113  1.1    mrg 	check(pp, y    , x    );
    114  1.1    mrg 	check(pp, y    , x + 1);
    115  1.1    mrg 	check(pp, y + 1, x - 1);
    116  1.1    mrg 	check(pp, y + 1, x    );
    117  1.1    mrg 	check(pp, y + 1, x + 1);
    118  1.1    mrg 
    119  1.1    mrg 	switch (pp->p_face) {
    120  1.1    mrg 	  case LEFTS:
    121  1.1    mrg 		see(pp, LEFTS);
    122  1.1    mrg 		see(pp, ABOVE);
    123  1.1    mrg 		see(pp, BELOW);
    124  1.1    mrg 		break;
    125  1.1    mrg 	  case RIGHT:
    126  1.1    mrg 		see(pp, RIGHT);
    127  1.1    mrg 		see(pp, ABOVE);
    128  1.1    mrg 		see(pp, BELOW);
    129  1.1    mrg 		break;
    130  1.1    mrg 	  case ABOVE:
    131  1.1    mrg 		see(pp, ABOVE);
    132  1.1    mrg 		see(pp, LEFTS);
    133  1.1    mrg 		see(pp, RIGHT);
    134  1.1    mrg 		break;
    135  1.1    mrg 	  case BELOW:
    136  1.1    mrg 		see(pp, BELOW);
    137  1.1    mrg 		see(pp, LEFTS);
    138  1.1    mrg 		see(pp, RIGHT);
    139  1.1    mrg 		break;
    140  1.1    mrg # ifdef FLY
    141  1.1    mrg 	  case FLYER:
    142  1.1    mrg 		break;
    143  1.1    mrg # endif
    144  1.1    mrg 	}
    145  1.1    mrg 	cgoto(pp, y, x);
    146  1.1    mrg }
    147  1.1    mrg 
    148  1.2  lukem void
    149  1.1    mrg see(pp, face)
    150  1.2  lukem 	PLAYER	*pp;
    151  1.2  lukem 	int	face;
    152  1.1    mrg {
    153  1.2  lukem 	char	*sp;
    154  1.2  lukem 	int	y, x, i, cnt;
    155  1.1    mrg 
    156  1.1    mrg 	x = pp->p_x;
    157  1.1    mrg 	y = pp->p_y;
    158  1.1    mrg 
    159  1.1    mrg 	switch (face) {
    160  1.1    mrg 	  case LEFTS:
    161  1.1    mrg 		sp = &Maze[y][x];
    162  1.2  lukem 		for (i = 0; See_over[(int)*--sp]; i++)
    163  1.1    mrg 			continue;
    164  1.1    mrg 
    165  1.1    mrg 		if (i == 0)
    166  1.1    mrg 			break;
    167  1.1    mrg 
    168  1.1    mrg 		cnt = i;
    169  1.1    mrg 		x = pp->p_x - 1;
    170  1.1    mrg 		--y;
    171  1.1    mrg 		while (i--)
    172  1.1    mrg 			check(pp, y, --x);
    173  1.1    mrg 		i = cnt;
    174  1.1    mrg 		x = pp->p_x - 1;
    175  1.1    mrg 		++y;
    176  1.1    mrg 		while (i--)
    177  1.1    mrg 			check(pp, y, --x);
    178  1.1    mrg 		i = cnt;
    179  1.1    mrg 		x = pp->p_x - 1;
    180  1.1    mrg 		++y;
    181  1.1    mrg 		while (i--)
    182  1.1    mrg 			check(pp, y, --x);
    183  1.1    mrg 		break;
    184  1.1    mrg 	  case RIGHT:
    185  1.1    mrg 		sp = &Maze[y][++x];
    186  1.2  lukem 		for (i = 0; See_over[(int)*sp++]; i++)
    187  1.1    mrg 			continue;
    188  1.1    mrg 
    189  1.1    mrg 		if (i == 0)
    190  1.1    mrg 			break;
    191  1.1    mrg 
    192  1.1    mrg 		cnt = i;
    193  1.1    mrg 		x = pp->p_x + 1;
    194  1.1    mrg 		--y;
    195  1.1    mrg 		while (i--)
    196  1.1    mrg 			check(pp, y, ++x);
    197  1.1    mrg 		i = cnt;
    198  1.1    mrg 		x = pp->p_x + 1;
    199  1.1    mrg 		++y;
    200  1.1    mrg 		while (i--)
    201  1.1    mrg 			check(pp, y, ++x);
    202  1.1    mrg 		i = cnt;
    203  1.1    mrg 		x = pp->p_x + 1;
    204  1.1    mrg 		++y;
    205  1.1    mrg 		while (i--)
    206  1.1    mrg 			check(pp, y, ++x);
    207  1.1    mrg 		break;
    208  1.1    mrg 	  case ABOVE:
    209  1.1    mrg 		sp = &Maze[--y][x];
    210  1.2  lukem 		if (!See_over[(int)*sp])
    211  1.1    mrg 			break;
    212  1.1    mrg 		do {
    213  1.1    mrg 			--y;
    214  1.1    mrg 			sp -= sizeof Maze[0];
    215  1.1    mrg 			check(pp, y, x - 1);
    216  1.1    mrg 			check(pp, y, x    );
    217  1.1    mrg 			check(pp, y, x + 1);
    218  1.2  lukem 		} while (See_over[(int)*sp]);
    219  1.1    mrg 		break;
    220  1.1    mrg 	  case BELOW:
    221  1.1    mrg 		sp = &Maze[++y][x];
    222  1.2  lukem 		if (!See_over[(int)*sp])
    223  1.1    mrg 			break;
    224  1.1    mrg 		do {
    225  1.1    mrg 			y++;
    226  1.1    mrg 			sp += sizeof Maze[0];
    227  1.1    mrg 			check(pp, y, x - 1);
    228  1.1    mrg 			check(pp, y, x    );
    229  1.1    mrg 			check(pp, y, x + 1);
    230  1.2  lukem 		} while (See_over[(int)*sp]);
    231  1.1    mrg 		break;
    232  1.1    mrg 	}
    233  1.1    mrg }
    234  1.1    mrg 
    235  1.2  lukem void
    236  1.1    mrg check(pp, y, x)
    237  1.2  lukem 	PLAYER	*pp;
    238  1.2  lukem 	int	y, x;
    239  1.1    mrg {
    240  1.2  lukem 	int	index;
    241  1.2  lukem 	int	ch;
    242  1.2  lukem 	PLAYER	*rpp;
    243  1.1    mrg 
    244  1.1    mrg 	index = y * sizeof Maze[0] + x;
    245  1.1    mrg 	ch = ((char *) Maze)[index];
    246  1.1    mrg 	if (ch != ((char *) pp->p_maze)[index]) {
    247  1.1    mrg 		rpp = pp;
    248  1.1    mrg 		cgoto(rpp, y, x);
    249  1.1    mrg 		if (x == rpp->p_x && y == rpp->p_y)
    250  1.1    mrg 			outch(rpp, translate(ch));
    251  1.1    mrg 		else if (isplayer(ch))
    252  1.1    mrg 			outch(rpp, player_sym(rpp, y, x));
    253  1.1    mrg 		else
    254  1.1    mrg 			outch(rpp, ch);
    255  1.1    mrg 		((char *) rpp->p_maze)[index] = ch;
    256  1.1    mrg 	}
    257  1.1    mrg }
    258  1.1    mrg 
    259  1.1    mrg /*
    260  1.1    mrg  * showstat
    261  1.1    mrg  *	Update the status of players
    262  1.1    mrg  */
    263  1.2  lukem void
    264  1.1    mrg showstat(pp)
    265  1.2  lukem 	PLAYER	*pp;
    266  1.1    mrg {
    267  1.2  lukem 	PLAYER	*np;
    268  1.2  lukem 	int	y;
    269  1.2  lukem 	char	c;
    270  1.1    mrg 
    271  1.1    mrg 	y = STAT_PLAY_ROW + 1 + (pp - Player);
    272  1.1    mrg 	c = stat_char(pp);
    273  1.1    mrg # ifdef MONITOR
    274  1.1    mrg 	for (np = Monitor; np < End_monitor; np++) {
    275  1.1    mrg 		cgoto(np, y, STAT_SCAN_COL);
    276  1.1    mrg 		outch(np, c);
    277  1.1    mrg 	}
    278  1.1    mrg # endif
    279  1.1    mrg 	for (np = Player; np < End_player; np++) {
    280  1.1    mrg 		cgoto(np, y, STAT_SCAN_COL);
    281  1.1    mrg 		outch(np, c);
    282  1.1    mrg 	}
    283  1.1    mrg }
    284  1.1    mrg 
    285  1.1    mrg /*
    286  1.1    mrg  * drawplayer:
    287  1.1    mrg  *	Draw the player on the screen and show him to everyone who's scanning
    288  1.1    mrg  *	unless he is cloaked.
    289  1.1    mrg  */
    290  1.2  lukem void
    291  1.1    mrg drawplayer(pp, draw)
    292  1.2  lukem 	PLAYER	*pp;
    293  1.2  lukem 	FLAG	draw;
    294  1.1    mrg {
    295  1.2  lukem 	PLAYER	*newp;
    296  1.2  lukem 	int	x, y;
    297  1.1    mrg 
    298  1.1    mrg 	x = pp->p_x;
    299  1.1    mrg 	y = pp->p_y;
    300  1.1    mrg 	Maze[y][x] = draw ? pp->p_face : pp->p_over;
    301  1.1    mrg 
    302  1.1    mrg # ifdef MONITOR
    303  1.1    mrg 	for (newp = Monitor; newp < End_monitor; newp++)
    304  1.1    mrg 		check(newp, y, x);
    305  1.1    mrg # endif
    306  1.1    mrg 
    307  1.1    mrg 	for (newp = Player; newp < End_player; newp++) {
    308  1.1    mrg 		if (!draw || newp == pp) {
    309  1.1    mrg 			check(newp, y, x);
    310  1.1    mrg 			continue;
    311  1.1    mrg 		}
    312  1.1    mrg 		if (newp->p_scan == 0) {
    313  1.1    mrg 			newp->p_scan--;
    314  1.1    mrg 			showstat(newp);
    315  1.1    mrg 		}
    316  1.1    mrg 		else if (newp->p_scan > 0) {
    317  1.1    mrg 			if (pp->p_cloak < 0)
    318  1.1    mrg 				check(newp, y, x);
    319  1.1    mrg 			newp->p_scan--;
    320  1.1    mrg 		}
    321  1.1    mrg 	}
    322  1.1    mrg 	if (!draw || pp->p_cloak < 0)
    323  1.1    mrg 		return;
    324  1.1    mrg 	if (pp->p_cloak-- == 0)
    325  1.1    mrg 		showstat(pp);
    326  1.1    mrg }
    327  1.1    mrg 
    328  1.2  lukem void
    329  1.1    mrg message(pp, s)
    330  1.2  lukem 	PLAYER	*pp;
    331  1.2  lukem 	char	*s;
    332  1.1    mrg {
    333  1.1    mrg 	cgoto(pp, HEIGHT, 0);
    334  1.1    mrg 	outstr(pp, s, strlen(s));
    335  1.1    mrg 	ce(pp);
    336  1.1    mrg }
    337  1.1    mrg 
    338  1.1    mrg /*
    339  1.1    mrg  * translate:
    340  1.1    mrg  *	Turn a character into the right direction character if we are
    341  1.1    mrg  *	looking at the current player.
    342  1.1    mrg  */
    343  1.2  lukem char
    344  1.1    mrg translate(ch)
    345  1.2  lukem 	char	ch;
    346  1.1    mrg {
    347  1.1    mrg 	switch (ch) {
    348  1.1    mrg 	  case LEFTS:
    349  1.1    mrg 		return '<';
    350  1.1    mrg 	  case RIGHT:
    351  1.1    mrg 		return '>';
    352  1.1    mrg 	  case ABOVE:
    353  1.1    mrg 		return '^';
    354  1.1    mrg 	  case BELOW:
    355  1.1    mrg 		return 'v';
    356  1.1    mrg 	}
    357  1.1    mrg 	return ch;
    358  1.1    mrg }
    359  1.1    mrg 
    360  1.1    mrg /*
    361  1.1    mrg  * player_sym:
    362  1.1    mrg  *	Return the player symbol
    363  1.1    mrg  */
    364  1.2  lukem int
    365  1.1    mrg player_sym(pp, y, x)
    366  1.2  lukem 	PLAYER	*pp;
    367  1.2  lukem 	int	y, x;
    368  1.1    mrg {
    369  1.2  lukem 	PLAYER	*npp;
    370  1.1    mrg 
    371  1.1    mrg 	npp = play_at(y, x);
    372  1.1    mrg 	if (npp->p_ident->i_team == ' ')
    373  1.1    mrg 		return Maze[y][x];
    374  1.1    mrg #ifdef MONITOR
    375  1.1    mrg 	if (pp->p_ident->i_team == '*')
    376  1.1    mrg 		return npp->p_ident->i_team;
    377  1.1    mrg #endif
    378  1.1    mrg 	if (pp->p_ident->i_team != npp->p_ident->i_team)
    379  1.1    mrg 		return Maze[y][x];
    380  1.1    mrg 	return pp->p_ident->i_team;
    381  1.1    mrg }
    382