Tweak raising/lowering (groups of) ceilings or floors.

Now, if more than one sectors are affected, always move them by the same
amount. That is, if one of them would be sticking against the other side,
don't move the rest.  Another change consists of determining the z delta
first, and only then moving the sprites by that amount. This fixes the
problem where you'd e.g. raise a 'floor door' against the ceiling, and the
effector sprites would be raised one time too much, preventing them from
being lowered the next time.

git-svn-id: https://svn.eduke32.com/eduke32@2111 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-11-11 20:05:44 +00:00
parent b2d789731a
commit b7834f21dd

View file

@ -5890,21 +5890,40 @@ static void Keys3d(void)
if (moveCeilings || moveFloors) if (moveCeilings || moveFloors)
{ {
int32_t dz = tsign * (updownunits << (eitherCTRL<<1)); // JBF 20031128
static const char *cfs[2] = { "ceiling", "floor" }; static const char *cfs[2] = { "ceiling", "floor" };
#ifdef YAX_ENABLE #ifdef YAX_ENABLE
int16_t bunchnum=-1, maxbunchnum=-1, cb, fb; int16_t bunchnum=-1, maxbunchnum=-1, cb, fb;
Bmemset(havebunch, 0, sizeof(havebunch)); Bmemset(havebunch, 0, sizeof(havebunch));
#endif #endif
for (j=0; j<(k?k:1); j++, sect=highlightsector[j])
{
// stage one: see if we don't move beyond the other side
// (ceiling if floor and vice versa)
if (moveCeilings && (dz > 0) && sector[sect].ceilingz+dz > sector[sect].floorz)
dz = (k<=1) ? 0 : min(sector[sect].floorz - sector[sect].ceilingz, dz);
else if (moveFloors && (dz < 0) && sector[sect].floorz+dz < sector[sect].ceilingz)
dz = (k<=1) ? 0 : max(sector[sect].ceilingz - sector[sect].floorz, dz);
if (dz == 0)
break;
}
if (dz)
{
// now truly move things if we're clear to go!
sect = sect0;
for (j=0; j<(k?k:1); j++, sect=highlightsector[j]) for (j=0; j<(k?k:1); j++, sect=highlightsector[j])
{ {
for (i=headspritesect[sect]; i!=-1; i=nextspritesect[i]) for (i=headspritesect[sect]; i!=-1; i=nextspritesect[i])
{ {
spriteoncfz(i, &cz, &fz); spriteoncfz(i, &cz, &fz);
if ((moveCeilings && sprite[i].z == cz) || (moveFloors && sprite[i].z == fz)) if ((moveCeilings && sprite[i].z == cz) || (moveFloors && sprite[i].z == fz))
sprite[i].z += tsign * (updownunits << (eitherCTRL<<1)); // JBF 20031128 sprite[i].z += dz;
} }
SECTORFLD(sect,z, moveFloors) += tsign * (updownunits << (eitherCTRL<<1)); // JBF 20031128 SECTORFLD(sect,z, moveFloors) += dz;
#ifdef YAX_ENABLE #ifdef YAX_ENABLE
bunchnum = yax_getbunch(sect, moveFloors); bunchnum = yax_getbunch(sect, moveFloors);
if (bunchnum >= 0 && !(havebunch[bunchnum>>3]&(1<<(bunchnum&7)))) if (bunchnum >= 0 && !(havebunch[bunchnum>>3]&(1<<(bunchnum&7))))
@ -5915,16 +5934,11 @@ static void Keys3d(void)
} }
#endif #endif
} }
if (k<=1 && sector[sect0].floorz < sector[sect0].ceilingz)
{
if (moveFloors)
sector[sect0].floorz = sector[sect0].ceilingz;
else
sector[sect0].ceilingz = sector[sect0].floorz;
} }
#ifdef YAX_ENABLE #ifdef YAX_ENABLE
if (dz)
{
// sync z values of extended sectors' ceilings/floors // sync z values of extended sectors' ceilings/floors
for (i=0; i<numsectors; i++) for (i=0; i<numsectors; i++)
{ {
@ -5934,16 +5948,19 @@ static void Keys3d(void)
if (fb >= 0 && (havebunch[fb>>3]&(1<<(fb&7)))) if (fb >= 0 && (havebunch[fb>>3]&(1<<(fb&7))))
sector[i].floorz = *tempzar[fb]; sector[i].floorz = *tempzar[fb];
} }
}
if (k==0 && bunchnum>=0) if (!dz)
silentmessage("Didn't move sector %ss", cfs[moveFloors]);
else if (k<=1 && bunchnum>=0)
silentmessage("Bunch %d's ceilings and floors = %d", bunchnum, SECTORFLD(sect0,z, moveFloors)); silentmessage("Bunch %d's ceilings and floors = %d", bunchnum, SECTORFLD(sect0,z, moveFloors));
else else
#endif #endif
if (k==0) if (k<=1)
silentmessage("Sector %d %sz = %d", sect0, cfs[moveFloors], SECTORFLD(sect0,z, moveFloors)); silentmessage("Sector %d %sz = %d", sect0, cfs[moveFloors], SECTORFLD(sect0,z, moveFloors));
else else
silentmessage("%s %d sector %ss by %d units", tsign<0 ? "Raised" : "Lowered", silentmessage("%s %d sector %ss by %d units", tsign<0 ? "Raised" : "Lowered",
k, cfs[moveFloors], (updownunits << (eitherCTRL<<1))); k, cfs[moveFloors], dz*tsign);
} }
if (AIMING_AT_SPRITE) if (AIMING_AT_SPRITE)