xref: /original-bsd/games/robots/make_level.c (revision bec2b583)
1 /*
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)make_level.c	8.1 (Berkeley) 05/31/93";
10 #endif /* not lint */
11 
12 # include	"robots.h"
13 
14 /*
15  * make_level:
16  *	Make the current level
17  */
make_level()18 make_level()
19 {
20 	register int	i;
21 	register COORD	*cp;
22 	register WINDOW	*wp;
23 	register int	x, *endp;
24 
25 	reset_count();
26 	for (i = 1; i < Y_FIELDSIZE; i++)
27 		for (x = 1; x < X_FIELDSIZE; x++)
28 			if (Field[i][x] != 0)
29 				mvaddch(i, x, ' ');
30 	if (My_pos.y > 0)
31 		mvaddch(My_pos.y, My_pos.x, ' ');
32 
33 	Waiting = FALSE;
34 	Wait_bonus = 0;
35 	leaveok(stdscr, FALSE);
36 	for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++)
37 		cp->y = -1;
38 	My_pos.y = -1;
39 
40 	bzero(Field, sizeof Field);
41 	Min.y = Y_FIELDSIZE;
42 	Min.x = X_FIELDSIZE;
43 	Max.y = 0;
44 	Max.x = 0;
45 	if ((i = Level * 10) > MAXROBOTS)
46 		i = MAXROBOTS;
47 	Num_robots = i;
48 	while (i-- > 0) {
49 		cp = rnd_pos();
50 		Robots[i] = *cp;
51 		Field[cp->y][cp->x]++;
52 		if (cp->y < Min.y)
53 			Min.y = cp->y;
54 		if (cp->x < Min.x)
55 			Min.x = cp->x;
56 		if (cp->y > Max.y)
57 			Max.y = cp->y;
58 		if (cp->x > Max.x)
59 			Max.x = cp->x;
60 	}
61 	My_pos = *rnd_pos();
62 	refresh();
63 }
64