DEADSOFTWARE

update copyrights
[flatwaifu.git] / src / fx.c
1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 * Copyright (C) 2011 Rambo
3 * Copyright (C) 2020 SovietPony
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
18 #include "glob.h"
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include "view.h"
23 #include "fx.h"
24 #include "misc.h"
25 #include "my.h"
27 enum{NONE,TFOG,IFOG,BUBL};
29 fx_t fx[MAXFX];
31 static void *bsnd[2];
32 static char bubsn;
33 static int last;
35 //unsigned char fx_scr1[64000],fx_scr2[64000];
37 #define SINP 256
38 #define SINPM (SINP-1)
39 #define W (SINP/100)
41 static int stdsin[SINP]={
42 #include "fx1sin.dat"
43 };
44 static int sintab[SINP];
46 static unsigned char dmap[32*32];
48 static int isin(int a) {
49 return sintab[a&SINPM];
50 }
52 static void setamp(int a) {
53 int i;
55 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
56 }
58 /*
59 void FX_trans1 (int t) {
60 int x,y,u,v;
61 static unsigned char k;
62 unsigned p;
64 setamp(t);
65 k=t;
66 t*=W;
67 for(y=0,p=0;y<200;++y)
68 for(x=0;x<320;++x,++p) {
69 if(dmap[(y&31)*32+(x&31)]>=k) {
70 u=x+((isin(y+t))>>16);
71 v=y+((isin(u+t))>>16);
72 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
73 else scra[p]=fx_scr1[v*320+u];
74 }else scra[p]=fx_scr2[p];
75 }
76 }
77 */
79 static void init_fx1sin(void) {
80 int j,r,l,rr;
81 unsigned i;
83 memset(dmap,0,32*32);
84 for(i=1,rr=32*32;i<64;++i) {
85 for(l=32*32/64;l;--l,--rr) {
86 r=rand()%rr;
87 for(j=0;r;--r,++j) {
88 for(;dmap[j];++j);
89 }
90 for(;dmap[j];++j);
91 dmap[j]=i;
92 }
93 }
94 }
96 void FX_alloc (void) {
97 bsnd[0]=Z_getsnd("BUBL1");
98 bsnd[1]=Z_getsnd("BUBL2");
99 init_fx1sin();
102 void FX_init (void) {
103 int i;
105 for(i=0;i<MAXFX;++i) fx[i].t=0;
106 bubsn=0;
107 last=0;
110 void FX_act (void) {
111 int i;
112 byte b;
114 bubsn=0;
115 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
116 case TFOG:
117 if(++fx[i].s>=20) fx[i].t=0;
118 break;
119 case IFOG:
120 if(++fx[i].s>=10) fx[i].t=0;
121 break;
122 case BUBL:
123 fx[i].yv-=5;
124 fx[i].xv=Z_dec(fx[i].xv,20);
125 fx[i].x+=fx[i].xv;
126 fx[i].y+=fx[i].yv;
127 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
128 break;
132 static int findfree (void) {
133 int i;
135 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
136 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
137 if(++last>=MAXFX) last=0;
138 return last;
141 void FX_tfog (int x, int y) {
142 int i;
144 i=findfree();
145 fx[i].t=TFOG;fx[i].s=0;
146 fx[i].x=x;fx[i].y=y;
149 void FX_ifog (int x, int y) {
150 int i;
152 i=findfree();
153 fx[i].t=IFOG;fx[i].s=0;
154 fx[i].x=x;fx[i].y=y;
157 void FX_bubble (int x, int y, int xv, int yv, int n) {
158 int i;
160 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
161 for(;n>0;--n) {
162 i=findfree();
163 fx[i].t=BUBL;fx[i].s=rand()&3;
164 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
165 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;