From bf8258ee306a9649e0cfbf5344f8a533907175d8 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 10 Oct 2011 23:41:19 +0100 Subject: [PATCH] Elements, LIGH, TESC, EMP and DEST thanks to MaksProg --- includes/graphics.h | 4 + includes/powder.h | 29 ++--- src/elements/dest.c | 59 ++++++++++ src/elements/emp.c | 102 +++++++++++++++++ src/elements/ligh.c | 260 ++++++++++++++++++++++++++++++++++++++++++++ src/elements/sprk.c | 36 +++++- src/graphics.c | 119 ++++++++++++++++++++ src/main.c | 1 + src/powder.c | 6 +- 9 files changed, 599 insertions(+), 17 deletions(-) create mode 100644 src/elements/dest.c create mode 100644 src/elements/emp.c create mode 100644 src/elements/ligh.c diff --git a/includes/graphics.h b/includes/graphics.h index 90dd4a7c5..afa09b3b7 100644 --- a/includes/graphics.h +++ b/includes/graphics.h @@ -36,6 +36,8 @@ #endif #endif +extern int emp_decor; + extern unsigned cmode; extern SDL_Surface *sdl_scrn; extern int sdl_scale; @@ -53,6 +55,8 @@ extern unsigned int fire_alpha[CELL*3][CELL*3]; extern pixel *fire_bg; extern pixel *pers_bg; +void draw_other(pixel *vid); + void draw_rgba_image(pixel *vid, unsigned char *data, int x, int y, float a); void *ptif_pack(pixel *src, int w, int h, int *result_size); diff --git a/includes/powder.h b/includes/powder.h index a7cf5fd4f..1e0c425da 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -145,6 +145,10 @@ #define PT_CONV 85 #define PT_CAUS 86 +#define PT_LIGH 87 +#define PT_TESC 88 +#define PT_DEST 89 + #define PT_SPNG 90 #define PT_RIME 91 #define PT_FOG 92 @@ -190,13 +194,9 @@ #define PT_QRTZ 132 #define PT_PQRT 133 -#define PT_SEED 134 -#define PT_MAZE 135 -#define PT_COAG 136 -#define PT_WALL 137 -#define PT_GNAR 138 -#define PT_REPL 139 -#define PT_MYST 140 +#define PT_EMP 134 +#define PT_BREC 135 + #define PT_BOYL 141 #define OLD_PT_WIND 147 @@ -334,6 +334,9 @@ int update_BIZR(UPDATE_FUNC_ARGS); int update_PVOD(UPDATE_FUNC_ARGS); int update_CONV(UPDATE_FUNC_ARGS); int update_CAUS(UPDATE_FUNC_ARGS); +int update_DEST(UPDATE_FUNC_ARGS); +int update_EMP(UPDATE_FUNC_ARGS); +int update_LIGH(UPDATE_FUNC_ARGS); int update_MISC(UPDATE_FUNC_ARGS); int update_legacy_PYRO(UPDATE_FUNC_ARGS); @@ -500,9 +503,9 @@ static const part_type ptypes[PT_NUM] = {"PVOD", PIXPACK(0x792020), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_POWERED, R_TEMP+0.0f +273.15f, 251, "Solid. When activated, destroys entering particles", ST_NONE, TYPE_SOLID, &update_PVOD}, {"CONV", PIXPACK(0x0AAB0A), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 251, "Solid. Converts whatever touches it into its ctype.", ST_NONE, TYPE_SOLID, &update_CONV}, {"CAUS", PIXPACK(0x80FFA0), 2.0f, 0.00f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 1.50f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_GAS, R_TEMP+0.0f +273.15f, 70, "Caustic Gas, acts like Acid", ST_GAS, TYPE_GAS, &update_CAUS}, - /*FREE*/{"34", PIXPACK(0x500050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "34! B34/S34)", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, - /*FREE*/{"LLIF", PIXPACK(0x505050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "Long Life! B345/S5", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, - /*FREE*/{"STAN", PIXPACK(0x5000FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "Stains! B3678/S235678", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, + {"LIGH", PIXPACK(0xFFFFC0), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 0, "More realistic lighting. Set pen size for setting size of the lighting.", ST_SOLID, TYPE_SOLID, &update_LIGH, 0}, + {"TESC", PIXPACK(0x707040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Tesla coil!!!", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW, NULL, 0}, + {"DEST", PIXPACK(0xFF3311), -0.05f, 0.00f * CFDS, 0.95f, 0.95f, -0.1f, 0.4f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 0, 1, 1, 101, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 150, "Makes big destruction.", ST_SOLID, TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_DEST, 0}, {"SPNG", PIXPACK(0xFFBE30), 0.00f, 0.00f * CFDS, 0.00f, 1.00f, 0.00f, 0.0f, 0.00f, 0.000f * CFDS, 0, 20, 0, 1, 30, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 251, "A sponge, absorbs water.", ST_SOLID, TYPE_SOLID, &update_SPNG}, {"RIME", PIXPACK(0xCCCCCC), 0.00f, 0.00f * CFDS, 0.00f, 1.00f, 0.00f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 30, 1, 1, 100, SC_CRACKER2, 243.15f, 100, "Not quite Ice", ST_SOLID, TYPE_SOLID, &update_RIME}, {"FOG", PIXPACK(0xAAAAAA), 0.8f, 0.00f * CFDS, 0.4f, 0.70f, -0.1f, 0.0f, 0.99f, 0.000f * CFDS, 0, 0, 0, 0, 30, 1, 1, 1, SC_CRACKER2, 243.15f, 100, "Not quite Steam", ST_GAS, TYPE_GAS|PROP_LIFE_DEC, &update_FOG}, @@ -547,8 +550,8 @@ static const part_type ptypes[PT_NUM] = {"SING", PIXPACK(0x242424), 0.7f, 0.36f * CFDS, 0.96f, 0.80f, 0.1f, 0.12f, 0.00f, -0.001f * CFDS, 1, 0, 0, 0, 0, 1, 1, 86, SC_NUCLEAR, R_TEMP+0.0f +273.15f, 70, "Singularity", ST_SOLID, TYPE_PART|PROP_LIFE_DEC, &update_SING}, {"QRTZ", PIXPACK(0xAADDDD), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 3, "Quartz, breakable mineral. Conducts but becomes brittle at lower temperatures.", ST_SOLID, TYPE_SOLID|PROP_HOT_GLOW|PROP_LIFE_DEC, &update_QRTZ}, {"PQRT", PIXPACK(0x88BBBB), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.27f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 0, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 3, "Broken quartz.", ST_SOLID, TYPE_PART| PROP_HOT_GLOW, &update_QRTZ}, - /*FREE*/{"SEED", PIXPACK(0xFBEC7D), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "B2/S", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, - /*FREE*/{"MAZE", PIXPACK(0xA8E4A0), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "B3/S12345", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, + {"EMP", PIXPACK(0x66AAFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.0f, 0.0f * CFDS, 0, 0, 0, 0, 3, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 121, "Breaks some working electronics if take spark. For total breaking use more EMP pixels.", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_EMP, 0}, + {"BREL", PIXPACK(0x707060), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.18f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 2, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 211, "Bronen electronic.", ST_SOLID, TYPE_PART|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW, NULL, 0}, /*FREE*/{"COAG", PIXPACK(0x9ACD32), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "B378/S235678", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, /*FREE*/{"WALL", PIXPACK(0x0047AB), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "B45678/S2345", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, /*FREE*/{"GNAR", PIXPACK(0xE5B73B), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "B1/S1", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, @@ -1028,7 +1031,7 @@ int parts_avg(int ci, int ni, int t); void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type, int flags); -int nearest_part(int ci, int t); +int nearest_part(int ci, int t, int max_d); void update_particles_i(pixel *vid, int start, int inc); diff --git a/src/elements/dest.c b/src/elements/dest.c new file mode 100644 index 000000000..fb2a9d76e --- /dev/null +++ b/src/elements/dest.c @@ -0,0 +1,59 @@ +#include + +int update_DEST(UPDATE_FUNC_ARGS) { + int r,rx,ry; + rx=rand()%5-2; + ry=rand()%5-2; + + r = pmap[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + return 0; + if ((r&0xFF)!=PT_DEST && (r&0xFF)!=PT_DMND) + { + if (parts[i].life<=0 || parts[i].life>37) + { + parts[i].life=30+rand()%20; + parts[i].temp+=20000; + pv[y/CELL][x/CELL]+=60.0f; + } + parts[i].temp+=10000; + if ((r&0xFF)==PT_PLUT || (r&0xFF)==PT_DEUT) + { + pv[y/CELL][x/CELL]+=20.0f; + parts[i].temp+=18000; + if (rand()%2==0) + { + part_change_type(r>>8, x+rx, y+ry, PT_NEUT); + float rad = (rand()%128+128)/127.0f; + float a = (rand()%360)*M_PI/180.0f; + parts[r>>8].vx = rad*cosf(a); + parts[r>>8].vy = rad*sinf(a); + parts[r>>8].temp+=40000; + pv[y/CELL][x/CELL]+=10.0f; + parts[i].life-=4; + } + } + if ((r&0xFF)==PT_INSL) + { + create_part(r>>8, x+rx, y+ry, PT_FIRE); + parts[r>>8].temp=10000; + } + else if (rand()%3==0) + { + kill_part(r>>8); + parts[i].life-=4*(ptypes[r&0xFF].properties==TYPE_SOLID?3:1); + if (parts[i].life<=0) + parts[i].life=1; + parts[i].temp+=10000; + } + else + { + parts[r>>8].temp+=10000; + } + int topv=pv[y/CELL][x/CELL]/9+parts[r>>8].temp/900; + if (topv>40.0f) + topv=40.0f; + pv[y/CELL][x/CELL]+=40.0f+topv; + } + return 0; +} diff --git a/src/elements/emp.c b/src/elements/emp.c new file mode 100644 index 000000000..3017bc607 --- /dev/null +++ b/src/elements/emp.c @@ -0,0 +1,102 @@ +#include + +int update_EMP(UPDATE_FUNC_ARGS) { + int r,rx,ry,ok=0,t; + if (parts[i].life) + return 0; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx>8)>=NPART || !r) + continue; + if ((r&0xFF)==PT_SPRK) + { + ok=1; + break; + } + } + if (!ok) + return 0; + parts[i].life=220; + emp_decor+=7; + if (emp_decor>100) + emp_decor=100; + for (r=0; r<=parts_lastActiveIndex; r++) + { + t=parts[r].type; + rx=parts[r].x; + ry=parts[r].y; + if (t==PT_SPRK || (t==PT_SWCH && parts[r].life!=0 && parts[r].life!=10) || (t==PT_WIRE && parts[r].ctype>0)) + { + int is_elec=0; + if ((parts[r].ctype==PT_PSCN || parts[r].ctype==PT_NSCN || parts[r].ctype==PT_PTCT || + parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH) || t==PT_WIRE || t==PT_SWCH) + { + is_elec=1; + if (rand()%100==0) + parts[r].temp+=3000; + if (rand()%80==0) + part_change_type(r, rx, ry, PT_BREC); + else if (rand()%120==0) + part_change_type(r, rx, ry, PT_NTCT); + } + int n,nx,ny; + for (nx=-2; nx<3; nx++) + for (ny=-2; ny<3; ny++) + if (rx+nx>=0 && ry+ny>0 && rx+nx>8)>=NPART || !n) + continue; + /*if ((n&0xFF)==PT_BTRY && rand()%60==0) + { + part_change_type(n>>8, rx+nx, ry+ny, PT_PLSM); + parts[n>>8].life=rand()%100+70; + parts[n>>8].temp+=3000; + }*/ + if (is_elec && ((n&0xFF)==PT_METL || (n&0xFF)==PT_BMTL) && rand()%280==0) + { + parts[n>>8].temp+=3000; + } + if (is_elec && (n&0xFF)==PT_BMTL && rand()%160==0) + { + part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL); + parts[n>>8].temp+=1000; + } + if (is_elec && (n&0xFF)==PT_METL && rand()%300==0) + { + part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL); + } + if ((t==PT_PSCN || t==PT_NSCN) && (n&0xFF)==PT_SWCH && rand()%100==0) + { + part_change_type(n>>8, rx+nx, ry+ny, PT_BREC); + } + if ((t==PT_PSCN || t==PT_NSCN) && (n&0xFF)==PT_SWCH && rand()%100==0) + { + parts[n>>8].temp+=2000; + } + if (is_elec && (n&0xFF)==PT_WIFI && rand()%8==0) + { + parts[n>>8].temp=rand()%10000; + } + if (is_elec && (n&0xFF)==PT_WIFI && rand()%16==0) + { + create_part(n>>8, rx+nx, ry+ny, PT_BREC); + parts[n>>8].temp+=1000; + } + if ((n&0xFF)==PT_ARAY && rand()%60==0) + { + create_part(n>>8, rx+nx, ry+ny, PT_BREC); + parts[n>>8].temp+=1000; + } + if (t==PT_DLAY && rand()%70==0) + { + parts[n>>8].temp+=2000; + } + } + } + } + return 0; +} diff --git a/src/elements/ligh.c b/src/elements/ligh.c new file mode 100644 index 000000000..7ce780a84 --- /dev/null +++ b/src/elements/ligh.c @@ -0,0 +1,260 @@ +#include + +int contact_part(int i, int tp) +{ + int x=parts[i].x, y=parts[i].y; + int r,rx,ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx>8)>=NPART || !r) + continue; + if ((r&0xFF)==tp) + return r>>8; + } + return -1; +} + +void create_line_par(int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2) +{ + if (c==WL_EHOLE || c==WL_ALLOWGAS || c==WL_ALLOWALLELEC || c==WL_ALLOWSOLID || c==WL_ALLOWAIR || c==WL_WALL || c==WL_DESTROYALL || c==WL_ALLOWLIQUID || c==WL_FAN || c==WL_STREAM || c==WL_DETECT || c==WL_EWALL || c==WL_WALLELEC) + return; // this function only for particles, no walls + int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; + float e, de; + if (cp) + { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + e -= 1.0f; + } + } +} + +int update_LIGH(UPDATE_FUNC_ARGS) +{ + /*tmp2: + -1 - part will be removed + 0 - + 1 - + 2 - + */ + int r,rx,ry, multipler, powderful=parts[i].temp*(1+parts[i].life/40)/2; + hv[y/CELL][x/CELL]+=powderful/40; + if (hv[y/CELL][x/CELL]>MAX_TEMP) + hv[y/CELL][x/CELL]=MAX_TEMP; + for (rx=-2; rx<3; rx++) // destruction + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx>8)>=NPART || !r) + continue; + if ((r&0xFF)!=PT_LIGH) + { + if (parts[i].tmp2==3) + { + if ((ptypes[r&0xFF].properties&PROP_CONDUCTS) && parts[r>>8].life==0 && parts[r>>8].ctype!=PT_SPRK) + { + parts[r>>8].ctype = parts[r>>8].type; + part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + parts[r>>8].life = 4; + + pv[y/CELL][x/CELL] += powderful/1200; + parts[r>>8].temp+=powderful/20; + } + else if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_SPRK&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT) + { + pv[y/CELL][x/CELL] += powderful/110; + parts[r>>8].temp+=powderful/1.5; + } + if ((r&0xFF)==PT_DEUT || (r&0xFF)==PT_PLUT) + { + parts[r>>8].temp+=powderful; + pv[y/CELL][x/CELL] +=powderful/35; + if (rand()%3==0) + { + part_change_type(r>>8,x+rx,y+ry,PT_NEUT); + parts[r>>8].vx=rand()%10-5; + parts[r>>8].vy=rand()%10-5; + } + } + } + if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_SPRK&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT) + parts[r>>8].temp+=powderful/16; + else + parts[r>>8].temp+=powderful/70; + } + } + if (parts[i].tmp2==3) + { + //if (rand()&1) + parts[i].tmp2=1; + /*else + parts[i].tmp2=0;*/ + return 1; + } + + if (parts[i].tmp2==-1) + { + kill_part(i); + return 0; + } + if (parts[i].tmp2<=0 || parts[i].life<=1) + { + /*if (parts[i].tmp2!=3 && rand()%3000<400/(parts[i].life+1)) + { + parts[i].tmp2=1; + return 1; + }*/ + if (parts[i].tmp2>0) + parts[i].tmp2=0; + parts[i].tmp2--; + return 1; + } + if (parts[i].tmp2<=-2) + { + killpart(i); + return 0; + } + + float angle, angle2=-1; + + int near=nearest_part(i, -1, parts[i].life*3.5); + if (near!=-1 && (parts[near].type==PT_LIGH || parts[near].type==PT_THDR || parts[near].type==PT_NEUT)) + near=-1; + if (near!=-1) + { + int t=parts[near].type; + + rx=parts[near].x-x; + ry=parts[near].y-y; + if (asin(ry-sqrt(rx*rx+ry*ry))rand()%2000) + { + part_change_type(near, x+rx, y+ry, PT_LIGH); + parts[near].tmp2=3; + parts[near].life=(int)(1.0*parts[i].life/2-1); + parts[near].tmp=parts[i].tmp-180; + parts[near].temp=parts[i].temp; + }*/ + if (t!=PT_TESC) + { + near=contact_part(near, PT_LIGH); + if (near!=-1) + { + parts[near].tmp2=3; + parts[near].life=(int)(1.0*parts[i].life/2-1); + parts[near].tmp=parts[i].tmp-180; + parts[near].temp=parts[i].temp; + } + } + } + else near=-1; + } + + //if (parts[i].tmp2==1/* || near!=-1*/) + angle=parts[i].tmp-30+rand()%60; + if (angle<0) + angle+=360; + if (angle>=360) + angle-=360; + if (parts[i].tmp2==2) + { + angle2=angle+100-rand()%200; + if (angle2<0) + angle2+=360; + if (angle2>=360) + angle-=360; + /*angle=parts[i].tmp-70+rand()%50; + if (angle<0) + angle+=360; + if (angle>=360) + angle-=360;*/ + } + + multipler=parts[i].life*1.5+rand()%((int)(parts[i].life+1)); + rx=cos(angle*M_PI/180)*multipler; + ry=-sin(angle*M_PI/180)*multipler; + create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle, 0); + + if (x+rx>=0 && y+ry>0 && x+rx>8)>=NPART || !r)) + { + parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+60); + parts[r>>8].life=(int)(1.0*parts[i].life/1.5-rand()%2); + parts[r>>8].tmp=angle; + parts[r>>8].temp=parts[i].temp; + } + } + + if (angle2!=-1) + { + multipler=parts[i].life*1.5+rand()%((int)(parts[i].life+1)); + rx=cos(angle2*M_PI/180)*multipler; + ry=-sin(angle2*M_PI/180)*multipler; + create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle2, 0); + + if (x+rx>=0 && y+ry>0 && x+rx>8)>=NPART || !r)) + { + parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+40); + parts[r>>8].life=(int)(1.0*parts[i].life/1.5-rand()%2); + parts[r>>8].tmp=angle; + parts[r>>8].temp=parts[i].temp; + } + } + } + + parts[i].tmp2=-1; + return 1; +} diff --git a/src/elements/sprk.c b/src/elements/sprk.c index bae66e877..45b9acb74 100644 --- a/src/elements/sprk.c +++ b/src/elements/sprk.c @@ -32,7 +32,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { } else if (ct==PT_ETRD&&parts[i].life==1) { - nearp = nearest_part(i, PT_ETRD); + nearp = nearest_part(i, PT_ETRD, -1); if (nearp!=-1&&parts_avg(i, nearp, PT_INSL)!=PT_INSL) { create_line(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), 0, 0, PT_PLSM, 0); @@ -52,6 +52,40 @@ int update_SPRK(UPDATE_FUNC_ARGS) { parts[i].temp = 3500; pv[y/CELL][x/CELL] += 1; } + else if (ct==PT_TESC) // tesla coil code + { + if (parts[i].tmp>300) + parts[i].tmp=300; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx>8)>=NPART || r) + continue; + if (rand()%(parts[i].tmp*parts[i].tmp/20+6)==0) + { + int p=create_part(-1, x+rx*2, y+ry*2, PT_LIGH); + if (p!=-1) + { + parts[p].life=rand()%(2+parts[i].tmp/15)+4+parts[i].tmp/7; + if (parts[i].life>60) + parts[i].life=60; + parts[p].temp=parts[p].life*parts[i].tmp/2.5; + parts[p].tmp2=1; + parts[p].tmp=acos(1.0*rx/sqrt(rx*rx+ry*ry))/M_PI*360; + parts[i].temp-=parts[i].tmp*2+parts[i].temp/5; // slight self-cooling + if (fabs(pv[y/CELL][x/CELL])!=0.0f) + { + if (fabs(pv[y/CELL][x/CELL])<=0.5f) + pv[y/CELL][x/CELL]=0; + else + pv[y/CELL][x/CELL]-=(pv[y/CELL][x/CELL]>0)?0.5:-0.5; + } + } + } + } + } else if (ct==PT_IRON) { for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) diff --git a/src/graphics.c b/src/graphics.c index c038f10db..83c9a5a7f 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -25,6 +25,8 @@ unsigned cmode = CM_FIRE; SDL_Surface *sdl_scrn; int sdl_scale = 1; +int emp_decor = 0; + int sandcolour_r = 0; int sandcolour_g = 0; int sandcolour_b = 0; @@ -1724,6 +1726,26 @@ void xor_rect(pixel *vid, int x, int y, int w, int h) } } +void draw_other(pixel *vid) // EMP effect +{ + int i, j; + if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/50+1; + if (emp_decor>100) emp_decor=100; + if (cmode==CM_NOTHING) // no in nothing mode + return; + if (emp_decor) + for (j=0; j255) r=255; + if (g>255) g=255; + if (b>255) g=255; + drawpixel(vid, i, j, r, g, b, a*255); + } +} + //the main function for drawing the particles void draw_parts(pixel *vid) { @@ -3329,6 +3351,103 @@ void draw_parts(pixel *vid) } } + else if (t==PT_LIGH) + { + uint8 R = 235; + uint8 G = 245; + uint8 B = 255; + float a=0.8*parts[i].life/40; + if (a>0.8) a=0.8; + blendpixel(vid, nx, ny, R, G, B, 255); + if (cmode == CM_FIRE||cmode==CM_BLOB || cmode==CM_FANCY) + { + cr = a*R; + cg = a*G; + cb = a*B; + x = nx/CELL; + y = ny/CELL; + cg += fire_g[y][x]; + if (cg > 255) cg = 255; + fire_g[y][x] = cg; + cb += fire_b[y][x]; + if (cb > 255) cb = 255; + fire_b[y][x] = cb; + cr += fire_r[y][x]; + if (cr > 255) cr = 255; + fire_r[y][x] = cr; + + if (a>0.3) + { + int rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx 255) cg = 255; + fire_g[y+ry][x+rx] = cg; + cb += fire_b[y+ry][x+rx]; + if (cb > 255) cb = 255; + fire_b[y+ry][x+rx] = cb; + cr += fire_r[y+ry][x+rx]; + if (cr > 255) cr = 255; + fire_r[y+ry][x+rx] = cr; + } + } + } + } + else if (t==PT_DEST) + { + cr = PIXR(ptypes[t].pcolors); + cg = PIXG(ptypes[t].pcolors); + cb = PIXB(ptypes[t].pcolors); + if (cmode != CM_CRACK) { + int newx = 0; + float flicker = rand()%30; + float gradv = flicker+(parts[i].life==0?20:1)+parts[i].life*8; + blendpixel(vid, nx, ny, cr, cg, cb, (gradv*4)>255?255:(gradv*4) ); + blendpixel(vid, nx+1, ny, cr, cg, cb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(vid, nx-1, ny, cr, cg, cb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(vid, nx, ny+1, cr, cg, cb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(vid, nx, ny-1, cr, cg, cb, (gradv*2)>255?255:(gradv*2) ); + if (gradv>255) gradv=255; + blendpixel(vid, nx+1, ny-1, cr, cg, cb, gradv); + blendpixel(vid, nx-1, ny-1, cr, cg, cb, gradv); + blendpixel(vid, nx+1, ny+1, cr, cg, cb, gradv); + blendpixel(vid, nx-1, ny+1, cr, cg, cb, gradv); + for (newx = 1; gradv>0.5; newx++) { + addpixel(vid, nx+newx, ny, cr, cg, cb, gradv); + addpixel(vid, nx-newx, ny, cr, cg, cb, gradv); + + addpixel(vid, nx, ny+newx, cr, cg, cb, gradv); + addpixel(vid, nx, ny-newx, cr, cg, cb, gradv); + float div_n=1.2f-0.006*parts[i].life; + if (div_n<1.01f) + div_n=1.01f; + gradv = gradv/div_n; + } + } else { + blendpixel(vid, nx, ny, cr, cg, cb, 255); + } + } + else if (t==PT_EMP && parts[i].life) + { + cr = parts[i].life*1.5; + cg = parts[i].life*1.5; + cb = 200-parts[i].life; + if (cr>255) + cr = 255; + if (cg>255) + cg = 255; + if (cb>255) + cb = 255; + if (cb<=0) + cb = 0; + blendpixel(vid, nx, ny, cr, cg, cb, 255); + } else if (t==PT_GBMB) { if (parts[i].life<=0) {//not yet detonated diff --git a/src/main.c b/src/main.c index f3d655f10..a83ba3eaf 100644 --- a/src/main.c +++ b/src/main.c @@ -1815,6 +1815,7 @@ int main(int argc, char *argv[]) draw_walls(part_vbuf); update_particles(part_vbuf); //update everything draw_parts(part_vbuf); //draw particles + draw_other(part_vbuf); if(sl == WL_GRAV+100 || sr == WL_GRAV+100) draw_grav_zones(part_vbuf); diff --git a/src/powder.c b/src/powder.c index 077a2429d..100ea963f 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1258,9 +1258,9 @@ inline int parts_avg(int ci, int ni,int t) } -int nearest_part(int ci, int t) +int nearest_part(int ci, int t, int max_d) { - int distance = MAX_DISTANCE; + int distance = (max_d!=-1)?max_d:MAX_DISTANCE; int ndistance = 0; int id = -1; int i = 0; @@ -1268,7 +1268,7 @@ int nearest_part(int ci, int t) int cy = (int)parts[ci].y; for (i=0; i<=parts_lastActiveIndex; i++) { - if (parts[i].type==t&&!parts[i].life&&i!=ci) + if ((parts[i].type==t||t==-1)&&!parts[i].life&&i!=ci) { ndistance = abs(cx-parts[i].x)+abs(cy-parts[i].y);// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2)); if (ndistance