/* Copyright (C) 1996-1997 Aleksey Volynskov
* Copyright (C) 2011 Rambo
* Copyright (C) 2020 SovietPony
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License ONLY.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "glob.h"
#include
#include
#include "view.h"
#include "dots.h"
#include "misc.h"
#define MAXINI 50
#define MAXSR 20
#define BL_XV 4
#define BL_YV 4
#define BL_MINT 10
#define BL_MAXT 14
#define SP_V 2
#define SP_MINT 5
#define SP_MAXT 7
typedef struct{
int xv,yv;
byte c,t;
}init_t;
dot_t dot[MAXDOT];
static init_t bl_ini[MAXINI],sp_ini[MAXINI];
static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
static int ldot;
void DOT_init(void) {
int i;
for(i=0;i=MAXDOT) ldot=0;
}
void DOT_alloc(void) {
int i;
for(i=0;i2) {
if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
else dot[i].o.vx=Z_sign(dot[i].o.vx);
if(rand()%yv==0) dot[i].o.vx*=2;
dot[i].o.yv=yv-2;
}
}
dot[i].o.xv=0;
if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
}
if(s&Z_HITWALL) {
dot[i].o.vx=Z_sign(xv)*2;
dot[i].o.yv=Z_sign(dot[i].o.yv);
if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
}
if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
}
z_dot=0;
}
void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
int i;
if(!Z_canfit(x,y,0,1)) return;
i=ldot;
dot[i].o.x=x;dot[i].o.y=y;
dot[i].o.xv=xv;dot[i].o.yv=yv;
dot[i].c=c;dot[i].t=t;
dot[i].o.vx=dot[i].o.vy=0;
incldot();
}
void DOT_blood(int x,int y,int xv,int yv,int n) {
int i,k,dx,dy;
for(k=n;k;--k) {
dx=x+sxr[sr_r];dy=y+syr[sr_r];
if(!Z_canfit(x,y,0,1)) continue;
i=ldot;
dot[i].o.x=dx;dot[i].o.y=dy;
dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
dot[i].c=bl_ini[bl_r].c;
dot[i].t=255;
dot[i].o.vx=dot[i].o.vy=0;
if(++bl_r>=MAXINI) bl_r=0;
if(++sr_r>=MAXSR) sr_r=0;
incldot();
}
}
void DOT_spark(int x,int y,int xv,int yv,int n) {
int i,k,dx,dy;
for(k=n;k;--k) {
dx=x+sxr[sr_r];dy=y+syr[sr_r];
if(!Z_canfit(x,y,0,1)) continue;
i=ldot;
dot[i].o.x=dx;dot[i].o.y=dy;
dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
dot[i].c=sp_ini[sp_r].c;
dot[i].t=sp_ini[sp_r].t;
dot[i].o.vx=dot[i].o.vy=0;
if(++sp_r>=MAXINI) sp_r=0;
if(++sr_r>=MAXSR) sr_r=0;
incldot();
}
}
void DOT_water(int x,int y,int xv,int yv,int n,int c) {
int i,k,dx,dy;
static byte ct[3]={0xC0,0x70,0xB0};
if(c<0 || c>=3) return;
c=ct[c];
for(k=n;k;--k) {
dx=x+sxr[sr_r];dy=y+syr[sr_r];
if(!Z_canfit(x,y,0,1)) continue;
i=ldot;
dot[i].o.x=dx;dot[i].o.y=dy;
dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
dot[i].c=bl_ini[bl_r].c-0xB0+c;
dot[i].t=254;
dot[i].o.vx=dot[i].o.vy=0;
if(++bl_r>=MAXINI) bl_r=0;
if(++sr_r>=MAXSR) sr_r=0;
incldot();
}
}