Skip to content

Commit

Permalink
part_change_type now returns true if it killed the particle
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Mar 10, 2018
1 parent b07e8d9 commit ad5b12f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
34 changes: 12 additions & 22 deletions src/simulation/Simulation.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/simulation/Simulation.h
Expand Up @@ -146,7 +146,7 @@ class Simulation
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);
Expand Down
5 changes: 3 additions & 2 deletions src/simulation/elements/PROT.cpp
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/simulation/elements/SPRK.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit ad5b12f

Please sign in to comment.