Restore old SOAP foam behaviour and make it work with nonstandard gravity.

This commit is contained in:
Saveliy Skresanov 2024-01-09 23:59:31 +07:00
parent 1dc641d13f
commit 9a05e56f15
3 changed files with 21 additions and 10 deletions

View File

@ -1365,14 +1365,6 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
return 0;
}
break;
// SOAP slowly floats up inside OIL
case PT_SOAP:
if (parts[i].type == PT_OIL)
{
if (rng.chance(19, 20) || std::abs(parts[i].x - nx) > 3 || std::abs(parts[i].y - ny) > 3)
return 0;
}
break;
}
switch (parts[i].type)

View File

@ -233,8 +233,6 @@ void SimulationData::init_can_move()
can_move[PT_THDR][PT_THDR] = 2;
can_move[PT_EMBR][PT_EMBR] = 2;
can_move[PT_TRON][PT_SWCH] = 3;
can_move[PT_SOAP][PT_OIL] = 0;
can_move[PT_OIL][PT_SOAP] = 1;
}
const CustomGOLData *SimulationData::GetCustomGOLByRule(int rule) const

View File

@ -243,6 +243,27 @@ static int update(UPDATE_FUNC_ARGS)
parts[i].ctype = 1;
parts[i].life = 10;
}
//SOAP+OIL foam effect
for (auto rx=-2; rx<3; rx++)
for (auto ry=-2; ry<3; ry++)
if (rx || ry)
{
auto r = pmap[y+ry][x+rx];
if (!r)
continue;
if (TYP(r) == PT_OIL)
{
float ax, ay, gx, gy;
sim->GetGravityField(x, y, elements[PT_SOAP].Gravity, 1.0f, gx, gy);
ax = ((parts[i].vx-gx)*0.5f + parts[ID(r)].vx)/2;
ay = ((parts[i].vy-gy)*0.5f + parts[ID(r)].vy)/2;
parts[i].vx = parts[ID(r)].vx = ax;
parts[i].vy = parts[ID(r)].vy = ay;
}
}
}
for (auto rx = -2; rx <= 2; rx++)
{