DEADSOFTWARE

cea21f88d93bef50d403041e64db6865819f00e1
[flatwaifu.git] / src / fx.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
5 This file is part of the Doom2D:Rembo project.
7 Doom2D:Rembo is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 Doom2D:Rembo is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/> or
18 write to the Free Software Foundation, Inc.,
19 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
22 #include "glob.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "view.h"
27 #include "fx.h"
28 #include "misc.h"
29 #include "my.h"
31 enum{NONE,TFOG,IFOG,BUBL};
33 fx_t fx[MAXFX];
35 static void *bsnd[2];
36 static char bubsn;
37 static int last;
39 //unsigned char fx_scr1[64000],fx_scr2[64000];
41 #define SINP 256
42 #define SINPM (SINP-1)
43 #define W (SINP/100)
45 static int stdsin[SINP]={
46 #include "fx1sin.dat"
47 };
48 static int sintab[SINP];
50 static unsigned char dmap[32*32];
52 static int isin(int a) {
53 return sintab[a&SINPM];
54 }
56 static void setamp(int a) {
57 int i;
59 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
60 }
62 /*
63 void FX_trans1 (int t) {
64 int x,y,u,v;
65 static unsigned char k;
66 unsigned p;
68 setamp(t);
69 k=t;
70 t*=W;
71 for(y=0,p=0;y<200;++y)
72 for(x=0;x<320;++x,++p) {
73 if(dmap[(y&31)*32+(x&31)]>=k) {
74 u=x+((isin(y+t))>>16);
75 v=y+((isin(u+t))>>16);
76 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
77 else scra[p]=fx_scr1[v*320+u];
78 }else scra[p]=fx_scr2[p];
79 }
80 }
81 */
83 static void init_fx1sin(void) {
84 int j,r,l,rr;
85 unsigned i;
87 memset(dmap,0,32*32);
88 for(i=1,rr=32*32;i<64;++i) {
89 for(l=32*32/64;l;--l,--rr) {
90 r=rand()%rr;
91 for(j=0;r;--r,++j) {
92 for(;dmap[j];++j);
93 }
94 for(;dmap[j];++j);
95 dmap[j]=i;
96 }
97 }
98 }
100 void FX_savegame (FILE *h) {
101 int i, n;
102 for (i = n = 0; i < MAXFX; ++i) {
103 if (fx[i].t) {
104 ++n;
107 myfwrite32(n, h);
108 for (i = 0; i < MAXFX; ++i) {
109 if (fx[i].t) {
110 myfwrite32(fx[i].x, h);
111 myfwrite32(fx[i].y, h);
112 myfwrite32(fx[i].xv, h);
113 myfwrite32(fx[i].yv, h);
114 myfwrite8(fx[i].t, h);
115 myfwrite8(fx[i].s, h);
120 void FX_loadgame (FILE *h) {
121 int i, n;
122 n = myfread32(h);
123 for (i = 0; i < n; i++) {
124 fx[i].x = myfread32(h);
125 fx[i].y = myfread32(h);
126 fx[i].xv = myfread32(h);
127 fx[i].yv = myfread32(h);
128 fx[i].t = myfread8(h);
129 fx[i].s = myfread8(h);
133 void FX_alloc (void) {
134 bsnd[0]=Z_getsnd("BUBL1");
135 bsnd[1]=Z_getsnd("BUBL2");
136 init_fx1sin();
139 void FX_init (void) {
140 int i;
142 for(i=0;i<MAXFX;++i) fx[i].t=0;
143 bubsn=0;
144 last=0;
147 void FX_act (void) {
148 int i;
149 byte b;
151 bubsn=0;
152 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
153 case TFOG:
154 if(++fx[i].s>=20) fx[i].t=0;
155 break;
156 case IFOG:
157 if(++fx[i].s>=10) fx[i].t=0;
158 break;
159 case BUBL:
160 fx[i].yv-=5;
161 fx[i].xv=Z_dec(fx[i].xv,20);
162 fx[i].x+=fx[i].xv;
163 fx[i].y+=fx[i].yv;
164 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
165 break;
169 static int findfree (void) {
170 int i;
172 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
173 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
174 if(++last>=MAXFX) last=0;
175 return last;
178 void FX_tfog (int x, int y) {
179 int i;
181 i=findfree();
182 fx[i].t=TFOG;fx[i].s=0;
183 fx[i].x=x;fx[i].y=y;
186 void FX_ifog (int x, int y) {
187 int i;
189 i=findfree();
190 fx[i].t=IFOG;fx[i].s=0;
191 fx[i].x=x;fx[i].y=y;
194 void FX_bubble (int x, int y, int xv, int yv, int n) {
195 int i;
197 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
198 for(;n>0;--n) {
199 i=findfree();
200 fx[i].t=BUBL;fx[i].s=rand()&3;
201 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
202 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;