diff --git a/src/p_acs.cpp b/src/p_acs.cpp index f39a62ab98..a5cb221620 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4184,12 +4184,12 @@ bool DLevelScript::DoCheckActorTexture(int tid, AActor *activator, int string, b if (floor) { - actor->Sector->NextLowestFloorAt(actor, actor->Z(), 0, &resultsec, &resffloor); + actor->Sector->NextLowestFloorAt(actor->X(), actor->Y(), actor->Z(), 0, actor->MaxStepHeight, &resultsec, &resffloor); secpic = resffloor ? *resffloor->top.texture : resultsec->planes[sector_t::floor].Texture; } else { - actor->Sector->NextHighestCeilingAt(actor, actor->Top(), 0, &resultsec, &resffloor); + actor->Sector->NextHighestCeilingAt(actor->X(), actor->Y(), actor->Z(), actor->Top(), 0, &resultsec, &resffloor); secpic = resffloor ? *resffloor->bottom.texture : resultsec->planes[sector_t::ceiling].Texture; } return tex == TexMan[secpic]; diff --git a/src/p_map.cpp b/src/p_map.cpp index 433e9d5f3b..8c9b210555 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -290,7 +290,7 @@ void P_GetFloorCeilingZ(FCheckPosition &tmf, int flags) sector_t *sec = (!(flags & FFCF_SAMESECTOR) || tmf.thing->Sector == NULL)? P_PointInSector(tmf.x, tmf.y) : tmf.sector; F3DFloor *ffc, *fff; - tmf.ceilingz = sec->NextHighestCeilingAt(tmf.x, tmf.y, tmf.z + tmf.thing->height, flags, &tmf.ceilingsector, &ffc); + tmf.ceilingz = sec->NextHighestCeilingAt(tmf.x, tmf.y, tmf.z, tmf.z + tmf.thing->height, flags, &tmf.ceilingsector, &ffc); tmf.floorz = tmf.dropoffz = sec->NextLowestFloorAt(tmf.x, tmf.y, tmf.z, flags, tmf.thing->MaxStepHeight, &tmf.floorsector, &fff); if (fff) diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index d9cd733cb6..27c8493ea6 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -932,7 +932,7 @@ fixed_t sector_t::LowestFloorAt(fixed_t x, fixed_t y, sector_t **resultsec) } -fixed_t sector_t::NextHighestCeilingAt(fixed_t x, fixed_t y, fixed_t z, int flags, sector_t **resultsec, F3DFloor **resultffloor) +fixed_t sector_t::NextHighestCeilingAt(fixed_t x, fixed_t y, fixed_t bottomz, fixed_t topz, int flags, sector_t **resultsec, F3DFloor **resultffloor) { sector_t *sec = this; fixed_t planeheight = FIXED_MIN; @@ -943,14 +943,20 @@ fixed_t sector_t::NextHighestCeilingAt(fixed_t x, fixed_t y, fixed_t z, int flag fixed_t realceil = sec->ceilingplane.ZatPoint(x, y); for (int i = sec->e->XFloor.ffloors.Size() - 1; i >= 0; --i) { - F3DFloor *ff = sec->e->XFloor.ffloors[i]; + F3DFloor *rover = sec->e->XFloor.ffloors[i]; + if (!(rover->flags & FF_SOLID) || !(rover->flags & FF_EXISTS)) continue; - fixed_t ffz = ff->bottom.plane->ZatPoint(x, y); - if (ffz < realceil && ((ff->flags & (FF_EXISTS | FF_SOLID)) == (FF_EXISTS | FF_SOLID) && z <= ffz)) - { // This floor is above our eyes. + fixed_t ff_bottom = rover->bottom.plane->ZatPoint(x, y); + fixed_t ff_top = rover->top.plane->ZatPoint(x, y); + + fixed_t delta1 = bottomz - (ff_bottom + ((ff_top - ff_bottom) / 2)); + fixed_t delta2 = topz - (ff_bottom + ((ff_top - ff_bottom) / 2)); + + if (ff_bottom < realceil && abs(delta1) >= abs(delta2)) + { if (resultsec) *resultsec = sec; - if (resultffloor) *resultffloor = ff; - return ffz; + if (resultffloor) *resultffloor = rover; + return ff_bottom; } } if ((flags & FFCF_NOPORTALS) || sec->PortalBlocksMovement(ceiling) || planeheight >= sec->SkyBoxes[ceiling]->threshold) diff --git a/src/r_defs.h b/src/r_defs.h index 3e6574e561..d04afbf880 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -820,19 +820,9 @@ struct sector_t return LowestFloorAt(a->X(), a->Y(), resultsec); } - fixed_t NextHighestCeilingAt(fixed_t x, fixed_t y, fixed_t z, int flags = 0, sector_t **resultsec = NULL, F3DFloor **resultffloor = NULL); + fixed_t NextHighestCeilingAt(fixed_t x, fixed_t y, fixed_t bottomz, fixed_t topz, int flags = 0, sector_t **resultsec = NULL, F3DFloor **resultffloor = NULL); fixed_t NextLowestFloorAt(fixed_t x, fixed_t y, fixed_t z, int flags = 0, fixed_t steph = 0, sector_t **resultsec = NULL, F3DFloor **resultffloor = NULL); - fixed_t NextHighestCeilingAt(AActor *a, fixed_t z, int flags = 0, sector_t **resultsec = NULL, F3DFloor **resultffloor = NULL) - { - return NextHighestCeilingAt(a->X(), a->Y(), z, flags, resultsec, resultffloor); - } - - fixed_t NextLowestFloorAt(AActor *a, fixed_t z, int flags, sector_t **resultsec = NULL, F3DFloor **resultffloor = NULL) - { - return NextLowestFloorAt(a->X(), a->Y(), z, flags, a->MaxStepHeight, resultsec, resultffloor); - } - // Member variables fixed_t CenterFloor () const { return floorplane.ZatPoint (centerspot); } fixed_t CenterCeiling () const { return ceilingplane.ZatPoint (centerspot); }