From 74387040a1b616de6f744e4137cff72880b580d8 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Wed, 20 Feb 2013 18:36:00 -0500 Subject: [PATCH] fix CRAY INST mode ignoring length, fix CRAY going ignoring walls, fix CRAY + GOL particles, allow CRAY to create sparks --- src/simulation/Simulation.cpp | 34 ++++++++++++++++++++++++++++++-- src/simulation/Simulation.h | 1 + src/simulation/elements/CRAY.cpp | 29 ++++++++++++++------------- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index a9d1b622a..0780bea4c 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1995,6 +1995,31 @@ void Simulation::clear_sim(void) } SetEdgeMode(edgeMode); } + +bool Simulation::IsObsticle(int x, int y, int type) +{ + if (pmap[y][x])// && (type != PT_SPRK || !(elements[pmap[y][x]&0xFF].Properties & PROP_CONDUCTS))) + return true; + + if (bmap[y/CELL][x/CELL]) + { + int wall = bmap[y/CELL][x/CELL]; + if (wall == WL_ALLOWGAS && !(elements[type].Properties&TYPE_GAS)) + return true; + else if (wall == WL_ALLOWENERGY && !(elements[type].Properties&TYPE_ENERGY)) + return true; + else if (wall == WL_ALLOWLIQUID && elements[type].Falldown!=2) + return true; + else if (wall == WL_ALLOWSOLID && elements[type].Falldown!=1) + return true; + else if (wall == WL_ALLOWAIR || wall == WL_WALL || wall == WL_WALLELEC) + return true; + else if (wall == WL_EWALL && !emap[y/CELL][x/CELL]) + return true; + } + return false; +} + void Simulation::init_can_move() { // can_move[moving type][type at destination] @@ -2818,11 +2843,10 @@ int Simulation::create_part(int p, int x, int y, int tv) drawOn==PT_CLNE || drawOn==PT_BCLN || drawOn==PT_CONV || - drawOn==PT_CRAY || (drawOn==PT_PCLN&&t!=PT_PSCN&&t!=PT_NSCN) || (drawOn==PT_PBCN&&t!=PT_PSCN&&t!=PT_NSCN) )&&( - t != PT_CLNE && t != PT_CRAY && t != PT_PCLN && t != PT_BCLN && t != PT_STKM && t != PT_STKM2 && t != PT_PBCN && t != PT_STOR && t != PT_FIGH && t != PT_CONV) + t != PT_CLNE && t != PT_PCLN && t != PT_BCLN && t != PT_STKM && t != PT_STKM2 && t != PT_PBCN && t != PT_STOR && t != PT_FIGH && t != PT_CONV) ) { parts[pmap[y][x]>>8].ctype = t; @@ -2834,6 +2858,12 @@ int Simulation::create_part(int p, int x, int y, int tv) if (t==PT_LIFE && v>8].tmp = v; } + else if (drawOn == PT_CRAY && drawOn != t && drawOn != PT_PSCN && drawOn != PT_INST && drawOn != PT_METL) + { + parts[pmap[y][x]>>8].ctype = t; + if (t==PT_LIFE && v>8].tmp2 = v; + } return -1; } if (photons[y][x] && (elements[t].Properties & TYPE_ENERGY)) diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index e9a1504e5..fd65f8252 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -138,6 +138,7 @@ public: TPT_NO_INLINE int try_move(int i, int x, int y, int nx, int ny); TPT_NO_INLINE int eval_move(int pt, int nx, int ny, unsigned *rr); void init_can_move(); + bool IsObsticle(int x, int y, int type); void create_cherenkov_photon(int pp); void create_gain_photon(int pp); TPT_NO_INLINE void kill_part(int i); diff --git a/src/simulation/elements/CRAY.cpp b/src/simulation/elements/CRAY.cpp index 0638f736a..f0c0c9f68 100644 --- a/src/simulation/elements/CRAY.cpp +++ b/src/simulation/elements/CRAY.cpp @@ -50,8 +50,9 @@ Element_CRAY::Element_CRAY() int Element_CRAY::update(UPDATE_FUNC_ARGS) { int r, nxx, nyy, docontinue, nxi, nyi, rx, ry, nr, ry1, rx1, partsRemaining = 255; - if (parts[i].tmp) + if (parts[i].tmp) //how far it shoots partsRemaining = parts[i].tmp; + // 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++) @@ -63,12 +64,12 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((r&0xFF)!=PT_CRAY && (r&0xFF)>8].life==3) { + if ((r&0xFF)==PT_SPRK && parts[r>>8].life==3) { //spark found, start creating int destroy = (parts[r>>8].ctype==PT_PSCN)?1:0; int nostop = (parts[r>>8].ctype==PT_INST)?1:0; for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi) { @@ -85,24 +86,24 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS) break; } r = pmap[y+nyi+nyy][x+nxi+nxx]; - if (!r) { - int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype); + if (!sim->IsObsticle(x+nxi+nxx, y+nyi+nyy, parts[i].ctype) || (parts[i].ctype == PT_SPRK && sim->elements[r&0xFF].Properties & PROP_CONDUCTS) && !destroy) { // 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); if (nr!=-1) { parts[nr].dcolour = colored; - if(!--partsRemaining) - docontinue = 0; } - } else if ((r&0xFF)==PT_FILT) {//get color if passed through FILT + } else if ((r&0xFF)==PT_FILT) { // get color if passed through FILT colored = wavelengthToDecoColour(parts[r>>8].ctype); - } else if ((r&0xFF)==PT_CRAY || nostop) { - docontinue = 1; } else if(destroy && ((r&0xFF) != PT_DMND)) { sim->kill_part(r>>8); - if(!--partsRemaining) - docontinue = 0; - } else { + } else if ((r&0xFF) != PT_CRAY && !nostop) { docontinue = 0; } + if(!--partsRemaining) + docontinue = 0; } } }