diff options
Diffstat (limited to 'src/simulation/elements/SPRK.cpp')
| -rw-r--r-- | src/simulation/elements/SPRK.cpp | 196 |
1 files changed, 130 insertions, 66 deletions
diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index 5d40b3f..9e42025 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -63,23 +63,22 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) parts[i].life = 4; if (ct == PT_WATR) parts[i].life = 64; - if (ct == PT_SLTW) + else if (ct == PT_SLTW) parts[i].life = 54; - if (ct == PT_SWCH) + else if (ct == PT_SWCH) parts[i].life = 14; return 0; } - if (ct==PT_SPRK) + switch(ct) { + case PT_SPRK: sim->kill_part(i); return 1; - } - else if (ct==PT_NTCT || ct==PT_PTCT) - { + case PT_NTCT: + case PT_PTCT: Element_NTCT::update(UPDATE_FUNC_SUBCALL_ARGS); - } - else if (ct==PT_ETRD) - { + break; + case PT_ETRD: if (parts[i].life==1) { nearp = sim->nearest_part(i, PT_ETRD, -1); @@ -94,9 +93,8 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) parts[nearp].ctype = PT_ETRD; } } - } - else if (ct==PT_NBLE) - { + break; + case PT_NBLE: if (parts[i].life<=1&&parts[i].tmp!=1) { parts[i].life = rand()%150+50; @@ -107,9 +105,8 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) parts[i].temp = 3500; sim->pv[y/CELL][x/CELL] += 1; } - } - else if (ct==PT_TESC) // tesla coil code - { + break; + case PT_TESC: if (parts[i].tmp>300) parts[i].tmp=300; for (rx=-1; rx<2; rx++) @@ -141,8 +138,8 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) } } } - } - else if (ct==PT_IRON) { + break; + case PT_IRON: for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) @@ -150,16 +147,18 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (((r&0xFF) == PT_DSTW && 30>(rand()/(RAND_MAX/1000))) || - ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/1000))) || - ((r&0xFF) == PT_WATR && 30>(rand()/(RAND_MAX/1000)))) + if ((r&0xFF)==PT_DSTW || (r&0xFF)==PT_SLTW || (r&0xFF)==PT_WATR) { - if (rand()<RAND_MAX/3) + int rnd = rand()%100; + if (!rnd) sim->part_change_type(r>>8,x+rx,y+ry,PT_O2); - else + else if (3>rnd) sim->part_change_type(r>>8,x+rx,y+ry,PT_H2); } } + break; + default: + break; } for (rx=-2; rx<3; rx++) for (ry=-2; ry<3; ry++) @@ -172,69 +171,134 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) conduct_sprk = 1; // ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed pavg = sim->parts_avg(r>>8, i,PT_INSL); - if ((rt==PT_SWCH||(rt==PT_SPRK&&parts[r>>8].ctype==PT_SWCH)) && pavg!=PT_INSL && parts[i].life<4) // make sparked SWCH turn off correctly + switch (rt) { - if (rt==PT_SWCH&&ct==PT_PSCN&&parts[r>>8].life<10) { - parts[r>>8].life = 10; + case PT_SWCH: + if (pavg!=PT_INSL && parts[i].life<4) + { + if(ct==PT_PSCN && parts[r>>8].life<10) { + parts[r>>8].life = 10; + } + else if (ct==PT_NSCN) + { + parts[r>>8].ctype = PT_NONE; + parts[r>>8].life = 9; + } } - if (ct==PT_NSCN) { - sim->part_change_type(r>>8,x+rx,y+ry,PT_SWCH); - parts[r>>8].ctype = PT_NONE; - parts[r>>8].life = 9; + break; + case PT_SPRK: + if (pavg!=PT_INSL && parts[i].life<4) + { + if (parts[r>>8].ctype==PT_SWCH) + { + if (ct==PT_NSCN) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_SWCH); + parts[r>>8].ctype = PT_NONE; + parts[r>>8].life = 9; + } + } + else if(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT) + if (ct==PT_METL) + { + parts[r>>8].temp = 473.0f; + } } + continue; + case PT_PUMP: + case PT_GPMP: + case PT_HSWC: + case PT_PBCN: + if (parts[i].life<4)// PROP_PTOGGLE, Maybe? We seem to use 2 different methods for handling actived elements, this one seems better. Yes, use this one for new elements, PCLN is different for compatibility with existing saves + { + if (ct==PT_PSCN) parts[r>>8].life = 10; + else if (ct==PT_NSCN && parts[r>>8].life>=10) parts[r>>8].life = 9; + } + continue; + case PT_LCRY: + if (abs(rx)<2&&abs(ry)<2 && parts[i].life<4) + { + if (ct==PT_PSCN && parts[r>>8].tmp == 0) parts[r>>8].tmp = 2; + else if (ct==PT_NSCN && parts[r>>8].tmp == 3) parts[r>>8].tmp = 1; + } + continue; + case PT_PPIP: + if (parts[i].life == 3 && pavg!=PT_INSL) + { + if (ct == PT_NSCN || ct == PT_PSCN || ct == PT_INST) + Element_PPIP::flood_trigger(sim, x+rx, y+ry, ct); + } + continue; + case PT_NTCT: case PT_PTCT: case PT_INWR: + if (ct==PT_METL && pavg!=PT_INSL && parts[i].life<4) + { + parts[r>>8].temp = 473.0f; + if (rt==PT_NTCT||rt==PT_PTCT) + continue; + } + break; } - else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_PUMP||rt==PT_GPMP||rt==PT_HSWC||rt==PT_PBCN) && parts[i].life<4) // PROP_PTOGGLE, Maybe? We seem to use 2 different methods for handling actived elements, this one seems better. Yes, use this one for new elements, PCLN is different for compatibility with existing saves - { - if (ct==PT_PSCN) parts[r>>8].life = 10; - else if (ct==PT_NSCN && parts[r>>8].life>=10) parts[r>>8].life = 9; - } - else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_LCRY&&abs(rx)<2&&abs(ry)<2) && parts[i].life<4) - { - if (ct==PT_PSCN && parts[r>>8].tmp == 0) parts[r>>8].tmp = 2; - else if (ct==PT_NSCN && parts[r>>8].tmp == 3) parts[r>>8].tmp = 1; - } - - if (rt == PT_PPIP && parts[i].life == 3 && pavg!=PT_INSL) - { - if (ct == PT_NSCN || ct == PT_PSCN || ct == PT_INST) - Element_PPIP::flood_trigger(sim, x+rx, y+ry, ct); - } - if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))) && pavg!=PT_INSL && parts[i].life<4) - { - parts[r>>8].temp = 473.0f; - if (rt==PT_NTCT||rt==PT_PTCT) - continue; - } + //the crazy conduct checks if (pavg == PT_INSL) continue; if (!((sim->elements[rt].Properties&PROP_CONDUCTS)||rt==PT_INST||rt==PT_QRTZ)) continue; if (abs(rx)+abs(ry)>=4 &&ct!=PT_SWCH&&rt!=PT_SWCH) continue; - //if (rt==ct && rt!=PT_INST) goto conduct; - if (ct==PT_NTCT && !(rt==PT_PSCN || rt==PT_NTCT || (rt==PT_NSCN&&parts[i].temp>373.0f))) - continue; - else if (ct==PT_PTCT && !(rt==PT_PSCN || rt==PT_PTCT || (rt==PT_NSCN&&parts[i].temp<373.0f))) + if (rt==ct && rt!=PT_INST) goto conduct; + + switch (ct) + { + case PT_INST: + if (rt==PT_NSCN) + goto conduct; continue; - else if (ct==PT_INWR && !(rt==PT_NSCN || rt==PT_INWR || rt==PT_PSCN)) + case PT_SWCH: + if (rt==PT_PSCN||rt==PT_NSCN||rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) + continue; + goto conduct; + case PT_ETRD: + if (rt==PT_METL||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN) + goto conduct; continue; - else if (ct==PT_NSCN && rt==PT_PSCN) + case PT_NTCT: + if (rt==PT_PSCN || (rt==PT_NSCN && parts[i].temp>373.0f)) + goto conduct; continue; - else if (ct==PT_ETRD && !(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN)) + case PT_PTCT: + if (rt==PT_PSCN || (rt==PT_NSCN && parts[i].temp<373.0f)) + goto conduct; continue; - else if (ct==PT_INST && rt!=PT_NSCN) continue; - else if (ct==PT_SWCH && (rt==PT_PSCN||rt==PT_NSCN||rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR)) + } + switch (rt) + { + case PT_QRTZ: + if ((ct==PT_NSCN||ct==PT_METL||ct==PT_PSCN||ct==PT_QRTZ) && (parts[r>>8].temp<173.15||sim->pv[(y+ry)/CELL][(x+rx)/CELL]>8)) + goto conduct; continue; - else if (rt==PT_QRTZ && !((ct==PT_NSCN||ct==PT_METL||ct==PT_PSCN||ct==PT_QRTZ) && (parts[r>>8].temp<173.15||sim->pv[(y+ry)/CELL][(x+rx)/CELL]>8))) + case PT_NTCT: + if (ct==PT_NSCN || (ct==PT_PSCN&&parts[r>>8].temp>373.0f)) + goto conduct; continue; - else if (rt==PT_NTCT && !(ct==PT_NSCN || ct==PT_NTCT || (ct==PT_PSCN&&parts[r>>8].temp>373.0f))) + case PT_PTCT: + if (ct==PT_NSCN || (ct==PT_PSCN&&parts[r>>8].temp<373.0f)) + goto conduct; continue; - else if (rt==PT_PTCT && !(ct==PT_NSCN || ct==PT_PTCT || (ct==PT_PSCN&&parts[r>>8].temp<373.0f))) + case PT_INWR: + if (ct==PT_NSCN || ct==PT_PSCN) + goto conduct; continue; - else if (rt==PT_INWR && !(ct==PT_NSCN || ct==PT_INWR || ct==PT_PSCN)) + case PT_INST: + if (ct==PT_PSCN) + goto conduct; continue; - else if (rt==PT_INST && ct!=PT_PSCN) + case PT_NBLE: + if (parts[r>>8].tmp != 1) + goto conduct; continue; - else if (rt==PT_NBLE && parts[r>>8].tmp == 1) + case PT_PSCN: + if (ct!=PT_NSCN) + goto conduct; continue; + } conduct: if (rt==PT_WATR||rt==PT_SLTW) { if (parts[r>>8].life==0 && parts[i].life<3) |
