diff --git a/src/elements/ligh.c b/src/elements/ligh.c index a17954f60..31f53b3e3 100644 --- a/src/elements/ligh.c +++ b/src/elements/ligh.c @@ -217,15 +217,19 @@ int update_LIGH(UPDATE_FUNC_ARGS) { int t=parts[near].type; float n_angle; // angle to nearest part + float angle_diff; rx=parts[near].x-x; ry=parts[near].y-y; - if (rx*rx+ry*ry!=0) - n_angle = asin(-ry/sqrt(rx*rx+ry*ry)); + if (rx!=0 || ry!=0) + n_angle = atan2f(-ry, rx); 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) + angle_diff = M_PI*2 - angle_diff; + if (parts[i].life<5 || angle_diff4 && 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) { - if(parts[i].tmp<=4) //Prevent Arithmetic errors with zero values - continue; 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; parts[p].tmp2=1; - parts[p].tmp=acos(1.0*rx/sqrt(rx*rx+ry*ry))/M_PI*360; + parts[p].tmp=atan2(-ry, rx)/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) {