diff --git a/src/simulation/elements/BANG.cpp b/src/simulation/elements/BANG.cpp index d2441caa3..2dc660a6c 100644 --- a/src/simulation/elements/BANG.cpp +++ b/src/simulation/elements/BANG.cpp @@ -106,8 +106,8 @@ int Element_BANG::update(UPDATE_FUNC_ARGS) { if(!(rand()%15)) { - sim->create_part(i, x, y, PT_BOMB); - parts[i].tmp = 1; + 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; diff --git a/src/simulation/elements/BOMB.cpp b/src/simulation/elements/BOMB.cpp index ccf56bd09..b170cc25d 100644 --- a/src/simulation/elements/BOMB.cpp +++ b/src/simulation/elements/BOMB.cpp @@ -50,65 +50,53 @@ Element_BOMB::Element_BOMB() int Element_BOMB::update(UPDATE_FUNC_ARGS) { int r, rx, ry, nb; - //Spark is used so much now that it should be a seperate element. - if (parts[i].tmp==1) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (x+rx>=0 && y+ry>0 && x+rx=0 && y+ry>0 && x+rxelements[r&0xFF].Properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID)) && !(sim->elements[r&0xFF].Properties & PROP_SPARKSETTLE)) { - sim->kill_part(i); - return 1; - } - } - } else if (parts[i].tmp==0) { - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (x+rx>=0 && y+ry>0 && x+rxdelete_part(x+nxi, y+nxj, 0);//it SHOULD kill anything but the exceptions above, doesn't seem to always work - sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f; - nb = sim->create_part(-1, x+nxi, y+nxj, PT_BOMB); - 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) { - nb = sim->create_part(-1, x+nxi, y+nxj, PT_BOMB); - if (nb!=-1) { - parts[nb].tmp = 1; - parts[nb].life = 50; + 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(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(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) + { + sim->delete_part(x+nxi, y+nxj, 0); + 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; - parts[nb].vx = rand()%20-10; - parts[nb].vy = rand()%20-10; } } - //CreateParts(x, y, 9, 9, PT_BOMB); - //CreateParts(x, y, 8, 8, PT_NONE); - sim->kill_part(i); - return 1; - } + for (nxj=-(rad+1); nxj<=(rad+1); nxj++) + for (nxi=-(rad+1); nxi<=(rad+1); nxi++) + if ((pow(nxi,2))/(pow((rad+1),2))+(pow(nxj,2))/(pow((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; } @@ -117,23 +105,8 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS) int Element_BOMB::graphics(GRAPHICS_FUNC_ARGS) { - if (cpart->tmp==0) { - //Normal bomb - *pixel_mode |= PMODE_FLARE; - } - else if(cpart->tmp==2) - { - //Flash - *pixel_mode = PMODE_FLAT | FIRE_ADD; - *colr = *colg = *colb = *firer = *fireg = *fireb = *firea = 255; - } - else - { - //Flying spark - *pixel_mode = PMODE_SPARK | PMODE_ADD; - *cola = 4*cpart->life; - } - return 0; + *pixel_mode |= PMODE_FLARE; + return 1; } diff --git a/src/simulation/elements/EMBR.cpp b/src/simulation/elements/EMBR.cpp new file mode 100644 index 000000000..80c2c4e9c --- /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.7f; + 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+rxelements[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 (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/FWRK.cpp b/src/simulation/elements/FWRK.cpp index 66109f5ab..ddbb8c96f 100644 --- a/src/simulation/elements/FWRK.cpp +++ b/src/simulation/elements/FWRK.cpp @@ -67,33 +67,29 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS) parts[i].life=0; if ((parts[i].life<3&&parts[i].life>0)||(parts[i].vy>6&&parts[i].life>0)) { - int q = (rand()%255+1); - int w = (rand()%255+1); - int e = (rand()%255+1); - for (rx=-1; rx<2; rx++) - for (ry=-2; ry<3; ry++) - if (x+rx>=0 && y+ry>0 && x+rx=rand()%8) - { - if (!pmap[y+ry][x+rx]) - { - np = sim->create_part(-1, x+rx, y+ry , PT_DUST); - sim->pv[y/CELL][x/CELL] += 2.00f*CFDS; - if (np!=-1) - { - parts[np].vy = -(rand()%10-1); - parts[np].vx = ((rand()%2)*2-1)*rand()%(5+5)+(parts[i].vx)*2 ; - parts[np].life= rand()%37+18; - parts[np].tmp=q; - parts[np].tmp2=w; - parts[np].ctype=e; - parts[np].temp= rand()%20+6000; - parts[np].dcolour = parts[i].dcolour; - } - } - } - } + 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 + cosf(angle)*magnitude; + parts[np].vy = parts[i].vy + sinf(angle)*magnitude - 2.5f; + 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; }