1 /*
2  * Code for handling the various special properties of the slime
3  *
4  * slime.c	1.0		(A.I. Design 1.42)	1/17/85
5  */
6 
7 #include	"rogue.h"
8 #include	"curses.h"
9 
10 /*
11  * Slime_split:
12  *	Called when it has been decided that A slime should divide itself
13  */
14 
15 static coord slimy;
16 
17 slime_split(tp)
18 THING *tp;
19 {
20 	register THING *nslime;
21 
22 	if (new_slime(tp) == 0 || (nslime = new_item()) == NULL)
23 		return;
24 	msg("The slime divides.  Ick!");
25 	new_monster(nslime, 'S', &slimy);
26 	if (cansee(slimy.y, slimy.x)) {
27 		nslime->t_oldch = chat(slimy.y, slimy.x);
28 		mvaddch(slimy.y, slimy.x, 'S');
29 	}
30 	start_run(&slimy);
31 }
32 
33 new_slime(tp)
34 THING *tp;
35 {
36 	register int y, x, ty, tx, ret;
37 	THING *ntp;
38 	coord sp;
39 
40 	ret = 0;
41 	tp->t_flags |= ISFLY;
42 	if (plop_monster((ty = tp->t_pos.y), (tx = tp->t_pos.x), &sp) == 0) {
43 		/*
44 		 * There were no open spaces next to this slime, look for other
45 		 * slimes that might have open spaces next to them.
46 		 */
47 		for (y = ty -1; y <= ty+1; y++)
48 			for (x = tx-1; x <= tx+1; x++)
49 				if (winat(y, x) == 'S' && (ntp = moat(y, x))) {
50 					if (ntp->t_flags & ISFLY)
51 						continue;				/* Already done this one */
52 					if (new_slime(ntp)) {
53 						y = ty+2;
54 						x = tx +2;
55 					}
56 				}
57 	} else {
58 		ret = 1;
59 		slimy = sp;
60 	}
61 	tp->t_flags &= ~ISFLY;
62 	return ret;
63 }
64 
65 plop_monster(r, c, cp)
66 int r, c;
67 coord *cp;
68 {
69 	register int y, x;
70 	bool appear = 0;
71 	byte ch;
72 
73 	for (y = r-1; y <= r+1; y++)
74 		for (x = c-1; x <= c+1; x++) {
75 			/*
76 			 * Don't put a monster in top of the player.
77 			 */
78 			if ((y == hero.y && x == hero.x) || offmap(y,x))
79 	 			continue;
80 			/*
81 			 * Or anything else nasty
82 			 */
83 			if (step_ok(ch = winat(y, x))) {
84 				if (ch == SCROLL && find_obj(y, x)->o_which == S_SCARE)
85 					continue;
86 				if (rnd(++appear) == 0) {
87 					cp->y = y;
88 					cp->x = x;
89 				}
90 			}
91 		}
92 	return appear;
93 }
94 