mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-03-15 11:49:52 +01:00
TPT: Fix major update_particles_i bug, do_move was being called on nonexistant particles, causing kill_part to kill another particle 96ec3486e8
This commit is contained in:
parent
a8483798cc
commit
779ac383dc
@ -1401,58 +1401,30 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
||||
|
||||
if (parts[i].type == PT_NEUT && (ptypes[r & 0xFF].properties & PROP_NEUTABSORB))
|
||||
{
|
||||
parts[i].type = PT_NONE;
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_PVOD) //this is where void eats particles
|
||||
{
|
||||
if (parts[i].type == PT_STKM)
|
||||
{
|
||||
player.spwn = 0;
|
||||
}
|
||||
if (parts[i].type == PT_STKM2)
|
||||
{
|
||||
player2.spwn = 0;
|
||||
}
|
||||
if (parts[i].type == PT_FIGH)
|
||||
{
|
||||
fighters[(unsigned char)parts[i].tmp].spwn = 0;
|
||||
fighcount--;
|
||||
}
|
||||
parts[i].type=PT_NONE;
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles
|
||||
{
|
||||
if (parts[i].type == PT_STKM)
|
||||
{
|
||||
player.spwn = 0;
|
||||
}
|
||||
if (parts[i].type == PT_STKM2)
|
||||
{
|
||||
player2.spwn = 0;
|
||||
}
|
||||
if (parts[i].type == PT_FIGH)
|
||||
{
|
||||
fighters[(unsigned char)parts[i].tmp].spwn = 0;
|
||||
fighcount--;
|
||||
}
|
||||
parts[i].type=PT_NONE;
|
||||
if (!legacy_enable)
|
||||
{
|
||||
parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f;
|
||||
}
|
||||
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
if (((r&0xFF)==PT_WHOL||(r&0xFF)==PT_NWHL) && parts[i].type==PT_ANAR) //whitehole eats anar
|
||||
{
|
||||
parts[i].type=PT_NONE;
|
||||
if (!legacy_enable)
|
||||
{
|
||||
parts[r>>8].temp = restrict_flt(parts[r>>8].temp- (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
|
||||
}
|
||||
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1498,8 +1470,10 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
||||
// try to move particle, and if successful update pmap and parts[i].x,y
|
||||
int Simulation::do_move(int i, int x, int y, float nxf, float nyf)
|
||||
{
|
||||
int nx = (int)(nxf+0.5f), ny = (int)(nyf+0.5f);
|
||||
int result = try_move(i, x, y, nx, ny);
|
||||
int nx = (int)(nxf+0.5f), ny = (int)(nyf+0.5f), result;
|
||||
if (parts[i].type == PT_NONE)
|
||||
return 0;
|
||||
result = try_move(i, x, y, nx, ny);
|
||||
if (result)
|
||||
{
|
||||
int t = parts[i].type;
|
||||
@ -1725,6 +1699,9 @@ void Simulation::kill_part(int i)//kills particle number i
|
||||
{
|
||||
int x, y;
|
||||
|
||||
if (parts[i].type == PT_NONE)
|
||||
return;
|
||||
|
||||
if(elementCount[parts[i].type] && parts[i].type)
|
||||
elementCount[parts[i].type]--;
|
||||
x = (int)(parts[i].x+0.5f);
|
||||
@ -3042,13 +3019,15 @@ killed:
|
||||
if (stagnant)//FLAG_STAGNANT set, was reflected on previous frame
|
||||
{
|
||||
// cast coords as int then back to float for compatibility with existing saves
|
||||
if (!do_move(i, x, y, (float)fin_x, (float)fin_y)) {
|
||||
if (!do_move(i, x, y, (float)fin_x, (float)fin_y) && parts[i].type) {
|
||||
kill_part(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (!do_move(i, x, y, fin_xf, fin_yf))
|
||||
{
|
||||
if (parts[i].type == PT_NONE)
|
||||
continue;
|
||||
// reflection
|
||||
parts[i].flags |= FLAG_STAGNANT;
|
||||
if (t==PT_NEUT && 100>(rand()%1000))
|
||||
@ -3108,8 +3087,11 @@ killed:
|
||||
// gasses and solids (but not powders)
|
||||
if (!do_move(i, x, y, fin_xf, fin_yf))
|
||||
{
|
||||
if (parts[i].type == PT_NONE)
|
||||
continue;
|
||||
// can't move there, so bounce off
|
||||
// TODO
|
||||
// TODO: Work out what previous TODO was for
|
||||
if (fin_x>x+ISTP) fin_x=x+ISTP;
|
||||
if (fin_x<x-ISTP) fin_x=x-ISTP;
|
||||
if (fin_y>y+ISTP) fin_y=y+ISTP;
|
||||
@ -3139,6 +3121,8 @@ killed:
|
||||
// liquids and powders
|
||||
if (!do_move(i, x, y, fin_xf, fin_yf))
|
||||
{
|
||||
if (parts[i].type == PT_NONE)
|
||||
continue;
|
||||
if (fin_x!=x && do_move(i, x, y, fin_xf, clear_yf))
|
||||
{
|
||||
parts[i].vx *= ptypes[t].collision;
|
||||
|
Loading…
x
Reference in New Issue
Block a user