DEADSOFTWARE

menu: remove data field from menu_t
[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 "game.h"
28 #include "fx.h"
29 #include "misc.h"
30 #include "my.h"
31 #include "monster.h"
33 #define MAXSR 20
35 smoke_t sm[MAXSMOK];
37 static int sr_r,sxr[MAXSR],syr[MAXSR];
38 static int lsm;
40 static void *burnsnd;
41 static int burntm=0;
43 void SMK_init (void) {
44 int i;
46 for(i=0;i<MAXSMOK;++i) {sm[i].t=0;}
47 lsm=0;
48 burntm=0;
49 }
51 void SMK_alloc (void) {
52 int i;
53 burnsnd=Z_getsnd("BURN");
54 for(i=0;i<MAXSR;++i) {
55 sxr[i]=myrand(256*2+1)-256;
56 syr[i]=myrand(256*2+1)-256;
57 }
58 sr_r=0;
59 }
61 static void inclast(void) {
62 if(++lsm>=MAXSMOK) lsm=0;
63 }
65 void SMK_act (void) {
66 int i,ox,oy;
67 static obj_t o;
69 if(burntm) --burntm;
70 for(i=0;i<MAXSMOK;++i) if(sm[i].t) {
71 if(sm[i].s) {
72 ox=sm[i].x;oy=sm[i].y;
73 sm[i].xv=Z_dec(sm[i].xv,20);
74 sm[i].yv=Z_dec(sm[i].yv,20);
75 sm[i].x+=sm[i].xv/2;sm[i].y+=sm[i].yv/2;
76 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
77 sm[i].x=ox;sm[i].y=oy;
78 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
79 sm[i].x=ox;sm[i].y=oy;
80 }
81 ox=sm[i].x;oy=sm[i].y;
82 sm[i].x+=sm[i].xv/2;sm[i].y+=sm[i].yv/2;
83 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
84 sm[i].x=ox;sm[i].y=oy;
85 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
86 sm[i].x=ox;sm[i].y=oy;
87 }
88 if(sm[i].o!=-3) {
89 o.x=sm[i].x>>8;o.y=sm[i].y>>8;
90 o.xv=sm[i].xv>>10;o.yv=sm[i].yv>>10;
91 o.vx=o.vy=0;
92 if(!(g_time&3)) Z_hit(&o,1,sm[i].o,HIT_FLAME);
93 }
94 }else{
95 ox=sm[i].x;oy=sm[i].y;
96 sm[i].xv=Z_dec(sm[i].xv,20);
97 sm[i].yv=Z_dec(sm[i].yv,20);
98 sm[i].x+=sm[i].xv;sm[i].y+=sm[i].yv;
99 if(!Z_canfit(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
100 sm[i].x=ox;sm[i].y=oy;
101 }else if(Z_inwater(sm[i].x>>8,(sm[i].y>>8)+3,3,7)) {
102 sm[i].x=ox;sm[i].y=oy;
105 --sm[i].t;
109 static void SMK_add (int x, int y, int xv, int yv, byte t, byte s, short o) {
110 int i;
112 if(!Z_canfit(x>>8,(y>>8)+3,3,7)) return;
113 if(Z_inwater(x>>8,(y>>8)+3,3,7)) {FX_bubble(x>>8,y>>8,xv,yv,1);return;}
114 i=lsm;
115 sm[i].x=x;sm[i].y=y;
116 sm[i].xv=xv;sm[i].yv=yv;
117 sm[i].t=t;sm[i].s=s;
118 sm[i].o=o;
119 inclast();
122 void SMK_gas (int x0, int y0, int xr, int yr, int xv, int yv, int k) {
123 int i,x,y;
124 static int sxv,syv;
126 xv=-xv;yv=-yv;
127 sxv=xv*k;syv=yv*k;
128 k=max(abs(xv),abs(yv));
129 if(!k) return;
130 for(i=0;i<=k;i+=3) {
131 x=((xv*i/k+x0)<<8)+sxr[sr_r]*xr;
132 y=((yv*i/k+y0)<<8)+syr[sr_r]*yr;
133 if(++sr_r>=MAXSR) sr_r=0;
134 SMK_add(x,y,sxv,syv,SMSN*3,0,-3);
138 void SMK_flame (int x0, int y0, int ox, int oy, int xr, int yr, int xv, int yv, int k, int o) {
139 int i,x,y;
140 static int sxv,syv;
142 sxv=xv*k;syv=yv*k;
143 xv=xv-(ox<<8);yv=yv-(oy<<8);
144 k=max(abs(xv),abs(yv));
145 if(!k) return;
146 if(!burntm) burntm=Z_sound(burnsnd,128);
147 for(i=0;i<=k;i+=200) {
148 x=xv*i/k+(x0<<8)+sxr[sr_r]*xr;
149 y=yv*i/k+(y0<<8)+syr[sr_r]*yr;
150 if(++sr_r>=MAXSR) sr_r=0;
151 SMK_add(x,y,sxv,syv,FLSN,1,o);