DEADSOFTWARE

map: use streams for map loader
[flatwaifu.git] / src / dots.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 "view.h"
22 #include "dots.h"
23 #include "misc.h"
24 #include "my.h"
26 #define MAXINI 50
27 #define MAXSR 20
29 #define BL_XV 4
30 #define BL_YV 4
31 #define BL_MINT 10
32 #define BL_MAXT 14
34 #define SP_V 2
35 #define SP_MINT 5
36 #define SP_MAXT 7
38 typedef struct{
39 int xv,yv;
40 byte c,t;
41 }init_t;
43 dot_t dot[MAXDOT];
45 static init_t bl_ini[MAXINI],sp_ini[MAXINI];
46 static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
47 static int ldot;
49 void DOT_init(void) {
50 int i;
52 for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
53 ldot=0;
54 }
56 static void incldot(void) {
57 if(++ldot>=MAXDOT) ldot=0;
58 }
60 void DOT_alloc(void) {
61 int i;
63 for(i=0;i<MAXINI;++i) {
64 bl_ini[i].xv=myrand(BL_XV*2+1)-BL_XV;
65 bl_ini[i].yv=-myrand(BL_YV);
66 bl_ini[i].c=0xB0+myrand(16);
67 bl_ini[i].t=myrand(BL_MAXT-BL_MINT+1)+BL_MINT;
68 sp_ini[i].xv=myrand(SP_V*2+1)-SP_V;
69 sp_ini[i].yv=myrand(SP_V*2+1)-SP_V;
70 sp_ini[i].c=0xA0+myrand(6);
71 sp_ini[i].t=myrand(SP_MAXT-SP_MINT+1)+SP_MINT;
72 }
73 for(i=0;i<MAXSR;++i) {
74 sxr[i]=myrand(2*2+1)-2;
75 syr[i]=myrand(2*2+1)-2;
76 }
77 bl_r=sp_r=sr_r=0;
78 }
80 void DOT_act(void) {
81 int i,s,xv,yv;
83 z_dot=1;
84 for(i=0;i<MAXDOT;++i) if(dot[i].t) {
85 xv=dot[i].o.xv+dot[i].o.vx;
86 yv=dot[i].o.yv+dot[i].o.vy;
87 s=Z_moveobj(&dot[i].o);
88 if(dot[i].t<254) --dot[i].t;
89 if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
90 if(s&Z_HITLAND) {
91 if(!dot[i].o.xv) {
92 if(yv>2) {
93 if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
94 else dot[i].o.vx=Z_sign(dot[i].o.vx);
95 if(rand()%yv==0) dot[i].o.vx*=2;
96 dot[i].o.yv=yv-2;
97 }
98 }
99 dot[i].o.xv=0;
100 if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
102 if(s&Z_HITWALL) {
103 dot[i].o.vx=Z_sign(xv)*2;
104 dot[i].o.yv=Z_sign(dot[i].o.yv);
105 if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
106 if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
108 if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
110 z_dot=0;
113 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
114 int i;
116 if(!Z_canfit(x,y,0,1)) return;
117 i=ldot;
118 dot[i].o.x=x;dot[i].o.y=y;
119 dot[i].o.xv=xv;dot[i].o.yv=yv;
120 dot[i].c=c;dot[i].t=t;
121 dot[i].o.vx=dot[i].o.vy=0;
122 incldot();
125 void DOT_blood(int x,int y,int xv,int yv,int n) {
126 int i,k,dx,dy;
128 for(k=n;k;--k) {
129 dx=x+sxr[sr_r];dy=y+syr[sr_r];
130 if(!Z_canfit(x,y,0,1)) continue;
131 i=ldot;
132 dot[i].o.x=dx;dot[i].o.y=dy;
133 dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
134 dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
135 dot[i].c=bl_ini[bl_r].c;
136 dot[i].t=255;
137 dot[i].o.vx=dot[i].o.vy=0;
138 if(++bl_r>=MAXINI) bl_r=0;
139 if(++sr_r>=MAXSR) sr_r=0;
140 incldot();
144 void DOT_spark(int x,int y,int xv,int yv,int n) {
145 int i,k,dx,dy;
147 for(k=n;k;--k) {
148 dx=x+sxr[sr_r];dy=y+syr[sr_r];
149 if(!Z_canfit(x,y,0,1)) continue;
150 i=ldot;
151 dot[i].o.x=dx;dot[i].o.y=dy;
152 dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
153 dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
154 dot[i].c=sp_ini[sp_r].c;
155 dot[i].t=sp_ini[sp_r].t;
156 dot[i].o.vx=dot[i].o.vy=0;
157 if(++sp_r>=MAXINI) sp_r=0;
158 if(++sr_r>=MAXSR) sr_r=0;
159 incldot();
163 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
164 int i,k,dx,dy;
165 static byte ct[3]={0xC0,0x70,0xB0};
167 if(c<0 || c>=3) return;
168 c=ct[c];
169 for(k=n;k;--k) {
170 dx=x+sxr[sr_r];dy=y+syr[sr_r];
171 if(!Z_canfit(x,y,0,1)) continue;
172 i=ldot;
173 dot[i].o.x=dx;dot[i].o.y=dy;
174 dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
175 dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
176 dot[i].c=bl_ini[bl_r].c-0xB0+c;
177 dot[i].t=254;
178 dot[i].o.vx=dot[i].o.vy=0;
179 if(++bl_r>=MAXINI) bl_r=0;
180 if(++sr_r>=MAXSR) sr_r=0;
181 incldot();