diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index f11a176e9..50e128861 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -181,7 +181,8 @@ void AddFlash(int nSector, int x, int y, int z, int val); void SetTorch(int nPlayer, int bTorchOnOff); void UndoFlashes(); void DoLights(); -void AddFlow(int nSprite, int nSpeed, int b, int ang = -1); +void AddFlow(sectortype* pSect, int nSpeed, int b, int ang = -1); +void AddFlow(walltype* pWall, int nSpeed, int b, int ang = -1); void BuildFlash(int nPlayer, int nVal); void AddGlow(int nSector, int nVal); void AddFlicker(int nSector, int nVal); @@ -292,7 +293,7 @@ void BuildDrip(DExhumedActor* nSprite); DExhumedActor* BuildEnergyBlock(int nSector); int BuildElevC(int arg1, int nChannel, int nSector, DExhumedActor* nWallSprite, int arg5, int arg6, int nCount, ...); int BuildElevF(int nChannel, int nSector, DExhumedActor* nWallSprite, int arg_4, int arg_5, int nCount, ...); -int BuildWallFace(int nChannel, int nWall, int nCount, ...); +int BuildWallFace(int nChannel, walltype* pWall, int nCount, ...); int BuildSlide(int nChannel, int edx, int ebx, int ecx, int arg1, int arg2, int arg3); // queen @@ -690,7 +691,7 @@ void runlist_ProcessSectorTag(int nSector, int nLotag, int nHitag); int runlist_AllocChannel(int a); void runlist_DoSubRunRec(int RunPtr); void runlist_SubRunRec(int RunPtr); -void runlist_ProcessWallTag(int nWall, int nLotag, int nHitag); +void runlist_ProcessWallTag(walltype* pWall, int nLotag, int nHitag); int runlist_CheckRadialDamage(DExhumedActor* actor); void runlist_RadialDamageEnemy(DExhumedActor* pActor, int nDamage, int nRadius); void runlist_DamageEnemy(DExhumedActor* nSprite, DExhumedActor* nSprite2, int nDamage); @@ -761,7 +762,7 @@ std::pair BuildSwPressSector(int nChannel, int nLink, int nSector, int std::pair BuildSwStepOn(int nChannel, int nLink, int nSector); std::pair BuildSwReady(int nChannel, int nLink); -std::pair BuildSwPressWall(int nChannel, int nLink, int nWall); +std::pair BuildSwPressWall(int nChannel, int nLink, walltype* pWall); // wasp diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index 573b0f330..68f113472 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -641,7 +641,7 @@ void ProcessSpriteTag(DExhumedActor* pActor, int nLotag, int nHitag) } case 88: { - AddFlow(pSprite->sectnum, nSpeed, 0, pSprite->ang); + AddFlow(pSprite->sector(), nSpeed, 0, pSprite->ang); DeleteActor(pActor); return; @@ -656,7 +656,7 @@ void ProcessSpriteTag(DExhumedActor* pActor, int nLotag, int nHitag) } case 78: { - AddFlow(pSprite->sectnum, nSpeed, 1, pSprite->ang); + AddFlow(pSprite->sector(), nSpeed, 1, pSprite->ang); auto pSector = pSprite->sector(); pSector->Flag |= 0x8000; @@ -810,7 +810,7 @@ void LoadObjects() if (hitag || lotag) { wal.lotag = runlist_HeadRun() + 1; - runlist_ProcessWallTag(wallnum(&wal), lotag, hitag); + runlist_ProcessWallTag(&wal, lotag, hitag); } } diff --git a/source/games/exhumed/src/lighting.cpp b/source/games/exhumed/src/lighting.cpp index a81ed6097..015fb34b4 100644 --- a/source/games/exhumed/src/lighting.cpp +++ b/source/games/exhumed/src/lighting.cpp @@ -62,7 +62,11 @@ struct Flicker struct Flow { - int objindex; + union + { + walltype* pWall; + sectortype* pSector; + }; int type; int xdelta; int ydelta; @@ -134,15 +138,16 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, Flow& w, Flow* def { if (arc.BeginObject(keyname)) { - arc("objindex", w.objindex) - ("type", w.type) + arc("type", w.type) ("xdelta", w.xdelta) ("ydelta", w.ydelta) ("atc", w.angcos) ("at10", w.angsin) ("xacc", w.xacc) - ("yacc", w.yacc) - .EndObject(); + ("yacc", w.yacc); + if (w.type < 2) arc("index", w.pSector); + else arc("index", w.pWall); + arc.EndObject(); } return arc; } @@ -646,52 +651,58 @@ void DoFlickers() } } -// nWall can also be passed in here via nSprite parameter - TODO - rename nSprite parameter :) -void AddFlow(int nIndex, int nSpeed, int b, int nAngle) +void AddFlow(sectortype* pSector, int nSpeed, int b, int nAngle) { - if (nFlowCount >= kMaxFlows) + if (nFlowCount >= kMaxFlows || b >= 2) + return; + + int nFlow = nFlowCount; + nFlowCount++; + + int nPic = pSector->floorpicnum; + + sFlowInfo[nFlow].xacc = (tileWidth(nPic) << 14) - 1; + sFlowInfo[nFlow].yacc = (tileHeight(nPic) << 14) - 1; + sFlowInfo[nFlow].angcos = -bcos(nAngle) * nSpeed; + sFlowInfo[nFlow].angsin = bsin(nAngle) * nSpeed; + sFlowInfo[nFlow].pSector = pSector; + + StartInterpolation(pSector, b ? Interp_Sect_CeilingPanX : Interp_Sect_FloorPanX); + StartInterpolation(pSector, b ? Interp_Sect_CeilingPanY : Interp_Sect_FloorPanY); + + sFlowInfo[nFlow].ydelta = 0; + sFlowInfo[nFlow].xdelta = 0; + sFlowInfo[nFlow].type = b; +} + + +void AddFlow(walltype* pWall, int nSpeed, int b, int nAngle) +{ + if (nFlowCount >= kMaxFlows || b < 2) return; int nFlow = nFlowCount; nFlowCount++; - if (b < 2) - { - int nPic = sector[nIndex].floorpicnum; + StartInterpolation(pWall, Interp_Wall_PanX); + StartInterpolation(pWall, Interp_Wall_PanY); - sFlowInfo[nFlow].xacc = (tileWidth(nPic) << 14) - 1; - sFlowInfo[nFlow].yacc = (tileHeight(nPic) << 14) - 1; - sFlowInfo[nFlow].angcos = -bcos(nAngle) * nSpeed; - sFlowInfo[nFlow].angsin = bsin(nAngle) * nSpeed; - sFlowInfo[nFlow].objindex = nIndex; - - StartInterpolation(nIndex, b ? Interp_Sect_CeilingPanX : Interp_Sect_FloorPanX); - StartInterpolation(nIndex, b ? Interp_Sect_CeilingPanY : Interp_Sect_FloorPanY); + if (b == 2) { + nAngle = 512; } - else - { - StartInterpolation(nIndex, Interp_Wall_PanX); - StartInterpolation(nIndex, Interp_Wall_PanY); - - int nAngle; - - if (b == 2) { - nAngle = 512; - } - else { - nAngle = 1536; - } - - int nPic = wall[nIndex].picnum; - - sFlowInfo[nFlow].xacc = (tileWidth(nPic) * wall[nIndex].xrepeat) << 8; - sFlowInfo[nFlow].yacc = (tileHeight(nPic) * wall[nIndex].yrepeat) << 8; - sFlowInfo[nFlow].angcos = -bcos(nAngle) * nSpeed; - sFlowInfo[nFlow].angsin = bsin(nAngle) * nSpeed; - sFlowInfo[nFlow].objindex = nIndex; + else { + nAngle = 1536; } + int nPic = pWall->picnum; + + sFlowInfo[nFlow].xacc = (tileWidth(nPic) * pWall->xrepeat) << 8; + sFlowInfo[nFlow].yacc = (tileHeight(nPic) * pWall->yrepeat) << 8; + sFlowInfo[nFlow].angcos = -bcos(nAngle) * nSpeed; + sFlowInfo[nFlow].angsin = bsin(nAngle) * nSpeed; + sFlowInfo[nFlow].pWall = pWall; + sFlowInfo[nFlow].ydelta = 0; sFlowInfo[nFlow].xdelta = 0; sFlowInfo[nFlow].type = b; @@ -711,18 +722,18 @@ void DoFlows() sFlowInfo[i].xdelta &= sFlowInfo[i].xacc; sFlowInfo[i].ydelta &= sFlowInfo[i].yacc; - int nSector =sFlowInfo[i].objindex; - sector[nSector].setfloorxpan(sFlowInfo[i].xdelta / 16384.f); - sector[nSector].setfloorypan(sFlowInfo[i].ydelta / 16384.f); + auto pSector =sFlowInfo[i].pSector; + pSector->setfloorxpan(sFlowInfo[i].xdelta / 16384.f); + pSector->setfloorypan(sFlowInfo[i].ydelta / 16384.f); break; } case 1: { - int nSector =sFlowInfo[i].objindex; + auto pSector = sFlowInfo[i].pSector; - sector[nSector].setceilingxpan(sFlowInfo[i].xdelta / 16384.f); - sector[nSector].setceilingypan(sFlowInfo[i].ydelta / 16384.f); + pSector->setceilingxpan(sFlowInfo[i].xdelta / 16384.f); + pSector->setceilingypan(sFlowInfo[i].ydelta / 16384.f); sFlowInfo[i].xdelta &= sFlowInfo[i].xacc; sFlowInfo[i].ydelta &= sFlowInfo[i].yacc; @@ -731,10 +742,10 @@ void DoFlows() case 2: { - int nWall = sFlowInfo[i].objindex; + auto pWall = sFlowInfo[i].pWall; - wall[nWall].setxpan(sFlowInfo[i].xdelta / 16384.f); - wall[nWall].setypan(sFlowInfo[i].ydelta / 16384.f); + pWall->setxpan(sFlowInfo[i].xdelta / 16384.f); + pWall->setypan(sFlowInfo[i].ydelta / 16384.f); if (sFlowInfo[i].xdelta < 0) { @@ -751,10 +762,10 @@ void DoFlows() case 3: { - int nWall = sFlowInfo[i].objindex; + auto pWall = sFlowInfo[i].pWall; - wall[nWall].setxpan(sFlowInfo[i].xdelta / 16384.f); - wall[nWall].setypan(sFlowInfo[i].ydelta / 16384.f); + pWall->setxpan(sFlowInfo[i].xdelta / 16384.f); + pWall->setypan(sFlowInfo[i].ydelta / 16384.f); if (sFlowInfo[i].xdelta >= sFlowInfo[i].xacc) { diff --git a/source/games/exhumed/src/object.cpp b/source/games/exhumed/src/object.cpp index 734f73e14..581111ee3 100644 --- a/source/games/exhumed/src/object.cpp +++ b/source/games/exhumed/src/object.cpp @@ -102,7 +102,7 @@ struct MoveSect struct wallFace { - int nWall; + walltype* pWall; int16_t nChannel; int16_t count; int16_t piclist[8]; @@ -263,7 +263,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, wallFace& w, wallF if (arc.BeginObject(keyname)) { arc("channel", w.nChannel) - ("wall", w.nWall) + ("wall", w.pWall) ("at4", w.count) .Array("at6", w.piclist, 8) .EndObject(); @@ -874,12 +874,12 @@ void InitWallFace() WallFace.Clear(); } -int BuildWallFace(int nChannel, int nWall, int nCount, ...) +int BuildWallFace(int nChannel, walltype* pWall, int nCount, ...) { auto WallFaceCount = WallFace.Reserve(1); WallFace[WallFaceCount].count = 0; - WallFace[WallFaceCount].nWall = nWall; + WallFace[WallFaceCount].pWall = pWall; WallFace[WallFaceCount].nChannel = nChannel; if (nCount > 8) { @@ -912,7 +912,7 @@ void AIWallFace::ProcessChannel(RunListEvent* ev) if ((si <= WallFace[nWallFace].count) && (si >= 0)) { - wall[WallFace[nWallFace].nWall].picnum = WallFace[nWallFace].piclist[si]; + WallFace[nWallFace].pWall->picnum = WallFace[nWallFace].piclist[si]; } } diff --git a/source/games/exhumed/src/runlist.cpp b/source/games/exhumed/src/runlist.cpp index 526cee25a..4d7c27a02 100644 --- a/source/games/exhumed/src/runlist.cpp +++ b/source/games/exhumed/src/runlist.cpp @@ -1515,9 +1515,9 @@ void runlist_ProcessSectorTag(int nSector, int nLotag, int nHitag) } } -void runlist_ProcessWallTag(int nWall, int nLotag, int nHitag) +void runlist_ProcessWallTag(walltype* pWall, int nLotag, int nHitag) { - auto& wal = wall[nWall]; + auto& wal = *pWall; int nChannel = runlist_AllocChannel(nHitag % 1000); assert(nChannel >= 0 && nChannel < kMaxChannels); @@ -1537,10 +1537,10 @@ void runlist_ProcessWallTag(int nWall, int nLotag, int nHitag) case 1: { - int nWallFace = BuildWallFace(nChannel, nWall, 2, wal.picnum, wal.picnum + 1); + int nWallFace = BuildWallFace(nChannel, pWall, 2, pWall->picnum, pWall->picnum + 1); runlist_AddRunRec(sRunChannels[nChannel].a, nWallFace, 0x70000); - auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, nEffectTag, 0), nWall); + auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, nEffectTag, 0), pWall); runlist_AddRunRec(sRunChannels[nChannel].a,nSwitch.first, nSwitch.second); return; @@ -1548,27 +1548,27 @@ void runlist_ProcessWallTag(int nWall, int nLotag, int nHitag) case 6: { - auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, 1, 0), nWall); + auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, 1, 0), pWall); runlist_AddRunRec(sRunChannels[nChannel].a,nSwitch.first, nSwitch.second); return; } case 7: // Regular switch { - int nWallFace = BuildWallFace(nChannel, nWall, 2, wal.picnum, wal.picnum + 1); + int nWallFace = BuildWallFace(nChannel, pWall, 2, pWall->picnum, pWall->picnum + 1); runlist_AddRunRec(sRunChannels[nChannel].a, nWallFace, 0x70000); - auto nSwitch = BuildSwPressWall(nChannel, BuildLink(1, 1), nWall); + auto nSwitch = BuildSwPressWall(nChannel, BuildLink(1, 1), pWall); runlist_AddRunRec(sRunChannels[nChannel].a,nSwitch.first, nSwitch.second); return; } case 8: // Reverse switch { - int nWallFace = BuildWallFace(nChannel, nWall, 2, wal.picnum, wal.picnum + 1); + int nWallFace = BuildWallFace(nChannel, pWall, 2, pWall->picnum, pWall->picnum + 1); runlist_AddRunRec(sRunChannels[nChannel].a, nWallFace, 0x70000); - auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, -1, 0), nWall); + auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, -1, 0), pWall); runlist_AddRunRec(sRunChannels[nChannel].a,nSwitch.first, nSwitch.second); return; @@ -1576,14 +1576,14 @@ void runlist_ProcessWallTag(int nWall, int nLotag, int nHitag) case 9: // Invisible switch { - auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, 1, 1), nWall); + auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, 1, 1), pWall); runlist_AddRunRec(sRunChannels[nChannel].a,nSwitch.first, nSwitch.second); return; } case 10: { - auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, -1, 0), nWall); + auto nSwitch = BuildSwPressWall(nChannel, BuildLink(2, -1, 0), pWall); runlist_AddRunRec(sRunChannels[nChannel].a,nSwitch.first, nSwitch.second); return; } @@ -1597,7 +1597,8 @@ void runlist_ProcessWallTag(int nWall, int nLotag, int nHitag) int nLastWall = 0; int n2ndLastWall = 0; - int nStart = nWall; + int nStart = wallnum(pWall); + int nWall = nStart; while (1) { @@ -1623,13 +1624,13 @@ void runlist_ProcessWallTag(int nWall, int nLotag, int nHitag) case 24: // Waterfall { - AddFlow(nWall, nPanSpeed, 3); + AddFlow(pWall, nPanSpeed, 3); return; } case 25: // Inverse waterfall { - AddFlow(nWall, nPanSpeed, 2); + AddFlow(pWall, nPanSpeed, 2); return; } } diff --git a/source/games/exhumed/src/switch.cpp b/source/games/exhumed/src/switch.cpp index 1575ece90..c6d91607a 100644 --- a/source/games/exhumed/src/switch.cpp +++ b/source/games/exhumed/src/switch.cpp @@ -37,14 +37,15 @@ struct Link struct Switch { - int16_t nWaitTimer; - int16_t nWait; + walltype* pWall; int nChannel; int nLink; - int16_t nRunPtr; int nSector; + int16_t nWaitTimer; + int16_t nWait; + int16_t nRunPtr; int16_t nRun2; - int nWall; + int16_t nRun3; uint16_t nKeyMask; }; @@ -69,7 +70,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, Switch& w, Switch* ("runptr", w.nRunPtr) ("sector", w.nSector) ("run2", w.nRun2) - ("wall", w.nWall) + ("wall", w.pWall) ("run3", w.nRun3) ("keymask", w.nKeyMask) .EndObject(); @@ -450,9 +451,9 @@ void AISWPressSector::Use(RunListEvent* ev) } -std::pair BuildSwPressWall(int nChannel, int nLink, int nWall) +std::pair BuildSwPressWall(int nChannel, int nLink, walltype* pWall) { - if (SwitchCount <= 0 || nLink < 0 || nWall < 0) { + if (SwitchCount <= 0 || nLink < 0 || !pWall) { I_Error("Too many switches!\n"); } @@ -460,7 +461,7 @@ std::pair BuildSwPressWall(int nChannel, int nLink, int nWall) SwitchData[SwitchCount].nChannel = nChannel; SwitchData[SwitchCount].nLink = nLink; - SwitchData[SwitchCount].nWall = nWall; + SwitchData[SwitchCount].pWall = pWall; SwitchData[SwitchCount].nRun3 = -1; return { SwitchCount, 0x60000 }; @@ -482,8 +483,8 @@ void AISWPressWall::Process(RunListEvent* ev) if (LinkMap[nLink].v[sRunChannels[nChannel].c] >= 0) { - int nWall = SwitchData[nSwitch].nWall; - SwitchData[nSwitch].nRun3 = runlist_AddRunRec(wall[nWall].lotag - 1, &RunData[ev->nRun]); + auto pWall = SwitchData[nSwitch].pWall; + SwitchData[nSwitch].nRun3 = runlist_AddRunRec(pWall->lotag - 1, &RunData[ev->nRun]); } } @@ -505,10 +506,10 @@ void AISWPressWall::Use(RunListEvent* ev) SwitchData[nSwitch].nRun3 = -1; } - int nWall = SwitchData[nSwitch].nWall; + auto pWall = SwitchData[nSwitch].pWall; int nSector =SwitchData[nSwitch].nSector; // CHECKME - where is this set?? - PlayFXAtXYZ(StaticSound[nSwitchSound], wall[nWall].x, wall[nWall].y, 0, nSector, CHANF_LISTENERZ); + PlayFXAtXYZ(StaticSound[nSwitchSound], pWall->x, pWall->y, 0, nSector, CHANF_LISTENERZ); } END_PS_NS