DEADSOFTWARE

ppc: fix saves and more map loading improvements
[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"
31 enum{NONE,TFOG,IFOG,BUBL};
33 #pragma pack(1)
34 typedef struct{
35 int x,y,xv,yv;
36 char t,s;
37 }fx_t;
38 #pragma pack()
40 static void *spr[15],*bsnd[2];
41 static char sprd[15];
42 static fx_t fx[MAXFX];
43 static char bubsn;
44 static int last;
46 unsigned char fx_scr1[64000],fx_scr2[64000];
48 #define SINP 256
49 #define SINPM (SINP-1)
50 #define W (SINP/100)
52 static int stdsin[SINP]={
53 #include "fx1sin.dat"
54 };
55 static int sintab[SINP];
57 static unsigned char dmap[32*32];
59 static int isin(int a) {
60 return sintab[a&SINPM];
61 }
63 static void setamp(int a) {
64 int i;
66 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
67 }
69 void FX_trans1(int t) {
71 int x,y,u,v;
72 static unsigned char k;
73 unsigned p;
75 setamp(t);
76 k=t;
77 t*=W;
78 for(y=0,p=0;y<200;++y)
79 for(x=0;x<320;++x,++p) {
80 if(dmap[(y&31)*32+(x&31)]>=k) {
81 u=x+((isin(y+t))>>16);
82 v=y+((isin(u+t))>>16);
83 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
84 else scra[p]=fx_scr1[v*320+u];
85 }else scra[p]=fx_scr2[p];
86 }
88 }
90 static void init_fx1sin(void) {
91 int j,r,l,rr;
92 unsigned i;
94 memset(dmap,0,32*32);
95 for(i=1,rr=32*32;i<64;++i) {
96 for(l=32*32/64;l;--l,--rr) {
97 r=rand()%rr;
98 for(j=0;r;--r,++j) {
99 for(;dmap[j];++j);
101 for(;dmap[j];++j);
102 dmap[j]=i;
107 void FX_savegame (FILE *h) {
108 int i, n;
109 for (i = n = 0; i < MAXFX; ++i) {
110 if (fx[i].t) {
111 ++n;
114 myfwrite32(n, h);
115 for (i = 0; i < MAXFX; ++i) {
116 if (fx[i].t) {
117 myfwrite32(fx[i].x, h);
118 myfwrite32(fx[i].y, h);
119 myfwrite32(fx[i].xv, h);
120 myfwrite32(fx[i].yv, h);
121 myfwrite8(fx[i].t, h);
122 myfwrite8(fx[i].s, h);
127 void FX_loadgame (FILE *h) {
128 int i, n;
129 myfread32(&n, h);
130 for (i = 0; i < n; i++) {
131 myfread32(&fx[i].x, h);
132 myfread32(&fx[i].y, h);
133 myfread32(&fx[i].xv, h);
134 myfread32(&fx[i].yv, h);
135 myfread8(&fx[i].t, h);
136 myfread8(&fx[i].s, h);
140 void FX_alloc(void) {
141 int i;
143 for(i=0;i<10;++i) spr[i]=Z_getspr("TFOG",i,0,sprd+i);
144 for(;i<15;++i) spr[i]=Z_getspr("IFOG",i-10,0,sprd+i);
145 bsnd[0]=Z_getsnd("BUBL1");
146 bsnd[1]=Z_getsnd("BUBL2");
147 init_fx1sin();
150 void FX_init(void) {
151 int i;
153 for(i=0;i<MAXFX;++i) fx[i].t=0;
154 bubsn=0;
155 last=0;
158 void FX_act(void) {
159 int i;
160 byte b;
162 bubsn=0;
163 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
164 case TFOG:
165 if(++fx[i].s>=20) fx[i].t=0;
166 break;
167 case IFOG:
168 if(++fx[i].s>=10) fx[i].t=0;
169 break;
170 case BUBL:
171 fx[i].yv-=5;
172 fx[i].xv=Z_dec(fx[i].xv,20);
173 fx[i].x+=fx[i].xv;
174 fx[i].y+=fx[i].yv;
175 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
176 break;
180 void FX_draw(void) {
181 int i,s;
183 for(i=0;i<MAXFX;++i) {
184 s=-1;
185 switch(fx[i].t) {
186 case TFOG: s=fx[i].s/2;break;
187 case IFOG: s=fx[i].s/2+10;break;
188 case BUBL:
189 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);
190 continue;
192 if(s>=0) Z_drawspr(fx[i].x,fx[i].y,spr[s],sprd[s]);
196 static int findfree(void) {
197 int i;
199 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
200 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
201 if(++last>=MAXFX) last=0;
202 return last;
205 void FX_tfog(int x,int y) {
206 int i;
208 i=findfree();
209 fx[i].t=TFOG;fx[i].s=0;
210 fx[i].x=x;fx[i].y=y;
213 void FX_ifog(int x,int y) {
214 int i;
216 i=findfree();
217 fx[i].t=IFOG;fx[i].s=0;
218 fx[i].x=x;fx[i].y=y;
221 void FX_bubble(int x,int y,int xv,int yv,int n) {
222 int i;
224 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
225 for(;n>0;--n) {
226 i=findfree();
227 fx[i].t=BUBL;fx[i].s=rand()&3;
228 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
229 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;