Skip to content

Commit

Permalink
.tmp2 for CRAY now sets creation offset (just like DRAY)
Browse files Browse the repository at this point in the history
LIFE info moved into .ctype, no reason to use a whole extra variable for it
  • Loading branch information
jacob1 committed Aug 30, 2015
1 parent 5caf8bc commit 37794c0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/client/GameSave.cpp
Expand Up @@ -1035,6 +1035,12 @@ void GameSave::readOPS(char * data, int dataLength)
{
particles[newIndex].temp = particles[newIndex].temp - 1.0f;
}
case PT_CRAY:
if (savedVersion < 91)
{
if (particles[newIndex].tmp2)
particles[newIndex].ctype |= particles[newIndex].tmp2<<8;
}
}
//note: PSv was used in version 77.0 and every version before, add something in PSv too if the element is that old
newIndex++;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/game/GameView.cpp
Expand Up @@ -2234,6 +2234,9 @@ 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)
sampleInfo << " (" << c->ElementResolve(ctype&0xFF, ctype>>8) << ")";
else if (c->IsValidElement(ctype))
sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")";
else
Expand Down
6 changes: 3 additions & 3 deletions src/simulation/Simulation.cpp
Expand Up @@ -2765,7 +2765,7 @@ 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 < NGOL && drawOn != PT_STOR)
if (t == PT_LIFE && v >= 0 && v < NGOL && 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)
Expand All @@ -2782,8 +2782,8 @@ int Simulation::create_part(int p, int x, int y, int tv)
else if (drawOn == PT_CRAY && drawOn != t)
{
parts[pmap[y][x]>>8].ctype = t;
if (t==PT_LIFE && v<NGOL)
parts[pmap[y][x]>>8].tmp2 = v;
if (t == PT_LIFE && v >= 0 && v < NGOL)
parts[pmap[y][x]>>8].ctype |= v<<8;
parts[pmap[y][x]>>8].temp = elements[t].Temperature;
}
return -1;
Expand Down
33 changes: 17 additions & 16 deletions src/simulation/elements/CRAY.cpp
Expand Up @@ -49,15 +49,15 @@ Element_CRAY::Element_CRAY()
//#TPT-Directive ElementHeader Element_CRAY static int update(UPDATE_FUNC_ARGS)
int Element_CRAY::update(UPDATE_FUNC_ARGS)
{
int r, nxx, nyy, docontinue, nxi, nyi, rx, ry;
int nxx, nyy, docontinue, nxi, nyi;
// set ctype to things that touch it if it doesn't have one already
if(parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled) {
int r, rx, ry;
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (parts[i].ctype<=0 || !sim->elements[parts[i].ctype&0xFF].Enabled)
{
for (int rx = -1; rx <= 1; rx++)
for (int ry = -1; ry <= 1; ry++)
if (BOUNDS_CHECK)
{
r = sim->photons[y+ry][x+rx];
int r = sim->photons[y+ry][x+rx];
if (!r)
r = pmap[y+ry][x+rx];
if (!r)
Expand All @@ -68,12 +68,15 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS)
parts[i].temp = parts[r>>8].temp;
}
}
} else if (parts[i].life==0) { // only fire when life is 0, but nothing sets the life right now
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
}
// only fire when life is 0, but nothing sets the life right now
else if (parts[i].life==0)
{
for (int rx =-1; rx <= 1; rx++)
for (int ry = -1; ry <= 1; ry++)
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
int r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SPRK && parts[r>>8].life==3) { //spark found, start creating
Expand All @@ -84,17 +87,15 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS)
int partsRemaining = 255;
if (parts[i].tmp) //how far it shoots
partsRemaining = parts[i].tmp;
for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi) {
int spacesRemaining = parts[i].tmp2;
for (docontinue = 1, nxi = rx*-1, nyi = ry*-1, nxx = spacesRemaining*nxi, nyy = spacesRemaining*nyi; docontinue; nyy+=nyi, nxx+=nxi)
{
if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0)) {
break;
}
r = pmap[y+nyi+nyy][x+nxi+nxx];
if (!sim->IsWallBlocking(x+nxi+nxx, y+nyi+nyy, parts[i].ctype) && (!sim->pmap[y+nyi+nyy][x+nxi+nxx] || createSpark)) { // create, also set color if it has passed through FILT
int nr;
if (parts[i].ctype == PT_LIFE)
nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype|(parts[i].tmp2<<8));
else
nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype);
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype);
if (nr!=-1) {
if (colored)
parts[nr].dcolour = colored;
Expand Down

0 comments on commit 37794c0

Please sign in to comment.