diff --git a/AGENTS.md b/AGENTS.md index a7faa81e71..b6a2f33cfb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -127,6 +127,14 @@ style question - see the note on unpredictable styles below. `declare_at_use.py` `undiv.py` undo decompiler artefacts across a whole selection; run `test_deparen.py` and `test_undiv.py` after touching the precedence table or the division patterns those two rely on. +On a large decompiled function most of the gap is usually block *order*, not code, and two tools restore it +before anything else is worth measuring: `switch_order.py` puts every switch's case bodies in the order of the +original's jump table (MSVC emits them in source order, Ghidra prints them by value; 37% -> 60% on +`renderGmOverlayBuilding` alone), and `flip_branches.py --find` lists the if/else statements whose arms the +original lays out the other way round (Ghidra prints the jump target first, so `if ((x & m) == 0) {A} else {B}` +was usually `!= 0` with the arms swapped). `quick_diff.py -r --runs N` then lists what still differs with the +source lines it comes from. + The rewriting scripts take a path filter and default to a dry run. Read the diff before building, then run `syntax_check.py` on what you touched: reviewing a diff catches a wrong transformation but not a rewrite that leaves the surrounding text unparseable, and `/Zs` finds that in seconds instead of a full build. diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 17882af542..c321da3bed 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -450,6 +450,9 @@ src/OpenSHC/Map/Units/UpdateJester.cpp src/OpenSHC/Map/Units/UpdateSlave.cpp src/OpenSHC/Map/Units/UpdateHealer.cpp src/OpenSHC/Map/Units/UpdateSpearman.cpp +src/OpenSHC/Rendering/ViewportRenderState/resetupViewport.cpp +src/OpenSHC/Rendering/ViewportRenderState/setupViewport.cpp +src/OpenSHC/Rendering/ViewportRenderState/setViewportBasedOnMapSize.cpp src/OpenSHC/Map/Units/UpdateSlinger.cpp src/OpenSHC/Map/Units/UpdateWoodcutter.cpp src/OpenSHC/Map/Units/UpdateFletcher.cpp diff --git a/src/OpenSHC/Rendering/ViewportRenderState/computeMouseTileFromScreenPosition.cpp b/src/OpenSHC/Rendering/ViewportRenderState/computeMouseTileFromScreenPosition.cpp new file mode 100644 index 0000000000..5631db05b6 --- /dev/null +++ b/src/OpenSHC/Rendering/ViewportRenderState/computeMouseTileFromScreenPosition.cpp @@ -0,0 +1,204 @@ +#include "../ViewportRenderState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MapRenderDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x004E5ED0 + void ViewportRenderState::computeMouseTileFromScreenPosition(int screenX, int screenY) + { + int probeScreenY = screenY - 8; + int foundTile = 0; + int orientationBase = 8; + + this->viewportState.field_0x6c = 0; + this->viewportState.cursorTile = 0; + this->viewportState.mouseX = 0; + this->viewportState.mouseY = 0; + if (this->viewportState.field_0x0 == 0) { + return; + } + + int const& isZoomedOut = this->viewportState.isZoomedOutUnk; + int quadrantX; + if (isZoomedOut == 0) { + quadrantX = ((this->viewportState.viewportX % 32 - this->windowX) + screenX) >> 1 & 0xf; + } else { + quadrantX = ((this->viewportState.viewportX % 32 + screenX * 2) - this->windowX) >> 1 & 0xf; + } + + if (DAT_TileMapState::instance.mapOrientation == 0) { + orientationBase = 8; + } else if (DAT_TileMapState::instance.mapOrientation == 6) { + orientationBase = 80408; + } else if (DAT_TileMapState::instance.mapOrientation == 4) { + orientationBase = 160808; + } else if (DAT_TileMapState::instance.mapOrientation == 2) { + orientationBase = 241208; + } + int probeDoubledY = probeScreenY * 2 + 8; + int probeOffset = probeScreenY - screenY; + + // a do-while on purpose: the same loop as a for adds an entry test the original does not have (0.88 -> 0.59) + do { + if ((DAT_TileMapState::instance.disableElevationRendering != 0 + || DAT_TileMapState::instance.flatViewToggleValue2 != 0) + && probeOffset != -8) { + break; + } + + int lookupIndex; + int tileRowY; + if (this->viewportState.isZoomedOutUnk == 0) { + int unclampedY = (this->viewportState.viewportY - this->windowY) + 8 + probeScreenY; + tileRowY = ((this->viewportState.viewportY % 16 - this->windowY) + probeScreenY - 8) & 0xf; + int unclampedX = (screenX - this->windowX) + this->viewportState.viewportX; + lookupIndex = (unclampedX / 32) + (unclampedY / 16) * 401 + orientationBase; + } else { + int unclampedX = ((screenX * 2 + 160) - this->windowX) + this->viewportState.viewportX; + tileRowY = ((this->viewportState.viewportY % 16 - this->windowY) + probeDoubledY) & 0xf; + int unclampedY = (probeDoubledY - this->windowY) + this->viewportState.viewportY; + lookupIndex = (unclampedY / 16) * 401 + (unclampedX / 32) + orientationBase; + } + + int quadrant = DAT_MapRenderDefinedData::instance.field_0xc24[tileRowY][quadrantX]; + if (quadrant == 1) { + lookupIndex = lookupIndex + 200; + } else if (quadrant == 2) { + lookupIndex = lookupIndex + 201; + } else if (quadrant == 3) { + lookupIndex = lookupIndex + 401; + } + + int tile = this->screenPointToTileNumber[lookupIndex]; + if ((DAT_TileMapState::instance.LogicLayer[tile] + & (Map::LogicHelpers::L_BORDER | Map::LogicHelpers::L_BORDER_EDGE)) + != 0) { + break; + } + + int tileHeightOffset + = DAT_TileMapState::instance.heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[tile]]; + if ((DAT_TileMapState::instance.LogicLayer[tile] & Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE) != 0) { + tileHeightOffset = tileHeightOffset + + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(DAT_TileMapState::instance.BuildingLayer[tile]); + } + if (this->viewportState.isZoomedOutUnk != 0) { + tileHeightOffset = tileHeightOffset / 2; + } + + if ((probeOffset - tileHeightOffset) + 8 + screenY <= screenY + || DAT_TileMapState::instance.disableElevationRendering != 0 + || DAT_TileMapState::instance.flatViewToggleValue2 != 0) { + foundTile = tile; + } + + probeScreenY = probeScreenY + 1; + probeDoubledY = probeDoubledY + 2; + probeOffset = probeOffset + 1; + } while (probeOffset < 255); + + this->viewportState.mouseAtomRefFloorTile = foundTile; + if (DAT_TileMapState::instance.PathConnectionLayer[foundTile] == 0 + || (DAT_TileMapState::instance.LogicLayer[foundTile] & Map::LogicHelpers::L_CRENEL) != 0) { + int neighbourTile + = DAT_TileMapState::instance + .directionTranslationMatrix[this->tileTranslationMatrix_YComponent[foundTile]] + [(DAT_TileMapState::instance.screenSouthEastDirection + 4) % 8] + + foundTile; + uint tileFlags = DAT_TileMapState::instance.LogicLayer[foundTile]; + if ((tileFlags & Map::LogicHelpers::L_MOAT) == 0) { + if ((tileFlags & Map::LogicHelpers::L_CRENEL) != 0) { + if ((DAT_TileMapState::instance.LogicLayer[neighbourTile] & Map::LogicHelpers::L_WALL_OR_GATEHOUSE) + != 0) { + foundTile = neighbourTile; + } + } else if ((tileFlags & Map::LogicHelpers::L_BUILDING) != 0) { + switch (DAT_BuildingsState::instance.buildings[DAT_TileMapState::instance.BuildingLayer[foundTile]] + .buildingType) { + case OpenSHC::Map::Buildings::BT_MANORHOUSE: + case OpenSHC::Map::Buildings::BT_STONEKEEP: + case OpenSHC::Map::Buildings::BT_STRONGHOLD: + case OpenSHC::Map::Buildings::BT_KEEPFOUR: + case OpenSHC::Map::Buildings::BT_KEEPFIVE: + case OpenSHC::Map::Buildings::BT_TOWER: + case OpenSHC::Map::Buildings::BT_TOWER1: + case OpenSHC::Map::Buildings::BT_TOWER2: + case OpenSHC::Map::Buildings::BT_TOWER3: + case OpenSHC::Map::Buildings::BT_TOWER4: + case OpenSHC::Map::Buildings::BT_TOWER5: + if ((DAT_TileMapState::instance.LogicLayer[neighbourTile] + & Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE) + != 0) { + foundTile = neighbourTile; + } + break; + default: + foundTile = 0; + break; + } + } else { + foundTile = 0; + } + } + } + + if ((DAT_TileMapState::instance.LogicLayer[foundTile] + & (Map::LogicHelpers::L_WALL_OR_GATEHOUSE | Map::LogicHelpers::L_CRENEL + | Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE)) + != 0 + && (DAT_TileMapState::instance.LogicLayer[foundTile] & 2) == 0) { + this->viewportState.field_0x6c = 1; + } + this->viewportState.cursorTile = foundTile; + this->viewportState.somePitchDitchID = 0; + if (foundTile == 0) { + this->viewportState.mouseY = 0; + this->viewportState.mouseX = 0; + this->viewportState.field_0x6c = 0; + this->viewportState.field_0x38 = 0; + this->viewportState.field_0x40 = 0; + this->viewportState.field_0x3c = 0; + return; + } + + this->viewportState.mouseY = this->tileTranslationMatrix_YComponent[foundTile]; + this->viewportState.mouseX = foundTile - this->translationMatrix[this->viewportState.mouseY].addXgetTile; + if (DAT_TileMapState::instance.flatViewToggleValue1 != 0) { + foundTile = this->viewportState.mouseFlatTile; + } + this->viewportState.field_0x38 = DAT_TileMapState::instance.LogicLayer[foundTile] & Map::LogicHelpers::L_MOAT; + this->viewportState.field_0x40 + = DAT_TileMapState::instance.LogicLayer[foundTile] & Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; + int moatID = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, DAT_TileMapState::ptr)( + foundTile); + if (moatID == 0) { + this->viewportState.field_0x38 = 0; + this->viewportState.field_0x40 = 0; + } + this->viewportState.field_0x3c = this->viewportState.field_0x38; + if (DAT_GameState::instance.mapAndTime.playerTeams[DAT_TileMapState::instance.moats[moatID].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID]) { + this->viewportState.field_0x38 = 0; + } else { + this->viewportState.field_0x40 = 0; + this->viewportState.field_0x3c = 0; + } + if ((DAT_TileMapState::instance.LogicLayer[foundTile] & 8) != 0) { + this->viewportState.somePitchDitchID = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(foundTile); + } + } + +} +} diff --git a/src/OpenSHC/Rendering/ViewportRenderState/renderAssassinClimbingOverlay.cpp b/src/OpenSHC/Rendering/ViewportRenderState/renderAssassinClimbingOverlay.cpp new file mode 100644 index 0000000000..beb42ae0aa --- /dev/null +++ b/src/OpenSHC/Rendering/ViewportRenderState/renderAssassinClimbingOverlay.cpp @@ -0,0 +1,45 @@ +#include "../ViewportRenderState.func.hpp" + +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" + +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x004E2630 + void ViewportRenderState::renderAssassinClimbingOverlay(int unitID) + { + short facingDirection = DAT_UnitsState::instance.units[unitID].facingDirectionMapOrientationCorrected; + short assassinHeightDifference = DAT_UnitsState::instance.units[unitID].assassinHeightDifference; + if (assassinHeightDifference <= 0) { + return; + } + int imageID = DAT_UnitsState::instance.units[unitID].imageIDUnk; + if (imageID <= 0) { + return; + } + + if (DAT_UnitsState::instance.units[unitID].assassinClimbingUpUnk_OR_previousFacingDirection == 0) { + if (facingDirection != 4 && facingDirection != 2 && facingDirection != 3 && facingDirection != 1 + && facingDirection != 5) { + return; + } + } else { + if (facingDirection != 0 && facingDirection != 6 && facingDirection != 7 && facingDirection != 1 + && facingDirection != 5) { + return; + } + } + + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, DAT_TextureRenderCoreObject::ptr) + ((OpenSHC::IO::Graphics::GmID)DAT_UnitsState::instance.units[unitID].gmIDUnk, imageID, + DAT_UnitsState::instance.units[unitID].field_0x41c, + DAT_UnitsState::instance.units[unitID].field_0x420 - assassinHeightDifference, + DAT_UnitsState::instance.units[unitID].field_0x41a); + } + +} +} diff --git a/src/OpenSHC/Rendering/ViewportRenderState/renderGmOverlayBuilding.cpp b/src/OpenSHC/Rendering/ViewportRenderState/renderGmOverlayBuilding.cpp new file mode 100644 index 0000000000..2590e7f782 --- /dev/null +++ b/src/OpenSHC/Rendering/ViewportRenderState/renderGmOverlayBuilding.cpp @@ -0,0 +1,1545 @@ +#include "../ViewportRenderState.func.hpp" + +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_CurrentlyRenderedSpriteID.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_GmImageAddressToBeRendered.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_RenderedUnitOwner.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace Rendering { + + using OpenSHC::DE::SHCDE::eGM; + using OpenSHC::Game::GameMode2; + using OpenSHC::IO::Graphics::GmID; + using OpenSHC::Map::MapType2; + using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::Map::Buildings::BuildingTypeShort; + using OpenSHC::UI::Enums::MenuViewType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004E3980 + void ViewportRenderState::renderGmOverlayBuilding(int tileIndex, int xUnk, int yUnk, int param_4) + { + short sVar1; + BuildingTypeShort buildingType; + uint uVar8; + int iVar9; + int iVar10; + int frame; + GmID overlayGmID; + eGM gmID; + GmID maskGmID; + int local_18; + int local_14; + int local_10; + int local_8; + int local_4; + + DAT_RenderedUnitOwner::instance = DAT_BuildingsState::instance.buildings[tileIndex].playerColorUnk; + local_18 = 0; + local_14 = 0; + if (DAT_BuildingsState::instance.buildings[tileIndex].displayOwnerFlag != 0) { + sVar1 = DAT_BuildingsState::instance.buildings[tileIndex].tickRelatedVisuallyActiveIndicator; + if (sVar1 <= 0) { + frame = 0; + } else if (sVar1 >= 5) { + frame = 0; + } else { + frame = 32 - sVar1 * 32 / 5; + if (frame == 32) { + frame = 0; + } + } + buildingType = DAT_BuildingsState::instance.buildings[tileIndex].buildingType; + if (buildingType == OpenSHC::Map::Buildings::BT_CAMPGROUND) { + if (DAT_BuildingsState::instance.buildings[tileIndex].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOAT_POP_CIRC, frame, + (xUnk - DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[85].originX) - 5, + (yUnk - DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[85].originY) - 89, + OpenSHC::IO::Graphics::GID_FLOAT_POP_CIRC, frame + 101, 0); + } + } else { + int slot = 0; + if (DAT_TileMapState::instance.disableElevationRendering != 0) { + return; + } + switch (buildingType) { + case OpenSHC::Map::Buildings::BT_WOODCUTTERSHUT: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 39, yUnk - 103); + } + DAT_GmImageAddressToBeRendered::instance + = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_WOODCUTTER; + if (DAT_GmImageAddressToBeRendered::instance != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)(xUnk - 35, yUnk - 57, + DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance].width, + DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance].height, + DAT_TextureRenderCoreObject::instance.gmProcessedImageData + + DAT_GMImageOffsets::instance[DAT_GmImageAddressToBeRendered::instance]); + } + DAT_GmImageAddressToBeRendered::instance + = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (DAT_GmImageAddressToBeRendered::instance != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)(xUnk - 56, yUnk - 70, + DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance].width, + DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance].height, + DAT_TextureRenderCoreObject::instance.gmProcessedImageData + + DAT_GMImageOffsets::instance[DAT_GmImageAddressToBeRendered::instance]); + } + break; + case OpenSHC::Map::Buildings::BT_INN: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 69, yUnk - 149); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_INN; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ANIM_INN, frame, + DAT_BuildingsState::instance.buildings[tileIndex].spriteOffetX + xUnk, + DAT_BuildingsState::instance.buildings[tileIndex].spriteOffetY + yUnk); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ANIM_INN, frame, + DAT_BuildingsState::instance.buildings[tileIndex].spriteOffetX + xUnk, + DAT_BuildingsState::instance.buildings[tileIndex].spriteOffetY + yUnk); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ANIM_INN, frame, + DAT_BuildingsState::instance.buildings[tileIndex].spriteOffetX + xUnk, + DAT_BuildingsState::instance.buildings[tileIndex].spriteOffetY + yUnk); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ANIM_INN, frame, + DAT_BuildingsState::instance.buildings[tileIndex].spriteOffetX + xUnk, + DAT_BuildingsState::instance.buildings[tileIndex].spriteOffetY + yUnk); + } + break; + case OpenSHC::Map::Buildings::BT_CHOPPINGBLOCK: + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_CHOPPING_BLOCK; + DAT_RenderedUnitOwner::instance = 0; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_CHOPPING_BLOCK, frame, xUnk - 35, yUnk - 76); + } + break; + case OpenSHC::Map::Buildings::BT_OILSMELTER: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk + 3, yUnk - 125); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_BOILED_OIL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_OIL_ANIMS, frame, xUnk - 35, yUnk - 62); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (frame != 0) { + if (frame > 122) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_OIL_ANIMS, frame, xUnk - 35, yUnk - 102); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_OIL_ANIMS, frame, xUnk - 35, yUnk - 100); + } + } + break; + case OpenSHC::Map::Buildings::BT_QUARRY: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 38, yUnk - 60); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 1; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_QUARRY; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_QUARRY_ANIMS, frame, xUnk + 12, yUnk - 140); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_QUARRY_ANIMS, frame, xUnk - 49, yUnk - 136); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_QUARRY_ANIMS, frame, xUnk - 32, yUnk - 107); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_QUARRY_ANIMS, frame, xUnk - 95, yUnk - 111); + } + break; + case OpenSHC::Map::Buildings::BT_DRAWBRIDGE: + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 7, yUnk - 124); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 51, yUnk - 126); + } + break; + case OpenSHC::Map::Buildings::BT_IRONMINE: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 39, yUnk - 33); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_IRON_MINER; + if (frame != 0) { + short const minerPose = DAT_BuildingsState::instance.buildings[tileIndex].field_0x11a; + if (minerPose == 0) { + local_18 = -31; + local_14 = -88; + } else if (minerPose == 1 || minerPose == 2) { + local_14 = -157; + local_18 = -26; + } + if (DAT_BuildingsState::instance.buildings[tileIndex].field_0x11a == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_MINE_ANIMS, frame, local_18 + xUnk, local_14 + yUnk); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_IRON_MINER, frame, + local_18 + xUnk, local_14 + yUnk, + DAT_BuildingsState::instance.buildings[tileIndex].field_0x292); + } + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_MINE_ANIMS, frame, xUnk - 31, yUnk - 89); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_MINE_ANIMS, frame, xUnk - 23, yUnk - 54); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + short const minerState = DAT_BuildingsState::instance.buildings[tileIndex].state; + int offsetX; + int offsetY; + if (minerState == 0) { + offsetX = -35; + offsetY = -70; + } else if (minerState == 1) { + offsetX = -35; + offsetY = -56; + } else if (minerState == 2) { + offsetX = -35; + offsetY = -70; + } else if (minerState == 3) { + offsetX = -35; + offsetY = -78; + } else if (minerState == 4) { + offsetX = -35; + offsetY = -89; + } else if (minerState == 5) { + offsetX = -35; + offsetY = -89; + } else { + offsetX = -51; + offsetY = -70; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_MINE_ANIMS, frame, offsetX + xUnk, offsetY + yUnk); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_MINE_ANIMS, frame, xUnk - 51, yUnk - 84); + } + break; + case OpenSHC::Map::Buildings::BT_PITCHRIG: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk + 12, yUnk - 80); + } + break; + case OpenSHC::Map::Buildings::BT_HUNTERSHUT: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 86); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_HUNTER; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_HUNTER_ANIMS, frame, xUnk - 35, yUnk - 60); + } + break; + case OpenSHC::Map::Buildings::BT_MILL: { + int millImage = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (millImage != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, millImage, xUnk - 38, yUnk - 114); + } + millImage = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_WINDMILL; + if (millImage != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_WINDMILL_ANIMS, millImage, xUnk - 78, yUnk - 259); + } + millImage = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (millImage != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_WINDMILL, millImage, xUnk - 78, yUnk - 259, frame); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_WINDMILL_ANIMS, frame, xUnk - 78, yUnk - 208); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_WINDMILL_ANIMS, frame, xUnk - 89, yUnk - 292); + } + break; + } + case OpenSHC::Map::Buildings::BT_BAKERY: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 123); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = 66; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_WORKSHOP_BAKER_ANIMS, frame, xUnk - 20, yUnk - 95); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_SMOKE_30X30; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_SMOKE_30X30, frame, xUnk - 4, yUnk - 140, 16); + } + break; + case OpenSHC::Map::Buildings::BT_BREWERY: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 123); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 2; + DAT_CurrentlyRenderedSpriteID::instance = 51; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_WORKSHOP_BREW_ANIMS, frame, xUnk - 60, yUnk - 68); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_SMOKE_30X30; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_SMOKE_30X30, frame, xUnk + 7, yUnk - 124, 16); + } + break; + case OpenSHC::Map::Buildings::BT_BLACKSMITH: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 123); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 2; + DAT_CurrentlyRenderedSpriteID::instance = 58; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_WORKSHOP_SMITH_ANIMS, frame, xUnk - 35, yUnk - 73); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_SMOKE_30X30; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_SMOKE_30X30, frame, xUnk + 3, yUnk - 124, 16); + } + break; + case OpenSHC::Map::Buildings::BT_POLETURNER: + case OpenSHC::Map::Buildings::BT_TANNER: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 128); + } + break; + case OpenSHC::Map::Buildings::BT_FLETCHER: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 130); + } + break; + case OpenSHC::Map::Buildings::BT_ARMOURER: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 137); + } + break; + case OpenSHC::Map::Buildings::BT_WHEATFARM: + case OpenSHC::Map::Buildings::BT_HOPFARM: + case OpenSHC::Map::Buildings::BT_APPLEFARM: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 55, yUnk - 109); + } + break; + case OpenSHC::Map::Buildings::BT_DAIRYFARM: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 55, yUnk - 109); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FARMER; + if (frame != 0) { + sVar1 = DAT_BuildingsState::instance.buildings[tileIndex].renderBlendStrength; + if (DAT_BuildingsState::instance.buildings[tileIndex].field_0x11a == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_FARMER_ANIMS, frame, xUnk - 35, yUnk - 81); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_FARMER, frame, xUnk - 35, yUnk - 81, sVar1); + } + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (frame != 0) { + sVar1 = DAT_BuildingsState::instance.buildings[tileIndex].renderBlendStrength; + if (DAT_BuildingsState::instance.buildings[tileIndex].field_0x11a == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_FARMER_ANIMS, frame, xUnk - 35, yUnk - 81); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_FARMER, frame, xUnk - 35, yUnk - 81, sVar1); + } + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_FARMER_ANIMS, frame, xUnk - 35, yUnk - 81); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_FARMER_ANIMS, frame, xUnk - 35, yUnk - 81); + } + break; + case OpenSHC::Map::Buildings::BT_STABLES: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = 189; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 18, yUnk - 99); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_STABLES; + if (frame != 0) { + short const blend = DAT_BuildingsState::instance.buildings[tileIndex].renderBlendStrength; + if (frame < 38) { + if (blend != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, frame, xUnk - 80, yUnk - 107, blend); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, frame, xUnk - 80, yUnk - 107); + } + } else { + if (blend != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, frame, xUnk - 80, yUnk - 107, blend); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, frame, xUnk - 103, yUnk - 100); + } + } + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + short const blend = DAT_BuildingsState::instance.buildings[tileIndex].renderBlendStrength; + if (frame < 38) { + if (blend != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, frame, xUnk - 58, yUnk - 96, blend); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, frame, xUnk - 58, yUnk - 96); + } + } else { + if (blend != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, frame, xUnk - 58, yUnk - 96, blend); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, frame, xUnk - 81, yUnk - 83); + } + } + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (frame != 0) { + short const blend = DAT_BuildingsState::instance.buildings[tileIndex].renderBlendStrength; + if (frame < 38) { + if (blend != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, frame, xUnk - 36, yUnk - 85, blend); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, frame, xUnk - 36, yUnk - 85); + } + } else { + if (blend != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, frame, xUnk - 36, yUnk - 85, blend); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, frame, xUnk - 55, yUnk - 74); + } + } + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + short const blend = DAT_BuildingsState::instance.buildings[tileIndex].renderBlendStrength; + if (frame < 38) { + if (blend != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, frame, xUnk - 14, yUnk - 74, blend); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, frame, xUnk - 14, yUnk - 74); + } + // the second image of the pair + short const blend2 = DAT_BuildingsState::instance.buildings[tileIndex].renderBlendStrength; + if (blend2 != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, 38, xUnk - 13, yUnk - 73, blend2); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, 38, xUnk - 2, yUnk - 73); + } + } else { + if (blend != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_ANIM_STABLES, frame, xUnk - 14, yUnk - 74, blend); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_STABLE_ANIMS, frame, xUnk - 33, yUnk - 63); + } + } + } + break; + case OpenSHC::Map::Buildings::BT_GRANARY: + for (slot = 0; slot < 16; slot++) { + if (DAT_BuildingsState::instance.buildings[tileIndex].tileRefs[slot] == param_4) { + break; + } + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if ((iVar9 != 0) && (slot == 0)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if ((iVar9 != 0) && (slot == 1)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage2; + if ((iVar9 != 0) && (slot == 2)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage2, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage6; + if ((iVar9 != 0) && (slot == 3)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage6, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if ((iVar9 != 0) && (slot == 4)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if ((iVar9 != 0) && (slot == 5)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage4; + if ((iVar9 != 0) && (slot == 6)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage4, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage9; + if ((iVar9 != 0) && (slot == 7)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage9, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if ((iVar9 != 0) && (slot == 8)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage3; + if ((iVar9 != 0) && (slot == 9)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage3, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage7; + if ((iVar9 != 0) && (slot == 10)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage7, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + if ((iVar9 != 0) && (slot == 11)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage5; + if ((iVar9 != 0) && (slot == 12)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage5, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage8; + if ((iVar9 != 0) && (slot == 13)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage8, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].flagSlot.overlayImage; + if ((iVar9 != 0) && (slot == 14)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, + DAT_BuildingsState::instance.buildings[tileIndex].flagSlot.overlayImage, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage10; + if ((iVar9 != 0) && (slot == 15)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ANIM_GOODS, iVar9, + (xUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1].width + / 2) + + 15, + (yUnk + - DAT_GMImageHeaders::instance.imh[GMFirstPictureIndex::instance[28] + iVar9 - 1] + .height) + - 5, + frame); + } + break; + case OpenSHC::Map::Buildings::BT_ARMORY: { + for (; slot < 16; slot++) { + if (DAT_BuildingsState::instance.buildings[tileIndex].tileRefs[slot] == param_4) { + break; + } + } + iVar9 = 0; + local_10 = 0; + local_18 = 0; + local_14 = 0; + local_4 = 0; + switch (DAT_TileMapState::instance.mapOrientation) { + case 0: + iVar9 = 5; + local_4 = 0; + local_10 = 7; + local_18 = 13; + local_14 = 15; + break; + case 2: + iVar9 = 4; + local_4 = 3; + local_10 = 6; + local_18 = 12; + local_14 = 14; + break; + case 4: + iVar9 = 0; + local_4 = 15; + local_10 = 2; + local_18 = 8; + local_14 = 10; + break; + case 6: + local_4 = 12; + iVar9 = 1; + local_10 = 3; + local_18 = 9; + local_14 = 11; + } + iVar10 = 0; + if (slot == iVar9) { + iVar10 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + } else if (slot == local_10) { + iVar10 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage3; + } else if (slot == local_18) { + iVar10 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage9; + } else if (slot == local_14) { + iVar10 = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + } + if (32 <= iVar10) { + iVar10 = 0; + overlayGmID = OpenSHC::IO::Graphics::GID_ANIM_GOODS; + local_8 = 0; + } else { + overlayGmID = OpenSHC::IO::Graphics::GID_ANIM_SHIELDS; + local_8 = -10; + iVar10 = DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[104].originY; + } + int blendFrame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + DAT_RenderedUnitOwner::instance = 0; + DAT_CurrentlyRenderedSpriteID::instance = overlayGmID; + if ((blendFrame != 0) && (slot == iVar9)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(overlayGmID, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1, + (xUnk + - DAT_GMImageHeaders::instance + .imh[blendFrame + GMFirstPictureIndex::instance[overlayGmID] - 1] + .width + / 2) + + 15 + local_8, + (yUnk + - DAT_GMImageHeaders::instance + .imh[blendFrame + GMFirstPictureIndex::instance[overlayGmID] - 1] + .height) + - 15 + iVar10, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage3; + if ((iVar9 != 0) && (slot == local_10)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(overlayGmID, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage3, + (xUnk + - DAT_GMImageHeaders::instance + .imh[iVar9 + GMFirstPictureIndex::instance[overlayGmID] - 1] + .width + / 2) + + 15 + local_8, + (yUnk + - DAT_GMImageHeaders::instance + .imh[iVar9 + GMFirstPictureIndex::instance[overlayGmID] - 1] + .height) + - 15 + iVar10, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage9; + if ((iVar9 != 0) && (slot == local_18)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(overlayGmID, + DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage9, + (xUnk + - DAT_GMImageHeaders::instance + .imh[iVar9 + GMFirstPictureIndex::instance[overlayGmID] - 1] + .width + / 2) + + 15 + local_8, + (yUnk + - DAT_GMImageHeaders::instance + .imh[iVar9 + GMFirstPictureIndex::instance[overlayGmID] - 1] + .height) + - 15 + iVar10, + frame); + } + iVar9 = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + if ((iVar9 != 0) && (slot == local_14)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(overlayGmID, iVar9, + (xUnk + - DAT_GMImageHeaders::instance + .imh[iVar9 + GMFirstPictureIndex::instance[overlayGmID] - 1] + .width + / 2) + + 15 + local_8, + (yUnk + - DAT_GMImageHeaders::instance + .imh[iVar9 + GMFirstPictureIndex::instance[overlayGmID] - 1] + .height) + - 15 + iVar10, + frame); + } + if (param_4 == DAT_BuildingsState::instance.buildings[tileIndex].tileRefs[local_4]) { + DAT_RenderedUnitOwner::instance + = DAT_BuildingsState::instance.buildings[tileIndex].playerColorUnk; + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage8; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 38, yUnk - 136); + break; + } + } + break; + } + case OpenSHC::Map::Buildings::BT_STONEKEEP: + if ((DAT_BuildingsState::instance.buildings[tileIndex].useOffsetGraphics == 0) + && (frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1, + frame != 0)) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 96, yUnk - 143); + break; + } + break; + case OpenSHC::Map::Buildings::BT_STRONGHOLD: + if ((DAT_BuildingsState::instance.buildings[tileIndex].useOffsetGraphics == 0) + && (frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1, + frame != 0)) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 159, yUnk - 298); + break; + } + break; + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 7, yUnk - 193); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 96, yUnk - 193); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 3, yUnk - 91); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 51, yUnk - 91); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_BODY_GATE, frame, xUnk + 17, yUnk - 94); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage2; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_BODY_GATE, frame, xUnk - 86, yUnk - 94); + } + break; + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 5, yUnk - 178); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 64, yUnk - 177); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 13, yUnk - 83); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 35, yUnk - 83); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_BODY_GATE, frame, xUnk, yUnk - 88); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage2; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_BODY_GATE, frame, xUnk - 70, yUnk - 88); + } + break; + case OpenSHC::Map::Buildings::BT_WOODGATE1: + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 3, yUnk - 110); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite2; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 32, yUnk - 106); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 32, yUnk - 70); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite4; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 8, yUnk - 71); + } + if (DAT_BuildingsState::instance.buildings[tileIndex].useOffsetGraphics == 0) { + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 17, yUnk - 55); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage2; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 21, yUnk - 55); + break; + } + } + break; + case OpenSHC::Map::Buildings::BT_TOWER1: + if (DAT_BuildingsState::instance.buildings[tileIndex].useOffsetGraphics == 0) { + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 33, yUnk - 320); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage2; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 34, yUnk - 379); + break; + } + } + break; + case OpenSHC::Map::Buildings::BT_TOWER2: + if (DAT_BuildingsState::instance.buildings[tileIndex].useOffsetGraphics == 0) { + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 48, yUnk - 194); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 41, yUnk - 147); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 2, yUnk - 140); + break; + } + } + break; + case OpenSHC::Map::Buildings::BT_TOWER3: + if (DAT_BuildingsState::instance.buildings[tileIndex].useOffsetGraphics == 0) { + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + /* + crenellations + */ + + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 63, yUnk - 225); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 41, yUnk - 150); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 13, yUnk - 147); + break; + } + } + break; + case OpenSHC::Map::Buildings::BT_TOWER4: + if (DAT_BuildingsState::instance.buildings[tileIndex].useOffsetGraphics == 0) { + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 77, yUnk - 246); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 57, yUnk - 154); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 15, yUnk - 150); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage2; + if (frame != 0) { + /* + roof + */ + + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 77, yUnk - 315); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage3; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 77, yUnk - 276); + break; + } + } + break; + case OpenSHC::Map::Buildings::BT_TOWER5: + if (DAT_BuildingsState::instance.buildings[tileIndex].useOffsetGraphics == 0) { + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 76, yUnk - 260); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraAnimationSprite3; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk - 50, yUnk - 157); + } + frame = DAT_BuildingsState::instance.buildings[tileIndex].extraOverlayImage1; + if (frame != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, frame, xUnk + 16, yUnk - 151); + break; + } + } + break; + case OpenSHC::Map::Buildings::BT_MARKETPLACE: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 39, yUnk - 106); + } + break; + case OpenSHC::Map::Buildings::BT_CHAPEL: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 38, yUnk - 124); + } + break; + case OpenSHC::Map::Buildings::BT_CHURCH: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 9, yUnk - 151); + } + break; + case OpenSHC::Map::Buildings::BT_CATHEDRAL: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 13, yUnk - 202); + } + break; + case OpenSHC::Map::Buildings::BT_APOTHECARY: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk + 5, yUnk - 177); + } + break; + case OpenSHC::Map::Buildings::BT_ENGINEERSGUILD: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 51, yUnk - 114); + } + break; + case OpenSHC::Map::Buildings::BT_TUNNELERSGUILD: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 54, yUnk - 119); + } + break; + case OpenSHC::Map::Buildings::BT_MERCENARYPOST: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 107); + } + break; + case OpenSHC::Map::Buildings::BT_BARRACKS: + frame = DAT_BuildingsState::instance.buildings[tileIndex].overlayImageID; + DAT_CurrentlyRenderedSpriteID::instance = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + if (frame != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, frame, xUnk - 37, yUnk - 117); + } + break; + } + } + } + frame = DAT_BuildingDefinedData::instance + .BuildingHeights[DAT_BuildingsState::instance.buildings[tileIndex].buildingType]; + int barXOffset = 0; + int barYOffset = 0; + if (frame == 0) { + uVar8 = DAT_BuildingsState::instance.buildings[tileIndex].widthOrHeight; + barXOffset = uVar8 << 5; + barYOffset = uVar8 << 4; + } + if ((((DAT_GameCore::instance.currentMenuViewType == OpenSHC::UI::Enums::MVT_BUILDING_AND_STATUS_MENU) + && (tileIndex == DAT_BuildingsState::instance.menuSelectedBuildingID)) + || ((tileIndex == DAT_BuildingsState::instance.selectedBuildingID + && (DAT_BuildingsState::instance.selectedBuildingUID + == DAT_BuildingsState::instance.buildings[tileIndex].uid)))) + && (sVar1 = DAT_BuildingsState::instance.buildings[tileIndex].maxHealth, + sVar1 != 0 + && (DAT_BuildingsState::instance.buildings[tileIndex].buildingType + != OpenSHC::Map::Buildings::BT_MANORHOUSE)) + && DAT_BuildingsState::instance.buildings[tileIndex].buildingType != OpenSHC::Map::Buildings::BT_STONEKEEP + && DAT_BuildingsState::instance.buildings[tileIndex].buildingType != OpenSHC::Map::Buildings::BT_STRONGHOLD + && DAT_BuildingsState::instance.buildings[tileIndex].buildingType != OpenSHC::Map::Buildings::BT_KEEPFOUR + && DAT_BuildingsState::instance.buildings[tileIndex].buildingType != OpenSHC::Map::Buildings::BT_KEEPFIVE + && DAT_BuildingsState::instance.buildings[tileIndex].buildingType + != OpenSHC::Map::Buildings::BT_CAMPGROUND) { + int const healthPercent + = MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::computeHealthPercentage, + DAT_DirectionAlgorithmState::ptr)( + DAT_BuildingsState::instance.buildings[tileIndex].currentHealth, sVar1); + switch (DAT_BuildingsState::instance.buildings[tileIndex].buildingType) { + case OpenSHC::Map::Buildings::BT_TOWER2: + barYOffset = barYOffset + 80; + break; + case OpenSHC::Map::Buildings::BT_TOWER3: + case OpenSHC::Map::Buildings::BT_TOWER4: + barYOffset = barYOffset + 90; + break; + case OpenSHC::Map::Buildings::BT_TOWER5: + barYOffset = barYOffset + 100; + break; + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + barYOffset = barYOffset + 30; + break; + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + barYOffset = barYOffset + 20; + break; + case OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED: + barYOffset = barYOffset - 30; + break; + } + int const healthImage = healthPercent / 10; + if (healthImage >= 0 && healthImage <= 10) { + buildingType = DAT_BuildingsState::instance.buildings[tileIndex].buildingType; + if ((buildingType == OpenSHC::Map::Buildings::BT_GRANARY) + || (buildingType == OpenSHC::Map::Buildings::BT_ARMORY)) { + int healthSlot; + for (healthSlot = 0; healthSlot < 16; healthSlot++) { + if (DAT_BuildingsState::instance.buildings[tileIndex].tileRefs[healthSlot] == param_4) { + break; + } + } + if (((DAT_TileMapState::instance.mapOrientation == 0) && (healthSlot == 15)) + || ((DAT_TileMapState::instance.mapOrientation == 2) && (healthSlot == 12)) + || ((DAT_TileMapState::instance.mapOrientation == 4) && (healthSlot == 0)) + || ((DAT_TileMapState::instance.mapOrientation == 6) && (healthSlot == 3))) { + frame = (yUnk - frame) - barYOffset; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_FLOATS, healthImage + 17, xUnk + 4, frame - 12); + } + } else { + frame = (yUnk - frame) - barYOffset; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_FLOATS, healthImage + 17, xUnk + 4, frame - 12); + } + } + } + if ((DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_BUILDERUnk) + || (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 != OpenSHC::Map::MT_SIEGE)) { + if (DAT_BuildingsState::instance.buildings[tileIndex].sleeping) { + int const animationTick = (DAT_TileMapState::instance.cursorOverlayAnimationFrame - 1) % 8; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOAT_POP_CIRC, animationTick + 203, + xUnk - 35, + yUnk + - DAT_BuildingDefinedData::instance + .BuildingHeights[DAT_BuildingsState::instance.buildings[tileIndex].buildingType] + - barYOffset - 42, + OpenSHC::IO::Graphics::GID_FLOAT_POP_CIRC, animationTick + 211, 0); + } else if (DAT_BuildingsState::instance.buildings[tileIndex].currentlyNeededEmployeeCount != 0 + && DAT_GameCore::instance.field_0x108 != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame + 280, xUnk - 35, + yUnk + - DAT_BuildingDefinedData::instance + .BuildingHeights[DAT_BuildingsState::instance.buildings[tileIndex].buildingType] + - barYOffset - 42, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, DAT_TileMapState::instance.cursorOverlayAnimationFrame + 296, + 0); + } + } + short const bannerState = DAT_BuildingsState::instance.buildings[tileIndex].targetMarker; + if (bannerState == OpenSHC::Map::Buildings::Enums::BTM_UNIT_TARGET) { + int const maskImage = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 16; + int const overlayImage = DAT_TileMapState::instance.cursorOverlayAnimationFrame; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, overlayImage, xUnk - 35, + yUnk + - DAT_BuildingDefinedData::instance + .BuildingHeights[DAT_BuildingsState::instance.buildings[tileIndex].buildingType] + - barXOffset - 42, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, maskImage, 0); + DAT_BuildingsState::instance.buildings[tileIndex].targetMarker = OpenSHC::Map::Buildings::Enums::BTM_NONE; + } else if (bannerState == OpenSHC::Map::Buildings::Enums::BTM_ENGINEER_TARGET) { + int const maskImage = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 132; + int const overlayImage = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 116; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, overlayImage, xUnk - 35, + yUnk + - DAT_BuildingDefinedData::instance + .BuildingHeights[DAT_BuildingsState::instance.buildings[tileIndex].buildingType] + - barXOffset - 42, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, maskImage, 0); + DAT_BuildingsState::instance.buildings[tileIndex].targetMarker = OpenSHC::Map::Buildings::Enums::BTM_NONE; + } + } + +} +} diff --git a/src/OpenSHC/Rendering/ViewportRenderState/renderMap.cpp b/src/OpenSHC/Rendering/ViewportRenderState/renderMap.cpp new file mode 100644 index 0000000000..26dc8b4c35 --- /dev/null +++ b/src/OpenSHC/Rendering/ViewportRenderState/renderMap.cpp @@ -0,0 +1,2725 @@ +#include "../ViewportRenderState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Rendering.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/IO/Graphics/GmIDInt.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/Entities/EntityTypeShort.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/States/UnitStateShort.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Rendering/ScreenResolutionEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/COL_BLACK.hpp" +#include "OpenSHC/Globals/COL_MAGENTA.hpp" +#include "OpenSHC/Globals/DAT_00ed3148.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_CurrentlyRenderedSpriteID.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_GmImageAddressToBeRendered.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_MapRenderDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_RenderMap_DrawSomeX.hpp" +#include "OpenSHC/Globals/DAT_RenderMap_DrawSomeY.hpp" +#include "OpenSHC/Globals/DAT_RenderMap_ImageID.hpp" +#include "OpenSHC/Globals/DAT_RenderMap_RowsLeft.hpp" +#include "OpenSHC/Globals/DAT_RenderMap_SecondBlitImageIndex.hpp" +#include "OpenSHC/Globals/DAT_RenderMap_WhatToDraw.hpp" +#include "OpenSHC/Globals/DAT_RenderMap_YOffset.hpp" +#include "OpenSHC/Globals/DAT_RenderedUnitOwner.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" +#include "OpenSHC/Globals/INT_00ed314c.hpp" +#include "OpenSHC/Globals/INT_00ed3154.hpp" +#include "OpenSHC/Globals/INT_00ed315c.hpp" + +namespace OpenSHC { +namespace Rendering { + + using OpenSHC::DE::SHCDE::eGM; + using OpenSHC::Game::GameMode; + using OpenSHC::Game::GameMode2; + using OpenSHC::IO::Graphics::GmID; + using OpenSHC::IO::Graphics::GmIDInt; + using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::Map::Buildings::BuildingTypeShort; + using OpenSHC::Map::Entities::EntityType; + using OpenSHC::Map::Entities::EntityTypeShort; + using OpenSHC::Map::Units::UnitLogicState; + using OpenSHC::Map::Units::UnitType; + using OpenSHC::Map::Units::UnitTypeShort; + using OpenSHC::Map::Units::States::UnitState; + using OpenSHC::Map::Units::States::UnitStateShort; + using OpenSHC::Rendering::ScreenResolutionEnum; + using OpenSHC::Rendering::Enums::RenderTarget; + using OpenSHC::Text::TextAlignment; + using OpenSHC::UI::Enums::BuildingsAndStatusMenuTabType; + using OpenSHC::UI::Enums::MenuModalType; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004E8CF0 + void ViewportRenderState::renderMap() + { + short* puVar1; + int iVar2; + EntityTypeShort EVar3; + UnitStateShort UVar4; + short sVar5; + short sVar6; + UnitTypeShort UVar7; + BuildingTypeShort BVar8; + ushort uVar9; + ushort uVar10; + GmID GVar11; + int bVar12; + int bVar13; + int bVar14; + byte bVar15; + int layerTileIndex; + short* psVar17; + int iVar18; + byte bVar19; + short sVar20; + int _visualTileOffset; + int* piVar21; + uint uVar22; + int iVar23; + int _numberToDisplay; + short sVar24; + int iVar25; + int iVar26; + int iVar27; + int iVar28; + uint uVar29; + short sVar30; + int iVar31; + uint uVar32; + int unitID; + int local_5c; + uint entityID; + uint local_54; + int _vpWidthPlus1_1; + int local_48; + uint _displayLayerLogicalValue; + int _zoomOffset; + int local_2c; + int local_24; + int* local_20; + int local_1c; + int local_14; + uint local_c; + int local_8; + int _vpWidthPlus1; + int _tile; + int tileIndex; + int _yOffset_01; + int _flatView; + int _viewportHeight; + int viewportWidth; + + iVar31 = 0; + iVar28 = 0; + _displayLayerLogicalValue = 0; + local_1c = 0; + local_5c = 600; + _flatView = 0; + local_8 = 0; + _zoomOffset = 0; + uVar9 = 0; + if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x768) { + local_5c = 768; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x1024) { + local_5c = 1024; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x1200) { + local_5c = 1200; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x720) { + local_5c = 720; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1440x900) { + local_5c = 900; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1080) { + local_5c = 1080; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1200) { + local_5c = 1200; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1440) { + local_5c = 1440; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1600) { + local_5c = 1600; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1366x768) { + local_5c = 768; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1680x1050) { + local_5c = 1050; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x900) { + local_5c = 900; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1360x768) { + local_5c = 768; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x600) { + local_5c = 600; + } + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::updateWaterAnimationFrames, this)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::assignRandomTiles, this)(); + viewportWidth = this->viewportState.viewportWidth; + _viewportHeight = this->viewportState.viewportHeight; + if ((DAT_TileMapState::instance.flatViewToggleValue1 != 0) + && (DAT_TileMapState::instance.flatViewToggleValue2 != 0)) { + _flatView = 1; + } + if (this->viewportState.isZoomedOutUnk != 0) { + iVar28 = 4; + _zoomOffset = 4; + } + _vpWidthPlus1_1 = this->viewportState.viewportHeight + 1; + this->viewportState.unknownScreenXRelated = iVar28 * 32 + 70; + iVar28 = this->viewportState.viewportWidth + 42; + DAT_RenderMap_DrawSomeY::instance = 8; + if (DAT_TileMapState::instance.mapOrientation == 0) { + LAB_004e8e99: + _visualTileOffset = 8; + } else if (DAT_TileMapState::instance.mapOrientation == 6) { + _visualTileOffset = 80408; + } else if (DAT_TileMapState::instance.mapOrientation == 4) { + _visualTileOffset = 160808; + } else { + _visualTileOffset = 241208; + if (DAT_TileMapState::instance.mapOrientation != 2) + goto LAB_004e8e99; + } + if (this->viewportState.field_0x94 != 0) { + if (this->viewportState.isZoomedOutUnk == 0) { + iVar31 = 64; + local_1c = 8; + } else { + iVar31 = 128; + local_1c = 16; + } + DAT_RenderMap_DrawSomeY::instance = iVar31 + 8; + } + _yOffset_01 + = (int)(this->viewportState.viewportY + iVar31 + (this->viewportState.viewportY + iVar31 >> 0x1f & 0xfU)) + >> 4; + layerTileIndex = (this->viewportState.viewportX / 32) + _visualTileOffset; + /* + *** + This piece of logic together with the huge array in the ViewportState gets + the tile the top left corner of the screen is showing, offset by some margin + to the right, not sure why that applies + *** + */ + + iVar2 = layerTileIndex - 2 + _yOffset_01 * 401; + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::resetBatchedRender, this)(); + if (DAT_TileMapState::instance.mapOrientation == 6) { + iVar26 = -this->viewportState.someYOffset; + iVar23 = this->viewportState.someXOffset; + } else if (DAT_TileMapState::instance.mapOrientation == 4) { + iVar23 = -this->viewportState.someYOffset; + iVar26 = -this->viewportState.someXOffset; + } else { + iVar23 = this->viewportState.someYOffset; + iVar26 = this->viewportState.someXOffset; + if (DAT_TileMapState::instance.mapOrientation == 2) { + iVar23 = -this->viewportState.someXOffset; + iVar26 = this->viewportState.someYOffset; + } + } + this->viewportState.tileCenterX = iVar23 + + (this->screenPointToTileNumber[_yOffset_01 * 401 + layerTileIndex] + - this + ->translationMatrix[this->tileTranslationMatrix_YComponent[this + ->screenPointToTileNumber[_yOffset_01 * 401 + layerTileIndex]]] + .addXgetTile); + this->viewportState.tileCenterY = iVar26 + + this->tileTranslationMatrix_YComponent[this->screenPointToTileNumber[_yOffset_01 * 401 + layerTileIndex]]; + DAT_TextureRenderCoreObject::instance.isZoom2 = this->viewportState.isZoomedOutUnk; + if (this->viewportState.isZoomedOutUnk == 0) { + layerTileIndex = DAT_WindowAndDirectDraw::instance.resolutionY + 24; + } else { + layerTileIndex = DAT_WindowAndDirectDraw::instance.resolutionY * 2 + 32; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::setMapSurfaceHeightRange, + DAT_TextureRenderCoreObject::ptr)(iVar31, layerTileIndex); + this->viewportState.ptrColor = (DAT_WindowAndDirectDraw::instance.surfacePointer_mapGame + + this->viewportState.currentCameraOffsetX + DAT_MouseState::instance.screenSpaceX + + (this->viewportState.currentCameraOffsetY + DAT_MouseState::instance.screenSpaceY) * 4056); + this->viewportState.mouseRayBuildingID = 0; + this->viewportState.mouseRayUnitID = 0; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + iVar31 = 1; + if (1 < DAT_UnitsState::instance.maxUnitCount) { + psVar17 = &DAT_UnitsState::instance.units[1].drawX; + do { + if (psVar17[60] != OpenSHC::Map::Units::ULS_INVISIBLE) { + *psVar17 = 0; + psVar17[1] = 0; + psVar17[2] = 0; + psVar17[3] = 0; + } + iVar31 = iVar31 + 1; + psVar17 = psVar17 + 584; + } while (iVar31 < DAT_UnitsState::instance.maxUnitCount); + } + iVar31 = 1; + if (1 < DAT_BuildingsState::instance.maxBuildingsCount) { + psVar17 = &DAT_BuildingsState::instance.buildings[1].surfaceAreaUnk; + do { + *psVar17 = 0; + iVar31 = iVar31 + 1; + psVar17 = psVar17 + 406; + } while (iVar31 < DAT_BuildingsState::instance.maxBuildingsCount); + } + while (local_1c < iVar28 + && (MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::renderUnits, this)(), + local_1c < viewportWidth + || ((DAT_TileMapState::instance.LogicLayer[this->screenPointToTileNumber[_zoomOffset + iVar2 + 8]] + & (Map::LogicHelpers::L_BORDER | Map::LogicHelpers::L_BORDER_EDGE)) + == 0))) { + _vpWidthPlus1 = _viewportHeight + 1; + DAT_RenderMap_DrawSomeX::instance = this->viewportState.unknownScreenXRelated; + iVar31 = _zoomOffset; + if (_vpWidthPlus1_1 == _vpWidthPlus1) { + DAT_RenderMap_DrawSomeX::instance = this->viewportState.unknownScreenXRelated + 16; + _vpWidthPlus1 = _viewportHeight; + } + for (; iVar31 < _vpWidthPlus1; iVar31 = iVar31 + 1) { + layerTileIndex = this->screenPointToTileNumber[iVar31 + iVar2]; + DAT_00ed3148::instance = DAT_TileMapState::instance.LogicLayer[layerTileIndex]; + if ((DAT_00ed3148::instance & 0x30) != 0) { + DAT_GmImageAddressToBeRendered::instance = GMFirstPictureIndex::instance[38] + 320; + DAT_RenderMap_YOffset::instance = 0; + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderTerrainTilesCenterPiece)(); + } else { + /* + draw every tile + */ + + DAT_GmImageAddressToBeRendered::instance + = (uint)DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + if ((iVar31 < 2) || (bVar13 = 1, !(iVar31 < _vpWidthPlus1 - 2))) { + bVar13 = 0; + } + if (this->DAT_MapEditorDisplayLayer != 0) { + if (this->DAT_MapEditorDisplayLayer == 1) { + _displayLayerLogicalValue + = (uint)(short)DAT_TileMapState::instance.PathConnectionLayer[layerTileIndex]; + } else if (this->DAT_MapEditorDisplayLayer == 2) { + _displayLayerLogicalValue + = (uint)(char)DAT_TileMapState::instance.PathLinkageLayer[layerTileIndex]; + } + if (_displayLayerLogicalValue != 0) { + if (this->DAT_MapEditorDisplayLayer == 2) { + _displayLayerLogicalValue = 255 - (_displayLayerLogicalValue & 0xff); + if (DAT_TileMapState::instance.mapOrientation == 2) { + _displayLayerLogicalValue = MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::rotateByteLeft, + DAT_DirectionAlgorithmState::ptr)((byte)_displayLayerLogicalValue, 6); + } else if (DAT_TileMapState::instance.mapOrientation == 4) { + _displayLayerLogicalValue = MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::rotateByteLeft, + DAT_DirectionAlgorithmState::ptr)((byte)_displayLayerLogicalValue, 4); + } else if (DAT_TileMapState::instance.mapOrientation == 6) { + _displayLayerLogicalValue = MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::rotateByteLeft, + DAT_DirectionAlgorithmState::ptr)((byte)_displayLayerLogicalValue, 2); + } + if (255 < (int)_displayLayerLogicalValue) { + _displayLayerLogicalValue = _displayLayerLogicalValue - 256; + } + DAT_GmImageAddressToBeRendered::instance + = GMFirstPictureIndex::instance[38] + 64 + _displayLayerLogicalValue; + } else { + _displayLayerLogicalValue = _displayLayerLogicalValue & 0x3f; + DAT_GmImageAddressToBeRendered::instance + = GMFirstPictureIndex::instance[38] + _displayLayerLogicalValue; + } + } + } + _yOffset_01 = GMFirstPictureIndex::instance[157]; + entityID = (uint)DAT_TileMapState::instance.EntityLayer[layerTileIndex]; + iVar23 = DAT_TileMapState::instance.OrganismLayer[layerTileIndex]; + local_2c = 0; + INT_00ed3154::instance = 0; + if ((DAT_00ed3148::instance & 0xa0108001) != 0) { + if ((DAT_00ed3148::instance & 1) != 0) { + uVar32 = (uint)(short)DAT_TileMapState::instance.RandomLayer[layerTileIndex]; + INT_00ed315c::instance = uVar32 & 0x7f; + INT_00ed314c::instance = uVar32 & 0xf; + DAT_RenderMap_YOffset::instance = 0; + DAT_RenderMap_RowsLeft::instance = 8; + if ((DAT_TileMapState::instance.Logic2Layer[layerTileIndex] & 8) != 0) { + INT_00ed3154::instance + = -(uint)((DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x20) != 0) + & 0x5a; + INT_00ed314c::instance = this->animationFrame16 + INT_00ed314c::instance; + if (15 < INT_00ed314c::instance) { + INT_00ed314c::instance = INT_00ed314c::instance - 16; + } + DAT_GmImageAddressToBeRendered::instance + = DAT_TileMapState::instance.GfxLayer[layerTileIndex] + INT_00ed314c::instance; + } else { + uVar10 = DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex]; + if ((char)uVar10 < '\0') { + DAT_GmImageAddressToBeRendered::instance + = (uint)DAT_TileMapState::instance.GfxLayer[layerTileIndex] + + DAT_MapRenderDefinedData::instance + .field_0x4dc[(this->animationFrame36 + INT_00ed314c::instance / 2) % 12]; + } else if ((uVar10 & 0x40) != 0) { + int const gfx = DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + if (gfx == GMFirstPictureIndex::instance[166] + 1500) { + int const waveFrame = (this->animationFrame36 + INT_00ed315c::instance) % 32; + if (waveFrame < 18) { + DAT_GmImageAddressToBeRendered::instance = gfx + waveFrame % 6; + } else { + DAT_GmImageAddressToBeRendered::instance + = DAT_MapRenderDefinedData::instance.field_0x4dc[waveFrame % 12] + 1488 + + GMFirstPictureIndex::instance[166]; + } + } else if (gfx == GMFirstPictureIndex::instance[166] + 1506) { + int const waveFrame = (this->animationFrame36 + INT_00ed315c::instance) % 32; + if (waveFrame < 18) { + DAT_GmImageAddressToBeRendered::instance = gfx + waveFrame % 12; + } else { + DAT_GmImageAddressToBeRendered::instance + = DAT_MapRenderDefinedData::instance.field_0x4dc[waveFrame % 12] + 1488 + + GMFirstPictureIndex::instance[166]; + } + } else if (gfx == GMFirstPictureIndex::instance[166] + 1518) { + int const waveFrame = (this->animationFrame36 + INT_00ed315c::instance) % 32; + if (waveFrame < 18) { + DAT_GmImageAddressToBeRendered::instance = gfx + waveFrame % 18; + } else { + DAT_GmImageAddressToBeRendered::instance + = DAT_MapRenderDefinedData::instance.field_0x4dc[waveFrame % 12] + 1488 + + GMFirstPictureIndex::instance[166]; + } + } + } else { + if ((uVar10 & 0x100) != 0) { + DAT_GmImageAddressToBeRendered::instance + = (uint)DAT_TileMapState::instance.GfxLayer[layerTileIndex] + + DAT_MapRenderDefinedData::instance.field_0x6a4[this->animationFrame32] + * 34; + } else { + if ((uVar10 & 0x200) == 0) { + INT_00ed314c::instance = uVar32 & 7; + piVar21 = this->landscapeSeaWhiteCapsAnimationFrames; + _yOffset_01 = 9; + do { + if (layerTileIndex == piVar21[-60]) { + local_2c = *piVar21 + 1 + (uVar32 & 3) * 8; + } + if (layerTileIndex == piVar21[-59]) { + local_2c = piVar21[1] + 1 + (uVar32 & 3) * 8; + } + if (layerTileIndex == piVar21[-58]) { + local_2c = piVar21[2] + 1 + (uVar32 & 3) * 8; + } + if (layerTileIndex == piVar21[-57]) { + local_2c = piVar21[3] + 1 + (uVar32 & 3) * 8; + } + if (layerTileIndex == piVar21[-56]) { + local_2c = piVar21[4] + 1 + (uVar32 & 3) * 8; + } + piVar21 = piVar21 + 5; + _yOffset_01 = _yOffset_01 - 1; + } while (_yOffset_01 != 0); + } + } + } + } + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::notifyAmbientSoundEvent, DAT_SFXState::ptr)(2); + _yOffset_01 = GMFirstPictureIndex::instance[157]; + } else if ((DAT_00ed3148::instance & 0x100000) != 0) { + DAT_RenderMap_RowsLeft::instance + = (uint)DAT_TileMapState::instance.ShowHiLayer[layerTileIndex]; + DAT_RenderMap_YOffset::instance + = DAT_TileMapState::instance + .heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[layerTileIndex]]; + byte const logic2 = DAT_TileMapState::instance.Logic2Layer[layerTileIndex]; + if ((logic2 & 200) != 0) { + INT_00ed3154::instance + = (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x20) != 0 ? 90 + : 0; + INT_00ed314c::instance + = DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] + this->animationFrame16; + DAT_GmImageAddressToBeRendered::instance + = INT_00ed314c::instance % 16 + DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + } else if ((logic2 & 7) != 0) { + INT_00ed3154::instance + = (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x20) != 0 ? 90 + : 0; + INT_00ed314c::instance = DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] + + this->animationFrame16 / 2; + DAT_GmImageAddressToBeRendered::instance + = INT_00ed314c::instance % 8 + DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + } else if ((logic2 & 0x10) != 0) { + INT_00ed3154::instance + = (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x20) != 0 ? 90 + : 0; + INT_00ed314c::instance + = DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] + this->animationFrame16; + DAT_GmImageAddressToBeRendered::instance + = INT_00ed314c::instance % 16 + DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + } else if ((logic2 & 0x20) != 0) { + INT_00ed3154::instance + = (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x20) != 0 ? 90 + : 0; + INT_00ed314c::instance = (DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] >> 10) + + this->animationFrame16 / 2; + DAT_GmImageAddressToBeRendered::instance + = INT_00ed314c::instance % 8 + DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + } + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::notifyAmbientSoundEvent, DAT_SFXState::ptr)(7); + _yOffset_01 = GMFirstPictureIndex::instance[157]; + } else if (DAT_00ed3148::instance == 0xa0008000) { + DAT_RenderMap_YOffset::instance + = DAT_TileMapState::instance + .heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[layerTileIndex]]; + DAT_RenderMap_RowsLeft::instance + = (uint)DAT_TileMapState::instance.ShowHiLayer[layerTileIndex]; + bVar15 = (byte)DAT_TileMapState::instance.RandomLayer[layerTileIndex]; + bVar19 = bVar15 & 7; + if (this->slowAnimationTicked != 0) { + DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] + = DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] + 1; + } + INT_00ed314c::instance = (uint)DAT_TileMapState::instance.WallGFXLayer[layerTileIndex]; + if ((bVar15 & 7) != 0) { + if (bVar19 == 1) { + if (510 < INT_00ed314c::instance) { + DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] = 0; + INT_00ed314c::instance = 0; + } + bVar15 = DAT_MapRenderDefinedData::instance.field_0x924[INT_00ed314c::instance]; + } else { + if ((bVar19 != 4) && (bVar19 != 5)) { + if (126 < INT_00ed314c::instance) { + DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] = 0; + INT_00ed314c::instance = 0; + } + DAT_GmImageAddressToBeRendered::instance + = (int)(char) + DAT_MapRenderDefinedData::instance.field_0xb24[INT_00ed314c::instance] + + (uint)DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + goto LAB_004e9845; + } + if (254 < INT_00ed314c::instance) { + DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] = 0; + INT_00ed314c::instance = 0; + } + bVar15 = DAT_MapRenderDefinedData::instance.field_0xb24[INT_00ed314c::instance]; + } + DAT_GmImageAddressToBeRendered::instance + = (int)(char)bVar15 + (uint)DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + } else { + if (511 < INT_00ed314c::instance) { + DAT_TileMapState::instance.WallGFXLayer[layerTileIndex] = 0; + INT_00ed314c::instance = 0; + } + DAT_GmImageAddressToBeRendered::instance + = (int)(char)DAT_MapRenderDefinedData::instance.field_0x724[INT_00ed314c::instance] + + (uint)DAT_TileMapState::instance.GfxLayer[layerTileIndex]; + } + } else { + uVar32 = (uint)DAT_TileMapState::instance.HeightLayer[layerTileIndex]; + if ((DAT_00ed3148::instance & 0x200) != 0 + && (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x3c0) != 0) { + uVar32 = uVar32 - 8; + } + DAT_RenderMap_YOffset::instance + = DAT_TileMapState::instance.heightBasedScreenYOffset[uVar32]; + if ((DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x20) == 0 + || DAT_TileMapState::instance.disableElevationRendering != 0) { + INT_00ed3154::instance = 0; + } else { + INT_00ed3154::instance = 90; + } + DAT_RenderMap_RowsLeft::instance + = (uint)DAT_TileMapState::instance.ShowHiLayer[layerTileIndex]; + } + } else { + uVar32 = (uint)DAT_TileMapState::instance.HeightLayer[layerTileIndex]; + if ((DAT_00ed3148::instance & 0x200) != 0 + && (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x3c0) != 0) { + uVar32 = uVar32 - 8; + } + DAT_RenderMap_YOffset::instance = DAT_TileMapState::instance.heightBasedScreenYOffset[uVar32]; + if ((DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x20) == 0 + || DAT_TileMapState::instance.disableElevationRendering != 0) { + INT_00ed3154::instance = 0; + } else { + INT_00ed3154::instance = 90; + } + DAT_RenderMap_RowsLeft::instance = (uint)DAT_TileMapState::instance.ShowHiLayer[layerTileIndex]; + } + LAB_004e9845: + local_54 = (uint)DAT_TileMapState::instance.BuildingLayer[layerTileIndex]; + if (_flatView != 0) { + DAT_RenderMap_YOffset::instance = 8; + if (this->DAT_MapEditorDisplayLayer != 0) { + DAT_RenderMap_RowsLeft::instance = 0; + INT_00ed3154::instance = 0; + } else { + uVar32 = (uint)(short)DAT_TileMapState::instance.RandomLayer[layerTileIndex]; + INT_00ed314c::instance = uVar32 & 0xf; + DAT_RenderMap_RowsLeft::instance = 0; + INT_00ed3154::instance = 0; + if (local_54 == 0 || (DAT_00ed3148::instance & 0x40000000) != 0) { + if ((DAT_00ed3148::instance & 0x100) != 0) { + if ((DAT_00ed3148::instance & 0x800) != 0) { + DAT_00ed3148::instance = DAT_00ed3148::instance & 1; + if ((DAT_GmImageAddressToBeRendered::instance + == GMFirstPictureIndex::instance[12] + 134U) + || (DAT_GmImageAddressToBeRendered::instance + == GMFirstPictureIndex::instance[12] + 136U)) { + DAT_GmImageAddressToBeRendered::instance = _yOffset_01 + 42; + } else { + DAT_GmImageAddressToBeRendered::instance = _yOffset_01 + 40; + } + } else { + if ((DAT_00ed3148::instance & 0x200) != 0) { + DAT_00ed3148::instance = DAT_00ed3148::instance & 1; + if (DAT_TileMapState::instance.DamageLayer[layerTileIndex] != 0) { + DAT_GmImageAddressToBeRendered::instance + = (uVar32 & 1) + 44 + _yOffset_01; + } else { + DAT_GmImageAddressToBeRendered::instance + = (uVar32 & 3) + 36 + _yOffset_01; + } + } else { + if (DAT_TileMapState::instance.DamageLayer[layerTileIndex] != 0) { + DAT_00ed3148::instance = DAT_00ed3148::instance & 1; + DAT_GmImageAddressToBeRendered::instance + = (uVar32 & 1) + 44 + _yOffset_01; + } + } + } + } else { + if ((DAT_00ed3148::instance & 0x80) != 0) { + _yOffset_01 = DAT_TileMapState::instance.OrganismLayer[layerTileIndex]; + if (_yOffset_01 < 2000) { + _yOffset_01 = MACRO_CALL_MEMBER( + OpenSHC::Map::LandscapeState_Func::getRandomRockImageOffset, + DAT_LandscapeState::ptr)((uVar32 & 3) + 1); + DAT_GmImageAddressToBeRendered::instance + = _yOffset_01 - 1 + GMFirstPictureIndex::instance[56]; + } else { + _yOffset_01 = _yOffset_01 * 32; + if (1 < *(short*)((int)&DAT_LandscapeState::instance.trees[1590] + .appleTreeColorVariation + + _yOffset_01 + 2)) { + iVar26 = MACRO_CALL_MEMBER( + OpenSHC::Map::LandscapeState_Func::getRandomRockImageOffset, + DAT_LandscapeState::ptr)((uVar32 & 3) + 1); + DAT_GmImageAddressToBeRendered::instance = iVar26 - 1 + + GMFirstPictureIndex::instance[*( + short*)((int)&DAT_LandscapeState::instance.trees[1590] + .animationFrameUnk + + _yOffset_01 + 2)]; + } + } + } + } + } else { + BVar8 = DAT_BuildingsState::instance.buildings[local_54].buildingType; + iVar26 = DAT_MapRenderDefinedData::instance.BuildingRenderSomeTypeArray[(short)BVar8]; + if (iVar26 == 3) { + uVar32 = (uint)((DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 4) + != 0); + if (BVar8 == OpenSHC::Map::Buildings::BT_WOODCUTTERSHUT) { + DAT_GmImageAddressToBeRendered::instance = _yOffset_01 + 24 + uVar32; + } else if (BVar8 == OpenSHC::Map::Buildings::BT_HUNTERSHUT) { + DAT_GmImageAddressToBeRendered::instance = _yOffset_01 + 26 + uVar32; + } else if (BVar8 == OpenSHC::Map::Buildings::BT_DAIRYFARM) { + DAT_GmImageAddressToBeRendered::instance = _yOffset_01 + 28 + uVar32; + } else { + DAT_GmImageAddressToBeRendered::instance = _yOffset_01 + 30 + uVar32; + } + } else if (-1 < iVar26) { + DAT_GmImageAddressToBeRendered::instance + = (uVar32 & 3) + _yOffset_01 + ((local_54 & 1) + iVar26 * 2) * 4; + } + } + } + } + DAT_RenderMap_ImageID::instance + = (uint)DAT_TileMapState::instance.ConstructionGFXLayer[layerTileIndex]; + bVar12 = 0; + bVar14 = 0; + if (DAT_RenderMap_ImageID::instance != 0) { + if (DAT_TileMapState::instance.buildingPlacementFail == FALSE + || (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x8000) != 0) { + DAT_GmImageAddressToBeRendered::instance = DAT_RenderMap_ImageID::instance; + if ((DAT_00ed3148::instance & 0x100) != 0 && _flatView == 0) { + DAT_RenderMap_YOffset::instance + = DAT_TileMapState::instance.heightBasedScreenYOffset[DAT_TileMapState::instance + .DefaultHeightLayer[layerTileIndex]]; + } + } else { + bVar12 = 1; + bVar14 = 1; + } + } else { + if ((DAT_00ed3148::instance & 0x4000) != 0 && DAT_TileMapState::instance.field_0x5549b8 != 0 + && (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY + || (_yOffset_01 + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, + DAT_TileMapState::ptr)(layerTileIndex), + DAT_GameState::instance.mapAndTime + .playerTeams[DAT_TileMapState::instance.moats[_yOffset_01].owner] + == DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID]))) { + DAT_RenderMap_ImageID::instance = 57; + bVar12 = 1; + bVar14 = 1; + } + } + unitID = (int)(short)DAT_TileMapState::instance.UnitLayer[layerTileIndex]; + if (unitID != 0 && unitID == DAT_UnitsState::instance.lastSelectedUnitID + && DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_DEBUG_DATA_UNIT_DATA) { + DAT_GmImageAddressToBeRendered::instance + = ((byte)DAT_UnitsState::instance.units[unitID].moveDelay & 0x3f) + + GMFirstPictureIndex::instance[38]; + } + if ((DAT_00ed3148::instance & 8) != 0 + && (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x2000) == 0 + && _flatView == 0) { + DAT_RenderMap_YOffset::instance + = DAT_TileMapState::instance + .heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[layerTileIndex] + 4]; + } + if (local_54 != 0) { + uVar9 = *this->viewportState.ptrColor; + *this->viewportState.ptrColor = COL_MAGENTA::instance.shortValue; + } + if (DAT_RenderMap_RowsLeft::instance != 0xff && bVar13 != 0 + && (MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderTerrainTilesCenterPiece)(), bVar12 != 0)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS, + DAT_RenderMap_ImageID::instance, DAT_RenderMap_DrawSomeX::instance, + (INT_00ed3154::instance - DAT_RenderMap_YOffset::instance) + + DAT_RenderMap_DrawSomeY::instance, + 24); + } + if (DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance].direction != 0 + && local_54 == 0 && bVar13 != 0 && bVar12 == 0) { + _yOffset_01 = (int)DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance] + .tileOffset; + /* + renders preview of selected object + */ + + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderFunctionResponsibleForManyGameObjects, + DAT_TextureRenderCoreObject::ptr)( + (char)DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance] + .horizontalOffsetImage + + DAT_RenderMap_DrawSomeX::instance, + (int)(((INT_00ed3154::instance - DAT_RenderMap_YOffset::instance) - _yOffset_01) + + DAT_RenderMap_DrawSomeY::instance), + (int)((char)DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance] + .buildingWidth), + _yOffset_01 + 7, + (ushort*)((int)( + + (DAT_GMImageOffsets::instance[DAT_GmImageAddressToBeRendered::instance] + 512 + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData)))); + } + if (local_2c != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ANIM_WHITECAPS, local_2c, + (DAT_RenderMap_DrawSomeX::instance + - DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[173].originX) + + 15, + (DAT_RenderMap_DrawSomeY::instance + - DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[173].originY) + + 7); + } + if (local_54 != 0) { + if (*this->viewportState.ptrColor == COL_MAGENTA::instance.shortValue) { + *this->viewportState.ptrColor = uVar9; + } else { + this->viewportState.mouseRayUnitID = 0; + this->viewportState.mouseRayBuildingID = local_54; + } + } + if ((DAT_00ed3148::instance & 0x201) == 0 && local_54 == 0) { + uVar10 = DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex]; + if ((uVar10 & 0x3c0) != 0 + && (DAT_RenderMap_ImageID::instance == 0 + || (((DAT_00ed3148::instance & 0x4000) != 0 + && (DAT_TileMapState::instance.field_0x5549b8 != 0)))) + && (DAT_00ed3148::instance & 0x30) == 0 && _flatView == 0) { + uVar32 = (uint)DAT_TileMapState::instance.WallGFXLayer[layerTileIndex]; + DAT_GmImageAddressToBeRendered::instance + = (uint)DAT_TileMapState::instance.AlphaGFXLayer[layerTileIndex]; + iVar26 = uVar32 - DAT_TileMapState::instance.heightBasedScreenYOffset[uVar32]; + _yOffset_01 = DAT_RenderMap_DrawSomeX::instance; + if ((uVar10 & 0x40) != 0) { + iVar26 = (iVar26 - uVar32) + INT_00ed3154::instance + 7; + } else { + if ((char)uVar10 < '\0') { + _yOffset_01 = (int)DAT_GMImageHeaders::instance + .imh[DAT_GmImageAddressToBeRendered::instance + + GMFirstPictureIndex::instance[54] - 1] + .height; + /* + renders wall connections + */ + + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderFunctionResponsibleForManyGameObjects, + DAT_TextureRenderCoreObject::ptr)(DAT_RenderMap_DrawSomeX::instance, + (int)(((iVar26 - uVar32) - _yOffset_01) + INT_00ed3154::instance + 98 + + DAT_RenderMap_DrawSomeY::instance), + DAT_GMImageHeaders::instance + .imh[DAT_GmImageAddressToBeRendered::instance + + GMFirstPictureIndex::instance[54] - 1] + .width, + _yOffset_01 - iVar26, + (ushort*)((int)( + + (DAT_GMImageOffsets::instance[GMFirstPictureIndex::instance[54] - 1 + + DAT_GmImageAddressToBeRendered::instance] + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData)))); + goto LAB_004e9e36; + } + if ((uVar10 & 0x100) != 0) { + iVar26 = (iVar26 - uVar32) + INT_00ed3154::instance; + _yOffset_01 = DAT_RenderMap_DrawSomeX::instance + 16; + } else { + if ((uVar10 & 0x200) == 0) + goto LAB_004e9e36; + iVar26 = (iVar26 - uVar32) + INT_00ed3154::instance - 1; + } + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_CASTLE_ANIMS, + DAT_GmImageAddressToBeRendered::instance, _yOffset_01, + (int)(iVar26 + DAT_RenderMap_DrawSomeY::instance)); + } + } + LAB_004e9e36: + _yOffset_01 = DAT_RenderMap_YOffset::instance; + uVar32 = (uint)DAT_TileMapState::instance.FloatingLayer[layerTileIndex]; + if (uVar32 != 0) { + if ((DAT_TileMapState::instance.refreshRelatedOne != 0) && (_flatView == 0)) { + if ((DAT_TileMapState::instance.LogicLayer[layerTileIndex] + & Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE) + != 0) { + local_54 = (uint)DAT_TileMapState::instance.BuildingLayer[layerTileIndex]; + iVar26 = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(local_54); + _yOffset_01 = _yOffset_01 + iVar26; + } else { + if ((DAT_TileMapState::instance.LogicLayer[layerTileIndex] + & Map::LogicHelpers::L_WALL_OR_GATEHOUSE) + != 0) { + local_54 = (uint)DAT_TileMapState::instance.BuildingLayer[layerTileIndex]; + if (local_54 == 0) { + _yOffset_01 = DAT_RenderMap_YOffset::instance + 4; + } else if (DAT_BuildingsState::instance.buildings[local_54].buildingType + == OpenSHC::Map::Buildings::BT_WOODGATE1) { + _yOffset_01 = DAT_RenderMap_YOffset::instance + 6; + } else { + _yOffset_01 = DAT_RenderMap_YOffset::instance + 20; + } + } + } + } + do { + uVar29 = this->floatersArray[uVar32].variation; + if ((uVar29 & 2) != 0) { + if ((DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x10) != 0) { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::scheduleUnitForBatchedRendering, + this)(0, + this->floatersArray[uVar32].originX + DAT_RenderMap_DrawSomeX::instance, + (this->floatersArray[uVar32].originY - _yOffset_01) + + DAT_RenderMap_DrawSomeY::instance, + (undefined4)(this->floatersArray[uVar32].imageID), (undefined4)((int)(uVar29)), + (undefined4)((int)(this->floatersArray[uVar32].gmID)), 0); + } else { + if ((uVar29 & 4) != 0) { + DAT_RenderedUnitOwner::instance = ~-(uint)((uVar29 & 0x10) != 0) + & DAT_GameSynchronyState::instance.currentPlayerSlotID; + DAT_CurrentlyRenderedSpriteID::instance = this->floatersArray[uVar32].gmID; + uVar29 = this->floatersArray[uVar32].variation; + } + if ((uVar29 & 0x20) != 0) { + iVar26 = this->floatersArray[uVar32].imageID; + GVar11 = (GmID)this->floatersArray[uVar32].gmID; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)((GmID)GVar11, iVar26, + this->floatersArray[uVar32].originX + DAT_RenderMap_DrawSomeX::instance, + (int)((this->floatersArray[uVar32].originY - _yOffset_01) + + DAT_RenderMap_DrawSomeY::instance), + GVar11, ((int)uVar29 >> 0x10) + iVar26, 0); + } else { + if ((uVar29 & 0xffff0000) != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + (GmID)this->floatersArray[uVar32].gmID, + this->floatersArray[uVar32].imageID, + this->floatersArray[uVar32].originX + DAT_RenderMap_DrawSomeX::instance, + (int)((this->floatersArray[uVar32].originY - _yOffset_01) + + DAT_RenderMap_DrawSomeY::instance), + (int)(uVar29 >> 0x10)); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((eGM)this->floatersArray[uVar32].gmID, + this->floatersArray[uVar32].imageID, + this->floatersArray[uVar32].originX + DAT_RenderMap_DrawSomeX::instance, + (int)((this->floatersArray[uVar32].originY - _yOffset_01) + + DAT_RenderMap_DrawSomeY::instance)); + } + } + } + } + uVar32 = this->floatersArray[uVar32].nextFloaterID; + } while (uVar32 != 0); + } + _yOffset_01 = 0; + if (entityID != 0) { + while ((iVar26 = DAT_RenderMap_YOffset::instance, _yOffset_01 = _yOffset_01 + 1, + _yOffset_01 < 10 && (DAT_EntityState::instance.entityArray[entityID].logicalState != 0))) { + if (DAT_EntityState::instance.entityArray[entityID].graphicType2 != 0 + && ((EVar3 = DAT_EntityState::instance.entityArray[entityID].entityType, + EVar3 == OpenSHC::Map::Entities::EntityTypeInt__ET_CROW + || (EVar3 == OpenSHC::Map::Entities::ET_SEAGULLUnk)) + || (EVar3 == OpenSHC::Map::Entities::ET_COW_FLYING)) + && DAT_EntityState::instance.entityArray[entityID].imageID != 0) { + DAT_RenderedUnitOwner::instance + = DAT_EntityState::instance.entityArray[entityID].colorUnk; + DAT_CurrentlyRenderedSpriteID::instance + = (GmIDInt)DAT_EntityState::instance.entityArray[entityID].gmID; + if ((DAT_TileMapState::instance.LogicLayer[layerTileIndex] + & Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE) + != 0) { + local_54 = (uint)DAT_TileMapState::instance.BuildingLayer[layerTileIndex]; + iVar18 = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(local_54); + iVar26 = iVar26 + iVar18; + } else { + if ((DAT_TileMapState::instance.LogicLayer[layerTileIndex] + & Map::LogicHelpers::L_WALL_OR_GATEHOUSE) + != 0) { + local_54 = (uint)DAT_TileMapState::instance.BuildingLayer[layerTileIndex]; + if (local_54 == 0) { + iVar26 = DAT_RenderMap_YOffset::instance + 4; + } else { + iVar26 = DAT_RenderMap_YOffset::instance + 20; + } + } + } + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::scheduleUnitForBatchedRendering, + this)(4294967295, + (DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance, + ((DAT_EntityState::instance.entityArray[entityID].y1 + - DAT_EntityState::instance.entityArray[entityID].originY) + - iVar26) + + DAT_RenderMap_DrawSomeY::instance, + (undefined4)(DAT_EntityState::instance.entityArray[entityID].imageID), 20, 0, 0); + } + iVar26 = DAT_EntityState::instance.entityArray[entityID].nextEntityOnThisTileByID; + if (entityID == iVar26 || DAT_GameSynchronyState::instance.syncStatus != 0 + || (entityID = iVar26, iVar26 == 0)) + break; + } + } + entityID = (uint)DAT_TileMapState::instance.EntityLayer[layerTileIndex]; + if (local_54 != 0 + && DAT_BuildingsState::instance.buildings[local_54].buildingType + == OpenSHC::Map::Buildings::BT_DRAWBRIDGE + && _flatView == 0 && DAT_TileMapState::instance.refreshRelatedOne != 0 + && (DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0xc) == 4) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::renderGmOverlayBuilding2, this)( + local_54, DAT_RenderMap_DrawSomeX::instance, + INT_00ed3154::instance + DAT_RenderMap_DrawSomeY::instance, layerTileIndex); + } + /* + ------ BEGIN RENDER UNITS ------ + */ + + if ((unitID != 0) + && (MACRO_CALL_MEMBER( + OpenSHC::Map::Units::UnitsState_Func::triggerDesyncIfTileUnitLinkageInvalid, + DAT_UnitsState::ptr)(layerTileIndex), + 0 < unitID)) { + while (_yOffset_01 = DAT_RenderMap_DrawSomeX::instance, + DAT_UnitsState::instance.units[unitID].logicalState != OpenSHC::Map::Units::ULS_INVISIBLE) { + DAT_CurrentlyRenderedSpriteID::instance + = (GmIDInt)DAT_UnitsState::instance.units[unitID].spriteID; + local_2c = 0; + if ((DAT_UnitsState::instance.units[unitID].unitType == OpenSHC::Map::Units::UT_A_ASSASSIN) + && (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_UnitsState::instance.units[unitID].owner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID])) { + iVar26 = DAT_UnitsState::instance.units[unitID].assassinsMicroDistanceToEnemyUnk; + if (iVar26 <= 160 + || (UVar4 = DAT_UnitsState::instance.units[unitID].state.generic, + UVar4 == OpenSHC::Map::Units::States::US_MELEE_ATTACK + || (UVar4 == OpenSHC::Map::Units::States::US_MELEE_ATTACK_WALL))) { + if (120 < iVar26 + && (DAT_GameSynchronyState::instance.currentGameMode + != OpenSHC::Game::GM_SOLITARY + || (DAT_UnitsState::instance.units[unitID].idleCounterUnk < 2401))) { + local_2c = 16; + } + goto LAB_004ea2c6; + } + if ((DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) + && (2400 < DAT_UnitsState::instance.units[unitID].idleCounterUnk)) + goto LAB_004ea2c6; + } else { + LAB_004ea2c6: + if (DAT_UnitsState::instance.units[unitID].field_0x5a != 0) { + DAT_RenderedUnitOwner::instance = 9; + } else { + DAT_RenderedUnitOwner::instance + = DAT_UnitsState::instance.units[unitID].calculatedOwnerPlayerIndex; + } + iVar18 = GMFirstPictureIndex::instance[DAT_CurrentlyRenderedSpriteID::instance]; + iVar27 = DAT_UnitsState::instance.units[unitID].gfxNumber; + iVar26 = iVar27 - 1 + iVar18; + iVar25 = DAT_RenderMap_YOffset::instance; + if (DAT_TileMapState::instance.refreshRelatedOne != 0) { + if (_flatView != 0) { + iVar25 = ((int)(char)DAT_UnitsState::instance.units[unitID].negativeHeight + - DAT_UnitsState::instance.units[unitID].buildingHeight) + + DAT_RenderMap_YOffset::instance; + } else { + iVar25 = (uint)(byte)DAT_UnitsState::instance.units[unitID].field_0x83 + + DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight; + } + } + sVar30 = DAT_UnitsState::instance.units[unitID].orientationRelatedPositionX; + sVar20 = DAT_UnitsState::instance.units[unitID].orientationRelatedPositionY; + DAT_UnitsState::instance.units[unitID].field_0x41c + = sVar30 - 6 + DAT_RenderMap_DrawSomeX::instance; + sVar30 = ((short)DAT_UnitsState::instance.units[unitID].field_0x5c + - DAT_UnitsState::instance.units[unitID].field_0x2a) + + (short)_yOffset_01 + sVar30; + bVar15 = DAT_UnitsState::instance.units[unitID].negativeHeight; + DAT_UnitsState::instance.units[unitID].field_0x420 + = (sVar20 - iVar25) - 12 + DAT_RenderMap_DrawSomeY::instance; + sVar24 = (short)DAT_UnitsState::instance.units[unitID].unknownV; + sVar5 = DAT_UnitsState::instance.units[unitID].field_0x84; + sVar6 = DAT_UnitsState::instance.units[unitID].buildingHeight; + DAT_UnitsState::instance.units[unitID].drawX = sVar30; + sVar20 = (((sVar5 - sVar6) - (short)iVar25) - sVar24) + + (short)DAT_RenderMap_DrawSomeY::instance + (short)(char)bVar15 + sVar20; + sVar5 = DAT_GMImageHeaders::instance.imh[iVar18 + iVar27 - 1].width; + DAT_UnitsState::instance.units[unitID].drawY = sVar20; + DAT_UnitsState::instance.units[unitID].drawWidth = sVar5; + if (bVar15 != 0) { + sVar24 = (sVar24 - (char)bVar15) + 8; + } else { + sVar24 = DAT_GMImageHeaders::instance.imh[iVar18 + iVar27 - 1].height; + } + _yOffset_01 = DAT_UnitsState::instance.units[unitID].vanish; + DAT_UnitsState::instance.units[unitID].drawHeight1 = sVar24; + if (_yOffset_01 != 0) { + if (_yOffset_01 != 1) { + if (local_2c != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)(sVar30, sVar20, sVar5, + DAT_UnitsState::instance.units[unitID].drawHeight1, + (byte*)((int)((DAT_GMImageOffsets::instance[iVar26] + + (int) + DAT_TextureRenderCoreObject::instance.gmProcessedImageData))), + local_2c); + } else { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)(sVar30, sVar20, sVar5, + DAT_UnitsState::instance.units[unitID].drawHeight1, + (byte*)((int)((DAT_GMImageOffsets::instance[iVar26] + + (int) + DAT_TextureRenderCoreObject::instance.gmProcessedImageData)))); + } + _yOffset_01 = DAT_UnitsState::instance.units[unitID].vanish; + if (1 < _yOffset_01) { + DAT_UnitsState::instance.units[unitID].vanish = _yOffset_01 - 1; + } + } + } else { + + _yOffset_01 = DAT_UnitsState::instance.units[unitID].field_0x64; + if (_yOffset_01 == 1) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func:: + scheduleUnitForBatchedRendering, + this)(unitID, (undefined4)(sVar30), (undefined4)(sVar20), + (undefined4)(sVar5), + (undefined4)(DAT_UnitsState::instance.units[unitID].drawHeight1), + (undefined4)((int)(DAT_GMImageOffsets::instance[iVar26] + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData)), + 1); + } else if (_yOffset_01 == 2) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func:: + scheduleUnitForBatchedRendering, + this)(unitID, (undefined4)(sVar30), (undefined4)(sVar20), + (undefined4)(sVar5), + (undefined4)(DAT_UnitsState::instance.units[unitID].drawHeight1), + (undefined4)((int)(DAT_GMImageOffsets::instance[iVar26] + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData)), + 0); + } else if ((DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex] & 0x10) != 0 + && DAT_UnitsState::instance.units[unitID].field_0x64 != -1) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func:: + scheduleUnitForBatchedRendering, + this)(unitID, (undefined4)(sVar30), (undefined4)(sVar20), + (undefined4)(sVar5), + (undefined4)(DAT_UnitsState::instance.units[unitID].drawHeight1), + (undefined4)((int)(DAT_GMImageOffsets::instance[iVar26] + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData)), + 0); + } else if ((DAT_00ed3148::instance & 0x400) != 0) { + if (DAT_BuildingsState::instance.buildings[local_54].buildingType + != OpenSHC::Map::Buildings::BT_TOWER2 + || (sVar24 = DAT_UnitsState::instance.units[unitID] + .facingDirectionMapOrientationCorrected, + sVar24 != 2 && (sVar24 != 6))) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func:: + scheduleUnitForBatchedRendering, + this)(unitID, (undefined4)(sVar30), (undefined4)(sVar20), + (undefined4)(sVar5), + (undefined4)(DAT_UnitsState::instance.units[unitID].drawHeight1), + (undefined4)((int)(DAT_GMImageOffsets::instance[iVar26] + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData)), + 1); + } else { + if ((DAT_UnitsState::instance.units[unitID].unitType + == OpenSHC::Map::Units::UT_A_ASSASSIN) + && (_yOffset_01 = DAT_UnitsState::instance.units[unitID].imageID2, + _yOffset_01 != 0)) { + sVar24 = DAT_UnitsState::instance.units[unitID].field_0x86; + if (sVar24 < 0) { + local_14 = 0; + } else { + local_14 = sVar24; + } + iVar27 = (32 - local_2c) / 3; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)(sVar30, + DAT_UnitsState::instance.units[unitID].field_0x86 + sVar20, sVar5, + DAT_UnitsState::instance.units[unitID].drawHeight1 - local_14, + (byte*)(( + int)((DAT_GMImageOffsets::instance[_yOffset_01 - 1 + iVar18] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData))), + (16 - iVar27) * 2); + sVar30 = DAT_UnitsState::instance.units[unitID].drawYOffset; + if (sVar30 != 0) { + sVar20 = DAT_UnitsState::instance.units[unitID].field_0x86; + if (sVar20 < 0) { + _yOffset_01 = 0; + } else { + _yOffset_01 = sVar20; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar20 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 + - _yOffset_01, + (byte*)(( + int)((DAT_GMImageOffsets::instance + [GMFirstPictureIndex::instance + [DAT_CurrentlyRenderedSpriteID::instance] + - 1 + sVar30] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData))), + 32 - iVar27); + } + } + uVar9 = *this->viewportState.ptrColor; + *this->viewportState.ptrColor = COL_MAGENTA::instance.shortValue; + sVar30 = DAT_UnitsState::instance.units[unitID].field_0x86; + if (local_2c != 0) { + if (sVar30 < 0) { + _yOffset_01 = 0; + } else { + _yOffset_01 = sVar30; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar30 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 - _yOffset_01, + (byte*)((int)((DAT_GMImageOffsets::instance[iVar26] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData))), + local_2c); + } else { + if (sVar30 < 0) { + _yOffset_01 = 0; + } else { + _yOffset_01 = sVar30; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar30 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 - _yOffset_01, + (byte*)((int)((DAT_GMImageOffsets::instance[iVar26] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData)))); + } + sVar30 = DAT_UnitsState::instance.units[unitID].graphicSize; + if (sVar30 != 4 && sVar30 >= 2) { + DAT_CurrentlyRenderedSpriteID::instance + = (GmIDInt)DAT_UnitsState::instance.units[unitID].gmIDUnk; + DAT_RenderedUnitOwner::instance + = (uint)DAT_UnitsState::instance.units[unitID].displayColorPlayerID; + _yOffset_01 = DAT_UnitsState::instance.units[unitID].imageIDUnk; + if (0 < _yOffset_01) { + sVar30 = DAT_UnitsState::instance.units[unitID].field_0x88; + if (sVar30 < 0) { + iVar26 = 0; + } else { + iVar26 = sVar30; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar30 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 - iVar26, + (byte*)(( + int)((DAT_GMImageOffsets::instance + [GMFirstPictureIndex::instance + [DAT_CurrentlyRenderedSpriteID::instance] + + _yOffset_01 - 1] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData)))); + } + } + if (DAT_UnitsState::instance.units[unitID].graphicSize >= 3) { + _yOffset_01 = DAT_UnitsState::instance.units[unitID].imageID2; + if (0 < _yOffset_01) { + sVar30 = DAT_UnitsState::instance.units[unitID].drawYOffset; + if (sVar30 < 0) { + iVar26 = 0; + } else { + iVar26 = sVar30; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar30 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 - iVar26, + (byte*)(( + int)((DAT_GMImageOffsets::instance + [GMFirstPictureIndex::instance + [DAT_CurrentlyRenderedSpriteID::instance] + + _yOffset_01 - 1] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData)))); + } + if (DAT_GameSynchronyState::instance.currentGameMode + != OpenSHC::Game::GM_SOLITARY) { + UVar7 = DAT_UnitsState::instance.units[unitID].unitType; + if ((UVar7 == OpenSHC::Map::Units::UT_S_TOWER) + && (DAT_UnitsState::instance.units[unitID].dying == 0)) { + _yOffset_01 = DAT_UnitsState::instance.units[unitID].drawX; + iVar26 = DAT_UnitsState::instance.units[unitID].drawY; + switch (DAT_UnitsState::instance.units[unitID] + .facingDirectionMapOrientationCorrected) { + case 0: + _yOffset_01 = _yOffset_01 + 34; + break; + case 1: + _yOffset_01 = _yOffset_01 + 47; + iVar26 = iVar26 - 12; + break; + case 2: + _yOffset_01 = _yOffset_01 + 75; + iVar26 = iVar26 - 19; + break; + case 3: + _yOffset_01 = _yOffset_01 + 101; + iVar26 = iVar26 - 10; + break; + case 4: + _yOffset_01 = _yOffset_01 + 112; + iVar26 = iVar26 + 2; + break; + case 5: + _yOffset_01 = _yOffset_01 + 100; + iVar26 = iVar26 + 20; + break; + case 6: + _yOffset_01 = _yOffset_01 + 70; + iVar26 = iVar26 + 19; + break; + case 7: + _yOffset_01 = _yOffset_01 + 44; + iVar26 = iVar26 + 23; + } + } else { + if ((UVar7 != OpenSHC::Map::Units::UT_S_BATTERINGRAM) + || (DAT_UnitsState::instance.units[unitID].dying != 0)) + goto LAB_004ea966; + _yOffset_01 = DAT_UnitsState::instance.units[unitID].drawX; + iVar26 = DAT_UnitsState::instance.units[unitID].drawY; + switch (DAT_UnitsState::instance.units[unitID] + .facingDirectionMapOrientationCorrected) { + case 0: + case 1: + _yOffset_01 = _yOffset_01 + 44; + iVar26 = iVar26 - 20; + break; + case 2: + _yOffset_01 = _yOffset_01 + 49; + iVar26 = iVar26 - 17; + break; + case 3: + _yOffset_01 = _yOffset_01 + 41; + iVar26 = iVar26 - 15; + break; + case 4: + _yOffset_01 = _yOffset_01 + 34; + iVar26 = iVar26 - 17; + break; + case 5: + case 6: + _yOffset_01 = _yOffset_01 + 32; + iVar26 = iVar26 - 20; + break; + case 7: + _yOffset_01 = _yOffset_01 + 40; + iVar26 = iVar26 - 23; + } + } + DAT_RenderedUnitOwner::instance + = (uint)DAT_UnitsState::instance.units[unitID].owner; + DAT_CurrentlyRenderedSpriteID::instance + = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + uVar32 = DAT_UnitsState::instance.units[unitID].fixedRng + + DAT_GameState::instance.mapAndTime.totalGameTicksUnk + & 0x8000003f; + if ((int)uVar32 < 0) { + uVar32 = (uVar32 - 1 | 0xffffffc0) + 1; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, (int)(uVar32 / 2 + 1), + _yOffset_01, iVar26); + } + } + LAB_004ea966: + if (*this->viewportState.ptrColor == COL_MAGENTA::instance.shortValue) { + *this->viewportState.ptrColor = uVar9; + } else { + this->viewportState.mouseRayUnitID = unitID; + this->viewportState.mouseRayBuildingID = 0; + } + } + } else { + if ((DAT_UnitsState::instance.units[unitID].unitType + == OpenSHC::Map::Units::UT_A_ASSASSIN) + && (_yOffset_01 = DAT_UnitsState::instance.units[unitID].imageID2, + _yOffset_01 != 0)) { + sVar24 = DAT_UnitsState::instance.units[unitID].field_0x86; + if (sVar24 < 0) { + local_c = 0; + } else { + local_c = (uint)sVar24; + } + iVar27 = (32 - local_2c) / 3; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)(sVar30, + DAT_UnitsState::instance.units[unitID].field_0x86 + sVar20, sVar5, + (int)(DAT_UnitsState::instance.units[unitID].drawHeight1 - local_c), + (byte*)((int)((DAT_GMImageOffsets::instance[_yOffset_01 - 1 + iVar18] + + (int) + DAT_TextureRenderCoreObject::instance.gmProcessedImageData))), + (16 - iVar27) * 2); + sVar30 = DAT_UnitsState::instance.units[unitID].drawYOffset; + if (sVar30 != 0) { + sVar20 = DAT_UnitsState::instance.units[unitID].field_0x86; + if (sVar20 < 0) { + _yOffset_01 = 0; + } else { + _yOffset_01 = sVar20; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar20 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 - _yOffset_01, + (byte*)((int)((DAT_GMImageOffsets::instance + [GMFirstPictureIndex::instance + [DAT_CurrentlyRenderedSpriteID::instance] + - 1 + sVar30] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData))), + 32 - iVar27); + } + } + uVar9 = *this->viewportState.ptrColor; + *this->viewportState.ptrColor = COL_MAGENTA::instance.shortValue; + bVar15 = DAT_UnitsState::instance.units[unitID].disappearFadeAlphaCountdown; + if (bVar15 != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1, + (byte*)((int)((DAT_GMImageOffsets::instance[iVar26] + + (int) + DAT_TextureRenderCoreObject::instance.gmProcessedImageData))), + (int)((char)bVar15)); + if (*this->viewportState.ptrColor == COL_MAGENTA::instance.shortValue) { + *this->viewportState.ptrColor = uVar9; + } else { + this->viewportState.mouseRayUnitID = unitID; + this->viewportState.mouseRayBuildingID = 0; + } + } else { + if (DAT_UnitsState::instance.units[unitID].graphicSize == 4) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func:: + renderAssassinClimbingOverlay, + this)(unitID); + } + sVar30 = DAT_UnitsState::instance.units[unitID].field_0x86; + if (sVar30 < 0) { + _yOffset_01 = 0; + } else { + _yOffset_01 = sVar30; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar30 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 - _yOffset_01, + (byte*)((int)((DAT_GMImageOffsets::instance[iVar26] + + (int) + DAT_TextureRenderCoreObject::instance.gmProcessedImageData)))); + sVar30 = DAT_UnitsState::instance.units[unitID].graphicSize; + if (sVar30 != 4 && sVar30 >= 2) { + DAT_CurrentlyRenderedSpriteID::instance + = (GmIDInt)DAT_UnitsState::instance.units[unitID].gmIDUnk; + DAT_RenderedUnitOwner::instance + = (uint)DAT_UnitsState::instance.units[unitID].displayColorPlayerID; + _yOffset_01 = DAT_UnitsState::instance.units[unitID].imageIDUnk; + if (0 < _yOffset_01) { + sVar30 = DAT_UnitsState::instance.units[unitID].field_0x88; + if (sVar30 < 0) { + iVar26 = 0; + } else { + iVar26 = sVar30; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar30 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 - iVar26, + (byte*)(( + int)((DAT_GMImageOffsets::instance + [GMFirstPictureIndex::instance + [DAT_CurrentlyRenderedSpriteID::instance] + + _yOffset_01 - 1] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData)))); + } + } + if (DAT_UnitsState::instance.units[unitID].graphicSize >= 3) { + _yOffset_01 = DAT_UnitsState::instance.units[unitID].imageID2; + if (0 < _yOffset_01) { + sVar30 = DAT_UnitsState::instance.units[unitID].drawYOffset; + if (sVar30 < 0) { + iVar26 = 0; + } else { + iVar26 = sVar30; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)( + DAT_UnitsState::instance.units[unitID].drawX, + sVar30 + DAT_UnitsState::instance.units[unitID].drawY, + DAT_UnitsState::instance.units[unitID].drawWidth, + DAT_UnitsState::instance.units[unitID].drawHeight1 - iVar26, + (byte*)(( + int)((DAT_GMImageOffsets::instance + [GMFirstPictureIndex::instance + [DAT_CurrentlyRenderedSpriteID::instance] + + _yOffset_01 - 1] + + (int)DAT_TextureRenderCoreObject::instance + .gmProcessedImageData)))); + } + if (DAT_GameSynchronyState::instance.currentGameMode + != OpenSHC::Game::GM_SOLITARY) { + UVar7 = DAT_UnitsState::instance.units[unitID].unitType; + if ((UVar7 == OpenSHC::Map::Units::UT_S_TOWER) + && (DAT_UnitsState::instance.units[unitID].dying == 0)) { + _yOffset_01 = DAT_UnitsState::instance.units[unitID].drawX; + iVar26 = DAT_UnitsState::instance.units[unitID].drawY; + switch (DAT_UnitsState::instance.units[unitID] + .facingDirectionMapOrientationCorrected) { + case 0: + _yOffset_01 = _yOffset_01 + 34; + break; + case 1: + _yOffset_01 = _yOffset_01 + 47; + iVar26 = iVar26 - 12; + break; + case 2: + _yOffset_01 = _yOffset_01 + 75; + iVar26 = iVar26 - 19; + break; + case 3: + _yOffset_01 = _yOffset_01 + 101; + iVar26 = iVar26 - 10; + break; + case 4: + _yOffset_01 = _yOffset_01 + 112; + iVar26 = iVar26 + 2; + break; + case 5: + _yOffset_01 = _yOffset_01 + 100; + iVar26 = iVar26 + 20; + break; + case 6: + _yOffset_01 = _yOffset_01 + 70; + iVar26 = iVar26 + 19; + break; + case 7: + _yOffset_01 = _yOffset_01 + 44; + iVar26 = iVar26 + 23; + } + } else { + if ((UVar7 != OpenSHC::Map::Units::UT_S_BATTERINGRAM) + || (DAT_UnitsState::instance.units[unitID].dying != 0)) + goto LAB_004eadfa; + _yOffset_01 = DAT_UnitsState::instance.units[unitID].drawX; + iVar26 = DAT_UnitsState::instance.units[unitID].drawY; + switch (DAT_UnitsState::instance.units[unitID] + .facingDirectionMapOrientationCorrected) { + case 0: + case 1: + _yOffset_01 = _yOffset_01 + 44; + iVar26 = iVar26 - 20; + break; + case 2: + _yOffset_01 = _yOffset_01 + 49; + iVar26 = iVar26 - 17; + break; + case 3: + _yOffset_01 = _yOffset_01 + 41; + iVar26 = iVar26 - 15; + break; + case 4: + _yOffset_01 = _yOffset_01 + 34; + iVar26 = iVar26 - 17; + break; + case 5: + case 6: + _yOffset_01 = _yOffset_01 + 32; + iVar26 = iVar26 - 20; + break; + case 7: + _yOffset_01 = _yOffset_01 + 40; + iVar26 = iVar26 - 23; + } + } + DAT_RenderedUnitOwner::instance + = (uint)DAT_UnitsState::instance.units[unitID].owner; + DAT_CurrentlyRenderedSpriteID::instance + = OpenSHC::IO::Graphics::GID_ANIM_FLAG_SMALL; + uVar32 = DAT_UnitsState::instance.units[unitID].fixedRng + + DAT_GameState::instance.mapAndTime.totalGameTicksUnk + & 0x8000003f; + if ((int)uVar32 < 0) { + uVar32 = (uVar32 - 1 | 0xffffffc0) + 1; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, (int)(uVar32 / 2 + 1), + _yOffset_01, iVar26); + } + } + LAB_004eadfa: + if (*this->viewportState.ptrColor == COL_MAGENTA::instance.shortValue) { + *this->viewportState.ptrColor = uVar9; + } else { + this->viewportState.mouseRayUnitID = unitID; + this->viewportState.mouseRayBuildingID = 0; + } + } + if (DAT_UnitsState::instance.units[unitID].isSelected != 0 + && DAT_UnitsState::instance.units[unitID].usingTeleport == 0 + && DAT_UnitsState::instance.units[unitID].disappearFadeAlphaCountdown + == 0) { + _yOffset_01 = (DAT_UnitsState::instance.units[unitID].drawWidth - 22) / 2; + if (DAT_UnitsState::instance.units[unitID].unitType + == OpenSHC::Map::Units::UT_LORD) { + sVar30 = DAT_UnitsState::instance.units[unitID].maxHealthRatingLord; + if (sVar30 != 0) { + iVar26 = DAT_UnitsState::instance.units[unitID].someDrawYOffset - 8 + + DAT_UnitsState::instance.units[unitID].drawY; + iVar27 = DAT_UnitsState::instance.units[unitID].drawX + _yOffset_01; + iVar18 = DAT_UnitsState::instance.units[unitID].healthbar + 228 + + sVar30 * 11; + } else { + iVar26 = DAT_UnitsState::instance.units[unitID].someDrawYOffset - 6 + + DAT_UnitsState::instance.units[unitID].drawY; + iVar27 = DAT_UnitsState::instance.units[unitID].drawX + _yOffset_01; + iVar18 = DAT_UnitsState::instance.units[unitID].healthbar + 17; + } + } else { + iVar26 + = DAT_GameState::instance + .playerDataArray[DAT_UnitsState::instance.units[unitID].owner] + .fearFactorLevel; + if (iVar26 != 0) { + if (iVar26 < 1) { + iVar18 = iVar26 * -11 + 173; + } else { + iVar18 = iVar26 * 11 + 118; + } + iVar26 = DAT_UnitsState::instance.units[unitID].someDrawYOffset - 8 + + DAT_UnitsState::instance.units[unitID].drawY; + iVar27 = DAT_UnitsState::instance.units[unitID].drawX + _yOffset_01; + iVar18 = DAT_UnitsState::instance.units[unitID].healthbar + iVar18; + } else { + iVar26 = DAT_UnitsState::instance.units[unitID].someDrawYOffset - 6 + + DAT_UnitsState::instance.units[unitID].drawY; + iVar27 = DAT_UnitsState::instance.units[unitID].drawX + _yOffset_01; + iVar18 = DAT_UnitsState::instance.units[unitID].healthbar + 17; + } + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_FLOATS, iVar18, iVar27, iVar26); + if (DAT_UnitsState::instance.units[unitID].unitType + == OpenSHC::Map::Units::UT_A_ASSASSIN + && DAT_GameState::instance.mapAndTime + .playerTeams[DAT_UnitsState::instance.units[unitID].owner] + == DAT_GameState::instance.mapAndTime.playerTeams + [DAT_GameSynchronyState::instance.currentPlayerSlotID] + && (DAT_UnitsState::instance.units[unitID] + .assassinsMicroDistanceToEnemyUnk + < 161 + || ((UVar4 = DAT_UnitsState::instance.units[unitID].state.generic, + UVar4 == OpenSHC::Map::Units::States::US_MELEE_ATTACK + || (UVar4 + == OpenSHC::Map::Units::States:: + US_MELEE_ATTACK_WALL))))) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 447, + DAT_UnitsState::instance.units[unitID].drawX + 2 + _yOffset_01, + DAT_UnitsState::instance.units[unitID].someDrawYOffset - 27 + + DAT_UnitsState::instance.units[unitID].drawY, + 16); + } + } + if ((unitID != 0) + && (sVar30 = DAT_UnitsState::instance.units[unitID].field_0x6e, + sVar30 != 0)) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, + sVar30 + 212, DAT_UnitsState::instance.units[unitID].drawX, + DAT_UnitsState::instance.units[unitID].someDrawYOffset - 54 + + DAT_UnitsState::instance.units[unitID].drawY, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, sVar30 + 220, 0); + DAT_UnitsState::instance.units[unitID].field_0x6e = 0; + } + sVar30 = DAT_UnitsState::instance.units[unitID].field_0x6c; + if (sVar30 == 1) { + iVar26 = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 48; + iVar18 = DAT_UnitsState::instance.units[unitID].someDrawYOffset - 70 + + DAT_UnitsState::instance.units[unitID].drawY; + _yOffset_01 = DAT_UnitsState::instance.units[unitID].field_0x2a - 53 + + DAT_UnitsState::instance.units[unitID].drawX; + iVar27 = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 32; + } else if (sVar30 == 2) { + _yOffset_01 = 0; + iVar18 = 0; + switch (DAT_UnitsState::instance.units[unitID].unitType) { + case OpenSHC::Map::Units::UT_S_CATAPULT: + _yOffset_01 = 41; + iVar18 = 58; + break; + case OpenSHC::Map::Units::UT_S_TREBUCHET: + case OpenSHC::Map::Units::UT_S_TOWER: + _yOffset_01 = 79; + iVar18 = 56; + break; + case OpenSHC::Map::Units::UT_S_BATTERINGRAM: + _yOffset_01 = 36; + iVar18 = 61; + break; + case OpenSHC::Map::Units::UT_S_SHIELD: + _yOffset_01 = -3; + iVar18 = 60; + break; + case OpenSHC::Map::Units::UT_S_MANGONEL: + _yOffset_01 = 43; + iVar18 = 35; + break; + case OpenSHC::Map::Units::UT_S_BALLISTA: + case OpenSHC::Map::Units::UT_S_FBALLISTA: + iVar18 = 36; + _yOffset_01 = 19; + break; + } + iVar26 = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 132; + iVar18 = (DAT_UnitsState::instance.units[unitID].someDrawYOffset - iVar18) + + DAT_UnitsState::instance.units[unitID].drawY; + _yOffset_01 = DAT_UnitsState::instance.units[unitID].drawX + _yOffset_01; + iVar27 = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 116; + } else { + if (sVar30 != 3) + goto LAB_004eb1be; + iVar18 = 0; + _yOffset_01 = 0; + switch (DAT_UnitsState::instance.units[unitID].unitType) { + case OpenSHC::Map::Units::UT_S_CATAPULT: + _yOffset_01 = 41; + iVar18 = 58; + break; + case OpenSHC::Map::Units::UT_S_TREBUCHET: + case OpenSHC::Map::Units::UT_S_TOWER: + _yOffset_01 = 79; + iVar18 = 56; + break; + case OpenSHC::Map::Units::UT_S_BATTERINGRAM: + _yOffset_01 = 36; + iVar18 = 61; + break; + case OpenSHC::Map::Units::UT_S_SHIELD: + _yOffset_01 = -3; + iVar18 = 60; + break; + case OpenSHC::Map::Units::UT_S_MANGONEL: + _yOffset_01 = 43; + iVar18 = 35; + break; + case OpenSHC::Map::Units::UT_S_BALLISTA: + case OpenSHC::Map::Units::UT_S_FBALLISTA: + iVar18 = 36; + _yOffset_01 = 19; + break; + } + iVar26 = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 164; + iVar18 = (DAT_UnitsState::instance.units[unitID].someDrawYOffset - iVar18) + + DAT_UnitsState::instance.units[unitID].drawY; + _yOffset_01 = DAT_UnitsState::instance.units[unitID].drawX + _yOffset_01; + iVar27 = DAT_TileMapState::instance.cursorOverlayAnimationFrame + 148; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, + iVar27, _yOffset_01, iVar18, OpenSHC::IO::Graphics::GID_FLOATS_NEW, iVar26, + 0); + DAT_UnitsState::instance.units[unitID].field_0x6c = 0; + } + } + } + LAB_004eb1be: + unitID = (int)(short)DAT_UnitsState::instance.units[unitID].nextUnitOnTheSameTile; + if ((DAT_GameSynchronyState::instance.syncStatus != 0) || (unitID < 1)) + break; + } + } + /* + ------ END RENDER UNITS ------ + */ + + local_24 = 0; + _yOffset_01 = DAT_RenderMap_YOffset::instance; + if (entityID != 0) { + do { + local_24 = local_24 + 1; + if ((9 < local_24) || (DAT_EntityState::instance.entityArray[entityID].logicalState == 0)) + break; + if (DAT_EntityState::instance.entityArray[entityID].graphicType2 != 0) { + DAT_CurrentlyRenderedSpriteID::instance + = (GmIDInt)DAT_EntityState::instance.entityArray[entityID].gmID; + if ((DAT_CurrentlyRenderedSpriteID::instance == OpenSHC::IO::Graphics::GID_BODY_FIRE) + || (DAT_CurrentlyRenderedSpriteID::instance + == OpenSHC::IO::Graphics::GID_BODY_FIRE_2)) { + local_8 = local_8 + 1; + if ((DAT_EntityState::instance.entityArray[entityID].fireIntensity == 0) + && (79 < local_8)) { + if (local_8 < 200) { + bVar15 = (byte)DAT_EntityState::instance.entityArray[entityID].rng_1 & 1; + } else { + bVar15 = (byte)DAT_EntityState::instance.entityArray[entityID].rng_1 & 3; + } + if (bVar15 != 0) + break; + } + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::notifyAmbientSoundEvent, + DAT_SFXState::ptr)(5); + _yOffset_01 = DAT_RenderMap_YOffset::instance; + } + DAT_RenderedUnitOwner::instance + = DAT_EntityState::instance.entityArray[entityID].colorUnk; + bVar12 = 0; + iVar26 = DAT_EntityState::instance.entityArray[entityID].height; + + int skipEntity = 0; + switch (DAT_CurrentlyRenderedSpriteID::instance) { + case OpenSHC::IO::Graphics::GID_ANIM_FLAGS: + case OpenSHC::IO::Graphics::GID_ANIM_CRUSADER_FLAG: + if (_flatView != 0) { + skipEntity = 1; + break; + } + case OpenSHC::IO::Graphics::GID_BODY_INFO: + bVar12 = 1; + case OpenSHC::IO::Graphics::GID_BODY_FIRE: + case OpenSHC::IO::Graphics::GID_BODY_DISEASE: + case OpenSHC::IO::Graphics::GID_BLAST_3: + case OpenSHC::IO::Graphics::GID_BODY_FIRE_2: + if (DAT_TileMapState::instance.refreshRelatedOne == 0 || _flatView != 0) { + iVar26 = _yOffset_01; + } + if (bVar12 == 0) { + goto scheduleEntityForBatching; + } + break; + case OpenSHC::IO::Graphics::GID_BODY_BRAZIER: + iVar18 = iVar26 + 4 + + (_yOffset_01 - (uint)DAT_TileMapState::instance.HeightLayer[layerTileIndex]); + if (DAT_TileMapState::instance.refreshRelatedOne != 0) { + iVar26 = _yOffset_01; + if ((_flatView == 0) + && (iVar26 = iVar18, + DAT_TileMapState::instance.BuildingLayer[layerTileIndex] != 0)) { + iVar26 = iVar18 - 10; + } + } else { + iVar26 = _yOffset_01; + if (DAT_TileMapState::instance.BuildingLayer[layerTileIndex] != 0) { + iVar26 = _yOffset_01 + 20; + } + } + break; + case OpenSHC::IO::Graphics::GID_ANIM_HEADS: + iVar26 = iVar26 + 7 + + (_yOffset_01 - (uint)DAT_TileMapState::instance.HeightLayer[layerTileIndex]); + uVar32 = DAT_TileMapState::instance.LogicLayer[layerTileIndex] + & Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + if (uVar32 != 0) { + iVar26 = iVar26 + 18; + } + if (DAT_TileMapState::instance.refreshRelatedOne == 0) { + iVar26 = _yOffset_01 + 20; + if (DAT_TileMapState::instance.BuildingLayer[layerTileIndex] == 0) { + iVar26 = _yOffset_01; + } + if (uVar32 != 0) { + iVar26 = iVar26 + 18; + } + } else if (_flatView != 0) { + skipEntity = 1; + } + + break; + case OpenSHC::IO::Graphics::GID_BODY_MISSILE_COW: + if (DAT_EntityState::instance.entityArray[entityID].someCounter_OR_hitGround != 0 + && (DAT_TileMapState::instance.refreshRelatedOne == 0 || (_flatView != 0))) { + iVar26 = _yOffset_01; + } + default: + scheduleEntityForBatching: + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::scheduleUnitForBatchedRendering, + this)(4294967295, + (DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance, + ((DAT_EntityState::instance.entityArray[entityID].y1 + - DAT_EntityState::instance.entityArray[entityID].originY) + - iVar26) + + DAT_RenderMap_DrawSomeY::instance, + (undefined4)(DAT_EntityState::instance.entityArray[entityID].graphicType2), + (undefined4)(DAT_EntityState::instance.entityArray[entityID].blendStrength), + (undefined4)(DAT_EntityState::instance.entityArray[entityID].imageID), 0); + _yOffset_01 = DAT_RenderMap_YOffset::instance; + skipEntity = 1; + } + if (skipEntity == 0) { + if ((DAT_EntityState::instance.entityArray[entityID].overlayGmPictureIndex != 0) + && (DAT_TextureRenderCoreObject::instance.isZoom2 != 0)) { + entityID + = DAT_EntityState::instance.entityArray[entityID].nextEntityOnThisTileByID; + continue; + } + + sVar30 = DAT_EntityState::instance.entityArray[entityID].blendStrength; + if (sVar30 < 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)( + (GmID)DAT_CurrentlyRenderedSpriteID::instance, + DAT_EntityState::instance.entityArray[entityID].graphicType2, + (DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance, + (int)(((DAT_EntityState::instance.entityArray[entityID].y1 + - DAT_EntityState::instance.entityArray[entityID].originY) + - iVar26) + + DAT_RenderMap_DrawSomeY::instance), + (GmID)(DAT_CurrentlyRenderedSpriteID::instance), + DAT_EntityState::instance.entityArray[entityID].imageID, -1 - sVar30); + _yOffset_01 = DAT_RenderMap_YOffset::instance; + } else { + _yOffset_01 = DAT_EntityState::instance.entityArray[entityID].originY; + if (sVar30 != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + (GmID)DAT_CurrentlyRenderedSpriteID::instance, + DAT_EntityState::instance.entityArray[entityID].graphicType2, + (DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance, + (int)((int)(((DAT_EntityState::instance.entityArray[entityID].y1 + - _yOffset_01) + - iVar26) + + DAT_RenderMap_DrawSomeY::instance)), + sVar30); + _yOffset_01 = DAT_RenderMap_YOffset::instance; + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + (eGM)DAT_CurrentlyRenderedSpriteID::instance, + DAT_EntityState::instance.entityArray[entityID].graphicType2, + (DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance, + (int)((int)(((DAT_EntityState::instance.entityArray[entityID].y1 + - _yOffset_01) + - iVar26) + + DAT_RenderMap_DrawSomeY::instance))); + _yOffset_01 = DAT_RenderMap_YOffset::instance; + } + } + } + } + + iVar26 = DAT_EntityState::instance.entityArray[entityID].nextEntityOnThisTileByID; + if ((entityID == iVar26) + || (entityID = iVar26, DAT_GameSynchronyState::instance.syncStatus != 0)) + break; + + } while (entityID != 0); + } + entityID = (uint)(byte)DAT_TileMapState::instance.EntityLayerLT25[layerTileIndex]; + _yOffset_01 = 0; + if (entityID != 0) { + while (_yOffset_01 = _yOffset_01 + 1, _yOffset_01 < 10) { + if (DAT_EntityState::instance.entityArray[entityID].tile != layerTileIndex) { + DAT_TileMapState::instance.EntityLayerLT25[layerTileIndex] = '\0'; + break; + } + if (DAT_EntityState::instance.entityArray[entityID].logicalState == 0) + break; + iVar26 = DAT_EntityState::instance.entityArray[entityID].graphicType2; + if (iVar26 != 0) { + DAT_CurrentlyRenderedSpriteID::instance + = (GmIDInt)DAT_EntityState::instance.entityArray[entityID].gmID; + DAT_RenderedUnitOwner::instance + = DAT_EntityState::instance.entityArray[entityID].colorUnk; + iVar18 = DAT_EntityState::instance.entityArray[entityID].height; + if ((DAT_EntityState::instance.entityArray[entityID].overlayGmPictureIndex == 0) + || (DAT_TextureRenderCoreObject::instance.isZoom2 == 0)) { + sVar30 = DAT_EntityState::instance.entityArray[entityID].blendStrength; + if (sVar30 < 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)( + (GmID)DAT_CurrentlyRenderedSpriteID::instance, iVar26, + (DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance, + (int)(((DAT_EntityState::instance.entityArray[entityID].y1 + - DAT_EntityState::instance.entityArray[entityID].originY) + - iVar18) + + DAT_RenderMap_DrawSomeY::instance), + (GmID)(DAT_CurrentlyRenderedSpriteID::instance), + DAT_EntityState::instance.entityArray[entityID].imageID, -1 - sVar30); + } else { + iVar27 = DAT_EntityState::instance.entityArray[entityID].originY; + if (sVar30 != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + (GmID)DAT_CurrentlyRenderedSpriteID::instance, iVar26, + (int)(( + int)((DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance)), + (int)(( + int)(((DAT_EntityState::instance.entityArray[entityID].y1 - iVar27) + - iVar18) + + DAT_RenderMap_DrawSomeY::instance)), + sVar30); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + (eGM)DAT_CurrentlyRenderedSpriteID::instance, iVar26, + (int)(( + int)((DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance)), + (int)(( + int)(((DAT_EntityState::instance.entityArray[entityID].y1 - iVar27) + - iVar18) + + DAT_RenderMap_DrawSomeY::instance))); + } + } + sVar30 = DAT_EntityState::instance.entityArray[entityID].overlayGmPictureIndex; + if (sVar30 != 0) { + sVar20 = DAT_EntityState::instance.entityArray[entityID].blendStrength; + EVar3 = DAT_EntityState::instance.entityArray[entityID].entityType; + iVar27 = (DAT_EntityState::instance.entityArray[entityID].x1 + - DAT_EntityState::instance.entityArray[entityID].originX) + + DAT_RenderMap_DrawSomeX::instance; + iVar18 = ((DAT_EntityState::instance.entityArray[entityID].y1 + - DAT_EntityState::instance.entityArray[entityID].originY) + - iVar18) + + DAT_RenderMap_DrawSomeY::instance; + DAT_TextManagerObject::instance.textSurfaceTarget + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + iVar26 = sVar20; + local_c = 0; + if ((EVar3 == (OpenSHC::Map::Entities::EntityType)42) + || (EVar3 == (OpenSHC::Map::Entities::EntityType)43)) { + DAT_EntityState::instance.entityArray[entityID].blendStrength = sVar20 - 2; + DAT_TextManagerObject::instance.renderPlusSignForNumbers = 1; + if (EVar3 == (OpenSHC::Map::Entities::EntityType)43) { + local_c = 255; + } + } + if (iVar26 < 0) { + iVar26 = 0; + } + DAT_CurrentlyRenderedSpriteID::instance + = (GmIDInt)DAT_EntityState::instance.entityArray[entityID].overlayGmID; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + (GmID)DAT_CurrentlyRenderedSpriteID::instance, sVar30, + DAT_EntityState::instance.entityArray[entityID].overlayOffsetX + iVar27, + DAT_EntityState::instance.entityArray[entityID].overlayOffsetY + iVar18, + iVar26); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, + DAT_TextManagerObject::ptr)( + DAT_EntityState::instance.entityArray[entityID].displayValue, + DAT_EntityState::instance.entityArray[entityID].displayValueOffsetX + + iVar27, + DAT_EntityState::instance.entityArray[entityID].displayValueOffsetY + + iVar18, + OpenSHC::Text::TTA_LEFT, local_c, 18, FALSE, iVar26); + DAT_TextManagerObject::instance.textSurfaceTarget + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + DAT_TextManagerObject::instance.renderPlusSignForNumbers = 0; + } + goto LAB_004eb7db; + } + uVar32 = (uint)DAT_EntityState::instance.entityArray[entityID].nextEntityOnThisTileByID; + } else { + LAB_004eb7db: + uVar32 = (uint)DAT_EntityState::instance.entityArray[entityID].nextEntityOnThisTileByID; + if ((entityID == uVar32) || (DAT_GameSynchronyState::instance.syncStatus != 0)) + break; + } + entityID = uVar32; + if (uVar32 == 0) + break; + } + } + if ((iVar23 != 0) && (iVar23 < 2000)) { + DAT_CurrentlyRenderedSpriteID::instance + = (GmIDInt)DAT_LandscapeState::instance.trees[iVar23].treeTypeBasedValue1; + iVar26 = DAT_LandscapeState::instance.trees[iVar23].animationFrameUnk; + iVar18 = GMFirstPictureIndex::instance[DAT_CurrentlyRenderedSpriteID::instance]; + _yOffset_01 = iVar18 - 1 + iVar26; + if (0 < DAT_CurrentlyRenderedSpriteID::instance && _yOffset_01 != 0 && iVar26 != 0) { + DAT_RenderedUnitOwner::instance + = DAT_LandscapeState::instance.trees[iVar23].appleTreeColorVariation; + DAT_TextureRenderCoreObject::instance.mbr_0x10 = 1; + /* + renders trees + */ + + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)( + (DAT_RenderMap_DrawSomeX::instance + - DAT_LandscapeState::instance.trees[iVar23].gmOriginX) + + 14, + ((DAT_RenderMap_DrawSomeY::instance + - DAT_LandscapeState::instance.trees[iVar23].gmOriginY) + - DAT_RenderMap_YOffset::instance) + + 6, + DAT_GMImageHeaders::instance.imh[iVar26 + iVar18 - 1].width, + DAT_GMImageHeaders::instance.imh[iVar26 + iVar18 - 1].height, + (byte*)((int)((DAT_GMImageOffsets::instance[_yOffset_01] + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData)))); + DAT_TextureRenderCoreObject::instance.mbr_0x10 = 0; + if ((DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_EDITOR) + && (DAT_LandscapeState::instance.trees[iVar23].hasCrow != 0)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_BODY_CROW, + this->animationFrame36 % 12 + 73, DAT_RenderMap_DrawSomeX::instance - 30, + (DAT_RenderMap_DrawSomeY::instance - DAT_RenderMap_YOffset::instance) - 220); + } + } + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::notifyAmbientSoundEvent, DAT_SFXState::ptr)(4); + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::notifyAmbientSoundEvent, DAT_SFXState::ptr)(8); + } + if (DAT_RenderMap_RowsLeft::instance != 0 && DAT_RenderMap_RowsLeft::instance < 255 + && bVar13 != 0) { + uVar32 = (uint)(short)DAT_TileMapState::instance.MiscDisplayLayer[layerTileIndex]; + DAT_RenderMap_WhatToDraw::instance = uVar32 & 3; + if ((DAT_00ed3148::instance & 0x100) != 0) { + DAT_GmImageAddressToBeRendered::instance + = (uint)DAT_TileMapState::instance.WallGFXLayer[layerTileIndex]; + DAT_RenderMap_SecondBlitImageIndex::instance = DAT_GmImageAddressToBeRendered::instance; + if (local_54 != 0) { + DAT_RenderMap_SecondBlitImageIndex::instance + = (uint)DAT_TileMapState::instance.PillarGFXLayer[layerTileIndex]; + } + LAB_004eb9a4: + MACRO_CALL(OpenSHC::Rendering_Func::BlitMapImageWithVerticalClip)(); + } else { + DAT_GmImageAddressToBeRendered::instance + = (uint)DAT_TileMapState::instance.PillarGFXLayer[layerTileIndex]; + if ((DAT_00ed3148::instance & 0x100000) != 0) { + if (DAT_GmImageAddressToBeRendered::instance == 32) { + DAT_GmImageAddressToBeRendered::instance = GMFirstPictureIndex::instance[9] + 31; + } else { + layerTileIndex = DAT_GmImageAddressToBeRendered::instance + this->animationFrame16; + if (50 < layerTileIndex) { + layerTileIndex = layerTileIndex - 16; + } + DAT_GmImageAddressToBeRendered::instance + = layerTileIndex - 1 + GMFirstPictureIndex::instance[9]; + if (32 < DAT_RenderMap_RowsLeft::instance + && (DAT_RenderMap_DrawSomeY::instance - DAT_RenderMap_RowsLeft::instance) + < local_5c - 160) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::notifyAmbientSoundEvent, + DAT_SFXState::ptr)(6); + } + } + DAT_RenderMap_SecondBlitImageIndex::instance = DAT_GmImageAddressToBeRendered::instance; + if ((uVar32 & 0x800) == 0) + goto LAB_004eb9a4; + MACRO_CALL(OpenSHC::Rendering_Func::BlitMapImageWithVerticalClipAndYOffset)(); + } else { + DAT_RenderMap_SecondBlitImageIndex::instance = DAT_GmImageAddressToBeRendered::instance; + if ((uVar32 & 0x800) != 0) { + MACRO_CALL(OpenSHC::Rendering_Func::BlitMapImageWithVerticalClipAndYOffset)(); + } else { + MACRO_CALL(OpenSHC::Rendering_Func::BlitMapImageWithVerticalClip)(); + } + if (bVar14 != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS, + DAT_RenderMap_ImageID::instance + 8, DAT_RenderMap_DrawSomeX::instance, + (INT_00ed3154::instance - DAT_RenderMap_YOffset::instance) + 9 + + DAT_RenderMap_DrawSomeY::instance, + 24); + } + } + } + } + } + DAT_RenderMap_DrawSomeX::instance = DAT_RenderMap_DrawSomeX::instance + 32; + } + iVar31 = _zoomOffset; + if (_vpWidthPlus1 == _viewportHeight) { + DAT_RenderMap_DrawSomeX::instance = this->viewportState.unknownScreenXRelated + 16; + layerTileIndex = _viewportHeight; + } else { + layerTileIndex = _viewportHeight + 1; + DAT_RenderMap_DrawSomeX::instance = this->viewportState.unknownScreenXRelated; + } + for (; iVar31 < layerTileIndex; iVar31 = iVar31 + 1) { + _yOffset_01 = this->screenPointToTileNumber[iVar31 + iVar2]; + DAT_00ed3148::instance = DAT_TileMapState::instance.LogicLayer[_yOffset_01]; + if ((DAT_00ed3148::instance & 0x30) == 0) { + if ((iVar31 < 2) || (bVar13 = 1, !(iVar31 < layerTileIndex - 2))) { + bVar13 = 0; + } + uVar32 = (uint)DAT_TileMapState::instance.FloatingLayer[_yOffset_01]; + DAT_RenderMap_ImageID::instance + = (uint)DAT_TileMapState::instance.ConstructionGFXLayer[_yOffset_01]; + DAT_GmImageAddressToBeRendered::instance = (uint)DAT_TileMapState::instance.GfxLayer[_yOffset_01]; + if (DAT_RenderMap_ImageID::instance != 0) { + DAT_GmImageAddressToBeRendered::instance = DAT_RenderMap_ImageID::instance; + } + DAT_RenderMap_YOffset::instance + = DAT_TileMapState::instance + .heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[_yOffset_01]]; + puVar1 = DAT_TileMapState::instance.MiscDisplayLayer + _yOffset_01; + uVar29 = (uint)DAT_TileMapState::instance.BuildingLayer[_yOffset_01]; + INT_00ed3154::instance = -(uint)((*puVar1 & 0x20) != 0) & 0x5a; + if (_flatView != 0) { + if (uVar29 != 0) { + BVar8 = DAT_BuildingsState::instance.buildings[uVar29].buildingType; + iVar23 = DAT_MapRenderDefinedData::instance.BuildingRenderSomeTypeArray[(short)BVar8]; + if (iVar23 == 3) { + uVar22 = (uint)((*puVar1 & 4) != 0); + if (BVar8 == OpenSHC::Map::Buildings::BT_WOODCUTTERSHUT) { + DAT_GmImageAddressToBeRendered::instance + = uVar22 + 24 + GMFirstPictureIndex::instance[157]; + } else if (BVar8 == OpenSHC::Map::Buildings::BT_HUNTERSHUT) { + DAT_GmImageAddressToBeRendered::instance + = uVar22 + 26 + GMFirstPictureIndex::instance[157]; + } else if (BVar8 == OpenSHC::Map::Buildings::BT_DAIRYFARM) { + DAT_GmImageAddressToBeRendered::instance + = uVar22 + 28 + GMFirstPictureIndex::instance[157]; + } else { + DAT_GmImageAddressToBeRendered::instance + = uVar22 + 30 + GMFirstPictureIndex::instance[157]; + } + } else if (-1 < iVar23) { + DAT_GmImageAddressToBeRendered::instance = (INT_00ed314c::instance & 3) + + GMFirstPictureIndex::instance[157] + ((uVar29 & 1) + iVar23 * 2) * 4; + } + } else { + if ((DAT_00ed3148::instance & 0x100) != 0) { + if ((DAT_00ed3148::instance & 0x800) != 0) { + DAT_00ed3148::instance = DAT_00ed3148::instance & 1; + if ((DAT_GmImageAddressToBeRendered::instance + == GMFirstPictureIndex::instance[12] + 134U) + || (DAT_GmImageAddressToBeRendered::instance + == GMFirstPictureIndex::instance[12] + 136U)) { + DAT_GmImageAddressToBeRendered::instance + = GMFirstPictureIndex::instance[157] + 42; + } else { + DAT_GmImageAddressToBeRendered::instance + = GMFirstPictureIndex::instance[157] + 40; + } + } else { + if ((DAT_00ed3148::instance & 0x200) != 0) { + DAT_00ed3148::instance = DAT_00ed3148::instance & 1; + DAT_GmImageAddressToBeRendered::instance + = (INT_00ed314c::instance & 3) + 36 + GMFirstPictureIndex::instance[157]; + } + } + } else { + if ((char)DAT_00ed3148::instance < '\0' + && 1999 < DAT_TileMapState::instance.OrganismLayer[_yOffset_01] + && (iVar23 = DAT_TileMapState::instance.OrganismLayer[_yOffset_01] * 32, + 1 < *(short*)((int)&DAT_LandscapeState::instance.trees[1590] + .appleTreeColorVariation + + iVar23 + 2))) { + iVar26 + = MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::getRandomRockImageOffset, + DAT_LandscapeState::ptr)( + ((byte)DAT_TileMapState::instance.RandomLayer[_yOffset_01] & 3) + 1); + DAT_GmImageAddressToBeRendered::instance = iVar26 - 1 + + GMFirstPictureIndex::instance[*( + short*)((int)&DAT_LandscapeState::instance.trees[1590].animationFrameUnk + + iVar23 + 2)]; + } + } + } + DAT_RenderMap_YOffset::instance = 8; + } + if (uVar29 != 0) { + if (local_1c < viewportWidth && bVar13 != 0 && 4 < iVar31) { + DAT_BuildingsState::instance.buildings[uVar29].surfaceAreaUnk + = DAT_BuildingsState::instance.buildings[uVar29].surfaceAreaUnk + 1; + } + uVar9 = *this->viewportState.ptrColor; + *this->viewportState.ptrColor = COL_MAGENTA::instance.shortValue; + if ((DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance].direction != 0) + && (bVar13 != 0)) { + iVar23 = (int)DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance] + .tileOffset; + /* + renders building sprite ontop of tilemap + */ + + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderFunctionResponsibleForManyGameObjects, + DAT_TextureRenderCoreObject::ptr)( + (char)DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance] + .horizontalOffsetImage + + DAT_RenderMap_DrawSomeX::instance, + ((INT_00ed3154::instance - DAT_RenderMap_YOffset::instance) - iVar23) + + DAT_RenderMap_DrawSomeY::instance, + (int)((char)DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance] + .buildingWidth), + iVar23 + 7, + (ushort*)((int)( + + (DAT_GMImageOffsets::instance[DAT_GmImageAddressToBeRendered::instance] + 512 + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData)))); + } + if ((_flatView == 0) + || (DAT_MapRenderDefinedData::instance.BuildingRenderSomeTypeArray + [(short)DAT_BuildingsState::instance.buildings[uVar29].buildingType] + < 0)) { + if (DAT_BuildingsState::instance.buildings[uVar29].buildingType + == OpenSHC::Map::Buildings::BT_DRAWBRIDGE + && DAT_TileMapState::instance.refreshRelatedOne != 0 + && _yOffset_01 + == this->translationMatrix[(short)DAT_BuildingsState::instance.buildings[uVar29].y + + 2] + .addXgetTile + + 2 + (int)(short)DAT_BuildingsState::instance.buildings[uVar29].x) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::renderBuildingAnimation, + this)(uVar29, DAT_RenderMap_DrawSomeX::instance + 16, + INT_00ed3154::instance + 24 + DAT_RenderMap_DrawSomeY::instance, + (undefined4)((int)(_yOffset_01)), 1); + } + uVar10 = *puVar1; + if ((uVar10 & 0xc) != 0) { + if (DAT_BuildingsState::instance.buildings[uVar29].buildingType + == OpenSHC::Map::Buildings::BT_DRAWBRIDGE) { + if (DAT_TileMapState::instance.refreshRelatedOne != 0) { + if ((uVar10 & 0xc) == 12) { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::renderBuildingAnimation, + this)(uVar29, DAT_RenderMap_DrawSomeX::instance + 16, + INT_00ed3154::instance + 40 + DAT_RenderMap_DrawSomeY::instance, + (undefined4)((int)(_yOffset_01)), 0); + } else if ((uVar10 & 8) != 0) { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::renderGmOverlayBuilding, + this)(uVar29, DAT_RenderMap_DrawSomeX::instance, + (INT_00ed3154::instance - DAT_RenderMap_YOffset::instance) + + DAT_RenderMap_DrawSomeY::instance, + _yOffset_01); + } + } + } else { + iVar23 = (INT_00ed3154::instance - DAT_RenderMap_YOffset::instance) + + DAT_RenderMap_DrawSomeY::instance; + if ((uVar10 & 8) != 0) { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::renderGmOverlayBuilding, + this)(uVar29, DAT_RenderMap_DrawSomeX::instance, iVar23, _yOffset_01); + } else { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::renderGmOverlayBuilding2, + this)(uVar29, DAT_RenderMap_DrawSomeX::instance, iVar23, _yOffset_01); + } + } + } + } + if (*this->viewportState.ptrColor == COL_MAGENTA::instance.shortValue) { + *this->viewportState.ptrColor = uVar9; + } else { + this->viewportState.mouseRayUnitID = 0; + this->viewportState.mouseRayBuildingID = uVar29; + } + } + if ((DAT_00ed3148::instance & 8) != 0 && (*puVar1 & 0x4000) != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame, + DAT_RenderMap_DrawSomeX::instance - 35, + (INT_00ed3154::instance - DAT_RenderMap_YOffset::instance) - 74 + + DAT_RenderMap_DrawSomeY::instance, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame + 16, 0); + *puVar1 = *puVar1 & 0xbfff; + } + iVar23 = DAT_RenderMap_YOffset::instance; + if (uVar32 != 0) { + if ((DAT_TileMapState::instance.refreshRelatedOne != 0) && (_flatView == 0)) { + if ((DAT_TileMapState::instance.LogicLayer[_yOffset_01] + & Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE) + != 0) { + iVar26 = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(DAT_TileMapState::instance.BuildingLayer[_yOffset_01]); + iVar23 = iVar23 + iVar26; + } else { + if ((DAT_TileMapState::instance.LogicLayer[_yOffset_01] + & Map::LogicHelpers::L_WALL_OR_GATEHOUSE) + != 0) { + if (DAT_TileMapState::instance.BuildingLayer[_yOffset_01] == 0) { + iVar23 = DAT_RenderMap_YOffset::instance + 4; + } else if (DAT_BuildingsState::instance + .buildings[DAT_TileMapState::instance.BuildingLayer[_yOffset_01]] + .buildingType + == OpenSHC::Map::Buildings::BT_WOODGATE1) { + iVar23 = DAT_RenderMap_YOffset::instance + 6; + } else { + iVar23 = DAT_RenderMap_YOffset::instance + 20; + } + } + } + } + do { + uVar29 = this->floatersArray[uVar32].variation; + if ((uVar29 & 1) != 0) { + iVar26 = iVar23; + if ((uVar29 & 8) != 0 && DAT_TileMapState::instance.refreshRelatedOne != 0 + && _flatView == 0 + && (iVar26 = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTotalHeightAt, + DAT_TileMapState::ptr)(_yOffset_01, 0), + iVar26 < 0)) { + iVar26 = -1 - iVar26; + } + if ((*puVar1 & 0x10) != 0) { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::scheduleUnitForBatchedRendering, + this)(0, + this->floatersArray[uVar32].originX + DAT_RenderMap_DrawSomeX::instance, + (this->floatersArray[uVar32].originY - iVar26) + + DAT_RenderMap_DrawSomeY::instance, + (undefined4)(this->floatersArray[uVar32].imageID), + (undefined4)(this->floatersArray[uVar32].variation), + (undefined4)((int)(this->floatersArray[uVar32].gmID)), 0); + } else { + uVar29 = this->floatersArray[uVar32].variation; + if ((uVar29 & 4) != 0) { + DAT_RenderedUnitOwner::instance = ~-(uint)((uVar29 & 0x10) != 0) + & DAT_GameSynchronyState::instance.currentPlayerSlotID; + DAT_CurrentlyRenderedSpriteID::instance = this->floatersArray[uVar32].gmID; + uVar29 = this->floatersArray[uVar32].variation; + } + if ((uVar29 & 0x20) != 0) { + iVar18 = this->floatersArray[uVar32].imageID; + GVar11 = (GmID)this->floatersArray[uVar32].gmID; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)((GmID)GVar11, iVar18, + this->floatersArray[uVar32].originX + DAT_RenderMap_DrawSomeX::instance, + (int)((this->floatersArray[uVar32].originY - iVar26) + + DAT_RenderMap_DrawSomeY::instance), + GVar11, ((int)uVar29 >> 0x10) + iVar18, 0); + } else { + if ((uVar29 & 0xffff0000) != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + (GmID)this->floatersArray[uVar32].gmID, + this->floatersArray[uVar32].imageID, + this->floatersArray[uVar32].originX + DAT_RenderMap_DrawSomeX::instance, + (int)((this->floatersArray[uVar32].originY - iVar26) + + DAT_RenderMap_DrawSomeY::instance), + (int)(uVar29 >> 0x10)); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((eGM)this->floatersArray[uVar32].gmID, + this->floatersArray[uVar32].imageID, + this->floatersArray[uVar32].originX + DAT_RenderMap_DrawSomeX::instance, + (int)((this->floatersArray[uVar32].originY - iVar26) + + DAT_RenderMap_DrawSomeY::instance)); + } + } + } + } + uVar32 = this->floatersArray[uVar32].nextFloaterID; + } while (uVar32 != 0); + } + DAT_TileMapState::instance.ConstructionGFXLayer[_yOffset_01] = 0; + *puVar1 = *puVar1 & 0x7fff; + } + DAT_RenderMap_DrawSomeX::instance = DAT_RenderMap_DrawSomeX::instance + 32; + } + if (layerTileIndex == _viewportHeight) { + _vpWidthPlus1_1 = _viewportHeight; + local_c = 200; + DAT_RenderMap_DrawSomeX::instance = this->viewportState.unknownScreenXRelated + 16; + } else { + _vpWidthPlus1_1 = _viewportHeight + 1; + local_c = 201; + DAT_RenderMap_DrawSomeX::instance = this->viewportState.unknownScreenXRelated; + } + if ((_flatView == 0) && (local_48 = _zoomOffset, _zoomOffset < _vpWidthPlus1_1)) { + local_20 = this->screenPointToTileNumber + _zoomOffset + iVar2; + do { + iVar31 = *local_20; + DAT_GmImageAddressToBeRendered::instance = (uint)DAT_TileMapState::instance.AlphaGFXLayer[iVar31]; + if (DAT_GmImageAddressToBeRendered::instance != 0 + && (DAT_TileMapState::instance.MiscDisplayLayer[iVar31] & 0x3c0) == 0) { + if ((local_48 < 2) || (_vpWidthPlus1_1 - 2 <= local_48)) { + bVar13 = 0; + } else { + bVar13 = 1; + } + DAT_00ed3148::instance = DAT_TileMapState::instance.LogicLayer[iVar31]; + if ((DAT_00ed3148::instance & 0x400) != 0) { + psVar17 = &DAT_BuildingsState::instance + .buildings[DAT_TileMapState::instance.BuildingLayer[iVar31]] + .tickRelatedVisuallyActiveIndicator; + sVar30 = *psVar17; + if (0 < sVar30 && sVar30 < 5 && bVar13 != 0) { + DAT_RenderMap_RowsLeft::instance = (uint)DAT_TileMapState::instance.ShowHiLayer[iVar31]; + DAT_RenderMap_YOffset::instance + = DAT_TileMapState::instance + .heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[iVar31]]; + MACRO_CALL(OpenSHC::Rendering_Func::ApplyBlending)((sVar30 << 5) / 5); + if (DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance].direction + != 0) { + iVar31 = (int)DAT_GMImageHeaders::instance + .imh[DAT_GmImageAddressToBeRendered::instance] + .tileOffset; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func:: + renderInterfaceOrBuildingOccupationArea, + DAT_TextureRenderCoreObject::ptr)( + (char)DAT_GMImageHeaders::instance.imh[DAT_GmImageAddressToBeRendered::instance] + .horizontalOffsetImage + + DAT_RenderMap_DrawSomeX::instance, + (DAT_RenderMap_DrawSomeY::instance - DAT_RenderMap_YOffset::instance) - iVar31, + (int)((char)DAT_GMImageHeaders::instance + .imh[DAT_GmImageAddressToBeRendered::instance] + .buildingWidth), + iVar31 + 7, + (ushort*)((int)( + + (DAT_GMImageOffsets::instance[DAT_GmImageAddressToBeRendered::instance] + + 512 + + (int)DAT_TextureRenderCoreObject::instance.gmProcessedImageData))), + (int)((*psVar17 << 5) / 5)); + } + } + } + } + local_20 = local_20 + 1; + DAT_RenderMap_DrawSomeX::instance = DAT_RenderMap_DrawSomeX::instance + 32; + local_48 = local_48 + 1; + } while (local_48 < _vpWidthPlus1_1); + } + iVar2 = iVar2 + local_c; + DAT_RenderMap_DrawSomeY::instance = DAT_RenderMap_DrawSomeY::instance + 8; + local_1c = local_1c + 1; + } + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::renderUnits, this)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::renderUnits, this)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::renderUnits, this)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::renderUnits, this)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::renderUnits, this)(); + if ((DAT_TileMapState::instance.mapSize == 160) + && (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x768)) { + if (this->viewportState.isZoomedOutUnk != 0) { + if ((DAT_GameCore::instance.activeMenuTab.tabType == OpenSHC::UI::Enums::BASMTT_SIEGETENT_SIEGETOWER) + || (DAT_GameCore::instance.activeMenuTab.tabType == OpenSHC::UI::Enums::BASMTT_SIEGETENT_SHIELD)) { + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, + DAT_PencilRenderCore::ptr)(0, 716, 4056, 716, 26); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, + DAT_PencilRenderCore::ptr)(0, 717, 4056, 717, 20); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, + DAT_PencilRenderCore::ptr)(0, 718, 4056, 718, 14); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, + DAT_PencilRenderCore::ptr)(0, 719, 4056, 719, 8); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(0, 720, 4056, 2033, (ushort)(COL_BLACK::instance.shortValue)); + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + } + goto LAB_004ec57a; + } + LAB_004ec582: + iVar31 = this->viewportState.currentCameraOffsetX + DAT_MouseState::instance.screenSpaceX; + iVar28 = this->viewportState.currentCameraOffsetY + DAT_MouseState::instance.screenSpaceY; + _viewportHeight = iVar28; + viewportWidth = iVar31; + } else { + LAB_004ec57a: + if (this->viewportState.isZoomedOutUnk == 0) + goto LAB_004ec582; + iVar28 = this->viewportState.currentCameraOffsetY + DAT_MouseState::instance.screenSpaceY; + iVar31 = this->viewportState.currentCameraOffsetX + DAT_MouseState::instance.screenSpaceX; + _viewportHeight = this->viewportState.currentCameraOffsetY + DAT_MouseState::instance.screenSpaceY * 2; + viewportWidth = this->viewportState.currentCameraOffsetX + 160 + DAT_MouseState::instance.screenSpaceX * 2; + } + if (this->viewportState.field_0x0 != 0) { + if (DAT_MouseState::instance.field_0x1dc < 1001) { + if (DAT_MouseState::instance.field_0x1dc != 1000) { + switch (DAT_MouseState::instance.field_0x1dc) { + case 1: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_CURSORS, 81, + viewportWidth + - DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[107].originX, + (_viewportHeight + - DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[107].originY) + + 45); + break; + case 3: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)((GmID)DAT_TileMapState::instance.cursorOverlayGmID, + (int)(DAT_TileMapState::instance.cursorOverlayImageBase + 16 + + DAT_TileMapState::instance.cursorOverlayAnimationFrame), + viewportWidth + - DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[DAT_TileMapState::instance.cursorOverlayGmID] + .originX, + _viewportHeight + - DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[DAT_TileMapState::instance.cursorOverlayGmID] + .originY, + 21); + case 2: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((eGM)DAT_TileMapState::instance.cursorOverlayGmID, + (int)(DAT_TileMapState::instance.cursorOverlayImageBase + + DAT_TileMapState::instance.cursorOverlayAnimationFrame), + viewportWidth + - DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[DAT_TileMapState::instance.cursorOverlayGmID] + .originX, + _viewportHeight + - DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[DAT_TileMapState::instance.cursorOverlayGmID] + .originY); + break; + case 4: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((eGM)DAT_TileMapState::instance.cursorOverlayGmID, + (int)(DAT_TileMapState::instance.cursorOverlayImageBase), viewportWidth - 8, + _viewportHeight - 8); + break; + case 5: + iVar28 = DAT_TileMapState::instance.flagAnimationFrame + % DAT_TileMapState::instance.flagAnimationDivisor + + DAT_TileMapState::instance.cursorOverlayImageBase; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)((GmID)DAT_TileMapState::instance.cursorOverlayGmID, + iVar28, + viewportWidth + - DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[DAT_TileMapState::instance.cursorOverlayGmID] + .originX, + _viewportHeight + - DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[DAT_TileMapState::instance.cursorOverlayGmID] + .originY, + (GmID)((int)(DAT_TileMapState::instance.cursorOverlayGmID)), + DAT_TileMapState::instance.flagAnimationDivisor + iVar28, 0); + } + goto switchD_004ec5fa_default; + } + DAT_TextureRenderCoreObject::instance.isZoom2 = 0; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 123, iVar31 + 28, iVar28 + 4); + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + "(", iVar31 + 60, iVar28 + 7, OpenSHC::Text::TTA_LEFT, 0xb8eefb, 0, 18, FALSE, 0); + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT) { + _numberToDisplay + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .startResources[4] + - DAT_TileMapState::instance.wallPlacementCost; + } else { + _numberToDisplay + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[4] + - DAT_TileMapState::instance.wallPlacementCost; + } + } else { + if (DAT_MouseState::instance.field_0x1dc != 1001) + goto switchD_004ec5fa_default; + DAT_TextureRenderCoreObject::instance.isZoom2 = 0; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 126, iVar31 + 28, iVar28 + 4); + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + "(", iVar31 + 60, iVar28 + 7, OpenSHC::Text::TTA_LEFT, 0xb8eefb, 0, 18, FALSE, 0); + _numberToDisplay + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[2] + - DAT_TileMapState::instance.wallPlacementCost; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumber2, DAT_TextManagerObject::ptr)( + _numberToDisplay, iVar31 + 60, iVar28 + 7, OpenSHC::Text::TTA_LEFT, 0xb8eefb, 0, 18, TRUE, 0); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + ")", iVar31 + 60, iVar28 + 7, OpenSHC::Text::TTA_LEFT, 0xb8eefb, 0, 18, TRUE, 0); + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + } + switchD_004ec5fa_default: + DAT_MouseState::instance.field_0x1dc = -1; + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::clearAllFloatingLayerElements, this)(); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::setMapSurfaceHeightRangeUnk, + DAT_TextureRenderCoreObject::ptr)(); + DAT_TextureRenderCoreObject::instance.isZoom2 = 0; + DAT_TileMapState::instance.field_0x5549b8 = 0; + return; + } + +} +} diff --git a/src/OpenSHC/Rendering/ViewportRenderState/renderUnits.cpp b/src/OpenSHC/Rendering/ViewportRenderState/renderUnits.cpp new file mode 100644 index 0000000000..5dc677b1dd --- /dev/null +++ b/src/OpenSHC/Rendering/ViewportRenderState/renderUnits.cpp @@ -0,0 +1,504 @@ +#include "../ViewportRenderState.func.hpp" + +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/States/UnitStateShort.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" + +#include "OpenSHC/Globals/COL_MAGENTA.hpp" +#include "OpenSHC/Globals/DAT_CurrentlyRenderedSpriteID.hpp" +#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_RenderedUnitOwner.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace Rendering { + + using OpenSHC::DE::SHCDE::eGM; + using OpenSHC::Game::GameMode; + using OpenSHC::IO::Graphics::GmID; + using OpenSHC::Map::Units::UnitType; + using OpenSHC::Map::Units::UnitTypeShort; + using OpenSHC::Map::Units::States::UnitState; + using OpenSHC::Map::Units::States::UnitStateShort; + + // FUNCTION: STRONGHOLDCRUSADER 0x004E7810 + void ViewportRenderState::renderUnits() + { + short graphicSize; + UnitTypeShort unitType; + int overlayX; + int overlayY; + + this->unitBatchedRenderCounterUntil6 = this->unitBatchedRenderCounterUntil6 + 1; + int _drawX = 0; + int _drawY = 0; + int _renderBatchSize = 0; + int _unitID = 0; + int _imageID = 0; + int _blendStrength = 0; + int _gmID = 0; + if (5 < this->unitBatchedRenderCounterUntil6) { + this->unitBatchedRenderCounterUntil6 = 1; + } + if (this->unitBatchedRenderCounterUntil6 == 1) { + _renderBatchSize = this->unitRender1; + this->unitRender1 = 0; + } else if (this->unitBatchedRenderCounterUntil6 == 2) { + _renderBatchSize = this->unitRender2; + this->unitRender2 = 0; + } else if (this->unitBatchedRenderCounterUntil6 == 3) { + _renderBatchSize = this->unitRender3; + this->unitRender3 = 0; + } else if (this->unitBatchedRenderCounterUntil6 == 4) { + _renderBatchSize = this->unitRender4; + this->unitRender4 = 0; + } else if (this->unitBatchedRenderCounterUntil6 == 5) { + _renderBatchSize = this->unitRender5; + this->unitRender5 = 0; + } + for (int _batchedUnitID = 0; _batchedUnitID < _renderBatchSize; _batchedUnitID++) { + switch (this->unitBatchedRenderCounterUntil6) { + case 1: + _unitID = this->unitBatch1[_batchedUnitID].unitIDOrStatus; + DAT_RenderedUnitOwner::instance = this->unitBatch1[_batchedUnitID].ownerColor; + DAT_CurrentlyRenderedSpriteID::instance = this->unitBatch1[_batchedUnitID].spriteID; + _imageID = this->unitBatch1[_batchedUnitID].imageID; + _drawY = this->unitBatch1[_batchedUnitID].drawY; + _drawX = this->unitBatch1[_batchedUnitID].drawX; + _blendStrength = this->unitBatch1[_batchedUnitID].blendStrength; + _gmID = this->unitBatch1[_batchedUnitID].gmID; + break; + case 2: + _unitID = this->unitBatch2[_batchedUnitID].unitIDOrStatus; + DAT_RenderedUnitOwner::instance = this->unitBatch2[_batchedUnitID].ownerColor; + DAT_CurrentlyRenderedSpriteID::instance = this->unitBatch2[_batchedUnitID].spriteID; + _imageID = this->unitBatch2[_batchedUnitID].imageID; + _drawY = this->unitBatch2[_batchedUnitID].drawY; + _drawX = this->unitBatch2[_batchedUnitID].drawX; + _blendStrength = this->unitBatch2[_batchedUnitID].blendStrength; + _gmID = this->unitBatch2[_batchedUnitID].gmID; + break; + case 3: + _unitID = this->unitBatch3[_batchedUnitID].unitIDOrStatus; + DAT_RenderedUnitOwner::instance = this->unitBatch3[_batchedUnitID].ownerColor; + DAT_CurrentlyRenderedSpriteID::instance = this->unitBatch3[_batchedUnitID].spriteID; + _imageID = this->unitBatch3[_batchedUnitID].imageID; + _drawY = this->unitBatch3[_batchedUnitID].drawY; + _drawX = this->unitBatch3[_batchedUnitID].drawX; + _blendStrength = this->unitBatch3[_batchedUnitID].blendStrength; + _gmID = this->unitBatch3[_batchedUnitID].gmID; + break; + case 4: + _unitID = this->unitBatch4[_batchedUnitID].unitIDOrStatus; + DAT_RenderedUnitOwner::instance = this->unitBatch4[_batchedUnitID].ownerColor; + DAT_CurrentlyRenderedSpriteID::instance = this->unitBatch4[_batchedUnitID].spriteID; + _imageID = this->unitBatch4[_batchedUnitID].imageID; + _drawY = this->unitBatch4[_batchedUnitID].drawY; + _drawX = this->unitBatch4[_batchedUnitID].drawX; + _blendStrength = this->unitBatch4[_batchedUnitID].blendStrength; + _gmID = this->unitBatch4[_batchedUnitID].gmID; + break; + case 5: + _unitID = this->unitBatch5[_batchedUnitID].unitIDOrStatus; + DAT_RenderedUnitOwner::instance = this->unitBatch5[_batchedUnitID].ownerColor; + DAT_CurrentlyRenderedSpriteID::instance = this->unitBatch5[_batchedUnitID].spriteID; + _imageID = this->unitBatch5[_batchedUnitID].imageID; + _drawY = this->unitBatch5[_batchedUnitID].drawY; + _drawX = this->unitBatch5[_batchedUnitID].drawX; + _blendStrength = this->unitBatch5[_batchedUnitID].blendStrength; + _gmID = this->unitBatch5[_batchedUnitID].gmID; + } + if (_unitID == -1) { + if (_blendStrength < 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)((GmID)DAT_CurrentlyRenderedSpriteID::instance, _imageID, + _drawX, _drawY, (GmID)(DAT_CurrentlyRenderedSpriteID::instance), _gmID, -1 - _blendStrength); + } else if (_blendStrength == 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)( + (eGM)DAT_CurrentlyRenderedSpriteID::instance, _imageID, _drawX, _drawY); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)( + (GmID)DAT_CurrentlyRenderedSpriteID::instance, _imageID, _drawX, _drawY, _blendStrength); + } + } else if (_unitID != 0) { + ushort savedPixelColor = *this->viewportState.ptrColor; + *this->viewportState.ptrColor = (ushort)COL_MAGENTA::instance.shortValue; + int _alpha = (int)(char)DAT_UnitsState::instance.units[_unitID].disappearFadeAlphaCountdown; + if (DAT_UnitsState::instance.units[_unitID].unitType == OpenSHC::Map::Units::UT_A_ASSASSIN) { + if (DAT_GameState::instance.mapAndTime.playerTeams[DAT_UnitsState::instance.units[_unitID].owner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && 120 < DAT_UnitsState::instance.units[_unitID].assassinsMicroDistanceToEnemyUnk + && (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY + || (DAT_UnitsState::instance.units[_unitID].idleCounterUnk <= 2400))) { + _alpha = 32 - (32 - _alpha) / 2; + } + overlayX = DAT_UnitsState::instance.units[_unitID].imageID2; + if (overlayX != 0) { + overlayY = (32 - _alpha) / 3; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)(_drawX, _drawY, _imageID, _blendStrength, + DAT_TextureRenderCoreObject::instance.gmProcessedImageData + + DAT_GMImageOffsets::instance[GMFirstPictureIndex::instance[( + int)DAT_CurrentlyRenderedSpriteID::instance] + + overlayX - 1], + (16 - overlayY) * 2); + graphicSize = DAT_UnitsState::instance.units[_unitID].drawYOffset; + if (graphicSize != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)(_drawX, _drawY, _imageID, _blendStrength, + DAT_TextureRenderCoreObject::instance.gmProcessedImageData + + DAT_GMImageOffsets::instance[GMFirstPictureIndex::instance[( + int)DAT_CurrentlyRenderedSpriteID::instance] + + graphicSize - 1], + 32 - overlayY); + } + } + } + if (_alpha != 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationWithBlendingUnk, + DAT_TextureRenderCoreObject::ptr)( + _drawX, _drawY, _imageID, _blendStrength, (byte*)_gmID, _alpha); + if (*this->viewportState.ptrColor != (ushort)COL_MAGENTA::instance.shortValue) { + this->viewportState.mouseRayUnitID = _unitID; + this->viewportState.mouseRayBuildingID = 0; + } else { + *this->viewportState.ptrColor = savedPixelColor; + } + } else { + if (DAT_UnitsState::instance.units[_unitID].graphicSize == 4) { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::renderAssassinClimbingOverlay, this)(_unitID); + } + graphicSize = DAT_UnitsState::instance.units[_unitID].field_0x86; + if (graphicSize < 0) { + overlayX = 0; + } else { + overlayX = graphicSize; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)( + _drawX, graphicSize + _drawY, _imageID, _blendStrength - overlayX, (byte*)_gmID); + graphicSize = DAT_UnitsState::instance.units[_unitID].graphicSize; + if (graphicSize != 4 && graphicSize >= 2) { + DAT_RenderedUnitOwner::instance + = (uint)DAT_UnitsState::instance.units[_unitID].displayColorPlayerID; + DAT_CurrentlyRenderedSpriteID::instance = DAT_UnitsState::instance.units[_unitID].gmIDUnk; + overlayX = DAT_UnitsState::instance.units[_unitID].imageIDUnk; + if (0 < overlayX) { + graphicSize = DAT_UnitsState::instance.units[_unitID].field_0x88; + if (graphicSize < 0) { + overlayY = 0; + } else { + overlayY = graphicSize; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)(_drawX, graphicSize + _drawY, _imageID, + _blendStrength - overlayY, + DAT_TextureRenderCoreObject::instance.gmProcessedImageData + + DAT_GMImageOffsets::instance[GMFirstPictureIndex::instance[( + int)DAT_CurrentlyRenderedSpriteID::instance] + + overlayX - 1]); + } + } + if (DAT_UnitsState::instance.units[_unitID].graphicSize >= 3) { + overlayX = DAT_UnitsState::instance.units[_unitID].imageID2; + if (0 < overlayX) { + graphicSize = DAT_UnitsState::instance.units[_unitID].drawYOffset; + if (graphicSize < 0) { + overlayY = 0; + } else { + overlayY = graphicSize; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderUnitAnimationUnk, + DAT_TextureRenderCoreObject::ptr)(_drawX, graphicSize + _drawY, _imageID, + _blendStrength - overlayY, + DAT_TextureRenderCoreObject::instance.gmProcessedImageData + + DAT_GMImageOffsets::instance[GMFirstPictureIndex::instance[( + int)DAT_CurrentlyRenderedSpriteID::instance] + + overlayX - 1]); + } + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + unitType = DAT_UnitsState::instance.units[_unitID].unitType; + overlayX = _drawX; + overlayY = _drawY; + if ((unitType == OpenSHC::Map::Units::UT_S_TOWER) + && (DAT_UnitsState::instance.units[_unitID].dying == 0)) { + switch ( + DAT_UnitsState::instance.units[_unitID].facingDirectionMapOrientationCorrected) { + case 0: + overlayX = _drawX + 34; + break; + case 1: + overlayX = _drawX + 47; + overlayY = _drawY - 12; + break; + case 2: + overlayX = _drawX + 75; + overlayY = _drawY - 19; + break; + case 3: + overlayX = _drawX + 101; + overlayY = _drawY - 10; + break; + case 4: + overlayX = _drawX + 112; + overlayY = _drawY + 2; + break; + case 5: + overlayX = _drawX + 100; + overlayY = _drawY + 20; + break; + case 6: + overlayX = _drawX + 70; + overlayY = _drawY + 19; + break; + case 7: + overlayX = _drawX + 44; + overlayY = _drawY + 23; + } + } else if ((unitType == OpenSHC::Map::Units::UT_S_BATTERINGRAM) + && (DAT_UnitsState::instance.units[_unitID].dying == 0)) { + switch ( + DAT_UnitsState::instance.units[_unitID].facingDirectionMapOrientationCorrected) { + case 0: + case 1: + overlayX = _drawX + 44; + overlayY = _drawY - 20; + break; + case 2: + overlayX = _drawX + 49; + overlayY = _drawY - 17; + break; + case 3: + overlayX = _drawX + 41; + overlayY = _drawY - 15; + break; + case 4: + overlayX = _drawX + 34; + overlayY = _drawY - 17; + break; + case 5: + case 6: + overlayX = _drawX + 32; + overlayY = _drawY - 20; + break; + case 7: + overlayX = _drawX + 40; + overlayY = _drawY - 23; + } + } + DAT_RenderedUnitOwner::instance = (uint)DAT_UnitsState::instance.units[_unitID].owner; + DAT_CurrentlyRenderedSpriteID::instance = 189; + int const animationTick = (DAT_UnitsState::instance.units[_unitID].fixedRng + + DAT_GameState::instance.mapAndTime.totalGameTicksUnk) + % 64; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)( + OpenSHC::DE::SHCDE::GM_ANIM_FLAG_SMALL, animationTick / 2 + 1, overlayX, overlayY); + } + } + if (*this->viewportState.ptrColor != (ushort)COL_MAGENTA::instance.shortValue) { + this->viewportState.mouseRayUnitID = _unitID; + this->viewportState.mouseRayBuildingID = 0; + } else { + *this->viewportState.ptrColor = savedPixelColor; + } + } + } else { + if ((_blendStrength & 4) != 0) { + DAT_RenderedUnitOwner::instance + = (_blendStrength & 0x10) != 0 ? 0 : DAT_GameSynchronyState::instance.currentPlayerSlotID; + DAT_CurrentlyRenderedSpriteID::instance = _gmID; + } + if ((_blendStrength & 0x20) != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)( + (GmID)_gmID, _imageID, _drawX, _drawY, (GmID)_gmID, (_blendStrength >> 16) + _imageID, 0); + } else if ((_blendStrength & 0xffff0000) != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)((GmID)_gmID, _imageID, _drawX, _drawY, _blendStrength >> 16); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((eGM)_gmID, _imageID, _drawX, _drawY); + } + } + if (0 < _unitID) { + if (DAT_UnitsState::instance.units[_unitID].isSelected != 0 + && DAT_UnitsState::instance.units[_unitID].usingTeleport == 0) { + int const barX = (_imageID - 22) / 2 + _drawX; + int barY; + int barImage; + if (DAT_UnitsState::instance.units[_unitID].unitType == OpenSHC::Map::Units::UT_LORD) { + short const lordRating = DAT_UnitsState::instance.units[_unitID].maxHealthRatingLord; + barY = DAT_UnitsState::instance.units[_unitID].someDrawYOffset; + if (lordRating == 0) { + barY = barY - 6 + _drawY; + barImage = DAT_UnitsState::instance.units[_unitID].healthbar + 17; + } else { + barY = barY - 8 + _drawY; + barImage = DAT_UnitsState::instance.units[_unitID].healthbar + 228 + lordRating * 11; + } + } else { + int const fearFactor + = DAT_GameState::instance.playerDataArray[DAT_UnitsState::instance.units[_unitID].owner] + .fearFactorLevel; + if (fearFactor != 0) { + int fearImage; + if (fearFactor > 0) { + fearImage = fearFactor * 11 + 118; + } else { + fearImage = 173 - fearFactor * 11; + } + barY = DAT_UnitsState::instance.units[_unitID].someDrawYOffset - 8; + barImage = DAT_UnitsState::instance.units[_unitID].healthbar + fearImage; + } else { + barY = DAT_UnitsState::instance.units[_unitID].someDrawYOffset - 6; + barImage = DAT_UnitsState::instance.units[_unitID].healthbar + 17; + } + barY = barY + _drawY; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_FLOATS, barImage, barX, barY); + if (DAT_UnitsState::instance.units[_unitID].unitType == OpenSHC::Map::Units::UT_A_ASSASSIN + && DAT_GameState::instance.mapAndTime.playerTeams[DAT_UnitsState::instance.units[_unitID].owner] + == DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && (DAT_UnitsState::instance.units[_unitID].assassinsMicroDistanceToEnemyUnk <= 160 + || DAT_UnitsState::instance.units[_unitID].state.generic + == OpenSHC::Map::Units::States::US_MELEE_ATTACK + || DAT_UnitsState::instance.units[_unitID].state.generic + == OpenSHC::Map::Units::States::US_MELEE_ATTACK_WALL)) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 447, + barX + 2, DAT_UnitsState::instance.units[_unitID].someDrawYOffset - 27 + _drawY, 16); + } + } + short const floaterImage = DAT_UnitsState::instance.units[_unitID].field_0x6e; + if (floaterImage != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, floaterImage + 212, + DAT_UnitsState::instance.units[_unitID].drawX, + DAT_UnitsState::instance.units[_unitID].drawY - 54 + + DAT_UnitsState::instance.units[_unitID].someDrawYOffset, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, floaterImage + 220, 0); + DAT_UnitsState::instance.units[_unitID].field_0x6e = 0; + } + short const siegeOverlay = DAT_UnitsState::instance.units[_unitID].field_0x6c; + if (siegeOverlay != 0) { + int offsetX = 0; + int offsetY = 0; + switch (siegeOverlay) { + case 1: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame + 32, + DAT_UnitsState::instance.units[_unitID].field_0x2a - 53 + + DAT_UnitsState::instance.units[_unitID].drawX, + DAT_UnitsState::instance.units[_unitID].drawY - 70 + + DAT_UnitsState::instance.units[_unitID].someDrawYOffset, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame + 48, 0); + break; + case 2: + switch (DAT_UnitsState::instance.units[_unitID].unitType) { + case OpenSHC::Map::Units::UT_S_CATAPULT: + offsetX = 41; + offsetY = 58; + break; + case OpenSHC::Map::Units::UT_S_TREBUCHET: + case OpenSHC::Map::Units::UT_S_TOWER: + offsetX = 79; + offsetY = 56; + break; + case OpenSHC::Map::Units::UT_S_BATTERINGRAM: + offsetX = 36; + offsetY = 61; + break; + case OpenSHC::Map::Units::UT_S_SHIELD: + offsetX = -3; + offsetY = 60; + break; + case OpenSHC::Map::Units::UT_S_MANGONEL: + offsetX = 43; + offsetY = 35; + break; + case OpenSHC::Map::Units::UT_S_BALLISTA: + case OpenSHC::Map::Units::UT_S_FBALLISTA: + offsetX = 19; + offsetY = 36; + break; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame + 116, + DAT_UnitsState::instance.units[_unitID].drawX + offsetX, + (DAT_UnitsState::instance.units[_unitID].drawY + + DAT_UnitsState::instance.units[_unitID].someDrawYOffset) + - offsetY, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame + 132, 0); + break; + case 3: + switch (DAT_UnitsState::instance.units[_unitID].unitType) { + case OpenSHC::Map::Units::UT_S_CATAPULT: + offsetX = 41; + offsetY = 58; + break; + case OpenSHC::Map::Units::UT_S_TREBUCHET: + case OpenSHC::Map::Units::UT_S_TOWER: + offsetX = 79; + offsetY = 56; + break; + case OpenSHC::Map::Units::UT_S_BATTERINGRAM: + offsetX = 36; + offsetY = 61; + break; + case OpenSHC::Map::Units::UT_S_SHIELD: + offsetX = -3; + offsetY = 60; + break; + case OpenSHC::Map::Units::UT_S_MANGONEL: + offsetX = 43; + offsetY = 35; + break; + case OpenSHC::Map::Units::UT_S_BALLISTA: + case OpenSHC::Map::Units::UT_S_FBALLISTA: + offsetX = 19; + offsetY = 36; + break; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame + 148, + DAT_UnitsState::instance.units[_unitID].drawX + offsetX, + (DAT_UnitsState::instance.units[_unitID].drawY + + DAT_UnitsState::instance.units[_unitID].someDrawYOffset) + - offsetY, + OpenSHC::IO::Graphics::GID_FLOATS_NEW, + DAT_TileMapState::instance.cursorOverlayAnimationFrame + 164, 0); + break; + } + DAT_UnitsState::instance.units[_unitID].field_0x6c = 0; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Rendering/ViewportRenderState/setTileSystemMemoryLookupArrays.cpp b/src/OpenSHC/Rendering/ViewportRenderState/setTileSystemMemoryLookupArrays.cpp new file mode 100644 index 0000000000..79b09b8ed8 --- /dev/null +++ b/src/OpenSHC/Rendering/ViewportRenderState/setTileSystemMemoryLookupArrays.cpp @@ -0,0 +1,174 @@ +#include "../ViewportRenderState.func.hpp" + +namespace OpenSHC { +namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x004E2050 + void ViewportRenderState::setTileSystemMemoryLookupArrays() + { + int tileNumber = 0; + int tileGrid[160000]; + for (int i = 0; i < 160000; i++) { + tileGrid[i] = 0; + } + + // the map is a diamond: rows grow by two tiles down to the middle, then shrink again + int rowFirstColumn = 199; + int rowWidth = 2; + int rowSpan = 398; + int row; + for (row = 0; row < 200; row++) { + this->translationMatrix[row].distanceToCenter = rowSpan / 2; + this->translationMatrix[row].firstTileOfRow = tileNumber; + this->translationMatrix[row].addXgetTile = tileNumber - rowSpan / 2; + for (int column = 0; column < rowWidth; column++) { + tileGrid[rowFirstColumn + row * 400 + column] = tileNumber; + tileNumber++; + } + rowSpan -= 2; + rowFirstColumn--; + rowWidth += 2; + } + rowSpan = 400 - rowWidth; + for (; row < 400; row++) { + rowFirstColumn++; + rowSpan += 2; + rowWidth -= 2; + this->translationMatrix[row].distanceToCenter = rowSpan / 2; + this->translationMatrix[row].firstTileOfRow = tileNumber; + this->translationMatrix[row].addXgetTile = tileNumber - rowSpan / 2; + for (int column = 0; column < rowWidth; column++) { + tileGrid[row * 400 + rowFirstColumn + column] = tileNumber; + tileNumber++; + } + } + this->translationMatrix[row].distanceToCenter = (400 - rowWidth) / 2; + this->translationMatrix[row].firstTileOfRow = tileNumber; + this->translationMatrix[row].addXgetTile = tileNumber - (400 - rowWidth) / 2; + + for (int i = 0; i < 8; i++) { + this->screenPointToTileNumber[i] = 0; + } + int screenIndex = 8; + + // orientation 0 + int startX = 0; + int startY = 199 * 400; + for (int r = 200; r > 0; r--) { + int x = startX; + int y = startY; + for (int n = 200; n > 0; n--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + x]; + x++; + y -= 400; + } + startY += 400; + x = startX; + y = startY; + for (int n = 200; n >= 0; n--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + x]; + x++; + y -= 400; + } + startX++; + } + for (int y = 399 * 400, n = 200; n > 0; n--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + startX]; + startX++; + y -= 400; + } + + // orientation 6 + startX = 199; + startY = 399; + for (int r = 0; r < 200; r++) { + int x = startX; + int y = startY * 400; + for (int n = 0; n < 200; n++) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + x]; + x--; + y -= 400; + } + int const nextStartX = startX + 1; + x = nextStartX; + y = (nextStartX - startX + startY) * 400; + int n = nextStartX - startX + 199; + do { + y -= 400; + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + x]; + x--; + n--; + } while (n >= 0); + startX = nextStartX; + startY--; + } + { + int y = startY * 400; + for (int n = 0; n < 200; n++) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + startX]; + startX--; + y -= 400; + } + } + + // orientation 4 + int column = 199; + for (int rowBase = 80000; rowBase > 0;) { + int y = rowBase; + for (int dx = 200; dx > 0; dx--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[column + y + dx]; + y += 400; + } + rowBase -= 400; + y = rowBase; + for (int dx = 200; dx >= 0; dx--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[column + y + dx]; + y += 400; + } + column--; + } + for (int y = 0, dx = 200; dx > 0; dx--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + dx - 1]; + y += 400; + } + + // orientation 2 + int rowY = 0; + int startColumn = 200; + do { + int x = startColumn; + int y = rowY * 400; + for (int n = 200; n > 0; n--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + x]; + x++; + y += 400; + } + int const nextStartColumn = startColumn - 1; + x = nextStartColumn; + y = (nextStartColumn - startColumn + 1 + rowY) * 400; + for (int n = 200; n >= 0; n--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + x]; + x++; + y += 400; + } + rowY++; + startColumn = nextStartColumn; + } while (startColumn > 0); + { + int y = rowY * 400; + for (int n = 200; n > 0; n--) { + this->screenPointToTileNumber[screenIndex++] = tileGrid[y + startColumn]; + startColumn++; + y += 400; + } + } + + for (int y = 0; y < 400; y++) { + for (int x = 0; x < 400; x++) { + this->DAT_BinaryTileMap400x400[y * 400 + x] = tileGrid[y * 400 + x] > 0; + } + } + } + +} +} diff --git a/src/OpenSHC/Rendering/ViewportRenderState/setupViewport.cpp b/src/OpenSHC/Rendering/ViewportRenderState/setupViewport.cpp new file mode 100644 index 0000000000..da807fa030 --- /dev/null +++ b/src/OpenSHC/Rendering/ViewportRenderState/setupViewport.cpp @@ -0,0 +1,706 @@ +#include "../ViewportRenderState.func.hpp" + +#include "OpenSHC/Rendering/ScreenResolutionEnum.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_ScrollingHandler.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace Rendering { + + using OpenSHC::Rendering::ScreenResolutionEnum; + using OpenSHC::UI::Enums::BuildingsAndStatusMenuTabType; + using OpenSHC::UI::Enums::MenuViewType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004E66F0 + void ViewportRenderState::setupViewport(int windowX, int windowY, int screenPixelWidth, int screenPixelHeight) + { + this->windowX = windowX; + // fixme: the original stores windowX into windowY as well + this->windowY = windowX; + this->screenPixelHeight = screenPixelHeight; + this->screenPixelWidth = screenPixelWidth; + if ((DAT_GameCore::instance.currentMenuViewType == OpenSHC::UI::Enums::MVT_BUILD_MENU + || DAT_GameCore::instance.currentMenuViewType == OpenSHC::UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) + && (DAT_GameCore::instance.activeMenuTab.tabType == OpenSHC::UI::Enums::BASMTT_SIEGETENT_SIEGETOWER + || DAT_GameCore::instance.activeMenuTab.tabType == OpenSHC::UI::Enums::BASMTT_SIEGETENT_SHIELD)) { + if (this->viewportState.isZoomedOutUnk == 0) { + if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_800x600) { + this->viewportState.viewportHeight = 30; + this->viewportState.viewportWidth = 79; + this->viewportState.mbr_0xac = 12; + this->viewportState.mbr_0xb0 = 40; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 20; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 40; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 30; + this->viewportState.someXOffset = 8; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1024x768) { + this->viewportState.viewportHeight = 37; + this->viewportState.viewportWidth = 100; + this->viewportState.mbr_0xac = 15; + this->viewportState.mbr_0xb0 = 46; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 17; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 52; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 35; + this->viewportState.someXOffset = 10; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1024x600) { + this->viewportState.viewportHeight = 37; + this->viewportState.viewportWidth = 79; + this->viewportState.mbr_0xac = 15; + this->viewportState.mbr_0xb0 = 40; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 17; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 52; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 35; + this->viewportState.someXOffset = 10; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1280x1024) { + this->viewportState.viewportHeight = 45; + this->viewportState.viewportWidth = 132; + this->viewportState.mbr_0xac = 19; + this->viewportState.mbr_0xb0 = 52; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 40; + this->viewportState.someXOffset = 12; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_640x480) { + this->viewportState.viewportWidth = 64; + this->viewportState.viewportHeight = 25; + this->viewportState.mbr_0xac = 10; + this->viewportState.mbr_0xb0 = 30; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 40; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 20; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 30; + this->viewportState.someXOffset = 7; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1600x1200) { + this->viewportState.viewportWidth = 154; + this->viewportState.mbr_0xb0 = 80; + this->viewportState.viewportHeight = 55; + this->viewportState.mbr_0xac = 24; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 14; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1280x720) { + this->viewportState.viewportHeight = 45; + this->viewportState.viewportWidth = 94; + this->viewportState.mbr_0xac = 19; + this->viewportState.mbr_0xb0 = 48; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 52; + this->viewportState.someXOffset = 17; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1440x900) { + this->viewportState.viewportWidth = 116; + this->viewportState.viewportHeight = 50; + this->viewportState.mbr_0xac = 22; + this->viewportState.mbr_0xb0 = 60; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 10; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1920x1080) { + this->viewportState.viewportWidth = 139; + this->viewportState.viewportHeight = 65; + this->viewportState.mbr_0xac = 29; + this->viewportState.mbr_0xb0 = 72; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 13; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1920x1200) { + this->viewportState.viewportWidth = 154; + this->viewportState.mbr_0xac = 29; + this->viewportState.viewportHeight = 65; + this->viewportState.mbr_0xb0 = 80; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 76; + this->viewportState.someXOffset = 14; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_2560x1440) { + this->viewportState.viewportWidth = 184; + this->viewportState.mbr_0xb0 = 96; + this->viewportState.viewportHeight = 85; + this->viewportState.mbr_0xac = 39; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 100; + this->viewportState.someXOffset = 16; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_2560x1600) { + this->viewportState.viewportWidth = 204; + this->viewportState.mbr_0xb0 = 112; + this->viewportState.viewportHeight = 85; + this->viewportState.mbr_0xac = 39; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 100; + this->viewportState.someXOffset = 16; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1366x768) { + this->viewportState.viewportHeight = 48; + this->viewportState.viewportWidth = 100; + this->viewportState.mbr_0xac = 22; + this->viewportState.mbr_0xb0 = 46; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 10; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1360x768) { + this->viewportState.viewportHeight = 48; + this->viewportState.viewportWidth = 100; + this->viewportState.mbr_0xac = 22; + this->viewportState.mbr_0xb0 = 46; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 10; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1680x1050) { + this->viewportState.viewportHeight = 58; + this->viewportState.viewportWidth = 135; + this->viewportState.mbr_0xac = 24; + this->viewportState.mbr_0xb0 = 72; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 13; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1600x900) { + this->viewportState.viewportWidth = 116; + this->viewportState.mbr_0xb0 = 60; + this->viewportState.viewportHeight = 55; + this->viewportState.mbr_0xac = 24; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 10; + this->viewportState.someYOffset = 64; + } + } else { + if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_800x600) { + this->viewportState.viewportHeight = 60; + this->viewportState.viewportWidth = 158; + this->viewportState.mbr_0xac = 31; + this->viewportState.mbr_0xb0 = 68; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 10; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 80; + DAT_ScrollingHandler::instance.scrollDistanceMin = 2; + this->viewportState.someYOffset = 65; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1024x768) { + this->viewportState.viewportHeight = 74; + this->viewportState.viewportWidth = 200; + this->viewportState.mbr_0xac = 36; + this->viewportState.mbr_0xb0 = 84; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 7; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 100; + DAT_ScrollingHandler::instance.scrollDistanceMin = 3; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1024x600) { + this->viewportState.viewportHeight = 74; + this->viewportState.viewportWidth = 158; + this->viewportState.mbr_0xac = 36; + this->viewportState.mbr_0xb0 = 68; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 7; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 100; + DAT_ScrollingHandler::instance.scrollDistanceMin = 3; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1280x1024) { + this->viewportState.viewportHeight = 90; + this->viewportState.viewportWidth = 264; + this->viewportState.mbr_0xac = 41; + this->viewportState.mbr_0xb0 = 94; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 5; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 100; + DAT_ScrollingHandler::instance.scrollDistanceMin = 3; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_640x480) { + this->viewportState.viewportWidth = 128; + this->viewportState.viewportHeight = 50; + this->viewportState.mbr_0xac = 25; + this->viewportState.mbr_0xb0 = 50; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 20; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 40; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 30; + this->viewportState.someXOffset = 7; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1600x1200) { + this->viewportState.viewportWidth = 308; + this->viewportState.viewportHeight = 110; + this->viewportState.mbr_0xac = 50; + this->viewportState.mbr_0xb0 = 110; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1280x720) { + this->viewportState.viewportHeight = 90; + this->viewportState.viewportWidth = 188; + this->viewportState.mbr_0xac = 41; + this->viewportState.mbr_0xb0 = 80; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 52; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1440x900) { + this->viewportState.viewportHeight = 100; + this->viewportState.viewportWidth = 232; + this->viewportState.mbr_0xac = 47; + this->viewportState.mbr_0xb0 = 90; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1920x1080) { + this->viewportState.viewportHeight = 130; + this->viewportState.viewportWidth = 278; + this->viewportState.mbr_0xac = 56; + this->viewportState.mbr_0xb0 = 100; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1920x1200) { + this->viewportState.viewportHeight = 130; + this->viewportState.viewportWidth = 308; + this->viewportState.mbr_0xac = 56; + this->viewportState.mbr_0xb0 = 110; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 76; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_2560x1440) { + this->viewportState.viewportWidth = 368; + this->viewportState.mbr_0xb0 = 120; + this->viewportState.viewportHeight = 170; + this->viewportState.mbr_0xac = 71; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 100; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_2560x1600) { + this->viewportState.viewportWidth = 408; + this->viewportState.mbr_0xb0 = 130; + this->viewportState.viewportHeight = 170; + this->viewportState.mbr_0xac = 71; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 100; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1366x768) { + this->viewportState.viewportHeight = 96; + this->viewportState.viewportWidth = 200; + this->viewportState.mbr_0xac = 47; + this->viewportState.mbr_0xb0 = 84; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 3; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1360x768) { + this->viewportState.viewportHeight = 96; + this->viewportState.viewportWidth = 200; + this->viewportState.mbr_0xac = 47; + this->viewportState.mbr_0xb0 = 84; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 3; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1680x1050) { + this->viewportState.viewportHeight = 116; + this->viewportState.viewportWidth = 270; + this->viewportState.mbr_0xb0 = 100; + this->viewportState.mbr_0xac = 50; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution + == OpenSHC::Rendering::SRE_1600x900) { + this->viewportState.viewportWidth = 232; + this->viewportState.mbr_0xb0 = 85; + this->viewportState.viewportHeight = 110; + this->viewportState.mbr_0xac = 50; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } + } + } else if (this->viewportState.isZoomedOutUnk == 0) { + if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_800x600) { + this->viewportState.viewportHeight = 30; + this->viewportState.viewportWidth = 63; + this->viewportState.mbr_0xac = 12; + this->viewportState.mbr_0xb0 = 40; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 20; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 40; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 30; + this->viewportState.someXOffset = 7; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x768) { + this->viewportState.viewportHeight = 37; + this->viewportState.viewportWidth = 84; + this->viewportState.mbr_0xac = 15; + this->viewportState.mbr_0xb0 = 46; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 17; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 52; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 40; + this->viewportState.someXOffset = 8; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x600) { + this->viewportState.viewportHeight = 37; + this->viewportState.viewportWidth = 63; + this->viewportState.mbr_0xac = 15; + this->viewportState.mbr_0xb0 = 40; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 17; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 52; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 40; + this->viewportState.someXOffset = 8; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x1024) { + this->viewportState.viewportHeight = 45; + this->viewportState.viewportWidth = 116; + this->viewportState.mbr_0xac = 19; + this->viewportState.mbr_0xb0 = 52; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 52; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 50; + this->viewportState.someXOffset = 8; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_640x480) { + this->viewportState.viewportWidth = 48; + this->viewportState.viewportHeight = 25; + this->viewportState.mbr_0xac = 10; + this->viewportState.mbr_0xb0 = 30; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 40; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 20; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 30; + this->viewportState.someXOffset = 7; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x1200) { + this->viewportState.viewportWidth = 138; + this->viewportState.mbr_0xb0 = 80; + this->viewportState.viewportHeight = 55; + this->viewportState.mbr_0xac = 24; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 14; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x720) { + this->viewportState.viewportHeight = 45; + this->viewportState.viewportWidth = 78; + this->viewportState.mbr_0xac = 19; + this->viewportState.mbr_0xb0 = 48; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 52; + this->viewportState.someXOffset = 17; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1440x900) { + this->viewportState.viewportWidth = 100; + this->viewportState.viewportHeight = 50; + this->viewportState.mbr_0xac = 22; + this->viewportState.mbr_0xb0 = 60; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 10; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1080) { + this->viewportState.viewportWidth = 123; + this->viewportState.viewportHeight = 65; + this->viewportState.mbr_0xac = 29; + this->viewportState.mbr_0xb0 = 72; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 13; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1200) { + this->viewportState.viewportWidth = 138; + this->viewportState.mbr_0xac = 39; + this->viewportState.viewportHeight = 65; + this->viewportState.mbr_0xb0 = 80; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 76; + this->viewportState.someXOffset = 14; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1440) { + this->viewportState.viewportWidth = 168; + this->viewportState.mbr_0xb0 = 90; + this->viewportState.viewportHeight = 85; + this->viewportState.mbr_0xac = 39; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 100; + this->viewportState.someXOffset = 16; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1600) { + this->viewportState.viewportHeight = 85; + this->viewportState.viewportWidth = 188; + this->viewportState.mbr_0xac = 29; + this->viewportState.mbr_0xb0 = 100; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 100; + this->viewportState.someXOffset = 18; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1366x768) { + this->viewportState.viewportHeight = 48; + this->viewportState.viewportWidth = 84; + this->viewportState.mbr_0xac = 22; + this->viewportState.mbr_0xb0 = 46; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 8; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1360x768) { + this->viewportState.viewportHeight = 48; + this->viewportState.viewportWidth = 84; + this->viewportState.mbr_0xac = 22; + this->viewportState.mbr_0xb0 = 46; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 8; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1680x1050) { + this->viewportState.viewportHeight = 58; + this->viewportState.viewportWidth = 119; + this->viewportState.mbr_0xac = 24; + this->viewportState.mbr_0xb0 = 72; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 13; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x900) { + this->viewportState.viewportWidth = 100; + this->viewportState.mbr_0xb0 = 60; + this->viewportState.viewportHeight = 55; + this->viewportState.mbr_0xac = 24; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 10; + this->viewportState.someYOffset = 64; + } + } else { + if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_800x600) { + this->viewportState.viewportHeight = 60; + this->viewportState.viewportWidth = 126; + this->viewportState.mbr_0xac = 31; + this->viewportState.mbr_0xb0 = 68; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 10; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 80; + DAT_ScrollingHandler::instance.scrollDistanceMin = 2; + this->viewportState.someYOffset = 65; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x768) { + this->viewportState.viewportHeight = 74; + this->viewportState.viewportWidth = 168; + this->viewportState.mbr_0xac = 36; + this->viewportState.mbr_0xb0 = 84; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 7; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 100; + DAT_ScrollingHandler::instance.scrollDistanceMin = 3; + this->viewportState.someYOffset = 78; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1024x600) { + this->viewportState.viewportHeight = 74; + this->viewportState.viewportWidth = 126; + this->viewportState.mbr_0xac = 36; + this->viewportState.mbr_0xb0 = 68; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 7; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 100; + DAT_ScrollingHandler::instance.scrollDistanceMin = 3; + this->viewportState.someYOffset = 78; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x1024) { + this->viewportState.viewportHeight = 90; + this->viewportState.viewportWidth = 232; + this->viewportState.mbr_0xac = 41; + this->viewportState.mbr_0xb0 = 94; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 5; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 100; + DAT_ScrollingHandler::instance.scrollDistanceMin = 3; + this->viewportState.someYOffset = 91; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_640x480) { + this->viewportState.viewportWidth = 96; + this->viewportState.viewportHeight = 50; + this->viewportState.mbr_0xac = 25; + this->viewportState.mbr_0xb0 = 50; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 20; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 40; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 30; + this->viewportState.someXOffset = 7; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x1200) { + this->viewportState.viewportWidth = 276; + this->viewportState.viewportHeight = 110; + this->viewportState.mbr_0xac = 50; + this->viewportState.mbr_0xb0 = 110; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1280x720) { + this->viewportState.viewportHeight = 90; + this->viewportState.viewportWidth = 156; + this->viewportState.mbr_0xac = 41; + this->viewportState.mbr_0xb0 = 80; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 52; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1440x900) { + this->viewportState.viewportHeight = 100; + this->viewportState.viewportWidth = 200; + this->viewportState.mbr_0xac = 47; + this->viewportState.mbr_0xb0 = 90; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1080) { + this->viewportState.viewportHeight = 130; + this->viewportState.viewportWidth = 246; + this->viewportState.mbr_0xac = 56; + this->viewportState.mbr_0xb0 = 100; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1920x1200) { + this->viewportState.viewportHeight = 130; + this->viewportState.viewportWidth = 276; + this->viewportState.mbr_0xac = 56; + this->viewportState.mbr_0xb0 = 110; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 76; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1440) { + this->viewportState.viewportWidth = 336; + this->viewportState.mbr_0xb0 = 120; + this->viewportState.viewportHeight = 170; + this->viewportState.mbr_0xac = 71; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 100; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_2560x1600) { + this->viewportState.viewportWidth = 376; + this->viewportState.mbr_0xb0 = 130; + this->viewportState.viewportHeight = 170; + this->viewportState.mbr_0xac = 71; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someYOffset = 100; + this->viewportState.someXOffset = 6; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1366x768) { + this->viewportState.viewportHeight = 96; + this->viewportState.viewportWidth = 168; + this->viewportState.mbr_0xac = 47; + this->viewportState.mbr_0xb0 = 84; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1360x768) { + this->viewportState.viewportHeight = 96; + this->viewportState.viewportWidth = 168; + this->viewportState.mbr_0xac = 47; + this->viewportState.mbr_0xb0 = 84; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1680x1050) { + this->viewportState.viewportHeight = 116; + this->viewportState.viewportWidth = 238; + this->viewportState.mbr_0xb0 = 100; + this->viewportState.mbr_0xac = 50; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } else if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_1600x900) { + this->viewportState.viewportWidth = 200; + this->viewportState.mbr_0xb0 = 85; + this->viewportState.viewportHeight = 110; + this->viewportState.mbr_0xac = 50; + DAT_ScrollingHandler::instance.scrollAccelerationInterval = 15; + DAT_ScrollingHandler::instance.scrollDistanceLimit = 60; + DAT_ScrollingHandler::instance.scrollDistanceMin = 1; + this->viewportState.someXOffset = 6; + this->viewportState.someYOffset = 64; + } + } + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::setViewportBasedOnMapSize, this)(); + } + +} +} diff --git a/src/OpenSHC/Rendering/ViewportRenderState/updateBuildingPreviewPosition.cpp b/src/OpenSHC/Rendering/ViewportRenderState/updateBuildingPreviewPosition.cpp new file mode 100644 index 0000000000..2fb544f098 --- /dev/null +++ b/src/OpenSHC/Rendering/ViewportRenderState/updateBuildingPreviewPosition.cpp @@ -0,0 +1,364 @@ +#include "../ViewportRenderState.func.hpp" + +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MapRenderDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MenuHandlerState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitPropertiesDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Rendering { + + using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::Map::Buildings::BuildingTypeShort; + using OpenSHC::Map::Units::UnitType; + using OpenSHC::Map::Units::States::UnitState; + using OpenSHC::UI::Enums::BuildingsAndStatusMenuTabType; + using OpenSHC::UI::Enums::MenuViewType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004E8430 + void ViewportRenderState::updateBuildingPreviewPosition(int mouseXScreenSpace, int mouseYScreenSpace) + { + int orientationBase = 8; + + this->viewportState.field_0x0 = 1; + if (mouseYScreenSpace - this->windowY < 0) { + this->viewportState.field_0x0 = 0; + } + if (mouseYScreenSpace - this->windowY >= this->screenPixelHeight) { + this->viewportState.field_0x0 = 0; + } + if (mouseXScreenSpace - this->windowX < 0) { + this->viewportState.field_0x0 = 0; + } + if (mouseXScreenSpace - this->windowX >= this->screenPixelWidth) { + this->viewportState.field_0x0 = 0; + } + + if (DAT_TextureRenderCoreObject::instance.activeMenuTabIndex != 0) { + int const tab = DAT_TextureRenderCoreObject::instance.activeMenuTabIndex - 1; + for (int i = 0; DAT_MapRenderDefinedData::instance.BuildingPreviewPositionRelatedOffsets[tab][i][0].x != -1; + i++) { + if (mouseXScreenSpace >= DAT_MenuHandlerState::instance.x + + DAT_MapRenderDefinedData::instance.BuildingPreviewPositionRelatedOffsets[tab][i][0].x + && mouseXScreenSpace + <= DAT_MapRenderDefinedData::instance.BuildingPreviewPositionRelatedOffsets[tab][i][1].x + + DAT_MapRenderDefinedData::instance.BuildingPreviewPositionRelatedOffsets[tab][i][0].x + + DAT_MenuHandlerState::instance.x + && mouseYScreenSpace + >= DAT_MapRenderDefinedData::instance.BuildingPreviewPositionRelatedOffsets[tab][i][0].y + + DAT_MenuHandlerState::instance.y + && mouseYScreenSpace + <= DAT_MapRenderDefinedData::instance.BuildingPreviewPositionRelatedOffsets[tab][i][1].y + + DAT_MapRenderDefinedData::instance.BuildingPreviewPositionRelatedOffsets[tab][i][0].y + + DAT_MenuHandlerState::instance.y) { + this->viewportState.field_0x0 = 0; + return; + } + } + } + + if (this->viewportState.field_0x0 == 0) { + if (DAT_GameCore::instance.currentMenuViewType != OpenSHC::UI::Enums::MVT_BUILD_MENU) { + return; + } + if (DAT_GameCore::instance.activeMenuTab.tabType != OpenSHC::UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM + && DAT_TileMapState::instance.shiftRelated0or3 != 1) { + return; + } + + mouseXScreenSpace = 0; + mouseYScreenSpace = 0; + MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::convertMinimapClickToTileXY, + DAT_MinimapViewState::ptr)(&mouseXScreenSpace, &mouseYScreenSpace); + if (mouseXScreenSpace == -1) { + return; + } + + int minimapTile = this->translationMatrix[mouseYScreenSpace].addXgetTile + mouseXScreenSpace; + this->viewportState.field_0x48 = 0; + this->viewportState.field_0x18 = DAT_TileMapState::instance.BuildingLayer[minimapTile]; + this->viewportState.field_0x20 = DAT_TileMapState::instance.UnitLayer[minimapTile]; + this->viewportState.mouseRayEntityID = DAT_TileMapState::instance.EntityLayer[minimapTile]; + + int minimapGateTile = 0; + short minimapBuildingID = DAT_TileMapState::instance.BuildingLayer[minimapTile]; + if (minimapBuildingID <= 0 + && (DAT_TileMapState::instance.LogicLayer[minimapTile] & Map::LogicHelpers::L_WALL_OR_GATEHOUSE) != 0) { + minimapGateTile = minimapTile; + } else if (DAT_TileMapState::instance.BuildingLayer[minimapTile] <= 0) { + this->viewportState.field_0x48 = DAT_TileMapState::instance.BuildingWasLayer[minimapTile]; + } + if (0 <= minimapGateTile) { + this->viewportState.mouseRayBuildingID = 0; + this->viewportState.cursorWallTile = minimapGateTile; + } + + this->viewportState.mouseX = mouseXScreenSpace; + this->viewportState.mouseTileX = mouseXScreenSpace; + this->viewportState.mouseAtomRefFloorTile = minimapTile; + this->viewportState.cursorTile = minimapTile; + this->viewportState.mouseFlatTile = minimapTile; + this->viewportState.mouseY = mouseYScreenSpace; + this->viewportState.mouseTileY = mouseYScreenSpace; + this->viewportState.field_0x38 + = DAT_TileMapState::instance.LogicLayer[minimapTile] & Map::LogicHelpers::L_MOAT; + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, DAT_TileMapState::ptr)( + minimapTile) + == 0) { + this->viewportState.field_0x38 = 0; + } + this->viewportState.field_0x40 + = DAT_TileMapState::instance.LogicLayer[minimapTile] & Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; + return; + } + + int quadrantX; + int quadrantY; + if (this->viewportState.isZoomedOutUnk == 0) { + quadrantY = (this->viewportState.viewportY % 16 - this->windowY) + mouseYScreenSpace - 8; + quadrantX = ((this->viewportState.viewportX % 32 - this->windowX) + mouseXScreenSpace) >> 1 & 0xf; + } else { + quadrantX = ((this->viewportState.viewportX % 32 + mouseXScreenSpace * 2) - this->windowX) >> 1 & 0xf; + quadrantY = (this->viewportState.viewportY % 16 + mouseYScreenSpace * 2 - 8) - this->windowY; + } + quadrantY = quadrantY & 0xf; + + if (DAT_TileMapState::instance.mapOrientation == 0) { + orientationBase = 8; + } else if (DAT_TileMapState::instance.mapOrientation == 6) { + orientationBase = 80408; + } else if (DAT_TileMapState::instance.mapOrientation == 4) { + orientationBase = 160808; + } else if (DAT_TileMapState::instance.mapOrientation == 2) { + orientationBase = 241208; + } + + int lookupIndex; + if (this->viewportState.isZoomedOutUnk == 0) { + int const unclampedY = (this->viewportState.viewportY - this->windowY) + mouseYScreenSpace + 8; + int const unclampedX = (this->viewportState.viewportX - this->windowX) + mouseXScreenSpace; + lookupIndex = unclampedX / 32 + orientationBase + unclampedY / 16 * 401; + } else { + int const unclampedY = ((mouseYScreenSpace * 2 + 8) - this->windowY) + this->viewportState.viewportY; + int const unclampedX = ((mouseXScreenSpace * 2 + 160) - this->windowX) + this->viewportState.viewportX; + lookupIndex = unclampedX / 32 + orientationBase + unclampedY / 16 * 401; + } + int quadrant = DAT_MapRenderDefinedData::instance.field_0xc24[quadrantY][quadrantX]; + if (quadrant == 1) { + lookupIndex = lookupIndex + 200; + } else if (quadrant == 2) { + lookupIndex = lookupIndex + 201; + } else if (quadrant == 3) { + lookupIndex = lookupIndex + 401; + } + + this->viewportState.mouseFlatTile = this->screenPointToTileNumber[lookupIndex]; + this->viewportState.field_0x14 = DAT_TileMapState::instance.EntityLayer[this->viewportState.mouseFlatTile]; + this->viewportState.field_0x14 = DAT_TileMapState::instance.LogicLayer[this->viewportState.mouseFlatTile]; + this->viewportState.field_0x18 = DAT_TileMapState::instance.BuildingLayer[this->viewportState.mouseFlatTile]; + this->viewportState.field_0x20 = DAT_TileMapState::instance.UnitLayer[this->viewportState.mouseFlatTile]; + this->viewportState.field_0x48 = 0; + + if (this->viewportState.mouseRayUnitID != 0) { + this->viewportState.mouseRayLastUnitID = this->viewportState.mouseRayUnitID; + this->viewportState.field_0x34 = timeGetTime(); + if (DAT_UnitsState::instance.units[this->viewportState.mouseRayUnitID].unitType + == OpenSHC::Map::Units::UT_S_TOWER + && DAT_UnitsState::instance.units[this->viewportState.mouseRayUnitID].state.generic + == (OpenSHC::Map::Units::States::US_STAND_UPUnk | OpenSHC::Map::Units::States::US_IDLEUnk)) { + this->viewportState.mouseRayBuildingID + = DAT_UnitsState::instance.units[this->viewportState.mouseRayUnitID].workplaceBuildingID_1; + this->viewportState.mouseRayUnitID = 0; + } + } + + this->viewportState.field_0x4c = DAT_MapRenderDefinedData::instance.field_0x1024[quadrantY][quadrantX]; + this->viewportState.field_0x50 = DAT_MapRenderDefinedData::instance.field_0x1424[quadrantY][quadrantX]; + this->viewportState.field_0x58 + = DAT_UnitPropertiesDefinedData::instance + .field_0x10f4c[this->viewportState.field_0x4c + this->viewportState.field_0x50 * 8][0]; + this->viewportState.field_0x5c + = DAT_UnitPropertiesDefinedData::instance + .field_0x10f4c[this->viewportState.field_0x4c + this->viewportState.field_0x50 * 8][1]; + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::setupMouseTileXY2, this)(); + + int lastBuildingID = -1; + int hoveredBuildingID = -1; + int hoveredGateTile = -1; + short hoveredBuildingLayer = DAT_TileMapState::instance.BuildingLayer[this->viewportState.mouseFlatTile]; + if (hoveredBuildingLayer <= 0 + && (DAT_TileMapState::instance.LogicLayer[this->viewportState.mouseFlatTile] + & Map::LogicHelpers::L_WALL_OR_GATEHOUSE) + != 0) { + hoveredGateTile = this->viewportState.mouseFlatTile; + } else if (DAT_TileMapState::instance.BuildingLayer[this->viewportState.mouseFlatTile] <= 0) { + this->viewportState.field_0x48 + = DAT_TileMapState::instance.BuildingWasLayer[this->viewportState.mouseFlatTile]; + } + + orientationBase = 8; + if (DAT_TileMapState::instance.mapOrientation == 0) { + orientationBase = 8; + } else if (DAT_TileMapState::instance.mapOrientation == 6) { + orientationBase = 80408; + } else if (DAT_TileMapState::instance.mapOrientation == 4) { + orientationBase = 160808; + } else if (DAT_TileMapState::instance.mapOrientation == 2) { + orientationBase = 241208; + } + + int zoomDivisor = 1; + if (this->viewportState.isZoomedOutUnk != 0) { + zoomDivisor = 2; + } + + int probeDoubledY = mouseYScreenSpace * 2 + 8; + int probeScreenY = mouseYScreenSpace - 8; + for (int probeOffset = -8; probeOffset < 255; probeOffset++) { + if ((DAT_TileMapState::instance.disableElevationRendering != 0 + || DAT_TileMapState::instance.flatViewToggleValue2 != 0) + && probeOffset != -8) { + break; + } + + int probeIndex; + int probeRowY; + if (this->viewportState.isZoomedOutUnk == 0) { + int probeY = (this->viewportState.viewportY - this->windowY) + 16 + probeScreenY; + int probeX = (this->viewportState.viewportX - this->windowX) + mouseXScreenSpace; + probeRowY = ((this->viewportState.viewportY % 16 - this->windowY) + probeScreenY) & 0xf; + probeIndex = (probeX / 32) + (probeY / 16) * 401 + orientationBase; + } else { + int probeX = ((mouseXScreenSpace * 2 + 160) - this->windowX) + this->viewportState.viewportX; + probeRowY = ((this->viewportState.viewportY % 16 - this->windowY) + probeDoubledY) & 0xf; + int probeY = (this->viewportState.viewportY - this->windowY) + probeDoubledY; + probeIndex = (probeY / 16) * 401 + (probeX / 32) + orientationBase; + } + + int probeQuadrant = DAT_MapRenderDefinedData::instance.field_0xc24[probeRowY][quadrantX]; + if (probeQuadrant == 1) { + probeIndex = probeIndex + 200; + } else if (probeQuadrant == 2) { + probeIndex = probeIndex + 201; + } else if (probeQuadrant == 3) { + probeIndex = probeIndex + 401; + } + + int probeTile = this->screenPointToTileNumber[probeIndex]; + if ((DAT_TileMapState::instance.LogicLayer[probeTile] + & (Map::LogicHelpers::L_BORDER | Map::LogicHelpers::L_BORDER_EDGE)) + != 0) { + break; + } + + int probeBuildingID = DAT_TileMapState::instance.BuildingLayer[probeTile]; + if (probeBuildingID <= 0) { + if ((DAT_TileMapState::instance.LogicLayer[probeTile] & Map::LogicHelpers::L_WALL_OR_GATEHOUSE) != 0) { + if (probeScreenY + - DAT_TileMapState::instance + .heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[probeTile]] + / zoomDivisor + <= mouseYScreenSpace + || DAT_TileMapState::instance.disableElevationRendering != 0 + || DAT_TileMapState::instance.flatViewToggleValue2 != 0) { + hoveredBuildingID = -1; + hoveredGateTile = probeTile; + } + } else if (probeScreenY + - DAT_TileMapState::instance + .heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[probeTile]] + / zoomDivisor + <= mouseYScreenSpace + || DAT_TileMapState::instance.disableElevationRendering != 0 + || DAT_TileMapState::instance.flatViewToggleValue2 != 0) { + this->viewportState.field_0x48 = DAT_TileMapState::instance.BuildingWasLayer[probeTile]; + hoveredBuildingID = -1; + } + } else if (probeBuildingID != this->viewportState.field_0x18 && probeBuildingID != hoveredBuildingID + && probeBuildingID != lastBuildingID) { + if ((probeScreenY + - DAT_GMImageHeaders::instance.imh[DAT_TileMapState::instance.GfxLayer[probeTile]].tileOffset + / zoomDivisor) + - DAT_TileMapState::instance + .heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[probeTile]] + / zoomDivisor + <= mouseYScreenSpace) { + hoveredBuildingID = probeBuildingID; + hoveredGateTile = -1; + } + lastBuildingID = probeBuildingID; + } + + probeDoubledY = probeDoubledY + 2; + probeScreenY = probeScreenY + 1; + } + + this->viewportState.cursorWallTile = 0; + if (hoveredBuildingID != -1) { + BuildingTypeShort hoveredBuildingType + = DAT_BuildingsState::instance.buildings[hoveredBuildingID].buildingType; + if ((hoveredBuildingType == OpenSHC::Map::Buildings::BT_GRANARY + || hoveredBuildingType == OpenSHC::Map::Buildings::BT_ARMORY) + && DAT_BuildingsState::instance.buildings[hoveredBuildingID].buildingIsVisuallyActive != 0) { + this->viewportState.mouseRayBuildingID = hoveredBuildingID; + this->viewportState.mouseRayUnitID = 0; + } + } else if (hoveredGateTile >= 0) { + this->viewportState.mouseRayBuildingID = 0; + this->viewportState.cursorWallTile = hoveredGateTile; + } + + if (this->viewportState.field_0x48 != 0) { + uint textNumInGroup = this->viewportState.field_0x48; + switch (this->viewportState.field_0x48) { + case 86: + textNumInGroup = 74; + break; + case 87: + textNumInGroup = 75; + break; + case 88: + textNumInGroup = 76; + break; + case 89: + textNumInGroup = 77; + break; + case 79: + textNumInGroup = 78; + break; + case 41: + textNumInGroup = 42; + break; + case 42: + textNumInGroup = 44; + break; + } + // set the text also for ruins tooltip: "This was a Round Tower" + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(5, 78, textNumInGroup, 0, 40, -1); + } + + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::computeMouseTileFromScreenPosition, this)( + mouseXScreenSpace, mouseYScreenSpace); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 47b2ecfdf6..6bcc2bcfd6 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -36391,7 +36391,7 @@ SHC_3BB0A8C1_0x004E1F50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004E1FA0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004E2050 | 0.0% | Pending +SHC_3BB0A8C1_0x004E2050 | 39.3% | Walking pointers, reg alloc SHC_3BB0A8C1_0x004E21E0 | 0.0% | Pending @@ -36401,7 +36401,7 @@ SHC_3BB0A8C1_0x004E25A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004E2600 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004E2630 | 0.0% | Pending +SHC_3BB0A8C1_0x004E2630 | 53.5% | Register allocation differs: the ten compares give facingDirection the top benefit (25 against 6 and 5), so it takes ecx, while the original serves it last (esi); reading it after the imageID check orders the code like the original but scores lower SHC_3BB0A8C1_0x004E26D0 | 100.0% | Reimplemented @@ -36503,7 +36503,7 @@ SHC_3BB0A8C1_0x004E3869 | 0.0% | Pending SHC_3BB0A8C1_0x004E3870 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004E3980 | 0.0% | Pending +SHC_3BB0A8C1_0x004E3980 | 63.3% | alloc-only (reg naming) SHC_3BB0A8C1_0x004E46C0 | 0.0% | Pending @@ -36887,7 +36887,7 @@ SHC_3BB0A8C1_0x004E5DD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004E5E20 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004E5ED0 | 0.0% | Pending +SHC_3BB0A8C1_0x004E5ED0 | 85.7% | The original keeps isZoomedOutUnk in ecx across the loop's back edge (read after the call, reused at the loop head), so it does not copy the block after the orientation chain into each arm; a local copy spills instead SHC_3BB0A8C1_0x004E6308 | 0.0% | Pending @@ -36981,13 +36981,13 @@ SHC_3BB0A8C1_0x004E6410 | 0.0% | Pending SHC_3BB0A8C1_0x004E64D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004E66F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004E66F0 | 87.1% | Late tail merge pairs the arms differently: the original folds the someYOffset 100 arms of the zoomed-out chains together and the last 1600x900 arm into the 1600x1200 arm; all arms are still separate and identical at the final pass SHC_3BB0A8C1_0x004E7770 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004E7800 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004E7810 | 0.0% | Pending +SHC_3BB0A8C1_0x004E7810 | 50.6% | alloc-only (reg naming) SHC_3BB0A8C1_0x004E78D0 | 0.0% | Pending @@ -37217,7 +37217,7 @@ SHC_3BB0A8C1_0x004E8429 | 0.0% | Pending SHC_3BB0A8C1_0x004E842A | 0.0% | Pending -SHC_3BB0A8C1_0x004E8430 | 0.0% | Pending +SHC_3BB0A8C1_0x004E8430 | 77.2% | reg alloc: mouseX/mouseY regs SHC_3BB0A8C1_0x004E8BFC | 0.0% | Pending @@ -37341,7 +37341,7 @@ SHC_3BB0A8C1_0x004E8CA0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004E8CC0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004E8CF0 | 0.0% | Pending +SHC_3BB0A8C1_0x004E8CF0 | 41.5% | structure, frame 0x68 vs 0x64 SHC_3BB0A8C1_0x004E9000 | 0.0% | Pending diff --git a/tools/reimplementation-helper/batch/README.md b/tools/reimplementation-helper/batch/README.md index b6e5ef8793..68ce79fe4d 100644 --- a/tools/reimplementation-helper/batch/README.md +++ b/tools/reimplementation-helper/batch/README.md @@ -44,8 +44,11 @@ functions and the traps - is in [../../compiler-internals/finding-mismatches.md] | `diff_anchor.py [--run] [NAME]` | Functions whose struct/loop base anchor differs from the original's (`lea esi, [ecx + 0x367e4]` against a different constant). Every displacement in the function then differs while the opcodes still line up, which reads as allocator noise - it is the whole gap between 83.7% and 61.7% on `processFoodConsumption`. The delta is the distance between the two fields MSVC chose; the decompilation names the original's as the pointer it starts the loop with. | | `diff_lea.py [--run] [NAME]` | `lea reg, [a + b]` on our side where the original has the destructive `add a, b`: `field = snapshotLocal + delta` has to keep the snapshot, `field = field + delta` updates the cached read in place. Drop the local when nothing between the read and the use writes the field - that was `updatePopularity`'s last 6.1%. `RLEA` is the reverse, a local the original keeps and we do not. | | `diff_signed.py [NAME-SUBSTRING]` | Comparisons the original makes signed and we make unsigned (or the reverse): `jg/jge/jl/jle` against our `ja/jae/jb/jbe` over the same `cmp`. Fix it by comparing through `(int)` in the source, not by editing the generated header, and re-run the tool to confirm - one instruction barely moves the percentage. | -| `quick_diff.py FILE.cpp... [-q] [--name FUNCTION]` | Compile one file with `/FA` and diff it against the original function disassembled straight from `_original/` - about 6 seconds, no link and no reccmp, so a dozen source variants can be tried in the time of one build. Handles free functions (the mangled scope is the innermost namespace), x87 operand spellings (`fmulp ST(2), ST(0)` vs `fmulp st(2)`, `__real@` constants) and indexed local-array slots (`_arr$[esp+edi*8+112]`); before those three fixes every floating-point instruction and every local-array element access on our side mismatched and `structural_diff.py` reported duplicates that did not exist. Shows the whole original function, which reccmp's diff does not when ours is shorter. A triage loop: confirm a 1.0 with `reccmp_report.py --run`, and do not trust a *rise* of its ratio below about 0.6 - on a badly matching function difflib rewards a different alignment, and one such "gain" was a 10-point loss in reccmp. | +| `quick_diff.py FILE.cpp... [-q] [-s] [-d] [-r] [-l] [--name FUNCTION] [--runs N \| --sbs [A-B]]` | Compile one file with `/FA` and diff it against the original function disassembled straight from `_original/` - about 6 seconds, no link and no reccmp, so a dozen source variants can be tried in the time of one build. Handles free functions (the mangled scope is the innermost namespace), x87 operand spellings (`fmulp ST(2), ST(0)` vs `fmulp st(2)`, `__real@` constants) and indexed local-array slots (`_arr$[esp+edi*8+112]`); before those three fixes every floating-point instruction and every local-array element access on our side mismatched and `structural_diff.py` reported duplicates that did not exist. Shows the whole original function, which reccmp's diff does not when ours is shorter. A triage loop: confirm a 1.0 with `reccmp_report.py --run`, and do not trust a *rise* of its ratio below about 0.6 - on a badly matching function difflib rewards a different alignment, and one such "gain" was a 10-point loss in reccmp. On a large function whose blocks are still out of order, `-r` diffs with every register replaced by `R` (and prints that ratio as `reg`), `-l` tags each of our lines with its source line, `--runs N` lists only the mismatching runs of at least N instructions with the source lines they cover - the work list for a 3000-instruction function - and `--sbs A-B` prints the two streams side by side for original instructions A..B. | | `quick_gl.py FILE.cpp [CALLEE.cpp...] [-q] [-s]` | `quick_diff.py` for a file in `cmake/compiler-flags-gl.txt`: compiles it with `/GL` and LTCG-links it into a throw-away DLL with the `/GL` objects of the callees it calls through `X_Func::` (found in the build list and the GL list), then diffs the function against the original. quick_diff strips `/GL`, so it cannot show an `ecx`/`edx` kept across a call; this does, in about 6 seconds. Needs a full build first (for the callee objects) and the callees' resolvers enabled (`enable_local_functions.py`). `aiFindBuildingToAttack` reads 0.7027 in quick_diff and 1.0000 here, as in reccmp. | +| `switch_order.py FILE.cpp [--apply [LINE...] \| --tables \| --order LINE V,...]` | Put every switch's case bodies in the order the original compiled them. MSVC emits case bodies in source order, so sorting the original's jump-table targets by address recovers the source order, while Ghidra prints the cases sorted by value. Decodes each `jmp [r*4 + T]` (including the byte-indexed two-level form), matches it to a source switch by case values and body count (so a switch written twice gets one table each), and reorders. Cases that fall through into the next move as one unit, so a reorder cannot change behaviour; a case counts as ending in a jump only if its last *top-level* statement is one - `if (x) { ...; break; }` still falls through. On its own this took `renderGmOverlayBuilding` 37% -> 60%. `--tables` prints the decoded tables; `--order` reorders by hand. | +| `flip_branches.py FILE.cpp [--find] [--apply LINES\|found] [--out F] [--chains]` | Swap if/else arms into the original's layout: `if (A op B) {X} else {Y}` -> `if (A !op B) {Y} else {X}`. MSVC makes the *then* arm the fall-through, Ghidra prints the jump target first, so a decompiled `if ((x & m) == 0) {A} else {B}` was usually `!= 0` with the arms the other way round - flipping every mask test in `renderMap` was worth 4 points. `--find` compiles the file, pairs basic blocks by register-canonical content (the branch itself left out, since a flipped one ends in the inverted jump) and marks each branch whose fall-through and target are exchanged against the original; `--apply found` flips those. Plain `x == 0` tests paid 14 times in 17, so measure: `--out` writes a variant for `quick_styles.py`. `--chains` also offers the head of an else-if chain (`if (!C) { if (D) ... } else {A}`). | +| `orig_emulate.py 0xADDR --this-size N [--arg V] [--dump OFF:COUNT[:i\|h\|b]]` | Run an original function under unicorn on a zeroed `this` and print what it wrote - for table-filling functions, where a match percentage says nothing about whether a rewrite computes the same values. Self-contained code only (no imports, globals as stored in the file); importable as a library. Needs `pip install unicorn`. | | `push_pattern.py FILE.cpp...` | Per call, the argument-push run as `pushes/interleaved` for both sides. A neat run (`0` interleaved) means every argument was already in a register or slot, i.e. the source had a **local**; a mixed run is what writing the expression inline at the call produces. A starred row is a call where the two sides disagree - add the local, or drop it, accordingly. Counts only calls whose set-up it can see, so a differing call *total* means our source has an extra call (a duplicated block), not that the tool failed. | | `perm_decls.py FILE FIRST LAST` | Permute one short run of declarations and keep the order that matches best, scored by `quick_diff.py -s`. Declaration order does **not** decide stack slots - the colorer sorts by reference weight per byte and leaves only *ties* to the order the symbols arrive in, so this pays exactly when two locals of equal weight are declared the wrong way round (`assignSelectionToKey` 95.9% -> 100% from one swapped line) and does nothing otherwise. Run `slot_weight.py` first to see whether the weights tie at all. For initialised declarations the order does decide which *register* each one gets, which is a separate effect worth permuting for. | | `reorder_search.py FILE NAME [--pairs] [--dry]` | Hill-climb the match % by reordering independent statements: permute runs of >=3 by default, or swap every adjacent independent pair with `--pairs`. Builds once per move and reverts anything that does not improve. | @@ -58,7 +61,8 @@ functions and the traps - is in [../../compiler-internals/finding-mismatches.md] | `rank_functions.py [filter] [--top N]` | Rank by source lines x (1 - match), so the big badly-matching functions come first instead of the small ones with a low percentage. | | `scan_dispatch.py [filter]` | Functions whose dispatch form disagrees with the original (jump table on one side, if/else-if chain on the other), and which way to fix each. | | `scan_chains.py [filter] [--min N]` | `if/else if` chains comparing one expression against several constants: the candidates to convert when `scan_dispatch.py` says the original has a table we do not. | -| `quick_styles.py FUNC [-s] [style...]` | `try_styles.py` scored by `quick_diff.py` instead of a build: about a second per variant against roughly half a minute for an incremental build plus a reccmp run, so a dozen source forms cost less than one build cycle. Same variant directory (`build-RelWithDebInfo/batch/variants/FUNC/*.cpp`), same table, same winner-restore; `-s` keeps `[esp + N]` offsets, for declaration order. It never touches the source list or the DLL, so it leaves no stale `diff.json` behind. The score is difflib's ratio, not the reccmp percentage - rank the forms here, then confirm the winner with `reccmp_report.py --run`, and mind `quick_diff`'s warning about ratio rises below about 0.6. | +| `quick_styles.py FUNC [-s] [--rank exact\|reg\|fine] [style...]` | `try_styles.py` scored by `quick_diff.py` instead of a build: about a second per variant against roughly half a minute for an incremental build plus a reccmp run, so a dozen source forms cost less than one build cycle. Same variant directory (`build-RelWithDebInfo/batch/variants/FUNC/*.cpp`), same table, same winner-restore; `-s` keeps `[esp + N]` offsets, for declaration order. It never touches the source list or the DLL, so it leaves no stale `diff.json` behind. The score is difflib's ratio, not the reccmp percentage - rank the forms here, then confirm the winner with `reccmp_report.py --run`, and mind `quick_diff`'s warning about ratio rises below about 0.6. Each row shows three scores - `exact`, `reg` (registers anonymised: the structural part) and `fine` (instructions equal including registers among those `reg` aligned) - and the source as it stands is scored first as `(current)`. On a large function `exact` can fall while reccmp rises, so rank by `reg` or `fine` there. A variant whose code is identical to an earlier row is marked `= row`: that, not a tied score, is the proof that a readability rewrite changed nothing. | +| `make_variants.py FUNC SPEC.py [--keep]` | Write the variants for `quick_styles.py` / `try_styles.py` from a Python file defining `VARIANTS = {name: [(old, new), ...]}`, each applied to the function's current source. A replacement that is not found skips its variant rather than writing one without the change. | | `try_styles.py FUNC [style...]` | Compile and measure several hand-written variants of one function, restore the winner, print the table. Variants live in `build-RelWithDebInfo/batch/variants/FUNC/*.cpp`. | ### Readability passes @@ -70,6 +74,8 @@ it was applied, but none is guaranteed to be -- re-measure after running one. |---|---| | `declare_at_use.py [filter]` | Move the leading declaration block down to each variable's first use, and drop declarations that are never used. Only moves one when the first assignment provably dominates every later use. | | `decast.py [filter]` | Collapse doubled casts, `(int)((int)(x))` -> `(int)(x)`. Skips `(int)((int)X + Y)`, where the inner cast covers one operand and dropping it would move the conversion onto the sum. | +| `dropcast.py [filter] [--apply] [--show]` | Drop the `(int)` casts integral promotion makes redundant: on a short/ushort/char/byte lvalue (a local, a parameter, or a field typed through `this`, a `DAT_X::instance` global or a chain of named fields, read from the generated headers), around a bracketed expression of only int and narrow operands, int literals and `+ - * / %`, and `(uint)` as the whole subscript on a narrow unsigned operand. A pointer field is never narrow, but indexing it gives its element. Code-generation neutral by construction (0 changed instructions over ViewportRenderState); dry run unless `--apply`. Fix a wrong header type first, in its own commit, then run this. | +| `test_dropcast.py` | Cases for `dropcast.py`, including the pointer field an earlier version mistook for its element and the casts that must stay (uint operands, oversized literals, calls, a field name typed differently in two structs, a signed subscript). | | `deparen.py [filter] [--apply]` | Drop redundant brackets from `if`/`while` conditions using C precedence. Keeps the load-bearing ones (`(a \|\| b) && c`, `(x & 7) == 0`, assignments and comma operators inside conditions). Dry run unless `--apply`. | | `test_deparen.py` | Precedence tests for `deparen.py`. Run after touching its table: an earlier version silently rewrote `(a != 0 \|\| b != 0) && (x & 0x100) == 0` into a different expression that still compiled. | | `undiv.py [filter] [--apply]` | Turn MSVC's biased shift for a signed power-of-two division back into a division: `(x + (x >> 0x1f & 7U)) >> 3` -> `x / 8`. Dry run unless `--apply`. Usually a large gain rather than merely neutral: over one namespace it was worth up to 22% on a single function. | diff --git a/tools/reimplementation-helper/batch/common.py b/tools/reimplementation-helper/batch/common.py index 4cec4615b7..e416860d48 100644 --- a/tools/reimplementation-helper/batch/common.py +++ b/tools/reimplementation-helper/batch/common.py @@ -27,6 +27,52 @@ DIFF_JSON = Path("reccmp/dll/diff.json") FUNCTION_RE = re.compile(r"//\s*FUNCTION:\s*STRONGHOLDCRUSADER\s+(0x[0-9A-Fa-f]+)") +ORIGINAL_EXE = Path("_original/Stronghold Crusader.exe") +# ---------------------------------------------------------------- original image + + +class OriginalImage(object): + """The original executable's bytes, addressable by virtual address.""" + + def __init__(self, path=ORIGINAL_EXE): + import struct + self.data = d = Path(path).read_bytes() + pe = struct.unpack_from(")[A-Za-z_]\w*|\[(?:[^\[\]]|\[(?:[^\[\]]|\[[^\[\]]*\])*\])*\])*") +SUBSCRIPTS = re.compile(r"\[(?:[^\[\]]|\[(?:[^\[\]]|\[[^\[\]]*\])*\])*\]") +MEMBER = re.compile(r"\s+([A-Za-z_][\w:]*\s*\**)\s+([A-Za-z_]\w*)\s*(\[[^;]*\])?;\s*//\s*0x") +STRUCT = re.compile(r"\s*(?:typedef\s+)?(?:struct|class)\s+(\w+)\s*(?::[^{]*)?\{") + + +class Types(object): + """Field, typedef and global types, from header texts (all generated headers by default).""" + + def __init__(self, headers=None, globals_=None): + if headers is None: + headers = [common.read_text(h) for h in glob.glob("src/OpenSHC/**/*.hpp", recursive=True)] + if globals_ is None: + globals_ = [common.read_text(h) for h in glob.glob("src/OpenSHC/Globals/*.hpp")] + self.signed = set(NARROW_SIGNED) + self.unsigned = set(NARROW_UNSIGNED) + self.struct_fields = {} + self.field_types = {} + self.globals = {} + for text in headers: + for m in re.finditer(r"typedef\s+(short|ushort|unsigned short|char|byte|uchar)\s+(\w+)\s*;", text): + (self.signed if m.group(1) in ("short", "char") else self.unsigned).add(m.group(2)) + cur = None + for line in text.splitlines(): + m = STRUCT.match(line) + if m: + cur = m.group(1) + self.struct_fields.setdefault(cur, {}) + continue + m = MEMBER.match(line) + if m: + t = re.sub(r"\s+", "", m.group(1)).split("::")[-1] + if m.group(3): + t += "[]" # an array is not an integer, but its element is: see walk() + self.field_types.setdefault(m.group(2), set()).add(t) + if cur: + self.struct_fields[cur][m.group(2)] = t + for text in globals_: + for m in re.finditer(r"MACRO_STRUCT_RESOLVER\(\s*([\w:]+)\s*,[^)]*\)\s*(\w+)\s*;", text): + self.globals[m.group(2)] = m.group(1).split("::")[-1] + + @property + def narrow(self): + return self.signed | self.unsigned + + +def element(t): + """The type an access produces once subscripted: `short[]` and `short*` indexed are a short.""" + if t.endswith("[]"): + return t[:-2] + return t[:-1] if t.endswith("*") else t + + +def local_types(src): + lt = {} + for m in re.finditer(r"^\s+((?:unsigned |signed )?[A-Za-z_][\w:]*)\s+([^;=(){}]+);", src, re.M): + t = m.group(1).split("::")[-1].replace("unsigned short", "ushort") + if t in KEYWORDS: + continue + for name in m.group(2).split(","): + name = name.strip() + if name.startswith("*"): + lt.setdefault(name.lstrip("*"), set()).add(t + "*") + elif re.match(r"^[A-Za-z_]\w*$", name): + lt.setdefault(name, set()).add(t) + elif re.match(r"^[A-Za-z_]\w*\s*\[", name): + lt.setdefault(name.split("[")[0].strip(), set()).add(t + "[]") + for m in re.finditer(r"\b((?:unsigned |signed )?[A-Za-z_][\w:]*)\s*(\*?)\s*(?:const\s+)?([A-Za-z_]\w*)\s*=[^=]", src): + if m.group(1) not in KEYWORDS: + lt.setdefault(m.group(3), set()).add(m.group(1).split("::")[-1] + m.group(2)) + for m in re.finditer(r"[(,]\s*((?:unsigned |signed )?[A-Za-z_][\w:]*)\s*(\*?)\s*([A-Za-z_]\w*)\s*(?=[,)])", src): + if m.group(1) not in KEYWORDS: + lt.setdefault(m.group(3), set()).add(m.group(1).split("::")[-1] + m.group(2)) + return lt + + +class Function(object): + """The type environment of one source file: its `this` class and its locals.""" + + def __init__(self, src, types): + self.types = types + self.locals = local_types(src) + m = re.search(r"FUNCTION: STRONGHOLDCRUSADER[^\n]*\n[^\n(]*?(\w+)::\w+\(", src) + self.this = m.group(1) if m else None + + def walk(self, seg, indexed): + """Types of a member chain resolved from its root, or None. `indexed` says whether the final member + was subscripted, which turns an array field into its element.""" + if seg[0] == "this" and self.this: + cur, rest = self.this, seg[1:] + elif len(seg) >= 2 and seg[1] in ("instance", "ptr"): + cur, rest = self.types.globals.get(seg[0], re.sub(r"^DAT_", "", seg[0])), seg[2:] + else: + return None + t = None + for name in rest: + t = self.types.struct_fields.get(cur, {}).get(name) + if t is None: + return None + cur = element(t).rstrip("*") + if t is None: + return None + return {element(t) if indexed else t} + + def types_of(self, expr): + """Possible types of a postfix chain such as `this->a.b[i]`.""" + e = re.sub(r"\s*(\.|->|::|\[|\])\s*", r"\1", expr) + indexed = e.endswith("]") + e = SUBSCRIPTS.sub("", e) + seg = re.split(r"::|\.|->", e) + if len(seg) == 1: + ts = self.locals.get(seg[0], set()) + return set(element(t) for t in ts) if indexed else ts + walked = self.walk(seg, indexed) + if walked: + return walked + ts = self.types.field_types.get(seg[-1], set()) + return set(element(t) for t in ts) if indexed else ts + + def narrowness(self, expr): + ts = self.types_of(expr) + if not ts: + return None + if ts <= self.types.signed: + return "signed" + if ts <= self.types.unsigned: + return "unsigned" + if ts <= self.types.narrow: + return "mixed" + return None + + def is_int(self, expr): + ts = self.types_of(expr) + return bool(ts) and ts <= INTLIKE + + def int_expression(self, expr): + """True when expr is built only from int/narrow operands, int literals and + - * / % ( ).""" + expr = re.sub(r"\s*(\.|->|::|\[|\])\s*", r"\1", expr) + pos = 0 + while pos < len(expr): + ch = expr[pos] + if ch.isspace() or ch in "+-*/%()": + pos += 1 + continue + m = re.match(r"0[xX][0-9a-fA-F]+|\d+", expr[pos:]) + if m: + lit = m.group(0) + nxt = expr[pos + len(lit):pos + len(lit) + 1] + if nxt and (nxt.isalnum() or nxt in "_."): + return False # a suffix (U, L) or a float + if int(lit, 0) > 0x7fffffff: + return False + pos += len(lit) + continue + if expr.startswith("(int)", pos): + pos += 5 + continue + pm = POSTFIX.match(expr, pos) + if not pm or expr[pm.end():pm.end() + 1] == "(": + return False # not an operand, or a call + ts = self.types_of(pm.group(0)) + if not ts or not ts <= (self.types.narrow | INTLIKE): + return False + pos = pm.end() + return True + + +def match_paren(s, i): + d = 0 + for k in range(i, len(s)): + if s[k] == "(": + d += 1 + elif s[k] == ")": + d -= 1 + if d == 0: + return k + return -1 + + +def process(src, types, show=False): + """(new text, number of casts dropped).""" + fn = Function(src, types) + out, i, n = [], 0, 0 + pat = re.compile(r"\((int|uint)\)\s*") + while True: + m = pat.search(src, i) + if not m: + out.append(src[i:]) + break + start = m.end() + paren = src[start:start + 1] == "(" + pm = POSTFIX.match(src, start + 1 if paren else start) + if not pm or (paren and src[pm.end():pm.end() + 1] != ")") or (not paren and src[pm.end():pm.end() + 1] == "("): + # not a lone lvalue: maybe a whole int expression in brackets + close = match_paren(src, start) if paren else -1 + if m.group(1) == "int" and close > 0 and fn.int_expression(src[start + 1:close]): + inner = src[start + 1:close] + prev = src[:m.start()].rstrip()[-1:] + nxt = src[close + 1:].lstrip()[:1] + # an argument or a bracketed operand needs no brackets of its own + bare = prev in "(," and nxt in ",)" + if show: + print(" E (int)(%s)" % " ".join(inner.split())[:70]) + out.append(src[i:m.start()]) + out.append(inner if bare else "(" + inner + ")") + i = close + 1 + n += 1 + continue + out.append(src[i:m.end()]) + i = m.end() + continue + expr = pm.group(0) + end = pm.end() + (1 if paren else 0) + kind = fn.narrowness(expr) + prev = src[:m.start()].rstrip()[-1:] + whole_subscript = prev == "[" and src[end:].lstrip().startswith("]") + if (m.group(1) == "int" and (kind is not None or fn.is_int(expr))) or \ + (whole_subscript and kind == "unsigned"): + if show: + print(" - %s%s" % (m.group(0), expr)) + out.append(src[i:m.start()]) + out.append(expr) + i = end + n += 1 + else: + out.append(src[i:m.end()]) + i = m.end() + return "".join(out), n + + +def main(): + args = [a for a in sys.argv[1:] if not a.startswith("--")] + path_filter = args[0] if args else "" + apply_ = "--apply" in sys.argv + show = "--show" in sys.argv + types = Types() + total = 0 + for f in common.list_files(): + if path_filter not in f: + continue + old = common.read_text(f).replace("\r\n", "\n") + if show: + print(f) + # repeat: dropping the inner cast of (int)((int)(x)) exposes the outer one + new, n = process(old, types, show) + while True: + new, more = process(new, types, show) + if not more: + break + n += more + if not n: + continue + print("%-52s %d" % (f.rsplit("/", 1)[-1][:-4], n)) + total += n + if apply_: + common.write_text(f, new) + common.format_file(f) + print("%d redundant cast(s) dropped%s" % (total, "" if apply_ else " (dry run, pass --apply)")) + + +if __name__ == "__main__": + main() diff --git a/tools/reimplementation-helper/batch/flip_branches.py b/tools/reimplementation-helper/batch/flip_branches.py new file mode 100644 index 0000000000..1aa082f3e8 --- /dev/null +++ b/tools/reimplementation-helper/batch/flip_branches.py @@ -0,0 +1,336 @@ +"""Swap if/else arms into the order the original laid them out. + +usage: + flip_branches.py FILE.cpp [--chains] list the if/else statements that can be flipped + flip_branches.py FILE.cpp --find [--min-ratio R] ... and mark those the original lays out the other way round + flip_branches.py FILE.cpp --apply LINES [--out F] flip the ifs starting on LINES (`12,40-44`); `found` = every + --find hit. Writes FILE in place unless --out is given. + +MSVC lays out an if/else with the *then* arm as the fall-through after the test and the else arm at the jump +target. Ghidra prints the jump target first, so a decompiled `if ((x & m) == 0) {A} else {B}` was usually +written `if ((x & m) != 0) {B} else {A}`: the same test, compiled the other way round, moving every block +after it. Flipping every mask test in `renderMap` this way was worth 4 points; flipping `x == 0` tests paid +14 times out of 17, so plain comparisons need measuring one by one (`--out` writes a variant for +quick_styles.py) - and `cmp x, 2; jl` still means the source said `x >= 2`, which flipping does not fix. + +A flippable statement is `if (A op B) {..} else {..}` with exactly one comparison (== != < <= > >=) at the top +level of the condition and no && || ?: beside it. Flipping inverts the operator and exchanges the arms, which is +the same program for integers. With `--chains`, the head of an else-if chain is flippable too: +`if (C) {A} else if (D) {B} ...` becomes `if (!C) { if (D) {B} ... } else {A}`, one level deeper. + +`--find` compiles the file (quick_diff.py's /FA path), cuts both sides into basic blocks, pairs our blocks with +the original's by register-canonical content, and reports each conditional branch whose fall-through pairs with +the original's jump target and vice versa. The line printed is the one MSVC attributes the branch to, which for +an if is the line the statement starts on. Block pairing is a heuristic: confirm every flip by measuring. +""" + +import difflib +import os +import re +import sys + +import common + +COMPARE = {"==": "!=", "!=": "==", "<": ">=", ">=": "<", ">": "<=", "<=": ">"} +JCC = {"je", "jne", "jl", "jle", "jg", "jge", "jb", "jbe", "ja", "jae", "js", "jns", "jp", "jnp", "jo", "jno"} + + +# ---------------------------------------------------------------- source side + +def match_paren(s, i): + d = 0 + for k in range(i, len(s)): + if s[k] == "(": + d += 1 + elif s[k] == ")": + d -= 1 + if d == 0: + return k + return -1 + + +def block_end(s, ob): + d = 0 + for i in range(ob, len(s)): + if s[i] == "{": + d += 1 + elif s[i] == "}": + d -= 1 + if d == 0: + return i + return -1 + + +def top_level_compare(cond): + """(lhs, op, rhs) when cond is a single comparison with nothing else at its top level, otherwise None.""" + depth = 0 + found = [] + i = 0 + while i < len(cond): + c = cond[i] + two = cond[i:i + 2] + if c in "([": + depth += 1 + elif c in ")]": + depth -= 1 + elif depth == 0: + if two in ("&&", "||") or c in "?,": + return None + if two in ("<<", ">>", "->"): + i += 3 if cond[i + 2:i + 3] == "=" else 2 + continue + if two in ("==", "!=", "<=", ">="): + found.append((i, two)) + i += 2 + continue + if c in "<>": + found.append((i, c)) + elif c == "=" and cond[i - 1:i] not in "=!<>": + return None # an assignment + i += 1 + if len(found) != 1: + return None + k, op = found[0] + return cond[:k].strip(), op, cond[k + len(op):].strip() + + +def strip_outer(cond): + cond = cond.strip() + while cond.startswith("(") and match_paren(cond, 0) == len(cond) - 1: + cond = cond[1:-1].strip() + return cond + + +class Site(object): + """One flippable `if`: positions in the text and its parts.""" + + def __init__(self, s, start): + self.start = start + self.line = s.count("\n", 0, start) + 1 + self.po = s.index("(", start) + self.pc = match_paren(s, self.po) + self.cond = s[self.po + 1:self.pc] + self.cond_last_line = s.count("\n", 0, self.pc) + 1 + self.compare = top_level_compare(strip_outer(self.cond)) + ws = re.match(r"\s*\{", s[self.pc + 1:]) + self.ok = bool(ws) and self.compare is not None + if not self.ok: + return + self.ob = self.pc + ws.end() + self.cb = block_end(s, self.ob) + rest = s[self.cb + 1:] + el = re.match(r"\s*else\s*\{", rest) + elif_ = re.match(r"\s*else\s+if\s*\(", rest) + if el: + self.kind = "else" + self.eob = self.cb + el.end() + self.ecb = block_end(s, self.eob) + elif elif_: + self.kind = "chain" + self.eob = self.cb + 1 + rest.index("if", elif_.start()) + self.ecb = chain_end(s, self.eob) + else: + self.ok = False + return + lhs, op, rhs = self.compare + self.label = "mask" if re.search(r"[^&]&[^&]", " " + lhs + " ") and rhs == "0" else \ + ("zero" if rhs == "0" else "compare") + + def inverted(self): + lhs, op, rhs = self.compare + return "%s %s %s" % (lhs, COMPARE[op], rhs) + + +def chain_end(s, k): + """End (inclusive) of the else-if chain whose first `if` starts at k.""" + while True: + po = s.index("(", k) + pc = match_paren(s, po) + ob = s.index("{", pc) + cb = block_end(s, ob) + m = re.match(r"\s*else\s*(if\s*\()?", s[cb + 1:]) + if not m: + return cb + if not m.group(1): + return block_end(s, s.index("{", cb + 1)) + k = cb + 1 + m.start(1) + + +def sites(s): + out = [] + for m in re.finditer(r"\bif\s*\(", s): + if re.search(r"\belse\s*$", s[max(0, m.start() - 20):m.start()]): + continue # an else-if link, flipped (if at all) through the head of its chain + site = Site(s, m.start()) + if site.ok: + out.append(site) + return out + + +def flip(s, site): + then_ = s[site.ob + 1:site.cb] + if site.kind == "else": + other = s[site.eob + 1:site.ecb] + new = "if (%s) {%s} else {%s}" % (site.inverted(), other, then_) + return s[:site.start] + new + s[site.ecb + 1:] + chain = s[site.eob:site.ecb + 1] + new = "if (%s) {\n%s\n} else {%s}" % (site.inverted(), chain, then_) + return s[:site.start] + new + s[site.ecb + 1:] + + +def apply_flips(s, lines, chains): + """Flip the sites starting on `lines`, innermost first; each flip re-parses, so nested flips stay valid.""" + MARK = "/*FLIP*/" + todo = [x for x in sites(s) if x.line in lines and (chains or x.kind == "else")] + for x in sorted(todo, key=lambda x: -x.start): + s = s[:x.start] + MARK + s[x.start:] + n = 0 + while MARK in s: + k = s.rindex(MARK) + s = s[:k] + s[k + len(MARK):] + site = Site(s, k) + s = flip(s, site) + n += 1 + return s, n + + +# ---------------------------------------------------------------- finding + +def find_flips(path, min_ratio=0.8): + """[(source line, our branch mnemonic, original block address)] for branches laid out the other way round.""" + sys.argv = [sys.argv[0]] + import quick_diff as qd + a, b = qd.streams(os.path.abspath(path)) + if b is None: + sys.exit("compile failed") + ca, cb = qd.register_canon(a), qd.register_canon(b) + oflow, uflow, lines = list(qd.orig_flow), list(qd.our_flow), list(qd.our_lines) + + def blocks(text, starts, target_of): + bl = [] + for k, t in enumerate(text): + if k in starts or not bl: + bl.append({"k0": k, "ins": []}) + bl[-1]["ins"].append(t) + bl[-1]["k1"] = k + index = {b_["k0"]: n for n, b_ in enumerate(bl)} + for b_ in bl: + k = b_["k1"] + op = text[k].split(" ")[0] + b_["cond"] = op in JCC + b_["fall"] = None if op in ("jmp", "ret") else index.get(k + 1) + t = target_of(k) + b_["tgt"] = index.get(t) if t is not None else None + return bl + + # original: blocks start at branch targets and after branches + addr_index = {addr: k for k, (addr, t) in enumerate(oflow)} + ostarts = set(addr_index[t] for addr, t in oflow if t in addr_index) + ostarts |= set(k + 1 for k, x in enumerate(ca) if x.split(" ")[0] in JCC | {"jmp", "ret"}) + OB = blocks(ca, ostarts, lambda k: addr_index.get(oflow[k][1])) + # ours: blocks start at labels and after branches + label_index = {} + for k, (labels, t) in enumerate(uflow): + for lab in labels: + label_index[lab] = k + ustarts = set(label_index.values()) | set(k + 1 for k, x in enumerate(cb) if x.split(" ")[0] in JCC | {"jmp", "ret"}) + UB = blocks(cb, ustarts, lambda k: label_index.get(uflow[k][1])) + + # a flipped test ends in the inverted jump (jne for je), so compare blocks with the condition left out: + # otherwise every two-instruction test block scores 0.5 against its counterpart and is never paired + def shape(ins): + return ["jcc L" if x.split(" ")[0] in JCC else x for x in ins] + + for b_ in OB + UB: + b_["shape"] = shape(b_["ins"]) + match = {} + for n, ub in enumerate(UB): + if len(ub["ins"]) < 2: + continue + pos = n / float(len(UB)) + best, best_score = None, 0 + for m, ob in enumerate(OB): + if abs(len(ob["ins"]) - len(ub["ins"])) > max(3, len(ub["ins"]) // 2): + continue + r = difflib.SequenceMatcher(None, ub["shape"], ob["shape"], autojunk=False).ratio() + if r < min_ratio: + continue + score = r - 0.3 * abs(pos - m / float(len(OB))) + if score > best_score: + best, best_score = m, score + if best is not None: + match[n] = best + + found = set() + for n, ub in enumerate(UB): + if not ub["cond"] or n not in match: + continue + ob = OB[match[n]] + if not ob["cond"]: + continue + f = match.get(ub["fall"]) if ub["fall"] is not None else None + t = match.get(ub["tgt"]) if ub["tgt"] is not None else None + if f is not None and t is not None and f != t and f == ob["tgt"] and t == ob["fall"]: + found.add((lines[ub["k1"]], cb[ub["k1"]].split(" ")[0], oflow[ob["k0"]][0])) + return sorted(found) + + +# ---------------------------------------------------------------- main + +def parse_lines(spec): + out = set() + for part in spec.split(","): + a, _, b = part.partition("-") + out.update(range(int(a), int(b or a) + 1)) + return out + + +def main(): + argv = sys.argv[1:] + if not argv: + sys.exit(__doc__) + path = common.repo_relative(argv[0]) + chains = "--chains" in argv + src = common.read_text(path).replace("\r\n", "\n") + min_ratio = float(argv[argv.index("--min-ratio") + 1]) if "--min-ratio" in argv else 0.8 + + hits = {} + if "--find" in argv or "found" in argv: + for line, op, addr in find_flips(path, min_ratio): + hits.setdefault(line, (op, addr)) + + def hit_for(site): + for ln in range(site.line, site.cond_last_line + 1): + if ln in hits: + return hits[ln] + return None + + all_sites = [x for x in sites(src) if chains or x.kind == "else"] + if "--apply" not in argv: + for x in all_sites: + h = hit_for(x) + if "--find" in argv and not h: + continue + print("%5d %-7s %-5s if (%s)%s" % (x.line, x.label, x.kind, " ".join(x.cond.split())[:80], + " <- FLIP (orig %08x)" % h[1] if h else "")) + if "--find" in argv: + unplaced = sorted(set(hits) - set(ln for x in all_sites for ln in range(x.line, x.cond_last_line + 1))) + if unplaced: + print("branches laid out the other way round with no flippable if on their line: %s" + % " ".join(map(str, unplaced))) + return + + spec = argv[argv.index("--apply") + 1] + if spec == "found": + lines = set(x.line for x in all_sites if hit_for(x)) + else: + lines = parse_lines(spec) + out, n = apply_flips(src, lines, chains) + dest = str((common.INVOCATION_DIR / argv[argv.index("--out") + 1]).resolve()) if "--out" in argv else path + common.write_text(dest, out) + common.format_file(dest) + print("flipped %d if statement(s) -> %s" % (n, dest)) + + +if __name__ == "__main__": + main() diff --git a/tools/reimplementation-helper/batch/make_variants.py b/tools/reimplementation-helper/batch/make_variants.py new file mode 100644 index 0000000000..4d8d4087bc --- /dev/null +++ b/tools/reimplementation-helper/batch/make_variants.py @@ -0,0 +1,59 @@ +"""Write source variants of one function from a list of text replacements, for quick_styles.py / try_styles.py. + +usage: + make_variants.py FunctionName SPEC.py [--keep] + +SPEC.py is Python that defines + + VARIANTS = { + "flip_mask": [("if ((x & 4) == 0) {", "if ((x & 4) != 0) {"), ...], + "plain_loop": [(old, new), ...], + } + +Each variant applies its (old, new) pairs in order to the function's current source and is written to +build-RelWithDebInfo/batch/variants//.cpp. Every `old` must occur in the text it is +applied to - a missing one skips that variant with a message instead of writing a file that silently lacks +the change. The variant directory is cleared first unless --keep is given (its _original.cpp.bak is kept +either way). Writing the replacements down rather than hand-copying files keeps a dozen variants of a +5000-line function reviewable, and lets a variant be regenerated after the source moves on. +""" + +import sys +from pathlib import Path + +import common + + +def main(): + argv = sys.argv[1:] + if len(argv) < 2: + sys.exit(__doc__) + func, spec = argv[0], common.INVOCATION_DIR / argv[1] + matches = list(Path("src/OpenSHC").rglob(func + ".cpp")) + if len(matches) != 1: + sys.exit("expected exactly one src/OpenSHC/**/%s.cpp, found %d" % (func, len(matches))) + src = common.read_text(matches[0]).replace("\r\n", "\n") + ns = {} + exec(compile(common.read_text(spec), str(spec), "exec"), ns) + + out = common.TMP / "variants" / func + out.mkdir(parents=True, exist_ok=True) + if "--keep" not in argv: + for old in out.glob("*.cpp"): + old.unlink() + written = 0 + for name, reps in ns["VARIANTS"].items(): + text = src + for old, new in reps: + if old not in text: + print("%s: skipped, not found: %r" % (name, old[:70])) + break + text = text.replace(old, new) + else: + common.write_text(out / (name + ".cpp"), text) + written += 1 + print("%d variant(s) in %s" % (written, out)) + + +if __name__ == "__main__": + main() diff --git a/tools/reimplementation-helper/batch/orig_emulate.py b/tools/reimplementation-helper/batch/orig_emulate.py new file mode 100644 index 0000000000..86a2c94918 --- /dev/null +++ b/tools/reimplementation-helper/batch/orig_emulate.py @@ -0,0 +1,84 @@ +"""Run an original function under unicorn and read back what it wrote. + +usage: + orig_emulate.py 0xADDRESS --this-size N [--arg V]... [--dump OFF:COUNT[:i|h|b]]... + +For a function whose job is to fill a table - `setTileSystemMemoryLookupArrays` writes ~1.9 MB of lookup +arrays into `this` - a match percentage says little about whether a rewrite computes the same thing, and +the game has to be run to find out. This maps the original image, gives the function a zeroed `this` of +N bytes in ecx and the given stack arguments, runs it to its return, and prints the requested ranges of +`this` as ints (i), shorts (h) or bytes (b). Compare that against a model of the rewrite in Python, or +against the same ranges written by our DLL. + +Only self-contained code runs this way: the image's globals are as stored in the file, imports are not +resolved, and a call into the CRT or the OS faults. Use it as a library for anything more involved: + + import orig_emulate + uc, this = orig_emulate.run(0x4e2050, 0x19f008) + tiles = orig_emulate.read_ints(uc, this + 0x4e600, 321602) + +Needs `pip install unicorn`. +""" + +import struct +import sys + +import common + + +def load(): + from unicorn import Uc, UC_ARCH_X86, UC_MODE_32 + image = common.original_image() + d = image.data + pe = struct.unpack_from(" 2 else "i" + print("+%#x: %s" % (off, " ".join(str(v) for v in read_ints(uc, this + off, count, fmt)))) + + +if __name__ == "__main__": + main() diff --git a/tools/reimplementation-helper/batch/quick_diff.py b/tools/reimplementation-helper/batch/quick_diff.py index 91428df2ff..f0d51842e3 100644 --- a/tools/reimplementation-helper/batch/quick_diff.py +++ b/tools/reimplementation-helper/batch/quick_diff.py @@ -1,6 +1,6 @@ """Compile ONE source file and diff its code against the original function, in seconds. -usage: quick_diff.py FILE.cpp... [-q] [-s] [-d] [--name FUNCTION] +usage: quick_diff.py FILE.cpp... [-q] [-s] [-d] [-r] [-l] [--name FUNCTION] [--runs N | --sbs [A-B]] Compiles each file with a DLL compile command plus /FA (no link, no reccmp), disassembles the original function at the file's `// FUNCTION:` address straight from `_original/` with capstone, normalizes both streams (globals, @@ -10,6 +10,13 @@ (forward/backward) instead of `L`: a layout where the same block copy exists on both sides but the jumps reach a different one scores 1.0000 without it and ~97% in reccmp. +For a large function whose gap is still structural, register names are noise that hides where the blocks +disagree. `-r` replaces every register with `R` before diffing (and prints that ratio as `reg`), `-l` tags each +of our lines with the source line it came from, `--runs N` lists only the mismatching runs of at least N lines +together with the source lines they cover - the list of places to work on, biggest first in practice - and +`--sbs A-B` prints the aligned streams side by side for original instructions A..B (all of them without a range), +our source line in the last column. All three imply `-r`. + This is a triage loop, not the score: it is stricter than reccmp about register names and looser about stack offsets and constants, so confirm a 1.0000 with `reccmp_report.py --run`. Unlike reccmp it shows the *whole* original function - reccmp cuts the original stream at the length of our function, which hides the original's @@ -20,7 +27,6 @@ import json import os import re -import struct import subprocess import sys @@ -28,15 +34,12 @@ import common -quiet = '-q' in sys.argv +# set by main() (or, for -s / -d / --name, by the command line of a script importing this one, as +# quick_gl.py does); a module importing this one otherwise gets the defaults keep_slots = '-s' in sys.argv keep_direction = '-d' in sys.argv # --name NAME: diff that function of a file holding several `// FUNCTION:` markers (default: the first) -want = sys.argv[sys.argv.index('--name') + 1] if '--name' in sys.argv else None -_skip = {'-q', '-s', '-d', '--name'} | ({want} if want else set()) -files = [os.path.abspath(f) for f in sys.argv[1:] if f not in _skip] -if not files and __name__ == "__main__": - sys.exit(__doc__) +want = sys.argv[sys.argv.index('--name') + 1] if '--name' in sys.argv[:-1] else None ROOT = str(common.ROOT).replace(chr(92), '/') os.chdir(ROOT) ENV = common.build_env() @@ -50,13 +53,19 @@ out = ROOT + '/build-RelWithDebInfo/batch/' + os.environ.get('QD_OUT', 'quick') os.makedirs(out, exist_ok=True) -d = open('_original/Stronghold Crusader.exe', 'rb').read() -pe = struct.unpack_from(' maxtarget and (i.mnemonic in ('int3', 'nop') or i.address % 16 == 0 and i.mnemonic == 'int3'): break if prev in ('ret', 'jmp') and i.address > maxtarget: break s = i.mnemonic + ' ' + i.op_str + target = None if i.mnemonic.startswith('j') or i.mnemonic == 'call': try: t = int(i.op_str, 16) if i.mnemonic != 'call' and va <= t < va + 20000: maxtarget = max(maxtarget, t) + target = t s = i.mnemonic + (' L' if not keep_direction else ' Lf' if t > i.address else ' Lb') else: s = i.mnemonic + ' F' @@ -106,6 +118,7 @@ def orig(va): prev = prev continue res.append(s.strip()) + orig_flow.append((i.address, target)) prev = i.mnemonic return res @@ -137,14 +150,29 @@ def slot(mm): idx = ' + ' + index.replace('*', '*0x') + '' if index else '' idx = re.sub(r'\*0x(\d+)', lambda m: '*' + hex(int(m.group(1))), idx) return '[esp' + idx + (' + ' + hex(v) if v >= 0 else ' - ' + hex(-v)) + ']' + del our_lines[:] + del our_flow[:] + line = 0 + labels = [] for l in m.group(2).splitlines(): + lm = re.match(r';\s*Line\s+(\d+)', l) + if lm: + line = int(lm.group(1)) + continue l = l.split(';')[0].strip() + lab = re.match(r'^(\$\w+@\w+):', l) + if lab: + labels.append(lab.group(1)) + continue if not l or l.endswith(':') or re.match(r'^\w+\$\w* = ', l) or l.startswith('npad') or l.startswith('$') or l.startswith('DD') or l.startswith('DB') or l.startswith('_'): continue l = l.replace('\t', ' ') l = re.sub(r'(\w+\$\w*|tv\d+)\[esp(?:\+(\w+\*\d+))?(?:([+-][0-9a-fA-F]+H|[+-]\d+))?\]', slot, l) op = l.split(' ')[0] + target = None if op.startswith('j') and 'DWORD PTR' not in l: + mt = re.search(r'(\$\w+@\w+)', l) + target = mt.group(1) if mt else None l = op + (' L' if '$' in l else ' F') elif op == 'call': l = 'call F' @@ -177,6 +205,9 @@ def slot(mm): l = re.sub(r'^imul (\w+), (0x[0-9a-f]+|-?\d+)$', r'imul \1, \1, \2', l) l = re.sub(r'^lea (\w+), dword ptr ', r'lea \1, ', l) res.append(l.strip()) + our_lines.append(line) + our_flow.append((labels, target)) + labels = [] return res @@ -217,17 +248,105 @@ def streams(f): return [canon(x) for x in orig(va)], (None if b is None else [canon(x) for x in b]) +def register_canon(lines): + return [REGISTER_RE.sub('R', x) for x in lines] + + +def mismatch_runs(a, b, lines, min_size): + """(op, orig range, ours range, source line range) for every non-equal run of at least min_size lines.""" + sm = difflib.SequenceMatcher(None, a, b, autojunk=False) + for op, i1, i2, j1, j2 in sm.get_opcodes(): + if op == 'equal' or (i2 - i1) + (j2 - j1) < min_size: + continue + src = sorted(set(l for l in lines[j1:j2] if l)) + if src: + where = '%d-%d' % (src[0], src[-1]) + else: + # nothing of ours here: name the line our code continues with + where = 'near %d' % (lines[min(j1, len(lines) - 1)] if lines else 0) + yield op, (i1, i2), (j1, j2), where + + +def side_by_side(a_raw, b_raw, a, b, lines, first, last): + sm = difflib.SequenceMatcher(None, a, b, autojunk=False) + for op, i1, i2, j1, j2 in sm.get_opcodes(): + if i2 < first or i1 > last: + continue + for k in range(max(i2 - i1, j2 - j1)): + x = a_raw[i1 + k] if i1 + k < i2 else '' + y = b_raw[j1 + k] if j1 + k < j2 else '' + ln = lines[j1 + k] if j1 + k < j2 else '' + print('%-44s %s %-44s %s' % (x[:44], ' ' if op == 'equal' else '|', y[:44], ln)) + + def main(): + global keep_slots, keep_direction, want + argv = sys.argv[1:] + runs = sbs = None + want = None + if '--name' in argv: + k = argv.index('--name') + want = argv[k + 1] + del argv[k:k + 2] + if '--runs' in argv: + k = argv.index('--runs') + runs = int(argv[k + 1]) + del argv[k:k + 2] + if '--sbs' in argv: + k = argv.index('--sbs') + sbs = (0, 1 << 30) + if k + 1 < len(argv) and re.match(r'^\d+-\d+$', argv[k + 1]): + sbs = tuple(int(x) for x in argv[k + 1].split('-')) + del argv[k + 1] + del argv[k] + flags = set(x for x in argv if x.startswith('-')) + quiet = '-q' in flags + keep_slots = '-s' in flags + keep_direction = '-d' in flags + tag_lines = '-l' in flags + reg = '-r' in flags or tag_lines or runs is not None or sbs is not None + files = [os.path.abspath(f) for f in argv if not f.startswith('-')] + if not files: + sys.exit(__doc__) for f in files: a, b = streams(f) if b is None: continue ratio = difflib.SequenceMatcher(None, a, b, autojunk=False).ratio() - print('##### %s ratio %.4f orig %d ours %d' % (os.path.basename(f), ratio, len(a), len(b))) - if not quiet: - for l in difflib.unified_diff(a, b, lineterm='', n=2): - if not l.startswith(('---', '+++')): - print(l) + head = '##### %s ratio %.4f' % (os.path.basename(f), ratio) + ca, cb = a, b + if reg: + ca, cb = register_canon(a), register_canon(b) + head += ' reg %.4f' % difflib.SequenceMatcher(None, ca, cb, autojunk=False).ratio() + print(head + ' orig %d ours %d' % (len(a), len(b))) + lines = list(our_lines) + if runs is not None: + for op, (i1, i2), (j1, j2), where in mismatch_runs(ca, cb, lines, runs): + print('%-7s orig %5d-%-5d ours %5d-%-5d src %s' % (op, i1, i2, j1, j2, where)) + elif sbs is not None: + side_by_side(a, b, ca, cb, lines, sbs[0], sbs[1]) + elif not tag_lines: + if not quiet: + for l in difflib.unified_diff(ca, cb, lineterm='', n=2): + if not l.startswith(('---', '+++')): + print(l) + elif not quiet: + # diff the untagged lines (a tag would stop every moved line from matching), print tagged ones + shown = ['%-40s @%d' % (x, n) for x, n in zip(cb, lines)] + sm = difflib.SequenceMatcher(None, ca, cb, autojunk=False) + for group in sm.get_grouped_opcodes(2): + i1, j1 = group[0][1], group[0][3] + i2, j2 = group[-1][2], group[-1][4] + print('@@ -%d,%d +%d,%d @@' % (i1 + 1, i2 - i1, j1 + 1, j2 - j1)) + for op, a1, a2, b1, b2 in group: + if op == 'equal': + for x in ca[a1:a2]: + print(' ' + x) + continue + for x in ca[a1:a2]: + print('-' + x) + for x in shown[b1:b2]: + print('+' + x) if __name__ == '__main__': diff --git a/tools/reimplementation-helper/batch/quick_styles.py b/tools/reimplementation-helper/batch/quick_styles.py index be2ac35fc4..07f5e4af87 100644 --- a/tools/reimplementation-helper/batch/quick_styles.py +++ b/tools/reimplementation-helper/batch/quick_styles.py @@ -7,51 +7,68 @@ Put each complete .cpp in build-RelWithDebInfo/batch/variants//