From d0445258c5b4109de0b90e70ece559d938cd519a Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Tue, 13 Oct 2015 00:59:41 +0100 Subject: [PATCH] CONV tmp value can now be used to restrict which elements get converted. Requires version bump to 92. --- src/client/GameSave.cpp | 20 ++++++++++++++++++++ src/gui/game/GameView.cpp | 4 ++-- src/simulation/Simulation.cpp | 9 +++++++-- src/simulation/elements/CONV.cpp | 16 ++++++++-------- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 6391fe99e2..31df486b68 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -1085,6 +1085,15 @@ void GameSave::readOPS(char * data, int dataLength) particles[newIndex].tmp2 = 0; } } + case PT_CONV: + if (savedVersion < 92) + { + if (particles[newIndex].tmp) + { + particles[newIndex].ctype |= particles[newIndex].tmp<<8; + particles[newIndex].tmp = 0; + } + } } //note: PSv was used in version 77.0 and every version before, add something in PSv too if the element is that old newIndex++; @@ -1738,6 +1747,17 @@ void GameSave::readPSv(char * data, int dataLength) if (particles[i-1].type == PT_VINE) particles[i-1].tmp = 1; } + if (ver < 92) + { + if (particles[i-1].type == PT_CONV) + { + if (particles[i-1].tmp) + { + particles[i-1].ctype |= particles[i-1].tmp<<8; + particles[i-1].tmp = 0; + } + } + } } } diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index af4755f2b2..0bdb1767ea 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -2267,8 +2267,8 @@ void GameView::OnDraw() sampleInfo << c->ElementResolve(sample.particle.type, sample.particle.ctype); if (wavelengthGfx) sampleInfo << " (" << ctype << ")"; - // CRAY and DRAY store extra LIFE info in upper bits of ctype, instead of tmp2 - else if (sample.particle.type == PT_CRAY || sample.particle.type == PT_DRAY) + // Some elements store extra LIFE info in upper bits of ctype, instead of tmp/tmp2 + else if (sample.particle.type == PT_CRAY || sample.particle.type == PT_DRAY || sample.particle.type == PT_CONV) sampleInfo << " (" << c->ElementResolve(ctype&0xFF, ctype>>8) << ")"; else if (c->IsValidElement(ctype)) sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")"; diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 06499299df..bf4bc7b0f1 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2847,8 +2847,13 @@ int Simulation::create_part(int p, int x, int y, int tv) && (!(elements[t].Properties & PROP_NOCTYPEDRAW))) { parts[pmap[y][x]>>8].ctype = t; - if (t == PT_LIFE && v >= 0 && v < NGOL && drawOn != PT_STOR) - parts[pmap[y][x]>>8].tmp = v; + if (t == PT_LIFE && v >= 0 && v < NGOL) + { + if (drawOn == PT_CONV) + parts[pmap[y][x]>>8].ctype |= v<<8; + else if (drawOn != PT_STOR) + parts[pmap[y][x]>>8].tmp = v; + } } else if ((drawOn == PT_DTEC || (drawOn == PT_PSTN && t != PT_FRME) || drawOn == PT_DRAY) && drawOn != t) { diff --git a/src/simulation/elements/CONV.cpp b/src/simulation/elements/CONV.cpp index 24baa906f8..39fadcc3f7 100644 --- a/src/simulation/elements/CONV.cpp +++ b/src/simulation/elements/CONV.cpp @@ -50,7 +50,8 @@ Element_CONV::Element_CONV() int Element_CONV::update(UPDATE_FUNC_ARGS) { int r, rx, ry; - if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || parts[i].ctype==PT_CONV || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOL))) + int ctype = parts[i].ctype&0xFF, ctypeExtra = parts[i].ctype>>8; + if (ctype<=0 || ctype>=PT_NUM || !sim->elements[ctype].Enabled || ctype==PT_CONV || (ctype==PT_LIFE && (ctypeExtra<0 || ctypeExtra>=NGOL))) { for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) @@ -68,26 +69,25 @@ int Element_CONV::update(UPDATE_FUNC_ARGS) { parts[i].ctype = r&0xFF; if ((r&0xFF)==PT_LIFE) - parts[i].tmp = parts[r>>8].ctype; + parts[i].ctype |= (parts[r>>8].ctype << 8); } } } else { - bool life = parts[i].ctype==PT_LIFE; + int restrictElement = sim->IsValidElement(parts[i].tmp) ? parts[i].tmp : 0; for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>=0 && x+rxphotons[y+ry][x+rx]; - if (!r) + if (!r || (restrictElement && (r&0xFF)!=restrictElement)) r = pmap[y+ry][x+rx]; - if (!r) + if (!r || (restrictElement && (r&0xFF)!=restrictElement)) continue; - if((r&0xFF)!=PT_CONV && (r&0xFF)!=PT_DMND && (r&0xFF)!=parts[i].ctype) + if((r&0xFF)!=PT_CONV && (r&0xFF)!=PT_DMND && (r&0xFF)!=ctype) { - if (life) sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8)); - else sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype); + sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype); } } }