DEADSOFTWARE

fd1080a4a49a52e34b738f06af873b8ded08d86e
[flatwaifu.git] / src / player.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 "keyb.h"
28 #include "view.h"
29 #include "dots.h"
30 #include "smoke.h"
31 #include "weapons.h"
32 #include "monster.h"
33 #include "fx.h"
34 #include "items.h"
35 #include "switch.h"
36 #include "player.h"
37 #include "misc.h"
39 extern int hit_xv,hit_yv;
41 #define PL_RAD 8
42 #define PL_HT 26
44 #define PL_SWUP 4
45 #define PL_FLYUP 4
47 #define PL_AIR 360
48 #define PL_AQUA_AIR 1091
50 byte p_immortal=0,p_fly=0;
52 int PL_JUMP=10,PL_RUN=8;
54 int wp_it[11]={0,I_CSAW,0,I_SGUN,I_SGUN2,I_MGUN,I_LAUN,I_PLAS,I_BFG,I_GUN2,0};
56 enum{STAND,GO,DIE,SLOP,DEAD,MESS,OUT,FALL};
58 typedef void fire_f(int,int,int,int,int);
60 player_t pl1,pl2;
61 static int aitime;
62 static void *aisnd[3];
63 static void *pdsnd[5];
65 static void *spr[27*2],*snd[11];
66 static char sprd[27*2];
67 static void *wpn[11][6];
68 static byte goanim[]="BDACDA",
69 dieanim[]="HHHHIIIIJJJJKKKKLLLLMMMM",
70 slopanim[]="OOPPQQRRSSTTUUVVWW";
73 #pragma pack(1)
74 struct {
75 int ku,kd,kl,kr,kf,kj,kwl,kwr,kp;
76 } _keys;
77 #pragma pack()
79 void PL_savegame(FILE* h) {
80 myfwrite(&pl1,1,sizeof(pl1)-sizeof(_keys),h);//myfwrite(&pl1,1,sizeof(pl1),h);
81 if(_2pl) myfwrite(&pl2,1,sizeof(pl2)-sizeof(_keys),h);//myfwrite(&pl2,1,sizeof(pl2),h);
82 myfwrite(&PL_JUMP,1,4,h);myfwrite(&PL_RUN,1,4,h);myfwrite(&p_immortal,1,1,h);
83 }
85 void PL_loadgame(FILE* h) {
86 myfread(&pl1,1,sizeof(pl1)-sizeof(_keys),h);//myfread(&pl1,1,sizeof(pl1),h);
87 if(_2pl) myfread(&pl2,1,sizeof(pl2)-sizeof(_keys),h);//myfread(&pl2,1,sizeof(pl2),h);
88 myfread(&PL_JUMP,1,4,h);myfread(&PL_RUN,1,4,h);myfread(&p_immortal,1,1,h);
89 }
91 static int nonz(int a) {return (a)?a:1;}
93 static int firediry(player_t *p) {
94 if(p->f&PLF_UP) return -42;
95 if(p->f&PLF_DOWN) return 19;
96 return 0;
97 }
99 static void fire(player_t *p) {
100 static fire_f *ff[11]={
101 WP_pistol,WP_pistol,WP_pistol,WP_shotgun,WP_dshotgun,
102 WP_mgun,WP_rocket,WP_plasma,WP_bfgshot,WP_shotgun,WP_pistol};
103 static int ft[11]={5,2,6,18,36,2,12,2,0,2,1};
105 if(p->cwpn) return;
106 if(p->wpn==8) {
107 if(!p->fire)
108 if(keys[p->kf] && p->cell>=40)
109 {Z_sound(snd[5],128);p->fire=21;p->cell-=40;p->drawst|=PL_DRAWWPN;return;}
110 else return;
111 if(p->fire==1) p->cwpn=12;
112 else return;
113 }else if(p->wpn==1) {
114 if(!p->csnd) {
115 if(!keys[p->kf]) {Z_sound(snd[7],128);p->csnd=13;return;}
117 if(keys[p->kf] && !p->fire) {
118 p->fire=2;
119 WP_chainsaw(p->o.x+((p->d)?4:-4),p->o.y,(g_dm)?9:3,p->id);
120 if(!p->csnd) {Z_sound(snd[8],128);p->csnd=29;}
121 }return;
122 }else if(p->fire) return;
123 if(keys[p->kf] || p->wpn==8) {
124 switch(p->wpn) {
125 case 2: case 5:
126 if(!p->ammo) return;
127 --p->ammo;p->drawst|=PL_DRAWWPN;break;
128 case 3: case 9:
129 if(!p->shel) return;
130 --p->shel;p->drawst|=PL_DRAWWPN;break;
131 case 4:
132 if(p->shel<2) return;
133 p->shel-=2;p->drawst|=PL_DRAWWPN;break;
134 case 6:
135 if(!p->rock) return;
136 --p->rock;p->drawst|=PL_DRAWWPN;break;
137 case 7:
138 if(!p->cell) return;
139 --p->cell;p->drawst|=PL_DRAWWPN;break;
140 case 10:
141 if(!p->fuel) return;
142 --p->fuel;p->drawst|=PL_DRAWWPN;break;
144 if(p->wpn==10)
145 WP_ognemet(p->o.x,p->o.y-15,p->o.x+((p->d)?30:-30),p->o.y-15+firediry(p),
146 p->o.xv+p->o.vx,p->o.yv+p->o.vy,p->id);
147 else if(p->wpn>=1) ff[p->wpn] (p->o.x,p->o.y-15,p->o.x+((p->d)?30:-30),
148 p->o.y-15+firediry(p),p->id);
149 else WP_punch(p->o.x+((p->d)?4:-4),p->o.y,3,p->id);
150 p->fire=ft[p->wpn];
151 if(p->wpn>=2) p->f|=PLF_FIRE;
155 static void chgwpn(player_t *p) {
156 if(p->cwpn) return;
157 if(p->fire && p->wpn!=1) return;
158 if(keys[p->kwl]) {
159 do{ if(--p->wpn<0) p->wpn=10; }while(!(p->wpns&(1<<p->wpn)));
160 p->cwpn=3;
161 }else if(keys[p->kwr]) {
162 do{ if(++p->wpn>10) p->wpn=0; }while(!(p->wpns&(1<<p->wpn)));
163 p->cwpn=3;
165 if(p->cwpn) {
166 p->drawst|=PL_DRAWWPN;p->fire=0;
167 if(p->wpn==1) Z_sound(snd[6],128);
171 static void jump(player_t *p,int st) {
172 if(Z_canbreathe(p->o.x,p->o.y,p->o.r,p->o.h)) {
173 if(p->air<PL_AIR) {p->air=PL_AIR;p->drawst|=PL_DRAWAIR;}
174 }else {
175 if(--p->air < -9) {
176 p->air=0;
177 PL_hit(p,10,-3,HIT_WATER);
178 }else if((p->air&31)==0) {
179 FX_bubble(p->o.x,p->o.y-20,0,0,5);
181 p->drawst|=PL_DRAWAIR;
183 if(keys[p->kj]) {
184 if(p_fly) {
185 p->o.yv=-PL_FLYUP;
186 }else{
187 if(Z_canstand(p->o.x,p->o.y,p->o.r)) p->o.yv=-PL_JUMP;
188 else if(st&Z_INWATER) p->o.yv=-PL_SWUP;
193 int PL_isdead(player_t *p) {
194 switch(p->st) {
195 case DEAD: case MESS:
196 case OUT:
197 return 1;
199 return 0;
202 void PL_init(void) {
203 p_immortal=0;
204 PL_JUMP=10;PL_RUN=8;
205 aitime=0;
208 void PL_alloc(void) {
209 int i,j;
210 static char nm[][6]={
211 "OOF",
212 "PLPAIN",
213 "PLDETH",
214 "SLOP",
215 "PDIEHI",
216 "BFG",
217 "SAWUP",
218 "SAWIDL",
219 "SAWFUL",
220 "SAWHIT",
221 "PLFALL"
222 };
223 static char s[6];
225 for(i=0;i<27;++i) {
226 spr[i*2]=Z_getspr("PLAY",i,1,sprd+i*2);
227 spr[i*2+1]=Z_getspr("PLAY",i,2,sprd+i*2+1);
229 memcpy(s,"PWPx",4);
230 for(i=1;i<11;++i) {
231 s[3]=((i<10)?'0':('A'-10))+i;
232 for(j=0;j<6;++j) wpn[i][j]=Z_getspr(s,j,1,NULL);
234 for(i=0;i<11;++i) snd[i]=Z_getsnd(nm[i]);
235 memcpy(s,"AIx",4);
236 for(i=0;i<3;++i) {
237 s[2]=i+'1';
238 aisnd[i]=Z_getsnd(s);
240 memcpy(s,"PLDTHx",6);
241 for(i=0;i<5;++i) {
242 s[5]=i+'1';
243 pdsnd[i]=Z_getsnd(s);
247 void PL_restore(player_t *p) {
248 p->o.xv=p->o.yv=p->o.vx=p->o.vy=0;
249 p->o.r=PL_RAD;p->o.h=PL_HT;
250 p->pain=0;
251 p->invl=p->suit=0;
252 switch(p->st) {
253 case DEAD: case MESS: case OUT:
254 case DIE: case SLOP: case FALL:
255 p->life=100;p->armor=0;p->air=PL_AIR;
256 p->wpns=5;
257 p->wpn=2;
258 p->ammo=50;p->fuel=p->shel=p->rock=p->cell=0;
259 p->amul=1;
261 p->st=STAND;
262 p->fire=p->cwpn=p->csnd=0;
263 p->f=0;
264 p->drawst=0xFF;
265 p->looky=0;
266 p->keys=(g_dm)?0x70:0;
269 void PL_reset(void) {
270 pl1.st=pl2.st=DEAD;
271 pl1.frag=pl2.frag=0;
274 void PL_spawn(player_t *p,int x,int y,char d) {
275 PL_restore(p);
276 p->o.x=x;p->o.y=y;p->d=d;
277 p->kills=p->secrets=0;
280 int PL_hit(player_t *p,int d,int o,int t) {
281 if(!d) return 0;
282 switch(p->st) {
283 case DIE: case SLOP:
284 case DEAD: case MESS:
285 case OUT: case FALL:
286 return 0;
288 if(t==HIT_TRAP) {if(!p_immortal) {p->armor=0;p->life=-100;}}
289 else if(t!=HIT_ROCKET && t!=HIT_ELECTRO) {
290 if(p->id==-1) {if(o==-1) return 0;}
291 else if(o==-2) return 0;
293 if(t!=HIT_WATER && t!=HIT_ELECTRO)
294 DOT_blood(p->o.x,p->o.y-15,hit_xv,hit_yv,d*2);
295 else if(t==HIT_WATER) FX_bubble(p->o.x,p->o.y-20,0,0,d/2);
296 if(p_immortal || p->invl) return 1;
297 p->hit+=d;
298 p->hito=o;
299 return 1;
302 void PL_damage(player_t *p) {
303 int i;
305 if(!p->hit && p->life>0) return;
306 switch(p->st) {
307 case DIE: case SLOP:
308 case DEAD: case MESS:
309 case OUT: case FALL:
310 return;
312 i=p->hit*p->life/nonz(p->armor*3/4+p->life);
313 p->pain+=p->hit;
314 p->drawst|=PL_DRAWLIFE|PL_DRAWARMOR;
315 if((p->armor-=p->hit-i)<0) {p->life+=p->armor;p->armor=0;}
316 if((p->life-=i)<=0) {
317 if(p->life>-30) {p->st=DIE;p->s=0;Z_sound(pdsnd[rand()%5],128);}
318 else {p->st=SLOP;p->s=0;Z_sound(snd[3],128);}
319 if(p->amul>1) IT_spawn(p->o.x,p->o.y,I_BPACK);
320 if(!g_dm) {
321 if(p->keys&16) IT_spawn(p->o.x,p->o.y,I_KEYR);
322 if(p->keys&32) IT_spawn(p->o.x,p->o.y,I_KEYG);
323 if(p->keys&64) IT_spawn(p->o.x,p->o.y,I_KEYB);
325 for(i=1,p->wpns>>=1;i<11;++i,p->wpns>>=1)
326 if(i!=2) if(p->wpns&1) IT_spawn(p->o.x,p->o.y,wp_it[i]);
327 p->wpns=5;p->wpn=2;
328 p->f|=PLF_PNSND;
329 p->drawst|=PL_DRAWWPN;
330 if(g_dm && _2pl) {
331 if(p->id==-1) {
332 if(p->hito==-2) {++pl2.kills;++pl2.frag;}
333 else if(p->hito==-1) --pl1.frag;
334 }else{
335 if(p->hito==-1) {++pl1.kills;++pl1.frag;}
336 else if(p->hito==-2) --pl2.frag;
338 pl1.drawst|=PL_DRAWFRAG;
339 if(_2pl) pl2.drawst|=PL_DRAWFRAG;
341 p->life=0;return;
343 return;
346 void PL_cry(player_t *p) {
347 Z_sound(snd[(p->pain>20)?1:0],128);
348 p->f|=PLF_PNSND;
351 int PL_give(player_t *p,int t) {
352 int i;
354 switch(p->st) {
355 case DIE: case SLOP:
356 case DEAD: case MESS: case OUT:
357 return 0;
359 switch(t) {
360 case I_STIM: case I_MEDI:
361 if(p->life>=100) return 0;
362 if((p->life+=((t==I_MEDI)?25:10))>100) p->life=100;
363 p->drawst|=PL_DRAWLIFE;return 1;
364 case I_CLIP:
365 if(p->ammo>=200*p->amul) return 0;
366 if((p->ammo+=10)>200*p->amul) p->ammo=200*p->amul;
367 p->drawst|=PL_DRAWWPN;return 1;
368 case I_AMMO:
369 if(p->ammo>=200*p->amul) return 0;
370 if((p->ammo+=50)>200*p->amul) p->ammo=200*p->amul;
371 p->drawst|=PL_DRAWWPN;return 1;
372 case I_SHEL:
373 if(p->shel>=50*p->amul) return 0;
374 if((p->shel+=4)>50*p->amul) p->shel=50*p->amul;
375 p->drawst|=PL_DRAWWPN;return 1;
376 case I_SBOX:
377 if(p->shel>=50*p->amul) return 0;
378 if((p->shel+=25)>50*p->amul) p->shel=50*p->amul;
379 p->drawst|=PL_DRAWWPN;return 1;
380 case I_ROCKET:
381 if(p->rock>=50*p->amul) return 0;
382 if((++p->rock)>50*p->amul) p->rock=50*p->amul;
383 p->drawst|=PL_DRAWWPN;return 1;
384 case I_RBOX:
385 if(p->rock>=50*p->amul) return 0;
386 if((p->rock+=5)>50*p->amul) p->rock=50*p->amul;
387 p->drawst|=PL_DRAWWPN;return 1;
388 case I_CELL:
389 if(p->cell>=300*p->amul) return 0;
390 if((p->cell+=40)>300*p->amul) p->cell=300*p->amul;
391 p->drawst|=PL_DRAWWPN;return 1;
392 case I_CELP:
393 if(p->cell>=300*p->amul) return 0;
394 if((p->cell+=100)>300*p->amul) p->cell=300*p->amul;
395 p->drawst|=PL_DRAWWPN;return 1;
396 case I_BPACK:
397 if(p->amul==1) {p->amul=2;i=1;} else i=0;
398 i|=PL_give(p,I_CLIP);
399 i|=PL_give(p,I_SHEL);
400 i|=PL_give(p,I_ROCKET);
401 i|=PL_give(p,I_CELL);
402 return i;
403 case I_CSAW:
404 if(!(p->wpns&2)) {p->wpns|=2;p->drawst|=PL_DRAWWPN;return 1;}
405 return 0;
406 case I_GUN2:
407 i=PL_give(p,I_SHEL);
408 if(!(p->wpns&512)) {p->wpns|=512;i=1;}
409 p->drawst|=PL_DRAWWPN;return i;
410 case I_SGUN:
411 i=PL_give(p,I_SHEL);
412 if(!(p->wpns&8)) {p->wpns|=8;i=1;}
413 p->drawst|=PL_DRAWWPN;return i;
414 case I_SGUN2:
415 i=PL_give(p,I_SHEL);
416 if(!(p->wpns&16)) {p->wpns|=16;i=1;}
417 p->drawst|=PL_DRAWWPN;return i;
418 case I_MGUN:
419 i=PL_give(p,I_AMMO);
420 if(!(p->wpns&32)) {p->wpns|=32;i=1;}
421 p->drawst|=PL_DRAWWPN;return i;
422 case I_LAUN:
423 i=PL_give(p,I_ROCKET);
424 i|=PL_give(p,I_ROCKET);
425 if(!(p->wpns&64)) {p->wpns|=64;i=1;}
426 p->drawst|=PL_DRAWWPN;return i;
427 case I_PLAS:
428 i=PL_give(p,I_CELL);
429 if(!(p->wpns&128)) {p->wpns|=128;i=1;}
430 p->drawst|=PL_DRAWWPN;return i;
431 case I_BFG:
432 i=PL_give(p,I_CELL);
433 if(!(p->wpns&256)) {p->wpns|=256;i=1;}
434 p->drawst|=PL_DRAWWPN;return i;
435 case I_ARM1:
436 if(p->armor>=100) return 0;
437 p->armor=100;p->drawst|=PL_DRAWARMOR;return 1;
438 case I_ARM2:
439 if(p->armor>=200) return 0;
440 p->armor=200;p->drawst|=PL_DRAWARMOR;return 1;
441 case I_MEGA:
442 i=0;
443 if(p->life<200) {p->life=200;p->drawst|=PL_DRAWLIFE;i=1;}
444 if(p->armor<200) {p->armor=200;p->drawst|=PL_DRAWARMOR;i=1;}
445 return i;
446 case I_SUPER:
447 if(p->life<200) {p->life=min(p->life+100,200);p->drawst|=PL_DRAWLIFE;return 1;}
448 return 0;
449 case I_INVL:
450 p->invl=PL_POWERUP_TIME;
451 return 1;
452 case I_SUIT:
453 p->suit=PL_POWERUP_TIME;
454 return 1;
455 case I_AQUA:
456 if(p->air >= PL_AQUA_AIR) return 0;
457 p->air=PL_AQUA_AIR;p->drawst|=PL_DRAWAIR;
458 return 1;
459 case I_KEYR:
460 if(p->keys&16) return 0;
461 p->keys|=16;p->drawst|=PL_DRAWKEYS;return 1;
462 case I_KEYG:
463 if(p->keys&32) return 0;
464 p->keys|=32;p->drawst|=PL_DRAWKEYS;return 1;
465 case I_KEYB:
466 if(p->keys&64) return 0;
467 p->keys|=64;p->drawst|=PL_DRAWKEYS;return 1;
468 default:
469 return 0;
473 void PL_act(player_t *p) {
474 int st;
476 if(--aitime<0) aitime=0;
477 SW_press(p->o.x,p->o.y,p->o.r,p->o.h,4|p->keys,p->id);
478 if(!p->suit) if((g_time&15)==0)
479 PL_hit(p,Z_getacid(p->o.x,p->o.y,p->o.r,p->o.h),-3,HIT_SOME);
480 if(p->st!=FALL && p->st!=OUT) {
481 if(((st=Z_moveobj(&p->o))&Z_FALLOUT) && p->o.y>=FLDH*CELH+50) {
482 switch(p->st) {
483 case DEAD: case MESS: case DIE: case SLOP:
484 p->s=5;break;
485 default:
486 p->s=Z_sound(snd[10],128);
487 if(g_dm) --p->frag;
488 }p->st=FALL;
490 }else st=0;
491 if(st&Z_HITWATER) Z_splash(&p->o,PL_RAD+PL_HT);
492 if(p->f&PLF_FIRE) if(p->fire!=2) p->f-=PLF_FIRE;
493 if(keys[p->ku]) {p->f|=PLF_UP;p->looky-=5;}
494 else{
495 p->f&=0xFFFF-PLF_UP;
496 if(keys[p->kd])
497 {p->f|=PLF_DOWN;p->looky+=5;}
498 else {p->f&=0xFFFF-PLF_DOWN;p->looky=Z_dec(p->looky,5);}
500 if(keys[p->kp]) SW_press(p->o.x,p->o.y,p->o.r,p->o.h,1|p->keys,p->id);
501 if(p->fire) --p->fire;
502 if(p->cwpn) --p->cwpn;
503 if(p->csnd) --p->csnd;
504 if(p->invl) --p->invl;
505 if(p->suit) --p->suit;
506 switch(p->st) {
507 case DIE:
508 p->o.h=7;
509 if(!dieanim[++p->s]) {p->st=DEAD;MN_killedp();}
510 p->o.xv=Z_dec(p->o.xv,1);
511 break;
512 case SLOP:
513 p->o.h=6;
514 if(!slopanim[++p->s]) {p->st=MESS;MN_killedp();}
515 p->o.xv=Z_dec(p->o.xv,1);
516 break;
517 case GO:
518 chgwpn(p);fire(p);jump(p,st);
519 if(p_fly)
520 SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128);
521 if((p->s+=abs(p->o.xv)/2) >= 24) p->s%=24;
522 if(!keys[p->kl] && !keys[p->kr]) {
523 if(p->o.xv) p->o.xv=Z_dec(p->o.xv,1);
524 else p->st=STAND;
525 break;
527 if(p->o.xv<PL_RUN && keys[p->kr]) {p->o.xv+=PL_RUN>>3;p->d=1;}
528 else if(PL_RUN>8)
529 SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32);
530 if(p->o.xv>-PL_RUN && keys[p->kl]) {p->o.xv-=PL_RUN>>3;p->d=0;}
531 else if(PL_RUN>8)
532 SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32);
533 break;
534 case STAND:
535 chgwpn(p);fire(p);jump(p,st);
536 if(p_fly)
537 SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128);
538 if(keys[p->kl]) {p->st=GO;p->s=0;p->d=0;}
539 else if(keys[p->kr]) {p->st=GO;p->s=0;p->d=1;}
540 break;
541 case DEAD:
542 case MESS:
543 case OUT:
544 p->o.xv=Z_dec(p->o.xv,1);
545 if(keys[p->ku] || keys[p->kd] || keys[p->kl] || keys[p->kr] ||
546 keys[p->kf] || keys[p->kj] || keys[p->kp] || keys[p->kwl] || keys[p->kwr]) {
547 if(p->st!=OUT) MN_spawn_deadpl(&p->o,p->color,(p->st==MESS)?1:0);
548 PL_restore(p);
549 if(g_dm) {G_respawn_player(p);break;}
550 if(!_2pl) {
551 if(--p->lives==0) {G_start();break;}
552 else{p->o.x=dm_pos[0].x;p->o.y=dm_pos[0].y;p->d=dm_pos[0].d;}
553 p->drawst|=PL_DRAWLIVES;
555 if(p->id==-1)
556 {p->o.x=dm_pos[0].x;p->o.y=dm_pos[0].y;p->d=dm_pos[0].d;}
557 else {p->o.x=dm_pos[1].x;p->o.y=dm_pos[1].y;p->d=dm_pos[1].d;}
558 }break;
559 case FALL:
560 if(--p->s<=0) p->st=OUT;
561 break;
565 static int standspr(player_t *p) {
566 if(p->f&PLF_UP) return 'X';
567 if(p->f&PLF_DOWN) return 'Z';
568 return 'E';
571 static int wpnspr(player_t *p) {
572 if(p->f&PLF_UP) return 'C';
573 if(p->f&PLF_DOWN) return 'E';
574 return 'A';
577 void PL_draw(player_t *p) {
578 int s,w,wx,wy;
579 static int wytab[]={-1,-2,-1,0};
581 s='A';w=0;wx=wy=0;
582 switch(p->st) {
583 case STAND:
584 if(p->f&PLF_FIRE) {s=standspr(p)+1;w=wpnspr(p)+1;}
585 else if(p->pain) {s='G';w='A';wx=p->d?2:-2;wy=1;}
586 else {s=standspr(p);w=wpnspr(p);}
587 break;
588 case DEAD:
589 s='N';break;
590 case MESS:
591 s='W';break;
592 case GO:
593 if(p->pain) {s='G';w='A';wx=p->d?2:-2;wy=1;}
594 else {
595 s=goanim[p->s/8];w=(p->f&PLF_FIRE)?'B':'A';
596 wx=p->d?2:-2;wy=1+wytab[s-'A'];
598 break;
599 case DIE:
600 s=dieanim[p->s];break;
601 case SLOP:
602 s=slopanim[p->s];break;
603 case OUT:
604 s=0;break;
606 if(p->wpn==0) w=0;
607 if(w) Z_drawspr(p->o.x+wx,p->o.y+wy,wpn[p->wpn][w-'A'],p->d);
608 if(s) Z_drawmanspr(p->o.x,p->o.y,spr[(s-'A')*2+p->d],sprd[(s-'A')*2+p->d],p->color);
611 void *PL_getspr(int s,int d) {
612 return spr[(s-'A')*2+d];
615 static void chk_bfg(player_t *p,int x,int y) {
616 int dx,dy;
618 if(aitime) return;
619 switch(p->st) {
620 case DIE: case SLOP: case FALL:
621 case DEAD: case MESS: case OUT:
622 return;
624 dx=p->o.x-x;dy=p->o.y-p->o.h/2-y;
625 if(dx*dx+dy*dy<=1600) {
626 aitime=Z_sound(aisnd[rand()%3],128)*4;
630 void bfg_fly(int x,int y,int o) {
631 // if(!g_dm) return;
632 if(o!=-1) chk_bfg(&pl1,x,y);
633 if(_2pl) if(o!=-2) chk_bfg(&pl2,x,y);
634 if(o==-1 || o==-2) MN_warning(x-50,y-50,x+50,y+50);
637 void PL_drawst(player_t *p) {
638 V_setrect(WD,120,w_o,HT);Z_clrst();
639 int i;
641 if(p->drawst&PL_DRAWAIR)
642 if (p->air<PL_AIR)//
643 Z_drawstair(p->air);
644 if(p->drawst&PL_DRAWLIFE)
645 Z_drawstprcnt(0,p->life);
646 if(p->drawst&PL_DRAWARMOR)
647 Z_drawstprcnt(1,p->armor);
648 if(p->drawst&PL_DRAWWPN) {
649 switch(p->wpn) {
650 case 2: case 5:
651 i=p->ammo;break;
652 case 3: case 4: case 9:
653 i=p->shel;break;
654 case 6:
655 i=p->rock;break;
656 case 10:
657 i=p->fuel;break;
658 case 7: case 8:
659 i=p->cell;break;
661 Z_drawstwpn(p->wpn,i);
663 if(p->drawst&PL_DRAWFRAG) Z_drawstnum(p->frag);
664 if(p->drawst&PL_DRAWKEYS) Z_drawstkeys(p->keys);
665 if(!_2pl) if(p->drawst&PL_DRAWLIVES) Z_drawstlives(p->lives);