install: add install sources and resources
[doom2d-restoration.git] / GAME / DOTS.C
blob81004e93fbd70eda9ac632630f8f14596fdd59b7
1 #include "glob.h"
2 //#include <stdio.h>
3 #include <stdlib.h>
4 #include "files.h"
5 #include "memory.h"
6 #include "vga.h"
7 #include "error.h"
8 #include "keyb.h"
9 #include "sound.h"
10 #include "view.h"
11 #include "dots.h"
12 #include "misc.h"
14 #define MAXINI 50
15 #define MAXSR 20
17 #define BL_XV 4
18 #define BL_YV 4
19 #define BL_MINT 10
20 #define BL_MAXT 14
22 #define SP_V 2
23 #define SP_MINT 5
24 #define SP_MAXT 7
26 extern byte z_dot;
28 typedef struct{
29   obj_t o;
30   byte c,t;
31 }dot_t;
33 typedef struct{
34   int xv,yv;
35   byte c,t;
36 }init_t;
38 static dot_t dot[MAXDOT];
39 static init_t bl_ini[MAXINI],sp_ini[MAXINI];
40 static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
41 static int ldot;
43 void DOT_savegame(int h) {
44   int i,n;
46   for(i=n=0;i<MAXDOT;++i) if(dot[i].t) ++n;
47   write(h,&n,4);
48 //  printf("dots: %d\n",n);
49   for(i=0;i<MAXDOT;++i) if(dot[i].t) write(h,&dot[i],sizeof(dot_t));
52 void DOT_loadgame(int h) {
53   int n;
55   read(h,&n,4);
56 //  printf("dots: %d\n",n);
57   read(h,dot,n*sizeof(dot_t));
58 //  for(i=0;i<n;++i) printf("dot#%d %u\n",i,(unsigned)dot[i].t);
61 void DOT_init(void) {
62   int i;
64   for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
65   ldot=0;
68 static void incldot(void) {
69   if(++ldot>=MAXDOT) ldot=0;
72 void DOT_alloc(void) {
73   int i;
75 //  logo("  dots");
76   for(i=0;i<MAXINI;++i) {
77         bl_ini[i].xv=random(BL_XV*2+1)-BL_XV;
78         bl_ini[i].yv=-random(BL_YV);
79         bl_ini[i].c=0xB0+random(16);
80         bl_ini[i].t=random(BL_MAXT-BL_MINT+1)+BL_MINT;
81         sp_ini[i].xv=random(SP_V*2+1)-SP_V;
82         sp_ini[i].yv=random(SP_V*2+1)-SP_V;
83         sp_ini[i].c=0xA0+random(6);
84         sp_ini[i].t=random(SP_MAXT-SP_MINT+1)+SP_MINT;
85   }
86   for(i=0;i<MAXSR;++i) {
87         sxr[i]=random(2*2+1)-2;
88         syr[i]=random(2*2+1)-2;
89   }
90   bl_r=sp_r=sr_r=0;
93 void DOT_act(void) {
94   int i,s,xv,yv;
96   z_dot=1;
97   for(i=0;i<MAXDOT;++i) if(dot[i].t) {
98     xv=dot[i].o.xv+dot[i].o.vx;
99     yv=dot[i].o.yv+dot[i].o.vy;
100     s=Z_moveobj(&dot[i].o);
101     if(dot[i].t<254) --dot[i].t;
102     if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
103     if(s&Z_HITLAND) {
104       if(!dot[i].o.xv) {
105         if(yv>2) {
106           if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
107           else dot[i].o.vx=Z_sign(dot[i].o.vx);
108           if(rand()%yv==0) dot[i].o.vx*=2;
109           dot[i].o.yv=yv-2;
110         }
111       }
112       dot[i].o.xv=0;
113       if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
114     }
115     if(s&Z_HITWALL) {
116       dot[i].o.vx=Z_sign(xv)*2;
117       dot[i].o.yv=Z_sign(dot[i].o.yv);
118       if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
119       if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
120     }
121     if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(random(100))?-2:0;}
122   }
123   z_dot=0;
126 void DOT_draw(void) {
127   int i;
129   for(i=0;i<MAXDOT;++i)
130     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);
133 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
134   int i;
136   if(!Z_canfit(x,y,0,1)) return;
137   i=ldot;
138   dot[i].o.x=x;dot[i].o.y=y;
139   dot[i].o.xv=xv;dot[i].o.yv=yv;
140   dot[i].c=c;dot[i].t=t;
141   dot[i].o.vx=dot[i].o.vy=0;
142   incldot();
145 void DOT_blood(int x,int y,int xv,int yv,int n) {
146   int i,k,dx,dy;
148   for(k=n;k;--k) {
149     dx=x+sxr[sr_r];dy=y+syr[sr_r];
150     if(!Z_canfit(x,y,0,1)) continue;
151     i=ldot;
152         dot[i].o.x=dx;dot[i].o.y=dy;
153         dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
154         dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
155         dot[i].c=bl_ini[bl_r].c;
156         dot[i].t=255;
157         dot[i].o.vx=dot[i].o.vy=0;
158         if(++bl_r>=MAXINI) bl_r=0;
159         if(++sr_r>=MAXSR) sr_r=0;
160     incldot();
161   }
164 void DOT_spark(int x,int y,int xv,int yv,int n) {
165   int i,k,dx,dy;
167   for(k=n;k;--k) {
168     dx=x+sxr[sr_r];dy=y+syr[sr_r];
169     if(!Z_canfit(x,y,0,1)) continue;
170     i=ldot;
171         dot[i].o.x=dx;dot[i].o.y=dy;
172         dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
173         dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
174         dot[i].c=sp_ini[sp_r].c;
175         dot[i].t=sp_ini[sp_r].t;
176         dot[i].o.vx=dot[i].o.vy=0;
177         if(++sp_r>=MAXINI) sp_r=0;
178         if(++sr_r>=MAXSR) sr_r=0;
179     incldot();
180   }
183 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
184   int i,k,dx,dy;
185   static byte ct[3]={0xC0,0x70,0xB0};
187   if(c<0 || c>=3) return;
188   c=ct[c];
189   for(k=n;k;--k) {
190     dx=x+sxr[sr_r];dy=y+syr[sr_r];
191     if(!Z_canfit(x,y,0,1)) continue;
192     i=ldot;
193         dot[i].o.x=dx;dot[i].o.y=dy;
194         dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
195         dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
196         dot[i].c=bl_ini[bl_r].c-0xB0+c;
197         dot[i].t=254;
198         dot[i].o.vx=dot[i].o.vy=0;
199         if(++bl_r>=MAXINI) bl_r=0;
200         if(++sr_r>=MAXSR) sr_r=0;
201     incldot();
202   }