xref: /original-bsd/games/robots/make_level.c (revision ad93c43e)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)make_level.c	5.2 (Berkeley) 03/09/88";
15 #endif /* not lint */
16 
17 # include	"robots.h"
18 
19 /*
20  * make_level:
21  *	Make the current level
22  */
23 make_level()
24 {
25 	register int	i;
26 	register COORD	*cp;
27 	register WINDOW	*wp;
28 	register int	x, *endp;
29 
30 	reset_count();
31 	for (i = 1; i < Y_FIELDSIZE; i++)
32 		for (x = 1; x < X_FIELDSIZE; x++)
33 			if (Field[i][x] != 0)
34 				mvaddch(i, x, ' ');
35 	if (My_pos.y > 0)
36 		mvaddch(My_pos.y, My_pos.x, ' ');
37 
38 	Waiting = FALSE;
39 	Wait_bonus = 0;
40 	leaveok(stdscr, FALSE);
41 	for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++)
42 		cp->y = -1;
43 	My_pos.y = -1;
44 
45 	bzero(Field, sizeof Field);
46 	Min.y = Y_FIELDSIZE;
47 	Min.x = X_FIELDSIZE;
48 	Max.y = 0;
49 	Max.x = 0;
50 	if ((i = Level * 10) > MAXROBOTS)
51 		i = MAXROBOTS;
52 	Num_robots = i;
53 	while (i-- > 0) {
54 		cp = rnd_pos();
55 		Robots[i] = *cp;
56 		Field[cp->y][cp->x]++;
57 		if (cp->y < Min.y)
58 			Min.y = cp->y;
59 		if (cp->x < Min.x)
60 			Min.x = cp->x;
61 		if (cp->y > Max.y)
62 			Max.y = cp->y;
63 		if (cp->x > Max.x)
64 			Max.x = cp->x;
65 	}
66 	My_pos = *rnd_pos();
67 	refresh();
68 }
69