1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 * Copyright (C) 2011 Rambo
3 * Copyright (C) 2020 SovietPony
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
40 #define PL_AQUA_AIR 1091
48 static int wp_it
[11]={0,I_CSAW
,0,I_SGUN
,I_SGUN2
,I_MGUN
,I_LAUN
,I_PLAS
,I_BFG
,I_GUN2
,0};
50 enum{STAND
,GO
,DIE
,SLOP
,DEAD
,MESS
,OUT
,FALL
};
52 typedef void fire_f(int,int,int,int,int);
57 static void *aisnd
[3];
58 static void *pdsnd
[5];
61 byte plr_goanim
[]="BDACDA";
62 byte plr_dieanim
[]="HHHHIIIIJJJJKKKKLLLLMMMM";
63 byte plr_slopanim
[]="OOPPQQRRSSTTUUVVWW";
65 static int nonz (int a
) {
69 static int firediry(player_t
*p
) {
70 if(p
->f
&PLF_UP
) return -42;
71 if(p
->f
&PLF_DOWN
) return 19;
75 static void fire(player_t
*p
) {
76 static fire_f
*ff
[11]={
77 WP_pistol
,WP_pistol
,WP_pistol
,WP_shotgun
,WP_dshotgun
,
78 WP_mgun
,WP_rocket
,WP_plasma
,WP_bfgshot
,WP_shotgun
,WP_pistol
};
79 static int ft
[11]={5,2,6,18,36,2,12,2,0,2,1};
84 if(I_pressed(p
->kf
) && p
->cell
>=40)
85 {Z_sound(snd
[5],128);p
->fire
=21;p
->cell
-=40;p
->drawst
|=PL_DRAWWPN
;return;}
87 if(p
->fire
==1) p
->cwpn
=12;
91 if(!I_pressed(p
->kf
)) {Z_sound(snd
[7],128);p
->csnd
=13;return;}
93 if(I_pressed(p
->kf
) && !p
->fire
) {
95 WP_chainsaw(p
->o
.x
+((p
->d
)?4:-4),p
->o
.y
,(g_dm
)?9:3,p
->id
);
96 if(!p
->csnd
) {Z_sound(snd
[8],128);p
->csnd
=29;}
98 }else if(p
->fire
) return;
99 if(I_pressed(p
->kf
) || p
->wpn
==8) {
103 --p
->ammo
;p
->drawst
|=PL_DRAWWPN
;break;
106 --p
->shel
;p
->drawst
|=PL_DRAWWPN
;break;
108 if(p
->shel
<2) return;
109 p
->shel
-=2;p
->drawst
|=PL_DRAWWPN
;break;
112 --p
->rock
;p
->drawst
|=PL_DRAWWPN
;break;
115 --p
->cell
;p
->drawst
|=PL_DRAWWPN
;break;
118 --p
->fuel
;p
->drawst
|=PL_DRAWWPN
;break;
121 WP_ognemet(p
->o
.x
,p
->o
.y
-15,p
->o
.x
+((p
->d
)?30:-30),p
->o
.y
-15+firediry(p
),
122 p
->o
.xv
+p
->o
.vx
,p
->o
.yv
+p
->o
.vy
,p
->id
);
123 else if(p
->wpn
>=1) ff
[p
->wpn
] (p
->o
.x
,p
->o
.y
-15,p
->o
.x
+((p
->d
)?30:-30),
124 p
->o
.y
-15+firediry(p
),p
->id
);
125 else WP_punch(p
->o
.x
+((p
->d
)?4:-4),p
->o
.y
,3,p
->id
);
127 if(p
->wpn
>=2) p
->f
|=PLF_FIRE
;
131 static void chgwpn(player_t
*p
) {
133 if(p
->fire
&& p
->wpn
!=1) return;
134 if(I_pressed(p
->kwl
)) {
135 do{ if(--p
->wpn
<0) p
->wpn
=10; }while(!(p
->wpns
&(1<<p
->wpn
)));
137 }else if(I_pressed(p
->kwr
)) {
138 do{ if(++p
->wpn
>10) p
->wpn
=0; }while(!(p
->wpns
&(1<<p
->wpn
)));
142 p
->drawst
|=PL_DRAWWPN
;p
->fire
=0;
143 if(p
->wpn
==1) Z_sound(snd
[6],128);
147 static void jump(player_t
*p
,int st
) {
148 if(Z_canbreathe(p
->o
.x
,p
->o
.y
,p
->o
.r
,p
->o
.h
)) {
149 if(p
->air
<PL_AIR
) {p
->air
=PL_AIR
;p
->drawst
|=PL_DRAWAIR
;}
153 PL_hit(p
,10,-3,HIT_WATER
);
154 }else if((p
->air
&31)==0) {
155 FX_bubble(p
->o
.x
,p
->o
.y
-20,0,0,5);
157 p
->drawst
|=PL_DRAWAIR
;
159 if(I_pressed(p
->kj
)) {
163 if(Z_canstand(p
->o
.x
,p
->o
.y
,p
->o
.r
)) p
->o
.yv
=-PL_JUMP
;
164 else if(st
&Z_INWATER
) p
->o
.yv
=-PL_SWUP
;
169 int PL_isdead (player_t
*p
) {
171 case DEAD
: case MESS
:
178 void PL_init (void) {
187 void PL_alloc(void) {
189 static char nm
[][6]={
203 for(i
=0;i
<11;++i
) snd
[i
]=Z_getsnd(nm
[i
]);
207 aisnd
[i
]=Z_getsnd(s
);
209 memcpy(s
,"PLDTHx",6);
212 pdsnd
[i
]=Z_getsnd(s
);
216 static void PL_restore(player_t
*p
) {
217 p
->o
.xv
=p
->o
.yv
=p
->o
.vx
=p
->o
.vy
=0;
218 p
->o
.r
=PL_RAD
;p
->o
.h
=PL_HT
;
222 case DEAD
: case MESS
: case OUT
:
223 case DIE
: case SLOP
: case FALL
:
224 p
->life
=100;p
->armor
=0;p
->air
=PL_AIR
;
227 p
->ammo
=50;p
->fuel
=p
->shel
=p
->rock
=p
->cell
=0;
231 p
->fire
=p
->cwpn
=p
->csnd
=0;
235 p
->keys
=(g_dm
)?0x70:0;
238 void PL_reset (void) {
243 void PL_spawn (player_t
*p
,int x
,int y
,char d
) {
245 p
->o
.x
=x
;p
->o
.y
=y
;p
->d
=d
;
246 p
->kills
=p
->secrets
=0;
249 int PL_hit (player_t
*p
,int d
,int o
,int t
) {
253 case DEAD
: case MESS
:
257 if(t
==HIT_TRAP
) {if(!p_immortal
) {p
->armor
=0;p
->life
=-100;}}
258 else if(t
!=HIT_ROCKET
&& t
!=HIT_ELECTRO
) {
259 if(p
->id
==-1) {if(o
==-1) return 0;}
260 else if(o
==-2) return 0;
262 if(t
!=HIT_WATER
&& t
!=HIT_ELECTRO
)
263 DOT_blood(p
->o
.x
,p
->o
.y
-15,hit_xv
,hit_yv
,d
*2);
264 else if(t
==HIT_WATER
) FX_bubble(p
->o
.x
,p
->o
.y
-20,0,0,d
/2);
265 if(p_immortal
|| p
->invl
) return 1;
271 void PL_damage (player_t
*p
) {
274 if(!p
->hit
&& p
->life
>0) return;
277 case DEAD
: case MESS
:
281 i
=p
->hit
*p
->life
/nonz(p
->armor
*3/4+p
->life
);
283 p
->drawst
|=PL_DRAWLIFE
|PL_DRAWARMOR
;
284 if((p
->armor
-=p
->hit
-i
)<0) {p
->life
+=p
->armor
;p
->armor
=0;}
285 if((p
->life
-=i
)<=0) {
286 if(p
->life
>-30) {p
->st
=DIE
;p
->s
=0;Z_sound(pdsnd
[rand()%5
],128);}
287 else {p
->st
=SLOP
;p
->s
=0;Z_sound(snd
[3],128);}
288 if(p
->amul
>1) IT_spawn(p
->o
.x
,p
->o
.y
,I_BPACK
);
290 if(p
->keys
&16) IT_spawn(p
->o
.x
,p
->o
.y
,I_KEYR
);
291 if(p
->keys
&32) IT_spawn(p
->o
.x
,p
->o
.y
,I_KEYG
);
292 if(p
->keys
&64) IT_spawn(p
->o
.x
,p
->o
.y
,I_KEYB
);
294 for(i
=1,p
->wpns
>>=1;i
<11;++i
,p
->wpns
>>=1)
295 if(i
!=2) if(p
->wpns
&1) IT_spawn(p
->o
.x
,p
->o
.y
,wp_it
[i
]);
298 p
->drawst
|=PL_DRAWWPN
;
301 if(p
->hito
==-2) {++pl2
.kills
;++pl2
.frag
;}
302 else if(p
->hito
==-1) --pl1
.frag
;
304 if(p
->hito
==-1) {++pl1
.kills
;++pl1
.frag
;}
305 else if(p
->hito
==-2) --pl2
.frag
;
307 pl1
.drawst
|=PL_DRAWFRAG
;
308 if(_2pl
) pl2
.drawst
|=PL_DRAWFRAG
;
315 void PL_cry (player_t
*p
) {
316 Z_sound(snd
[(p
->pain
>20)?1:0],128);
320 int PL_give (player_t
*p
, int t
) {
325 case DEAD
: case MESS
: case OUT
:
329 case I_STIM
: case I_MEDI
:
330 if(p
->life
>=100) return 0;
331 if((p
->life
+=((t
==I_MEDI
)?25:10))>100) p
->life
=100;
332 p
->drawst
|=PL_DRAWLIFE
;return 1;
334 if(p
->ammo
>=200*p
->amul
) return 0;
335 if((p
->ammo
+=10)>200*p
->amul
) p
->ammo
=200*p
->amul
;
336 p
->drawst
|=PL_DRAWWPN
;return 1;
338 if(p
->ammo
>=200*p
->amul
) return 0;
339 if((p
->ammo
+=50)>200*p
->amul
) p
->ammo
=200*p
->amul
;
340 p
->drawst
|=PL_DRAWWPN
;return 1;
342 if(p
->shel
>=50*p
->amul
) return 0;
343 if((p
->shel
+=4)>50*p
->amul
) p
->shel
=50*p
->amul
;
344 p
->drawst
|=PL_DRAWWPN
;return 1;
346 if(p
->shel
>=50*p
->amul
) return 0;
347 if((p
->shel
+=25)>50*p
->amul
) p
->shel
=50*p
->amul
;
348 p
->drawst
|=PL_DRAWWPN
;return 1;
350 if(p
->rock
>=50*p
->amul
) return 0;
351 if((++p
->rock
)>50*p
->amul
) p
->rock
=50*p
->amul
;
352 p
->drawst
|=PL_DRAWWPN
;return 1;
354 if(p
->rock
>=50*p
->amul
) return 0;
355 if((p
->rock
+=5)>50*p
->amul
) p
->rock
=50*p
->amul
;
356 p
->drawst
|=PL_DRAWWPN
;return 1;
358 if(p
->cell
>=300*p
->amul
) return 0;
359 if((p
->cell
+=40)>300*p
->amul
) p
->cell
=300*p
->amul
;
360 p
->drawst
|=PL_DRAWWPN
;return 1;
362 if(p
->cell
>=300*p
->amul
) return 0;
363 if((p
->cell
+=100)>300*p
->amul
) p
->cell
=300*p
->amul
;
364 p
->drawst
|=PL_DRAWWPN
;return 1;
366 if(p
->amul
==1) {p
->amul
=2;i
=1;} else i
=0;
367 i
|=PL_give(p
,I_CLIP
);
368 i
|=PL_give(p
,I_SHEL
);
369 i
|=PL_give(p
,I_ROCKET
);
370 i
|=PL_give(p
,I_CELL
);
373 if(!(p
->wpns
&2)) {p
->wpns
|=2;p
->drawst
|=PL_DRAWWPN
;return 1;}
377 if(!(p
->wpns
&512)) {p
->wpns
|=512;i
=1;}
378 p
->drawst
|=PL_DRAWWPN
;return i
;
381 if(!(p
->wpns
&8)) {p
->wpns
|=8;i
=1;}
382 p
->drawst
|=PL_DRAWWPN
;return i
;
385 if(!(p
->wpns
&16)) {p
->wpns
|=16;i
=1;}
386 p
->drawst
|=PL_DRAWWPN
;return i
;
389 if(!(p
->wpns
&32)) {p
->wpns
|=32;i
=1;}
390 p
->drawst
|=PL_DRAWWPN
;return i
;
392 i
=PL_give(p
,I_ROCKET
);
393 i
|=PL_give(p
,I_ROCKET
);
394 if(!(p
->wpns
&64)) {p
->wpns
|=64;i
=1;}
395 p
->drawst
|=PL_DRAWWPN
;return i
;
398 if(!(p
->wpns
&128)) {p
->wpns
|=128;i
=1;}
399 p
->drawst
|=PL_DRAWWPN
;return i
;
402 if(!(p
->wpns
&256)) {p
->wpns
|=256;i
=1;}
403 p
->drawst
|=PL_DRAWWPN
;return i
;
405 if(p
->armor
>=100) return 0;
406 p
->armor
=100;p
->drawst
|=PL_DRAWARMOR
;return 1;
408 if(p
->armor
>=200) return 0;
409 p
->armor
=200;p
->drawst
|=PL_DRAWARMOR
;return 1;
412 if(p
->life
<200) {p
->life
=200;p
->drawst
|=PL_DRAWLIFE
;i
=1;}
413 if(p
->armor
<200) {p
->armor
=200;p
->drawst
|=PL_DRAWARMOR
;i
=1;}
416 if(p
->life
<200) {p
->life
=min(p
->life
+100,200);p
->drawst
|=PL_DRAWLIFE
;return 1;}
419 p
->invl
=PL_POWERUP_TIME
;
422 p
->suit
=PL_POWERUP_TIME
;
425 if(p
->air
>= PL_AQUA_AIR
) return 0;
426 p
->air
=PL_AQUA_AIR
;p
->drawst
|=PL_DRAWAIR
;
429 if(p
->keys
&16) return 0;
430 p
->keys
|=16;p
->drawst
|=PL_DRAWKEYS
;return 1;
432 if(p
->keys
&32) return 0;
433 p
->keys
|=32;p
->drawst
|=PL_DRAWKEYS
;return 1;
435 if(p
->keys
&64) return 0;
436 p
->keys
|=64;p
->drawst
|=PL_DRAWKEYS
;return 1;
442 void PL_act (player_t
*p
) {
445 if(--aitime
<0) aitime
=0;
446 SW_press(p
->o
.x
,p
->o
.y
,p
->o
.r
,p
->o
.h
,4|p
->keys
,p
->id
);
447 if(!p
->suit
) if((g_time
&15)==0)
448 PL_hit(p
,Z_getacid(p
->o
.x
,p
->o
.y
,p
->o
.r
,p
->o
.h
),-3,HIT_SOME
);
449 if(p
->st
!=FALL
&& p
->st
!=OUT
) {
450 if(((st
=Z_moveobj(&p
->o
))&Z_FALLOUT
) && p
->o
.y
>=FLDH
*CELH
+50) {
452 case DEAD
: case MESS
: case DIE
: case SLOP
:
455 p
->s
=Z_sound(snd
[10],128);
460 if(st
&Z_HITWATER
) Z_splash(&p
->o
,PL_RAD
+PL_HT
);
461 if(p
->f
&PLF_FIRE
) if(p
->fire
!=2) p
->f
-=PLF_FIRE
;
462 if(I_pressed(p
->ku
)) {p
->f
|=PLF_UP
;p
->looky
-=5;}
466 {p
->f
|=PLF_DOWN
;p
->looky
+=5;}
467 else {p
->f
&=0xFFFF-PLF_DOWN
;p
->looky
=Z_dec(p
->looky
,5);}
469 if(I_pressed(p
->kp
)) SW_press(p
->o
.x
,p
->o
.y
,p
->o
.r
,p
->o
.h
,1|p
->keys
,p
->id
);
470 if(p
->fire
) --p
->fire
;
471 if(p
->cwpn
) --p
->cwpn
;
472 if(p
->csnd
) --p
->csnd
;
473 if(p
->invl
) --p
->invl
;
474 if(p
->suit
) --p
->suit
;
478 if(!plr_dieanim
[++p
->s
]) {p
->st
=DEAD
;MN_killedp();}
479 p
->o
.xv
=Z_dec(p
->o
.xv
,1);
483 if(!plr_slopanim
[++p
->s
]) {p
->st
=MESS
;MN_killedp();}
484 p
->o
.xv
=Z_dec(p
->o
.xv
,1);
487 chgwpn(p
);fire(p
);jump(p
,st
);
489 SMK_gas(p
->o
.x
,p
->o
.y
-2,2,3,p
->o
.xv
+p
->o
.vx
,p
->o
.yv
+p
->o
.vy
,128);
490 if((p
->s
+=abs(p
->o
.xv
)/2) >= 24) p
->s
%=24;
491 if(!I_pressed(p
->kl
) && !I_pressed(p
->kr
)) {
492 if(p
->o
.xv
) p
->o
.xv
=Z_dec(p
->o
.xv
,1);
496 if(p
->o
.xv
<PL_RUN
&& I_pressed(p
->kr
)) {p
->o
.xv
+=PL_RUN
>>3;p
->d
=1;}
498 SMK_gas(p
->o
.x
,p
->o
.y
-2,2,3,p
->o
.xv
+p
->o
.vx
,p
->o
.yv
+p
->o
.vy
,32);
499 if(p
->o
.xv
>-PL_RUN
&& I_pressed(p
->kl
)) {p
->o
.xv
-=PL_RUN
>>3;p
->d
=0;}
501 SMK_gas(p
->o
.x
,p
->o
.y
-2,2,3,p
->o
.xv
+p
->o
.vx
,p
->o
.yv
+p
->o
.vy
,32);
504 chgwpn(p
);fire(p
);jump(p
,st
);
506 SMK_gas(p
->o
.x
,p
->o
.y
-2,2,3,p
->o
.xv
+p
->o
.vx
,p
->o
.yv
+p
->o
.vy
,128);
507 if(I_pressed(p
->kl
)) {p
->st
=GO
;p
->s
=0;p
->d
=0;}
508 else if(I_pressed(p
->kr
)) {p
->st
=GO
;p
->s
=0;p
->d
=1;}
513 p
->o
.xv
=Z_dec(p
->o
.xv
,1);
514 if(I_pressed(p
->ku
) || I_pressed(p
->kd
) || I_pressed(p
->kl
) || I_pressed(p
->kr
) ||
515 I_pressed(p
->kf
) || I_pressed(p
->kj
) || I_pressed(p
->kp
) || I_pressed(p
->kwl
) || I_pressed(p
->kwr
)) {
516 if(p
->st
!=OUT
) MN_spawn_deadpl(&p
->o
,p
->color
,(p
->st
==MESS
)?1:0);
518 if(g_dm
) {G_respawn_player(p
);break;}
520 if(--p
->lives
==0) {G_start();break;}
521 else{p
->o
.x
=dm_pos
[0].x
;p
->o
.y
=dm_pos
[0].y
;p
->d
=dm_pos
[0].d
;}
522 p
->drawst
|=PL_DRAWLIVES
;
525 {p
->o
.x
=dm_pos
[0].x
;p
->o
.y
=dm_pos
[0].y
;p
->d
=dm_pos
[0].d
;}
526 else {p
->o
.x
=dm_pos
[1].x
;p
->o
.y
=dm_pos
[1].y
;p
->d
=dm_pos
[1].d
;}
529 if(--p
->s
<=0) p
->st
=OUT
;
534 static void chk_bfg(player_t
*p
,int x
,int y
) {
539 case DIE
: case SLOP
: case FALL
:
540 case DEAD
: case MESS
: case OUT
:
543 dx
=p
->o
.x
-x
;dy
=p
->o
.y
-p
->o
.h
/2-y
;
544 if(dx
*dx
+dy
*dy
<=1600) {
545 aitime
=Z_sound(aisnd
[rand()%3
],128)*4;
549 void bfg_fly (int x
,int y
,int o
) {
551 if(o
!=-1) chk_bfg(&pl1
,x
,y
);
552 if(_2pl
) if(o
!=-2) chk_bfg(&pl2
,x
,y
);
553 if(o
==-1 || o
==-2) MN_warning(x
-50,y
-50,x
+50,y
+50);