Home | History | Annotate | Line # | Download | only in huntd
draw.c revision 1.1.1.2
      1      1.1  mrg /*
      2  1.1.1.2  wiz  * Copyright (c) 1983-2003, Regents of the University of California.
      3  1.1.1.2  wiz  * All rights reserved.
      4  1.1.1.2  wiz  *
      5  1.1.1.2  wiz  * Redistribution and use in source and binary forms, with or without
      6  1.1.1.2  wiz  * modification, are permitted provided that the following conditions are
      7  1.1.1.2  wiz  * met:
      8  1.1.1.2  wiz  *
      9  1.1.1.2  wiz  * + Redistributions of source code must retain the above copyright
     10  1.1.1.2  wiz  *   notice, this list of conditions and the following disclaimer.
     11  1.1.1.2  wiz  * + Redistributions in binary form must reproduce the above copyright
     12  1.1.1.2  wiz  *   notice, this list of conditions and the following disclaimer in the
     13  1.1.1.2  wiz  *   documentation and/or other materials provided with the distribution.
     14  1.1.1.2  wiz  * + Neither the name of the University of California, San Francisco nor
     15  1.1.1.2  wiz  *   the names of its contributors may be used to endorse or promote
     16  1.1.1.2  wiz  *   products derived from this software without specific prior written
     17  1.1.1.2  wiz  *   permission.
     18  1.1.1.2  wiz  *
     19  1.1.1.2  wiz  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     20  1.1.1.2  wiz  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1.1.2  wiz  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     22  1.1.1.2  wiz  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     23  1.1.1.2  wiz  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     24  1.1.1.2  wiz  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     25  1.1.1.2  wiz  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1.1.2  wiz  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1.1.2  wiz  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1.1.2  wiz  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     29  1.1.1.2  wiz  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30      1.1  mrg  */
     31      1.1  mrg 
     32      1.1  mrg # include	"hunt.h"
     33      1.1  mrg 
     34      1.1  mrg drawmaze(pp)
     35      1.1  mrg register PLAYER	*pp;
     36      1.1  mrg {
     37      1.1  mrg 	register int	x;
     38      1.1  mrg 	register char	*sp;
     39      1.1  mrg 	register int	y;
     40      1.1  mrg 	register char	*endp;
     41      1.1  mrg 
     42      1.1  mrg 	clrscr(pp);
     43      1.1  mrg 	outstr(pp, pp->p_maze[0], WIDTH);
     44      1.1  mrg 	for (y = 1; y < HEIGHT - 1; y++) {
     45      1.1  mrg 		endp = &pp->p_maze[y][WIDTH];
     46      1.1  mrg 		for (x = 0, sp = pp->p_maze[y]; sp < endp; x++, sp++)
     47      1.1  mrg 			if (*sp != SPACE) {
     48      1.1  mrg 				cgoto(pp, y, x);
     49      1.1  mrg 				if (pp->p_x == x && pp->p_y == y)
     50      1.1  mrg 					outch(pp, translate(*sp));
     51      1.1  mrg 				else if (isplayer(*sp))
     52      1.1  mrg 					outch(pp, player_sym(pp, y, x));
     53      1.1  mrg 				else
     54      1.1  mrg 					outch(pp, *sp);
     55      1.1  mrg 			}
     56      1.1  mrg 	}
     57      1.1  mrg 	cgoto(pp, HEIGHT - 1, 0);
     58      1.1  mrg 	outstr(pp, pp->p_maze[HEIGHT - 1], WIDTH);
     59      1.1  mrg 	drawstatus(pp);
     60      1.1  mrg }
     61      1.1  mrg 
     62      1.1  mrg /*
     63      1.1  mrg  * drawstatus - put up the status lines (this assumes the screen
     64      1.1  mrg  *		size is 80x24 with the maze being 64x24)
     65      1.1  mrg  */
     66      1.1  mrg drawstatus(pp)
     67      1.1  mrg register PLAYER	*pp;
     68      1.1  mrg {
     69      1.1  mrg 	register int	i;
     70      1.1  mrg 	register PLAYER	*np;
     71      1.1  mrg 
     72      1.1  mrg 	cgoto(pp, STAT_AMMO_ROW, STAT_LABEL_COL);
     73      1.1  mrg 	outstr(pp, "Ammo:", 5);
     74      1.1  mrg 	(void) sprintf(Buf, "%3d", pp->p_ammo);
     75      1.1  mrg 	cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
     76      1.1  mrg 	outstr(pp, Buf, 3);
     77      1.1  mrg 
     78      1.1  mrg 	cgoto(pp, STAT_GUN_ROW, STAT_LABEL_COL);
     79      1.1  mrg 	outstr(pp, "Gun:", 4);
     80      1.1  mrg 	cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
     81      1.1  mrg 	outstr(pp, (pp->p_ncshot < MAXNCSHOT) ? " ok" : "   ", 3);
     82      1.1  mrg 
     83      1.1  mrg 	cgoto(pp, STAT_DAM_ROW, STAT_LABEL_COL);
     84      1.1  mrg 	outstr(pp, "Damage:", 7);
     85      1.1  mrg 	(void) sprintf(Buf, "%2d/%2d", pp->p_damage, pp->p_damcap);
     86      1.1  mrg 	cgoto(pp, STAT_DAM_ROW, STAT_VALUE_COL);
     87      1.1  mrg 	outstr(pp, Buf, 5);
     88      1.1  mrg 
     89      1.1  mrg 	cgoto(pp, STAT_KILL_ROW, STAT_LABEL_COL);
     90      1.1  mrg 	outstr(pp, "Kills:", 6);
     91      1.1  mrg 	(void) sprintf(Buf, "%3d", (pp->p_damcap - MAXDAM) / 2);
     92      1.1  mrg 	cgoto(pp, STAT_KILL_ROW, STAT_VALUE_COL);
     93      1.1  mrg 	outstr(pp, Buf, 3);
     94      1.1  mrg 
     95      1.1  mrg 	cgoto(pp, STAT_PLAY_ROW, STAT_LABEL_COL);
     96      1.1  mrg 	outstr(pp, "Player:", 7);
     97      1.1  mrg 	for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++) {
     98      1.1  mrg 		(void) sprintf(Buf, "%5.2f%c%-10.10s %c", np->p_ident->i_score,
     99      1.1  mrg 			stat_char(np), np->p_ident->i_name,
    100      1.1  mrg 			np->p_ident->i_team);
    101      1.1  mrg 		cgoto(pp, i++, STAT_NAME_COL);
    102      1.1  mrg 		outstr(pp, Buf, STAT_NAME_LEN);
    103      1.1  mrg 	}
    104      1.1  mrg 
    105      1.1  mrg # ifdef MONITOR
    106      1.1  mrg 	cgoto(pp, STAT_MON_ROW, STAT_LABEL_COL);
    107      1.1  mrg 	outstr(pp, "Monitor:", 8);
    108      1.1  mrg 	for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++) {
    109      1.1  mrg 		(void) sprintf(Buf, "%5.5s %-10.10s %c", " ",
    110      1.1  mrg 			np->p_ident->i_name, np->p_ident->i_team);
    111      1.1  mrg 		cgoto(pp, i++, STAT_NAME_COL);
    112      1.1  mrg 		outstr(pp, Buf, STAT_NAME_LEN);
    113      1.1  mrg 	}
    114      1.1  mrg # endif
    115      1.1  mrg }
    116      1.1  mrg 
    117      1.1  mrg look(pp)
    118      1.1  mrg register PLAYER	*pp;
    119      1.1  mrg {
    120      1.1  mrg 	register int	x, y;
    121      1.1  mrg 
    122      1.1  mrg 	x = pp->p_x;
    123      1.1  mrg 	y = pp->p_y;
    124      1.1  mrg 
    125      1.1  mrg 	check(pp, y - 1, x - 1);
    126      1.1  mrg 	check(pp, y - 1, x    );
    127      1.1  mrg 	check(pp, y - 1, x + 1);
    128      1.1  mrg 	check(pp, y    , x - 1);
    129      1.1  mrg 	check(pp, y    , x    );
    130      1.1  mrg 	check(pp, y    , x + 1);
    131      1.1  mrg 	check(pp, y + 1, x - 1);
    132      1.1  mrg 	check(pp, y + 1, x    );
    133      1.1  mrg 	check(pp, y + 1, x + 1);
    134      1.1  mrg 
    135      1.1  mrg 	switch (pp->p_face) {
    136      1.1  mrg 	  case LEFTS:
    137      1.1  mrg 		see(pp, LEFTS);
    138      1.1  mrg 		see(pp, ABOVE);
    139      1.1  mrg 		see(pp, BELOW);
    140      1.1  mrg 		break;
    141      1.1  mrg 	  case RIGHT:
    142      1.1  mrg 		see(pp, RIGHT);
    143      1.1  mrg 		see(pp, ABOVE);
    144      1.1  mrg 		see(pp, BELOW);
    145      1.1  mrg 		break;
    146      1.1  mrg 	  case ABOVE:
    147      1.1  mrg 		see(pp, ABOVE);
    148      1.1  mrg 		see(pp, LEFTS);
    149      1.1  mrg 		see(pp, RIGHT);
    150      1.1  mrg 		break;
    151      1.1  mrg 	  case BELOW:
    152      1.1  mrg 		see(pp, BELOW);
    153      1.1  mrg 		see(pp, LEFTS);
    154      1.1  mrg 		see(pp, RIGHT);
    155      1.1  mrg 		break;
    156      1.1  mrg # ifdef FLY
    157      1.1  mrg 	  case FLYER:
    158      1.1  mrg 		break;
    159      1.1  mrg # endif
    160      1.1  mrg 	}
    161      1.1  mrg 	cgoto(pp, y, x);
    162      1.1  mrg }
    163      1.1  mrg 
    164      1.1  mrg see(pp, face)
    165      1.1  mrg register PLAYER	*pp;
    166      1.1  mrg int		face;
    167      1.1  mrg {
    168      1.1  mrg 	register char	*sp;
    169      1.1  mrg 	register int	y, x, i, cnt;
    170      1.1  mrg 
    171      1.1  mrg 	x = pp->p_x;
    172      1.1  mrg 	y = pp->p_y;
    173      1.1  mrg 
    174      1.1  mrg 	switch (face) {
    175      1.1  mrg 	  case LEFTS:
    176      1.1  mrg 		sp = &Maze[y][x];
    177      1.1  mrg 		for (i = 0; See_over[*--sp]; i++)
    178      1.1  mrg 			continue;
    179      1.1  mrg 
    180      1.1  mrg 		if (i == 0)
    181      1.1  mrg 			break;
    182      1.1  mrg 
    183      1.1  mrg 		cnt = i;
    184      1.1  mrg 		x = pp->p_x - 1;
    185      1.1  mrg 		--y;
    186      1.1  mrg 		while (i--)
    187      1.1  mrg 			check(pp, y, --x);
    188      1.1  mrg 		i = cnt;
    189      1.1  mrg 		x = pp->p_x - 1;
    190      1.1  mrg 		++y;
    191      1.1  mrg 		while (i--)
    192      1.1  mrg 			check(pp, y, --x);
    193      1.1  mrg 		i = cnt;
    194      1.1  mrg 		x = pp->p_x - 1;
    195      1.1  mrg 		++y;
    196      1.1  mrg 		while (i--)
    197      1.1  mrg 			check(pp, y, --x);
    198      1.1  mrg 		break;
    199      1.1  mrg 	  case RIGHT:
    200      1.1  mrg 		sp = &Maze[y][++x];
    201      1.1  mrg 		for (i = 0; See_over[*sp++]; i++)
    202      1.1  mrg 			continue;
    203      1.1  mrg 
    204      1.1  mrg 		if (i == 0)
    205      1.1  mrg 			break;
    206      1.1  mrg 
    207      1.1  mrg 		cnt = i;
    208      1.1  mrg 		x = pp->p_x + 1;
    209      1.1  mrg 		--y;
    210      1.1  mrg 		while (i--)
    211      1.1  mrg 			check(pp, y, ++x);
    212      1.1  mrg 		i = cnt;
    213      1.1  mrg 		x = pp->p_x + 1;
    214      1.1  mrg 		++y;
    215      1.1  mrg 		while (i--)
    216      1.1  mrg 			check(pp, y, ++x);
    217      1.1  mrg 		i = cnt;
    218      1.1  mrg 		x = pp->p_x + 1;
    219      1.1  mrg 		++y;
    220      1.1  mrg 		while (i--)
    221      1.1  mrg 			check(pp, y, ++x);
    222      1.1  mrg 		break;
    223      1.1  mrg 	  case ABOVE:
    224      1.1  mrg 		sp = &Maze[--y][x];
    225      1.1  mrg 		if (!See_over[*sp])
    226      1.1  mrg 			break;
    227      1.1  mrg 		do {
    228      1.1  mrg 			--y;
    229      1.1  mrg 			sp -= sizeof Maze[0];
    230      1.1  mrg 			check(pp, y, x - 1);
    231      1.1  mrg 			check(pp, y, x    );
    232      1.1  mrg 			check(pp, y, x + 1);
    233      1.1  mrg 		} while (See_over[*sp]);
    234      1.1  mrg 		break;
    235      1.1  mrg 	  case BELOW:
    236      1.1  mrg 		sp = &Maze[++y][x];
    237      1.1  mrg 		if (!See_over[*sp])
    238      1.1  mrg 			break;
    239      1.1  mrg 		do {
    240      1.1  mrg 			y++;
    241      1.1  mrg 			sp += sizeof Maze[0];
    242      1.1  mrg 			check(pp, y, x - 1);
    243      1.1  mrg 			check(pp, y, x    );
    244      1.1  mrg 			check(pp, y, x + 1);
    245      1.1  mrg 		} while (See_over[*sp]);
    246      1.1  mrg 		break;
    247      1.1  mrg 	}
    248      1.1  mrg }
    249      1.1  mrg 
    250      1.1  mrg check(pp, y, x)
    251      1.1  mrg PLAYER	*pp;
    252      1.1  mrg int	y, x;
    253      1.1  mrg {
    254      1.1  mrg 	register int	index;
    255      1.1  mrg 	register int	ch;
    256      1.1  mrg 	register PLAYER	*rpp;
    257      1.1  mrg 
    258      1.1  mrg 	index = y * sizeof Maze[0] + x;
    259      1.1  mrg 	ch = ((char *) Maze)[index];
    260      1.1  mrg 	if (ch != ((char *) pp->p_maze)[index]) {
    261      1.1  mrg 		rpp = pp;
    262      1.1  mrg 		cgoto(rpp, y, x);
    263      1.1  mrg 		if (x == rpp->p_x && y == rpp->p_y)
    264      1.1  mrg 			outch(rpp, translate(ch));
    265      1.1  mrg 		else if (isplayer(ch))
    266      1.1  mrg 			outch(rpp, player_sym(rpp, y, x));
    267      1.1  mrg 		else
    268      1.1  mrg 			outch(rpp, ch);
    269      1.1  mrg 		((char *) rpp->p_maze)[index] = ch;
    270      1.1  mrg 	}
    271      1.1  mrg }
    272      1.1  mrg 
    273      1.1  mrg /*
    274      1.1  mrg  * showstat
    275      1.1  mrg  *	Update the status of players
    276      1.1  mrg  */
    277      1.1  mrg showstat(pp)
    278      1.1  mrg register PLAYER	*pp;
    279      1.1  mrg {
    280      1.1  mrg 	register PLAYER	*np;
    281      1.1  mrg 	register int	y;
    282      1.1  mrg 	register char	c;
    283      1.1  mrg 
    284      1.1  mrg 	y = STAT_PLAY_ROW + 1 + (pp - Player);
    285      1.1  mrg 	c = stat_char(pp);
    286      1.1  mrg # ifdef MONITOR
    287      1.1  mrg 	for (np = Monitor; np < End_monitor; np++) {
    288      1.1  mrg 		cgoto(np, y, STAT_SCAN_COL);
    289      1.1  mrg 		outch(np, c);
    290      1.1  mrg 	}
    291      1.1  mrg # endif
    292      1.1  mrg 	for (np = Player; np < End_player; np++) {
    293      1.1  mrg 		cgoto(np, y, STAT_SCAN_COL);
    294      1.1  mrg 		outch(np, c);
    295      1.1  mrg 	}
    296      1.1  mrg }
    297      1.1  mrg 
    298      1.1  mrg /*
    299      1.1  mrg  * drawplayer:
    300      1.1  mrg  *	Draw the player on the screen and show him to everyone who's scanning
    301      1.1  mrg  *	unless he is cloaked.
    302      1.1  mrg  */
    303      1.1  mrg drawplayer(pp, draw)
    304      1.1  mrg PLAYER	*pp;
    305      1.1  mrg FLAG	draw;
    306      1.1  mrg {
    307      1.1  mrg 	register PLAYER	*newp;
    308      1.1  mrg 	register int	x, y;
    309      1.1  mrg 
    310      1.1  mrg 	x = pp->p_x;
    311      1.1  mrg 	y = pp->p_y;
    312      1.1  mrg 	Maze[y][x] = draw ? pp->p_face : pp->p_over;
    313      1.1  mrg 
    314      1.1  mrg # ifdef MONITOR
    315      1.1  mrg 	for (newp = Monitor; newp < End_monitor; newp++)
    316      1.1  mrg 		check(newp, y, x);
    317      1.1  mrg # endif
    318      1.1  mrg 
    319      1.1  mrg 	for (newp = Player; newp < End_player; newp++) {
    320      1.1  mrg 		if (!draw || newp == pp) {
    321      1.1  mrg 			check(newp, y, x);
    322      1.1  mrg 			continue;
    323      1.1  mrg 		}
    324      1.1  mrg 		if (newp->p_scan == 0) {
    325      1.1  mrg 			newp->p_scan--;
    326      1.1  mrg 			showstat(newp);
    327      1.1  mrg 		}
    328      1.1  mrg 		else if (newp->p_scan > 0) {
    329      1.1  mrg 			if (pp->p_cloak < 0)
    330      1.1  mrg 				check(newp, y, x);
    331      1.1  mrg 			newp->p_scan--;
    332      1.1  mrg 		}
    333      1.1  mrg 	}
    334      1.1  mrg 	if (!draw || pp->p_cloak < 0)
    335      1.1  mrg 		return;
    336      1.1  mrg 	if (pp->p_cloak-- == 0)
    337      1.1  mrg 		showstat(pp);
    338      1.1  mrg }
    339      1.1  mrg 
    340      1.1  mrg message(pp, s)
    341      1.1  mrg register PLAYER	*pp;
    342      1.1  mrg char		*s;
    343      1.1  mrg {
    344      1.1  mrg 	cgoto(pp, HEIGHT, 0);
    345      1.1  mrg 	outstr(pp, s, strlen(s));
    346      1.1  mrg 	ce(pp);
    347      1.1  mrg }
    348      1.1  mrg 
    349      1.1  mrg /*
    350      1.1  mrg  * translate:
    351      1.1  mrg  *	Turn a character into the right direction character if we are
    352      1.1  mrg  *	looking at the current player.
    353      1.1  mrg  */
    354      1.1  mrg translate(ch)
    355      1.1  mrg char	ch;
    356      1.1  mrg {
    357      1.1  mrg 	switch (ch) {
    358      1.1  mrg 	  case LEFTS:
    359      1.1  mrg 		return '<';
    360      1.1  mrg 	  case RIGHT:
    361      1.1  mrg 		return '>';
    362      1.1  mrg 	  case ABOVE:
    363      1.1  mrg 		return '^';
    364      1.1  mrg 	  case BELOW:
    365      1.1  mrg 		return 'v';
    366      1.1  mrg 	}
    367      1.1  mrg 	return ch;
    368      1.1  mrg }
    369      1.1  mrg 
    370      1.1  mrg /*
    371      1.1  mrg  * player_sym:
    372      1.1  mrg  *	Return the player symbol
    373      1.1  mrg  */
    374      1.1  mrg player_sym(pp, y, x)
    375      1.1  mrg PLAYER	*pp;
    376      1.1  mrg int	y, x;
    377      1.1  mrg {
    378      1.1  mrg 	register PLAYER	*npp;
    379      1.1  mrg 
    380      1.1  mrg 	npp = play_at(y, x);
    381      1.1  mrg 	if (npp->p_ident->i_team == ' ')
    382      1.1  mrg 		return Maze[y][x];
    383      1.1  mrg #ifdef MONITOR
    384      1.1  mrg 	if (pp->p_ident->i_team == '*')
    385      1.1  mrg 		return npp->p_ident->i_team;
    386      1.1  mrg #endif
    387      1.1  mrg 	if (pp->p_ident->i_team != npp->p_ident->i_team)
    388      1.1  mrg 		return Maze[y][x];
    389      1.1  mrg 	return pp->p_ident->i_team;
    390      1.1  mrg }
    391