part_change_type now returns true if it killed the particle
This commit is contained in:
parent
b07e8d93d5
commit
ad5b12fe6d
@ -2935,26 +2935,26 @@ void Simulation::kill_part(int i)//kills particle number i
|
|||||||
pfree = 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)
|
if (x<0 || y<0 || x>=XRES || y>=YRES || i>=NPART || t<0 || t>=PT_NUM || !parts[i].type)
|
||||||
return;
|
return false;
|
||||||
if (!elements[t].Enabled)
|
if (!elements[t].Enabled || t == PT_NONE)
|
||||||
t = PT_NONE;
|
|
||||||
if (t == PT_NONE)
|
|
||||||
{
|
{
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
else if ((t == PT_STKM || t == PT_STKM2 || t == PT_SPAWN || t == PT_SPAWN2) && elementCount[t])
|
else if ((t == PT_STKM || t == PT_STKM2 || t == PT_SPAWN || t == PT_SPAWN2) && elementCount[t])
|
||||||
{
|
{
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
else if ((t == PT_STKM && player.spwn) || (t == PT_STKM2 && player2.spwn))
|
else if ((t == PT_STKM && player.spwn) || (t == PT_STKM2 && player2.spwn))
|
||||||
{
|
{
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parts[i].type == PT_STKM)
|
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)
|
if (ID(photons[y][x]) == i)
|
||||||
photons[y][x] = 0;
|
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.
|
//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))
|
if ((elements[t].Properties&TYPE_GAS) && !(elements[parts[i].type].Properties&TYPE_GAS))
|
||||||
pv[y/CELL][x/CELL] += 0.50f;
|
pv[y/CELL][x/CELL] += 0.50f;
|
||||||
|
|
||||||
if (t == PT_NONE)
|
if (part_change_type(i,x,y,t))
|
||||||
{
|
|
||||||
kill_part(i);
|
|
||||||
goto killed;
|
goto killed;
|
||||||
}
|
|
||||||
else
|
|
||||||
part_change_type(i,x,y,t);
|
|
||||||
// part_change_type could refuse to change the type and kill the particle
|
// part_change_type could refuse to change the type and kill the particle
|
||||||
// for example, changing type to STKM but one already exists
|
// for example, changing type to STKM but one already exists
|
||||||
// we need to account for that to not cause simulation corruption issues
|
// 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)
|
if (s)
|
||||||
{
|
{
|
||||||
parts[i].life = 0;
|
parts[i].life = 0;
|
||||||
part_change_type(i,x,y,t);
|
|
||||||
// part_change_type could refuse to change the type and kill the particle
|
// part_change_type could refuse to change the type and kill the particle
|
||||||
// for example, changing type to STKM but one already exists
|
// for example, changing type to STKM but one already exists
|
||||||
// we need to account for that to not cause simulation corruption issues
|
// 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;
|
goto killed;
|
||||||
if (t==PT_FIRE)
|
if (t == PT_FIRE)
|
||||||
parts[i].life = rand()%50+120;
|
parts[i].life = rand()%50+120;
|
||||||
if (t==PT_NONE)
|
|
||||||
{
|
|
||||||
kill_part(i);
|
|
||||||
goto killed;
|
|
||||||
}
|
|
||||||
transitionOccurred = true;
|
transitionOccurred = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ public:
|
|||||||
int flood_water(int x, int y, int i, int originaly, int check);
|
int flood_water(int x, int y, int i, int originaly, int check);
|
||||||
int FloodINST(int x, int y, int fullc, int cm);
|
int FloodINST(int x, int y, int fullc, int cm);
|
||||||
void detach(int i);
|
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 InCurrentBrush(int i, int j, int rx, int ry);
|
||||||
//int get_brush_flags();
|
//int get_brush_flags();
|
||||||
int create_part(int p, int x, int y, int t, int v = -1);
|
int create_part(int p, int x, int y, int t, int v = -1);
|
||||||
|
@ -58,12 +58,13 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
|
|||||||
{
|
{
|
||||||
//remove active sparks
|
//remove active sparks
|
||||||
int sparked = parts[uID].ctype;
|
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].life = 44 + parts[uID].life;
|
||||||
parts[uID].ctype = 0;
|
parts[uID].ctype = 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
utype = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PT_DEUT:
|
case PT_DEUT:
|
||||||
|
@ -66,7 +66,8 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS)
|
|||||||
parts[i].life = 54;
|
parts[i].life = 54;
|
||||||
else if (ct == PT_SWCH)
|
else if (ct == PT_SWCH)
|
||||||
parts[i].life = 14;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
//Some functions of SPRK based on ctype (what it is on)
|
//Some functions of SPRK based on ctype (what it is on)
|
||||||
|
Reference in New Issue
Block a user