From 5e1c7d7932aead512549bacb6fa8847da2530e9f Mon Sep 17 00:00:00 2001 From: cracker64 Date: Sun, 3 Mar 2013 16:30:34 -0500 Subject: [PATCH] Some better comments in SPRK, renamed rt and ct. --- src/simulation/elements/SPRK.cpp | 107 ++++++++++++++++--------------- 1 file changed, 56 insertions(+), 51 deletions(-) diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index 3520b96b1..3939bd8af 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -49,7 +49,7 @@ Element_SPRK::Element_SPRK() //#TPT-Directive ElementHeader Element_SPRK static int update(UPDATE_FUNC_ARGS) int Element_SPRK::update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt, conduct_sprk, nearp, pavg, ct = parts[i].ctype; + int r, rx, ry, rt, conduct_sprk, nearp, pavg, ct = parts[i].ctype, sender, receiver; Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); if (parts[i].life<=0) @@ -69,6 +69,7 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) parts[i].life = 14; return 0; } + //Some functions of SPRK based on ctype (what it is on) switch(ct) { case PT_SPRK: @@ -167,19 +168,21 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - rt = r&0xFF; - conduct_sprk = 1; -// ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed + receiver = r&0xFF; + sender = ct; pavg = sim->parts_avg(r>>8, i,PT_INSL); - switch (rt) + //receiver is the element SPRK is trying to conduct to + //sender is the element the SPRK is on + //First, some checks usually for (de)activation of elements + switch (receiver) { case PT_SWCH: if (pavg!=PT_INSL && parts[i].life<4) { - if(ct==PT_PSCN && parts[r>>8].life<10) { + if(sender==PT_PSCN && parts[r>>8].life<10) { parts[r>>8].life = 10; } - else if (ct==PT_NSCN) + else if (sender==PT_NSCN) { parts[r>>8].ctype = PT_NONE; parts[r>>8].life = 9; @@ -191,7 +194,7 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) { if (parts[r>>8].ctype==PT_SWCH) { - if (ct==PT_NSCN) + if (sender==PT_NSCN) { sim->part_change_type(r>>8,x+rx,y+ry,PT_SWCH); parts[r>>8].ctype = PT_NONE; @@ -199,99 +202,99 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) } } else if(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT) - if (ct==PT_METL) + if (sender==PT_METL) { parts[r>>8].temp = 473.0f; } } continue; - case PT_PUMP: - case PT_GPMP: - case PT_HSWC: - case PT_PBCN: + 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; + if (sender==PT_PSCN) parts[r>>8].life = 10; + else if (sender==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; + if (sender==PT_PSCN && parts[r>>8].tmp == 0) parts[r>>8].tmp = 2; + else if (sender==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); + if (sender == PT_NSCN || sender == PT_PSCN || sender == PT_INST) + Element_PPIP::flood_trigger(sim, x+rx, y+ry, sender); } continue; case PT_NTCT: case PT_PTCT: case PT_INWR: - if (ct==PT_METL && pavg!=PT_INSL && parts[i].life<4) + if (sender==PT_METL && pavg!=PT_INSL && parts[i].life<4) { parts[r>>8].temp = 473.0f; - if (rt==PT_NTCT||rt==PT_PTCT) + if (receiver==PT_NTCT||receiver==PT_PTCT) continue; } break; } - //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; - switch (ct) + if (pavg == PT_INSL) continue; //Insulation blocks everything past here + if (!((sim->elements[receiver].Properties&PROP_CONDUCTS)||receiver==PT_INST||receiver==PT_QRTZ)) continue; //Stop non-conducting recievers, allow INST and QRTZ as special cases + if (abs(rx)+abs(ry)>=4 &&sender!=PT_SWCH&&receiver!=PT_SWCH) continue; //Only switch conducts really far + if (receiver==sender && receiver!=PT_INST) goto conduct; //Everything conducts to itself, except INST. + + //Sender cases, where elements can have specific outputs + switch (sender) { case PT_INST: - if (rt==PT_NSCN) + if (receiver==PT_NSCN) goto conduct; continue; 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) + if (receiver==PT_PSCN||receiver==PT_NSCN||receiver==PT_WATR||receiver==PT_SLTW||receiver==PT_NTCT||receiver==PT_PTCT||receiver==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) + if (receiver==PT_METL||receiver==PT_BMTL||receiver==PT_BRMT||receiver==PT_LRBD||receiver==PT_RBDM||receiver==PT_PSCN||receiver==PT_NSCN) goto conduct; continue; case PT_NTCT: - if (rt==PT_PSCN || (rt==PT_NSCN && parts[i].temp>373.0f)) + if (receiver==PT_PSCN || (receiver==PT_NSCN && parts[i].temp>373.0f)) goto conduct; continue; case PT_PTCT: - if (rt==PT_PSCN || (rt==PT_NSCN && parts[i].temp<373.0f)) + if (receiver==PT_PSCN || (receiver==PT_NSCN && parts[i].temp<373.0f)) goto conduct; continue; case PT_INWR: - if (rt==PT_NSCN || rt==PT_PSCN) + if (receiver==PT_NSCN || receiver==PT_PSCN) goto conduct; continue; + default: + break; } - switch (rt) + //Receiving cases, where elements can have specific inputs + switch (receiver) { 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)) + if ((sender==PT_NSCN||sender==PT_METL||sender==PT_PSCN||sender==PT_QRTZ) && (parts[r>>8].temp<173.15||sim->pv[(y+ry)/CELL][(x+rx)/CELL]>8)) goto conduct; continue; case PT_NTCT: - if (ct==PT_NSCN || (ct==PT_PSCN&&parts[r>>8].temp>373.0f)) + if (sender==PT_NSCN || (sender==PT_PSCN&&parts[r>>8].temp>373.0f)) goto conduct; continue; case PT_PTCT: - if (ct==PT_NSCN || (ct==PT_PSCN&&parts[r>>8].temp<373.0f)) + if (sender==PT_NSCN || (sender==PT_PSCN&&parts[r>>8].temp<373.0f)) goto conduct; continue; case PT_INWR: - if (ct==PT_NSCN || ct==PT_PSCN) + if (sender==PT_NSCN || sender==PT_PSCN) goto conduct; continue; case PT_INST: - if (ct==PT_PSCN) + if (sender==PT_PSCN) goto conduct; continue; case PT_NBLE: @@ -299,21 +302,24 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) goto conduct; continue; case PT_PSCN: - if (ct!=PT_NSCN) + if (sender!=PT_NSCN) goto conduct; continue; + default: + break; } conduct: - if (rt==PT_WATR||rt==PT_SLTW) { + //Yay, passed normal conduction rules, check a few last things and change receiver to spark + if (receiver==PT_WATR||receiver==PT_SLTW) { if (parts[r>>8].life==0 && parts[i].life<3) { sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); - if (rt==PT_WATR) parts[r>>8].life = 6; + if (receiver==PT_WATR) parts[r>>8].life = 6; else parts[r>>8].life = 5; - parts[r>>8].ctype = rt; + parts[r>>8].ctype = receiver; } } - else if (rt==PT_INST) { + else if (receiver==PT_INST) { if (parts[r>>8].life==0 && parts[i].life<4) { sim->FloodINST(x+rx,y+ry,PT_SPRK,PT_INST);//spark the wire @@ -321,21 +327,20 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) } else if (parts[r>>8].life==0 && parts[i].life<4) { parts[r>>8].life = 4; - parts[r>>8].ctype = rt; + parts[r>>8].ctype = receiver; sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); - if (parts[r>>8].temp+10.0f<673.0f&&!sim->legacy_enable&&(rt==PT_METL||rt==PT_BMTL||rt==PT_BRMT||rt==PT_PSCN||rt==PT_NSCN||rt==PT_ETRD||rt==PT_NBLE||rt==PT_IRON)) + if (parts[r>>8].temp+10.0f<673.0f&&!sim->legacy_enable&&(receiver==PT_METL||receiver==PT_BMTL||receiver==PT_BRMT||receiver==PT_PSCN||receiver==PT_NSCN||receiver==PT_ETRD||receiver==PT_NBLE||receiver==PT_IRON)) parts[r>>8].temp = parts[r>>8].temp+10.0f; } - else if (ct==PT_ETRD && parts[i].life==5) + else if (sender==PT_ETRD && parts[i].life==5) //ETRD is odd and conducts to others only at life 5, this could probably be somewhere else { - sim->part_change_type(i,x,y,ct); + sim->part_change_type(i,x,y,sender); parts[i].ctype = PT_NONE; parts[i].life = 20; parts[r>>8].life = 4; - parts[r>>8].ctype = rt; + parts[r>>8].ctype = receiver; sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); } - } return 0; }