From b318c3721a43de9789efc6c286b41566649f5252 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 20 Aug 2012 16:48:03 +0100 Subject: TPT: Powered pipe, based on jacob1's commits diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 53366b0..002433e 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -832,6 +832,13 @@ void GameSave::readOPS(char * data, int dataLength) { if(i >= partsDataLen) goto fail; particles[newIndex].tmp |= (((unsigned)partsData[i++]) << 8); + //Read 3rd and 4th bytes + if(fieldDescriptor & 0x1000) + { + if(i+1 >= partsDataLen) goto fail; + particles[newIndex].tmp |= (((unsigned)partsData[i++]) << 16); + particles[newIndex].tmp |= (((unsigned)partsData[i++]) << 24); + } } } @@ -1795,6 +1802,12 @@ char * GameSave::serialiseOPS(int & dataLength) { fieldDesc |= 1 << 4; partsData[partsDataLen++] = particles[i].tmp >> 8; + if(particles[i].tmp > 65535) + { + fieldDesc |= 1 << 12; + partsData[partsDataLen++] = (particles[i].tmp&0xFF000000)>>24; + partsData[partsDataLen++] = (particles[i].tmp&0x00FF0000)>>16; + } } } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 50d4cb5..2db746a 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -105,6 +105,7 @@ int Simulation::Load(int fullX, int fullY, GameSave * save) } parts_lastActiveIndex = NPART-1; force_stacking_check = 1; + Element_PPIP::ppip_changed = 1; for(int i = 0; i < save->signs.size() && signs.size() < MAXSIGNS; i++) { sign tempSign = save->signs[i]; @@ -2810,6 +2811,7 @@ int Simulation::create_part(int p, int x, int y, int tv) case PT_FRZW: parts[i].life = 100; break; + case PT_PPIP: case PT_PIPE: parts[i].life = 60; break; @@ -3251,6 +3253,20 @@ void Simulation::update_particles_i(int start, int inc) } } } + + if (Element_PPIP::ppip_changed) + { + for (i=0; i<=parts_lastActiveIndex; i++) + { + if (parts[i].type==PT_PPIP) + { + parts[i].tmp |= (parts[i].tmp&0xE0000000)>>3; + parts[i].tmp &= ~0xE0000000; + } + } + Element_PPIP::ppip_changed = 0; + } + //game of life! if (elementCount[PT_LIFE]>0&&++CGOL>=GSPEED)//GSPEED is frames per generation { @@ -4014,7 +4030,7 @@ killed: } r = pmap[fin_y][fin_x]; - if ((r & 0xFF) == PT_PIPE && !(parts[r>>8].tmp&0xFF)) + if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && !(parts[r>>8].tmp&0xFF)) { parts[r>>8].tmp = (parts[r>>8].tmp&~0xFF) | parts[i].type; parts[r>>8].temp = parts[i].temp; diff --git a/src/simulation/elements/BRCK.cpp b/src/simulation/elements/BRCK.cpp index b730418..6afcdb5 100644 --- a/src/simulation/elements/BRCK.cpp +++ b/src/simulation/elements/BRCK.cpp @@ -43,7 +43,18 @@ Element_BRCK::Element_BRCK() HighTemperatureTransition = PT_LAVA; Update = NULL; - + Graphics = &Element_BRCK::graphics; +} + +//#TPT-Directive ElementHeader Element_BRCK static int graphics(GRAPHICS_FUNC_ARGS) +int Element_BRCK::graphics(GRAPHICS_FUNC_ARGS) +{ + if (cpart->tmp == 1) + { + *pixel_mode |= PMODE_GLOW; + *colb += 100; + } + return 0; } Element_BRCK::~Element_BRCK() {} \ No newline at end of file diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 6bbc2cd..d645a29 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -2,51 +2,66 @@ //#TPT-Directive ElementClass Element_PIPE PT_PIPE 99 Element_PIPE::Element_PIPE() { - Identifier = "DEFAULT_PT_PIPE"; - Name = "PIPE"; - Colour = PIXPACK(0x444444); - MenuVisible = 1; - MenuSection = SC_SOLIDS; - Enabled = 1; - - Advection = 0.0f; - AirDrag = 0.00f * CFDS; - AirLoss = 0.95f; - Loss = 0.00f; - Collision = 0.0f; - Gravity = 0.0f; - Diffusion = 0.00f; - HotAir = 0.000f * CFDS; - Falldown = 0; - - Flammable = 0; - Explosive = 0; - Meltable = 0; - Hardness = 0; - - Weight = 100; - - Temperature = 273.15f; - HeatConduct = 0; - Description = "Moves elements around, read FAQ on website for help."; - - State = ST_SOLID; - Properties = TYPE_SOLID|PROP_LIFE_DEC; - - LowPressure = IPL; - LowPressureTransition = NT; - HighPressure = 10.0f; - HighPressureTransition = PT_BRMT; - LowTemperature = ITL; - LowTemperatureTransition = NT; - HighTemperature = ITH; - HighTemperatureTransition = NT; - - Update = &Element_PIPE::update; - Graphics = &Element_PIPE::graphics; + Identifier = "DEFAULT_PT_PIPE"; + Name = "PIPE"; + Colour = PIXPACK(0x444444); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.95f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = 273.15f; + HeatConduct = 0; + Description = "Moves elements around, read FAQ on website for help."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 10.0f; + HighPressureTransition = PT_BRMT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PIPE::update; + Graphics = &Element_PIPE::graphics; } #define PFLAG_NORMALSPEED 0x00010000 +// parts[].tmp flags +// trigger flags to be processed this frame (trigger flags for next frame are shifted 3 bits to the left): +#define PPIP_TMPFLAG_TRIGGER_ON 0x10000000 +#define PPIP_TMPFLAG_TRIGGER_OFF 0x08000000 +#define PPIP_TMPFLAG_TRIGGER_REVERSE 0x04000000 +#define PPIP_TMPFLAG_TRIGGERS 0x1C000000 +// current status of the pipe +#define PPIP_TMPFLAG_PAUSED 0x02000000 +#define PPIP_TMPFLAG_REVERSED 0x01000000 +// 0x000000FF element +// 0x00000100 is single pixel pipe +// 0x00000200 will transfer like a single pixel pipe when in forward mode +// 0x00001C00 forward single pixel pipe direction +// 0x00002000 will transfer like a single pixel pipe when in reverse mode +// 0x0001C000 reverse single pixel pipe direction signed char pos_1_rx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; signed char pos_1_ry[] = {-1, 0, 1,-1, 1,-1, 0, 1}; @@ -56,7 +71,61 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) { int r, rx, ry, np; int rnd, rndstore; - if (parts[i].ctype>=2 && parts[i].ctype<=4) + if (parts[i].tmp & PPIP_TMPFLAG_TRIGGERS) + { + int pause_changed = 0; + if (parts[i].tmp & PPIP_TMPFLAG_TRIGGER_ON) // TRIGGER_ON overrides TRIGGER_OFF + { + if (parts[i].tmp & PPIP_TMPFLAG_PAUSED) + pause_changed = 1; + parts[i].tmp &= ~PPIP_TMPFLAG_PAUSED; + } + else if (parts[i].tmp & PPIP_TMPFLAG_TRIGGER_OFF) + { + if (!(parts[i].tmp & PPIP_TMPFLAG_PAUSED)) + pause_changed = 1; + parts[i].tmp |= PPIP_TMPFLAG_PAUSED; + } + if (pause_changed) + { + int rx, ry, r; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + { + if (x+rx>=0 && y+ry>0 && x+rx>8].tmp = 0; + else + parts[r>>8].tmp = 1; //make surrounding BRCK glow + } + } + } + } + + if (parts[i].tmp & PPIP_TMPFLAG_TRIGGER_REVERSE) + { + parts[i].tmp ^= PPIP_TMPFLAG_REVERSED; + if (parts[i].ctype == 2) //Switch colors so it goes in reverse + parts[i].ctype = 4; + else if (parts[i].ctype == 4) + parts[i].ctype = 2; + if (parts[i].tmp & 0x100) //Switch one pixel pipe direction + { + int coords = (parts[i].tmp>>13)&0xF; + int coords2 = (parts[i].tmp>>9)&0xF; + parts[i].tmp &= ~0x1FE00; + parts[i].tmp |= coords<<9; + parts[i].tmp |= coords2<<13; + } + } + + parts[i].tmp &= ~PPIP_TMPFLAG_TRIGGERS; + } + if (parts[i].ctype>=2 && parts[i].ctype<=4 && !(parts[i].tmp & PPIP_TMPFLAG_PAUSED)) { if (parts[i].life==3) { @@ -71,7 +140,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((r&0xFF)==PT_PIPE&&parts[r>>8].ctype==1) + if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP)&&parts[r>>8].ctype==1) { parts[r>>8].ctype = (((parts[i].ctype)%3)+2);//reverse parts[r>>8].life = 6; @@ -79,11 +148,13 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) { parts[r>>8].tmp |= 0x200;//will transfer to a single pixel pipe parts[r>>8].tmp |= count<<10;//coords of where it came from + parts[i].tmp |= ((7-count)<<14); + parts[i].tmp |= 0x2000; } neighborcount ++; lastneighbor = r>>8; } - else if ((r&0xFF)==PT_PIPE&&parts[r>>8].ctype!=(((parts[i].ctype-1)%3)+2)) + else if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP)&&parts[r>>8].ctype!=(((parts[i].ctype-1)%3)+2)) { neighborcount ++; lastneighbor = r>>8; @@ -95,7 +166,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) } else { - if (parts[i].flags&PFLAG_NORMALSPEED)//skip particle push to prevent particle number being higher causeing speed up + if (parts[i].flags&PFLAG_NORMALSPEED)//skip particle push to prevent particle number being higher causing speed up { parts[i].flags &= ~PFLAG_NORMALSPEED; } @@ -121,11 +192,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) np = sim->create_part(-1,x+rx,y+ry,parts[i].tmp&0xFF); if (np!=-1) { - parts[np].temp = parts[i].temp;//pipe saves temp and life now - parts[np].life = parts[i].tmp2; - parts[np].tmp = parts[i].pavg[0]; - parts[np].ctype = parts[i].pavg[1]; - parts[i].tmp &= ~0xFF; + transfer_pipe_to_part(parts+i, parts+np); } } //try eating particle at entrance @@ -133,22 +200,13 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) { if ((r&0xFF)==PT_SOAP) sim->detach(r>>8); - parts[i].tmp = (parts[i].tmp&~0xFF) | parts[r>>8].type; - parts[i].temp = parts[r>>8].temp; - parts[i].tmp2 = parts[r>>8].life; - parts[i].pavg[0] = parts[r>>8].tmp; - parts[i].pavg[1] = parts[r>>8].ctype; + transfer_part_to_pipe(parts+(r>>8), parts+i); sim->kill_part(r>>8); } else if ((parts[i].tmp&0xFF) == 0 && (r&0xFF)==PT_STOR && parts[r>>8].tmp && (sim->elements[parts[r>>8].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) { - parts[i].tmp = parts[r>>8].tmp; - parts[i].temp = parts[r>>8].temp; - parts[i].tmp2 = parts[r>>8].tmp2; - parts[i].pavg[0] = parts[r>>8].pavg[0]; - parts[i].pavg[1] = parts[r>>8].pavg[1]; - parts[r>>8].tmp = 0; - parts[r>>8].life = 0; + // STOR stores properties in the same places as PIPE does + transfer_pipe_to_pipe(parts+(r>>8), parts+i); } } } @@ -184,7 +242,11 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) - sim->create_part(-1,x+rx,y+ry,PT_BRCK);//BRCK border, people didn't like DMND + { + int index = sim->create_part(-1,x+rx,y+ry,PT_BRCK);//BRCK border, people didn't like DMND + if (parts[i].type == PT_PPIP && index != -1) + parts[index].tmp = 1; + } } } if (parts[i].life<=1) @@ -211,11 +273,11 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) if (x+rx>=0 && y+ry>0 && x+rxgraphicscache[t].isready) { *pixel_mode = ren->graphicscache[t].pixel_mode; + *cola = ren->graphicscache[t].cola; *colr = ren->graphicscache[t].colr; *colg = ren->graphicscache[t].colg; *colb = ren->graphicscache[t].colb; @@ -259,8 +322,8 @@ int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS) else { *colr = PIXR(ren->sim->elements[t].Colour); - *colg = PIXR(ren->sim->elements[t].Colour); - *colb = PIXR(ren->sim->elements[t].Colour); + *colg = PIXG(ren->sim->elements[t].Colour); + *colb = PIXB(ren->sim->elements[t].Colour); if (ren->sim->elements[t].Graphics) { (*(ren->sim->elements[t].Graphics))(ren, &tpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb); @@ -319,6 +382,44 @@ int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_PIPE static void transfer_pipe_to_part(Particle *pipe, Particle *part) +void Element_PIPE::transfer_pipe_to_part(Particle *pipe, Particle *part) +{ + part->type = (pipe->tmp & 0xFF); + part->temp = pipe->temp; + part->life = pipe->tmp2; + part->tmp = pipe->pavg[0]; + part->ctype = pipe->pavg[1]; + pipe->tmp &= ~0xFF; + + part->vx = 0.0f; + part->vy = 0.0f; + part->tmp2 = 0; + part->flags = 0; + part->dcolour = 0; +} + +//#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->temp = part->temp; + pipe->tmp2 = part->life; + pipe->pavg[0] = part->tmp; + pipe->pavg[1] = part->ctype; +} + +//#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->temp = src->temp; + dest->tmp2 = src->tmp2; + dest->pavg[0] = src->pavg[0]; + dest->pavg[1] = src->pavg[1]; + src->tmp &= ~0xFF; +} + //#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) { @@ -333,7 +434,7 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original rndstore = rand(); // RAND_MAX is at least 32767 on all platforms i.e. pow(8,5)-1 // so can go 5 cycles without regenerating rndstore - for (q=0; q<3; q++)//try to push twice + for (q=0; q<3; q++)//try to push 3 times { rnd = rndstore&7; rndstore = rndstore>>3; @@ -344,19 +445,25 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original r = sim->pmap[y+ry][x+rx]; if (!r) continue; - else if ((r&0xFF)==PT_PIPE && sim->parts[r>>8].ctype!=notctype && (sim->parts[r>>8].tmp&0xFF)==0) + else if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && sim->parts[r>>8].ctype!=notctype && (sim->parts[r>>8].tmp&0xFF)==0) { - sim->parts[r>>8].tmp = (sim->parts[r>>8].tmp&~0xFF) | (sim->parts[i].tmp&0xFF); - sim->parts[r>>8].temp = sim->parts[i].temp; - sim->parts[r>>8].tmp2 = sim->parts[i].tmp2; - sim->parts[r>>8].pavg[0] = sim->parts[i].pavg[0]; - sim->parts[r>>8].pavg[1] = sim->parts[i].pavg[1]; + transfer_pipe_to_pipe(sim->parts+i, sim->parts+(r>>8)); if (r>>8 > original) sim->parts[r>>8].flags |= PFLAG_NORMALSPEED;//skip particle push, normalizes speed - sim->parts[i].tmp &= ~0xFF; count++; pushParticle(sim, r>>8,count,original); } + else if ((r&0xFF) == PT_PRTI) //Pass particles into PRTI for a pipe speed increase + { + int nnx; + for (nnx=0; nnx<80; nnx++) + if (!sim->portalp[sim->parts[r>>8].tmp][count][nnx].type) + { + transfer_pipe_to_part(sim->parts+i, &(sim->portalp[sim->parts[r>>8].tmp][count][nnx])); + count++; + break; + } + } } } } @@ -364,23 +471,35 @@ 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 (!r) - { - } - else if ((r&0xFF)==PT_PIPE && sim->parts[r>>8].ctype!=notctype && (sim->parts[r>>8].tmp&0xFF)==0) + if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && sim->parts[r>>8].ctype!=notctype && (sim->parts[r>>8].tmp&0xFF)==0) { - sim->parts[r>>8].tmp = (sim->parts[r>>8].tmp&~0xFF) | (sim->parts[i].tmp&0xFF); - sim->parts[r>>8].temp = sim->parts[i].temp; - sim->parts[r>>8].tmp2 = sim->parts[i].tmp2; - sim->parts[r>>8].pavg[0] = sim->parts[i].pavg[0]; - sim->parts[r>>8].pavg[1] = sim->parts[i].pavg[1]; + transfer_pipe_to_pipe(sim->parts+i, sim->parts+(r>>8)); if (r>>8 > original) sim->parts[r>>8].flags |= PFLAG_NORMALSPEED;//skip particle push, normalizes speed - sim->parts[i].tmp &= ~0xFF; count++; pushParticle(sim, r>>8,count,original); } - + else if ((r&0xFF) == PT_PRTI) //Pass particles into PRTI for a pipe speed increase + { + int nnx; + for (nnx=0; nnx<80; nnx++) + if (!sim->portalp[sim->parts[r>>8].tmp][count][nnx].type) + { + transfer_pipe_to_part(sim->parts+i, &(sim->portalp[sim->parts[r>>8].tmp][count][nnx])); + count++; + break; + } + } + else if ((r&0xFF) == PT_NONE) //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); + if (np!=-1) + { + transfer_pipe_to_part(sim->parts+i, sim->parts+np); + } + } } return; diff --git a/src/simulation/elements/PPIP.cpp b/src/simulation/elements/PPIP.cpp new file mode 100644 index 0000000..03d0b82 --- /dev/null +++ b/src/simulation/elements/PPIP.cpp @@ -0,0 +1,160 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PPIP PT_PPIP 161 +Element_PPIP::Element_PPIP() +{ + Identifier = "DEFAULT_PT_PPIP"; + Name = "PPIP"; + Colour = PIXPACK(0x444466); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.95f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = 273.15f; + HeatConduct = 0; + Description = "Powered version of PIPE, use PSCN/NSCN to Activate/Deactivate."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 10.0f; + HighPressureTransition = PT_BRMT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PIPE::update; + Graphics = &Element_PIPE::graphics; +} + +#define PFLAG_NORMALSPEED 0x00010000 +// parts[].tmp flags +// trigger flags to be processed this frame (trigger flags for next frame are shifted 3 bits to the left): +#define PPIP_TMPFLAG_TRIGGER_ON 0x10000000 +#define PPIP_TMPFLAG_TRIGGER_OFF 0x08000000 +#define PPIP_TMPFLAG_TRIGGER_REVERSE 0x04000000 +#define PPIP_TMPFLAG_TRIGGERS 0x1C000000 +// current status of the pipe +#define PPIP_TMPFLAG_PAUSED 0x02000000 +#define PPIP_TMPFLAG_REVERSED 0x01000000 +// 0x000000FF element +// 0x00000100 is single pixel pipe +// 0x00000200 will transfer like a single pixel pipe when in forward mode +// 0x00001C00 forward single pixel pipe direction +// 0x00002000 will transfer like a single pixel pipe when in reverse mode +// 0x0001C000 reverse single pixel pipe direction + +//#TPT-Directive ElementHeader Element_PPIP static int ppip_changed +int Element_PPIP::ppip_changed = 0; + +//#TPT-Directive ElementHeader Element_PPIP static void flood_trigger(Simulation * sim, int x, int y, int sparkedBy) +void Element_PPIP::flood_trigger(Simulation * sim, int x, int y, int sparkedBy) +{ + int coord_stack_limit = XRES*YRES; + unsigned short (*coord_stack)[2]; + int coord_stack_size = 0; + int x1, x2; + + Particle * parts = sim->parts; + int (*pmap)[XRES] = sim->pmap; + + // Separate flags for on and off in case PPIP is sparked by PSCN and NSCN on the same frame + // - then PSCN can override NSCN and behaviour is not dependent on particle order + int prop = 0; + if (sparkedBy==PT_PSCN) prop = PPIP_TMPFLAG_TRIGGER_ON << 3; + 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[pmap[y][x]>>8].tmp & prop)) + return; + + coord_stack = new unsigned short[coord_stack_limit][2]; + coord_stack[coord_stack_size][0] = x; + coord_stack[coord_stack_size][1] = y; + coord_stack_size++; + + do + { + coord_stack_size--; + x = coord_stack[coord_stack_size][0]; + y = coord_stack[coord_stack_size][1]; + x1 = x2 = x; + // go left as far as possible + while (x1>=CELL) + { + if ((pmap[y][x1-1]&0xFF)!=PT_PPIP) + { + break; + } + x1--; + } + // go right as far as possible + while (x2>8].tmp & prop)) + ppip_changed = 1; + parts[pmap[y][x]>>8].tmp |= prop; + } + + // add adjacent pixels to stack + // +-1 to x limits to include diagonally adjacent pixels + // Don't need to check x bounds here, because already limited to [CELL, XRES-CELL] + if (y>=CELL+1) + for (x=x1-1; x<=x2+1; x++) + if ((pmap[y-1][x]&0xFF)==PT_PPIP && !(parts[pmap[y-1][x]>>8].tmp & prop)) + { + coord_stack[coord_stack_size][0] = x; + coord_stack[coord_stack_size][1] = y-1; + coord_stack_size++; + if (coord_stack_size>=coord_stack_limit) + { + delete[] coord_stack; + return; + } + } + if (y>8].tmp & prop)) + { + coord_stack[coord_stack_size][0] = x; + coord_stack[coord_stack_size][1] = y+1; + coord_stack_size++; + if (coord_stack_size>=coord_stack_limit) + { + delete[] coord_stack; + return; + } + } + } while (coord_stack_size>0); + delete[] coord_stack; +} + +Element_PPIP::~Element_PPIP() {} diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index 4cccdbb..cb8eff6 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -187,6 +187,11 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) else if (ct==PT_NSCN && parts[r>>8].tmp == 3) parts[r>>8].tmp = 1; } + if (rt == PT_PPIP && parts[i].life == 3 && pavg!=PT_INSL) + { + if (ct == PT_NSCN || ct == PT_PSCN || ct == PT_INST) + Element_PPIP::flood_trigger(sim, x+rx, y+ry, ct); + } // ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed -- cgit v0.9.2-21-gd62e