]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/movem.c
1 /* $NetBSD: movem.c,v 1.9 2012/06/19 05:30:43 dholland 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.9 2012/06/19 05:30:43 dholland Exp $");
21 static void movemt(int, int);
22 static void mmove(int, int, int, int);
23 static void movsphere(void);
26 * movemonst() Routine to move the monsters toward the player
28 * This routine has the responsibility to determine which monsters are to
29 * move, and call movemt() to do the move.
32 static short w1
[9], w1x
[9], w1y
[9];
33 static int tmp1
, tmp2
, tmp3
, tmp4
, distance
;
39 return; /* no action if time is stopped */
41 if ((c
[HASTESELF
] & 1) == 0)
44 movsphere(); /* move the spheres of annihilation if any */
46 return; /* no action if monsters are held */
48 if (c
[AGGRAVATE
]) { /* determine window of monsters to move */
53 distance
= 40; /* depth of intelligent monster movement */
59 distance
= 17; /* depth of intelligent monster movement */
62 if (level
== 0) { /* if on outside level monsters can move in
72 } else { /* if in a dungeon monsters can't be on the
73 * perimeter (wall there) */
84 for (j
= tmp1
; j
< tmp2
; j
++) /* now reset monster moved flags */
85 for (i
= tmp3
; i
< tmp4
; i
++)
87 moved
[lasthx
][lasthy
] = 0;
89 if (c
[AGGRAVATE
] || !c
[STEALTH
]) { /* who gets moved? split for
91 for (j
= tmp1
; j
< tmp2
; j
++) /* look thru all locations in
93 for (i
= tmp3
; i
< tmp4
; i
++)
94 if (mitem
[i
][j
]) /* if there is a monster
96 if (moved
[i
][j
] == 0) /* if it has not already
98 movemt(i
, j
); /* go and move the
100 } else { /* not aggravated and not stealth */
101 for (j
= tmp1
; j
< tmp2
; j
++) /* look thru all locations in
103 for (i
= tmp3
; i
< tmp4
; i
++)
104 if (mitem
[i
][j
]) /* if there is a monster
106 if (moved
[i
][j
] == 0) /* if it has not already
108 if (stealth
[i
][j
]) /* if it is asleep due
110 movemt(i
, j
); /* go and move the
114 if (mitem
[lasthx
][lasthy
]) { /* now move monster last hit by
115 * player if not already moved */
116 if (moved
[lasthx
][lasthy
] == 0) { /* if it has not already
118 movemt(lasthx
, lasthy
);
126 * movemt(x,y) Function to move a monster at (x,y) -- must determine where
129 * This routine is responsible for determining where one monster at (x,y) will
130 * move to. Enter with the monsters coordinates in (x,y).
133 static int tmpitem
, xl
, xh
, yl
, yh
;
137 int k
, m
, z
, tmp
, xtmp
, ytmp
, monst
;
138 switch (monst
= mitem
[i
][j
]) { /* for half speed monsters */
143 case INVISIBLESTALKER
:
145 if ((gltime
& 1) == 1)
149 if (c
[SCAREMONST
]) { /* choose destination randomly if scared */
150 if ((xl
= i
+ rnd(3) - 2) < 0)
154 if ((yl
= j
+ rnd(3) - 2) < 0)
158 if ((tmp
= item
[xl
][yl
]) != OWALL
)
159 if (mitem
[xl
][yl
] == 0)
160 if ((mitem
[i
][j
] != VAMPIRE
) || (tmpitem
!= OMIRROR
))
161 if (tmp
!= OCLOSEDDOOR
)
165 if (monster
[monst
].intelligence
> 10 - c
[HARDGAME
]) { /* if smart monster */
166 /* intelligent movement here -- first setup screen array */
173 for (k
= yl
; k
< yh
; k
++)
174 for (m
= xl
; m
< xh
; m
++) {
175 switch (item
[m
][k
]) {
183 smm
: screen
[m
][k
] = 127;
186 if (mitem
[m
][k
] == VAMPIRE
)
193 screen
[playerx
][playery
] = 1;
196 * now perform proximity ripple from playerx,playery to
205 for (tmp
= 1; tmp
< distance
; tmp
++) /* only up to 20 squares
207 for (k
= yl
; k
< yh
; k
++)
208 for (m
= xl
; m
< xh
; m
++)
209 if (screen
[m
][k
] == tmp
) /* if find proximity n
211 for (z
= 1; z
< 9; z
++) { /* go around in a circle */
212 if (screen
[xtmp
= m
+ diroffx
[z
]][ytmp
= k
+ diroffy
[z
]] == 0)
213 screen
[xtmp
][ytmp
] = tmp
+ 1;
214 if (xtmp
== i
&& ytmp
== j
)
218 out
: if (tmp
< distance
) /* did find connectivity */
219 /* now select lowest value around playerx,playery */
220 for (z
= 1; z
< 9; z
++) /* go around in a circle */
221 if (screen
[xl
= i
+ diroffx
[z
]][yl
= j
+ diroffy
[z
]] == tmp
)
222 if (!mitem
[xl
][yl
]) {
223 mmove(i
, j
, w1x
[0] = xl
, w1y
[0] = yl
);
227 /* dumb monsters move here */
234 else if (i
> playerx
)
238 else if (j
> playery
)
240 for (k
= 0; k
< 9; k
++)
243 for (k
= xl
; k
< xh
; k
++)
244 for (m
= yl
; m
< yh
; m
++) { /* for each square compute
245 * distance to player */
246 tmp
= k
- i
+ 4 + 3 * (m
- j
);
247 tmpitem
= item
[k
][m
];
248 if (tmpitem
!= OWALL
|| (k
== playerx
&& m
== playery
))
249 if (mitem
[k
][m
] == 0)
250 if ((mitem
[i
][j
] != VAMPIRE
) || (tmpitem
!= OMIRROR
))
251 if (tmpitem
!= OCLOSEDDOOR
) {
252 w1
[tmp
] = (playerx
- k
) * (playerx
- k
) + (playery
- m
) * (playery
- m
);
259 for (k
= 1; k
< 9; k
++)
264 if ((i
!= w1x
[tmp
]) || (j
!= w1y
[tmp
]))
265 mmove(i
, j
, w1x
[tmp
], w1y
[tmp
]);
269 * mmove(x,y,xd,yd) Function to actually perform the monster movement
272 * Enter with the from coordinates in (x,y) and the destination coordinates
276 mmove(int aa
, int bb
, int cc
, int dd
)
279 const char *who
= NULL
;
281 flag
= 0; /* set to 1 if monster hit by arrow trap */
282 if ((cc
== playerx
) && (dd
== playery
)) {
288 if ((i
== OPIT
) || (i
== OTRAPDOOR
))
289 switch (mitem
[aa
][bb
]) {
307 mitem
[aa
][bb
] = 0; /* fell in a pit or trapdoor */
309 tmp
= mitem
[cc
][dd
] = mitem
[aa
][bb
];
310 if (i
== OANNIHILATION
) {
311 if (tmp
>= DEMONLORD
+ 3) { /* demons dispel spheres */
313 lprintf("\nThe %s dispels the sphere!", monster
[tmp
].name
);
314 rmsphere(cc
, dd
); /* delete the sphere */
316 i
= tmp
= mitem
[cc
][dd
] = 0;
319 if ((hitp
[cc
][dd
] = hitp
[aa
][bb
]) < 0)
323 if (tmp
== LEPRECHAUN
)
333 item
[cc
][dd
] = 0; /* leprechaun takes gold */
336 if (tmp
== TROLL
) /* if a troll regenerate him */
337 if ((gltime
& 1) == 0)
338 if (monster
[tmp
].hitpoints
> hitp
[cc
][dd
])
341 if (i
== OTRAPARROW
) { /* arrow hits monster */
343 if ((hitp
[cc
][dd
] -= rnd(10) + level
) <= 0) {
349 if (i
== ODARTRAP
) { /* dart hits monster */
351 if ((hitp
[cc
][dd
] -= rnd(6)) <= 0) {
357 if (i
== OTELEPORTER
) { /* monster hits teleport trap */
359 fillmonst(mitem
[cc
][dd
]);
363 return; /* if blind don't show where monsters are */
364 if (know
[cc
][dd
] & 1) {
369 lprintf("\n%s hits the %s", who
, monster
[tmp
].name
);
373 lprintf("\n%s hits and kills the %s",
374 who
, monster
[tmp
].name
);
378 lprintf("\nThe %s gets teleported", monster
[tmp
].name
);
384 * if (yrepcount>1) { know[aa][bb] &= 2; know[cc][dd] &= 2; return;
387 if (know
[aa
][bb
] & 1)
389 if (know
[cc
][dd
] & 1)
394 * movsphere() Function to look for and move spheres of annihilation
396 * This function works on the sphere linked list, first duplicating the list
397 * (the act of moving changes the list), then processing each sphere in order
398 * to move it. They eat anything in their way, including stairs, volcanic
399 * shafts, potions, etc, except for upper level demons, who can dispel
401 * No value is returned.
403 #define SPHMAX 20 /* maximum number of spheres movsphere can
409 struct sphere
*sp
, *sp2
;
410 struct sphere sph
[SPHMAX
];
412 /* first duplicate sphere list */
413 for (sp
= 0, x
= 0, sp2
= spheres
; sp2
; sp2
= sp2
->p
) /* look through sphere
415 if (sp2
->lev
== level
) { /* only if this level */
417 sph
[x
++].p
= 0; /* copy the struct */
419 sph
[x
- 2].p
= &sph
[x
- 1]; /* link pointers */
422 sp
= sph
; /* if any spheres, point to them */
424 return; /* no spheres */
426 for (sp
= sph
; sp
; sp
= sp
->p
) { /* look through sphere list */
429 if (item
[x
][y
] != OANNIHILATION
)
430 continue; /* not really there */
431 if (--(sp
->lifetime
) < 0) { /* has sphere run out of gas? */
432 rmsphere(x
, y
); /* delete sphere */
435 switch (rnd((int) max(7, c
[INTELLIGENCE
] >> 1))) { /* time to move the
438 case 2: /* change direction to a random one */
440 default: /* move in normal direction */
444 newsphere(x
+ diroffx
[dir
], y
+ diroffy
[dir
], dir
, len
);