DEADSOFTWARE

98b909ebf803eea40342235b1c98770727e85c84
[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"
40 #define MANCOLOR 0xD0
42 #define MAX_ATM 90
44 #define MN_TN (MN__LAST-MN_DEMON)
46 extern byte z_mon;
48 enum{
49 SLEEP,GO,RUN,CLIMB,DIE,DEAD,ATTACK,SHOOT,PAIN,WAIT,REVIVE,RUNOUT
50 };
52 #pragma pack(1)
53 typedef struct{
54 obj_t o;
55 byte t,d,st,ftime;
56 int fobj;
57 int s;
58 char *ap;
59 int aim,life,pain,ac,tx,ty,ammo;
60 short atm;
61 }mn_t;
62 #pragma pack(0)
64 typedef struct{
65 int r,h,l,mp,rv,jv,sp,minp;
66 }mnsz_t;
68 byte nomon=1;
70 static char *sleepanim[MN_TN]={
71 "AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB",
72 "A","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB","AAABBB",
73 "A","A","AAABBB"
74 }, *goanim[MN_TN]={
75 "AABBCCDD","AABBCCDD","AABBDDAACCDD","AABBDDAACCDD","AABBDDCCDDBB",
76 "AABBDDAACCDD","AABBCCDD","AABBCCDD","A","AABB","AABBCCBB",
77 "AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF","AABBCCDDEEFF",
78 "AABB","A","DDEEFFGGHHIIJJKKLLAABBCC","ACDABD"
79 }, *painanim[MN_TN]={
80 "H","H","G","G","G","G","H","H","F","E","G","I","I","J","L","Q","EECCDDCC",
81 "A","D","G"
82 }, *waitanim[MN_TN]={
83 "A","A","A","A","A","A","A","A","A","AABB","A","A","A","I","K","A","A",
84 "A","D","E"
85 }, *attackanim[MN_TN]={
86 "EEFFGG","EEFFGG","EEEEEF","EEEEEF","EEEEEF","EF","EEFFGG","EEFFGG",
87 "BBCCDD","CCDD","DDEEFF","GH","GH","GGGGHH","GGHHII",
88 "QQGGGHHHIIJJKKLLMMNNOOPP","BBFFAA","A","OOPPQQ","EEEEFF"
89 }, *dieanim[MN_TN]={
90 "IIIJJJKKKLLLMMM","IIIJJJKKKLLL","HHHIIIJJJKKK","HHHIIIJJJKKK",
91 "HHHIIIJJJKKKLLLMMMNNNOOO","HHHIIIJJJKKKLLLMMM",
92 "IIIJJJKKKLLLMMMNNN","IIIJJJKKKLLLMMMNNN","GGGHHHIIIJJJKKK",
93 "FFFGGGHHHIIIJJJKKK","HHHIIIJJJKKKLLLMMM",
94 "JJJJKKKKLLLLMMMMNNNNOOOOPPPPQQQQRRRR","JJJKKKLLLMMMNNNOOO",
95 "KKKLLLMMMNNNOOOPPPRRRSSS","MMMNNNOOOPPP","RRRSSSTTTUUUVVVWWWXXXYYY",
96 "DDDD","CCCDDDEEEFFFGGG","D","HHHHIIIIJJJJKKKKLLLLMMMM"
97 }, *slopanim[MN_TN]={
98 "","NNNOOOPPPRRRSSSTTT","MMMNNNOOOPPPRRRSSSTTT","MMMNNNOOOPPPRRRSSSTTT","",
99 "OOOPPPQQQRRRSSS","","","","","","","","","","","","","","OOPPQQRRSSTTUUVV"
100 }, *deadanim[MN_TN]={
101 "N","M","L","L","P","N","O","O","L","","","S","P","T","Q","Z","C","","D","N"
102 }, *messanim[MN_TN]={
103 "","U","U","U","","T","","","","","","","","","","","","","","W"
104 };
106 int hit_xv,hit_yv;
108 static void *spr[MN_TN][29*2],*fspr[8],*fsnd,*pauksnd,*trupsnd,*sgun[2];
109 static char sprd[MN_TN][29*2];
110 static void *snd[MN_TN][5],*impsitsnd[2],*impdthsnd[2],*firsnd,*slopsnd,*gsnd[4];
111 static void *swgsnd,*pchsnd,*pl_spr[2],*telesnd;
112 static void *positsnd[3],*podthsnd[3];
113 static mn_t mn[MAXMN];
114 static int mnum,gsndt;
115 static mnsz_t mnsz[MN_TN+1]={
116 //rad ht life pain rv jv slop min_pn
117 0, 0, 0, 0, 0, 0, 0, 0, // none
118 15, 28, 60, 20, 7,10, 0, 10, // demon
119 10, 28, 25, 15, 3,10, 30, 0, // imp
120 10, 28, 15, 10, 3,10, 30, 0, // zomby
121 10, 28, 20, 10, 3,10, 30, 0, // sergeant
122 20, 55, 500, 70, 5,10, 0, 50, // cyberdemon
123 12, 28, 60, 20, 3,10, 30, 10, // chaingunner
124 12, 32, 150, 40, 3,10, 0, 30, // baron of hell
125 12, 32, 75, 40, 3,10, 0, 30, // hell knight
126 15, 28, 100, 10, 4, 4, 0, 0, // cacodemon
127 8, 18, 60, 10, 4, 4, 0, 0, // lost soul
128 15, 28, 100, 10, 4, 4, 0, 0, // pain elemental
129 64, 50, 500, 70, 4,10, 0, 50, // spider mastermind
130 25, 27, 150, 20, 4,10, 0, 0, // arachnotron
131 18, 30, 200, 40, 3, 7, 0, 20, // mancubus
132 17, 36, 200, 40, 6,11, 0, 20, // revenant
133 17, 36, 150, 30, 7,12, 0, 10, // archvile
134 5, 5, 35, 20,14, 6, 0, 10, // fish
135 5, 17, 20, 0, 7, 6, 0, 0, // barrel
136 17, 38, 20, 40, 3, 6, 0, 20, // robot
137 8, 26, 400, 70, 8,10, 30, 50 // man
138 };
140 void MN_savegame(FILE* h) {
141 int n;
143 for(n=MAXMN;--n;) if(mn[n].t) break;
144 ++n;myfwrite(&n,1,4,h);
145 myfwrite(mn,1,n*sizeof(mn[0]),h);
146 myfwrite(&mnum,1,4,h);myfwrite(&gsndt,1,4,h);
149 static void setst(int,int);
151 static int MN_hit(int n,int d,int o,int t);
153 void MN_loadgame(FILE* h) {
154 int n,c;
156 myfread(&n,1,4,h);
157 myfread(mn,1,n*sizeof(mn[0]),h);
158 myfread(&mnum,1,4,h);myfread(&gsndt,1,4,h);
159 for(n=0;n<MAXMN;++n) if(mn[n].t) {
160 c=mn[n].ac;setst(n,mn[n].st);mn[n].ac=c;
164 #define GGAS_TOTAL (MN__LAST-MN_DEMON+16+10)
166 void MN_alloc(void) {
167 int i,j;
168 static char sn[MN_TN][5][6]={
169 {"DMACT","DMPAIN","SGTATK","SGTSIT","SGTDTH"},
170 {"BGACT","POPAIN","CLAW","",""},
171 {"POSACT","POPAIN","","",""},
172 {"POSACT","POPAIN","","",""},
173 {"","DMPAIN","HOOF","CYBSIT","CYBDTH"},
174 {"POSACT","POPAIN","","",""},
175 {"","DMPAIN","","BRSSIT","BRSDTH"},
176 {"","DMPAIN","","KNTSIT","KNTDTH"},
177 {"DMACT","DMPAIN","","CACSIT","CACDTH"},
178 {"DMACT","DMPAIN","SKLATK","SKLATK","FIRXPL"},
179 {"DMACT","PEPAIN","","PESIT","PEDTH"},
180 {"","DMPAIN","METAL","SPISIT","SPIDTH"},
181 {"BSPACT","DMPAIN","BSPWLK","BSPSIT","BSPDTH"},
182 {"DMACT","MNPAIN","MANATK","MANSIT","MANDTH"},
183 {"SKEACT","POPAIN","SKEATK","SKESIT","SKEDTH"},
184 {"VILACT","VIPAIN","VILATK","VILSIT","VILDTH"},
185 {"","","BITE1","",""},
186 {"","","","","BAREXP"},
187 {"BSPACT","","BSPWLK","BSPSIT","BSPDTH"},
188 {"HAHA1","PLPAIN","","STOP1","PDIEHI"}
189 },msn[MN_TN][4]={
190 "SARG","TROO","POSS","SPOS","CYBR","CPOS","BOSS","BOS2","HEAD","SKUL",
191 "PAIN","SPID","BSPI","FATT","SKEL","VILE","FISH","BAR1","ROBO","PLAY"
192 };
193 static char gsn[6]="GOOD0";
194 static int mms[MN_TN]={
195 14*2,21*2,21*2,21*2,16*2,20*2,15*2,15*2,12*2,11*2,13*2,19*2,16*2,
196 20*2,17*2,29*2,6*2,2*2,17*2,23*2
197 };
199 sgun[0]=Z_getspr("PWP4",0,1,NULL);
200 sgun[1]=Z_getspr("PWP4",1,1,NULL);
201 for(j=0;j<MN_TN;++j) {
202 for(i=0;i<mms[j];++i) spr[j][i]=Z_getspr(msn[j],i/2,(i&1)+1,&sprd[j][i]);
203 if(j==MN_BARREL-1)
204 for(i=4;i<14;++i) spr[j][i]=Z_getspr("BEXP",i/2-2,(i&1)+1,&sprd[j][i]);
205 for(i=0;i<5;++i)
206 if(sn[j][i][0]) snd[j][i]=Z_getsnd(sn[j][i]);
207 else snd[j][i]=NULL;
208 logo_gas(j+5,GGAS_TOTAL);
210 for(i=0;i<8;++i) fspr[i]=Z_getspr("FIRE",i,0,NULL);
211 pl_spr[0]=Z_getspr("PLAY",'N'-'A',0,NULL);
212 pl_spr[1]=Z_getspr("PLAY",'W'-'A',0,NULL);
213 impsitsnd[0]=Z_getsnd("BGSIT1");
214 impsitsnd[1]=Z_getsnd("BGSIT2");
215 impdthsnd[0]=Z_getsnd("BGDTH1");
216 impdthsnd[1]=Z_getsnd("BGDTH2");
217 positsnd[0]=Z_getsnd("POSIT1");
218 positsnd[1]=Z_getsnd("POSIT2");
219 positsnd[2]=Z_getsnd("POSIT3");
220 podthsnd[0]=Z_getsnd("PODTH1");
221 podthsnd[1]=Z_getsnd("PODTH2");
222 podthsnd[2]=Z_getsnd("PODTH3");
223 fsnd=Z_getsnd("FLAME");
224 firsnd=Z_getsnd("FIRSHT");
225 slopsnd=Z_getsnd("SLOP");
226 swgsnd=Z_getsnd("SKESWG");
227 pchsnd=Z_getsnd("SKEPCH");
228 telesnd=Z_getsnd("TELEPT");
229 pauksnd=Z_getsnd("PAUK1");
230 trupsnd=Z_getsnd("UTRUP");
231 for(i=0;i<4;++i) {gsn[4]=i+'1';gsnd[i]=Z_getsnd(gsn);}
234 void MN_init(void) {
235 int i;
237 for(i=0;i<MAXMN;++i) {mn[i].t=0;mn[i].st=SLEEP;}
238 gsndt=mnum=0;
241 static void setst(int i,int st) {
242 char *a;
243 int t;
245 switch(mn[i].st) {
246 case DIE: case DEAD:
247 if(st!=DEAD && st!=REVIVE) return;
249 mn[i].ac=0;
250 t=mn[i].t-1;
251 switch(mn[i].st=st) {
252 case SLEEP: a=sleepanim[t];break;
253 case PAIN: a=painanim[t];break;
254 case WAIT: a=waitanim[t];break;
255 case CLIMB:
256 case RUN: case RUNOUT:
257 case GO: a=goanim[t];break;
258 case SHOOT:
259 if(t==MN_SKEL-1) {a="KKKKJJ";break;}
260 if(t==MN_ROBO-1) {a="MN";break;}
261 case ATTACK: a=attackanim[t];
262 if(st==ATTACK && t==MN_VILE-1) a="[[\\\\]]";
263 break;
264 case DIE:
265 if(g_map==9 && t==MN_BSP-1) Z_sound(pauksnd,128);
266 a=dieanim[t];break;
267 case DEAD:
268 a=deadanim[t];
269 if(mn[i].ap==slopanim[t]) a=messanim[t];
270 if(t==MN_BARREL-1) {mn[i].t=0;}
271 break;
272 case REVIVE:
273 a=(mn[i].ap==messanim[t])?slopanim[t]:dieanim[t];
274 mn[i].ac=strlen(a)-1;
275 mn[i].o.r=mnsz[t+1].r;mn[i].o.h=mnsz[t+1].h;
276 mn[i].life=mnsz[t+1].l;mn[i].ammo=mn[i].pain=0;
277 ++mnum;
278 break;
280 mn[i].ap=a;
283 int MN_spawn(int x,int y,byte d,int t) {
284 int i;
286 if(g_dm && nomon && t<MN_PL_DEAD) return -1;
287 for(i=0;i<MAXMN;++i) if(!mn[i].t) goto ok;
288 for(i=0;i<MAXMN;++i) if(mn[i].t>=MN_PL_DEAD) goto ok;
289 return -1;
290 ok:
291 mn[i].o.x=x;mn[i].o.y=y;
292 mn[i].o.xv=mn[i].o.yv=mn[i].o.vx=mn[i].o.vy=0;
293 mn[i].d=d;mn[i].t=t;
294 mn[i].st=SLEEP;
295 if(t<MN_PL_DEAD) {
296 mn[i].o.r=mnsz[t].r;mn[i].o.h=mnsz[t].h;
297 mn[i].life=mnsz[t].l;
298 setst(i,SLEEP);mn[i].s=myrand(18);
299 ++mnum;
300 }else {mn[i].o.r=8;mn[i].o.h=6;mn[i].life=0;mn[i].st=DEAD;}
301 mn[i].aim=-3;mn[i].atm=0;
302 mn[i].pain=0;
303 mn[i].ammo=0;
304 mn[i].ftime=0;
305 return i;
308 int MN_spawn_deadpl(obj_t *o,byte c,int t) {
309 int i;
311 if((i=MN_spawn(o->x,o->y,c,t+MN_PL_DEAD))==-1) return -1;
312 mn[i].o=*o;return i;
315 static int isfriend(int a,int b) {
316 if(a==MN_BARREL || b==MN_BARREL) return 1;
317 if(a==b) switch(a) {
318 case MN_IMP: case MN_DEMON:
319 case MN_BARON: case MN_KNIGHT:
320 case MN_CACO: case MN_SOUL:
321 case MN_MANCUB: case MN_SKEL:
322 case MN_FISH:
323 return 1;
325 if(a==MN_SOUL && b==MN_PAIN) return 1;
326 if(b==MN_SOUL && a==MN_PAIN) return 1;
327 return 0;
330 static int MN_findnewprey(int i) {
331 int a,b,l;
333 a=!PL_isdead(&pl1);
334 if(_2pl) b=!PL_isdead(&pl2); else b=0;
335 if(a) {
336 if(b) mn[i].aim=(abs(mn[i].o.x-pl1.o.x)+abs(mn[i].o.y-pl1.o.y)
337 <= abs(mn[i].o.x-pl2.o.x)+abs(mn[i].o.y-pl2.o.y))?-1:-2;
338 else mn[i].aim=-1;
339 }else{
340 if(b) mn[i].aim=-2;
341 else{
342 for(a=0,b=32000,mn[i].aim=-3;a<MAXMN;++a)
343 if(mn[a].t && mn[a].st!=DEAD && a!=i && !isfriend(mn[a].t,mn[i].t))
344 if((l=abs(mn[i].o.x-mn[a].o.x)+abs(mn[i].o.y-mn[a].o.y))<b)
345 {mn[i].aim=a;b=l;}
346 if(mn[i].aim<0) {mn[i].atm=MAX_ATM;return 0;} else mn[i].atm=0;
349 return 1;
352 int Z_getobjpos(int i,obj_t *o) {
353 if(i==-1) {*o=pl1.o;return !PL_isdead(&pl1);}
354 if(_2pl) if(i==-2) {*o=pl2.o;return !PL_isdead(&pl2);}
355 if(i>=0 && i<MAXMN) if(mn[i].t && mn[i].st!=DEAD)
356 {*o=mn[i].o;return 1;}
357 return 0;
360 static void *wakeupsnd(int t) {
361 switch(t) {
362 case MN_IMP: return impsitsnd[myrand(2)];
363 case MN_ZOMBY: case MN_SERG: case MN_CGUN:
364 return positsnd[myrand(3)];
366 return snd[t-1][3];
369 static void *dthsnd(int t) {
370 switch(t) {
371 case MN_IMP: return impdthsnd[myrand(2)];
372 case MN_ZOMBY: case MN_SERG: case MN_CGUN:
373 return podthsnd[myrand(3)];
375 return snd[t-1][4];
378 static int canshoot(int t) {
379 switch(t) {
380 case MN_DEMON: case MN_FISH: case MN_BARREL:
381 return 0;
383 return 1;
386 static int shoot(int i,obj_t *o,int n) {
387 int xd,yd,m;
389 if(mn[i].ammo<0) return 0;
390 if(!n) switch(mn[i].t) {
391 case MN_FISH: case MN_BARREL:
392 case MN_DEMON: return 0;
393 case MN_CGUN:
394 case MN_BSP:
395 case MN_ROBO:
396 if(++mn[i].ammo>=50) mn[i].ammo=(mn[i].t==MN_ROBO)?-200:-50;
397 break;
398 case MN_MAN:
399 break;
400 case MN_MANCUB:
401 if(++mn[i].ammo>=5) mn[i].ammo=-50;
402 break;
403 case MN_SPIDER:
404 if(++mn[i].ammo>=100) mn[i].ammo=-50;
405 break;
406 case MN_CYBER:
407 if(rand()&1) return 0;
408 if(++mn[i].ammo>=10) mn[i].ammo=-50;
409 break;
410 case MN_BARON: case MN_KNIGHT:
411 if(rand()&7) return 0;
412 break;
413 case MN_SKEL:
414 if(rand()&31) return 0;
415 break;
416 case MN_VILE:
417 if(rand()&7) return 0;
418 break;
419 case MN_PAIN:
420 if(rand()&7) return 0;
421 break;
422 default:
423 if(rand()&15) return 0;
425 if(!Z_look(&mn[i].o,o,mn[i].d)) return 0;
426 mn[i].atm=0;
427 mn[i].tx=o->x+(o->xv+o->vx)*6;mn[i].ty=o->y-o->h/2+(o->yv+o->vy)*6;
428 if(abs(mn[i].tx-mn[i].o.x)<abs(mn[i].ty-mn[i].o.y+mn[i].o.h/2)) return 0;
429 switch(mn[i].t) {
430 case MN_IMP: case MN_BARON: case MN_KNIGHT: case MN_CACO:
431 setst(i,SHOOT);Z_sound(firsnd,128);break;
432 case MN_SKEL:
433 setst(i,SHOOT);Z_sound(snd[MN_SKEL-1][2],128);break;
434 case MN_VILE:
435 mn[i].tx=o->x;mn[i].ty=o->y;
436 setst(i,SHOOT);Z_sound(fsnd,128);
437 Z_sound(snd[MN_VILE-1][2],128);break;
438 case MN_SOUL:
439 setst(i,ATTACK);Z_sound(snd[MN_SOUL-1][2],128);
440 yd=mn[i].ty-mn[i].o.y+mn[i].o.h/2;xd=mn[i].tx-mn[i].o.x;
441 if(!(m=max(abs(xd),abs(yd)))) m=1;
442 mn[i].o.xv=xd*16/m;mn[i].o.yv=yd*16/m;
443 break;
444 case MN_MANCUB: if(mn[i].ammo==1) Z_sound(snd[MN_MANCUB-1][2],128);
445 case MN_ZOMBY: case MN_SERG: case MN_BSP: case MN_ROBO:
446 case MN_CYBER: case MN_CGUN: case MN_SPIDER:
447 case MN_PAIN: case MN_MAN:
448 setst(i,SHOOT);break;
449 default:
450 return 0;
452 return 1;
455 static int kick(int i,obj_t *o) {
456 switch(mn[i].t) {
457 case MN_FISH:
458 setst(i,ATTACK);return 1;
459 case MN_DEMON:
460 setst(i,ATTACK);Z_sound(snd[0][2],128);return 1;
461 case MN_IMP:
462 setst(i,ATTACK);Z_sound(snd[1][2],128);return 1;
463 case MN_SKEL:
464 setst(i,ATTACK);Z_sound(swgsnd,128);return 1;
465 case MN_ROBO:
466 setst(i,ATTACK);Z_sound(swgsnd,128);return 1;
467 case MN_BARON: case MN_KNIGHT: case MN_CACO: case MN_MANCUB:
468 return shoot(i,o,1);
470 return 0;
473 static int iscorpse(obj_t *o,int n) {
474 int i;
476 if(!n) if(rand()&7) return -3;
477 for(i=0;i<MAXMN;++i) if(mn[i].t) if(mn[i].st==DEAD)
478 if(Z_overlap(o,&mn[i].o)) switch(mn[i].t) {
479 case MN_SOUL: case MN_PAIN:
480 case MN_CYBER: case MN_SPIDER:
481 case MN_PL_DEAD: case MN_PL_MESS:
482 case MN_VILE: case MN_BARREL:
483 continue;
484 default:
485 return i;
487 return -3;
490 void MN_act(void) {
491 int i,st,sx,sy,t;
492 static obj_t o;
493 static int pt_x=0,pt_xs=1,pt_y=0,pt_ys=1;
495 if(abs(pt_x+=pt_xs) > 123) pt_xs=-pt_xs;
496 if(abs(pt_y+=pt_ys) > 50) pt_ys=-pt_ys;
497 if(gsndt>0) if(--gsndt==0) {
498 Z_sound(gsnd[myrand(4)],128);
500 for(i=0;i<MAXMN;++i) if((t=mn[i].t)!=0) {
501 switch(t) {
502 case MN_FISH:
503 if(!Z_inwater(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h)) break;
504 case MN_SOUL: case MN_PAIN: case MN_CACO:
505 if(mn[i].st!=DIE && mn[i].st!=DEAD) --mn[i].o.yv;
506 break;
507 }z_mon=1;st=Z_moveobj(&mn[i].o);z_mon=0;
508 BM_mark(&mn[i].o,BM_MONSTER);
509 if(st&Z_FALLOUT) {
510 if(t==MN_ROBO) g_exit=1;
511 mn[i].t=0;--mnum;continue;
513 if(st&Z_HITWATER) Z_splash(&mn[i].o,mn[i].o.r+mn[i].o.h);
514 SW_press(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h,8,i);
515 if(mn[i].ftime) {
516 --mn[i].ftime;
517 SMK_flame(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,
518 mn[i].o.xv+mn[i].o.vx,mn[i].o.yv+mn[i].o.vy,
519 mn[i].o.r/2,mn[i].o.h/2,rand()%(200*2+1)-200,-500,1,mn[i].fobj);
521 if(st&Z_INWATER) mn[i].ftime=0;
522 if(mn[i].st==DEAD) continue;
523 if(st&Z_INWATER) if(!(rand()&31)) switch(t) {
524 case MN_FISH:
525 if(rand()&3) break;
526 case MN_ROBO: case MN_BARREL:
527 case MN_PL_DEAD: case MN_PL_MESS:
528 FX_bubble(mn[i].o.x+((rand()&1)*2-1)*myrand(mn[i].o.r+1),
529 mn[i].o.y-myrand(mn[i].o.h+1),0,0,1
530 );
531 break;
532 default:
533 FX_bubble(mn[i].o.x,mn[i].o.y-mn[i].o.h*3/4,0,0,5);
536 if(t==MN_BARREL) {
538 if(!mn[i].ap[++mn[i].ac]) {
539 mn[i].ac=0;if(mn[i].st==DIE || mn[i].st==DEAD) {mn[i].t=0;}
540 }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);
541 continue;
543 if(t==MN_SOUL) if(st&Z_HITAIR) Z_set_speed(&mn[i].o,16);
544 if(mn[i].ammo<0) ++mn[i].ammo;
545 if(mn[i].o.yv<0)
546 if(st&Z_INWATER) mn[i].o.yv=-4;
547 ++mn[i].atm;
548 switch(mn[i].st) {
549 case PAIN:
550 if(mn[i].pain>=mnsz[t].mp)
551 {mn[i].pain=mnsz[t].mp;Z_sound(snd[t-1][1],128);}
552 if((mn[i].pain-=5)<=mnsz[t].minp)
553 {setst(i,GO);mn[i].pain=0;mn[i].ammo=-9;}
554 break;
555 case SLEEP:
556 if(++mn[i].s>=18) mn[i].s=0; else break;
557 if(Z_look(&mn[i].o,&pl1.o,mn[i].d))
558 {setst(i,GO);mn[i].aim=-1;mn[i].atm=0;Z_sound(wakeupsnd(t),128);}
559 if(_2pl) if(Z_look(&mn[i].o,&pl2.o,mn[i].d))
560 {setst(i,GO);mn[i].aim=-2;mn[i].atm=0;Z_sound(wakeupsnd(t),128);}
561 break;
562 case WAIT:
563 if(--mn[i].s<0) setst(i,GO);
564 break;
565 case GO:
566 if(st&Z_BLOCK) {mn[i].d^=1;setst(i,RUNOUT);mn[i].s=40;break;}
567 if(t==MN_VILE) if(iscorpse(&mn[i].o,0)>=0) {
568 setst(i,ATTACK);mn[i].o.xv=0;break;
570 if(!Z_getobjpos(mn[i].aim,&o) || mn[i].atm>MAX_ATM)
571 if(!MN_findnewprey(i)) {
572 mn[i].aim=-3;
573 o.x=mn[i].o.x+pt_x;o.y=mn[i].o.y+pt_y;
574 o.xv=o.vx=o.yv=o.vy=o.r=0;o.h=1;
575 }else Z_getobjpos(mn[i].aim,&o);
576 if(Z_overlap(&mn[i].o,&o)) {
577 mn[i].atm=0;
578 if(kick(i,&o)) break;
580 sx=o.x-mn[i].o.x;
581 sy=o.y-o.h/2-mn[i].o.y+mn[i].o.h/2;
582 if(!(st&Z_BLOCK)) if(abs(sx)<20)
583 if(t!=MN_FISH) {setst(i,RUN);mn[i].s=15;mn[i].d=rand()&1;break;}
584 if(st&Z_HITWALL) {
585 if(SW_press(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h,2,i))
586 {setst(i,WAIT);mn[i].s=4;break;}
587 switch(t) {
588 case MN_CACO: case MN_SOUL: case MN_PAIN: case MN_FISH:
589 break;
590 default:
591 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
592 {mn[i].o.yv=-mnsz[t].jv;setst(i,CLIMB);break;}
593 }break;
595 mn[i].d=(sx>0)?1:0;
596 if(canshoot(t))
597 if(abs(sx)>abs(sy)) if(shoot(i,&o,0)) break;
599 switch(t) {
600 case MN_FISH:
601 if(!(st&Z_INWATER)) {
602 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r)) {
603 mn[i].o.yv=-6;
604 mn[i].o.vx+=rand()%17-8;
605 }setst(i,PAIN);mn[i].pain+=50;break;
607 case MN_CACO: case MN_SOUL: case MN_PAIN:
608 if(abs(sy)>4) mn[i].o.yv=(sy<0)?-4:4; else mn[i].o.yv=0;
609 if(t==MN_FISH) if(mn[i].o.yv<0)
610 if(!Z_inwater(mn[i].o.x,mn[i].o.y-8,mn[i].o.r,mn[i].o.h))
611 {mn[i].o.yv=0;setst(i,RUN);mn[i].d=rand()&1;mn[i].s=20;}
612 break;
613 default:
614 if(sy<-20) if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
615 if(!(rand()&3)) mn[i].o.yv=-mnsz[t].jv;
617 if(++mn[i].s>=8) {
618 mn[i].s=0;
619 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
621 mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
622 if(st&Z_INWATER) mn[i].o.xv/=2;
623 else if(t==MN_FISH) mn[i].o.xv=0;
624 break;
625 case RUN:
626 if(st&Z_BLOCK) {setst(i,RUNOUT);mn[i].d^=1;mn[i].s=40;break;}
627 if(--mn[i].s<=0 || ((st&Z_HITWALL) && mn[i].o.yv+mn[i].o.vy==0)) {
628 setst(i,GO);mn[i].s=0;if(st&(Z_HITWALL|Z_BLOCK)) mn[i].d^=1;
629 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
630 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
631 if(st&Z_INWATER) mn[i].o.xv/=2;
632 else if(t==MN_FISH) mn[i].o.xv=0;
633 break;
634 case RUNOUT:
635 if(!(st&Z_BLOCK) && mn[i].s>0) mn[i].s=0;
636 if(--mn[i].s<=-18) {
637 setst(i,GO);mn[i].s=0;if(st&(Z_HITWALL|Z_BLOCK)) mn[i].d^=1;
638 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
639 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
640 if(st&Z_INWATER) mn[i].o.xv/=2;
641 else if(t==MN_FISH) mn[i].o.xv=0;
642 break;
643 case CLIMB:
644 if(mn[i].o.yv+mn[i].o.vy>=0 || !(st&Z_HITWALL)) {
645 setst(i,GO);mn[i].s=0;
646 if(st&(Z_HITWALL|Z_BLOCK)) {mn[i].d^=1;setst(i,RUN);mn[i].s=15;}
647 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
648 if(st&Z_INWATER) mn[i].o.xv/=2;
649 else if(t==MN_FISH) mn[i].o.xv=0;
650 break;
651 case ATTACK:
652 case SHOOT:
653 if(t==MN_SOUL) {if(st&(Z_HITWALL|Z_HITCEIL|Z_HITLAND)) setst(i,GO); break;}
654 if(t!=MN_FISH) mn[i].o.xv=Z_dec(mn[i].o.xv,1);
655 if(t==MN_VILE && mn[i].st==SHOOT) {
656 if(!Z_getobjpos(mn[i].aim,&o)) {setst(i,GO);break;}
657 if(!Z_look(&mn[i].o,&o,mn[i].d)) {setst(i,GO);break;}
658 if(Z_inwater(o.x,o.y,o.r,o.h)) {setst(i,GO);break;}
659 mn[i].tx=o.x;mn[i].ty=o.y;
660 Z_hitobj(mn[i].aim,2,i,HIT_SOME);
661 }break;
663 if(mn[i].st==REVIVE) {
664 if(--mn[i].ac==0) setst(i,GO);
665 }else ++mn[i].ac;
666 if(!mn[i].ap[mn[i].ac]) switch(mn[i].st) {
667 case ATTACK:
668 switch(t) {
669 case MN_SOUL: mn[i].ac=0;
670 case MN_IMP:
671 case MN_DEMON:
672 if(Z_hit(&mn[i].o,15,i,HIT_SOME)) if(t==MN_SOUL) setst(i,GO);
673 break;
674 case MN_FISH:
675 if(Z_hit(&mn[i].o,10,i,HIT_SOME))
676 Z_sound(snd[MN_FISH-1][2],128);
677 break;
678 case MN_SKEL: case MN_ROBO:
679 o=mn[i].o;o.xv=mn[i].d?50:-50;
680 if(Z_hit(&o,50,i,HIT_SOME)) Z_sound(pchsnd,128);
681 break;
682 case MN_VILE:
683 sx=iscorpse(&mn[i].o,1);
684 if(sx==-3) break;
685 if(!mn[sx].t || mn[sx].st!=DEAD) break;
686 setst(sx,REVIVE);Z_sound(slopsnd,128);
687 hit_xv=hit_yv=0;MN_hit(i,5,-3,HIT_SOME);
688 break;
689 }if(t!=MN_SOUL && mn[i].st!=DIE) setst(i,GO);
690 break;
691 case SHOOT:
692 switch(t) {
693 case MN_IMP:
694 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);
695 break;
696 case MN_ZOMBY:
697 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);
698 break;
699 case MN_SERG:
700 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);
701 break;
702 case MN_MAN:
703 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);
704 mn[i].ammo=-36;break;
705 case MN_CYBER:
706 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);
707 break;
708 case MN_SKEL:
709 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);
710 break;
711 case MN_CGUN:
712 case MN_SPIDER:
713 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);
714 break;
715 case MN_BSP:
716 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);
717 break;
718 case MN_ROBO:
719 WP_plasma(mn[i].o.x+(mn[i].d*2-1)*15,mn[i].o.y-30,mn[i].tx,mn[i].ty,i);
720 break;
721 case MN_MANCUB:
722 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);
723 break;
724 case MN_BARON: case MN_KNIGHT:
725 WP_ball7(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
726 break;
727 case MN_CACO:
728 WP_ball2(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
729 break;
730 case MN_PAIN:
731 if((sx=MN_spawn(mn[i].o.x,mn[i].o.y,mn[i].d,MN_SOUL))==-1) break;
732 Z_getobjpos(mn[sx].aim=mn[i].aim,&o);mn[sx].atm=0;
733 shoot(sx,&o,1);
734 break;
736 if(t==MN_CGUN || t==MN_SPIDER || t==MN_BSP || t==MN_MANCUB || t==MN_ROBO)
737 if(!Z_getobjpos(mn[i].aim,&o)) MN_findnewprey(i);
738 else if(shoot(i,&o,0)) break;
739 setst(i,GO);break;
740 case DIE:
741 setst(i,DEAD);
742 if(t==MN_PAIN || t==MN_SOUL) mn[i].ftime=0;
743 if(t==MN_PAIN) {
744 if((sx=MN_spawn(mn[i].o.x-15,mn[i].o.y,0,MN_SOUL))==-1) break;
745 setst(sx,GO);
746 if((sx=MN_spawn(mn[i].o.x+15,mn[i].o.y,1,MN_SOUL))==-1) break;
747 setst(sx,GO);
748 if((sx=MN_spawn(mn[i].o.x,mn[i].o.y-10,1,MN_SOUL))==-1) break;
749 setst(sx,GO);
750 }break;
751 default: mn[i].ac=0;
753 switch(mn[i].st) {
754 case GO: case RUN: case CLIMB: case RUNOUT:
755 if(t==MN_CYBER || t==MN_SPIDER || t==MN_BSP) {
756 if(mn[i].ac==0 || mn[i].ac==6) Z_sound(snd[t-1][2],128);
757 }else if(t==MN_ROBO)
758 if(mn[i].ac==0 || mn[i].ac==12) Z_sound(snd[t-1][2],128);
763 void MN_mark(void) {
764 int i;
765 for(i=0;i<MAXMN;++i) if(mn[i].t!=0) BM_mark(&mn[i].o,BM_MONSTER);
768 void MN_draw(void) {
769 int i;
771 for(i=0;i<MAXMN;++i) if(mn[i].t) {
773 if(mn[i].t>=MN_PL_DEAD) {
774 Z_drawmanspr(mn[i].o.x,mn[i].o.y,pl_spr[mn[i].t-MN_PL_DEAD],0,mn[i].d);
775 continue;
777 if((mn[i].t!=MN_SOUL && mn[i].t!=MN_PAIN) || mn[i].st!=DEAD) {
778 if(mn[i].t!=MN_MAN)
779 Z_drawspr(mn[i].o.x,mn[i].o.y,
780 spr[mn[i].t-1][(mn[i].ap[mn[i].ac]-'A')*2+mn[i].d],
781 sprd[mn[i].t-1][(mn[i].ap[mn[i].ac]-'A')*2+mn[i].d]);
782 else{
783 if(mn[i].ap[mn[i].ac]=='E' || mn[i].ap[mn[i].ac]=='F')
784 Z_drawspr(mn[i].o.x,mn[i].o.y,sgun[mn[i].ap[mn[i].ac]-'E'],mn[i].d);
785 Z_drawmanspr(mn[i].o.x,mn[i].o.y,
786 spr[mn[i].t-1][(mn[i].ap[mn[i].ac]-'A')*2+mn[i].d],
787 sprd[mn[i].t-1][(mn[i].ap[mn[i].ac]-'A')*2+mn[i].d],MANCOLOR);
790 if(mn[i].t==MN_VILE && mn[i].st==SHOOT) {
791 Z_drawspr(mn[i].tx,mn[i].ty,fspr[mn[i].ac/3],0);
796 int MN_hit(int n,int d,int o,int t) {
797 int i;
799 if(mn[n].st==DEAD || mn[n].st==DIE) return 0;
800 if(o==n) {
801 if(t!=HIT_ROCKET && t!=HIT_ELECTRO) return 0;
802 if(mn[n].t==MN_CYBER || mn[n].t==MN_BARREL) return 1;
804 if(o>=0) {
805 if(mn[o].t==MN_SOUL && mn[n].t==MN_PAIN) return 0;
806 if(mn[o].t==mn[n].t) switch(mn[n].t) {
807 case MN_IMP: case MN_DEMON:
808 case MN_BARON: case MN_KNIGHT:
809 case MN_CACO: case MN_SOUL:
810 case MN_MANCUB: case MN_SKEL:
811 case MN_FISH:
812 return 0;
815 if(t==HIT_FLAME) if(mn[n].ftime && mn[n].fobj==o) {if(g_time&31) return 1;}
816 else {mn[n].ftime=255;mn[n].fobj=o;}
817 if(t==HIT_ELECTRO) if(mn[n].t==MN_FISH)
818 {setst(n,RUN);mn[n].s=20;mn[n].d=rand()&1;return 1;}
819 if(t==HIT_TRAP) mn[n].life=-100;
820 if(mn[n].t==MN_ROBO) d=0;
821 if((mn[n].life-=d)<=0) --mnum;
822 if(!mn[n].pain) mn[n].pain=3;
823 mn[n].pain+=d;
824 if(mn[n].st!=PAIN) {
825 if(mn[n].pain>=mnsz[mn[n].t].minp) setst(n,PAIN);
827 if(mn[n].t!=MN_BARREL)
828 DOT_blood(mn[n].o.x,mn[n].o.y-mn[n].o.h/2,hit_xv,hit_yv,d*2);
829 mn[n].aim=o;mn[n].atm=0;
830 if(mn[n].life<=0) {
831 if(mn[n].t!=MN_BARREL)
832 if(o==-1) ++pl1.kills;
833 else if(o==-2) ++pl2.kills;
834 setst(n,DIE);
835 switch(mn[n].t) {
836 case MN_ZOMBY: i=I_CLIP;break;
837 case MN_SERG: i=I_SGUN;break;
838 case MN_CGUN: i=I_MGUN;break;
839 case MN_MAN: i=I_KEYR;break;
840 default: i=0;
841 }if(i) IT_spawn(mn[n].o.x,mn[n].o.y,i);
842 mn[n].o.xv=0;mn[n].o.h=6;
843 if(mn[n].life<=-mnsz[mn[n].t].sp)
844 switch(mn[n].t) {
845 case MN_IMP: case MN_ZOMBY: case MN_SERG: case MN_CGUN:
846 case MN_MAN:
847 mn[n].ap=slopanim[mn[n].t-1];
848 Z_sound(slopsnd,128);
849 break;
850 case MN_BSP: if(g_map==9) break;
851 default:
852 Z_sound(dthsnd(mn[n].t),128);
854 else if(mn[n].t!=MN_BSP || g_map!=9) Z_sound(dthsnd(mn[n].t),128);
855 mn[n].life=0;
856 }else if(mn[n].st==SLEEP) {setst(n,GO);mn[n].pain=mnsz[mn[n].t].mp;}
857 return 1;
860 #define hit(o,x,y) (y<=o.y && y>o.y-o.h && x>=o.x-o.r && x<=o.x+o.r)
862 int Z_gunhit(int x,int y,int o,int xv,int yv) {
863 int i;
865 if(o!=-1) if(hit(pl1.o,x,y)) if(PL_hit(&pl1,3,o,HIT_SOME))
866 {pl1.o.vx+=xv;pl1.o.vy+=yv;return -1;}
867 if(_2pl && o!=-2) if(hit(pl2.o,x,y)) if(PL_hit(&pl2,3,o,HIT_SOME))
868 {pl2.o.vx+=xv;pl2.o.vy+=yv;return -2;}
870 for(i=0;i<MAXMN;++i) if(mn[i].t && o!=i)
871 if(hit(mn[i].o,x,y)) if(MN_hit(i,3,o,HIT_SOME))
872 {mn[i].o.vx+=xv;mn[i].o.vy+=yv;return 1;}
873 return 0;
876 static void goodsnd(void) {
877 if(!g_dm) return;
878 gsndt=18;
881 int Z_hit(obj_t *o,int d,int own,int t) {
882 int i;
884 hit_xv=o->xv+o->vx;
885 hit_yv=o->yv+o->vy;
886 if(Z_overlap(o,&pl1.o)) if(PL_hit(&pl1,d,own,t)) {
887 pl1.o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
888 pl1.o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
889 if(t==HIT_BFG) goodsnd();
890 return -1;
892 if(_2pl) if(Z_overlap(o,&pl2.o)) if(PL_hit(&pl2,d,own,t)) {
893 pl2.o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
894 pl2.o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
895 if(t==HIT_BFG) goodsnd();
896 return -2;
899 for(i=0;i<MAXMN;++i) if(mn[i].t)
900 if(Z_overlap(o,&mn[i].o)) if(MN_hit(i,d,own,t)) {
901 mn[i].o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
902 mn[i].o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
903 return 1;
905 return 0;
908 void MN_killedp(void) {
909 int i;
911 for(i=0;i<MAXMN;++i) if(mn[i].t==MN_MAN)
912 if(mn[i].st!=DEAD && mn[i].st!=DIE && mn[i].st!=SLEEP)
913 Z_sound(trupsnd,128);
916 int Z_hitobj(int obj,int d,int own,int t) {
917 hit_xv=hit_yv=0;
918 if(obj==-1) return PL_hit(&pl1,d,own,t);
919 else if(obj==-2 && _2pl) return PL_hit(&pl2,d,own,t);
920 else if(obj<0 || obj>=MAXMN) return 0;
921 if(mn[obj].t) return MN_hit(obj,d,own,t);
922 return 0;
925 void Z_explode(int x,int y,int rad,int own) {
926 long r;
927 int dx,dy,m,i;
929 if(x<-100 || x>FLDW*CELW+100) return;
930 if(y<-100 || y>FLDH*CELH+100) return;
931 r=(long)rad*rad;
932 dx=pl1.o.x-x;dy=pl1.o.y-pl1.o.h/2-y;
933 if((long)dx*dx+(long)dy*dy<r) {
934 if(!(m=max(abs(dx),abs(dy)))) m=1;
935 pl1.o.vx+=hit_xv=dx*10/m;
936 pl1.o.vy+=hit_yv=dy*10/m;
937 PL_hit(&pl1,100*(rad-m)/rad,own,HIT_ROCKET);
939 if(_2pl) {
940 dx=pl2.o.x-x;dy=pl2.o.y-pl2.o.h/2-y;
941 if((long)dx*dx+(long)dy*dy<r) {
942 if(!(m=max(abs(dx),abs(dy)))) m=1;
943 pl2.o.vx+=hit_xv=dx*10/m;
944 pl2.o.vy+=hit_yv=dy*10/m;
945 PL_hit(&pl2,100*(rad-m)/rad,own,HIT_ROCKET);
948 for(i=0;i<MAXMN;++i) if(mn[i].t) {
949 dx=mn[i].o.x-x;dy=mn[i].o.y-mn[i].o.h/2-y;
950 if((long)dx*dx+(long)dy*dy<r) {
951 if(!(m=max(abs(dx),abs(dy)))) m=1;
952 mn[i].o.vx+=hit_xv=dx*10/m;
953 mn[i].o.vy+=hit_yv=dy*10/m;
954 MN_hit(i,mn[i].o.r*10*(rad-m)/rad,own,HIT_ROCKET);
959 void Z_bfg9000(int x,int y,int own) {
960 int dx,dy,i;
962 hit_xv=hit_yv=0;
963 if(x<-100 || x>FLDW*CELW+100) return;
964 if(y<-100 || y>FLDH*CELH+100) return;
965 dx=pl1.o.x-x;dy=pl1.o.y-pl1.o.h/2-y;
966 if(own!=-1) if((long)dx*dx+(long)dy*dy<16000)
967 if(Z_cansee(x,y,pl1.o.x,pl1.o.y-pl1.o.h/2)) {
968 if(PL_hit(&pl1,50,own,HIT_SOME))
969 WP_bfghit(pl1.o.x,pl1.o.y-pl1.o.h/2,own);
971 if(_2pl) {
972 dx=pl2.o.x-x;dy=pl2.o.y-pl2.o.h/2-y;
973 if(own!=-2) if((long)dx*dx+(long)dy*dy<16000)
974 if(Z_cansee(x,y,pl2.o.x,pl2.o.y-pl2.o.h/2)) {
975 if(PL_hit(&pl2,50,own,HIT_SOME))
976 WP_bfghit(pl2.o.x,pl2.o.y-pl2.o.h/2,own);
979 for(i=0;i<MAXMN;++i) if(mn[i].t && own!=i) {
980 dx=mn[i].o.x-x;dy=mn[i].o.y-mn[i].o.h/2-y;
981 if((long)dx*dx+(long)dy*dy<16000)
982 if(Z_cansee(x,y,mn[i].o.x,mn[i].o.y-mn[i].o.h/2)) {
983 if(MN_hit(i,50,own,HIT_SOME))
984 WP_bfghit(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,own);
989 int Z_chktrap(int t,int d,int o,int ht) {
990 int i,s;
992 hit_xv=hit_yv=0;
993 s=0;
994 if(Z_istrapped(pl1.o.x,pl1.o.y,pl1.o.r,pl1.o.h)) {
995 s=1;
996 if(t) PL_hit(&pl1,d,o,ht);
998 if(_2pl) if(Z_istrapped(pl2.o.x,pl2.o.y,pl2.o.r,pl2.o.h)) {
999 s=1;
1000 if(t) PL_hit(&pl2,d,o,ht);
1002 for(i=0;i<MAXMN;++i) if(mn[i].t && mn[i].st!=DEAD)
1003 if(Z_istrapped(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h)) {
1004 s=1;
1005 if(t) MN_hit(i,d,o,ht);
1007 return s;
1010 void Z_teleobj(int o,int x,int y) {
1011 obj_t *p;
1013 if(o==-1) p=&pl1.o;
1014 else if(o==-2) p=&pl2.o;
1015 else if(o>=0 && o<MAXMN) p=&mn[o].o;
1016 else return;
1017 FX_tfog(p->x,p->y);FX_tfog(p->x=x,p->y=y);
1018 Z_sound(telesnd,128);
1021 void MN_warning(int l,int t,int r,int b) {
1022 int i;
1024 for(i=0;i<MAXMN;++i) if(mn[i].t && mn[i].t!=MN_CACO && mn[i].t!=MN_SOUL
1025 && mn[i].t!=MN_PAIN && mn[i].t!=MN_FISH)
1026 if(mn[i].st!=DIE && mn[i].st!=DEAD && mn[i].st!=SLEEP)
1027 if(mn[i].o.x+mn[i].o.r>=l && mn[i].o.x-mn[i].o.r<=r
1028 && mn[i].o.y>=t && mn[i].o.y-mn[i].o.h<=b)
1029 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
1030 mn[i].o.yv=-mnsz[mn[i].t].jv;