DEADSOFTWARE

ppc: fix saves and more map loading improvements
[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 i, n;
142 for (n = MAXMN - 1; n >= 0 && mn[n].t == 0; n--) {
143 // empty
145 n += 1;
146 myfwrite32(n, h);
147 for (i = 0; i < n; i++) {
148 myfwrite32(mn[i].o.x, h);
149 myfwrite32(mn[i].o.y, h);
150 myfwrite32(mn[i].o.xv, h);
151 myfwrite32(mn[i].o.yv, h);
152 myfwrite32(mn[i].o.vx, h);
153 myfwrite32(mn[i].o.vy, h);
154 myfwrite32(mn[i].o.r, h);
155 myfwrite32(mn[i].o.h, h);
156 myfwrite8(mn[i].t, h);
157 myfwrite8(mn[i].d, h);
158 myfwrite8(mn[i].st, h);
159 myfwrite8(mn[i].ftime, h);
160 myfwrite32(mn[i].fobj, h);
161 myfwrite32(mn[i].s, h);
162 myfwrite32(mn[i].ap, h); // useless, changed after load
163 myfwrite32(mn[i].aim, h);
164 myfwrite32(mn[i].life, h);
165 myfwrite32(mn[i].pain, h);
166 myfwrite32(mn[i].ac, h);
167 myfwrite32(mn[i].tx, h);
168 myfwrite32(mn[i].ty, h);
169 myfwrite32(mn[i].ammo, h);
170 myfwrite16(mn[i].atm, h);
172 myfwrite32(mnum, h);
173 myfwrite32(gsndt, h);
176 static void setst(int,int);
178 static int MN_hit(int n,int d,int o,int t);
180 void MN_loadgame (FILE *h) {
181 int i, n, c;
182 myfread32(&n, h);
183 for (i = 0; i < n; i++) {
184 myfread32(&mn[i].o.x, h);
185 myfread32(&mn[i].o.y, h);
186 myfread32(&mn[i].o.xv, h);
187 myfread32(&mn[i].o.yv, h);
188 myfread32(&mn[i].o.vx, h);
189 myfread32(&mn[i].o.vy, h);
190 myfread32(&mn[i].o.r, h);
191 myfread32(&mn[i].o.h, h);
192 myfread8(&mn[i].t, h);
193 myfread8(&mn[i].d, h);
194 myfread8(&mn[i].st, h);
195 myfread8(&mn[i].ftime, h);
196 myfread32(&mn[i].fobj, h);
197 myfread32(&mn[i].s, h);
198 myfread32(&mn[i].ap, h); // useless, changed after loading
199 myfread32(&mn[i].aim, h);
200 myfread32(&mn[i].life, h);
201 myfread32(&mn[i].pain, h);
202 myfread32(&mn[i].ac, h);
203 myfread32(&mn[i].tx, h);
204 myfread32(&mn[i].ty, h);
205 myfread32(&mn[i].ammo, h);
206 myfread16(&mn[i].atm, h);
208 myfread32(&mnum, h);
209 myfread32(&gsndt, h);
210 for (n = 0; n < MAXMN; ++n) {
211 if (mn[n].t) {
212 c = mn[n].ac;
213 setst(n, mn[n].st);
214 mn[n].ac = c;
219 #define GGAS_TOTAL (MN__LAST-MN_DEMON+16+10)
221 void MN_alloc(void) {
222 int i,j;
223 static char sn[MN_TN][5][6]={
224 {"DMACT","DMPAIN","SGTATK","SGTSIT","SGTDTH"},
225 {"BGACT","POPAIN","CLAW","",""},
226 {"POSACT","POPAIN","","",""},
227 {"POSACT","POPAIN","","",""},
228 {"","DMPAIN","HOOF","CYBSIT","CYBDTH"},
229 {"POSACT","POPAIN","","",""},
230 {"","DMPAIN","","BRSSIT","BRSDTH"},
231 {"","DMPAIN","","KNTSIT","KNTDTH"},
232 {"DMACT","DMPAIN","","CACSIT","CACDTH"},
233 {"DMACT","DMPAIN","SKLATK","SKLATK","FIRXPL"},
234 {"DMACT","PEPAIN","","PESIT","PEDTH"},
235 {"","DMPAIN","METAL","SPISIT","SPIDTH"},
236 {"BSPACT","DMPAIN","BSPWLK","BSPSIT","BSPDTH"},
237 {"DMACT","MNPAIN","MANATK","MANSIT","MANDTH"},
238 {"SKEACT","POPAIN","SKEATK","SKESIT","SKEDTH"},
239 {"VILACT","VIPAIN","VILATK","VILSIT","VILDTH"},
240 {"","","BITE1","",""},
241 {"","","","","BAREXP"},
242 {"BSPACT","","BSPWLK","BSPSIT","BSPDTH"},
243 {"HAHA1","PLPAIN","","STOP1","PDIEHI"}
244 },msn[MN_TN][4]={
245 "SARG","TROO","POSS","SPOS","CYBR","CPOS","BOSS","BOS2","HEAD","SKUL",
246 "PAIN","SPID","BSPI","FATT","SKEL","VILE","FISH","BAR1","ROBO","PLAY"
247 };
248 static char gsn[6]="GOOD0";
249 static int mms[MN_TN]={
250 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,
251 20*2,17*2,29*2,6*2,2*2,17*2,23*2
252 };
254 sgun[0]=Z_getspr("PWP4",0,1,NULL);
255 sgun[1]=Z_getspr("PWP4",1,1,NULL);
256 for(j=0;j<MN_TN;++j) {
257 for(i=0;i<mms[j];++i) spr[j][i]=Z_getspr(msn[j],i/2,(i&1)+1,&sprd[j][i]);
258 if(j==MN_BARREL-1)
259 for(i=4;i<14;++i) spr[j][i]=Z_getspr("BEXP",i/2-2,(i&1)+1,&sprd[j][i]);
260 for(i=0;i<5;++i)
261 if(sn[j][i][0]) snd[j][i]=Z_getsnd(sn[j][i]);
262 else snd[j][i]=NULL;
263 logo_gas(j+5,GGAS_TOTAL);
265 for(i=0;i<8;++i) fspr[i]=Z_getspr("FIRE",i,0,NULL);
266 pl_spr[0]=Z_getspr("PLAY",'N'-'A',0,NULL);
267 pl_spr[1]=Z_getspr("PLAY",'W'-'A',0,NULL);
268 impsitsnd[0]=Z_getsnd("BGSIT1");
269 impsitsnd[1]=Z_getsnd("BGSIT2");
270 impdthsnd[0]=Z_getsnd("BGDTH1");
271 impdthsnd[1]=Z_getsnd("BGDTH2");
272 positsnd[0]=Z_getsnd("POSIT1");
273 positsnd[1]=Z_getsnd("POSIT2");
274 positsnd[2]=Z_getsnd("POSIT3");
275 podthsnd[0]=Z_getsnd("PODTH1");
276 podthsnd[1]=Z_getsnd("PODTH2");
277 podthsnd[2]=Z_getsnd("PODTH3");
278 fsnd=Z_getsnd("FLAME");
279 firsnd=Z_getsnd("FIRSHT");
280 slopsnd=Z_getsnd("SLOP");
281 swgsnd=Z_getsnd("SKESWG");
282 pchsnd=Z_getsnd("SKEPCH");
283 telesnd=Z_getsnd("TELEPT");
284 pauksnd=Z_getsnd("PAUK1");
285 trupsnd=Z_getsnd("UTRUP");
286 for(i=0;i<4;++i) {gsn[4]=i+'1';gsnd[i]=Z_getsnd(gsn);}
289 void MN_init(void) {
290 int i;
292 for(i=0;i<MAXMN;++i) {mn[i].t=0;mn[i].st=SLEEP;}
293 gsndt=mnum=0;
296 static void setst(int i,int st) {
297 char *a;
298 int t;
300 switch(mn[i].st) {
301 case DIE: case DEAD:
302 if(st!=DEAD && st!=REVIVE) return;
304 mn[i].ac=0;
305 t=mn[i].t-1;
306 switch(mn[i].st=st) {
307 case SLEEP: a=sleepanim[t];break;
308 case PAIN: a=painanim[t];break;
309 case WAIT: a=waitanim[t];break;
310 case CLIMB:
311 case RUN: case RUNOUT:
312 case GO: a=goanim[t];break;
313 case SHOOT:
314 if(t==MN_SKEL-1) {a="KKKKJJ";break;}
315 if(t==MN_ROBO-1) {a="MN";break;}
316 case ATTACK: a=attackanim[t];
317 if(st==ATTACK && t==MN_VILE-1) a="[[\\\\]]";
318 break;
319 case DIE:
320 if(g_map==9 && t==MN_BSP-1) Z_sound(pauksnd,128);
321 a=dieanim[t];break;
322 case DEAD:
323 a=deadanim[t];
324 if(mn[i].ap==slopanim[t]) a=messanim[t];
325 if(t==MN_BARREL-1) {mn[i].t=0;}
326 break;
327 case REVIVE:
328 a=(mn[i].ap==messanim[t])?slopanim[t]:dieanim[t];
329 mn[i].ac=strlen(a)-1;
330 mn[i].o.r=mnsz[t+1].r;mn[i].o.h=mnsz[t+1].h;
331 mn[i].life=mnsz[t+1].l;mn[i].ammo=mn[i].pain=0;
332 ++mnum;
333 break;
335 mn[i].ap=a;
338 int MN_spawn(int x,int y,byte d,int t) {
339 int i;
341 if(g_dm && nomon && t<MN_PL_DEAD) return -1;
342 for(i=0;i<MAXMN;++i) if(!mn[i].t) goto ok;
343 for(i=0;i<MAXMN;++i) if(mn[i].t>=MN_PL_DEAD) goto ok;
344 return -1;
345 ok:
346 mn[i].o.x=x;mn[i].o.y=y;
347 mn[i].o.xv=mn[i].o.yv=mn[i].o.vx=mn[i].o.vy=0;
348 mn[i].d=d;mn[i].t=t;
349 mn[i].st=SLEEP;
350 if(t<MN_PL_DEAD) {
351 mn[i].o.r=mnsz[t].r;mn[i].o.h=mnsz[t].h;
352 mn[i].life=mnsz[t].l;
353 setst(i,SLEEP);mn[i].s=myrand(18);
354 ++mnum;
355 }else {mn[i].o.r=8;mn[i].o.h=6;mn[i].life=0;mn[i].st=DEAD;}
356 mn[i].aim=-3;mn[i].atm=0;
357 mn[i].pain=0;
358 mn[i].ammo=0;
359 mn[i].ftime=0;
360 return i;
363 int MN_spawn_deadpl(obj_t *o,byte c,int t) {
364 int i;
366 if((i=MN_spawn(o->x,o->y,c,t+MN_PL_DEAD))==-1) return -1;
367 mn[i].o=*o;return i;
370 static int isfriend(int a,int b) {
371 if(a==MN_BARREL || b==MN_BARREL) return 1;
372 if(a==b) switch(a) {
373 case MN_IMP: case MN_DEMON:
374 case MN_BARON: case MN_KNIGHT:
375 case MN_CACO: case MN_SOUL:
376 case MN_MANCUB: case MN_SKEL:
377 case MN_FISH:
378 return 1;
380 if(a==MN_SOUL && b==MN_PAIN) return 1;
381 if(b==MN_SOUL && a==MN_PAIN) return 1;
382 return 0;
385 static int MN_findnewprey(int i) {
386 int a,b,l;
388 a=!PL_isdead(&pl1);
389 if(_2pl) b=!PL_isdead(&pl2); else b=0;
390 if(a) {
391 if(b) mn[i].aim=(abs(mn[i].o.x-pl1.o.x)+abs(mn[i].o.y-pl1.o.y)
392 <= abs(mn[i].o.x-pl2.o.x)+abs(mn[i].o.y-pl2.o.y))?-1:-2;
393 else mn[i].aim=-1;
394 }else{
395 if(b) mn[i].aim=-2;
396 else{
397 for(a=0,b=32000,mn[i].aim=-3;a<MAXMN;++a)
398 if(mn[a].t && mn[a].st!=DEAD && a!=i && !isfriend(mn[a].t,mn[i].t))
399 if((l=abs(mn[i].o.x-mn[a].o.x)+abs(mn[i].o.y-mn[a].o.y))<b)
400 {mn[i].aim=a;b=l;}
401 if(mn[i].aim<0) {mn[i].atm=MAX_ATM;return 0;} else mn[i].atm=0;
404 return 1;
407 int Z_getobjpos(int i,obj_t *o) {
408 if(i==-1) {*o=pl1.o;return !PL_isdead(&pl1);}
409 if(_2pl) if(i==-2) {*o=pl2.o;return !PL_isdead(&pl2);}
410 if(i>=0 && i<MAXMN) if(mn[i].t && mn[i].st!=DEAD)
411 {*o=mn[i].o;return 1;}
412 return 0;
415 static void *wakeupsnd(int t) {
416 switch(t) {
417 case MN_IMP: return impsitsnd[myrand(2)];
418 case MN_ZOMBY: case MN_SERG: case MN_CGUN:
419 return positsnd[myrand(3)];
421 return snd[t-1][3];
424 static void *dthsnd(int t) {
425 switch(t) {
426 case MN_IMP: return impdthsnd[myrand(2)];
427 case MN_ZOMBY: case MN_SERG: case MN_CGUN:
428 return podthsnd[myrand(3)];
430 return snd[t-1][4];
433 static int canshoot(int t) {
434 switch(t) {
435 case MN_DEMON: case MN_FISH: case MN_BARREL:
436 return 0;
438 return 1;
441 static int shoot(int i,obj_t *o,int n) {
442 int xd,yd,m;
444 if(mn[i].ammo<0) return 0;
445 if(!n) switch(mn[i].t) {
446 case MN_FISH: case MN_BARREL:
447 case MN_DEMON: return 0;
448 case MN_CGUN:
449 case MN_BSP:
450 case MN_ROBO:
451 if(++mn[i].ammo>=50) mn[i].ammo=(mn[i].t==MN_ROBO)?-200:-50;
452 break;
453 case MN_MAN:
454 break;
455 case MN_MANCUB:
456 if(++mn[i].ammo>=5) mn[i].ammo=-50;
457 break;
458 case MN_SPIDER:
459 if(++mn[i].ammo>=100) mn[i].ammo=-50;
460 break;
461 case MN_CYBER:
462 if(rand()&1) return 0;
463 if(++mn[i].ammo>=10) mn[i].ammo=-50;
464 break;
465 case MN_BARON: case MN_KNIGHT:
466 if(rand()&7) return 0;
467 break;
468 case MN_SKEL:
469 if(rand()&31) return 0;
470 break;
471 case MN_VILE:
472 if(rand()&7) return 0;
473 break;
474 case MN_PAIN:
475 if(rand()&7) return 0;
476 break;
477 default:
478 if(rand()&15) return 0;
480 if(!Z_look(&mn[i].o,o,mn[i].d)) return 0;
481 mn[i].atm=0;
482 mn[i].tx=o->x+(o->xv+o->vx)*6;mn[i].ty=o->y-o->h/2+(o->yv+o->vy)*6;
483 if(abs(mn[i].tx-mn[i].o.x)<abs(mn[i].ty-mn[i].o.y+mn[i].o.h/2)) return 0;
484 switch(mn[i].t) {
485 case MN_IMP: case MN_BARON: case MN_KNIGHT: case MN_CACO:
486 setst(i,SHOOT);Z_sound(firsnd,128);break;
487 case MN_SKEL:
488 setst(i,SHOOT);Z_sound(snd[MN_SKEL-1][2],128);break;
489 case MN_VILE:
490 mn[i].tx=o->x;mn[i].ty=o->y;
491 setst(i,SHOOT);Z_sound(fsnd,128);
492 Z_sound(snd[MN_VILE-1][2],128);break;
493 case MN_SOUL:
494 setst(i,ATTACK);Z_sound(snd[MN_SOUL-1][2],128);
495 yd=mn[i].ty-mn[i].o.y+mn[i].o.h/2;xd=mn[i].tx-mn[i].o.x;
496 if(!(m=max(abs(xd),abs(yd)))) m=1;
497 mn[i].o.xv=xd*16/m;mn[i].o.yv=yd*16/m;
498 break;
499 case MN_MANCUB: if(mn[i].ammo==1) Z_sound(snd[MN_MANCUB-1][2],128);
500 case MN_ZOMBY: case MN_SERG: case MN_BSP: case MN_ROBO:
501 case MN_CYBER: case MN_CGUN: case MN_SPIDER:
502 case MN_PAIN: case MN_MAN:
503 setst(i,SHOOT);break;
504 default:
505 return 0;
507 return 1;
510 static int kick(int i,obj_t *o) {
511 switch(mn[i].t) {
512 case MN_FISH:
513 setst(i,ATTACK);return 1;
514 case MN_DEMON:
515 setst(i,ATTACK);Z_sound(snd[0][2],128);return 1;
516 case MN_IMP:
517 setst(i,ATTACK);Z_sound(snd[1][2],128);return 1;
518 case MN_SKEL:
519 setst(i,ATTACK);Z_sound(swgsnd,128);return 1;
520 case MN_ROBO:
521 setst(i,ATTACK);Z_sound(swgsnd,128);return 1;
522 case MN_BARON: case MN_KNIGHT: case MN_CACO: case MN_MANCUB:
523 return shoot(i,o,1);
525 return 0;
528 static int iscorpse(obj_t *o,int n) {
529 int i;
531 if(!n) if(rand()&7) return -3;
532 for(i=0;i<MAXMN;++i) if(mn[i].t) if(mn[i].st==DEAD)
533 if(Z_overlap(o,&mn[i].o)) switch(mn[i].t) {
534 case MN_SOUL: case MN_PAIN:
535 case MN_CYBER: case MN_SPIDER:
536 case MN_PL_DEAD: case MN_PL_MESS:
537 case MN_VILE: case MN_BARREL:
538 continue;
539 default:
540 return i;
542 return -3;
545 void MN_act(void) {
546 int i,st,sx,sy,t;
547 static obj_t o;
548 static int pt_x=0,pt_xs=1,pt_y=0,pt_ys=1;
550 if(abs(pt_x+=pt_xs) > 123) pt_xs=-pt_xs;
551 if(abs(pt_y+=pt_ys) > 50) pt_ys=-pt_ys;
552 if(gsndt>0) if(--gsndt==0) {
553 Z_sound(gsnd[myrand(4)],128);
555 for(i=0;i<MAXMN;++i) if((t=mn[i].t)!=0) {
556 switch(t) {
557 case MN_FISH:
558 if(!Z_inwater(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h)) break;
559 case MN_SOUL: case MN_PAIN: case MN_CACO:
560 if(mn[i].st!=DIE && mn[i].st!=DEAD) --mn[i].o.yv;
561 break;
562 }z_mon=1;st=Z_moveobj(&mn[i].o);z_mon=0;
563 BM_mark(&mn[i].o,BM_MONSTER);
564 if(st&Z_FALLOUT) {
565 if(t==MN_ROBO) g_exit=1;
566 mn[i].t=0;--mnum;continue;
568 if(st&Z_HITWATER) Z_splash(&mn[i].o,mn[i].o.r+mn[i].o.h);
569 SW_press(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h,8,i);
570 if(mn[i].ftime) {
571 --mn[i].ftime;
572 SMK_flame(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,
573 mn[i].o.xv+mn[i].o.vx,mn[i].o.yv+mn[i].o.vy,
574 mn[i].o.r/2,mn[i].o.h/2,rand()%(200*2+1)-200,-500,1,mn[i].fobj);
576 if(st&Z_INWATER) mn[i].ftime=0;
577 if(mn[i].st==DEAD) continue;
578 if(st&Z_INWATER) if(!(rand()&31)) switch(t) {
579 case MN_FISH:
580 if(rand()&3) break;
581 case MN_ROBO: case MN_BARREL:
582 case MN_PL_DEAD: case MN_PL_MESS:
583 FX_bubble(mn[i].o.x+((rand()&1)*2-1)*myrand(mn[i].o.r+1),
584 mn[i].o.y-myrand(mn[i].o.h+1),0,0,1
585 );
586 break;
587 default:
588 FX_bubble(mn[i].o.x,mn[i].o.y-mn[i].o.h*3/4,0,0,5);
591 if(t==MN_BARREL) {
593 if(!mn[i].ap[++mn[i].ac]) {
594 mn[i].ac=0;if(mn[i].st==DIE || mn[i].st==DEAD) {mn[i].t=0;}
595 }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);
596 continue;
598 if(t==MN_SOUL) if(st&Z_HITAIR) Z_set_speed(&mn[i].o,16);
599 if(mn[i].ammo<0) ++mn[i].ammo;
600 if(mn[i].o.yv<0)
601 if(st&Z_INWATER) mn[i].o.yv=-4;
602 ++mn[i].atm;
603 switch(mn[i].st) {
604 case PAIN:
605 if(mn[i].pain>=mnsz[t].mp)
606 {mn[i].pain=mnsz[t].mp;Z_sound(snd[t-1][1],128);}
607 if((mn[i].pain-=5)<=mnsz[t].minp)
608 {setst(i,GO);mn[i].pain=0;mn[i].ammo=-9;}
609 break;
610 case SLEEP:
611 if(++mn[i].s>=18) mn[i].s=0; else break;
612 if(Z_look(&mn[i].o,&pl1.o,mn[i].d))
613 {setst(i,GO);mn[i].aim=-1;mn[i].atm=0;Z_sound(wakeupsnd(t),128);}
614 if(_2pl) if(Z_look(&mn[i].o,&pl2.o,mn[i].d))
615 {setst(i,GO);mn[i].aim=-2;mn[i].atm=0;Z_sound(wakeupsnd(t),128);}
616 break;
617 case WAIT:
618 if(--mn[i].s<0) setst(i,GO);
619 break;
620 case GO:
621 if(st&Z_BLOCK) {mn[i].d^=1;setst(i,RUNOUT);mn[i].s=40;break;}
622 if(t==MN_VILE) if(iscorpse(&mn[i].o,0)>=0) {
623 setst(i,ATTACK);mn[i].o.xv=0;break;
625 if(!Z_getobjpos(mn[i].aim,&o) || mn[i].atm>MAX_ATM)
626 if(!MN_findnewprey(i)) {
627 mn[i].aim=-3;
628 o.x=mn[i].o.x+pt_x;o.y=mn[i].o.y+pt_y;
629 o.xv=o.vx=o.yv=o.vy=o.r=0;o.h=1;
630 }else Z_getobjpos(mn[i].aim,&o);
631 if(Z_overlap(&mn[i].o,&o)) {
632 mn[i].atm=0;
633 if(kick(i,&o)) break;
635 sx=o.x-mn[i].o.x;
636 sy=o.y-o.h/2-mn[i].o.y+mn[i].o.h/2;
637 if(!(st&Z_BLOCK)) if(abs(sx)<20)
638 if(t!=MN_FISH) {setst(i,RUN);mn[i].s=15;mn[i].d=rand()&1;break;}
639 if(st&Z_HITWALL) {
640 if(SW_press(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h,2,i))
641 {setst(i,WAIT);mn[i].s=4;break;}
642 switch(t) {
643 case MN_CACO: case MN_SOUL: case MN_PAIN: case MN_FISH:
644 break;
645 default:
646 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
647 {mn[i].o.yv=-mnsz[t].jv;setst(i,CLIMB);break;}
648 }break;
650 mn[i].d=(sx>0)?1:0;
651 if(canshoot(t))
652 if(abs(sx)>abs(sy)) if(shoot(i,&o,0)) break;
654 switch(t) {
655 case MN_FISH:
656 if(!(st&Z_INWATER)) {
657 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r)) {
658 mn[i].o.yv=-6;
659 mn[i].o.vx+=rand()%17-8;
660 }setst(i,PAIN);mn[i].pain+=50;break;
662 case MN_CACO: case MN_SOUL: case MN_PAIN:
663 if(abs(sy)>4) mn[i].o.yv=(sy<0)?-4:4; else mn[i].o.yv=0;
664 if(t==MN_FISH) if(mn[i].o.yv<0)
665 if(!Z_inwater(mn[i].o.x,mn[i].o.y-8,mn[i].o.r,mn[i].o.h))
666 {mn[i].o.yv=0;setst(i,RUN);mn[i].d=rand()&1;mn[i].s=20;}
667 break;
668 default:
669 if(sy<-20) if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
670 if(!(rand()&3)) mn[i].o.yv=-mnsz[t].jv;
672 if(++mn[i].s>=8) {
673 mn[i].s=0;
674 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
676 mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
677 if(st&Z_INWATER) mn[i].o.xv/=2;
678 else if(t==MN_FISH) mn[i].o.xv=0;
679 break;
680 case RUN:
681 if(st&Z_BLOCK) {setst(i,RUNOUT);mn[i].d^=1;mn[i].s=40;break;}
682 if(--mn[i].s<=0 || ((st&Z_HITWALL) && mn[i].o.yv+mn[i].o.vy==0)) {
683 setst(i,GO);mn[i].s=0;if(st&(Z_HITWALL|Z_BLOCK)) mn[i].d^=1;
684 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
685 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
686 if(st&Z_INWATER) mn[i].o.xv/=2;
687 else if(t==MN_FISH) mn[i].o.xv=0;
688 break;
689 case RUNOUT:
690 if(!(st&Z_BLOCK) && mn[i].s>0) mn[i].s=0;
691 if(--mn[i].s<=-18) {
692 setst(i,GO);mn[i].s=0;if(st&(Z_HITWALL|Z_BLOCK)) mn[i].d^=1;
693 if(!(rand()&7)) Z_sound(snd[t-1][0],128);
694 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
695 if(st&Z_INWATER) mn[i].o.xv/=2;
696 else if(t==MN_FISH) mn[i].o.xv=0;
697 break;
698 case CLIMB:
699 if(mn[i].o.yv+mn[i].o.vy>=0 || !(st&Z_HITWALL)) {
700 setst(i,GO);mn[i].s=0;
701 if(st&(Z_HITWALL|Z_BLOCK)) {mn[i].d^=1;setst(i,RUN);mn[i].s=15;}
702 }mn[i].o.xv=((mn[i].d)?1:-1)*mnsz[t].rv;
703 if(st&Z_INWATER) mn[i].o.xv/=2;
704 else if(t==MN_FISH) mn[i].o.xv=0;
705 break;
706 case ATTACK:
707 case SHOOT:
708 if(t==MN_SOUL) {if(st&(Z_HITWALL|Z_HITCEIL|Z_HITLAND)) setst(i,GO); break;}
709 if(t!=MN_FISH) mn[i].o.xv=Z_dec(mn[i].o.xv,1);
710 if(t==MN_VILE && mn[i].st==SHOOT) {
711 if(!Z_getobjpos(mn[i].aim,&o)) {setst(i,GO);break;}
712 if(!Z_look(&mn[i].o,&o,mn[i].d)) {setst(i,GO);break;}
713 if(Z_inwater(o.x,o.y,o.r,o.h)) {setst(i,GO);break;}
714 mn[i].tx=o.x;mn[i].ty=o.y;
715 Z_hitobj(mn[i].aim,2,i,HIT_SOME);
716 }break;
718 if(mn[i].st==REVIVE) {
719 if(--mn[i].ac==0) setst(i,GO);
720 }else ++mn[i].ac;
721 if(!mn[i].ap[mn[i].ac]) switch(mn[i].st) {
722 case ATTACK:
723 switch(t) {
724 case MN_SOUL: mn[i].ac=0;
725 case MN_IMP:
726 case MN_DEMON:
727 if(Z_hit(&mn[i].o,15,i,HIT_SOME)) if(t==MN_SOUL) setst(i,GO);
728 break;
729 case MN_FISH:
730 if(Z_hit(&mn[i].o,10,i,HIT_SOME))
731 Z_sound(snd[MN_FISH-1][2],128);
732 break;
733 case MN_SKEL: case MN_ROBO:
734 o=mn[i].o;o.xv=mn[i].d?50:-50;
735 if(Z_hit(&o,50,i,HIT_SOME)) Z_sound(pchsnd,128);
736 break;
737 case MN_VILE:
738 sx=iscorpse(&mn[i].o,1);
739 if(sx==-3) break;
740 if(!mn[sx].t || mn[sx].st!=DEAD) break;
741 setst(sx,REVIVE);Z_sound(slopsnd,128);
742 hit_xv=hit_yv=0;MN_hit(i,5,-3,HIT_SOME);
743 break;
744 }if(t!=MN_SOUL && mn[i].st!=DIE) setst(i,GO);
745 break;
746 case SHOOT:
747 switch(t) {
748 case MN_IMP:
749 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);
750 break;
751 case MN_ZOMBY:
752 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);
753 break;
754 case MN_SERG:
755 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);
756 break;
757 case MN_MAN:
758 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);
759 mn[i].ammo=-36;break;
760 case MN_CYBER:
761 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);
762 break;
763 case MN_SKEL:
764 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);
765 break;
766 case MN_CGUN:
767 case MN_SPIDER:
768 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);
769 break;
770 case MN_BSP:
771 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);
772 break;
773 case MN_ROBO:
774 WP_plasma(mn[i].o.x+(mn[i].d*2-1)*15,mn[i].o.y-30,mn[i].tx,mn[i].ty,i);
775 break;
776 case MN_MANCUB:
777 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);
778 break;
779 case MN_BARON: case MN_KNIGHT:
780 WP_ball7(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
781 break;
782 case MN_CACO:
783 WP_ball2(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,mn[i].tx,mn[i].ty,i);
784 break;
785 case MN_PAIN:
786 if((sx=MN_spawn(mn[i].o.x,mn[i].o.y,mn[i].d,MN_SOUL))==-1) break;
787 Z_getobjpos(mn[sx].aim=mn[i].aim,&o);mn[sx].atm=0;
788 shoot(sx,&o,1);
789 break;
791 if(t==MN_CGUN || t==MN_SPIDER || t==MN_BSP || t==MN_MANCUB || t==MN_ROBO)
792 if(!Z_getobjpos(mn[i].aim,&o)) MN_findnewprey(i);
793 else if(shoot(i,&o,0)) break;
794 setst(i,GO);break;
795 case DIE:
796 setst(i,DEAD);
797 if(t==MN_PAIN || t==MN_SOUL) mn[i].ftime=0;
798 if(t==MN_PAIN) {
799 if((sx=MN_spawn(mn[i].o.x-15,mn[i].o.y,0,MN_SOUL))==-1) break;
800 setst(sx,GO);
801 if((sx=MN_spawn(mn[i].o.x+15,mn[i].o.y,1,MN_SOUL))==-1) break;
802 setst(sx,GO);
803 if((sx=MN_spawn(mn[i].o.x,mn[i].o.y-10,1,MN_SOUL))==-1) break;
804 setst(sx,GO);
805 }break;
806 default: mn[i].ac=0;
808 switch(mn[i].st) {
809 case GO: case RUN: case CLIMB: case RUNOUT:
810 if(t==MN_CYBER || t==MN_SPIDER || t==MN_BSP) {
811 if(mn[i].ac==0 || mn[i].ac==6) Z_sound(snd[t-1][2],128);
812 }else if(t==MN_ROBO)
813 if(mn[i].ac==0 || mn[i].ac==12) Z_sound(snd[t-1][2],128);
818 void MN_mark(void) {
819 int i;
820 for(i=0;i<MAXMN;++i) if(mn[i].t!=0) BM_mark(&mn[i].o,BM_MONSTER);
823 void MN_draw(void) {
824 int i;
826 for(i=0;i<MAXMN;++i) if(mn[i].t) {
828 if(mn[i].t>=MN_PL_DEAD) {
829 Z_drawmanspr(mn[i].o.x,mn[i].o.y,pl_spr[mn[i].t-MN_PL_DEAD],0,mn[i].d);
830 continue;
832 if((mn[i].t!=MN_SOUL && mn[i].t!=MN_PAIN) || mn[i].st!=DEAD) {
833 if(mn[i].t!=MN_MAN)
834 Z_drawspr(mn[i].o.x,mn[i].o.y,
835 spr[mn[i].t-1][(mn[i].ap[mn[i].ac]-'A')*2+mn[i].d],
836 sprd[mn[i].t-1][(mn[i].ap[mn[i].ac]-'A')*2+mn[i].d]);
837 else{
838 if(mn[i].ap[mn[i].ac]=='E' || mn[i].ap[mn[i].ac]=='F')
839 Z_drawspr(mn[i].o.x,mn[i].o.y,sgun[mn[i].ap[mn[i].ac]-'E'],mn[i].d);
840 Z_drawmanspr(mn[i].o.x,mn[i].o.y,
841 spr[mn[i].t-1][(mn[i].ap[mn[i].ac]-'A')*2+mn[i].d],
842 sprd[mn[i].t-1][(mn[i].ap[mn[i].ac]-'A')*2+mn[i].d],MANCOLOR);
845 if(mn[i].t==MN_VILE && mn[i].st==SHOOT) {
846 Z_drawspr(mn[i].tx,mn[i].ty,fspr[mn[i].ac/3],0);
851 int MN_hit(int n,int d,int o,int t) {
852 int i;
854 if(mn[n].st==DEAD || mn[n].st==DIE) return 0;
855 if(o==n) {
856 if(t!=HIT_ROCKET && t!=HIT_ELECTRO) return 0;
857 if(mn[n].t==MN_CYBER || mn[n].t==MN_BARREL) return 1;
859 if(o>=0) {
860 if(mn[o].t==MN_SOUL && mn[n].t==MN_PAIN) return 0;
861 if(mn[o].t==mn[n].t) switch(mn[n].t) {
862 case MN_IMP: case MN_DEMON:
863 case MN_BARON: case MN_KNIGHT:
864 case MN_CACO: case MN_SOUL:
865 case MN_MANCUB: case MN_SKEL:
866 case MN_FISH:
867 return 0;
870 if(t==HIT_FLAME) if(mn[n].ftime && mn[n].fobj==o) {if(g_time&31) return 1;}
871 else {mn[n].ftime=255;mn[n].fobj=o;}
872 if(t==HIT_ELECTRO) if(mn[n].t==MN_FISH)
873 {setst(n,RUN);mn[n].s=20;mn[n].d=rand()&1;return 1;}
874 if(t==HIT_TRAP) mn[n].life=-100;
875 if(mn[n].t==MN_ROBO) d=0;
876 if((mn[n].life-=d)<=0) --mnum;
877 if(!mn[n].pain) mn[n].pain=3;
878 mn[n].pain+=d;
879 if(mn[n].st!=PAIN) {
880 if(mn[n].pain>=mnsz[mn[n].t].minp) setst(n,PAIN);
882 if(mn[n].t!=MN_BARREL)
883 DOT_blood(mn[n].o.x,mn[n].o.y-mn[n].o.h/2,hit_xv,hit_yv,d*2);
884 mn[n].aim=o;mn[n].atm=0;
885 if(mn[n].life<=0) {
886 if(mn[n].t!=MN_BARREL)
887 if(o==-1) ++pl1.kills;
888 else if(o==-2) ++pl2.kills;
889 setst(n,DIE);
890 switch(mn[n].t) {
891 case MN_ZOMBY: i=I_CLIP;break;
892 case MN_SERG: i=I_SGUN;break;
893 case MN_CGUN: i=I_MGUN;break;
894 case MN_MAN: i=I_KEYR;break;
895 default: i=0;
896 }if(i) IT_spawn(mn[n].o.x,mn[n].o.y,i);
897 mn[n].o.xv=0;mn[n].o.h=6;
898 if(mn[n].life<=-mnsz[mn[n].t].sp)
899 switch(mn[n].t) {
900 case MN_IMP: case MN_ZOMBY: case MN_SERG: case MN_CGUN:
901 case MN_MAN:
902 mn[n].ap=slopanim[mn[n].t-1];
903 Z_sound(slopsnd,128);
904 break;
905 case MN_BSP: if(g_map==9) break;
906 default:
907 Z_sound(dthsnd(mn[n].t),128);
909 else if(mn[n].t!=MN_BSP || g_map!=9) Z_sound(dthsnd(mn[n].t),128);
910 mn[n].life=0;
911 }else if(mn[n].st==SLEEP) {setst(n,GO);mn[n].pain=mnsz[mn[n].t].mp;}
912 return 1;
915 #define hit(o,x,y) (y<=o.y && y>o.y-o.h && x>=o.x-o.r && x<=o.x+o.r)
917 int Z_gunhit(int x,int y,int o,int xv,int yv) {
918 int i;
920 if(o!=-1) if(hit(pl1.o,x,y)) if(PL_hit(&pl1,3,o,HIT_SOME))
921 {pl1.o.vx+=xv;pl1.o.vy+=yv;return -1;}
922 if(_2pl && o!=-2) if(hit(pl2.o,x,y)) if(PL_hit(&pl2,3,o,HIT_SOME))
923 {pl2.o.vx+=xv;pl2.o.vy+=yv;return -2;}
925 for(i=0;i<MAXMN;++i) if(mn[i].t && o!=i)
926 if(hit(mn[i].o,x,y)) if(MN_hit(i,3,o,HIT_SOME))
927 {mn[i].o.vx+=xv;mn[i].o.vy+=yv;return 1;}
928 return 0;
931 static void goodsnd(void) {
932 if(!g_dm) return;
933 gsndt=18;
936 int Z_hit(obj_t *o,int d,int own,int t) {
937 int i;
939 hit_xv=o->xv+o->vx;
940 hit_yv=o->yv+o->vy;
941 if(Z_overlap(o,&pl1.o)) if(PL_hit(&pl1,d,own,t)) {
942 pl1.o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
943 pl1.o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
944 if(t==HIT_BFG) goodsnd();
945 return -1;
947 if(_2pl) if(Z_overlap(o,&pl2.o)) if(PL_hit(&pl2,d,own,t)) {
948 pl2.o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
949 pl2.o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
950 if(t==HIT_BFG) goodsnd();
951 return -2;
954 for(i=0;i<MAXMN;++i) if(mn[i].t)
955 if(Z_overlap(o,&mn[i].o)) if(MN_hit(i,d,own,t)) {
956 mn[i].o.vx+=(o->xv+o->vx)*((t==HIT_BFG)?8:1)/4;
957 mn[i].o.vy+=(o->yv+o->vy)*((t==HIT_BFG)?8:1)/4;
958 return 1;
960 return 0;
963 void MN_killedp(void) {
964 int i;
966 for(i=0;i<MAXMN;++i) if(mn[i].t==MN_MAN)
967 if(mn[i].st!=DEAD && mn[i].st!=DIE && mn[i].st!=SLEEP)
968 Z_sound(trupsnd,128);
971 int Z_hitobj(int obj,int d,int own,int t) {
972 hit_xv=hit_yv=0;
973 if(obj==-1) return PL_hit(&pl1,d,own,t);
974 else if(obj==-2 && _2pl) return PL_hit(&pl2,d,own,t);
975 else if(obj<0 || obj>=MAXMN) return 0;
976 if(mn[obj].t) return MN_hit(obj,d,own,t);
977 return 0;
980 void Z_explode(int x,int y,int rad,int own) {
981 long r;
982 int dx,dy,m,i;
984 if(x<-100 || x>FLDW*CELW+100) return;
985 if(y<-100 || y>FLDH*CELH+100) return;
986 r=(long)rad*rad;
987 dx=pl1.o.x-x;dy=pl1.o.y-pl1.o.h/2-y;
988 if((long)dx*dx+(long)dy*dy<r) {
989 if(!(m=max(abs(dx),abs(dy)))) m=1;
990 pl1.o.vx+=hit_xv=dx*10/m;
991 pl1.o.vy+=hit_yv=dy*10/m;
992 PL_hit(&pl1,100*(rad-m)/rad,own,HIT_ROCKET);
994 if(_2pl) {
995 dx=pl2.o.x-x;dy=pl2.o.y-pl2.o.h/2-y;
996 if((long)dx*dx+(long)dy*dy<r) {
997 if(!(m=max(abs(dx),abs(dy)))) m=1;
998 pl2.o.vx+=hit_xv=dx*10/m;
999 pl2.o.vy+=hit_yv=dy*10/m;
1000 PL_hit(&pl2,100*(rad-m)/rad,own,HIT_ROCKET);
1003 for(i=0;i<MAXMN;++i) if(mn[i].t) {
1004 dx=mn[i].o.x-x;dy=mn[i].o.y-mn[i].o.h/2-y;
1005 if((long)dx*dx+(long)dy*dy<r) {
1006 if(!(m=max(abs(dx),abs(dy)))) m=1;
1007 mn[i].o.vx+=hit_xv=dx*10/m;
1008 mn[i].o.vy+=hit_yv=dy*10/m;
1009 MN_hit(i,mn[i].o.r*10*(rad-m)/rad,own,HIT_ROCKET);
1014 void Z_bfg9000(int x,int y,int own) {
1015 int dx,dy,i;
1017 hit_xv=hit_yv=0;
1018 if(x<-100 || x>FLDW*CELW+100) return;
1019 if(y<-100 || y>FLDH*CELH+100) return;
1020 dx=pl1.o.x-x;dy=pl1.o.y-pl1.o.h/2-y;
1021 if(own!=-1) if((long)dx*dx+(long)dy*dy<16000)
1022 if(Z_cansee(x,y,pl1.o.x,pl1.o.y-pl1.o.h/2)) {
1023 if(PL_hit(&pl1,50,own,HIT_SOME))
1024 WP_bfghit(pl1.o.x,pl1.o.y-pl1.o.h/2,own);
1026 if(_2pl) {
1027 dx=pl2.o.x-x;dy=pl2.o.y-pl2.o.h/2-y;
1028 if(own!=-2) if((long)dx*dx+(long)dy*dy<16000)
1029 if(Z_cansee(x,y,pl2.o.x,pl2.o.y-pl2.o.h/2)) {
1030 if(PL_hit(&pl2,50,own,HIT_SOME))
1031 WP_bfghit(pl2.o.x,pl2.o.y-pl2.o.h/2,own);
1034 for(i=0;i<MAXMN;++i) if(mn[i].t && own!=i) {
1035 dx=mn[i].o.x-x;dy=mn[i].o.y-mn[i].o.h/2-y;
1036 if((long)dx*dx+(long)dy*dy<16000)
1037 if(Z_cansee(x,y,mn[i].o.x,mn[i].o.y-mn[i].o.h/2)) {
1038 if(MN_hit(i,50,own,HIT_SOME))
1039 WP_bfghit(mn[i].o.x,mn[i].o.y-mn[i].o.h/2,own);
1044 int Z_chktrap(int t,int d,int o,int ht) {
1045 int i,s;
1047 hit_xv=hit_yv=0;
1048 s=0;
1049 if(Z_istrapped(pl1.o.x,pl1.o.y,pl1.o.r,pl1.o.h)) {
1050 s=1;
1051 if(t) PL_hit(&pl1,d,o,ht);
1053 if(_2pl) if(Z_istrapped(pl2.o.x,pl2.o.y,pl2.o.r,pl2.o.h)) {
1054 s=1;
1055 if(t) PL_hit(&pl2,d,o,ht);
1057 for(i=0;i<MAXMN;++i) if(mn[i].t && mn[i].st!=DEAD)
1058 if(Z_istrapped(mn[i].o.x,mn[i].o.y,mn[i].o.r,mn[i].o.h)) {
1059 s=1;
1060 if(t) MN_hit(i,d,o,ht);
1062 return s;
1065 void Z_teleobj(int o,int x,int y) {
1066 obj_t *p;
1068 if(o==-1) p=&pl1.o;
1069 else if(o==-2) p=&pl2.o;
1070 else if(o>=0 && o<MAXMN) p=&mn[o].o;
1071 else return;
1072 FX_tfog(p->x,p->y);FX_tfog(p->x=x,p->y=y);
1073 Z_sound(telesnd,128);
1076 void MN_warning(int l,int t,int r,int b) {
1077 int i;
1079 for(i=0;i<MAXMN;++i) if(mn[i].t && mn[i].t!=MN_CACO && mn[i].t!=MN_SOUL
1080 && mn[i].t!=MN_PAIN && mn[i].t!=MN_FISH)
1081 if(mn[i].st!=DIE && mn[i].st!=DEAD && mn[i].st!=SLEEP)
1082 if(mn[i].o.x+mn[i].o.r>=l && mn[i].o.x-mn[i].o.r<=r
1083 && mn[i].o.y>=t && mn[i].o.y-mn[i].o.h<=b)
1084 if(Z_canstand(mn[i].o.x,mn[i].o.y,mn[i].o.r))
1085 mn[i].o.yv=-mnsz[mn[i].t].jv;