From da45e0e46924d7f6e1d870682d5c07e4fbf0a585 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 28 Dec 2017 21:27:01 -0500 Subject: [PATCH] last src/simulation/element changes PSTN, CRAY, and possibly some others will need to be modified to account for this without breaking saves. The save format will need to include PMAPBITS and adjust properly --- src/simulation/Elements.h | 9 ++++++- src/simulation/SimulationData.h | 5 ---- src/simulation/elements/ARAY.cpp | 2 +- src/simulation/elements/BCLN.cpp | 2 +- src/simulation/elements/BOMB.cpp | 4 ++-- src/simulation/elements/CLNE.cpp | 2 +- src/simulation/elements/CONV.cpp | 4 ++-- src/simulation/elements/CRAY.cpp | 6 ++--- src/simulation/elements/DRAY.cpp | 8 +++---- src/simulation/elements/DSTW.cpp | 2 +- src/simulation/elements/EMP.cpp | 2 +- src/simulation/elements/GOLD.cpp | 2 +- src/simulation/elements/H2.cpp | 2 +- src/simulation/elements/HEAC.cpp | 2 +- src/simulation/elements/NBLE.cpp | 2 +- src/simulation/elements/NEUT.cpp | 2 +- src/simulation/elements/O2.cpp | 2 +- src/simulation/elements/PBCN.cpp | 2 +- src/simulation/elements/PCLN.cpp | 2 +- src/simulation/elements/PIPE.cpp | 40 ++++++++++++++++---------------- src/simulation/elements/PLNT.cpp | 4 +++- src/simulation/elements/PPIP.cpp | 10 ++++---- src/simulation/elements/PROT.cpp | 4 ++-- src/simulation/elements/PSTN.cpp | 4 ++-- src/simulation/elements/STKM.cpp | 2 +- src/simulation/elements/STOR.cpp | 2 +- src/simulation/elements/SWCH.cpp | 4 ++-- src/simulation/elements/TTAN.cpp | 24 ++++++++++--------- src/simulation/elements/VIRS.cpp | 2 +- 29 files changed, 82 insertions(+), 76 deletions(-) diff --git a/src/simulation/Elements.h b/src/simulation/Elements.h index b3dcbf3da..b05ca5010 100644 --- a/src/simulation/Elements.h +++ b/src/simulation/Elements.h @@ -50,7 +50,14 @@ #define OLD_PT_WIND 147 -//#define PT_NUM 161 +// Change this to change the amount of bits used to store type in pmap (and a few elements such as PIPE and CRAY) +#define PMAPBITS 8 +#define PMAPMASK ((2<<(PMAPBITS-1))-1) +#define ID(r) ((r)>>PMAPBITS) +#define TYP(r) ((r)&PMAPMASK) +#define PMAP(id, typ) ((id)<>8) -#define TYP(r) ((r)&0xFF) -#define PMAP(id, typ) ((id)<<8 | ((typ)&0xFF)) -#define PMAPID(id) ((id)<<8) - #ifndef SIMULATIONDATA_H #define SIMULATIONDATA_H diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index a613641e5..2f451f0c7 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -139,7 +139,7 @@ int Element_ARAY::update(UPDATE_FUNC_ARGS) { for (int rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1) { - int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, parts[r].tmp&0xFF); + int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, TYP(parts[r].tmp)); if (np != -1) { parts[np].temp = parts[r].temp; diff --git a/src/simulation/elements/BCLN.cpp b/src/simulation/elements/BCLN.cpp index e344e3db3..8fc59b50b 100644 --- a/src/simulation/elements/BCLN.cpp +++ b/src/simulation/elements/BCLN.cpp @@ -84,7 +84,7 @@ int Element_BCLN::update(UPDATE_FUNC_ARGS) if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_LIFE, parts[i].tmp); else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0) { - int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF); + int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, TYP(parts[i].ctype)); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/BOMB.cpp b/src/simulation/elements/BOMB.cpp index 38ae77767..93c7b8b80 100644 --- a/src/simulation/elements/BOMB.cpp +++ b/src/simulation/elements/BOMB.cpp @@ -72,7 +72,7 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS) if ((ynxj < 0) || (ynxj >= YRES) || (xnxi <= 0) || (xnxi >= XRES)) continue; - nt = pmap[ynxj][xnxi]&0xFF; + nt = TYP(pmap[ynxj][xnxi]); if (nt!=PT_DMND && nt!=PT_CLNE && nt!=PT_PCLN && nt!=PT_BCLN && nt!=PT_VIBR) { if (nt) @@ -89,7 +89,7 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS) } for (nxj=-(rad+1); nxj<=(rad+1); nxj++) for (nxi=-(rad+1); nxi<=(rad+1); nxi++) - if ((pow((float)nxi,2))/(pow((float)(rad+1),2))+(pow((float)nxj,2))/(pow((float)(rad+1),2))<=1 && !(pmap[y+nxj][x+nxi]&0xFF)) + if ((pow((float)nxi,2))/(pow((float)(rad+1),2))+(pow((float)nxj,2))/(pow((float)(rad+1),2))<=1 && !TYP(pmap[y+nxj][x+nxi])) { nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR); if (nb!=-1) diff --git a/src/simulation/elements/CLNE.cpp b/src/simulation/elements/CLNE.cpp index 8c42dce7e..7f74bd877 100644 --- a/src/simulation/elements/CLNE.cpp +++ b/src/simulation/elements/CLNE.cpp @@ -75,7 +75,7 @@ int Element_CLNE::update(UPDATE_FUNC_ARGS) if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_LIFE, parts[i].tmp); else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0) { - int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF); + int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, TYP(parts[i].ctype)); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/CONV.cpp b/src/simulation/elements/CONV.cpp index ac0e1a756..0fda3d767 100644 --- a/src/simulation/elements/CONV.cpp +++ b/src/simulation/elements/CONV.cpp @@ -48,7 +48,7 @@ Element_CONV::Element_CONV() int Element_CONV::update(UPDATE_FUNC_ARGS) { int r, rx, ry; - int ctype = parts[i].ctype&0xFF, ctypeExtra = ID(parts[i].ctype); + int ctype = TYP(parts[i].ctype), ctypeExtra = ID(parts[i].ctype); 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++) @@ -86,7 +86,7 @@ int Element_CONV::update(UPDATE_FUNC_ARGS) continue; if (TYP(r) != PT_CONV && TYP(r) != PT_DMND && TYP(r) != ctype) { - sim->create_part(ID(r), x+rx, y+ry, parts[i].ctype&0xFF, ID(parts[i].ctype)); + sim->create_part(ID(r), x+rx, y+ry, TYP(parts[i].ctype), ID(parts[i].ctype)); } } } diff --git a/src/simulation/elements/CRAY.cpp b/src/simulation/elements/CRAY.cpp index 509459733..fa91a05fe 100644 --- a/src/simulation/elements/CRAY.cpp +++ b/src/simulation/elements/CRAY.cpp @@ -49,7 +49,7 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS) { 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 || !sim->elements[parts[i].ctype&0xFF].Enabled) + if (parts[i].ctype<=0 || !sim->elements[TYP(parts[i].ctype)].Enabled) { for (int rx = -1; rx <= 1; rx++) for (int ry = -1; ry <= 1; ry++) @@ -91,8 +91,8 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS) break; } r = pmap[y+nyi+nyy][x+nxi+nxx]; - if (!sim->IsWallBlocking(x+nxi+nxx, y+nyi+nyy, parts[i].ctype&0xFF) && (!sim->pmap[y+nyi+nyy][x+nxi+nxx] || createSpark)) { // create, also set color if it has passed through FILT - int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype&0xFF, ID(parts[i].ctype)); + if (!sim->IsWallBlocking(x+nxi+nxx, y+nyi+nyy, TYP(parts[i].ctype)) && (!sim->pmap[y+nyi+nyy][x+nxi+nxx] || createSpark)) { // create, also set color if it has passed through FILT + int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, TYP(parts[i].ctype), ID(parts[i].ctype)); if (nr!=-1) { if (colored) parts[nr].dcolour = colored; diff --git a/src/simulation/elements/DRAY.cpp b/src/simulation/elements/DRAY.cpp index 36282f11c..35855d3da 100644 --- a/src/simulation/elements/DRAY.cpp +++ b/src/simulation/elements/DRAY.cpp @@ -54,7 +54,7 @@ bool InBounds(int x, int y) //#TPT-Directive ElementHeader Element_DRAY static int update(UPDATE_FUNC_ARGS) int Element_DRAY::update(UPDATE_FUNC_ARGS) { - int ctype = parts[i].ctype&0xFF, ctypeExtra = ID(parts[i].ctype), copyLength = parts[i].tmp, copySpaces = parts[i].tmp2; + int ctype = TYP(parts[i].ctype), ctypeExtra = ID(parts[i].ctype), copyLength = parts[i].tmp, copySpaces = parts[i].tmp2; if (copySpaces < 0) copySpaces = parts[i].tmp2 = 0; if (copyLength < 0) @@ -106,7 +106,7 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS) // 1: if .tmp isn't set, and the element in this spot is the ctype, then stop // 2: if .tmp is set, stop when the length limit reaches 0 // 3. Stop when we are out of bounds - if ((!copyLength && (rr&0xFF) == ctype && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra)) + if ((!copyLength && TYP(rr) == ctype && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra)) || !(--partsRemaining && InBounds(xCurrent+xStep, yCurrent+yStep))) { copyLength -= partsRemaining; @@ -123,9 +123,9 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS) { // get particle to copy if (isEnergy) - type = sim->photons[yCurrent][xCurrent]&0xFF; + type = TYP(sim->photons[yCurrent][xCurrent]); else - type = pmap[yCurrent][xCurrent]&0xFF; + type = TYP(pmap[yCurrent][xCurrent]); // if sparked by PSCN, overwrite whatever is in the target location, instead of just ignoring it if (overwrite) diff --git a/src/simulation/elements/DSTW.cpp b/src/simulation/elements/DSTW.cpp index ab6a4ca6e..29efda55c 100644 --- a/src/simulation/elements/DSTW.cpp +++ b/src/simulation/elements/DSTW.cpp @@ -53,7 +53,7 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS) if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; - switch (r&0xFF) + switch (TYP(r)) { case PT_SALT: if (!(rand()%50)) diff --git a/src/simulation/elements/EMP.cpp b/src/simulation/elements/EMP.cpp index f4bbd6faf..8c59458ef 100644 --- a/src/simulation/elements/EMP.cpp +++ b/src/simulation/elements/EMP.cpp @@ -135,7 +135,7 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount) int n = sim->pmap[ry+ny][rx+nx]; if (!n) continue; - int ntype = n&0xFF; + int ntype = TYP(n); n = ID(n); //Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor //So not affected by spark on metl, watr etc diff --git a/src/simulation/elements/GOLD.cpp b/src/simulation/elements/GOLD.cpp index 6a9d9c405..d887929ed 100644 --- a/src/simulation/elements/GOLD.cpp +++ b/src/simulation/elements/GOLD.cpp @@ -87,7 +87,7 @@ int Element_GOLD::update(UPDATE_FUNC_ARGS) } } } - if ((sim->photons[y][x]&0xFF) == PT_NEUT) + if (TYP(sim->photons[y][x]) == PT_NEUT) { if (!(rand()%7)) { diff --git a/src/simulation/elements/H2.cpp b/src/simulation/elements/H2.cpp index 1ca36ca1c..090da2d08 100644 --- a/src/simulation/elements/H2.cpp +++ b/src/simulation/elements/H2.cpp @@ -115,7 +115,7 @@ int Element_H2::update(UPDATE_FUNC_ARGS) parts[j].temp = temp; parts[j].tmp = 0x1; } - rx = x+rand()%3-1, ry = y+rand()%3-1, rt = pmap[ry][rx]&0xFF; + rx = x+rand()%3-1, ry = y+rand()%3-1, rt = TYP(pmap[ry][rx]); if (sim->can_move[PT_PLSM][rt] || rt == PT_H2) { j = sim->create_part(-3,rx,ry,PT_PLSM); diff --git a/src/simulation/elements/HEAC.cpp b/src/simulation/elements/HEAC.cpp index c29a227c1..19675b8bd 100644 --- a/src/simulation/elements/HEAC.cpp +++ b/src/simulation/elements/HEAC.cpp @@ -52,7 +52,7 @@ Element_HEAC::Element_HEAC() struct Element_HEAC::IsInsulator : public std::binary_function { bool operator() (Simulation* a, int b) { - return b && (a->elements[b&0xFF].HeatConduct == 0 || ((b&0xFF) == PT_HSWC && a->parts[ID(b)].life != 10)); + return b && (a->elements[TYP(b)].HeatConduct == 0 || (TYP(b) == PT_HSWC && a->parts[ID(b)].life != 10)); } }; //#TPT-Directive ElementHeader Element_HEAC static IsInsulator isInsulator diff --git a/src/simulation/elements/NBLE.cpp b/src/simulation/elements/NBLE.cpp index 802f68798..8c2da7fde 100644 --- a/src/simulation/elements/NBLE.cpp +++ b/src/simulation/elements/NBLE.cpp @@ -73,7 +73,7 @@ int Element_NBLE::update(UPDATE_FUNC_ARGS) parts[j].temp = temp; parts[j].tmp = 0x1; } - int rx = x+rand()%3-1, ry = y+rand()%3-1, rt = pmap[ry][rx]&0xFF; + int rx = x+rand()%3-1, ry = y+rand()%3-1, rt = TYP(pmap[ry][rx]); if (sim->can_move[PT_PLSM][rt] || rt == PT_NBLE) { j = sim->create_part(-3,rx,ry,PT_PLSM); diff --git a/src/simulation/elements/NEUT.cpp b/src/simulation/elements/NEUT.cpp index be205fead..67f48bca4 100644 --- a/src/simulation/elements/NEUT.cpp +++ b/src/simulation/elements/NEUT.cpp @@ -55,7 +55,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS) if (BOUNDS_CHECK) { r = pmap[y+ry][x+rx]; - switch (r&0xFF) + switch (TYP(r)) { case PT_WATR: if (3>(rand()%20)) diff --git a/src/simulation/elements/O2.cpp b/src/simulation/elements/O2.cpp index c5e4705d5..6296bfe52 100644 --- a/src/simulation/elements/O2.cpp +++ b/src/simulation/elements/O2.cpp @@ -90,7 +90,7 @@ int Element_O2::update(UPDATE_FUNC_ARGS) parts[j].temp = MAX_TEMP; parts[j].tmp = 0x1; } - rx = x+rand()%3-1, ry = y+rand()%3-1, r = pmap[ry][rx]&0xFF; + rx = x+rand()%3-1, ry = y+rand()%3-1, r = TYP(pmap[ry][rx]); if (sim->can_move[PT_PLSM][r] || r == PT_O2) { j = sim->create_part(-3,rx,ry,PT_PLSM); diff --git a/src/simulation/elements/PBCN.cpp b/src/simulation/elements/PBCN.cpp index 004b45926..2c4cec28b 100644 --- a/src/simulation/elements/PBCN.cpp +++ b/src/simulation/elements/PBCN.cpp @@ -134,7 +134,7 @@ int Element_PBCN::update(UPDATE_FUNC_ARGS) else if (parts[i].ctype!=PT_LIGH || !(rand()%30)) { - int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF); + int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, TYP(parts[i].ctype)); if (np>-1) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/PCLN.cpp b/src/simulation/elements/PCLN.cpp index 44b272180..7fe7fba91 100644 --- a/src/simulation/elements/PCLN.cpp +++ b/src/simulation/elements/PCLN.cpp @@ -125,7 +125,7 @@ int Element_PCLN::update(UPDATE_FUNC_ARGS) else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0) { - int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF); + int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, TYP(parts[i].ctype)); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 4f9da7dd0..b2c1196e7 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -75,8 +75,8 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) { int r, rx, ry, np; int rnd, rndstore; - if ((parts[i].tmp&0xFF)>=PT_NUM || !sim->elements[parts[i].tmp&0xFF].Enabled) - parts[i].tmp &= ~0xFF; + if (TYP(parts[i].tmp)>=PT_NUM || !sim->elements[TYP(parts[i].tmp)].Enabled) + parts[i].tmp &= ~PMAPMASK; if (parts[i].tmp & PPIP_TMPFLAG_TRIGGERS) { int pause_changed = 0; @@ -193,23 +193,23 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if(!r) r = sim->photons[y+ry][x+rx]; - if (surround_space && !r && (parts[i].tmp&0xFF)!=0) //creating at end + if (surround_space && !r && TYP(parts[i].tmp)!=0) //creating at end { - np = sim->create_part(-1,x+rx,y+ry,parts[i].tmp&0xFF); + np = sim->create_part(-1, x+rx, y+ry, TYP(parts[i].tmp)); if (np!=-1) { transfer_pipe_to_part(sim, parts+i, parts+np); } } //try eating particle at entrance - else if ((parts[i].tmp&0xFF) == 0 && (sim->elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) + else if (TYP(parts[i].tmp) == 0 && (sim->elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) { if (TYP(r)==PT_SOAP) Element_SOAP::detach(sim, ID(r)); transfer_part_to_pipe(parts+(ID(r)), parts+i); sim->kill_part(ID(r)); } - else if ((parts[i].tmp&0xFF) == 0 && TYP(r)==PT_STOR && parts[ID(r)].tmp>0 && sim->IsValidElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) + else if (TYP(parts[i].tmp) == 0 && TYP(r)==PT_STOR && parts[ID(r)].tmp>0 && sim->IsValidElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) { // STOR stores properties in the same places as PIPE does transfer_pipe_to_pipe(parts+(ID(r)), parts+i); @@ -278,7 +278,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_PIPE static int graphics(GRAPHICS_FUNC_ARGS) int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS) { - int t = cpart->tmp & 0xFF; + int t = TYP(cpart->tmp); if (t>0 && tsim->elements[t].Enabled) { if (t == PT_STKM || t == PT_STKM2 || t == PT_FIGH) @@ -318,9 +318,9 @@ int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS) Element::defaultGraphics(ren, &tpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb); } } - //*colr = PIXR(elements[cpart->tmp&0xFF].pcolors); - //*colg = PIXG(elements[cpart->tmp&0xFF].pcolors); - //*colb = PIXB(elements[cpart->tmp&0xFF].pcolors); + //*colr = PIXR(elements[t].pcolors); + //*colg = PIXG(elements[t].pcolors); + //*colb = PIXB(elements[t].pcolors); } else { @@ -350,12 +350,12 @@ int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS) //#TPT-Directive ElementHeader Element_PIPE static void transfer_pipe_to_part(Simulation * sim, Particle *pipe, Particle *part) void Element_PIPE::transfer_pipe_to_part(Simulation * sim, Particle *pipe, Particle *part) { - part->type = (pipe->tmp & 0xFF); + part->type = TYP(pipe->tmp); part->temp = pipe->temp; part->life = pipe->tmp2; part->tmp = pipe->pavg[0]; part->ctype = pipe->pavg[1]; - pipe->tmp &= ~0xFF; + pipe->tmp &= ~PMAPMASK; if (!(sim->elements[part->type].Properties & TYPE_ENERGY)) { @@ -372,7 +372,7 @@ void Element_PIPE::transfer_pipe_to_part(Simulation * sim, Particle *pipe, Parti //#TPT-Directive ElementHeader Element_PIPE static void transfer_part_to_pipe(Particle *part, Particle *pipe) void Element_PIPE::transfer_part_to_pipe(Particle *part, Particle *pipe) { - pipe->tmp = (pipe->tmp&~0xFF) | part->type; + pipe->tmp = (pipe->tmp&~PMAPMASK) | part->type; pipe->temp = part->temp; pipe->tmp2 = part->life; pipe->pavg[0] = part->tmp; @@ -382,19 +382,19 @@ void Element_PIPE::transfer_part_to_pipe(Particle *part, Particle *pipe) //#TPT-Directive ElementHeader Element_PIPE static void transfer_pipe_to_pipe(Particle *src, Particle *dest) void Element_PIPE::transfer_pipe_to_pipe(Particle *src, Particle *dest) { - dest->tmp = (dest->tmp&~0xFF) | (src->tmp&0xFF); + dest->tmp = (dest->tmp&~PMAPMASK) | TYP(src->tmp); dest->temp = src->temp; dest->tmp2 = src->tmp2; dest->pavg[0] = src->pavg[0]; dest->pavg[1] = src->pavg[1]; - src->tmp &= ~0xFF; + src->tmp &= ~PMAPMASK; } //#TPT-Directive ElementHeader Element_PIPE static void pushParticle(Simulation * sim, int i, int count, int original) void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original) { int rndstore, rnd, rx, ry, r, x, y, np, q, notctype=(((sim->parts[i].ctype)%3)+2); - if ((sim->parts[i].tmp&0xFF) == 0 || count >= 2)//don't push if there is nothing there, max speed of 2 per frame + if (TYP(sim->parts[i].tmp) == 0 || count >= 2)//don't push if there is nothing there, max speed of 2 per frame return; x = (int)(sim->parts[i].x+0.5f); y = (int)(sim->parts[i].y+0.5f); @@ -415,7 +415,7 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original r = sim->pmap[y+ry][x+rx]; if (!r) continue; - else if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && sim->parts[ID(r)].ctype!=notctype && (sim->parts[ID(r)].tmp&0xFF)==0) + else if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && sim->parts[ID(r)].ctype!=notctype && TYP(sim->parts[ID(r)].tmp)==0) { transfer_pipe_to_pipe(sim->parts+i, sim->parts+(ID(r))); if (ID(r) > original) @@ -445,7 +445,7 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original { int coords = 7 - ((sim->parts[i].tmp>>10)&7); r = sim->pmap[y+ pos_1_ry[coords]][x+ pos_1_rx[coords]]; - if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && sim->parts[ID(r)].ctype!=notctype && (sim->parts[ID(r)].tmp&0xFF)==0) + if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && sim->parts[ID(r)].ctype!=notctype && TYP(sim->parts[ID(r)].tmp)==0) { transfer_pipe_to_pipe(sim->parts+i, sim->parts+(ID(r))); if (ID(r) > original) @@ -468,11 +468,11 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original break; } } - else if (TYP(r) == PT_NONE) //Move particles out of pipe automatically, much faster at ends + else if (!r) //Move particles out of pipe automatically, much faster at ends { rx = pos_1_rx[coords]; ry = pos_1_ry[coords]; - np = sim->create_part(-1,x+rx,y+ry,sim->parts[i].tmp&0xFF); + np = sim->create_part(-1,x+rx,y+ry,TYP(sim->parts[i].tmp)); if (np!=-1) { transfer_pipe_to_part(sim, sim->parts+i, sim->parts+np); diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp index 0b3eee34f..ce1fe41b3 100644 --- a/src/simulation/elements/PLNT.cpp +++ b/src/simulation/elements/PLNT.cpp @@ -48,16 +48,18 @@ Element_PLNT::Element_PLNT() Graphics = &Element_PLNT::graphics; } +#include //#TPT-Directive ElementHeader Element_PLNT static int update(UPDATE_FUNC_ARGS) int Element_PLNT::update(UPDATE_FUNC_ARGS) { int r, rx, ry, np, rndstore; + std::cout << PMAPBITS << ", " << PMAPMASK << std::endl; for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; - switch (r&0xFF) + switch (TYP(r)) { case PT_WATR: if (!(rand()%50)) diff --git a/src/simulation/elements/PPIP.cpp b/src/simulation/elements/PPIP.cpp index 7c5753dd0..a86f9d859 100644 --- a/src/simulation/elements/PPIP.cpp +++ b/src/simulation/elements/PPIP.cpp @@ -83,7 +83,7 @@ void Element_PPIP::flood_trigger(Simulation * sim, int x, int y, int sparkedBy) else if (sparkedBy==PT_NSCN) prop = PPIP_TMPFLAG_TRIGGER_OFF << 3; else if (sparkedBy==PT_INST) prop = PPIP_TMPFLAG_TRIGGER_REVERSE << 3; - if (prop==0 || (pmap[y][x]&0xFF)!=PT_PPIP || (parts[ID(pmap[y][x])].tmp & prop)) + if (prop==0 || TYP(pmap[y][x])!=PT_PPIP || (parts[ID(pmap[y][x])].tmp & prop)) return; coord_stack = new unsigned short[coord_stack_limit][2]; @@ -100,7 +100,7 @@ void Element_PPIP::flood_trigger(Simulation * sim, int x, int y, int sparkedBy) // go left as far as possible while (x1>=CELL) { - if ((pmap[y][x1-1]&0xFF)!=PT_PPIP) + if (TYP(pmap[y][x1-1]) != PT_PPIP) { break; } @@ -109,7 +109,7 @@ void Element_PPIP::flood_trigger(Simulation * sim, int x, int y, int sparkedBy) // go right as far as possible while (x2=CELL+1) for (x=x1-1; x<=x2+1; x++) - if ((pmap[y-1][x]&0xFF)==PT_PPIP && !(parts[ID(pmap[y-1][x])].tmp & prop)) + if (TYP(pmap[y-1][x]) == PT_PPIP && !(parts[ID(pmap[y-1][x])].tmp & prop)) { coord_stack[coord_stack_size][0] = x; coord_stack[coord_stack_size][1] = y-1; @@ -141,7 +141,7 @@ void Element_PPIP::flood_trigger(Simulation * sim, int x, int y, int sparkedBy) } if (ypv[y/CELL][x/CELL] -= .003f; int under = pmap[y][x]; - int utype = under & 0xFF; + int utype = TYP(under); int uID = ID(under); switch (utype) { @@ -150,7 +150,7 @@ int Element_PROT::update(UPDATE_FUNC_ARGS) } //collide with other protons to make heavier materials int ahead = sim->photons[y][x]; - if (ID(ahead) != i && (ahead&0xFF) == PT_PROT) + if (ID(ahead) != i && TYP(ahead) == PT_PROT) { float velocity1 = powf(parts[i].vx, 2.0f)+powf(parts[i].vy, 2.0f); float velocity2 = powf(parts[ID(ahead)].vx, 2.0f)+powf(parts[ID(ahead)].vy, 2.0f); diff --git a/src/simulation/elements/PSTN.cpp b/src/simulation/elements/PSTN.cpp index 5667fc211..5af614ad6 100644 --- a/src/simulation/elements/PSTN.cpp +++ b/src/simulation/elements/PSTN.cpp @@ -237,7 +237,7 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct for(int c = retract; c < MAX_FRAME; c++) { posY = stackY + (c*newY); posX = stackX + (c*newX); - if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && (sim->pmap[posY][posX]&0xFF) == PT_FRME) { + if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && TYP(sim->pmap[posY][posX]) == PT_FRME) { int spaces = CanMoveStack(sim, posX, posY, realDirectionX, realDirectionY, maxSize, amount, retract, block).spaces; if(spaces < amount) amount = spaces; @@ -249,7 +249,7 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct for(int c = 1; c < MAX_FRAME; c++) { posY = stackY - (c*newY); posX = stackX - (c*newX); - if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && (sim->pmap[posY][posX]&0xFF) == PT_FRME) { + if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && TYP(sim->pmap[posY][posX]) == PT_FRME) { int spaces = CanMoveStack(sim, posX, posY, realDirectionX, realDirectionY, maxSize, amount, retract, block).spaces; if(spaces < amount) amount = spaces; diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index de55943fc..34219f2dc 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -590,7 +590,7 @@ void Element_STKM::STKM_interact(Simulation *sim, playerst *playerp, int i, int } if (sim->elements[TYP(r)].Properties&PROP_DEADLY) - switch (r&0xFF) + switch (TYP(r)) { case PT_ACID: sim->parts[i].life -= 5; diff --git a/src/simulation/elements/STOR.cpp b/src/simulation/elements/STOR.cpp index e3bcc2730..2ce2a9180 100644 --- a/src/simulation/elements/STOR.cpp +++ b/src/simulation/elements/STOR.cpp @@ -75,7 +75,7 @@ int Element_STOR::update(UPDATE_FUNC_ARGS) { for(ry1 = 1; ry1 >= -1; ry1--){ for(rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1){ // Oscillate the X starting at 0, 1, -1, 3, -5, etc (Though stop at -1) - np = sim->create_part(-1,x+rx1,y+ry1,parts[i].tmp&0xFF); + np = sim->create_part(-1,x+rx1,y+ry1,TYP(parts[i].tmp)); if (np!=-1) { parts[np].temp = parts[i].temp; diff --git a/src/simulation/elements/SWCH.cpp b/src/simulation/elements/SWCH.cpp index 8d4d0038e..4c21b2cef 100644 --- a/src/simulation/elements/SWCH.cpp +++ b/src/simulation/elements/SWCH.cpp @@ -47,7 +47,7 @@ Element_SWCH::Element_SWCH() bool isRedBRAY(UPDATE_FUNC_ARGS, int xc, int yc) { - return (pmap[yc][xc]&0xFF) == PT_BRAY && parts[ID(pmap[yc][xc])].tmp == 2; + return TYP(pmap[yc][xc]) == PT_BRAY && parts[ID(pmap[yc][xc])].tmp == 2; } //#TPT-Directive ElementHeader Element_SWCH static int update(UPDATE_FUNC_ARGS) @@ -83,7 +83,7 @@ int Element_SWCH::update(UPDATE_FUNC_ARGS) } } //turn SWCH on/off from two red BRAYS. There must be one either above or below, and one either left or right to work, and it can't come from the side, it must be a diagonal beam - if (!(pmap[y-1][x-1]&0xFF) && !(pmap[y-1][x+1]&0xFF) && (isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x, y-1) || isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x, y+1)) && (isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x+1, y) || isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x-1, y))) + if (!TYP(pmap[y-1][x-1]) && !TYP(pmap[y-1][x+1]) && (isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x, y-1) || isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x, y+1)) && (isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x+1, y) || isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x-1, y))) { if (parts[i].life == 10) parts[i].life = 9; diff --git a/src/simulation/elements/TTAN.cpp b/src/simulation/elements/TTAN.cpp index 5cc970a1c..1241a5921 100644 --- a/src/simulation/elements/TTAN.cpp +++ b/src/simulation/elements/TTAN.cpp @@ -48,22 +48,24 @@ Element_TTAN::Element_TTAN() //#TPT-Directive ElementHeader Element_TTAN static int update(UPDATE_FUNC_ARGS) int Element_TTAN::update(UPDATE_FUNC_ARGS) { - int rx, ry, ttan = 0; - if(nt<=2) + int ttan = 0; + if (nt <= 2) ttan = 2; - else if(parts[i].tmp) + else if (parts[i].tmp) ttan = 2; - else if(nt<=6) - for (rx=-1; rx<2; rx++) { - for (ry=-1; ry<2; ry++) { - if ((!rx != !ry) && BOUNDS_CHECK) { - if((pmap[y+ry][x+rx]&0xFF)==PT_TTAN) + else if (nt <= 6) + { + for (int rx = -1; rx <= 1; rx++) + for (int ry = -1; ry <= 1; ry++) + if ((!rx != !ry) && BOUNDS_CHECK) + { + if (TYP(pmap[y+ry][x+rx]) == PT_TTAN) ttan++; } - } - } + } - if(ttan>=2) { + if (ttan >= 2) + { sim->air->bmap_blockair[y/CELL][x/CELL] = 1; sim->air->bmap_blockairh[y/CELL][x/CELL] = 0x8; } diff --git a/src/simulation/elements/VIRS.cpp b/src/simulation/elements/VIRS.cpp index 6da928eeb..07a0f46d6 100644 --- a/src/simulation/elements/VIRS.cpp +++ b/src/simulation/elements/VIRS.cpp @@ -128,7 +128,7 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS) rndstore >>= 3; } //protons make VIRS last forever - else if ((sim->photons[y+ry][x+rx]&0xFF) == PT_PROT) + else if (TYP(sim->photons[y+ry][x+rx]) == PT_PROT) { parts[i].pavg[1] = 0; }