]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/movem.c
1 /* $NetBSD: movem.c,v 1.5 1997/10/18 20:03:34 christos Exp $ */
4 * movem.c (move monster) Larn is copyrighted 1986 by Noah Morgan.
6 * Here are the functions in this file:
8 * movemonst() Routine to move the monsters toward the player
9 * movemt(x,y) Function to move a monster at (x,y) -- must determine where
10 * mmove(x,y,xd,yd) Function to actually perform the monster movement
11 * movsphere() Function to look for and move spheres of annihilation
13 #include <sys/cdefs.h>
15 __RCSID("$NetBSD: movem.c,v 1.5 1997/10/18 20:03:34 christos Exp $");
22 * movemonst() Routine to move the monsters toward the player
24 * This routine has the responsibility to determine which monsters are to
25 * move, and call movemt() to do the move.
28 static short w1
[9], w1x
[9], w1y
[9];
29 static int tmp1
, tmp2
, tmp3
, tmp4
, distance
;
35 return; /* no action if time is stopped */
37 if ((c
[HASTESELF
] & 1) == 0)
40 movsphere(); /* move the spheres of annihilation if any */
42 return; /* no action if monsters are held */
44 if (c
[AGGRAVATE
]) { /* determine window of monsters to move */
49 distance
= 40; /* depth of intelligent monster movement */
55 distance
= 17; /* depth of intelligent monster movement */
58 if (level
== 0) { /* if on outside level monsters can move in
68 } else { /* if in a dungeon monsters can't be on the
69 * perimeter (wall there) */
80 for (j
= tmp1
; j
< tmp2
; j
++) /* now reset monster moved flags */
81 for (i
= tmp3
; i
< tmp4
; i
++)
83 moved
[lasthx
][lasthy
] = 0;
85 if (c
[AGGRAVATE
] || !c
[STEALTH
]) { /* who gets moved? split for
87 for (j
= tmp1
; j
< tmp2
; j
++) /* look thru all locations in
89 for (i
= tmp3
; i
< tmp4
; i
++)
90 if (mitem
[i
][j
]) /* if there is a monster
92 if (moved
[i
][j
] == 0) /* if it has not already
94 movemt(i
, j
); /* go and move the
96 } else { /* not aggravated and not stealth */
97 for (j
= tmp1
; j
< tmp2
; j
++) /* look thru all locations in
99 for (i
= tmp3
; i
< tmp4
; i
++)
100 if (mitem
[i
][j
]) /* if there is a monster
102 if (moved
[i
][j
] == 0) /* if it has not already
104 if (stealth
[i
][j
]) /* if it is asleep due
106 movemt(i
, j
); /* go and move the
110 if (mitem
[lasthx
][lasthy
]) { /* now move monster last hit by
111 * player if not already moved */
112 if (moved
[lasthx
][lasthy
] == 0) { /* if it has not already
114 movemt(lasthx
, lasthy
);
122 * movemt(x,y) Function to move a monster at (x,y) -- must determine where
125 * This routine is responsible for determining where one monster at (x,y) will
126 * move to. Enter with the monsters coordinates in (x,y).
129 static int tmpitem
, xl
, xh
, yl
, yh
;
134 int k
, m
, z
, tmp
, xtmp
, ytmp
, monst
;
135 switch (monst
= mitem
[i
][j
]) { /* for half speed monsters */
140 case INVISIBLESTALKER
:
142 if ((gltime
& 1) == 1)
146 if (c
[SCAREMONST
]) { /* choose destination randomly if scared */
147 if ((xl
= i
+ rnd(3) - 2) < 0)
151 if ((yl
= j
+ rnd(3) - 2) < 0)
155 if ((tmp
= item
[xl
][yl
]) != OWALL
)
156 if (mitem
[xl
][yl
] == 0)
157 if ((mitem
[i
][j
] != VAMPIRE
) || (tmpitem
!= OMIRROR
))
158 if (tmp
!= OCLOSEDDOOR
)
162 if (monster
[monst
].intelligence
> 10 - c
[HARDGAME
]) { /* if smart monster */
163 /* intelligent movement here -- first setup screen array */
170 for (k
= yl
; k
< yh
; k
++)
171 for (m
= xl
; m
< xh
; m
++) {
172 switch (item
[m
][k
]) {
180 smm
: screen
[m
][k
] = 127;
183 if (mitem
[m
][k
] == VAMPIRE
)
190 screen
[playerx
][playery
] = 1;
193 * now perform proximity ripple from playerx,playery to
202 for (tmp
= 1; tmp
< distance
; tmp
++) /* only up to 20 squares
204 for (k
= yl
; k
< yh
; k
++)
205 for (m
= xl
; m
< xh
; m
++)
206 if (screen
[m
][k
] == tmp
) /* if find proximity n
208 for (z
= 1; z
< 9; z
++) { /* go around in a circle */
209 if (screen
[xtmp
= m
+ diroffx
[z
]][ytmp
= k
+ diroffy
[z
]] == 0)
210 screen
[xtmp
][ytmp
] = tmp
+ 1;
211 if (xtmp
== i
&& ytmp
== j
)
215 out
: if (tmp
< distance
) /* did find connectivity */
216 /* now select lowest value around playerx,playery */
217 for (z
= 1; z
< 9; z
++) /* go around in a circle */
218 if (screen
[xl
= i
+ diroffx
[z
]][yl
= j
+ diroffy
[z
]] == tmp
)
219 if (!mitem
[xl
][yl
]) {
220 mmove(i
, j
, w1x
[0] = xl
, w1y
[0] = yl
);
224 /* dumb monsters move here */
231 else if (i
> playerx
)
235 else if (j
> playery
)
237 for (k
= 0; k
< 9; k
++)
240 for (k
= xl
; k
< xh
; k
++)
241 for (m
= yl
; m
< yh
; m
++) { /* for each square compute
242 * distance to player */
243 tmp
= k
- i
+ 4 + 3 * (m
- j
);
244 tmpitem
= item
[k
][m
];
245 if (tmpitem
!= OWALL
|| (k
== playerx
&& m
== playery
))
246 if (mitem
[k
][m
] == 0)
247 if ((mitem
[i
][j
] != VAMPIRE
) || (tmpitem
!= OMIRROR
))
248 if (tmpitem
!= OCLOSEDDOOR
) {
249 w1
[tmp
] = (playerx
- k
) * (playerx
- k
) + (playery
- m
) * (playery
- m
);
256 for (k
= 1; k
< 9; k
++)
261 if ((i
!= w1x
[tmp
]) || (j
!= w1y
[tmp
]))
262 mmove(i
, j
, w1x
[tmp
], w1y
[tmp
]);
266 * mmove(x,y,xd,yd) Function to actually perform the monster movement
269 * Enter with the from coordinates in (x,y) and the destination coordinates
273 mmove(aa
, bb
, cc
, dd
)
277 char *who
= NULL
, *p
;
278 flag
= 0; /* set to 1 if monster hit by arrow trap */
279 if ((cc
== playerx
) && (dd
== playery
)) {
285 if ((i
== OPIT
) || (i
== OTRAPDOOR
))
286 switch (mitem
[aa
][bb
]) {
304 mitem
[aa
][bb
] = 0; /* fell in a pit or trapdoor */
306 tmp
= mitem
[cc
][dd
] = mitem
[aa
][bb
];
307 if (i
== OANNIHILATION
) {
308 if (tmp
>= DEMONLORD
+ 3) { /* demons dispel spheres */
310 lprintf("\nThe %s dispels the sphere!", monster
[tmp
].name
);
311 rmsphere(cc
, dd
); /* delete the sphere */
313 i
= tmp
= mitem
[cc
][dd
] = 0;
316 if ((hitp
[cc
][dd
] = hitp
[aa
][bb
]) < 0)
320 if (tmp
== LEPRECHAUN
)
330 item
[cc
][dd
] = 0; /* leprechaun takes gold */
333 if (tmp
== TROLL
) /* if a troll regenerate him */
334 if ((gltime
& 1) == 0)
335 if (monster
[tmp
].hitpoints
> hitp
[cc
][dd
])
338 if (i
== OTRAPARROW
) { /* arrow hits monster */
340 if ((hitp
[cc
][dd
] -= rnd(10) + level
) <= 0) {
346 if (i
== ODARTRAP
) { /* dart hits monster */
348 if ((hitp
[cc
][dd
] -= rnd(6)) <= 0) {
354 if (i
== OTELEPORTER
) { /* monster hits teleport trap */
356 fillmonst(mitem
[cc
][dd
]);
360 return; /* if blind don't show where monsters are */
361 if (know
[cc
][dd
] & 1) {
367 p
= "\n%s hits the %s";
370 p
= "\n%s hits and kills the %s";
373 p
= "\nThe %s%s gets teleported";
378 lprintf(p
, who
, monster
[tmp
].name
);
383 * if (yrepcount>1) { know[aa][bb] &= 2; know[cc][dd] &= 2; return;
386 if (know
[aa
][bb
] & 1)
388 if (know
[cc
][dd
] & 1)
393 * movsphere() Function to look for and move spheres of annihilation
395 * This function works on the sphere linked list, first duplicating the list
396 * (the act of moving changes the list), then processing each sphere in order
397 * to move it. They eat anything in their way, including stairs, volcanic
398 * shafts, potions, etc, except for upper level demons, who can dispel
400 * No value is returned.
402 #define SPHMAX 20 /* maximum number of spheres movsphere can
408 struct sphere
*sp
, *sp2
;
409 struct sphere sph
[SPHMAX
];
411 /* first duplicate sphere list */
412 for (sp
= 0, x
= 0, sp2
= spheres
; sp2
; sp2
= sp2
->p
) /* look through sphere
414 if (sp2
->lev
== level
) { /* only if this level */
416 sph
[x
++].p
= 0; /* copy the struct */
418 sph
[x
- 2].p
= &sph
[x
- 1]; /* link pointers */
421 sp
= sph
; /* if any spheres, point to them */
423 return; /* no spheres */
425 for (sp
= sph
; sp
; sp
= sp
->p
) { /* look through sphere list */
428 if (item
[x
][y
] != OANNIHILATION
)
429 continue; /* not really there */
430 if (--(sp
->lifetime
) < 0) { /* has sphere run out of gas? */
431 rmsphere(x
, y
); /* delete sphere */
434 switch (rnd((int) max(7, c
[INTELLIGENCE
] >> 1))) { /* time to move the
437 case 2: /* change direction to a random one */
439 default: /* move in normal direction */
443 newsphere(x
+ diroffx
[dir
], y
+ diroffy
[dir
], dir
, len
);