DEADSOFTWARE

fix some warnings
[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"
38 #include "my.h"
40 extern int hit_xv,hit_yv;
42 #define PL_RAD 8
43 #define PL_HT 26
45 #define PL_SWUP 4
46 #define PL_FLYUP 4
48 #define PL_AIR 360
49 #define PL_AQUA_AIR 1091
51 byte p_immortal=0,p_fly=0;
53 int PL_JUMP=10,PL_RUN=8;
55 int wp_it[11]={0,I_CSAW,0,I_SGUN,I_SGUN2,I_MGUN,I_LAUN,I_PLAS,I_BFG,I_GUN2,0};
57 enum{STAND,GO,DIE,SLOP,DEAD,MESS,OUT,FALL};
59 typedef void fire_f(int,int,int,int,int);
61 player_t pl1,pl2;
62 static int aitime;
63 static void *aisnd[3];
64 static void *pdsnd[5];
66 static void *spr[27*2],*snd[11];
67 static char sprd[27*2];
68 static void *wpn[11][6];
69 static byte goanim[]="BDACDA",
70 dieanim[]="HHHHIIIIJJJJKKKKLLLLMMMM",
71 slopanim[]="OOPPQQRRSSTTUUVVWW";
74 #pragma pack(1)
75 struct {
76 int ku,kd,kl,kr,kf,kj,kwl,kwr,kp;
77 } _keys;
78 #pragma pack()
80 void PL_save_player (player_t *p, FILE *h) {
81 myfwrite32(p->o.x, h);
82 myfwrite32(p->o.y, h);
83 myfwrite32(p->o.xv, h);
84 myfwrite32(p->o.yv, h);
85 myfwrite32(p->o.vx, h);
86 myfwrite32(p->o.vy, h);
87 myfwrite32(p->o.r, h);
88 myfwrite32(p->o.h, h);
89 myfwrite32(p->looky, h);
90 myfwrite32(p->st, h);
91 myfwrite32(p->s, h);
92 myfwrite32(p->life, h);
93 myfwrite32(p->armor, h);
94 myfwrite32(p->hit, h);
95 myfwrite32(p->hito, h);
96 myfwrite32(p->pain, h);
97 myfwrite32(p->air, h);
98 myfwrite32(p->invl, h);
99 myfwrite32(p->suit, h);
100 myfwrite8(p->d, h);
101 myfwrite32(p->frag, h);
102 myfwrite32(p->ammo, h);
103 myfwrite32(p->shel, h);
104 myfwrite32(p->rock, h);
105 myfwrite32(p->cell, h);
106 myfwrite32(p->fuel, h);
107 myfwrite32(p->kills, h);
108 myfwrite32(p->secrets, h);
109 myfwrite8(p->fire, h);
110 myfwrite8(p->cwpn, h);
111 myfwrite8(p->csnd, h);
112 myfwrite8(p->amul, h);
113 myfwrite16(p->wpns, h);
114 myfwrite8(p->wpn, h);
115 myfwrite8(p->f, h);
116 myfwrite8(p->drawst, h);
117 myfwrite8(p->color, h);
118 myfwrite32(p->id, h);
119 myfwrite8(p->keys, h);
120 myfwrite8(p->lives, h);
121 // k* not saved
124 void PL_savegame (FILE *h) {
125 PL_save_player(&pl1, h);
126 if (_2pl) {
127 PL_save_player(&pl2, h);
129 myfwrite32(PL_JUMP, h);
130 myfwrite32(PL_RUN, h);
131 myfwrite8(p_immortal, h);
134 void PL_load_player (player_t *p, FILE *h) {
135 p->o.x = myfread32(h);
136 p->o.y = myfread32(h);
137 p->o.xv = myfread32(h);
138 p->o.yv = myfread32(h);
139 p->o.vx = myfread32(h);
140 p->o.vy = myfread32(h);
141 p->o.r = myfread32(h);
142 p->o.h = myfread32(h);
143 p->looky = myfread32(h);
144 p->st = myfread32(h);
145 p->s = myfread32(h);
146 p->life = myfread32(h);
147 p->armor = myfread32(h);
148 p->hit = myfread32(h);
149 p->hito = myfread32(h);
150 p->pain = myfread32(h);
151 p->air = myfread32(h);
152 p->invl = myfread32(h);
153 p->suit = myfread32(h);
154 p->d = myfread8(h);
155 p->frag = myfread32(h);
156 p->ammo = myfread32(h);
157 p->shel = myfread32(h);
158 p->rock = myfread32(h);
159 p->cell = myfread32(h);
160 p->fuel = myfread32(h);
161 p->kills = myfread32(h);
162 p->secrets = myfread32(h);
163 p->fire = myfread8(h);
164 p->cwpn = myfread8(h);
165 p->csnd = myfread8(h);
166 p->amul = myfread8(h);
167 p->wpns = myfread16(h);
168 p->wpn = myfread8(h);
169 p->f = myfread8(h);
170 p->drawst = myfread8(h);
171 p->color = myfread8(h);
172 p->id = myfread32(h);
173 p->keys = myfread8(h);
174 p->lives = myfread8(h);
175 // k* not saved
178 void PL_loadgame (FILE *h) {
179 PL_load_player(&pl1, h);
180 if (_2pl) {
181 PL_load_player(&pl2, h);
183 PL_JUMP = myfread32(h);
184 PL_RUN = myfread32(h);
185 p_immortal = myfread8(h);
188 static int nonz(int a) {return (a)?a:1;}
190 static int firediry(player_t *p) {
191 if(p->f&PLF_UP) return -42;
192 if(p->f&PLF_DOWN) return 19;
193 return 0;
196 static void fire(player_t *p) {
197 static fire_f *ff[11]={
198 WP_pistol,WP_pistol,WP_pistol,WP_shotgun,WP_dshotgun,
199 WP_mgun,WP_rocket,WP_plasma,WP_bfgshot,WP_shotgun,WP_pistol};
200 static int ft[11]={5,2,6,18,36,2,12,2,0,2,1};
202 if(p->cwpn) return;
203 if(p->wpn==8) {
204 if(!p->fire)
205 if(keys[p->kf] && p->cell>=40)
206 {Z_sound(snd[5],128);p->fire=21;p->cell-=40;p->drawst|=PL_DRAWWPN;return;}
207 else return;
208 if(p->fire==1) p->cwpn=12;
209 else return;
210 }else if(p->wpn==1) {
211 if(!p->csnd) {
212 if(!keys[p->kf]) {Z_sound(snd[7],128);p->csnd=13;return;}
214 if(keys[p->kf] && !p->fire) {
215 p->fire=2;
216 WP_chainsaw(p->o.x+((p->d)?4:-4),p->o.y,(g_dm)?9:3,p->id);
217 if(!p->csnd) {Z_sound(snd[8],128);p->csnd=29;}
218 }return;
219 }else if(p->fire) return;
220 if(keys[p->kf] || p->wpn==8) {
221 switch(p->wpn) {
222 case 2: case 5:
223 if(!p->ammo) return;
224 --p->ammo;p->drawst|=PL_DRAWWPN;break;
225 case 3: case 9:
226 if(!p->shel) return;
227 --p->shel;p->drawst|=PL_DRAWWPN;break;
228 case 4:
229 if(p->shel<2) return;
230 p->shel-=2;p->drawst|=PL_DRAWWPN;break;
231 case 6:
232 if(!p->rock) return;
233 --p->rock;p->drawst|=PL_DRAWWPN;break;
234 case 7:
235 if(!p->cell) return;
236 --p->cell;p->drawst|=PL_DRAWWPN;break;
237 case 10:
238 if(!p->fuel) return;
239 --p->fuel;p->drawst|=PL_DRAWWPN;break;
241 if(p->wpn==10)
242 WP_ognemet(p->o.x,p->o.y-15,p->o.x+((p->d)?30:-30),p->o.y-15+firediry(p),
243 p->o.xv+p->o.vx,p->o.yv+p->o.vy,p->id);
244 else if(p->wpn>=1) ff[p->wpn] (p->o.x,p->o.y-15,p->o.x+((p->d)?30:-30),
245 p->o.y-15+firediry(p),p->id);
246 else WP_punch(p->o.x+((p->d)?4:-4),p->o.y,3,p->id);
247 p->fire=ft[p->wpn];
248 if(p->wpn>=2) p->f|=PLF_FIRE;
252 static void chgwpn(player_t *p) {
253 if(p->cwpn) return;
254 if(p->fire && p->wpn!=1) return;
255 if(keys[p->kwl]) {
256 do{ if(--p->wpn<0) p->wpn=10; }while(!(p->wpns&(1<<p->wpn)));
257 p->cwpn=3;
258 }else if(keys[p->kwr]) {
259 do{ if(++p->wpn>10) p->wpn=0; }while(!(p->wpns&(1<<p->wpn)));
260 p->cwpn=3;
262 if(p->cwpn) {
263 p->drawst|=PL_DRAWWPN;p->fire=0;
264 if(p->wpn==1) Z_sound(snd[6],128);
268 static void jump(player_t *p,int st) {
269 if(Z_canbreathe(p->o.x,p->o.y,p->o.r,p->o.h)) {
270 if(p->air<PL_AIR) {p->air=PL_AIR;p->drawst|=PL_DRAWAIR;}
271 }else {
272 if(--p->air < -9) {
273 p->air=0;
274 PL_hit(p,10,-3,HIT_WATER);
275 }else if((p->air&31)==0) {
276 FX_bubble(p->o.x,p->o.y-20,0,0,5);
278 p->drawst|=PL_DRAWAIR;
280 if(keys[p->kj]) {
281 if(p_fly) {
282 p->o.yv=-PL_FLYUP;
283 }else{
284 if(Z_canstand(p->o.x,p->o.y,p->o.r)) p->o.yv=-PL_JUMP;
285 else if(st&Z_INWATER) p->o.yv=-PL_SWUP;
290 int PL_isdead(player_t *p) {
291 switch(p->st) {
292 case DEAD: case MESS:
293 case OUT:
294 return 1;
296 return 0;
299 void PL_init(void) {
300 p_immortal=0;
301 PL_JUMP=10;PL_RUN=8;
302 aitime=0;
305 void PL_alloc(void) {
306 int i,j;
307 static char nm[][6]={
308 "OOF",
309 "PLPAIN",
310 "PLDETH",
311 "SLOP",
312 "PDIEHI",
313 "BFG",
314 "SAWUP",
315 "SAWIDL",
316 "SAWFUL",
317 "SAWHIT",
318 "PLFALL"
319 };
320 static char s[6];
322 for(i=0;i<27;++i) {
323 spr[i*2]=Z_getspr("PLAY",i,1,sprd+i*2);
324 spr[i*2+1]=Z_getspr("PLAY",i,2,sprd+i*2+1);
326 memcpy(s,"PWPx",4);
327 for(i=1;i<11;++i) {
328 s[3]=((i<10)?'0':('A'-10))+i;
329 for(j=0;j<6;++j) wpn[i][j]=Z_getspr(s,j,1,NULL);
331 for(i=0;i<11;++i) snd[i]=Z_getsnd(nm[i]);
332 memcpy(s,"AIx",4);
333 for(i=0;i<3;++i) {
334 s[2]=i+'1';
335 aisnd[i]=Z_getsnd(s);
337 memcpy(s,"PLDTHx",6);
338 for(i=0;i<5;++i) {
339 s[5]=i+'1';
340 pdsnd[i]=Z_getsnd(s);
344 void PL_restore(player_t *p) {
345 p->o.xv=p->o.yv=p->o.vx=p->o.vy=0;
346 p->o.r=PL_RAD;p->o.h=PL_HT;
347 p->pain=0;
348 p->invl=p->suit=0;
349 switch(p->st) {
350 case DEAD: case MESS: case OUT:
351 case DIE: case SLOP: case FALL:
352 p->life=100;p->armor=0;p->air=PL_AIR;
353 p->wpns=5;
354 p->wpn=2;
355 p->ammo=50;p->fuel=p->shel=p->rock=p->cell=0;
356 p->amul=1;
358 p->st=STAND;
359 p->fire=p->cwpn=p->csnd=0;
360 p->f=0;
361 p->drawst=0xFF;
362 p->looky=0;
363 p->keys=(g_dm)?0x70:0;
366 void PL_reset(void) {
367 pl1.st=pl2.st=DEAD;
368 pl1.frag=pl2.frag=0;
371 void PL_spawn(player_t *p,int x,int y,char d) {
372 PL_restore(p);
373 p->o.x=x;p->o.y=y;p->d=d;
374 p->kills=p->secrets=0;
377 int PL_hit(player_t *p,int d,int o,int t) {
378 if(!d) return 0;
379 switch(p->st) {
380 case DIE: case SLOP:
381 case DEAD: case MESS:
382 case OUT: case FALL:
383 return 0;
385 if(t==HIT_TRAP) {if(!p_immortal) {p->armor=0;p->life=-100;}}
386 else if(t!=HIT_ROCKET && t!=HIT_ELECTRO) {
387 if(p->id==-1) {if(o==-1) return 0;}
388 else if(o==-2) return 0;
390 if(t!=HIT_WATER && t!=HIT_ELECTRO)
391 DOT_blood(p->o.x,p->o.y-15,hit_xv,hit_yv,d*2);
392 else if(t==HIT_WATER) FX_bubble(p->o.x,p->o.y-20,0,0,d/2);
393 if(p_immortal || p->invl) return 1;
394 p->hit+=d;
395 p->hito=o;
396 return 1;
399 void PL_damage(player_t *p) {
400 int i;
402 if(!p->hit && p->life>0) return;
403 switch(p->st) {
404 case DIE: case SLOP:
405 case DEAD: case MESS:
406 case OUT: case FALL:
407 return;
409 i=p->hit*p->life/nonz(p->armor*3/4+p->life);
410 p->pain+=p->hit;
411 p->drawst|=PL_DRAWLIFE|PL_DRAWARMOR;
412 if((p->armor-=p->hit-i)<0) {p->life+=p->armor;p->armor=0;}
413 if((p->life-=i)<=0) {
414 if(p->life>-30) {p->st=DIE;p->s=0;Z_sound(pdsnd[rand()%5],128);}
415 else {p->st=SLOP;p->s=0;Z_sound(snd[3],128);}
416 if(p->amul>1) IT_spawn(p->o.x,p->o.y,I_BPACK);
417 if(!g_dm) {
418 if(p->keys&16) IT_spawn(p->o.x,p->o.y,I_KEYR);
419 if(p->keys&32) IT_spawn(p->o.x,p->o.y,I_KEYG);
420 if(p->keys&64) IT_spawn(p->o.x,p->o.y,I_KEYB);
422 for(i=1,p->wpns>>=1;i<11;++i,p->wpns>>=1)
423 if(i!=2) if(p->wpns&1) IT_spawn(p->o.x,p->o.y,wp_it[i]);
424 p->wpns=5;p->wpn=2;
425 p->f|=PLF_PNSND;
426 p->drawst|=PL_DRAWWPN;
427 if(g_dm && _2pl) {
428 if(p->id==-1) {
429 if(p->hito==-2) {++pl2.kills;++pl2.frag;}
430 else if(p->hito==-1) --pl1.frag;
431 }else{
432 if(p->hito==-1) {++pl1.kills;++pl1.frag;}
433 else if(p->hito==-2) --pl2.frag;
435 pl1.drawst|=PL_DRAWFRAG;
436 if(_2pl) pl2.drawst|=PL_DRAWFRAG;
438 p->life=0;return;
440 return;
443 void PL_cry(player_t *p) {
444 Z_sound(snd[(p->pain>20)?1:0],128);
445 p->f|=PLF_PNSND;
448 int PL_give(player_t *p,int t) {
449 int i;
451 switch(p->st) {
452 case DIE: case SLOP:
453 case DEAD: case MESS: case OUT:
454 return 0;
456 switch(t) {
457 case I_STIM: case I_MEDI:
458 if(p->life>=100) return 0;
459 if((p->life+=((t==I_MEDI)?25:10))>100) p->life=100;
460 p->drawst|=PL_DRAWLIFE;return 1;
461 case I_CLIP:
462 if(p->ammo>=200*p->amul) return 0;
463 if((p->ammo+=10)>200*p->amul) p->ammo=200*p->amul;
464 p->drawst|=PL_DRAWWPN;return 1;
465 case I_AMMO:
466 if(p->ammo>=200*p->amul) return 0;
467 if((p->ammo+=50)>200*p->amul) p->ammo=200*p->amul;
468 p->drawst|=PL_DRAWWPN;return 1;
469 case I_SHEL:
470 if(p->shel>=50*p->amul) return 0;
471 if((p->shel+=4)>50*p->amul) p->shel=50*p->amul;
472 p->drawst|=PL_DRAWWPN;return 1;
473 case I_SBOX:
474 if(p->shel>=50*p->amul) return 0;
475 if((p->shel+=25)>50*p->amul) p->shel=50*p->amul;
476 p->drawst|=PL_DRAWWPN;return 1;
477 case I_ROCKET:
478 if(p->rock>=50*p->amul) return 0;
479 if((++p->rock)>50*p->amul) p->rock=50*p->amul;
480 p->drawst|=PL_DRAWWPN;return 1;
481 case I_RBOX:
482 if(p->rock>=50*p->amul) return 0;
483 if((p->rock+=5)>50*p->amul) p->rock=50*p->amul;
484 p->drawst|=PL_DRAWWPN;return 1;
485 case I_CELL:
486 if(p->cell>=300*p->amul) return 0;
487 if((p->cell+=40)>300*p->amul) p->cell=300*p->amul;
488 p->drawst|=PL_DRAWWPN;return 1;
489 case I_CELP:
490 if(p->cell>=300*p->amul) return 0;
491 if((p->cell+=100)>300*p->amul) p->cell=300*p->amul;
492 p->drawst|=PL_DRAWWPN;return 1;
493 case I_BPACK:
494 if(p->amul==1) {p->amul=2;i=1;} else i=0;
495 i|=PL_give(p,I_CLIP);
496 i|=PL_give(p,I_SHEL);
497 i|=PL_give(p,I_ROCKET);
498 i|=PL_give(p,I_CELL);
499 return i;
500 case I_CSAW:
501 if(!(p->wpns&2)) {p->wpns|=2;p->drawst|=PL_DRAWWPN;return 1;}
502 return 0;
503 case I_GUN2:
504 i=PL_give(p,I_SHEL);
505 if(!(p->wpns&512)) {p->wpns|=512;i=1;}
506 p->drawst|=PL_DRAWWPN;return i;
507 case I_SGUN:
508 i=PL_give(p,I_SHEL);
509 if(!(p->wpns&8)) {p->wpns|=8;i=1;}
510 p->drawst|=PL_DRAWWPN;return i;
511 case I_SGUN2:
512 i=PL_give(p,I_SHEL);
513 if(!(p->wpns&16)) {p->wpns|=16;i=1;}
514 p->drawst|=PL_DRAWWPN;return i;
515 case I_MGUN:
516 i=PL_give(p,I_AMMO);
517 if(!(p->wpns&32)) {p->wpns|=32;i=1;}
518 p->drawst|=PL_DRAWWPN;return i;
519 case I_LAUN:
520 i=PL_give(p,I_ROCKET);
521 i|=PL_give(p,I_ROCKET);
522 if(!(p->wpns&64)) {p->wpns|=64;i=1;}
523 p->drawst|=PL_DRAWWPN;return i;
524 case I_PLAS:
525 i=PL_give(p,I_CELL);
526 if(!(p->wpns&128)) {p->wpns|=128;i=1;}
527 p->drawst|=PL_DRAWWPN;return i;
528 case I_BFG:
529 i=PL_give(p,I_CELL);
530 if(!(p->wpns&256)) {p->wpns|=256;i=1;}
531 p->drawst|=PL_DRAWWPN;return i;
532 case I_ARM1:
533 if(p->armor>=100) return 0;
534 p->armor=100;p->drawst|=PL_DRAWARMOR;return 1;
535 case I_ARM2:
536 if(p->armor>=200) return 0;
537 p->armor=200;p->drawst|=PL_DRAWARMOR;return 1;
538 case I_MEGA:
539 i=0;
540 if(p->life<200) {p->life=200;p->drawst|=PL_DRAWLIFE;i=1;}
541 if(p->armor<200) {p->armor=200;p->drawst|=PL_DRAWARMOR;i=1;}
542 return i;
543 case I_SUPER:
544 if(p->life<200) {p->life=min(p->life+100,200);p->drawst|=PL_DRAWLIFE;return 1;}
545 return 0;
546 case I_INVL:
547 p->invl=PL_POWERUP_TIME;
548 return 1;
549 case I_SUIT:
550 p->suit=PL_POWERUP_TIME;
551 return 1;
552 case I_AQUA:
553 if(p->air >= PL_AQUA_AIR) return 0;
554 p->air=PL_AQUA_AIR;p->drawst|=PL_DRAWAIR;
555 return 1;
556 case I_KEYR:
557 if(p->keys&16) return 0;
558 p->keys|=16;p->drawst|=PL_DRAWKEYS;return 1;
559 case I_KEYG:
560 if(p->keys&32) return 0;
561 p->keys|=32;p->drawst|=PL_DRAWKEYS;return 1;
562 case I_KEYB:
563 if(p->keys&64) return 0;
564 p->keys|=64;p->drawst|=PL_DRAWKEYS;return 1;
565 default:
566 return 0;
570 void PL_act(player_t *p) {
571 int st;
573 if(--aitime<0) aitime=0;
574 SW_press(p->o.x,p->o.y,p->o.r,p->o.h,4|p->keys,p->id);
575 if(!p->suit) if((g_time&15)==0)
576 PL_hit(p,Z_getacid(p->o.x,p->o.y,p->o.r,p->o.h),-3,HIT_SOME);
577 if(p->st!=FALL && p->st!=OUT) {
578 if(((st=Z_moveobj(&p->o))&Z_FALLOUT) && p->o.y>=FLDH*CELH+50) {
579 switch(p->st) {
580 case DEAD: case MESS: case DIE: case SLOP:
581 p->s=5;break;
582 default:
583 p->s=Z_sound(snd[10],128);
584 if(g_dm) --p->frag;
585 }p->st=FALL;
587 }else st=0;
588 if(st&Z_HITWATER) Z_splash(&p->o,PL_RAD+PL_HT);
589 if(p->f&PLF_FIRE) if(p->fire!=2) p->f-=PLF_FIRE;
590 if(keys[p->ku]) {p->f|=PLF_UP;p->looky-=5;}
591 else{
592 p->f&=0xFFFF-PLF_UP;
593 if(keys[p->kd])
594 {p->f|=PLF_DOWN;p->looky+=5;}
595 else {p->f&=0xFFFF-PLF_DOWN;p->looky=Z_dec(p->looky,5);}
597 if(keys[p->kp]) SW_press(p->o.x,p->o.y,p->o.r,p->o.h,1|p->keys,p->id);
598 if(p->fire) --p->fire;
599 if(p->cwpn) --p->cwpn;
600 if(p->csnd) --p->csnd;
601 if(p->invl) --p->invl;
602 if(p->suit) --p->suit;
603 switch(p->st) {
604 case DIE:
605 p->o.h=7;
606 if(!dieanim[++p->s]) {p->st=DEAD;MN_killedp();}
607 p->o.xv=Z_dec(p->o.xv,1);
608 break;
609 case SLOP:
610 p->o.h=6;
611 if(!slopanim[++p->s]) {p->st=MESS;MN_killedp();}
612 p->o.xv=Z_dec(p->o.xv,1);
613 break;
614 case GO:
615 chgwpn(p);fire(p);jump(p,st);
616 if(p_fly)
617 SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128);
618 if((p->s+=abs(p->o.xv)/2) >= 24) p->s%=24;
619 if(!keys[p->kl] && !keys[p->kr]) {
620 if(p->o.xv) p->o.xv=Z_dec(p->o.xv,1);
621 else p->st=STAND;
622 break;
624 if(p->o.xv<PL_RUN && keys[p->kr]) {p->o.xv+=PL_RUN>>3;p->d=1;}
625 else if(PL_RUN>8)
626 SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32);
627 if(p->o.xv>-PL_RUN && keys[p->kl]) {p->o.xv-=PL_RUN>>3;p->d=0;}
628 else if(PL_RUN>8)
629 SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32);
630 break;
631 case STAND:
632 chgwpn(p);fire(p);jump(p,st);
633 if(p_fly)
634 SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128);
635 if(keys[p->kl]) {p->st=GO;p->s=0;p->d=0;}
636 else if(keys[p->kr]) {p->st=GO;p->s=0;p->d=1;}
637 break;
638 case DEAD:
639 case MESS:
640 case OUT:
641 p->o.xv=Z_dec(p->o.xv,1);
642 if(keys[p->ku] || keys[p->kd] || keys[p->kl] || keys[p->kr] ||
643 keys[p->kf] || keys[p->kj] || keys[p->kp] || keys[p->kwl] || keys[p->kwr]) {
644 if(p->st!=OUT) MN_spawn_deadpl(&p->o,p->color,(p->st==MESS)?1:0);
645 PL_restore(p);
646 if(g_dm) {G_respawn_player(p);break;}
647 if(!_2pl) {
648 if(--p->lives==0) {G_start();break;}
649 else{p->o.x=dm_pos[0].x;p->o.y=dm_pos[0].y;p->d=dm_pos[0].d;}
650 p->drawst|=PL_DRAWLIVES;
652 if(p->id==-1)
653 {p->o.x=dm_pos[0].x;p->o.y=dm_pos[0].y;p->d=dm_pos[0].d;}
654 else {p->o.x=dm_pos[1].x;p->o.y=dm_pos[1].y;p->d=dm_pos[1].d;}
655 }break;
656 case FALL:
657 if(--p->s<=0) p->st=OUT;
658 break;
662 static int standspr(player_t *p) {
663 if(p->f&PLF_UP) return 'X';
664 if(p->f&PLF_DOWN) return 'Z';
665 return 'E';
668 static int wpnspr(player_t *p) {
669 if(p->f&PLF_UP) return 'C';
670 if(p->f&PLF_DOWN) return 'E';
671 return 'A';
674 void PL_draw(player_t *p) {
675 int s,w,wx,wy;
676 static int wytab[]={-1,-2,-1,0};
678 s='A';w=0;wx=wy=0;
679 switch(p->st) {
680 case STAND:
681 if(p->f&PLF_FIRE) {s=standspr(p)+1;w=wpnspr(p)+1;}
682 else if(p->pain) {s='G';w='A';wx=p->d?2:-2;wy=1;}
683 else {s=standspr(p);w=wpnspr(p);}
684 break;
685 case DEAD:
686 s='N';break;
687 case MESS:
688 s='W';break;
689 case GO:
690 if(p->pain) {s='G';w='A';wx=p->d?2:-2;wy=1;}
691 else {
692 s=goanim[p->s/8];w=(p->f&PLF_FIRE)?'B':'A';
693 wx=p->d?2:-2;wy=1+wytab[s-'A'];
695 break;
696 case DIE:
697 s=dieanim[p->s];break;
698 case SLOP:
699 s=slopanim[p->s];break;
700 case OUT:
701 s=0;break;
703 if(p->wpn==0) w=0;
704 if(w) Z_drawspr(p->o.x+wx,p->o.y+wy,wpn[p->wpn][w-'A'],p->d);
705 if(s) Z_drawmanspr(p->o.x,p->o.y,spr[(s-'A')*2+p->d],sprd[(s-'A')*2+p->d],p->color);
708 void *PL_getspr(int s,int d) {
709 return spr[(s-'A')*2+d];
712 static void chk_bfg(player_t *p,int x,int y) {
713 int dx,dy;
715 if(aitime) return;
716 switch(p->st) {
717 case DIE: case SLOP: case FALL:
718 case DEAD: case MESS: case OUT:
719 return;
721 dx=p->o.x-x;dy=p->o.y-p->o.h/2-y;
722 if(dx*dx+dy*dy<=1600) {
723 aitime=Z_sound(aisnd[rand()%3],128)*4;
727 void bfg_fly(int x,int y,int o) {
728 // if(!g_dm) return;
729 if(o!=-1) chk_bfg(&pl1,x,y);
730 if(_2pl) if(o!=-2) chk_bfg(&pl2,x,y);
731 if(o==-1 || o==-2) MN_warning(x-50,y-50,x+50,y+50);
734 void PL_drawst(player_t *p) {
735 V_setrect(WD,120,w_o,HT);Z_clrst();
736 int i;
738 if(p->drawst&PL_DRAWAIR)
739 if (p->air<PL_AIR)//
740 Z_drawstair(p->air);
741 if(p->drawst&PL_DRAWLIFE)
742 Z_drawstprcnt(0,p->life);
743 if(p->drawst&PL_DRAWARMOR)
744 Z_drawstprcnt(1,p->armor);
745 if(p->drawst&PL_DRAWWPN) {
746 switch(p->wpn) {
747 case 2: case 5:
748 i=p->ammo;break;
749 case 3: case 4: case 9:
750 i=p->shel;break;
751 case 6:
752 i=p->rock;break;
753 case 10:
754 i=p->fuel;break;
755 case 7: case 8:
756 i=p->cell;break;
758 Z_drawstwpn(p->wpn,i);
760 if(p->drawst&PL_DRAWFRAG) Z_drawstnum(p->frag);
761 if(p->drawst&PL_DRAWKEYS) Z_drawstkeys(p->keys);
762 if(!_2pl) if(p->drawst&PL_DRAWLIVES) Z_drawstlives(p->lives);