24 static smoke_t sm[MAXSMOK];
25 static int sr_r,sxr[MAXSR],syr[MAXSR];
28 static void *spr[SMSN],*fspr[FLSN];
33 0xBC,0xBA,0xB8,0xB6,0xB4,0xB2,0xB0,0xD5,0xD6,0xD7,0xA1,0xA0,0xE3,0xE2,0xE1,0xE0
36 void SMK_savegame(int h) {
39 for(i=n=0;i<MAXSMOK;++i) if(sm[i].t) ++n;
41 for(i=0;i<MAXSMOK;++i) if(sm[i].t) write(h,&sm[i],sizeof(sm[0]));
44 void SMK_loadgame(int h) {
48 read(h,sm,n*sizeof(sm[0]));
54 for(i=0;i<MAXSMOK;++i) {sm[i].t=0;}
59 void SMK_alloc(void) {
62 burnsnd=Z_getsnd("BURN");
63 for(i=0;i<SMSN;++i) spr[i]=Z_getspr("SMOK",i,0,NULL);
64 for(i=0;i<FLSN;++i) fspr[i]=Z_getspr("FLAM",i,0,NULL);
65 for(i=0;i<MAXSR;++i) {
66 sxr[i]=random(256*2+1)-256;
67 syr[i]=random(256*2+1)-256;
72 static void inclast(void) {
73 if(++lsm>=MAXSMOK) lsm=0;
81 for(i=0;i<MAXSMOK;++i) if(sm[i].t) {
83 ox=sm[i].x;oy=sm[i].y;
84 sm[i].xv=Z_dec(sm[i].xv,20);
85 sm[i].yv=Z_dec(sm[i].yv,20);
86 sm[i].x+=sm[i].xv/2;sm[i].y+=sm[i].yv/2;
87 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
88 sm[i].x=ox;sm[i].y=oy;
89 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
90 sm[i].x=ox;sm[i].y=oy;
92 ox=sm[i].x;oy=sm[i].y;
93 sm[i].x+=sm[i].xv/2;sm[i].y+=sm[i].yv/2;
94 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
95 sm[i].x=ox;sm[i].y=oy;
96 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
97 sm[i].x=ox;sm[i].y=oy;
100 o.x=sm[i].x>>8;o.y=sm[i].y>>8;
101 o.xv=sm[i].xv>>10;o.yv=sm[i].yv>>10;
103 if(!(g_time&3)) Z_hit(&o,1,sm[i].o,HIT_FLAME);
106 ox=sm[i].x;oy=sm[i].y;
107 sm[i].xv=Z_dec(sm[i].xv,20);
108 sm[i].yv=Z_dec(sm[i].yv,20);
109 sm[i].x+=sm[i].xv;sm[i].y+=sm[i].yv;
110 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
111 sm[i].x=ox;sm[i].y=oy;
112 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
113 sm[i].x=ox;sm[i].y=oy;
120 void smoke_sprf(void);
121 void flame_sprf(void);
123 void SMK_draw(void) {
126 for(i=0;i<MAXSMOK;++i) if(sm[i].t) switch(sm[i].s) {
128 if((s=sm[i].t)>=(SMSN-1)*3) s=0; else s=SMSN-1-s/3;
129 V_sprf((sm[i].x>>8)-w_x+100,(sm[i].y>>8)-w_y+50+w_o,spr[s],smoke_sprf);
132 if((s=sm[i].t)>=(FLSN-1)) s=0; else s=FLSN-1-s;
133 V_sprf((sm[i].x>>8)-w_x+100,(sm[i].y>>8)-w_y+50+w_o,fspr[s],flame_sprf);
138 void SMK_add(int x,int y,int xv,int yv,byte t,byte s,short o) {
141 if(!Z_canfit(x>>8,(y>>8)+3,3,7)) return;
142 if(Z_inwater(x>>8,(y>>8)+3,3,7)) {FX_bubble(x>>8,y>>8,xv,yv,1);return;}
145 sm[i].xv=xv;sm[i].yv=yv;
151 void SMK_gas(int x0,int y0,int xr,int yr,int xv,int yv,int k) {
157 k=max(abs(xv),abs(yv));
160 x=((xv*i/k+x0)<<8)+sxr[sr_r]*xr;
161 y=((yv*i/k+y0)<<8)+syr[sr_r]*yr;
162 if(++sr_r>=MAXSR) sr_r=0;
163 SMK_add(x,y,sxv,syv,SMSN*3,0,-3);
167 void SMK_flame(int x0,int y0,int ox,int oy,int xr,int yr,int xv,int yv,int k,int o) {
172 xv=xv-(ox<<8);yv=yv-(oy<<8);
173 k=max(abs(xv),abs(yv));
175 if(!burntm) burntm=Z_sound(burnsnd,128);
176 for(i=0;i<=k;i+=200) {
177 x=xv*i/k+(x0<<8)+sxr[sr_r]*xr;
178 y=yv*i/k+(y0<<8)+syr[sr_r]*yr;
179 if(++sr_r>=MAXSR) sr_r=0;
180 SMK_add(x,y,sxv,syv,FLSN,1,o);