DEADSOFTWARE

fix some warnings
[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 "vga.h"
27 #include "view.h"
28 #include "fx.h"
29 #include "misc.h"
30 #include "my.h"
32 enum{NONE,TFOG,IFOG,BUBL};
34 #pragma pack(1)
35 typedef struct{
36 int x,y,xv,yv;
37 char t,s;
38 }fx_t;
39 #pragma pack()
41 static void *spr[15],*bsnd[2];
42 static char sprd[15];
43 static fx_t fx[MAXFX];
44 static char bubsn;
45 static int last;
47 unsigned char fx_scr1[64000],fx_scr2[64000];
49 #define SINP 256
50 #define SINPM (SINP-1)
51 #define W (SINP/100)
53 static int stdsin[SINP]={
54 #include "fx1sin.dat"
55 };
56 static int sintab[SINP];
58 static unsigned char dmap[32*32];
60 static int isin(int a) {
61 return sintab[a&SINPM];
62 }
64 static void setamp(int a) {
65 int i;
67 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
68 }
70 void FX_trans1(int t) {
72 int x,y,u,v;
73 static unsigned char k;
74 unsigned p;
76 setamp(t);
77 k=t;
78 t*=W;
79 for(y=0,p=0;y<200;++y)
80 for(x=0;x<320;++x,++p) {
81 if(dmap[(y&31)*32+(x&31)]>=k) {
82 u=x+((isin(y+t))>>16);
83 v=y+((isin(u+t))>>16);
84 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
85 else scra[p]=fx_scr1[v*320+u];
86 }else scra[p]=fx_scr2[p];
87 }
89 }
91 static void init_fx1sin(void) {
92 int j,r,l,rr;
93 unsigned i;
95 memset(dmap,0,32*32);
96 for(i=1,rr=32*32;i<64;++i) {
97 for(l=32*32/64;l;--l,--rr) {
98 r=rand()%rr;
99 for(j=0;r;--r,++j) {
100 for(;dmap[j];++j);
102 for(;dmap[j];++j);
103 dmap[j]=i;
108 void FX_savegame (FILE *h) {
109 int i, n;
110 for (i = n = 0; i < MAXFX; ++i) {
111 if (fx[i].t) {
112 ++n;
115 myfwrite32(n, h);
116 for (i = 0; i < MAXFX; ++i) {
117 if (fx[i].t) {
118 myfwrite32(fx[i].x, h);
119 myfwrite32(fx[i].y, h);
120 myfwrite32(fx[i].xv, h);
121 myfwrite32(fx[i].yv, h);
122 myfwrite8(fx[i].t, h);
123 myfwrite8(fx[i].s, h);
128 void FX_loadgame (FILE *h) {
129 int i, n;
130 n = myfread32(h);
131 for (i = 0; i < n; i++) {
132 fx[i].x = myfread32(h);
133 fx[i].y = myfread32(h);
134 fx[i].xv = myfread32(h);
135 fx[i].yv = myfread32(h);
136 fx[i].t = myfread8(h);
137 fx[i].s = myfread8(h);
141 void FX_alloc(void) {
142 int i;
144 for(i=0;i<10;++i) spr[i]=Z_getspr("TFOG",i,0,sprd+i);
145 for(;i<15;++i) spr[i]=Z_getspr("IFOG",i-10,0,sprd+i);
146 bsnd[0]=Z_getsnd("BUBL1");
147 bsnd[1]=Z_getsnd("BUBL2");
148 init_fx1sin();
151 void FX_init(void) {
152 int i;
154 for(i=0;i<MAXFX;++i) fx[i].t=0;
155 bubsn=0;
156 last=0;
159 void FX_act(void) {
160 int i;
161 byte b;
163 bubsn=0;
164 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
165 case TFOG:
166 if(++fx[i].s>=20) fx[i].t=0;
167 break;
168 case IFOG:
169 if(++fx[i].s>=10) fx[i].t=0;
170 break;
171 case BUBL:
172 fx[i].yv-=5;
173 fx[i].xv=Z_dec(fx[i].xv,20);
174 fx[i].x+=fx[i].xv;
175 fx[i].y+=fx[i].yv;
176 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
177 break;
181 void FX_draw(void) {
182 int i,s;
184 for(i=0;i<MAXFX;++i) {
185 s=-1;
186 switch(fx[i].t) {
187 case TFOG: s=fx[i].s/2;break;
188 case IFOG: s=fx[i].s/2+10;break;
189 case BUBL:
190 V_dot((fx[i].x>>8)-w_x+WD/2,(fx[i].y>>8)-w_y+HT/2+1+w_o,0xC0+fx[i].s);//V_dot((fx[i].x>>8)-w_x+100,(fx[i].y>>8)-w_y+50+w_o,0xC0+fx[i].s);
191 continue;
193 if(s>=0) Z_drawspr(fx[i].x,fx[i].y,spr[s],sprd[s]);
197 static int findfree(void) {
198 int i;
200 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
201 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
202 if(++last>=MAXFX) last=0;
203 return last;
206 void FX_tfog(int x,int y) {
207 int i;
209 i=findfree();
210 fx[i].t=TFOG;fx[i].s=0;
211 fx[i].x=x;fx[i].y=y;
214 void FX_ifog(int x,int y) {
215 int i;
217 i=findfree();
218 fx[i].t=IFOG;fx[i].s=0;
219 fx[i].x=x;fx[i].y=y;
222 void FX_bubble(int x,int y,int xv,int yv,int n) {
223 int i;
225 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
226 for(;n>0;--n) {
227 i=findfree();
228 fx[i].t=BUBL;fx[i].s=rand()&3;
229 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
230 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;