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
32 extern int hit_xv
,hit_yv
;
34 void bfg_fly(int x
,int y
,int own
);
36 enum{NONE
=0,ROCKET
,PLASMA
,APLASMA
,BALL1
,BALL2
,BALL7
,BFGBALL
,BFGHIT
,
48 static void *snd
[14],*spr
[49*2];
49 static char sprd
[49*2];
50 static weapon_t wp
[MAXWPN
];
52 static void throw(int,int,int,int,int,int,int,int);
54 void WP_savegame(FILE* h
) {
57 for(n
=MAXWPN
;--n
;) if(wp
[n
].t
) break;
58 ++n
;myfwrite(&n
,1,4,h
);myfwrite(wp
,1,n
*sizeof(wp
[0]),h
);
61 void WP_loadgame(FILE* h
) {
64 myfread(&n
,1,4,h
);myfread(wp
,1,n
*sizeof(wp
[0]),h
);
69 static char nm
[14][6]={
87 spr
[i
*2]=Z_getspr("MISL",i
,1,sprd
+i
*2);
88 spr
[i
*2+1]=Z_getspr("MISL",i
,2,sprd
+i
*2+1);
91 spr
[i
*2]=Z_getspr("PLSS",i
-4,1,sprd
+i
*2);
92 spr
[i
*2+1]=Z_getspr("PLSS",i
-4,2,sprd
+i
*2+1);
95 spr
[i
*2]=Z_getspr("PLSE",i
-6,1,sprd
+i
*2);
96 spr
[i
*2+1]=Z_getspr("PLSE",i
-6,2,sprd
+i
*2+1);
99 spr
[i
*2]=Z_getspr("APLS",i
-11,1,sprd
+i
*2);
100 spr
[i
*2+1]=Z_getspr("APLS",i
-11,2,sprd
+i
*2+1);
103 spr
[i
*2]=Z_getspr("APBX",i
-13,1,sprd
+i
*2);
104 spr
[i
*2+1]=Z_getspr("APBX",i
-13,2,sprd
+i
*2+1);
107 spr
[i
*2]=Z_getspr("BFS1",i
-18,1,sprd
+i
*2);
108 spr
[i
*2+1]=Z_getspr("BFS1",i
-18,2,sprd
+i
*2+1);
111 spr
[i
*2]=Z_getspr("BFE1",i
-20,1,sprd
+i
*2);
112 spr
[i
*2+1]=Z_getspr("BFE1",i
-20,2,sprd
+i
*2+1);
115 spr
[i
*2]=Z_getspr("BFE2",i
-26,1,sprd
+i
*2);
116 spr
[i
*2+1]=Z_getspr("BFE2",i
-26,2,sprd
+i
*2+1);
119 spr
[i
*2]=Z_getspr("MISL",i
-30+4,1,sprd
+i
*2);
120 spr
[i
*2+1]=Z_getspr("MISL",i
-30+4,2,sprd
+i
*2+1);
123 spr
[i
*2]=Z_getspr("BAL1",i
-32,1,sprd
+i
*2);
124 spr
[i
*2+1]=Z_getspr("BAL1",i
-32,2,sprd
+i
*2+1);
127 spr
[i
*2]=Z_getspr("BAL7",i
-37,1,sprd
+i
*2);
128 spr
[i
*2+1]=Z_getspr("BAL7",i
-37,2,sprd
+i
*2+1);
131 spr
[i
*2]=Z_getspr("BAL2",i
-42,1,sprd
+i
*2);
132 spr
[i
*2+1]=Z_getspr("BAL2",i
-42,2,sprd
+i
*2+1);
135 spr
[i
*2]=Z_getspr("MANF",i
-47,1,sprd
+i
*2);
136 spr
[i
*2+1]=Z_getspr("MANF",i
-47,2,sprd
+i
*2+1);
138 for(i
=0;i
<14;++i
) snd
[i
]=Z_getsnd(nm
[i
]);
144 for(i
=0;i
<MAXWPN
;++i
) wp
[i
].t
=NONE
;
151 for(i
=0;i
<MAXWPN
;++i
) if(wp
[i
].t
) {
152 if(wp
[i
].t
==ROCKET
|| wp
[i
].t
==REVF
)
153 SMK_gas(wp
[i
].o
.x
+Z_sign(wp
[i
].o
.xv
)*2,
154 wp
[i
].o
.y
-wp
[i
].o
.h
/2,3,3,
155 wp
[i
].o
.xv
+wp
[i
].o
.vx
,wp
[i
].o
.yv
+wp
[i
].o
.vy
,64
157 --wp
[i
].o
.yv
;st
=Z_moveobj(&wp
[i
].o
);
158 if(st
&Z_FALLOUT
) {wp
[i
].t
=0;continue;}
159 if(st
&Z_HITWATER
) switch(wp
[i
].t
) {
160 case PLASMA
: case APLASMA
:
164 Z_splash(&wp
[i
].o
,wp
[i
].o
.r
+wp
[i
].o
.h
);break;
168 if(Z_getobjpos(wp
[i
].target
,&o
))
169 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);
171 if(wp
[i
].s
>=2) {if(++wp
[i
].s
>=8) wp
[i
].t
=0; break;}
172 if(st
&Z_HITAIR
) Z_set_speed(&wp
[i
].o
,12);
173 if(st
&(Z_HITWALL
|Z_HITCEIL
|Z_HITLAND
)) {
174 wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[4],128);
175 Z_explode(wp
[i
].o
.x
,wp
[i
].o
.y
,30,wp
[i
].own
);break;}
176 else if(Z_hit(&wp
[i
].o
,10,wp
[i
].own
,HIT_SOME
)) {
177 wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[4],128);
178 Z_explode(wp
[i
].o
.x
,wp
[i
].o
.y
-wp
[i
].o
.h
/2,30,wp
[i
].own
);break;}
179 bfg_fly(wp
[i
].o
.x
,wp
[i
].o
.y
-wp
[i
].o
.h
/2,wp
[i
].own
);
184 Z_sound(snd
[12],128);
185 Z_water_trap(&wp
[i
].o
);
186 Z_chktrap(1,10,wp
[i
].own
,HIT_ELECTRO
);
195 {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;}
196 if(st
&Z_HITAIR
) Z_set_speed(&wp
[i
].o
,16);
197 if(st
&(Z_HITWALL
|Z_HITCEIL
|Z_HITLAND
))
198 {wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[7],128);break;}
199 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
))
200 {wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[7],128);break;}
204 Z_sound(snd
[8],40);Z_sound(snd
[13],128);
205 Z_water_trap(&wp
[i
].o
);
206 Z_chktrap(1,1000,wp
[i
].own
,HIT_ELECTRO
);
210 if(wp
[i
].s
>=2) {if(++wp
[i
].s
>=14) wp
[i
].t
=0; break;}
211 else if(st
&(Z_HITWALL
|Z_HITCEIL
|Z_HITLAND
)) {
212 Z_bfg9000(wp
[i
].o
.x
,wp
[i
].o
.y
,wp
[i
].own
);
213 wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[8],128);break;}
214 else if(Z_hit(&wp
[i
].o
,100,wp
[i
].own
,HIT_BFG
)) {
215 Z_bfg9000(wp
[i
].o
.x
,wp
[i
].o
.y
,wp
[i
].own
);
216 wp
[i
].s
=2;wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;Z_sound(snd
[8],128);break;}
217 bfg_fly(wp
[i
].o
.x
,wp
[i
].o
.y
-wp
[i
].o
.h
/2,wp
[i
].own
);
220 if(++wp
[i
].s
>=8) wp
[i
].t
=0;
230 for(i
=0;i
<MAXWPN
;++i
) {
233 case NONE
: default: break;
237 d
=(wp
[i
].o
.xv
>0)?1:0;
238 x
=abs(wp
[i
].o
.xv
);y
=wp
[i
].o
.yv
;s
=0;
239 if(y
<0) {if(-y
>=x
) s
=30;}
240 else if(y
>0) if(y
>=x
/2) s
=31;
241 }else {s
=(d
-2)/2+1;d
=0;}
244 if((s
=wp
[i
].s
)>=2) {s
/=2;break;}
250 if((s
=wp
[i
].s
)>=2) s
=s
/2+1;
252 case PLASMA
: s
+=4;break;
253 case APLASMA
: s
+=11;break;
254 case BALL1
: s
+=32;break;
255 case BALL2
: s
+=42;break;
256 case BALL7
: s
+=37;d
=(wp
[i
].o
.xv
>=0)?1:0;break;
257 case MANF
: s
+=47;d
=(wp
[i
].o
.xv
>=0)?1:0;break;
260 if((s
=wp
[i
].s
)>=2) s
=s
/2+1;
263 s
=wp
[i
].s
/2+26;break;
265 if(s
>=0) Z_drawspr(wp
[i
].o
.x
,wp
[i
].o
.y
,spr
[s
*2+d
],sprd
[s
*2+d
]);
269 void WP_gun(int x
,int y
,int xd
,int yd
,int o
,int v
) {
275 f
=BM_MONSTER
|BM_WALL
;
276 if(o
!=-1) f
|=BM_PLR1
;
277 if(o
!=-2) f
|=BM_PLR2
;
284 if(!xd
&& !yd
) return;
285 if((xd
=abs(xd
)) > (yd
=abs(yd
))) d
=xd
; else d
=yd
;
291 if(x
<0 || x
>=FLDW
*8 || y
<0 || y
>=FLDH
*8) break;
292 if(((m
=bmap
[y
>>5][x
>>5])&f
)) {
293 if(m
&BM_WALL
) if(fld
[y
>>3][x
>>3]==1 || fld
[y
>>3][x
>>3]==2) {
294 for(x
=lx
,y
=ly
,xe
=ye
=0;fld
[y
>>3][x
>>3]!=1 && fld
[y
>>3][x
>>3]!=2;) {
296 if((xe
+=xd
)>=d
) {xe
-=d
;x
+=sx
;}
297 if((ye
+=yd
)>=d
) {ye
-=d
;y
+=sy
;}
299 DOT_spark(lx
,ly
,sx
*10,sy
*10,1);
302 if(m
&(BM_MONSTER
|BM_PLR1
|BM_PLR2
)) if(Z_gunhit(x
,y
,o
,sx
*v
,sy
*v
)) break;
304 if((xe
+=(xd
<<3))>=d
) {
307 if((ye
+=(yd
<<3))>=d
) {
312 else{m
=x
&31;if(sx
>0) m
^=31; ++m
;}
314 else{s
=y
&31;if(sy
>0) s
^=31; ++s
;}
315 if((s
<m
&& s
!=0) || m
==0) m
=s
;
317 x
+=(xd
*m
+xe
)/d
*sx
;xe
=(xd
*m
+xe
)%d
;
318 y
+=(yd
*m
+ye
)/d
*sy
;ye
=(yd
*m
+ye
)%d
;
323 void WP_punch(int x
,int y
,int d
,int own
) {
326 o
.x
=x
;o
.y
=y
;o
.r
=12;o
.h
=26;
327 o
.xv
=o
.yv
=o
.vx
=o
.vy
=0;
328 if(Z_hit(&o
,d
,own
,HIT_SOME
)) Z_sound(snd
[9],128);
331 int WP_chainsaw(int x
,int y
,int d
,int own
) {
334 o
.x
=x
;o
.y
=y
;o
.r
=12;o
.h
=26;
335 o
.xv
=o
.yv
=o
.vx
=o
.vy
=0;
336 if(Z_hit(&o
,d
,own
,HIT_SOME
)) return 1;
340 static void throw(int i
,int x
,int y
,int xd
,int yd
,int r
,int h
,int s
) {
343 wp
[i
].o
.x
=x
;wp
[i
].o
.y
=y
+h
/2;
345 if(!(m
=max(abs(xd
),abs(yd
)))) m
=1;
346 wp
[i
].o
.xv
=xd
*s
/m
;wp
[i
].o
.yv
=yd
*s
/m
;
347 wp
[i
].o
.r
=r
;wp
[i
].o
.h
=h
;
348 wp
[i
].o
.vx
=wp
[i
].o
.vy
=0;
351 void WP_rocket(int x
,int y
,int xd
,int yd
,int o
) {
354 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
356 wp
[i
].t
=ROCKET
;wp
[i
].s
=(xd
>=x
)?1:0;
358 throw(i
,x
,y
,xd
,yd
,2,5,12);
363 void WP_revf(int x
,int y
,int xd
,int yd
,int o
,int t
) {
366 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
368 wp
[i
].t
=REVF
;wp
[i
].s
=(xd
>=x
)?1:0;
369 wp
[i
].own
=o
;wp
[i
].target
=t
;
370 throw(i
,x
,y
,xd
,yd
,2,5,12);
375 void WP_plasma(int x
,int y
,int xd
,int yd
,int o
) {
378 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
380 wp
[i
].t
=PLASMA
;wp
[i
].s
=0;
382 throw(i
,x
,y
,xd
,yd
,2,5,16);
387 void WP_ball1(int x
,int y
,int xd
,int yd
,int o
) {
390 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
391 wp
[i
].t
=BALL1
;wp
[i
].s
=0;
393 throw(i
,x
,y
,xd
,yd
,2,5,16);
398 void WP_ball2(int x
,int y
,int xd
,int yd
,int o
) {
401 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
402 wp
[i
].t
=BALL2
;wp
[i
].s
=0;
404 throw(i
,x
,y
,xd
,yd
,2,5,16);
409 void WP_ball7(int x
,int y
,int xd
,int yd
,int o
) {
412 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
413 wp
[i
].t
=BALL7
;wp
[i
].s
=0;
415 throw(i
,x
,y
,xd
,yd
,2,5,16);
420 void WP_aplasma(int x
,int y
,int xd
,int yd
,int o
) {
423 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
425 wp
[i
].t
=APLASMA
;wp
[i
].s
=0;
427 throw(i
,x
,y
,xd
,yd
,2,5,16);
432 void WP_manfire(int x
,int y
,int xd
,int yd
,int o
) {
435 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
437 wp
[i
].t
=MANF
;wp
[i
].s
=0;
439 throw(i
,x
,y
,xd
,yd
,5,11,16);
444 void WP_bfgshot(int x
,int y
,int xd
,int yd
,int o
) {
447 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
448 wp
[i
].t
=BFGBALL
;wp
[i
].s
=0;
450 throw(i
,x
,y
,xd
,yd
,5,12,16);
455 void WP_bfghit(int x
,int y
,int o
) {
458 for(i
=0;i
<MAXWPN
;++i
) if(!wp
[i
].t
) {
459 wp
[i
].t
=BFGHIT
;wp
[i
].s
=0;
460 wp
[i
].o
.x
=x
;wp
[i
].o
.y
=y
;
461 wp
[i
].o
.xv
=wp
[i
].o
.yv
=0;
462 wp
[i
].o
.r
=0;wp
[i
].o
.h
=1;
463 wp
[i
].o
.vx
=wp
[i
].o
.vy
=0;
469 void WP_pistol(int x
,int y
,int xd
,int yd
,int o
) {
471 WP_gun(x
,y
,xd
,yd
,o
,1);
473 WP_gun(x
,y
+1,xd
,yd
+1,o
,1);
474 WP_gun(x
,y
-1,xd
,yd
-1,o
,1);
478 void WP_mgun(int x
,int y
,int xd
,int yd
,int o
) {
479 Z_sound(snd
[11],128);
480 WP_gun(x
,y
,xd
,yd
,o
,1);
483 void WP_shotgun(int x
,int y
,int xd
,int yd
,int o
) {
489 WP_gun(x
,y
+j
,xd
,yd
+j
,o
,i
&1);
493 void WP_dshotgun(int x
,int y
,int xd
,int yd
,int o
) {
497 for(i
=(g_dm
)?25:20;i
>=0;--i
) {
499 WP_gun(x
,y
+j
,xd
,yd
+j
,o
,(i%3
)?0:1);
503 void WP_ognemet(int x
,int y
,int xd
,int yd
,int xv
,int yv
,int o
) {
506 m
=abs(xd
-x
);if(!m
) m
=abs(yd
-y
);
507 SMK_flame(x
,y
,xv
,yv
,2,2,(xd
-x
)*3000/m
,(yd
-y
)*3000/m
,1,o
);