diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index b5e30f0e8..6d71b7445 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -363,6 +363,143 @@ SimulationSample Simulation::Get(int x, int y) #define PMAP_CMP_CONDUCTIVE(pmap, t) (((pmap)&0xFF)==(t) || (((pmap)&0xFF)==PT_SPRK && parts[(pmap)>>8].ctype==(t))) +int Simulation::FloodINST(int x, int y, int fullc, int cm) +{ + int c = fullc&0xFF; + int x1, x2, dy = (c=PT_NUM) + return 0; + + if (cm==-1) + { + if (c==0) + { + cm = pmap[y][x]&0xFF; + if (!cm) + return 0; + } + else + cm = 0; + } + + if ((pmap[y][x]&0xFF)!=cm) + return 1; + + 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)!=cm) + { + break; + } + x1--; + } + // go right as far as possible + while (x2=0) + created_something = 1; + } + + // add vertically adjacent pixels to stack + // (wire crossing for INST) + if (y>=CELL+1 && x1==x2 && + PMAP_CMP_CONDUCTIVE(pmap[y-1][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y-1][x1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y-1][x1+1], cm) && + !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y-2][x1], cm) && !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1+1], cm)) + { + // travelling vertically up, skipping a horizontal line + if ((pmap[y-2][x1]&0xFF)==cm) + { + coord_stack[coord_stack_size][0] = x1; + coord_stack[coord_stack_size][1] = y-2; + coord_stack_size++; + if (coord_stack_size>=coord_stack_limit) + return -1; + } + } + else if (y>=CELL+1) + { + for (x=x1; x<=x2; x++) + { + if ((pmap[y-1][x]&0xFF)==cm) + { + if (x==x1 || x==x2 || y>=YRES-CELL-1 || !PMAP_CMP_CONDUCTIVE(pmap[y+1][x], cm)) + { + // if at the end of a horizontal section, or if it's a T junction + 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) + return -1; + } + } + } + } + + if (y=coord_stack_limit) + return -1; + } + } + else if (y=coord_stack_limit) + return -1; + } + + } + } + } + } while (coord_stack_size>0); + free(coord_stack); + return created_something; +} + + int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) { int c = fullc&0xFF; @@ -375,9 +512,6 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) if (c==SPC_PROP) return 0; - if (cm==PT_INST&&co==PT_SPRK) - if ((pmap[y][x]&0xFF)==PT_SPRK) - return 0; if (cm==-1) { if (c==0) @@ -437,112 +571,31 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) // fill span for (x=x1; x<=x2; x++) { - if (cm==PT_INST&&co==PT_SPRK) - { - if (create_part(-1, x, y, fullc)>=0) - created_something = 1; - } - else - { - if (CreateParts(x, y, 0, 0, fullc, flags)) - created_something = 1; - } + if (CreateParts(x, y, 0, 0, fullc, flags)) + created_something = 1; } - // add vertically adjacent pixels to stack - if (cm==PT_INST&&co==PT_SPRK) - { - //wire crossing for INST - if (y>=CELL+1 && x1==x2 && - PMAP_CMP_CONDUCTIVE(pmap[y-1][x1-1], PT_INST) && PMAP_CMP_CONDUCTIVE(pmap[y-1][x1], PT_INST) && PMAP_CMP_CONDUCTIVE(pmap[y-1][x1+1], PT_INST) && - !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1-1], PT_INST) && PMAP_CMP_CONDUCTIVE(pmap[y-2][x1], PT_INST) && !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1+1], PT_INST)) - { - // travelling vertically up, skipping a horizontal line - if ((pmap[y-2][x1]&0xFF)==PT_INST) + if (y>=CELL+dy) + for (x=x1; x<=x2; x++) + if ((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm) { - coord_stack[coord_stack_size][0] = x1; - coord_stack[coord_stack_size][1] = y-2; + coord_stack[coord_stack_size][0] = x; + coord_stack[coord_stack_size][1] = y-dy; coord_stack_size++; if (coord_stack_size>=coord_stack_limit) return -1; } - } - else if (y>=CELL+1) - { - for (x=x1; x<=x2; x++) - { - if ((pmap[y-1][x]&0xFF)==PT_INST) - { - if (x==x1 || x==x2 || y>=YRES-CELL-1 || !PMAP_CMP_CONDUCTIVE(pmap[y+1][x], PT_INST)) - { - // if at the end of a horizontal section, or if it's a T junction - 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) - return -1; - } - } - } - } - if (y=coord_stack_limit) return -1; } - } - else if (y=coord_stack_limit) - return -1; - } - - } - } - } - } - else - { - if (y>=CELL+dy) - for (x=x1; x<=x2; x++) - if ((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm) - { - coord_stack[coord_stack_size][0] = x; - coord_stack[coord_stack_size][1] = y-dy; - coord_stack_size++; - if (coord_stack_size>=coord_stack_limit) - return -1; - } - if (y=coord_stack_limit) - return -1; - } - } } while (coord_stack_size>0); free(coord_stack); return created_something; diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 0e6c66f5c..b47fde6d4 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -160,6 +160,7 @@ public: void ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrush); void CreateBox(int x1, int y1, int x2, int y2, int c, int flags); + int FloodINST(int x, int y, int fullc, int cm); int FloodParts(int x, int y, int c, int cm, int bm, int flags); //Create particles from brush/mask int CreateParts(int positionX, int positionY, int c, Brush * cBrush); diff --git a/src/simulation/elements/FRZW.cpp b/src/simulation/elements/FRZW.cpp index 8ba954a14..5bdbb2129 100644 --- a/src/simulation/elements/FRZW.cpp +++ b/src/simulation/elements/FRZW.cpp @@ -28,7 +28,7 @@ Element_FRZW::Element_FRZW() Temperature = 120.0f; HeatConduct = 29; - Description = "FREEZE WATER"; + Description = "Freeze water. Hybrid liquid formed when Freeze powder melts."; State = ST_LIQUID; Properties = TYPE_LIQUID||PROP_LIFE_DEC; diff --git a/src/simulation/elements/FRZZ.cpp b/src/simulation/elements/FRZZ.cpp index 816267286..47a5c0f41 100644 --- a/src/simulation/elements/FRZZ.cpp +++ b/src/simulation/elements/FRZZ.cpp @@ -26,21 +26,21 @@ Element_FRZZ::Element_FRZZ() Weight = 50; - Temperature = 90.0f; + Temperature = 253.15f; HeatConduct = 46; - Description = "FREEZE"; + Description = "Freeze powder. When melted, forms ice that always cools. Spreads with regular water."; State = ST_SOLID; Properties = TYPE_PART; LowPressure = IPL; LowPressureTransition = NT; - HighPressure = IPH; - HighPressureTransition = NT; - LowTemperature = ITL; - LowTemperatureTransition = NT; - HighTemperature = ITH; - HighTemperatureTransition = NT; + HighPressure = 1.8f; + HighPressureTransition = PT_SNOW; + LowTemperature = 50.0f; + LowTemperatureTransition = PT_ICEI; + HighTemperature = 273.15; + HighTemperatureTransition = PT_WATR; Update = &Element_FRZZ::update; diff --git a/src/simulation/elements/ICEI.cpp b/src/simulation/elements/ICEI.cpp index 852b646a6..c1d4e544d 100644 --- a/src/simulation/elements/ICEI.cpp +++ b/src/simulation/elements/ICEI.cpp @@ -66,6 +66,8 @@ int Element_ICEI::update(UPDATE_FUNC_ARGS) sim->part_change_type(i,x,y,PT_SLTW); sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW); } + if (((r&0xFF)==PT_FRZZ) && (parts[i].ctype=PT_FRZW) && 1>(rand()%1000)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_ICEI); } return 0; } diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp index 91d29d0c8..62178af6f 100644 --- a/src/simulation/elements/PLNT.cpp +++ b/src/simulation/elements/PLNT.cpp @@ -73,7 +73,7 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS) sim->kill_part(r>>8); parts[i].life = rand()%60 + 60; } - else if ((r&0xFF)==PT_WOOD && (1>rand()%20) && abs(rx+ry)<=2 && sim->VINE_MODE) + else if ( ((r&0xFF)==PT_WOOD) && (1>rand()%20) && (abs(rx+ry)<=2) && (sim->VINE_MODE || parts[i].tmp==1) ) { int nnx = rand()%3 -1; int nny = rand()%3 -1; diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index feb825bee..e670caea8 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -243,7 +243,7 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) else if (rt==PT_INST) { if (parts[r>>8].life==0 && parts[i].life<4) { - sim->FloodParts(x+rx,y+ry,PT_SPRK,PT_INST,-1, 0);//spark the wire + sim->FloodINST(x+rx,y+ry,PT_SPRK,PT_INST);//spark the wire } } else if (parts[r>>8].life==0 && parts[i].life<4) { diff --git a/src/simulation/elements/VINE.cpp b/src/simulation/elements/VINE.cpp index 991dfc444..04c90bfd5 100644 --- a/src/simulation/elements/VINE.cpp +++ b/src/simulation/elements/VINE.cpp @@ -60,6 +60,7 @@ int Element_VINE::update(UPDATE_FUNC_ARGS) np = sim->create_part(-1,x+rx,y+ry,PT_VINE); if (np<0) return 0; parts[np].temp = parts[i].temp; + parts[i].tmp = 1; sim->part_change_type(i,x,y,PT_PLNT); } }