DEADSOFTWARE

fix some warnings
[flatwaifu.git] / src / dots.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
23 #include "glob.h"
24 #include <stdlib.h>
25 #include "vga.h"
26 #include "view.h"
27 #include "dots.h"
28 #include "misc.h"
29 #include "my.h"
31 #define MAXINI 50
32 #define MAXSR 20
34 #define BL_XV 4
35 #define BL_YV 4
36 #define BL_MINT 10
37 #define BL_MAXT 14
39 #define SP_V 2
40 #define SP_MINT 5
41 #define SP_MAXT 7
43 extern byte z_dot;
45 #pragma pack(1)
46 typedef struct{
47 obj_t o;
48 byte c,t;
49 }dot_t;
50 #pragma pack()
52 typedef struct{
53 int xv,yv;
54 byte c,t;
55 }init_t;
57 static dot_t dot[MAXDOT];
58 static init_t bl_ini[MAXINI],sp_ini[MAXINI];
59 static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
60 static int ldot;
62 void DOT_savegame (FILE *h) {
63 int i, n;
64 for (i = n = 0; i < MAXDOT; ++i) {
65 if (dot[i].t) {
66 ++n;
67 }
68 }
69 myfwrite32(n, h);
70 for (i = 0; i < MAXDOT; ++i) {
71 if (dot[i].t) {
72 myfwrite32(dot[i].o.x, h);
73 myfwrite32(dot[i].o.y, h);
74 myfwrite32(dot[i].o.xv, h);
75 myfwrite32(dot[i].o.yv, h);
76 myfwrite32(dot[i].o.vx, h);
77 myfwrite32(dot[i].o.vy, h);
78 myfwrite32(dot[i].o.r, h);
79 myfwrite32(dot[i].o.h, h);
80 myfwrite8(dot[i].c, h);
81 myfwrite8(dot[i].t, h);
82 }
83 }
84 }
86 void DOT_loadgame (FILE *h) {
87 int i, n;
88 n = myfread32(h);
89 for (i = 0; i < n; i++) {
90 dot[i].o.x = myfread32(h);
91 dot[i].o.y = myfread32(h);
92 dot[i].o.xv = myfread32(h);
93 dot[i].o.yv = myfread32(h);
94 dot[i].o.vx = myfread32(h);
95 dot[i].o.vy = myfread32(h);
96 dot[i].o.r = myfread32(h);
97 dot[i].o.h = myfread32(h);
98 dot[i].c = myfread8(h);
99 dot[i].t = myfread8(h);
103 void DOT_init(void) {
104 int i;
106 for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
107 ldot=0;
110 static void incldot(void) {
111 if(++ldot>=MAXDOT) ldot=0;
114 void DOT_alloc(void) {
115 int i;
117 for(i=0;i<MAXINI;++i) {
118 bl_ini[i].xv=myrand(BL_XV*2+1)-BL_XV;
119 bl_ini[i].yv=-myrand(BL_YV);
120 bl_ini[i].c=0xB0+myrand(16);
121 bl_ini[i].t=myrand(BL_MAXT-BL_MINT+1)+BL_MINT;
122 sp_ini[i].xv=myrand(SP_V*2+1)-SP_V;
123 sp_ini[i].yv=myrand(SP_V*2+1)-SP_V;
124 sp_ini[i].c=0xA0+myrand(6);
125 sp_ini[i].t=myrand(SP_MAXT-SP_MINT+1)+SP_MINT;
127 for(i=0;i<MAXSR;++i) {
128 sxr[i]=myrand(2*2+1)-2;
129 syr[i]=myrand(2*2+1)-2;
131 bl_r=sp_r=sr_r=0;
134 void DOT_act(void) {
135 int i,s,xv,yv;
137 z_dot=1;
138 for(i=0;i<MAXDOT;++i) if(dot[i].t) {
139 xv=dot[i].o.xv+dot[i].o.vx;
140 yv=dot[i].o.yv+dot[i].o.vy;
141 s=Z_moveobj(&dot[i].o);
142 if(dot[i].t<254) --dot[i].t;
143 if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
144 if(s&Z_HITLAND) {
145 if(!dot[i].o.xv) {
146 if(yv>2) {
147 if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
148 else dot[i].o.vx=Z_sign(dot[i].o.vx);
149 if(rand()%yv==0) dot[i].o.vx*=2;
150 dot[i].o.yv=yv-2;
153 dot[i].o.xv=0;
154 if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
156 if(s&Z_HITWALL) {
157 dot[i].o.vx=Z_sign(xv)*2;
158 dot[i].o.yv=Z_sign(dot[i].o.yv);
159 if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
160 if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
162 if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
164 z_dot=0;
167 void DOT_draw(void) {
168 int i;
170 for(i=0;i<MAXDOT;++i)
171 if(dot[i].t) V_dot(dot[i].o.x-w_x+WD/2,dot[i].o.y-w_y+HT/2+1+w_o,dot[i].c);//if(dot[i].t) V_dot(dot[i].o.x-w_x+100,dot[i].o.y-w_y+50+w_o,dot[i].c);
174 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
175 int i;
177 if(!Z_canfit(x,y,0,1)) return;
178 i=ldot;
179 dot[i].o.x=x;dot[i].o.y=y;
180 dot[i].o.xv=xv;dot[i].o.yv=yv;
181 dot[i].c=c;dot[i].t=t;
182 dot[i].o.vx=dot[i].o.vy=0;
183 incldot();
186 void DOT_blood(int x,int y,int xv,int yv,int n) {
187 int i,k,dx,dy;
189 for(k=n;k;--k) {
190 dx=x+sxr[sr_r];dy=y+syr[sr_r];
191 if(!Z_canfit(x,y,0,1)) continue;
192 i=ldot;
193 dot[i].o.x=dx;dot[i].o.y=dy;
194 dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
195 dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
196 dot[i].c=bl_ini[bl_r].c;
197 dot[i].t=255;
198 dot[i].o.vx=dot[i].o.vy=0;
199 if(++bl_r>=MAXINI) bl_r=0;
200 if(++sr_r>=MAXSR) sr_r=0;
201 incldot();
205 void DOT_spark(int x,int y,int xv,int yv,int n) {
206 int i,k,dx,dy;
208 for(k=n;k;--k) {
209 dx=x+sxr[sr_r];dy=y+syr[sr_r];
210 if(!Z_canfit(x,y,0,1)) continue;
211 i=ldot;
212 dot[i].o.x=dx;dot[i].o.y=dy;
213 dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
214 dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
215 dot[i].c=sp_ini[sp_r].c;
216 dot[i].t=sp_ini[sp_r].t;
217 dot[i].o.vx=dot[i].o.vy=0;
218 if(++sp_r>=MAXINI) sp_r=0;
219 if(++sr_r>=MAXSR) sr_r=0;
220 incldot();
224 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
225 int i,k,dx,dy;
226 static byte ct[3]={0xC0,0x70,0xB0};
228 if(c<0 || c>=3) return;
229 c=ct[c];
230 for(k=n;k;--k) {
231 dx=x+sxr[sr_r];dy=y+syr[sr_r];
232 if(!Z_canfit(x,y,0,1)) continue;
233 i=ldot;
234 dot[i].o.x=dx;dot[i].o.y=dy;
235 dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
236 dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
237 dot[i].c=bl_ini[bl_r].c-0xB0+c;
238 dot[i].t=254;
239 dot[i].o.vx=dot[i].o.vy=0;
240 if(++bl_r>=MAXINI) bl_r=0;
241 if(++sr_r>=MAXSR) sr_r=0;
242 incldot();