DEADSOFTWARE

portability: avoid errors on some compilers
[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"
25 #define MAXINI 50
26 #define MAXSR 20
28 #define BL_XV 4
29 #define BL_YV 4
30 #define BL_MINT 10
31 #define BL_MAXT 14
33 #define SP_V 2
34 #define SP_MINT 5
35 #define SP_MAXT 7
37 typedef struct{
38 int xv,yv;
39 byte c,t;
40 }init_t;
42 dot_t dot[MAXDOT];
44 static init_t bl_ini[MAXINI],sp_ini[MAXINI];
45 static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
46 static int ldot;
48 void DOT_init(void) {
49 int i;
51 for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
52 ldot=0;
53 }
55 static void incldot(void) {
56 if(++ldot>=MAXDOT) ldot=0;
57 }
59 void DOT_alloc(void) {
60 int i;
62 for(i=0;i<MAXINI;++i) {
63 bl_ini[i].xv=myrand(BL_XV*2+1)-BL_XV;
64 bl_ini[i].yv=-myrand(BL_YV);
65 bl_ini[i].c=0xB0+myrand(16);
66 bl_ini[i].t=myrand(BL_MAXT-BL_MINT+1)+BL_MINT;
67 sp_ini[i].xv=myrand(SP_V*2+1)-SP_V;
68 sp_ini[i].yv=myrand(SP_V*2+1)-SP_V;
69 sp_ini[i].c=0xA0+myrand(6);
70 sp_ini[i].t=myrand(SP_MAXT-SP_MINT+1)+SP_MINT;
71 }
72 for(i=0;i<MAXSR;++i) {
73 sxr[i]=myrand(2*2+1)-2;
74 syr[i]=myrand(2*2+1)-2;
75 }
76 bl_r=sp_r=sr_r=0;
77 }
79 void DOT_act(void) {
80 int i,s,xv,yv;
82 z_dot=1;
83 for(i=0;i<MAXDOT;++i) if(dot[i].t) {
84 xv=dot[i].o.xv+dot[i].o.vx;
85 yv=dot[i].o.yv+dot[i].o.vy;
86 s=Z_moveobj(&dot[i].o);
87 if(dot[i].t<254) --dot[i].t;
88 if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
89 if(s&Z_HITLAND) {
90 if(!dot[i].o.xv) {
91 if(yv>2) {
92 if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
93 else dot[i].o.vx=Z_sign(dot[i].o.vx);
94 if(rand()%yv==0) dot[i].o.vx*=2;
95 dot[i].o.yv=yv-2;
96 }
97 }
98 dot[i].o.xv=0;
99 if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
101 if(s&Z_HITWALL) {
102 dot[i].o.vx=Z_sign(xv)*2;
103 dot[i].o.yv=Z_sign(dot[i].o.yv);
104 if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
105 if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
107 if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
109 z_dot=0;
112 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
113 int i;
115 if(!Z_canfit(x,y,0,1)) return;
116 i=ldot;
117 dot[i].o.x=x;dot[i].o.y=y;
118 dot[i].o.xv=xv;dot[i].o.yv=yv;
119 dot[i].c=c;dot[i].t=t;
120 dot[i].o.vx=dot[i].o.vy=0;
121 incldot();
124 void DOT_blood(int x,int y,int xv,int yv,int n) {
125 int i,k,dx,dy;
127 for(k=n;k;--k) {
128 dx=x+sxr[sr_r];dy=y+syr[sr_r];
129 if(!Z_canfit(x,y,0,1)) continue;
130 i=ldot;
131 dot[i].o.x=dx;dot[i].o.y=dy;
132 dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
133 dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
134 dot[i].c=bl_ini[bl_r].c;
135 dot[i].t=255;
136 dot[i].o.vx=dot[i].o.vy=0;
137 if(++bl_r>=MAXINI) bl_r=0;
138 if(++sr_r>=MAXSR) sr_r=0;
139 incldot();
143 void DOT_spark(int x,int y,int xv,int yv,int n) {
144 int i,k,dx,dy;
146 for(k=n;k;--k) {
147 dx=x+sxr[sr_r];dy=y+syr[sr_r];
148 if(!Z_canfit(x,y,0,1)) continue;
149 i=ldot;
150 dot[i].o.x=dx;dot[i].o.y=dy;
151 dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
152 dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
153 dot[i].c=sp_ini[sp_r].c;
154 dot[i].t=sp_ini[sp_r].t;
155 dot[i].o.vx=dot[i].o.vy=0;
156 if(++sp_r>=MAXINI) sp_r=0;
157 if(++sr_r>=MAXSR) sr_r=0;
158 incldot();
162 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
163 int i,k,dx,dy;
164 static byte ct[3]={0xC0,0x70,0xB0};
166 if(c<0 || c>=3) return;
167 c=ct[c];
168 for(k=n;k;--k) {
169 dx=x+sxr[sr_r];dy=y+syr[sr_r];
170 if(!Z_canfit(x,y,0,1)) continue;
171 i=ldot;
172 dot[i].o.x=dx;dot[i].o.y=dy;
173 dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
174 dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
175 dot[i].c=bl_ini[bl_r].c-0xB0+c;
176 dot[i].t=254;
177 dot[i].o.vx=dot[i].o.vy=0;
178 if(++bl_r>=MAXINI) bl_r=0;
179 if(++sr_r>=MAXSR) sr_r=0;
180 incldot();