DEADSOFTWARE

ppc: fix saves and more map loading improvements
[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;
63 for (i = n = 0; i < MAXDOT; ++i) {
64 if (dot[i].t) {
65 ++n;
66 }
67 }
68 myfwrite32(n, h);
69 for (i = 0; i < MAXDOT; ++i) {
70 if (dot[i].t) {
71 myfwrite32(dot[i].o.x, h);
72 myfwrite32(dot[i].o.y, h);
73 myfwrite32(dot[i].o.xv, h);
74 myfwrite32(dot[i].o.yv, h);
75 myfwrite32(dot[i].o.vx, h);
76 myfwrite32(dot[i].o.vy, h);
77 myfwrite32(dot[i].o.r, h);
78 myfwrite32(dot[i].o.h, h);
79 myfwrite8(dot[i].c, h);
80 myfwrite8(dot[i].t, h);
81 }
82 }
83 }
85 void DOT_loadgame (FILE *h) {
86 int i, n;
87 myfread32(&n, h);
88 for (i = 0; i < n; i++) {
89 myfread32(&dot[i].o.x, h);
90 myfread32(&dot[i].o.y, h);
91 myfread32(&dot[i].o.xv, h);
92 myfread32(&dot[i].o.yv, h);
93 myfread32(&dot[i].o.vx, h);
94 myfread32(&dot[i].o.vy, h);
95 myfread32(&dot[i].o.r, h);
96 myfread32(&dot[i].o.h, h);
97 myfread8(&dot[i].c, h);
98 myfread8(&dot[i].t, h);
99 }
102 void DOT_init(void) {
103 int i;
105 for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
106 ldot=0;
109 static void incldot(void) {
110 if(++ldot>=MAXDOT) ldot=0;
113 void DOT_alloc(void) {
114 int i;
116 for(i=0;i<MAXINI;++i) {
117 bl_ini[i].xv=myrand(BL_XV*2+1)-BL_XV;
118 bl_ini[i].yv=-myrand(BL_YV);
119 bl_ini[i].c=0xB0+myrand(16);
120 bl_ini[i].t=myrand(BL_MAXT-BL_MINT+1)+BL_MINT;
121 sp_ini[i].xv=myrand(SP_V*2+1)-SP_V;
122 sp_ini[i].yv=myrand(SP_V*2+1)-SP_V;
123 sp_ini[i].c=0xA0+myrand(6);
124 sp_ini[i].t=myrand(SP_MAXT-SP_MINT+1)+SP_MINT;
126 for(i=0;i<MAXSR;++i) {
127 sxr[i]=myrand(2*2+1)-2;
128 syr[i]=myrand(2*2+1)-2;
130 bl_r=sp_r=sr_r=0;
133 void DOT_act(void) {
134 int i,s,xv,yv;
136 z_dot=1;
137 for(i=0;i<MAXDOT;++i) if(dot[i].t) {
138 xv=dot[i].o.xv+dot[i].o.vx;
139 yv=dot[i].o.yv+dot[i].o.vy;
140 s=Z_moveobj(&dot[i].o);
141 if(dot[i].t<254) --dot[i].t;
142 if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
143 if(s&Z_HITLAND) {
144 if(!dot[i].o.xv) {
145 if(yv>2) {
146 if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
147 else dot[i].o.vx=Z_sign(dot[i].o.vx);
148 if(rand()%yv==0) dot[i].o.vx*=2;
149 dot[i].o.yv=yv-2;
152 dot[i].o.xv=0;
153 if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
155 if(s&Z_HITWALL) {
156 dot[i].o.vx=Z_sign(xv)*2;
157 dot[i].o.yv=Z_sign(dot[i].o.yv);
158 if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
159 if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
161 if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
163 z_dot=0;
166 void DOT_draw(void) {
167 int i;
169 for(i=0;i<MAXDOT;++i)
170 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);
173 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
174 int i;
176 if(!Z_canfit(x,y,0,1)) return;
177 i=ldot;
178 dot[i].o.x=x;dot[i].o.y=y;
179 dot[i].o.xv=xv;dot[i].o.yv=yv;
180 dot[i].c=c;dot[i].t=t;
181 dot[i].o.vx=dot[i].o.vy=0;
182 incldot();
185 void DOT_blood(int x,int y,int xv,int yv,int n) {
186 int i,k,dx,dy;
188 for(k=n;k;--k) {
189 dx=x+sxr[sr_r];dy=y+syr[sr_r];
190 if(!Z_canfit(x,y,0,1)) continue;
191 i=ldot;
192 dot[i].o.x=dx;dot[i].o.y=dy;
193 dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
194 dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
195 dot[i].c=bl_ini[bl_r].c;
196 dot[i].t=255;
197 dot[i].o.vx=dot[i].o.vy=0;
198 if(++bl_r>=MAXINI) bl_r=0;
199 if(++sr_r>=MAXSR) sr_r=0;
200 incldot();
204 void DOT_spark(int x,int y,int xv,int yv,int n) {
205 int i,k,dx,dy;
207 for(k=n;k;--k) {
208 dx=x+sxr[sr_r];dy=y+syr[sr_r];
209 if(!Z_canfit(x,y,0,1)) continue;
210 i=ldot;
211 dot[i].o.x=dx;dot[i].o.y=dy;
212 dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
213 dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
214 dot[i].c=sp_ini[sp_r].c;
215 dot[i].t=sp_ini[sp_r].t;
216 dot[i].o.vx=dot[i].o.vy=0;
217 if(++sp_r>=MAXINI) sp_r=0;
218 if(++sr_r>=MAXSR) sr_r=0;
219 incldot();
223 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
224 int i,k,dx,dy;
225 static byte ct[3]={0xC0,0x70,0xB0};
227 if(c<0 || c>=3) return;
228 c=ct[c];
229 for(k=n;k;--k) {
230 dx=x+sxr[sr_r];dy=y+syr[sr_r];
231 if(!Z_canfit(x,y,0,1)) continue;
232 i=ldot;
233 dot[i].o.x=dx;dot[i].o.y=dy;
234 dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
235 dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
236 dot[i].c=bl_ini[bl_r].c-0xB0+c;
237 dot[i].t=254;
238 dot[i].o.vx=dot[i].o.vy=0;
239 if(++bl_r>=MAXINI) bl_r=0;
240 if(++sr_r>=MAXSR) sr_r=0;
241 incldot();