DEADSOFTWARE

d89b9d6122fd359742141cf17d219cbeaa99e2df
[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"
30 #define MAXINI 50
31 #define MAXSR 20
33 #define BL_XV 4
34 #define BL_YV 4
35 #define BL_MINT 10
36 #define BL_MAXT 14
38 #define SP_V 2
39 #define SP_MINT 5
40 #define SP_MAXT 7
42 extern byte z_dot;
44 #pragma pack(1)
45 typedef struct{
46 obj_t o;
47 byte c,t;
48 }dot_t;
49 #pragma pack()
51 typedef struct{
52 int xv,yv;
53 byte c,t;
54 }init_t;
56 static dot_t dot[MAXDOT];
57 static init_t bl_ini[MAXINI],sp_ini[MAXINI];
58 static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
59 static int ldot;
61 void DOT_savegame(FILE* h) {
62 int i,n;
64 for(i=n=0;i<MAXDOT;++i) if(dot[i].t) ++n;
65 myfwrite(&n,1,4,h);
66 for(i=0;i<MAXDOT;++i) if(dot[i].t) myfwrite(&dot[i],1,sizeof(dot_t),h);
67 }
69 void DOT_loadgame(FILE* h) {
70 int n;
72 myfread(&n,1,4,h);
73 myfread(dot,1,n*sizeof(dot_t),h);
74 }
76 void DOT_init(void) {
77 int i;
79 for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
80 ldot=0;
81 }
83 static void incldot(void) {
84 if(++ldot>=MAXDOT) ldot=0;
85 }
87 void DOT_alloc(void) {
88 int i;
90 for(i=0;i<MAXINI;++i) {
91 bl_ini[i].xv=myrand(BL_XV*2+1)-BL_XV;
92 bl_ini[i].yv=-myrand(BL_YV);
93 bl_ini[i].c=0xB0+myrand(16);
94 bl_ini[i].t=myrand(BL_MAXT-BL_MINT+1)+BL_MINT;
95 sp_ini[i].xv=myrand(SP_V*2+1)-SP_V;
96 sp_ini[i].yv=myrand(SP_V*2+1)-SP_V;
97 sp_ini[i].c=0xA0+myrand(6);
98 sp_ini[i].t=myrand(SP_MAXT-SP_MINT+1)+SP_MINT;
99 }
100 for(i=0;i<MAXSR;++i) {
101 sxr[i]=myrand(2*2+1)-2;
102 syr[i]=myrand(2*2+1)-2;
104 bl_r=sp_r=sr_r=0;
107 void DOT_act(void) {
108 int i,s,xv,yv;
110 z_dot=1;
111 for(i=0;i<MAXDOT;++i) if(dot[i].t) {
112 xv=dot[i].o.xv+dot[i].o.vx;
113 yv=dot[i].o.yv+dot[i].o.vy;
114 s=Z_moveobj(&dot[i].o);
115 if(dot[i].t<254) --dot[i].t;
116 if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
117 if(s&Z_HITLAND) {
118 if(!dot[i].o.xv) {
119 if(yv>2) {
120 if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
121 else dot[i].o.vx=Z_sign(dot[i].o.vx);
122 if(rand()%yv==0) dot[i].o.vx*=2;
123 dot[i].o.yv=yv-2;
126 dot[i].o.xv=0;
127 if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
129 if(s&Z_HITWALL) {
130 dot[i].o.vx=Z_sign(xv)*2;
131 dot[i].o.yv=Z_sign(dot[i].o.yv);
132 if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
133 if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
135 if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
137 z_dot=0;
140 void DOT_draw(void) {
141 int i;
143 for(i=0;i<MAXDOT;++i)
144 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);
147 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
148 int i;
150 if(!Z_canfit(x,y,0,1)) return;
151 i=ldot;
152 dot[i].o.x=x;dot[i].o.y=y;
153 dot[i].o.xv=xv;dot[i].o.yv=yv;
154 dot[i].c=c;dot[i].t=t;
155 dot[i].o.vx=dot[i].o.vy=0;
156 incldot();
159 void DOT_blood(int x,int y,int xv,int yv,int n) {
160 int i,k,dx,dy;
162 for(k=n;k;--k) {
163 dx=x+sxr[sr_r];dy=y+syr[sr_r];
164 if(!Z_canfit(x,y,0,1)) continue;
165 i=ldot;
166 dot[i].o.x=dx;dot[i].o.y=dy;
167 dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
168 dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
169 dot[i].c=bl_ini[bl_r].c;
170 dot[i].t=255;
171 dot[i].o.vx=dot[i].o.vy=0;
172 if(++bl_r>=MAXINI) bl_r=0;
173 if(++sr_r>=MAXSR) sr_r=0;
174 incldot();
178 void DOT_spark(int x,int y,int xv,int yv,int n) {
179 int i,k,dx,dy;
181 for(k=n;k;--k) {
182 dx=x+sxr[sr_r];dy=y+syr[sr_r];
183 if(!Z_canfit(x,y,0,1)) continue;
184 i=ldot;
185 dot[i].o.x=dx;dot[i].o.y=dy;
186 dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
187 dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
188 dot[i].c=sp_ini[sp_r].c;
189 dot[i].t=sp_ini[sp_r].t;
190 dot[i].o.vx=dot[i].o.vy=0;
191 if(++sp_r>=MAXINI) sp_r=0;
192 if(++sr_r>=MAXSR) sr_r=0;
193 incldot();
197 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
198 int i,k,dx,dy;
199 static byte ct[3]={0xC0,0x70,0xB0};
201 if(c<0 || c>=3) return;
202 c=ct[c];
203 for(k=n;k;--k) {
204 dx=x+sxr[sr_r];dy=y+syr[sr_r];
205 if(!Z_canfit(x,y,0,1)) continue;
206 i=ldot;
207 dot[i].o.x=dx;dot[i].o.y=dy;
208 dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
209 dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
210 dot[i].c=bl_ini[bl_r].c-0xB0+c;
211 dot[i].t=254;
212 dot[i].o.vx=dot[i].o.vy=0;
213 if(++bl_r>=MAXINI) bl_r=0;
214 if(++sr_r>=MAXSR) sr_r=0;
215 incldot();