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
36 extern int hit_xv
,hit_yv
;
38 void bfg_fly(int x
,int y
,int own
);
40 enum{NONE
=0,ROCKET
,PLASMA
,APLASMA
,BALL1
,BALL2
,BALL7
,BFGBALL
,BFGHIT
,
52 static void *snd
[14],*spr
[49*2];
53 static char sprd
[49*2];
54 static weapon_t wp
[MAXWPN
];
56 static void throw(int,int,int,int,int,int,int,int);
58 void WP_savegame(FILE* h
) {
61 for(n
=MAXWPN
;--n
;) if(wp
[n
].t
) break;
62 ++n
;myfwrite(&n
,1,4,h
);myfwrite(wp
,1,n
*sizeof(wp
[0]),h
);
65 void WP_loadgame(FILE* h
) {
68 myfread(&n
,1,4,h
);myfread(wp
,1,n
*sizeof(wp
[0]),h
);
73 static char nm
[14][6]={
91 spr
[i
*2]=Z_getspr("MISL",i
,1,sprd
+i
*2);
92 spr
[i
*2+1]=Z_getspr("MISL",i
,2,sprd
+i
*2+1);
95 spr
[i
*2]=Z_getspr("PLSS",i
-4,1,sprd
+i
*2);
96 spr
[i
*2+1]=Z_getspr("PLSS",i
-4,2,sprd
+i
*2+1);
99 spr
[i
*2]=Z_getspr("PLSE",i
-6,1,sprd
+i
*2);
100 spr
[i
*2+1]=Z_getspr("PLSE",i
-6,2,sprd
+i
*2+1);
103 spr
[i
*2]=Z_getspr("APLS",i
-11,1,sprd
+i
*2);
104 spr
[i
*2+1]=Z_getspr("APLS",i
-11,2,sprd
+i
*2+1);
107 spr
[i
*2]=Z_getspr("APBX",i
-13,1,sprd
+i
*2);
108 spr
[i
*2+1]=Z_getspr("APBX",i
-13,2,sprd
+i
*2+1);
111 spr
[i
*2]=Z_getspr("BFS1",i
-18,1,sprd
+i
*2);
112 spr
[i
*2+1]=Z_getspr("BFS1",i
-18,2,sprd
+i
*2+1);
115 spr
[i
*2]=Z_getspr("BFE1",i
-20,1,sprd
+i
*2);
116 spr
[i
*2+1]=Z_getspr("BFE1",i
-20,2,sprd
+i
*2+1);
119 spr
[i
*2]=Z_getspr("BFE2",i
-26,1,sprd
+i
*2);
120 spr
[i
*2+1]=Z_getspr("BFE2",i
-26,2,sprd
+i
*2+1);
123 spr
[i
*2]=Z_getspr("MISL",i
-30+4,1,sprd
+i
*2);
124 spr
[i
*2+1]=Z_getspr("MISL",i
-30+4,2,sprd
+i
*2+1);
127 spr
[i
*2]=Z_getspr("BAL1",i
-32,1,sprd
+i
*2);
128 spr
[i
*2+1]=Z_getspr("BAL1",i
-32,2,sprd
+i
*2+1);
131 spr
[i
*2]=Z_getspr("BAL7",i
-37,1,sprd
+i
*2);
132 spr
[i
*2+1]=Z_getspr("BAL7",i
-37,2,sprd
+i
*2+1);
135 spr
[i
*2]=Z_getspr("BAL2",i
-42,1,sprd
+i
*2);
136 spr
[i
*2+1]=Z_getspr("BAL2",i
-42,2,sprd
+i
*2+1);
139 spr
[i
*2]=Z_getspr("MANF",i
-47,1,sprd
+i
*2);
140 spr
[i
*2+1]=Z_getspr("MANF",i
-47,2,sprd
+i
*2+1);
142 for(i
=0;i
<14;++i
) snd
[i
]=Z_getsnd(nm
[i
]);
148 for(i
=0;i
<MAXWPN
;++i
) wp
[i
].t
=NONE
;
155 for(i
=0;i
<MAXWPN
;++i
) if(wp
[i
].t
) {
156 if(wp
[i
].t
==ROCKET
|| wp
[i
].t
==REVF
)
157 SMK_gas(wp
[i
].o
.x
+Z_sign(wp
[i
].o
.xv
)*2,
158 wp
[i
].o
.y
-wp
[i
].o
.h
/2,3,3,
159 wp
[i
].o
.xv
+wp
[i
].o
.vx
,wp
[i
].o
.yv
+wp
[i
].o
.vy
,64
161 --wp
[i
].o
.yv
;st
=Z_moveobj(&wp
[i
].o
);
162 if(st
&Z_FALLOUT
) {wp
[i
].t
=0;continue;}
163 if(st
&Z_HITWATER
) switch(wp
[i
].t
) {
164 case PLASMA
: case APLASMA
:
168 Z_splash(&wp
[i
].o
,wp
[i
].o
.r
+wp
[i
].o
.h
);break;
172 if(Z_getobjpos(wp
[i
].target
,&o
))
173 throw(i
,wp
[i
].o
.x
,wp
[i
].o
.y
-2,o
.x
+o
.xv
+o
.vx
,o
.y
+o
.yv
+o
.vy
,2,5,12);
175 if(wp
[i
].s
>=2) {if(++wp
[i
].s
>=8) wp
[i
].t
=0; break;}
176 if(st
&Z_HITAIR
) Z_set_speed(&wp
[i
].o
,12);
177 if(st
&(Z_HITWALL
|Z_HITCEIL
|Z_HITLAND
)) {
178 wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[4],128);
179 Z_explode(wp
[i
].o
.x
,wp
[i
].o
.y
,30,wp
[i
].own
);break;}
180 else if(Z_hit(&wp
[i
].o
,10,wp
[i
].own
,HIT_SOME
)) {
181 wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[4],128);
182 Z_explode(wp
[i
].o
.x
,wp
[i
].o
.y
-wp
[i
].o
.h
/2,30,wp
[i
].own
);break;}
183 bfg_fly(wp
[i
].o
.x
,wp
[i
].o
.y
-wp
[i
].o
.h
/2,wp
[i
].own
);
188 Z_sound(snd
[12],128);
189 Z_water_trap(&wp
[i
].o
);
190 Z_chktrap(1,10,wp
[i
].own
,HIT_ELECTRO
);
199 {if(++wp
[i
].s
>=((wp
[i
].t
==BALL1
|| wp
[i
].t
==BALL7
|| wp
[i
].t
==BALL2
|| wp
[i
].t
==MANF
)?8:12)) wp
[i
].t
=0; break;}
200 if(st
&Z_HITAIR
) Z_set_speed(&wp
[i
].o
,16);
201 if(st
&(Z_HITWALL
|Z_HITCEIL
|Z_HITLAND
))
202 {wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[7],128);break;}
203 else if(Z_hit(&wp
[i
].o
,(wp
[i
].t
==BALL7
|| wp
[i
].t
==MANF
)?40:((wp
[i
].t
==BALL2
)?20:5),wp
[i
].own
,HIT_SOME
))
204 {wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[7],128);break;}
208 Z_sound(snd
[8],40);Z_sound(snd
[13],128);
209 Z_water_trap(&wp
[i
].o
);
210 Z_chktrap(1,1000,wp
[i
].own
,HIT_ELECTRO
);
214 if(wp
[i
].s
>=2) {if(++wp
[i
].s
>=14) wp
[i
].t
=0; break;}
215 else if(st
&(Z_HITWALL
|Z_HITCEIL
|Z_HITLAND
)) {
216 Z_bfg9000(wp
[i
].o
.x
,wp
[i
].o
.y
,wp
[i
].own
);
217 wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[8],128);break;}
218 else if(Z_hit(&wp
[i
].o
,100,wp
[i
].own
,HIT_BFG
)) {
219 Z_bfg9000(wp
[i
].o
.x
,wp
[i
].o
.y
,wp
[i
].own
);
220 wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[8],128);break;}
221 bfg_fly(wp
[i
].o
.x
,wp
[i
].o
.y
-wp
[i
].o
.h
/2,wp
[i
].own
);
224 if(++wp
[i
].s
>=8) wp
[i
].t
=0;
234 for(i
=0;i
<MAXWPN
;++i
) {
237 case NONE
: default: break;
241 d
=(wp
[i
].o
.xv
>0)?1:0;
242 x
=abs(wp
[i
].o
.xv
);y
=wp
[i
].o
.yv
;s
=0;
243 if(y
<0) {if(-y
>=x
) s
=30;}
244 else if(y
>0) if(y
>=x
/2) s
=31;
245 }else {s
=(d
-2)/2+1;d
=0;}
248 if((s
=wp
[i
].s
)>=2) {s
/=2;break;}
254 if((s
=wp
[i
].s
)>=2) s
=s
/2+1;
256 case PLASMA
: s
+=4;break;
257 case APLASMA
: s
+=11;break;
258 case BALL1
: s
+=32;break;
259 case BALL2
: s
+=42;break;
260 case BALL7
: s
+=37;d
=(wp
[i
].o
.xv
>=0)?1:0;break;
261 case MANF
: s
+=47;d
=(wp
[i
].o
.xv
>=0)?1:0;break;
264 if((s
=wp
[i
].s
)>=2) s
=s
/2+1;
267 s
=wp
[i
].s
/2+26;break;
269 if(s
>=0) Z_drawspr(wp
[i
].o
.x
,wp
[i
].o
.y
,spr
[s
*2+d
],sprd
[s
*2+d
]);
273 void WP_gun(int x
,int y
,int xd
,int yd
,int o
,int v
) {
279 f
=BM_MONSTER
|BM_WALL
;
280 if(o
!=-1) f
|=BM_PLR1
;
281 if(o
!=-2) f
|=BM_PLR2
;
288 if(!xd
&& !yd
) return;
289 if((xd
=abs(xd
)) > (yd
=abs(yd
))) d
=xd
; else d
=yd
;
295 if(x
<0 || x
>=FLDW
*8 || y
<0 || y
>=FLDH
*8) break;
296 if(((m
=bmap
[y
>>5][x
>>5])&f
)) {
297 if(m
&BM_WALL
) if(fld
[y
>>3][x
>>3]==1 || fld
[y
>>3][x
>>3]==2) {
298 for(x
=lx
,y
=ly
,xe
=ye
=0;fld
[y
>>3][x
>>3]!=1 && fld
[y
>>3][x
>>3]!=2;) {
300 if((xe
+=xd
)>=d
) {xe
-=d
;x
+=sx
;}
301 if((ye
+=yd
)>=d
) {ye
-=d
;y
+=sy
;}
303 DOT_spark(lx
,ly
,sx
*10,sy
*10,1);
306 if(m
&(BM_MONSTER
|BM_PLR1
|BM_PLR2
)) if(Z_gunhit(x
,y
,o
,sx
*v
,sy
*v
)) break;
308 if((xe
+=(xd
<<3))>=d
) {
311 if((ye
+=(yd
<<3))>=d
) {
316 else{m
=x
&31;if(sx
>0) m
^=31; ++m
;}
318 else{s
=y
&31;if(sy
>0) s
^=31; ++s
;}
319 if((s
<m
&& s
!=0) || m
==0) m
=s
;
321 x
+=(xd
*m
+xe
)/d
*sx
;xe
=(xd
*m
+xe
)%d
;
322 y
+=(yd
*m
+ye
)/d
*sy
;ye
=(yd
*m
+ye
)%d
;
327 void WP_punch(int x
,int y
,int d
,int own
) {
330 o
.x
=x
;o
.y
=y
;o
.r
=12;o
.h
=26;
331 o
.xv
=o
.yv
=o
.vx
=o
.vy
=0;
332 if(Z_hit(&o
,d
,own
,HIT_SOME
)) Z_sound(snd
[9],128);
335 int WP_chainsaw(int x
,int y
,int d
,int own
) {
338 o
.x
=x
;o
.y
=y
;o
.r
=12;o
.h
=26;
339 o
.xv
=o
.yv
=o
.vx
=o
.vy
=0;
340 if(Z_hit(&o
,d
,own
,HIT_SOME
)) return 1;
344 static void throw(int i
,int x
,int y
,int xd
,int yd
,int r
,int h
,int s
) {
347 wp
[i
].o
.x
=x
;wp
[i
].o
.y
=y
+h
/2;
349 if(!(m
=max(abs(xd
),abs(yd
)))) m
=1;
350 wp
[i
].o
.xv
=xd
*s
/m
;wp
[i
].o
.yv
=yd
*s
/m
;
351 wp
[i
].o
.r
=r
;wp
[i
].o
.h
=h
;
352 wp
[i
].o
.vx
=wp
[i
].o
.vy
=0;
355 void WP_rocket(int x
,int y
,int xd
,int yd
,int o
) {
358 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
360 wp
[i
].t
=ROCKET
;wp
[i
].s
=(xd
>=x
)?1:0;
362 throw(i
,x
,y
,xd
,yd
,2,5,12);
367 void WP_revf(int x
,int y
,int xd
,int yd
,int o
,int t
) {
370 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
372 wp
[i
].t
=REVF
;wp
[i
].s
=(xd
>=x
)?1:0;
373 wp
[i
].own
=o
;wp
[i
].target
=t
;
374 throw(i
,x
,y
,xd
,yd
,2,5,12);
379 void WP_plasma(int x
,int y
,int xd
,int yd
,int o
) {
382 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
384 wp
[i
].t
=PLASMA
;wp
[i
].s
=0;
386 throw(i
,x
,y
,xd
,yd
,2,5,16);
391 void WP_ball1(int x
,int y
,int xd
,int yd
,int o
) {
394 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
395 wp
[i
].t
=BALL1
;wp
[i
].s
=0;
397 throw(i
,x
,y
,xd
,yd
,2,5,16);
402 void WP_ball2(int x
,int y
,int xd
,int yd
,int o
) {
405 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
406 wp
[i
].t
=BALL2
;wp
[i
].s
=0;
408 throw(i
,x
,y
,xd
,yd
,2,5,16);
413 void WP_ball7(int x
,int y
,int xd
,int yd
,int o
) {
416 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
417 wp
[i
].t
=BALL7
;wp
[i
].s
=0;
419 throw(i
,x
,y
,xd
,yd
,2,5,16);
424 void WP_aplasma(int x
,int y
,int xd
,int yd
,int o
) {
427 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
429 wp
[i
].t
=APLASMA
;wp
[i
].s
=0;
431 throw(i
,x
,y
,xd
,yd
,2,5,16);
436 void WP_manfire(int x
,int y
,int xd
,int yd
,int o
) {
439 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
441 wp
[i
].t
=MANF
;wp
[i
].s
=0;
443 throw(i
,x
,y
,xd
,yd
,5,11,16);
448 void WP_bfgshot(int x
,int y
,int xd
,int yd
,int o
) {
451 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
452 wp
[i
].t
=BFGBALL
;wp
[i
].s
=0;
454 throw(i
,x
,y
,xd
,yd
,5,12,16);
459 void WP_bfghit(int x
,int y
,int o
) {
462 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
463 wp
[i
].t
=BFGHIT
;wp
[i
].s
=0;
464 wp
[i
].o
.x
=x
;wp
[i
].o
.y
=y
;
465 wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;
466 wp
[i
].o
.r
=0;wp
[i
].o
.h
=1;
467 wp
[i
].o
.vx
=wp
[i
].o
.vy
=0;
473 void WP_pistol(int x
,int y
,int xd
,int yd
,int o
) {
475 WP_gun(x
,y
,xd
,yd
,o
,1);
477 WP_gun(x
,y
+1,xd
,yd
+1,o
,1);
478 WP_gun(x
,y
-1,xd
,yd
-1,o
,1);
482 void WP_mgun(int x
,int y
,int xd
,int yd
,int o
) {
483 Z_sound(snd
[11],128);
484 WP_gun(x
,y
,xd
,yd
,o
,1);
487 void WP_shotgun(int x
,int y
,int xd
,int yd
,int o
) {
493 WP_gun(x
,y
+j
,xd
,yd
+j
,o
,i
&1);
497 void WP_dshotgun(int x
,int y
,int xd
,int yd
,int o
) {
501 for(i
=(g_dm
)?25:20;i
>=0;--i
) {
503 WP_gun(x
,y
+j
,xd
,yd
+j
,o
,(i%3
)?0:1);
507 void WP_ognemet(int x
,int y
,int xd
,int yd
,int xv
,int yv
,int o
) {
510 m
=abs(xd
-x
);if(!m
) m
=abs(yd
-y
);
511 SMK_flame(x
,y
,xv
,yv
,2,2,(xd
-x
)*3000/m
,(yd
-y
)*3000/m
,1,o
);