diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:44:09 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:44:09 (GMT) |
| commit | 058a2edd75debbd0297f92572316daa704bd379f (patch) | |
| tree | ad303f091f9a08b209b91eb34a9fcad996a3de69 /src/simulation/elements | |
| parent | e3594aba9e05c6865d396418c028049cda92c2f3 (diff) | |
| parent | 7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff) | |
| download | powder-058a2edd75debbd0297f92572316daa704bd379f.zip powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz | |
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/simulation/elements')
169 files changed, 17216 insertions, 0 deletions
diff --git a/src/simulation/elements/116.cpp b/src/simulation/elements/116.cpp new file mode 100644 index 0000000..9697c97 --- /dev/null +++ b/src/simulation/elements/116.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_116 PT_116 116 +Element_116::Element_116() +{ + Identifier = "DEFAULT_PT_116"; + Name = "EQVE"; + Colour = PIXPACK(0xFFE0A0); + MenuVisible = 0; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.96f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 85; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Shared velocity test"; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_116::~Element_116() {}
\ No newline at end of file diff --git a/src/simulation/elements/146.cpp b/src/simulation/elements/146.cpp new file mode 100644 index 0000000..51f4d3b --- /dev/null +++ b/src/simulation/elements/146.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_146 PT_146 146 +Element_146::Element_146() +{ + Identifier = "DEFAULT_PT_146"; + Name = "BRAN"; + Colour = PIXPACK(0xCCCC00); + MenuVisible = 0; + MenuSection = SC_LIFE; + Enabled = 0; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 9000.0f; + HeatConduct = 40; + Description = "Brian 6 S6/B246/3"; + + State = ST_NONE; + Properties = TYPE_SOLID|PROP_LIFE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_146::~Element_146() {}
\ No newline at end of file diff --git a/src/simulation/elements/ACEL.cpp b/src/simulation/elements/ACEL.cpp new file mode 100644 index 0000000..8dfad79 --- /dev/null +++ b/src/simulation/elements/ACEL.cpp @@ -0,0 +1,85 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ACEL PT_ACEL 137 +Element_ACEL::Element_ACEL() +{ + Identifier = "DEFAULT_PT_ACEL"; + Name = "ACEL"; + Colour = PIXPACK(0x0099CC); + MenuVisible = 1; + MenuSection = SC_FORCE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Accelerator"; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_ACEL::update; + Graphics = &Element_ACEL::graphics; +} + +//#TPT-Directive ElementHeader Element_ACEL static int update(UPDATE_FUNC_ARGS) +int Element_ACEL::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + parts[i].tmp = 0; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry) && !(rx && ry)) + { + r = pmap[y+ry][x+rx]; + if(!r) + r = sim->photons[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + continue; + if(sim->elements[r&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) + { + parts[r>>8].vx *= 1.1f; + parts[r>>8].vy *= 1.1f; + parts[i].tmp = 1; + } + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_ACEL static int graphics(GRAPHICS_FUNC_ARGS) +int Element_ACEL::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(cpart->tmp) + *pixel_mode |= PMODE_GLOW; + return 0; +} + + +Element_ACEL::~Element_ACEL() {}
\ No newline at end of file diff --git a/src/simulation/elements/ACID.cpp b/src/simulation/elements/ACID.cpp new file mode 100644 index 0000000..fb6cb81 --- /dev/null +++ b/src/simulation/elements/ACID.cpp @@ -0,0 +1,144 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ACID PT_ACID 21 +Element_ACID::Element_ACID() +{ + Identifier = "DEFAULT_PT_ACID"; + Name = "ACID"; + Colour = PIXPACK(0xED55FF); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 40; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 10; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 34; + Description = "Dissolves almost everything."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_DEADLY; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_ACID::update; + Graphics = &Element_ACID::graphics; +} + +//#TPT-Directive ElementHeader Element_ACID static int update(UPDATE_FUNC_ARGS) +int Element_ACID::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, trade, np; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_ACID && (r&0xFF)!=PT_CAUS) + { + if ((r&0xFF)==PT_PLEX || (r&0xFF)==PT_NITR || (r&0xFF)==PT_GUNP || (r&0xFF)==PT_RBDM || (r&0xFF)==PT_LRBD) + { + sim->part_change_type(i,x,y,PT_FIRE); + sim->part_change_type(r>>8,x+rx,y+ry,PT_FIRE); + parts[i].life = 4; + parts[r>>8].life = 4; + } + else if ((r&0xFF)==PT_WTRV) + { + if(!(rand()%250)) + { + sim->part_change_type(i, x, y, PT_CAUS); + parts[i].life = (rand()%50)+25; + sim->kill_part(r>>8); + } + } + else if (((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && sim->elements[r&0xFF].Hardness>(rand()%1000))&&parts[i].life>=50) + { + if (sim->parts_avg(i, r>>8,PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid + { + float newtemp = ((60.0f-(float)sim->elements[r&0xFF].Hardness))*7.0f; + if(newtemp < 0){ + newtemp = 0; + } + parts[i].temp += newtemp; + parts[i].life--; + sim->kill_part(r>>8); + } + } + else if (parts[i].life<=50) + { + sim->kill_part(i); + return 1; + } + } + } + for ( trade = 0; trade<2; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + continue; + if ((r&0xFF)==PT_ACID&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion + { + int temp = parts[i].life - parts[r>>8].life; + if (temp ==1) + { + parts[r>>8].life ++; + parts[i].life --; + } + else if (temp>0) + { + parts[r>>8].life += temp/2; + parts[i].life -= temp/2; + } + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_ACID static int graphics(GRAPHICS_FUNC_ARGS) +int Element_ACID::graphics(GRAPHICS_FUNC_ARGS) + +{ + int s = cpart->life; + if (s>75) s = 75; //These two should not be here. + if (s<49) s = 49; + s = (s-49)*3; + if (s==0) s = 1; + *colr += s*4; + *colg += s*1; + *colb += s*2; + *pixel_mode |= PMODE_BLUR; + return 0; +} + + +Element_ACID::~Element_ACID() {}
\ No newline at end of file diff --git a/src/simulation/elements/AMTR.cpp b/src/simulation/elements/AMTR.cpp new file mode 100644 index 0000000..ff25bb6 --- /dev/null +++ b/src/simulation/elements/AMTR.cpp @@ -0,0 +1,79 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_AMTR PT_AMTR 72 +Element_AMTR::Element_AMTR() +{ + Identifier = "DEFAULT_PT_AMTR"; + Name = "AMTR"; + Colour = PIXPACK(0x808080); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.96f; + Loss = 0.80f; + Collision = 0.00f; + Gravity = 0.10f; + Diffusion = 1.00f; + HotAir = 0.0000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Anti-Matter, Destroys a majority of particles"; + + State = ST_NONE; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_AMTR::update; + +} + +//#TPT-Directive ElementHeader Element_AMTR static int update(UPDATE_FUNC_ARGS) +int Element_AMTR::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_AMTR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_NONE && (r&0xFF)!=PT_PHOT && (r&0xFF)!=PT_VOID && (r&0xFF)!=PT_BHOL && (r&0xFF)!=PT_NBHL && (r&0xFF)!=PT_PRTI && (r&0xFF)!=PT_PRTO) + { + parts[i].life++; + if (parts[i].life==4) + { + sim->kill_part(i); + return 1; + } + if (10>(rand()/(RAND_MAX/100))) + sim->create_part(r>>8, x+rx, y+ry, PT_PHOT); + else + sim->kill_part(r>>8); + sim->pv[y/CELL][x/CELL] -= 2.0f; + } + } + return 0; +} + + +Element_AMTR::~Element_AMTR() {}
\ No newline at end of file diff --git a/src/simulation/elements/ANAR.cpp b/src/simulation/elements/ANAR.cpp new file mode 100644 index 0000000..f8bcd49 --- /dev/null +++ b/src/simulation/elements/ANAR.cpp @@ -0,0 +1,78 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ANAR PT_ANAR 113 +Element_ANAR::Element_ANAR() +{ + Identifier = "DEFAULT_PT_ANAR"; + Name = "ANAR"; + Colour = PIXPACK(0xFFFFEE); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = -0.7f; + AirDrag = -0.02f * CFDS; + AirLoss = 0.96f; + Loss = 0.80f; + Collision = 0.1f; + Gravity = -0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 85; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Very light dust. Behaves opposite gravity"; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_ANAR::update; + +} + +//#TPT-Directive ElementHeader Element_ANAR static int update(UPDATE_FUNC_ARGS) +int Element_ANAR::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + + //if (parts[i].temp >= 0.23) + // parts[i].temp --; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_HFLM) + { + if (1>rand()%22) + { + sim->part_change_type(i,x,y,PT_HFLM); + parts[i].life = rand()%150+50; + parts[r>>8].temp = parts[i].temp = 0; + sim->pv[y/CELL][x/CELL] -= 0.5; + } + } + } + return 0; +} + + +Element_ANAR::~Element_ANAR() {}
\ No newline at end of file diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp new file mode 100644 index 0000000..2794bef --- /dev/null +++ b/src/simulation/elements/ARAY.cpp @@ -0,0 +1,154 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ARAY PT_ARAY 126 +Element_ARAY::Element_ARAY() +{ + Identifier = "DEFAULT_PT_ARAY"; + Name = "ARAY"; + Colour = PIXPACK(0xFFBB00); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Ray Emitter. Rays create points when they collide"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_ARAY::update; + +} + +//#TPT-Directive ElementHeader Element_ARAY static int update(UPDATE_FUNC_ARGS) +int Element_ARAY::update(UPDATE_FUNC_ARGS) + { + int r, nxx, nyy, docontinue, nxi, nyi, rx, ry, nr, ry1, rx1; + if (parts[i].life==0) { + int colored =0; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SPRK && parts[r>>8].life==3) { + 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) { + 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 (!r) { + int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY); + if (nr!=-1) { + if (destroy) {//if it came from PSCN + parts[nr].tmp = 2; + parts[nr].life = 2; + } else + parts[nr].ctype = colored; + parts[nr].temp = parts[i].temp; + } + } else if (!destroy) { + if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==0) {//if it hits another BRAY that isn't red + if (nyy!=0 || nxx!=0) { + parts[r>>8].life = 1020;//makes it last a while + parts[r>>8].tmp = 1; + if (!parts[r>>8].ctype)//and colors it if it isn't already + parts[r>>8].ctype = colored; + } + docontinue = 0;//then stop it + } else if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==1) {//if it hits one that already was a long life, reset it + parts[r>>8].life = 1020; + //docontinue = 1; + } else if ((r&0xFF)==PT_FILT) {//get color if passed through FILT + colored = parts[r>>8].ctype; + //this if prevents BRAY from stopping on certain materials + } else if ((r&0xFF)!=PT_STOR && (r&0xFF)!=PT_INWR && ((r&0xFF)!=PT_SPRK || parts[r>>8].ctype!=PT_INWR) && (r&0xFF)!=PT_ARAY && (r&0xFF)!=PT_WIFI && !((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) { + if (nyy!=0 || nxx!=0) { + sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK); + } + if (!(nostop && parts[r>>8].type==PT_SPRK && parts[r>>8].ctype >= 0 && parts[r>>8].ctype < PT_NUM && (sim->elements[parts[r>>8].ctype].Properties&PROP_CONDUCTS))) { + docontinue = 0; + } else { + docontinue = 1; + } + } else if((r&0xFF)==PT_STOR) { + if(parts[r>>8].tmp) + { + //Cause STOR to release + for(ry1 = 1; ry1 >= -1; ry1--){ + for(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>>8].tmp); + if (np!=-1) + { + parts[np].temp = parts[r>>8].temp; + parts[np].life = parts[r>>8].tmp2; + parts[np].tmp = parts[r>>8].pavg[0]; + parts[np].ctype = parts[r>>8].pavg[1]; + parts[r>>8].tmp = 0; + parts[r>>8].life = 10; + break; + } + } + } + } + else + { + parts[r>>8].life = 10; + } + } + } else if (destroy) { + if ((r&0xFF)==PT_BRAY) { + parts[r>>8].life = 1; + docontinue = 1; + //this if prevents red BRAY from stopping on certain materials + } else if ((r&0xFF)==PT_STOR || (r&0xFF)==PT_INWR || ((r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_INWR) || (r&0xFF)==PT_ARAY || (r&0xFF)==PT_WIFI || (r&0xFF)==PT_FILT || ((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) { + if((r&0xFF)==PT_STOR) + { + parts[r>>8].tmp = 0; + parts[r>>8].life = 0; + } + docontinue = 1; + } else { + docontinue = 0; + } + } + } + } + //parts[i].life = 4; + } + } + return 0; +} + + +Element_ARAY::~Element_ARAY() {}
\ No newline at end of file diff --git a/src/simulation/elements/BANG.cpp b/src/simulation/elements/BANG.cpp new file mode 100644 index 0000000..8922e0e --- /dev/null +++ b/src/simulation/elements/BANG.cpp @@ -0,0 +1,131 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BANG PT_BANG 139 +Element_BANG::Element_BANG() +{ + Identifier = "DEFAULT_PT_BANG"; + Name = "TNT"; + Colour = PIXPACK(0xC05050); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 88; + Description = "Explosive."; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_BANG::update; + +} + +//#TPT-Directive ElementHeader Element_BANG static int update(UPDATE_FUNC_ARGS) +int Element_BANG::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, nb; + if(parts[i].tmp==0) + { + if(parts[i].temp>=673.0f) + parts[i].tmp = 1; + else + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) + { + parts[i].tmp = 1; + } + else if ((r&0xFF)==PT_SPRK || (r&0xFF)==PT_LIGH) + { + parts[i].tmp = 1; + } + } + + } + else if(parts[i].tmp==1) + { + if ((pmap[y][x]>>8 == i)) + { + int tempvalue = 2; + sim->flood_prop(x, y, offsetof(Particle, tmp), &tempvalue, StructProperty::Integer); + } + parts[i].tmp = 2; + } + else if(parts[i].tmp==2) + { + parts[i].tmp = 3; + } + else if(parts[i].tmp>=3) + { + float otemp = parts[i].temp-275.13f; + //Explode!! + sim->pv[y/CELL][x/CELL] += 0.5f; + parts[i].tmp = 0; + if(!(rand()%3)) + { + if(!(rand()%2)) + { + sim->create_part(i, x, y, PT_FIRE); + parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP); + } + else + { + sim->create_part(i, x, y, PT_SMKE); + parts[i].life = rand()%50+500; + parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP); + } + } + else + { + if(!(rand()%15)) + { + sim->create_part(i, x, y, PT_EMBR); + parts[i].tmp = 0; + parts[i].life = 50; + parts[i].temp = restrict_flt((MAX_TEMP/3)+otemp, MIN_TEMP, MAX_TEMP); + parts[i].vx = rand()%20-10; + parts[i].vy = rand()%20-10; + } + else + { + sim->kill_part(i); + } + } + return 1; + } + return 0; +} + + +Element_BANG::~Element_BANG() {} diff --git a/src/simulation/elements/BCLN.cpp b/src/simulation/elements/BCLN.cpp new file mode 100644 index 0000000..80a5d44 --- /dev/null +++ b/src/simulation/elements/BCLN.cpp @@ -0,0 +1,99 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BCLN PT_BCLN 93 +Element_BCLN::Element_BCLN() +{ + Identifier = "DEFAULT_PT_BCLN"; + Name = "BCLN"; + Colour = PIXPACK(0xFFD040); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.97f; + Loss = 0.50f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 12; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Breakable Clone."; + + State = ST_NONE; + Properties = TYPE_SOLID|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_BCLN::update; + +} + +//#TPT-Directive ElementHeader Element_BCLN static int update(UPDATE_FUNC_ARGS) +int Element_BCLN::update(UPDATE_FUNC_ARGS) + { + if (!parts[i].life && sim->pv[y/CELL][x/CELL]>4.0f) + parts[i].life = rand()%40+80; + if (parts[i].life) + { + float advection = 0.1f; + parts[i].vx += advection*sim->vx[y/CELL][x/CELL]; + parts[i].vy += advection*sim->vy[y/CELL][x/CELL]; + } + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + { + int r, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) + { + r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && + (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_STKM && + (r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 && + (r&0xFF)<PT_NUM) + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE || (r&0xFF)==PT_LAVA) + parts[i].tmp = parts[r>>8].ctype; + } + } + } + else { + if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype|(parts[i].tmp<<8)); + 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); + if (np>=0) + { + if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) + parts[np].ctype = parts[i].tmp; + } + } + } + return 0; +} + + +Element_BCLN::~Element_BCLN() {} diff --git a/src/simulation/elements/BCOL.cpp b/src/simulation/elements/BCOL.cpp new file mode 100644 index 0000000..1fb6f82 --- /dev/null +++ b/src/simulation/elements/BCOL.cpp @@ -0,0 +1,146 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BCOL PT_BCOL 73 +Element_BCOL::Element_BCOL() +{ + Identifier = "DEFAULT_PT_BCOL"; + Name = "BCOL"; + Colour = PIXPACK(0x333333); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 5; + Hardness = 2; + + Weight = 90; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 150; + Description = "Broken Coal. Heavy particles. See COAL"; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_BCOL::update; + Graphics = &Element_BCOL::graphics; +} + +//#TPT-Directive ElementHeader Element_BCOL static int update(UPDATE_FUNC_ARGS) +int Element_BCOL::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, trade, temp; + if (parts[i].life<=0) { + sim->create_part(i, x, y, PT_FIRE); + return 1; + } else if (parts[i].life < 100) { + parts[i].life--; + sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE); + } + + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) && 1>(rand()%500)) + { + if (parts[i].life>100) { + parts[i].life = 99; + } + } + if ((r&0xFF)==PT_LAVA && 1>(rand()%500)) + { + if (parts[r>>8].ctype == PT_IRON) { + parts[r>>8].ctype = PT_METL; + sim->kill_part(i); + return 1; + } + } + } + /*if(100-parts[i].life > parts[i].tmp2) + parts[i].tmp2 = 100-parts[i].life; + if(parts[i].tmp2 < 0) parts[i].tmp2 = 0; + for ( trade = 0; trade<4; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL)&&(parts[i].tmp2>parts[r>>8].tmp2)&&parts[i].tmp2>0)//diffusion + { + int temp = parts[i].tmp2 - parts[r>>8].tmp2; + if(temp < 10) + continue; + if (temp ==1) + { + parts[r>>8].tmp2 ++; + parts[i].tmp2 --; + } + else if (temp>0) + { + parts[r>>8].tmp2 += temp/2; + parts[i].tmp2 -= temp/2; + } + } + } + }*/ + if(parts[i].temp > parts[i].tmp2) + parts[i].tmp2 = parts[i].temp; + return 0; +} + + +//#TPT-Directive ElementHeader Element_BCOL static int graphics(GRAPHICS_FUNC_ARGS) +int Element_BCOL::graphics(GRAPHICS_FUNC_ARGS) + //Both COAL and Broken Coal +{ + *colr += (cpart->tmp2-295.15f)/3; + + if (*colr > 170) + *colr = 170; + if (*colr < *colg) + *colr = *colg; + + *colg = *colb = *colr; + + if((cpart->temp-295.15f) > 300.0f-200.0f) + { + float frequency = 3.1415/(2*300.0f-(300.0f-200.0f)); + int q = ((cpart->temp-295.15f)>300.0f)?300.0f-(300.0f-200.0f):(cpart->temp-295.15f)-(300.0f-200.0f); + + *colr += sin(frequency*q) * 226; + *colg += sin(frequency*q*4.55 +3.14) * 34; + *colb += sin(frequency*q*2.22 +3.14) * 64; + } + return 0; +} + + + +Element_BCOL::~Element_BCOL() {}
\ No newline at end of file diff --git a/src/simulation/elements/BGLA.cpp b/src/simulation/elements/BGLA.cpp new file mode 100644 index 0000000..79e7fe2 --- /dev/null +++ b/src/simulation/elements/BGLA.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BGLA PT_BGLA 47 +Element_BGLA::Element_BGLA() +{ + Identifier = "DEFAULT_PT_BGLA"; + Name = "BGLA"; + Colour = PIXPACK(0x606060); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 5; + Hardness = 0; + + Weight = 90; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 150; + Description = "Broken Glass, Heavy particles. Meltable. Bagels."; + + State = ST_SOLID; + Properties = TYPE_PART | PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1973.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_BGLA::~Element_BGLA() {}
\ No newline at end of file diff --git a/src/simulation/elements/BHOL.cpp b/src/simulation/elements/BHOL.cpp new file mode 100644 index 0000000..35eda8c --- /dev/null +++ b/src/simulation/elements/BHOL.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BHOL PT_BHOL 39 +Element_BHOL::Element_BHOL() +{ + Identifier = "DEFAULT_PT_BHOL"; + Name = "VACU"; + Colour = PIXPACK(0x303030); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + 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.01f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = R_TEMP+70.0f+273.15f; + HeatConduct = 255; + Description = "Vacuum, sucks in other particles and heats up."; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_BHOL::~Element_BHOL() {}
\ No newline at end of file diff --git a/src/simulation/elements/BIZR.cpp b/src/simulation/elements/BIZR.cpp new file mode 100644 index 0000000..13df996 --- /dev/null +++ b/src/simulation/elements/BIZR.cpp @@ -0,0 +1,124 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BIZR PT_BIZR 103 +Element_BIZR::Element_BIZR() +{ + Identifier = "DEFAULT_PT_BIZR"; + Name = "BIZR"; + Colour = PIXPACK(0x00FF77); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 29; + Description = "Bizarre... contradicts the normal state changes."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 100.0f; + LowTemperatureTransition = PT_BIZRG; + HighTemperature = 400.0f; + HighTemperatureTransition = PT_BIZRS; + + Update = &Element_BIZR::update; + Graphics = &Element_BIZR::graphics; +} + +//#TPT-Directive ElementHeader Element_BIZR static int update(UPDATE_FUNC_ARGS) +int Element_BIZR::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, nr, ng, nb, na; + float tr, tg, tb, ta, mr, mg, mb, ma; + float blend; + if(parts[i].dcolour){ + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_BIZR && (r&0xFF)!=PT_BIZRG && (r&0xFF)!=PT_BIZRS) + { + blend = 0.95f; + tr = (parts[r>>8].dcolour>>16)&0xFF; + tg = (parts[r>>8].dcolour>>8)&0xFF; + tb = (parts[r>>8].dcolour)&0xFF; + ta = (parts[r>>8].dcolour>>24)&0xFF; + + mr = (parts[i].dcolour>>16)&0xFF; + mg = (parts[i].dcolour>>8)&0xFF; + mb = (parts[i].dcolour)&0xFF; + ma = (parts[i].dcolour>>24)&0xFF; + + nr = (tr*blend) + (mr*(1-blend)); + ng = (tg*blend) + (mg*(1-blend)); + nb = (tb*blend) + (mb*(1-blend)); + na = (ta*blend) + (ma*(1-blend)); + + parts[r>>8].dcolour = nr<<16 | ng<<8 | nb | na<<24; + } + } + } + if(((r = sim->photons[y][x])&0xFF)==PT_PHOT || ((r = pmap[y][x])&0xFF)==PT_PHOT) + { + sim->part_change_type(r>>8, x, y, PT_ELEC); + parts[r>>8].ctype = 0; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_BIZR static int graphics(GRAPHICS_FUNC_ARGS) +int Element_BIZR::graphics(GRAPHICS_FUNC_ARGS) + //BIZR, BIZRG, BIZRS +{ + int x = 0; + *colg = 0; + *colb = 0; + *colr = 0; + for (x=0; x<12; x++) { + *colr += (cpart->ctype >> (x+18)) & 1; + *colb += (cpart->ctype >> x) & 1; + } + for (x=0; x<12; x++) + *colg += (cpart->ctype >> (x+9)) & 1; + x = 624/(*colr+*colg+*colb+1); + *colr *= x; + *colg *= x; + *colb *= x; + if(fabs(cpart->vx)+fabs(cpart->vy)>0) + { + *firea = 255; + *fireg = *colg/5 * fabs(cpart->vx)+fabs(cpart->vy); + *fireb = *colb/5 * fabs(cpart->vx)+fabs(cpart->vy); + *firer = *colr/5 * fabs(cpart->vx)+fabs(cpart->vy); + *pixel_mode |= FIRE_ADD; + } + return 0; +} + + +Element_BIZR::~Element_BIZR() {}
\ No newline at end of file diff --git a/src/simulation/elements/BIZRG.cpp b/src/simulation/elements/BIZRG.cpp new file mode 100644 index 0000000..1e5f27f --- /dev/null +++ b/src/simulation/elements/BIZRG.cpp @@ -0,0 +1,124 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BIZRG PT_BIZRG 104 +Element_BIZRG::Element_BIZRG() +{ + Identifier = "DEFAULT_PT_BIZRG"; + Name = "BIZG"; + Colour = PIXPACK(0x00FFBB); + MenuVisible = 1; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 1.0f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.1f; + Gravity = 0.0f; + Diffusion = 2.75f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 1; + + Temperature = R_TEMP-200.0f+273.15f; + HeatConduct = 42; + Description = "Bizarre gas"; + + State = ST_GAS; + Properties = TYPE_GAS; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 100.0f; + HighTemperatureTransition = PT_BIZR; + + Update = &Element_BIZRG::update; + Graphics = &Element_BIZRG::graphics; +} + +//#TPT-Directive ElementHeader Element_BIZRG static int update(UPDATE_FUNC_ARGS) +int Element_BIZRG::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, nr, ng, nb, na; + float tr, tg, tb, ta, mr, mg, mb, ma; + float blend; + if(parts[i].dcolour){ + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_BIZR && (r&0xFF)!=PT_BIZRG && (r&0xFF)!=PT_BIZRS) + { + blend = 0.95f; + tr = (parts[r>>8].dcolour>>16)&0xFF; + tg = (parts[r>>8].dcolour>>8)&0xFF; + tb = (parts[r>>8].dcolour)&0xFF; + ta = (parts[r>>8].dcolour>>24)&0xFF; + + mr = (parts[i].dcolour>>16)&0xFF; + mg = (parts[i].dcolour>>8)&0xFF; + mb = (parts[i].dcolour)&0xFF; + ma = (parts[i].dcolour>>24)&0xFF; + + nr = (tr*blend) + (mr*(1-blend)); + ng = (tg*blend) + (mg*(1-blend)); + nb = (tb*blend) + (mb*(1-blend)); + na = (ta*blend) + (ma*(1-blend)); + + parts[r>>8].dcolour = nr<<16 | ng<<8 | nb | na<<24; + } + } + } + if(((r = sim->photons[y][x])&0xFF)==PT_PHOT || ((r = pmap[y][x])&0xFF)==PT_PHOT) + { + sim->part_change_type(r>>8, x, y, PT_ELEC); + parts[r>>8].ctype = 0; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_BIZRG static int graphics(GRAPHICS_FUNC_ARGS) +int Element_BIZRG::graphics(GRAPHICS_FUNC_ARGS) + //BIZR, BIZRG, BIZRS +{ + int x = 0; + *colg = 0; + *colb = 0; + *colr = 0; + for (x=0; x<12; x++) { + *colr += (cpart->ctype >> (x+18)) & 1; + *colb += (cpart->ctype >> x) & 1; + } + for (x=0; x<12; x++) + *colg += (cpart->ctype >> (x+9)) & 1; + x = 624/(*colr+*colg+*colb+1); + *colr *= x; + *colg *= x; + *colb *= x; + if(fabs(cpart->vx)+fabs(cpart->vy)>0) + { + *firea = 255; + *fireg = *colg/5 * fabs(cpart->vx)+fabs(cpart->vy); + *fireb = *colb/5 * fabs(cpart->vx)+fabs(cpart->vy); + *firer = *colr/5 * fabs(cpart->vx)+fabs(cpart->vy); + *pixel_mode |= FIRE_ADD; + } + return 0; +} + + +Element_BIZRG::~Element_BIZRG() {}
\ No newline at end of file diff --git a/src/simulation/elements/BIZRS.cpp b/src/simulation/elements/BIZRS.cpp new file mode 100644 index 0000000..439a723 --- /dev/null +++ b/src/simulation/elements/BIZRS.cpp @@ -0,0 +1,124 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BIZRS PT_BIZRS 105 +Element_BIZRS::Element_BIZRS() +{ + Identifier = "DEFAULT_PT_BIZRS"; + Name = "BIZS"; + Colour = PIXPACK(0x00E455); + MenuVisible = 1; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+300.0f+273.15f; + HeatConduct = 251; + Description = "Bizarre solid"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 400.0f; + LowTemperatureTransition = PT_BIZR; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_BIZRS::update; + Graphics = &Element_BIZRS::graphics; +} + +//#TPT-Directive ElementHeader Element_BIZRS static int update(UPDATE_FUNC_ARGS) +int Element_BIZRS::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, nr, ng, nb, na; + float tr, tg, tb, ta, mr, mg, mb, ma; + float blend; + if(parts[i].dcolour){ + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_BIZR && (r&0xFF)!=PT_BIZRG && (r&0xFF)!=PT_BIZRS) + { + blend = 0.95f; + tr = (parts[r>>8].dcolour>>16)&0xFF; + tg = (parts[r>>8].dcolour>>8)&0xFF; + tb = (parts[r>>8].dcolour)&0xFF; + ta = (parts[r>>8].dcolour>>24)&0xFF; + + mr = (parts[i].dcolour>>16)&0xFF; + mg = (parts[i].dcolour>>8)&0xFF; + mb = (parts[i].dcolour)&0xFF; + ma = (parts[i].dcolour>>24)&0xFF; + + nr = (tr*blend) + (mr*(1-blend)); + ng = (tg*blend) + (mg*(1-blend)); + nb = (tb*blend) + (mb*(1-blend)); + na = (ta*blend) + (ma*(1-blend)); + + parts[r>>8].dcolour = nr<<16 | ng<<8 | nb | na<<24; + } + } + } + if(((r = sim->photons[y][x])&0xFF)==PT_PHOT || ((r = pmap[y][x])&0xFF)==PT_PHOT) + { + sim->part_change_type(r>>8, x, y, PT_ELEC); + parts[r>>8].ctype = 0; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_BIZRS static int graphics(GRAPHICS_FUNC_ARGS) +int Element_BIZRS::graphics(GRAPHICS_FUNC_ARGS) + //BIZR, BIZRG, BIZRS +{ + int x = 0; + *colg = 0; + *colb = 0; + *colr = 0; + for (x=0; x<12; x++) { + *colr += (cpart->ctype >> (x+18)) & 1; + *colb += (cpart->ctype >> x) & 1; + } + for (x=0; x<12; x++) + *colg += (cpart->ctype >> (x+9)) & 1; + x = 624/(*colr+*colg+*colb+1); + *colr *= x; + *colg *= x; + *colb *= x; + if(fabs(cpart->vx)+fabs(cpart->vy)>0) + { + *firea = 255; + *fireg = *colg/5 * fabs(cpart->vx)+fabs(cpart->vy); + *fireb = *colb/5 * fabs(cpart->vx)+fabs(cpart->vy); + *firer = *colr/5 * fabs(cpart->vx)+fabs(cpart->vy); + *pixel_mode |= FIRE_ADD; + } + return 0; +} + + +Element_BIZRS::~Element_BIZRS() {}
\ No newline at end of file diff --git a/src/simulation/elements/BMTL.cpp b/src/simulation/elements/BMTL.cpp new file mode 100644 index 0000000..adc5289 --- /dev/null +++ b/src/simulation/elements/BMTL.cpp @@ -0,0 +1,80 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BMTL PT_BMTL 29 +Element_BMTL::Element_BMTL() +{ + Identifier = "DEFAULT_PT_BMTL"; + Name = "BMTL"; + Colour = PIXPACK(0x505070); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Breakable metal."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 1.0f; + HighPressureTransition = ST; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1273.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_BMTL::update; + +} + +//#TPT-Directive ElementHeader Element_BMTL static int update(UPDATE_FUNC_ARGS) +int Element_BMTL::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, rt, tempFactor; + if (parts[i].tmp>1) + { + parts[i].tmp--; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + rt = parts[r>>8].type; + if ((rt==PT_METL || rt==PT_IRON) && 1>(rand()/(RAND_MAX/100))) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_BMTL); + parts[r>>8].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(rand()%5);//rand()/(RAND_MAX/300)+100; + } + } + } + else if (parts[i].tmp==1 && 1>rand()%1000) + { + parts[i].tmp = 0; + sim->part_change_type(i,x,y,PT_BRMT); + } + return 0; +} + + +Element_BMTL::~Element_BMTL() {}
\ No newline at end of file diff --git a/src/simulation/elements/BOMB.cpp b/src/simulation/elements/BOMB.cpp new file mode 100644 index 0000000..0335e59 --- /dev/null +++ b/src/simulation/elements/BOMB.cpp @@ -0,0 +1,113 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BOMB PT_BOMB 129 +Element_BOMB::Element_BOMB() +{ + Identifier = "DEFAULT_PT_BOMB"; + Name = "BOMB"; + Colour = PIXPACK(0xFFF288); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Bomb."; + + State = ST_NONE; + Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC|PROP_SPARKSETTLE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_BOMB::update; + Graphics = &Element_BOMB::graphics; +} + +//#TPT-Directive ElementHeader Element_BOMB static int update(UPDATE_FUNC_ARGS) +int Element_BOMB::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, nb; + + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_BOMB && (r&0xFF)!=PT_EMBR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_VIBR) + { + int rad = 8; + int nxi; + int nxj; + pmap[y][x] = 0; + for (nxj=-rad; nxj<=rad; nxj++) + for (nxi=-rad; nxi<=rad; nxi++) + if ((pow((float)nxi,2))/(pow((float)rad,2))+(pow((float)nxj,2))/(pow((float)rad,2))<=1) + if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_VIBR) + { + sim->delete_part(x+nxi, y+nxj, 0); + sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f; + nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR); + if (nb!=-1) + { + parts[nb].tmp = 2; + parts[nb].life = 2; + parts[nb].temp = MAX_TEMP; + } + } + 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)) + { + nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR); + if (nb!=-1) + { + parts[nb].tmp = 0; + parts[nb].life = 50; + parts[nb].temp = MAX_TEMP; + parts[nb].vx = rand()%40-20; + parts[nb].vy = rand()%40-20; + } + } + sim->kill_part(i); + return 1; + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_BOMB static int graphics(GRAPHICS_FUNC_ARGS) +int Element_BOMB::graphics(GRAPHICS_FUNC_ARGS) + +{ + *pixel_mode |= PMODE_FLARE; + return 1; +} + + +Element_BOMB::~Element_BOMB() {} diff --git a/src/simulation/elements/BOYL.cpp b/src/simulation/elements/BOYL.cpp new file mode 100644 index 0000000..18ebee8 --- /dev/null +++ b/src/simulation/elements/BOYL.cpp @@ -0,0 +1,94 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BOYL PT_BOYL 141 +Element_BOYL::Element_BOYL() +{ + Identifier = "DEFAULT_PT_BOYL"; + Name = "BOYL"; + Colour = PIXPACK(0x0A3200); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 1.0f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.1f; + Gravity = 0.0f; + Diffusion = 0.18f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 1; + + Temperature = R_TEMP+2.0f +273.15f; + HeatConduct = 42; + Description = "Boyle, variable pressure gas. Expands when heated."; + + State = ST_GAS; + Properties = TYPE_GAS; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_BOYL::update; + +} + +//#TPT-Directive ElementHeader Element_BOYL static int update(UPDATE_FUNC_ARGS) +int Element_BOYL::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (sim->pv[y/CELL][x/CELL]<(parts[i].temp/100)) + sim->pv[y/CELL][x/CELL] += 0.001f*((parts[i].temp/100)-sim->pv[y/CELL][x/CELL]); + if (y+CELL<YRES && sim->pv[y/CELL+1][x/CELL]<(parts[i].temp/100)) + sim->pv[y/CELL+1][x/CELL] += 0.001f*((parts[i].temp/100)-sim->pv[y/CELL+1][x/CELL]); + if (x+CELL<XRES) + { + sim->pv[y/CELL][x/CELL+1] += 0.001f*((parts[i].temp/100)-sim->pv[y/CELL][x/CELL+1]); + if (y+CELL<YRES) + sim->pv[y/CELL+1][x/CELL+1] += 0.001f*((parts[i].temp/100)-sim->pv[y/CELL+1][x/CELL+1]); + } + if (y-CELL>=0 && sim->pv[y/CELL-1][x/CELL]<(parts[i].temp/100)) + sim->pv[y/CELL-1][x/CELL] += 0.001f*((parts[i].temp/100)-sim->pv[y/CELL-1][x/CELL]); + if (x-CELL>=0) + { + sim->pv[y/CELL][x/CELL-1] += 0.001f*((parts[i].temp/100)-sim->pv[y/CELL][x/CELL-1]); + if (y-CELL>=0) + sim->pv[y/CELL-1][x/CELL-1] += 0.001f*((parts[i].temp/100)-sim->pv[y/CELL-1][x/CELL-1]); + } + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && + x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_WATR && 1>rand()%30) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_FOG); + } + else if ((r&0xFF)==PT_O2 && 1>rand()%9) + { + sim->kill_part(r>>8); + sim->part_change_type(i,x,y,PT_WATR); + sim->pv[y/CELL][x/CELL] += 4.0; + } + } + return 0; +} + + +Element_BOYL::~Element_BOYL() {}
\ No newline at end of file diff --git a/src/simulation/elements/BRAY.cpp b/src/simulation/elements/BRAY.cpp new file mode 100644 index 0000000..dfcd080 --- /dev/null +++ b/src/simulation/elements/BRAY.cpp @@ -0,0 +1,109 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BRAY PT_BRAY 127 +Element_BRAY::Element_BRAY() +{ + Identifier = "DEFAULT_PT_BRAY"; + Name = "BRAY"; + Colour = PIXPACK(0xFFFFFF); + MenuVisible = 0; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Ray Point. Rays create points when they collide"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC|PROP_LIFE_KILL; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + Graphics = &Element_BRAY::graphics; +} + +//#TPT-Directive ElementHeader Element_BRAY static int graphics(GRAPHICS_FUNC_ARGS) +int Element_BRAY::graphics(GRAPHICS_FUNC_ARGS) + +{ + int x, trans = 255; + if(cpart->tmp==0) + { + trans = cpart->life * 7; + if (trans>255) trans = 255; + if (cpart->ctype) { + *colg = 0; + *colb = 0; + *colr = 0; + for (x=0; x<12; x++) { + *colr += (cpart->ctype >> (x+18)) & 1; + *colb += (cpart->ctype >> x) & 1; + } + for (x=0; x<12; x++) + *colg += (cpart->ctype >> (x+9)) & 1; + x = 624/(*colr+*colg+*colb+1); + *colr *= x; + *colg *= x; + *colb *= x; + } + } + else if(cpart->tmp==1) + { + trans = cpart->life/4; + if (trans>255) trans = 255; + if (cpart->ctype) { + *colg = 0; + *colb = 0; + *colr = 0; + for (x=0; x<12; x++) { + *colr += (cpart->ctype >> (x+18)) & 1; + *colb += (cpart->ctype >> x) & 1; + } + for (x=0; x<12; x++) + *colg += (cpart->ctype >> (x+9)) & 1; + x = 624/(*colr+*colg+*colb+1); + *colr *= x; + *colg *= x; + *colb *= x; + } + } + else if(cpart->tmp==2) + { + trans = cpart->life*100; + if (trans>255) trans = 255; + *colr = 255; + *colg = 150; + *colb = 50; + } + *cola = trans; + *pixel_mode &= ~PMODE; + *pixel_mode |= PMODE_BLEND | PMODE_GLOW; + return 0; +} + + +Element_BRAY::~Element_BRAY() {}
\ No newline at end of file diff --git a/src/simulation/elements/BRCK.cpp b/src/simulation/elements/BRCK.cpp new file mode 100644 index 0000000..6769aa3 --- /dev/null +++ b/src/simulation/elements/BRCK.cpp @@ -0,0 +1,65 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BRCK PT_BRCK 67 +Element_BRCK::Element_BRCK() +{ + Identifier = "DEFAULT_PT_BRCK"; + Name = "BRCK"; + Colour = PIXPACK(0x808080); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Brick, breakable building material."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 8.8f; + HighPressureTransition = PT_STNE; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1223.0f; + 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 |= FIRE_ADD; + *colb += 100; + + *firea = 40; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + } + return 0; +} + +Element_BRCK::~Element_BRCK() {}
\ No newline at end of file diff --git a/src/simulation/elements/BREC.cpp b/src/simulation/elements/BREC.cpp new file mode 100644 index 0000000..e260a7c --- /dev/null +++ b/src/simulation/elements/BREC.cpp @@ -0,0 +1,64 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BREC PT_BREC 135 +Element_BREC::Element_BREC() +{ + Identifier = "DEFAULT_PT_BREC"; + Name = "BREL"; + Colour = PIXPACK(0x707060); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.18f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 2; + Hardness = 2; + + Weight = 90; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 211; + Description = "Broken electronics"; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_BREC::update; + +} + +//#TPT-Directive ElementHeader Element_BREC static int update(UPDATE_FUNC_ARGS) +int Element_BREC::update(UPDATE_FUNC_ARGS) +{ + int np; + if (1>rand()%200 && (sim->pv[y/CELL][x/CELL] > 30.0f) && parts[i].temp>9000 && parts[i].life>0) + { + sim->part_change_type(i, x ,y ,PT_EXOT); + parts[i].life = 1000; + } + if ((sim->pv[y/CELL][x/CELL] > 10.0f) && (parts[i].life>0)) { + parts[i].temp = parts[i].temp + (sim->pv[y/CELL][x/CELL])/8; + } + return 0; +} + +Element_BREC::~Element_BREC() {} diff --git a/src/simulation/elements/BRMT.cpp b/src/simulation/elements/BRMT.cpp new file mode 100644 index 0000000..55eb243 --- /dev/null +++ b/src/simulation/elements/BRMT.cpp @@ -0,0 +1,85 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BRMT PT_BRMT 30 +Element_BRMT::Element_BRMT() +{ + Identifier = "DEFAULT_PT_BRMT"; + Name = "BRMT"; + Colour = PIXPACK(0x705060); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 2; + Hardness = 2; + + Weight = 90; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 211; + Description = "Broken metal."; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1273.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_BRMT::update; + +} + +//#TPT-Directive ElementHeader Element_BRMT static int update(UPDATE_FUNC_ARGS) +int Element_BRMT::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, rt, tempFactor; + if (parts[i].temp > (250.0f+273.15f)) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + rt = parts[r>>8].type; + tempFactor = 1000 - (((250.0f+273.15f)-parts[i].temp)*2); + if(tempFactor < 2) + tempFactor = 2; + if ((rt==PT_BREC) && 1 > (rand()%tempFactor)) + { + if(rand()%2) + { + sim->create_part(r>>8, x+rx, y+ry, PT_THRM); + } + else + { sim->create_part(i, x, y, PT_THRM); + } + return 1; + //part_change_type(r>>8,x+rx,y+ry,PT_BMTL); + //parts[r>>8].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(rand()%5);//rand()/(RAND_MAX/300)+100; + } + } + } + return 0; +} + + +Element_BRMT::~Element_BRMT() {}
\ No newline at end of file diff --git a/src/simulation/elements/BTRY.cpp b/src/simulation/elements/BTRY.cpp new file mode 100644 index 0000000..efbb3d2 --- /dev/null +++ b/src/simulation/elements/BTRY.cpp @@ -0,0 +1,75 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BTRY PT_BTRY 53 +Element_BTRY::Element_BTRY() +{ + Identifier = "DEFAULT_PT_BTRY"; + Name = "BTRY"; + Colour = PIXPACK(0x858505); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Solid. Generates Electricity."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 2273.0f; + HighTemperatureTransition = PT_PLSM; + + Update = &Element_BTRY::update; + +} + +//#TPT-Directive ElementHeader Element_BTRY static int update(UPDATE_FUNC_ARGS) +int Element_BTRY::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, rt; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + rt = parts[r>>8].type; + if (sim->parts_avg(i,r>>8,PT_INSL) != PT_INSL) + { + if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[r>>8].life==0 && abs(rx)+abs(ry) < 4) + { + parts[r>>8].life = 4; + parts[r>>8].ctype = rt; + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + } + } + } + return 0; +} + + +Element_BTRY::~Element_BTRY() {}
\ No newline at end of file diff --git a/src/simulation/elements/BVBR.cpp b/src/simulation/elements/BVBR.cpp new file mode 100644 index 0000000..dfff186 --- /dev/null +++ b/src/simulation/elements/BVBR.cpp @@ -0,0 +1,50 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_BVBR PT_BVBR 166 +Element_BVBR::Element_BVBR() +{ + Identifier = "DEFAULT_PT_BVBR"; + Name = "BVBR"; + Colour = PIXPACK(0x005000); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.3f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.95f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.15f; + Diffusion = 0.00f; + HotAir = 0.0000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 67; + + Temperature = 273.15f; + HeatConduct = 164; + Description = "Broken vibranium."; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_VIBR::update; + Graphics = &Element_VIBR::graphics; + +} + +Element_BVBR::~Element_BVBR() {}
\ No newline at end of file diff --git a/src/simulation/elements/C5.cpp b/src/simulation/elements/C5.cpp new file mode 100644 index 0000000..28e2055 --- /dev/null +++ b/src/simulation/elements/C5.cpp @@ -0,0 +1,75 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_C5 PT_C5 130 +Element_C5::Element_C5() +{ + Identifier = "DEFAULT_PT_C5"; + Name = "C-5"; + Colour = PIXPACK(0x2050E0); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 88; + Description = "Cold explosive"; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_C5::update; + +} + +//#TPT-Directive ElementHeader Element_C5 static int update(UPDATE_FUNC_ARGS) +int Element_C5::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)!=PT_C5 && parts[r>>8].temp<100 && sim->elements[r&0xFF].HeatConduct && ((r&0xFF)!=PT_HSWC||parts[r>>8].life==10)) || (r&0xFF)==PT_HFLM) + { + if (1>rand()%6) + { + sim->part_change_type(i,x,y,PT_HFLM); + parts[r>>8].temp = parts[i].temp = 0; + parts[i].life = rand()%150+50; + sim->pv[y/CELL][x/CELL] += 1.5; + } + } + } + return 0; +} + + +Element_C5::~Element_C5() {}
\ No newline at end of file diff --git a/src/simulation/elements/CAUS.cpp b/src/simulation/elements/CAUS.cpp new file mode 100644 index 0000000..a8fc0da --- /dev/null +++ b/src/simulation/elements/CAUS.cpp @@ -0,0 +1,86 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_CAUS PT_CAUS 86 +Element_CAUS::Element_CAUS() +{ + Identifier = "DEFAULT_PT_CAUS"; + Name = "CAUS"; + Colour = PIXPACK(0x80FFA0); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 2.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.1f; + Gravity = 0.0f; + Diffusion = 1.50f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 1; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Caustic Gas, acts like Acid"; + + State = ST_GAS; + Properties = TYPE_GAS|PROP_DEADLY; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_CAUS::update; + +} + +//#TPT-Directive ElementHeader Element_CAUS static int update(UPDATE_FUNC_ARGS) +int Element_CAUS::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, trade, np; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_ACID && (r&0xFF)!=PT_CAUS) + { + if (((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && sim->elements[r&0xFF].Hardness>(rand()%1000))&&parts[i].life>=50) + { + if (sim->parts_avg(i, r>>8,PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid + { + float newtemp = ((60.0f-(float)sim->elements[r&0xFF].Hardness))*7.0f; + if(newtemp < 0){ + newtemp = 0; + } + parts[i].temp += newtemp; + parts[i].life--; + sim->kill_part(r>>8); + } + } + else if (parts[i].life<=50) + { + sim->kill_part(i); + return 1; + } + } + } + return 0; +} + + +Element_CAUS::~Element_CAUS() {}
\ No newline at end of file diff --git a/src/simulation/elements/CBNW.cpp b/src/simulation/elements/CBNW.cpp new file mode 100644 index 0000000..4331750 --- /dev/null +++ b/src/simulation/elements/CBNW.cpp @@ -0,0 +1,153 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_CBNW PT_CBNW 82 +Element_CBNW::Element_CBNW() +{ + Identifier = "DEFAULT_PT_CBNW"; + Name = "BUBW"; + Colour = PIXPACK(0x2030D0); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Carbonated water. Conducts electricity. Freezes. Extinguishes fires."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 273.15f; + LowTemperatureTransition = PT_ICEI; + HighTemperature = 373.0f; + HighTemperatureTransition = PT_WTRV; + + Update = &Element_CBNW::update; + Graphics = &Element_CBNW::graphics; +} + +//#TPT-Directive ElementHeader Element_CBNW static int update(UPDATE_FUNC_ARGS) +int Element_CBNW::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, oldt; + oldt = parts[i].tmp; + if (sim->pv[y/CELL][x/CELL]<=3) + { + if(20>(rand()%80000)) + { + sim->part_change_type(i,x,y,PT_CO2); + parts[i].ctype = 5; + sim->pv[y/CELL][x/CELL] += 0.5f; + } + else if(sim->pv[y/CELL][x/CELL]<=-0.5) + { + sim->part_change_type(i,x,y,PT_CO2); + parts[i].ctype = 5; + sim->pv[y/CELL][x/CELL] += 0.5f; + } + } + if (parts[i].tmp>0) + parts[i].tmp--; + if(!(rand()%200)) + { + parts[i].tmp2 = rand()%40; + } else if(parts[i].tmp2!=20) { + parts[i].tmp2 -= (parts[i].tmp2>20)?1:-1; + } + if(oldt==1) + { + //Explode + if(rand()%4) + { + sim->part_change_type(i,x,y,PT_CO2); + parts[i].ctype = 5; + sim->pv[y/CELL][x/CELL] += 0.2f; + } + } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((sim->elements[r&0xFF].Properties&TYPE_PART) && parts[i].tmp == 0 && 1>(rand()%250)) + { + //Start explode + parts[i].tmp = rand()%25;//(rand()%100)+50; + } + else if((sim->elements[r&0xFF].Properties&TYPE_SOLID) && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_GLAS && parts[i].tmp == 0 && (2-sim->pv[y/CELL][x/CELL])>(rand()%20000)) + { + if(rand()%2) + { + sim->part_change_type(i,x,y,PT_CO2); + parts[i].ctype = 5; + sim->pv[y/CELL][x/CELL] += 0.2f; + } + } + if ((r&0xFF)==PT_CBNW) + { + if(!parts[i].tmp && parts[r>>8].tmp) + { + parts[i].tmp = parts[r>>8].tmp; + if((r>>8)>i) //If the other particle hasn't been life updated + parts[i].tmp--; + } + else if(parts[i].tmp && !parts[r>>8].tmp) + { + parts[r>>8].tmp = parts[i].tmp; + if((r>>8)>i) //If the other particle hasn't been life updated + parts[r>>8].tmp++; + } + } + if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && 1>(rand()%500)) + { + sim->part_change_type(i,x,y,PT_FIRE); + parts[i].life = 4; + parts[i].ctype = PT_WATR; + } + if ((r&0xFF)==PT_FIRE && parts[r>>8].ctype!=PT_WATR){ + sim->kill_part(r>>8); + if(1>(rand()%150)){ + sim->kill_part(i); + return 1; + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_CBNW static int graphics(GRAPHICS_FUNC_ARGS) +int Element_CBNW::graphics(GRAPHICS_FUNC_ARGS) + +{ + int z = cpart->tmp2 - 20;//speckles! + *colr += z * 1; + *colg += z * 2; + *colb += z * 8; + return 0; +} + + +Element_CBNW::~Element_CBNW() {}
\ No newline at end of file diff --git a/src/simulation/elements/CLNE.cpp b/src/simulation/elements/CLNE.cpp new file mode 100644 index 0000000..6ffe4f1 --- /dev/null +++ b/src/simulation/elements/CLNE.cpp @@ -0,0 +1,91 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_CLNE PT_CLNE 9 +Element_CLNE::Element_CLNE() +{ + Identifier = "DEFAULT_PT_CLNE"; + Name = "CLNE"; + Colour = PIXPACK(0xFFD010); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Solid. Duplicates any particles it touches."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_CLNE::update; + +} + +//#TPT-Directive ElementHeader Element_CLNE static int update(UPDATE_FUNC_ARGS) +int Element_CLNE::update(UPDATE_FUNC_ARGS) + { + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + { + int r, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) + { + r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && + (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_STKM && + (r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 && + (r&0xFF)<PT_NUM) + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE || (r&0xFF)==PT_LAVA) + parts[i].tmp = parts[r>>8].ctype; + } + } + } + else { + if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype|(parts[i].tmp<<8)); + 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); + if (np>=0) + { + if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) + parts[np].ctype = parts[i].tmp; + } + } + } + return 0; +} + + +Element_CLNE::~Element_CLNE() {} diff --git a/src/simulation/elements/CLST.cpp b/src/simulation/elements/CLST.cpp new file mode 100644 index 0000000..3cab1f7 --- /dev/null +++ b/src/simulation/elements/CLST.cpp @@ -0,0 +1,101 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_CLST PT_CLST 155 +Element_CLST::Element_CLST() +{ + Identifier = "DEFAULT_PT_CLST"; + Name = "CLST"; + Colour = PIXPACK(0xE4A4A4); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.2f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 2; + Hardness = 2; + + Weight = 55; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Clay dust. Produces paste when mixed with water."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1256.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_CLST::update; + Graphics = &Element_CLST::graphics; +} + +//#TPT-Directive ElementHeader Element_CLST static int update(UPDATE_FUNC_ARGS) +int Element_CLST::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + float cxy; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_WATR && 1>(rand()%1500)) + { + sim->part_change_type(i,x,y,PT_PSTS); + sim->kill_part(r>>8); + } + if ((r&0xFF)==PT_NITR) + { + sim->create_part(i, x, y, PT_BANG); + sim->create_part(r>>8, x+rx, y+ry, PT_BANG); + } + if ((r&0xFF)==PT_CLST) + { + if(parts[i].temp <195) + cxy = 0.05; + if(parts[i].temp >= 195 && parts[i].temp <295) + cxy = 0.015; + if(parts[i].temp >= 295 && parts[i].temp <350) + cxy = 0.01; + if(parts[i].temp > 350) + cxy = 0.005; + parts[i].vx += cxy*rx; + parts[i].vy += cxy*ry;//These two can be set not to calculate over 350 later. They do virtually nothing over 0.005. + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_CLST static int graphics(GRAPHICS_FUNC_ARGS) +int Element_CLST::graphics(GRAPHICS_FUNC_ARGS) + +{ + int z = cpart->tmp - 5;//speckles! + *colr += z * 16; + *colg += z * 16; + *colb += z * 16; + return 0; +} + + +Element_CLST::~Element_CLST() {}
\ No newline at end of file diff --git a/src/simulation/elements/CNCT.cpp b/src/simulation/elements/CNCT.cpp new file mode 100644 index 0000000..77f70be --- /dev/null +++ b/src/simulation/elements/CNCT.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_CNCT PT_CNCT 24 +Element_CNCT::Element_CNCT() +{ + Identifier = "DEFAULT_PT_CNCT"; + Name = "CNCT"; + Colour = PIXPACK(0xC0C0C0); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 2; + Hardness = 2; + + Weight = 55; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 100; + Description = "Concrete, stronger than stone."; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1123.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_CNCT::~Element_CNCT() {}
\ No newline at end of file diff --git a/src/simulation/elements/CO2.cpp b/src/simulation/elements/CO2.cpp new file mode 100644 index 0000000..49614fb --- /dev/null +++ b/src/simulation/elements/CO2.cpp @@ -0,0 +1,106 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_CO2 PT_CO2 80 +Element_CO2::Element_CO2() +{ + Identifier = "DEFAULT_PT_CO2"; + Name = "CO2"; + Colour = PIXPACK(0x666666); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 2.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.1f; + Gravity = 0.1f; + Diffusion = 1.0f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 1; + + Temperature = R_TEMP+273.15f; + HeatConduct = 88; + Description = "Carbon Dioxide"; + + State = ST_GAS; + Properties = TYPE_GAS; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 194.65f; + LowTemperatureTransition = PT_DRIC; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_CO2::update; + +} + +//#TPT-Directive ElementHeader Element_CO2 static int update(UPDATE_FUNC_ARGS) +int Element_CO2::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (parts[i].ctype==5 && 20>(rand()%40000)) + { + if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0) + parts[i].ctype = 0; + } + if ((r>>8)>=NPART || !r) + continue; + if ((r&0xFF)==PT_FIRE){ + sim->kill_part(r>>8); + if(1>(rand()%150)){ + sim->kill_part(i); + return 1; + } + } + if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%250)) + { + sim->part_change_type(r>>8, x+rx, y+ry, PT_CBNW); + if (parts[i].ctype==5) //conserve number of water particles - ctype=5 means this CO2 hasn't released the water particle from BUBW yet + sim->create_part(i, x, y, PT_WATR); + else + sim->kill_part(i); + } + } + if (parts[i].temp > 9773.15 && sim->pv[y/CELL][x/CELL] > 200.0f) + { + if (rand()%5 < 1) + { + int j; + sim->create_part(i,x,y,PT_O2); + + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); + if (j != -1) + parts[j].temp = 15000; + if (!(rand()%50)) + { + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); + if (j != -1) + parts[j].temp = 15000; + } + + parts[i].temp = 15000; + sim->pv[y/CELL][x/CELL] += 100; + } + } + return 0; +} + + +Element_CO2::~Element_CO2() {} diff --git a/src/simulation/elements/COAL.cpp b/src/simulation/elements/COAL.cpp new file mode 100644 index 0000000..eae7450 --- /dev/null +++ b/src/simulation/elements/COAL.cpp @@ -0,0 +1,153 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_COAL PT_COAL 59 +Element_COAL::Element_COAL() +{ + Identifier = "DEFAULT_PT_COAL"; + Name = "COAL"; + Colour = PIXPACK(0x222222); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.0f; + HotAir = 0.0f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 200; + Description = "Solid. Burns slowly."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_COAL::update; + Graphics = &Element_COAL::graphics; +} + +//#TPT-Directive ElementHeader Element_COAL static int update(UPDATE_FUNC_ARGS) +int Element_COAL::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, trade, temp; + if (parts[i].life<=0) { + sim->create_part(i, x, y, PT_FIRE); + return 1; + } else if (parts[i].life < 100) { + parts[i].life--; + sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE); + } + if ((sim->pv[y/CELL][x/CELL] > 4.3f)&&parts[i].tmp>40) + parts[i].tmp=39; + else if (parts[i].tmp<40&&parts[i].tmp>0) + parts[i].tmp--; + else if (parts[i].tmp<=0) { + sim->create_part(i, x, y, PT_BCOL); + return 1; + } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) && 1>(rand()%500)) + { + if (parts[i].life>100) { + parts[i].life = 99; + } + } + if ((r&0xFF)==PT_LAVA && 1>(rand()%500)) + { + if (parts[r>>8].ctype == PT_IRON) { + parts[r>>8].ctype = PT_METL; + sim->kill_part(i); + return 1; + } + } + } + /*if(100-parts[i].life > parts[i].tmp2) + parts[i].tmp2 = 100-parts[i].life; + if(parts[i].tmp2 < 0) parts[i].tmp2 = 0; + for ( trade = 0; trade<4; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL)&&(parts[i].tmp2>parts[r>>8].tmp2)&&parts[i].tmp2>0)//diffusion + { + int temp = parts[i].tmp2 - parts[r>>8].tmp2; + if(temp < 10) + continue; + if (temp ==1) + { + parts[r>>8].tmp2 ++; + parts[i].tmp2 --; + } + else if (temp>0) + { + parts[r>>8].tmp2 += temp/2; + parts[i].tmp2 -= temp/2; + } + } + } + }*/ + if(parts[i].temp > parts[i].tmp2) + parts[i].tmp2 = parts[i].temp; + return 0; +} + + +//#TPT-Directive ElementHeader Element_COAL static int graphics(GRAPHICS_FUNC_ARGS) +int Element_COAL::graphics(GRAPHICS_FUNC_ARGS) + //Both COAL and Broken Coal +{ + *colr += (cpart->tmp2-295.15f)/3; + + if (*colr > 170) + *colr = 170; + if (*colr < *colg) + *colr = *colg; + + *colg = *colb = *colr; + + if((cpart->temp-295.15f) > 300.0f-200.0f) + { + float frequency = 3.1415/(2*300.0f-(300.0f-200.0f)); + int q = ((cpart->temp-295.15f)>300.0f)?300.0f-(300.0f-200.0f):(cpart->temp-295.15f)-(300.0f-200.0f); + + *colr += sin(frequency*q) * 226; + *colg += sin(frequency*q*4.55 +3.14) * 34; + *colb += sin(frequency*q*2.22 +3.14) * 64; + } + return 0; +} + + + +Element_COAL::~Element_COAL() {}
\ No newline at end of file diff --git a/src/simulation/elements/CONV.cpp b/src/simulation/elements/CONV.cpp new file mode 100644 index 0000000..6ad1336 --- /dev/null +++ b/src/simulation/elements/CONV.cpp @@ -0,0 +1,96 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_CONV PT_CONV 85 +Element_CONV::Element_CONV() +{ + Identifier = "DEFAULT_PT_CONV"; + Name = "CONV"; + Colour = PIXPACK(0x0AAB0A); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Solid. Converts whatever touches it into its ctype."; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_CONV::update; + +} + +//#TPT-Directive ElementHeader Element_CONV static int update(UPDATE_FUNC_ARGS) +int Element_CONV::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) + { + r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && + (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_STKM && + (r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 && + (r&0xFF)!=PT_CONV && (r&0xFF)<PT_NUM) + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE) + parts[i].tmp = parts[r>>8].ctype; + } + } + } + else if(parts[i].ctype>0 && parts[i].ctype<PT_NUM && sim->elements[parts[i].ctype].Enabled && parts[i].ctype!=PT_CONV) { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) + { + r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if((r&0xFF)!=PT_CONV && (r&0xFF)!=PT_DMND && (r&0xFF)!=parts[i].ctype) + { + if (parts[i].ctype==PT_LIFE) sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8)); + else sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype); + } + } + } + return 0; +} + + +Element_CONV::~Element_CONV() {}
\ No newline at end of file diff --git a/src/simulation/elements/DESL.cpp b/src/simulation/elements/DESL.cpp new file mode 100644 index 0000000..a79086d --- /dev/null +++ b/src/simulation/elements/DESL.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DESL PT_DESL 58 +Element_DESL::Element_DESL() +{ + Identifier = "DEFAULT_PT_DESL"; + Name = "DESL"; + Colour = PIXPACK(0x440000); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 1.0f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.0f; + HotAir = 0.0f * CFDS; + Falldown = 2; + + Flammable = 2; + Explosive = 0; + Meltable = 0; + Hardness = 5; + + Weight = 15; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 42; + Description = "Liquid. Explodes under high pressure and temperatures"; + + State = ST_LIQUID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 5.0f; + HighPressureTransition = PT_FIRE; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 335.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + +} + +Element_DESL::~Element_DESL() {}
\ No newline at end of file diff --git a/src/simulation/elements/DEST.cpp b/src/simulation/elements/DEST.cpp new file mode 100644 index 0000000..a4f7891 --- /dev/null +++ b/src/simulation/elements/DEST.cpp @@ -0,0 +1,121 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DEST PT_DEST 89 +Element_DEST::Element_DEST() +{ + Identifier = "DEFAULT_PT_DEST"; + Name = "DEST"; + Colour = PIXPACK(0xFF3311); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = -0.05f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.95f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.4f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 101; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 150; + Description = "More destructive Bomb."; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_DEST::update; + Graphics = &Element_DEST::graphics; +} + +//#TPT-Directive ElementHeader Element_DEST static int update(UPDATE_FUNC_ARGS) +int Element_DEST::update(UPDATE_FUNC_ARGS) + { + int r,rx,ry,topv; + rx=rand()%5-2; + ry=rand()%5-2; + + r = pmap[y+ry][x+rx]; + if (!r || (r&0xFF)==PT_DEST || (r&0xFF)==PT_DMND || (r&0xFF)==PT_BCLN || (r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN || (r&0xFF)==PT_PBCN) + return 0; + + if (parts[i].life<=0 || parts[i].life>37) + { + parts[i].life=30+rand()%20; + parts[i].temp+=20000; + sim->pv[y/CELL][x/CELL]+=60.0f; + } + parts[i].temp+=10000; + if ((r&0xFF)==PT_PLUT || (r&0xFF)==PT_DEUT) + { + sim->pv[y/CELL][x/CELL]+=20.0f; + parts[i].temp+=18000; + if (rand()%2==0) + { + float orig_temp = parts[r>>8].temp; + sim->create_part(r>>8, x+rx, y+ry, PT_NEUT); + parts[r>>8].temp = restrict_flt(orig_temp+40000.0f, MIN_TEMP, MAX_TEMP); + sim->pv[y/CELL][x/CELL] += 10.0f; + parts[i].life-=4; + } + } + else if ((r&0xFF)==PT_INSL) + { + sim->create_part(r>>8, x+rx, y+ry, PT_PLSM); + } + else if (rand()%3==0) + { + sim->kill_part(r>>8); + parts[i].life -= 4*((sim->elements[r&0xFF].Properties&TYPE_SOLID)?3:1); + if (parts[i].life<=0) + parts[i].life=1; + parts[i].temp+=10000; + } + else + { + if (sim->elements[r&0xFF].HeatConduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+10000.0f, MIN_TEMP, MAX_TEMP); + } + topv=sim->pv[y/CELL][x/CELL]/9+parts[r>>8].temp/900; + if (topv>40.0f) + topv=40.0f; + sim->pv[y/CELL][x/CELL]+=40.0f+topv; + parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP); + return 0; +} + + +//#TPT-Directive ElementHeader Element_DEST static int graphics(GRAPHICS_FUNC_ARGS) +int Element_DEST::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(cpart->life) + { + *pixel_mode |= PMODE_LFLARE; + } + else + { + *pixel_mode |= PMODE_SPARK; + } + return 0; +} + + +Element_DEST::~Element_DEST() {}
\ No newline at end of file diff --git a/src/simulation/elements/DEUT.cpp b/src/simulation/elements/DEUT.cpp new file mode 100644 index 0000000..b8209e4 --- /dev/null +++ b/src/simulation/elements/DEUT.cpp @@ -0,0 +1,149 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DEUT PT_DEUT 95 +Element_DEUT::Element_DEUT() +{ + Identifier = "DEFAULT_PT_DEUT"; + Name = "DEUT"; + Colour = PIXPACK(0x00153F); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 31; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 251; + Description = "Deuterium oxide. Volume changes with temp, radioactive with neutrons."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_DEUT::update; + Graphics = &Element_DEUT::graphics; +} + +//#TPT-Directive ElementHeader Element_DEUT static int update(UPDATE_FUNC_ARGS) +int Element_DEUT::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, trade, np; + float gravtot = fabs(sim->gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(sim->gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]); + int maxlife = ((10000/(parts[i].temp + 1))-1); + if ((10000%((int)parts[i].temp+1))>rand()%((int)parts[i].temp+1)) + maxlife ++; + // Compress when Newtonian gravity is applied + // multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf + maxlife = maxlife*(5.0f - 8.0f/(gravtot+2.0f)); + if (parts[i].life < maxlife) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r || (parts[i].life >=maxlife)) + continue; + if ((r&0xFF)==PT_DEUT&&33>=rand()/(RAND_MAX/100)+1) + { + if ((parts[i].life + parts[r>>8].life + 1) <= maxlife) + { + parts[i].life += parts[r>>8].life + 1; + sim->kill_part(r>>8); + } + } + } + } + else + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (parts[i].life<=maxlife) + continue; + if ((!r)&&parts[i].life>=1)//if nothing then create deut + { + np = sim->create_part(-1,x+rx,y+ry,PT_DEUT); + if (np<0) continue; + parts[i].life--; + parts[np].temp = parts[i].temp; + parts[np].life = 0; + } + } + for ( trade = 0; trade<4; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_DEUT&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion + { + int temp = parts[i].life - parts[r>>8].life; + if (temp ==1) + { + parts[r>>8].life ++; + parts[i].life --; + } + else if (temp>0) + { + parts[r>>8].life += temp/2; + parts[i].life -= temp/2; + } + } + } + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_DEUT static int graphics(GRAPHICS_FUNC_ARGS) +int Element_DEUT::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(cpart->life>=700) + { + *firea = 60; + *firer = *colr += cpart->life*1; + *fireg = *colg += cpart->life*2; + *fireb = *colb += cpart->life*3; + *pixel_mode |= PMODE_GLOW | FIRE_ADD; + } + else + { + *colr += cpart->life*1; + *colg += cpart->life*2; + *colb += cpart->life*3; + *pixel_mode |= PMODE_BLUR; + } + return 0; +} + + +Element_DEUT::~Element_DEUT() {}
\ No newline at end of file diff --git a/src/simulation/elements/DLAY.cpp b/src/simulation/elements/DLAY.cpp new file mode 100644 index 0000000..e69c202 --- /dev/null +++ b/src/simulation/elements/DLAY.cpp @@ -0,0 +1,111 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DLAY PT_DLAY 79 +Element_DLAY::Element_DLAY() +{ + Identifier = "DEFAULT_PT_DLAY"; + Name = "DLAY"; + Colour = PIXPACK(0x753590); + MenuVisible = 1; + MenuSection = SC_POWERED; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = 4.0f+273.15f; + HeatConduct = 0; + Description = "Conducts with temperature-dependent delay. (use HEAT/COOL)."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_DLAY::update; + Graphics = &Element_DLAY::graphics; +} + +//#TPT-Directive ElementHeader Element_DLAY static int update(UPDATE_FUNC_ARGS) +int Element_DLAY::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, oldl; + oldl = parts[i].life; + if (parts[i].life>0) + parts[i].life--; + //if (parts[i].life==1) + //{ + if (parts[i].temp>=MAX_TEMP+273.15f) + parts[i].temp = MAX_TEMP+273.15f; + if (parts[i].temp<= 1.0f+273.15f) + parts[i].temp = 1.0f+273.15f; + + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r || sim->parts_avg(r>>8, i,PT_INSL)==PT_INSL) + continue; + if ((r&0xFF)==PT_SPRK && parts[i].life==0 && parts[r>>8].life>0 && parts[r>>8].life<4 && parts[r>>8].ctype==PT_PSCN) + { + parts[i].life = (int)(parts[i].temp-273.15); + } + else if ((r&0xFF)==PT_DLAY) + { + if(!parts[i].life && parts[r>>8].life) + { + parts[i].life = parts[r>>8].life; + if((r>>8)>i) //If the other particle hasn't been life updated + parts[i].life--; + } + else if(parts[i].life && !parts[r>>8].life) + { + parts[r>>8].life = parts[i].life; + if((r>>8)>i) //If the other particle hasn't been life updated + parts[r>>8].life++; + } + } + else if((r&0xFF)==PT_NSCN && oldl==1) + { + sim->create_part(-1, x+rx, y+ry, PT_SPRK); + } + } + //} + return 0; +} + + +//#TPT-Directive ElementHeader Element_DLAY static int graphics(GRAPHICS_FUNC_ARGS) +int Element_DLAY::graphics(GRAPHICS_FUNC_ARGS) + +{ + int stage = (int)(((float)cpart->life/(cpart->temp-273.15))*100.0f); + *colr += stage; + *colg += stage; + *colb += stage; + return 0; +} + + +Element_DLAY::~Element_DLAY() {}
\ No newline at end of file diff --git a/src/simulation/elements/DMG.cpp b/src/simulation/elements/DMG.cpp new file mode 100644 index 0000000..9c19199 --- /dev/null +++ b/src/simulation/elements/DMG.cpp @@ -0,0 +1,118 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DMG PT_DMG 163 +Element_DMG::Element_DMG() +{ + Identifier = "DEFAULT_PT_DMG"; + Name = "DMG"; + Colour = PIXPACK(0x88FF88); + MenuVisible = 1; + MenuSection = SC_FORCE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "DMG."; + + State = ST_NONE; + Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC|PROP_SPARKSETTLE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_DMG::update; + Graphics = &Element_DMG::graphics; +} + +//#TPT-Directive ElementHeader Element_DMG static int update(UPDATE_FUNC_ARGS) +int Element_DMG::update(UPDATE_FUNC_ARGS) + { + int r, rr, rx, ry, nb, nxi, nxj, t, dist; + int rad = 25; + float angle, fx, fy; + + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_DMG && (r&0xFF)!=PT_EMBR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_BCLN) + { + sim->kill_part(i); + for (nxj=-rad; nxj<=rad; nxj++) + for (nxi=-rad; nxi<=rad; nxi++) + if (x+nxi>=0 && y+nxj>=0 && x+nxi<XRES && y+nxj<YRES && (nxi || nxj)) + { + dist = sqrt(pow(nxi, 2.0f)+pow(nxj, 2.0f));//;(pow((float)nxi,2))/(pow((float)rad,2))+(pow((float)nxj,2))/(pow((float)rad,2)); + if (!dist || (dist <= rad)) + { + rr = pmap[y+nxj][x+nxi]; + if (rr) + { + angle = atan2((float)nxj, nxi); + fx = cos(angle) * 7.0f; + fy = sin(angle) * 7.0f; + + parts[rr>>8].vx += fx; + parts[rr>>8].vy += fy; + + sim->vx[(y+nxj)/CELL][(x+nxi)/CELL] += fx; + sim->vy[(y+nxj)/CELL][(x+nxi)/CELL] += fy; + + sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 1.0f; + + t = parts[rr>>8].type; + if(t && sim->elements[t].HighPressureTransition>-1 && sim->elements[t].HighPressureTransition<PT_NUM) + sim->part_change_type(rr>>8, x+nxi, y+nxj, sim->elements[t].HighPressureTransition); + else if(t == PT_BMTL) + sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BRMT); + else if(t == PT_GLAS) + sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BGLA); + else if(t == PT_COAL) + sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BCOL); + else if(t == PT_QRTZ) + sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_PQRT); + } + } + } + return 1; + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_DMG static int graphics(GRAPHICS_FUNC_ARGS) +int Element_DMG::graphics(GRAPHICS_FUNC_ARGS) + +{ + *pixel_mode |= PMODE_FLARE; + return 1; +} + + +Element_DMG::~Element_DMG() {} diff --git a/src/simulation/elements/DMND.cpp b/src/simulation/elements/DMND.cpp new file mode 100644 index 0000000..3c6d24a --- /dev/null +++ b/src/simulation/elements/DMND.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DMND PT_DMND 28 +Element_DMND::Element_DMND() +{ + Identifier = "DEFAULT_PT_DMND"; + Name = "DMND"; + Colour = PIXPACK(0xCCFFFF); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = R_TEMP+0.0f +273.15f; + HeatConduct = 186; + Description = "Diamond. Indestructible."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_DMND::~Element_DMND() {}
\ No newline at end of file diff --git a/src/simulation/elements/DRIC.cpp b/src/simulation/elements/DRIC.cpp new file mode 100644 index 0000000..ea2a3c8 --- /dev/null +++ b/src/simulation/elements/DRIC.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DRIC PT_DRIC 81 +Element_DRIC::Element_DRIC() +{ + Identifier = "DEFAULT_PT_DRIC"; + Name = "DRIC"; + Colour = PIXPACK(0xE0E0E0); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = -0.0005f* CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 100; + + Temperature = 172.65f; + HeatConduct = 2; + Description = "Dry Ice."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 195.65f; + HighTemperatureTransition = PT_CO2; + + Update = NULL; + +} + +Element_DRIC::~Element_DRIC() {}
\ No newline at end of file diff --git a/src/simulation/elements/DSTW.cpp b/src/simulation/elements/DSTW.cpp new file mode 100644 index 0000000..8b16107 --- /dev/null +++ b/src/simulation/elements/DSTW.cpp @@ -0,0 +1,92 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DSTW PT_DSTW 25 +Element_DSTW::Element_DSTW() +{ + Identifier = "DEFAULT_PT_DSTW"; + Name = "DSTW"; + Colour = PIXPACK(0x1020C0); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 23; + Description = "Distilled water, does not conduct electricity."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 273.15f; + LowTemperatureTransition = PT_ICEI; + HighTemperature = 373.0f; + HighTemperatureTransition = PT_WTRV; + + Update = &Element_DSTW::update; + +} + +//#TPT-Directive ElementHeader Element_DSTW static int update(UPDATE_FUNC_ARGS) +int Element_DSTW::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SALT && 1>(rand()%250)) + { + sim->part_change_type(i,x,y,PT_SLTW); + // on average, convert 3 DSTW to SLTW before SALT turns into SLTW + if (rand()%3==0) + sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW); + } + if (((r&0xFF)==PT_WATR||(r&0xFF)==PT_SLTW) && 1>(rand()%500)) + { + sim->part_change_type(i,x,y,PT_WATR); + } + if ((r&0xFF)==PT_SLTW && 1>(rand()%10000)) + { + sim->part_change_type(i,x,y,PT_SLTW); + } + if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>12.0f) && 1>(rand()%500)) + { + sim->part_change_type(i,x,y,PT_FIRE); + parts[i].life = 4; + } + if ((r&0xFF)==PT_FIRE){ + sim->kill_part(r>>8); + if(1>(rand()%150)){ + sim->kill_part(i); + return 1; + } + } + } + return 0; +} + + +Element_DSTW::~Element_DSTW() {}
\ No newline at end of file diff --git a/src/simulation/elements/DTEC.cpp b/src/simulation/elements/DTEC.cpp new file mode 100644 index 0000000..6d67cf2 --- /dev/null +++ b/src/simulation/elements/DTEC.cpp @@ -0,0 +1,99 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DTEC PT_DTEC 162 +Element_DTEC::Element_DTEC() +{ + Identifier = "DEFAULT_PT_DTEC"; + Name = "DTEC"; + Colour = PIXPACK(0xFD9D18); + MenuVisible = 1; + MenuSection = SC_SENSOR; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.96f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Creates a spark when something with its ctype is nearby"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_DTEC::update; + +} + +//#TPT-Directive ElementHeader Element_DTEC static int in_radius(int rd, int x, int y) +int Element_DTEC::in_radius(int rd, int x, int y) +{ + return (pow((double)x,2)*pow((double)rd,2)+pow((double)y,2)*pow((double)rd,2)<=pow((double)rd,2)*pow((double)rd,2)); +} + +//#TPT-Directive ElementHeader Element_DTEC static int update(UPDATE_FUNC_ARGS) +int Element_DTEC::update(UPDATE_FUNC_ARGS) +{ + int r, rx, ry, rt, rd = parts[i].tmp2; + if (rd > 25) parts[i].tmp2 = rd = 25; + if (parts[i].life) + { + parts[i].life = 0; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + rt = parts[r>>8].type; + if (sim->parts_avg(i,r>>8,PT_INSL) != PT_INSL) + { + if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[r>>8].life==0 && in_radius(rd, rx, ry)) + { + parts[r>>8].life = 4; + parts[r>>8].ctype = rt; + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + } + } + } + } + for (rx=-rd; rx<rd+1; rx++) + for (ry=-rd; ry<rd+1; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if(!r) + r = sim->photons[y+ry][x+rx]; + if(!r) + continue; + if (parts[r>>8].type == parts[i].ctype && (parts[i].ctype != PT_LIFE || parts[i].tmp == parts[r>>8].tmp)) + parts[i].life = 1; + } + return 0; +} + + + +Element_DTEC::~Element_DTEC() {} diff --git a/src/simulation/elements/DUST.cpp b/src/simulation/elements/DUST.cpp new file mode 100644 index 0000000..924dabb --- /dev/null +++ b/src/simulation/elements/DUST.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DUST PT_DUST 1 +Element_DUST::Element_DUST() +{ + Identifier = "DEFAULT_PT_DUST"; + Name = "DUST"; + Colour = PIXPACK(0xFFE0A0); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.96f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 10; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 85; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Very light dust. Flammable."; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + Graphics = NULL; +} + +Element_DUST::~Element_DUST() {}
\ No newline at end of file diff --git a/src/simulation/elements/DYST.cpp b/src/simulation/elements/DYST.cpp new file mode 100644 index 0000000..fdf16bb --- /dev/null +++ b/src/simulation/elements/DYST.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DYST PT_DYST 64 +Element_DYST::Element_DYST() +{ + Identifier = "DEFAULT_PT_DYST"; + Name = "DYST"; + Colour = PIXPACK(0xBBB0A0); + MenuVisible = 0; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.96f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 20; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 80; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Dead Yeast."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 473.0f; + HighTemperatureTransition = PT_DUST; + + Update = NULL; + +} + +Element_DYST::~Element_DYST() {}
\ No newline at end of file diff --git a/src/simulation/elements/ELEC.cpp b/src/simulation/elements/ELEC.cpp new file mode 100644 index 0000000..c602da8 --- /dev/null +++ b/src/simulation/elements/ELEC.cpp @@ -0,0 +1,160 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ELEC PT_ELEC 136 +Element_ELEC::Element_ELEC() +{ + Identifier = "DEFAULT_PT_ELEC"; + Name = "ELEC"; + Colour = PIXPACK(0xDFEFFF); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + Loss = 1.00f; + Collision = -0.99f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = -1; + + Temperature = R_TEMP+200.0f+273.15f; + HeatConduct = 251; + Description = "Electrons"; + + State = ST_GAS; + Properties = TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_ELEC::update; + Graphics = &Element_ELEC::graphics; +} + +//#TPT-Directive ElementHeader Element_ELEC static int update(UPDATE_FUNC_ARGS) +int Element_ELEC::update(UPDATE_FUNC_ARGS) + { + int r, rt, rx, ry, nb, rrx, rry; + float rr, rrr; + parts[i].pavg[0] = x; + parts[i].pavg[1] = y; + if(pmap[y][x]==PT_GLOW) + { + sim->part_change_type(i, x, y, PT_PHOT); + } + for (rx=-2; rx<=2; rx++) + for (ry=-2; ry<=2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) { + r = pmap[y+ry][x+rx]; + if (!r) + r = sim->photons[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_GLAS) + { + for (rrx=-1; rrx<=1; rrx++) + { + for (rry=-1; rry<=1; rry++) + { + if (x+rx+rrx>=0 && y+ry+rry>=0 && x+rx+rrx<XRES && y+ry+rry<YRES) { + nb = sim->create_part(-1, x+rx+rrx, y+ry+rry, PT_EMBR); + if (nb!=-1) { + parts[nb].tmp = 0; + parts[nb].life = 50; + parts[nb].temp = parts[i].temp*0.8f; + parts[nb].vx = rand()%20-10; + parts[nb].vy = rand()%20-10; + } + } + } + } + //fire_r[y/CELL][x/CELL] += rand()%200; //D: Doesn't work with OpenGL, also shouldn't be here + //fire_g[y/CELL][x/CELL] += rand()%200; + //fire_b[y/CELL][x/CELL] += rand()%200; + /* possible alternative, but doesn't work well at the moment because FIRE_ADD divides firea by 8, so the glow isn't strong enough + create_part(i, x, y, PT_EMBR); + parts[i].tmp = 2; + parts[i].life = 2; + parts[i].ctype = ((rand()%200)<<16) | ((rand()%200)<<8) | (rand()%200); + */ + sim->kill_part(i); + return 1; + } + if ((r&0xFF)==PT_LCRY) + { + parts[r>>8].tmp2 = 5+rand()%5; + } + if ((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_SLTW || (r&0xFF)==PT_CBNW) + { + if(rand()<RAND_MAX/3) + { + sim->create_part(r>>8, x+rx, y+ry, PT_O2); + return 1; + } + else + { + sim->create_part(r>>8, x+rx, y+ry, PT_H2); + return 1; + } + } + if ((r&0xFF)==PT_NEUT && !pmap[y+ry][x+rx]) + { + sim->part_change_type(r>>8, x+rx, y+ry, PT_H2); + parts[r>>8].life = 0; + parts[r>>8].ctype = 0; + } + if ((r&0xFF)==PT_DEUT) + { + if(parts[r>>8].life < 6000) + parts[r>>8].life += 1; + parts[r>>8].temp = 0; + sim->kill_part(i); + return 1; + } + if ((r&0xFF)==PT_EXOT) + { + parts[r>>8].tmp2 += 5; + parts[r>>8].life = 1000; + } + if ((sim->elements[r&0xFF].Properties & PROP_CONDUCTS) && ((r&0xFF)!=PT_NBLE||parts[i].temp<2273.15)) + { + sim->create_part(-1, x+rx, y+ry, PT_SPRK); + sim->kill_part(i); + return 1; + } + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_ELEC static int graphics(GRAPHICS_FUNC_ARGS) +int Element_ELEC::graphics(GRAPHICS_FUNC_ARGS) + +{ + *firea = 70; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + + *pixel_mode |= FIRE_ADD; + return 0; +} + + +Element_ELEC::~Element_ELEC() {} diff --git a/src/simulation/elements/EMBR.cpp b/src/simulation/elements/EMBR.cpp new file mode 100644 index 0000000..5ba37c2 --- /dev/null +++ b/src/simulation/elements/EMBR.cpp @@ -0,0 +1,126 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_EMBR PT_EMBR 147 +Element_EMBR::Element_EMBR() +{ + + //{"EMBR", PIXPACK(0xFFF288), 0.4f, 0.001f * CFDS, 0.99f, 0.90f, 0.0f, 0.07f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 20, 0, 1, 30, SC_EXPLOSIVE, 500.0f +273.15f, 29, "Sparks. Formed by explosions.", ST_NONE, TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL|PROP_SPARKSETTLE, &update_EMBR, &graphics_EMBR}, + + Identifier = "DEFAULT_PT_EMBR"; + Name = "EMBR"; + Colour = PIXPACK(0xFFF288); + MenuVisible = 0; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.001f * CFDS; + AirLoss = 0.99f; + Loss = 0.90f; + Collision = 0.0f; + Gravity = 0.07f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = 500.0f +273.15f; + HeatConduct = 29; + Description = "Sparks. Formed by explosions."; + + State = ST_NONE; + Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL|PROP_SPARKSETTLE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_EMBR::update; + Graphics = &Element_EMBR::graphics; +} + +//#TPT-Directive ElementHeader Element_EMBR static int update(UPDATE_FUNC_ARGS) +int Element_EMBR::update(UPDATE_FUNC_ARGS) { + int r, rx, ry, nb; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((sim->elements[r&0xFF].Properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID)) && !(sim->elements[r&0xFF].Properties & PROP_SPARKSETTLE)) + { + sim->kill_part(i); + return 1; + } + } + return 0; +} + +//#TPT-Directive ElementHeader Element_EMBR static int graphics(GRAPHICS_FUNC_ARGS) +int Element_EMBR::graphics(GRAPHICS_FUNC_ARGS) +{ + if (cpart->ctype&0xFFFFFF) + { + int maxComponent; + *colr = (cpart->ctype&0xFF0000)>>16; + *colg = (cpart->ctype&0x00FF00)>>8; + *colb = (cpart->ctype&0x0000FF); + maxComponent = *colr; + + if (*colg>maxComponent) maxComponent = *colg; + if (*colb>maxComponent) maxComponent = *colb; + if (maxComponent<60)//make sure it isn't too dark to see + { + float multiplier = 60.0f/maxComponent; + *colr *= multiplier; + *colg *= multiplier; + *colb *= multiplier; + } + } + else if (cpart->tmp != 0) + { + *colr = *colg = *colb = 255; + } + + if (ren->decorations_enable && cpart->dcolour) + { + int a = (cpart->dcolour>>24)&0xFF; + *colr = (a*((cpart->dcolour>>16)&0xFF) + (255-a)**colr) >> 8; + *colg = (a*((cpart->dcolour>>8)&0xFF) + (255-a)**colg) >> 8; + *colb = (a*((cpart->dcolour)&0xFF) + (255-a)**colb) >> 8; + } + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + if (cpart->tmp==1) + { + *pixel_mode = FIRE_ADD | PMODE_BLEND | PMODE_GLOW; + *firea = (cpart->life-15)*4; + *cola = (cpart->life+15)*4; + } + else if (cpart->tmp==2) + { + *pixel_mode = PMODE_FLAT | FIRE_ADD; + *firea = 255; + } + else + { + *pixel_mode = PMODE_SPARK | PMODE_ADD; + if (cpart->life<64) *cola = 4*cpart->life; + } + return 0; +} + +Element_EMBR::~Element_EMBR() {} diff --git a/src/simulation/elements/EMP.cpp b/src/simulation/elements/EMP.cpp new file mode 100644 index 0000000..e21f69c --- /dev/null +++ b/src/simulation/elements/EMP.cpp @@ -0,0 +1,183 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_EMP PT_EMP 134 +Element_EMP::Element_EMP() +{ + Identifier = "DEFAULT_PT_EMP"; + Name = "EMP"; + Colour = PIXPACK(0x66AAFF); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.0f; + HotAir = 0.0f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 3; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 121; + Description = "Breaks activated electronics."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_EMP::update; + Graphics = &Element_EMP::graphics; +} + +//#TPT-Directive ElementHeader Element_EMP static int update(UPDATE_FUNC_ARGS) +int Element_EMP::update(UPDATE_FUNC_ARGS) + { + int r,rx,ry,ok=0,t,n,nx,ny; + if (parts[i].life) + return 0; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SPRK && parts[r>>8].life>0 && parts[r>>8].life<4) + { + ok=1; + break; + } + } + if (!ok) + return 0; + parts[i].life=220; + sim->emp_decor += 3; + if (sim->emp_decor > 40) + sim->emp_decor = 40; + for (r=0; r<=sim->parts_lastActiveIndex; r++) + { + t=parts[r].type; + rx=parts[r].x; + ry=parts[r].y; + if (t==PT_SPRK || (t==PT_SWCH && parts[r].life!=0 && parts[r].life!=10) || (t==PT_WIRE && parts[r].ctype>0)) + { + int is_elec=0; + if ((parts[r].ctype==PT_PSCN || parts[r].ctype==PT_NSCN || parts[r].ctype==PT_PTCT || + parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH) || t==PT_WIRE || t==PT_SWCH) + { + is_elec=1; + if (sim->elements[parts[r].type].HeatConduct && rand()%100==0) + parts[r].temp = restrict_flt(parts[r].temp+3000.0f, MIN_TEMP, MAX_TEMP); + if (rand()%80==0) + sim->part_change_type(r, rx, ry, PT_BREC); + else if (rand()%120==0) + sim->part_change_type(r, rx, ry, PT_NTCT); + } + + for (nx=-2; nx<3; nx++) + for (ny=-2; ny<3; ny++) + if (rx+nx>=0 && ry+ny>=0 && rx+nx<XRES && ry+ny<YRES && (rx || ry)) + { + n = pmap[ry+ny][rx+nx]; + if (!n) + continue; + /*if ((n&0xFF)==PT_BTRY && rand()%60==0) + { + part_change_type(n>>8, rx+nx, ry+ny, PT_PLSM); + parts[n>>8].life=rand()%100+70; + parts[n>>8].temp+=3000; + }*/ + + //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 + if (is_elec) + { + if (((n&0xFF)==PT_METL || (n&0xFF)==PT_BMTL) && rand()%280==0) + { + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP); + } + if ((n&0xFF)==PT_BMTL && rand()%160==0) + { + sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);//TODO: Redundant, was this meant to be BRMT or something? + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); + } + if ((n&0xFF)==PT_METL && rand()%300==0) + { + sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL); + } + if ((n&0xFF)==PT_WIFI && rand()%8==0) + { + //Randomise channel + parts[n>>8].temp = rand()%MAX_TEMP; + } + if ((n&0xFF)==PT_WIFI && rand()%16==0) + { + sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC); + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); + } + } + if ((n&0xFF)==PT_SWCH && rand()%100==0) + { + sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BREC); + } + if ((n&0xFF)==PT_SWCH && rand()%100==0) + { + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+2000.0f, MIN_TEMP, MAX_TEMP); + } + if ((n&0xFF)==PT_ARAY && rand()%60==0) + { + sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC); + parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); + } + if (t==PT_DLAY && rand()%70==0) + { + //Randomise delay + parts[n>>8].temp = (rand()%256) + 273.15f; + } + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_EMP static int graphics(GRAPHICS_FUNC_ARGS) +int Element_EMP::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(cpart->life) + { + *colr = cpart->life*1.5; + *colg = cpart->life*1.5; + *colb = 200-(cpart->life); + if (*colr>255) + *colr = 255; + if (*colg>255) + *colg = 255; + if (*colb>255) + *colb = 255; + if (*colb<=0) + *colb = 0; + } + return 0; +} + + +Element_EMP::~Element_EMP() {}
\ No newline at end of file diff --git a/src/simulation/elements/ETRD.cpp b/src/simulation/elements/ETRD.cpp new file mode 100644 index 0000000..3a63f6f --- /dev/null +++ b/src/simulation/elements/ETRD.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ETRD PT_ETRD 50 +Element_ETRD::Element_ETRD() +{ + Identifier = "DEFAULT_PT_ETRD"; + Name = "ETRD"; + Colour = PIXPACK(0x404040); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Electrode. Creates a surface that allows Plasma arcs. (Use sparingly)"; + + State = ST_NONE; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_ETRD::~Element_ETRD() {}
\ No newline at end of file diff --git a/src/simulation/elements/EXOT.cpp b/src/simulation/elements/EXOT.cpp new file mode 100644 index 0000000..03eca2f --- /dev/null +++ b/src/simulation/elements/EXOT.cpp @@ -0,0 +1,211 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_EXOT PT_EXOT 145 +Element_EXOT::Element_EXOT() +{ + Identifier = "DEFAULT_PT_EXOT"; + Name = "EXOT"; + Colour = PIXPACK(0x404040); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.3f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.95f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.15f; + Diffusion = 0.00f; + HotAir = 0.0003f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 2; + + Weight = 46; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 250; + Description = "Exotic matter. Explodes with excess exposure to electrons."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_EXOT::update; + Graphics = &Element_EXOT::graphics; +} + +//#TPT-Directive ElementHeader Element_EXOT static int update(UPDATE_FUNC_ARGS) +int Element_EXOT::update(UPDATE_FUNC_ARGS) { + int r, rt, rx, ry, nb, rrx, rry, trade, tym, t; + t = parts[i].type; + for (rx=-2; rx<=2; rx++) + for (ry=-2; ry<=2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF) == PT_WARP) + { + if (parts[r>>8].tmp2>2000) + if (1>rand()%100) + { + parts[i].tmp2 += 100; + } + } + else if ((r&0xFF) == PT_EXOT && parts[r>>8].life == 1500 && 1>rand()%1000) + parts[i].life = 1500; + else if ((r&0xFF) == PT_LAVA) + { + if (parts[r>>8].ctype == PT_TTAN && 1>rand()%10) + { + parts[r>>8].ctype = PT_VIBR; + sim->kill_part(i); + return 1; + } + /*else if (parts[r>>8].ctype == PT_VIBR && 1>rand()%1000) + { + sim->kill_part(i); + return 1; + }*/ + } + if ((parts[i].tmp>245) && (parts[i].life>1000)) + if ((r&0xFF)!=PT_EXOT && (r&0xFF)!=PT_BREC && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PRTI && (r&0xFF)!=PT_PRTO && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_PHOT && (r&0xFF)!=PT_VOID && (r&0xFF)!=PT_NBHL && (r&0xFF)!=PT_WARP && (r&0xFF)!=PT_NEUT) + { + sim->create_part(i, x, y, parts[r>>8].type); + return 0; + } + } + parts[i].tmp--; + parts[i].tmp2--; + if (parts[i].tmp<1 || parts[i].tmp>250) + parts[i].tmp = 250; + if (parts[i].tmp2<1) + parts[i].tmp2 = 1; + else if (parts[i].tmp2>6000) + { + parts[i].tmp2 = 10000; + if (parts[i].life<1001) + { + sim->part_change_type(i, x, y, PT_WARP); + return 0; + } + } + else if(parts[i].life<1001) + sim->pv[y/CELL][x/CELL] += (parts[i].tmp2*CFDS)/160000; + if (sim->pv[y/CELL][x/CELL]>200 && parts[i].temp>9000 && parts[i].tmp2>200) + { + parts[i].tmp2 = 6000; + sim->part_change_type(i, x, y, PT_WARP); + return 0; + } + if (parts[i].tmp2>100) + { + for ( trade = 0; trade<9; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==t && (parts[i].tmp2>parts[r>>8].tmp2) && parts[r>>8].tmp2>=0 )//diffusion + { + tym = parts[i].tmp2 - parts[r>>8].tmp2; + if (tym ==1) + { + parts[r>>8].tmp2 ++; + parts[i].tmp2 --; + break; + } + if (tym>0) + { + parts[r>>8].tmp2 += tym/2; + parts[i].tmp2 -= tym/2; + break; + } + } + } + } + } + if (parts[i].temp<273.15f) + { + parts[i].vx = 0; + parts[i].vy = 0; + sim->pv[y/CELL][x/CELL] -= 0.01; + parts[i].tmp--; + } + return 0; + +} + +//#TPT-Directive ElementHeader Element_EXOT static int graphics(GRAPHICS_FUNC_ARGS) +int Element_EXOT::graphics(GRAPHICS_FUNC_ARGS) +{ + int q = cpart->temp; + int b = cpart->tmp; + int c = cpart->tmp2; + if (cpart->life < 1001) + { + if ((cpart->tmp2 - 1)>rand()%1000) + { + float frequency = 0.04045; + *colr = (sin(frequency*c + 4) * 127 + 150); + *colg = (sin(frequency*c + 6) * 127 + 150); + *colb = (sin(frequency*c + 8) * 127 + 150); + + *firea = 100; + *firer = 0; + *fireg = 0; + *fireb = 0; + + *pixel_mode |= PMODE_FLAT; + *pixel_mode |= PMODE_FLARE; + } + else + { + float frequency = 0.00045; + *colr = (sin(frequency*q + 4) * 127 + (b/1.7)); + *colg = (sin(frequency*q + 6) * 127 + (b/1.7)); + *colb = (sin(frequency*q + 8) * 127 + (b/1.7)); + *cola = cpart->tmp / 6; + + *firea = *cola; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + + *pixel_mode |= FIRE_ADD; + *pixel_mode |= PMODE_BLUR; + } + } + else + { + float frequency = 0.01300; + *colr = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); + *colg = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); + *colb = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); + *cola = cpart->tmp / 6; + *firea = *cola; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + *pixel_mode |= FIRE_ADD; + *pixel_mode |= PMODE_BLUR; + } + return 0; +} + +Element_EXOT::~Element_EXOT() {} diff --git a/src/simulation/elements/Element.cpp b/src/simulation/elements/Element.cpp new file mode 100644 index 0000000..9c1002a --- /dev/null +++ b/src/simulation/elements/Element.cpp @@ -0,0 +1,225 @@ +#include "simulation/Elements.h" +#include "simulation/StructProperty.h" + +Element::Element(): + Identifier("DEFAULT_INVALID"), + Name(""), + Colour(PIXPACK(0xFF00FF)), + MenuVisible(0), + MenuSection(0), + Enabled(0), + + Advection(0.0f), + AirDrag(-0.0f * CFDS), + AirLoss(1.0f), + Loss(1.0f), + Collision(0.0f), + Gravity(0.0f), + Diffusion(0.0f), + HotAir(0.0f * CFDS), + Falldown(0), + + Flammable(0), + Explosive(0), + Meltable(0), + Hardness(30), + + Weight(50), + + Temperature(273.15f), + HeatConduct(128), + Description("No description"), + + State(ST_SOLID), + Properties(TYPE_SOLID), + + LowPressure(IPL), + LowPressureTransition(NT), + HighPressure(IPH), + HighPressureTransition(NT), + LowTemperature(ITL), + LowTemperatureTransition(NT), + HighTemperature(ITH), + HighTemperatureTransition(NT), + + Update(NULL), + Graphics(&Element::defaultGraphics), + IconGenerator(NULL) +{ +} + +std::vector<StructProperty> Element::GetProperties() +{ + std::vector<StructProperty> properties; + properties.push_back(StructProperty("Name", StructProperty::String, offsetof(Element, Name))); + properties.push_back(StructProperty("Colour", StructProperty::Colour, offsetof(Element, Colour))); + properties.push_back(StructProperty("MenuVisible", StructProperty::Integer, offsetof(Element, MenuVisible))); + properties.push_back(StructProperty("MenuSection", StructProperty::Integer, offsetof(Element, MenuSection))); + properties.push_back(StructProperty("Advection", StructProperty::Float, offsetof(Element, Advection))); + properties.push_back(StructProperty("AirDrag", StructProperty::Float, offsetof(Element, AirDrag))); + properties.push_back(StructProperty("AirLoss", StructProperty::Float, offsetof(Element, AirLoss))); + properties.push_back(StructProperty("Loss", StructProperty::Float, offsetof(Element, Loss))); + properties.push_back(StructProperty("Collision", StructProperty::Float, offsetof(Element, Collision))); + properties.push_back(StructProperty("Gravity", StructProperty::Float, offsetof(Element, Gravity))); + properties.push_back(StructProperty("Diffusion", StructProperty::Float, offsetof(Element, Diffusion))); + properties.push_back(StructProperty("HotAir", StructProperty::Float, offsetof(Element, HotAir))); + properties.push_back(StructProperty("Falldown", StructProperty::Integer, offsetof(Element, Falldown))); + properties.push_back(StructProperty("Flammable", StructProperty::Integer, offsetof(Element, Flammable))); + properties.push_back(StructProperty("Explosive", StructProperty::Integer, offsetof(Element, Explosive))); + properties.push_back(StructProperty("Meltable", StructProperty::Integer, offsetof(Element, Meltable))); + properties.push_back(StructProperty("Hardness", StructProperty::Integer, offsetof(Element, Hardness))); + properties.push_back(StructProperty("Weight", StructProperty::Integer, offsetof(Element, Weight))); + properties.push_back(StructProperty("Temperature", StructProperty::Float, offsetof(Element, Temperature))); + properties.push_back(StructProperty("HeatConduct", StructProperty::UChar, offsetof(Element, HeatConduct))); + properties.push_back(StructProperty("Description", StructProperty::String, offsetof(Element, Description))); + properties.push_back(StructProperty("State", StructProperty::Char, offsetof(Element, State))); + properties.push_back(StructProperty("Properties", StructProperty::Integer, offsetof(Element, Properties))); + properties.push_back(StructProperty("LowPressure", StructProperty::Float, offsetof(Element, LowPressure))); + properties.push_back(StructProperty("LowPressureTransition", StructProperty::Integer, offsetof(Element, LowPressureTransition))); + properties.push_back(StructProperty("HighPressure", StructProperty::Float, offsetof(Element, HighPressure))); + properties.push_back(StructProperty("HighPressureTransition", StructProperty::Integer, offsetof(Element, HighPressureTransition))); + properties.push_back(StructProperty("LowTemperature", StructProperty::Float, offsetof(Element, LowTemperature))); + properties.push_back(StructProperty("LowTemperatureTransition", StructProperty::Integer, offsetof(Element, LowTemperatureTransition))); + properties.push_back(StructProperty("HighTemperature", StructProperty::Float, offsetof(Element, HighTemperature))); + properties.push_back(StructProperty("HighTemperatureTransition", StructProperty::Integer, offsetof(Element, HighTemperatureTransition))); + return properties; +} + +int Element::legacyUpdate(UPDATE_FUNC_ARGS) { + int r, rx, ry, rt; + int t = parts[i].type; + if (t==PT_WTRV) { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && + x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_WATR||(r&0xFF)==PT_DSTW||(r&0xFF)==PT_SLTW) && 1>(rand()%1000)) + { + sim->part_change_type(i,x,y,PT_WATR); + sim->part_change_type(r>>8,x+rx,y+ry,PT_WATR); + } + if (((r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW) && 1>(rand()%1000)) + { + sim->part_change_type(i,x,y,PT_WATR); + if (1>(rand()%1000)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_WATR); + } + } + } + else if (t==PT_WATR) { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && + x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10)) + { + sim->part_change_type(i,x,y,PT_WTRV); + } + } + } + else if (t==PT_SLTW) { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && + x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10)) + { + if (rand()%4==0) sim->part_change_type(i,x,y,PT_SALT); + else sim->part_change_type(i,x,y,PT_WTRV); + } + } + } + else if (t==PT_DSTW) { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && + x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10)) + { + sim->part_change_type(i,x,y,PT_WTRV); + } + } + } + else if (t==PT_ICEI) { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%1000)) + { + sim->part_change_type(i,x,y,PT_ICEI); + sim->part_change_type(r>>8,x+rx,y+ry,PT_ICEI); + } + } + } + else if (t==PT_SNOW) { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%1000)) + { + sim->part_change_type(i,x,y,PT_ICEI); + sim->part_change_type(r>>8,x+rx,y+ry,PT_ICEI); + } + if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 15>(rand()%1000)) + sim->part_change_type(i,x,y,PT_WATR); + } + } + if (t==PT_WTRV && sim->pv[y/CELL][x/CELL]>4.0f) + sim->part_change_type(i,x,y,PT_DSTW); + if (t==PT_OIL && sim->pv[y/CELL][x/CELL]<-6.0f) + sim->part_change_type(i,x,y,PT_GAS); + if (t==PT_GAS && sim->pv[y/CELL][x/CELL]>6.0f) + sim->part_change_type(i,x,y,PT_OIL); + if (t==PT_DESL && sim->pv[y/CELL][x/CELL]>12.0f) + { + sim->part_change_type(i,x,y,PT_FIRE); + parts[i].life = rand()%50+120; + } + return 0; +} + +int Element::defaultGraphics(GRAPHICS_FUNC_ARGS) +{ + int t = cpart->type; + //Property based defaults + if(ren->sim->elements[t].Properties & PROP_RADIOACTIVE) *pixel_mode |= PMODE_GLOW; + if(ren->sim->elements[t].Properties & TYPE_LIQUID) + { + *pixel_mode |= PMODE_BLUR; + } + if(ren->sim->elements[t].Properties & TYPE_GAS) + { + *pixel_mode &= ~PMODE; + *pixel_mode |= FIRE_BLEND; + *firer = *colr/2; + *fireg = *colg/2; + *fireb = *colb/2; + *firea = 125; + *pixel_mode |= DECO_FIRE; + } + return 1; +} diff --git a/src/simulation/elements/Element.h b/src/simulation/elements/Element.h new file mode 100644 index 0000000..b51bddc --- /dev/null +++ b/src/simulation/elements/Element.h @@ -0,0 +1,63 @@ +#ifndef ELEMENTCLASS_H +#define ELEMENTCLASS_H + +#include "simulation/Simulation.h" +#include "graphics/Renderer.h" +#include "simulation/Elements.h" +#include "simulation/StructProperty.h" + +class Simulation; +class Renderer; +struct Particle; +class Element +{ +public: + char *Identifier; + char *Name; + pixel Colour; + float Advection; + float AirDrag; + float AirLoss; + float Loss; + float Collision; + float Gravity; + float Diffusion; + float HotAir; + int Falldown; + int Flammable; + int Explosive; + int Meltable; + int Hardness; + int MenuVisible; + int Enabled; + int Weight; + int MenuSection; + float Temperature; + unsigned char HeatConduct; + char *Description; + char State; + unsigned int Properties; + int (*Update) (UPDATE_FUNC_ARGS); + int (*Graphics) (GRAPHICS_FUNC_ARGS); + VideoBuffer * (*IconGenerator)(int, int, int); + + float HighPressure; + int HighPressureTransition; + float LowPressure; + int LowPressureTransition; + float HighTemperature; + int HighTemperatureTransition; + float LowTemperature; + int LowTemperatureTransition; + + Element(); + virtual ~Element() {} + static int defaultGraphics(GRAPHICS_FUNC_ARGS); + static int legacyUpdate(UPDATE_FUNC_ARGS); + + /** Returns a list of properties, their type and offset within the structure that can be changed + by higher-level processes refering to them by name such as Lua or the property tool **/ + static std::vector<StructProperty> GetProperties(); +}; + +#endif diff --git a/src/simulation/elements/FIGH.cpp b/src/simulation/elements/FIGH.cpp new file mode 100644 index 0000000..66be5bd --- /dev/null +++ b/src/simulation/elements/FIGH.cpp @@ -0,0 +1,140 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FIGH PT_FIGH 158 +Element_FIGH::Element_FIGH() +{ + Identifier = "DEFAULT_PT_FIGH"; + Name = "FIGH"; + Colour = PIXPACK(0xFFE0A0); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.5f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.2f; + Loss = 1.0f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.0f; + HotAir = 0.00f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 50; + + Temperature = R_TEMP+14.6f+273.15f; + HeatConduct = 0; + Description = "Fighter. Tries to kill stickmen."; + + State = ST_NONE; + Properties = 0; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 620.0f; + HighTemperatureTransition = PT_FIRE; + + Update = &Element_FIGH::update; + Graphics = &Element_STKM::graphics; +} + +//#TPT-Directive ElementHeader Element_FIGH static int update(UPDATE_FUNC_ARGS) +int Element_FIGH::update(UPDATE_FUNC_ARGS) + +{ + playerst* figh = &sim->fighters[(unsigned char)parts[i].tmp]; + + unsigned int tarx, tary; + + parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man + + //Set target cords + if (sim->player.spwn && sim->player2.spwn) + { + if ((pow((float)sim->player.legs[2]-x, 2) + pow((float)sim->player.legs[3]-y, 2))<= + (pow((float)sim->player2.legs[2]-x, 2) + pow((float)sim->player2.legs[3]-y, 2))) + { + tarx = (unsigned int)sim->player.legs[2]; + tary = (unsigned int)sim->player.legs[3]; + } + else + { + tarx = (unsigned int)sim->player2.legs[2]; + tary = (unsigned int)sim->player2.legs[3]; + } + parts[i].tmp2 = 1; + } + else + { + if (sim->player.spwn) + { + tarx = (unsigned int)sim->player.legs[2]; + tary = (unsigned int)sim->player.legs[3]; + parts[i].tmp2 = 1; + } + if (sim->player2.spwn) + { + tarx = (unsigned int)sim->player2.legs[2]; + tary = (unsigned int)sim->player2.legs[3]; + parts[i].tmp2 = 1; + } + } + + switch (parts[i].tmp2) + { + case 1: + if ((pow(float(tarx-x), 2) + pow(float(tary-y), 2))<600) + { + if (figh->elem == PT_LIGH || figh->elem == PT_NEUT + || sim->elements[figh->elem].Properties&(PROP_DEADLY|PROP_RADIOACTIVE) + || sim->elements[figh->elem].Temperature>=323 || sim->elements[figh->elem].Temperature<=243) + figh->comm = (int)figh->comm | 0x08; + } + else + if (tarx<x) + { + if(!(sim->eval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+6, NULL) + && sim->eval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+3, NULL))) + figh->comm = 0x01; + else + figh->comm = 0x02; + + if (!sim->eval_move(PT_FIGH, figh->legs[4]-4, figh->legs[5]-1, NULL) + || !sim->eval_move(PT_FIGH, figh->legs[12]-4, figh->legs[13]-1, NULL) + || sim->eval_move(PT_FIGH, 2*figh->legs[4]-figh->legs[6], figh->legs[5]+5, NULL)) + figh->comm = (int)figh->comm | 0x04; + } + else + { + if (!(sim->eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+6, NULL) + && sim->eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+3, NULL))) + figh->comm = 0x02; + else + figh->comm = 0x01; + + if (!sim->eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL) + || !sim->eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL) + || sim->eval_move(PT_FIGH, 2*figh->legs[12]-figh->legs[14], figh->legs[13]+5, NULL)) + figh->comm = (int)figh->comm | 0x04; + } + break; + default: + figh->comm = 0; + break; + } + + figh->pcomm = figh->comm; + + Element_STKM::run_stickman(figh, UPDATE_FUNC_SUBCALL_ARGS); + return 0; +} + +Element_FIGH::~Element_FIGH() {}
\ No newline at end of file diff --git a/src/simulation/elements/FILT.cpp b/src/simulation/elements/FILT.cpp new file mode 100644 index 0000000..58501c2 --- /dev/null +++ b/src/simulation/elements/FILT.cpp @@ -0,0 +1,77 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FILT PT_FILT 125 +Element_FILT::Element_FILT() +{ + Identifier = "DEFAULT_PT_FILT"; + Name = "FILT"; + Colour = PIXPACK(0x000056); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Filter for photons, changes the color."; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NOAMBHEAT; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + Graphics = &Element_FILT::graphics; +} + +//#TPT-Directive ElementHeader Element_FILT static int graphics(GRAPHICS_FUNC_ARGS) +int Element_FILT::graphics(GRAPHICS_FUNC_ARGS) + +{ + int x, temp_bin = (int)((cpart->temp-273.0f)*0.025f); + if (temp_bin < 0) temp_bin = 0; + if (temp_bin > 25) temp_bin = 25; + cpart->ctype = 0x1F << temp_bin; + *colg = 0; + *colb = 0; + *colr = 0; + for (x=0; x<12; x++) { + *colr += (cpart->ctype >> (x+18)) & 1; + *colb += (cpart->ctype >> x) & 1; + } + for (x=0; x<12; x++) + *colg += (cpart->ctype >> (x+9)) & 1; + x = 624/(*colr+*colg+*colb+1); + *cola = 127; + *colr *= x; + *colg *= x; + *colb *= x; + *pixel_mode &= ~PMODE; + *pixel_mode |= PMODE_BLEND; + return 0; +} + + +Element_FILT::~Element_FILT() {} diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp new file mode 100644 index 0000000..f9313fa --- /dev/null +++ b/src/simulation/elements/FIRE.cpp @@ -0,0 +1,201 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FIRE PT_FIRE 4 +Element_FIRE::Element_FIRE() +{ + Identifier = "DEFAULT_PT_FIRE"; + Name = "FIRE"; + Colour = PIXPACK(0xFF1000); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.9f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.97f; + Loss = 0.20f; + Collision = 0.0f; + Gravity = -0.1f; + Diffusion = 0.00f; + HotAir = 0.001f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 2; + + Temperature = R_TEMP+400.0f+273.15f; + HeatConduct = 88; + Description = "Ignites flammable materials. Heats air."; + + State = ST_GAS; + Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 2773.0f; + HighTemperatureTransition = PT_PLSM; + + Update = &Element_FIRE::update; + Graphics = &Element_FIRE::graphics; +} + +//#TPT-Directive ElementHeader Element_FIRE static int update(UPDATE_FUNC_ARGS) +int Element_FIRE::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, rt, t = parts[i].type; + if (t==PT_PLSM&&parts[i].ctype == PT_NBLE&&parts[i].life <=1) + { + t = PT_NBLE; + sim->part_change_type(i,x,y,t); + parts[i].life = 0; + } + if(t==PT_FIRE && parts[i].life <=1) + { + if ((parts[i].tmp&0x3) == 3){ + t = PT_DSTW; + sim->part_change_type(i,x,y,t); + parts[i].life = 0; + parts[i].ctype = PT_FIRE; + } + else if (parts[i].temp<625) + { + t = PT_SMKE; + sim->part_change_type(i,x,y,t); + parts[i].life = rand()%20+250; + } + } + if(t==PT_PLSM && parts[i].life <=1) + { + if ((parts[i].tmp&0x3) == 3){ + t = PT_DSTW; + sim->part_change_type(i,x,y,t); + parts[i].life = 0; + parts[i].ctype = PT_FIRE; + } + } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (sim->bmap[(y+ry)/CELL][(x+rx)/CELL] && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_STREAM) + continue; + rt = parts[r>>8].type; + if ((surround_space || sim->elements[rt].Explosive) && + (t!=PT_SPRK || (rt!=PT_RBDM && rt!=PT_LRBD && rt!=PT_INSL)) && + (t!=PT_PHOT || rt!=PT_INSL) && + (rt!=PT_SPNG || parts[r>>8].life==0) && + sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (int)(sim->pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f))>(rand()%1000)) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_FIRE); + parts[r>>8].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); + parts[r>>8].life = rand()%80+180; + parts[r>>8].tmp = parts[r>>8].ctype = 0; + if (sim->elements[rt].Explosive) + sim->pv[y/CELL][x/CELL] += 0.25f * CFDS; + } + } + if (sim->legacy_enable) updateLegacy(UPDATE_FUNC_SUBCALL_ARGS); + return 0; +} + +//#TPT-Directive ElementHeader Element_FIRE static int updateLegacy(UPDATE_FUNC_ARGS) +int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) { + int r, rx, ry, rt, lpv, t = parts[i].type; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (sim->bmap[(y+ry)/CELL][(x+rx)/CELL] && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_STREAM) + continue; + rt = r&0xFF; + lpv = (int)sim->pv[(y+ry)/CELL][(x+rx)/CELL]; + if (lpv < 1) lpv = 1; + if (t!=PT_SPRK && sim->elements[rt].Meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) && + sim->elements[rt].Meltable*lpv>(rand()%1000)) + { + if (t!=PT_LAVA || parts[i].life>0) + { + parts[r>>8].ctype = (rt==PT_BRMT)?PT_BMTL:parts[r>>8].type; + parts[r>>8].ctype = (parts[r>>8].ctype==PT_SAND)?PT_GLAS:parts[r>>8].ctype; + sim->part_change_type(r>>8,x+rx,y+ry,PT_LAVA); + parts[r>>8].life = rand()%120+240; + } + else + { + parts[i].life = 0; + t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE; + parts[i].ctype = PT_NONE;//rt; + sim->part_change_type(i,x,y,t); + return 1; + } + } + if (t!=PT_SPRK && (rt==PT_ICEI || rt==PT_SNOW)) + { + parts[r>>8].type = PT_WATR; + if (t==PT_FIRE) + { + sim->kill_part(i); + return 1; + } + if (t==PT_LAVA) + { + parts[i].life = 0; + t = parts[i].type = PT_STNE; + sim->part_change_type(i,x,y,t); + } + } + if (t!=PT_SPRK && (rt==PT_WATR || rt==PT_DSTW || rt==PT_SLTW)) + { + sim->kill_part(r>>8); + if (t==PT_FIRE) + { + sim->kill_part(i); + return 1; + } + if (t==PT_LAVA) + { + parts[i].life = 0; + t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE; + parts[i].ctype = PT_NONE; + sim->part_change_type(i,x,y,t); + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_FIRE static int graphics(GRAPHICS_FUNC_ARGS) +int Element_FIRE::graphics(GRAPHICS_FUNC_ARGS) + +{ + int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + *colr = (unsigned char)ren->flm_data[caddress]; + *colg = (unsigned char)ren->flm_data[caddress+1]; + *colb = (unsigned char)ren->flm_data[caddress+2]; + + *firea = 255; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + + *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel + *pixel_mode |= FIRE_ADD; + //Returning 0 means dynamic, do not cache + return 0; +} + +Element_FIRE::~Element_FIRE() {}
\ No newline at end of file diff --git a/src/simulation/elements/FIRW.cpp b/src/simulation/elements/FIRW.cpp new file mode 100644 index 0000000..bc047df --- /dev/null +++ b/src/simulation/elements/FIRW.cpp @@ -0,0 +1,134 @@ +#include "simulation/Elements.h" +extern "C" +{ + #include "hmap.h" +} +//#TPT-Directive ElementClass Element_FIRW PT_FIRW 69 +Element_FIRW::Element_FIRW() +{ + Identifier = "DEFAULT_PT_FIRW"; + Name = "FIRW"; + Colour = PIXPACK(0xFFA040); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.2f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.96f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 55; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Fireworks!"; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_FIRW::update; + Graphics = &Element_FIRW::graphics; +} + +//#TPT-Directive ElementHeader Element_FIRW static int update(UPDATE_FUNC_ARGS) +int Element_FIRW::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, rt, np; + if (parts[i].tmp<=0) { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + rt = parts[r>>8].type; + if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR) + { + float gx, gy, multiplier; + sim->GetGravityField(x, y, sim->elements[PT_FIRW].Gravity, 1.0f, gx, gy); + if (gx*gx+gy*gy < 0.001f) + { + float angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi) + gx += sinf(angle)*sim->elements[PT_FIRW].Gravity*0.5f; + gy += cosf(angle)*sim->elements[PT_FIRW].Gravity*0.5f; + } + parts[i].tmp = 1; + parts[i].life = rand()%10+20; + multiplier = (parts[i].life+20)*0.2f/sqrtf(gx*gx+gy*gy); + parts[i].vx -= gx*multiplier; + parts[i].vy -= gy*multiplier; + return 0; + } + } + } + else if (parts[i].tmp==1) { + if (parts[i].life<=0) { + parts[i].tmp=2; + } else { + parts[i].flags &= ~FLAG_STAGNANT; + } + } + else if (parts[i].tmp>=2) + { + float angle, magnitude; + int caddress = (rand()%200)*3; + int n; + unsigned col = (((unsigned char)(firw_data[caddress]))<<16) | (((unsigned char)(firw_data[caddress+1]))<<8) | ((unsigned char)(firw_data[caddress+2])); + for (n=0; n<40; n++) + { + np = sim->create_part(-3, x, y, PT_EMBR); + if (np>-1) + { + magnitude = ((rand()%60)+40)*0.05f; + angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi) + parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude; + parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; + parts[np].ctype = col; + parts[np].tmp = 1; + parts[np].life = rand()%40+70; + parts[np].temp = (rand()%500)+5750.0f; + parts[np].dcolour = parts[i].dcolour; + } + } + sim->pv[y/CELL][x/CELL] += 8.0f; + sim->kill_part(i); + return 1; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_FIRW static int graphics(GRAPHICS_FUNC_ARGS) +int Element_FIRW::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(cpart->tmp > 0) + { + *pixel_mode |= PMODE_GLOW; + } + return 0; +} + + +Element_FIRW::~Element_FIRW() {}
\ No newline at end of file diff --git a/src/simulation/elements/FOG.cpp b/src/simulation/elements/FOG.cpp new file mode 100644 index 0000000..9cfbe62 --- /dev/null +++ b/src/simulation/elements/FOG.cpp @@ -0,0 +1,73 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FOG PT_FOG 92 +Element_FOG::Element_FOG() +{ + Identifier = "DEFAULT_PT_FOG"; + Name = "FOG"; + Colour = PIXPACK(0xAAAAAA); + MenuVisible = 1; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.8f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.4f; + Loss = 0.70f; + Collision = -0.1f; + Gravity = 0.0f; + Diffusion = 0.99f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 1; + + Temperature = 243.15f; + HeatConduct = 100; + Description = "Not quite Steam"; + + State = ST_GAS; + Properties = TYPE_GAS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 373.15f; + HighTemperatureTransition = PT_WTRV; + + Update = &Element_FOG::update; + +} + +//#TPT-Directive ElementHeader Element_FOG static int update(UPDATE_FUNC_ARGS) +int Element_FOG::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (sim->elements[r&0xFF].State==ST_SOLID&&5>=rand()%50&&parts[i].life==0&&!((r&0xFF)==PT_CLNE||(r&0xFF)==PT_PCLN)) // TODO: should this also exclude BCLN? + { + sim->part_change_type(i,x,y,PT_RIME); + } + if ((r&0xFF)==PT_SPRK) + { + parts[i].life += rand()%20; + } + } + return 0; +} + + +Element_FOG::~Element_FOG() {}
\ No newline at end of file diff --git a/src/simulation/elements/FRAY.cpp b/src/simulation/elements/FRAY.cpp new file mode 100644 index 0000000..57e2b22 --- /dev/null +++ b/src/simulation/elements/FRAY.cpp @@ -0,0 +1,80 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FRAY PT_FRAY 159 +Element_FRAY::Element_FRAY() +{ + Identifier = "DEFAULT_PT_FRAY"; + Name = "FRAY"; + Colour = PIXPACK(0x00BBFF); + MenuVisible = 1; + MenuSection = SC_FORCE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = 20.0f+0.0f +273.15f; + HeatConduct = 0; + Description = "Force Emitter. Push or pull objects based on temp value, use like ARAY"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_FRAY::update; + +} + +//#TPT-Directive ElementHeader Element_FRAY static int update(UPDATE_FUNC_ARGS) +int Element_FRAY::update(UPDATE_FUNC_ARGS) + { + int r, nxx, nyy, docontinue, len, nxi, nyi, rx, ry, nr, ry1, rx1; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SPRK) { + for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1, len = 0; docontinue; nyy+=nyi, nxx+=nxi, len++) { + if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0) || len>10) { + break; + } + r = pmap[y+nyi+nyy][x+nxi+nxx]; + if (!r) + r = sim->photons[y+nyi+nyy][x+nxi+nxx]; + + if (r && !(sim->elements[r&0xFF].Properties & TYPE_SOLID)){ + parts[r>>8].vx += nxi*((parts[i].temp-273.15)/10.0f); + parts[r>>8].vy += nyi*((parts[i].temp-273.15)/10.0f); + } + } + } + } + return 0; +} + + +Element_FRAY::~Element_FRAY() {}
\ No newline at end of file diff --git a/src/simulation/elements/FRZW.cpp b/src/simulation/elements/FRZW.cpp new file mode 100644 index 0000000..5bdbb21 --- /dev/null +++ b/src/simulation/elements/FRZW.cpp @@ -0,0 +1,81 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FRZW PT_FRZW 101 +Element_FRZW::Element_FRZW() +{ + Identifier = "DEFAULT_PT_FRZW"; + Name = "FRZW"; + Colour = PIXPACK(0x1020C0); + MenuVisible = 1; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = 120.0f; + HeatConduct = 29; + Description = "Freeze water. Hybrid liquid formed when Freeze powder melts."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID||PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 53.0f; + HighTemperatureTransition = PT_ICEI; + + Update = &Element_FRZW::update; + +} + +//#TPT-Directive ElementHeader Element_FRZW static int update(UPDATE_FUNC_ARGS) +int Element_FRZW::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_WATR&&5>rand()%70) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_FRZW); + } + } + if (parts[i].life==0&&13>rand()%2500) + { + sim->part_change_type(i,x,y,PT_ICEI); + parts[i].ctype=PT_FRZW; + parts[i].temp = restrict_flt(parts[i].temp-200.0f, MIN_TEMP, MAX_TEMP); + } + else if ((100-(parts[i].life))>rand()%50000) + { + sim->part_change_type(i,x,y,PT_ICEI); + parts[i].ctype=PT_FRZW; + parts[i].temp = restrict_flt(parts[i].temp-200.0f, MIN_TEMP, MAX_TEMP); + } + return 0; +} + + +Element_FRZW::~Element_FRZW() {}
\ No newline at end of file diff --git a/src/simulation/elements/FRZZ.cpp b/src/simulation/elements/FRZZ.cpp new file mode 100644 index 0000000..47a5c0f --- /dev/null +++ b/src/simulation/elements/FRZZ.cpp @@ -0,0 +1,76 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FRZZ PT_FRZZ 100 +Element_FRZZ::Element_FRZZ() +{ + Identifier = "DEFAULT_PT_FRZZ"; + Name = "FRZZ"; + Colour = PIXPACK(0xC0E0FF); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.96f; + Loss = 0.90f; + Collision = -0.1f; + Gravity = 0.05f; + Diffusion = 0.01f; + HotAir = -0.00005f* CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 50; + + Temperature = 253.15f; + HeatConduct = 46; + 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 = 1.8f; + HighPressureTransition = PT_SNOW; + LowTemperature = 50.0f; + LowTemperatureTransition = PT_ICEI; + HighTemperature = 273.15; + HighTemperatureTransition = PT_WATR; + + Update = &Element_FRZZ::update; + +} + +//#TPT-Directive ElementHeader Element_FRZZ static int update(UPDATE_FUNC_ARGS) +int Element_FRZZ::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_WATR&&5>rand()%100) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_FRZW); + parts[r>>8].life = 100; + parts[i].type = PT_NONE; + } + + } + if (parts[i].type==PT_NONE) { + sim->kill_part(i); + return 1; + } + return 0; +} + + +Element_FRZZ::~Element_FRZZ() {}
\ No newline at end of file diff --git a/src/simulation/elements/FSEP.cpp b/src/simulation/elements/FSEP.cpp new file mode 100644 index 0000000..52e4a67 --- /dev/null +++ b/src/simulation/elements/FSEP.cpp @@ -0,0 +1,86 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FSEP PT_FSEP 71 +Element_FSEP::Element_FSEP() +{ + Identifier = "DEFAULT_PT_FSEP"; + Name = "FSEP"; + Colour = PIXPACK(0x63AD5F); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.96f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 70; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Fuse Powder. See FUSE."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_FSEP::update; + +} + +//#TPT-Directive ElementHeader Element_FSEP static int update(UPDATE_FUNC_ARGS) +int Element_FSEP::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].life<=0) { + r = sim->create_part(i, x, y, PT_PLSM); + if (r!=-1) + parts[r].life = 50; + return 1; + } else if (parts[i].life < 40) { + parts[i].life--; + if ((rand()%10)==0) { + r = sim->create_part(-1, (rx=x+rand()%3-1), (ry=y+rand()%3-1), PT_PLSM); + if (r!=-1) + parts[r].life = 50; + } + } + else { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && 1>(rand()%15)) + { + if (parts[i].life>40) { + parts[i].life = 39; + } + } + } + } + return 0; +} + + +Element_FSEP::~Element_FSEP() {}
\ No newline at end of file diff --git a/src/simulation/elements/FUSE.cpp b/src/simulation/elements/FUSE.cpp new file mode 100644 index 0000000..946e86b --- /dev/null +++ b/src/simulation/elements/FUSE.cpp @@ -0,0 +1,92 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FUSE PT_FUSE 70 +Element_FUSE::Element_FUSE() +{ + Identifier = "DEFAULT_PT_FUSE"; + Name = "FUSE"; + Colour = PIXPACK(0x0A5706); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.0f; + HotAir = 0.0f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 200; + Description = "Solid. Burns slowly. Ignites at somewhat high temperatures and electricity."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_FUSE::update; + +} + +//#TPT-Directive ElementHeader Element_FUSE static int update(UPDATE_FUNC_ARGS) +int Element_FUSE::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].life<=0) { + r = sim->create_part(i, x, y, PT_PLSM); + if (r!=-1) + parts[r].life = 50; + return 1; + } else if (parts[i].life < 40) { + parts[i].life--; + if ((rand()%100)==0) { + r = sim->create_part(-1, (rx=x+rand()%3-1), (ry=y+rand()%3-1), PT_PLSM); + if (r!=-1) + parts[r].life = 50; + } + } + if ((sim->pv[y/CELL][x/CELL] > 2.7f)&&parts[i].tmp>40) + parts[i].tmp=39; + else if (parts[i].tmp<40&&parts[i].tmp>0) + parts[i].tmp--; + else if (parts[i].tmp<=0) { + sim->create_part(i, x, y, PT_FSEP); + return 1; + } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SPRK || ((parts[i].temp>=(273.15+700.0f)) && 1>(rand()%20))) + { + if (parts[i].life>40) { + parts[i].life = 39; + } + } + } + return 0; +} + + +Element_FUSE::~Element_FUSE() {}
\ No newline at end of file diff --git a/src/simulation/elements/FWRK.cpp b/src/simulation/elements/FWRK.cpp new file mode 100644 index 0000000..f05db69 --- /dev/null +++ b/src/simulation/elements/FWRK.cpp @@ -0,0 +1,120 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_FWRK PT_FWRK 98 +Element_FWRK::Element_FWRK() +{ + Identifier = "DEFAULT_PT_FWRK"; + Name = "FWRK"; + Colour = PIXPACK(0x666666); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.99f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.4f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 97; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 100; + Description = "First fireworks made, activated by heat/neutrons."; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_FWRK::update; + +} + +//#TPT-Directive ElementHeader Element_FWRK static int update(UPDATE_FUNC_ARGS) +int Element_FWRK::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, np; + if (parts[i].life==0 && ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&surround_space)||parts[i].ctype==PT_DUST)) + { + float gx, gy, multiplier, gmax; + int randTmp; + sim->GetGravityField(x, y, sim->elements[PT_FWRK].Gravity, 1.0f, gx, gy); + if (gx*gx+gy*gy < 0.001f) + { + float angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi) + gx += sinf(angle)*sim->elements[PT_FWRK].Gravity*0.5f; + gy += cosf(angle)*sim->elements[PT_FWRK].Gravity*0.5f; + } + gmax = std::max(fabsf(gx), fabsf(gy)); + if (sim->eval_move(PT_FWRK, (int)(x-(gx/gmax)+0.5f), (int)(y-(gy/gmax)+0.5f), NULL)) + { + multiplier = 15.0f/sqrtf(gx*gx+gy*gy); + + //Some variation in speed parallel to gravity direction + randTmp = (rand()%200)-100; + gx += gx*randTmp*0.002f; + gy += gy*randTmp*0.002f; + //and a bit more variation in speed perpendicular to gravity direction + randTmp = (rand()%200)-100; + gx += -gy*randTmp*0.005f; + gy += gx*randTmp*0.005f; + + parts[i].life=rand()%10+18; + parts[i].ctype=0; + parts[i].vx -= gx*multiplier; + parts[i].vy -= gy*multiplier; + parts[i].dcolour = parts[i].dcolour; + return 0; + } + } + if (parts[i].life>=45) + parts[i].life=0; + if (parts[i].life<3&&parts[i].life>0) + { + int r = (rand()%245+11); + int g = (rand()%245+11); + int b = (rand()%245+11); + int n; + float angle, magnitude; + unsigned col = (r<<16) | (g<<8) | b; + for (n=0; n<40; n++) + { + np = sim->create_part(-3, x, y, PT_EMBR); + if (np>-1) + { + magnitude = ((rand()%60)+40)*0.05f; + angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi) + parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude; + parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; + parts[np].ctype = col; + parts[np].tmp = 1; + parts[np].life = rand()%40+70; + parts[np].temp = (rand()%500)+5750.0f; + parts[np].dcolour = parts[i].dcolour; + } + } + sim->pv[y/CELL][x/CELL] += 8.0f; + sim->kill_part(i); + return 1; + } + return 0; +} + + +Element_FWRK::~Element_FWRK() {}
\ No newline at end of file diff --git a/src/simulation/elements/GAS.cpp b/src/simulation/elements/GAS.cpp new file mode 100644 index 0000000..4e87b76 --- /dev/null +++ b/src/simulation/elements/GAS.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GAS PT_GAS 10 +Element_GAS::Element_GAS() +{ + Identifier = "DEFAULT_PT_GAS"; + Name = "GAS"; + Colour = PIXPACK(0xE0FF20); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 1.0f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.1f; + Gravity = 0.0f; + Diffusion = 0.75f; + HotAir = 0.001f * CFDS; + Falldown = 0; + + Flammable = 600; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 1; + + Temperature = R_TEMP+2.0f +273.15f; + HeatConduct = 42; + Description = "Gas. Diffuses. Flammable. Liquefies under pressure."; + + State = ST_GAS; + Properties = TYPE_GAS; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 6.0f; + HighPressureTransition = PT_OIL; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 573.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + +} + +Element_GAS::~Element_GAS() {}
\ No newline at end of file diff --git a/src/simulation/elements/GBMB.cpp b/src/simulation/elements/GBMB.cpp new file mode 100644 index 0000000..827f062 --- /dev/null +++ b/src/simulation/elements/GBMB.cpp @@ -0,0 +1,93 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GBMB PT_GBMB 157 +Element_GBMB::Element_GBMB() +{ + Identifier = "DEFAULT_PT_GBMB"; + Name = "GBMB"; + Colour = PIXPACK(0x1144BB); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Sticks to first object it touches then produces strong gravity push."; + + State = ST_NONE; + Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_GBMB::update; + Graphics = &Element_GBMB::graphics; +} + +//#TPT-Directive ElementHeader Element_GBMB static int update(UPDATE_FUNC_ARGS) +int Element_GBMB::update(UPDATE_FUNC_ARGS) + { + int rx,ry,r; + if (parts[i].life<=0) + { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + { + r = pmap[y+ry][x+rx]; + if(!r) + continue; + if((r&0xFF)!=PT_BOMB && (r&0xFF)!=PT_GBMB && + (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && + (r&0xFF)!=PT_DMND) + { + parts[i].life=60; + break; + } + } + } + if(parts[i].life>20) + sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 20; + if(parts[i].life<20 && parts[i].life>=1) + sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = -80; + return 0; +} + + +//#TPT-Directive ElementHeader Element_GBMB static int graphics(GRAPHICS_FUNC_ARGS) +int Element_GBMB::graphics(GRAPHICS_FUNC_ARGS) + +{ + if (cpart->life <= 0) { + *pixel_mode |= PMODE_FLARE; + } + else + { + *pixel_mode |= PMODE_SPARK; + } + return 0; +} + + +Element_GBMB::~Element_GBMB() {}
\ No newline at end of file diff --git a/src/simulation/elements/GEL.cpp b/src/simulation/elements/GEL.cpp new file mode 100644 index 0000000..5a139db --- /dev/null +++ b/src/simulation/elements/GEL.cpp @@ -0,0 +1,155 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GEL PT_GEL 142 +Element_GEL::Element_GEL() +{ + Identifier = "DEFAULT_PT_GEL"; + Name = "GEL"; + Colour = PIXPACK(0xFF9900); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 35; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Gel. A liquid with variable viscosity and heat conductivity"; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_LIFE_DEC|PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_GEL::update; + Graphics = &Element_GEL::graphics; +} + +//#TPT-Directive ElementHeader Element_GEL static int update(UPDATE_FUNC_ARGS) +int Element_GEL::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + int absorbChanceDenom; + if (parts[i].tmp>100) parts[i].tmp = 100; + if (parts[i].tmp<0) parts[i].tmp = 0; + absorbChanceDenom = parts[i].tmp*10 + 500; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + + //Desaturation + if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_FRZW) && parts[i].tmp<100 && 500>rand()%absorbChanceDenom) + { + parts[i].tmp++; + sim->kill_part(r>>8); + } + if (((r&0xFF)==PT_PSTE) && parts[i].tmp<100 && 20>rand()%absorbChanceDenom) + { + parts[i].tmp++; + sim->create_part(r>>8, x+rx, y+ry, PT_CLST); + } + if (((r&0xFF)==PT_SLTW) && parts[i].tmp<100 && 50>rand()%absorbChanceDenom) + { + parts[i].tmp++; + if (rand()%4) + sim->kill_part(r>>8); + else + sim->part_change_type(r>>8, x+rx, y+ry, PT_SALT); + } + if (((r&0xFF)==PT_CBNW) && parts[i].tmp<100 && 100>rand()%absorbChanceDenom) + { + parts[i].tmp++; + sim->part_change_type(r>>8, x+rx, y+ry, PT_CO2); + } + + if ((r&0xFF)==PT_SPNG && parts[i].tmp<100 && ((parts[r>>8].life+1)>parts[i].tmp)) + { + parts[r>>8].life--; + parts[i].tmp++; + } + + char gel = 0; + if ((r&0xFF)==PT_GEL) + gel = 1; + + //Concentration diffusion + if (gel && (parts[r>>8].tmp+1)<parts[i].tmp) + { + parts[r>>8].tmp++; + parts[i].tmp--; + } + + if ((r&0xFF)==PT_SPNG && (parts[r>>8].life+1)<parts[i].tmp) + { + parts[r>>8].life++; + parts[i].tmp--; + } + + float dx, dy; + dx = parts[i].x - parts[r>>8].x; + dy = parts[i].y - parts[r>>8].y; + + //Stickness + if ((dx*dx + dy*dy)>1.5 && (gel || !sim->elements[r&0xFF].Falldown || (fabs((float)rx)<2 && fabs((float)ry)<2))) + { + float per, nd; + nd = dx*dx + dy*dy - 0.5; + + per = 5*(1 - parts[i].tmp/100)*(nd/(dx*dx + dy*dy + nd) - 0.5); + if (sim->elements[r&0xFF].State==ST_LIQUID) + per *= 0.1; + + dx *= per; dy *= per; + parts[i].vx += dx; + parts[i].vy += dy; + if ((sim->elements[r&0xFF].Properties&TYPE_PART) || (r&0xFF)==PT_GOO) + { + parts[r>>8].vx -= dx; + parts[r>>8].vy -= dy; + } + } + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_GEL static int graphics(GRAPHICS_FUNC_ARGS) +int Element_GEL::graphics(GRAPHICS_FUNC_ARGS) + +{ + int q = cpart->tmp; + *colr = q*(32-255)/120+255; + *colg = q*(48-186)/120+186; + *colb = q*208/120; + return 0; +} + + + +Element_GEL::~Element_GEL() {} diff --git a/src/simulation/elements/GLAS.cpp b/src/simulation/elements/GLAS.cpp new file mode 100644 index 0000000..b752a0b --- /dev/null +++ b/src/simulation/elements/GLAS.cpp @@ -0,0 +1,62 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GLAS PT_GLAS 45 +Element_GLAS::Element_GLAS() +{ + Identifier = "DEFAULT_PT_GLAS"; + Name = "GLAS"; + Colour = PIXPACK(0x404040); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = R_TEMP+0.0f +273.15f; + HeatConduct = 150; + Description = "Solid. Meltable. Shatters under pressure"; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NEUTPASS | PROP_HOT_GLOW | PROP_SPARKSETTLE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1973.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_GLAS::update; + +} + +//#TPT-Directive ElementHeader Element_GLAS static int update(UPDATE_FUNC_ARGS) +int Element_GLAS::update(UPDATE_FUNC_ARGS) + { + parts[i].pavg[0] = parts[i].pavg[1]; + parts[i].pavg[1] = sim->pv[y/CELL][x/CELL]; + if (parts[i].pavg[1]-parts[i].pavg[0] > 0.25f || parts[i].pavg[1]-parts[i].pavg[0] < -0.25f) + { + sim->part_change_type(i,x,y,PT_BGLA); + } + return 0; +} + + +Element_GLAS::~Element_GLAS() {}
\ No newline at end of file diff --git a/src/simulation/elements/GLOW.cpp b/src/simulation/elements/GLOW.cpp new file mode 100644 index 0000000..775e188 --- /dev/null +++ b/src/simulation/elements/GLOW.cpp @@ -0,0 +1,96 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GLOW PT_GLOW 66 +Element_GLOW::Element_GLOW() +{ + Identifier = "DEFAULT_PT_GLOW"; + Name = "GLOW"; + Colour = PIXPACK(0x445464); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.3f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.98f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.15f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 2; + + Weight = 40; + + Temperature = R_TEMP+20.0f+273.15f; + HeatConduct = 44; + Description = "Glow, Glows under pressure"; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_GLOW::update; + Graphics = &Element_GLOW::graphics; +} + +//#TPT-Directive ElementHeader Element_GLOW static int update(UPDATE_FUNC_ARGS) +int Element_GLOW::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_WATR&&5>(rand()%2000)) + { + parts[i].type = PT_NONE; + sim->part_change_type(r>>8,x+rx,y+ry,PT_DEUT); + parts[r>>8].life = 10; + } + } + parts[i].ctype = sim->pv[y/CELL][x/CELL]*16; + + parts[i].tmp = abs((int)((sim->vx[y/CELL][x/CELL]+sim->vy[y/CELL][x/CELL])*16.0f)) + abs((int)((parts[i].vx+parts[i].vy)*64.0f)); + //printf("%f %f\n", parts[i].vx, parts[i].vy); + if (parts[i].type==PT_NONE) { + sim->kill_part(i); + return 1; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_GLOW static int graphics(GRAPHICS_FUNC_ARGS) +int Element_GLOW::graphics(GRAPHICS_FUNC_ARGS) + +{ + *firer = restrict_flt(cpart->temp-(275.13f+32.0f), 0, 128)/50.0f; + *fireg = restrict_flt(cpart->ctype, 0, 128)/50.0f; + *fireb = restrict_flt(cpart->tmp, 0, 128)/50.0f; + + *colr = restrict_flt(64.0f+cpart->temp-(275.13f+32.0f), 0, 255); + *colg = restrict_flt(64.0f+cpart->ctype, 0, 255); + *colb = restrict_flt(64.0f+cpart->tmp, 0, 255); + + *pixel_mode |= FIRE_ADD; + return 0; +} + + +Element_GLOW::~Element_GLOW() {}
\ No newline at end of file diff --git a/src/simulation/elements/GOO.cpp b/src/simulation/elements/GOO.cpp new file mode 100644 index 0000000..3dcef31 --- /dev/null +++ b/src/simulation/elements/GOO.cpp @@ -0,0 +1,64 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GOO PT_GOO 12 +Element_GOO::Element_GOO() +{ + Identifier = "DEFAULT_PT_GOO"; + Name = "GOO"; + Colour = PIXPACK(0x804000); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.97f; + Loss = 0.50f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 12; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 75; + Description = "Solid. Deforms and disappears under pressure."; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NEUTPENETRATE|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_GOO::update; + +} + +//#TPT-Directive ElementHeader Element_GOO static int update(UPDATE_FUNC_ARGS) +int Element_GOO::update(UPDATE_FUNC_ARGS) + { + if (!parts[i].life && sim->pv[y/CELL][x/CELL]>1.0f) + parts[i].life = rand()%80+300; + if (parts[i].life) + { + float advection = 0.1f; + parts[i].vx += advection*sim->vx[y/CELL][x/CELL]; + parts[i].vy += advection*sim->vy[y/CELL][x/CELL]; + } + return 0; +} + + +Element_GOO::~Element_GOO() {}
\ No newline at end of file diff --git a/src/simulation/elements/GPMP.cpp b/src/simulation/elements/GPMP.cpp new file mode 100644 index 0000000..3cf51a3 --- /dev/null +++ b/src/simulation/elements/GPMP.cpp @@ -0,0 +1,94 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GPMP PT_GPMP 154 +Element_GPMP::Element_GPMP() +{ + Identifier = "DEFAULT_PT_GPMP"; + Name = "GPMP"; + Colour = PIXPACK(0x0A3B3B); + MenuVisible = 1; + MenuSection = SC_POWERED; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = 0.0f +273.15f; + HeatConduct = 0; + Description = "Changes gravity to its temp when activated. (use HEAT/COOL)."; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_GPMP::update; + Graphics = &Element_GPMP::graphics; +} + +//#TPT-Directive ElementHeader Element_GPMP static int update(UPDATE_FUNC_ARGS) +int Element_GPMP::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].life>0 && parts[i].life!=10) + parts[i].life--; + if (parts[i].life==10) + { + if (parts[i].temp>=256.0+273.15) + parts[i].temp=256.0+273.15; + if (parts[i].temp<= -256.0+273.15) + parts[i].temp = -256.0+273.15; + + sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 0.2f*(parts[i].temp-273.15); + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_GPMP) + { + if (parts[r>>8].life<10&&parts[r>>8].life>0) + parts[i].life = 9; + else if (parts[r>>8].life==0) + parts[r>>8].life = 10; + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_GPMP static int graphics(GRAPHICS_FUNC_ARGS) +int Element_GPMP::graphics(GRAPHICS_FUNC_ARGS) + +{ + int lifemod = ((cpart->life>10?10:cpart->life)*19); + *colg += lifemod; + *colb += lifemod; + return 0; +} + + +Element_GPMP::~Element_GPMP() {} diff --git a/src/simulation/elements/GRAV.cpp b/src/simulation/elements/GRAV.cpp new file mode 100644 index 0000000..b913a28 --- /dev/null +++ b/src/simulation/elements/GRAV.cpp @@ -0,0 +1,111 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GRAV PT_GRAV 102 +Element_GRAV::Element_GRAV() +{ + Identifier = "DEFAULT_PT_GRAV"; + Name = "GRAV"; + Colour = PIXPACK(0xFFE0A0); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + Loss = 1.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 10; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 85; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Very light dust. Changes colour based on velocity."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_GRAV::update; + Graphics = &Element_GRAV::graphics; +} + +//#TPT-Directive ElementHeader Element_GRAV static int update(UPDATE_FUNC_ARGS) +int Element_GRAV::update(UPDATE_FUNC_ARGS) + { + /*int t = parts[i].type; + if (t==PT_LOVE) + ISLOVE=1; + else if (t==PT_LOLZ) + ISLOLZ=1; + else if (t==PT_GRAV) + ISGRAV=1;*/ + return 0; +} + +int lastIndex; + +//#TPT-Directive ElementHeader Element_GRAV static int graphics(GRAPHICS_FUNC_ARGS) +int Element_GRAV::graphics(GRAPHICS_FUNC_ARGS) + +{ + int GRAV_R, GRAV_B, GRAV_G, GRAV_R2, GRAV_B2, GRAV_G2; + + GRAV_R = std::abs((ren->sim->currentTick%120)-60); + GRAV_G = std::abs(((ren->sim->currentTick+60)%120)-60); + GRAV_B = std::abs(((ren->sim->currentTick+120)%120)-60); + GRAV_R2 = std::abs((ren->sim->currentTick%60)-30); + GRAV_G2 = std::abs(((ren->sim->currentTick+30)%60)-30); + GRAV_B2 = std::abs(((ren->sim->currentTick+60)%60)-30); + + + *colr = 20; + *colg = 20; + *colb = 20; + if (cpart->vx>0) + { + *colr += (cpart->vx)*GRAV_R; + *colg += (cpart->vx)*GRAV_G; + *colb += (cpart->vx)*GRAV_B; + } + if (cpart->vy>0) + { + *colr += (cpart->vy)*GRAV_G; + *colg += (cpart->vy)*GRAV_B; + *colb += (cpart->vy)*GRAV_R; + + } + if (cpart->vx<0) + { + *colr -= (cpart->vx)*GRAV_B; + *colg -= (cpart->vx)*GRAV_R; + *colb -= (cpart->vx)*GRAV_G; + + } + if (cpart->vy<0) + { + *colr -= (cpart->vy)*GRAV_R2; + *colg -= (cpart->vy)*GRAV_G2; + *colb -= (cpart->vy)*GRAV_B2; + } + return 0; +} + + +Element_GRAV::~Element_GRAV() {}
\ No newline at end of file diff --git a/src/simulation/elements/GUNP.cpp b/src/simulation/elements/GUNP.cpp new file mode 100644 index 0000000..798e0f7 --- /dev/null +++ b/src/simulation/elements/GUNP.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_GUNP PT_GUNP 7 +Element_GUNP::Element_GUNP() +{ + Identifier = "DEFAULT_PT_GUNP"; + Name = "GUN"; + Colour = PIXPACK(0xC0C0D0); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.94f; + Loss = 0.80f; + Collision = -0.1f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 600; + Explosive = 1; + Meltable = 0; + Hardness = 10; + + Weight = 85; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 97; + Description = "Light dust. Explosive."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 673.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + +} + +Element_GUNP::~Element_GUNP() {}
\ No newline at end of file diff --git a/src/simulation/elements/H2.cpp b/src/simulation/elements/H2.cpp new file mode 100644 index 0000000..2b6c31b --- /dev/null +++ b/src/simulation/elements/H2.cpp @@ -0,0 +1,124 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_H2 PT_H2 148 +Element_H2::Element_H2() +{ + Identifier = "DEFAULT_PT_H2"; + Name = "HYGN"; + Colour = PIXPACK(0x5070FF); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 2.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.10f; + Gravity = 0.00f; + Diffusion = 3.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 1; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Combines with O2 to make WATR"; + + State = ST_GAS; + Properties = TYPE_GAS; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_H2::update; + +} + +//#TPT-Directive ElementHeader Element_H2 static int update(UPDATE_FUNC_ARGS) +int Element_H2::update(UPDATE_FUNC_ARGS) +{ + int r,rx,ry,rt; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + rt = (r&0xFF); + if (!r) + continue; + if (sim->pv[y/CELL][x/CELL] > 8.0f && rt == PT_DESL) // This will not work. DESL turns to fire above 5.0 pressure + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_WATR); + sim->part_change_type(i,x,y,PT_OIL); + } + if (parts[r>>8].temp > 2273.15 && sim->pv[y/CELL][x/CELL] > 45.0f) + continue; + if (sim->pv[y/CELL][x/CELL] <= 45.0f) + { + if (rt==PT_FIRE) + { + parts[r>>8].temp=2473.15; + if(parts[r>>8].tmp&0x02) + parts[r>>8].temp=3473; + parts[r>>8].tmp |= 1; + } + if (rt==PT_FIRE || (rt==PT_PLSM && !(parts[r>>8].tmp&4)) || (rt==PT_LAVA && parts[r>>8].ctype != PT_BMTL)) + { + sim->create_part(i,x,y,PT_FIRE); + parts[i].temp+=(rand()/(RAND_MAX/100)); + parts[i].tmp |= 1; + } + } + } + if (parts[i].temp > 2273.15 && sim->pv[y/CELL][x/CELL] > 50.0f) + { + if (rand()%5 < 1) + { + int j; + float temp = parts[i].temp; + sim->create_part(i,x,y,PT_NBLE); + + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); + if (j != -1) + parts[j].temp = temp; + if (!(rand()%10)) + { + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); + if (j != -1) + parts[j].temp = temp; + } + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); + if (j != -1) + { + parts[j].ctype = 0x7C0000; + parts[j].temp = temp; + } + + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PLSM); + if (j != -1) + { + parts[j].temp = temp; + parts[j].tmp |= 4; + } + + parts[i].temp = temp+750+rand()%500; + sim->pv[y/CELL][x/CELL] += 30; + } + } + return 0; +} + + +Element_H2::~Element_H2() {} diff --git a/src/simulation/elements/HFLM.cpp b/src/simulation/elements/HFLM.cpp new file mode 100644 index 0000000..e4fb3b4 --- /dev/null +++ b/src/simulation/elements/HFLM.cpp @@ -0,0 +1,75 @@ +#include "simulation/Elements.h" +extern "C" +{ + #include "hmap.h" +} + +//#TPT-Directive ElementClass Element_HFLM PT_HFLM 68 +Element_HFLM::Element_HFLM() +{ + Identifier = "DEFAULT_PT_HFLM"; + Name = "CFLM"; + Colour = PIXPACK(0x8080FF); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.9f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.97f; + Loss = 0.20f; + Collision = 0.0f; + Gravity = -0.1f; + Diffusion = 0.00f; + HotAir = 0.0005f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 2; + + Temperature = 0.0f; + HeatConduct = 88; + Description = "Sub-zero flame."; + + State = ST_LIQUID; + Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + Graphics = &Element_HFLM::graphics; +} + +//#TPT-Directive ElementHeader Element_HFLM static int graphics(GRAPHICS_FUNC_ARGS) +int Element_HFLM::graphics(GRAPHICS_FUNC_ARGS) + +{ + int caddress = restrict_flt(restrict_flt((float)((int)(cpart->life/2)), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + *colr = (unsigned char)hflm_data[caddress]; + *colg = (unsigned char)hflm_data[caddress+1]; + *colb = (unsigned char)hflm_data[caddress+2]; + + *firea = 255; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + + *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel + *pixel_mode |= FIRE_ADD; + //Returning 0 means dynamic, do not cache + return 0; +} + + +Element_HFLM::~Element_HFLM() {}
\ No newline at end of file diff --git a/src/simulation/elements/HSWC.cpp b/src/simulation/elements/HSWC.cpp new file mode 100644 index 0000000..0f3c7e7 --- /dev/null +++ b/src/simulation/elements/HSWC.cpp @@ -0,0 +1,87 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_HSWC PT_HSWC 75 +Element_HSWC::Element_HSWC() +{ + Identifier = "DEFAULT_PT_HSWC"; + Name = "HSWC"; + Colour = PIXPACK(0x3B0A0A); + MenuVisible = 1; + MenuSection = SC_POWERED; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Heat switch. Conducts Heat only when activated"; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_HSWC::update; + Graphics = &Element_HSWC::graphics; +} + +//#TPT-Directive ElementHeader Element_HSWC static int update(UPDATE_FUNC_ARGS) +int Element_HSWC::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].life>0 && parts[i].life!=10) + parts[i].life--; + if (parts[i].life==10) + { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_HSWC) + { + if (parts[r>>8].life<10&&parts[r>>8].life>0) + parts[i].life = 9; + else if (parts[r>>8].life==0) + parts[r>>8].life = 10; + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_HSWC static int graphics(GRAPHICS_FUNC_ARGS) +int Element_HSWC::graphics(GRAPHICS_FUNC_ARGS) + +{ + int lifemod = ((cpart->life>10?10:cpart->life)*19); + *colr += lifemod; + return 0; +} + + +Element_HSWC::~Element_HSWC() {}
\ No newline at end of file diff --git a/src/simulation/elements/ICEI.cpp b/src/simulation/elements/ICEI.cpp new file mode 100644 index 0000000..3624877 --- /dev/null +++ b/src/simulation/elements/ICEI.cpp @@ -0,0 +1,76 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ICEI PT_ICEI 13 +Element_ICEI::Element_ICEI() +{ + Identifier = "DEFAULT_PT_ICEI"; + Name = "ICE"; + Colour = PIXPACK(0xA0C0FF); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = -0.0003f* CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 100; + + Temperature = R_TEMP-50.0f+273.15f; + HeatConduct = 46; + Description = "Solid. Freezes water. Crushes under pressure. Cools down air."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 0.8f; + HighPressureTransition = PT_SNOW; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 252.05f; + HighTemperatureTransition = ST; + + Update = &Element_ICEI::update; + +} + +//#TPT-Directive ElementHeader Element_ICEI static int update(UPDATE_FUNC_ARGS) +int Element_ICEI::update(UPDATE_FUNC_ARGS) + { //currently used for snow as well + int r, rx, ry; + if (parts[i].ctype==PT_FRZW)//get colder if it is from FRZW + { + parts[i].temp = restrict_flt(parts[i].temp-1.0f, MIN_TEMP, MAX_TEMP); + } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_SALT || (r&0xFF)==PT_SLTW) && parts[i].temp > sim->elements[PT_SLTW].LowTemperature && 1>(rand()%1000)) + { + 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; +} + + +Element_ICEI::~Element_ICEI() {}
\ No newline at end of file diff --git a/src/simulation/elements/IGNT.cpp b/src/simulation/elements/IGNT.cpp new file mode 100644 index 0000000..de26eb7 --- /dev/null +++ b/src/simulation/elements/IGNT.cpp @@ -0,0 +1,95 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_IGNT PT_IGNT 140 +Element_IGNT::Element_IGNT() +{ + Identifier = "DEFAULT_PT_IGNT"; + Name = "IGNC"; + Colour = PIXPACK(0xC0B050); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 88; + Description = "Ignition cord."; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NEUTPENETRATE | PROP_SPARKSETTLE | PROP_LIFE_KILL; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 673.0f; + HighTemperatureTransition = PT_FIRE; + + Update = &Element_IGNT::update; + +} + +//#TPT-Directive ElementHeader Element_IGNT static int update(UPDATE_FUNC_ARGS) +int Element_IGNT::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if(parts[i].tmp==0) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) + { + parts[i].tmp = 1; + } + else if ((r&0xFF)==PT_SPRK || (r&0xFF)==PT_LIGH || ((r&0xFF)==PT_IGNT && parts[r>>8].life==1)) + { + parts[i].tmp = 1; + } + } + } + else if(parts[i].life > 0) + { + if(rand()%3) + { + int nb = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_EMBR); + if (nb!=-1) { + parts[nb].tmp = 0; + parts[nb].life = 30; + parts[nb].vx = rand()%20-10; + parts[nb].vy = rand()%20-10; + parts[nb].temp = restrict_flt(400.0f+parts[i].temp-273.15, MIN_TEMP, MAX_TEMP); + } + } + else + { + sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE); + } + parts[i].life--; + } + return 0; +} + + +Element_IGNT::~Element_IGNT() {}
\ No newline at end of file diff --git a/src/simulation/elements/INSL.cpp b/src/simulation/elements/INSL.cpp new file mode 100644 index 0000000..8685775 --- /dev/null +++ b/src/simulation/elements/INSL.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_INSL PT_INSL 38 +Element_INSL::Element_INSL() +{ + Identifier = "DEFAULT_PT_INSL"; + Name = "INSL"; + Colour = PIXPACK(0x9EA3B6); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + 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 = 7; + Explosive = 0; + Meltable = 0; + Hardness = 10; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Insulator, does not conduct heat or electricity."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_INSL::~Element_INSL() {}
\ No newline at end of file diff --git a/src/simulation/elements/INST.cpp b/src/simulation/elements/INST.cpp new file mode 100644 index 0000000..a8a8d3e --- /dev/null +++ b/src/simulation/elements/INST.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_INST PT_INST 106 +Element_INST::Element_INST() +{ + Identifier = "DEFAULT_PT_INST"; + Name = "INST"; + Colour = PIXPACK(0x404039); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Instantly conducts, PSCN to charge, NSCN to take."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_INST::~Element_INST() {}
\ No newline at end of file diff --git a/src/simulation/elements/INVIS.cpp b/src/simulation/elements/INVIS.cpp new file mode 100644 index 0000000..54d722d --- /dev/null +++ b/src/simulation/elements/INVIS.cpp @@ -0,0 +1,75 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_INVIS PT_INVIS 115 +Element_INVIS::Element_INVIS() +{ + Identifier = "DEFAULT_PT_INVIS"; + Name = "INVS"; + Colour = PIXPACK(0x00CCCC); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 15; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 164; + Description = "Invisible to everything while under pressure."; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NEUTPASS; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_INVIS::update; + Graphics = &Element_INVIS::graphics; +} + +//#TPT-Directive ElementHeader Element_INVIS static int update(UPDATE_FUNC_ARGS) +int Element_INVIS::update(UPDATE_FUNC_ARGS) +{ + if (sim->pv[y/CELL][x/CELL]>4.0f || sim->pv[y/CELL][x/CELL]<-4.0f) + parts[i].tmp = 1; + else + parts[i].tmp = 0; + return 0; +} + +//#TPT-Directive ElementHeader Element_INVIS static int graphics(GRAPHICS_FUNC_ARGS) +int Element_INVIS::graphics(GRAPHICS_FUNC_ARGS) +{ + //pv[ny/CELL][nx/CELL]>4.0f || pv[ny/CELL][nx/CELL]<-4.0f + if(cpart->tmp) + { + *cola = 100; + *colr = 15; + *colg = 0; + *colb = 150; + *pixel_mode = PMODE_BLEND; + } + return 0; +} + + +Element_INVIS::~Element_INVIS() {} diff --git a/src/simulation/elements/INWR.cpp b/src/simulation/elements/INWR.cpp new file mode 100644 index 0000000..35d57ec --- /dev/null +++ b/src/simulation/elements/INWR.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_INWR PT_INWR 62 +Element_INWR::Element_INWR() +{ + Identifier = "DEFAULT_PT_INWR"; + Name = "INWR"; + Colour = PIXPACK(0x544141); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Insulated Wire. Doesn't conduct to metal or semiconductors."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1687.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_INWR::~Element_INWR() {}
\ No newline at end of file diff --git a/src/simulation/elements/IRON.cpp b/src/simulation/elements/IRON.cpp new file mode 100644 index 0000000..1542da9 --- /dev/null +++ b/src/simulation/elements/IRON.cpp @@ -0,0 +1,76 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_IRON PT_IRON 76 +Element_IRON::Element_IRON() +{ + Identifier = "DEFAULT_PT_IRON"; + Name = "IRON"; + Colour = PIXPACK(0x707070); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 50; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Rusts with salt, can be used for electrolysis of WATR"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1687.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_IRON::update; + +} + +//#TPT-Directive ElementHeader Element_IRON static int update(UPDATE_FUNC_ARGS) +int Element_IRON::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((((r&0xFF) == PT_SALT && 15>(rand()/(RAND_MAX/700))) || + ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/2000))) || + ((r&0xFF) == PT_WATR && 5 >(rand()/(RAND_MAX/6000))) || + ((r&0xFF) == PT_O2 && 2 >(rand()/(RAND_MAX/500))) || + ((r&0xFF) == PT_LO2))&& + (!(parts[i].life)) + ) + { + sim->part_change_type(i,x,y,PT_BMTL); + parts[i].tmp=(rand()/(RAND_MAX/10))+20; + } + } + return 0; +} + + +Element_IRON::~Element_IRON() {}
\ No newline at end of file diff --git a/src/simulation/elements/ISOZ.cpp b/src/simulation/elements/ISOZ.cpp new file mode 100644 index 0000000..05df489 --- /dev/null +++ b/src/simulation/elements/ISOZ.cpp @@ -0,0 +1,65 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ISOZ PT_ISOZ 107 +Element_ISOZ::Element_ISOZ() +{ + Identifier = "DEFAULT_PT_ISOZ"; + Name = "ISOZ"; + Colour = PIXPACK(0xAA30D0); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 24; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Radioactive liquid"; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 160.0f; + LowTemperatureTransition = PT_ISZS; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_ISOZ::update; + +} + +//#TPT-Directive ElementHeader Element_ISOZ static int update(UPDATE_FUNC_ARGS) +int Element_ISOZ::update(UPDATE_FUNC_ARGS) + { // for both ISZS and ISOZ + float rr, rrr; + if (1>rand()%200 && ((int)(-4.0f*(sim->pv[y/CELL][x/CELL])))>(rand()%1000)) + { + sim->create_part(i, x, y, PT_PHOT); + rr = (rand()%228+128)/127.0f; + rrr = (rand()%360)*3.14159f/180.0f; + parts[i].vx = rr*cosf(rrr); + parts[i].vy = rr*sinf(rrr); + } + return 0; +} + + +Element_ISOZ::~Element_ISOZ() {}
\ No newline at end of file diff --git a/src/simulation/elements/ISZS.cpp b/src/simulation/elements/ISZS.cpp new file mode 100644 index 0000000..b12f34c --- /dev/null +++ b/src/simulation/elements/ISZS.cpp @@ -0,0 +1,65 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_ISZS PT_ISZS 108 +Element_ISZS::Element_ISZS() +{ + Identifier = "DEFAULT_PT_ISZS"; + Name = "ISZS"; + Colour = PIXPACK(0x662089); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = -0.0007f* CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = 140.00f; + HeatConduct = 251; + Description = "Solid form of ISOZ, slowly decays."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 300.0f; + HighTemperatureTransition = PT_ISOZ; + + Update = &Element_ISZS::update; + +} + +//#TPT-Directive ElementHeader Element_ISZS static int update(UPDATE_FUNC_ARGS) +int Element_ISZS::update(UPDATE_FUNC_ARGS) + { // for both ISZS and ISOZ + float rr, rrr; + if (1>rand()%200 && ((int)(-4.0f*(sim->pv[y/CELL][x/CELL])))>(rand()%1000)) + { + sim->create_part(i, x, y, PT_PHOT); + rr = (rand()%228+128)/127.0f; + rrr = (rand()%360)*3.14159f/180.0f; + parts[i].vx = rr*cosf(rrr); + parts[i].vy = rr*sinf(rrr); + } + return 0; +} + + +Element_ISZS::~Element_ISZS() {}
\ No newline at end of file diff --git a/src/simulation/elements/LAVA.cpp b/src/simulation/elements/LAVA.cpp new file mode 100644 index 0000000..35eefec --- /dev/null +++ b/src/simulation/elements/LAVA.cpp @@ -0,0 +1,71 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_LAVA PT_LAVA 6 +Element_LAVA::Element_LAVA() +{ + Identifier = "DEFAULT_PT_LAVA"; + Name = "LAVA"; + Colour = PIXPACK(0xE05010); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.3f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.95f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.15f; + Diffusion = 0.00f; + HotAir = 0.0003f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 2; + + Weight = 45; + + Temperature = R_TEMP+1500.0f+273.15f; + HeatConduct = 60; + Description = "Heavy liquid. Ignites flammable materials. Solidifies when cold."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 2573.15f; + LowTemperatureTransition = ST; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_FIRE::update; + Graphics = &Element_LAVA::graphics; +} + + +//#TPT-Directive ElementHeader Element_LAVA static int graphics(GRAPHICS_FUNC_ARGS) +int Element_LAVA::graphics(GRAPHICS_FUNC_ARGS) + +{ + *colr = cpart->life * 2 + 0xE0; + *colg = cpart->life * 1 + 0x50; + *colb = cpart->life / 2 + 0x10; + if (*colr>255) *colr = 255; + if (*colg>192) *colg = 192; + if (*colb>128) *colb = 128; + *firea = 40; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + *pixel_mode |= FIRE_ADD; + *pixel_mode |= PMODE_BLUR; + //Returning 0 means dynamic, do not cache + return 0; +} + + +Element_LAVA::~Element_LAVA() {}
\ No newline at end of file diff --git a/src/simulation/elements/LCRY.cpp b/src/simulation/elements/LCRY.cpp new file mode 100644 index 0000000..7cd4def --- /dev/null +++ b/src/simulation/elements/LCRY.cpp @@ -0,0 +1,154 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_LCRY PT_LCRY 54 +Element_LCRY::Element_LCRY() +{ + Identifier = "DEFAULT_PT_LCRY"; + Name = "LCRY"; + Colour = PIXPACK(0x505050); + MenuVisible = 1; + MenuSection = SC_POWERED; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Liquid Crystal. Changes colour when charged. (PSCN Charges, NSCN Discharges)"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1273.0f; + HighTemperatureTransition = PT_BGLA; + + Update = &Element_LCRY::update; + Graphics = &Element_LCRY::graphics; +} + +//#TPT-Directive ElementHeader Element_LCRY static int update(UPDATE_FUNC_ARGS) +int Element_LCRY::update(UPDATE_FUNC_ARGS) + +{ + int r, rx, ry; + if(parts[i].tmp==1 || parts[i].tmp==0) + { + if(parts[i].tmp==1) + { + if(parts[i].life<=0) + parts[i].tmp = 0; + else + { + parts[i].life-=2; + if(parts[i].life < 0) + parts[i].life = 0; + parts[i].tmp2 = parts[i].life; + } + } + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_LCRY && parts[r>>8].tmp == 3) + { + parts[r>>8].tmp = 1; + } + } + } + else if(parts[i].tmp==2 || parts[i].tmp==3) + { + if(parts[i].tmp==2) + { + if(parts[i].life>=10) + parts[i].tmp = 3; + else + { + parts[i].life+=2; + if(parts[i].life > 10) + parts[i].life = 10; + parts[i].tmp2 = parts[i].life; + } + } + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_LCRY && parts[r>>8].tmp == 0) + { + parts[r>>8].tmp = 2; + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_LCRY static int graphics(GRAPHICS_FUNC_ARGS) +int Element_LCRY::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(ren->decorations_enable && cpart->dcolour && (cpart->dcolour&0xFF000000)) + { + *colr = (cpart->dcolour>>16)&0xFF; + *colg = (cpart->dcolour>>8)&0xFF; + *colb = (cpart->dcolour)&0xFF; + + if(cpart->tmp2<10){ + *colr /= 10-cpart->tmp2; + *colg /= 10-cpart->tmp2; + *colb /= 10-cpart->tmp2; + } + + } + else + { + *colr = *colg = *colb = 0x50+((cpart->tmp2>10?10:cpart->tmp2)*10); + } + *pixel_mode |= NO_DECO; + return 0; + + /*int lifemod = ((cpart->tmp2>10?10:cpart->tmp2)*10); + *colr += lifemod; + *colg += lifemod; + *colb += lifemod; + if(decorations_enable && cpart->dcolour && cpart->dcolour&0xFF000000) + { + lifemod *= 2.5f; + if(lifemod < 40) + lifemod = 40; + *colr = (lifemod*((cpart->dcolour>>16)&0xFF) + (255-lifemod)**colr) >> 8; + *colg = (lifemod*((cpart->dcolour>>8)&0xFF) + (255-lifemod)**colg) >> 8; + *colb = (lifemod*((cpart->dcolour)&0xFF) + (255-lifemod)**colb) >> 8; + } + *pixel_mode |= NO_DECO; + return 0;*/ +} + + +Element_LCRY::~Element_LCRY() {}
\ No newline at end of file diff --git a/src/simulation/elements/LIFE.cpp b/src/simulation/elements/LIFE.cpp new file mode 100644 index 0000000..4207931 --- /dev/null +++ b/src/simulation/elements/LIFE.cpp @@ -0,0 +1,125 @@ +#include "simulation/Elements.h" + +bool Element_GOL_colourInit = false; +pixel Element_GOL_colour[NGOL]; + +//#TPT-Directive ElementClass Element_LIFE PT_LIFE 78 +Element_LIFE::Element_LIFE() +{ + Identifier = "DEFAULT_PT_LIFE"; + Name = "LIFE"; + Colour = PIXPACK(0x0CAC00); + MenuVisible = 0; + MenuSection = SC_LIFE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 9000.0f; + HeatConduct = 40; + Description = "Game Of Life! B3/S23"; + + State = ST_NONE; + Properties = TYPE_SOLID|PROP_LIFE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + Graphics = &Element_LIFE::graphics; + + if(!Element_GOL_colourInit) + { + Element_GOL_colourInit = true; + + + int golMenuCount; + gol_menu * golMenuT = LoadGOLMenu(golMenuCount); + for(int i = 0; i < golMenuCount && i < NGOL; i++) + { + Element_GOL_colour[i] = golMenuT[i].colour; + } + free(golMenuT); + } +} + + +//#TPT-Directive ElementHeader Element_LIFE static int graphics(GRAPHICS_FUNC_ARGS) +int Element_LIFE::graphics(GRAPHICS_FUNC_ARGS) + +{ + pixel pc; + if (cpart->ctype==NGT_LOTE)//colors for life states + { + if (cpart->tmp==2) + pc = PIXRGB(255, 128, 0); + else if (cpart->tmp==1) + pc = PIXRGB(255, 255, 0); + else + pc = PIXRGB(255, 0, 0); + } + else if (cpart->ctype==NGT_FRG2)//colors for life states + { + if (cpart->tmp==2) + pc = PIXRGB(0, 100, 50); + else + pc = PIXRGB(0, 255, 90); + } + else if (cpart->ctype==NGT_STAR)//colors for life states + { + if (cpart->tmp==4) + pc = PIXRGB(0, 0, 128); + else if (cpart->tmp==3) + pc = PIXRGB(0, 0, 150); + else if (cpart->tmp==2) + pc = PIXRGB(0, 0, 190); + else if (cpart->tmp==1) + pc = PIXRGB(0, 0, 230); + else + pc = PIXRGB(0, 0, 70); + } + else if (cpart->ctype==NGT_FROG)//colors for life states + { + if (cpart->tmp==2) + pc = PIXRGB(0, 100, 0); + else + pc = PIXRGB(0, 255, 0); + } + else if (cpart->ctype==NGT_BRAN)//colors for life states + { + if (cpart->tmp==1) + pc = PIXRGB(150, 150, 0); + else + pc = PIXRGB(255, 255, 0); + } else { + pc = Element_GOL_colour[cpart->ctype]; + } + *colr = PIXR(pc); + *colg = PIXG(pc); + *colb = PIXB(pc); + return 0; +} + + +Element_LIFE::~Element_LIFE() {}
\ No newline at end of file diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp new file mode 100644 index 0000000..c0c723e --- /dev/null +++ b/src/simulation/elements/LIGH.cpp @@ -0,0 +1,359 @@ +#include "simulation/Elements.h" + +//#TPT-Directive ElementClass Element_LIGH PT_LIGH 87 +Element_LIGH::Element_LIGH() +{ + Identifier = "DEFAULT_PT_LIGH"; + Name = "LIGH"; + Colour = PIXPACK(0xFFFFC0); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "More realistic lightning. Set pen size to set the size of the lightning."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_LIGH::update; + Graphics = &Element_LIGH::graphics; +} + +#define LIGHTING_POWER 0.65 + +//#TPT-Directive ElementHeader Element_LIGH static int update(UPDATE_FUNC_ARGS) +int Element_LIGH::update(UPDATE_FUNC_ARGS) + +{ + /* + * + * tmp2: + * -1 - part will be removed + * 0 - "branches" of the lightning + * 1 - bending + * 2 - branching + * 3 - transfer spark or make destruction + * 4 - first pixel + * + * life - "thickness" of lighting (but anyway one pixel) + * + * tmp - angle of lighting, measured in degrees anticlockwise from the positive x direction + * + */ + int r,rx,ry, multipler, powderful; + float angle, angle2=-1; + int pNear = 0; + powderful = powderful = parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER; + Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); + if (sim->aheat_enable) + { + sim->hv[y/CELL][x/CELL]+=powderful/50; + if (sim->hv[y/CELL][x/CELL]>MAX_TEMP) + sim->hv[y/CELL][x/CELL]=MAX_TEMP; + } + + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_LIGH && (r&0xFF)!=PT_TESC) + { + if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT) + { + if ((sim->elements[r&0xFF].Properties&PROP_CONDUCTS) && parts[r>>8].life==0) + { + sim->create_part(r>>8,x+rx,y+ry,PT_SPRK); + } + sim->pv[y/CELL][x/CELL] += powderful/400; + if (sim->elements[r&0xFF].HeatConduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/1.5, MIN_TEMP, MAX_TEMP); + } + if ((r&0xFF)==PT_DEUT || (r&0xFF)==PT_PLUT) // start nuclear reactions + { + parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful, MIN_TEMP, MAX_TEMP); + sim->pv[y/CELL][x/CELL] +=powderful/35; + if (rand()%3==0) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_NEUT); + parts[r>>8].life = rand()%480+480; + parts[r>>8].vx=rand()%10-5; + parts[r>>8].vy=rand()%10-5; + } + } + if ((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL) // ignite coal + { + if (parts[r>>8].life>100) { + parts[r>>8].life = 99; + } + } + if (sim->elements[r&0xFF].HeatConduct) + parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/10, MIN_TEMP, MAX_TEMP); + if (((r&0xFF)==PT_STKM && sim->player.elem!=PT_LIGH) || ((r&0xFF)==PT_STKM2 && sim->player2.elem!=PT_LIGH)) + { + parts[r>>8].life-=powderful/100; + } + } + } + if (parts[i].tmp2==3) + { + parts[i].tmp2=0; + return 1; + } + + if (parts[i].tmp2==-1) + { + sim->kill_part(i); + return 1; + } + if (parts[i].tmp2<=0 || parts[i].life<=1) + { + if (parts[i].tmp2>0) + parts[i].tmp2=0; + parts[i].tmp2--; + return 1; + } + if (parts[i].tmp2<=-2) + { + sim->kill_part(i); + return 1; + } + + angle2=-1; + + pNear = LIGH_nearest_part(sim, i, parts[i].life*2.5); + if (pNear!=-1) + { + int t=parts[pNear].type; + float n_angle; // angle to nearest part + float angle_diff; + rx=parts[pNear].x-x; + ry=parts[pNear].y-y; + if (rx!=0 || ry!=0) + n_angle = atan2f(-ry, rx); + else + n_angle = 0; + if (n_angle<0) + n_angle+=M_PI*2; + angle_diff = fabsf(n_angle-parts[i].tmp*M_PI/180); + if (angle_diff>M_PI) + angle_diff = M_PI*2 - angle_diff; + if (parts[i].life<5 || angle_diff<M_PI*0.8) // lightning strike + { + create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0); + + if (t!=PT_TESC) + { + pNear=contact_part(sim, pNear, PT_LIGH); + if (pNear!=-1) + { + parts[pNear].tmp2=3; + parts[pNear].life=(int)(1.0*parts[i].life/2-1); + parts[pNear].tmp=parts[i].tmp-180; + parts[pNear].temp=parts[i].temp; + } + } + } + else pNear=-1; + } + + //if (parts[i].tmp2==1/* || near!=-1*/) + //angle=0;//parts[i].tmp-30+rand()%60; + angle = parts[i].tmp-30+rand()%60; + if (angle<0) + angle+=360; + if (angle>=360) + angle-=360; + if (parts[i].tmp2==2 && pNear==-1) + { + angle2=angle+100-rand()%200; + if (angle2<0) + angle2+=360; + if (angle2>=360) + angle-=360; + } + + multipler=parts[i].life*1.5+rand()%((int)(parts[i].life+1)); + rx=cos(angle*M_PI/180)*multipler; + ry=-sin(angle*M_PI/180)*multipler; + create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle, 0); + + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r&0xFF)==PT_LIGH) + { + parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+60); + parts[r>>8].life=(int)(1.0*parts[i].life/1.5-rand()%2); + parts[r>>8].tmp=angle; + parts[r>>8].temp=parts[i].temp; + } + } + + if (angle2!=-1) + { + multipler=parts[i].life*1.5+rand()%((int)(parts[i].life+1)); + rx=cos(angle2*M_PI/180)*multipler; + ry=-sin(angle2*M_PI/180)*multipler; + create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle2, 0); + + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r&0xFF)==PT_LIGH) + { + parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+40); + parts[r>>8].life=(int)(1.0*parts[i].life/1.5-rand()%2); + parts[r>>8].tmp=angle; + parts[r>>8].temp=parts[i].temp; + } + } + } + + parts[i].tmp2=-1; + return 1; +} + +//#TPT-Directive ElementHeader Element_LIGH static int LIGH_nearest_part(Simulation * sim, int ci, int max_d) +int Element_LIGH::LIGH_nearest_part(Simulation * sim, int ci, int max_d) +{ + int distance = (max_d!=-1)?max_d:MAX_DISTANCE; + int ndistance = 0; + int id = -1; + int i = 0; + int cx = (int)sim->parts[ci].x; + int cy = (int)sim->parts[ci].y; + for (i=0; i<=sim->parts_lastActiveIndex; i++) + { + if (sim->parts[i].type && sim->parts[i].life && i!=ci && sim->parts[i].type!=PT_LIGH && sim->parts[i].type!=PT_THDR && sim->parts[i].type!=PT_NEUT && sim->parts[i].type!=PT_PHOT) + { + ndistance = abs(cx-sim->parts[i].x)+abs(cy-sim->parts[i].y);// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2)); + if (ndistance<distance) + { + distance = ndistance; + id = i; + } + } + } + return id; +} + +//#TPT-Directive ElementHeader Element_LIGH static int contact_part(Simulation * sim, int i, int tp) +int Element_LIGH::contact_part(Simulation * sim, int i, int tp) +{ + int x=sim->parts[i].x, y=sim->parts[i].y; + int r,rx,ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = sim->pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==tp) + return r>>8; + } + return -1; +} + +//#TPT-Directive ElementHeader Element_LIGH static void create_line_par(Simulation * sim, int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2) +void Element_LIGH::create_line_par(Simulation * sim, int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2) +{ + int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; + float e, de; + if (c==WL_EHOLE || c==WL_ALLOWGAS || c==WL_ALLOWALLELEC || c==WL_ALLOWSOLID || c==WL_ALLOWAIR || c==WL_WALL || c==WL_DESTROYALL || c==WL_ALLOWLIQUID || c==WL_FAN || c==WL_STREAM || c==WL_DETECT || c==WL_EWALL || c==WL_WALLELEC) + return; // this function only for particles, no walls + if (cp) + { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1<y2) ? 1 : -1; + for (x=x1; x<=x2; x++) + { + int p; + if (cp) + p = sim->create_part(-1, y, x, c); + else + p = sim->create_part(-1, x, y,c); + if (p!=-1) + { + sim->parts[p].life = life; + sim->parts[p].temp = temp; + sim->parts[p].tmp = tmp; + sim->parts[p].tmp2 = tmp2; + } + e += de; + if (e >= 0.5f) + { + y += sy; + e -= 1.0f; + } + } +} + + +//#TPT-Directive ElementHeader Element_LIGH static int graphics(GRAPHICS_FUNC_ARGS) +int Element_LIGH::graphics(GRAPHICS_FUNC_ARGS) + +{ + *firea = 120; + *firer = *colr = 235; + *fireg = *colg = 245; + *fireb = *colb = 255; + *pixel_mode |= PMODE_GLOW | FIRE_ADD; + return 1; +} + + +Element_LIGH::~Element_LIGH() {}
\ No newline at end of file diff --git a/src/simulation/elements/LNTG.cpp b/src/simulation/elements/LNTG.cpp new file mode 100644 index 0000000..ac97191 --- /dev/null +++ b/src/simulation/elements/LNTG.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_LNTG PT_LNTG 37 +Element_LNTG::Element_LNTG() +{ + Identifier = "DEFAULT_PT_LNTG"; + Name = "LN2"; + Colour = PIXPACK(0x80A0DF); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 30; + + Temperature = 70.15f; + HeatConduct = 70; + Description = "Liquid Nitrogen. Very cold."; + + State = ST_SOLID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 63.0f; + LowTemperatureTransition = PT_NICE; + HighTemperature = 77.0f; + HighTemperatureTransition = PT_NONE; + + Update = NULL; + +} + +Element_LNTG::~Element_LNTG() {}
\ No newline at end of file diff --git a/src/simulation/elements/LO2.cpp b/src/simulation/elements/LO2.cpp new file mode 100644 index 0000000..e032b9e --- /dev/null +++ b/src/simulation/elements/LO2.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_LO2 PT_LO2 60 +Element_LO2::Element_LO2() +{ + Identifier = "DEFAULT_PT_LO2"; + Name = "LOXY"; + Colour = PIXPACK(0x80A0EF); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 5000; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 30; + + Temperature = 80.0f; + HeatConduct = 70; + Description = "Liquid Oxygen. Very cold. Reacts with fire"; + + State = ST_LIQUID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 90.1f; + HighTemperatureTransition = PT_O2; + + Update = NULL; + +} + +Element_LO2::~Element_LO2() {}
\ No newline at end of file diff --git a/src/simulation/elements/LOLZ.cpp b/src/simulation/elements/LOLZ.cpp new file mode 100644 index 0000000..a5e8371 --- /dev/null +++ b/src/simulation/elements/LOLZ.cpp @@ -0,0 +1,71 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_LOLZ PT_LOLZ 123 +Element_LOLZ::Element_LOLZ() +{ + Identifier = "DEFAULT_PT_LOLZ"; + Name = "LOLZ"; + Colour = PIXPACK(0x569212); + MenuVisible = 1; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.00f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.0f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = 373.0f; + HeatConduct = 40; + Description = "Lolz"; + + State = ST_GAS; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_LOLZ::update; + +} + +//#TPT-Directive ElementHeader Element_LOLZ static int RuleTable[9][9] +int Element_LOLZ::RuleTable[9][9] = +{ + {0,0,0,0,0,0,0,0,0}, + {1,0,0,0,0,0,1,0,0}, + {1,0,0,0,0,0,1,0,0}, + {1,0,0,1,1,0,0,1,0}, + {1,0,1,0,0,1,0,1,0}, + {1,0,1,0,0,1,0,1,0}, + {0,1,0,1,1,0,0,1,0}, + {0,1,0,0,0,0,0,1,0}, + {0,1,0,0,0,0,0,1,0}, +}; + +//#TPT-Directive ElementHeader Element_LOLZ static int update(UPDATE_FUNC_ARGS) +int Element_LOLZ::update(UPDATE_FUNC_ARGS) + { + sim->ISLOLZ = true; + return 0; +} + + +Element_LOLZ::~Element_LOLZ() {}
\ No newline at end of file diff --git a/src/simulation/elements/LOVE.cpp b/src/simulation/elements/LOVE.cpp new file mode 100644 index 0000000..3e7b3d4 --- /dev/null +++ b/src/simulation/elements/LOVE.cpp @@ -0,0 +1,71 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_LOVE PT_LOVE 94 +Element_LOVE::Element_LOVE() +{ + Identifier = "DEFAULT_PT_LOVE"; + Name = "LOVE"; + Colour = PIXPACK(0xFF30FF); + MenuVisible = 1; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.00f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.0f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = 373.0f; + HeatConduct = 40; + Description = "Love..."; + + State = ST_GAS; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_LOVE::update; + +} + +//#TPT-Directive ElementHeader Element_LOVE static int RuleTable[9][9] +int Element_LOVE::RuleTable[9][9] = +{ + {0,0,1,1,0,0,0,0,0}, + {0,1,0,0,1,1,0,0,0}, + {1,0,0,0,0,0,1,0,0}, + {1,0,0,0,0,0,0,1,0}, + {0,1,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,1,0}, + {1,0,0,0,0,0,1,0,0}, + {0,1,0,0,1,1,0,0,0}, + {0,0,1,1,0,0,0,0,0}, +}; + +//#TPT-Directive ElementHeader Element_LOVE static int update(UPDATE_FUNC_ARGS) +int Element_LOVE::update(UPDATE_FUNC_ARGS) + { + sim->ISLOVE = true; + return 0; +} + + +Element_LOVE::~Element_LOVE() {}
\ No newline at end of file diff --git a/src/simulation/elements/LRBD.cpp b/src/simulation/elements/LRBD.cpp new file mode 100644 index 0000000..f609cce --- /dev/null +++ b/src/simulation/elements/LRBD.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_LRBD PT_LRBD 42 +Element_LRBD::Element_LRBD() +{ + Identifier = "DEFAULT_PT_LRBD"; + Name = "LRBD"; + Colour = PIXPACK(0xAAAAAA); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.3f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.95f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.15f; + Diffusion = 0.00f; + HotAir = 0.000001f* CFDS; + Falldown = 2; + + Flammable = 1000; + Explosive = 1; + Meltable = 0; + Hardness = 2; + + Weight = 45; + + Temperature = R_TEMP+45.0f+273.15f; + HeatConduct = 170; + Description = "Liquid Rubidium."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 311.0f; + LowTemperatureTransition = PT_RBDM; + HighTemperature = 961.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + +} + +Element_LRBD::~Element_LRBD() {}
\ No newline at end of file diff --git a/src/simulation/elements/MERC.cpp b/src/simulation/elements/MERC.cpp new file mode 100644 index 0000000..1fec32a --- /dev/null +++ b/src/simulation/elements/MERC.cpp @@ -0,0 +1,121 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_MERC PT_MERC 152 +Element_MERC::Element_MERC() +{ + Identifier = "DEFAULT_PT_MERC"; + Name = "MERC"; + Colour = PIXPACK(0x736B6D); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 91; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Mercury. Volume changes with temperature, Conductive."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_CONDUCTS|PROP_NEUTABSORB|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_MERC::update; + +} + +//#TPT-Directive ElementHeader Element_MERC static int update(UPDATE_FUNC_ARGS) +int Element_MERC::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, trade, np; + int maxtmp = ((10000/(parts[i].temp + 1))-1); + if ((10000%((int)parts[i].temp+1))>rand()%((int)parts[i].temp+1)) + maxtmp ++; + if (parts[i].tmp < maxtmp) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r || (parts[i].tmp >=maxtmp)) + continue; + if ((r&0xFF)==PT_MERC&&33>=rand()/(RAND_MAX/100)+1) + { + if ((parts[i].tmp + parts[r>>8].tmp + 1) <= maxtmp) + { + parts[i].tmp += parts[r>>8].tmp + 1; + sim->kill_part(r>>8); + } + } + } + } + else + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (parts[i].tmp<=maxtmp) + continue; + if ((!r)&&parts[i].tmp>=1)//if nothing then create deut + { + np = sim->create_part(-1,x+rx,y+ry,PT_MERC); + if (np<0) continue; + parts[i].tmp--; + parts[np].temp = parts[i].temp; + parts[np].tmp = 0; + } + } + for ( trade = 0; trade<4; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_MERC&&(parts[i].tmp>parts[r>>8].tmp)&&parts[i].tmp>0)//diffusion + { + int temp = parts[i].tmp - parts[r>>8].tmp; + if (temp ==1) + { + parts[r>>8].tmp ++; + parts[i].tmp --; + } + else if (temp>0) + { + parts[r>>8].tmp += temp/2; + parts[i].tmp -= temp/2; + } + } + } + } + return 0; +} + + +Element_MERC::~Element_MERC() {}
\ No newline at end of file diff --git a/src/simulation/elements/METL.cpp b/src/simulation/elements/METL.cpp new file mode 100644 index 0000000..17b09d0 --- /dev/null +++ b/src/simulation/elements/METL.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_METL PT_METL 14 +Element_METL::Element_METL() +{ + Identifier = "DEFAULT_PT_METL"; + Name = "METL"; + Colour = PIXPACK(0x404060); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Solid. Conducts electricity. Meltable."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1273.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_METL::~Element_METL() {}
\ No newline at end of file diff --git a/src/simulation/elements/MORT.cpp b/src/simulation/elements/MORT.cpp new file mode 100644 index 0000000..f8f1d8c --- /dev/null +++ b/src/simulation/elements/MORT.cpp @@ -0,0 +1,57 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_MORT PT_MORT 77 +Element_MORT::Element_MORT() +{ + Identifier = "DEFAULT_PT_MORT"; + Name = "MORT"; + Colour = PIXPACK(0xE0E0E0); + MenuVisible = 1; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + Loss = 1.00f; + Collision = -0.99f; + Gravity = 0.0f; + Diffusion = 0.01f; + HotAir = 0.002f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = -1; + + Temperature = R_TEMP+4.0f +273.15f; + HeatConduct = 60; + Description = "Steam Train."; + + State = ST_NONE; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_MORT::update; + +} + +//#TPT-Directive ElementHeader Element_MORT static int update(UPDATE_FUNC_ARGS) +int Element_MORT::update(UPDATE_FUNC_ARGS) + { + sim->create_part(-1, x, y-1, PT_SMKE); + return 0; +} + + +Element_MORT::~Element_MORT() {}
\ No newline at end of file diff --git a/src/simulation/elements/MWAX.cpp b/src/simulation/elements/MWAX.cpp new file mode 100644 index 0000000..4153893 --- /dev/null +++ b/src/simulation/elements/MWAX.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_MWAX PT_MWAX 34 +Element_MWAX::Element_MWAX() +{ + Identifier = "DEFAULT_PT_MWAX"; + Name = "MWAX"; + Colour = PIXPACK(0xE0E0AA); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.3f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.95f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.15f; + Diffusion = 0.00f; + HotAir = 0.000001f* CFDS; + Falldown = 2; + + Flammable = 5; + Explosive = 0; + Meltable = 0; + Hardness = 2; + + Weight = 25; + + Temperature = R_TEMP+28.0f+273.15f; + HeatConduct = 44; + Description = "Liquid Wax."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 318.0f; + LowTemperatureTransition = PT_WAX; + HighTemperature = 673.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + +} + +Element_MWAX::~Element_MWAX() {}
\ No newline at end of file diff --git a/src/simulation/elements/NBHL.cpp b/src/simulation/elements/NBHL.cpp new file mode 100644 index 0000000..2ccb864 --- /dev/null +++ b/src/simulation/elements/NBHL.cpp @@ -0,0 +1,60 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NBHL PT_NBHL 150 +Element_NBHL::Element_NBHL() +{ + Identifier = "DEFAULT_PT_NBHL"; + Name = "BHOL"; + Colour = PIXPACK(0x202020); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = R_TEMP+0.0f +273.15f; + HeatConduct = 186; + Description = "Black hole (Requires newtonian gravity)"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_NBHL::update; + +} + +//#TPT-Directive ElementHeader Element_NBHL static int update(UPDATE_FUNC_ARGS) +int Element_NBHL::update(UPDATE_FUNC_ARGS) + { + if (parts[i].tmp) + sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] += restrict_flt(0.001f*parts[i].tmp, 0.1f, 51.2f); + else + sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] += 0.1f; + return 0; +} + + +Element_NBHL::~Element_NBHL() {} diff --git a/src/simulation/elements/NBLE.cpp b/src/simulation/elements/NBLE.cpp new file mode 100644 index 0000000..3093d45 --- /dev/null +++ b/src/simulation/elements/NBLE.cpp @@ -0,0 +1,93 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NBLE PT_NBLE 52 +Element_NBLE::Element_NBLE() +{ + Identifier = "DEFAULT_PT_NBLE"; + Name = "NBLE"; + Colour = PIXPACK(0xEB4917); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 1.0f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.1f; + Gravity = 0.0f; + Diffusion = 0.75f; + HotAir = 0.001f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 1; + + Temperature = R_TEMP+2.0f +273.15f; + HeatConduct = 106; + Description = "Noble Gas. Diffuses. Conductive. Ionizes into plasma when introduced to electricity"; + + State = ST_GAS; + Properties = TYPE_GAS|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_NBLE::update; + +} + +//#TPT-Directive ElementHeader Element_NBLE static int update(UPDATE_FUNC_ARGS) +int Element_NBLE::update(UPDATE_FUNC_ARGS) + +{ + if (parts[i].temp > 5273.15 && sim->pv[y/CELL][x/CELL] > 100.0f) + { + parts[i].tmp = 1; + if (rand()%5 < 1) + { + int j; + float temp = parts[i].temp; + sim->create_part(i,x,y,PT_CO2); + + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); + if (j != -1) + parts[j].temp = temp; + if (!(rand()%25)) + { + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); + if (j != -1) + parts[j].temp = temp; + } + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); + if (j != -1) + { + parts[j].ctype = 0xF800000; + parts[j].temp = temp; + } + + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PLSM); + if (j != -1) + { + parts[j].temp = temp; + parts[j].tmp |= 4; + } + + parts[i].temp = temp+1750+rand()%500; + sim->pv[y/CELL][x/CELL] += 50; + } + } + return 0; +} + + +Element_NBLE::~Element_NBLE() {}
\ No newline at end of file diff --git a/src/simulation/elements/NEUT.cpp b/src/simulation/elements/NEUT.cpp new file mode 100644 index 0000000..4641370 --- /dev/null +++ b/src/simulation/elements/NEUT.cpp @@ -0,0 +1,207 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NEUT PT_NEUT 18 +Element_NEUT::Element_NEUT() +{ + Identifier = "DEFAULT_PT_NEUT"; + Name = "NEUT"; + Colour = PIXPACK(0x20E0FF); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + Loss = 1.00f; + Collision = -0.99f; + Gravity = 0.0f; + Diffusion = 0.01f; + HotAir = 0.002f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = -1; + + Temperature = R_TEMP+4.0f +273.15f; + HeatConduct = 60; + Description = "Neutrons. Interact with matter in odd ways."; + + State = ST_GAS; + Properties = TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_NEUT::update; + Graphics = &Element_NEUT::graphics; +} + +//#TPT-Directive ElementHeader Element_NEUT static int update(UPDATE_FUNC_ARGS) +int Element_NEUT::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, rt; + int pressureFactor = 3 + (int)sim->pv[y/CELL][x/CELL]; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_WATR || (r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW) + { + parts[i].vx *= 0.995; + parts[i].vy *= 0.995; + } + if ((r&0xFF)==PT_PLUT && pressureFactor>(rand()%1000)) + { + if (33>rand()%100) + { + sim->create_part(r>>8, x+rx, y+ry, rand()%3 ? PT_LAVA : PT_URAN); + parts[r>>8].temp = MAX_TEMP; + if (parts[r>>8].type==PT_LAVA) { + parts[r>>8].tmp = 100; + parts[r>>8].ctype = PT_PLUT; + } + } + else + { + sim->create_part(r>>8, x+rx, y+ry, PT_NEUT); + parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx; + parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy; + } + sim->pv[y/CELL][x/CELL] += 10.0f * CFDS; //Used to be 2, some people said nukes weren't powerful enough + Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); + } +#ifdef SDEUT + else if ((r&0xFF)==PT_DEUT && (pressureFactor+1+(parts[r>>8].life/100))>(rand()%1000)) + { + create_n_parts(sim, parts[r>>8].life, x+rx, y+ry, parts[i].vx, parts[i].vy, restrict_flt(parts[r>>8].temp + parts[r>>8].life*500, MIN_TEMP, MAX_TEMP), PT_NEUT); + sim->kill_part(r>>8); + } +#else + else if ((r&0xFF)==PT_DEUT && (pressureFactor+1)>(rand()%1000)) + { + create_part(r>>8, x+rx, y+ry, PT_NEUT); + parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx; + parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy; + if (parts[r>>8].life>0) + { + parts[r>>8].life --; + parts[r>>8].temp = restrict_flt(parts[r>>8].temp + parts[r>>8].life*17, MIN_TEMP, MAX_TEMP); + pv[y/CELL][x/CELL] += 6.0f * CFDS; + } + else + sim.kill_part(r>>8); + } +#endif + else if ((r&0xFF)==PT_GUNP && 15>(rand()%1000)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_DUST); + else if ((r&0xFF)==PT_DYST && 15>(rand()%1000)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_YEST); + else if ((r&0xFF)==PT_YEST) + sim->part_change_type(r>>8,x+rx,y+ry,PT_DYST); + else if ((r&0xFF)==PT_WATR && 15>(rand()%100)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_DSTW); + else if ((r&0xFF)==PT_PLEX && 15>(rand()%1000)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_GOO); + else if ((r&0xFF)==PT_NITR && 15>(rand()%1000)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_DESL); + else if ((r&0xFF)==PT_PLNT && 5>(rand()%100)) + sim->create_part(r>>8, x+rx, y+ry, PT_WOOD); + else if ((r&0xFF)==PT_DESL && 15>(rand()%1000)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_GAS); + else if ((r&0xFF)==PT_COAL && 5>(rand()%100)) + sim->create_part(r>>8, x+rx, y+ry, PT_WOOD); + else if ((r&0xFF)==PT_DUST && 5>(rand()%100)) + sim->part_change_type(r>>8, x+rx, y+ry, PT_FWRK); + else if ((r&0xFF)==PT_FWRK && 5>(rand()%100)) + parts[r>>8].ctype = PT_DUST; + else if ((r&0xFF)==PT_ACID && 5>(rand()%100)) + sim->create_part(r>>8, x+rx, y+ry, PT_ISOZ); + else if ((r&0xFF)==PT_TTAN && 5>(rand()%100)) + { + sim->kill_part(i); + return 1; + } + else if ((r&0xFF)==PT_EXOT && 5>(rand()%100)) + parts[r>>8].life = 1500; + /*if(parts[r>>8].type>1 && parts[r>>8].type!=PT_NEUT && parts[r>>8].type-1!=PT_NEUT && parts[r>>8].type-1!=PT_STKM && + (elements[parts[r>>8].type-1].menusection==SC_LIQUID|| + elements[parts[r>>8].type-1].menusection==SC_EXPLOSIVE|| + elements[parts[r>>8].type-1].menusection==SC_GAS|| + elements[parts[r>>8].type-1].menusection==SC_POWDERS) && 15>(rand()%1000)) + parts[r>>8].type--;*/ + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_NEUT static int graphics(GRAPHICS_FUNC_ARGS) +int Element_NEUT::graphics(GRAPHICS_FUNC_ARGS) + +{ + *firea = 120; + *firer = 10; + *fireg = 80; + *fireb = 120; + + *pixel_mode |= FIRE_ADD; + return 1; +} + +//#TPT-Directive ElementHeader Element_NEUT static int create_n_parts(Simulation * sim, int n, int x, int y, float vx, float vy, float temp, int t) +int Element_NEUT::create_n_parts(Simulation * sim, int n, int x, int y, float vx, float vy, float temp, int t)//testing a new deut create part +{ + int i, c; + n = (n/50); + if (n<1) { + n = 1; + } + if (n>340) { + n = 340; + } + if (x<0 || y<0 || x>=XRES || y>=YRES || t<0 || t>=PT_NUM || !sim->elements[t].Enabled) + return -1; + + for (c=0; c<n; c++) { + float r = (rand()%128+128)/127.0f; + float a = (rand()%360)*M_PI/180.0f; + if (sim->pfree == -1) + return -1; + i = sim->pfree; + sim->pfree = sim->parts[i].life; + if (i>sim->parts_lastActiveIndex) sim->parts_lastActiveIndex = i; + + sim->parts[i].x = (float)x; + sim->parts[i].y = (float)y; + sim->parts[i].type = t; + sim->parts[i].life = rand()%480+480; + sim->parts[i].vx = r*cosf(a); + sim->parts[i].vy = r*sinf(a); + sim->parts[i].ctype = 0; + sim->parts[i].temp = temp; + sim->parts[i].tmp = 0; + if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT && !sim->pmap[y][x]) + sim->pmap[y][x] = t|(i<<8); + else if ((t==PT_PHOT||t==PT_NEUT) && !sim->photons[y][x]) + sim->photons[y][x] = t|(i<<8); + + sim->pv[y/CELL][x/CELL] += 6.0f * CFDS; + } + return 0; +} + + +Element_NEUT::~Element_NEUT() {} diff --git a/src/simulation/elements/NICE.cpp b/src/simulation/elements/NICE.cpp new file mode 100644 index 0000000..8a6086e --- /dev/null +++ b/src/simulation/elements/NICE.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NICE PT_NICE 51 +Element_NICE::Element_NICE() +{ + Identifier = "DEFAULT_PT_NICE"; + Name = "NICE"; + Colour = PIXPACK(0xC0E0FF); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = -0.0005f* CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 100; + + Temperature = 35.0f; + HeatConduct = 46; + Description = "Nitrogen Ice."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 63.1f; + HighTemperatureTransition = PT_LNTG; + + Update = NULL; + +} + +Element_NICE::~Element_NICE() {}
\ No newline at end of file diff --git a/src/simulation/elements/NITR.cpp b/src/simulation/elements/NITR.cpp new file mode 100644 index 0000000..bf0feee --- /dev/null +++ b/src/simulation/elements/NITR.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NITR PT_NITR 8 +Element_NITR::Element_NITR() +{ + Identifier = "DEFAULT_PT_NITR"; + Name = "NITR"; + Colour = PIXPACK(0x20E010); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.5f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.92f; + Loss = 0.97f; + Collision = 0.0f; + Gravity = 0.2f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 1000; + Explosive = 2; + Meltable = 0; + Hardness = 3; + + Weight = 23; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 50; + Description = "Liquid. Pressure sensitive explosive."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 673.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + +} + +Element_NITR::~Element_NITR() {}
\ No newline at end of file diff --git a/src/simulation/elements/NONE.cpp b/src/simulation/elements/NONE.cpp new file mode 100644 index 0000000..95d9d3e --- /dev/null +++ b/src/simulation/elements/NONE.cpp @@ -0,0 +1,66 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NONE PT_NONE 0 +Element_NONE::Element_NONE() +{ + Identifier = "DEFAULT_PT_NONE"; + Name = ""; + Colour = PIXPACK(0x000000); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Erases particles."; + + State = ST_NONE; + Properties = 0; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + IconGenerator = &Element_NONE::iconGen; +} + +//#TPT-Directive ElementHeader Element_NONE static VideoBuffer * iconGen(int, int, int) +VideoBuffer * Element_NONE::iconGen(int wallID, int width, int height) +{ + VideoBuffer * newTexture = new VideoBuffer(width, height); + + for (int j=3; j<(width-4)/2; j++) + { + newTexture->SetPixel(j+6, j, 0xFF, 0, 0, 255); + newTexture->SetPixel(j+7, j, 0xFF, 0, 0, 255); + newTexture->SetPixel(-j+19, j, 0xFF, 0, 0, 255); + newTexture->SetPixel(-j+20, j, 0xFF, 0, 0, 255); + } + + return newTexture; +} + + +Element_NONE::~Element_NONE() {}
\ No newline at end of file diff --git a/src/simulation/elements/NSCN.cpp b/src/simulation/elements/NSCN.cpp new file mode 100644 index 0000000..c16e9c4 --- /dev/null +++ b/src/simulation/elements/NSCN.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NSCN PT_NSCN 36 +Element_NSCN::Element_NSCN() +{ + Identifier = "DEFAULT_PT_NSCN"; + Name = "NSCN"; + Colour = PIXPACK(0x505080); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "N-Type Silicon, Will not transfer current to P-Type Silicon."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1687.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_NSCN::~Element_NSCN() {}
\ No newline at end of file diff --git a/src/simulation/elements/NTCT.cpp b/src/simulation/elements/NTCT.cpp new file mode 100644 index 0000000..2241468 --- /dev/null +++ b/src/simulation/elements/NTCT.cpp @@ -0,0 +1,58 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NTCT PT_NTCT 43 +Element_NTCT::Element_NTCT() +{ + Identifier = "DEFAULT_PT_NTCT"; + Name = "NTCT"; + Colour = PIXPACK(0x505040); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Semi-conductor. Only conducts electricity when hot (More than 100C)"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1687.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_NTCT::update; + +} + +//#TPT-Directive ElementHeader Element_NTCT static int update(UPDATE_FUNC_ARGS) +int Element_NTCT::update(UPDATE_FUNC_ARGS) + { + if (parts[i].temp>295.0f) + parts[i].temp -= 2.5f; + return 0; +} + + +Element_NTCT::~Element_NTCT() {}
\ No newline at end of file diff --git a/src/simulation/elements/NWHL.cpp b/src/simulation/elements/NWHL.cpp new file mode 100644 index 0000000..7fcda4a --- /dev/null +++ b/src/simulation/elements/NWHL.cpp @@ -0,0 +1,57 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_NWHL PT_NWHL 151 +Element_NWHL::Element_NWHL() +{ + Identifier = "DEFAULT_PT_NWHL"; + Name = "WHOL"; + Colour = PIXPACK(0xFFFFFF); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = R_TEMP+0.0f +273.15f; + HeatConduct = 186; + Description = "White hole (Requires newtonian gravity)"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_NWHL::update; + +} + +//#TPT-Directive ElementHeader Element_NWHL static int update(UPDATE_FUNC_ARGS) +int Element_NWHL::update(UPDATE_FUNC_ARGS) + { + sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] -= 0.1f; + return 0; +} + + +Element_NWHL::~Element_NWHL() {}
\ No newline at end of file diff --git a/src/simulation/elements/O2.cpp b/src/simulation/elements/O2.cpp new file mode 100644 index 0000000..20bd902 --- /dev/null +++ b/src/simulation/elements/O2.cpp @@ -0,0 +1,104 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_O2 PT_O2 61 +Element_O2::Element_O2() +{ + Identifier = "DEFAULT_PT_O2"; + Name = "OXYG"; + Colour = PIXPACK(0x80A0FF); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 2.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.1f; + Gravity = 0.0f; + Diffusion = 3.0f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 1; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Gas. Ignites easily."; + + State = ST_GAS; + Properties = TYPE_GAS; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 90.0f; + LowTemperatureTransition = PT_LO2; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_O2::update; + +} + +//#TPT-Directive ElementHeader Element_O2 static int update(UPDATE_FUNC_ARGS) +int Element_O2::update(UPDATE_FUNC_ARGS) +{ + int r,rx,ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + + if ((r&0xFF)==PT_FIRE) + { + parts[r>>8].temp+=(rand()/(RAND_MAX/100)); + if(parts[r>>8].tmp&0x01) + parts[r>>8].temp=3473; + parts[r>>8].tmp |= 2; + } + if ((r&0xFF)==PT_FIRE || ((r&0xFF)==PT_PLSM && !(parts[r>>8].tmp&4))) + { + sim->create_part(i,x,y,PT_FIRE); + parts[i].temp+=(rand()/(RAND_MAX/100)); + parts[i].tmp |= 2; + } + + } + if (parts[i].temp > 9973.15 && sim->pv[y/CELL][x/CELL] > 250.0f && abs(sim->gravx[((y/CELL)*(XRES/CELL))+(x/CELL)]) + abs(sim->gravy[((y/CELL)*(XRES/CELL))+(x/CELL)]) > 20) + { + if (rand()%5 < 1) + { + int j; + sim->create_part(i,x,y,PT_BRMT); + + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); + if (j != -1) + parts[j].temp = 15000; + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); + if (j != -1) + parts[j].temp = 15000; + j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PLSM); + if (j != -1) + { + parts[j].temp = 15000; + parts[j].tmp |= 4; + } + + parts[i].temp = 15000; + sim->pv[y/CELL][x/CELL] += 300; + } + } + return 0; +} + + +Element_O2::~Element_O2() {} diff --git a/src/simulation/elements/OIL.cpp b/src/simulation/elements/OIL.cpp new file mode 100644 index 0000000..5dd7595 --- /dev/null +++ b/src/simulation/elements/OIL.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_OIL PT_OIL 3 +Element_OIL::Element_OIL() +{ + Identifier = "DEFAULT_PT_OIL"; + Name = "OIL"; + Colour = PIXPACK(0x404010); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 20; + Explosive = 0; + Meltable = 0; + Hardness = 5; + + Weight = 20; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 42; + Description = "Liquid. Flammable."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 333.0f; + HighTemperatureTransition = PT_GAS; + + Update = NULL; + +} + +Element_OIL::~Element_OIL() {}
\ No newline at end of file diff --git a/src/simulation/elements/PBCN.cpp b/src/simulation/elements/PBCN.cpp new file mode 100644 index 0000000..e3bc7ce --- /dev/null +++ b/src/simulation/elements/PBCN.cpp @@ -0,0 +1,164 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PBCN PT_PBCN 153 +Element_PBCN::Element_PBCN() +{ + Identifier = "DEFAULT_PT_PBCN"; + Name = "PBCN"; + Colour = PIXPACK(0x3B1D0A); + MenuVisible = 1; + MenuSection = SC_POWERED; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.97f; + Loss = 0.50f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 12; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Powered breakable clone"; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PBCN::update; + Graphics = &Element_PBCN::graphics; +} + +//#TPT-Directive ElementHeader Element_PBCN static int update(UPDATE_FUNC_ARGS) +int Element_PBCN::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].life>0 && parts[i].life!=10) + parts[i].life--; + if (!parts[i].tmp2 && sim->pv[y/CELL][x/CELL]>4.0f) + parts[i].tmp2 = rand()%40+80; + if (parts[i].tmp2) + { + float advection = 0.1f; + parts[i].vx += advection*sim->vx[y/CELL][x/CELL]; + parts[i].vy += advection*sim->vy[y/CELL][x/CELL]; + parts[i].tmp2--; + if(!parts[i].tmp2){ + sim->kill_part(i); + return 1; + } + } + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) + { + r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && + (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_SPRK && + (r&0xFF)!=PT_NSCN && (r&0xFF)!=PT_PSCN && + (r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 && + (r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM) + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE || (r&0xFF)==PT_LAVA) + parts[i].tmp = parts[r>>8].ctype; + } + } + if (parts[i].life==10) + { + + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_PBCN) + { + if (parts[r>>8].life<10&&parts[r>>8].life>0) + parts[i].life = 9; + else if (parts[r>>8].life==0) + parts[r>>8].life = 10; + } + } + } + if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && sim->elements[parts[i].ctype].Enabled && parts[i].life==10) { + if (parts[i].ctype==PT_PHOT) {//create photons a different way + for (rx=-1; rx<2; rx++) + { + for (ry = -1; ry < 2; ry++) + { + if (rx || ry) + { + int r = sim->create_part(-1, x + rx, y + ry, + parts[i].ctype); + if (r != -1) + { + parts[r].vx = rx * 3; + parts[r].vy = ry * 3; + if (r>i) + { + // Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced + parts[r].flags |= FLAG_SKIPMOVE; + } + } + } + } + } + } + else if (parts[i].ctype==PT_LIFE) {//create life a different way + for (rx=-1; rx<2; rx++) { + for (ry=-1; ry<2; ry++) { + sim->create_part(-1, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8)); + } + } + } + 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); + if (np>=0) + { + if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) + parts[np].ctype = parts[i].tmp; + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_PBCN static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PBCN::graphics(GRAPHICS_FUNC_ARGS) + +{ + int lifemod = ((cpart->life>10?10:cpart->life)*10); + *colr += lifemod; + *colg += lifemod/2; + return 0; +} + + +Element_PBCN::~Element_PBCN() {} diff --git a/src/simulation/elements/PCLN.cpp b/src/simulation/elements/PCLN.cpp new file mode 100644 index 0000000..7e6b3d7 --- /dev/null +++ b/src/simulation/elements/PCLN.cpp @@ -0,0 +1,154 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PCLN PT_PCLN 74 +Element_PCLN::Element_PCLN() +{ + Identifier = "DEFAULT_PT_PCLN"; + Name = "PCLN"; + Colour = PIXPACK(0x3B3B0A); + MenuVisible = 1; + MenuSection = SC_POWERED; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Solid. When activated, duplicates any particles it touches."; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PCLN::update; + Graphics = &Element_PCLN::graphics; +} + +//#TPT-Directive ElementHeader Element_PCLN static int update(UPDATE_FUNC_ARGS) +int Element_PCLN::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].life>0 && parts[i].life!=10) + parts[i].life--; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SPRK && parts[r>>8].life>0 && parts[r>>8].life<4) + { + if (parts[r>>8].ctype==PT_PSCN) + parts[i].life = 10; + else if (parts[r>>8].ctype==PT_NSCN) + parts[i].life = 9; + } + if ((r&0xFF)==PT_PCLN) + { + if (parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0) + parts[i].life = 9; + else if (parts[i].life==0&&parts[r>>8].life==10) + parts[i].life = 10; + } + } + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) + { + r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && + (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_SPRK && + (r&0xFF)!=PT_NSCN && (r&0xFF)!=PT_PSCN && + (r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 && + (r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM) + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE || (r&0xFF)==PT_LAVA) + parts[i].tmp = parts[r>>8].ctype; + } + } + if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && sim->elements[parts[i].ctype].Enabled && parts[i].life==10) { + if (parts[i].ctype==PT_PHOT) {//create photons a different way + for (rx=-1; rx<2; rx++) + { + for (ry = -1; ry < 2; ry++) + { + if (rx || ry) + { + int r = sim->create_part(-1, x + rx, y + ry, + parts[i].ctype); + if (r != -1) + { + parts[r].vx = rx * 3; + parts[r].vy = ry * 3; + if (r>i) + { + // Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced + parts[r].flags |= FLAG_SKIPMOVE; + } + } + } + } + } + } + else if (parts[i].ctype==PT_LIFE) {//create life a different way + for (rx=-1; rx<2; rx++) { + for (ry=-1; ry<2; ry++) { + sim->create_part(-1, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8)); + } + } + } + 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); + if (np>=0) + { + if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) + parts[np].ctype = parts[i].tmp; + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_PCLN static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PCLN::graphics(GRAPHICS_FUNC_ARGS) + +{ + int lifemod = ((cpart->life>10?10:cpart->life)*10); + *colr += lifemod; + *colg += lifemod; + return 0; +} + + +Element_PCLN::~Element_PCLN() {} diff --git a/src/simulation/elements/PHOT.cpp b/src/simulation/elements/PHOT.cpp new file mode 100644 index 0000000..ac8c5c8 --- /dev/null +++ b/src/simulation/elements/PHOT.cpp @@ -0,0 +1,141 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PHOT PT_PHOT 31 +Element_PHOT::Element_PHOT() +{ + Identifier = "DEFAULT_PT_PHOT"; + Name = "PHOT"; + Colour = PIXPACK(0xFFFFFF); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + Loss = 1.00f; + Collision = -0.99f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = -1; + + Temperature = R_TEMP+900.0f+273.15f; + HeatConduct = 251; + Description = "Photons. Travel in straight lines."; + + State = ST_GAS; + Properties = TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PHOT::update; + Graphics = &Element_PHOT::graphics; +} + +//#TPT-Directive ElementHeader Element_PHOT static int update(UPDATE_FUNC_ARGS) +int Element_PHOT::update(UPDATE_FUNC_ARGS) + { + int r, rt, rx, ry; + float rr, rrr; + parts[i].pavg[0] = x; + parts[i].pavg[1] = y; + if (!(parts[i].ctype&0x3FFFFFFF)) { + sim->kill_part(i); + return 1; + } + if (parts[i].temp > 506) + if (1>rand()%10) Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_ISOZ && 5>(rand()%2000)) + { + parts[i].vx *= 0.90; + parts[i].vy *= 0.90; + sim->create_part(r>>8, x+rx, y+ry, PT_PHOT); + rrr = (rand()%360)*3.14159f/180.0f; + rr = (rand()%128+128)/127.0f; + parts[r>>8].vx = rr*cosf(rrr); + parts[r>>8].vy = rr*sinf(rrr); + sim->pv[y/CELL][x/CELL] -= 15.0f * CFDS; + } + if ((r&0xFF)==PT_ISZS && 5>(rand()%2000)) + { + parts[i].vx *= 0.90; + parts[i].vy *= 0.90; + sim->create_part(r>>8, x+rx, y+ry, PT_PHOT); + rr = (rand()%228+128)/127.0f; + rrr = (rand()%360)*3.14159f/180.0f; + parts[r>>8].vx = rr*cosf(rrr); + parts[r>>8].vy = rr*sinf(rrr); + sim->pv[y/CELL][x/CELL] -= 15.0f * CFDS; + } + } + r = pmap[y][x]; + if((r&0xFF) == PT_QRTZ && r)// && parts[i].ctype==0x3FFFFFFF) + { + float a = (rand()%360)*3.14159f/180.0f; + parts[i].vx = 3.0f*cosf(a); + parts[i].vy = 3.0f*sinf(a); + if(parts[i].ctype == 0x3FFFFFFF) + parts[i].ctype = 0x1F<<(rand()%26); + parts[i].life++; //Delay death + } + //r = pmap[y][x]; + //rt = r&0xFF; + /*if (rt==PT_CLNE || rt==PT_PCLN || rt==PT_BCLN || rt==PT_PBCN) { + if (!parts[r>>8].ctype) + parts[r>>8].ctype = PT_PHOT; + }*/ + + return 0; +} + + + +//#TPT-Directive ElementHeader Element_PHOT static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PHOT::graphics(GRAPHICS_FUNC_ARGS) + +{ + int x = 0; + *colr = *colg = *colb = 0; + for (x=0; x<12; x++) { + *colr += (cpart->ctype >> (x+18)) & 1; + *colb += (cpart->ctype >> x) & 1; + } + for (x=0; x<12; x++) + *colg += (cpart->ctype >> (x+9)) & 1; + x = 624/(*colr+*colg+*colb+1); + *colr *= x; + *colg *= x; + *colb *= x; + + *firea = 100; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + + *pixel_mode &= ~PMODE_FLAT; + *pixel_mode |= FIRE_ADD | PMODE_ADD; + return 0; +} + + +Element_PHOT::~Element_PHOT() {}
\ No newline at end of file diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp new file mode 100644 index 0000000..3d631a1 --- /dev/null +++ b/src/simulation/elements/PIPE.cpp @@ -0,0 +1,516 @@ +#include "simulation/Elements.h" +//#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; +} + +#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}; + +//#TPT-Directive ElementHeader Element_PIPE static int update(UPDATE_FUNC_ARGS) +int Element_PIPE::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, np; + int rnd, rndstore; + 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<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r&0xFF) == PT_BRCK) + { + if (parts[i].tmp & PPIP_TMPFLAG_PAUSED) + parts[r>>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) + { + int lastneighbor = -1; + int neighborcount = 0; + int count = 0; + // make automatic pipe pattern + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + 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; + if ( parts[i].tmp&0x100)//is a single pixel pipe + { + 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 || (r&0xFF) == PT_PPIP)&&parts[r>>8].ctype!=(((parts[i].ctype-1)%3)+2)) + { + neighborcount ++; + lastneighbor = r>>8; + } + count++; + } + if(neighborcount == 1) + parts[lastneighbor].tmp |= 0x100; + } + else + { + if (parts[i].flags&PFLAG_NORMALSPEED)//skip particle push to prevent particle number being higher causing speed up + { + parts[i].flags &= ~PFLAG_NORMALSPEED; + } + else + { + pushParticle(sim, i,0,i); + } + + if (nt)//there is something besides PIPE around current particle + { + rndstore = rand(); + rnd = rndstore&7; + rndstore = rndstore>>3; + rx = pos_1_rx[rnd]; + ry = pos_1_ry[rnd]; + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) + { + 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 + { + np = sim->create_part(-1,x+rx,y+ry,parts[i].tmp&0xFF); + if (np!=-1) + { + transfer_pipe_to_part(parts+i, parts+np); + } + } + //try eating particle at entrance + else if ((parts[i].tmp&0xFF) == 0 && (sim->elements[r&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) + { + if ((r&0xFF)==PT_SOAP) + sim->detach(r>>8); + 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))) + { + // STOR stores properties in the same places as PIPE does + transfer_pipe_to_pipe(parts+(r>>8), parts+i); + } + } + } + } + } + else if (!parts[i].ctype && parts[i].life<=10) + { + if (parts[i].temp<272.15)//manual pipe colors + { + if (parts[i].temp>173.25&&parts[i].temp<273.15) + { + parts[i].ctype = 2; + parts[i].life = 0; + } + if (parts[i].temp>73.25&&parts[i].temp<=173.15) + { + parts[i].ctype = 3; + parts[i].life = 0; + } + if (parts[i].temp>=0&&parts[i].temp<=73.15) + { + parts[i].ctype = 4; + parts[i].life = 0; + } + } + else + { + // make a border + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + { + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + { + 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) + parts[i].ctype = 1; + } + } + else if (parts[i].ctype==1)//wait for empty space before starting to generate automatic pipe pattern + { + if (!parts[i].life) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + if (!pmap[y+ry][x+rx] && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_ALLOWAIR && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_WALL && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_WALLELEC && (sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_EWALL || sim->emap[(y+ry)/CELL][(x+rx)/CELL])) + parts[i].life=50; + } + } + else if (parts[i].life==5)//check for beginning of pipe single pixel + { + int issingle = 1; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && parts[i].ctype==1 && parts[i].life ) + issingle = 0; + } + if (issingle) + parts[i].tmp |= 0x100; + } + else if (parts[i].life==2) + { + parts[i].ctype = 2; + parts[i].life = 6; + } + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_PIPE static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS) + +{ + + if ((cpart->tmp&0xFF)>0 && (cpart->tmp&0xFF)<PT_NUM) + { + //Create a temp. particle and do a subcall. + Particle tpart; + int t; + memset(&tpart, 0, sizeof(Particle)); + tpart.type = cpart->tmp&0xFF; + tpart.temp = cpart->temp; + tpart.life = cpart->tmp2; + tpart.tmp = cpart->pavg[0]; + tpart.ctype = cpart->pavg[1]; + if (tpart.type == PT_PHOT && tpart.ctype == 0x40000000) + tpart.ctype = 0x3FFFFFFF; + t = tpart.type; + if (ren->graphicscache[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; + *firea = ren->graphicscache[t].firea; + *firer = ren->graphicscache[t].firer; + *fireg = ren->graphicscache[t].fireg; + *fireb = ren->graphicscache[t].fireb; + } + else + { + *colr = 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); + } + else + { + 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); + } + else + { + if (cpart->ctype==2) + { + *colr = 50; + *colg = 1; + *colb = 1; + } + else if (cpart->ctype==3) + { + *colr = 1; + *colg = 50; + *colb = 1; + } + else if (cpart->ctype==4) + { + *colr = 1; + *colg = 1; + *colb = 50; + } + else if (cpart->temp<272.15&&cpart->ctype!=1) + { + if (cpart->temp>173.25&&cpart->temp<273.15) + { + *colr = 50; + *colg = 1; + *colb = 1; + } + if (cpart->temp>73.25&&cpart->temp<=173.15) + { + *colr = 1; + *colg = 50; + *colb = 1; + } + if (cpart->temp>=0&&cpart->temp<=73.15) + { + *colr = 1; + *colg = 1; + *colb = 50; + } + } + } + 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; + + if (part->type != PT_PHOT && part->type != PT_ELEC && part->type != PT_NEUT) + { + part->vx = 0.0f; + part->vy = 0.0f; + } + else if (part->type == PT_PHOT && part->ctype == 0x40000000) + part->ctype = 0x3FFFFFFF; + 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) +{ + 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 + return; + x = (int)(sim->parts[i].x+0.5f); + y = (int)(sim->parts[i].y+0.5f); + if( !(sim->parts[i].tmp&0x200) ) + { + //normal random push + 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 3 times + { + rnd = rndstore&7; + rndstore = rndstore>>3; + rx = pos_1_rx[rnd]; + ry = pos_1_ry[rnd]; + if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) + { + r = sim->pmap[y+ry][x+rx]; + if (!r) + continue; + else if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && sim->parts[r>>8].ctype!=notctype && (sim->parts[r>>8].tmp&0xFF)==0) + { + 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 + 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 //predefined 1 pixel thick pipe movement + { + int coords = 7 - ((sim->parts[i].tmp>>10)&7); + r = sim->pmap[y+ pos_1_ry[coords]][x+ pos_1_rx[coords]]; + if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && sim->parts[r>>8].ctype!=notctype && (sim->parts[r>>8].tmp&0xFF)==0) + { + 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 + 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; +} + + +Element_PIPE::~Element_PIPE() {} diff --git a/src/simulation/elements/PLEX.cpp b/src/simulation/elements/PLEX.cpp new file mode 100644 index 0000000..c2f157b --- /dev/null +++ b/src/simulation/elements/PLEX.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PLEX PT_PLEX 11 +Element_PLEX::Element_PLEX() +{ + Identifier = "DEFAULT_PT_PLEX"; + Name = "C-4"; + Colour = PIXPACK(0xD080E0); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 1000; + Explosive = 2; + Meltable = 50; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 88; + Description = "Solid. Pressure sensitive explosive."; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 673.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + +} + +Element_PLEX::~Element_PLEX() {}
\ No newline at end of file diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp new file mode 100644 index 0000000..6e8202c --- /dev/null +++ b/src/simulation/elements/PLNT.cpp @@ -0,0 +1,126 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PLNT PT_PLNT 20 +Element_PLNT::Element_PLNT() +{ + Identifier = "DEFAULT_PT_PLNT"; + Name = "PLNT"; + Colour = PIXPACK(0x0CAC00); + 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 = 20; + Explosive = 0; + Meltable = 0; + Hardness = 10; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 65; + Description = "Plant, drinks water and grows."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_NEUTPENETRATE|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 573.0f; + HighTemperatureTransition = PT_FIRE; + + Update = &Element_PLNT::update; + Graphics = &Element_PLNT::graphics; +} + +//#TPT-Directive ElementHeader Element_PLNT static int update(UPDATE_FUNC_ARGS) +int Element_PLNT::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, np; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_WATR && 1>(rand()%250)) + { + np = sim->create_part(r>>8,x+rx,y+ry,PT_PLNT); + if (np<0) continue; + parts[np].life = 0; + } + else if ((r&0xFF)==PT_LAVA && 1>(rand()%250)) + { + sim->part_change_type(i,x,y,PT_FIRE); + parts[i].life = 4; + } + else if (((r&0xFF)==PT_SMKE || (r&0xFF)==PT_CO2) && (1>rand()%250)) + { + sim->kill_part(r>>8); + parts[i].life = rand()%60 + 60; + } + else if (surround_space && ((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; + if (x+rx+nnx>=0 && y+ry+nny>0 && x+rx+nnx<XRES && y+ry+nny<YRES && (nnx || nny)) + { + if (pmap[y+ry+nny][x+rx+nnx]) + continue; + np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_VINE); + if (np<0) continue; + parts[np].temp = parts[i].temp; + } + } + } + if (parts[i].life==2) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + sim->create_part(-1,x+rx,y+ry,PT_O2); + } + parts[i].life = 0; + } + if (parts[i].temp > 350 && parts[i].temp > parts[i].tmp2) + parts[i].tmp2 = (int)parts[i].temp; + return 0; +} + +//#TPT-Directive ElementHeader Element_PLNT static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PLNT::graphics(GRAPHICS_FUNC_ARGS) +{ + float maxtemp = std::max((float)cpart->tmp2, cpart->temp); + if (maxtemp > 300) + { + *colr += (int)restrict_flt((maxtemp-300)/5,0,58); + *colg -= (int)restrict_flt((maxtemp-300)/2,0,102); + *colb += (int)restrict_flt((maxtemp-300)/5,0,70); + } + if (maxtemp < 273) + { + *colg += (int)restrict_flt((273-maxtemp)/4,0,255); + *colb += (int)restrict_flt((273-maxtemp)/1.5,0,255); + } + return 0; +} + + +Element_PLNT::~Element_PLNT() {}
\ No newline at end of file diff --git a/src/simulation/elements/PLSM.cpp b/src/simulation/elements/PLSM.cpp new file mode 100644 index 0000000..4812b84 --- /dev/null +++ b/src/simulation/elements/PLSM.cpp @@ -0,0 +1,70 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PLSM PT_PLSM 49 +Element_PLSM::Element_PLSM() +{ + Identifier = "DEFAULT_PT_PLSM"; + Name = "PLSM"; + Colour = PIXPACK(0xBB99FF); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 0.9f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.97f; + Loss = 0.20f; + Collision = 0.0f; + Gravity = -0.1f; + Diffusion = 0.30f; + HotAir = 0.001f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 1; + + Temperature = 10000.0f +273.15f; + HeatConduct = 5; + Description = "Plasma, extremely hot."; + + State = ST_NONE; + Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_FIRE::update; + Graphics = &Element_PLSM::graphics; +} + +//#TPT-Directive ElementHeader Element_PLSM static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PLSM::graphics(GRAPHICS_FUNC_ARGS) + +{ + int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + *colr = (unsigned char)ren->plasma_data[caddress]; + *colg = (unsigned char)ren->plasma_data[caddress+1]; + *colb = (unsigned char)ren->plasma_data[caddress+2]; + + *firea = 255; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + + *pixel_mode = PMODE_GLOW | PMODE_ADD; //Clear default, don't draw pixel + *pixel_mode |= FIRE_ADD; + //Returning 0 means dynamic, do not cache + return 0; +} + + +Element_PLSM::~Element_PLSM() {}
\ No newline at end of file diff --git a/src/simulation/elements/PLUT.cpp b/src/simulation/elements/PLUT.cpp new file mode 100644 index 0000000..c9b759a --- /dev/null +++ b/src/simulation/elements/PLUT.cpp @@ -0,0 +1,60 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PLUT PT_PLUT 19 +Element_PLUT::Element_PLUT() +{ + Identifier = "DEFAULT_PT_PLUT"; + Name = "PLUT"; + Colour = PIXPACK(0x407020); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.99f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.4f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 90; + + Temperature = R_TEMP+4.0f +273.15f; + HeatConduct = 251; + Description = "Heavy particles. Fissile. Generates neutrons under pressure."; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_NEUTPENETRATE|PROP_RADIOACTIVE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PLUT::update; + +} + +//#TPT-Directive ElementHeader Element_PLUT static int update(UPDATE_FUNC_ARGS) +int Element_PLUT::update(UPDATE_FUNC_ARGS) + { + if (1>rand()%100 && ((int)(5.0f*sim->pv[y/CELL][x/CELL]))>(rand()%1000)) + { + sim->create_part(i, x, y, PT_NEUT); + } + return 0; +} + + +Element_PLUT::~Element_PLUT() {}
\ No newline at end of file diff --git a/src/simulation/elements/PPIP.cpp b/src/simulation/elements/PPIP.cpp new file mode 100644 index 0000000..03830a7 --- /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_POWERED; + 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 = IPH; + HighPressureTransition = NT; + 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<XRES-CELL) + { + if ((pmap[y][x2+1]&0xFF)!=PT_PPIP) + { + break; + } + x2++; + } + // fill span + for (x=x1; x<=x2; x++) + { + if (!(parts[pmap[y][x]>>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<YRES-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; + } + } + } while (coord_stack_size>0); + delete[] coord_stack; +} + +Element_PPIP::~Element_PPIP() {} diff --git a/src/simulation/elements/PQRT.cpp b/src/simulation/elements/PQRT.cpp new file mode 100644 index 0000000..8c51947 --- /dev/null +++ b/src/simulation/elements/PQRT.cpp @@ -0,0 +1,168 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PQRT PT_PQRT 133 +Element_PQRT::Element_PQRT() +{ + Identifier = "DEFAULT_PT_PQRT"; + Name = "PQRT"; + Colour = PIXPACK(0x88BBBB); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.27f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 90; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 3; + Description = "Broken quartz."; + + State = ST_SOLID; + Properties = TYPE_PART| PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 2573.15f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_PQRT::update; + Graphics = &Element_PQRT::graphics; +} + +//#TPT-Directive ElementHeader Element_PQRT static int update(UPDATE_FUNC_ARGS) +int Element_PQRT::update(UPDATE_FUNC_ARGS) + { + int r, tmp, trade, rx, ry, np, t; + t = parts[i].type; + if (t == PT_QRTZ) + { + parts[i].pavg[0] = parts[i].pavg[1]; + parts[i].pavg[1] = sim->pv[y/CELL][x/CELL]; + if (parts[i].pavg[1]-parts[i].pavg[0] > 0.05*(parts[i].temp/3) || parts[i].pavg[1]-parts[i].pavg[0] < -0.05*(parts[i].temp/3)) + { + sim->part_change_type(i,x,y,PT_PQRT); + } + } + // absorb SLTW + if (parts[i].ctype!=-1) + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + else if ((r&0xFF)==PT_SLTW && (1>rand()%2500)) + { + sim->kill_part(r>>8); + parts[i].ctype ++; + } + } + // grow if absorbed SLTW + if (parts[i].ctype>0) + { + for ( trade = 0; trade<5; trade ++) + { + rx = rand()%3-1; + ry = rand()%3-1; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r && parts[i].ctype!=0) + { + np = sim->create_part(-1,x+rx,y+ry,PT_QRTZ); + if (np>-1) + { + parts[np].tmp = parts[i].tmp; + parts[i].ctype--; + if (5>rand()%10) + { + parts[np].ctype=-1;//dead qrtz + } + else if (!parts[i].ctype && 1>rand()%15) + { + parts[i].ctype=-1; + } + + break; + } + } + } + } + } + // diffuse absorbed SLTW + if (parts[i].ctype>0) + { + for ( trade = 0; trade<9; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==t && (parts[i].ctype>parts[r>>8].ctype) && parts[r>>8].ctype>=0 )//diffusion + { + tmp = parts[i].ctype - parts[r>>8].ctype; + if (tmp ==1) + { + parts[r>>8].ctype ++; + parts[i].ctype --; + break; + } + if (tmp>0) + { + parts[r>>8].ctype += tmp/2; + parts[i].ctype -= tmp/2; + break; + } + } + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_PQRT static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PQRT::graphics(GRAPHICS_FUNC_ARGS) + //QRTZ and PQRT +{ + int t = cpart->type, z = cpart->tmp - 5;//speckles! + /*if (cpart->temp>(ptransitions[t].thv-800.0f))//hotglow for quartz + { + float frequency = 3.1415/(2*ptransitions[t].thv-(ptransitions[t].thv-800.0f)); + int q = (cpart->temp>ptransitions[t].thv)?ptransitions[t].thv-(ptransitions[t].thv-800.0f):cpart->temp-(ptransitions[t].thv-800.0f); + *colr += sin(frequency*q) * 226 + (z * 16); + *colg += sin(frequency*q*4.55 +3.14) * 34 + (z * 16); + *colb += sin(frequency*q*2.22 +3.14) * 64 + (z * 16); + } + else*/ + { + *colr += z * 16; + *colg += z * 16; + *colb += z * 16; + } + return 0; +} + + +Element_PQRT::~Element_PQRT() {}
\ No newline at end of file diff --git a/src/simulation/elements/PRTI.cpp b/src/simulation/elements/PRTI.cpp new file mode 100644 index 0000000..8383d90 --- /dev/null +++ b/src/simulation/elements/PRTI.cpp @@ -0,0 +1,140 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PRTI PT_PRTI 109 +Element_PRTI::Element_PRTI() +{ + Identifier = "DEFAULT_PT_PRTI"; + Name = "PRTI"; + Colour = PIXPACK(0xEB5917); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = -0.005f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Portal IN. Things go in here, now with channels (same as WIFI)"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PRTI::update; + Graphics = &Element_PRTI::graphics; +} + +//#TPT-Directive ElementHeader Element_PRTI static int update(UPDATE_FUNC_ARGS) +int Element_PRTI::update(UPDATE_FUNC_ARGS) + { + int r, nnx, rx, ry, fe = 0; + int count =0; + parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1); + if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1; + else if (parts[i].tmp<0) parts[i].tmp = 0; + for (count=0; count<8; count++) + { + rx = sim->portal_rx[count]; + ry = sim->portal_ry[count]; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + fe = 1; + if (!r || (r&0xFF)==PT_PRTI || (r&0xFF)==PT_PRTO || (!(sim->elements[r&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) && (r&0xFF)!=PT_SPRK)) + { + r = sim->photons[y+ry][x+rx]; + if (!r || (r&0xFF)==PT_PRTI || (r&0xFF)==PT_PRTO || (!(sim->elements[r&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) && (r&0xFF)!=PT_SPRK)) + continue; + } + + if ((r&0xFF)==PT_STKM || (r&0xFF)==PT_STKM2 || (r&0xFF)==PT_FIGH) + continue;// Handling these is a bit more complicated, and is done in STKM_interact() + + if ((r&0xFF) == PT_SOAP) + sim->detach(r>>8); + + for ( nnx=0; nnx<80; nnx++) + if (!sim->portalp[parts[i].tmp][count][nnx].type) + { + sim->portalp[parts[i].tmp][count][nnx] = parts[r>>8]; + if ((r&0xFF)==PT_SPRK) + sim->part_change_type(r>>8,x+rx,y+ry,parts[r>>8].ctype); + else + sim->kill_part(r>>8); + fe = 1; + break; + } + } + } + + + if (fe) { + int orbd[4] = {0, 0, 0, 0}; //Orbital distances + int orbl[4] = {0, 0, 0, 0}; //Orbital locations + if (!sim->parts[i].life) parts[i].life = rand()*rand()*rand(); + if (!sim->parts[i].ctype) parts[i].ctype = rand()*rand()*rand(); + sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); + for (r = 0; r < 4; r++) { + if (orbd[r]>1) { + orbd[r] -= 12; + if (orbd[r]<1) { + orbd[r] = (rand()%128)+128; + orbl[r] = rand()%255; + } else { + orbl[r] += 2; + orbl[r] = orbl[r]%255; + } + } else { + orbd[r] = (rand()%128)+128; + orbl[r] = rand()%255; + } + } + sim->orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); + } else { + parts[i].life = 0; + parts[i].ctype = 0; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_PRTI static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PRTI::graphics(GRAPHICS_FUNC_ARGS) + +{ + *firea = 8; + *firer = 255; + *fireg = 0; + *fireb = 0; + *pixel_mode |= EFFECT_DBGLINES; + *pixel_mode |= EFFECT_GRAVIN; + *pixel_mode &= ~PMODE; + *pixel_mode |= PMODE_ADD; + return 1; +} + + +Element_PRTI::~Element_PRTI() {} diff --git a/src/simulation/elements/PRTO.cpp b/src/simulation/elements/PRTO.cpp new file mode 100644 index 0000000..b4554ec --- /dev/null +++ b/src/simulation/elements/PRTO.cpp @@ -0,0 +1,177 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PRTO PT_PRTO 110 +Element_PRTO::Element_PRTO() +{ + Identifier = "DEFAULT_PT_PRTO"; + Name = "PRTO"; + Colour = PIXPACK(0x0020EB); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.005f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Portal OUT. Things come out here, now with channels (same as WIFI)"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PRTO::update; + Graphics = &Element_PRTO::graphics; +} + +//#TPT-Directive ElementHeader Element_PRTO static int update(UPDATE_FUNC_ARGS) +int Element_PRTO::update(UPDATE_FUNC_ARGS) + { + int r, nnx, rx, ry, np, fe = 0; + int count = 0; + parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1); + if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1; + else if (parts[i].tmp<0) parts[i].tmp = 0; + for (count=0; count<8; count++) + { + rx = sim->portal_rx[count]; + ry = sim->portal_ry[count]; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + fe = 1; + if (r) + continue; + if (!r) + { + for ( nnx =0 ; nnx<80; nnx++) + { + int randomness = (count + rand()%3-1 + 4)%8;//add -1,0,or 1 to count + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_SPRK)// TODO: make it look better, spark creation + { + sim->create_part(-1,x+1,y,PT_SPRK); + sim->create_part(-1,x+1,y+1,PT_SPRK); + sim->create_part(-1,x+1,y-1,PT_SPRK); + sim->create_part(-1,x,y-1,PT_SPRK); + sim->create_part(-1,x,y+1,PT_SPRK); + sim->create_part(-1,x-1,y+1,PT_SPRK); + sim->create_part(-1,x-1,y,PT_SPRK); + sim->create_part(-1,x-1,y-1,PT_SPRK); + sim->portalp[parts[i].tmp][randomness][nnx] = sim->emptyparticle; + break; + } + else if (sim->portalp[parts[i].tmp][randomness][nnx].type) + { + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM) + sim->player.spwn = 0; + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM2) + sim->player2.spwn = 0; + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_FIGH) + { + sim->fighcount--; + sim->fighters[(unsigned char)sim->portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 0; + } + np = sim->create_part(-1, x+rx, y+ry, sim->portalp[parts[i].tmp][randomness][nnx].type); + if (np<0) + { + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM) + sim->player.spwn = 1; + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM2) + sim->player2.spwn = 1; + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_FIGH) + { + sim->fighcount++; + sim->fighters[(unsigned char)sim->portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 1; + } + continue; + } + if (parts[np].type==PT_FIGH) + { + // Release the fighters[] element allocated by create_part, the one reserved when the fighter went into the portal will be used + sim->fighters[(unsigned char)parts[np].tmp].spwn = 0; + sim->fighters[(unsigned char)sim->portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 1; + } + parts[np] = sim->portalp[parts[i].tmp][randomness][nnx]; + parts[np].x = x+rx; + parts[np].y = y+ry; + sim->portalp[parts[i].tmp][randomness][nnx] = sim->emptyparticle; + break; + } + } + } + } + } + if (fe) { + int orbd[4] = {0, 0, 0, 0}; //Orbital distances + int orbl[4] = {0, 0, 0, 0}; //Orbital locations + if (!sim->parts[i].life) parts[i].life = rand()*rand()*rand(); + if (!sim->parts[i].ctype) parts[i].ctype = rand()*rand()*rand(); + sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); + for (r = 0; r < 4; r++) { + if (orbd[r]<254) { + orbd[r] += 16; + if (orbd[r]>254) { + orbd[r] = 0; + orbl[r] = rand()%255; + } + else + { + orbl[r] += 1; + orbl[r] = orbl[r]%255; + } + //orbl[r] += 1; + //orbl[r] = orbl[r]%255; + } else { + orbd[r] = 0; + orbl[r] = rand()%255; + } + } + sim->orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); + } else { + parts[i].life = 0; + parts[i].ctype = 0; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_PRTO static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PRTO::graphics(GRAPHICS_FUNC_ARGS) + +{ + *firea = 8; + *firer = 0; + *fireg = 0; + *fireb = 255; + *pixel_mode |= EFFECT_DBGLINES; + *pixel_mode |= EFFECT_GRAVOUT; + *pixel_mode &= ~PMODE; + *pixel_mode |= PMODE_ADD; + return 1; +} + + +Element_PRTO::~Element_PRTO() {}
\ No newline at end of file diff --git a/src/simulation/elements/PSCN.cpp b/src/simulation/elements/PSCN.cpp new file mode 100644 index 0000000..b074f7b --- /dev/null +++ b/src/simulation/elements/PSCN.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PSCN PT_PSCN 35 +Element_PSCN::Element_PSCN() +{ + Identifier = "DEFAULT_PT_PSCN"; + Name = "PSCN"; + Colour = PIXPACK(0x805050); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "P-Type Silicon, Will transfer current to any conductor."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1687.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_PSCN::~Element_PSCN() {}
\ No newline at end of file diff --git a/src/simulation/elements/PSTE.cpp b/src/simulation/elements/PSTE.cpp new file mode 100644 index 0000000..6efea51 --- /dev/null +++ b/src/simulation/elements/PSTE.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PSTE PT_PSTE 111 +Element_PSTE::Element_PSTE() +{ + Identifier = "DEFAULT_PT_PSTE"; + Name = "PSTE"; + Colour = PIXPACK(0xAA99AA); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 31; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Colloid, Hardens under pressure"; + + State = ST_LIQUID; + Properties = TYPE_LIQUID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 0.5f; + HighPressureTransition = PT_PSTS; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 747.0f; + HighTemperatureTransition = PT_BRCK; + + Update = NULL; + +} + +Element_PSTE::~Element_PSTE() {}
\ No newline at end of file diff --git a/src/simulation/elements/PSTS.cpp b/src/simulation/elements/PSTS.cpp new file mode 100644 index 0000000..5dd331c --- /dev/null +++ b/src/simulation/elements/PSTS.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PSTS PT_PSTS 112 +Element_PSTS::Element_PSTS() +{ + Identifier = "DEFAULT_PT_PSTS"; + Name = "PSTS"; + Colour = PIXPACK(0x776677); + MenuVisible = 0; + MenuSection = SC_CRACKER; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.00f; + 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 = 20; + + Weight = 100; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Solid form of PSTE, temporary"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = 0.5f; + LowPressureTransition = PT_PSTE; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_PSTS::~Element_PSTS() {}
\ No newline at end of file diff --git a/src/simulation/elements/PTCT.cpp b/src/simulation/elements/PTCT.cpp new file mode 100644 index 0000000..bda58c7 --- /dev/null +++ b/src/simulation/elements/PTCT.cpp @@ -0,0 +1,58 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PTCT PT_PTCT 46 +Element_PTCT::Element_PTCT() +{ + Identifier = "DEFAULT_PT_PTCT"; + Name = "PTCT"; + Colour = PIXPACK(0x405050); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Semi-conductor. Only conducts electricity when cold (Less than 100C)"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1414.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_PTCT::update; + +} + +//#TPT-Directive ElementHeader Element_PTCT static int update(UPDATE_FUNC_ARGS) +int Element_PTCT::update(UPDATE_FUNC_ARGS) + { + if (parts[i].temp>295.0f) + parts[i].temp -= 2.5f; + return 0; +} + + +Element_PTCT::~Element_PTCT() {}
\ No newline at end of file diff --git a/src/simulation/elements/PUMP.cpp b/src/simulation/elements/PUMP.cpp new file mode 100644 index 0000000..2d62799 --- /dev/null +++ b/src/simulation/elements/PUMP.cpp @@ -0,0 +1,98 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PUMP PT_PUMP 97 +Element_PUMP::Element_PUMP() +{ + Identifier = "DEFAULT_PT_PUMP"; + Name = "PUMP"; + Colour = PIXPACK(0x0A0A3B); + MenuVisible = 1; + MenuSection = SC_POWERED; + 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 = 10; + + Weight = 100; + + Temperature = 273.15f; + HeatConduct = 0; + Description = "Changes pressure to its temp when activated. (use HEAT/COOL)."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PUMP::update; + Graphics = &Element_PUMP::graphics; +} + +//#TPT-Directive ElementHeader Element_PUMP static int update(UPDATE_FUNC_ARGS) +int Element_PUMP::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].life>0 && parts[i].life!=10) + parts[i].life--; + if (parts[i].life==10) + { + if (parts[i].temp>=256.0+273.15) + parts[i].temp=256.0+273.15; + if (parts[i].temp<= -256.0+273.15) + parts[i].temp = -256.0+273.15; + + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if ((x+rx)-CELL>=0 && (y+ry)-CELL>0 && (x+rx)+CELL<XRES && (y+ry)+CELL<YRES && !(rx && ry)) + { + sim->pv[(y/CELL)+ry][(x/CELL)+rx] += 0.1f*((parts[i].temp-273.15)-sim->pv[(y/CELL)+ry][(x/CELL)+rx]); + } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_PUMP) + { + if (parts[r>>8].life<10&&parts[r>>8].life>0) + parts[i].life = 9; + else if (parts[r>>8].life==0) + parts[r>>8].life = 10; + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_PUMP static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PUMP::graphics(GRAPHICS_FUNC_ARGS) + +{ + int lifemod = ((cpart->life>10?10:cpart->life)*19); + *colb += lifemod; + return 0; +} + + +Element_PUMP::~Element_PUMP() {} diff --git a/src/simulation/elements/PVOD.cpp b/src/simulation/elements/PVOD.cpp new file mode 100644 index 0000000..267c7bd --- /dev/null +++ b/src/simulation/elements/PVOD.cpp @@ -0,0 +1,91 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_PVOD PT_PVOD 84 +Element_PVOD::Element_PVOD() +{ + Identifier = "DEFAULT_PT_PVOD"; + Name = "PVOD"; + Colour = PIXPACK(0x792020); + MenuVisible = 1; + MenuSection = SC_POWERED; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Solid. When activated, destroys entering particles"; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_PVOD::update; + Graphics = &Element_PVOD::graphics; +} + +//#TPT-Directive ElementHeader Element_PVOD static int update(UPDATE_FUNC_ARGS) +int Element_PVOD::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + if (parts[i].life>0 && parts[i].life!=10) + parts[i].life--; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SPRK && parts[r>>8].life>0 && parts[r>>8].life<4) + { + if (parts[r>>8].ctype==PT_PSCN) + parts[i].life = 10; + else if (parts[r>>8].ctype==PT_NSCN) + parts[i].life = 9; + } + if ((r&0xFF)==PT_PVOD) + { + if (parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0) + parts[i].life = 9; + else if (parts[i].life==0&&parts[r>>8].life==10) + parts[i].life = 10; + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_PVOD static int graphics(GRAPHICS_FUNC_ARGS) +int Element_PVOD::graphics(GRAPHICS_FUNC_ARGS) + +{ + int lifemod = ((cpart->life>10?10:cpart->life)*16); + *colr += lifemod; + return 0; +} + + +Element_PVOD::~Element_PVOD() {}
\ No newline at end of file diff --git a/src/simulation/elements/QRTZ.cpp b/src/simulation/elements/QRTZ.cpp new file mode 100644 index 0000000..20aa97d --- /dev/null +++ b/src/simulation/elements/QRTZ.cpp @@ -0,0 +1,168 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_QRTZ PT_QRTZ 132 +Element_QRTZ::Element_QRTZ() +{ + Identifier = "DEFAULT_PT_QRTZ"; + Name = "QRTZ"; + Colour = PIXPACK(0xAADDDD); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = R_TEMP+0.0f +273.15f; + HeatConduct = 3; + Description = "Quartz, breakable mineral. Conducts but becomes brittle at lower temperatures."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_HOT_GLOW|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 2573.15f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_QRTZ::update; + Graphics = &Element_QRTZ::graphics; +} + +//#TPT-Directive ElementHeader Element_QRTZ static int update(UPDATE_FUNC_ARGS) +int Element_QRTZ::update(UPDATE_FUNC_ARGS) + { + int r, tmp, trade, rx, ry, np, t; + t = parts[i].type; + if (t == PT_QRTZ) + { + parts[i].pavg[0] = parts[i].pavg[1]; + parts[i].pavg[1] = sim->pv[y/CELL][x/CELL]; + if (parts[i].pavg[1]-parts[i].pavg[0] > 0.05*(parts[i].temp/3) || parts[i].pavg[1]-parts[i].pavg[0] < -0.05*(parts[i].temp/3)) + { + sim->part_change_type(i,x,y,PT_PQRT); + } + } + // absorb SLTW + if (parts[i].ctype!=-1) + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + else if ((r&0xFF)==PT_SLTW && (1>rand()%2500)) + { + sim->kill_part(r>>8); + parts[i].ctype ++; + } + } + // grow if absorbed SLTW + if (parts[i].ctype>0) + { + for ( trade = 0; trade<5; trade ++) + { + rx = rand()%3-1; + ry = rand()%3-1; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r && parts[i].ctype!=0) + { + np = sim->create_part(-1,x+rx,y+ry,PT_QRTZ); + if (np>-1) + { + parts[np].tmp = parts[i].tmp; + parts[i].ctype--; + if (5>rand()%10) + { + parts[np].ctype=-1;//dead qrtz + } + else if (!parts[i].ctype && 1>rand()%15) + { + parts[i].ctype=-1; + } + + break; + } + } + } + } + } + // diffuse absorbed SLTW + if (parts[i].ctype>0) + { + for ( trade = 0; trade<9; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==t && (parts[i].ctype>parts[r>>8].ctype) && parts[r>>8].ctype>=0 )//diffusion + { + tmp = parts[i].ctype - parts[r>>8].ctype; + if (tmp ==1) + { + parts[r>>8].ctype ++; + parts[i].ctype --; + break; + } + if (tmp>0) + { + parts[r>>8].ctype += tmp/2; + parts[i].ctype -= tmp/2; + break; + } + } + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_QRTZ static int graphics(GRAPHICS_FUNC_ARGS) +int Element_QRTZ::graphics(GRAPHICS_FUNC_ARGS) + //QRTZ and PQRT +{ + int t = cpart->type, z = cpart->tmp - 5;//speckles! + /*if (cpart->temp>(ptransitions[t].thv-800.0f))//hotglow for quartz + { + float frequency = 3.1415/(2*ptransitions[t].thv-(ptransitions[t].thv-800.0f)); + int q = (cpart->temp>ptransitions[t].thv)?ptransitions[t].thv-(ptransitions[t].thv-800.0f):cpart->temp-(ptransitions[t].thv-800.0f); + *colr += sin(frequency*q) * 226 + (z * 16); + *colg += sin(frequency*q*4.55 +3.14) * 34 + (z * 16); + *colb += sin(frequency*q*2.22 +3.14) * 64 + (z * 16); + } + else*/ + { + *colr += z * 16; + *colg += z * 16; + *colb += z * 16; + } + return 0; +} + + +Element_QRTZ::~Element_QRTZ() {}
\ No newline at end of file diff --git a/src/simulation/elements/RBDM.cpp b/src/simulation/elements/RBDM.cpp new file mode 100644 index 0000000..90a332b --- /dev/null +++ b/src/simulation/elements/RBDM.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_RBDM PT_RBDM 41 +Element_RBDM::Element_RBDM() +{ + Identifier = "DEFAULT_PT_RBDM"; + Name = "RBDM"; + Colour = PIXPACK(0xCCCCCC); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 1000; + Explosive = 1; + Meltable = 50; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 240; + Description = "Rubidium, explosive, especially on contact with water, low melting point"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 312.0f; + HighTemperatureTransition = PT_LRBD; + + Update = NULL; + +} + +Element_RBDM::~Element_RBDM() {}
\ No newline at end of file diff --git a/src/simulation/elements/REPL.cpp b/src/simulation/elements/REPL.cpp new file mode 100644 index 0000000..b2deaee --- /dev/null +++ b/src/simulation/elements/REPL.cpp @@ -0,0 +1,73 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_REPL PT_REPL 160 +Element_REPL::Element_REPL() +{ + Identifier = "DEFAULT_PT_REPL"; + Name = "RPEL"; + Colour = PIXPACK(0x99CC00); + MenuVisible = 1; + MenuSection = SC_FORCE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = 20.0f+0.0f +273.15f; + HeatConduct = 0; + Description = "Repel or attract particles based on temp value."; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_REPL::update; + +} + +//#TPT-Directive ElementHeader Element_REPL static int update(UPDATE_FUNC_ARGS) +int Element_REPL::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, ri; + for(ri = 0; ri <= 10; ri++) + { + rx = (rand()%20)-10; + ry = (rand()%20)-10; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + r = sim->photons[y+ry][x+rx]; + + if (r && !(sim->elements[r&0xFF].Properties & TYPE_SOLID)){ + parts[r>>8].vx += isign(rx)*((parts[i].temp-273.15)/10.0f); + parts[r>>8].vy += isign(ry)*((parts[i].temp-273.15)/10.0f); + } + } + } + return 0; +} + + +Element_REPL::~Element_REPL() {}
\ No newline at end of file diff --git a/src/simulation/elements/RIME.cpp b/src/simulation/elements/RIME.cpp new file mode 100644 index 0000000..1ff2fad --- /dev/null +++ b/src/simulation/elements/RIME.cpp @@ -0,0 +1,77 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_RIME PT_RIME 91 +Element_RIME::Element_RIME() +{ + Identifier = "DEFAULT_PT_RIME"; + Name = "RIME"; + Colour = PIXPACK(0xCCCCCC); + MenuVisible = 1; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.00f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.00f; + Loss = 1.00f; + Collision = 0.00f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 100; + + Temperature = 243.15f; + HeatConduct = 100; + Description = "Not quite Ice"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 273.15f; + HighTemperatureTransition = PT_WATR; + + Update = &Element_RIME::update; + +} + +//#TPT-Directive ElementHeader Element_RIME static int update(UPDATE_FUNC_ARGS) +int Element_RIME::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + parts[i].vx = 0; + parts[i].vy = 0; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SPRK) + { + sim->part_change_type(i,x,y,PT_FOG); + parts[i].life = rand()%50 + 60; + } + else if ((r&0xFF)==PT_FOG&&parts[r>>8].life>0) + { + sim->part_change_type(i,x,y,PT_FOG); + parts[i].life = parts[r>>8].life; + } + } + return 0; +} + + +Element_RIME::~Element_RIME() {}
\ No newline at end of file diff --git a/src/simulation/elements/SALT.cpp b/src/simulation/elements/SALT.cpp new file mode 100644 index 0000000..a2e6274 --- /dev/null +++ b/src/simulation/elements/SALT.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SALT PT_SALT 26 +Element_SALT::Element_SALT() +{ + Identifier = "DEFAULT_PT_SALT"; + Name = "SALT"; + Colour = PIXPACK(0xFFFFFF); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 5; + Hardness = 1; + + Weight = 75; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 110; + Description = "Salt, dissolves in water."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1173.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_SALT::~Element_SALT() {}
\ No newline at end of file diff --git a/src/simulation/elements/SAND.cpp b/src/simulation/elements/SAND.cpp new file mode 100644 index 0000000..a1d9c00 --- /dev/null +++ b/src/simulation/elements/SAND.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SAND PT_SAND 44 +Element_SAND::Element_SAND() +{ + Identifier = "DEFAULT_PT_SAND"; + Name = "SAND"; + Colour = PIXPACK(0xFFD090); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 5; + Hardness = 1; + + Weight = 90; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 150; + Description = "Sand, Heavy particles. Meltable."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1973.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_SAND::~Element_SAND() {}
\ No newline at end of file diff --git a/src/simulation/elements/SHLD1.cpp b/src/simulation/elements/SHLD1.cpp new file mode 100644 index 0000000..605180a --- /dev/null +++ b/src/simulation/elements/SHLD1.cpp @@ -0,0 +1,88 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SHLD1 PT_SHLD1 119 +Element_SHLD1::Element_SHLD1() +{ + Identifier = "DEFAULT_PT_SHLD1"; + Name = "SHLD"; + Colour = PIXPACK(0xAAAAAA); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Shield, spark it to grow"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 7.0f; + HighPressureTransition = PT_NONE; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SHLD1::update; + +} + +//#TPT-Directive ElementHeader Element_SHLD1 static int update(UPDATE_FUNC_ARGS) +int Element_SHLD1::update(UPDATE_FUNC_ARGS) + { + int r, nnx, nny, rx, ry; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + else if ((r&0xFF)==PT_SPRK&&parts[i].life==0) + { + if (55>rand()%200&&parts[i].life==0) + { + sim->part_change_type(i,x,y,PT_SHLD2); + parts[i].life = 7; + } + for ( nnx=-1; nnx<2; nnx++) + for ( nny=-1; nny<2; nny++) + { + if (!pmap[y+ry+nny][x+rx+nnx]) + { + sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); + //parts[pmap[y+ny+nny][x+nx+nnx]>>8].life=7; + } + } + } + else if ((r&0xFF)==PT_SHLD3&&4>rand()%10) + { + sim->part_change_type(i,x,y,PT_SHLD2); + parts[i].life = 7; + } + } + return 0; +} + + + +Element_SHLD1::~Element_SHLD1() {}
\ No newline at end of file diff --git a/src/simulation/elements/SHLD2.cpp b/src/simulation/elements/SHLD2.cpp new file mode 100644 index 0000000..c00e4c9 --- /dev/null +++ b/src/simulation/elements/SHLD2.cpp @@ -0,0 +1,91 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SHLD2 PT_SHLD2 120 +Element_SHLD2::Element_SHLD2() +{ + Identifier = "DEFAULT_PT_SHLD2"; + Name = "SHD2"; + Colour = PIXPACK(0x777777); + MenuVisible = 0; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Shield lvl 2"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 15.0f; + HighPressureTransition = PT_NONE; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SHLD2::update; + +} + +//#TPT-Directive ElementHeader Element_SHLD2 static int update(UPDATE_FUNC_ARGS) +int Element_SHLD2::update(UPDATE_FUNC_ARGS) + { + int r, nnx, nny, rx, ry, np; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r && parts[i].life>0) + sim->create_part(-1,x+rx,y+ry,PT_SHLD1); + if (!r) + continue; + else if ((r&0xFF)==PT_SPRK&&parts[i].life==0) + { + if (25>rand()%200&&parts[i].life==0) + { + sim->part_change_type(i,x,y,PT_SHLD3); + parts[i].life = 7; + } + for ( nnx=-1; nnx<2; nnx++) + for ( nny=-1; nny<2; nny++) + { + if (!pmap[y+ry+nny][x+rx+nnx]) + { + np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); + if (np<0) continue; + parts[np].life=7; + } + } + } + else if ((r&0xFF)==PT_SHLD4&&4>rand()%10) + { + sim->part_change_type(i,x,y,PT_SHLD3); + parts[i].life = 7; + } + } + return 0; +} + + + +Element_SHLD2::~Element_SHLD2() {}
\ No newline at end of file diff --git a/src/simulation/elements/SHLD3.cpp b/src/simulation/elements/SHLD3.cpp new file mode 100644 index 0000000..633a8c4 --- /dev/null +++ b/src/simulation/elements/SHLD3.cpp @@ -0,0 +1,101 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SHLD3 PT_SHLD3 121 +Element_SHLD3::Element_SHLD3() +{ + Identifier = "DEFAULT_PT_SHLD3"; + Name = "SHD3"; + Colour = PIXPACK(0x444444); + MenuVisible = 0; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Shield lvl 3"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 25.0f; + HighPressureTransition = PT_NONE; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SHLD3::update; + +} + +//#TPT-Directive ElementHeader Element_SHLD3 static int update(UPDATE_FUNC_ARGS) +int Element_SHLD3::update(UPDATE_FUNC_ARGS) + { + int r, nnx, nny, rx, ry, np; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + { + if (1>rand()%2500) + { + np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); + if (np<0) continue; + parts[np].life=7; + sim->part_change_type(i,x,y,PT_SHLD2); + } + else + continue; + + } + if ((r&0xFF)==PT_SHLD1 && parts[i].life>3) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_SHLD2); + parts[r>>8].life=7; + } + else if ((r&0xFF)==PT_SPRK&&parts[i].life==0) + { + if (18>rand()%3000&&parts[i].life==0) + { + sim->part_change_type(i,x,y,PT_SHLD4); + parts[i].life = 7; + } + for ( nnx=-1; nnx<2; nnx++) + for ( nny=-1; nny<2; nny++) + { + + if (!pmap[y+ry+nny][x+rx+nnx]) + { + np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); + if (np<0) continue; + parts[np].life=7; + } + } + } + } + return 0; +} + + + +Element_SHLD3::~Element_SHLD3() {}
\ No newline at end of file diff --git a/src/simulation/elements/SHLD4.cpp b/src/simulation/elements/SHLD4.cpp new file mode 100644 index 0000000..95c8ae4 --- /dev/null +++ b/src/simulation/elements/SHLD4.cpp @@ -0,0 +1,92 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SHLD4 PT_SHLD4 122 +Element_SHLD4::Element_SHLD4() +{ + Identifier = "DEFAULT_PT_SHLD4"; + Name = "SHD4"; + Colour = PIXPACK(0x212121); + MenuVisible = 0; + MenuSection = SC_CRACKER2; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Shield lvl 4"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 40.0f; + HighPressureTransition = PT_NONE; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SHLD4::update; + +} + +//#TPT-Directive ElementHeader Element_SHLD4 static int update(UPDATE_FUNC_ARGS) +int Element_SHLD4::update(UPDATE_FUNC_ARGS) + { + int r, nnx, nny, rx, ry, np; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + { + if (1>rand()%5500) + { + np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); + if (np<0) continue; + parts[np].life=7; + sim->part_change_type(i,x,y,PT_SHLD2); + } + else + continue; + + } + if ((r&0xFF)==PT_SHLD2 && parts[i].life>3) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_SHLD3); + parts[r>>8].life = 7; + } + else if ((r&0xFF)==PT_SPRK&&parts[i].life==0) + for ( nnx=-1; nnx<2; nnx++) + for ( nny=-1; nny<2; nny++) + { + if (!pmap[y+ry+nny][x+rx+nnx]) + { + np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); + if (np<0) continue; + parts[np].life=7; + } + } + } + return 0; +} + + +Element_SHLD4::~Element_SHLD4() {}
\ No newline at end of file diff --git a/src/simulation/elements/SING.cpp b/src/simulation/elements/SING.cpp new file mode 100644 index 0000000..78641a8 --- /dev/null +++ b/src/simulation/elements/SING.cpp @@ -0,0 +1,155 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SING PT_SING 131 +Element_SING::Element_SING() +{ + Identifier = "DEFAULT_PT_SING"; + Name = "SING"; + Colour = PIXPACK(0x242424); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.36f * CFDS; + AirLoss = 0.96f; + Loss = 0.80f; + Collision = 0.1f; + Gravity = 0.12f; + Diffusion = 0.00f; + HotAir = -0.001f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 86; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Singularity"; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SING::update; + +} + +//#TPT-Directive ElementHeader Element_SING static int update(UPDATE_FUNC_ARGS) +int Element_SING::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, cry, crx, rad, nxi, nxj, nb, j, spawncount; + int singularity = -parts[i].life; + float angle, v; + + if (sim->pv[y/CELL][x/CELL]<singularity) + sim->pv[y/CELL][x/CELL] += 0.1f*(singularity-sim->pv[y/CELL][x/CELL]); + if (y+CELL<YRES && sim->pv[y/CELL+1][x/CELL]<singularity) + sim->pv[y/CELL+1][x/CELL] += 0.1f*(singularity-sim->pv[y/CELL+1][x/CELL]); + if (x+CELL<XRES) + { + sim->pv[y/CELL][x/CELL+1] += 0.1f*(singularity-sim->pv[y/CELL][x/CELL+1]); + if (y+CELL<YRES) + sim->pv[y/CELL+1][x/CELL+1] += 0.1f*(singularity-sim->pv[y/CELL+1][x/CELL+1]); + } + if (y-CELL>=0 && sim->pv[y/CELL-1][x/CELL]<singularity) + sim->pv[y/CELL-1][x/CELL] += 0.1f*(singularity-sim->pv[y/CELL-1][x/CELL]); + if (x-CELL>=0) + { + sim->pv[y/CELL][x/CELL-1] += 0.1f*(singularity-sim->pv[y/CELL][x/CELL-1]); + if (y-CELL>=0) + sim->pv[y/CELL-1][x/CELL-1] += 0.1f*(singularity-sim->pv[y/CELL-1][x/CELL-1]); + } + if (parts[i].life<1) { + //Pop! + for (rx=-1; rx<2; rx++) { + crx = (x/CELL)+rx; + for (ry=-1; ry<2; ry++) { + cry = (y/CELL)+ry; + if (cry >= 0 && crx >= 0 && crx < (XRES/CELL) && cry < (YRES/CELL)) { + sim->pv[cry][crx] += (float)parts[i].tmp; + } + } + } + spawncount = (parts[i].tmp>255)?255:parts[i].tmp; + if (spawncount>=1) + spawncount = spawncount/8; + spawncount = spawncount*spawncount*M_PI; + for (j=0;j<spawncount;j++) + { + switch(rand()%3) + { + case 0: + nb = sim->create_part(-3, x, y, PT_PHOT); + break; + case 1: + nb = sim->create_part(-3, x, y, PT_NEUT); + break; + case 2: + nb = sim->create_part(-3, x, y, PT_ELEC); + break; + } + if (nb!=-1) { + parts[nb].life = (rand()%300); + parts[nb].temp = MAX_TEMP/2; + angle = rand()*2.0f*M_PI/RAND_MAX; + v = (float)(rand())*5.0f/RAND_MAX; + parts[nb].vx = v*cosf(angle); + parts[nb].vy = v*sinf(angle); + } + else if (sim->pfree==-1) + break;//if we've run out of particles, stop trying to create them - saves a lot of lag on "sing bomb" saves + } + sim->kill_part(i); + return 1; + } + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_DMND&&33>=rand()/(RAND_MAX/100)+1) + { + if ((r&0xFF)==PT_SING && parts[r>>8].life >10) + { + if (parts[i].life+parts[r>>8].life > 255) + continue; + parts[i].life += parts[r>>8].life; + } + else + { + if (parts[i].life+3 > 255) + { + if (parts[r>>8].type!=PT_SING && 1>rand()%100) + { + int np; + np = sim->create_part(r>>8,x+rx,y+ry,PT_SING); + parts[np].life = rand()%50+60; + } + continue; + } + parts[i].life += 3; + parts[i].tmp++; + } + parts[i].temp = restrict_flt(parts[r>>8].temp+parts[i].temp, MIN_TEMP, MAX_TEMP); + sim->kill_part(r>>8); + } + } + return 0; +} + + +Element_SING::~Element_SING() {} diff --git a/src/simulation/elements/SLTW.cpp b/src/simulation/elements/SLTW.cpp new file mode 100644 index 0000000..c422a9f --- /dev/null +++ b/src/simulation/elements/SLTW.cpp @@ -0,0 +1,81 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SLTW PT_SLTW 27 +Element_SLTW::Element_SLTW() +{ + Identifier = "DEFAULT_PT_SLTW"; + Name = "SLTW"; + Colour = PIXPACK(0x4050F0); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 35; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 75; + Description = "Saltwater, conducts electricity, difficult to freeze."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 252.05f; + LowTemperatureTransition = PT_ICEI; + HighTemperature = 383.0f; + HighTemperatureTransition = ST; + + Update = &Element_SLTW::update; + +} + +//#TPT-Directive ElementHeader Element_SLTW static int update(UPDATE_FUNC_ARGS) +int Element_SLTW::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SALT && 1>(rand()%10000)) + sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW); + if ((r&0xFF)==PT_PLNT&&5>(rand()%1000)) + sim->kill_part(r>>8); + if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && !sim->legacy_enable && parts[i].temp>(273.15f+12.0f) && 1>(rand()%500)) + { + sim->part_change_type(i,x,y,PT_FIRE); + parts[i].life = 4; + } + if ((r&0xFF)==PT_FIRE){ + sim->kill_part(r>>8); + if(1>(rand()%150)){ + sim->kill_part(i); + return 1; + } + } + } + return 0; +} + + +Element_SLTW::~Element_SLTW() {} diff --git a/src/simulation/elements/SMKE.cpp b/src/simulation/elements/SMKE.cpp new file mode 100644 index 0000000..a00eca2 --- /dev/null +++ b/src/simulation/elements/SMKE.cpp @@ -0,0 +1,68 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SMKE PT_SMKE 57 +Element_SMKE::Element_SMKE() +{ + Identifier = "DEFAULT_PT_SMKE"; + Name = "SMKE"; + Colour = PIXPACK(0x222222); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 0.9f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.97f; + Loss = 0.20f; + Collision = 0.0f; + Gravity = -0.1f; + Diffusion = 0.00f; + HotAir = 0.001f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 1; + + Temperature = R_TEMP+320.0f+273.15f; + HeatConduct = 88; + Description = "Smoke"; + + State = ST_SOLID; + Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 625.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + Graphics = &Element_SMKE::graphics; +} + +//#TPT-Directive ElementHeader Element_SMKE static int graphics(GRAPHICS_FUNC_ARGS) +int Element_SMKE::graphics(GRAPHICS_FUNC_ARGS) + +{ + *colr = 55; + *colg = 55; + *colb = 55; + + *firea = 75; + *firer = 55; + *fireg = 55; + *fireb = 55; + + *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel + *pixel_mode |= FIRE_BLEND; + //Returning 1 means static, cache as we please + return 1; +} + +Element_SMKE::~Element_SMKE() {}
\ No newline at end of file diff --git a/src/simulation/elements/SNOW.cpp b/src/simulation/elements/SNOW.cpp new file mode 100644 index 0000000..4e592f7 --- /dev/null +++ b/src/simulation/elements/SNOW.cpp @@ -0,0 +1,74 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SNOW PT_SNOW 16 +Element_SNOW::Element_SNOW() +{ + Identifier = "DEFAULT_PT_SNOW"; + Name = "SNOW"; + Colour = PIXPACK(0xC0E0FF); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.96f; + Loss = 0.90f; + Collision = -0.1f; + Gravity = 0.05f; + Diffusion = 0.01f; + HotAir = -0.00005f* CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 50; + + Temperature = R_TEMP-30.0f+273.15f; + HeatConduct = 46; + Description = "Light particles."; + + State = ST_SOLID; + Properties = TYPE_PART|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 273.0f; + HighTemperatureTransition = ST; + + Update = &Element_SNOW::update; + +} + +//#TPT-Directive ElementHeader Element_SNOW static int update(UPDATE_FUNC_ARGS) +int Element_SNOW::update(UPDATE_FUNC_ARGS) + { //currently used for snow as well + int r, rx, ry; + if (parts[i].ctype==PT_FRZW)//get colder if it is from FRZW + { + parts[i].temp = restrict_flt(parts[i].temp-1.0f, MIN_TEMP, MAX_TEMP); + } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_SALT || (r&0xFF)==PT_SLTW) && 1>(rand()%1000)) + { + sim->part_change_type(i,x,y,PT_SLTW); + sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW); + } + } + return 0; +} + + +Element_SNOW::~Element_SNOW() {} diff --git a/src/simulation/elements/SOAP.cpp b/src/simulation/elements/SOAP.cpp new file mode 100644 index 0000000..1d3a55b --- /dev/null +++ b/src/simulation/elements/SOAP.cpp @@ -0,0 +1,291 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SOAP PT_SOAP 149 +Element_SOAP::Element_SOAP() +{ + Identifier = "DEFAULT_PT_SOAP"; + Name = "SOAP"; + Colour = PIXPACK(0xF5F5DC); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 35; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Soap. Creates bubbles."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_NEUTPENETRATE|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITL; + HighTemperatureTransition = NT; + + Update = &Element_SOAP::update; + Graphics = &Element_SOAP::graphics; + +} + +//#TPT-Directive ElementHeader Element_SOAP static void attach(Particle * parts, int i1, int i2) +void Element_SOAP::attach(Particle * parts, int i1, int i2) +{ + if (!(parts[i2].ctype&4)) + { + parts[i1].ctype |= 2; + parts[i1].tmp = i2; + + parts[i2].ctype |= 4; + parts[i2].tmp2 = i1; + } + else if (!(parts[i2].ctype&2)) + { + parts[i1].ctype |= 4; + parts[i1].tmp2= i2; + + parts[i2].ctype |= 2; + parts[i2].tmp = i1; + } +} + +//#TPT-Directive ElementHeader Element_SOAP static int update(UPDATE_FUNC_ARGS) +int Element_SOAP::update(UPDATE_FUNC_ARGS) + +{ + int r, rx, ry, nr, ng, nb, na; + float tr, tg, tb, ta; + float blend; + + //0x01 - bubble on/off + //0x02 - first mate yes/no + //0x04 - "back" mate yes/no + + if (parts[i].ctype&1) + { + if (parts[i].temp>0) + { + if (parts[i].life<=0) + { + if ((parts[i].ctype&6) != 6 && (parts[i].ctype&6)) + { + int target; + + target = i; + + while((parts[target].ctype&6) != 6 && (parts[target].ctype&6)) + { + if (parts[target].ctype&2) + { + target = parts[target].tmp; + sim->detach(target); + } + + if (parts[target].ctype&4) + { + target = parts[target].tmp2; + sim->detach(target); + } + } + } + + if ((parts[i].ctype&6) != 6) + parts[i].ctype = 0; + + if ((parts[i].ctype&6) == 6 && (parts[parts[i].tmp].ctype&6) == 6 && parts[parts[i].tmp].tmp == i) + sim->detach(i); + } + + parts[i].vy -= 0.1f; + + parts[i].vy *= 0.5f; + parts[i].vx *= 0.5f; + } + + if(!(parts[i].ctype&2)) + { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + + if ((parts[r>>8].type == PT_SOAP) && (parts[r>>8].ctype&1) && !(parts[r>>8].ctype&4)) + Element_SOAP::attach(parts, i, r>>8); + } + } + else + { + if (parts[i].life<=0) + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r && !sim->bmap[(y+ry)/CELL][(x+rx)/CELL]) + continue; + + if (parts[i].temp>0) + { + if (sim->bmap[(y+ry)/CELL][(x+rx)/CELL] + || (r && sim->elements[r&0xFF].State != ST_GAS + && (r&0xFF) != PT_SOAP && (r&0xFF) != PT_GLAS)) + { + sim->detach(i); + continue; + } + } + + if ((r&0xFF) == PT_SOAP && parts[r>>8].ctype == 1) + { + int buf; + + buf = parts[i].tmp; + + parts[i].tmp = r>>8; + parts[buf].tmp2 = r>>8; + parts[r>>8].tmp2 = i; + parts[r>>8].tmp = buf; + parts[r>>8].ctype = 7; + } + + if ((r&0xFF) == PT_SOAP && parts[r>>8].ctype == 7 && parts[i].tmp != r>>8 && parts[i].tmp2 != r>>8) + { + int buf; + + parts[parts[i].tmp].tmp2 = parts[r>>8].tmp2; + parts[parts[r>>8].tmp2].tmp = parts[i].tmp; + parts[r>>8].tmp2 = i; + parts[i].tmp = r>>8; + } + } + } + + if(parts[i].ctype&2) + { + float d, dx, dy; + + dx = parts[i].x - parts[parts[i].tmp].x; + dy = parts[i].y - parts[parts[i].tmp].y; + + d = 9/(pow(dx, 2)+pow(dy, 2)+9)-0.5; + + parts[parts[i].tmp].vx -= dx*d; + parts[parts[i].tmp].vy -= dy*d; + + parts[i].vx += dx*d; + parts[i].vy += dy*d; + + if ((parts[parts[i].tmp].ctype&2) && (parts[parts[i].tmp].ctype&1) + && (parts[parts[parts[i].tmp].tmp].ctype&2) && (parts[parts[parts[i].tmp].tmp].ctype&1)) + { + int ii; + + ii = parts[parts[parts[i].tmp].tmp].tmp; + + dx = parts[ii].x - parts[parts[i].tmp].x; + dy = parts[ii].y - parts[parts[i].tmp].y; + + d = 81/(pow(dx, 2)+pow(dy, 2)+81)-0.5; + + parts[parts[i].tmp].vx -= dx*d*0.5f; + parts[parts[i].tmp].vy -= dy*d*0.5f; + + parts[ii].vx += dx*d*0.5f; + parts[ii].vy += dy*d*0.5f; + } + } + } + else + { + if (sim->pv[y/CELL][x/CELL]>0.5f || sim->pv[y/CELL][x/CELL]<(-0.5f)) + { + parts[i].ctype = 1; + parts[i].life = 10; + } + + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + + if ((r&0xFF) == PT_OIL) + { + float ax, ay; + + parts[i].vy -= 0.1f; + + parts[i].vy *= 0.5f; + parts[i].vx *= 0.5f; + + ax = (parts[i].vx + parts[r>>8].vx)/2; + ay = (parts[i].vy + parts[r>>8].vy)/2; + + parts[i].vx = ax; + parts[i].vy = ay; + parts[r>>8].vx = ax; + parts[r>>8].vy = ay; + } + } + } + + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_SOAP) + { + blend = 0.85f; + tr = (parts[r>>8].dcolour>>16)&0xFF; + tg = (parts[r>>8].dcolour>>8)&0xFF; + tb = (parts[r>>8].dcolour)&0xFF; + ta = (parts[r>>8].dcolour>>24)&0xFF; + + nr = (tr*blend); + ng = (tg*blend); + nb = (tb*blend); + na = (ta*blend); + + parts[r>>8].dcolour = nr<<16 | ng<<8 | nb | na<<24; + } + } + + return 0; +} + +//#TPT-Directive ElementHeader Element_SOAP static int graphics(GRAPHICS_FUNC_ARGS) +int Element_SOAP::graphics(GRAPHICS_FUNC_ARGS) + +{ + *pixel_mode |= EFFECT_LINES; + return 1; +} + +Element_SOAP::~Element_SOAP() {} diff --git a/src/simulation/elements/SPAWN.cpp b/src/simulation/elements/SPAWN.cpp new file mode 100644 index 0000000..85295f2 --- /dev/null +++ b/src/simulation/elements/SPAWN.cpp @@ -0,0 +1,60 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SPAWN PT_SPAWN 118 +Element_SPAWN::Element_SPAWN() +{ + Identifier = "DEFAULT_PT_SPAWN"; + Name = "SPWN"; + Colour = PIXPACK(0xAAAAAA); + MenuVisible = 0; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "STKM spawn point"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SPAWN::update; + +} + +//#TPT-Directive ElementHeader Element_SPAWN static int update(UPDATE_FUNC_ARGS) +int Element_SPAWN::update(UPDATE_FUNC_ARGS) + { + if (!sim->player.spwn) + sim->create_part(-1, x, y, PT_STKM); + + return 0; +} + + + +Element_SPAWN::~Element_SPAWN() {}
\ No newline at end of file diff --git a/src/simulation/elements/SPAWN2.cpp b/src/simulation/elements/SPAWN2.cpp new file mode 100644 index 0000000..3cc048b --- /dev/null +++ b/src/simulation/elements/SPAWN2.cpp @@ -0,0 +1,60 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SPAWN2 PT_SPAWN2 117 +Element_SPAWN2::Element_SPAWN2() +{ + Identifier = "DEFAULT_PT_SPAWN2"; + Name = "SPWN2"; + Colour = PIXPACK(0xAAAAAA); + MenuVisible = 0; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "STK2 spawn point"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SPAWN2::update; + +} + +//#TPT-Directive ElementHeader Element_SPAWN2 static int update(UPDATE_FUNC_ARGS) +int Element_SPAWN2::update(UPDATE_FUNC_ARGS) + { + if (!sim->player2.spwn) + sim->create_part(-1, x, y, PT_STKM2); + + return 0; +} + + + +Element_SPAWN2::~Element_SPAWN2() {}
\ No newline at end of file diff --git a/src/simulation/elements/SPNG.cpp b/src/simulation/elements/SPNG.cpp new file mode 100644 index 0000000..95dd12f --- /dev/null +++ b/src/simulation/elements/SPNG.cpp @@ -0,0 +1,198 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SPNG PT_SPNG 90 +Element_SPNG::Element_SPNG() +{ + Identifier = "DEFAULT_PT_SPNG"; + Name = "SPNG"; + Colour = PIXPACK(0xFFBE30); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.00f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.00f; + Loss = 0.00f; + Collision = 0.00f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 20; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "A sponge, absorbs water."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 2730.0f; + HighTemperatureTransition = PT_FIRE; + + Update = &Element_SPNG::update; + Graphics = &Element_SPNG::graphics; +} + +//#TPT-Directive ElementHeader Element_SPNG static int update(UPDATE_FUNC_ARGS) +int Element_SPNG::update(UPDATE_FUNC_ARGS) + { + int r, trade, rx, ry, tmp, np; + int limit = 50; + if (parts[i].life<limit && sim->pv[y/CELL][x/CELL]<=3&&sim->pv[y/CELL][x/CELL]>=-3&&parts[i].temp<=374.0f) + { + int absorbChanceDenom = parts[i].life*10000/limit + 500; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_FRZW) && parts[i].life<limit && 500>rand()%absorbChanceDenom) + { + parts[i].life++; + sim->kill_part(r>>8); + } + if ((r&0xFF)==PT_SLTW && parts[i].life<limit && 50>rand()%absorbChanceDenom) + { + parts[i].life++; + if (rand()%4) + sim->kill_part(r>>8); + else + sim->part_change_type(r>>8, x+rx, y+ry, PT_SALT); + } + if ((r&0xFF)==PT_CBNW && parts[i].life<limit && 100>rand()%absorbChanceDenom) + { + parts[i].life++; + sim->part_change_type(r>>8, x+rx, y+ry, PT_CO2); + } + if ((r&0xFF)==PT_PSTE && parts[i].life<limit && 20>rand()%absorbChanceDenom) + { + parts[i].life++; + sim->create_part(r>>8, x+rx, y+ry, PT_CLST); + } + } + } + else + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((!r)&&parts[i].life>=1)//if nothing then create water + { + np = sim->create_part(-1,x+rx,y+ry,PT_WATR); + if (np>-1) parts[i].life--; + } + } + for ( trade = 0; trade<9; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SPNG&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion + { + tmp = parts[i].life - parts[r>>8].life; + if (tmp ==1) + { + parts[r>>8].life ++; + parts[i].life --; + trade = 9; + } + else if (tmp>0) + { + parts[r>>8].life += tmp/2; + parts[i].life -= tmp/2; + trade = 9; + } + } + } + } + tmp = 0; + if (parts[i].life>0) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_FIRE) + { + tmp++; + if (parts[r>>8].life>60) + parts[r>>8].life -= parts[r>>8].life/60; + else if (parts[r>>8].life>2) + parts[r>>8].life--; + } + } + } + if (tmp && parts[i].life>3) + parts[i].life -= parts[i].life/3; + if (tmp>1) + tmp = tmp/2; + if (tmp || parts[i].temp>=374) + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((!r)&&parts[i].life>=1)//if nothing then create steam + { + np = sim->create_part(-1,x+rx,y+ry,PT_WTRV); + if (np>-1) + { + parts[np].temp = parts[i].temp; + tmp--; + parts[i].life--; + parts[i].temp -= 20.0f; + } + } + } + if (tmp>0) + { + if (parts[i].life>tmp) + parts[i].life -= tmp; + else + parts[i].life = 0; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_SPNG static int graphics(GRAPHICS_FUNC_ARGS) +int Element_SPNG::graphics(GRAPHICS_FUNC_ARGS) + +{ + *colr -= cpart->life*15; + *colg -= cpart->life*15; + *colb -= cpart->life*15; + if (*colr<=50) + *colr = 50; + if (*colg<=50) + *colg = 50; + if (*colb<=20) + *colb = 20; + return 0; +} + + +Element_SPNG::~Element_SPNG() {} diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp new file mode 100644 index 0000000..09638ff --- /dev/null +++ b/src/simulation/elements/SPRK.cpp @@ -0,0 +1,290 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SPRK PT_SPRK 15 +Element_SPRK::Element_SPRK() +{ + Identifier = "DEFAULT_PT_SPRK"; + Name = "SPRK"; + Colour = PIXPACK(0xFFFF80); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.001f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Electricity. Conducted by metal and water."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SPRK::update; + Graphics = &Element_SPRK::graphics; +} + +//#TPT-Directive ElementHeader Element_SPRK static int update(UPDATE_FUNC_ARGS) +int Element_SPRK::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, rt, conduct_sprk, nearp, pavg, ct = parts[i].ctype; + Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); + + if (parts[i].life<=0) + { + if (ct==PT_WATR||ct==PT_SLTW||ct==PT_PSCN||ct==PT_NSCN||ct==PT_ETRD||ct==PT_INWR) + parts[i].temp = R_TEMP + 273.15f; + if (ct<=0 || ct>=PT_NUM || !sim->elements[parts[i].ctype].Enabled) + ct = PT_METL; + sim->part_change_type(i,x,y,ct); + parts[i].ctype = PT_NONE; + parts[i].life = 4; + if (ct == PT_WATR) + parts[i].life = 64; + if (ct == PT_SLTW) + parts[i].life = 54; + if (ct == PT_SWCH) + parts[i].life = 14; + return 0; + } + if (ct==PT_SPRK) + { + sim->kill_part(i); + return 1; + } + else if (ct==PT_NTCT || ct==PT_PTCT) + { + Element_NTCT::update(UPDATE_FUNC_SUBCALL_ARGS); + } + else if (ct==PT_ETRD&&parts[i].life==1) + { + nearp = sim->nearest_part(i, PT_ETRD, -1); + if (nearp!=-1 && sim->parts_avg(i, nearp, PT_INSL)!=PT_INSL) + { + sim->CreateLine(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), 0, 0, PT_PLSM, 0); + sim->part_change_type(i,x,y,ct); + ct = parts[i].ctype = PT_NONE; + parts[i].life = 20; + sim->part_change_type(nearp,(int)(parts[nearp].x+0.5f),(int)(parts[nearp].y+0.5f),PT_SPRK); + parts[nearp].life = 9; + parts[nearp].ctype = PT_ETRD; + } + } + else if (ct==PT_NBLE&&parts[i].life<=1&&parts[i].tmp!=1) + { + parts[i].life = rand()%150+50; + sim->part_change_type(i,x,y,PT_PLSM); + parts[i].ctype = PT_NBLE; + if (parts[i].temp > 5273.15) + parts[i].tmp |= 4; + parts[i].temp = 3500; + sim->pv[y/CELL][x/CELL] += 1; + } + else if (ct==PT_TESC) // tesla coil code + { + if (parts[i].tmp>300) + parts[i].tmp=300; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (r) + continue; + if (parts[i].tmp>4 && rand()%(parts[i].tmp*parts[i].tmp/20+6)==0) + { + int p = sim->create_part(-1, x+rx*2, y+ry*2, PT_LIGH); + if (p!=-1) + { + parts[p].life=rand()%(2+parts[i].tmp/15)+parts[i].tmp/7; + if (parts[i].life>60) + parts[i].life=60; + parts[p].temp=parts[p].life*parts[i].tmp/2.5; + parts[p].tmp2=1; + parts[p].tmp=atan2(-ry, (float)rx)/M_PI*360; + parts[i].temp-=parts[i].tmp*2+parts[i].temp/5; // slight self-cooling + if (fabs(sim->pv[y/CELL][x/CELL])!=0.0f) + { + if (fabs(sim->pv[y/CELL][x/CELL])<=0.5f) + sim->pv[y/CELL][x/CELL]=0; + else + sim->pv[y/CELL][x/CELL]-=(sim->pv[y/CELL][x/CELL]>0)?0.5:-0.5; + } + } + } + } + } + else if (ct==PT_IRON) { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF) == PT_DSTW && 30>(rand()/(RAND_MAX/1000))) || + ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/1000))) || + ((r&0xFF) == PT_WATR && 30>(rand()/(RAND_MAX/1000)))) + { + if (rand()<RAND_MAX/3) + sim->part_change_type(r>>8,x+rx,y+ry,PT_O2); + else + sim->part_change_type(r>>8,x+rx,y+ry,PT_H2); + } + } + } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + rt = parts[r>>8].type; + conduct_sprk = 1; + + + pavg = sim->parts_avg(r>>8, i,PT_INSL); + if ((rt==PT_SWCH||(rt==PT_SPRK&&parts[r>>8].ctype==PT_SWCH)) && pavg!=PT_INSL && parts[i].life<4) // make sparked SWCH turn off correctly + { + if (rt==PT_SWCH&&ct==PT_PSCN&&parts[r>>8].life<10) { + parts[r>>8].life = 10; + } + if (ct==PT_NSCN) { + sim->part_change_type(r>>8,x+rx,y+ry,PT_SWCH); + parts[r>>8].ctype = PT_NONE; + parts[r>>8].life = 9; + } + } + else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_PUMP||rt==PT_GPMP||rt==PT_HSWC||rt==PT_PBCN) && parts[i].life<4) // PROP_PTOGGLE, Maybe? We seem to use 2 different methods for handling actived elements, this one seems better. Yes, use this one for new elements, PCLN is different for compatibility with existing saves + { + if (ct==PT_PSCN) parts[r>>8].life = 10; + else if (ct==PT_NSCN && parts[r>>8].life>=10) parts[r>>8].life = 9; + } + else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_LCRY&&abs(rx)<2&&abs(ry)<2) && parts[i].life<4) + { + if (ct==PT_PSCN && parts[r>>8].tmp == 0) parts[r>>8].tmp = 2; + 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 + + if (pavg == PT_INSL) conduct_sprk = 0; + if (!((sim->elements[rt].Properties&PROP_CONDUCTS)||rt==PT_INST||rt==PT_QRTZ)) conduct_sprk = 0; + if (abs(rx)+abs(ry)>=4 &&ct!=PT_SWCH&&rt!=PT_SWCH) + conduct_sprk = 0; + + + if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))) && pavg!=PT_INSL && parts[i].life<4) + { + parts[r>>8].temp = 473.0f; + if (rt==PT_NTCT||rt==PT_PTCT) + conduct_sprk = 0; + } + if (ct==PT_NTCT && !(rt==PT_PSCN || rt==PT_NTCT || (rt==PT_NSCN&&parts[i].temp>373.0f))) + conduct_sprk = 0; + if (ct==PT_PTCT && !(rt==PT_PSCN || rt==PT_PTCT || (rt==PT_NSCN&&parts[i].temp<373.0f))) + conduct_sprk = 0; + if (ct==PT_INWR && !(rt==PT_NSCN || rt==PT_INWR || rt==PT_PSCN)) + conduct_sprk = 0; + if (ct==PT_NSCN && rt==PT_PSCN) + conduct_sprk = 0; + if (ct==PT_ETRD && !(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN)) + conduct_sprk = 0; + if (ct==PT_INST&&rt!=PT_NSCN) conduct_sprk = 0; + if (ct==PT_SWCH && (rt==PT_PSCN||rt==PT_NSCN||rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR)) + conduct_sprk = 0; + if (rt==PT_QRTZ && !((ct==PT_NSCN||ct==PT_METL||ct==PT_PSCN||ct==PT_QRTZ) && (parts[r>>8].temp<173.15||sim->pv[(y+ry)/CELL][(x+rx)/CELL]>8))) + conduct_sprk = 0; + if (rt==PT_NTCT && !(ct==PT_NSCN || ct==PT_NTCT || (ct==PT_PSCN&&parts[r>>8].temp>373.0f))) + conduct_sprk = 0; + if (rt==PT_PTCT && !(ct==PT_NSCN || ct==PT_PTCT || (ct==PT_PSCN&&parts[r>>8].temp<373.0f))) + conduct_sprk = 0; + if (rt==PT_INWR && !(ct==PT_NSCN || ct==PT_INWR || ct==PT_PSCN)) + conduct_sprk = 0; + if (rt==PT_INST&&ct!=PT_PSCN) + conduct_sprk = 0; + if (rt == PT_NBLE && parts[r>>8].tmp == 1) + conduct_sprk = 0; + + if (conduct_sprk) { + if (rt==PT_WATR||rt==PT_SLTW) { + if (parts[r>>8].life==0 && parts[i].life<3) + { + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + if (rt==PT_WATR) parts[r>>8].life = 6; + else parts[r>>8].life = 5; + parts[r>>8].ctype = rt; + } + } + else if (rt==PT_INST) { + if (parts[r>>8].life==0 && parts[i].life<4) + { + sim->FloodINST(x+rx,y+ry,PT_SPRK,PT_INST);//spark the wire + } + } + else if (parts[r>>8].life==0 && parts[i].life<4) { + parts[r>>8].life = 4; + parts[r>>8].ctype = rt; + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + if (parts[r>>8].temp+10.0f<673.0f&&!sim->legacy_enable&&(rt==PT_METL||rt==PT_BMTL||rt==PT_BRMT||rt==PT_PSCN||rt==PT_NSCN||rt==PT_ETRD||rt==PT_NBLE||rt==PT_IRON)) + parts[r>>8].temp = parts[r>>8].temp+10.0f; + } + else if (ct==PT_ETRD && parts[i].life==5) + { + sim->part_change_type(i,x,y,ct); + parts[i].ctype = PT_NONE; + parts[i].life = 20; + parts[r>>8].life = 4; + parts[r>>8].ctype = rt; + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + } + } + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_SPRK static int graphics(GRAPHICS_FUNC_ARGS) +int Element_SPRK::graphics(GRAPHICS_FUNC_ARGS) + +{ + *firea = 80; + *firer = 170; + *fireg = 200; + *fireb = 220; + *pixel_mode |= FIRE_ADD; + return 1; +} + + +Element_SPRK::~Element_SPRK() {}
\ No newline at end of file diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp new file mode 100644 index 0000000..081720e --- /dev/null +++ b/src/simulation/elements/STKM.cpp @@ -0,0 +1,557 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_STKM PT_STKM 55 +Element_STKM::Element_STKM() +{ + Identifier = "DEFAULT_PT_STKM"; + Name = "STKM"; + Colour = PIXPACK(0xFFE0A0); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.5f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.2f; + Loss = 1.0f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.0f; + HotAir = 0.00f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 50; + + Temperature = R_TEMP+14.6f+273.15f; + HeatConduct = 0; + Description = "Stickman. Don't kill him!"; + + State = ST_NONE; + Properties = 0; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 620.0f; + HighTemperatureTransition = PT_FIRE; + + Update = &Element_STKM::update; + Graphics = &Element_STKM::graphics; +} + +//#TPT-Directive ElementHeader Element_STKM static int update(UPDATE_FUNC_ARGS) +int Element_STKM::update(UPDATE_FUNC_ARGS) + +{ + run_stickman(&sim->player, UPDATE_FUNC_SUBCALL_ARGS); + return 0; +} + + + +//#TPT-Directive ElementHeader Element_STKM static int graphics(GRAPHICS_FUNC_ARGS) +int Element_STKM::graphics(GRAPHICS_FUNC_ARGS) +{ + *colr = *colg = *colb = *cola = 0; + *pixel_mode = PSPEC_STICKMAN; + return 1; +} + +#define INBOND(x, y) ((x)>=0 && (y)>=0 && (x)<XRES && (y)<YRES) + +//#TPT-Directive ElementHeader Element_STKM static int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) +int Element_STKM::run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) { + int r, rx, ry; + int t = parts[i].type; + float pp, d; + float dt = 0.9;///(FPSB*FPSB); //Delta time in square + float gvx, gvy; + float gx, gy, dl, dr; + + if ((parts[i].ctype>0 && parts[i].ctype<PT_NUM && sim->elements[parts[i].ctype].Enabled && sim->elements[parts[i].ctype].Falldown>0) || parts[i].ctype==SPC_AIR || parts[i].ctype == PT_NEUT || parts[i].ctype == PT_PHOT || parts[i].ctype == PT_LIGH) + playerp->elem = parts[i].ctype; + playerp->frames++; + + //Temperature handling + if (parts[i].temp<243) + parts[i].life -= 1; + if ((parts[i].temp<309.6f) && (parts[i].temp>=243)) + parts[i].temp += 1; + + //Death + if (parts[i].life<1 || (sim->pv[y/CELL][x/CELL]>=4.5f && playerp->elem != SPC_AIR) ) //If his HP is less that 0 or there is very big wind... + { + for (r=-2; r<=1; r++) + { + sim->create_part(-1, x+r, y-2, playerp->elem); + sim->create_part(-1, x+r+1, y+2, playerp->elem); + sim->create_part(-1, x-2, y+r+1, playerp->elem); + sim->create_part(-1, x+2, y+r, playerp->elem); + } + sim->kill_part(i); //Kill him + return 1; + } + + //Follow gravity + gvx = gvy = 0.0f; + switch (sim->gravityMode) + { + default: + case 0: + gvy = 1; + break; + case 1: + gvy = gvx = 0.0f; + break; + case 2: + { + float gravd; + gravd = 0.01f - hypotf((parts[i].x - XCNTR), (parts[i].y - YCNTR)); + gvx = ((float)(parts[i].x - XCNTR) / gravd); + gvy = ((float)(parts[i].y - YCNTR) / gravd); + } + break; + } + + gvx += sim->gravx[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)]; + gvy += sim->gravy[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)]; + + parts[i].vx -= gvx*dt; //Head up! + parts[i].vy -= gvy*dt; + + //Verlet integration + pp = 2*playerp->legs[0]-playerp->legs[2]+playerp->accs[0]*dt*dt; + playerp->legs[2] = playerp->legs[0]; + playerp->legs[0] = pp; + pp = 2*playerp->legs[1]-playerp->legs[3]+playerp->accs[1]*dt*dt; + playerp->legs[3] = playerp->legs[1]; + playerp->legs[1] = pp; + + pp = 2*playerp->legs[4]-playerp->legs[6]+(playerp->accs[2]+gvx)*dt*dt; + playerp->legs[6] = playerp->legs[4]; + playerp->legs[4] = pp; + pp = 2*playerp->legs[5]-playerp->legs[7]+(playerp->accs[3]+gvy)*dt*dt; + playerp->legs[7] = playerp->legs[5]; + playerp->legs[5] = pp; + + pp = 2*playerp->legs[8]-playerp->legs[10]+playerp->accs[4]*dt*dt; + playerp->legs[10] = playerp->legs[8]; + playerp->legs[8] = pp; + pp = 2*playerp->legs[9]-playerp->legs[11]+playerp->accs[5]*dt*dt; + playerp->legs[11] = playerp->legs[9]; + playerp->legs[9] = pp; + + pp = 2*playerp->legs[12]-playerp->legs[14]+(playerp->accs[6]+gvx)*dt*dt; + playerp->legs[14] = playerp->legs[12]; + playerp->legs[12] = pp; + pp = 2*playerp->legs[13]-playerp->legs[15]+(playerp->accs[7]+gvy)*dt*dt; + playerp->legs[15] = playerp->legs[13]; + playerp->legs[13] = pp; + + //Setting accseleration to 0 + playerp->accs[0] = 0; + playerp->accs[1] = 0; + + playerp->accs[2] = 0; + playerp->accs[3] = 0; + + playerp->accs[4] = 0; + playerp->accs[5] = 0; + + playerp->accs[6] = 0; + playerp->accs[7] = 0; + + gx = (playerp->legs[4] + playerp->legs[12])/2 - gvy; + gy = (playerp->legs[5] + playerp->legs[13])/2 + gvx; + dl = pow(gx - playerp->legs[4], 2) + pow(gy - playerp->legs[5], 2); + dr = pow(gx - playerp->legs[12], 2) + pow(gy - playerp->legs[13], 2); + + //Go left + if (((int)(playerp->comm)&0x01) == 0x01) + { + if (dl>dr) + { + if (!sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) + { + playerp->accs[2] = -3*gvy-3*gvx; + playerp->accs[3] = 3*gvx-3*gvy; + playerp->accs[0] = -gvy; + playerp->accs[1] = gvx; + } + } + else + { + if (!sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL)) + { + playerp->accs[6] = -3*gvy-3*gvx; + playerp->accs[7] = 3*gvx-3*gvy; + playerp->accs[0] = -gvy; + playerp->accs[1] = gvx; + } + } + } + + //Go right + if (((int)(playerp->comm)&0x02) == 0x02) + { + if (dl<dr) + { + if (!sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) + { + playerp->accs[2] = 3*gvy-3*gvx; + playerp->accs[3] = -3*gvx-3*gvy; + playerp->accs[0] = gvy; + playerp->accs[1] = -gvx; + } + } + else + { + if (!sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL)) + { + playerp->accs[6] = 3*gvy-3*gvx; + playerp->accs[7] = -3*gvx-3*gvy; + playerp->accs[0] = gvy; + playerp->accs[1] = -gvx; + } + } + } + + //Jump + if (((int)(playerp->comm)&0x04) == 0x04 && + (!sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL) || !sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL))) + { + parts[i].vy -= 4*gvy; + playerp->accs[3] -= gvy; + playerp->accs[7] -= gvy; + } + + //Charge detector wall if foot inside + if (sim->bmap[(int)(playerp->legs[5]+0.5)/CELL][(int)(playerp->legs[4]+0.5)/CELL]==WL_DETECT) + sim->set_emap((int)playerp->legs[4]/CELL, (int)playerp->legs[5]/CELL); + if (sim->bmap[(int)(playerp->legs[13]+0.5)/CELL][(int)(playerp->legs[12]+0.5)/CELL]==WL_DETECT) + sim->set_emap((int)(playerp->legs[12]+0.5)/CELL, (int)(playerp->legs[13]+0.5)/CELL); + + //Searching for particles near head + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + r = sim->photons[y+ry][x+rx]; + + if (!r && !sim->bmap[(y+ry)/CELL][(x+rx)/CELL]) + continue; + + if (sim->elements[r&0xFF].Falldown!=0 || sim->elements[r&0xFF].State == ST_GAS + || sim->elements[r&0xFF].Properties&TYPE_GAS + || sim->elements[r&0xFF].Properties&TYPE_LIQUID + || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) + { + playerp->elem = r&0xFF; //Current element + } + if ((r&0xFF)==PT_TESC || (r&0xFF)==PT_LIGH) + playerp->elem = PT_LIGH; + if ((r&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP + { + if (parts[i].life<=95) + parts[i].life += 5; + else + parts[i].life = 100; + sim->kill_part(r>>8); + } + + if ((r&0xFF) == PT_NEUT) + { + if (parts[i].life<=100) parts[i].life -= (102-parts[i].life)/2; + else parts[i].life *= 0.9f; + sim->kill_part(r>>8); + } + if (sim->bmap[(ry+y)/CELL][(rx+x)/CELL]==WL_FAN) + playerp->elem = SPC_AIR; + if ((r&0xFF)==PT_PRTI) + Element_STKM::STKM_interact(sim, playerp, i, rx, ry); + if (!parts[i].type)//STKM_interact may kill STKM + return 1; + } + + //Head position + rx = x + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01); + ry = y - 3*(playerp->pcomm == 0); + + //Spawn + if (((int)(playerp->comm)&0x08) == 0x08) + { + ry -= 2*(rand()%2)+1; + r = pmap[ry][rx]; + if (sim->elements[r&0xFF].State == ST_SOLID) + { + sim->create_part(-1, rx, ry, PT_SPRK); + playerp->frames = 0; + } + else + { + int np = -1; + if (playerp->elem == SPC_AIR) + sim->CreateParts(rx + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0); + else if (playerp->elem==PT_LIGH && playerp->frames<30)//limit lightning creation rate + np = -1; + else + np = sim->create_part(-1, rx, ry, playerp->elem); + if ( (np < NPART) && np>=0) + { + if (playerp->elem == PT_PHOT) + { + int random = abs(rand()%3-1)*3; + if (random==0) + { + sim->kill_part(np); + } + else + { + parts[np].vy = 0; + if (((int)playerp->pcomm)&(0x01|0x02)) + parts[np].vx = (((((int)playerp->pcomm)&0x02) == 0x02) - (((int)(playerp->pcomm)&0x01) == 0x01))*random; + else + parts[np].vx = random; + } + } + else if (playerp->elem == PT_LIGH) + { + float angle; + int power = 100; + if (gvx!=0 || gvy!=0) + angle = atan2(gvx, gvy)*180.0f/M_PI; + else + angle = rand()%360; + if (((int)playerp->comm)&0x01) + angle += 180; + if (angle>360) + angle-=360; + if (angle<0) + angle+=360; + parts[np].tmp = angle; + parts[np].life=rand()%(2+power/15)+power/7; + parts[np].temp=parts[np].life*power/2.5; + parts[np].tmp2=1; + } + else if (playerp->elem != SPC_AIR) + { + parts[np].vx -= -gvy*(5*((((int)playerp->pcomm)&0x02) == 0x02) - 5*(((int)(playerp->pcomm)&0x01) == 0x01)); + parts[np].vy -= gvx*(5*((((int)playerp->pcomm)&0x02) == 0x02) - 5*(((int)(playerp->pcomm)&0x01) == 0x01)); + parts[i].vx -= (sim->elements[(int)playerp->elem].Weight*parts[np].vx)/1000; + } + playerp->frames = 0; + } + + } + } + + //Simulation of joints + d = 25/(pow((playerp->legs[0]-playerp->legs[4]), 2) + pow((playerp->legs[1]-playerp->legs[5]), 2)+25) - 0.5; //Fast distance + playerp->legs[4] -= (playerp->legs[0]-playerp->legs[4])*d; + playerp->legs[5] -= (playerp->legs[1]-playerp->legs[5])*d; + playerp->legs[0] += (playerp->legs[0]-playerp->legs[4])*d; + playerp->legs[1] += (playerp->legs[1]-playerp->legs[5])*d; + + d = 25/(pow((playerp->legs[8]-playerp->legs[12]), 2) + pow((playerp->legs[9]-playerp->legs[13]), 2)+25) - 0.5; + playerp->legs[12] -= (playerp->legs[8]-playerp->legs[12])*d; + playerp->legs[13] -= (playerp->legs[9]-playerp->legs[13])*d; + playerp->legs[8] += (playerp->legs[8]-playerp->legs[12])*d; + playerp->legs[9] += (playerp->legs[9]-playerp->legs[13])*d; + + d = 36/(pow((playerp->legs[0]-parts[i].x), 2) + pow((playerp->legs[1]-parts[i].y), 2)+36) - 0.5; + parts[i].vx -= (playerp->legs[0]-parts[i].x)*d; + parts[i].vy -= (playerp->legs[1]-parts[i].y)*d; + playerp->legs[0] += (playerp->legs[0]-parts[i].x)*d; + playerp->legs[1] += (playerp->legs[1]-parts[i].y)*d; + + d = 36/(pow((playerp->legs[8]-parts[i].x), 2) + pow((playerp->legs[9]-parts[i].y), 2)+36) - 0.5; + parts[i].vx -= (playerp->legs[8]-parts[i].x)*d; + parts[i].vy -= (playerp->legs[9]-parts[i].y)*d; + playerp->legs[8] += (playerp->legs[8]-parts[i].x)*d; + playerp->legs[9] += (playerp->legs[9]-parts[i].y)*d; + + if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) + { + playerp->legs[4] = playerp->legs[6]; + playerp->legs[5] = playerp->legs[7]; + } + + if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL)) + { + playerp->legs[12] = playerp->legs[14]; + playerp->legs[13] = playerp->legs[15]; + } + + //This makes stick man "pop" from obstacles + if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) + { + float t; + t = playerp->legs[4]; playerp->legs[4] = playerp->legs[6]; playerp->legs[6] = t; + t = playerp->legs[5]; playerp->legs[5] = playerp->legs[7]; playerp->legs[7] = t; + } + + if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL)) + { + float t; + t = playerp->legs[12]; playerp->legs[12] = playerp->legs[14]; playerp->legs[14] = t; + t = playerp->legs[13]; playerp->legs[13] = playerp->legs[15]; playerp->legs[15] = t; + } + + //Keeping legs distance + if ((pow((playerp->legs[4] - playerp->legs[12]), 2) + pow((playerp->legs[5]-playerp->legs[13]), 2))<16) + { + float tvx, tvy; + tvx = -gvy; + tvy = gvx; + + if (tvx || tvy) + { + playerp->accs[2] -= 0.2*tvx/hypot(tvx, tvy); + playerp->accs[3] -= 0.2*tvy/hypot(tvx, tvy); + + playerp->accs[6] += 0.2*tvx/hypot(tvx, tvy); + playerp->accs[7] += 0.2*tvy/hypot(tvx, tvy); + } + } + + if ((pow((playerp->legs[0] - playerp->legs[8]), 2) + pow((playerp->legs[1]-playerp->legs[9]), 2))<16) + { + float tvx, tvy; + tvx = -gvy; + tvy = gvx; + + if (tvx || tvy) + { + playerp->accs[0] -= 0.2*tvx/hypot(tvx, tvy); + playerp->accs[1] -= 0.2*tvy/hypot(tvx, tvy); + + playerp->accs[4] += 0.2*tvx/hypot(tvx, tvy); + playerp->accs[5] += 0.2*tvy/hypot(tvx, tvy); + } + } + + //If legs touch something + Element_STKM::STKM_interact(sim, playerp, i, (int)(playerp->legs[4]+0.5), (int)(playerp->legs[5]+0.5)); + Element_STKM::STKM_interact(sim, playerp, i, (int)(playerp->legs[12]+0.5), (int)(playerp->legs[13]+0.5)); + Element_STKM::STKM_interact(sim, playerp, i, (int)(playerp->legs[4]+0.5), (int)playerp->legs[5]); + Element_STKM::STKM_interact(sim, playerp, i, (int)(playerp->legs[12]+0.5), (int)playerp->legs[13]); + if (!parts[i].type) + return 1; + + parts[i].ctype = playerp->elem; + return 0; +} + +//#TPT-Directive ElementHeader Element_STKM static void STKM_interact(Simulation * sim, playerst* playerp, int i, int x, int y) +void Element_STKM::STKM_interact(Simulation * sim, playerst* playerp, int i, int x, int y) +{ + int r; + if (x<0 || y<0 || x>=XRES || y>=YRES || !sim->parts[i].type) + return; + r = sim->pmap[y][x]; + if (r) + { + if ((r&0xFF)==PT_SPRK && playerp->elem!=PT_LIGH) //If on charge + { + sim->parts[i].life -= (int)(rand()*20/RAND_MAX)+32; + } + + if (sim->elements[r&0xFF].HeatConduct && ((playerp->elem!=PT_LIGH && sim->parts[r>>8].temp>=323) || sim->parts[r>>8].temp<=243)) + { + sim->parts[i].life -= 2; + playerp->accs[3] -= 1; + } + + if (sim->elements[r&0xFF].Properties&PROP_DEADLY) + switch (r&0xFF) + { + case PT_ACID: + sim->parts[i].life -= 5; + break; + default: + sim->parts[i].life -= 1; + break; + } + + if (sim->elements[r&0xFF].Properties&PROP_RADIOACTIVE) + sim->parts[i].life -= 1; + + if ((r&0xFF)==PT_PRTI && sim->parts[i].type) + { + int nnx, count=1;//gives rx=0, ry=1 in update_PRTO + sim->parts[r>>8].tmp = (int)((sim->parts[r>>8].temp-73.15f)/100+1); + if (sim->parts[r>>8].tmp>=CHANNELS) sim->parts[r>>8].tmp = CHANNELS-1; + else if (sim->parts[r>>8].tmp<0) sim->parts[r>>8].tmp = 0; + for (nnx=0; nnx<80; nnx++) + if (!sim->portalp[sim->parts[r>>8].tmp][count][nnx].type) + { + sim->portalp[sim->parts[r>>8].tmp][count][nnx] = sim->parts[i]; + sim->kill_part(i); + //stop new STKM/fighters being created to replace the ones in the portal: + playerp->spwn = 1; + if (sim->portalp[sim->parts[r>>8].tmp][count][nnx].type==PT_FIGH) + sim->fighcount++; + break; + } + } + if (((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) && sim->parts[i].type) + { + if (!sim->legacy_enable) + { + sim->parts[r>>8].temp = restrict_flt(sim->parts[r>>8].temp+sim->parts[i].temp/2, MIN_TEMP, MAX_TEMP); + } + sim->kill_part(i); + } + if (((r&0xFF)==PT_VOID || ((r&0xFF)==PT_PVOD && sim->parts[r>>8].life==10)) && (!sim->parts[r>>8].ctype || (sim->parts[r>>8].ctype==sim->parts[i].type)!=(sim->parts[r>>8].tmp&1)) && sim->parts[i].type) + { + sim->kill_part(i); + } + } +} + +//#TPT-Directive ElementHeader Element_STKM static void STKM_init_legs(Simulation * sim, playerst* playerp, int i) +void Element_STKM::STKM_init_legs(Simulation * sim, playerst* playerp, int i) +{ + int x, y; + + x = (int)(sim->parts[i].x+0.5f); + y = (int)(sim->parts[i].y+0.5f); + + playerp->legs[0] = x-1; + playerp->legs[1] = y+6; + playerp->legs[2] = x-1; + playerp->legs[3] = y+6; + + playerp->legs[4] = x-3; + playerp->legs[5] = y+12; + playerp->legs[6] = x-3; + playerp->legs[7] = y+12; + + playerp->legs[8] = x+1; + playerp->legs[9] = y+6; + playerp->legs[10] = x+1; + playerp->legs[11] = y+6; + + playerp->legs[12] = x+3; + playerp->legs[13] = y+12; + playerp->legs[14] = x+3; + playerp->legs[15] = y+12; + + for (int i = 0; i < 8; i++) + playerp->accs[i] = 0; + playerp->comm = 0; + playerp->pcomm = 0; + playerp->frames = 0; +} + + +Element_STKM::~Element_STKM() {} diff --git a/src/simulation/elements/STKM2.cpp b/src/simulation/elements/STKM2.cpp new file mode 100644 index 0000000..a2c0073 --- /dev/null +++ b/src/simulation/elements/STKM2.cpp @@ -0,0 +1,56 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_STKM2 PT_STKM2 128 +Element_STKM2::Element_STKM2() +{ + Identifier = "DEFAULT_PT_STKM2"; + Name = "STK2"; + Colour = PIXPACK(0x6464FF); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.5f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.2f; + Loss = 1.0f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.0f; + HotAir = 0.00f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 50; + + Temperature = R_TEMP+14.6f+273.15f; + HeatConduct = 0; + Description = "Stickman. Don't kill him!"; + + State = ST_NONE; + Properties = 0; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 620.0f; + HighTemperatureTransition = PT_FIRE; + + Update = &Element_STKM2::update; + Graphics = &Element_STKM::graphics; +} + +//#TPT-Directive ElementHeader Element_STKM2 static int update(UPDATE_FUNC_ARGS) +int Element_STKM2::update(UPDATE_FUNC_ARGS) + { + Element_STKM::run_stickman(&sim->player2, UPDATE_FUNC_SUBCALL_ARGS); + return 0; +} + +Element_STKM2::~Element_STKM2() {}
\ No newline at end of file diff --git a/src/simulation/elements/STNE.cpp b/src/simulation/elements/STNE.cpp new file mode 100644 index 0000000..ff5251d --- /dev/null +++ b/src/simulation/elements/STNE.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_STNE PT_STNE 5 +Element_STNE::Element_STNE() +{ + Identifier = "DEFAULT_PT_STNE"; + Name = "STNE"; + Colour = PIXPACK(0xA0A0A0); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 5; + Hardness = 1; + + Weight = 90; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 150; + Description = "Heavy particles. Meltable."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 983.0f; + HighTemperatureTransition = PT_LAVA; + + Update = NULL; + +} + +Element_STNE::~Element_STNE() {}
\ No newline at end of file diff --git a/src/simulation/elements/STOR.cpp b/src/simulation/elements/STOR.cpp new file mode 100644 index 0000000..c6064cd --- /dev/null +++ b/src/simulation/elements/STOR.cpp @@ -0,0 +1,112 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_STOR PT_STOR 83 +Element_STOR::Element_STOR() +{ + Identifier = "DEFAULT_PT_STOR"; + Name = "STOR"; + Colour = PIXPACK(0x50DFDF); + MenuVisible = 1; + MenuSection = SC_POWERED; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Solid. Stores a single particle, releases when charged with PSCN, also passes to PIPE"; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_STOR::update; + Graphics = &Element_STOR::graphics; +} + +//#TPT-Directive ElementHeader Element_STOR static int update(UPDATE_FUNC_ARGS) +int Element_STOR::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, np, rx1, ry1; + if(parts[i].life && !parts[i].tmp) + parts[i].life--; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + continue; + if (!parts[i].tmp && !parts[i].life && (r&0xFF)!=PT_STOR && !(sim->elements[(r&0xFF)].Properties&TYPE_SOLID) && (!parts[i].ctype || (r&0xFF)==parts[i].ctype)) + { + parts[i].tmp = 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; + sim->kill_part(r>>8); + } + if(parts[i].tmp && (r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_PSCN && parts[r>>8].life>0 && parts[r>>8].life<4) + { + for(ry1 = 1; ry1 >= -1; ry1--){ + for(rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1){ // Oscilate 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); + if (np!=-1) + { + parts[np].temp = parts[i].temp; + parts[np].life = parts[i].tmp2; + parts[np].tmp = parts[i].pavg[0]; + parts[np].ctype = parts[i].pavg[1]; + parts[i].tmp = 0; + parts[i].life = 10; + break; + } + } + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_STOR static int graphics(GRAPHICS_FUNC_ARGS) +int Element_STOR::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(cpart->tmp){ + *pixel_mode |= PMODE_GLOW; + *colr = 0x50; + *colg = 0xDF; + *colb = 0xDF; + } else { + *colr = 0x20; + *colg = 0xAF; + *colb = 0xAF; + } + return 0; +} + + +Element_STOR::~Element_STOR() {} diff --git a/src/simulation/elements/SWCH.cpp b/src/simulation/elements/SWCH.cpp new file mode 100644 index 0000000..818af27 --- /dev/null +++ b/src/simulation/elements/SWCH.cpp @@ -0,0 +1,113 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_SWCH PT_SWCH 56 +Element_SWCH::Element_SWCH() +{ + Identifier = "DEFAULT_PT_SWCH"; + Name = "SWCH"; + Colour = PIXPACK(0x103B11); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Solid. Only conducts when switched on. (PSCN switches on, NSCN switches off)"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_SWCH::update; + Graphics = &Element_SWCH::graphics; +} + +bool isRedBRAY(UPDATE_FUNC_ARGS, int xc, int yc) +{ + return (pmap[yc][xc]&0xFF) == PT_BRAY && parts[pmap[yc][xc]>>8].tmp == 2; +} + +//#TPT-Directive ElementHeader Element_SWCH static int update(UPDATE_FUNC_ARGS) +int Element_SWCH::update(UPDATE_FUNC_ARGS) + { + int r, rt, rx, ry; + if (parts[i].life>0 && parts[i].life!=10) + parts[i].life--; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (sim->parts_avg(i,r>>8,PT_INSL)!=PT_INSL) { + rt = r&0xFF; + if (rt==PT_SWCH) + { + if (parts[i].life>=10&&parts[r>>8].life<10&&parts[r>>8].life>0) + parts[i].life = 9; + else if (parts[i].life==0&&parts[r>>8].life>=10) + { + //Set to other particle's life instead of 10, otherwise spark loops form when SWCH is sparked while turning on + parts[i].life = parts[r>>8].life; + } + } + else if (rt==PT_SPRK&&parts[i].life==10&&parts[r>>8].ctype!=PT_PSCN&&parts[r>>8].ctype!=PT_NSCN) { + sim->part_change_type(i,x,y,PT_SPRK); + parts[i].ctype = PT_SWCH; + parts[i].life = 4; + } + } + } + //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 (parts[i].life == 10) + parts[i].life = 9; + else if (parts[i].life <= 5) + parts[i].life = 14; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_SWCH static int graphics(GRAPHICS_FUNC_ARGS) +int Element_SWCH::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(cpart->life >= 10) + { + *colr = 17; + *colg = 217; + *colb = 24; + *pixel_mode |= PMODE_GLOW; + } + return 0; +} + + +Element_SWCH::~Element_SWCH() {}
\ No newline at end of file diff --git a/src/simulation/elements/TESC.cpp b/src/simulation/elements/TESC.cpp new file mode 100644 index 0000000..d8b4e9f --- /dev/null +++ b/src/simulation/elements/TESC.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_TESC PT_TESC 88 +Element_TESC::Element_TESC() +{ + Identifier = "DEFAULT_PT_TESC"; + Name = "TESC"; + Colour = PIXPACK(0x707040); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Tesla coil!"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_TESC::~Element_TESC() {}
\ No newline at end of file diff --git a/src/simulation/elements/THDR.cpp b/src/simulation/elements/THDR.cpp new file mode 100644 index 0000000..6ee1dea --- /dev/null +++ b/src/simulation/elements/THDR.cpp @@ -0,0 +1,102 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_THDR PT_THDR 48 +Element_THDR::Element_THDR() +{ + Identifier = "DEFAULT_PT_THDR"; + Name = "THDR"; + Colour = PIXPACK(0xFFFFA0); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.0f; + Loss = 0.30f; + Collision = -0.99f; + Gravity = 0.6f; + Diffusion = 0.62f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 1; + + Temperature = 9000.0f +273.15f; + HeatConduct = 1; + Description = "Lightning! Very hot, inflicts damage upon most materials, transfers current to metals."; + + State = ST_NONE; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_THDR::update; + Graphics = &Element_THDR::graphics; +} + +//#TPT-Directive ElementHeader Element_THDR static int update(UPDATE_FUNC_ARGS) +int Element_THDR::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((sim->elements[r&0xFF].Properties&PROP_CONDUCTS) && parts[r>>8].life==0 && !((r&0xFF)==PT_WATR||(r&0xFF)==PT_SLTW) && parts[r>>8].ctype!=PT_SPRK) + { + parts[i].type = PT_NONE; + parts[r>>8].ctype = parts[r>>8].type; + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + parts[r>>8].life = 4; + } + else if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_SPRK&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT&&(r&0xFF)) + { + sim->pv[y/CELL][x/CELL] += 100.0f; + if (sim->legacy_enable&&1>(rand()%200)) + { + parts[i].life = rand()%50+120; + sim->part_change_type(i,x,y,PT_FIRE); + } + else + { + parts[i].type = PT_NONE; + } + } + } + if (parts[i].type==PT_NONE) { + sim->kill_part(i); + return 1; + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_THDR static int graphics(GRAPHICS_FUNC_ARGS) +int Element_THDR::graphics(GRAPHICS_FUNC_ARGS) + +{ + *firea = 160; + *fireg = 192; + *fireb = 255; + *firer = 144; + *pixel_mode |= FIRE_ADD; + return 1; +} + + +Element_THDR::~Element_THDR() {} diff --git a/src/simulation/elements/THRM.cpp b/src/simulation/elements/THRM.cpp new file mode 100644 index 0000000..e7d1dde --- /dev/null +++ b/src/simulation/elements/THRM.cpp @@ -0,0 +1,80 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_THRM PT_THRM 65 +Element_THRM::Element_THRM() +{ + Identifier = "DEFAULT_PT_THRM"; + Name = "THRM"; + Colour = PIXPACK(0xA08090); + MenuVisible = 1; + MenuSection = SC_EXPLOSIVE; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.04f * CFDS; + AirLoss = 0.94f; + Loss = 0.95f; + Collision = -0.1f; + Gravity = 0.3f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 2; + Hardness = 2; + + Weight = 90; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 211; + Description = "Thermite. Burns at extremely high temperature."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_THRM::update; + +} + +//#TPT-Directive ElementHeader Element_THRM static int update(UPDATE_FUNC_ARGS) +int Element_THRM::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM || (r&0xFF)==PT_LAVA)) // TODO: could this go in update_PYRO? + { + if (1>(rand()%500)) { + sim->part_change_type(i,x,y,PT_LAVA); + parts[i].ctype = PT_BMTL; + parts[i].temp = 3500.0f; + sim->pv[y/CELL][x/CELL] += 50.0f; + } else { + sim->part_change_type(i,x,y,PT_LAVA); + parts[i].life = 400; + parts[i].ctype = PT_THRM; + parts[i].temp = 3500.0f; + parts[i].tmp = 20; + } + } + } + return 0; +} + + +Element_THRM::~Element_THRM() {}
\ No newline at end of file diff --git a/src/simulation/elements/TRON.cpp b/src/simulation/elements/TRON.cpp new file mode 100644 index 0000000..36493a7 --- /dev/null +++ b/src/simulation/elements/TRON.cpp @@ -0,0 +1,236 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_TRON PT_TRON 143 +Element_TRON::Element_TRON() +{ + Identifier = "DEFAULT_PT_TRON"; + Name = "TRON"; + Colour = PIXPACK(0xA9FF00); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 0.0f; + HeatConduct = 40; + Description = "Smart particles, Travels in straight lines and avoids obstacles. Grows with time."; + + State = ST_NONE; + Properties = TYPE_SOLID|PROP_LIFE_DEC|PROP_LIFE_KILL; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_TRON::update; + Graphics = &Element_TRON::graphics; + + Element_TRON::init_graphics(); +} + +#define TRON_HEAD 1 +#define TRON_NOGROW 2 +#define TRON_WAIT 4 //it was just created, so WAIT a frame +#define TRON_NODIE 8 +#define TRON_DEATH 16 //Crashed, now dying +int tron_rx[4] = {-1, 0, 1, 0}; +int tron_ry[4] = { 0,-1, 0, 1}; +unsigned int tron_colours[32]; + +//#TPT-Directive ElementHeader Element_TRON static void init_graphics() +void Element_TRON::init_graphics() +{ + int i; + int r, g, b; + for (i=0; i<32; i++) + { + HSV_to_RGB(i<<4,255,255,&r,&g,&b); + tron_colours[i] = r<<16 | g<<8 | b; + } +} + +//#TPT-Directive ElementHeader Element_TRON static int update(UPDATE_FUNC_ARGS) +int Element_TRON::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry, np; + if (parts[i].tmp&TRON_WAIT) + { + parts[i].tmp &= ~TRON_WAIT; + return 0; + } + if (parts[i].tmp&TRON_HEAD) + { + int firstdircheck = 0,seconddir,seconddircheck = 0,lastdir,lastdircheck = 0; + int direction = (parts[i].tmp>>5 & 0x3); + int originaldir = direction; + + //random turn + int random = rand()%340; + if (random==1 || random==3) + { + //randomly turn left(3) or right(1) + direction = (direction + random)%4; + } + + //check infront + //do sight check + firstdircheck = Element_TRON::trymovetron(sim,x,y,direction,i,parts[i].tmp2); + if (firstdircheck < parts[i].tmp2) + { + if (originaldir != direction) //if we just tried a random turn, don't pick random again + { + seconddir = originaldir; + lastdir = (direction + 2)%4; + } + else + { + seconddir = (direction + ((rand()%2)*2)+1)% 4; + lastdir = (seconddir + 2)%4; + } + seconddircheck = trymovetron(sim,x,y,seconddir,i,parts[i].tmp2); + lastdircheck = trymovetron(sim,x,y,lastdir,i,parts[i].tmp2); + } + //find the best move + if (seconddircheck > firstdircheck) + direction = seconddir; + if (lastdircheck > seconddircheck && lastdircheck > firstdircheck) + direction = lastdir; + //now try making new head, even if it fails + if (Element_TRON::new_tronhead(sim,x + tron_rx[direction],y + tron_ry[direction],i,direction) == -1) + { + //ohgod crash + parts[i].tmp |= TRON_DEATH; + //trigger tail death for TRON_NODIE, or is that mode even needed? just set a high tail length(but it still won't start dying when it crashes) + } + + //set own life and clear .tmp (it dies if it can't move anyway) + parts[i].life = parts[i].tmp2; + parts[i].tmp &= parts[i].tmp&0xF818; + } + else // fade tail deco, or prevent tail from dieing + { + if (parts[i].tmp&TRON_NODIE) + parts[i].life++; + //parts[i].dcolour = clamp_flt((float)parts[i].life/(float)parts[i].tmp2,0,1.0f) << 24 | parts[i].dcolour&0x00FFFFFF; + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_TRON static int graphics(GRAPHICS_FUNC_ARGS) +int Element_TRON::graphics(GRAPHICS_FUNC_ARGS) + { + unsigned int col = tron_colours[(cpart->tmp&0xF800)>>11]; + if(cpart->tmp & TRON_HEAD) + *pixel_mode |= PMODE_GLOW; + *colr = (col & 0xFF0000)>>16; + *colg = (col & 0x00FF00)>>8; + *colb = (col & 0x0000FF); + if(cpart->tmp & TRON_DEATH) + { + *pixel_mode |= FIRE_ADD | PMODE_FLARE; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + *firea = 255; + } + if(cpart->life < cpart->tmp2 && !(cpart->tmp & TRON_HEAD)) + { + *pixel_mode |= PMODE_BLEND; + *pixel_mode &= ~PMODE_FLAT; + *cola = (int)((((float)cpart->life)/((float)cpart->tmp2))*255.0f); + } + return 0; +} + +//#TPT-Directive ElementHeader Element_TRON static int new_tronhead(Simulation * sim, int x, int y, int i, int direction) +int Element_TRON::new_tronhead(Simulation * sim, int x, int y, int i, int direction) +{ + int np = sim->create_part(-1, x , y ,PT_TRON); + if (np==-1) + return -1; + if (sim->parts[i].life >= 100) // increase tail length + { + if (!(sim->parts[i].tmp&TRON_NOGROW)) + sim->parts[i].tmp2++; + sim->parts[i].life = 5; + } + //give new head our properties + sim->parts[np].tmp = 1 | direction<<5 | sim->parts[i].tmp&(TRON_NOGROW|TRON_NODIE) | (sim->parts[i].tmp&0xF800); + if (np > i) + sim->parts[np].tmp |= TRON_WAIT; + + sim->parts[np].ctype = sim->parts[i].ctype; + sim->parts[np].tmp2 = sim->parts[i].tmp2; + sim->parts[np].life = sim->parts[i].life + 2; + return 1; +} + +//#TPT-Directive ElementHeader Element_TRON static int trymovetron(Simulation * sim, int x, int y, int dir, int i, int len) +int Element_TRON::trymovetron(Simulation * sim, int x, int y, int dir, int i, int len) +{ + int k,j,r,rx,ry,tx,ty,count; + count = 0; + rx = x; + ry = y; + for (k = 1; k <= len; k ++) + { + rx += tron_rx[dir]; + ry += tron_ry[dir]; + r = sim->pmap[ry][rx]; + if (!r && !sim->bmap[(ry)/CELL][(rx)/CELL] && ry > CELL && rx > CELL && ry < YRES-CELL && rx < XRES-CELL) + { + count++; + for (tx = rx - tron_ry[dir] , ty = ry - tron_rx[dir], j=1; abs(tx-rx) < (len-k) && abs(ty-ry) < (len-k); tx-=tron_ry[dir],ty-=tron_rx[dir],j++) + { + r = sim->pmap[ty][tx]; + if (!r && !sim->bmap[(ty)/CELL][(tx)/CELL] && ty > CELL && tx > CELL && ty < YRES-CELL && tx < XRES-CELL) + { + if (j == (len-k))//there is a safe path, so we can break out + return len+1; + count++; + } + else //we hit a block so no need to check farther here + break; + } + for (tx = rx + tron_ry[dir] , ty = ry + tron_rx[dir], j=1; abs(tx-rx) < (len-k) && abs(ty-ry) < (len-k); tx+=tron_ry[dir],ty+=tron_rx[dir],j++) + { + r = sim->pmap[ty][tx]; + if (!r && !sim->bmap[(ty)/CELL][(tx)/CELL] && ty > CELL && tx > CELL && ty < YRES-CELL && tx < XRES-CELL) + { + if (j == (len-k)) + return len+1; + count++; + } + else + break; + } + } + else //a block infront, no need to continue + break; + } + return count; +} + +Element_TRON::~Element_TRON() {} diff --git a/src/simulation/elements/TSNS.cpp b/src/simulation/elements/TSNS.cpp new file mode 100644 index 0000000..d5c8aa7 --- /dev/null +++ b/src/simulation/elements/TSNS.cpp @@ -0,0 +1,93 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_TSNS PT_TSNS 164 +Element_TSNS::Element_TSNS() +{ + Identifier = "DEFAULT_PT_TSNS"; + Name = "TSNS"; + Colour = PIXPACK(0xFD9D18); + MenuVisible = 1; + MenuSection = SC_SENSOR; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.96f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Creates a spark when there's a nearby particle with a greater temperature"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_TSNS::update; + +} + +//#TPT-Directive ElementHeader Element_TSNS static int update(UPDATE_FUNC_ARGS) +int Element_TSNS::update(UPDATE_FUNC_ARGS) +{ + int r, rx, ry, rt, rd = parts[i].tmp2; + if (rd > 25) parts[i].tmp2 = rd = 25; + if (parts[i].life) + { + parts[i].life = 0; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + rt = parts[r>>8].type; + if (sim->parts_avg(i,r>>8,PT_INSL) != PT_INSL) + { + if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[r>>8].life==0 && Element_DTEC::in_radius(rd, rx, ry)) + { + parts[r>>8].life = 4; + parts[r>>8].ctype = rt; + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + } + } + } + } + for (rx=-rd; rx<rd+1; rx++) + for (ry=-rd; ry<rd+1; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if(!r) + r = sim->photons[y+ry][x+rx]; + if(!r) + continue; + if (parts[r>>8].temp > parts[i].temp && parts[r>>8].type != PT_TSNS) + parts[i].life = 1; + } + return 0; +} + + + +Element_TSNS::~Element_TSNS() {} diff --git a/src/simulation/elements/TTAN.cpp b/src/simulation/elements/TTAN.cpp new file mode 100644 index 0000000..c51319d --- /dev/null +++ b/src/simulation/elements/TTAN.cpp @@ -0,0 +1,76 @@ +#include "simulation/Elements.h" +#include "simulation/Air.h" +//#TPT-Directive ElementClass Element_TTAN PT_TTAN 144 +Element_TTAN::Element_TTAN() +{ + Identifier = "DEFAULT_PT_TTAN"; + Name = "TTAN"; + Colour = PIXPACK(0x909090); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 50; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Titanium, Higher melting temperature than other metals, blocks all air pressure"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_HOT_GLOW|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1941.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_TTAN::update; + +} + +//#TPT-Directive ElementHeader Element_TTAN static int update(UPDATE_FUNC_ARGS) +int Element_TTAN::update(UPDATE_FUNC_ARGS) + { + int nx, ny, ttan = 0; + if(nt<=2) + ttan = 2; + else if(parts[i].tmp) + ttan = 2; + else if(nt<=6) + for (nx=-1; nx<2; nx++) { + for (ny=-1; ny<2; ny++) { + if ((!nx != !ny) && x+nx>=0 && y+ny>=0 && x+nx<XRES && y+ny<YRES) { + if((pmap[y+ny][x+nx]&0xFF)==PT_TTAN) + ttan++; + } + } + } + + if(ttan>=2) { + sim->air->bmap_blockair[y/CELL][x/CELL] = 1; + sim->air->bmap_blockairh[y/CELL][x/CELL] = 1; + } + return 0; +} + + +Element_TTAN::~Element_TTAN() {} diff --git a/src/simulation/elements/URAN.cpp b/src/simulation/elements/URAN.cpp new file mode 100644 index 0000000..a988bf3 --- /dev/null +++ b/src/simulation/elements/URAN.cpp @@ -0,0 +1,61 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_URAN PT_URAN 32 +Element_URAN::Element_URAN() +{ + Identifier = "DEFAULT_PT_URAN"; + Name = "URAN"; + Colour = PIXPACK(0x707020); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.4f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.99f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.4f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 90; + + Temperature = R_TEMP+30.0f+273.15f; + HeatConduct = 251; + Description = "Heavy particles. Generates heat under pressure."; + + State = ST_SOLID; + Properties = TYPE_PART | PROP_RADIOACTIVE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_URAN::update; + +} + +//#TPT-Directive ElementHeader Element_URAN static int update(UPDATE_FUNC_ARGS) +int Element_URAN::update(UPDATE_FUNC_ARGS) + { + if (!sim->legacy_enable && sim->pv[y/CELL][x/CELL]>0.0f) + { + float atemp = parts[i].temp + (-MIN_TEMP); + parts[i].temp = restrict_flt((atemp*(1+(sim->pv[y/CELL][x/CELL]/2000)))+MIN_TEMP, MIN_TEMP, MAX_TEMP); + } + return 0; +} + + +Element_URAN::~Element_URAN() {}
\ No newline at end of file diff --git a/src/simulation/elements/VIBR.cpp b/src/simulation/elements/VIBR.cpp new file mode 100644 index 0000000..68119f7 --- /dev/null +++ b/src/simulation/elements/VIBR.cpp @@ -0,0 +1,235 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_VIBR PT_VIBR 165 +Element_VIBR::Element_VIBR() +{ + Identifier = "DEFAULT_PT_VIBR"; + Name = "VIBR"; + Colour = PIXPACK(0x005000); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.85f; + 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 = 251; + Description = "Vibranium. Stores energy and releases it in violent explosions."; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_VIBR::update; + Graphics = &Element_VIBR::graphics; +} + +//#TPT-Directive ElementHeader Element_VIBR static int update(UPDATE_FUNC_ARGS) +int Element_VIBR::update(UPDATE_FUNC_ARGS) { + int r, rx, ry; + int trade, transfer; + if (parts[i].ctype == 1) //leaving in, just because + { + if (sim->pv[y/CELL][x/CELL] > -2.5 || parts[i].tmp) + { + parts[i].ctype = 0; + sim->part_change_type(i, x, y, PT_VIBR); + } + } + else if (!parts[i].life) //if not exploding + { + //Heat absorption code + if (parts[i].temp > 274.65f) + { + parts[i].tmp++; + parts[i].temp -= 3; + } + if (parts[i].temp < 271.65f) + { + parts[i].tmp--; + parts[i].temp += 3; + } + //Pressure absorption code + if (sim->pv[y/CELL][x/CELL] > 2.5) + { + parts[i].tmp += 7; + sim->pv[y/CELL][x/CELL]--; + } + if (sim->pv[y/CELL][x/CELL] < -2.5) + { + parts[i].tmp -= 2; + sim->pv[y/CELL][x/CELL]++; + } + //initiate explosion counter + if (parts[i].tmp > 1000) + parts[i].life = 750; + } + else //if it is exploding + { + //Release sparks before explode + if (parts[i].life < 300) + { + rx = rand()%3-1; + ry = rand()%3-1; + r = pmap[y+ry][x+rx]; + if ((r&0xFF) && (r&0xFF) != PT_BREC && (sim->elements[r&0xFF].Properties&PROP_CONDUCTS) && !parts[r>>8].life) + { + parts[r>>8].life = 4; + parts[r>>8].ctype = r&0xFF; + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + } + } + //Release all heat + if (parts[i].life < 500) + { + int random = rand(); + rx = random%7-3; + ry = (random>>3)%7-3; + if(x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES) + { + r = pmap[y+ry][x+rx]; + if ((r&0xFF) && (r&0xFF)!=PT_VIBR && (r&0xFF)!=PT_BVBR && sim->elements[r&0xFF].HeatConduct && ((r&0xFF)!=PT_HSWC||parts[r>>8].life==10)) + { + parts[r>>8].temp += parts[i].tmp*3; + parts[i].tmp = 0; + } + } + } + //Explosion code + if (parts[i].life == 1) + { + int random = rand(), index; + sim->create_part(i, x, y, PT_EXOT); + parts[i].tmp2 = rand()%1000; + index = sim->create_part(-3,x+((random>>4)&3)-1,y+((random>>6)&3)-1,PT_ELEC); + if (index != -1) + parts[index].temp = 7000; + index = sim->create_part(-3,x+((random>>8)&3)-1,y+((random>>10)&3)-1,PT_PHOT); + if (index != -1) + parts[index].temp = 7000; + index = sim->create_part(-1,x+((random>>12)&3)-1,y+rand()%3-1,PT_BREC); + if (index != -1) + parts[index].temp = 7000; + parts[i].temp=9000; + sim->pv[y/CELL][x/CELL] += 50; + + return 1; + } + } + //Neighbor check loop + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + r = sim->photons[y+ry][x+rx]; + if (!r) + continue; + //Melts into EXOT + if ((r&0xFF) == PT_EXOT && !(rand()%250)) + { + sim->create_part(i, x, y, PT_EXOT); + } + else if ((r&0xFF) == PT_ANAR) + { + sim->part_change_type(i,x,y,PT_BVBR); + sim->pv[y/CELL][x/CELL] -= 1; + } + else if (parts[i].life && ((r&0xFF)==PT_VIBR || (r&0xFF)==PT_BVBR) && !parts[r>>8].life) + { + parts[r>>8].tmp += 10; + } + //Absorbs energy particles + if ((sim->elements[r&0xFF].Properties & TYPE_ENERGY)) + { + parts[i].tmp += 20; + sim->kill_part(r>>8); + } + } + for (trade = 0; trade < 9; trade++) + { + int random = rand(); + rx = random%7-3; + ry = (random>>3)%7-3; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r&0xFF) != PT_VIBR && (r&0xFF) != PT_BVBR) + continue; + if (parts[i].tmp > parts[r>>8].tmp) + { + transfer = parts[i].tmp - parts[r>>8].tmp; + if (transfer == 1) + { + parts[r>>8].tmp += 1; + parts[i].tmp -= 1; + trade = 9; + } + else if (transfer > 0) + { + parts[r>>8].tmp += transfer/2; + parts[i].tmp -= transfer/2; + trade = 9; + } + } + } + } + if (parts[i].tmp < 0) + parts[i].tmp = 0; // only preventing because negative tmp doesn't save + return 0; +} + +//#TPT-Directive ElementHeader Element_VIBR static int graphics(GRAPHICS_FUNC_ARGS) +int Element_VIBR::graphics(GRAPHICS_FUNC_ARGS) +{ + int gradient = cpart->tmp/10; + if (gradient >= 100 || cpart->life) + { + *colr = (int)(fabs(sin(exp((750.0f-cpart->life)/170)))*200.0f); + *colg = 255; + *colb = (int)(fabs(sin(exp((750.0f-cpart->life)/170)))*200.0f); + *firea = 90; + *firer = *colr; + *fireg = *colg; + *fireb = *colb; + *pixel_mode = PMODE_NONE; + *pixel_mode |= FIRE_BLEND; + } + else if (gradient < 100) + { + *colr += (int)restrict_flt(gradient*2.0f,0,255); + *colg += (int)restrict_flt(gradient*2.0f,0,175); + *colb += (int)restrict_flt(gradient*2.0f,0,255); + *firea = (int)restrict_flt(gradient*.6f,0,60); + *firer = *colr/2; + *fireg = *colg/2; + *fireb = *colb/2; + *pixel_mode |= FIRE_BLEND; + } + return 0; +} + +Element_VIBR::~Element_VIBR() {} diff --git a/src/simulation/elements/VINE.cpp b/src/simulation/elements/VINE.cpp new file mode 100644 index 0000000..e31c8cd --- /dev/null +++ b/src/simulation/elements/VINE.cpp @@ -0,0 +1,91 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_VINE PT_VINE 114 +Element_VINE::Element_VINE() +{ + Identifier = "DEFAULT_PT_VINE"; + Name = "VINE"; + Colour = PIXPACK(0x079A00); + 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 = 20; + Explosive = 0; + Meltable = 0; + Hardness = 10; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 65; + Description = "Vine, grows"; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 573.0f; + HighTemperatureTransition = PT_FIRE; + + Update = &Element_VINE::update; + +} + +//#TPT-Directive ElementHeader Element_VINE static int update(UPDATE_FUNC_ARGS) +int Element_VINE::update(UPDATE_FUNC_ARGS) + { + int r, np, rx =(rand()%3)-1, ry=(rand()%3)-1; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (1>rand()%15) + sim->part_change_type(i,x,y,PT_PLNT); + else if (!r) + { + 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); + } + } + if (parts[i].temp > 350 && parts[i].temp > parts[i].tmp2) + parts[i].tmp2 = (int)parts[i].temp; + return 0; +} + +//#TPT-Directive ElementHeader Element_VINE static int graphics(GRAPHICS_FUNC_ARGS) +int Element_VINE::graphics(GRAPHICS_FUNC_ARGS) +{ + float maxtemp = std::max((float)cpart->tmp2, cpart->temp); + if (maxtemp > 300) + { + *colr += (int)restrict_flt((maxtemp-300)/5,0,58); + *colg -= (int)restrict_flt((maxtemp-300)/2,0,102); + *colb += (int)restrict_flt((maxtemp-300)/5,0,70); + } + if (maxtemp < 273) + { + *colg += (int)restrict_flt((273-maxtemp)/4,0,255); + *colb += (int)restrict_flt((273-maxtemp)/1.5,0,255); + } + return 0; +} + + +Element_VINE::~Element_VINE() {}
\ No newline at end of file diff --git a/src/simulation/elements/VOID.cpp b/src/simulation/elements/VOID.cpp new file mode 100644 index 0000000..05eb872 --- /dev/null +++ b/src/simulation/elements/VOID.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_VOID PT_VOID 22 +Element_VOID::Element_VOID() +{ + Identifier = "DEFAULT_PT_VOID"; + Name = "VOID"; + Colour = PIXPACK(0x790B0B); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 1.00f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = -0.0003f* CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Hole, will drain away any particles."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_VOID::~Element_VOID() {}
\ No newline at end of file diff --git a/src/simulation/elements/WARP.cpp b/src/simulation/elements/WARP.cpp new file mode 100644 index 0000000..bb8f8e1 --- /dev/null +++ b/src/simulation/elements/WARP.cpp @@ -0,0 +1,95 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_WARP PT_WARP 96 +Element_WARP::Element_WARP() +{ + Identifier = "DEFAULT_PT_WARP"; + Name = "WARP"; + Colour = PIXPACK(0x101010); + MenuVisible = 1; + MenuSection = SC_NUCLEAR; + Enabled = 1; + + Advection = 0.8f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.9f; + Loss = 0.70f; + Collision = -0.1f; + Gravity = 0.0f; + Diffusion = 3.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 1; + + Temperature = R_TEMP +273.15f; + HeatConduct = 100; + Description = "Displaces other elements."; + + State = ST_GAS; + Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_WARP::update; + +} + +//#TPT-Directive ElementHeader Element_WARP static int update(UPDATE_FUNC_ARGS) +int Element_WARP::update(UPDATE_FUNC_ARGS) + { + int trade, r, rx, ry; + if (parts[i].tmp2>2000) + { + parts[i].temp = 10000; + sim->pv[y/CELL][x/CELL] += (parts[i].tmp2/5000) * CFDS; + if (2>rand()%100) + sim->create_part(-3, x, y, PT_ELEC); + } + for ( trade = 0; trade<5; trade ++) + { + rx = rand()%3-1; + ry = rand()%3-1; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)!=PT_WARP&&(r&0xFF)!=PT_STKM&&(r&0xFF)!=PT_STKM2&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_BCLN&&(r&0xFF)!=PT_PCLN) + { + parts[i].x = parts[r>>8].x; + parts[i].y = parts[r>>8].y; + parts[r>>8].x = x; + parts[r>>8].y = y; + parts[r>>8].vx = (rand()%4)-1.5; + parts[r>>8].vy = (rand()%4)-2; + parts[i].life += 4; + pmap[y][x] = r; + pmap[y+ry][x+rx] = (i<<8)|parts[i].type; + trade = 5; + } + } + } + return 0; +} + +//#TPT-Directive ElementHeader Element_WARP static int graphics(GRAPHICS_FUNC_ARGS) +int Element_WARP::graphics(GRAPHICS_FUNC_ARGS) +{ + *colr = *colg = *colb = *cola = 0; + *pixel_mode &= ~PMODE; + return 0; +} + +Element_WARP::~Element_WARP() {} diff --git a/src/simulation/elements/WATR.cpp b/src/simulation/elements/WATR.cpp new file mode 100644 index 0000000..f0fde66 --- /dev/null +++ b/src/simulation/elements/WATR.cpp @@ -0,0 +1,89 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_WATR PT_WATR 2 +Element_WATR::Element_WATR() +{ + Identifier = "DEFAULT_PT_WATR"; + Name = "WATR"; + Colour = PIXPACK(0x2030D0); + MenuVisible = 1; + MenuSection = SC_LIQUID; + Enabled = 1; + + Advection = 0.6f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.98f; + Loss = 0.95f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 2; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 20; + + Weight = 30; + + Temperature = R_TEMP-2.0f +273.15f; + HeatConduct = 29; + Description = "Liquid. Conducts electricity. Freezes. Extinguishes fires."; + + State = ST_LIQUID; + Properties = TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 273.15f; + LowTemperatureTransition = PT_ICEI; + HighTemperature = 373.0f; + HighTemperatureTransition = PT_WTRV; + + Update = &Element_WATR::update; + +} + +//#TPT-Directive ElementHeader Element_WATR static int update(UPDATE_FUNC_ARGS) +int Element_WATR::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_SALT && 1>(rand()%250)) + { + sim->part_change_type(i,x,y,PT_SLTW); + // on average, convert 3 WATR to SLTW before SALT turns into SLTW + if (rand()%3==0) + sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW); + } + if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && 1>(rand()%500)) + { + sim->part_change_type(i,x,y,PT_FIRE); + parts[i].life = 4; + parts[i].ctype = PT_WATR; + } + if ((r&0xFF)==PT_FIRE && parts[r>>8].ctype!=PT_WATR){ + sim->kill_part(r>>8); + if(1>(rand()%150)){ + sim->kill_part(i); + return 1; + } + } + /*if ((r&0xFF)==PT_CNCT && 1>(rand()%500)) Concrete+Water to paste, not very popular + { + part_change_type(i,x,y,PT_PSTE); + sim.kill_part(r>>8); + }*/ + } + return 0; +} + +Element_WATR::~Element_WATR() {} diff --git a/src/simulation/elements/WAX.cpp b/src/simulation/elements/WAX.cpp new file mode 100644 index 0000000..5f9a113 --- /dev/null +++ b/src/simulation/elements/WAX.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_WAX PT_WAX 33 +Element_WAX::Element_WAX() +{ + Identifier = "DEFAULT_PT_WAX"; + Name = "WAX"; + Colour = PIXPACK(0xF0F0BB); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 10; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 44; + Description = "Wax. Melts at moderately high temperatures."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 319.0f; + HighTemperatureTransition = PT_MWAX; + + Update = NULL; + +} + +Element_WAX::~Element_WAX() {}
\ No newline at end of file diff --git a/src/simulation/elements/WHOL.cpp b/src/simulation/elements/WHOL.cpp new file mode 100644 index 0000000..3007960 --- /dev/null +++ b/src/simulation/elements/WHOL.cpp @@ -0,0 +1,49 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_WHOL PT_WHOL 40 +Element_WHOL::Element_WHOL() +{ + Identifier = "DEFAULT_PT_WHOL"; + Name = "VENT"; + Colour = PIXPACK(0xEFEFEF); + MenuVisible = 1; + MenuSection = SC_SPECIAL; + 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.010f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 0; + + Weight = 100; + + Temperature = R_TEMP-16.0f+273.15f; + HeatConduct = 255; + Description = "Air vent, creates pressure and pushes other particles away."; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = NULL; + +} + +Element_WHOL::~Element_WHOL() {}
\ No newline at end of file diff --git a/src/simulation/elements/WIFI.cpp b/src/simulation/elements/WIFI.cpp new file mode 100644 index 0000000..4cbf0d5 --- /dev/null +++ b/src/simulation/elements/WIFI.cpp @@ -0,0 +1,101 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_WIFI PT_WIFI 124 +Element_WIFI::Element_WIFI() +{ + Identifier = "DEFAULT_PT_WIFI"; + Name = "WIFI"; + Colour = PIXPACK(0x40A060); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 2; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 0; + Description = "Wireless transmitter, color coded."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = 15.0f; + HighPressureTransition = PT_BRMT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_WIFI::update; + Graphics = &Element_WIFI::graphics; +} + +//#TPT-Directive ElementHeader Element_WIFI static int update(UPDATE_FUNC_ARGS) +int Element_WIFI::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1); + if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1; + else if (parts[i].tmp<0) parts[i].tmp = 0; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + // wireless[][0] - whether channel is active on this frame + // wireless[][1] - whether channel should be active on next frame + if (sim->wireless[parts[i].tmp][0]) + { + if (((r&0xFF)==PT_NSCN||(r&0xFF)==PT_PSCN||(r&0xFF)==PT_INWR)&&parts[r>>8].life==0 && sim->wireless[parts[i].tmp][0]) + { + parts[r>>8].ctype = r&0xFF; + sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + parts[r>>8].life = 4; + } + } + else + { + if ((r&0xFF)==PT_SPRK && parts[r>>8].ctype!=PT_NSCN && parts[r>>8].life>=3) + { + sim->wireless[parts[i].tmp][1] = 1; + sim->ISWIRE = 2; + } + } + } + return 0; +} + + +//#TPT-Directive ElementHeader Element_WIFI static int graphics(GRAPHICS_FUNC_ARGS) +int Element_WIFI::graphics(GRAPHICS_FUNC_ARGS) + +{ + float frequency = 0.0628; + int q = cpart->tmp; + *colr = sin(frequency*q + 0) * 127 + 128; + *colg = sin(frequency*q + 2) * 127 + 128; + *colb = sin(frequency*q + 4) * 127 + 128; + *pixel_mode |= EFFECT_DBGLINES; + return 0; +} + + +Element_WIFI::~Element_WIFI() {}
\ No newline at end of file diff --git a/src/simulation/elements/WIRE.cpp b/src/simulation/elements/WIRE.cpp new file mode 100644 index 0000000..4f59060 --- /dev/null +++ b/src/simulation/elements/WIRE.cpp @@ -0,0 +1,127 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_WIRE PT_WIRE 156 +Element_WIRE::Element_WIRE() +{ + Identifier = "DEFAULT_PT_WIRE"; + Name = "WIRE"; + Colour = PIXPACK(0xFFCC00); + MenuVisible = 1; + MenuSection = SC_ELEC; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.00f; + 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 = R_TEMP+0.0f +273.15f; + HeatConduct = 250; + Description = "WireWorld wires."; + + State = ST_SOLID; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_WIRE::update; + Graphics = &Element_WIRE::graphics; +} + +//#TPT-Directive ElementHeader Element_WIRE static int update(UPDATE_FUNC_ARGS) +int Element_WIRE::update(UPDATE_FUNC_ARGS) + { + int s,r,rx,ry,count; + /* + 0: wire + 1: spark head + 2: spark tail + + tmp is previous state, ctype is current state + */ + //parts[i].tmp=parts[i].ctype; + parts[i].ctype=0; + if(parts[i].tmp==1) + { + parts[i].ctype=2; + } + if(parts[i].tmp==2) + { + parts[i].ctype=0; + } + + count=0; + for(rx=-1; rx<2; rx++) + for(ry=-1; ry<2; ry++) + { + if(x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if((r&0xFF)==PT_SPRK && parts[r>>8].life==3 && parts[r>>8].ctype==PT_PSCN) + { + parts[i].ctype=1; + return 0; + } + else if((r&0xFF)==PT_NSCN && parts[i].tmp==1){sim->create_part(-1, x+rx, y+ry, PT_SPRK);} + else if((r&0xFF)==PT_WIRE && parts[r>>8].tmp==1 && !parts[i].tmp){count++;} + } + } + if(count==1 || count==2) + parts[i].ctype=1; + return 0; +} + + + +//#TPT-Directive ElementHeader Element_WIRE static int graphics(GRAPHICS_FUNC_ARGS) +int Element_WIRE::graphics(GRAPHICS_FUNC_ARGS) + +{ + if (cpart->ctype==0) + { + *colr = 255; + *colg = 204; + *colb = 0; + return 0; + } + if (cpart->ctype==1) + { + *colr = 50; + *colg = 100; + *colb = 255; + //*pixel_mode |= PMODE_GLOW; + return 0; + } + if (cpart->ctype==2) + { + *colr = 255; + *colg = 100; + *colb = 50; + //*pixel_mode |= PMODE_GLOW; + return 0; + } + return 0; +} + + +Element_WIRE::~Element_WIRE() {}
\ No newline at end of file diff --git a/src/simulation/elements/WOOD.cpp b/src/simulation/elements/WOOD.cpp new file mode 100644 index 0000000..54e2e50 --- /dev/null +++ b/src/simulation/elements/WOOD.cpp @@ -0,0 +1,70 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_WOOD PT_WOOD 17 +Element_WOOD::Element_WOOD() +{ + Identifier = "DEFAULT_PT_WOOD"; + Name = "WOOD"; + Colour = PIXPACK(0xC0A040); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 20; + Explosive = 0; + Meltable = 0; + Hardness = 15; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 164; + Description = "Solid. Flammable."; + + State = ST_SOLID; + Properties = TYPE_SOLID | PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 873.0f; + HighTemperatureTransition = PT_FIRE; + + Update = NULL; + Graphics = &Element_WOOD::graphics; +} + +//#TPT-Directive ElementHeader Element_WOOD static int graphics(GRAPHICS_FUNC_ARGS) +int Element_WOOD::graphics(GRAPHICS_FUNC_ARGS) +{ + float maxtemp = std::max((float)cpart->tmp, cpart->temp); + if (maxtemp > 400) + { + *colr -= (int)restrict_flt((maxtemp-400)/3,0,172); + *colg -= (int)restrict_flt((maxtemp-400)/4,0,140); + *colb -= (int)restrict_flt((maxtemp-400)/20,0,44); + if (maxtemp > 450) + cpart->tmp = (int)maxtemp; + } + if (maxtemp < 273) + { + *colr -= (int)restrict_flt((273-maxtemp)/5,0,40); + *colg += (int)restrict_flt((273-maxtemp)/4,0,40); + *colb += (int)restrict_flt((273-maxtemp)/1.5,0,150); + } + return 0; +} + +Element_WOOD::~Element_WOOD() {}
\ No newline at end of file diff --git a/src/simulation/elements/WTRV.cpp b/src/simulation/elements/WTRV.cpp new file mode 100644 index 0000000..fb72db8 --- /dev/null +++ b/src/simulation/elements/WTRV.cpp @@ -0,0 +1,73 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_WTRV PT_WTRV 23 +Element_WTRV::Element_WTRV() +{ + Identifier = "DEFAULT_PT_WTRV"; + Name = "WTRV"; + Colour = PIXPACK(0xA0A0FF); + MenuVisible = 1; + MenuSection = SC_GAS; + Enabled = 1; + + Advection = 1.0f; + AirDrag = 0.01f * CFDS; + AirLoss = 0.99f; + Loss = 0.30f; + Collision = -0.1f; + Gravity = -0.1f; + Diffusion = 0.75f; + HotAir = 0.0003f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 0; + Hardness = 4; + + Weight = 1; + + Temperature = R_TEMP+100.0f+273.15f; + HeatConduct = 48; + Description = "Steam, heats up air, produced from hot water."; + + State = ST_GAS; + Properties = TYPE_GAS; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = 371.0f; + LowTemperatureTransition = ST; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_WTRV::update; + +} + +//#TPT-Directive ElementHeader Element_WTRV static int update(UPDATE_FUNC_ARGS) +int Element_WTRV::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && !sim->legacy_enable && parts[i].temp>(273.15f+12.0f) && 1>(rand()%500)) + { + sim->part_change_type(i,x,y,PT_FIRE); + parts[i].life = 4; + parts[i].ctype = PT_WATR; + } + } + if(parts[i].temp>1273&&parts[i].ctype==PT_FIRE) + parts[i].temp-=parts[i].temp/1000; + return 0; +} + + +Element_WTRV::~Element_WTRV() {}
\ No newline at end of file diff --git a/src/simulation/elements/YEST.cpp b/src/simulation/elements/YEST.cpp new file mode 100644 index 0000000..99df265 --- /dev/null +++ b/src/simulation/elements/YEST.cpp @@ -0,0 +1,72 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_YEST PT_YEST 63 +Element_YEST::Element_YEST() +{ + Identifier = "DEFAULT_PT_YEST"; + Name = "YEST"; + Colour = PIXPACK(0xEEE0C0); + MenuVisible = 1; + MenuSection = SC_POWDERS; + Enabled = 1; + + Advection = 0.7f; + AirDrag = 0.02f * CFDS; + AirLoss = 0.96f; + Loss = 0.80f; + Collision = 0.0f; + Gravity = 0.1f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 1; + + Flammable = 15; + Explosive = 0; + Meltable = 0; + Hardness = 30; + + Weight = 80; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 70; + Description = "Yeast, grows when warm (~37C)."; + + State = ST_SOLID; + Properties = TYPE_PART; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 373.0f; + HighTemperatureTransition = PT_DYST; + + Update = &Element_YEST::update; + +} + +//#TPT-Directive ElementHeader Element_YEST static int update(UPDATE_FUNC_ARGS) +int Element_YEST::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if ((r&0xFF)==PT_DYST && 1>(rand()%30) && !sim->legacy_enable) + { + sim->part_change_type(i,x,y,PT_DYST); + } + } + if (parts[i].temp>303&&parts[i].temp<317) { + sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_YEST); + } + return 0; +} + + +Element_YEST::~Element_YEST() {}
\ No newline at end of file diff --git a/src/simulation/elements/dcel.cpp b/src/simulation/elements/dcel.cpp new file mode 100644 index 0000000..07f930b --- /dev/null +++ b/src/simulation/elements/dcel.cpp @@ -0,0 +1,85 @@ +#include "simulation/Elements.h" +//#TPT-Directive ElementClass Element_DCEL PT_DCEL 138 +Element_DCEL::Element_DCEL() +{ + Identifier = "DEFAULT_PT_DCEL"; + Name = "DCEL"; + Colour = PIXPACK(0x99CC00); + MenuVisible = 1; + MenuSection = SC_FORCE; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + 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 = 1; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Decelerator"; + + State = ST_NONE; + Properties = TYPE_SOLID; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = ITH; + HighTemperatureTransition = NT; + + Update = &Element_DCEL::update; + Graphics = &Element_DCEL::graphics; +} + +//#TPT-Directive ElementHeader Element_DCEL static int update(UPDATE_FUNC_ARGS) +int Element_DCEL::update(UPDATE_FUNC_ARGS) + { + int r, rx, ry; + parts[i].tmp = 0; + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry) && !(rx && ry)) + { + r = pmap[y+ry][x+rx]; + if(!r) + r = sim->photons[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + continue; + if(sim->elements[r&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) + { + parts[r>>8].vx *= 0.9f; + parts[r>>8].vy *= 0.9f; + parts[i].tmp = 1; + } + } + return 0; +} + + + +//#TPT-Directive ElementHeader Element_DCEL static int graphics(GRAPHICS_FUNC_ARGS) +int Element_DCEL::graphics(GRAPHICS_FUNC_ARGS) + +{ + if(cpart->tmp) + *pixel_mode |= PMODE_GLOW; + return 0; +} + + +Element_DCEL::~Element_DCEL() {}
\ No newline at end of file |
