DEADSOFTWARE

1357446b1dd45abbffc46d0ee6709d2fd2c8a467
[flatwaifu.git] / src / monster.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
23 #include "glob.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include "files.h"
27 #include "view.h"
28 #include "bmap.h"
29 #include "dots.h"
30 #include "weapons.h"
31 #include "player.h"
32 #include "monster.h"
33 #include "items.h"
34 #include "switch.h"
35 #include "misc.h"
36 #include "fx.h"
37 #include "smoke.h"
38 #include "my.h"
40 #define MAX_ATM 90
42 extern byte z_mon;
44 enum{
45 SLEEP,GO,RUN,CLIMB,DIE,DEAD,ATTACK,SHOOT,PAIN,WAIT,REVIVE,RUNOUT
46 };
48 typedef struct{
49 int r,h,l,mp,rv,jv,sp,minp;
50 }mnsz_t;
52 byte nomon=1;
54 static char *sleepanim[MN_TN]={
55 "AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB",
56 "A","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB",
57 "A","A","AAABBB"
58 }, *goanim[MN_TN]={
59 "AABBCCDD","AABBCCDD","AABBDDAACCDD","AABBDDAACCDD","AABBDDCCDDBB",
60 "AABBDDAACCDD","AABBCCDD","AABBCCDD","A","AABB","AABBCCBB",
61 "AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF",
62 "AABB","A","DDEEFFGGHHIIJJKKLLAABBCC","ACDABD"
63 }, *painanim[MN_TN]={
64 "H","H","G","G","G","G","H","H","F","E","G","I","I","J","L","Q","EECCDDCC",
65 "A","D","G"
66 }, *waitanim[MN_TN]={
67 "A","A","A","A","A","A","A","A","A","AABB","A","A","A","I","K","A","A",
68 "A","D","E"
69 }, *attackanim[MN_TN]={
70 "EEFFGG","EEFFGG","EEEEEF","EEEEEF","EEEEEF","EF","EEFFGG","EEFFGG",
71 "BBCCDD","CCDD","DDEEFF","GH","GH","GGGGHH","GGHHII",
72 "QQGGGHHHIIJJKKLLMMNNOOPP","BBFFAA","A","OOPPQQ","EEEEFF"
73 }, *dieanim[MN_TN]={
74 "IIIJJJKKKLLLMMM","IIIJJJKKKLLL","HHHIIIJJJKKK","HHHIIIJJJKKK",
75 "HHHIIIJJJKKKLLLMMMNNNOOO","HHHIIIJJJKKKLLLMMM",
76 "IIIJJJKKKLLLMMMNNN","IIIJJJKKKLLLMMMNNN","GGGHHHIIIJJJKKK",
77 "FFFGGGHHHIIIJJJKKK","HHHIIIJJJKKKLLLMMM",
78 "JJJJKKKKLLLLMMMMNNNNOOOOPPPPQQQQRRRR","JJJKKKLLLMMMNNNOOO",
79 "KKKLLLMMMNNNOOOPPPRRRSSS","MMMNNNOOOPPP","RRRSSSTTTUUUVVVWWWXXXYYY",
80 "DDDD","CCCDDDEEEFFFGGG","D","HHHHIIIIJJJJKKKKLLLLMMMM"
81 }, *slopanim[MN_TN]={
82 "","NNNOOOPPPRRRSSSTTT","MMMNNNOOOPPPRRRSSSTTT","MMMNNNOOOPPPRRRSSSTTT","",
83 "OOOPPPQQQRRRSSS","","","","","","","","","","","","","","OOPPQQRRSSTTUUVV"
84 }, *deadanim[MN_TN]={
85 "N","M","L","L","P","N","O","O","L","","","S","P","T","Q","Z","C","","D","N"
86 }, *messanim[MN_TN]={
87 "","U","U","U","","T","","","","","","","","","","","","","","W"
88 };
90 int hit_xv,hit_yv;
91 mn_t mn[MAXMN];
93 static void *fsnd,*pauksnd,*trupsnd;
94 static void *snd[MN_TN][5],*impsitsnd[2],*impdthsnd[2],*firsnd,*slopsnd,*gsnd[4];
95 static void *swgsnd,*pchsnd,*telesnd;
96 static void *positsnd[3],*podthsnd[3];
97 static int mnum,gsndt;
98 static mnsz_t mnsz[MN_TN+1]={
99 //rad ht life pain rv jv slop min_pn
100 0, 0, 0, 0, 0, 0, 0, 0, // none
101 15, 28, 60, 20, 7,10, 0, 10, // demon
102 10, 28, 25, 15, 3,10, 30, 0, // imp
103 10, 28, 15, 10, 3,10, 30, 0, // zomby
104 10, 28, 20, 10, 3,10, 30, 0, // sergeant
105 20, 55, 500, 70, 5,10, 0, 50, // cyberdemon
106 12, 28, 60, 20, 3,10, 30, 10, // chaingunner
107 12, 32, 150, 40, 3,10, 0, 30, // baron of hell
108 12, 32, 75, 40, 3,10, 0, 30, // hell knight
109 15, 28, 100, 10, 4, 4, 0, 0, // cacodemon
110 8, 18, 60, 10, 4, 4, 0, 0, // lost soul
111 15, 28, 100, 10, 4, 4, 0, 0, // pain elemental
112 64, 50, 500, 70, 4,10, 0, 50, // spider mastermind
113 25, 27, 150, 20, 4,10, 0, 0, // arachnotron
114 18, 30, 200, 40, 3, 7, 0, 20, // mancubus
115 17, 36, 200, 40, 6,11, 0, 20, // revenant
116 17, 36, 150, 30, 7,12, 0, 10, // archvile
117 5, 5, 35, 20,14, 6, 0, 10, // fish
118 5, 17, 20, 0, 7, 6, 0, 0, // barrel
119 17, 38, 20, 40, 3, 6, 0, 20, // robot
120 8, 26, 400, 70, 8,10, 30, 50 // man
121 };
123 void MN_savegame (FILE *h) {
124 int i, n;
125 for (n = MAXMN - 1; n >= 0 && mn[n].t == 0; n--) {
126 // empty
128 n += 1;
129 myfwrite32(n, h);
130 for (i = 0; i < n; i++) {
131 myfwrite32(mn[i].o.x, h);
132 myfwrite32(mn[i].o.y, h);
133 myfwrite32(mn[i].o.xv, h);
134 myfwrite32(mn[i].o.yv, h);
135 myfwrite32(mn[i].o.vx, h);
136 myfwrite32(mn[i].o.vy, h);
137 myfwrite32(mn[i].o.r, h);
138 myfwrite32(mn[i].o.h, h);
139 myfwrite8(mn[i].t, h);
140 myfwrite8(mn[i].d, h);
141 myfwrite8(mn[i].st, h);
142 myfwrite8(mn[i].ftime, h);
143 myfwrite32(mn[i].fobj, h);
144 myfwrite32(mn[i].s, h);
145 myfwrite32(0, h); // mn[i].ap useless, changed after load
146 myfwrite32(mn[i].aim, h);
147 myfwrite32(mn[i].life, h);
148 myfwrite32(mn[i].pain, h);
149 myfwrite32(mn[i].ac, h);
150 myfwrite32(mn[i].tx, h);
151 myfwrite32(mn[i].ty, h);
152 myfwrite32(mn[i].ammo, h);
153 myfwrite16(mn[i].atm, h);
155 myfwrite32(mnum, h);
156 myfwrite32(gsndt, h);
159 static void setst(int,int);
161 static int MN_hit(int n,int d,int o,int t);
163 void MN_loadgame (FILE *h) {
164 int i, n, c;
165 n = myfread32(h);
166 for (i = 0; i < n; i++) {
167 mn[i].o.x = myfread32(h);
168 mn[i].o.y = myfread32(h);
169 mn[i].o.xv = myfread32(h);
170 mn[i].o.yv = myfread32(h);
171 mn[i].o.vx = myfread32(h);
172 mn[i].o.vy = myfread32(h);
173 mn[i].o.r = myfread32(h);
174 mn[i].o.h = myfread32(h);
175 mn[i].t = myfread8(h);
176 mn[i].d = myfread8(h);
177 mn[i].st = myfread8(h);
178 mn[i].ftime = myfread8(h);
179 mn[i].fobj = myfread32(h);
180 mn[i].s = myfread32(h);
181 mn[i].ap = NULL; myfread32(h); // useless, changed after loading
182 mn[i].aim = myfread32(h);
183 mn[i].life = myfread32(h);
184 mn[i].pain = myfread32(h);
185 mn[i].ac = myfread32(h);
186 mn[i].tx = myfread32(h);
187 mn[i].ty = myfread32(h);
188 mn[i].ammo = myfread32(h);
189 mn[i].atm = myfread16(h);
191 mnum = myfread32(h);
192 gsndt = myfread32(h);
193 for (n = 0; n < MAXMN; ++n) {
194 if (mn[n].t) {
195 c = mn[n].ac;
196 setst(n, mn[n].st);
197 mn[n].ac = c;
202 #define GGAS_TOTAL (MN__LAST-MN_DEMON+16+10)
204 void MN_alloc(void) {
205 int i,j;
206 static char sn[MN_TN][5][6]={
207 {"DMACT","DMPAIN","SGTATK","SGTSIT","SGTDTH"},
208 {"BGACT","POPAIN","CLAW","",""},
209 {"POSACT","POPAIN","","",""},
210 {"POSACT","POPAIN","","",""},
211 {"","DMPAIN","HOOF","CYBSIT","CYBDTH"},
212 {"POSACT","POPAIN","","",""},
213 {"","DMPAIN","","BRSSIT","BRSDTH"},
214 {"","DMPAIN","","KNTSIT","KNTDTH"},
215 {"DMACT","DMPAIN","","CACSIT","CACDTH"},
216 {"DMACT","DMPAIN","SKLATK","SKLATK","FIRXPL"},
217 {"DMACT","PEPAIN","","PESIT","PEDTH"},
218 {"","DMPAIN","METAL","SPISIT","SPIDTH"},
219 {"BSPACT","DMPAIN","BSPWLK","BSPSIT","BSPDTH"},
220 {"DMACT","MNPAIN","MANATK","MANSIT","MANDTH"},
221 {"SKEACT","POPAIN","SKEATK","SKESIT","SKEDTH"},
222 {"VILACT","VIPAIN","VILATK","VILSIT","VILDTH"},
223 {"","","BITE1","",""},
224 {"","","","","BAREXP"},
225 {"BSPACT","","BSPWLK","BSPSIT","BSPDTH"},
226 {"HAHA1","PLPAIN","","STOP1","PDIEHI"}
227 };
228 static char gsn[6]="GOOD0";
229 for(j=0;j<MN_TN;++j) {
230 for(i=0;i<5;++i)
231 if(sn[j][i][0])
232 snd[j][i]=Z_getsnd(sn[j][i]);
233 else
234 snd[j][i]=NULL;
235 logo_gas(j+5,GGAS_TOTAL);
237 impsitsnd[0]=Z_getsnd("BGSIT1");
238 impsitsnd[1]=Z_getsnd("BGSIT2");
239 impdthsnd[0]=Z_getsnd("BGDTH1");
240 impdthsnd[1]=Z_getsnd("BGDTH2");
241 positsnd[0]=Z_getsnd("POSIT1");
242 positsnd[1]=Z_getsnd("POSIT2");
243 positsnd[2]=Z_getsnd("POSIT3");
244 podthsnd[0]=Z_getsnd("PODTH1");
245 podthsnd[1]=Z_getsnd("PODTH2");
246 podthsnd[2]=Z_getsnd("PODTH3");
247 fsnd=Z_getsnd("FLAME");
248 firsnd=Z_getsnd("FIRSHT");
249 slopsnd=Z_getsnd("SLOP");
250 swgsnd=Z_getsnd("SKESWG");
251 pchsnd=Z_getsnd("SKEPCH");
252 telesnd=Z_getsnd("TELEPT");
253 pauksnd=Z_getsnd("PAUK1");
254 trupsnd=Z_getsnd("UTRUP");
255 for(i=0;i<4;++i) {gsn[4]=i+'1';gsnd[i]=Z_getsnd(gsn);}
258 void MN_init(void) {
259 int i;
261 for(i=0;i<MAXMN;++i) {mn[i].t=0;mn[i].st=SLEEP;}
262 gsndt=mnum=0;
265 static void setst(int i,int st) {
266 char *a;
267 int t;
269 switch(mn[i].st) {
270 case DIE: case DEAD:
271 if(st!=DEAD && st!=REVIVE) return;
273 mn[i].ac=0;
274 t=mn[i].t-1;
275 switch(mn[i].st=st) {
276 case SLEEP: a=sleepanim[t];break;
277 case PAIN: a=painanim[t];break;
278 case WAIT: a=waitanim[t];break;
279 case CLIMB:
280 case RUN: case RUNOUT:
281 case GO: a=goanim[t];break;
282 case SHOOT:
283 if(t==MN_SKEL-1) {a="KKKKJJ";break;}
284 if(t==MN_ROBO-1) {a="MN";break;}
285 case ATTACK: a=attackanim[t];
286 if(st==ATTACK && t==MN_VILE-1) a="[[\\\\]]";
287 break;
288 case DIE:
289 if(g_map==9 && t==MN_BSP-1) Z_sound(pauksnd,128);
290 a=dieanim[t];break;
291 case DEAD:
292 a=deadanim[t];
293 if(mn[i].ap==slopanim[t]) a=messanim[t];
294 if(t==MN_BARREL-1) {mn[i].t=0;}
295 break;
296 case REVIVE:
297 a=(mn[i].ap==messanim[t])?slopanim[t]:dieanim[t];
298 mn[i].ac=strlen(a)-1;
299 mn[i].o.r=mnsz[t+1].r;mn[i].o.h=mnsz[t+1].h;
300 mn[i].life=mnsz[t+1].l;mn[i].ammo=mn[i].pain=0;
301 ++mnum;
302 break;
304 mn[i].ap=a;
307 int MN_spawn(int x,int y,byte d,int t) {
308 int i;
310 if(g_dm && nomon && t<MN_PL_DEAD) return -1;
311 for(i=0;i<MAXMN;++i) if(!mn[i].t) goto ok;
312 for(i=0;i<MAXMN;++i) if(mn[i].t>=MN_PL_DEAD) goto ok;
313 return -1;
314 ok:
315 mn[i].o.x=x;mn[i].o.y=y;
316 mn[i].o.xv=mn[i].o.yv=mn[i].o.vx=mn[i].o.vy=0;
317 mn[i].d=d;mn[i].t=t;
318 mn[i].st=SLEEP;
319 if(t<MN_PL_DEAD) {
320 mn[i].o.r=mnsz[t].r;mn[i].o.h=mnsz[t].h;
321 mn[i].life=mnsz[t].l;
322 setst(i,SLEEP);mn[i].s=myrand(18);
323 ++mnum;
324 }else {mn[i].o.r=8;mn[i].o.h=6;mn[i].life=0;mn[i].st=DEAD;}
325 mn[i].aim=-3;mn[i].atm=0;
326 mn[i].pain=0;
327 mn[i].ammo=0;
328 mn[i].ftime=0;
329 return i;
332 int MN_spawn_deadpl(obj_t *o,byte c,int t) {
333 int i;
335 if((i=MN_spawn(o->x,o->y,c,t+MN_PL_DEAD))==-1) return -1;
336 mn[i].o=*o;return i;
339 static int isfriend(int a,int b) {
340 if(a==MN_BARREL || b==MN_BARREL) return 1;
341 if(a==b) switch(a) {
342 case MN_IMP: case MN_DEMON:
343 case MN_BARON: case MN_KNIGHT:
344 case MN_CACO: case MN_SOUL:
345 case MN_MANCUB: case MN_SKEL:
346 case MN_FISH:
347 return 1;
349 if(a==MN_SOUL && b==MN_PAIN) return 1;
350 if(b==MN_SOUL && a==MN_PAIN) return 1;
351 return 0;
354 static int MN_findnewprey(int i) {
355 int a,b,l;
357 a=!PL_isdead(&pl1);
358 if(_2pl) b=!PL_isdead(&pl2); else b=0;
359 if(a) {
360 if(b) mn[i].aim=(abs(mn[i].o.x-pl1.o.x)+abs(mn[i].o.y-pl1.o.y)
361 <= abs(mn[i].o.x-pl2.o.x)+abs(mn[i].o.y-pl2.o.y))?-1:-2;
362 else mn[i].aim=-1;
363 }else{
364 if(b) mn[i].aim=-2;
365 else{
366 for(a=0,b=32000,mn[i].aim=-3;a<MAXMN;++a)
367 if(mn[a].t && mn[a].st!=DEAD && a!=i && !isfriend(mn[a].t,mn[i].t))
368 if((l=abs(mn[i].o.x-mn[a].o.x)+abs(mn[i].o.y-mn[a].o.y))<b)
369 {mn[i].aim=a;b=l;}
370 if(mn[i].aim<0) {mn[i].atm=MAX_ATM;return 0;} else mn[i].atm=0;
373 return 1;
376 int Z_getobjpos(int i,obj_t *o) {
377 if(i==-1) {*o=pl1.o;return !PL_isdead(&pl1);}
378 if(_2pl) if(i==-2) {*o=pl2.o;return !PL_isdead(&pl2);}
379 if(i>=0 && i<MAXMN) if(mn[i].t && mn[i].st!=DEAD)
380 {*o=mn[i].o;return 1;}
381 return 0;
384 static void *wakeupsnd(int t) {
385 switch(t) {
386 case MN_IMP: return impsitsnd[myrand(2)];
387 case MN_ZOMBY: case MN_SERG: case MN_CGUN:
388 return positsnd[myrand(3)];
390 return snd[t-1][3];
393 static void *dthsnd(int t) {
394 switch(t) {
395 case MN_IMP: return impdthsnd[myrand(2)];
396 case MN_ZOMBY: case MN_SERG: case MN_CGUN:
397 return podthsnd[myrand(3)];
399 return snd[t-1][4];
402 static int canshoot(int t) {
403 switch(t) {
404 case MN_DEMON: case MN_FISH: case MN_BARREL:
405 return 0;
407 return 1;
410 static int shoot(int i,obj_t *o,int n) {
411 int xd,yd,m;
413 if(mn[i].ammo<0) return 0;
414 if(!n) switch(mn[i].t) {
415 case MN_FISH: case MN_BARREL:
416 case MN_DEMON: return 0;
417 case MN_CGUN:
418 case MN_BSP:
419 case MN_ROBO:
420 if(++mn[i].ammo>=50) mn[i].ammo=(mn[i].t==MN_ROBO)?-200:-50;
421 break;
422 case MN_MAN:
423 break;
424 case MN_MANCUB:
425 if(++mn[i].ammo>=5) mn[i].ammo=-50;
426 break;
427 case MN_SPIDER:
428 if(++mn[i].ammo>=100) mn[i].ammo=-50;
429 break;
430 case MN_CYBER:
431 if(rand()&1) return 0;
432 if(++mn[i].ammo>=10) mn[i].ammo=-50;
433 break;
434 case MN_BARON: case MN_KNIGHT:
435 if(rand()&7) return 0;
436 break;
437 case MN_SKEL:
438 if(rand()&31) return 0;
439 break;
440 case MN_VILE:
441 if(rand()&7) return 0;
442 break;
443 case MN_PAIN:
444 if(rand()&7) return 0;
445 break;
446 default:
447 if(rand()&15) return 0;
449 if(!Z_look(&mn[i].o,o,mn[i].d)) return 0;
450 mn[i].atm=0;
451 mn[i].tx=o->x+(o->xv+o->vx)*6;mn[i].ty=o->y-o->h/2+(o->yv+o->vy)*6;
452 if(abs(mn[i].tx-mn[i].o.x)<abs(mn[i].ty-mn[i].o.y+mn[i].o.h/2)) return 0;
453 switch(mn[i].t) {
454 case MN_IMP: case MN_BARON: case MN_KNIGHT: case MN_CACO:
455 setst(i,SHOOT);Z_sound(firsnd,128);break;
456 case MN_SKEL:
457 setst(i,SHOOT);Z_sound(snd[MN_SKEL-1][2],128);break;
458 case MN_VILE:
459 mn[i].tx=o->x;mn[i].ty=o->y;
460 setst(i,SHOOT);Z_sound(fsnd,128);
461 Z_sound(snd[MN_VILE-1][2],128);break;
462 case MN_SOUL:
463 setst(i,ATTACK);Z_sound(snd[MN_SOUL-1][2],128);
464 yd=mn[i].ty-mn[i].o.y+mn[i].o.h/2;xd=mn[i].tx-mn[i].o.x;
465 if(!(m=max(abs(xd),abs(yd)))) m=1;
466 mn[i].o.xv=xd*16/m;mn[i].o.yv=yd*16/m;
467 break;
468 case MN_MANCUB: if(mn[i].ammo==1) Z_sound(snd[MN_MANCUB-1][2],128);
469 case MN_ZOMBY: case MN_SERG: case MN_BSP: case MN_ROBO:
470 case MN_CYBER: case MN_CGUN: case MN_SPIDER:
471 case MN_PAIN: case MN_MAN:
472 setst(i,SHOOT);break;
473 default:
474 return 0;
476 return 1;
479 static int kick(int i,obj_t *o) {
480 switch(mn[i].t) {
481 case MN_FISH:
482 setst(i,ATTACK);return 1;
483 case MN_DEMON:
484 setst(i,ATTACK);Z_sound(snd[0][2],128);return 1;
485 case MN_IMP:
486 setst(i,ATTACK);Z_sound(snd[1][2],128);return 1;
487 case MN_SKEL:
488 setst(i,ATTACK);Z_sound(swgsnd,128);return 1;
489 case MN_ROBO:
490 setst(i,ATTACK);Z_sound(swgsnd,128);return 1;
491 case MN_BARON: case MN_KNIGHT: case MN_CACO: case MN_MANCUB:
492 return shoot(i,o,1);
494 return 0;
497 static int iscorpse(obj_t *o,int n) {
498 int i;
500 if(!n) if(rand()&7) return -3;
501 for(i=0;i<MAXMN;++i) if(mn[i].t) if(mn[i].st==DEAD)
502 if(Z_overlap(o,&mn[i].o)) switch(mn[i].t) {
503 case MN_SOUL: case MN_PAIN:
504 case MN_CYBER: case MN_SPIDER:
505 case MN_PL_DEAD: case MN_PL_MESS:
506 case MN_VILE: case MN_BARREL:
507 continue;
508 default:
509 return i;
511 return -3;
514 void MN_act(void) {
515 int i,st,sx,sy,t;
516 static obj_t o;
517 static int pt_x=0,pt_xs=1,pt_y=0,pt_ys=1;
519 if(abs(pt_x+=pt_xs) > 123) pt_xs=-pt_xs;
520 if(abs(pt_y+=pt_ys) > 50) pt_ys=-pt_ys;
521 if(gsndt>0) if(--gsndt==0) {
522 Z_sound(gsnd[myrand(4)],128);
524 for(i=0;i<MAXMN;++i) if((t=mn[i].t)!=0) {
525 switch(t) {
526 case MN_FISH:
527 if(!Z_inwater(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h)) break;
528 case MN_SOUL: case MN_PAIN: case MN_CACO:
529 if(mn[i].st!=DIE && mn[i].st!=DEAD) --mn[i].o.yv;
530 break;
531 }z_mon=1;st=Z_moveobj(&mn[i].o);z_mon=0;
532 BM_mark(&mn[i].o,BM_MONSTER);
533 if(st&Z_FALLOUT) {
534 if(t==MN_ROBO) g_exit=1;
535 mn[i].t=0;--mnum;continue;
537 if(st&Z_HITWATER) Z_splash(&mn[i].o,mn[i].o.r+mn[i].o.h);
538 SW_press(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h,8,i);
539 if(mn[i].ftime) {
540 --mn[i].ftime;
541 SMK_flame(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,
542 mn[i].o.xv+mn[i].o.vx,mn[i].o.yv+mn[i].o.vy,
543 mn[i].o.r/2,mn[i].o.h/2,rand()%(200*2+1)-200,-500,1,mn[i].fobj);
545 if(st&Z_INWATER) mn[i].ftime=0;
546 if(mn[i].st==DEAD) continue;
547 if(st&Z_INWATER) if(!(rand()&31)) switch(t) {
548 case MN_FISH:
549 if(rand()&3) break;
550 case MN_ROBO: case MN_BARREL:
551 case MN_PL_DEAD: case MN_PL_MESS:
552 FX_bubble(mn[i].o.x+((rand()&1)*2-1)*myrand(mn[i].o.r+1),
553 mn[i].o.y-myrand(mn[i].o.h+1),0,0,1
554 );
555 break;
556 default:
557 FX_bubble(mn[i].o.x,mn[i].o.y-mn[i].o.h*3/4,0,0,5);
560 if(t==MN_BARREL) {
562 if(!mn[i].ap[++mn[i].ac]) {
563 mn[i].ac=0;if(mn[i].st==DIE || mn[i].st==DEAD) {mn[i].t=0;}
564 }else if(mn[i].st==DIE && mn[i].ac==2) Z_explode(mn[i].o.x,mn[i].o.y-8,30,mn[i].aim);
565 continue;
567 if(t==MN_SOUL) if(st&Z_HITAIR) Z_set_speed(&mn[i].o,16);
568 if(mn[i].ammo<0) ++mn[i].ammo;
569 if(mn[i].o.yv<0)
570 if(st&Z_INWATER) mn[i].o.yv=-4;
571 ++mn[i].atm;
572 switch(mn[i].st) {
573 case PAIN:
574 if(mn[i].pain>=mnsz[t].mp)
575 {mn[i].pain=mnsz[t].mp;Z_sound(snd[t-1][1],128);}
576 if((mn[i].pain-=5)<=mnsz[t].minp)
577 {setst(i,GO);mn[i].pain=0;mn[i].ammo=-9;}
578 break;
579 case SLEEP:
580 if(++mn[i].s>=18) mn[i].s=0; else break;
581 if(Z_look(&mn[i].o,&pl1.o,mn[i].d))
582 {setst(i,GO);mn[i].aim=-1;mn[i].atm=0;Z_sound(wakeupsnd(t),128);}
583 if(_2pl) if(Z_look(&mn[i].o,&pl2.o,mn[i].d))
584 {setst(i,GO);mn[i].aim=-2;mn[i].atm=0;Z_sound(wakeupsnd(t),128);}
585 break;
586 case WAIT:
587 if(--mn[i].s<0) setst(i,GO);
588 break;
589 case GO:
590 if(st&Z_BLOCK) {mn[i].d^=1;setst(i,RUNOUT);mn[i].s=40;break;}
591 if(t==MN_VILE) if(iscorpse(&mn[i].o,0)>=0) {
592 setst(i,ATTACK);mn[i].o.xv=0;break;
594 if(!Z_getobjpos(mn[i].aim,&o) || mn[i].atm>MAX_ATM)
595 if(!MN_findnewprey(i)) {
596 mn[i].aim=-3;
597 o.x=mn[i].o.x+pt_x;o.y=mn[i].o.y+pt_y;
598 o.xv=o.vx=o.yv=o.vy=o.r=0;o.h=1;
599 }else Z_getobjpos(mn[i].aim,&o);
600 if(Z_overlap(&mn[i].o,&o)) {
601 mn[i].atm=0;
602 if(kick(i,&o)) break;
604 sx=o.x-mn[i].o.x;
605 sy=o.y-o.h/2-mn[i].o.y+mn[i].o.h/2;
606 if(!(st&Z_BLOCK)) if(abs(sx)<20)
607 if(t!=MN_FISH) {setst(i,RUN);mn[i].s=15;mn[i].d=rand()&1;break;}
608 if(st&Z_HITWALL) {
609 if(SW_press(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h,2,i))
610 {setst(i,WAIT);mn[i].s=4;break;}
611 switch(t) {
612 case MN_CACO: case MN_SOUL: case MN_PAIN: case MN_FISH:
613 break;
614 default:
615 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
616 {mn[i].o.yv=-mnsz[t].jv;setst(i,CLIMB);break;}
617 }break;
619 mn[i].d=(sx>0)?1:0;
620 if(canshoot(t))
621 if(abs(sx)>abs(sy)) if(shoot(i,&o,0)) break;
623 switch(t) {
624 case MN_FISH:
625 if(!(st&Z_INWATER)) {
626 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r)) {
627 mn[i].o.yv=-6;
628 mn[i].o.vx+=rand()%17-8;
629 }setst(i,PAIN);mn[i].pain+=50;break;
631 case MN_CACO: case MN_SOUL: case MN_PAIN:
632 if(abs(sy)>4) mn[i].o.yv=(sy<0)?-4:4; else mn[i].o.yv=0;
633 if(t==MN_FISH) if(mn[i].o.yv<0)
634 if(!Z_inwater(mn[i].o.x,mn[i].o.y-8,mn[i].o.r,mn[i].o.h))
635 {mn[i].o.yv=0;setst(i,RUN);mn[i].d=rand()&1;mn[i].s=20;}
636 break;
637 default:
638 if(sy<-20) if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
639 if(!(rand()&3)) mn[i].o.yv=-mnsz[t].jv;
641 if(++mn[i].s>=8) {
642 mn[i].s=0;
643 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
645 mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
646 if(st&Z_INWATER) mn[i].o.xv/=2;
647 else if(t==MN_FISH) mn[i].o.xv=0;
648 break;
649 case RUN:
650 if(st&Z_BLOCK) {setst(i,RUNOUT);mn[i].d^=1;mn[i].s=40;break;}
651 if(--mn[i].s<=0 || ((st&Z_HITWALL) && mn[i].o.yv+mn[i].o.vy==0)) {
652 setst(i,GO);mn[i].s=0;if(st&(Z_HITWALL|Z_BLOCK)) mn[i].d^=1;
653 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
654 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
655 if(st&Z_INWATER) mn[i].o.xv/=2;
656 else if(t==MN_FISH) mn[i].o.xv=0;
657 break;
658 case RUNOUT:
659 if(!(st&Z_BLOCK) && mn[i].s>0) mn[i].s=0;
660 if(--mn[i].s<=-18) {
661 setst(i,GO);mn[i].s=0;if(st&(Z_HITWALL|Z_BLOCK)) mn[i].d^=1;
662 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
663 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
664 if(st&Z_INWATER) mn[i].o.xv/=2;
665 else if(t==MN_FISH) mn[i].o.xv=0;
666 break;
667 case CLIMB:
668 if(mn[i].o.yv+mn[i].o.vy>=0 || !(st&Z_HITWALL)) {
669 setst(i,GO);mn[i].s=0;
670 if(st&(Z_HITWALL|Z_BLOCK)) {mn[i].d^=1;setst(i,RUN);mn[i].s=15;}
671 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
672 if(st&Z_INWATER) mn[i].o.xv/=2;
673 else if(t==MN_FISH) mn[i].o.xv=0;
674 break;
675 case ATTACK:
676 case SHOOT:
677 if(t==MN_SOUL) {if(st&(Z_HITWALL|Z_HITCEIL|Z_HITLAND)) setst(i,GO); break;}
678 if(t!=MN_FISH) mn[i].o.xv=Z_dec(mn[i].o.xv,1);
679 if(t==MN_VILE && mn[i].st==SHOOT) {
680 if(!Z_getobjpos(mn[i].aim,&o)) {setst(i,GO);break;}
681 if(!Z_look(&mn[i].o,&o,mn[i].d)) {setst(i,GO);break;}
682 if(Z_inwater(o.x,o.y,o.r,o.h)) {setst(i,GO);break;}
683 mn[i].tx=o.x;mn[i].ty=o.y;
684 Z_hitobj(mn[i].aim,2,i,HIT_SOME);
685 }break;
687 if(mn[i].st==REVIVE) {
688 if(--mn[i].ac==0) setst(i,GO);
689 }else ++mn[i].ac;
690 if(!mn[i].ap[mn[i].ac]) switch(mn[i].st) {
691 case ATTACK:
692 switch(t) {
693 case MN_SOUL: mn[i].ac=0;
694 case MN_IMP:
695 case MN_DEMON:
696 if(Z_hit(&mn[i].o,15,i,HIT_SOME)) if(t==MN_SOUL) setst(i,GO);
697 break;
698 case MN_FISH:
699 if(Z_hit(&mn[i].o,10,i,HIT_SOME))
700 Z_sound(snd[MN_FISH-1][2],128);
701 break;
702 case MN_SKEL: case MN_ROBO:
703 o=mn[i].o;o.xv=mn[i].d?50:-50;
704 if(Z_hit(&o,50,i,HIT_SOME)) Z_sound(pchsnd,128);
705 break;
706 case MN_VILE:
707 sx=iscorpse(&mn[i].o,1);
708 if(sx==-3) break;
709 if(!mn[sx].t || mn[sx].st!=DEAD) break;
710 setst(sx,REVIVE);Z_sound(slopsnd,128);
711 hit_xv=hit_yv=0;MN_hit(i,5,-3,HIT_SOME);
712 break;
713 }if(t!=MN_SOUL && mn[i].st!=DIE) setst(i,GO);
714 break;
715 case SHOOT:
716 switch(t) {
717 case MN_IMP:
718 WP_ball1(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
719 break;
720 case MN_ZOMBY:
721 WP_pistol(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
722 break;
723 case MN_SERG:
724 WP_shotgun(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
725 break;
726 case MN_MAN:
727 WP_dshotgun(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
728 mn[i].ammo=-36;break;
729 case MN_CYBER:
730 WP_rocket(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
731 break;
732 case MN_SKEL:
733 WP_revf(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i,mn[i].aim);
734 break;
735 case MN_CGUN:
736 case MN_SPIDER:
737 WP_mgun(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
738 break;
739 case MN_BSP:
740 WP_aplasma(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
741 break;
742 case MN_ROBO:
743 WP_plasma(mn[i].o.x+(mn[i].d*2-1)*15,mn[i].o.y-30,mn[i].tx,mn[i].ty,i);
744 break;
745 case MN_MANCUB:
746 WP_manfire(mn[i].o.x+(mn[i].d*2-1)*mn[i].o.r,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
747 break;
748 case MN_BARON: case MN_KNIGHT:
749 WP_ball7(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
750 break;
751 case MN_CACO:
752 WP_ball2(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
753 break;
754 case MN_PAIN:
755 if((sx=MN_spawn(mn[i].o.x,mn[i].o.y,mn[i].d,MN_SOUL))==-1) break;
756 Z_getobjpos(mn[sx].aim=mn[i].aim,&o);mn[sx].atm=0;
757 shoot(sx,&o,1);
758 break;
760 if(t==MN_CGUN || t==MN_SPIDER || t==MN_BSP || t==MN_MANCUB || t==MN_ROBO)
761 if(!Z_getobjpos(mn[i].aim,&o)) MN_findnewprey(i);
762 else if(shoot(i,&o,0)) break;
763 setst(i,GO);break;
764 case DIE:
765 setst(i,DEAD);
766 if(t==MN_PAIN || t==MN_SOUL) mn[i].ftime=0;
767 if(t==MN_PAIN) {
768 if((sx=MN_spawn(mn[i].o.x-15,mn[i].o.y,0,MN_SOUL))==-1) break;
769 setst(sx,GO);
770 if((sx=MN_spawn(mn[i].o.x+15,mn[i].o.y,1,MN_SOUL))==-1) break;
771 setst(sx,GO);
772 if((sx=MN_spawn(mn[i].o.x,mn[i].o.y-10,1,MN_SOUL))==-1) break;
773 setst(sx,GO);
774 }break;
775 default: mn[i].ac=0;
777 switch(mn[i].st) {
778 case GO: case RUN: case CLIMB: case RUNOUT:
779 if(t==MN_CYBER || t==MN_SPIDER || t==MN_BSP) {
780 if(mn[i].ac==0 || mn[i].ac==6) Z_sound(snd[t-1][2],128);
781 }else if(t==MN_ROBO)
782 if(mn[i].ac==0 || mn[i].ac==12) Z_sound(snd[t-1][2],128);
787 void MN_mark(void) {
788 int i;
789 for(i=0;i<MAXMN;++i) if(mn[i].t!=0) BM_mark(&mn[i].o,BM_MONSTER);
792 int MN_hit(int n,int d,int o,int t) {
793 int i;
795 if(mn[n].st==DEAD || mn[n].st==DIE) return 0;
796 if(o==n) {
797 if(t!=HIT_ROCKET && t!=HIT_ELECTRO) return 0;
798 if(mn[n].t==MN_CYBER || mn[n].t==MN_BARREL) return 1;
800 if(o>=0) {
801 if(mn[o].t==MN_SOUL && mn[n].t==MN_PAIN) return 0;
802 if(mn[o].t==mn[n].t) switch(mn[n].t) {
803 case MN_IMP: case MN_DEMON:
804 case MN_BARON: case MN_KNIGHT:
805 case MN_CACO: case MN_SOUL:
806 case MN_MANCUB: case MN_SKEL:
807 case MN_FISH:
808 return 0;
811 if(t==HIT_FLAME) if(mn[n].ftime && mn[n].fobj==o) {if(g_time&31) return 1;}
812 else {mn[n].ftime=255;mn[n].fobj=o;}
813 if(t==HIT_ELECTRO) if(mn[n].t==MN_FISH)
814 {setst(n,RUN);mn[n].s=20;mn[n].d=rand()&1;return 1;}
815 if(t==HIT_TRAP) mn[n].life=-100;
816 if(mn[n].t==MN_ROBO) d=0;
817 if((mn[n].life-=d)<=0) --mnum;
818 if(!mn[n].pain) mn[n].pain=3;
819 mn[n].pain+=d;
820 if(mn[n].st!=PAIN) {
821 if(mn[n].pain>=mnsz[mn[n].t].minp) setst(n,PAIN);
823 if(mn[n].t!=MN_BARREL)
824 DOT_blood(mn[n].o.x,mn[n].o.y-mn[n].o.h/2,hit_xv,hit_yv,d*2);
825 mn[n].aim=o;mn[n].atm=0;
826 if(mn[n].life<=0) {
827 if(mn[n].t!=MN_BARREL)
828 if(o==-1) ++pl1.kills;
829 else if(o==-2) ++pl2.kills;
830 setst(n,DIE);
831 switch(mn[n].t) {
832 case MN_ZOMBY: i=I_CLIP;break;
833 case MN_SERG: i=I_SGUN;break;
834 case MN_CGUN: i=I_MGUN;break;
835 case MN_MAN: i=I_KEYR;break;
836 default: i=0;
837 }if(i) IT_spawn(mn[n].o.x,mn[n].o.y,i);
838 mn[n].o.xv=0;mn[n].o.h=6;
839 if(mn[n].life<=-mnsz[mn[n].t].sp)
840 switch(mn[n].t) {
841 case MN_IMP: case MN_ZOMBY: case MN_SERG: case MN_CGUN:
842 case MN_MAN:
843 mn[n].ap=slopanim[mn[n].t-1];
844 Z_sound(slopsnd,128);
845 break;
846 case MN_BSP: if(g_map==9) break;
847 default:
848 Z_sound(dthsnd(mn[n].t),128);
850 else if(mn[n].t!=MN_BSP || g_map!=9) Z_sound(dthsnd(mn[n].t),128);
851 mn[n].life=0;
852 }else if(mn[n].st==SLEEP) {setst(n,GO);mn[n].pain=mnsz[mn[n].t].mp;}
853 return 1;
856 #define hit(o,x,y) (y<=o.y && y>o.y-o.h && x>=o.x-o.r && x<=o.x+o.r)
858 int Z_gunhit(int x,int y,int o,int xv,int yv) {
859 int i;
861 if(o!=-1) if(hit(pl1.o,x,y)) if(PL_hit(&pl1,3,o,HIT_SOME))
862 {pl1.o.vx+=xv;pl1.o.vy+=yv;return -1;}
863 if(_2pl && o!=-2) if(hit(pl2.o,x,y)) if(PL_hit(&pl2,3,o,HIT_SOME))
864 {pl2.o.vx+=xv;pl2.o.vy+=yv;return -2;}
866 for(i=0;i<MAXMN;++i) if(mn[i].t && o!=i)
867 if(hit(mn[i].o,x,y)) if(MN_hit(i,3,o,HIT_SOME))
868 {mn[i].o.vx+=xv;mn[i].o.vy+=yv;return 1;}
869 return 0;
872 static void goodsnd(void) {
873 if(!g_dm) return;
874 gsndt=18;
877 int Z_hit(obj_t *o,int d,int own,int t) {
878 int i;
880 hit_xv=o->xv+o->vx;
881 hit_yv=o->yv+o->vy;
882 if(Z_overlap(o,&pl1.o)) if(PL_hit(&pl1,d,own,t)) {
883 pl1.o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
884 pl1.o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
885 if(t==HIT_BFG) goodsnd();
886 return -1;
888 if(_2pl) if(Z_overlap(o,&pl2.o)) if(PL_hit(&pl2,d,own,t)) {
889 pl2.o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
890 pl2.o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
891 if(t==HIT_BFG) goodsnd();
892 return -2;
895 for(i=0;i<MAXMN;++i) if(mn[i].t)
896 if(Z_overlap(o,&mn[i].o)) if(MN_hit(i,d,own,t)) {
897 mn[i].o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
898 mn[i].o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
899 return 1;
901 return 0;
904 void MN_killedp(void) {
905 int i;
907 for(i=0;i<MAXMN;++i) if(mn[i].t==MN_MAN)
908 if(mn[i].st!=DEAD && mn[i].st!=DIE && mn[i].st!=SLEEP)
909 Z_sound(trupsnd,128);
912 int Z_hitobj(int obj,int d,int own,int t) {
913 hit_xv=hit_yv=0;
914 if(obj==-1) return PL_hit(&pl1,d,own,t);
915 else if(obj==-2 && _2pl) return PL_hit(&pl2,d,own,t);
916 else if(obj<0 || obj>=MAXMN) return 0;
917 if(mn[obj].t) return MN_hit(obj,d,own,t);
918 return 0;
921 void Z_explode(int x,int y,int rad,int own) {
922 long r;
923 int dx,dy,m,i;
925 if(x<-100 || x>FLDW*CELW+100) return;
926 if(y<-100 || y>FLDH*CELH+100) return;
927 r=(long)rad*rad;
928 dx=pl1.o.x-x;dy=pl1.o.y-pl1.o.h/2-y;
929 if((long)dx*dx+(long)dy*dy<r) {
930 if(!(m=max(abs(dx),abs(dy)))) m=1;
931 pl1.o.vx+=hit_xv=dx*10/m;
932 pl1.o.vy+=hit_yv=dy*10/m;
933 PL_hit(&pl1,100*(rad-m)/rad,own,HIT_ROCKET);
935 if(_2pl) {
936 dx=pl2.o.x-x;dy=pl2.o.y-pl2.o.h/2-y;
937 if((long)dx*dx+(long)dy*dy<r) {
938 if(!(m=max(abs(dx),abs(dy)))) m=1;
939 pl2.o.vx+=hit_xv=dx*10/m;
940 pl2.o.vy+=hit_yv=dy*10/m;
941 PL_hit(&pl2,100*(rad-m)/rad,own,HIT_ROCKET);
944 for(i=0;i<MAXMN;++i) if(mn[i].t) {
945 dx=mn[i].o.x-x;dy=mn[i].o.y-mn[i].o.h/2-y;
946 if((long)dx*dx+(long)dy*dy<r) {
947 if(!(m=max(abs(dx),abs(dy)))) m=1;
948 mn[i].o.vx+=hit_xv=dx*10/m;
949 mn[i].o.vy+=hit_yv=dy*10/m;
950 MN_hit(i,mn[i].o.r*10*(rad-m)/rad,own,HIT_ROCKET);
955 void Z_bfg9000(int x,int y,int own) {
956 int dx,dy,i;
958 hit_xv=hit_yv=0;
959 if(x<-100 || x>FLDW*CELW+100) return;
960 if(y<-100 || y>FLDH*CELH+100) return;
961 dx=pl1.o.x-x;dy=pl1.o.y-pl1.o.h/2-y;
962 if(own!=-1) if((long)dx*dx+(long)dy*dy<16000)
963 if(Z_cansee(x,y,pl1.o.x,pl1.o.y-pl1.o.h/2)) {
964 if(PL_hit(&pl1,50,own,HIT_SOME))
965 WP_bfghit(pl1.o.x,pl1.o.y-pl1.o.h/2,own);
967 if(_2pl) {
968 dx=pl2.o.x-x;dy=pl2.o.y-pl2.o.h/2-y;
969 if(own!=-2) if((long)dx*dx+(long)dy*dy<16000)
970 if(Z_cansee(x,y,pl2.o.x,pl2.o.y-pl2.o.h/2)) {
971 if(PL_hit(&pl2,50,own,HIT_SOME))
972 WP_bfghit(pl2.o.x,pl2.o.y-pl2.o.h/2,own);
975 for(i=0;i<MAXMN;++i) if(mn[i].t && own!=i) {
976 dx=mn[i].o.x-x;dy=mn[i].o.y-mn[i].o.h/2-y;
977 if((long)dx*dx+(long)dy*dy<16000)
978 if(Z_cansee(x,y,mn[i].o.x,mn[i].o.y-mn[i].o.h/2)) {
979 if(MN_hit(i,50,own,HIT_SOME))
980 WP_bfghit(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,own);
985 int Z_chktrap(int t,int d,int o,int ht) {
986 int i,s;
988 hit_xv=hit_yv=0;
989 s=0;
990 if(Z_istrapped(pl1.o.x,pl1.o.y,pl1.o.r,pl1.o.h)) {
991 s=1;
992 if(t) PL_hit(&pl1,d,o,ht);
994 if(_2pl) if(Z_istrapped(pl2.o.x,pl2.o.y,pl2.o.r,pl2.o.h)) {
995 s=1;
996 if(t) PL_hit(&pl2,d,o,ht);
998 for(i=0;i<MAXMN;++i) if(mn[i].t && mn[i].st!=DEAD)
999 if(Z_istrapped(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h)) {
1000 s=1;
1001 if(t) MN_hit(i,d,o,ht);
1003 return s;
1006 void Z_teleobj(int o,int x,int y) {
1007 obj_t *p;
1009 if(o==-1) p=&pl1.o;
1010 else if(o==-2) p=&pl2.o;
1011 else if(o>=0 && o<MAXMN) p=&mn[o].o;
1012 else return;
1013 FX_tfog(p->x,p->y);FX_tfog(p->x=x,p->y=y);
1014 Z_sound(telesnd,128);
1017 void MN_warning(int l,int t,int r,int b) {
1018 int i;
1020 for(i=0;i<MAXMN;++i) if(mn[i].t && mn[i].t!=MN_CACO && mn[i].t!=MN_SOUL
1021 && mn[i].t!=MN_PAIN && mn[i].t!=MN_FISH)
1022 if(mn[i].st!=DIE && mn[i].st!=DEAD && mn[i].st!=SLEEP)
1023 if(mn[i].o.x+mn[i].o.r>=l && mn[i].o.x-mn[i].o.r<=r
1024 && mn[i].o.y>=t && mn[i].o.y-mn[i].o.h<=b)
1025 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
1026 mn[i].o.yv=-mnsz[mn[i].t].jv;