From ad5b12fe6da0e68b5e8732caaf604729b456b263 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 10 Mar 2018 15:39:39 -0500 Subject: [PATCH] part_change_type now returns true if it killed the particle --- src/simulation/Simulation.cpp | 34 +++++++++++--------------------- src/simulation/Simulation.h | 2 +- src/simulation/elements/PROT.cpp | 5 +++-- src/simulation/elements/SPRK.cpp | 3 ++- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index ff467cec4..e1bb6f00d 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2935,26 +2935,26 @@ void Simulation::kill_part(int i)//kills particle number i pfree = i; } -void Simulation::part_change_type(int i, int x, int y, int t)//changes the type of particle number i, to t. This also changes pmap at the same time. +// Changes the type of particle number i, to t. This also changes pmap at the same time +// Returns true if the particle was killed +bool Simulation::part_change_type(int i, int x, int y, int t) { if (x<0 || y<0 || x>=XRES || y>=YRES || i>=NPART || t<0 || t>=PT_NUM || !parts[i].type) - return; - if (!elements[t].Enabled) - t = PT_NONE; - if (t == PT_NONE) + return false; + if (!elements[t].Enabled || t == PT_NONE) { kill_part(i); - return; + return true; } else if ((t == PT_STKM || t == PT_STKM2 || t == PT_SPAWN || t == PT_SPAWN2) && elementCount[t]) { kill_part(i); - return; + return true; } else if ((t == PT_STKM && player.spwn) || (t == PT_STKM2 && player2.spwn)) { kill_part(i); - return; + return true; } if (parts[i].type == PT_STKM) @@ -3014,6 +3014,7 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type if (ID(photons[y][x]) == i) photons[y][x] = 0; } + return false; } //the function for creating a particle, use p=-1 for creating a new particle, -2 is from a brush, or a particle number to replace a particle. @@ -4107,13 +4108,8 @@ void Simulation::UpdateParticles(int start, int end) if ((elements[t].Properties&TYPE_GAS) && !(elements[parts[i].type].Properties&TYPE_GAS)) pv[y/CELL][x/CELL] += 0.50f; - if (t == PT_NONE) - { - kill_part(i); + if (part_change_type(i,x,y,t)) goto killed; - } - else - part_change_type(i,x,y,t); // part_change_type could refuse to change the type and kill the particle // for example, changing type to STKM but one already exists // we need to account for that to not cause simulation corruption issues @@ -4247,19 +4243,13 @@ void Simulation::UpdateParticles(int start, int end) if (s) { parts[i].life = 0; - part_change_type(i,x,y,t); // part_change_type could refuse to change the type and kill the particle // for example, changing type to STKM but one already exists // we need to account for that to not cause simulation corruption issues - if (parts[i].type == PT_NONE) + if (part_change_type(i,x,y,t)) goto killed; - if (t==PT_FIRE) + if (t == PT_FIRE) parts[i].life = rand()%50+120; - if (t==PT_NONE) - { - kill_part(i); - goto killed; - } transitionOccurred = true; } diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index e8b89bbf5..a998beb5a 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -146,7 +146,7 @@ public: int flood_water(int x, int y, int i, int originaly, int check); int FloodINST(int x, int y, int fullc, int cm); void detach(int i); - void part_change_type(int i, int x, int y, int t); + bool part_change_type(int i, int x, int y, int t); //int InCurrentBrush(int i, int j, int rx, int ry); //int get_brush_flags(); int create_part(int p, int x, int y, int t, int v = -1); diff --git a/src/simulation/elements/PROT.cpp b/src/simulation/elements/PROT.cpp index fc1a38cfb..091961e82 100644 --- a/src/simulation/elements/PROT.cpp +++ b/src/simulation/elements/PROT.cpp @@ -58,12 +58,13 @@ int Element_PROT::update(UPDATE_FUNC_ARGS) { //remove active sparks int sparked = parts[uID].ctype; - if (sparked > 0 && sparked < PT_NUM && sim->elements[sparked].Enabled) + if (!sim->part_change_type(uID, x, y, sparked)) { - sim->part_change_type(uID, x, y, sparked); parts[uID].life = 44 + parts[uID].life; parts[uID].ctype = 0; } + else + utype = 0; break; } case PT_DEUT: diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index daddb46ce..b6c53f25c 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -66,7 +66,8 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) parts[i].life = 54; else if (ct == PT_SWCH) parts[i].life = 14; - sim->part_change_type(i,x,y,ct); + if (sim->part_change_type(i,x,y,ct)) + return 1; return 0; } //Some functions of SPRK based on ctype (what it is on)