DEADSOFTWARE

fully move highter level rendering code in separate file
[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 "vga.h"
27 #include "files.h"
28 #include "view.h"
29 #include "bmap.h"
30 #include "dots.h"
31 #include "weapons.h"
32 #include "player.h"
33 #include "monster.h"
34 #include "items.h"
35 #include "switch.h"
36 #include "misc.h"
37 #include "fx.h"
38 #include "smoke.h"
39 #include "my.h"
41 #define MAX_ATM 90
43 extern byte z_mon;
45 enum{
46 SLEEP,GO,RUN,CLIMB,DIE,DEAD,ATTACK,SHOOT,PAIN,WAIT,REVIVE,RUNOUT
47 };
49 typedef struct{
50 int r,h,l,mp,rv,jv,sp,minp;
51 }mnsz_t;
53 byte nomon=1;
55 static char *sleepanim[MN_TN]={
56 "AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB",
57 "A","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB",
58 "A","A","AAABBB"
59 }, *goanim[MN_TN]={
60 "AABBCCDD","AABBCCDD","AABBDDAACCDD","AABBDDAACCDD","AABBDDCCDDBB",
61 "AABBDDAACCDD","AABBCCDD","AABBCCDD","A","AABB","AABBCCBB",
62 "AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF",
63 "AABB","A","DDEEFFGGHHIIJJKKLLAABBCC","ACDABD"
64 }, *painanim[MN_TN]={
65 "H","H","G","G","G","G","H","H","F","E","G","I","I","J","L","Q","EECCDDCC",
66 "A","D","G"
67 }, *waitanim[MN_TN]={
68 "A","A","A","A","A","A","A","A","A","AABB","A","A","A","I","K","A","A",
69 "A","D","E"
70 }, *attackanim[MN_TN]={
71 "EEFFGG","EEFFGG","EEEEEF","EEEEEF","EEEEEF","EF","EEFFGG","EEFFGG",
72 "BBCCDD","CCDD","DDEEFF","GH","GH","GGGGHH","GGHHII",
73 "QQGGGHHHIIJJKKLLMMNNOOPP","BBFFAA","A","OOPPQQ","EEEEFF"
74 }, *dieanim[MN_TN]={
75 "IIIJJJKKKLLLMMM","IIIJJJKKKLLL","HHHIIIJJJKKK","HHHIIIJJJKKK",
76 "HHHIIIJJJKKKLLLMMMNNNOOO","HHHIIIJJJKKKLLLMMM",
77 "IIIJJJKKKLLLMMMNNN","IIIJJJKKKLLLMMMNNN","GGGHHHIIIJJJKKK",
78 "FFFGGGHHHIIIJJJKKK","HHHIIIJJJKKKLLLMMM",
79 "JJJJKKKKLLLLMMMMNNNNOOOOPPPPQQQQRRRR","JJJKKKLLLMMMNNNOOO",
80 "KKKLLLMMMNNNOOOPPPRRRSSS","MMMNNNOOOPPP","RRRSSSTTTUUUVVVWWWXXXYYY",
81 "DDDD","CCCDDDEEEFFFGGG","D","HHHHIIIIJJJJKKKKLLLLMMMM"
82 }, *slopanim[MN_TN]={
83 "","NNNOOOPPPRRRSSSTTT","MMMNNNOOOPPPRRRSSSTTT","MMMNNNOOOPPPRRRSSSTTT","",
84 "OOOPPPQQQRRRSSS","","","","","","","","","","","","","","OOPPQQRRSSTTUUVV"
85 }, *deadanim[MN_TN]={
86 "N","M","L","L","P","N","O","O","L","","","S","P","T","Q","Z","C","","D","N"
87 }, *messanim[MN_TN]={
88 "","U","U","U","","T","","","","","","","","","","","","","","W"
89 };
91 int hit_xv,hit_yv;
92 mn_t mn[MAXMN];
94 static void *fsnd,*pauksnd,*trupsnd;
95 static void *snd[MN_TN][5],*impsitsnd[2],*impdthsnd[2],*firsnd,*slopsnd,*gsnd[4];
96 static void *swgsnd,*pchsnd,*telesnd;
97 static void *positsnd[3],*podthsnd[3];
98 static int mnum,gsndt;
99 static mnsz_t mnsz[MN_TN+1]={
100 //rad ht life pain rv jv slop min_pn
101 0, 0, 0, 0, 0, 0, 0, 0, // none
102 15, 28, 60, 20, 7,10, 0, 10, // demon
103 10, 28, 25, 15, 3,10, 30, 0, // imp
104 10, 28, 15, 10, 3,10, 30, 0, // zomby
105 10, 28, 20, 10, 3,10, 30, 0, // sergeant
106 20, 55, 500, 70, 5,10, 0, 50, // cyberdemon
107 12, 28, 60, 20, 3,10, 30, 10, // chaingunner
108 12, 32, 150, 40, 3,10, 0, 30, // baron of hell
109 12, 32, 75, 40, 3,10, 0, 30, // hell knight
110 15, 28, 100, 10, 4, 4, 0, 0, // cacodemon
111 8, 18, 60, 10, 4, 4, 0, 0, // lost soul
112 15, 28, 100, 10, 4, 4, 0, 0, // pain elemental
113 64, 50, 500, 70, 4,10, 0, 50, // spider mastermind
114 25, 27, 150, 20, 4,10, 0, 0, // arachnotron
115 18, 30, 200, 40, 3, 7, 0, 20, // mancubus
116 17, 36, 200, 40, 6,11, 0, 20, // revenant
117 17, 36, 150, 30, 7,12, 0, 10, // archvile
118 5, 5, 35, 20,14, 6, 0, 10, // fish
119 5, 17, 20, 0, 7, 6, 0, 0, // barrel
120 17, 38, 20, 40, 3, 6, 0, 20, // robot
121 8, 26, 400, 70, 8,10, 30, 50 // man
122 };
124 void MN_savegame (FILE *h) {
125 int i, n;
126 for (n = MAXMN - 1; n >= 0 && mn[n].t == 0; n--) {
127 // empty
129 n += 1;
130 myfwrite32(n, h);
131 for (i = 0; i < n; i++) {
132 myfwrite32(mn[i].o.x, h);
133 myfwrite32(mn[i].o.y, h);
134 myfwrite32(mn[i].o.xv, h);
135 myfwrite32(mn[i].o.yv, h);
136 myfwrite32(mn[i].o.vx, h);
137 myfwrite32(mn[i].o.vy, h);
138 myfwrite32(mn[i].o.r, h);
139 myfwrite32(mn[i].o.h, h);
140 myfwrite8(mn[i].t, h);
141 myfwrite8(mn[i].d, h);
142 myfwrite8(mn[i].st, h);
143 myfwrite8(mn[i].ftime, h);
144 myfwrite32(mn[i].fobj, h);
145 myfwrite32(mn[i].s, h);
146 myfwrite32(0, h); // mn[i].ap useless, changed after load
147 myfwrite32(mn[i].aim, h);
148 myfwrite32(mn[i].life, h);
149 myfwrite32(mn[i].pain, h);
150 myfwrite32(mn[i].ac, h);
151 myfwrite32(mn[i].tx, h);
152 myfwrite32(mn[i].ty, h);
153 myfwrite32(mn[i].ammo, h);
154 myfwrite16(mn[i].atm, h);
156 myfwrite32(mnum, h);
157 myfwrite32(gsndt, h);
160 static void setst(int,int);
162 static int MN_hit(int n,int d,int o,int t);
164 void MN_loadgame (FILE *h) {
165 int i, n, c;
166 n = myfread32(h);
167 for (i = 0; i < n; i++) {
168 mn[i].o.x = myfread32(h);
169 mn[i].o.y = myfread32(h);
170 mn[i].o.xv = myfread32(h);
171 mn[i].o.yv = myfread32(h);
172 mn[i].o.vx = myfread32(h);
173 mn[i].o.vy = myfread32(h);
174 mn[i].o.r = myfread32(h);
175 mn[i].o.h = myfread32(h);
176 mn[i].t = myfread8(h);
177 mn[i].d = myfread8(h);
178 mn[i].st = myfread8(h);
179 mn[i].ftime = myfread8(h);
180 mn[i].fobj = myfread32(h);
181 mn[i].s = myfread32(h);
182 mn[i].ap = NULL; myfread32(h); // useless, changed after loading
183 mn[i].aim = myfread32(h);
184 mn[i].life = myfread32(h);
185 mn[i].pain = myfread32(h);
186 mn[i].ac = myfread32(h);
187 mn[i].tx = myfread32(h);
188 mn[i].ty = myfread32(h);
189 mn[i].ammo = myfread32(h);
190 mn[i].atm = myfread16(h);
192 mnum = myfread32(h);
193 gsndt = myfread32(h);
194 for (n = 0; n < MAXMN; ++n) {
195 if (mn[n].t) {
196 c = mn[n].ac;
197 setst(n, mn[n].st);
198 mn[n].ac = c;
203 #define GGAS_TOTAL (MN__LAST-MN_DEMON+16+10)
205 void MN_alloc(void) {
206 int i,j;
207 static char sn[MN_TN][5][6]={
208 {"DMACT","DMPAIN","SGTATK","SGTSIT","SGTDTH"},
209 {"BGACT","POPAIN","CLAW","",""},
210 {"POSACT","POPAIN","","",""},
211 {"POSACT","POPAIN","","",""},
212 {"","DMPAIN","HOOF","CYBSIT","CYBDTH"},
213 {"POSACT","POPAIN","","",""},
214 {"","DMPAIN","","BRSSIT","BRSDTH"},
215 {"","DMPAIN","","KNTSIT","KNTDTH"},
216 {"DMACT","DMPAIN","","CACSIT","CACDTH"},
217 {"DMACT","DMPAIN","SKLATK","SKLATK","FIRXPL"},
218 {"DMACT","PEPAIN","","PESIT","PEDTH"},
219 {"","DMPAIN","METAL","SPISIT","SPIDTH"},
220 {"BSPACT","DMPAIN","BSPWLK","BSPSIT","BSPDTH"},
221 {"DMACT","MNPAIN","MANATK","MANSIT","MANDTH"},
222 {"SKEACT","POPAIN","SKEATK","SKESIT","SKEDTH"},
223 {"VILACT","VIPAIN","VILATK","VILSIT","VILDTH"},
224 {"","","BITE1","",""},
225 {"","","","","BAREXP"},
226 {"BSPACT","","BSPWLK","BSPSIT","BSPDTH"},
227 {"HAHA1","PLPAIN","","STOP1","PDIEHI"}
228 };
229 static char gsn[6]="GOOD0";
230 for(j=0;j<MN_TN;++j) {
231 for(i=0;i<5;++i)
232 if(sn[j][i][0])
233 snd[j][i]=Z_getsnd(sn[j][i]);
234 else
235 snd[j][i]=NULL;
236 logo_gas(j+5,GGAS_TOTAL);
238 impsitsnd[0]=Z_getsnd("BGSIT1");
239 impsitsnd[1]=Z_getsnd("BGSIT2");
240 impdthsnd[0]=Z_getsnd("BGDTH1");
241 impdthsnd[1]=Z_getsnd("BGDTH2");
242 positsnd[0]=Z_getsnd("POSIT1");
243 positsnd[1]=Z_getsnd("POSIT2");
244 positsnd[2]=Z_getsnd("POSIT3");
245 podthsnd[0]=Z_getsnd("PODTH1");
246 podthsnd[1]=Z_getsnd("PODTH2");
247 podthsnd[2]=Z_getsnd("PODTH3");
248 fsnd=Z_getsnd("FLAME");
249 firsnd=Z_getsnd("FIRSHT");
250 slopsnd=Z_getsnd("SLOP");
251 swgsnd=Z_getsnd("SKESWG");
252 pchsnd=Z_getsnd("SKEPCH");
253 telesnd=Z_getsnd("TELEPT");
254 pauksnd=Z_getsnd("PAUK1");
255 trupsnd=Z_getsnd("UTRUP");
256 for(i=0;i<4;++i) {gsn[4]=i+'1';gsnd[i]=Z_getsnd(gsn);}
259 void MN_init(void) {
260 int i;
262 for(i=0;i<MAXMN;++i) {mn[i].t=0;mn[i].st=SLEEP;}
263 gsndt=mnum=0;
266 static void setst(int i,int st) {
267 char *a;
268 int t;
270 switch(mn[i].st) {
271 case DIE: case DEAD:
272 if(st!=DEAD && st!=REVIVE) return;
274 mn[i].ac=0;
275 t=mn[i].t-1;
276 switch(mn[i].st=st) {
277 case SLEEP: a=sleepanim[t];break;
278 case PAIN: a=painanim[t];break;
279 case WAIT: a=waitanim[t];break;
280 case CLIMB:
281 case RUN: case RUNOUT:
282 case GO: a=goanim[t];break;
283 case SHOOT:
284 if(t==MN_SKEL-1) {a="KKKKJJ";break;}
285 if(t==MN_ROBO-1) {a="MN";break;}
286 case ATTACK: a=attackanim[t];
287 if(st==ATTACK && t==MN_VILE-1) a="[[\\\\]]";
288 break;
289 case DIE:
290 if(g_map==9 && t==MN_BSP-1) Z_sound(pauksnd,128);
291 a=dieanim[t];break;
292 case DEAD:
293 a=deadanim[t];
294 if(mn[i].ap==slopanim[t]) a=messanim[t];
295 if(t==MN_BARREL-1) {mn[i].t=0;}
296 break;
297 case REVIVE:
298 a=(mn[i].ap==messanim[t])?slopanim[t]:dieanim[t];
299 mn[i].ac=strlen(a)-1;
300 mn[i].o.r=mnsz[t+1].r;mn[i].o.h=mnsz[t+1].h;
301 mn[i].life=mnsz[t+1].l;mn[i].ammo=mn[i].pain=0;
302 ++mnum;
303 break;
305 mn[i].ap=a;
308 int MN_spawn(int x,int y,byte d,int t) {
309 int i;
311 if(g_dm && nomon && t<MN_PL_DEAD) return -1;
312 for(i=0;i<MAXMN;++i) if(!mn[i].t) goto ok;
313 for(i=0;i<MAXMN;++i) if(mn[i].t>=MN_PL_DEAD) goto ok;
314 return -1;
315 ok:
316 mn[i].o.x=x;mn[i].o.y=y;
317 mn[i].o.xv=mn[i].o.yv=mn[i].o.vx=mn[i].o.vy=0;
318 mn[i].d=d;mn[i].t=t;
319 mn[i].st=SLEEP;
320 if(t<MN_PL_DEAD) {
321 mn[i].o.r=mnsz[t].r;mn[i].o.h=mnsz[t].h;
322 mn[i].life=mnsz[t].l;
323 setst(i,SLEEP);mn[i].s=myrand(18);
324 ++mnum;
325 }else {mn[i].o.r=8;mn[i].o.h=6;mn[i].life=0;mn[i].st=DEAD;}
326 mn[i].aim=-3;mn[i].atm=0;
327 mn[i].pain=0;
328 mn[i].ammo=0;
329 mn[i].ftime=0;
330 return i;
333 int MN_spawn_deadpl(obj_t *o,byte c,int t) {
334 int i;
336 if((i=MN_spawn(o->x,o->y,c,t+MN_PL_DEAD))==-1) return -1;
337 mn[i].o=*o;return i;
340 static int isfriend(int a,int b) {
341 if(a==MN_BARREL || b==MN_BARREL) return 1;
342 if(a==b) switch(a) {
343 case MN_IMP: case MN_DEMON:
344 case MN_BARON: case MN_KNIGHT:
345 case MN_CACO: case MN_SOUL:
346 case MN_MANCUB: case MN_SKEL:
347 case MN_FISH:
348 return 1;
350 if(a==MN_SOUL && b==MN_PAIN) return 1;
351 if(b==MN_SOUL && a==MN_PAIN) return 1;
352 return 0;
355 static int MN_findnewprey(int i) {
356 int a,b,l;
358 a=!PL_isdead(&pl1);
359 if(_2pl) b=!PL_isdead(&pl2); else b=0;
360 if(a) {
361 if(b) mn[i].aim=(abs(mn[i].o.x-pl1.o.x)+abs(mn[i].o.y-pl1.o.y)
362 <= abs(mn[i].o.x-pl2.o.x)+abs(mn[i].o.y-pl2.o.y))?-1:-2;
363 else mn[i].aim=-1;
364 }else{
365 if(b) mn[i].aim=-2;
366 else{
367 for(a=0,b=32000,mn[i].aim=-3;a<MAXMN;++a)
368 if(mn[a].t && mn[a].st!=DEAD && a!=i && !isfriend(mn[a].t,mn[i].t))
369 if((l=abs(mn[i].o.x-mn[a].o.x)+abs(mn[i].o.y-mn[a].o.y))<b)
370 {mn[i].aim=a;b=l;}
371 if(mn[i].aim<0) {mn[i].atm=MAX_ATM;return 0;} else mn[i].atm=0;
374 return 1;
377 int Z_getobjpos(int i,obj_t *o) {
378 if(i==-1) {*o=pl1.o;return !PL_isdead(&pl1);}
379 if(_2pl) if(i==-2) {*o=pl2.o;return !PL_isdead(&pl2);}
380 if(i>=0 && i<MAXMN) if(mn[i].t && mn[i].st!=DEAD)
381 {*o=mn[i].o;return 1;}
382 return 0;
385 static void *wakeupsnd(int t) {
386 switch(t) {
387 case MN_IMP: return impsitsnd[myrand(2)];
388 case MN_ZOMBY: case MN_SERG: case MN_CGUN:
389 return positsnd[myrand(3)];
391 return snd[t-1][3];
394 static void *dthsnd(int t) {
395 switch(t) {
396 case MN_IMP: return impdthsnd[myrand(2)];
397 case MN_ZOMBY: case MN_SERG: case MN_CGUN:
398 return podthsnd[myrand(3)];
400 return snd[t-1][4];
403 static int canshoot(int t) {
404 switch(t) {
405 case MN_DEMON: case MN_FISH: case MN_BARREL:
406 return 0;
408 return 1;
411 static int shoot(int i,obj_t *o,int n) {
412 int xd,yd,m;
414 if(mn[i].ammo<0) return 0;
415 if(!n) switch(mn[i].t) {
416 case MN_FISH: case MN_BARREL:
417 case MN_DEMON: return 0;
418 case MN_CGUN:
419 case MN_BSP:
420 case MN_ROBO:
421 if(++mn[i].ammo>=50) mn[i].ammo=(mn[i].t==MN_ROBO)?-200:-50;
422 break;
423 case MN_MAN:
424 break;
425 case MN_MANCUB:
426 if(++mn[i].ammo>=5) mn[i].ammo=-50;
427 break;
428 case MN_SPIDER:
429 if(++mn[i].ammo>=100) mn[i].ammo=-50;
430 break;
431 case MN_CYBER:
432 if(rand()&1) return 0;
433 if(++mn[i].ammo>=10) mn[i].ammo=-50;
434 break;
435 case MN_BARON: case MN_KNIGHT:
436 if(rand()&7) return 0;
437 break;
438 case MN_SKEL:
439 if(rand()&31) return 0;
440 break;
441 case MN_VILE:
442 if(rand()&7) return 0;
443 break;
444 case MN_PAIN:
445 if(rand()&7) return 0;
446 break;
447 default:
448 if(rand()&15) return 0;
450 if(!Z_look(&mn[i].o,o,mn[i].d)) return 0;
451 mn[i].atm=0;
452 mn[i].tx=o->x+(o->xv+o->vx)*6;mn[i].ty=o->y-o->h/2+(o->yv+o->vy)*6;
453 if(abs(mn[i].tx-mn[i].o.x)<abs(mn[i].ty-mn[i].o.y+mn[i].o.h/2)) return 0;
454 switch(mn[i].t) {
455 case MN_IMP: case MN_BARON: case MN_KNIGHT: case MN_CACO:
456 setst(i,SHOOT);Z_sound(firsnd,128);break;
457 case MN_SKEL:
458 setst(i,SHOOT);Z_sound(snd[MN_SKEL-1][2],128);break;
459 case MN_VILE:
460 mn[i].tx=o->x;mn[i].ty=o->y;
461 setst(i,SHOOT);Z_sound(fsnd,128);
462 Z_sound(snd[MN_VILE-1][2],128);break;
463 case MN_SOUL:
464 setst(i,ATTACK);Z_sound(snd[MN_SOUL-1][2],128);
465 yd=mn[i].ty-mn[i].o.y+mn[i].o.h/2;xd=mn[i].tx-mn[i].o.x;
466 if(!(m=max(abs(xd),abs(yd)))) m=1;
467 mn[i].o.xv=xd*16/m;mn[i].o.yv=yd*16/m;
468 break;
469 case MN_MANCUB: if(mn[i].ammo==1) Z_sound(snd[MN_MANCUB-1][2],128);
470 case MN_ZOMBY: case MN_SERG: case MN_BSP: case MN_ROBO:
471 case MN_CYBER: case MN_CGUN: case MN_SPIDER:
472 case MN_PAIN: case MN_MAN:
473 setst(i,SHOOT);break;
474 default:
475 return 0;
477 return 1;
480 static int kick(int i,obj_t *o) {
481 switch(mn[i].t) {
482 case MN_FISH:
483 setst(i,ATTACK);return 1;
484 case MN_DEMON:
485 setst(i,ATTACK);Z_sound(snd[0][2],128);return 1;
486 case MN_IMP:
487 setst(i,ATTACK);Z_sound(snd[1][2],128);return 1;
488 case MN_SKEL:
489 setst(i,ATTACK);Z_sound(swgsnd,128);return 1;
490 case MN_ROBO:
491 setst(i,ATTACK);Z_sound(swgsnd,128);return 1;
492 case MN_BARON: case MN_KNIGHT: case MN_CACO: case MN_MANCUB:
493 return shoot(i,o,1);
495 return 0;
498 static int iscorpse(obj_t *o,int n) {
499 int i;
501 if(!n) if(rand()&7) return -3;
502 for(i=0;i<MAXMN;++i) if(mn[i].t) if(mn[i].st==DEAD)
503 if(Z_overlap(o,&mn[i].o)) switch(mn[i].t) {
504 case MN_SOUL: case MN_PAIN:
505 case MN_CYBER: case MN_SPIDER:
506 case MN_PL_DEAD: case MN_PL_MESS:
507 case MN_VILE: case MN_BARREL:
508 continue;
509 default:
510 return i;
512 return -3;
515 void MN_act(void) {
516 int i,st,sx,sy,t;
517 static obj_t o;
518 static int pt_x=0,pt_xs=1,pt_y=0,pt_ys=1;
520 if(abs(pt_x+=pt_xs) > 123) pt_xs=-pt_xs;
521 if(abs(pt_y+=pt_ys) > 50) pt_ys=-pt_ys;
522 if(gsndt>0) if(--gsndt==0) {
523 Z_sound(gsnd[myrand(4)],128);
525 for(i=0;i<MAXMN;++i) if((t=mn[i].t)!=0) {
526 switch(t) {
527 case MN_FISH:
528 if(!Z_inwater(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h)) break;
529 case MN_SOUL: case MN_PAIN: case MN_CACO:
530 if(mn[i].st!=DIE && mn[i].st!=DEAD) --mn[i].o.yv;
531 break;
532 }z_mon=1;st=Z_moveobj(&mn[i].o);z_mon=0;
533 BM_mark(&mn[i].o,BM_MONSTER);
534 if(st&Z_FALLOUT) {
535 if(t==MN_ROBO) g_exit=1;
536 mn[i].t=0;--mnum;continue;
538 if(st&Z_HITWATER) Z_splash(&mn[i].o,mn[i].o.r+mn[i].o.h);
539 SW_press(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h,8,i);
540 if(mn[i].ftime) {
541 --mn[i].ftime;
542 SMK_flame(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,
543 mn[i].o.xv+mn[i].o.vx,mn[i].o.yv+mn[i].o.vy,
544 mn[i].o.r/2,mn[i].o.h/2,rand()%(200*2+1)-200,-500,1,mn[i].fobj);
546 if(st&Z_INWATER) mn[i].ftime=0;
547 if(mn[i].st==DEAD) continue;
548 if(st&Z_INWATER) if(!(rand()&31)) switch(t) {
549 case MN_FISH:
550 if(rand()&3) break;
551 case MN_ROBO: case MN_BARREL:
552 case MN_PL_DEAD: case MN_PL_MESS:
553 FX_bubble(mn[i].o.x+((rand()&1)*2-1)*myrand(mn[i].o.r+1),
554 mn[i].o.y-myrand(mn[i].o.h+1),0,0,1
555 );
556 break;
557 default:
558 FX_bubble(mn[i].o.x,mn[i].o.y-mn[i].o.h*3/4,0,0,5);
561 if(t==MN_BARREL) {
563 if(!mn[i].ap[++mn[i].ac]) {
564 mn[i].ac=0;if(mn[i].st==DIE || mn[i].st==DEAD) {mn[i].t=0;}
565 }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);
566 continue;
568 if(t==MN_SOUL) if(st&Z_HITAIR) Z_set_speed(&mn[i].o,16);
569 if(mn[i].ammo<0) ++mn[i].ammo;
570 if(mn[i].o.yv<0)
571 if(st&Z_INWATER) mn[i].o.yv=-4;
572 ++mn[i].atm;
573 switch(mn[i].st) {
574 case PAIN:
575 if(mn[i].pain>=mnsz[t].mp)
576 {mn[i].pain=mnsz[t].mp;Z_sound(snd[t-1][1],128);}
577 if((mn[i].pain-=5)<=mnsz[t].minp)
578 {setst(i,GO);mn[i].pain=0;mn[i].ammo=-9;}
579 break;
580 case SLEEP:
581 if(++mn[i].s>=18) mn[i].s=0; else break;
582 if(Z_look(&mn[i].o,&pl1.o,mn[i].d))
583 {setst(i,GO);mn[i].aim=-1;mn[i].atm=0;Z_sound(wakeupsnd(t),128);}
584 if(_2pl) if(Z_look(&mn[i].o,&pl2.o,mn[i].d))
585 {setst(i,GO);mn[i].aim=-2;mn[i].atm=0;Z_sound(wakeupsnd(t),128);}
586 break;
587 case WAIT:
588 if(--mn[i].s<0) setst(i,GO);
589 break;
590 case GO:
591 if(st&Z_BLOCK) {mn[i].d^=1;setst(i,RUNOUT);mn[i].s=40;break;}
592 if(t==MN_VILE) if(iscorpse(&mn[i].o,0)>=0) {
593 setst(i,ATTACK);mn[i].o.xv=0;break;
595 if(!Z_getobjpos(mn[i].aim,&o) || mn[i].atm>MAX_ATM)
596 if(!MN_findnewprey(i)) {
597 mn[i].aim=-3;
598 o.x=mn[i].o.x+pt_x;o.y=mn[i].o.y+pt_y;
599 o.xv=o.vx=o.yv=o.vy=o.r=0;o.h=1;
600 }else Z_getobjpos(mn[i].aim,&o);
601 if(Z_overlap(&mn[i].o,&o)) {
602 mn[i].atm=0;
603 if(kick(i,&o)) break;
605 sx=o.x-mn[i].o.x;
606 sy=o.y-o.h/2-mn[i].o.y+mn[i].o.h/2;
607 if(!(st&Z_BLOCK)) if(abs(sx)<20)
608 if(t!=MN_FISH) {setst(i,RUN);mn[i].s=15;mn[i].d=rand()&1;break;}
609 if(st&Z_HITWALL) {
610 if(SW_press(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h,2,i))
611 {setst(i,WAIT);mn[i].s=4;break;}
612 switch(t) {
613 case MN_CACO: case MN_SOUL: case MN_PAIN: case MN_FISH:
614 break;
615 default:
616 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
617 {mn[i].o.yv=-mnsz[t].jv;setst(i,CLIMB);break;}
618 }break;
620 mn[i].d=(sx>0)?1:0;
621 if(canshoot(t))
622 if(abs(sx)>abs(sy)) if(shoot(i,&o,0)) break;
624 switch(t) {
625 case MN_FISH:
626 if(!(st&Z_INWATER)) {
627 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r)) {
628 mn[i].o.yv=-6;
629 mn[i].o.vx+=rand()%17-8;
630 }setst(i,PAIN);mn[i].pain+=50;break;
632 case MN_CACO: case MN_SOUL: case MN_PAIN:
633 if(abs(sy)>4) mn[i].o.yv=(sy<0)?-4:4; else mn[i].o.yv=0;
634 if(t==MN_FISH) if(mn[i].o.yv<0)
635 if(!Z_inwater(mn[i].o.x,mn[i].o.y-8,mn[i].o.r,mn[i].o.h))
636 {mn[i].o.yv=0;setst(i,RUN);mn[i].d=rand()&1;mn[i].s=20;}
637 break;
638 default:
639 if(sy<-20) if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
640 if(!(rand()&3)) mn[i].o.yv=-mnsz[t].jv;
642 if(++mn[i].s>=8) {
643 mn[i].s=0;
644 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
646 mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
647 if(st&Z_INWATER) mn[i].o.xv/=2;
648 else if(t==MN_FISH) mn[i].o.xv=0;
649 break;
650 case RUN:
651 if(st&Z_BLOCK) {setst(i,RUNOUT);mn[i].d^=1;mn[i].s=40;break;}
652 if(--mn[i].s<=0 || ((st&Z_HITWALL) && mn[i].o.yv+mn[i].o.vy==0)) {
653 setst(i,GO);mn[i].s=0;if(st&(Z_HITWALL|Z_BLOCK)) mn[i].d^=1;
654 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
655 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
656 if(st&Z_INWATER) mn[i].o.xv/=2;
657 else if(t==MN_FISH) mn[i].o.xv=0;
658 break;
659 case RUNOUT:
660 if(!(st&Z_BLOCK) && mn[i].s>0) mn[i].s=0;
661 if(--mn[i].s<=-18) {
662 setst(i,GO);mn[i].s=0;if(st&(Z_HITWALL|Z_BLOCK)) mn[i].d^=1;
663 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
664 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
665 if(st&Z_INWATER) mn[i].o.xv/=2;
666 else if(t==MN_FISH) mn[i].o.xv=0;
667 break;
668 case CLIMB:
669 if(mn[i].o.yv+mn[i].o.vy>=0 || !(st&Z_HITWALL)) {
670 setst(i,GO);mn[i].s=0;
671 if(st&(Z_HITWALL|Z_BLOCK)) {mn[i].d^=1;setst(i,RUN);mn[i].s=15;}
672 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
673 if(st&Z_INWATER) mn[i].o.xv/=2;
674 else if(t==MN_FISH) mn[i].o.xv=0;
675 break;
676 case ATTACK:
677 case SHOOT:
678 if(t==MN_SOUL) {if(st&(Z_HITWALL|Z_HITCEIL|Z_HITLAND)) setst(i,GO); break;}
679 if(t!=MN_FISH) mn[i].o.xv=Z_dec(mn[i].o.xv,1);
680 if(t==MN_VILE && mn[i].st==SHOOT) {
681 if(!Z_getobjpos(mn[i].aim,&o)) {setst(i,GO);break;}
682 if(!Z_look(&mn[i].o,&o,mn[i].d)) {setst(i,GO);break;}
683 if(Z_inwater(o.x,o.y,o.r,o.h)) {setst(i,GO);break;}
684 mn[i].tx=o.x;mn[i].ty=o.y;
685 Z_hitobj(mn[i].aim,2,i,HIT_SOME);
686 }break;
688 if(mn[i].st==REVIVE) {
689 if(--mn[i].ac==0) setst(i,GO);
690 }else ++mn[i].ac;
691 if(!mn[i].ap[mn[i].ac]) switch(mn[i].st) {
692 case ATTACK:
693 switch(t) {
694 case MN_SOUL: mn[i].ac=0;
695 case MN_IMP:
696 case MN_DEMON:
697 if(Z_hit(&mn[i].o,15,i,HIT_SOME)) if(t==MN_SOUL) setst(i,GO);
698 break;
699 case MN_FISH:
700 if(Z_hit(&mn[i].o,10,i,HIT_SOME))
701 Z_sound(snd[MN_FISH-1][2],128);
702 break;
703 case MN_SKEL: case MN_ROBO:
704 o=mn[i].o;o.xv=mn[i].d?50:-50;
705 if(Z_hit(&o,50,i,HIT_SOME)) Z_sound(pchsnd,128);
706 break;
707 case MN_VILE:
708 sx=iscorpse(&mn[i].o,1);
709 if(sx==-3) break;
710 if(!mn[sx].t || mn[sx].st!=DEAD) break;
711 setst(sx,REVIVE);Z_sound(slopsnd,128);
712 hit_xv=hit_yv=0;MN_hit(i,5,-3,HIT_SOME);
713 break;
714 }if(t!=MN_SOUL && mn[i].st!=DIE) setst(i,GO);
715 break;
716 case SHOOT:
717 switch(t) {
718 case MN_IMP:
719 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);
720 break;
721 case MN_ZOMBY:
722 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);
723 break;
724 case MN_SERG:
725 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);
726 break;
727 case MN_MAN:
728 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);
729 mn[i].ammo=-36;break;
730 case MN_CYBER:
731 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);
732 break;
733 case MN_SKEL:
734 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);
735 break;
736 case MN_CGUN:
737 case MN_SPIDER:
738 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);
739 break;
740 case MN_BSP:
741 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);
742 break;
743 case MN_ROBO:
744 WP_plasma(mn[i].o.x+(mn[i].d*2-1)*15,mn[i].o.y-30,mn[i].tx,mn[i].ty,i);
745 break;
746 case MN_MANCUB:
747 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);
748 break;
749 case MN_BARON: case MN_KNIGHT:
750 WP_ball7(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
751 break;
752 case MN_CACO:
753 WP_ball2(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
754 break;
755 case MN_PAIN:
756 if((sx=MN_spawn(mn[i].o.x,mn[i].o.y,mn[i].d,MN_SOUL))==-1) break;
757 Z_getobjpos(mn[sx].aim=mn[i].aim,&o);mn[sx].atm=0;
758 shoot(sx,&o,1);
759 break;
761 if(t==MN_CGUN || t==MN_SPIDER || t==MN_BSP || t==MN_MANCUB || t==MN_ROBO)
762 if(!Z_getobjpos(mn[i].aim,&o)) MN_findnewprey(i);
763 else if(shoot(i,&o,0)) break;
764 setst(i,GO);break;
765 case DIE:
766 setst(i,DEAD);
767 if(t==MN_PAIN || t==MN_SOUL) mn[i].ftime=0;
768 if(t==MN_PAIN) {
769 if((sx=MN_spawn(mn[i].o.x-15,mn[i].o.y,0,MN_SOUL))==-1) break;
770 setst(sx,GO);
771 if((sx=MN_spawn(mn[i].o.x+15,mn[i].o.y,1,MN_SOUL))==-1) break;
772 setst(sx,GO);
773 if((sx=MN_spawn(mn[i].o.x,mn[i].o.y-10,1,MN_SOUL))==-1) break;
774 setst(sx,GO);
775 }break;
776 default: mn[i].ac=0;
778 switch(mn[i].st) {
779 case GO: case RUN: case CLIMB: case RUNOUT:
780 if(t==MN_CYBER || t==MN_SPIDER || t==MN_BSP) {
781 if(mn[i].ac==0 || mn[i].ac==6) Z_sound(snd[t-1][2],128);
782 }else if(t==MN_ROBO)
783 if(mn[i].ac==0 || mn[i].ac==12) Z_sound(snd[t-1][2],128);
788 void MN_mark(void) {
789 int i;
790 for(i=0;i<MAXMN;++i) if(mn[i].t!=0) BM_mark(&mn[i].o,BM_MONSTER);
793 int MN_hit(int n,int d,int o,int t) {
794 int i;
796 if(mn[n].st==DEAD || mn[n].st==DIE) return 0;
797 if(o==n) {
798 if(t!=HIT_ROCKET && t!=HIT_ELECTRO) return 0;
799 if(mn[n].t==MN_CYBER || mn[n].t==MN_BARREL) return 1;
801 if(o>=0) {
802 if(mn[o].t==MN_SOUL && mn[n].t==MN_PAIN) return 0;
803 if(mn[o].t==mn[n].t) switch(mn[n].t) {
804 case MN_IMP: case MN_DEMON:
805 case MN_BARON: case MN_KNIGHT:
806 case MN_CACO: case MN_SOUL:
807 case MN_MANCUB: case MN_SKEL:
808 case MN_FISH:
809 return 0;
812 if(t==HIT_FLAME) if(mn[n].ftime && mn[n].fobj==o) {if(g_time&31) return 1;}
813 else {mn[n].ftime=255;mn[n].fobj=o;}
814 if(t==HIT_ELECTRO) if(mn[n].t==MN_FISH)
815 {setst(n,RUN);mn[n].s=20;mn[n].d=rand()&1;return 1;}
816 if(t==HIT_TRAP) mn[n].life=-100;
817 if(mn[n].t==MN_ROBO) d=0;
818 if((mn[n].life-=d)<=0) --mnum;
819 if(!mn[n].pain) mn[n].pain=3;
820 mn[n].pain+=d;
821 if(mn[n].st!=PAIN) {
822 if(mn[n].pain>=mnsz[mn[n].t].minp) setst(n,PAIN);
824 if(mn[n].t!=MN_BARREL)
825 DOT_blood(mn[n].o.x,mn[n].o.y-mn[n].o.h/2,hit_xv,hit_yv,d*2);
826 mn[n].aim=o;mn[n].atm=0;
827 if(mn[n].life<=0) {
828 if(mn[n].t!=MN_BARREL)
829 if(o==-1) ++pl1.kills;
830 else if(o==-2) ++pl2.kills;
831 setst(n,DIE);
832 switch(mn[n].t) {
833 case MN_ZOMBY: i=I_CLIP;break;
834 case MN_SERG: i=I_SGUN;break;
835 case MN_CGUN: i=I_MGUN;break;
836 case MN_MAN: i=I_KEYR;break;
837 default: i=0;
838 }if(i) IT_spawn(mn[n].o.x,mn[n].o.y,i);
839 mn[n].o.xv=0;mn[n].o.h=6;
840 if(mn[n].life<=-mnsz[mn[n].t].sp)
841 switch(mn[n].t) {
842 case MN_IMP: case MN_ZOMBY: case MN_SERG: case MN_CGUN:
843 case MN_MAN:
844 mn[n].ap=slopanim[mn[n].t-1];
845 Z_sound(slopsnd,128);
846 break;
847 case MN_BSP: if(g_map==9) break;
848 default:
849 Z_sound(dthsnd(mn[n].t),128);
851 else if(mn[n].t!=MN_BSP || g_map!=9) Z_sound(dthsnd(mn[n].t),128);
852 mn[n].life=0;
853 }else if(mn[n].st==SLEEP) {setst(n,GO);mn[n].pain=mnsz[mn[n].t].mp;}
854 return 1;
857 #define hit(o,x,y) (y<=o.y && y>o.y-o.h && x>=o.x-o.r && x<=o.x+o.r)
859 int Z_gunhit(int x,int y,int o,int xv,int yv) {
860 int i;
862 if(o!=-1) if(hit(pl1.o,x,y)) if(PL_hit(&pl1,3,o,HIT_SOME))
863 {pl1.o.vx+=xv;pl1.o.vy+=yv;return -1;}
864 if(_2pl && o!=-2) if(hit(pl2.o,x,y)) if(PL_hit(&pl2,3,o,HIT_SOME))
865 {pl2.o.vx+=xv;pl2.o.vy+=yv;return -2;}
867 for(i=0;i<MAXMN;++i) if(mn[i].t && o!=i)
868 if(hit(mn[i].o,x,y)) if(MN_hit(i,3,o,HIT_SOME))
869 {mn[i].o.vx+=xv;mn[i].o.vy+=yv;return 1;}
870 return 0;
873 static void goodsnd(void) {
874 if(!g_dm) return;
875 gsndt=18;
878 int Z_hit(obj_t *o,int d,int own,int t) {
879 int i;
881 hit_xv=o->xv+o->vx;
882 hit_yv=o->yv+o->vy;
883 if(Z_overlap(o,&pl1.o)) if(PL_hit(&pl1,d,own,t)) {
884 pl1.o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
885 pl1.o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
886 if(t==HIT_BFG) goodsnd();
887 return -1;
889 if(_2pl) if(Z_overlap(o,&pl2.o)) if(PL_hit(&pl2,d,own,t)) {
890 pl2.o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
891 pl2.o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
892 if(t==HIT_BFG) goodsnd();
893 return -2;
896 for(i=0;i<MAXMN;++i) if(mn[i].t)
897 if(Z_overlap(o,&mn[i].o)) if(MN_hit(i,d,own,t)) {
898 mn[i].o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
899 mn[i].o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
900 return 1;
902 return 0;
905 void MN_killedp(void) {
906 int i;
908 for(i=0;i<MAXMN;++i) if(mn[i].t==MN_MAN)
909 if(mn[i].st!=DEAD && mn[i].st!=DIE && mn[i].st!=SLEEP)
910 Z_sound(trupsnd,128);
913 int Z_hitobj(int obj,int d,int own,int t) {
914 hit_xv=hit_yv=0;
915 if(obj==-1) return PL_hit(&pl1,d,own,t);
916 else if(obj==-2 && _2pl) return PL_hit(&pl2,d,own,t);
917 else if(obj<0 || obj>=MAXMN) return 0;
918 if(mn[obj].t) return MN_hit(obj,d,own,t);
919 return 0;
922 void Z_explode(int x,int y,int rad,int own) {
923 long r;
924 int dx,dy,m,i;
926 if(x<-100 || x>FLDW*CELW+100) return;
927 if(y<-100 || y>FLDH*CELH+100) return;
928 r=(long)rad*rad;
929 dx=pl1.o.x-x;dy=pl1.o.y-pl1.o.h/2-y;
930 if((long)dx*dx+(long)dy*dy<r) {
931 if(!(m=max(abs(dx),abs(dy)))) m=1;
932 pl1.o.vx+=hit_xv=dx*10/m;
933 pl1.o.vy+=hit_yv=dy*10/m;
934 PL_hit(&pl1,100*(rad-m)/rad,own,HIT_ROCKET);
936 if(_2pl) {
937 dx=pl2.o.x-x;dy=pl2.o.y-pl2.o.h/2-y;
938 if((long)dx*dx+(long)dy*dy<r) {
939 if(!(m=max(abs(dx),abs(dy)))) m=1;
940 pl2.o.vx+=hit_xv=dx*10/m;
941 pl2.o.vy+=hit_yv=dy*10/m;
942 PL_hit(&pl2,100*(rad-m)/rad,own,HIT_ROCKET);
945 for(i=0;i<MAXMN;++i) if(mn[i].t) {
946 dx=mn[i].o.x-x;dy=mn[i].o.y-mn[i].o.h/2-y;
947 if((long)dx*dx+(long)dy*dy<r) {
948 if(!(m=max(abs(dx),abs(dy)))) m=1;
949 mn[i].o.vx+=hit_xv=dx*10/m;
950 mn[i].o.vy+=hit_yv=dy*10/m;
951 MN_hit(i,mn[i].o.r*10*(rad-m)/rad,own,HIT_ROCKET);
956 void Z_bfg9000(int x,int y,int own) {
957 int dx,dy,i;
959 hit_xv=hit_yv=0;
960 if(x<-100 || x>FLDW*CELW+100) return;
961 if(y<-100 || y>FLDH*CELH+100) return;
962 dx=pl1.o.x-x;dy=pl1.o.y-pl1.o.h/2-y;
963 if(own!=-1) if((long)dx*dx+(long)dy*dy<16000)
964 if(Z_cansee(x,y,pl1.o.x,pl1.o.y-pl1.o.h/2)) {
965 if(PL_hit(&pl1,50,own,HIT_SOME))
966 WP_bfghit(pl1.o.x,pl1.o.y-pl1.o.h/2,own);
968 if(_2pl) {
969 dx=pl2.o.x-x;dy=pl2.o.y-pl2.o.h/2-y;
970 if(own!=-2) if((long)dx*dx+(long)dy*dy<16000)
971 if(Z_cansee(x,y,pl2.o.x,pl2.o.y-pl2.o.h/2)) {
972 if(PL_hit(&pl2,50,own,HIT_SOME))
973 WP_bfghit(pl2.o.x,pl2.o.y-pl2.o.h/2,own);
976 for(i=0;i<MAXMN;++i) if(mn[i].t && own!=i) {
977 dx=mn[i].o.x-x;dy=mn[i].o.y-mn[i].o.h/2-y;
978 if((long)dx*dx+(long)dy*dy<16000)
979 if(Z_cansee(x,y,mn[i].o.x,mn[i].o.y-mn[i].o.h/2)) {
980 if(MN_hit(i,50,own,HIT_SOME))
981 WP_bfghit(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,own);
986 int Z_chktrap(int t,int d,int o,int ht) {
987 int i,s;
989 hit_xv=hit_yv=0;
990 s=0;
991 if(Z_istrapped(pl1.o.x,pl1.o.y,pl1.o.r,pl1.o.h)) {
992 s=1;
993 if(t) PL_hit(&pl1,d,o,ht);
995 if(_2pl) if(Z_istrapped(pl2.o.x,pl2.o.y,pl2.o.r,pl2.o.h)) {
996 s=1;
997 if(t) PL_hit(&pl2,d,o,ht);
999 for(i=0;i<MAXMN;++i) if(mn[i].t && mn[i].st!=DEAD)
1000 if(Z_istrapped(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h)) {
1001 s=1;
1002 if(t) MN_hit(i,d,o,ht);
1004 return s;
1007 void Z_teleobj(int o,int x,int y) {
1008 obj_t *p;
1010 if(o==-1) p=&pl1.o;
1011 else if(o==-2) p=&pl2.o;
1012 else if(o>=0 && o<MAXMN) p=&mn[o].o;
1013 else return;
1014 FX_tfog(p->x,p->y);FX_tfog(p->x=x,p->y=y);
1015 Z_sound(telesnd,128);
1018 void MN_warning(int l,int t,int r,int b) {
1019 int i;
1021 for(i=0;i<MAXMN;++i) if(mn[i].t && mn[i].t!=MN_CACO && mn[i].t!=MN_SOUL
1022 && mn[i].t!=MN_PAIN && mn[i].t!=MN_FISH)
1023 if(mn[i].st!=DIE && mn[i].st!=DEAD && mn[i].st!=SLEEP)
1024 if(mn[i].o.x+mn[i].o.r>=l && mn[i].o.x-mn[i].o.r<=r
1025 && mn[i].o.y>=t && mn[i].o.y-mn[i].o.h<=b)
1026 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
1027 mn[i].o.yv=-mnsz[mn[i].t].jv;