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.
This commit is contained in:
jacksonmj 2011-10-13 22:32:23 +08:00 committed by Simon Robertshaw
parent 9dc154f1f1
commit af21bcd353
5 changed files with 150 additions and 130 deletions

View File

@ -20,9 +20,9 @@ int update_EMP(UPDATE_FUNC_ARGS) {
if (!ok) if (!ok)
return 0; return 0;
parts[i].life=220; parts[i].life=220;
emp_decor+=7; emp_decor+=3;
if (emp_decor>100) if (emp_decor>40)
emp_decor=100; emp_decor=40;
for (r=0; r<=parts_lastActiveIndex; r++) for (r=0; r<=parts_lastActiveIndex; r++)
{ {
t=parts[r].type; t=parts[r].type;

View File

@ -2,6 +2,29 @@
#define LIGHTING_POWER 0.65 #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 (ndistance<distance)
{
distance = ndistance;
id = i;
}
}
}
return id;
}
int contact_part(int i, int tp) int contact_part(int i, int tp)
{ {
int x=parts[i].x, y=parts[i].y; int x=parts[i].x, y=parts[i].y;
@ -93,10 +116,15 @@ int update_LIGH(UPDATE_FUNC_ARGS)
* *
*/ */
int r,rx,ry, multipler, powderful=parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER; int r,rx,ry, multipler, powderful=parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER;
hv[y/CELL][x/CELL]+=powderful/40; update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
if (aheat_enable)
{
hv[y/CELL][x/CELL]+=powderful/50;
if (hv[y/CELL][x/CELL]>MAX_TEMP) if (hv[y/CELL][x/CELL]>MAX_TEMP)
hv[y/CELL][x/CELL]=MAX_TEMP; hv[y/CELL][x/CELL]=MAX_TEMP;
for (rx=-2; rx<3; rx++) // destruction }
for (rx=-2; rx<3; rx++)
for (ry=-2; ry<3; ry++) for (ry=-2; ry<3; ry++)
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{ {
@ -105,23 +133,16 @@ int update_LIGH(UPDATE_FUNC_ARGS)
continue; continue;
if ((r&0xFF)!=PT_LIGH && (r&0xFF)!=PT_TESC) if ((r&0xFF)!=PT_LIGH && (r&0xFF)!=PT_TESC)
{ {
if (parts[i].tmp2==3) if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT)
{ {
if ((ptypes[r&0xFF].properties&PROP_CONDUCTS) && parts[r>>8].life==0) if ((ptypes[r&0xFF].properties&PROP_CONDUCTS) && parts[r>>8].life==0)
{ {
parts[r>>8].ctype = parts[r>>8].type;
create_part(r>>8,x+rx,y+ry,PT_SPRK); 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;
{
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); 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) 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); parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful, MIN_TEMP, MAX_TEMP);
pv[y/CELL][x/CELL] +=powderful/35; pv[y/CELL][x/CELL] +=powderful/35;
@ -133,22 +154,23 @@ int update_LIGH(UPDATE_FUNC_ARGS)
parts[r>>8].vy=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) 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].life-=powderful/100;
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);
} }
} }
} }
if (parts[i].tmp2==3) if (parts[i].tmp2==3)
{ {
//if (rand()&1) parts[i].tmp2=0;
parts[i].tmp2=1;
/*else
parts[i].tmp2=0;*/
return 1; 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<=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) if (parts[i].tmp2>0)
parts[i].tmp2=0; parts[i].tmp2=0;
parts[i].tmp2--; parts[i].tmp2--;
@ -177,27 +194,23 @@ int update_LIGH(UPDATE_FUNC_ARGS)
float angle, angle2=-1; float angle, angle2=-1;
int near=nearest_part(i, -1, parts[i].life*3.5); int near = LIGH_nearest_part(i, parts[i].life*2.5);
if (near!=-1 && (parts[near].type==PT_LIGH || parts[near].type==PT_THDR || parts[near].type==PT_NEUT))
near=-1;
if (near!=-1) if (near!=-1)
{ {
int t=parts[near].type; int t=parts[near].type;
float n_angle; // angle to nearest part
rx=parts[near].x-x; rx=parts[near].x-x;
ry=parts[near].y-y; ry=parts[near].y-y;
if (asin(ry-sqrt(rx*rx+ry*ry))<M_PI*2/3) if (rx*rx+ry*ry!=0)
n_angle = asin(-ry/sqrt(rx*rx+ry*ry));
else
n_angle = 0;
if (n_angle<0)
n_angle+=M_PI*2;
if (parts[i].life<5 || fabs(n_angle-parts[i].tmp*M_PI/180)<M_PI*0.8) // lightning strike
{ {
create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0); create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0);
/*if (t!=PT_DMND && t!=PT_UDMT && t!=PT_TESC && parts[i].temp-300>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) if (t!=PT_TESC)
{ {
near=contact_part(near, PT_LIGH); near=contact_part(near, PT_LIGH);
@ -214,35 +227,19 @@ int update_LIGH(UPDATE_FUNC_ARGS)
} }
//if (parts[i].tmp2==1/* || near!=-1*/) //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=0;//parts[i].tmp-30+rand()%60;
angle = parts[i].tmp-30+rand()%60;
if (angle<0) if (angle<0)
angle+=360; angle+=360;
if (angle>=360) if (angle>=360)
angle-=360; angle-=360;
if (parts[i].tmp2==2) if (parts[i].tmp2==2 && near==-1)
{ {
angle2=angle+100-rand()%200; angle2=angle+100-rand()%200;
if (angle2<0) if (angle2<0)
angle2+=360; angle2+=360;
if (angle2>=360) if (angle2>=360)
angle-=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)); 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<XRES && y+ry<YRES && (rx || ry)) if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
/*if ((r&0xFF)!=PT_LIGH && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_UDMT && (r&0xFF)!=PT_TESC)
part_change_type(r>>8, x+rx, y+ry, PT_LIGH);*/
if ((r&0xFF)==PT_LIGH) if ((r&0xFF)==PT_LIGH)
{ {
parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+60); 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<XRES && y+ry<YRES && (rx || ry)) if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
/*if ((r&0xFF)!=PT_LIGH && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_UDMT && (r&0xFF)!=PT_TESC) if ((r&0xFF)==PT_LIGH)
part_change_type(r>>8, x+rx, y+ry, PT_LIGH);*/
if ((r&0xFF)==PT_LIGH && !((r>>8)>=NPART || !r))
{ {
parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+40); 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].life=(int)(1.0*parts[i].life/1.5-rand()%2);

View File

@ -61,7 +61,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if ((r>>8)>=NPART || r) if (r)
continue; continue;
if (rand()%(parts[i].tmp*parts[i].tmp/20+6)==0) 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 if(parts[i].tmp<=4) //Prevent Arithmetic errors with zero values
continue; 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) if (parts[i].life>60)
parts[i].life=60; parts[i].life=60;
parts[p].temp=parts[p].life*parts[i].tmp/2.5; parts[p].temp=parts[p].life*parts[i].tmp/2.5;

View File

@ -1729,20 +1729,22 @@ void xor_rect(pixel *vid, int x, int y, int w, int h)
void draw_other(pixel *vid) // EMP effect void draw_other(pixel *vid) // EMP effect
{ {
int i, j; int i, j;
if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/50+1; if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/25+2;
if (emp_decor>100) emp_decor=100; if (emp_decor>40) emp_decor=40;
if (cmode==CM_NOTHING) // no in nothing mode if (cmode==CM_NOTHING) // no in nothing mode
return; return;
if (emp_decor) if (emp_decor)
for (j=0; j<YRES; j++)
for (i=0; i<XRES; i++)
{ {
int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255; int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255;
float a=1.0*emp_decor/110; int a=(1.0*emp_decor/110)*255;
if (r>255) r=255; if (r>255) r=255;
if (g>255) g=255; if (g>255) g=255;
if (b>255) g=255; if (b>255) g=255;
drawpixel(vid, i, j, r, g, b, a*255); for (j=0; j<YRES; j++)
for (i=0; i<XRES; i++)
{
drawpixel(vid, i, j, r, g, b, a);
}
} }
} }
@ -3356,8 +3358,16 @@ void draw_parts(pixel *vid)
uint8 R = 235; uint8 R = 235;
uint8 G = 245; uint8 G = 245;
uint8 B = 255; uint8 B = 255;
float a=0.8*parts[i].life/40; float a;
if (parts[i].tmp2!=3)
{
a=0.8*parts[i].life/40;
if (a>0.8) a=0.8; if (a>0.8) a=0.8;
}
else
{
a=1.0;
}
blendpixel(vid, nx, ny, R, G, B, 255); blendpixel(vid, nx, ny, R, G, B, 255);
if (cmode == CM_FIRE||cmode==CM_BLOB || cmode==CM_FANCY) 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) else if (t==PT_DEST)
{ {

View File

@ -845,10 +845,20 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
parts[i].tmp = 0; parts[i].tmp = 0;
parts[i].tmp2 = 0; parts[i].tmp2 = 0;
} }
if (t==PT_LIGH) if (t==PT_LIGH && p==-2)
{ {
parts[i].tmp = 270; switch (gravityMode)
if (p==-2) {
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; parts[i].tmp2 = 4;
} }
if (t==PT_SOAP) if (t==PT_SOAP)
@ -2804,6 +2814,19 @@ int flood_water(int x, int y, int i, int originaly, int check)
return 1; 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 //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) 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) if (lighting_recreate>0 && rx+ry>0)
return 0; return 0;
int p=create_part(-2, x, y, c); p=create_part(-2, x, y, c);
if (p!=-1) if (p!=-1)
{ {
parts[p].life=rx+ry; parts[p].life=rx+ry;
if (parts[p].life>55) if (parts[p].life>55)
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; lighting_recreate+=parts[p].life/2+1;
return 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); delete_part(x, y, 0);
if (c!=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); delete_part(x+i, y+j, 0);
if (c!=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; return 1;
} }
//else, no special modes, draw element like normal. //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 (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; f = 1;
} }
else else
for (j=-ry; j<=ry; j++) for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++) for (i=-rx; i<=rx; i++)
if (InCurrentBrush(i ,j ,rx ,ry)) if (InCurrentBrush(i ,j ,rx ,ry))
{ if (create_part_add_props(-2, x+i, y+j, c, rx, ry)==-1)
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)
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)
f = 1; f = 1;
return !f; return !f;
} }