From af21bcd353ae76a15364dfec3bd1c4c568845d39 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Thu, 13 Oct 2011 22:32:23 +0800 Subject: [PATCH] Some changes to LIGH/EMP/TESC based on changes in MaksProg's mod v0.3 Weaker and shorter EMP flash. TESC has correct tmp value when created with replace mode. LIGH harms STKM. Gravity affects LIGH in create_part if p==-2, instead of in update_LIGH, so that TESC lightning is not affected by gravity. --- src/elements/emp.c | 6 +- src/elements/ligh.c | 139 +++++++++++++++++++++----------------------- src/elements/sprk.c | 4 +- src/graphics.c | 63 ++++++++++++++------ src/powder.c | 68 +++++++++++----------- 5 files changed, 150 insertions(+), 130 deletions(-) diff --git a/src/elements/emp.c b/src/elements/emp.c index b90fa86b4..a4c606761 100644 --- a/src/elements/emp.c +++ b/src/elements/emp.c @@ -20,9 +20,9 @@ int update_EMP(UPDATE_FUNC_ARGS) { if (!ok) return 0; parts[i].life=220; - emp_decor+=7; - if (emp_decor>100) - emp_decor=100; + emp_decor+=3; + if (emp_decor>40) + emp_decor=40; for (r=0; r<=parts_lastActiveIndex; r++) { t=parts[r].type; diff --git a/src/elements/ligh.c b/src/elements/ligh.c index 1d38a6d40..f2b8a5176 100644 --- a/src/elements/ligh.c +++ b/src/elements/ligh.c @@ -2,6 +2,29 @@ #define LIGHTING_POWER 0.65 +int LIGH_nearest_part(int ci, int max_d) +{ + int distance = (max_d!=-1)?max_d:MAX_DISTANCE; + int ndistance = 0; + int id = -1; + int i = 0; + int cx = (int)parts[ci].x; + int cy = (int)parts[ci].y; + for (i=0; i<=parts_lastActiveIndex; i++) + { + if (parts[i].type && !parts[i].life && i!=ci && parts[i].type!=PT_LIGH && parts[i].type!=PT_THDR && parts[i].type!=PT_NEUT && parts[i].type!=PT_PHOT) + { + 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 (ndistanceMAX_TEMP) - hv[y/CELL][x/CELL]=MAX_TEMP; - for (rx=-2; rx<3; rx++) // destruction + update_PYRO(UPDATE_FUNC_SUBCALL_ARGS); + if (aheat_enable) + { + hv[y/CELL][x/CELL]+=powderful/50; + if (hv[y/CELL][x/CELL]>MAX_TEMP) + hv[y/CELL][x/CELL]=MAX_TEMP; + } + + for (rx=-2; rx<3; rx++) for (ry=-2; ry<3; ry++) if (x+rx>=0 && y+ry>=0 && x+rx>8].life==0) { - parts[r>>8].ctype = parts[r>>8].type; create_part(r>>8,x+rx,y+ry,PT_SPRK); - parts[r>>8].life = 4; - - pv[y/CELL][x/CELL] += powderful/1200; - if (ptypes[r&0xFF].hconduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/20, MIN_TEMP, MAX_TEMP); } - 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/400; + if (ptypes[r&0xFF].hconduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/1.5, MIN_TEMP, MAX_TEMP); + } + if ((r&0xFF)==PT_DEUT || (r&0xFF)==PT_PLUT) // start nuclear reactions + { + parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful, MIN_TEMP, MAX_TEMP); + pv[y/CELL][x/CELL] +=powderful/35; + if (rand()%3==0) { - pv[y/CELL][x/CELL] += powderful/110; - if (ptypes[r&0xFF].hconduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/1.5, MIN_TEMP, MAX_TEMP); + part_change_type(r>>8,x+rx,y+ry,PT_NEUT); + parts[r>>8].life = rand()%480+480; + parts[r>>8].vx=rand()%10-5; + parts[r>>8].vy=rand()%10-5; } - if ((r&0xFF)==PT_DEUT || (r&0xFF)==PT_PLUT) - { - parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful, MIN_TEMP, MAX_TEMP); - 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].life = rand()%480+480; - parts[r>>8].vx=rand()%10-5; - parts[r>>8].vy=rand()%10-5; - } + } + if ((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL) // ignite coal + { + if (parts[r>>8].life>100) { + parts[r>>8].life = 99; } } if (ptypes[r&0xFF].hconduct) + parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/10, MIN_TEMP, MAX_TEMP); + if ((r&0xFF)==PT_STKM || (r&0xFF)==PT_STKM2) { - 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 = restrict_flt(parts[r>>8].temp+powderful/16, MIN_TEMP, MAX_TEMP); - else - parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/70, MIN_TEMP, MAX_TEMP); + parts[r>>8].life-=powderful/100; } } } if (parts[i].tmp2==3) { - //if (rand()&1) - parts[i].tmp2=1; - /*else - parts[i].tmp2=0;*/ + parts[i].tmp2=0; return 1; } @@ -159,11 +181,6 @@ int update_LIGH(UPDATE_FUNC_ARGS) } 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--; @@ -177,27 +194,23 @@ int update_LIGH(UPDATE_FUNC_ARGS) 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; + int near = LIGH_nearest_part(i, parts[i].life*2.5); if (near!=-1) { int t=parts[near].type; - + float n_angle; // angle to nearest part 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); @@ -214,35 +227,19 @@ int update_LIGH(UPDATE_FUNC_ARGS) } //if (parts[i].tmp2==1/* || near!=-1*/) - switch (gravityMode) - { - default: - case 0: - angle = parts[i].tmp-30+rand()%60; - break; - case 1: - angle = rand()%360; - break; - case 2: - angle = atan2(x-XCNTR, y-YCNTR)*(180.0f/M_PI)+90; - } //angle=0;//parts[i].tmp-30+rand()%60; + angle = parts[i].tmp-30+rand()%60; if (angle<0) angle+=360; if (angle>=360) angle-=360; - if (parts[i].tmp2==2) + if (parts[i].tmp2==2 && near==-1) { 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)); @@ -253,8 +250,6 @@ int update_LIGH(UPDATE_FUNC_ARGS) if (x+rx>=0 && y+ry>=0 && x+rx>8, x+rx, y+ry, PT_LIGH);*/ if ((r&0xFF)==PT_LIGH) { parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+60); @@ -274,9 +269,7 @@ int update_LIGH(UPDATE_FUNC_ARGS) if (x+rx>=0 && y+ry>0 && x+rx>8, x+rx, y+ry, PT_LIGH);*/ - if ((r&0xFF)==PT_LIGH && !((r>>8)>=NPART || !r)) + if ((r&0xFF)==PT_LIGH) { 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); diff --git a/src/elements/sprk.c b/src/elements/sprk.c index f8f64f892..efab62e47 100644 --- a/src/elements/sprk.c +++ b/src/elements/sprk.c @@ -61,7 +61,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { if (x+rx>=0 && y+ry>0 && x+rx>8)>=NPART || r) + if (r) continue; if (rand()%(parts[i].tmp*parts[i].tmp/20+6)==0) { @@ -70,7 +70,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { { if(parts[i].tmp<=4) //Prevent Arithmetic errors with zero values continue; - parts[p].life=rand()%(2+parts[i].tmp/15)+4+parts[i].tmp/7; + parts[p].life=rand()%(2+parts[i].tmp/15)+parts[i].tmp/7; if (parts[i].life>60) parts[i].life=60; parts[p].temp=parts[p].life*parts[i].tmp/2.5; diff --git a/src/graphics.c b/src/graphics.c index 83c9a5a7f..1f10b1177 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1728,22 +1728,24 @@ 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; + int i, j; + if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/25+2; + if (emp_decor>40) emp_decor=40; 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); - } + return; + if (emp_decor) + { + int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255; + int a=(1.0*emp_decor/110)*255; + if (r>255) r=255; + if (g>255) g=255; + if (b>255) g=255; + for (j=0; j0.8) a=0.8; + float a; + if (parts[i].tmp2!=3) + { + a=0.8*parts[i].life/40; + if (a>0.8) a=0.8; + } + else + { + a=1.0; + } blendpixel(vid, nx, ny, R, G, B, 255); if (cmode == CM_FIRE||cmode==CM_BLOB || cmode==CM_FANCY) { @@ -3398,6 +3408,25 @@ void draw_parts(pixel *vid) } } } + else if (cmode!=CM_NOTHING) + { + blendpixel(vid, x, y, R, G, B, 255); + + blendpixel(vid, x, y-1, R, G, B, 150); + blendpixel(vid, x-1, y, R, G, B, 150); + blendpixel(vid, x+1, y, R, G, B, 150); + blendpixel(vid, x, y+1, R, G, B, 150); + + blendpixel(vid, x-1, y-1, R, G, B, 100); + blendpixel(vid, x+1, y-1, R, G, B, 100); + blendpixel(vid, x+1, y+1, R, G, B, 100); + blendpixel(vid, x-1, y+1, R, G, B, 100); + + blendpixel(vid, x, y-2, R, G, B, 50); + blendpixel(vid, x-2, y, R, G, B, 50); + blendpixel(vid, x+2, y, R, G, B, 50); + blendpixel(vid, x, y+2, R, G, B, 50); + } } else if (t==PT_DEST) { diff --git a/src/powder.c b/src/powder.c index 88d26a0cb..0633f75e2 100644 --- a/src/powder.c +++ b/src/powder.c @@ -845,11 +845,21 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a parts[i].tmp = 0; parts[i].tmp2 = 0; } - if (t==PT_LIGH) + if (t==PT_LIGH && p==-2) { - parts[i].tmp = 270; - if (p==-2) - parts[i].tmp2 = 4; + switch (gravityMode) + { + default: + case 0: + parts[i].tmp= 270+rand()%40-20; + break; + case 1: + parts[i].tmp = rand()%360; + break; + case 2: + parts[i].tmp = atan2(x-XCNTR, y-YCNTR)*(180.0f/M_PI)+90; + } + parts[i].tmp2 = 4; } if (t==PT_SOAP) { @@ -2804,6 +2814,19 @@ int flood_water(int x, int y, int i, int originaly, int check) return 1; } +//wrapper around create_part to create TESC with correct tmp value +int create_part_add_props(int p, int x, int y, int tv, int rx, int ry) +{ + p=create_part(p, x, y, tv); + if (tv==PT_TESC) + { + parts[p].tmp=rx*4+ry*4+7; + if (parts[p].tmp>300) + parts[p].tmp=300; + } + return p; +} + //this creates particles from a brush, don't use if you want to create one particle int create_parts(int x, int y, int rx, int ry, int c, int flags) { @@ -2843,13 +2866,13 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags) { if (lighting_recreate>0 && rx+ry>0) return 0; - int p=create_part(-2, x, y, c); + p=create_part(-2, x, y, c); if (p!=-1) { parts[p].life=rx+ry; if (parts[p].life>55) parts[p].life=55; - parts[p].temp=parts[p].life*150; // temperatute of the lighting shows the power of the lighting + parts[p].temp=parts[p].life*150; // temperature of the lighting shows the power of the lighting lighting_recreate+=parts[p].life/2+1; return 1; } @@ -2970,7 +2993,7 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags) { delete_part(x, y, 0); if (c!=0) - create_part(-2, x, y, c); + create_part_add_props(-2, x, y, c, rx, ry); } } } @@ -2987,48 +3010,23 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags) { delete_part(x+i, y+j, 0); if (c!=0) - create_part(-2, x+i, y+j, c); + create_part_add_props(-2, x+i, y+j, c, rx, ry); } } return 1; } //else, no special modes, draw element like normal. - if(c==PT_TESC) - { - if (rx==0&&ry==0)//workaround for 1pixel brush/floodfill crashing. todo: find a better fix later. - { - if (create_part(-2, x, y, c)==-1) - f = 1; - } - else - for (j=-ry; j<=ry; j++) - for (i=-rx; i<=rx; i++) - if (InCurrentBrush(i ,j ,rx ,ry)) - { - p = create_part(-2, x+i, y+j, c); - if (p==-1) - { - f = 1; - } else { - parts[p].tmp=rx*4+ry*4+7; - if (parts[p].tmp>300) - parts[p].tmp=300; - } - } - return !f; - } - if (rx==0&&ry==0)//workaround for 1pixel brush/floodfill crashing. todo: find a better fix later. { - if (create_part(-2, x, y, c)==-1) + if (create_part_add_props(-2, x, y, c, rx, ry)==-1) f = 1; } else for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) if (InCurrentBrush(i ,j ,rx ,ry)) - if (create_part(-2, x+i, y+j, c)==-1) + if (create_part_add_props(-2, x+i, y+j, c, rx, ry)==-1) f = 1; return !f; }