From 79edfe9589c4b82ce320e0ae88d043b66b14f570 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 8 Sep 2013 09:21:08 +0100 Subject: [PATCH] Include elements[].Enabled in check for invalid lava ctype --- src/gui/game/GameController.cpp | 10 ++++++++++ src/gui/game/GameController.h | 1 + src/gui/game/GameView.cpp | 4 ++-- src/simulation/Simulation.cpp | 6 +++--- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 12358480f..a114b826e 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1389,6 +1389,16 @@ std::string GameController::ElementResolve(int type, int ctype) return ""; } +bool GameController::IsValidElement(int type) +{ + if(gameModel && gameModel->GetSimulation()) + { + return (type > 0 && type < PT_NUM && gameModel->GetSimulation()->elements[type].Enabled); + } + else + return false; +} + std::string GameController::WallName(int type) { if(gameModel && gameModel->GetSimulation() && gameModel->GetSimulation()->wtypes && type >= 0 && type < UI_WALLCOUNT) diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index d723ccb63..b2a7d99b6 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -137,6 +137,7 @@ public: ui::Point PointTranslate(ui::Point point); ui::Point NormaliseBlockCoord(ui::Point point); std::string ElementResolve(int type, int ctype); + bool IsValidElement(int type); std::string WallName(int type); void ResetAir(); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 65f341aea..5d0cc34d7 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -2069,7 +2069,7 @@ void GameView::OnDraw() ctype = sample.particle.tmp&0xFF; if(showDebug) { - if (sample.particle.type == PT_LAVA && ctype > 0 && ctype < PT_NUM) + if (sample.particle.type == PT_LAVA && c->IsValidElement(ctype)) sampleInfo << "Molten " << c->ElementResolve(ctype, -1); else if ((sample.particle.type == PT_PIPE || sample.particle.type == PT_PPIP) && ctype > 0 && ctype < PT_NUM) sampleInfo << c->ElementResolve(sample.particle.type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]); @@ -2087,7 +2087,7 @@ void GameView::OnDraw() else { sampleInfo << c->ElementResolve(sample.particle.type, sample.particle.ctype); - if(ctype > 0 && ctype < PT_NUM) + if (c->IsValidElement(ctype)) sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")"; else sampleInfo << " ()"; diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 7d466a456..03c4dd2e9 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -3811,7 +3811,7 @@ void Simulation::update_particles_i(int start, int inc) s = 1; //A fix for ice with ctype = 0 - if ((t==PT_ICEI || t==PT_SNOW) && (parts[i].ctype==0 || parts[i].ctype>=PT_NUM || parts[i].ctype==PT_ICEI || parts[i].ctype==PT_SNOW)) + if ((t==PT_ICEI || t==PT_SNOW) && (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || parts[i].ctype==PT_ICEI || parts[i].ctype==PT_SNOW || !elements[parts[i].ctype].Enabled)) parts[i].ctype = PT_WATR; if (ctemph>elements[t].HighTemperature && elements[t].HighTemperatureTransition>-1) @@ -3838,7 +3838,7 @@ void Simulation::update_particles_i(int start, int inc) #endif else if (t == PT_ICEI || t == PT_SNOW) { - if (parts[i].ctype < PT_NUM && parts[i].ctype != t) + if (parts[i].ctype > 0 && parts[i].ctype < PT_NUM && parts[i].ctype != t) { if (elements[parts[i].ctype].LowTemperatureTransition==t && pt<=elements[parts[i].ctype].LowTemperature) s = 0; @@ -3941,7 +3941,7 @@ void Simulation::update_particles_i(int start, int inc) } else if (t == PT_LAVA) { - if (parts[i].ctype>0 && parts[i].ctype0 && parts[i].ctype=elements[PT_BMTL].HighTemperature) s = 0;