diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 39b2e34c4..1243ea00d 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -1665,10 +1665,10 @@ char * GameSave::serialiseOPS(int & dataLength) { fieldDesc |= 1 << 10; partsData[partsDataLen++] = particles[i].tmp2; - if(partsptr[i].tmp2 > 255) + if(particles[i].tmp2 > 255) { fieldDesc |= 1 << 11; - partsData[partsDataLen++] = partsptr[i].tmp2 >> 8; + partsData[partsDataLen++] = particles[i].tmp2 >> 8; } } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 9a347e828..9117fd003 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2875,6 +2875,28 @@ int Simulation::create_part(int p, int x, int y, int tv)//the function for creat return i; } +void Simulation::GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY) +{ + pGravX = newtonGrav*gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]; + pGravY = newtonGrav*gravy[(y/CELL)*(XRES/CELL)+(x/CELL)]; + switch (gravityMode) + { + default: + case 0: //normal, vertical gravity + pGravY += particleGrav; + break; + case 1: //no gravity + break; + case 2: //radial gravity + if (x-XCNTR != 0 || y-YCNTR != 0) + { + float pGravMult = particleGrav/sqrtf((x-XCNTR)*(x-XCNTR) + (y-YCNTR)*(y-YCNTR)); + pGravX -= pGravMult * (float)(x - XCNTR); + pGravY -= pGravMult * (float)(y - YCNTR); + } + } +} + void Simulation::create_gain_photon(int pp)//photons from PHOT going through GLOW { float xx, yy; diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index b47fde6d4..60a010ce5 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -179,6 +179,8 @@ public: void ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL); void ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode); + void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY); + void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate); inline void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]); inline void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]); diff --git a/src/simulation/elements/FIRW.cpp b/src/simulation/elements/FIRW.cpp index 9be26dddd..b9ec468b9 100644 --- a/src/simulation/elements/FIRW.cpp +++ b/src/simulation/elements/FIRW.cpp @@ -13,11 +13,11 @@ Element_FIRW::Element_FIRW() MenuSection = SC_EXPLOSIVE; Enabled = 1; - Advection = 0.7f; + Advection = 0.4f; AirDrag = 0.02f * CFDS; AirLoss = 0.96f; - Loss = 0.80f; - Collision = -0.99f; + Loss = 0.95f; + Collision = -0.5f; Gravity = 0.1f; Diffusion = 0.00f; HotAir = 0.000f * CFDS; @@ -65,8 +65,19 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS) 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()%40+60; + 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; } } } @@ -74,8 +85,7 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS) if (parts[i].life<=0) { parts[i].tmp=2; } else { - // TODO: different gravity modes + Newtonian gravity - parts[i].vy = -parts[i].life*0.04f - 0.1f; + parts[i].flags &= ~FLAG_STAGNANT; } } else if (parts[i].tmp>=2) @@ -91,8 +101,8 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS) { 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].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; diff --git a/src/simulation/elements/FWRK.cpp b/src/simulation/elements/FWRK.cpp index ddbb8c96f..6889f91df 100644 --- a/src/simulation/elements/FWRK.cpp +++ b/src/simulation/elements/FWRK.cpp @@ -50,22 +50,42 @@ Element_FWRK::Element_FWRK() int Element_FWRK::update(UPDATE_FUNC_ARGS) { int r, rx, ry, np; - if ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&parts[i].life==0&&!pmap[y-1][x])||parts[i].ctype==PT_DUST) + if (parts[i].life==0 && ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&surround_space)||parts[i].ctype==PT_DUST)) { - np = sim->create_part(-1, x , y-1 , PT_FWRK); - if (np!=-1) + 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) { - parts[np].vy = rand()%8-22; - parts[np].vx = rand()%20-rand()%20; - parts[np].life=rand()%15+25; - parts[np].dcolour = parts[i].dcolour; - sim->kill_part(i); - return 1; + 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 = fmaxf(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)||(parts[i].vy>6&&parts[i].life>0)) + if (parts[i].life<3&&parts[i].life>0) { int r = (rand()%245+11); int g = (rand()%245+11); @@ -80,8 +100,8 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS) { 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].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;