From 20a7d0528bb57c89b67a0252794c3a34e20fc1d8 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 12 May 2014 11:27:39 -0400 Subject: [PATCH] also fix SOAP changing .ctype of particles it thinks it's attached to --- src/simulation/Simulation.cpp | 24 +++--------------------- src/simulation/elements/PIPE.cpp | 2 +- src/simulation/elements/PRTI.cpp | 2 +- src/simulation/elements/SOAP.cpp | 28 +++++++++++++++++++++++----- src/simulation/elements/STOR.cpp | 3 ++- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 97e548685b..d39cd52b30 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2578,24 +2578,6 @@ int Simulation::get_normal_interp(int pt, float x0, float y0, float dx, float dy return get_normal(pt, x, y, dx, dy, nx, ny); } -//For soap only -void Simulation::detach(int i) -{ - if ((parts[i].ctype&2) == 2) - { - if ((parts[parts[i].tmp].ctype&4) == 4) - parts[parts[i].tmp].ctype ^= 4; - } - - if ((parts[i].ctype&4) == 4) - { - if ((parts[parts[i].tmp2].ctype&2) == 2) - parts[parts[i].tmp2].ctype ^= 2; - } - - parts[i].ctype = 0; -} - void Simulation::kill_part(int i)//kills particle number i { int x = (int)(parts[i].x+0.5f); @@ -2627,7 +2609,7 @@ void Simulation::kill_part(int i)//kills particle number i } else if (parts[i].type == PT_SOAP) { - detach(i); + Element_SOAP::detach(this, i); } parts[i].type = PT_NONE; @@ -2657,7 +2639,7 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type fighcount--; } else if (parts[i].type == PT_SOAP) - detach(i); + Element_SOAP::detach(this, i); parts[i].type = t; if (elements[t].Properties & TYPE_ENERGY) @@ -2827,7 +2809,7 @@ int Simulation::create_part(int p, int x, int y, int tv) } else if (parts[p].type == PT_SOAP) { - detach(p); + Element_SOAP::detach(this, p); } i = p; } diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index ee1a21ab18..daf354b17a 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -201,7 +201,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) else if ((parts[i].tmp&0xFF) == 0 && (sim->elements[r&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) { if ((r&0xFF)==PT_SOAP) - sim->detach(r>>8); + Element_SOAP::detach(sim, r>>8); transfer_part_to_pipe(parts+(r>>8), parts+i); sim->kill_part(r>>8); } diff --git a/src/simulation/elements/PRTI.cpp b/src/simulation/elements/PRTI.cpp index aaddb4d781..658f738c83 100644 --- a/src/simulation/elements/PRTI.cpp +++ b/src/simulation/elements/PRTI.cpp @@ -82,7 +82,7 @@ int Element_PRTI::update(UPDATE_FUNC_ARGS) continue;// Handling these is a bit more complicated, and is done in STKM_interact() if ((r&0xFF) == PT_SOAP) - sim->detach(r>>8); + Element_SOAP::detach(sim, r>>8); for ( nnx=0; nnx<80; nnx++) if (!sim->portalp[parts[i].tmp][count][nnx].type) diff --git a/src/simulation/elements/SOAP.cpp b/src/simulation/elements/SOAP.cpp index 01ea3e6603..e18ad284af 100644 --- a/src/simulation/elements/SOAP.cpp +++ b/src/simulation/elements/SOAP.cpp @@ -47,6 +47,24 @@ Element_SOAP::Element_SOAP() } +//#TPT-Directive ElementHeader Element_SOAP static void detach(Simulation * sim, int i) +void Element_SOAP::detach(Simulation * sim, int i) +{ + if ((sim->parts[i].ctype&2) == 2 && sim->parts[sim->parts[i].tmp].type == PT_SOAP) + { + if ((sim->parts[sim->parts[i].tmp].ctype&4) == 4) + sim->parts[sim->parts[i].tmp].ctype ^= 4; + } + + if ((sim->parts[i].ctype&4) == 4 && sim->parts[sim->parts[i].tmp2].type == PT_SOAP) + { + if ((sim->parts[sim->parts[i].tmp2].ctype&2) == 2) + sim->parts[sim->parts[i].tmp2].ctype ^= 2; + } + + sim->parts[i].ctype = 0; +} + //#TPT-Directive ElementHeader Element_SOAP static void attach(Particle * parts, int i1, int i2) void Element_SOAP::attach(Particle * parts, int i1, int i2) { @@ -93,24 +111,24 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS) { int target = i; //break entire bubble in a loop - while((parts[target].ctype&6) != 6 && (parts[target].ctype&6)) + while((parts[target].ctype&6) != 6 && (parts[target].ctype&6) && parts[target].type == PT_SOAP) { if (parts[target].ctype&2) { target = parts[target].tmp; - sim->detach(target); + detach(sim, target); } if (parts[target].ctype&4) { target = parts[target].tmp2; - sim->detach(target); + detach(sim, target); } } } if ((parts[i].ctype&6) != 6) parts[i].ctype = 0; if ((parts[i].ctype&6) == 6 && (parts[parts[i].tmp].ctype&6) == 6 && parts[parts[i].tmp].tmp == i) - sim->detach(i); + detach(sim, i); } parts[i].vy = (parts[i].vy-0.1f)*0.5f; parts[i].vx *= 0.5f; @@ -144,7 +162,7 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS) || (r && sim->elements[r&0xFF].State != ST_GAS && (r&0xFF) != PT_SOAP && (r&0xFF) != PT_GLAS)) { - sim->detach(i); + detach(sim, i); continue; } } diff --git a/src/simulation/elements/STOR.cpp b/src/simulation/elements/STOR.cpp index ce26767ec1..348297c286 100644 --- a/src/simulation/elements/STOR.cpp +++ b/src/simulation/elements/STOR.cpp @@ -61,7 +61,8 @@ int Element_STOR::update(UPDATE_FUNC_ARGS) continue; if (!parts[i].tmp && !parts[i].life && (r&0xFF)!=PT_STOR && !(sim->elements[(r&0xFF)].Properties&TYPE_SOLID) && (!parts[i].ctype || (r&0xFF)==parts[i].ctype)) { - if ((r&0xFF) == PT_SOAP) sim->detach(r>>8); + if ((r&0xFF) == PT_SOAP) + Element_SOAP::detach(sim, r>>8); parts[i].tmp = parts[r>>8].type; parts[i].temp = parts[r>>8].temp; parts[i].tmp2 = parts[r>>8].life;