DEADSOFTWARE

portability: avoid errors on some compilers
[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"
26 enum{NONE,TFOG,IFOG,BUBL};
28 fx_t fx[MAXFX];
30 static void *bsnd[2];
31 static char bubsn;
32 static int last;
34 //unsigned char fx_scr1[64000],fx_scr2[64000];
36 #define SINP 256
37 #define SINPM (SINP-1)
38 #define W (SINP/100)
40 static int stdsin[SINP]={
41 #include "fx1sin.dat"
42 };
43 static int sintab[SINP];
45 static unsigned char dmap[32*32];
47 static int isin(int a) {
48 return sintab[a&SINPM];
49 }
51 static void setamp(int a) {
52 int i;
54 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
55 }
57 /*
58 void FX_trans1 (int t) {
59 int x,y,u,v;
60 static unsigned char k;
61 unsigned p;
63 setamp(t);
64 k=t;
65 t*=W;
66 for(y=0,p=0;y<200;++y)
67 for(x=0;x<320;++x,++p) {
68 if(dmap[(y&31)*32+(x&31)]>=k) {
69 u=x+((isin(y+t))>>16);
70 v=y+((isin(u+t))>>16);
71 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
72 else scra[p]=fx_scr1[v*320+u];
73 }else scra[p]=fx_scr2[p];
74 }
75 }
76 */
78 static void init_fx1sin(void) {
79 int j,r,l,rr;
80 unsigned i;
82 memset(dmap,0,32*32);
83 for(i=1,rr=32*32;i<64;++i) {
84 for(l=32*32/64;l;--l,--rr) {
85 r=rand()%rr;
86 for(j=0;r;--r,++j) {
87 for(;dmap[j];++j);
88 }
89 for(;dmap[j];++j);
90 dmap[j]=i;
91 }
92 }
93 }
95 void FX_alloc (void) {
96 bsnd[0]=Z_getsnd("BUBL1");
97 bsnd[1]=Z_getsnd("BUBL2");
98 init_fx1sin();
99 }
101 void FX_init (void) {
102 int i;
104 for(i=0;i<MAXFX;++i) fx[i].t=0;
105 bubsn=0;
106 last=0;
109 void FX_act (void) {
110 int i;
111 byte b;
113 bubsn=0;
114 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
115 case TFOG:
116 if(++fx[i].s>=20) fx[i].t=0;
117 break;
118 case IFOG:
119 if(++fx[i].s>=10) fx[i].t=0;
120 break;
121 case BUBL:
122 fx[i].yv-=5;
123 fx[i].xv=Z_dec(fx[i].xv,20);
124 fx[i].x+=fx[i].xv;
125 fx[i].y+=fx[i].yv;
126 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
127 break;
131 static int findfree (void) {
132 int i;
134 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
135 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
136 if(++last>=MAXFX) last=0;
137 return last;
140 void FX_tfog (int x, int y) {
141 int i;
143 i=findfree();
144 fx[i].t=TFOG;fx[i].s=0;
145 fx[i].x=x;fx[i].y=y;
148 void FX_ifog (int x, int y) {
149 int i;
151 i=findfree();
152 fx[i].t=IFOG;fx[i].s=0;
153 fx[i].x=x;fx[i].y=y;
156 void FX_bubble (int x, int y, int xv, int yv, int n) {
157 int i;
159 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
160 for(;n>0;--n) {
161 i=findfree();
162 fx[i].t=BUBL;fx[i].s=rand()&3;
163 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
164 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;