1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 * Copyright (C) 2011 Rambo
3 * Copyright (C) 2020 SovietPony
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.
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.
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/>.
44 static init_t bl_ini
[MAXINI
],sp_ini
[MAXINI
];
45 static int bl_r
,sp_r
,sr_r
,sxr
[MAXSR
],syr
[MAXSR
];
51 for(i
=0;i
<MAXDOT
;++i
) {dot
[i
].t
=0;dot
[i
].o
.r
=0;dot
[i
].o
.h
=1;}
55 static void incldot(void) {
56 if(++ldot
>=MAXDOT
) ldot
=0;
59 void DOT_alloc(void) {
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
;
72 for(i
=0;i
<MAXSR
;++i
) {
73 sxr
[i
]=myrand(2*2+1)-2;
74 syr
[i
]=myrand(2*2+1)-2;
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;}
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;
99 if(dot
[i
].t
>4 && dot
[i
].t
!=255) dot
[i
].t
=4;
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;}
112 void DOT_add(int x
,int y
,char xv
,char yv
,byte c
,byte t
) {
115 if(!Z_canfit(x
,y
,0,1)) return;
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;
124 void DOT_blood(int x
,int y
,int xv
,int yv
,int n
) {
128 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
129 if(!Z_canfit(x
,y
,0,1)) continue;
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
;
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;
143 void DOT_spark(int x
,int y
,int xv
,int yv
,int n
) {
147 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
148 if(!Z_canfit(x
,y
,0,1)) continue;
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;
162 void DOT_water(int x
,int y
,int xv
,int yv
,int n
,int c
) {
164 static byte ct
[3]={0xC0,0x70,0xB0};
166 if(c
<0 || c
>=3) return;
169 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
170 if(!Z_canfit(x
,y
,0,1)) continue;
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
;
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;