- changed parameters of several modern action functions.

This commit is contained in:
Christoph Oelckers 2021-11-23 22:28:19 +01:00
parent 759a8428fa
commit 063e3fb34e
4 changed files with 56 additions and 59 deletions

View file

@ -217,12 +217,6 @@ inline double PointOnLineSide(const TVector2<T>& pos, const TVector2<T>& linesta
return (pos.X - linestart.X) * (lineend.Y - linestart.Y) - (pos.Y - linestart.Y) * (lineend.X - linestart.X); return (pos.X - linestart.X) * (lineend.Y - linestart.Y) - (pos.Y - linestart.Y) * (lineend.X - linestart.X);
} }
inline int sectorofwall(int wallNum)
{
if ((unsigned)wallNum < (unsigned)numwalls) return wall[wallNum].sector;
return -1;
}
extern int numshades; extern int numshades;
// Return type is int because this gets passed to variadic functions where structs may produce undefined behavior. // Return type is int because this gets passed to variadic functions where structs may produce undefined behavior.

View file

@ -212,8 +212,8 @@ void DrawMirrors(int x, int y, int z, fixed_t a, fixed_t horiz, int smooth, int
numwalls += 4; // hack alert. Blood adds some dummy walls and sectors that must not be among the counter, but here they have to be valid. numwalls += 4; // hack alert. Blood adds some dummy walls and sectors that must not be among the counter, but here they have to be valid.
numsectors++; numsectors++;
int nWall = mirror[i].link; int nWall = mirror[i].link;
int nSector = sectorofwall(nWall);
walltype* pWall = &wall[nWall]; walltype* pWall = &wall[nWall];
int nSector = pWall->sector;
int nNextWall = pWall->nextwall; int nNextWall = pWall->nextwall;
int nNextSector = pWall->nextsector; int nNextSector = pWall->nextsector;
pWall->nextwall = mirrorwall[0]; pWall->nextwall = mirrorwall[0];

View file

@ -33,7 +33,7 @@ BEGIN_BLD_NS
int mirrorcnt, mirrorsector, mirrorwall[4]; int mirrorcnt, mirrorsector, mirrorwall[4];
MIRROR mirror[16]; MIRROR mirror[16]; // only needed by Polymost.
void InitMirrors(void) void InitMirrors(void)
{ {
@ -74,7 +74,7 @@ void InitMirrors(void)
{ {
if (tmp != pWallj->xw().data) if (tmp != pWallj->xw().data)
continue; continue;
pWalli->hitag = j; pWalli->hitag = j; // hitag is only used by Polymost, the new renderer uses external links.
pWallj->hitag = i; pWallj->hitag = i;
mirror[mirrorcnt].link = j; mirror[mirrorcnt].link = j;
break; break;
@ -118,8 +118,11 @@ void InitMirrors(void)
auto link2 = link->GetOwner(); auto link2 = link->GetOwner();
if (link2 == nullptr) if (link2 == nullptr)
continue; continue;
auto secti = &sector[i];
int j = link2->s().sectnum; int j = link2->s().sectnum;
if (sector[j].ceilingpicnum != 504) auto sectj = link2->s().sector();
if (sectj->ceilingpicnum != 504)
I_Error("Lower link sector %d doesn't have mirror picnum\n", j); I_Error("Lower link sector %d doesn't have mirror picnum\n", j);
mirror[mirrorcnt].type = 2; mirror[mirrorcnt].type = 2;
mirror[mirrorcnt].dx = link2->s().x - link->s().x; mirror[mirrorcnt].dx = link2->s().x - link->s().x;
@ -127,9 +130,9 @@ void InitMirrors(void)
mirror[mirrorcnt].dz = link2->s().z - link->s().z; mirror[mirrorcnt].dz = link2->s().z - link->s().z;
mirror[mirrorcnt].wallnum = i; mirror[mirrorcnt].wallnum = i;
mirror[mirrorcnt].link = j; mirror[mirrorcnt].link = j;
sector[i].floorpicnum = 4080 + mirrorcnt; secti->floorpicnum = 4080 + mirrorcnt;
sector[i].portalflags = PORTAL_SECTOR_FLOOR; secti->portalflags = PORTAL_SECTOR_FLOOR;
sector[i].portalnum = portalAdd(PORTAL_SECTOR_FLOOR, j, mirror[mirrorcnt].dx, mirror[mirrorcnt].dy, mirror[mirrorcnt].dz); secti->portalnum = portalAdd(PORTAL_SECTOR_FLOOR, j, mirror[mirrorcnt].dx, mirror[mirrorcnt].dy, mirror[mirrorcnt].dz);
mirrorcnt++; mirrorcnt++;
mirror[mirrorcnt].type = 1; mirror[mirrorcnt].type = 1;
mirror[mirrorcnt].dx = link->s().x - link2->s().x; mirror[mirrorcnt].dx = link->s().x - link2->s().x;
@ -137,9 +140,9 @@ void InitMirrors(void)
mirror[mirrorcnt].dz = link->s().z - link2->s().z; mirror[mirrorcnt].dz = link->s().z - link2->s().z;
mirror[mirrorcnt].wallnum = j; mirror[mirrorcnt].wallnum = j;
mirror[mirrorcnt].link = i; mirror[mirrorcnt].link = i;
sector[j].ceilingpicnum = 4080 + mirrorcnt; sectj->ceilingpicnum = 4080 + mirrorcnt;
sector[j].portalflags = PORTAL_SECTOR_CEILING; sectj->portalflags = PORTAL_SECTOR_CEILING;
sector[j].portalnum = portalAdd(PORTAL_SECTOR_CEILING, i, mirror[mirrorcnt].dx, mirror[mirrorcnt].dy, mirror[mirrorcnt].dz); sectj->portalnum = portalAdd(PORTAL_SECTOR_CEILING, i, mirror[mirrorcnt].dx, mirror[mirrorcnt].dy, mirror[mirrorcnt].dz);
mirrorcnt++; mirrorcnt++;
} }
} }

View file

@ -2469,24 +2469,25 @@ void trPlayerCtrlUsePowerup(DBloodActor* sourceactor, PLAYER* pPlayer, int evCmd
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void useObjResizer(DBloodActor* sourceactor, int targType, int targIndex, DBloodActor* targetactor) void useObjResizer(DBloodActor* sourceactor, int targType, sectortype* targSect, walltype* targWall, DBloodActor* targetactor)
{ {
auto pXSource = &sourceactor->x(); auto pXSource = &sourceactor->x();
switch (targType) switch (targType)
{ {
// for sectors // for sectors
case OBJ_SECTOR: case OBJ_SECTOR:
if (!targSect) return;
if (valueIsBetween(pXSource->data1, -1, 32767)) if (valueIsBetween(pXSource->data1, -1, 32767))
sector[targIndex].floorxpan_ = (float)ClipRange(pXSource->data1, 0, 255); targSect->floorxpan_ = (float)ClipRange(pXSource->data1, 0, 255);
if (valueIsBetween(pXSource->data2, -1, 32767)) if (valueIsBetween(pXSource->data2, -1, 32767))
sector[targIndex].floorypan_ = (float)ClipRange(pXSource->data2, 0, 255); targSect->floorypan_ = (float)ClipRange(pXSource->data2, 0, 255);
if (valueIsBetween(pXSource->data3, -1, 32767)) if (valueIsBetween(pXSource->data3, -1, 32767))
sector[targIndex].ceilingxpan_ = (float)ClipRange(pXSource->data3, 0, 255); targSect->ceilingxpan_ = (float)ClipRange(pXSource->data3, 0, 255);
if (valueIsBetween(pXSource->data4, -1, 65535)) if (valueIsBetween(pXSource->data4, -1, 65535))
sector[targIndex].ceilingypan_ = (float)ClipRange(pXSource->data4, 0, 255); targSect->ceilingypan_ = (float)ClipRange(pXSource->data4, 0, 255);
break; break;
// for sprites // for sprites
case OBJ_SPRITE: case OBJ_SPRITE:
@ -2542,18 +2543,18 @@ void useObjResizer(DBloodActor* sourceactor, int targType, int targIndex, DBlood
break; break;
} }
case OBJ_WALL: case OBJ_WALL:
auto pWall = &wall[targIndex]; if (!targWall) return;
if (valueIsBetween(pXSource->data1, -1, 32767)) if (valueIsBetween(pXSource->data1, -1, 32767))
pWall->xrepeat = ClipRange(pXSource->data1, 0, 255); targWall->xrepeat = ClipRange(pXSource->data1, 0, 255);
if (valueIsBetween(pXSource->data2, -1, 32767)) if (valueIsBetween(pXSource->data2, -1, 32767))
pWall->yrepeat = ClipRange(pXSource->data2, 0, 255); targWall->yrepeat = ClipRange(pXSource->data2, 0, 255);
if (valueIsBetween(pXSource->data3, -1, 32767)) if (valueIsBetween(pXSource->data3, -1, 32767))
pWall->xpan_ = (float)ClipRange(pXSource->data3, 0, 255); targWall->xpan_ = (float)ClipRange(pXSource->data3, 0, 255);
if (valueIsBetween(pXSource->data4, -1, 65535)) if (valueIsBetween(pXSource->data4, -1, 65535))
pWall->ypan_ = (float)ClipRange(pXSource->data4, 0, 255); targWall->ypan_ = (float)ClipRange(pXSource->data4, 0, 255);
break; break;
} }
} }
@ -2564,7 +2565,7 @@ void useObjResizer(DBloodActor* sourceactor, int targType, int targIndex, DBlood
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, DBloodActor* targetactor) void usePropertiesChanger(DBloodActor* sourceactor, int objType, sectortype* pSector, walltype* pWall, DBloodActor* targetactor)
{ {
auto pXSource = &sourceactor->x(); auto pXSource = &sourceactor->x();
spritetype* pSource = &sourceactor->s(); spritetype* pSource = &sourceactor->s();
@ -2573,7 +2574,8 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
{ {
case OBJ_WALL: case OBJ_WALL:
{ {
walltype* pWall = &wall[objIndex]; int old = -1; if (!pWall) return;
int old = -1;
// data3 = set wall hitag // data3 = set wall hitag
if (valueIsBetween(pXSource->data3, -1, 32767)) if (valueIsBetween(pXSource->data3, -1, 32767))
@ -2843,7 +2845,7 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
break; break;
case OBJ_SECTOR: case OBJ_SECTOR:
{ {
sectortype* pSector = &sector[objIndex]; if (!pSector) return;
XSECTOR* pXSector = &pSector->xs(); XSECTOR* pXSector = &pSector->xs();
// data1 = sector underwater status and depth level // data1 = sector underwater status and depth level
@ -2854,7 +2856,7 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
spritetype* pUpper = NULL; XSPRITE* pXUpper = NULL; spritetype* pUpper = NULL; XSPRITE* pXUpper = NULL;
auto aLower = getLowerLink(objIndex); auto aLower = pSector->lowerLink;
spritetype* pLower = nullptr; spritetype* pLower = nullptr;
XSPRITE* pXLower = nullptr; XSPRITE* pXLower = nullptr;
if (aLower) if (aLower)
@ -2863,9 +2865,9 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
pXLower = &aLower->x(); pXLower = &aLower->x();
// must be sure we found exact same upper link // must be sure we found exact same upper link
for (int i = 0; i < numsectors; i++) for (auto& sec : sectors())
{ {
auto aUpper = getUpperLink(i); auto aUpper = sec.upperLink;
if (aUpper == nullptr || aUpper->x().data1 != pXLower->data1) continue; if (aUpper == nullptr || aUpper->x().data1 != pXLower->data1) continue;
pUpper = &aUpper->s(); pUpper = &aUpper->s();
pXUpper = &aUpper->x(); pXUpper = &aUpper->x();
@ -2919,7 +2921,7 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
} }
// search for dudes in this sector and change their underwater status // search for dudes in this sector and change their underwater status
BloodSectIterator it(objIndex); BloodSectIterator it(pSector);
while (auto iactor = it.Next()) while (auto iactor = it.Next())
{ {
spritetype* pSpr = &iactor->s(); spritetype* pSpr = &iactor->s();
@ -2965,18 +2967,18 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
// data2 = sector visibility // data2 = sector visibility
if (valueIsBetween(pXSource->data2, -1, 32767)) if (valueIsBetween(pXSource->data2, -1, 32767))
sector[objIndex].visibility = ClipRange(pXSource->data2, 0 , 234); pSector->visibility = ClipRange(pXSource->data2, 0 , 234);
// data3 = sector ceil cstat // data3 = sector ceil cstat
if (valueIsBetween(pXSource->data3, -1, 32767)) { if (valueIsBetween(pXSource->data3, -1, 32767)) {
if ((pSource->flags & kModernTypeFlag1)) sector[objIndex].ceilingstat |= pXSource->data3; if ((pSource->flags & kModernTypeFlag1)) pSector->ceilingstat |= pXSource->data3;
else sector[objIndex].ceilingstat = pXSource->data3; else pSector->ceilingstat = pXSource->data3;
} }
// data4 = sector floor cstat // data4 = sector floor cstat
if (valueIsBetween(pXSource->data4, -1, 65535)) { if (valueIsBetween(pXSource->data4, -1, 65535)) {
if ((pSource->flags & kModernTypeFlag1)) sector[objIndex].floorstat |= pXSource->data4; if ((pSource->flags & kModernTypeFlag1)) pSector->floorstat |= pXSource->data4;
else sector[objIndex].floorstat = pXSource->data4; else pSector->floorstat = pXSource->data4;
} }
} }
break; break;
@ -3317,12 +3319,12 @@ void useSectorWindGen(DBloodActor* sourceactor, sectortype* pSector)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void useSpriteDamager(DBloodActor* sourceactor, int objType, int objIndex, DBloodActor* targetactor) void useSpriteDamager(DBloodActor* sourceactor, int objType, sectortype* targSect, DBloodActor* targetactor)
{ {
auto pSource = &sourceactor->s(); auto pSource = &sourceactor->s();
auto pXSource = &sourceactor->x(); auto pXSource = &sourceactor->x();
sectortype* pSector = &sector[pSource->sectnum]; sectortype* pSector = pSource->sector();
int top, bottom; int top, bottom;
bool floor, ceil, wall, enter; bool floor, ceil, wall, enter;
@ -3339,7 +3341,7 @@ void useSpriteDamager(DBloodActor* sourceactor, int objType, int objIndex, DBloo
ceil = (top <= pSector->ceilingz); ceil = (top <= pSector->ceilingz);
wall = (pSource->cstat & 0x10); wall = (pSource->cstat & 0x10);
enter = (!floor && !ceil && !wall); enter = (!floor && !ceil && !wall);
BloodSectIterator it(objIndex); BloodSectIterator it(targSect);
while (auto iactor = it.Next()) while (auto iactor = it.Next())
{ {
auto& hit = iactor->hit; auto& hit = iactor->hit;
@ -3348,11 +3350,11 @@ void useSpriteDamager(DBloodActor* sourceactor, int objType, int objIndex, DBloo
continue; continue;
else if (enter) else if (enter)
damageSprites(sourceactor, iactor); damageSprites(sourceactor, iactor);
else if (floor && hit.florhit.type == kHitSector && hit.florhit.index == objIndex) else if (floor && hit.florhit.type == kHitSector && hit.florhit.sector() == targSect)
damageSprites(sourceactor, iactor); damageSprites(sourceactor, iactor);
else if (ceil && hit.ceilhit.type == kHitSector && hit.ceilhit.index == objIndex) else if (ceil && hit.ceilhit.type == kHitSector && hit.ceilhit.sector() == targSect)
damageSprites(sourceactor, iactor); damageSprites(sourceactor, iactor);
else if (wall && hit.hit.type == kHitWall && sectorofwall(hit.hit.index) == objIndex) else if (wall && hit.hit.type == kHitWall && hit.hit.wall()->sectorp() == targSect)
damageSprites(sourceactor, iactor); damageSprites(sourceactor, iactor);
} }
break; break;
@ -3501,7 +3503,7 @@ void damageSprites(DBloodActor* sourceactor, DBloodActor* actor)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void useSeqSpawnerGen(DBloodActor* sourceactor, int objType, int index, DBloodActor* iactor) void useSeqSpawnerGen(DBloodActor* sourceactor, int objType, sectortype* pSector, walltype* pWall, DBloodActor* iactor)
{ {
auto pXSource = &sourceactor->x(); auto pXSource = &sourceactor->x();
if (pXSource->data2 > 0 && !getSequence(pXSource->data2)) if (pXSource->data2 > 0 && !getSequence(pXSource->data2))
@ -3516,7 +3518,6 @@ void useSeqSpawnerGen(DBloodActor* sourceactor, int objType, int index, DBloodAc
{ {
case OBJ_SECTOR: case OBJ_SECTOR:
{ {
auto pSector = &sector[index];
if (pXSource->data2 <= 0) if (pXSource->data2 <= 0)
{ {
if (pXSource->data3 == 3 || pXSource->data3 == 1) if (pXSource->data3 == 3 || pXSource->data3 == 1)
@ -3535,7 +3536,6 @@ void useSeqSpawnerGen(DBloodActor* sourceactor, int objType, int index, DBloodAc
} }
case OBJ_WALL: case OBJ_WALL:
{ {
auto pWall = &wall[index];
if (pXSource->data2 <= 0) if (pXSource->data2 <= 0)
{ {
if (pXSource->data3 == 3 || pXSource->data3 == 1) if (pXSource->data3 == 3 || pXSource->data3 == 1)
@ -3568,16 +3568,16 @@ void useSeqSpawnerGen(DBloodActor* sourceactor, int objType, int index, DBloodAc
int cx, cy, cz; int cx, cy, cz;
cx = (pWall->x + pWall->point2Wall()->x) >> 1; cx = (pWall->x + pWall->point2Wall()->x) >> 1;
cy = (pWall->y + pWall->point2Wall()->y) >> 1; cy = (pWall->y + pWall->point2Wall()->y) >> 1;
int nSector = sectorofwall(index); auto pMySector = pWall->sectorp();
int32_t ceilZ, floorZ; int32_t ceilZ, floorZ;
getzsofslope(nSector, cx, cy, &ceilZ, &floorZ); getzsofslopeptr(pSector, cx, cy, &ceilZ, &floorZ);
int32_t ceilZ2, floorZ2; int32_t ceilZ2, floorZ2;
getzsofslope(pWall->nextsector, cx, cy, &ceilZ2, &floorZ2); getzsofslopeptr(pWall->nextSector(), cx, cy, &ceilZ2, &floorZ2);
ceilZ = ClipLow(ceilZ, ceilZ2); ceilZ = ClipLow(ceilZ, ceilZ2);
floorZ = ClipHigh(floorZ, floorZ2); floorZ = ClipHigh(floorZ, floorZ2);
cz = (ceilZ + floorZ) >> 1; cz = (ceilZ + floorZ) >> 1;
sfxPlay3DSound(cx, cy, cz, pXSource->data4, nSector); sfxPlay3DSound(cx, cy, cz, pXSource->data4, pSector);
} }
} }
return; return;
@ -4798,7 +4798,7 @@ void modernTypeTrigger(int destObjType, sectortype* destSect, walltype* destWall
{ {
case OBJ_SPRITE: case OBJ_SPRITE:
case OBJ_SECTOR: case OBJ_SECTOR:
useSpriteDamager(pActor, destObjType, destObjIndex, destactor); useSpriteDamager(pActor, destObjType, destSect, destactor);
break; break;
} }
break; break;
@ -4809,7 +4809,7 @@ void modernTypeTrigger(int destObjType, sectortype* destSect, walltype* destWall
break; break;
// takes data2 as SEQ ID and spawns it on it's or TX ID object // takes data2 as SEQ ID and spawns it on it's or TX ID object
case kModernSeqSpawner: case kModernSeqSpawner:
useSeqSpawnerGen(pActor, destObjType, destObjIndex, destactor); useSeqSpawnerGen(pActor, destObjType, destSect, destWall, destactor);
break; break;
// creates wind on TX ID sector // creates wind on TX ID sector
case kModernWindGenerator: case kModernWindGenerator:
@ -4818,7 +4818,7 @@ void modernTypeTrigger(int destObjType, sectortype* destSect, walltype* destWall
break; break;
// size and pan changer of sprite/wall/sector via TX ID // size and pan changer of sprite/wall/sector via TX ID
case kModernObjSizeChanger: case kModernObjSizeChanger:
useObjResizer(pActor, destObjType, destObjIndex, destactor); useObjResizer(pActor, destObjType, destSect, destWall, destactor);
break; break;
// iterate data filed value of destination object // iterate data filed value of destination object
case kModernObjDataAccumulator: case kModernObjDataAccumulator:
@ -4844,7 +4844,7 @@ void modernTypeTrigger(int destObjType, sectortype* destSect, walltype* destWall
break; break;
// change various properties // change various properties
case kModernObjPropertiesChanger: case kModernObjPropertiesChanger:
usePropertiesChanger(pActor, destObjType, destObjIndex, destactor); usePropertiesChanger(pActor, destObjType, destSect, destWall, destactor);
break; break;
// updated vanilla sound gen that now allows to play sounds on TX ID sprites // updated vanilla sound gen that now allows to play sounds on TX ID sprites
case kGenModernSound: case kGenModernSound:
@ -5611,8 +5611,8 @@ bool modernTypeOperateSprite(DBloodActor* actor, const EVENT& event)
[[fallthrough]]; [[fallthrough]];
case kCmdRepeat: case kCmdRepeat:
if (pXSprite->txID > 0) modernTypeSendCommand(actor, pXSprite->txID, (COMMAND_ID)pXSprite->command); if (pXSprite->txID > 0) modernTypeSendCommand(actor, pXSprite->txID, (COMMAND_ID)pXSprite->command);
else if (pXSprite->data1 == 0 && validSectorIndex(pSprite->sectnum)) useSpriteDamager(actor, OBJ_SECTOR, pSprite->sectnum, nullptr); else if (pXSprite->data1 == 0 && validSectorIndex(pSprite->sectnum)) useSpriteDamager(actor, OBJ_SECTOR, pSprite->sector(), nullptr);
else if (pXSprite->data1 >= 666 && pXSprite->data1 < 669) useSpriteDamager(actor, -1, -1, nullptr); else if (pXSprite->data1 >= 666 && pXSprite->data1 < 669) useSpriteDamager(actor, -1, nullptr, nullptr);
else else
{ {
PLAYER* pPlayer = getPlayerById(pXSprite->data1); PLAYER* pPlayer = getPlayerById(pXSprite->data1);
@ -5644,7 +5644,7 @@ bool modernTypeOperateSprite(DBloodActor* actor, const EVENT& event)
if (pXSprite->txID <= 0) if (pXSprite->txID <= 0)
{ {
if (SetSpriteState(actor, pXSprite->state ^ 1) == 1) if (SetSpriteState(actor, pXSprite->state ^ 1) == 1)
usePropertiesChanger(actor, -1, -1, nullptr); usePropertiesChanger(actor, -1, nullptr, nullptr, nullptr);
return true; return true;
} }
[[fallthrough]]; [[fallthrough]];
@ -5670,7 +5670,7 @@ bool modernTypeOperateSprite(DBloodActor* actor, const EVENT& event)
[[fallthrough]]; [[fallthrough]];
case kCmdRepeat: case kCmdRepeat:
if (pXSprite->txID > 0) modernTypeSendCommand(actor, pXSprite->txID, (COMMAND_ID)pXSprite->command); if (pXSprite->txID > 0) modernTypeSendCommand(actor, pXSprite->txID, (COMMAND_ID)pXSprite->command);
else if (pSprite->type == kModernSeqSpawner) useSeqSpawnerGen(actor, 3, 0, actor); else if (pSprite->type == kModernSeqSpawner) useSeqSpawnerGen(actor, OBJ_SPRITE, nullptr, nullptr, actor);
else useEffectGen(actor, nullptr); else useEffectGen(actor, nullptr);
if (pXSprite->busyTime > 0) if (pXSprite->busyTime > 0)