DEADSOFTWARE

fully move highter level rendering code in separate file
[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 "vga.h"
26 #include "view.h"
27 #include "smoke.h"
28 #include "fx.h"
29 #include "misc.h"
30 #include "my.h"
32 #define MAXSR 20
34 smoke_t sm[MAXSMOK];
36 static int sr_r,sxr[MAXSR],syr[MAXSR];
37 static int lsm;
39 static void *burnsnd;
40 static int burntm=0;
42 byte flametab[16]={
43 0xBC,0xBA,0xB8,0xB6,0xB4,0xB2,0xB0,0xD5,0xD6,0xD7,0xA1,0xA0,0xE3,0xE2,0xE1,0xE0
44 };
46 void SMK_savegame (FILE *h) {
47 int i, n;
48 for (i = n = 0; i < MAXSMOK; ++i) {
49 if (sm[i].t) {
50 ++n;
51 }
52 }
53 myfwrite32(n, h);
54 for (i = 0; i < MAXSMOK; ++i) {
55 if (sm[i].t) {
56 myfwrite32(sm[i].x, h);
57 myfwrite32(sm[i].y, h);
58 myfwrite32(sm[i].xv, h);
59 myfwrite32(sm[i].xv, h);
60 myfwrite8(sm[i].t, h);
61 myfwrite8(sm[i].s, h);
62 myfwrite16(sm[i].o, h);
63 }
64 }
65 }
67 void SMK_loadgame (FILE *h) {
68 int i, n;
69 n = myfread32(h);
70 for (i = 0; i < n; ++i) {
71 sm[i].x = myfread32(h);
72 sm[i].y = myfread32(h);
73 sm[i].xv = myfread32(h);
74 sm[i].xv = myfread32(h);
75 sm[i].t = myfread8(h);
76 sm[i].s = myfread8(h);
77 sm[i].o = myfread16(h);
78 }
79 }
81 void SMK_init(void) {
82 int i;
84 for(i=0;i<MAXSMOK;++i) {sm[i].t=0;}
85 lsm=0;
86 burntm=0;
87 }
89 void SMK_alloc(void) {
90 int i;
91 burnsnd=Z_getsnd("BURN");
92 for(i=0;i<MAXSR;++i) {
93 sxr[i]=myrand(256*2+1)-256;
94 syr[i]=myrand(256*2+1)-256;
95 }
96 sr_r=0;
97 }
99 static void inclast(void) {
100 if(++lsm>=MAXSMOK) lsm=0;
103 void SMK_act(void) {
104 int i,ox,oy;
105 static obj_t o;
107 if(burntm) --burntm;
108 for(i=0;i<MAXSMOK;++i) if(sm[i].t) {
109 if(sm[i].s) {
110 ox=sm[i].x;oy=sm[i].y;
111 sm[i].xv=Z_dec(sm[i].xv,20);
112 sm[i].yv=Z_dec(sm[i].yv,20);
113 sm[i].x+=sm[i].xv/2;sm[i].y+=sm[i].yv/2;
114 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
115 sm[i].x=ox;sm[i].y=oy;
116 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
117 sm[i].x=ox;sm[i].y=oy;
119 ox=sm[i].x;oy=sm[i].y;
120 sm[i].x+=sm[i].xv/2;sm[i].y+=sm[i].yv/2;
121 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
122 sm[i].x=ox;sm[i].y=oy;
123 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
124 sm[i].x=ox;sm[i].y=oy;
126 if(sm[i].o!=-3) {
127 o.x=sm[i].x>>8;o.y=sm[i].y>>8;
128 o.xv=sm[i].xv>>10;o.yv=sm[i].yv>>10;
129 o.vx=o.vy=0;
130 if(!(g_time&3)) Z_hit(&o,1,sm[i].o,HIT_FLAME);
132 }else{
133 ox=sm[i].x;oy=sm[i].y;
134 sm[i].xv=Z_dec(sm[i].xv,20);
135 sm[i].yv=Z_dec(sm[i].yv,20);
136 sm[i].x+=sm[i].xv;sm[i].y+=sm[i].yv;
137 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
138 sm[i].x=ox;sm[i].y=oy;
139 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
140 sm[i].x=ox;sm[i].y=oy;
143 --sm[i].t;
147 void SMK_add(int x,int y,int xv,int yv,byte t,byte s,short o) {
148 int i;
150 if(!Z_canfit(x>>8,(y>>8)+3,3,7)) return;
151 if(Z_inwater(x>>8,(y>>8)+3,3,7)) {FX_bubble(x>>8,y>>8,xv,yv,1);return;}
152 i=lsm;
153 sm[i].x=x;sm[i].y=y;
154 sm[i].xv=xv;sm[i].yv=yv;
155 sm[i].t=t;sm[i].s=s;
156 sm[i].o=o;
157 inclast();
160 void SMK_gas(int x0,int y0,int xr,int yr,int xv,int yv,int k) {
161 int i,x,y;
162 static int sxv,syv;
164 xv=-xv;yv=-yv;
165 sxv=xv*k;syv=yv*k;
166 k=max(abs(xv),abs(yv));
167 if(!k) return;
168 for(i=0;i<=k;i+=3) {
169 x=((xv*i/k+x0)<<8)+sxr[sr_r]*xr;
170 y=((yv*i/k+y0)<<8)+syr[sr_r]*yr;
171 if(++sr_r>=MAXSR) sr_r=0;
172 SMK_add(x,y,sxv,syv,SMSN*3,0,-3);
176 void SMK_flame(int x0,int y0,int ox,int oy,int xr,int yr,int xv,int yv,int k,int o) {
177 int i,x,y;
178 static int sxv,syv;
180 sxv=xv*k;syv=yv*k;
181 xv=xv-(ox<<8);yv=yv-(oy<<8);
182 k=max(abs(xv),abs(yv));
183 if(!k) return;
184 if(!burntm) burntm=Z_sound(burnsnd,128);
185 for(i=0;i<=k;i+=200) {
186 x=xv*i/k+(x0<<8)+sxr[sr_r]*xr;
187 y=yv*i/k+(y0<<8)+syr[sr_r]*yr;
188 if(++sr_r>=MAXSR) sr_r=0;
189 SMK_add(x,y,sxv,syv,FLSN,1,o);