summaryrefslogtreecommitdiff
path: root/src/simulation/Simulation.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-18 18:02:27 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-18 18:02:27 (GMT)
commit779ac383dcb6d88d46723f1e9a2d99c80cadac70 (patch)
tree1d3b1529894dd88b32450a836005a2dc4a43e49b /src/simulation/Simulation.cpp
parenta8483798cca834beb8d8657ab9e7508912dc5ebf (diff)
downloadpowder-779ac383dcb6d88d46723f1e9a2d99c80cadac70.zip
powder-779ac383dcb6d88d46723f1e9a2d99c80cadac70.tar.gz
TPT: Fix major update_particles_i bug, do_move was being called on nonexistant particles, causing kill_part to kill another particle 96ec3486e8
Diffstat (limited to 'src/simulation/Simulation.cpp')
-rw-r--r--src/simulation/Simulation.cpp54
1 files changed, 19 insertions, 35 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index aaa4834..19215fd 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -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;