diff options
| author | jacksonmj <mj-pt@jacksonmj.co.uk> | 2011-10-11 16:11:20 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-10-13 16:33:20 (GMT) |
| commit | 2f46dca7c1d0016957dfd88831f453f06e080fef (patch) | |
| tree | cab1f08654c1da126e70b4cd9d9f3196ff26d289 /src/elements/emp.c | |
| parent | 107e77a1a13f3dbdbc9703247f52f41716cd8115 (diff) | |
| download | powder-2f46dca7c1d0016957dfd88831f453f06e080fef.zip powder-2f46dca7c1d0016957dfd88831f453f06e080fef.tar.gz | |
Some work on DEST, EMP, LIGH
Change indentation to tabs, respect temperature limit (if a hotter
reaction is required, should raise temp limit instead of ignoring it).
DEST: fix TYPE_SOLID check, and prevent it displacing DMND
EMP: randomise DLAY delay instead of heating it (since DLAY does not melt
and does not transfer heat)
Fix nearest_part so that t=-1 does not include dead particles
Diffstat (limited to 'src/elements/emp.c')
| -rw-r--r-- | src/elements/emp.c | 180 |
1 files changed, 94 insertions, 86 deletions
diff --git a/src/elements/emp.c b/src/elements/emp.c index 3017bc6..96d1a6d 100644 --- a/src/elements/emp.c +++ b/src/elements/emp.c @@ -3,100 +3,108 @@ int update_EMP(UPDATE_FUNC_ARGS) { int r,rx,ry,ok=0,t; if (parts[i].life) - return 0; + return 0; 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)) + 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 ((r&0xFF)==PT_SPRK) - { - ok=1; - break; - } + 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; + 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<XRES && ry+ny<YRES && (rx || ry)) - { - n = pmap[ry+ny][rx+nx]; - if ((n>>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; - } - } - } + 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 = restrict_flt(parts[r].temp+3000.0f, MIN_TEMP, MAX_TEMP); + 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<XRES && ry+ny<YRES && (rx || ry)) + { + n = pmap[ry+ny][rx+nx]; + if (!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; + }*/ + + //Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor + //So not affected by spark on metl, watr etc + if (is_elec) + { + if (((n&0xFF)==PT_METL || (n&0xFF)==PT_BMTL) && rand()%280==0) + { + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP); + } + if ((n&0xFF)==PT_BMTL && rand()%160==0) + { + part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);//TODO: Redundant, was this meant to be BRMT or something? + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); + } + if ((n&0xFF)==PT_METL && rand()%300==0) + { + part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL); + } + if ((n&0xFF)==PT_WIFI && rand()%8==0) + { + //Randomise channel + parts[n>>8].temp = rand()%MAX_TEMP; + } + if ((n&0xFF)==PT_WIFI && rand()%16==0) + { + create_part(n>>8, rx+nx, ry+ny, PT_BREC); + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); + } + } + if ((n&0xFF)==PT_SWCH && rand()%100==0) + { + part_change_type(n>>8, rx+nx, ry+ny, PT_BREC); + } + if ((n&0xFF)==PT_SWCH && rand()%100==0) + { + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+2000.0f, MIN_TEMP, MAX_TEMP); + } + if ((n&0xFF)==PT_ARAY && rand()%60==0) + { + create_part(n>>8, rx+nx, ry+ny, PT_BREC); + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); + } + if (t==PT_DLAY && rand()%70==0) + { + //Randomise delay + parts[n>>8].temp = (rand()%256) + 273.15f; + } + } + } } return 0; } |
