diff options
| author | jacksonmj <mj-pt@jacksonmj.co.uk> | 2011-10-13 14:32:23 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-10-13 16:33:22 (GMT) |
| commit | af21bcd353ae76a15364dfec3bd1c4c568845d39 (patch) | |
| tree | 69b8a613db33cb532d8b9946e90b7e70baffc850 /src/elements | |
| parent | 9dc154f1f1667bb7fc73aca6bd5d6fad7c381a0e (diff) | |
| download | powder-af21bcd353ae76a15364dfec3bd1c4c568845d39.zip powder-af21bcd353ae76a15364dfec3bd1c4c568845d39.tar.gz | |
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.
Diffstat (limited to 'src/elements')
| -rw-r--r-- | src/elements/emp.c | 6 | ||||
| -rw-r--r-- | src/elements/ligh.c | 139 | ||||
| -rw-r--r-- | src/elements/sprk.c | 4 |
3 files changed, 71 insertions, 78 deletions
diff --git a/src/elements/emp.c b/src/elements/emp.c index b90fa86..a4c6067 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 1d38a6d..f2b8a51 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 (ndistance<distance) + { + distance = ndistance; + id = i; + } + } + } + return id; +} + int contact_part(int i, int tp) { 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; - 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 + 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<XRES && y+ry<YRES && (rx || ry)) { @@ -105,50 +133,44 @@ int update_LIGH(UPDATE_FUNC_ARGS) continue; 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) { - 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))<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); - /*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) { 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<XRES && y+ry<YRES && (rx || ry)) { 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) { 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)) { 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 && !((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 f8f64f8..efab62e 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<XRES && y+ry<YRES && (rx || ry)) { r = pmap[y+ry][x+rx]; - if ((r>>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; |
