DEADSOFTWARE

6ccb15a11511c6ad9297cd09d67cdd821ce3e927
[flatwaifu.git] / src / smoke.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 "view.h"
26 #include "smoke.h"
27 #include "fx.h"
28 #include "misc.h"
29 #include "my.h"
31 #define MAXSR 20
33 smoke_t sm[MAXSMOK];
35 static int sr_r,sxr[MAXSR],syr[MAXSR];
36 static int lsm;
38 static void *burnsnd;
39 static int burntm=0;
41 void SMK_savegame (FILE *h) {
42 int i, n;
43 for (i = n = 0; i < MAXSMOK; ++i) {
44 if (sm[i].t) {
45 ++n;
46 }
47 }
48 myfwrite32(n, h);
49 for (i = 0; i < MAXSMOK; ++i) {
50 if (sm[i].t) {
51 myfwrite32(sm[i].x, h);
52 myfwrite32(sm[i].y, h);
53 myfwrite32(sm[i].xv, h);
54 myfwrite32(sm[i].xv, h);
55 myfwrite8(sm[i].t, h);
56 myfwrite8(sm[i].s, h);
57 myfwrite16(sm[i].o, h);
58 }
59 }
60 }
62 void SMK_loadgame (FILE *h) {
63 int i, n;
64 n = myfread32(h);
65 for (i = 0; i < n; ++i) {
66 sm[i].x = myfread32(h);
67 sm[i].y = myfread32(h);
68 sm[i].xv = myfread32(h);
69 sm[i].xv = myfread32(h);
70 sm[i].t = myfread8(h);
71 sm[i].s = myfread8(h);
72 sm[i].o = myfread16(h);
73 }
74 }
76 void SMK_init(void) {
77 int i;
79 for(i=0;i<MAXSMOK;++i) {sm[i].t=0;}
80 lsm=0;
81 burntm=0;
82 }
84 void SMK_alloc(void) {
85 int i;
86 burnsnd=Z_getsnd("BURN");
87 for(i=0;i<MAXSR;++i) {
88 sxr[i]=myrand(256*2+1)-256;
89 syr[i]=myrand(256*2+1)-256;
90 }
91 sr_r=0;
92 }
94 static void inclast(void) {
95 if(++lsm>=MAXSMOK) lsm=0;
96 }
98 void SMK_act(void) {
99 int i,ox,oy;
100 static obj_t o;
102 if(burntm) --burntm;
103 for(i=0;i<MAXSMOK;++i) if(sm[i].t) {
104 if(sm[i].s) {
105 ox=sm[i].x;oy=sm[i].y;
106 sm[i].xv=Z_dec(sm[i].xv,20);
107 sm[i].yv=Z_dec(sm[i].yv,20);
108 sm[i].x+=sm[i].xv/2;sm[i].y+=sm[i].yv/2;
109 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
110 sm[i].x=ox;sm[i].y=oy;
111 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
112 sm[i].x=ox;sm[i].y=oy;
114 ox=sm[i].x;oy=sm[i].y;
115 sm[i].x+=sm[i].xv/2;sm[i].y+=sm[i].yv/2;
116 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
117 sm[i].x=ox;sm[i].y=oy;
118 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
119 sm[i].x=ox;sm[i].y=oy;
121 if(sm[i].o!=-3) {
122 o.x=sm[i].x>>8;o.y=sm[i].y>>8;
123 o.xv=sm[i].xv>>10;o.yv=sm[i].yv>>10;
124 o.vx=o.vy=0;
125 if(!(g_time&3)) Z_hit(&o,1,sm[i].o,HIT_FLAME);
127 }else{
128 ox=sm[i].x;oy=sm[i].y;
129 sm[i].xv=Z_dec(sm[i].xv,20);
130 sm[i].yv=Z_dec(sm[i].yv,20);
131 sm[i].x+=sm[i].xv;sm[i].y+=sm[i].yv;
132 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
133 sm[i].x=ox;sm[i].y=oy;
134 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
135 sm[i].x=ox;sm[i].y=oy;
138 --sm[i].t;
142 void SMK_add(int x,int y,int xv,int yv,byte t,byte s,short o) {
143 int i;
145 if(!Z_canfit(x>>8,(y>>8)+3,3,7)) return;
146 if(Z_inwater(x>>8,(y>>8)+3,3,7)) {FX_bubble(x>>8,y>>8,xv,yv,1);return;}
147 i=lsm;
148 sm[i].x=x;sm[i].y=y;
149 sm[i].xv=xv;sm[i].yv=yv;
150 sm[i].t=t;sm[i].s=s;
151 sm[i].o=o;
152 inclast();
155 void SMK_gas(int x0,int y0,int xr,int yr,int xv,int yv,int k) {
156 int i,x,y;
157 static int sxv,syv;
159 xv=-xv;yv=-yv;
160 sxv=xv*k;syv=yv*k;
161 k=max(abs(xv),abs(yv));
162 if(!k) return;
163 for(i=0;i<=k;i+=3) {
164 x=((xv*i/k+x0)<<8)+sxr[sr_r]*xr;
165 y=((yv*i/k+y0)<<8)+syr[sr_r]*yr;
166 if(++sr_r>=MAXSR) sr_r=0;
167 SMK_add(x,y,sxv,syv,SMSN*3,0,-3);
171 void SMK_flame(int x0,int y0,int ox,int oy,int xr,int yr,int xv,int yv,int k,int o) {
172 int i,x,y;
173 static int sxv,syv;
175 sxv=xv*k;syv=yv*k;
176 xv=xv-(ox<<8);yv=yv-(oy<<8);
177 k=max(abs(xv),abs(yv));
178 if(!k) return;
179 if(!burntm) burntm=Z_sound(burnsnd,128);
180 for(i=0;i<=k;i+=200) {
181 x=xv*i/k+(x0<<8)+sxr[sr_r]*xr;
182 y=yv*i/k+(y0<<8)+syr[sr_r]*yr;
183 if(++sr_r>=MAXSR) sr_r=0;
184 SMK_add(x,y,sxv,syv,FLSN,1,o);