From 786e39ff52297778ff05efda18e799d7e8332909 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 7 Nov 2026 14:07:45 +0100 Subject: [PATCH 01/28] types: Moat tile is int, x/y and fillProgress are signed The original reads tile as a dword (main's own UpgradeMapLogicToVersion_Unknown3 already does *(uint*)&moats[i].tile), x and y with movsx, and tests fillProgress signed (test al, al; jg / cmp dl, 4; jl). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- src/OpenSHC/Map/Moat.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/OpenSHC/Map/Moat.hpp b/src/OpenSHC/Map/Moat.hpp index a676966a90..7cfea8fffa 100644 --- a/src/OpenSHC/Map/Moat.hpp +++ b/src/OpenSHC/Map/Moat.hpp @@ -15,14 +15,13 @@ namespace Map { // SIZE: 0x00000010 typedef struct Moat { - ushort tile; // 0x00000000 length: 2 - undefined1 padding_0x2[2]; // 0x00000002 length: 2 - undefined2 x; // 0x00000004 length: 2 - undefined2 y; // 0x00000006 length: 2 + int tile; // 0x00000000 length: 4 + short x; // 0x00000004 length: 2 + short y; // 0x00000006 length: 2 short zeroOrTwo; // 0x00000008 length: 2 undefined1 padding_0xa[2]; // 0x0000000A length: 2 char owner; // 0x0000000C length: 1 - byte fillProgress; // 0x0000000D length: 1 + char fillProgress; // 0x0000000D length: 1 byte stage; // 0x0000000E length: 1 char someCountDown; // 0x0000000F length: 1 From c6eb340821b6f8ab9b7829e714e676a471fa0564 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 7 Nov 2026 14:07:45 +0100 Subject: [PATCH 02/28] types: Rock::x and Rock::y are short applyRockGraphicsToFootprint reads both with movsx. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- src/OpenSHC/Map/Rocks/Rock.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Rocks/Rock.hpp b/src/OpenSHC/Map/Rocks/Rock.hpp index df8dd97a21..13def74be7 100644 --- a/src/OpenSHC/Map/Rocks/Rock.hpp +++ b/src/OpenSHC/Map/Rocks/Rock.hpp @@ -22,8 +22,8 @@ namespace Map { short one; // 0x0000000C length: 2 short unknownGMID; // 0x0000000E length: 2 short type; // 0x00000010 length: 2 - ushort x; // 0x00000012 length: 2 - ushort y; // 0x00000014 length: 2 + short x; // 0x00000012 length: 2 + short y; // 0x00000014 length: 2 short size; // 0x00000016 length: 2 short orientation; // 0x00000018 length: 2 undefined1 padding_0x1a[6]; // 0x0000001A length: 6 From 57ad68af229d3d4bbe7a5635e1285357952981b7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 7 Nov 2026 14:07:46 +0100 Subject: [PATCH 03/28] types: Unit field_0x83 is a byte field, not padding triggerLoweredView clears it next to heightDiv10. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- src/OpenSHC/Map/Units/Unit.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/Map/Units/Unit.hpp b/src/OpenSHC/Map/Units/Unit.hpp index 1d8ab3103c..94585f49bd 100644 --- a/src/OpenSHC/Map/Units/Unit.hpp +++ b/src/OpenSHC/Map/Units/Unit.hpp @@ -81,7 +81,7 @@ namespace Map { short gmIDUnk; // 0x0000007E length: 2 short displayColorPlayerID; // 0x00000080 length: 2 undefined1 heightDiv10; // 0x00000082 length: 1 - undefined1 padding_0x83[1]; // 0x00000083 length: 1 + undefined1 field_0x83; // 0x00000083 length: 1 short field_0x84; // 0x00000084 length: 2 short field_0x86; // 0x00000086 length: 2 short field_0x88; // 0x00000088 length: 2 From db8c482eee3e4f4e696c52433e3b04006e75047e Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 7 Nov 2026 14:08:02 +0100 Subject: [PATCH 04/28] types: TileMapState counters and flags are signed, MacroLayer is short maxPitchDitchCount, temporaryTerrainTypeIndex, SEC_Section1052..1054, the forceUpdate flags and buildingMin/MaxHeight are compared signed in the original; MacroLayer is read with movsx everywhere; mapping40x40 holds char; the dword at 0x5548D0 is a field (setupAllMapSections clears it), not padding. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- src/OpenSHC/Map/TileMapState.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState.hpp b/src/OpenSHC/Map/TileMapState.hpp index 80bedcbab0..0c58fdc654 100644 --- a/src/OpenSHC/Map/TileMapState.hpp +++ b/src/OpenSHC/Map/TileMapState.hpp @@ -65,7 +65,7 @@ namespace Map { uchar ShowHiLayer[80400]; // 0x002EE270 length: 80400 short MiscDisplayLayer[80400]; // 0x00301C80 length: 160800 char DamageLayer[80400]; // 0x003290A0 length: 80400 - ushort MacroLayer[80400]; // 0x0033CAB0 length: 160800 + short MacroLayer[80400]; // 0x0033CAB0 length: 160800 ushort PathConnectionLayer[80400]; // 0x00363ED0 length: 160800 uchar PathLinkageLayer[80400]; // 0x0038B2F0 length: 80400 uchar OccupancyLayer[80400]; // 0x0039ED00 length: 80400 @@ -80,7 +80,7 @@ namespace Map { undefined4 someLimit; // 0x00500224 length: 4 undefined4 someYLike; // 0x00500228 length: 4 undefined4 someYLikeLimit; // 0x0050022C length: 4 - byte mapping40x40[40][40]; // 0x00500230 length: 1600 + char mapping40x40[40][40]; // 0x00500230 length: 1600 Moat moats[16000]; // 0x00500870 length: 256000 int currentMoatCount; // 0x0053F070 length: 4 undefined4 moatTileCount; // 0x0053F074 length: 4 @@ -88,19 +88,19 @@ namespace Map { undefined4 ALG_MoatYResult; // 0x0053F07C length: 4 int someMoatTile; // 0x0053F080 length: 4 PitchDitch pitchDitches[4000]; // 0x0053F084 length: 80000 - undefined4 maxPitchDitchCount; // 0x00552904 length: 4 + int maxPitchDitchCount; // 0x00552904 length: 4 undefined1 padding_0x552908[4]; // 0x00552908 length: 4 short specialAreasArray[8]; // 0x0055290C length: 16 - undefined4 temporaryTerrainTypeIndex; // 0x0055291C length: 4 - undefined4 SEC_Section1052; // 0x00552920 length: 4 - undefined4 SEC_Section1053; // 0x00552924 length: 4 - undefined4 SEC_Section1054; // 0x00552928 length: 4 + int temporaryTerrainTypeIndex; // 0x0055291C length: 4 + int SEC_Section1052; // 0x00552920 length: 4 + int SEC_Section1053; // 0x00552924 length: 4 + int SEC_Section1054; // 0x00552928 length: 4 int temporaryTerrainTypeArray[1000]; // 0x0055292C length: 4000 int temporaryTerrainTypeBinaryArray[1000]; // 0x005538CC length: 4000 undefined4 forceUpdateLogicalAndMiscDisplayLayers; // 0x0055486C length: 4 - undefined4 forceUpdateTextureTilemap; // 0x00554870 length: 4 - undefined4 forceUpdateGFXLayers; // 0x00554874 length: 4 - undefined4 forceUpdateMacroLayerFlag; // 0x00554878 length: 4 + int forceUpdateTextureTilemap; // 0x00554870 length: 4 + int forceUpdateGFXLayers; // 0x00554874 length: 4 + int forceUpdateMacroLayerFlag; // 0x00554878 length: 4 undefined4 field_0x55487c; // 0x0055487C length: 4 undefined1 padding_0x554880[8]; // 0x00554880 length: 8 undefined4 placedBuildingID; // 0x00554888 length: 4 @@ -121,7 +121,7 @@ namespace Map { undefined4 refreshRelatedOne; // 0x005548C4 length: 4 undefined4 disableElevationRendering; // 0x005548C8 length: 4 undefined4 flatViewToggleValue1; // 0x005548CC length: 4 - undefined1 padding_0x5548d0[4]; // 0x005548D0 length: 4 + undefined4 field_0x5548d0; // 0x005548D0 length: 4 undefined4 flatViewToggleValue2; // 0x005548D4 length: 4 undefined4 refreshRelatedTwo; // 0x005548D8 length: 4 int savedEditorActiveBrush; // 0x005548DC length: 4 @@ -156,8 +156,8 @@ namespace Map { undefined4 buildingSpriteID2; // 0x00554950 length: 4 undefined4 cursorTargetID; // 0x00554954 length: 4 undefined4 buildingHeightLimit; // 0x00554958 length: 4 - undefined4 buildingMinHeight; // 0x0055495C length: 4 - undefined4 buildingMaxHeight; // 0x00554960 length: 4 + int buildingMinHeight; // 0x0055495C length: 4 + int buildingMaxHeight; // 0x00554960 length: 4 undefined4 buildingMaxHeightDifference; // 0x00554964 length: 4 undefined4 buildingPlacementProperty_3; // 0x00554968 length: 4 undefined4 buildingPlacementProperty_4; // 0x0055496C length: 4 From b882e31c2aa2441a840abe2a8c415c3ffbfef6b1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 7 Nov 2026 14:08:03 +0100 Subject: [PATCH 05/28] types: validateWallPlacementAtTile takes the mapper command as short The original compares it as a word; with the short type its reimplementation reaches 100% (from 81%). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- src/OpenSHC/Map/TileMapState.func.hpp | 2 +- src/OpenSHC/Map/TileMapState.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState.func.hpp b/src/OpenSHC/Map/TileMapState.func.hpp index 164412bdca..03df972cf4 100644 --- a/src/OpenSHC/Map/TileMapState.func.hpp +++ b/src/OpenSHC/Map/TileMapState.func.hpp @@ -162,7 +162,7 @@ namespace Map { void (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004F93E0, &TileMapState::destroyWallsOfPlayer) destroyWallsOfPlayer; - MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, uint, uint, MappersEnum), false, + MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, uint, uint, short), false, Address::SHC_3BB0A8C1_0x004F94A0, &TileMapState::validateWallPlacementAtTile) validateWallPlacementAtTile; diff --git a/src/OpenSHC/Map/TileMapState.hpp b/src/OpenSHC/Map/TileMapState.hpp index 0c58fdc654..585698dcd5 100644 --- a/src/OpenSHC/Map/TileMapState.hpp +++ b/src/OpenSHC/Map/TileMapState.hpp @@ -312,7 +312,7 @@ namespace Map { void destroyWallsOfPlayer(int playerID); - void validateWallPlacementAtTile(int playerID, uint x, uint y, MappersEnum param_4); + void validateWallPlacementAtTile(int playerID, uint x, uint y, short param_4); void setupBuildingSizeIndexMappingForBuildingWithSize(int buildingSize); From 04af9b18661184f6f5a773a5d4df3b079e171b44 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 7 Nov 2026 14:08:30 +0100 Subject: [PATCH 06/28] Reimplement 88 Map::TileMapState functions at 100% From reimpl/TileMapState: every function that measures 100% there (raw or normalized, i.e. only call targets differ), and again 100% in a trial build of this branch with the data and function resolvers enabled. - 88 sources in src/OpenSHC/Map/TileMapState/ (the 17 already on main are unchanged), with their status lines set to 100.0% Reimplemented - cmake/compiler-flags-gl.txt: the 16 of them whose original keeps this in ecx across an already finished callee (getBuildingSizeIndexMappingData, setSignpostDistanceForCampaignMission, ...); /GL plus the enabled callee is what reproduces that, without it they measure 40-65% Behaviour fixes carried over: spawnEraserTileEffect no longer clears L_BUILDING (the original mask is ~0x410b00), setupAllMapSections calls the empty 0x469F10 with UnitsState/LandscapeState in ecx as the original does, placeDefensiveStructureTile has its missing M_MAPPER_STAIR5 arm. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- cmake/compiler-flags-gl.txt | 16 ++ .../TileMapState/Constructor_TileMapState.cpp | 66 ++++++ .../TileMapState/advanceMoatDigProgress.cpp | 45 ++++ .../applyRockGraphicsToFootprint.cpp | 59 +++++ .../Map/TileMapState/changeMapOrientation.cpp | 57 +++++ .../clearBuildingDisplayFlagsAndEntities.cpp | 34 +++ ...arBuildingFootprintAndRemoveSiegeTower.cpp | 49 ++++ .../clearBuildingFootprintAndResetUnits.cpp | 59 +++++ .../clearBuildingFootprintWithEdgeRubble.cpp | 53 +++++ .../TileMapState/clearBuildingFromTerrain.cpp | 121 ++++++++++ .../clearBuildingTilesAndTrees.cpp | 49 ++++ .../Map/TileMapState/clearDrawBridgeWater.cpp | 35 +++ .../clearFixedSizeTwoBuildingFootprint.cpp | 42 ++++ .../TileMapState/clearInvalidMoatEntries.cpp | 30 +++ src/OpenSHC/Map/TileMapState/clearMoat.cpp | 26 ++ .../Map/TileMapState/clearMoatDataAtTile.cpp | 23 ++ .../collectCliffEdgeTilesForClimbData.cpp | 60 +++++ .../TileMapState/computeClimbRampRotation.cpp | 90 +++++++ .../computeTileAlongAxisOffset.cpp | 28 +++ .../computeWallCornerRenderRotation.cpp | 85 +++++++ .../countLogicPropertyInSurroundingTiles.cpp | 25 ++ .../countMoatsOwnedByEachPlayer.cpp | 29 +++ .../countUnfinishedMoatTilesForPlayer.cpp | 22 ++ .../TileMapState/countUnownedPitchDitches.cpp | 19 ++ .../Map/TileMapState/createMoatData.cpp | 64 +++++ .../Map/TileMapState/destroyPitchDitch.cpp | 36 +++ .../Map/TileMapState/destroyWallsOfPlayer.cpp | 56 +++++ .../findNearestValidDigTileNearTarget.cpp | 76 ++++++ ...TileInSameAreaAndNoTooHeightDifference.cpp | 27 +++ .../Map/TileMapState/getBuildingHurtSFXID.cpp | 57 +++++ .../getBuildingSizeForCommandBuildingType.cpp | 223 ++++++++++++++++++ .../getBuildingSizeIndexMappingData.cpp | 35 +++ .../getCastleBuildRangeForMapSize.cpp | 25 ++ .../getMaxWallHeightInBrushArea.cpp | 36 +++ ...NonFarmFieldBuildingHealthAtTileOr1000.cpp | 48 ++++ ...tOrientationThatIsWallTowerOrGatehouse.cpp | 38 +++ .../TileMapState/getPitchDitchIDForTile.cpp | 18 ++ .../getRubbleGraphicStageForDamageLevel.cpp | 73 ++++++ .../Map/TileMapState/getTileForBrush.cpp | 61 +++++ .../Map/TileMapState/getTotalHeightAtTile.cpp | 38 +++ .../getWallFlagForOrientedDirection.cpp | 37 +++ .../hasHigherNeighborWithStairs.cpp | 35 +++ ...HigherPlainNeighborWithWallOrGatehouse.cpp | 44 ++++ .../hasOnlyTowerNeighborsNoWalls.cpp | 49 ++++ .../increaseHeightForTunnelSingleTile.cpp | 48 ++++ .../increaseHeightForTunnelWithBrush.cpp | 57 +++++ .../TileMapState/isCliffDropInDirection.cpp | 15 ++ .../TileMapState/isFootprintIndexOnEdge.cpp | 29 +++ .../TileMapState/isTileEnclosedByWalls.cpp | 32 +++ .../isTileEnclosedByWallsOrGates.cpp | 41 ++++ .../isWallConnectionHeightValid.cpp | 61 +++++ .../isWallCornerForCardinalDirection.cpp | 54 +++++ .../isWallCornerForDiagonalDirection.cpp | 50 ++++ .../markBuildingFootprintFlag.cpp | 26 ++ src/OpenSHC/Map/TileMapState/noop1.cpp | 10 + .../placeDefensiveStructureTile.cpp | 125 ++++++++++ src/OpenSHC/Map/TileMapState/planMoat.cpp | 62 +++++ .../rebuildShowHiLayerFromHeights.cpp | 24 ++ src/OpenSHC/Map/TileMapState/removeMoat.cpp | 43 ++++ .../resetAreaBasedOnLogicalLayer.cpp | 67 ++++++ .../TileMapState/resetHeightAndMapBorders.cpp | 107 +++++++++ .../TileMapState/resetTileAndClearMoat.cpp | 60 +++++ .../TileMapState/resetTileToDefaultState.cpp | 31 +++ .../TileMapState/returnMoatIDForPlayerIDs.cpp | 18 ++ .../TileMapState/returnOwnedMoatAtTile.cpp | 18 ++ .../rotateFearFactorBuildingVariations.cpp | 96 ++++++++ ...etChangedLayerToThreeAndMapping0x40x40.cpp | 24 ++ src/OpenSHC/Map/TileMapState/setMapSize.cpp | 22 ++ .../setSignpostDistanceForCampaignMission.cpp | 41 ++++ .../Map/TileMapState/setupAllMapSections.cpp | 145 ++++++++++++ .../setupBuildingSizeIndexMapping.cpp | 26 ++ .../TileMapState/setupLogicalMapBorders.cpp | 43 ++++ .../Map/TileMapState/setupTileMapSections.cpp | 84 +++++++ .../TileMapState/spawnEraserTileEffect.cpp | 61 +++++ .../storeMinAndMaxHeightOfArea.cpp | 43 ++++ .../Map/TileMapState/swapMoatOwnership.cpp | 22 ++ .../Map/TileMapState/swapPitchOwnership.cpp | 22 ++ .../Map/TileMapState/swapWallOwnership.cpp | 58 +++++ .../Map/TileMapState/triggerLoweredView.cpp | 61 +++++ .../unmarkBuildingFootprintFlag.cpp | 25 ++ .../updateAreaBasedOnSurrounding.cpp | 31 +++ .../TileMapState/updateGameRelatedValue.cpp | 37 +++ .../Map/TileMapState/updateMacroLayer.cpp | 38 +++ .../updatePathLinkagesForBuilding.cpp | 76 ++++++ .../Map/TileMapState/updatePitchDitches.cpp | 78 ++++++ .../updateShowHiLayerOrResetChangedLayer.cpp | 88 +++++++ .../upgradeMapFormatLogicLayer.cpp | 44 ++++ .../validateBuildingPlacementAtTile.cpp | 64 +++++ .../validateWallPlacementAtTile.cpp | 71 ++++++ status/addresses-SHC-3BB0A8C1.txt | 176 +++++++------- 90 files changed, 4564 insertions(+), 88 deletions(-) create mode 100644 src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp create mode 100644 src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp create mode 100644 src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp create mode 100644 src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearInvalidMoatEntries.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearMoat.cpp create mode 100644 src/OpenSHC/Map/TileMapState/clearMoatDataAtTile.cpp create mode 100644 src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp create mode 100644 src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp create mode 100644 src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp create mode 100644 src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp create mode 100644 src/OpenSHC/Map/TileMapState/countLogicPropertyInSurroundingTiles.cpp create mode 100644 src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp create mode 100644 src/OpenSHC/Map/TileMapState/countUnfinishedMoatTilesForPlayer.cpp create mode 100644 src/OpenSHC/Map/TileMapState/countUnownedPitchDitches.cpp create mode 100644 src/OpenSHC/Map/TileMapState/createMoatData.cpp create mode 100644 src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp create mode 100644 src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp create mode 100644 src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp create mode 100644 src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getNonFarmFieldBuildingHealthAtTileOr1000.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getPitchDitchIDForTile.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getTileForBrush.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp create mode 100644 src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp create mode 100644 src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp create mode 100644 src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp create mode 100644 src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp create mode 100644 src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp create mode 100644 src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp create mode 100644 src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp create mode 100644 src/OpenSHC/Map/TileMapState/isFootprintIndexOnEdge.cpp create mode 100644 src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp create mode 100644 src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp create mode 100644 src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp create mode 100644 src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp create mode 100644 src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp create mode 100644 src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp create mode 100644 src/OpenSHC/Map/TileMapState/noop1.cpp create mode 100644 src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp create mode 100644 src/OpenSHC/Map/TileMapState/planMoat.cpp create mode 100644 src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp create mode 100644 src/OpenSHC/Map/TileMapState/removeMoat.cpp create mode 100644 src/OpenSHC/Map/TileMapState/resetAreaBasedOnLogicalLayer.cpp create mode 100644 src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp create mode 100644 src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp create mode 100644 src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp create mode 100644 src/OpenSHC/Map/TileMapState/returnMoatIDForPlayerIDs.cpp create mode 100644 src/OpenSHC/Map/TileMapState/returnOwnedMoatAtTile.cpp create mode 100644 src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp create mode 100644 src/OpenSHC/Map/TileMapState/setChangedLayerToThreeAndMapping0x40x40.cpp create mode 100644 src/OpenSHC/Map/TileMapState/setMapSize.cpp create mode 100644 src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp create mode 100644 src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp create mode 100644 src/OpenSHC/Map/TileMapState/setupBuildingSizeIndexMapping.cpp create mode 100644 src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp create mode 100644 src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp create mode 100644 src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp create mode 100644 src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp create mode 100644 src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp create mode 100644 src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp create mode 100644 src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp create mode 100644 src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp create mode 100644 src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp create mode 100644 src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp create mode 100644 src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp create mode 100644 src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp create mode 100644 src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp create mode 100644 src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp create mode 100644 src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp create mode 100644 src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp create mode 100644 src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp create mode 100644 src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 7a4a662301..a4434f8bc7 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -115,3 +115,19 @@ src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAn src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_GatehouseOpenClose.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_WorkshopWeaponSelection.cpp src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface.cpp +src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp +src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp +src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp +src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp +src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp +src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp +src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp +src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp +src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp +src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp +src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp +src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp +src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp +src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp +src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp diff --git a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp new file mode 100644 index 0000000000..5d024cc05f --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp @@ -0,0 +1,66 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Commands::MappersEnum; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00515F40 + TileMapState* TileMapState::Constructor_TileMapState() + { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupMovementDirectionTranslationMatrix, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMapping, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupTileMapSections, this)(); + this->editorActiveBrush = 7; + this->refreshCertainTileMap = 2; + this->counter1 = 0; + this->mapperMax = FALSE; + this->editorSnapToMode = 0; + this->editorAffectType = 0; + this->unknownZero_0x554900 = 0; + this->currentMapperCommand = OpenSHC::Commands::M_MAPPER_NULL; + this->refreshRelatedOne = 1; + this->disableElevationRendering = 0; + this->refreshRelatedTwo = 0; + this->forceUpdateLogicalAndMiscDisplayLayers = 1; + this->forceUpdateTextureTilemap = 1; + this->forceUpdateGFXLayers = 1; + this->refreshCertainTileMap_old = 4; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); + this->moatTileCount = 0; + this->skipPlacementCheck = 0; + this->gateOrientationVariant = 0x50; + this->lastTime = timeGetTime(); + this->rockOrientation = 0; + this->editorRockType = 0; + this->cursorAnimationTime = timeGetTime(); + this->cursorOverlayAnimationFrame = 1; + this->temporaryTerrainTypeIndex = 0; + this->skipPlacementFailChecks = 0; + DAT_GameCore::instance.isTimeHalted = FALSE; + DAT_GameState::instance.mapAndTime.skirmishFogOfWar = 0; + this->ptr_LogicLayer = this->LogicLayer; + this->ptr_TerrainTypeTileMap = this->Logic2Layer; + this->ptr_TerrainHeightTileMap = this->HeightLayer; + this->ptr_ChangedLayer = this->ChangedLayer; + this->ptr_OccupancyLayer = this->OccupancyLayer; + this->ptr_DamageLayer = this->DamageLayer; + this->ptr_PathConnectionLayer = this->PathConnectionLayer; + this->ptr_MovementDirectionTranslationMatrix = this; + this->ptr_SpecialAreasArray = this->specialAreasArray; + this->ptr_AIZoneLayer = this->AIZoneLayer; + this->ptr_MiscDisplayLayer = this->MiscDisplayLayer; + this->currentMoatCount = 16000; + this->maxPitchDitchCount = 4000; + return this; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp b/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp new file mode 100644 index 0000000000..c4237ebe31 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp @@ -0,0 +1,45 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" + +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + + // FUNCTION: STRONGHOLDCRUSADER 0x00500500 + BOOLEnum TileMapState::advanceMoatDigProgress(int moatID) + { + this->moats[moatID].fillProgress = this->moats[moatID].fillProgress + 1; + // nested form: the original keeps the FALSE return as the trailing block + if (this->moats[moatID].fillProgress >= 4) { + int tile = this->moats[moatID].tile; + this->moats[moatID].someCountDown = 0; + this->moats[moatID].fillProgress = 4; + this->moats[moatID].stage = 2; + this->HeightLayer[tile] = 0; + this->LogicLayer[this->moats[moatID].tile] + = this->LogicLayer[this->moats[moatID].tile] & ~L_MOAT_DUG_OR_PLANNED; + this->LogicLayer[this->moats[moatID].tile] + = this->LogicLayer[this->moats[moatID].tile] & ~L_PLAIN2_AND_PITCH; + this->LogicLayer[this->moats[moatID].tile] = this->LogicLayer[this->moats[moatID].tile] | L_MOAT; + this->Logic2Layer[this->moats[moatID].tile] = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(2, this->moats[moatID].x, this->moats[moatID].y); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(this->moats[moatID].y, this->moats[moatID].tile); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::triggerMinimapRedraw, DAT_MinimapViewState::ptr)(1); + return 1; + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp new file mode 100644 index 0000000000..8fac0d7958 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp @@ -0,0 +1,59 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/LandscapeState.func.hpp" + +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FB770 + void TileMapState::applyRockGraphicsToFootprint(int rockID) + { + int rockX = DAT_LandscapeState::instance.rocks[rockID].x; + int rockY = DAT_LandscapeState::instance.rocks[rockID].y; + int orientation = DAT_LandscapeState::instance.rocks[rockID].orientation + this->mapOrientation; + int index = 0; + if (orientation >= 8) { + orientation = orientation - 8; + } + int size = DAT_LandscapeState::instance.rocks[rockID].size; + int surface = (orientation / 2) * size * size; + + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, DAT_LandscapeState::instance.rocks[rockID].size); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + rockY].addXgetTile + rockX + + this->buildingX; + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { + if (this->disableElevationRendering == 0) { + this->GfxLayer[tile] + = ((short)GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] + + (short)DAT_LandscapeState::instance.rocks[rockID].gfx + + (short)this->buildingRotationRelatedValue + surface) + - 1; + } else if (DAT_LandscapeState::instance.rocks[rockID].size == 1) { + this->GfxLayer[tile] + = ((short)GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] + + (short)DAT_LandscapeState::instance.rocks[rockID].gfx + + (short)this->buildingRotationRelatedValue + surface) + - 1; + } else { + this->GfxLayer[tile] + = (short)MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::getRandomRockImageOffset, + DAT_LandscapeState::ptr)(((byte)DAT_TileMapState::instance.RandomLayer[tile] & 3) + 1) + + (short)GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] + + surface - 1; + } + } + index++; + } while (index < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp b/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp new file mode 100644 index 0000000000..b80e8a4ab2 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp @@ -0,0 +1,57 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00501B90 + void TileMapState::changeMapOrientation(int mapOrientation) + { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::saveFocusTileAndCenterPreview, + DAT_ViewportRenderState::ptr)(); + DAT_TileMapState::instance.mapOrientation = mapOrientation; + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::restoreFocusTile, DAT_ViewportRenderState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::forceFullTileMapRedraw, this)(); + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::refreshAllBuildingTileDisplays, DAT_BuildingsState::ptr)(); + DAT_BuildingsState::instance.field_0x10 = 5; + switch (this->mapOrientation) { + case 0: + this->screenSouthEastDirection = 3; + this->orientedRowStep = 1; + this->screenEastDirection = 2; + this->screenSouthDirection = 4; + this->screenSouthWestDirection = 5; + return; + case 2: + this->screenSouthEastDirection = 5; + this->orientedRowStep = 1; + this->screenEastDirection = 4; + this->screenSouthDirection = 6; + this->screenSouthWestDirection = 7; + return; + case 4: + this->screenSouthEastDirection = 7; + this->screenEastDirection = 6; + this->screenSouthDirection = 0; + this->screenSouthWestDirection = 1; + this->orientedRowStep = -1; + return; + case 6: + this->screenSouthEastDirection = 1; + this->screenEastDirection = 0; + this->screenSouthDirection = 2; + this->screenSouthWestDirection = 3; + this->orientedRowStep = -1; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp new file mode 100644 index 0000000000..71140eb177 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp @@ -0,0 +1,34 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004FB360 + void TileMapState::clearBuildingDisplayFlagsAndEntities(int buildingID, int param_2) + { + int buildingSizeTileIndex = 0; + int buildingX = DAT_BuildingsState::instance.buildings[buildingID].x; + int buildingY = DAT_BuildingsState::instance.buildings[buildingID].y; + uint widthOrHeight = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, widthOrHeight); + int tileUnk = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + buildingY].addXgetTile + + this->buildingX + buildingX; + this->MiscDisplayLayer[tileUnk] &= ~0xc; + if (param_2 == 1) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tileUnk); + } + buildingSizeTileIndex++; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp new file mode 100644 index 0000000000..c7a71edab2 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp @@ -0,0 +1,49 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Map::Units::UnitType; + using OpenSHC::Map::Units::States::UnitState; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FAC70 + void TileMapState::clearBuildingFootprintAndRemoveSiegeTower(int x, int y, int size) + { + int tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, size); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->LogicLayer[tile] = this->LogicLayer[tile] + & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk + | L_KEEP_NON_MANOR_HOUSE); + this->BuildingLayer[tile] = 0; + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)( + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile], tile); + int unitID = this->UnitLayer[tile]; + if (unitID != 0 && DAT_UnitsState::instance.units[unitID].unitType == OpenSHC::Map::Units::UT_S_TOWER) { + DAT_UnitsState::instance.units[unitID].state.generic = OpenSHC::Map::Units::States::US_DISAPPEAR; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp new file mode 100644 index 0000000000..244dbcbeb5 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp @@ -0,0 +1,59 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FAB70 + void TileMapState::clearBuildingFootprintAndResetUnits(int x, int y, int size) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, size); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->LogicLayer[tile] = this->LogicLayer[tile] + & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk + | L_KEEP_NON_MANOR_HOUSE); + if ((this->MiscDisplayLayer[tile] & 0x20) != 0) { + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xffdf; + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + } + int buildingID = this->BuildingLayer[tile]; + this->BuildingLayer[tile] = 0; + if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { + this->BuildingWasLayer[tile] = 0; + } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isFootprintIndexOnEdge, this)( + buildingSizeTileIndex, size) + != FALSE) { + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x2000; + } else { + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x4000; + } + for (int unitID = this->UnitLayer[tile]; unitID != 0; + unitID = DAT_UnitsState::instance.units[unitID].nextUnitOnTheSameTile) { + DAT_UnitsState::instance.units[unitID].vanish = 0; + DAT_UnitsState::instance.units[unitID].unknownCountdown_0x402 = 0; + } + buildingSizeTileIndex++; + this->ChangedLayer[tile] = 2; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp new file mode 100644 index 0000000000..f285e422e5 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp @@ -0,0 +1,53 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FAD70 + void TileMapState::clearBuildingFootprintWithEdgeRubble(int x, int y, int size) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, size); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->LogicLayer[tile] = this->LogicLayer[tile] + & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk + | L_KEEP_NON_MANOR_HOUSE); + if ((this->MiscDisplayLayer[tile] & 0x20) != 0) { + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xffdf; + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + } + int buildingID = this->BuildingLayer[tile]; + this->BuildingLayer[tile] = 0; + if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { + this->BuildingWasLayer[tile] = 0; + } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isFootprintIndexOnEdge, this)( + buildingSizeTileIndex, size) + != FALSE) { + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x2000; + } else { + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x4000; + } + buildingSizeTileIndex++; + this->ChangedLayer[tile] = 2; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp new file mode 100644 index 0000000000..ba5792665e --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp @@ -0,0 +1,121 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00515A20 + void TileMapState::clearBuildingFromTerrain(int buildingID) + { + uint x = (short)DAT_BuildingsState::instance.buildings[buildingID].x; + uint y = (short)DAT_BuildingsState::instance.buildings[buildingID].y; + uint size = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType != OpenSHC::Map::Buildings::BT_KILLINGPIT) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateBuildingPlacementAtTile, this)( + DAT_BuildingsState::instance.buildings[buildingID].owner, x, y); + if (this->buildingPlacementFail != FALSE) { + return; + } + } + + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType == OpenSHC::Map::Buildings::BT_STOCKPILE) { + if (DAT_BuildingsState::instance.buildings[buildingID].field_0x190 == 1) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearStockpileFootprintTiles, this)(x, y); + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearFixedSizeTwoBuildingFootprint, this)(x, y); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, size); + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_WHEATFARM) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintAndResetUnits, this)(x, y, size); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( + buildingID, 1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingTilesAndTrees, this)(buildingID, 36); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::unmarkBuildingFootprintFlag, this)(x, y, 9); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, 9); + size = 6; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_HOPFARM) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintAndResetUnits, this)(x, y, size); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( + buildingID, 1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingTilesAndTrees, this)(buildingID, 24); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::unmarkBuildingFootprintFlag, this)(x, y, 9); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, 9); + size = 6; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_DAIRYFARM) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintAndResetUnits, this)(x, y, size); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( + buildingID, 1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingTilesAndTrees, this)(buildingID, 0x1b); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::unmarkBuildingFootprintFlag, this)(x, y, 10); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, 10); + size = 6; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_APPLEFARM) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintAndResetUnits, this)(x, y, size); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( + buildingID, 1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingTilesAndTrees, this)(buildingID, 8); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::unmarkBuildingFootprintFlag, this)(x, y, 0xb); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, 0xb); + size = 6; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_DRAWBRIDGE) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearSizeFiveBuildingFootprintAndMoats, this)(x, y); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( + buildingID, 1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, size); + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_CATAPULT + || DAT_BuildingsState::instance.buildings[buildingID].buildingType == OpenSHC::Map::Buildings::BT_TREBUCHET + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_BATTERINGRAM + || DAT_BuildingsState::instance.buildings[buildingID].buildingType == OpenSHC::Map::Buildings::BT_SIEGETOWER + || DAT_BuildingsState::instance.buildings[buildingID].buildingType == OpenSHC::Map::Buildings::BT_SHIELD + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_FIREBALLISTA) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintWithEdgeRubble, this)(x, y, size); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( + buildingID, 1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, size); + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintAndRemoveSiegeTower, this)( + x, y, size); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintAndResetUnits, this)(x, y, size); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( + buildingID, 1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, size); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintAndResetUnits, this)(x, y, size); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( + buildingID, 1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, size); + } + + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(size + 6, x, y); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_TileMapState::instance.field_0x554a30 = 1; + MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::triggerMinimapRedraw, DAT_MinimapViewState::ptr)(1); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp new file mode 100644 index 0000000000..8287496ae6 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp @@ -0,0 +1,49 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + using namespace OpenSHC::Map::LogicHelpers; // L_* flags + using OpenSHC::Map::Buildings::Building; + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_APPLE; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_DAIRY; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_HOP; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_WHEAT; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FAAB0 + void TileMapState::clearBuildingTilesAndTrees(int buildingID, int surfaceArea) + { + for (int i = 0; i < surfaceArea; i++) { + int tileUnk = DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i]; + if ((this->LogicLayer[tileUnk] & L_FARM_FIELD_APPLE) != 0) { + int treeID = this->OrganismLayer[tileUnk]; + if (treeID != 0 && treeID < 2000) { + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeTree, DAT_LandscapeState::ptr)(treeID); + } + } + this->LogicLayer[tileUnk] = this->LogicLayer[tileUnk] + & ~(L_BUILDING | L_FARM_FIELD_WHEAT | L_FARM_FIELD_HOP | L_FARM_FIELD_APPLE | L_FARM_FIELD_DAIRY); + this->DamageLayer[tileUnk] = 0; + this->BuildingLayer[tileUnk] = 0; + if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { + this->BuildingWasLayer[tileUnk] = 0; + } + this->ChangedLayer[tileUnk] = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)( + (int)DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tileUnk], tileUnk); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp new file mode 100644 index 0000000000..4f2356f8d3 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp @@ -0,0 +1,35 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_MOAT; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508870 + void TileMapState::clearDrawBridgeWater(int x, int y) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, 5); + int targetedTile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->LogicLayer[targetedTile] = this->LogicLayer[targetedTile] & ~L_MOAT; + this->HeightLayer[targetedTile] = 8; + uint moatID = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, this)(targetedTile); + if (moatID != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatData, this)(moatID); + this->LogicLayer[targetedTile] = this->LogicLayer[targetedTile] & ~L_MOAT; + this->BuildingWasLayer[targetedTile] = 0; + } + this->BuildingLayer[targetedTile] = 0; + buildingSizeTileIndex++; + this->BuildingWasLayer[targetedTile] = 0; + this->ChangedLayer[targetedTile] = 2; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp new file mode 100644 index 0000000000..83bda1493f --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp @@ -0,0 +1,42 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FAE50 + void TileMapState::clearFixedSizeTwoBuildingFootprint(int x, int y) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, 2); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->LogicLayer[tile] = this->LogicLayer[tile] + & ~(L_STOCKPILEUnk | L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk + | L_KEEP_NON_MANOR_HOUSE); + int buildingID = this->BuildingLayer[tile]; + this->BuildingLayer[tile] = 0; + if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { + this->BuildingWasLayer[tile] = 0; + } else { + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x4000; + } + buildingSizeTileIndex++; + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearInvalidMoatEntries.cpp b/src/OpenSHC/Map/TileMapState/clearInvalidMoatEntries.cpp new file mode 100644 index 0000000000..9387b69c7f --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearInvalidMoatEntries.cpp @@ -0,0 +1,30 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; + + // FUNCTION: STRONGHOLDCRUSADER 0x005006C0 + void TileMapState::clearInvalidMoatEntries() + { + for (int moatID = 1; moatID < this->currentMoatCount; moatID++) { + if (this->moats[moatID].owner == 0) { + continue; + } + int tile = this->moats[moatID].tile; + if ((DAT_TileMapState::instance.LogicLayer[tile] & (L_MOAT_DUG_OR_PLANNED | L_MOAT)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatData, this)(moatID); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearMoat.cpp b/src/OpenSHC/Map/TileMapState/clearMoat.cpp new file mode 100644 index 0000000000..e2d8ae0c07 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearMoat.cpp @@ -0,0 +1,26 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; + + // FUNCTION: STRONGHOLDCRUSADER 0x005005F0 + void TileMapState::clearMoat(int tile) + { + if ((this->LogicLayer[tile] & L_MOAT_DUG_OR_PLANNED) == 0) { + return; + } + + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)(tile + - DAT_ViewportRenderState::instance + .translationMatrix[DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]] + .addXgetTile, + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]); + this->LogicLayer[tile] = this->LogicLayer[tile] & ~L_MOAT_DUG_OR_PLANNED; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearMoatDataAtTile.cpp b/src/OpenSHC/Map/TileMapState/clearMoatDataAtTile.cpp new file mode 100644 index 0000000000..79c5839089 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearMoatDataAtTile.cpp @@ -0,0 +1,23 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500310 + void TileMapState::clearMoatDataAtTile(int x, int y) + { + for (int moatID = 0; moatID < this->currentMoatCount; moatID++) { + if (this->moats[moatID].x == x && this->moats[moatID].y == y) { + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(Moat), 0, &this->moats[moatID]); + this->moatTileCount = this->moatTileCount - 1; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp new file mode 100644 index 0000000000..aa1eab944e --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp @@ -0,0 +1,60 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_ClimbLogicDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L2_OASIS_GRASS; + using OpenSHC::Map::LogicHelpers::L2_PLATEAU_HIGH; + using OpenSHC::Map::LogicHelpers::L2_STONES_OR_DRIVEN_SANDUnk; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_SEA; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FC340 + void TileMapState::collectCliffEdgeTilesForClimbData() + { + this->temporaryTerrainTypeIndex = 0; + for (int tile = 0; tile < 80400; tile++) { + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + continue; + } + + if ((this->LogicLayer[tile] & L_RIVER) != 0 + && (this->Logic2Layer[tile] & L2_STONES_OR_DRIVEN_SANDUnk) != 0) { + this->temporaryTerrainTypeBinaryArray[this->temporaryTerrainTypeIndex] = 1; + this->temporaryTerrainTypeArray[this->temporaryTerrainTypeIndex] = tile; + int const row = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int const height = this->HeightLayer[tile]; + for (int index = 0; index < 8; index++) { + int neighbour + = this->directionTranslationMatrix[row][DAT_ClimbLogicDefinedData::instance.field_0x2c[index]] + + tile; + if ((this->LogicLayer[neighbour] & L_RIVER) != 0 && this->HeightLayer[neighbour] > height + 0x50) { + this->temporaryTerrainTypeBinaryArray[this->temporaryTerrainTypeIndex] = 0; + break; + } + } + this->temporaryTerrainTypeIndex = this->temporaryTerrainTypeIndex + 1; + if ((int)this->temporaryTerrainTypeIndex >= 1000) { + return; + } + } + + if (((this->LogicLayer[tile] & L_RIVER) != 0 && (this->Logic2Layer[tile] & L2_OASIS_GRASS) != 0) + || ((this->LogicLayer[tile] & L_SEA) != 0 && (this->Logic2Layer[tile] & L2_PLATEAU_HIGH) != 0)) { + this->temporaryTerrainTypeBinaryArray[this->temporaryTerrainTypeIndex] = 1; + this->temporaryTerrainTypeArray[this->temporaryTerrainTypeIndex] = tile; + this->temporaryTerrainTypeIndex = this->temporaryTerrainTypeIndex + 1; + if ((int)this->temporaryTerrainTypeIndex >= 1000) { + return; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp new file mode 100644 index 0000000000..4eaad9373e --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp @@ -0,0 +1,90 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FC810 + int TileMapState::computeClimbRampRotation(int tileUnk, uint x, uint y) + { + int high; + if ((this->LogicLayer[tileUnk] & L_WALL_OR_GATEHOUSE) != 0) { + high = this->DefaultHeightLayer[tileUnk]; + } else { + high = this->HeightLayer[tileUnk]; + } + + int neighbour = this->directionTranslationMatrix[y][this->screenSouthDirection] + tileUnk; + int heightAt86; + if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0) { + heightAt86 = this->DefaultHeightLayer[neighbour]; + } else { + heightAt86 = this->HeightLayer[neighbour]; + } + + neighbour = this->directionTranslationMatrix[y][this->screenEastDirection] + tileUnk; + int heightAt85; + if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0) { + heightAt85 = this->DefaultHeightLayer[neighbour]; + } else { + heightAt85 = this->HeightLayer[neighbour]; + } + + neighbour = this->directionTranslationMatrix[y][this->screenSouthEastDirection] + tileUnk; + int heightAt84; + if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0) { + heightAt84 = this->DefaultHeightLayer[neighbour]; + } else { + heightAt84 = this->HeightLayer[neighbour]; + } + + uint rotation; + if (high > heightAt86 + 0x14 && heightAt86 < 0x88) { + if (high > heightAt85 + 0x14 && heightAt85 < 0x88) { + if (high > heightAt84 + 0x14 && heightAt84 < 0x88) { + rotation = 5; + } else { + rotation = 3; + } + } else { + rotation = 1; + } + } else if (high > heightAt85 + 0x14 && heightAt85 < 0x88) { + if (high > heightAt86 + 0x14 && heightAt86 < 0x88) { + rotation = 3; + } else { + rotation = 2; + } + } else if (heightAt86 < 0x88 || heightAt85 < 0x88) { + /* 0 when the tileUnk is not high enough above its neighbour, 5 when it is */ + rotation = (high <= heightAt84 + 0x14) - 1 & 5; + } else { + rotation = 4; + } + + if (this->mapOrientation == 0) { + if (rotation == 1) { + this->wallCornerRotation = 0x20 - (x & 0x1f); + } else { + this->wallCornerRotation = 0x20 - (y & 0x1f); + } + } else if (this->mapOrientation == 4) { + if (rotation == 1) { + this->wallCornerRotation = (x & 0x1f) + 1; + } else { + this->wallCornerRotation = (y & 0x1f) + 1; + } + } else if (this->mapOrientation == 2) { + this->wallCornerRotation = (y & 0x1f) + 1; + } else { + this->wallCornerRotation = 0x20 - (y & 0x1f); + } + if ((int)this->wallCornerRotation > 0x1f) { + this->wallCornerRotation = 1; + } + return rotation; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp new file mode 100644 index 0000000000..d7e8f0a46e --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp @@ -0,0 +1,28 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500B50 + int TileMapState::computeTileAlongAxisOffset(int tileUnk, int addend, uint offset) + { + int yStep = 1; + int direction = 4; + int y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tileUnk]; + if ((int)offset < 0) { + yStep = -1; + direction = 0; + } + + int count = abs((int)offset); + for (int i = 0; i < count; i++) { + tileUnk = tileUnk + this->directionTranslationMatrix[y][direction]; + y = y + yStep; + } + return tileUnk + addend; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp new file mode 100644 index 0000000000..83e92d2f92 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp @@ -0,0 +1,85 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FC650 + int TileMapState::computeWallCornerRenderRotation(uint x) + { + int tileUnk = this->DAT_SomeTile; + int y = this->DAT_SomeY; + int result = 0; + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)(tileUnk, y, 2) + != FALSE) { + if (this->mapOrientation == 0) { + if ((x & 0xf) == 0xf) { + result = 2; + } else { + result = 0x11 - (x & 0xf); + } + } else if (this->mapOrientation == 4) { + if ((x & 0xf) == 0) { + result = 2; + } else { + result = (x & 0xf) + 2; + } + } else if (this->mapOrientation == 2) { + if ((x & 0xf) == 0) { + result = 1; + } else { + result = (x & 0xf) + 0x11; + } + } else if (this->mapOrientation == 6) { + if ((x & 0xf) == 0xf) { + result = 1; + } else { + result = 0x20 - (x & 0xf); + } + } + } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)(tileUnk, y, 0) + != FALSE) { + if (this->mapOrientation == 0) { + if ((y & 0xf) == 0xf) { + result = 1; + } else { + result = 0x20 - (y & 0xf); + } + } else if (this->mapOrientation == 4) { + if ((y & 0xf) == 0) { + result = 1; + } else { + result = (y & 0xf) + 0x11; + } + } else if (this->mapOrientation == 6) { + if ((y & 0xf) == 0) { + result = 2; + } else { + result = (y & 0xf) + 2; + } + } else if (this->mapOrientation == 2) { + if ((y & 0xf) == 0xf) { + result = 2; + } else { + result = 0x11 - (y & 0xf); + } + } + } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( + tileUnk, y, 2) + != 0) { + result = 48; + } else { + /* 0x3f when the other direction carries a wall too, 0x21 when it does not */ + result = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( + tileUnk, y, 4) + != 0 + ? 0x3f + : 0x21; + } + return result; + } +} +} diff --git a/src/OpenSHC/Map/TileMapState/countLogicPropertyInSurroundingTiles.cpp b/src/OpenSHC/Map/TileMapState/countLogicPropertyInSurroundingTiles.cpp new file mode 100644 index 0000000000..95f8d15a0f --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/countLogicPropertyInSurroundingTiles.cpp @@ -0,0 +1,25 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8530 + void TileMapState::countLogicPropertyInSurroundingTiles(int tile, int y, uint logic1) + { + this->DAT_CardinalTilesAroundTile = 0; + if ((this->LogicLayer[this->directionTranslationMatrix[y][0] + tile] & logic1) != 0) { + this->DAT_CardinalTilesAroundTile++; + } + if ((this->LogicLayer[this->directionTranslationMatrix[y][2] + tile] & logic1) != 0) { + this->DAT_CardinalTilesAroundTile++; + } + if ((this->LogicLayer[this->directionTranslationMatrix[y][4] + tile] & logic1) != 0) { + this->DAT_CardinalTilesAroundTile++; + } + if ((this->LogicLayer[this->directionTranslationMatrix[y][6] + tile] & logic1) != 0) { + this->DAT_CardinalTilesAroundTile++; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp b/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp new file mode 100644 index 0000000000..94f3ca4c46 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp @@ -0,0 +1,29 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x005000E0 + void TileMapState::countMoatsOwnedByEachPlayer() + { + DAT_GameState::instance.playerDataArray[1].moatsOwned = 0; + DAT_GameState::instance.playerDataArray[2].moatsOwned = 0; + DAT_GameState::instance.playerDataArray[3].moatsOwned = 0; + DAT_GameState::instance.playerDataArray[4].moatsOwned = 0; + DAT_GameState::instance.playerDataArray[5].moatsOwned = 0; + DAT_GameState::instance.playerDataArray[6].moatsOwned = 0; + DAT_GameState::instance.playerDataArray[7].moatsOwned = 0; + DAT_GameState::instance.playerDataArray[8].moatsOwned = 0; + for (int moatID = 1; moatID < 16000; moatID++) { + char const owner = this->moats[moatID].owner; + if (owner != 0) { + int const ownerIndex = owner; + DAT_GameState::instance.playerDataArray[ownerIndex].moatsOwned++; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/countUnfinishedMoatTilesForPlayer.cpp b/src/OpenSHC/Map/TileMapState/countUnfinishedMoatTilesForPlayer.cpp new file mode 100644 index 0000000000..94d1f7836b --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/countUnfinishedMoatTilesForPlayer.cpp @@ -0,0 +1,22 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_MOAT; + + // FUNCTION: STRONGHOLDCRUSADER 0x00500180 + int TileMapState::countUnfinishedMoatTilesForPlayer(int playerID) + { + int unfinishedMoatTiles = 0; + for (int moatID = 1; moatID < 16000; moatID++) { + if (this->moats[moatID].owner != 0 && this->moats[moatID].owner == playerID + && (this->LogicLayer[this->moats[moatID].tile] & L_MOAT) == 0) { + unfinishedMoatTiles++; + } + } + return unfinishedMoatTiles; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/countUnownedPitchDitches.cpp b/src/OpenSHC/Map/TileMapState/countUnownedPitchDitches.cpp new file mode 100644 index 0000000000..018ebbd565 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/countUnownedPitchDitches.cpp @@ -0,0 +1,19 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500800 + int TileMapState::countUnownedPitchDitches() + { + int unownedPitchDitches = 0; + for (int pitchDitchID = 0; pitchDitchID < 4000; pitchDitchID++) { + if (this->pitchDitches[pitchDitchID].owner == 0) { + unownedPitchDitches++; + } + } + return unownedPitchDitches; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/createMoatData.cpp b/src/OpenSHC/Map/TileMapState/createMoatData.cpp new file mode 100644 index 0000000000..30042c5d4d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/createMoatData.cpp @@ -0,0 +1,64 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Game::GameMode2; + + // FUNCTION: STRONGHOLDCRUSADER 0x005110B0 + int TileMapState::createMoatData(undefined4 playerID, uint x, uint y, int filled) + { + if (x > 399 || y > 399) { + return 0; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { + return 0; + } + + int existingMoatID = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, this)( + DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x); + if (existingMoatID != 0) { + return existingMoatID; + } + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT + && MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::hasEnoughGoldForMoat, DAT_BuildingsState::ptr)() + == 0) { + return 0; + } + + for (int moatID = 1; moatID < 16000; moatID++) { + if (this->moats[moatID].owner != 0) { + continue; + } + + if (moatID >= this->currentMoatCount) { + this->currentMoatCount = moatID + 1; + } + this->moats[moatID].owner = (char)playerID; + this->moats[moatID].x = (short)x; + this->moats[moatID].y = (short)y; + this->moats[moatID].tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + this->moats[moatID].zeroOrTwo = 2; + if (filled != 0) { + this->moats[moatID].stage = 2; + this->moats[moatID].fillProgress = 4; + } else { + this->moats[moatID].stage = 1; + this->moats[moatID].fillProgress = 0; + } + this->moatTileCount = this->moatTileCount + 1; + return moatID; + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp b/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp new file mode 100644 index 0000000000..d046dd4219 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp @@ -0,0 +1,36 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00500890 + void TileMapState::destroyPitchDitch(int pitchDitchID) + { + this->LogicLayer[this->pitchDitches[pitchDitchID].tile] + = this->LogicLayer[this->pitchDitches[pitchDitchID].tile] & ~L_PLAIN2_AND_PITCH; + this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] + = this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] & ~0x2000; + this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] + = this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] & ~0x4000; + if ((this->LogicLayer[this->pitchDitches[pitchDitchID].tile] & L_WALL_OR_GATEHOUSE) == 0 + && this->BuildingLayer[this->pitchDitches[pitchDitchID].tile] == 0) { + this->HeightLayer[this->pitchDitches[pitchDitchID].tile] + = this->DefaultHeightLayer[this->pitchDitches[pitchDitchID].tile]; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(4, this->pitchDitches[pitchDitchID].x, this->pitchDitches[pitchDitchID].y); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(PitchDitch), 0, &this->pitchDitches[pitchDitchID]); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp new file mode 100644 index 0000000000..3dd177442d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp @@ -0,0 +1,56 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F93E0 + void TileMapState::destroyWallsOfPlayer(int playerID) + { + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { + continue; + } + if ((this->WallOwnerLayer[tile] & 7) + 1 != playerID) { + continue; + } + + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)( + tile); + this->LogicLayer[tile] = this->LogicLayer[tile] + & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + this->DamageLayer[tile] = 0; + uint y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_TileMapState::instance.field_0x554a30 = 1; + int x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(y, tile); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(7, x, y); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp new file mode 100644 index 0000000000..06ab5e34a7 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -0,0 +1,76 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500980 + BOOLEnum TileMapState::findNearestValidDigTileNearTarget(uint x1, uint y1, uint x2, uint y2) + { + if (x1 > 399 || y1 > 399) { + return 0; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y1 * 400 + x1] == 0) { + return 0; + } + if (x2 > 399 || y2 > 399 || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y2 * 400 + x2] == 0) { + return 0; + } + + int area = (short)this + ->PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[y1].addXgetTile + x1]; + int targetTile = DAT_ViewportRenderState::instance.translationMatrix[y2].addXgetTile + x2; + int bestDistance = 10000; + int bestIndex = -1; + uint targetHeight = this->HeightLayer[targetTile]; + int targetBuildingID = this->BuildingLayer[targetTile]; + if (targetBuildingID != 0) { + targetHeight = targetHeight + + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(targetBuildingID); + } + + for (int index = 0; index < 4; index++) { + int fromXPosition = DAT_TerrainDefinedData::instance.field_0x378c[index].x + x2; + int fromYPosition = DAT_TerrainDefinedData::instance.field_0x378c[index].y + y2; + int tile = DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile + fromXPosition; + if ((short)this->PathConnectionLayer[tile] != area) { + continue; + } + uint height = this->HeightLayer[tile]; + int buildingID = this->BuildingLayer[tile]; + if (buildingID != 0) { + height = height + + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID); + } + if ((int)height >= (int)(targetHeight + 0x10) || (int)height <= (int)(targetHeight - 0x10)) { + continue; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(x1, y1, fromXPosition, fromYPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < bestDistance) { + bestDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + bestIndex = index; + } + } + + if (bestIndex <= -1) { + this->field_0x5549a8 = x2; + this->field_0x5549ac = y2; + return 0; + } + this->field_0x5549a8 = DAT_TerrainDefinedData::instance.field_0x378c[bestIndex].x + x2; + this->field_0x5549ac = DAT_TerrainDefinedData::instance.field_0x378c[bestIndex].y + y2; + return 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp b/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp new file mode 100644 index 0000000000..1fb3dd439d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp @@ -0,0 +1,27 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00500370 + BOOLEnum TileMapState::findTileInSameAreaAndNoTooHeightDifference(int area, int tile, int yUnk) + { + for (int attempts = 0; attempts < 8; attempts++) { + int neighbour = this->directionTranslationMatrix[yUnk][attempts] + tile; + if (this->HeightLayer[neighbour] > this->HeightLayer[tile] + 16) { + continue; + } + if ((short)this->PathConnectionLayer[neighbour] != area) { + continue; + } + return TRUE; + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp new file mode 100644 index 0000000000..1fb7d06de6 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp @@ -0,0 +1,57 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::BuildingLogicalState; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8210 + uint TileMapState::getBuildingHurtSFXID(int tileUnk) + { + short buildingID = this->BuildingLayer[tileUnk]; + if (buildingID != 0) { + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == 0) { + return 0; + } + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == OpenSHC::Map::Buildings::BLS_REMOVE) { + return 0; + } + if (DAT_BuildingsState::instance.buildings[buildingID].currentHealth == 0) { + return 0; + } + + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case OpenSHC::Map::Buildings::BT_BARRACKS: + case OpenSHC::Map::Buildings::BT_STOCKPILE: + case OpenSHC::Map::Buildings::BT_ARMORY: + case OpenSHC::Map::Buildings::BT_ENGINEERSGUILD: + case OpenSHC::Map::Buildings::BT_TUNNELERSGUILD: + case OpenSHC::Map::Buildings::BT_CHAPEL: + case OpenSHC::Map::Buildings::BT_CHURCH: + case OpenSHC::Map::Buildings::BT_CATHEDRAL: + case OpenSHC::Map::Buildings::BT_MANORHOUSE: + case OpenSHC::Map::Buildings::BT_STONEKEEP: + case OpenSHC::Map::Buildings::BT_STRONGHOLD: + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + case OpenSHC::Map::Buildings::BT_GATEHOUSE: + 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: + case OpenSHC::Map::Buildings::BT_OUTPOST_EUROPEAN: + return 2; + default: + return 1; + } + } + return (uint)this->LogicLayer[tileUnk] >> 7 & 2; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp new file mode 100644 index 0000000000..5862d948e5 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp @@ -0,0 +1,223 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Commands/MappersEnum.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Commands::MappersEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FA550 + int TileMapState::getBuildingSizeForCommandBuildingType(MappersEnum commandBuildingType) + { + /* + The original dispatches through a byte index table at 0x004FA614 (0x147 entries, biased by + M_MAPPER_UNDUGMOAT) into a jump table at 0x004FA5DC, which is what MSVC emits for a dense + switch; Ghidra could not normalise it and rendered the dispatch as a read through an + unnamed pointer array. The case groups below are that byte table, decoded. + + field159_0x5549b8 is written through the global instance, not through this, which is how + the original addresses it. + */ + switch (commandBuildingType) { + case OpenSHC::Commands::M_MAPPER_FLETCHER: + case OpenSHC::Commands::M_MAPPER_HOVEL: + case OpenSHC::Commands::M_MAPPER_BAKER: + case OpenSHC::Commands::M_MAPPER_BREWER: + case OpenSHC::Commands::M_MAPPER_GRANARY: + case OpenSHC::Commands::M_MAPPER_ARMOURY: + case OpenSHC::Commands::M_MAPPER_POLETURNER: + case OpenSHC::Commands::M_MAPPER_BLACKSMITH: + case OpenSHC::Commands::M_MAPPER_ARMOURER: + case OpenSHC::Commands::M_MAPPER_TANNER: + case OpenSHC::Commands::M_MAPPER_IRON_MINE: + case OpenSHC::Commands::M_MAPPER_PITCH_WORKINGS: + case OpenSHC::Commands::M_MAPPER_TOWER2: + case OpenSHC::Commands::M_MAPPER_GARDEN10: + case OpenSHC::Commands::M_MAPPER_GARDEN11: + case OpenSHC::Commands::M_MAPPER_GARDEN12: + case OpenSHC::Commands::M_MAPPER_OIL_SMELTER: + case (MappersEnum)258: + case (MappersEnum)259: + case (MappersEnum)260: + case OpenSHC::Commands::M_MAPPER_WATERPOT: + return 4; + case OpenSHC::Commands::M_MAPPER_STORES: + case OpenSHC::Commands::M_MAPPER_TRADEPOST: + case OpenSHC::Commands::M_MAPPER_BARRACKS_EURO: + case OpenSHC::Commands::M_MAPPER_BARRACKS_ARAB: + case OpenSHC::Commands::M_MAPPER_ENGINEERS_GUILD: + case OpenSHC::Commands::M_MAPPER_TUNNELERS_GUILD: + case OpenSHC::Commands::M_MAPPER_INN: + case OpenSHC::Commands::M_MAPPER_GATE_INNER: + case OpenSHC::Commands::M_MAPPER_DRAWBRIDGE: + case OpenSHC::Commands::M_MAPPER_TOWER3: + case OpenSHC::Commands::M_MAPPER_GATE_STONE1A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE1B: + case OpenSHC::Commands::M_MAPPER_OUTPOST_EURO: + case OpenSHC::Commands::M_MAPPER_OUTPOST_ARAB: + case OpenSHC::Commands::M_MAPPER_CESS_PIT1: + case OpenSHC::Commands::M_MAPPER_CESS_PIT2: + case OpenSHC::Commands::M_MAPPER_CESS_PIT3: + case OpenSHC::Commands::M_MAPPER_CESS_PIT4: + case OpenSHC::Commands::M_MAPPER_DUNGEON: + case OpenSHC::Commands::M_MAPPER_DUNKING_STOOL: + case OpenSHC::Commands::M_MAPPER_DANCING_BEAR: + case OpenSHC::Commands::M_MAPPER_POND1: + case OpenSHC::Commands::M_MAPPER_POND2_SMALL: + return 5; + case OpenSHC::Commands::M_MAPPER_QUARRY: + case OpenSHC::Commands::M_MAPPER_STABLES: + case OpenSHC::Commands::M_MAPPER_HEALER: + case OpenSHC::Commands::M_MAPPER_CHURCH1: + case OpenSHC::Commands::M_MAPPER_TOWER4: + case OpenSHC::Commands::M_MAPPER_TOWER5: + case OpenSHC::Commands::M_MAPPER_POND3_LARGE1: + case OpenSHC::Commands::M_MAPPER_POND4_LARGE2: + return 6; + case OpenSHC::Commands::M_MAPPER_WOODSMAN: + case OpenSHC::Commands::M_MAPPER_TUNNEL: + case OpenSHC::Commands::M_MAPPER_TUNNEL_CONSTRUCTION: + case OpenSHC::Commands::M_MAPPER_MILL: + case OpenSHC::Commands::M_MAPPER_HUNTER: + case OpenSHC::Commands::M_MAPPER_TOWER1: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD1A: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD1B: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD1C: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD1D: + case OpenSHC::Commands::M_MAPPER_GARDEN7: + case OpenSHC::Commands::M_MAPPER_GARDEN8: + case OpenSHC::Commands::M_MAPPER_GARDEN9: + case OpenSHC::Commands::M_MAPPER_MAYPOLE: + case OpenSHC::Commands::M_MAPPER_STOCKS: + case OpenSHC::Commands::M_MAPPER_CATAPULT: + case OpenSHC::Commands::M_MAPPER_TREBUCHET: + case OpenSHC::Commands::M_MAPPER_SIEGE_TOWER: + case OpenSHC::Commands::M_MAPPER_BATTERING_RAM: + case OpenSHC::Commands::M_MAPPER_PORTABLE_SHIELD: + case OpenSHC::Commands::M_MAPPER_BURNING_STAKE: + case OpenSHC::Commands::M_MAPPER_RACK_STRETCHING: + case OpenSHC::Commands::M_MAPPER_CHOPPING_BLOCK: + case OpenSHC::Commands::M_MAPPER_DOG_CAGE: + case OpenSHC::Commands::M_MAPPER_WELL: + case OpenSHC::Commands::M_MAPPER_ARAB_BALLISTA: + return 3; + case OpenSHC::Commands::M_MAPPER_KEEP1: + case OpenSHC::Commands::M_MAPPER_KEEP2: + case OpenSHC::Commands::M_MAPPER_GATE_MAIN: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2B: + return 7; + case OpenSHC::Commands::M_MAPPER_CAMP_FIRE: + case OpenSHC::Commands::M_MAPPER_KILLING_PIT: + case OpenSHC::Commands::M_MAPPER_PITCH_DITCH: + case (MappersEnum)248: + case (MappersEnum)249: + case (MappersEnum)250: + case (MappersEnum)251: + case OpenSHC::Commands::M_MAPPER_SHRINE5: + return 1; + case OpenSHC::Commands::M_MAPPER_KEEP3: + case OpenSHC::Commands::M_MAPPER_APPLEFARM: + return 0xb; + case OpenSHC::Commands::M_MAPPER_WHEATFARM: + case OpenSHC::Commands::M_MAPPER_HOPSFARM: + case OpenSHC::Commands::M_MAPPER_CHURCH2: + return 9; + case OpenSHC::Commands::M_MAPPER_CHURCH3: + return 0xd; + case OpenSHC::Commands::M_MAPPER_CATTLEFARM: + return 0xa; + case OpenSHC::Commands::M_MAPPER_UNDUGMOAT: + case OpenSHC::Commands::M_MAPPER_DUGMOAT: + case OpenSHC::Commands::M_MAPPER_MOAT: + case OpenSHC::Commands::M_MAPPER_ANTIMOAT: + DAT_TileMapState::instance.field_0x5549b8 = 1; + return 2; + case OpenSHC::Commands::M_MAPPER_OXENBASE: + case OpenSHC::Commands::M_MAPPER_SIGNPOST: + case OpenSHC::Commands::M_MAPPER_GATE_POSTERN: + case OpenSHC::Commands::M_MAPPER_GARDEN1: + case OpenSHC::Commands::M_MAPPER_GARDEN2: + case OpenSHC::Commands::M_MAPPER_GARDEN3: + case OpenSHC::Commands::M_MAPPER_GARDEN4: + case OpenSHC::Commands::M_MAPPER_GARDEN5: + case OpenSHC::Commands::M_MAPPER_GARDEN6: + case OpenSHC::Commands::M_MAPPER_GALLOWS: + case (MappersEnum)252: + case (MappersEnum)253: + case (MappersEnum)254: + case (MappersEnum)255: + case (MappersEnum)256: + case (MappersEnum)257: + case OpenSHC::Commands::M_MAPPER_GIBBET: + case OpenSHC::Commands::M_MAPPER_STATUE1: + case OpenSHC::Commands::M_MAPPER_STATUE2: + case OpenSHC::Commands::M_MAPPER_STATUE3: + case OpenSHC::Commands::M_MAPPER_STATUE4: + case OpenSHC::Commands::M_MAPPER_STATUE5: + case OpenSHC::Commands::M_MAPPER_SHRINE1: + case OpenSHC::Commands::M_MAPPER_SHRINE2: + case OpenSHC::Commands::M_MAPPER_SHRINE3: + case OpenSHC::Commands::M_MAPPER_SHRINE4: + return 2; + case OpenSHC::Commands::M_MAPPER_FLAG_TYPE0: + case OpenSHC::Commands::M_MAPPER_FLAG_TYPE1: + case OpenSHC::Commands::M_MAPPER_FLAG_TYPE2: + case OpenSHC::Commands::M_MAPPER_FLAG_TYPE3: + case OpenSHC::Commands::M_MAPPER_HEADS: + case OpenSHC::Commands::M_MAPPER_BRAZIER: + case OpenSHC::Commands::M_MAPPER_MANGONEL: + case OpenSHC::Commands::M_MAPPER_BALLISTA: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARCHERS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_SPEARMEN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_PIKEMEN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_MACEMEN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_XBOWMEN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_SWORDSMEN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_KNIGHTS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_LADDERMEN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ENGINEERS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ENGINEERS_POTS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_MONKS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_CATAPULTS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_TREBUCHETS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_BATTERING_RAMS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_SIEGE_TOWERS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_PORTABLE_SHIELDS: + case OpenSHC::Commands::M_MAPPER_PEOPLE_TUNNELERS: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT1: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT2: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT3: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT4: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT5: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT6: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT7: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARAB_BOW: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARAB_SLAVE: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARAB_SLINGER: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARAB_ASSASIN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARAB_HORSEMAN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARAB_SWORDSMAN: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARAB_GRENADIER: + case OpenSHC::Commands::M_MAPPER_PEOPLE_ARAB_BALLISTA: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM1: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM2: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM3: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM4: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM5: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM6: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM7: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTE1: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTE2: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTT1: + case OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTK1: + return 0; + } + return -1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp new file mode 100644 index 0000000000..0912b24d0c --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp @@ -0,0 +1,35 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingSizeIndexMapping.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9880 + void TileMapState::getBuildingSizeIndexMappingData(int buildingSizeTileIndex, int buildingWidthOrHeight) + { + this->constructionTileCount = buildingWidthOrHeight * buildingWidthOrHeight; + this->buildingX = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][0]; + this->buildingY = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][1]; + switch (this->mapOrientation) { + case 0: + this->buildingRotationRelatedValue + = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][2]; + return; + case 2: + this->buildingRotationRelatedValue + = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][3]; + return; + case 4: + this->buildingRotationRelatedValue + = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][4]; + return; + case 6: + this->buildingRotationRelatedValue + = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][5]; + } + return; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp b/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp new file mode 100644 index 0000000000..56763b7058 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp @@ -0,0 +1,25 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/MapConstants.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004FBC30 + undefined4 TileMapState::getCastleBuildRangeForMapSize() + { + switch (this->mapSize) { + case 160: + return 45; + case 200: + return 50; + case 300: + return 60; + case MC_MAP_XY_LIMIT: + return 70; + } + return 70; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp b/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp new file mode 100644 index 0000000000..6bb6c92213 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp @@ -0,0 +1,36 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00502950 + int TileMapState::getMaxWallHeightInBrushArea(int param_1, uint param_2) + { + int baseTile = param_1; + uint baseY = param_2; + int maxWallHeight = 0; + for (int index = 1; index < 5; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, index, ¶m_1, (int*)¶m_2, baseTile, baseY); + if ((this->LogicLayer[param_1] & L_WALL_OR_GATEHOUSE) == 0) { + continue; + } + if ((this->LogicLayer[param_1] & L_STOCKPILEUnk) != 0) { + continue; + } + if ((this->LogicLayer[param_1] & L_CRENEL) != 0) { + continue; + } + if (this->HeightLayer[param_1] > maxWallHeight) { + maxWallHeight = this->HeightLayer[param_1]; + } + } + return maxWallHeight; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getNonFarmFieldBuildingHealthAtTileOr1000.cpp b/src/OpenSHC/Map/TileMapState/getNonFarmFieldBuildingHealthAtTileOr1000.cpp new file mode 100644 index 0000000000..ea298623c1 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getNonFarmFieldBuildingHealthAtTileOr1000.cpp @@ -0,0 +1,48 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" + +#include "OpenSHC/Globals/DAT_BuildingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_APPLE; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_DAIRY; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_HOP; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_WHEAT; + + using OpenSHC::Map::Buildings::BuildingLogicalState; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8160 + int TileMapState::getNonFarmFieldBuildingHealthAtTileOr1000(int tile) + { + short buildingID = this->BuildingLayer[tile]; + if (buildingID <= 0) { + return 1000; + } + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == 0) { + return 1000; + } + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == OpenSHC::Map::Buildings::BLS_REMOVE) { + return 1000; + } + if (DAT_BuildingsState::instance.buildings[buildingID].currentHealth == 0) { + return 1000; + } + if (DAT_BuildingDefinedData::instance + .BuildingTypeHasHealth[DAT_BuildingsState::instance.buildings[buildingID].buildingType] + == 0) { + return 1000; + } + + if ((this->LogicLayer[tile] & (L_FARM_FIELD_WHEAT | L_FARM_FIELD_HOP | L_FARM_FIELD_APPLE | L_FARM_FIELD_DAIRY)) + != 0) { + return 1000; + } + return DAT_BuildingsState::instance.buildings[buildingID].currentHealth; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp new file mode 100644 index 0000000000..2d8bff6973 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp @@ -0,0 +1,38 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8B50 + int TileMapState::getOrientationThatIsWallTowerOrGatehouse(uint x, uint y) + { + if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { + return 15; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { + return 15; + } + + int rowTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + for (int index = 0; index < 8; index++) { + int orientation = DAT_TerrainDefinedData::instance.SomeOrientationOrderArray[index]; + int neighbour = this->directionTranslationMatrix[y][orientation] + rowTile; + if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[neighbour] & (L_STOCKPILEUnk | L_CRENEL_VARIATIONUnk)) == 0) { + return orientation; + } + } + return 15; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getPitchDitchIDForTile.cpp b/src/OpenSHC/Map/TileMapState/getPitchDitchIDForTile.cpp new file mode 100644 index 0000000000..e2966b9158 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getPitchDitchIDForTile.cpp @@ -0,0 +1,18 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500850 + int TileMapState::getPitchDitchIDForTile(int tile) + { + for (int pitchDitchID = 1; pitchDitchID < this->maxPitchDitchCount; pitchDitchID++) { + if (this->pitchDitches[pitchDitchID].owner != 0 && tile == this->pitchDitches[pitchDitchID].tile) { + return pitchDitchID; + } + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp new file mode 100644 index 0000000000..190058e1d2 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp @@ -0,0 +1,73 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004FA460 + undefined4 TileMapState::getRubbleGraphicStageForDamageLevel(int rotation) + { + /* the result lives in eax from the start (xor eax, eax), every comparison goes through ecx */ + int result = 0; + int orientation = this->mapOrientation; + if (orientation == 0) { + if (rotation == 0x50) { + result = 1; + } else if (rotation == 0x51) { + result = 0; + } else if (rotation == 1) { + result = 2; + } else if (rotation == 7) { + result = 5; + } else if (rotation == 3) { + result = 3; + } else if (rotation == 5) { + result = 4; + } + } else if (orientation == 4) { + if (rotation == 0x50) { + result = 1; + } else if (rotation == 0x51) { + result = 0; + } else if (rotation == 1) { + result = 4; + } else if (rotation == 7) { + result = 3; + } else if (rotation == 3) { + result = 5; + } else if (rotation == 5) { + result = 2; + } + } else if (orientation == 2) { + if (rotation == 0x50) { + result = 0; + } else if (rotation == 0x51) { + result = 1; + } else if (rotation == 1) { + result = 5; + } else if (rotation == 7) { + result = 4; + } else if (rotation == 3) { + result = 2; + } else if (rotation == 5) { + result = 3; + } + } else if (orientation == 6) { + if (rotation == 0x50) { + result = 0; + } else if (rotation == 0x51) { + result = 1; + } else if (rotation == 1) { + result = 3; + } else if (rotation == 7) { + result = 2; + } else if (rotation == 3) { + result = 4; + } else if (rotation == 5) { + result = 5; + } + } + return result; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp new file mode 100644 index 0000000000..a97d886cd7 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp @@ -0,0 +1,61 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004FBD80 + void TileMapState::getTileForBrush(int square, int index, int* tilePointer, int* yPointer, int baseTile, uint y) + { + if (square != 0) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::getTileInSquareBrush, DAT_PathFindingState::ptr)( + index, baseTile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile, y); + *tilePointer = DAT_PathFindingState::instance.resultTile; + *yPointer = DAT_PathFindingState::instance.resultY; + return; + } + + if (index >= 37) { + index = 0; + } + int brushStep = DAT_TerrainDefinedData::instance.field_0xc[index]; + if (brushStep == 0xf) { + return; + } + if (brushStep < 8) { + *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer = *yPointer + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + return; + } + + if (brushStep < 28) { + brushStep = brushStep - 20; + *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer = *yPointer + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer = *yPointer + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + } else if (brushStep < 48) { + brushStep = brushStep - 40; + *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer = *yPointer + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer = *yPointer + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer = *yPointer + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp b/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp new file mode 100644 index 0000000000..844faef35d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp @@ -0,0 +1,38 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::BuildingType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FFB10 + uint TileMapState::getTotalHeightAtTile(int tile) + { + int buildingID = this->BuildingLayer[tile]; + if (buildingID != 0) { + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSELARGE) { + return MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID) + + this->DefaultHeightLayer[tile]; + } + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSESMALL) { + return MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID) + + this->DefaultHeightLayer[tile]; + } + return MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID) + + this->HeightLayer[tile]; + } + return this->HeightLayer[tile]; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp new file mode 100644 index 0000000000..219c252262 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp @@ -0,0 +1,37 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F89C0 + BOOLEnum TileMapState::getWallFlagForOrientedDirection(int tileUnk, int y, int twoOrFour) + { + int direction = 0; + if (twoOrFour == 2) { + if (this->mapOrientation == 0) { + direction = 2; + } else if (this->mapOrientation == 2) { + direction = 4; + } else if (this->mapOrientation == 4) { + direction = 6; + } else if (this->mapOrientation == 6) { + direction = 0; + } + } else if (twoOrFour == 4) { + if (this->mapOrientation == 0) { + direction = 4; + } else if (this->mapOrientation == 2) { + direction = 6; + } else if (this->mapOrientation == 4) { + direction = 0; + } else if (this->mapOrientation == 6) { + direction = 2; + } + } else { + return 0; + } + return (uint)this->LogicLayer[this->directionTranslationMatrix[y][direction] + tileUnk] >> 8 & 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp new file mode 100644 index 0000000000..9c6392c669 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp @@ -0,0 +1,35 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8A40 + BOOLEnum TileMapState::hasHigherNeighborWithStairs(int tileUnk, int y, int direction) + { + int rotatedDirection = 0; + if (this->mapOrientation == 0) { + rotatedDirection = direction; + } else if (this->mapOrientation == 4) { + rotatedDirection = direction + 4; + } else if (this->mapOrientation == 2) { + rotatedDirection = direction + 2; + } else if (this->mapOrientation == 6) { + rotatedDirection = direction + 6; + } + if (rotatedDirection >= 8) { + rotatedDirection = rotatedDirection - 8; + } + + int neighbour = this->directionTranslationMatrix[y][rotatedDirection] + tileUnk; + if (this->HeightLayer[neighbour] <= this->HeightLayer[tileUnk]) { + return FALSE; + } + return (uint)this->LogicLayer[neighbour] >> 0xb & TRUE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp new file mode 100644 index 0000000000..6e50555415 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp @@ -0,0 +1,44 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8AC0 + BOOLEnum TileMapState::hasHigherPlainNeighborWithWallOrGatehouse(int tile, int y, int direction) + { + int rotatedDirection = 0; + if (this->mapOrientation == 0) { + rotatedDirection = direction; + } else if (this->mapOrientation == 4) { + rotatedDirection = direction + 4; + } else if (this->mapOrientation == 2) { + rotatedDirection = direction + 2; + } else if (this->mapOrientation == 6) { + rotatedDirection = direction + 6; + } + if (rotatedDirection >= 8) { + rotatedDirection = rotatedDirection - 8; + } + + int neighbour = this->directionTranslationMatrix[y][rotatedDirection] + tile; + if (this->HeightLayer[neighbour] <= this->HeightLayer[tile]) { + return FALSE; + } + if ((this->LogicLayer[neighbour] & L_CRENEL) != 0) { + return FALSE; + } + if ((this->LogicLayer[neighbour] & L_STOCKPILEUnk) != 0) { + return FALSE; + } + return (uint)this->LogicLayer[neighbour] >> 8 & TRUE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp b/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp new file mode 100644 index 0000000000..fdaf81b454 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp @@ -0,0 +1,49 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8900 + BOOLEnum TileMapState::hasOnlyTowerNeighborsNoWalls(int tile, int y) + { + int unknownWallRelated = 0; + int wallOrGatehouse = 0; + int offset = this->directionTranslationMatrix[y][0] + tile; + if ((this->LogicLayer[offset] & L_UNKNOWN_WALL_RELATED) != 0) { + unknownWallRelated++; + } else if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0) { + wallOrGatehouse++; + } + offset = this->directionTranslationMatrix[y][2] + tile; + if ((this->LogicLayer[offset] & L_UNKNOWN_WALL_RELATED) != 0) { + unknownWallRelated++; + } else if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0) { + wallOrGatehouse++; + } + offset = this->directionTranslationMatrix[y][4] + tile; + if ((this->LogicLayer[offset] & L_UNKNOWN_WALL_RELATED) != 0) { + unknownWallRelated++; + } else if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0) { + wallOrGatehouse++; + } + offset = this->directionTranslationMatrix[y][6] + tile; + if ((this->LogicLayer[offset] & L_UNKNOWN_WALL_RELATED) != 0) { + unknownWallRelated++; + } else if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0) { + wallOrGatehouse++; + } + if (unknownWallRelated != 0 && wallOrGatehouse == 0) { + return TRUE; + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp new file mode 100644 index 0000000000..94a8ee8f8d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp @@ -0,0 +1,48 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_FORD; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_MARSH; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F80E0 + void TileMapState::increaseHeightForTunnelSingleTile(int tile, uint x, uint y, int increment) + { + if ((this->LogicLayer[tile] + & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_RIVER | L_FORD | L_KEEP_NON_MANOR_HOUSE | L_MARSH | L_MOAT)) + != 0) { + return; + } + if ((this->LogicLayer[tile] & (L_SEA | L_BORDER | L_BORDER_EDGE | L_ROCKY)) != 0) { + return; + } + if (this->BuildingLayer[tile] != 0) { + return; + } + + if ((this->HeightLayer[tile] < 16 || this->DefaultHeightLayer[tile] < 16) + && (int)((uint)this->HeightLayer[tile] + increment) >= 0) { + this->HeightLayer[tile] = this->HeightLayer[tile] + (char)increment; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(4, x, y); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(y, tile); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp new file mode 100644 index 0000000000..1deea8175e --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp @@ -0,0 +1,57 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_FORD; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_MARSH; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00501CD0 + void TileMapState::increaseHeightForTunnelWithBrush(int tile, uint x, uint y, int increment) + { + int baseTile = tile; + uint baseY = y; + for (int index = 0; index < 9; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 0, index, &tile, (int*)&y, baseTile, baseY); + /* a copy the height store cannot alias: the original pushes it without reloading tile */ + int const brushTile = tile; + if ((this->LogicLayer[tile] & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & (L_SEA | L_BORDER | L_BORDER_EDGE | L_ROCKY)) != 0) { + continue; + } + if ((this->LogicLayer[tile] & (L_RIVER | L_FORD | L_MARSH | L_MOAT)) != 0) { + continue; + } + + if ((this->HeightLayer[tile] < 0x10 || this->DefaultHeightLayer[tile] < 0x10) + && (int)((uint)this->HeightLayer[tile] + increment) >= 0) { + this->HeightLayer[tile] = this->HeightLayer[tile] + (char)increment; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(y, brushTile); + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(5, x, y); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp b/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp new file mode 100644 index 0000000000..b780f960b1 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp @@ -0,0 +1,15 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004FC7C0 + BOOLEnum TileMapState::isCliffDropInDirection(int tileUnk, undefined4 param_2, int y) + { + int direction = (this->screenSouthEastDirection + 4) % 8; + return this->HeightLayer[tileUnk] + > this->HeightLayer[this->directionTranslationMatrix[y][direction] + tileUnk] + 0x14; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isFootprintIndexOnEdge.cpp b/src/OpenSHC/Map/TileMapState/isFootprintIndexOnEdge.cpp new file mode 100644 index 0000000000..70401976c2 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isFootprintIndexOnEdge.cpp @@ -0,0 +1,29 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9930 + BOOLEnum TileMapState::isFootprintIndexOnEdge(int counter, int size) + { + if (size < 3) { + return TRUE; + } + if (counter < size) { + return TRUE; + } + if (counter >= (size - 1) * size) { + return TRUE; + } + if (counter % size == 0) { + return TRUE; + } + return counter % size == size - 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp new file mode 100644 index 0000000000..1a76d9936d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp @@ -0,0 +1,32 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8640 + BOOLEnum TileMapState::isTileEnclosedByWalls(int tile, int y) + { + int offset = this->directionTranslationMatrix[y][0] + tile; + if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { + return 1; + } + offset = this->directionTranslationMatrix[y][4] + tile; + if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { + return 1; + } + offset = this->directionTranslationMatrix[y][2] + tile; + if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { + return 1; + } + offset = this->directionTranslationMatrix[y][6] + tile; + if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { + return 1; + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp new file mode 100644 index 0000000000..dfb35c7c91 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp @@ -0,0 +1,41 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F85B0 + BOOLEnum TileMapState::isTileEnclosedByWallsOrGates(int tile, int y) + { + int offset = this->directionTranslationMatrix[y][0] + tile; + if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[offset] & (L_STOCKPILEUnk | L_CRENEL)) == 0) { + return TRUE; + } + offset = this->directionTranslationMatrix[y][4] + tile; + if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[offset] & (L_STOCKPILEUnk | L_CRENEL)) == 0) { + return TRUE; + } + offset = this->directionTranslationMatrix[y][2] + tile; + if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[offset] & (L_STOCKPILEUnk | L_CRENEL)) == 0) { + return TRUE; + } + offset = this->directionTranslationMatrix[y][6] + tile; + if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[offset] & (L_STOCKPILEUnk | L_CRENEL)) == 0) { + return TRUE; + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp b/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp new file mode 100644 index 0000000000..0decdfcc1d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp @@ -0,0 +1,61 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8840 + BOOLEnum TileMapState::isWallConnectionHeightValid(int tile, int y, int param_3) + { + int tileHeight = this->HeightLayer[tile]; + int firstDirection = 0; + int secondDirection = 0; + if (param_3 == 0) { + secondDirection = 4; + } else if (param_3 == 2) { + firstDirection = 2; + secondDirection = 6; + } else if (param_3 == 4) { + firstDirection = 0; + secondDirection = param_3; + } else if (param_3 == 6) { + firstDirection = 2; + secondDirection = 6; + } + + int first = this->directionTranslationMatrix[y][firstDirection] + tile; + if ((this->LogicLayer[first] & L_WALL_OR_GATEHOUSE) == 0) { + return FALSE; + } + if ((this->LogicLayer[first] & L_STOCKPILEUnk) != 0) { + return FALSE; + } + int minHeight = tileHeight - 0x10; + if (this->HeightLayer[first] < minHeight && this->DamageLayer[first] == 0) { + return FALSE; + } + + int second = this->directionTranslationMatrix[y][secondDirection] + tile; + if ((this->LogicLayer[second] & L_WALL_OR_GATEHOUSE) == 0) { + return FALSE; + } + if ((this->LogicLayer[second] & L_STOCKPILEUnk) != 0) { + return FALSE; + } + if (this->HeightLayer[second] < minHeight && this->DamageLayer[second] == 0) { + return FALSE; + } + return TRUE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp b/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp new file mode 100644 index 0000000000..b7e008769d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp @@ -0,0 +1,54 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F86D0 + BOOLEnum TileMapState::isWallCornerForCardinalDirection(int tile, int y, int direction) + { + int first = 0; + int second = 0; + int third = 0; + int fourth = 0; + if (direction == 0) { + first = 0; + second = 4; + third = 2; + fourth = 6; + } else if (direction == 2) { + first = 2; + second = 6; + third = 0; + fourth = 4; + } else if (direction == 4) { + first = 0; + second = 4; + third = 2; + fourth = 6; + } else if (direction == 6) { + first = 2; + second = 6; + third = 0; + fourth = 4; + } + + if ((this->LogicLayer[this->directionTranslationMatrix[y][first] + tile] & L_CRENEL) == 0) { + return FALSE; + } + if ((this->LogicLayer[this->directionTranslationMatrix[y][second] + tile] & L_CRENEL) == 0) { + return FALSE; + } + if ((this->LogicLayer[this->directionTranslationMatrix[y][third] + tile] & L_CRENEL) != 0) { + return FALSE; + } + return ~((uint)this->LogicLayer[this->directionTranslationMatrix[y][fourth] + tile] >> 9) & TRUE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp b/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp new file mode 100644 index 0000000000..9102067b61 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp @@ -0,0 +1,50 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8780 + uint TileMapState::isWallCornerForDiagonalDirection(int tile, int y, int direction) + { + int first = 0; + int second = 0; + int third = 0; + int fourth = 0; + if (direction == 1) { + first = 4; + second = 6; + third = 0; + fourth = 2; + } else if (direction == 3) { + first = 0; + second = 6; + third = 4; + fourth = 2; + } else if (direction == 5) { + first = 0; + second = 2; + third = 4; + fourth = 6; + } else if (direction == 7) { + first = 4; + second = 2; + third = 0; + fourth = 6; + } + + if ((this->LogicLayer[this->directionTranslationMatrix[y][first] + tile] & L_CRENEL) == 0) { + return 0; + } + if ((this->LogicLayer[this->directionTranslationMatrix[y][second] + tile] & L_CRENEL) == 0) { + return 0; + } + if ((this->LogicLayer[this->directionTranslationMatrix[y][third] + tile] & L_CRENEL) != 0) { + return 0; + } + return ~((uint)this->LogicLayer[this->directionTranslationMatrix[y][fourth] + tile] >> 9) & 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp new file mode 100644 index 0000000000..3d00eac4c9 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp @@ -0,0 +1,26 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_PLAIN1_AND_FARM; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FA9D0 + void TileMapState::markBuildingFootprintFlag(int param_1, int param_2, int param_3) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, param_3); + buildingSizeTileIndex++; + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + param_2].addXgetTile + + this->buildingX + param_1; + this->LogicLayer[tile] = this->LogicLayer[tile] | L_PLAIN1_AND_FARM; + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xfff3; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/noop1.cpp b/src/OpenSHC/Map/TileMapState/noop1.cpp new file mode 100644 index 0000000000..ea3d3f93c3 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/noop1.cpp @@ -0,0 +1,10 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F70D0 + void TileMapState::noop1(undefined4 param_1) { return; } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp new file mode 100644 index 0000000000..5739af1938 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp @@ -0,0 +1,125 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BOULDERS; + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_IRON; + using OpenSHC::Map::LogicHelpers::L_PEBBLES; + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_TREE; + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Map::LogicHelpers::L_BOULDERS; + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_IRON; + using OpenSHC::Map::LogicHelpers::L_PEBBLES; + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_TREE; + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Commands::MappersEnum; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x005034A0 + void TileMapState::placeDefensiveStructureTile(int playerID, uint x, uint y, MappersEnum mapper) + { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateWallPlacementAtTile, this)(playerID, x, y, mapper); + if (this->illegalBuild != FALSE) { + return; + } + + int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + short command = (short)mapper; + this->DamageLayer[tile] = 0; + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + if (command == OpenSHC::Commands::M_MAPPER_WALL) { + this->HeightLayer[tile] = this->DefaultHeightLayer[tile] + 0x5a; + } else if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { + this->HeightLayer[tile] = this->DefaultHeightLayer[tile] + 0x3c; + } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL; + this->HeightLayer[tile] = this->HeightLayer[tile] + 0x62; + /* a crenel on an odd tile of one axis carries the alternate variation */ + if ((int)(x & 1) == 1 && (y & 1) == 0) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; + } else if ((int)(x & 1) == 0 && (y & 1) == 1) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; + } + } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL2) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL; + this->HeightLayer[tile] = this->HeightLayer[tile] + 0x44; + if ((int)(x & 1) == 1 && (y & 1) == 0) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; + } else if ((int)(x & 1) == 0 && (y & 1) == 1) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; + } + } else if (command == OpenSHC::Commands::M_MAPPER_STAIR1) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; + this->HeightLayer[tile] = this->HeightLayer[tile] + 0x50; + } else if (command == OpenSHC::Commands::M_MAPPER_STAIR2) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; + this->HeightLayer[tile] = this->HeightLayer[tile] + 0x40; + } else if (command == OpenSHC::Commands::M_MAPPER_STAIR3) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; + this->HeightLayer[tile] = this->HeightLayer[tile] + 0x30; + } else if (command == OpenSHC::Commands::M_MAPPER_STAIR4) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; + this->HeightLayer[tile] = this->HeightLayer[tile] + 0x20; + } else if (command == OpenSHC::Commands::M_MAPPER_STAIR5) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; + this->HeightLayer[tile] = this->HeightLayer[tile] + 0x10; + } + + this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_UNKNOWN_WALL_RELATED | L_BOULDERS | L_PEBBLES | L_IRON) + | L_WALL_OR_GATEHOUSE; + if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) != 0) { + this->LogicLayer[tile] = this->LogicLayer[tile] & ~L_PLAIN2_AND_PITCH; + this->HeightLayer[tile] = this->HeightLayer[tile] + 4; + } + if ((this->LogicLayer[tile] & L_TREE) != 0) { + int organism = this->OrganismLayer[tile]; + if (organism < 2000) { + DAT_LandscapeState::instance.trees[organism].state = 3; + } + } + if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_UNKNOWN_WALL_RELATED; + } + this->WallOwnerLayer[tile] = this->WallOwnerLayer[tile] & 0xf8 | (char)playerID - 1U; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(y, tile); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoat, this)(tile); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(7, x, y); + if (command != OpenSHC::Commands::M_MAPPER_STAIR1 && command != OpenSHC::Commands::M_MAPPER_STAIR2 + && command != OpenSHC::Commands::M_MAPPER_STAIR3 && command != OpenSHC::Commands::M_MAPPER_STAIR4 + && command != OpenSHC::Commands::M_MAPPER_STAIR5 && command != OpenSHC::Commands::M_MAPPER_STAIR6) { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processWallBuildingLoss, + DAT_BuildingsState::ptr)(playerID, 1, 0, 0); + } + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::triggerMinimapRedraw, DAT_MinimapViewState::ptr)(1); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/planMoat.cpp b/src/OpenSHC/Map/TileMapState/planMoat.cpp new file mode 100644 index 0000000000..6734ace63a --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/planMoat.cpp @@ -0,0 +1,62 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BOULDERS; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_FORD; + using OpenSHC::Map::LogicHelpers::L_IRON; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_MARSH; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; + using OpenSHC::Map::LogicHelpers::L_PLAIN1_AND_FARM; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00514480 + void TileMapState::planMoat(undefined4 playerID, int tile, uint tileY) + { + uint logic = this->LogicLayer[tile]; + if ((logic & (L_BORDER | L_BORDER_EDGE)) != 0) { + return; + } + if (this->OrganismLayer[tile] != 0) { + return; + } + if ((logic & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + return; + } + if (this->BuildingLayer[tile] != 0) { + return; + } + if ((logic & (L_WALL_OR_GATEHOUSE | L_BOULDERS | L_IRON | L_RIVER | L_FORD | L_MARSH)) != 0) { + return; + } + if ((logic & (L_SEA | L_PLAIN1_AND_FARM | L_ROCKY)) != 0) { + return; + } + + int moatX = tile - DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile; + if ((logic & (L_MOAT_DUG_OR_PLANNED | L_MOAT)) == 0 && this->HeightLayer[tile] <= 12) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::createMoatData, this)(playerID, moatX, tileY, 0) + != 0) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_MOAT_DUG_OR_PLANNED; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(tileY, tile); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp b/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp new file mode 100644 index 0000000000..a6d670a1bf --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp @@ -0,0 +1,24 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/MapConstants.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F79D0 + void TileMapState::rebuildShowHiLayerFromHeights() + { + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile += 8) { + this->ShowHiLayer[tile] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile]]; + this->ShowHiLayer[tile + 1] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 1]]; + this->ShowHiLayer[tile + 2] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 2]]; + this->ShowHiLayer[tile + 3] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 3]]; + this->ShowHiLayer[tile + 4] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 4]]; + this->ShowHiLayer[tile + 5] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 5]]; + this->ShowHiLayer[tile + 6] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 6]]; + this->ShowHiLayer[tile + 7] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 7]]; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/removeMoat.cpp b/src/OpenSHC/Map/TileMapState/removeMoat.cpp new file mode 100644 index 0000000000..63d55eb057 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/removeMoat.cpp @@ -0,0 +1,43 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_MOAT; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x005113F0 + BOOLEnum TileMapState::removeMoat(uint moatID, int param_2) + { + this->moats[moatID].fillProgress = this->moats[moatID].fillProgress - 1; + // nested form: the original keeps the FALSE return as the trailing block + if (this->moats[moatID].fillProgress <= 0) { + this->HeightLayer[this->moats[moatID].tile] = 8; + this->LogicLayer[this->moats[moatID].tile] = this->LogicLayer[this->moats[moatID].tile] & ~L_MOAT; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(2, this->moats[moatID].x, this->moats[moatID].y); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(this->moats[moatID].y, this->moats[moatID].tile); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + int tile = this->moats[moatID].tile; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatData, this)(moatID); + if (this->BuildingLayer[tile] != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateBuildingGraphicsLayer, this)( + this->BuildingLayer[tile]); + } + MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::triggerMinimapRedraw, DAT_MinimapViewState::ptr)(1); + return TRUE; + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/resetAreaBasedOnLogicalLayer.cpp b/src/OpenSHC/Map/TileMapState/resetAreaBasedOnLogicalLayer.cpp new file mode 100644 index 0000000000..85a489bded --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/resetAreaBasedOnLogicalLayer.cpp @@ -0,0 +1,67 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + + // FUNCTION: STRONGHOLDCRUSADER 0x005127B0 + void TileMapState::resetAreaBasedOnLogicalLayer() + { + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) == 0) { + continue; + } + + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::useEraserBrush, this)(tile + - DAT_ViewportRenderState::instance + .translationMatrix[DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]] + .addXgetTile, + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile], 1); + this->GfxLayer[tile] = 0; + this->AlphaGFXLayer[tile] = 0; + this->ConstructionGFXLayer[tile] = 0; + this->PillarGFXLayer[tile] = 1; + this->WallGFXLayer[tile] = 0; + this->FloatingLayer[tile] = 0; + this->UnitLayer[tile] = 0; + this->EntityLayer[tile] = 0; + this->EntityLayerLT25[tile] = 0; + this->BuildingLayer[tile] = 0; + this->LogicLayer[tile] = 0; + this->Logic2Layer[tile] = 0; + this->ChangedLayer[tile] = 0; + this->OrganismLayer[tile] = 0; + this->DamageLayer[tile] = 0; + this->MacroLayer[tile] = 0; + this->HeightLayer[tile] = 8; + this->DefaultHeightLayer[tile] = 8; + this->ShowHiLayer[tile] = 0; + this->MiscDisplayLayer[tile] = 0; + this->LuminesenceLayer[tile] = 0; + this->WallOwnerLayer[tile] = 0; + this->BuildingWasLayer[tile] = 0; + this->OccupancyLayer[tile] = 0; + this->AIZoneLayer[tile] = 0; + this->AIInfoLayer[tile] = 0; + this->unitDeathHeatMap[tile] = 0; + this->SEC_TileMap1104[tile] = 0; + this->SEC_PathfindingCostTileMap1105[0][tile] = 0; + this->SEC_PathfindingCostTileMap1105[1][tile] = 0; + this->SEC_PathfindingCostTileMap1105[2][tile] = 0; + this->SEC_PathfindingCostTileMap1105[3][tile] = 0; + this->SEC_PathfindingCostTileMap1105[4][tile] = 0; + this->SEC_PathfindingCostTileMap1105[5][tile] = 0; + this->SEC_PathfindingCostTileMap1105[6][tile] = 0; + this->SEC_PathfindingCostTileMap1105[7][tile] = 0; + this->SEC_PathfindingCostTileMap1105[8][tile] = 0; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp new file mode 100644 index 0000000000..b0bc40a819 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp @@ -0,0 +1,107 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F6CF0 + void TileMapState::resetHeightAndMapBorders(int mapSize) + { + int inset = (MC_MAP_XY_LIMIT - mapSize) / 2; + this->mapSize = mapSize; + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + } + this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_BORDER | L_BORDER_EDGE); + } + + /* the two outer diagonals of the diamond carry the border flags */ + int rowLength = 0; + int tile = 0; + do { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_BORDER; + tile++; + if (rowLength > 0) { + this->LogicLayer[tile] = this->LogicLayer[tile] | L_BORDER_EDGE; + } + tile = tile + rowLength; + if (rowLength > 0 && (this->LogicLayer[tile - 1] & L_BORDER) == 0) { + this->LogicLayer[tile - 1] = L_BORDER_EDGE; + } + this->LogicLayer[tile] = L_BORDER; + rowLength = rowLength + 2; + tile++; + } while (rowLength < MC_MAP_XY_LIMIT); + + for (rowLength = 398; rowLength >= 0; rowLength = rowLength - 2) { + this->LogicLayer[tile] = L_BORDER; + tile++; + if (rowLength > 0) { + this->LogicLayer[tile] = L_BORDER_EDGE; + } + tile = tile + rowLength; + if (rowLength > 0 && (this->LogicLayer[tile - 1] & L_BORDER) == 0) { + this->LogicLayer[tile - 1] = L_BORDER_EDGE; + } + this->LogicLayer[tile] = L_BORDER; + tile++; + } + + /* and again inset by (400 - mapSize) / 2 for a map smaller than the full diamond */ + int row = 0; + tile = 0; + for (int skipped = 0; skipped < inset; skipped++) { + tile = tile + 2 + row; + row = row + 2; + } + int firstRow = row; + for (; row < MC_MAP_XY_LIMIT; row = row + 2) { + this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER; + tile++; + if (row - inset > 0) { + this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER_EDGE; + } + tile = tile + row; + if (row - inset > 0 && (this->LogicLayer[tile - inset] & L_BORDER) == 0) { + this->LogicLayer[tile - inset - 1] = this->LogicLayer[tile - inset - 1] | L_BORDER_EDGE; + } + this->LogicLayer[tile - inset] = this->LogicLayer[tile - inset] | L_BORDER; + tile++; + } + for (row = 398; row >= firstRow; row = row - 2) { + this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER; + tile++; + if (row - inset > 0) { + this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER_EDGE; + } + tile = tile + row; + if (row - inset > 0 && (this->LogicLayer[tile - inset] & L_BORDER) == 0) { + this->LogicLayer[tile - inset - 1] = this->LogicLayer[tile - inset - 1] | L_BORDER_EDGE; + } + this->LogicLayer[tile - inset] = this->LogicLayer[tile - inset] | L_BORDER; + tile++; + } + if (mapSize != MC_MAP_XY_LIMIT) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::setWalkabilityBorderLogicLayerForSmallerMapSizes, + DAT_PathFindingState::ptr)(); + } + + /* every border tile ends up at the minimum height */ + for (int borderTile = 0; borderTile < MC_MAP_TILES_COUNT; borderTile++) { + if ((this->LogicLayer[borderTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->HeightLayer[borderTile] = 8; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp new file mode 100644 index 0000000000..43aa6cd9eb --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp @@ -0,0 +1,60 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_TREE; + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00507350 + void TileMapState::resetTileAndClearMoat(int tile) + { + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + this->LogicLayer[tile] = this->LogicLayer[tile] + & ~(L_PLAIN2_AND_PITCH | L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED + | L_CRENEL_VARIATIONUnk); + this->HeightLayer[tile] = DAT_TileMapState::instance.DefaultHeightLayer[tile]; + this->DamageLayer[tile] = 0; + if ((this->LogicLayer[tile] & L_TREE) != 0) { + int treeID = this->OrganismLayer[tile]; + if (treeID < 2000) { + switch (DAT_LandscapeState::instance.trees[treeID].treeType) { + case (TreeType)5: + case (TreeType)6: + case (TreeType)7: + case (TreeType)8: + case (TreeType)9: + case (TreeType)10: + case (TreeType)11: + case (TreeType)12: + case (TreeType)13: + case (TreeType)14: + case (TreeType)16: + case (TreeType)17: + case (TreeType)18: + case (TreeType)19: + DAT_LandscapeState::instance.trees[treeID].state = 3; + } + } + } + if ((this->LogicLayer[tile] & (L_MOAT | L_MOAT_DUG_OR_PLANNED)) != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)(x, y); + this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_MOAT | L_MOAT_DUG_OR_PLANNED); + } + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xfc3f; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp b/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp new file mode 100644 index 0000000000..4d7aa9e32c --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp @@ -0,0 +1,31 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F81D0 + void TileMapState::resetTileToDefaultState(int param_1, uint param_2, uint param_3) + { + this->LogicLayer[param_1] = this->LogicLayer[param_1] + & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); + this->HeightLayer[param_1] = this->DefaultHeightLayer[param_1]; + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)( + param_1); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(5, param_2, param_3); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/returnMoatIDForPlayerIDs.cpp b/src/OpenSHC/Map/TileMapState/returnMoatIDForPlayerIDs.cpp new file mode 100644 index 0000000000..71e68644fa --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/returnMoatIDForPlayerIDs.cpp @@ -0,0 +1,18 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500290 + int TileMapState::returnMoatIDForPlayerIDs(int playerID, int playerID2) + { + for (int moatID = 1; moatID < this->currentMoatCount; moatID++) { + if (this->moats[moatID].tile == playerID && this->moats[moatID].owner == playerID2) { + return moatID; + } + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/returnOwnedMoatAtTile.cpp b/src/OpenSHC/Map/TileMapState/returnOwnedMoatAtTile.cpp new file mode 100644 index 0000000000..e31e800025 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/returnOwnedMoatAtTile.cpp @@ -0,0 +1,18 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500250 + int TileMapState::returnOwnedMoatAtTile(int targetedTile) + { + for (int moatID = 1; moatID < this->currentMoatCount; moatID++) { + if (this->moats[moatID].owner != 0 && this->moats[moatID].tile == targetedTile) { + return moatID; + } + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp new file mode 100644 index 0000000000..bf4a5b4bc2 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp @@ -0,0 +1,96 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Commands/MappersEnum.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Commands::MappersEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8300 + void TileMapState::rotateFearFactorBuildingVariations() + { + /* + currentMapperCommand is reached through the global instance's absolute address, and the + switch below is the original's byte table at 0x004F847C into the jump table at 0x004F8454, + biased by M_MAPPER_GARDEN1. The "- 1 & 6" forms are the original's setcc/dec/and idiom. + */ + DWORD now = timeGetTime(); + if (this->editorRockType == 5) { + if (this->rockOrientation == 0) { + this->rockOrientation = 2; + } else if (this->rockOrientation == 2) { + this->rockOrientation = 4; + } else { + this->rockOrientation = (this->rockOrientation != 4) - 1 & 6; + } + } + if ((int)now < (int)(this->lastTime + 1000)) { + return; + } + + this->lastTime = now; + this->gateOrientationVariant = (this->gateOrientationVariant == 0x50) + 0x50; + if (this->editorRockType == 0) { + if (this->rockOrientation == 0) { + this->rockOrientation = 2; + } else if (this->rockOrientation == 2) { + this->rockOrientation = 4; + } else { + this->rockOrientation = (this->rockOrientation != 4) - 1 & 6; + } + } + + switch (DAT_TileMapState::instance.currentMapperCommand) { + case OpenSHC::Commands::M_MAPPER_GARDEN1: + case OpenSHC::Commands::M_MAPPER_GARDEN2: + case OpenSHC::Commands::M_MAPPER_GARDEN3: + case OpenSHC::Commands::M_MAPPER_GARDEN4: + case OpenSHC::Commands::M_MAPPER_GARDEN5: + case OpenSHC::Commands::M_MAPPER_GARDEN7: + case OpenSHC::Commands::M_MAPPER_GARDEN8: + case OpenSHC::Commands::M_MAPPER_GARDEN10: + case OpenSHC::Commands::M_MAPPER_GARDEN11: + case OpenSHC::Commands::M_MAPPER_CESS_PIT1: + case OpenSHC::Commands::M_MAPPER_CESS_PIT2: + case OpenSHC::Commands::M_MAPPER_CESS_PIT3: + case OpenSHC::Commands::M_MAPPER_STATUE1: + case OpenSHC::Commands::M_MAPPER_STATUE2: + case OpenSHC::Commands::M_MAPPER_STATUE3: + case OpenSHC::Commands::M_MAPPER_STATUE4: + case OpenSHC::Commands::M_MAPPER_SHRINE1: + case OpenSHC::Commands::M_MAPPER_POND1: + case OpenSHC::Commands::M_MAPPER_POND3_LARGE1: + DAT_TileMapState::instance.currentMapperCommand = (MappersEnum)(DAT_TileMapState::instance.currentMapperCommand + OpenSHC::Commands::M_MAPPER_AREA); + return; + case OpenSHC::Commands::M_MAPPER_GARDEN6: + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_GARDEN1; + return; + case OpenSHC::Commands::M_MAPPER_GARDEN9: + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_GARDEN7; + return; + case OpenSHC::Commands::M_MAPPER_GARDEN12: + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_GARDEN10; + return; + case OpenSHC::Commands::M_MAPPER_STATUE5: + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_STATUE1; + return; + case OpenSHC::Commands::M_MAPPER_POND2_SMALL: + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_POND1; + return; + case OpenSHC::Commands::M_MAPPER_POND4_LARGE2: + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_POND3_LARGE1; + return; + case OpenSHC::Commands::M_MAPPER_SHRINE2: + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_SHRINE1; + return; + case OpenSHC::Commands::M_MAPPER_CESS_PIT4: + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_CESS_PIT1; + return; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setChangedLayerToThreeAndMapping0x40x40.cpp b/src/OpenSHC/Map/TileMapState/setChangedLayerToThreeAndMapping0x40x40.cpp new file mode 100644 index 0000000000..4e41e3e7e0 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setChangedLayerToThreeAndMapping0x40x40.cpp @@ -0,0 +1,24 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/OS.func.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F6AE0 + void TileMapState::setChangedLayerToThreeAndMapping0x40x40() + { + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->ChangedLayer), 3, this->ChangedLayer); + MACRO_CALL(OpenSHC::OS_Func::_memset)(this->mapping40x40, 3, sizeof(this->mapping40x40)); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::setChangedLayerZeroBasedOn40x40Layer, + DAT_PathFindingState::ptr)(1); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setMapSize.cpp b/src/OpenSHC/Map/TileMapState/setMapSize.cpp new file mode 100644 index 0000000000..c0c4b15a4b --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setMapSize.cpp @@ -0,0 +1,22 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F6F90 + void TileMapState::setMapSize(int size) + { + int index = 0; + for (; size <= DAT_TerrainDefinedData::instance.MapSizes[index]; index++) {} + + if (DAT_TerrainDefinedData::instance.MapSizes[index] == -1) { + this->mapSize = DAT_TerrainDefinedData::instance.MapSizes[0]; + return; + } + this->mapSize = DAT_TerrainDefinedData::instance.MapSizes[index]; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp b/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp new file mode 100644 index 0000000000..6695af2132 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp @@ -0,0 +1,41 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Game/GameMode2.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Game::GameMode2; + + // FUNCTION: STRONGHOLDCRUSADER 0x00500BB0 + void TileMapState::setSignpostDistanceForCampaignMission() + { + DAT_GameState::instance.mapAndTime.unk_signpostDistance = 30; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CAMPAIGN_MISSION) { + if (DAT_GameCore::instance.missionNumber1to20 <= 2) { + DAT_GameState::instance.mapAndTime.unk_signpostDistance = 0; + return; + } + if (DAT_GameCore::instance.missionNumber1to20 <= 4) { + DAT_GameState::instance.mapAndTime.unk_signpostDistance = 15; + return; + } + if (DAT_GameCore::instance.missionNumber1to20 == 6) { + DAT_GameState::instance.mapAndTime.unk_signpostDistance = 37; + } + return; + } + + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_ECONOMIC_CAMPAIGN_SH1 + || (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_BUILDERUnk + && (int)DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 >= 2)) { + DAT_GameState::instance.mapAndTime.unk_signpostDistance = 7; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp new file mode 100644 index 0000000000..1049b14fbb --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -0,0 +1,145 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Global.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_AICState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WallAndPitchState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00512100 + void TileMapState::setupAllMapSections() + { + this->temporaryTerrainTypeIndex = 0; + this->SEC_Section1052 = 0; + this->SEC_Section1053 = 0; + this->SEC_Section1054 = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupTileMapSections, this)(); + DAT_WallAndPitchState::instance.countdown = 0; + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::setTileSystemMemoryLookupArrays, + DAT_ViewportRenderState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::tweakValidTilesToExcludeMapBorders, + DAT_ViewportRenderState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::setupViewport, DAT_ViewportRenderState::ptr)( + 0, 0, DAT_WindowAndDirectDraw::instance.resolutionX, DAT_WindowAndDirectDraw::instance.resolutionY - 128); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupLogicalMapBorders, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateShowHiLayerOrResetChangedLayer, this)(); + + /* the border tiles get their own graphic, everything else the plain one */ + for (int tile = 0; tile < 80400; tile += 6) { + for (int i = 0; i < 6; i++) { + if (this->LogicLayer[tile + i] == L_BORDER) { + this->GfxLayer[tile + i] = (ushort)GMFirstPictureIndex::instance[2]; + } else if (this->LogicLayer[tile + i] == L_BORDER_EDGE) { + this->GfxLayer[tile + i] = (ushort)GMFirstPictureIndex::instance[2] + 1; + } else { + this->GfxLayer[tile + i] = (ushort)GMFirstPictureIndex::instance[2] + 2; + } + } + } + + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ShortValue, DAT_LowLevelMemory::ptr)( + 80400, 1, this->PillarGFXLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + 80400, '\b', this->HeightLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + 80400, '\b', this->DefaultHeightLayer); + DAT_PathFindingState::instance.searchGeneration = 1; + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + 160800, '\0', DAT_TileMapState::instance.WalkLayer); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::setChangedLayerZeroBasedOn40x40Layer, + DAT_PathFindingState::ptr)(0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateLogicalTileMapRelatedSections, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateGfxLayer, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateGFXLayers, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetMoatArray, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetPitchDitchArray, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::toggleFlatView, this)(0); + DAT_TileMapState::instance.field_0x5548d0 = 0; + DAT_TileMapState::instance.flatViewToggleValue2 = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::clearBuildings, DAT_BuildingsState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::clearRocksAndTrees, DAT_LandscapeState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::resetWind, DAT_LandscapeState::ptr)(); + // the original calls this empty function as a member (object in ecx), of UnitsState here and of UnitsState + // and LandscapeState below; the generated header has it as a global, so pass the object through a one-argument + // __fastcall pointer + ((void(__fastcall*)(OpenSHC::Map::Units::UnitsState*))MACRO_CALL(OpenSHC::Global_Func::DoNothing))( + DAT_UnitsState::ptr); + MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::clearAllUnits, DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::clearAllTribes, DAT_TribesState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::clearMapAndTimeAndPlayerData, DAT_GameState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::resetVariousCountsAndStatisticsAndStartGoodsAndResources, + DAT_GameState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::clearCurrentResourcesAndStrongWalls, DAT_GameState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::initializeGameStateAfterMapLoad, DAT_GameState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::fillWith0xFF, DAT_GameState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::clearAnimalSpawnLocationsUnk, DAT_TribesState::ptr)(); + + for (int tribe = 0; tribe < 1000; tribe++) { + DAT_AICState::instance.tribeIDArray[tribe] = 0; + DAT_AICState::instance.tribeUIDArray[tribe] = 0; + } + ((void(__fastcall*)(OpenSHC::Map::Units::UnitsState*))MACRO_CALL(OpenSHC::Global_Func::DoNothing))( + DAT_UnitsState::ptr); + ((void(__fastcall*)(OpenSHC::Map::LandscapeState*))MACRO_CALL(OpenSHC::Global_Func::DoNothing))( + DAT_LandscapeState::ptr); + MACRO_CALL_MEMBER( + OpenSHC::Map::Entities::EntityState_Func::clearEntityArrayAndSeagullArray, DAT_EntityState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); + this->forceUpdateLogicalAndMiscDisplayLayers = 1; + this->forceUpdateTextureTilemap = 1; + this->forceUpdateGFXLayers = 1; + this->forceUpdateMacroLayerFlag = 1; + this->field_0x55487c = 200; + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageLayerForEachBuildingAtEachTile, + DAT_PathFindingState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updateSeparateAreaTileMap, DAT_PathFindingState::ptr)(1); + this->forceUpdateMacroLayerFlag = 1; + this->field_0x55487c = 500; + MACRO_CALL_MEMBER( + OpenSHC::UI::MinimapViewState_Func::setTileColorsDependingOnMapSize, DAT_MinimapViewState::ptr)(0, 100); + MACRO_CALL_MEMBER( + OpenSHC::UI::MinimapViewState_Func::setMapPropertyDependingOnMapSize, DAT_MinimapViewState::ptr)(0, 100); + DAT_GameCore::instance.currentlyInGameUnk_0xa4 = FALSE; + MACRO_CALL(OpenSHC::Map_Func::ResetSomeValuesFunctionUnk)(); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setupBuildingSizeIndexMapping.cpp b/src/OpenSHC/Map/TileMapState/setupBuildingSizeIndexMapping.cpp new file mode 100644 index 0000000000..6a5414abd3 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setupBuildingSizeIndexMapping.cpp @@ -0,0 +1,26 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00503720 + void TileMapState::setupBuildingSizeIndexMapping() + { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(1); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(2); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(3); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(4); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(5); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(6); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(7); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(8); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(9); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(10); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(11); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(12); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMappingForBuildingWithSize, this)(13); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp b/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp new file mode 100644 index 0000000000..f5dd47d0de --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp @@ -0,0 +1,43 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F6C60 + void TileMapState::setupLogicalMapBorders() + { + int rowWidth = 0; + int index = 0; + for (; rowWidth < 400; rowWidth += 2) { + this->LogicLayer[index] = L_BORDER; + index++; + if (rowWidth > 0) { + this->LogicLayer[index] = L_BORDER_EDGE; + } + index = index + rowWidth; + if (rowWidth > 0) { + this->LogicLayer[index - 1] = L_BORDER_EDGE; + } + this->LogicLayer[index] = L_BORDER; + index++; + } + for (rowWidth = 398;rowWidth >= 0; rowWidth -= 2) { + this->LogicLayer[index] = L_BORDER; + index++; + if (rowWidth > 0) { + this->LogicLayer[index] = L_BORDER_EDGE; + } + index = index + rowWidth; + if (rowWidth > 0) { + this->LogicLayer[index - 1] = L_BORDER_EDGE; + } + this->LogicLayer[index] = L_BORDER; + index++; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp new file mode 100644 index 0000000000..6047a48d28 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp @@ -0,0 +1,84 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Random/RNG.func.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00511DF0 + void TileMapState::setupTileMapSections() + { + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->GfxLayer), '\0', this->GfxLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->AlphaGFXLayer), '\0', this->AlphaGFXLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->ConstructionGFXLayer), '\0', this->ConstructionGFXLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->PillarGFXLayer), '\0', this->PillarGFXLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->WallGFXLayer), '\0', this->WallGFXLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->FloatingLayer), '\0', this->FloatingLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->UnitLayer), '\0', this->UnitLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->EntityLayer), '\0', this->EntityLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->EntityLayerLT25), '\0', this->EntityLayerLT25); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->BuildingLayer), '\0', this->BuildingLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->LogicLayer), '\0', this->LogicLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->Logic2Layer), '\0', this->Logic2Layer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->ChangedLayer), '\0', this->ChangedLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->OrganismLayer), '\0', this->OrganismLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->DamageLayer), '\0', this->DamageLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->MacroLayer), '\0', this->MacroLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->HeightLayer), '\0', this->HeightLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->DefaultHeightLayer), '\0', this->DefaultHeightLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->ShowHiLayer), '\0', this->ShowHiLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->MiscDisplayLayer), '\0', this->MiscDisplayLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->LuminesenceLayer), '\0', this->LuminesenceLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->WallOwnerLayer), '\0', this->WallOwnerLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->BuildingWasLayer), '\0', this->BuildingWasLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->OccupancyLayer), '\0', this->OccupancyLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->AIZoneLayer), '\0', this->AIZoneLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->AIInfoLayer), '\0', this->AIInfoLayer); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->unitDeathHeatMap), '\0', this->unitDeathHeatMap); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->SEC_TileMap1104), '\0', this->SEC_TileMap1104); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(this->SEC_PathfindingCostTileMap1105), '\0', this->SEC_PathfindingCostTileMap1105); + + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + this->RandomLayer[tile] = SEC_RNG::instance.currentNumber2; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::changeMapOrientation, this)(0); + this->DAT_FutureMapOrientation = 8; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp b/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp new file mode 100644 index 0000000000..0c718871c6 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp @@ -0,0 +1,61 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9F00 + void TileMapState::spawnEraserTileEffect(undefined4 param_1, int tile) + { + uint y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xfbff; + if (this->UnitLayer[tile] != 0) { + return; + } + + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tile); + this->LogicLayer[tile] = this->LogicLayer[tile] + & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); + int microX + = (tile + - DAT_ViewportRenderState::instance + .translationMatrix[DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]] + .addXgetTile) + * 8; + int microY = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile] * 8; + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, 0, + 0, microX, microY, DAT_TileMapState::instance.DefaultHeightLayer[tile], microX + 1, microY + 1, + DAT_TileMapState::instance.DefaultHeightLayer[tile], (EntityType)0x1e, 0); + this->BuildingWasLayer[tile] = 0; + this->DamageLayer[tile] = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(y, tile); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(9, x, y); + MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::triggerMinimapRedraw, DAT_MinimapViewState::ptr)(1); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_TileMapState::instance.field_0x554a30 = 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp new file mode 100644 index 0000000000..5cc0b11423 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp @@ -0,0 +1,43 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9980 + void TileMapState::storeMinAndMaxHeightOfArea(uint x, uint y, int buildingWidthAndHeight) + { + this->buildingMinHeight = 1000; + this->buildingMaxHeight = 0; + if (x > 399 || y > 399) { + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { + return; + } + + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, buildingWidthAndHeight); + uint footprintY = this->buildingY + y; + uint footprintX = this->buildingX + x; + if (footprintX <= 399 && footprintY <= 399 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[footprintY * 400 + footprintX] != 0) { + uint height + = this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[footprintY].addXgetTile + + this->buildingX + x]; + if ((int)height > this->buildingMaxHeight) { + this->buildingMaxHeight = height; + } + if ((int)height < this->buildingMinHeight) { + this->buildingMinHeight = height; + } + } + buildingSizeTileIndex++; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp new file mode 100644 index 0000000000..d94c0b2e1a --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp @@ -0,0 +1,22 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500790 + void TileMapState::swapMoatOwnership(int param_1, int param_2) + { + for (int moatID = 1; moatID < 16000; moatID++) { + if (this->moats[moatID].owner == 0) { + continue; + } + if (this->moats[moatID].owner == param_1) { + this->moats[moatID].owner = (char)param_2; + } else if (this->moats[moatID].owner == param_2) { + this->moats[moatID].owner = (char)param_1; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp new file mode 100644 index 0000000000..e53a5e4462 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp @@ -0,0 +1,22 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00500940 + void TileMapState::swapPitchOwnership(int param_1, int param_2) + { + for (int pitchDitchID = 1; pitchDitchID < 4000; pitchDitchID++) { + if (this->pitchDitches[pitchDitchID].owner == 0) { + continue; + } + if (this->pitchDitches[pitchDitchID].owner == param_1) { + this->pitchDitches[pitchDitchID].owner = (short)param_2; + } else if (this->pitchDitches[pitchDitchID].owner == param_2) { + this->pitchDitches[pitchDitchID].owner = (short)param_1; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp new file mode 100644 index 0000000000..42f9c13e46 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp @@ -0,0 +1,58 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9220 + void TileMapState::swapWallOwnership(int playerID, int otherPlayerID) + { + for (int tileUnk = 0; tileUnk < 80400; tileUnk += 6) { + if ((this->LogicLayer[tileUnk + 0] & L_WALL_OR_GATEHOUSE) != 0) { + if ((this->WallOwnerLayer[tileUnk + 0] & 7) + 1 == playerID) { + this->WallOwnerLayer[tileUnk + 0] = this->WallOwnerLayer[tileUnk + 0] & 0xf8 | (char)otherPlayerID - 1U; + } else if ((this->WallOwnerLayer[tileUnk + 0] & 7) + 1 == otherPlayerID) { + this->WallOwnerLayer[tileUnk + 0] = this->WallOwnerLayer[tileUnk + 0] & 0xf8 | (char)playerID - 1U; + } + } + if ((this->LogicLayer[tileUnk + 1] & L_WALL_OR_GATEHOUSE) != 0) { + if ((this->WallOwnerLayer[tileUnk + 1] & 7) + 1 == playerID) { + this->WallOwnerLayer[tileUnk + 1] = this->WallOwnerLayer[tileUnk + 1] & 0xf8 | (char)otherPlayerID - 1U; + } else if ((this->WallOwnerLayer[tileUnk + 1] & 7) + 1 == otherPlayerID) { + this->WallOwnerLayer[tileUnk + 1] = this->WallOwnerLayer[tileUnk + 1] & 0xf8 | (char)playerID - 1U; + } + } + if ((this->LogicLayer[tileUnk + 2] & L_WALL_OR_GATEHOUSE) != 0) { + if ((this->WallOwnerLayer[tileUnk + 2] & 7) + 1 == playerID) { + this->WallOwnerLayer[tileUnk + 2] = this->WallOwnerLayer[tileUnk + 2] & 0xf8 | (char)otherPlayerID - 1U; + } else if ((this->WallOwnerLayer[tileUnk + 2] & 7) + 1 == otherPlayerID) { + this->WallOwnerLayer[tileUnk + 2] = this->WallOwnerLayer[tileUnk + 2] & 0xf8 | (char)playerID - 1U; + } + } + if ((this->LogicLayer[tileUnk + 3] & L_WALL_OR_GATEHOUSE) != 0) { + if ((this->WallOwnerLayer[tileUnk + 3] & 7) + 1 == playerID) { + this->WallOwnerLayer[tileUnk + 3] = this->WallOwnerLayer[tileUnk + 3] & 0xf8 | (char)otherPlayerID - 1U; + } else if ((this->WallOwnerLayer[tileUnk + 3] & 7) + 1 == otherPlayerID) { + this->WallOwnerLayer[tileUnk + 3] = this->WallOwnerLayer[tileUnk + 3] & 0xf8 | (char)playerID - 1U; + } + } + if ((this->LogicLayer[tileUnk + 4] & L_WALL_OR_GATEHOUSE) != 0) { + if ((this->WallOwnerLayer[tileUnk + 4] & 7) + 1 == playerID) { + this->WallOwnerLayer[tileUnk + 4] = this->WallOwnerLayer[tileUnk + 4] & 0xf8 | (char)otherPlayerID - 1U; + } else if ((this->WallOwnerLayer[tileUnk + 4] & 7) + 1 == otherPlayerID) { + this->WallOwnerLayer[tileUnk + 4] = this->WallOwnerLayer[tileUnk + 4] & 0xf8 | (char)playerID - 1U; + } + } + if ((this->LogicLayer[tileUnk + 5] & L_WALL_OR_GATEHOUSE) != 0) { + if ((this->WallOwnerLayer[tileUnk + 5] & 7) + 1 == playerID) { + this->WallOwnerLayer[tileUnk + 5] = this->WallOwnerLayer[tileUnk + 5] & 0xf8 | (char)otherPlayerID - 1U; + } else if ((this->WallOwnerLayer[tileUnk + 5] & 7) + 1 == otherPlayerID) { + this->WallOwnerLayer[tileUnk + 5] = this->WallOwnerLayer[tileUnk + 5] & 0xf8 | (char)playerID - 1U; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp new file mode 100644 index 0000000000..1180855365 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp @@ -0,0 +1,61 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Units::UnitLogicState; + using OpenSHC::Map::Units::UnitType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F6FD0 + void TileMapState::triggerLoweredView(int param_1) + { + int view = 2; + if (this->flatViewToggleValue2 == 0) { + view = param_1; + } + if (this->refreshCertainTileMap_old == view) { + return; + } + this->refreshCertainTileMap = view; + this->counter1 = 0; + if (view != 3) { + return; + } + if (DAT_GameCore::instance.gamePausedLogical != 0) { + return; + } + + for (int unitID = 1; unitID < (int)DAT_UnitsState::instance.maxUnitCount; unitID++) { + if (DAT_UnitsState::instance.units[unitID].logicalState == OpenSHC::Map::Units::ULS_INVISIBLE) { + continue; + } + if (DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_DRUNK + && DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_RABBIT + && DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_HUNTERDOG + && DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_JESTER + && DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_CHICKEN + && DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_CHILD + && DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_JUGGLER + && DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_FIREEATER) { + continue; + } + + int height = (DAT_UnitsState::instance.units[unitID].buildingHeight + + DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight) + / 10; + if (height > 14) { + height = 14; + } + DAT_UnitsState::instance.units[unitID].heightDiv10 = (char)height; + DAT_UnitsState::instance.units[unitID].field_0x83 = 0; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp new file mode 100644 index 0000000000..f4994b2580 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp @@ -0,0 +1,25 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_PLAIN1_AND_FARM; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FAD20 + void TileMapState::unmarkBuildingFootprintFlag(int param_1, int param_2, int param_3) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, param_3); + buildingSizeTileIndex++; + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + param_2].addXgetTile + + this->buildingX + param_1; + this->LogicLayer[tile] = this->LogicLayer[tile] & ~L_PLAIN1_AND_FARM; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp new file mode 100644 index 0000000000..6cb6e376a0 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp @@ -0,0 +1,31 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004FAA30 + void TileMapState::updateAreaBasedOnSurrounding(int x, int y, int buildingSize) + { + int buildingSizeTileIndex = 0; + int area + = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findAccessibleAreaNearBuildingLocation, + DAT_BuildingsState::ptr)(x, y, buildingSize); + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, buildingSize); + int tileUnk = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (this->PathConnectionLayer[tileUnk] == 0) { + this->PathConnectionLayer[tileUnk] = (ushort)area; + } + buildingSizeTileIndex++; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp b/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp new file mode 100644 index 0000000000..905e51d09e --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp @@ -0,0 +1,37 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00511850 + void TileMapState::updateGameRelatedValue() + { + if (DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown == 0) { + return; + } + + if (DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown == 0x28) { + this->field_0x554a10 = -1; + } + DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown + = DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown - 1; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setSignpostDistanceForCampaignMission, this)(); + int signpostDistance = ((0x28 - DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown) + * DAT_GameState::instance.mapAndTime.unk_signpostDistance) + / 0x28; + if (signpostDistance == this->field_0x554a10) { + return; + } + + this->field_0x554a10 = signpostDistance; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::pathfindingUpdate_0x4a8ab0, + DAT_PathFindingState::ptr)(signpostDistance); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp b/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp new file mode 100644 index 0000000000..c8bd742bc5 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp @@ -0,0 +1,38 @@ +#include "../TileMapState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L2_BEACH; + using OpenSHC::Map::LogicHelpers::L2_EARTH_AND_STONES; + using OpenSHC::Map::LogicHelpers::L2_OASIS_GRASS; + using OpenSHC::Map::LogicHelpers::L2_PLATEAU_HIGH; + using OpenSHC::Map::LogicHelpers::L2_PLATEAU_MEDIUM; + using OpenSHC::Map::LogicHelpers::L2_SCRUB; + using OpenSHC::Map::LogicHelpers::L_DEFAULT_EARTH_OR_TEXTURE; + using OpenSHC::Map::LogicHelpers::L_MARSH; + using OpenSHC::Map::LogicHelpers::L_NONE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00511020 + void TileMapState::updateMacroLayer() + { + if (this->forceUpdateMacroLayerFlag <= 0) { + return; + } + + this->forceUpdateMacroLayerFlag = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)( + L_DEFAULT_EARTH_OR_TEXTURE, L2_SCRUB, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_MARSH, L_NONE, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)( + L_NONE, L2_EARTH_AND_STONES, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_NONE, L2_OASIS_GRASS, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_NONE, L2_BEACH, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_NONE, L2_PLATEAU_MEDIUM, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_NONE, L2_PLATEAU_HIGH, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated2, this)(); + this->forceUpdateTextureTilemap = 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp new file mode 100644 index 0000000000..a90edaa412 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp @@ -0,0 +1,76 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::BuildingType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00506AD0 + void TileMapState::updatePathLinkagesForBuilding(int buildingID) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int tileUnk = DAT_ViewportRenderState::instance + .translationMatrix[DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY] + .addXgetTile + + DAT_BuildingsState::instance.buildings[buildingID].x + this->buildingX; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY, tileUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoat, this)(tileUnk); + buildingSizeTileIndex++; + } while (buildingSizeTileIndex < this->constructionTileCount); + + short buildingType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + if (buildingType == OpenSHC::Map::Buildings::BT_GATEHOUSELARGE) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageTileMapRelatedToGates, + DAT_PathFindingState::ptr)(buildingID); + return; + } + if (buildingType == OpenSHC::Map::Buildings::BT_GATEHOUSESMALL) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageTileMapRelatedToGates, + DAT_PathFindingState::ptr)(buildingID); + return; + } + if (buildingType == OpenSHC::Map::Buildings::BT_WOODGATE1) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageTileMapRelatedToGates, + DAT_PathFindingState::ptr)(buildingID); + return; + } + if (buildingType == OpenSHC::Map::Buildings::BT_STONEKEEP) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageTileMapRelatedToKeeps, + DAT_PathFindingState::ptr)(buildingID); + return; + } + if (buildingType == OpenSHC::Map::Buildings::BT_STRONGHOLD) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageTileMapRelatedToKeeps, + DAT_PathFindingState::ptr)(buildingID); + return; + } + if (buildingType == OpenSHC::Map::Buildings::BT_KEEPFOUR) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageTileMapRelatedToKeeps, + DAT_PathFindingState::ptr)(buildingID); + return; + } + if (buildingType == OpenSHC::Map::Buildings::BT_KEEPFIVE) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageTileMapRelatedToKeeps, + DAT_PathFindingState::ptr)(buildingID); + return; + } + if (buildingType == OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageTileMapRelatedToSiegeTower, + DAT_PathFindingState::ptr)(buildingID); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp new file mode 100644 index 0000000000..3fde39dae9 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp @@ -0,0 +1,78 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Entities.func.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + + // FUNCTION: STRONGHOLDCRUSADER 0x005114C0 + void TileMapState::updatePitchDitches() + { + if (DAT_GameState::instance.gameTicksLoadBalancer % 10 == 3) { + this->maxPitchDitchCount = 0; + for (int id = 1; id < 4000; id++) { + if (this->pitchDitches[id].owner != 0) { + this->maxPitchDitchCount = id + 1; + } + } + } + + for (int id = 1; id < this->maxPitchDitchCount; id++) { + if (this->pitchDitches[id].owner == 0) { + continue; + } + int tile = this->pitchDitches[id].tile; + if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) == 0 || this->pitchDitches[id].state == -1) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::destroyPitchDitch, this)(id); + } else if (this->pitchDitches[id].state == 0) { + /* the original increments the state rather than storing the literal */ + this->pitchDitches[id].state = this->pitchDitches[id].state + 1; + this->pitchDitches[id].field_0x12 = 0; + } else if (this->pitchDitches[id].state == 2) { + this->pitchDitches[id].field_0x12 = this->pitchDitches[id].field_0x12 + 1; + if (this->pitchDitches[id].field_0x12 == 20) { + this->pitchDitches[id].state = this->pitchDitches[id].state + 1; + this->pitchDitches[id].field_0x12 = 0; + uint height = DAT_TileMapState::instance.HeightLayer[tile]; + /* the fire spreads to the four adjacent ditches that are still unlit */ + for (int i = 0; i < 4; i++) { + int neighbour = DAT_ViewportRenderState::instance + .translationMatrix[this->pitchDitches[id].y + + DAT_TerrainDefinedData::instance.field_0x376c[i].y] + .addXgetTile + + this->pitchDitches[id].x + DAT_TerrainDefinedData::instance.field_0x376c[i].x; + if ((this->LogicLayer[neighbour] & L_PLAIN2_AND_PITCH) == 0) { + continue; + } + int other = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getPitchDitchIDForTile, this)( + neighbour); + if (other == 0 || this->pitchDitches[other].state != 1) { + continue; + } + if (abs((int)(height - DAT_TileMapState::instance.HeightLayer[neighbour])) < 25) { + MACRO_CALL(OpenSHC::Map::Entities_Func::SetPlaceOnFire)(this->pitchDitches[other].owner, + this->pitchDitches[other].x * 8, this->pitchDitches[other].y * 8, + DAT_TileMapState::instance.HeightLayer[this->pitchDitches[other].tile], 3); + this->pitchDitches[other].state = 2; + } + } + } + } else if (this->pitchDitches[id].state == 3) { + this->pitchDitches[id].field_0x12 = this->pitchDitches[id].field_0x12 + 1; + if (this->pitchDitches[id].field_0x12 == 200) { + DAT_TileMapState::instance.HeightLayer[tile] = DAT_TileMapState::instance.DefaultHeightLayer[tile]; + this->pitchDitches[id].state = -1; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp new file mode 100644 index 0000000000..404e028aa7 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp @@ -0,0 +1,88 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_RotateMapOrPullDownTerrain.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00501A20 + void TileMapState::updateShowHiLayerOrResetChangedLayer() + { + int importHeight = 0; + this->refreshRelatedTwo = 0; + if (this->refreshCertainTileMap == 0) { + return; + } + + this->counter1 = this->counter1 + 1; + this->refreshCertainTileMap_old = this->refreshCertainTileMap; + this->refreshRelatedOne = 0; + for (int row = 0; row < 256; row++) { + int target = ((uint)row >> 2) + 1; + /* the pull-down eases towards the target in steps that shrink as it gets closer */ + int step; + if (this->refreshCertainTileMap == 3) { + step = this->heightBasedScreenYOffset[row] - target; + } else if (this->refreshCertainTileMap == 4) { + step = row - this->heightBasedScreenYOffset[row]; + } else { + step = 0; + } + if (step > 60) { + step = 30; + } else if (step > 40) { + step = 20; + } else if (step > 30) { + step = 14; + } else if (step > 20) { + step = 8; + } else if (step > 10) { + step = 4; + } else if (step > 6) { + step = 3; + } else if (step > 2) { + step = 2; + } else if (step > 0) { + step = 1; + } else { + step = 0; + } + + if (this->refreshCertainTileMap == 1) { + this->heightBasedScreenYOffset[row] = target; + } else if (this->refreshCertainTileMap == 2) { + this->heightBasedScreenYOffset[row] = row; + } else if (this->refreshCertainTileMap == 3) { + this->heightBasedScreenYOffset[row] = this->heightBasedScreenYOffset[row] - step; + if (this->heightBasedScreenYOffset[row] > target) { + importHeight = 1; + } + } else if (this->refreshCertainTileMap == 4) { + this->heightBasedScreenYOffset[row] = this->heightBasedScreenYOffset[row] + step; + if (this->heightBasedScreenYOffset[row] != row) { + importHeight = 1; + } + } + } + + this->refreshRelatedTwo = 1; + // nested form: the original keeps the rebuild tail call as the trailing block + if (importHeight == 0) { + if (this->refreshCertainTileMap == 4 || this->refreshCertainTileMap == 2) { + this->refreshRelatedOne = 1; + } else { + this->refreshRelatedOne = 0; + this->refreshRelatedTwo = 2; + } + this->refreshCertainTileMap = 0; + this->forceUpdateLogicalAndMiscDisplayLayers = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); + this->counter1 = 0; + DAT_RotateMapOrPullDownTerrain::instance = 1; + return; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::rebuildShowHiLayerFromHeights, this)(); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp b/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp new file mode 100644 index 0000000000..37848d246b --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp @@ -0,0 +1,44 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Version.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00511D70 + void TileMapState::upgradeMapFormatLogicLayer( + PackagedFileMagicNum receivedMapVersion, PackagedFileMagicNum packagerMapVersion) + { + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_Unknown1)(); + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_Unknown2)(); + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_Unknown3)(); + if (this->mapSize == 0) { + this->mapSize = MC_MAP_XY_LIMIT; + } + if (receivedMapVersion == packagerMapVersion) { + return; + } + + if ((int)receivedMapVersion < 102) { + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_102)(); + } + if ((int)receivedMapVersion < 120) { + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_120)(); + } + if ((int)receivedMapVersion < 125) { + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_125)(); + } + if ((int)receivedMapVersion < 128) { + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_128)(); + } + if ((int)receivedMapVersion < 145) { + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_145)(); + } + if ((int)receivedMapVersion < 147) { + MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_147)(); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp b/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp new file mode 100644 index 0000000000..6487cb5a87 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp @@ -0,0 +1,64 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9DF0 + void TileMapState::validateBuildingPlacementAtTile(int playerID, int x, int y) + { + this->buildingPlacementFail = FALSE; + int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int buildingID = this->BuildingLayer[tile]; + if (buildingID <= 0 + || (DAT_BuildingsState::instance.buildings[buildingID].owner != playerID && playerID != 0)) { + this->buildingPlacementFail = TRUE; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0 && this->BuildingLayer[tile] == 0) { + if ((this->WallOwnerLayer[tile] & 7) + 1 != playerID) { + return; + } + this->buildingPlacementFail = FALSE; + } + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) == 0 + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_GATEHOUSELARGE + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_GATEHOUSESMALL + && DAT_BuildingsState::instance.buildings[buildingID].buildingType != OpenSHC::Map::Buildings::BT_WOODGATE1 + && DAT_BuildingsState::instance.buildings[buildingID].buildingType != OpenSHC::Map::Buildings::BT_WOODGATE2 + && DAT_BuildingsState::instance.buildings[buildingID].buildingType != OpenSHC::Map::Buildings::BT_KEEPDOOR + && DAT_BuildingsState::instance.buildings[buildingID].buildingType != OpenSHC::Map::Buildings::BT_DRAWBRIDGE + && DAT_BuildingsState::instance.buildings[buildingID].buildingType != OpenSHC::Map::Buildings::BT_CAMPGROUND + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_PARADEGROUND + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_PARADEGROUND2 + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_PARADEGROUND3 + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_PARADEGROUND4 + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_PARADEGROUND5 + && DAT_BuildingsState::instance.buildings[buildingID].buildingType != OpenSHC::Map::Buildings::BT_CAMPFIRE + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_KILLINGPIT) { + this->buildingPlacementFail = TRUE; + } + this->cursorTargetID = buildingID; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp new file mode 100644 index 0000000000..49c6494d7f --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp @@ -0,0 +1,71 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_FORD; + using OpenSHC::Map::LogicHelpers::L_MARSH; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_PLAIN1_AND_FARM; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Map::Units::UnitLogicState; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F94A0 + void TileMapState::validateWallPlacementAtTile(int playerID, uint x, uint y, short param_4) + { + this->illegalBuild = TRUE; + int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + uint logic = this->LogicLayer[tile]; + int const building = this->BuildingLayer[tile]; + if ((logic & L_WALL_OR_GATEHOUSE) != 0 && (char)this->DamageLayer[tile] < 12) { + return; + } + if ((logic & L_BUILDING) != 0) { + return; + } + if (building != 0) { + return; + } + if ((logic & (L_PLAIN1_AND_FARM | L_BORDER)) != 0) { + return; + } + if ((logic & (L_SEA | L_ROCKY | L_RIVER | L_FORD | L_MARSH | L_MOAT)) != 0) { + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)(playerID, x, y, 5) + != FALSE) { + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::findSomeSuitableLocationUnk, + DAT_PathFindingState::ptr)(playerID, x, y, 2) + != 0) { + return; + } + + if (this->UnitLayer[tile] != 0 && (this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { + int const unitID = (short)this->UnitLayer[tile]; + if (param_4 == OpenSHC::Commands::M_MAPPER_CRENAL || param_4 == OpenSHC::Commands::M_MAPPER_CRENAL2) { + DAT_UnitsState::instance.units[unitID].logicalState = OpenSHC::Map::Units::ULS_REMOVE; + } + } + this->illegalBuild = FALSE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6e036f9340..2b8511f0a9 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38739,25 +38739,25 @@ SHC_3BB0A8C1_0x004F6A70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F6A80 | 0.0% | Pending -SHC_3BB0A8C1_0x004F6AE0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F6AE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F6B20 | 0.0% | Pending SHC_3BB0A8C1_0x004F6C20 | 0.0% | Pending -SHC_3BB0A8C1_0x004F6C60 | 0.0% | Pending +SHC_3BB0A8C1_0x004F6C60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F6CF0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F6CF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F6DC0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F6F90 | 0.0% | Pending +SHC_3BB0A8C1_0x004F6F90 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F6FD0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F6FD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F70B0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F70D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F70D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F70E0 | 100.0% | Reimplemented @@ -38767,7 +38767,7 @@ SHC_3BB0A8C1_0x004F7140 | 0.0% | Pending SHC_3BB0A8C1_0x004F7170 | 0.0% | Pending -SHC_3BB0A8C1_0x004F79D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F79D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F7A80 | 0.0% | Pending @@ -38787,13 +38787,13 @@ SHC_3BB0A8C1_0x004F80D4 | 0.0% | Pending SHC_3BB0A8C1_0x004F80D8 | 0.0% | Pending -SHC_3BB0A8C1_0x004F80E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F80E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8160 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F81D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F81D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8210 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8210 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F8288 | 0.0% | Pending @@ -38995,7 +38995,7 @@ SHC_3BB0A8C1_0x004F82F0 | 0.0% | Pending SHC_3BB0A8C1_0x004F82F1 | 0.0% | Pending -SHC_3BB0A8C1_0x004F8300 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8300 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F8454 | 0.0% | Pending @@ -39355,43 +39355,43 @@ SHC_3BB0A8C1_0x004F8523 | 0.0% | Pending SHC_3BB0A8C1_0x004F8524 | 0.0% | Pending -SHC_3BB0A8C1_0x004F8530 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8530 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F85B0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F85B0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8640 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8640 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F86D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F86D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8780 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8780 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8840 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8840 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8900 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8900 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F89C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F89C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8A40 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8A40 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8AC0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8AC0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8B50 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8B50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F8BD0 | 0.0% | Pending SHC_3BB0A8C1_0x004F9000 | 0.0% | Pending -SHC_3BB0A8C1_0x004F9220 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9220 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F93E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F93E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F94A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F94A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F9590 | 0.0% | Pending SHC_3BB0A8C1_0x004F9630 | 0.0% | Pending -SHC_3BB0A8C1_0x004F9880 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9880 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F990C | 0.0% | Pending @@ -39407,9 +39407,9 @@ SHC_3BB0A8C1_0x004F9920 | 0.0% | Pending SHC_3BB0A8C1_0x004F9924 | 0.0% | Pending -SHC_3BB0A8C1_0x004F9930 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9930 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F9980 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9980 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F99D0 | 0.0% | Pending @@ -39649,17 +39649,17 @@ SHC_3BB0A8C1_0x004F9DE9 | 0.0% | Pending SHC_3BB0A8C1_0x004F9DEA | 0.0% | Pending -SHC_3BB0A8C1_0x004F9DF0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9DF0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F9F00 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9F00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FA000 | 0.0% | Pending SHC_3BB0A8C1_0x004FA2D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004FA460 | 0.0% | Pending +SHC_3BB0A8C1_0x004FA460 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FA550 | 0.0% | Pending +SHC_3BB0A8C1_0x004FA550 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FA5DC | 0.0% | Pending @@ -40347,23 +40347,23 @@ SHC_3BB0A8C1_0x004FA760 | 0.0% | Pending SHC_3BB0A8C1_0x004FA8D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004FA9D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FA9D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FAA30 | 0.0% | Pending +SHC_3BB0A8C1_0x004FAA30 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FAAB0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FAAB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FAAE0 | 0.0% | Pending -SHC_3BB0A8C1_0x004FAB70 | 0.0% | Pending +SHC_3BB0A8C1_0x004FAB70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FAC70 | 0.0% | Pending +SHC_3BB0A8C1_0x004FAC70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FAD20 | 0.0% | Pending +SHC_3BB0A8C1_0x004FAD20 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FAD70 | 0.0% | Pending +SHC_3BB0A8C1_0x004FAD70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FAE50 | 0.0% | Pending +SHC_3BB0A8C1_0x004FAE50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FAEE0 | 0.0% | Pending @@ -40565,13 +40565,13 @@ SHC_3BB0A8C1_0x004FB354 | 0.0% | Pending SHC_3BB0A8C1_0x004FB358 | 0.0% | Pending -SHC_3BB0A8C1_0x004FB360 | 0.0% | Pending +SHC_3BB0A8C1_0x004FB360 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FB3F0 | 0.0% | Pending SHC_3BB0A8C1_0x004FB4D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004FB770 | 0.0% | Pending +SHC_3BB0A8C1_0x004FB770 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FB7D0 | 0.0% | Pending @@ -40583,7 +40583,7 @@ SHC_3BB0A8C1_0x004FB990 | 0.0% | Pending SHC_3BB0A8C1_0x004FB9E0 | 0.0% | Pending -SHC_3BB0A8C1_0x004FBC30 | 0.0% | Pending +SHC_3BB0A8C1_0x004FBC30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FBC6C | 0.0% | Pending @@ -41077,7 +41077,7 @@ SHC_3BB0A8C1_0x004FBD6F | 0.0% | Pending SHC_3BB0A8C1_0x004FBD70 | 0.0% | Pending -SHC_3BB0A8C1_0x004FBD80 | 0.0% | Pending +SHC_3BB0A8C1_0x004FBD80 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FBE70 | 0.0% | Pending @@ -41085,15 +41085,15 @@ SHC_3BB0A8C1_0x004FC0B0 | 0.0% | Pending SHC_3BB0A8C1_0x004FC280 | 0.0% | Pending -SHC_3BB0A8C1_0x004FC340 | 0.0% | Pending +SHC_3BB0A8C1_0x004FC340 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FC490 | 0.0% | Pending -SHC_3BB0A8C1_0x004FC650 | 0.0% | Pending +SHC_3BB0A8C1_0x004FC650 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FC7C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FC7C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FC810 | 0.0% | Pending +SHC_3BB0A8C1_0x004FC810 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FC9E0 | 0.0% | Pending @@ -41259,7 +41259,7 @@ SHC_3BB0A8C1_0x004FFB02 | 0.0% | Pending SHC_3BB0A8C1_0x004FFB03 | 0.0% | Pending -SHC_3BB0A8C1_0x004FFB10 | 0.0% | Pending +SHC_3BB0A8C1_0x004FFB10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FFBA0 | 0.0% | Pending @@ -41421,55 +41421,55 @@ SHC_3BB0A8C1_0x00500091 | 0.0% | Pending SHC_3BB0A8C1_0x005000A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005000E0 | 0.0% | Pending +SHC_3BB0A8C1_0x005000E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500180 | 0.0% | Pending +SHC_3BB0A8C1_0x00500180 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00500210 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500250 | 0.0% | Pending +SHC_3BB0A8C1_0x00500250 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500290 | 0.0% | Pending +SHC_3BB0A8C1_0x00500290 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005002D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500310 | 0.0% | Pending +SHC_3BB0A8C1_0x00500310 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500370 | 0.0% | Pending +SHC_3BB0A8C1_0x00500370 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005003D0 | 0.0% | Pending -SHC_3BB0A8C1_0x00500500 | 0.0% | Pending +SHC_3BB0A8C1_0x00500500 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005005F0 | 0.0% | Pending +SHC_3BB0A8C1_0x005005F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00500640 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00500680 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005006C0 | 0.0% | Pending +SHC_3BB0A8C1_0x005006C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00500720 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00500750 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500790 | 0.0% | Pending +SHC_3BB0A8C1_0x00500790 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005007D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500800 | 0.0% | Pending +SHC_3BB0A8C1_0x00500800 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500850 | 0.0% | Pending +SHC_3BB0A8C1_0x00500850 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500890 | 0.0% | Pending +SHC_3BB0A8C1_0x00500890 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500940 | 0.0% | Pending +SHC_3BB0A8C1_0x00500940 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500980 | 0.0% | Pending +SHC_3BB0A8C1_0x00500980 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500B50 | 0.0% | Pending +SHC_3BB0A8C1_0x00500B50 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00500BB0 | 0.0% | Pending +SHC_3BB0A8C1_0x00500BB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00500C20 | 100.0% | Reimplemented @@ -41543,9 +41543,9 @@ SHC_3BB0A8C1_0x005017A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005017C0 | 0.0% | Pending -SHC_3BB0A8C1_0x00501A20 | 0.0% | Pending +SHC_3BB0A8C1_0x00501A20 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00501B90 | 0.0% | Pending +SHC_3BB0A8C1_0x00501B90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00501CB0 | 0.0% | Pending @@ -41561,7 +41561,7 @@ SHC_3BB0A8C1_0x00501CC4 | 0.0% | Pending SHC_3BB0A8C1_0x00501CC8 | 0.0% | Pending -SHC_3BB0A8C1_0x00501CD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00501CD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00501D90 | 0.0% | Pending @@ -41577,7 +41577,7 @@ SHC_3BB0A8C1_0x005024F0 | 0.0% | Pending SHC_3BB0A8C1_0x00502680 | 0.0% | Pending -SHC_3BB0A8C1_0x00502950 | 0.0% | Pending +SHC_3BB0A8C1_0x00502950 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005029D0 | 0.0% | Pending @@ -41651,9 +41651,9 @@ SHC_3BB0A8C1_0x00503491 | 0.0% | Pending SHC_3BB0A8C1_0x00503492 | 0.0% | Pending -SHC_3BB0A8C1_0x005034A0 | 0.0% | Pending +SHC_3BB0A8C1_0x005034A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00503720 | 0.0% | Pending +SHC_3BB0A8C1_0x00503720 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005037B0 | 0.0% | Pending @@ -42083,7 +42083,7 @@ SHC_3BB0A8C1_0x005060C0 | 0.0% | Pending SHC_3BB0A8C1_0x00506370 | 0.0% | Pending -SHC_3BB0A8C1_0x00506AD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00506AD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00506BD0 | 0.0% | Pending @@ -42099,7 +42099,7 @@ SHC_3BB0A8C1_0x00507130 | 0.0% | Pending SHC_3BB0A8C1_0x00507280 | 0.0% | Pending -SHC_3BB0A8C1_0x00507350 | 0.0% | Pending +SHC_3BB0A8C1_0x00507350 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00507408 | 0.0% | Pending @@ -42161,7 +42161,7 @@ SHC_3BB0A8C1_0x00508590 | 0.0% | Pending SHC_3BB0A8C1_0x00508760 | 0.0% | Pending -SHC_3BB0A8C1_0x00508870 | 0.0% | Pending +SHC_3BB0A8C1_0x00508870 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00508910 | 0.0% | Pending @@ -44173,23 +44173,23 @@ SHC_3BB0A8C1_0x00511018 | 0.0% | Pending SHC_3BB0A8C1_0x0051101C | 0.0% | Pending -SHC_3BB0A8C1_0x00511020 | 0.0% | Pending +SHC_3BB0A8C1_0x00511020 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005110B0 | 0.0% | Pending +SHC_3BB0A8C1_0x005110B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005111D0 | 0.0% | Pending SHC_3BB0A8C1_0x00511240 | 0.0% | Pending -SHC_3BB0A8C1_0x005113F0 | 0.0% | Pending +SHC_3BB0A8C1_0x005113F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005114C0 | 0.0% | Pending +SHC_3BB0A8C1_0x005114C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005115C0 | 0.0% | Pending SHC_3BB0A8C1_0x005116E0 | 0.0% | Pending -SHC_3BB0A8C1_0x00511850 | 0.0% | Pending +SHC_3BB0A8C1_0x00511850 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005118C0 | 100.0% | Reimplemented @@ -44723,19 +44723,19 @@ SHC_3BB0A8C1_0x00511D60 | 0.0% | Pending SHC_3BB0A8C1_0x00511D64 | 0.0% | Pending -SHC_3BB0A8C1_0x00511D70 | 0.0% | Pending +SHC_3BB0A8C1_0x00511D70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00511DF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00511DF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005120C0 | 0.0% | Pending -SHC_3BB0A8C1_0x00512100 | 0.0% | Pending +SHC_3BB0A8C1_0x00512100 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00512180 | 0.0% | Pending SHC_3BB0A8C1_0x00512450 | 0.0% | Pending -SHC_3BB0A8C1_0x005127B0 | 0.0% | Pending +SHC_3BB0A8C1_0x005127B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005127D0 | 0.0% | Pending @@ -44743,7 +44743,7 @@ SHC_3BB0A8C1_0x00512920 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00512940 | 0.0% | Pending -SHC_3BB0A8C1_0x00514480 | 0.0% | Pending +SHC_3BB0A8C1_0x00514480 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00514520 | 0.0% | Pending @@ -44767,13 +44767,13 @@ SHC_3BB0A8C1_0x00515680 | 0.0% | Pending SHC_3BB0A8C1_0x00515740 | 0.0% | Pending -SHC_3BB0A8C1_0x00515A20 | 0.0% | Pending +SHC_3BB0A8C1_0x00515A20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00515C80 | 0.0% | Pending SHC_3BB0A8C1_0x00515DA0 | 0.0% | Pending -SHC_3BB0A8C1_0x00515F40 | 0.0% | Pending +SHC_3BB0A8C1_0x00515F40 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005160C0 | 0.0% | Pending From b374897c5465499d675a5efcd490732dabf192e0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 7 Nov 2026 17:55:00 +0100 Subject: [PATCH 07/28] style(TileMapState): apply the reimplementation style guide to the 88 sources Measured against a reccmp baseline of this branch before and after, in two rounds: all 88 functions come out byte-identical in match, average 99.92, every one still 100% raw or normalized. Nothing had to be reverted. - rule 18: 70 hex literals to decimal, bit masks left in hex; 399/400 to MC_MAP_XY_LIMIT_INCLUSIVE/MC_MAP_XY_LIMIT, 80400 to MC_MAP_TILES_COUNT and 398 to MC_MAP_XY_LIMIT - 2, matching what the sibling files already did - rule 16: param_N named in 14 files. Four of those parameters are unused in the body, and since the function matches at 100% the original does not use them either, so they are called unused rather than given a guessed meaning - rule 4: the three byte-sized layer fills in setupAllMapSections take sizeof of the layer. PillarGFXLayer's is a short fill, so its 80400 is an element count and stays MC_MAP_TILES_COUNT - rule 1: the trailing return; of getBuildingSizeIndexMappingData and noop1 - rule 23: the ternary in computeWallCornerRenderRotation is another else-if - rule 9: resetHeightAndMapBorders bounds its loop on a plain local, so its do-while became a for - rule 21: the twelve remaining do-while loops carry a note instead. Their bound is this->constructionTileCount, which the getBuildingSizeIndexMappingData call inside the body writes, so a leading test would read the previous footprint's count. Those loops are required for correctness, not just for the match, and converting them would have been a behaviour bug - block comments to //, which is what main's cpps use; duplicate using blocks dropped in three files; clear-masks spelled as the complement of the bits they clear, as the same lines already spell the bits they set; clang-format Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- .../TileMapState/Constructor_TileMapState.cpp | 2 +- .../applyRockGraphicsToFootprint.cpp | 3 ++ .../clearBuildingDisplayFlagsAndEntities.cpp | 7 ++-- ...arBuildingFootprintAndRemoveSiegeTower.cpp | 3 ++ .../clearBuildingFootprintAndResetUnits.cpp | 5 ++- .../clearBuildingFootprintWithEdgeRubble.cpp | 5 ++- .../TileMapState/clearBuildingFromTerrain.cpp | 6 ++-- .../Map/TileMapState/clearDrawBridgeWater.cpp | 3 ++ .../clearFixedSizeTwoBuildingFootprint.cpp | 3 ++ .../collectCliffEdgeTilesForClimbData.cpp | 6 ++-- .../TileMapState/computeClimbRampRotation.cpp | 29 +++++++++------- .../computeWallCornerRenderRotation.cpp | 24 ++++++------- .../Map/TileMapState/createMoatData.cpp | 5 +-- .../Map/TileMapState/destroyWallsOfPlayer.cpp | 6 ---- .../findNearestValidDigTileNearTarget.cpp | 10 +++--- .../Map/TileMapState/getBuildingHurtSFXID.cpp | 3 +- .../getBuildingSizeForCommandBuildingType.cpp | 22 ++++++------ .../getBuildingSizeIndexMappingData.cpp | 1 - .../getMaxWallHeightInBrushArea.cpp | 18 +++++----- .../getRubbleGraphicStageForDamageLevel.cpp | 18 +++++----- .../Map/TileMapState/getTileForBrush.cpp | 2 +- .../increaseHeightForTunnelWithBrush.cpp | 4 +-- .../TileMapState/isCliffDropInDirection.cpp | 4 +-- .../isWallConnectionHeightValid.cpp | 17 ++++------ .../markBuildingFootprintFlag.cpp | 13 ++++--- src/OpenSHC/Map/TileMapState/noop1.cpp | 2 +- .../placeDefensiveStructureTile.cpp | 33 ++++++------------ src/OpenSHC/Map/TileMapState/removeMoat.cpp | 2 +- .../TileMapState/resetHeightAndMapBorders.cpp | 15 ++++---- .../TileMapState/resetTileAndClearMoat.cpp | 2 +- .../TileMapState/resetTileToDefaultState.cpp | 11 +++--- .../rotateFearFactorBuildingVariations.cpp | 13 ++++--- .../Map/TileMapState/setupAllMapSections.cpp | 13 +++---- .../TileMapState/setupLogicalMapBorders.cpp | 6 ++-- .../Map/TileMapState/setupTileMapSections.cpp | 2 +- .../TileMapState/spawnEraserTileEffect.cpp | 6 ++-- .../storeMinAndMaxHeightOfArea.cpp | 14 +++++--- .../Map/TileMapState/swapMoatOwnership.cpp | 10 +++--- .../Map/TileMapState/swapPitchOwnership.cpp | 10 +++--- .../Map/TileMapState/swapWallOwnership.cpp | 34 ++++++++++++------- .../Map/TileMapState/triggerLoweredView.cpp | 4 +-- .../unmarkBuildingFootprintFlag.cpp | 11 +++--- .../updateAreaBasedOnSurrounding.cpp | 3 ++ .../TileMapState/updateGameRelatedValue.cpp | 6 ++-- .../updatePathLinkagesForBuilding.cpp | 10 ++++-- .../Map/TileMapState/updatePitchDitches.cpp | 4 +-- .../updateShowHiLayerOrResetChangedLayer.cpp | 2 +- .../upgradeMapFormatLogicLayer.cpp | 2 +- .../validateWallPlacementAtTile.cpp | 5 +-- 49 files changed, 238 insertions(+), 201 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp index 5d024cc05f..28becf90ab 100644 --- a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp +++ b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp @@ -36,7 +36,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); this->moatTileCount = 0; this->skipPlacementCheck = 0; - this->gateOrientationVariant = 0x50; + this->gateOrientationVariant = 80; this->lastTime = timeGetTime(); this->rockOrientation = 0; this->editorRockType = 0; diff --git a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp index 8fac0d7958..7dc4cb9e63 100644 --- a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp @@ -25,6 +25,9 @@ namespace Map { int size = DAT_LandscapeState::instance.rocks[rockID].size; int surface = (orientation / 2) * size * size; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( index, DAT_LandscapeState::instance.rocks[rockID].size); diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp index 71140eb177..39da7bf574 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp @@ -10,19 +10,22 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FB360 - void TileMapState::clearBuildingDisplayFlagsAndEntities(int buildingID, int param_2) + void TileMapState::clearBuildingDisplayFlagsAndEntities(int buildingID, int destroyEntities) { int buildingSizeTileIndex = 0; int buildingX = DAT_BuildingsState::instance.buildings[buildingID].x; int buildingY = DAT_BuildingsState::instance.buildings[buildingID].y; uint widthOrHeight = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, widthOrHeight); int tileUnk = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + buildingY].addXgetTile + this->buildingX + buildingX; this->MiscDisplayLayer[tileUnk] &= ~0xc; - if (param_2 == 1) { + if (destroyEntities == 1) { MACRO_CALL_MEMBER( OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tileUnk); } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp index c7a71edab2..7296766a3d 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp @@ -25,6 +25,9 @@ namespace Map { void TileMapState::clearBuildingFootprintAndRemoveSiegeTower(int x, int y, int size) { int tileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp index 244dbcbeb5..ce93f3e713 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp @@ -22,6 +22,9 @@ namespace Map { void TileMapState::clearBuildingFootprintAndResetUnits(int x, int y, int size) { int buildingSizeTileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, size); @@ -31,7 +34,7 @@ namespace Map { & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk | L_KEEP_NON_MANOR_HOUSE); if ((this->MiscDisplayLayer[tile] & 0x20) != 0) { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xffdf; + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0x20; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; } int buildingID = this->BuildingLayer[tile]; diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp index f285e422e5..eb0dd6519c 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp @@ -21,6 +21,9 @@ namespace Map { void TileMapState::clearBuildingFootprintWithEdgeRubble(int x, int y, int size) { int buildingSizeTileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, size); @@ -30,7 +33,7 @@ namespace Map { & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk | L_KEEP_NON_MANOR_HOUSE); if ((this->MiscDisplayLayer[tile] & 0x20) != 0) { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xffdf; + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0x20; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; } int buildingID = this->BuildingLayer[tile]; diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp index ba5792665e..5f820c714e 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp @@ -59,7 +59,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFootprintAndResetUnits, this)(x, y, size); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( buildingID, 1); - MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingTilesAndTrees, this)(buildingID, 0x1b); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingTilesAndTrees, this)(buildingID, 27); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::unmarkBuildingFootprintFlag, this)(x, y, 10); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, 10); size = 6; @@ -69,8 +69,8 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingDisplayFlagsAndEntities, this)( buildingID, 1); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingTilesAndTrees, this)(buildingID, 8); - MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::unmarkBuildingFootprintFlag, this)(x, y, 0xb); - MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, 0xb); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::unmarkBuildingFootprintFlag, this)(x, y, 11); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateAreaBasedOnSurrounding, this)(x, y, 11); size = 6; } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType == OpenSHC::Map::Buildings::BT_DRAWBRIDGE) { diff --git a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp index 4f2356f8d3..ae40619962 100644 --- a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp +++ b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp @@ -11,6 +11,9 @@ namespace Map { void TileMapState::clearDrawBridgeWater(int x, int y) { int buildingSizeTileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, 5); diff --git a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp index 83bda1493f..fd25d1bf63 100644 --- a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp @@ -18,6 +18,9 @@ namespace Map { void TileMapState::clearFixedSizeTwoBuildingFootprint(int x, int y) { int buildingSizeTileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, 2); diff --git a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp index aa1eab944e..8e8979c092 100644 --- a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp +++ b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + #include "OpenSHC/Globals/DAT_ClimbLogicDefinedData.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" @@ -18,7 +20,7 @@ namespace Map { void TileMapState::collectCliffEdgeTilesForClimbData() { this->temporaryTerrainTypeIndex = 0; - for (int tile = 0; tile < 80400; tile++) { + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { continue; } @@ -33,7 +35,7 @@ namespace Map { int neighbour = this->directionTranslationMatrix[row][DAT_ClimbLogicDefinedData::instance.field_0x2c[index]] + tile; - if ((this->LogicLayer[neighbour] & L_RIVER) != 0 && this->HeightLayer[neighbour] > height + 0x50) { + if ((this->LogicLayer[neighbour] & L_RIVER) != 0 && this->HeightLayer[neighbour] > height + 80) { this->temporaryTerrainTypeBinaryArray[this->temporaryTerrainTypeIndex] = 0; break; } diff --git a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp index 4eaad9373e..652ff7d91b 100644 --- a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp @@ -40,9 +40,9 @@ namespace Map { } uint rotation; - if (high > heightAt86 + 0x14 && heightAt86 < 0x88) { - if (high > heightAt85 + 0x14 && heightAt85 < 0x88) { - if (high > heightAt84 + 0x14 && heightAt84 < 0x88) { + if (high > heightAt86 + 20 && heightAt86 < 136) { + if (high > heightAt85 + 20 && heightAt85 < 136) { + if (high > heightAt84 + 20 && heightAt84 < 136) { rotation = 5; } else { rotation = 3; @@ -50,24 +50,29 @@ namespace Map { } else { rotation = 1; } - } else if (high > heightAt85 + 0x14 && heightAt85 < 0x88) { - if (high > heightAt86 + 0x14 && heightAt86 < 0x88) { + } else if (high > heightAt85 + 20 && heightAt85 < 136) { + if (high > heightAt86 + 20 && heightAt86 < 136) { rotation = 3; } else { rotation = 2; } - } else if (heightAt86 < 0x88 || heightAt85 < 0x88) { - /* 0 when the tileUnk is not high enough above its neighbour, 5 when it is */ - rotation = (high <= heightAt84 + 0x14) - 1 & 5; + } else if (heightAt86 < 136 || heightAt85 < 136) { + // the original reaches this with a setcc/dec/and, which is how MSVC compiles the + // conditional below + if (high > heightAt84 + 20) { + rotation = 5; + } else { + rotation = 0; + } } else { rotation = 4; } if (this->mapOrientation == 0) { if (rotation == 1) { - this->wallCornerRotation = 0x20 - (x & 0x1f); + this->wallCornerRotation = 32 - (x & 0x1f); } else { - this->wallCornerRotation = 0x20 - (y & 0x1f); + this->wallCornerRotation = 32 - (y & 0x1f); } } else if (this->mapOrientation == 4) { if (rotation == 1) { @@ -78,9 +83,9 @@ namespace Map { } else if (this->mapOrientation == 2) { this->wallCornerRotation = (y & 0x1f) + 1; } else { - this->wallCornerRotation = 0x20 - (y & 0x1f); + this->wallCornerRotation = 32 - (y & 0x1f); } - if ((int)this->wallCornerRotation > 0x1f) { + if ((int)this->wallCornerRotation > 31) { this->wallCornerRotation = 1; } return rotation; diff --git a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp index 83e92d2f92..995fe2738b 100644 --- a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp @@ -19,7 +19,7 @@ namespace Map { if ((x & 0xf) == 0xf) { result = 2; } else { - result = 0x11 - (x & 0xf); + result = 17 - (x & 0xf); } } else if (this->mapOrientation == 4) { if ((x & 0xf) == 0) { @@ -31,13 +31,13 @@ namespace Map { if ((x & 0xf) == 0) { result = 1; } else { - result = (x & 0xf) + 0x11; + result = (x & 0xf) + 17; } } else if (this->mapOrientation == 6) { if ((x & 0xf) == 0xf) { result = 1; } else { - result = 0x20 - (x & 0xf); + result = 32 - (x & 0xf); } } } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)(tileUnk, y, 0) @@ -46,13 +46,13 @@ namespace Map { if ((y & 0xf) == 0xf) { result = 1; } else { - result = 0x20 - (y & 0xf); + result = 32 - (y & 0xf); } } else if (this->mapOrientation == 4) { if ((y & 0xf) == 0) { result = 1; } else { - result = (y & 0xf) + 0x11; + result = (y & 0xf) + 17; } } else if (this->mapOrientation == 6) { if ((y & 0xf) == 0) { @@ -64,20 +64,20 @@ namespace Map { if ((y & 0xf) == 0xf) { result = 2; } else { - result = 0x11 - (y & 0xf); + result = 17 - (y & 0xf); } } } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( tileUnk, y, 2) != 0) { result = 48; + } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( + tileUnk, y, 4) + != 0) { + // the other direction carries a wall too + result = 63; } else { - /* 0x3f when the other direction carries a wall too, 0x21 when it does not */ - result = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( - tileUnk, y, 4) - != 0 - ? 0x3f - : 0x21; + result = 33; } return result; } diff --git a/src/OpenSHC/Map/TileMapState/createMoatData.cpp b/src/OpenSHC/Map/TileMapState/createMoatData.cpp index 30042c5d4d..afac27b36b 100644 --- a/src/OpenSHC/Map/TileMapState/createMoatData.cpp +++ b/src/OpenSHC/Map/TileMapState/createMoatData.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" #include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" @@ -15,10 +16,10 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x005110B0 int TileMapState::createMoatData(undefined4 playerID, uint x, uint y, int filled) { - if (x > 399 || y > 399) { + if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { return 0; } - if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { return 0; } diff --git a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp index 3dd177442d..7af1f6dcff 100644 --- a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp +++ b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp @@ -18,12 +18,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::Map::LogicHelpers::L_CRENEL; - using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; - using OpenSHC::Map::LogicHelpers::L_STAIRS; - using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; - using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - // FUNCTION: STRONGHOLDCRUSADER 0x004F93E0 void TileMapState::destroyWallsOfPlayer(int playerID) { diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp index 06ab5e34a7..eb14fa3e38 100644 --- a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" @@ -14,13 +15,14 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500980 BOOLEnum TileMapState::findNearestValidDigTileNearTarget(uint x1, uint y1, uint x2, uint y2) { - if (x1 > 399 || y1 > 399) { + if (x1 > MC_MAP_XY_LIMIT_INCLUSIVE || y1 > MC_MAP_XY_LIMIT_INCLUSIVE) { return 0; } - if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y1 * 400 + x1] == 0) { + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y1 * MC_MAP_XY_LIMIT + x1] == 0) { return 0; } - if (x2 > 399 || y2 > 399 || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y2 * 400 + x2] == 0) { + if (x2 > MC_MAP_XY_LIMIT_INCLUSIVE || y2 > MC_MAP_XY_LIMIT_INCLUSIVE + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y2 * MC_MAP_XY_LIMIT + x2] == 0) { return 0; } @@ -51,7 +53,7 @@ namespace Map { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, DAT_BuildingsState::ptr)(buildingID); } - if ((int)height >= (int)(targetHeight + 0x10) || (int)height <= (int)(targetHeight - 0x10)) { + if ((int)height >= (int)(targetHeight + 16) || (int)height <= (int)(targetHeight - 16)) { continue; } MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, diff --git a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp index 1fb7d06de6..54f714f1a4 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp @@ -17,7 +17,8 @@ namespace Map { if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == 0) { return 0; } - if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == OpenSHC::Map::Buildings::BLS_REMOVE) { + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState + == OpenSHC::Map::Buildings::BLS_REMOVE) { return 0; } if (DAT_BuildingsState::instance.buildings[buildingID].currentHealth == 0) { diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp index 5862d948e5..3ee68ad635 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp @@ -12,15 +12,13 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FA550 int TileMapState::getBuildingSizeForCommandBuildingType(MappersEnum commandBuildingType) { - /* - The original dispatches through a byte index table at 0x004FA614 (0x147 entries, biased by - M_MAPPER_UNDUGMOAT) into a jump table at 0x004FA5DC, which is what MSVC emits for a dense - switch; Ghidra could not normalise it and rendered the dispatch as a read through an - unnamed pointer array. The case groups below are that byte table, decoded. - - field159_0x5549b8 is written through the global instance, not through this, which is how - the original addresses it. - */ + // The original dispatches through a byte index table at 0x004FA614 (0x147 entries, biased by + // M_MAPPER_UNDUGMOAT) into a jump table at 0x004FA5DC, which is what MSVC emits for a dense + // switch; Ghidra could not normalise it and rendered the dispatch as a read through an + // unnamed pointer array. The case groups below are that byte table, decoded. + // + // field159_0x5549b8 is written through the global instance, not through this, which is how + // the original addresses it. switch (commandBuildingType) { case OpenSHC::Commands::M_MAPPER_FLETCHER: case OpenSHC::Commands::M_MAPPER_HOVEL: @@ -121,15 +119,15 @@ namespace Map { return 1; case OpenSHC::Commands::M_MAPPER_KEEP3: case OpenSHC::Commands::M_MAPPER_APPLEFARM: - return 0xb; + return 11; case OpenSHC::Commands::M_MAPPER_WHEATFARM: case OpenSHC::Commands::M_MAPPER_HOPSFARM: case OpenSHC::Commands::M_MAPPER_CHURCH2: return 9; case OpenSHC::Commands::M_MAPPER_CHURCH3: - return 0xd; + return 13; case OpenSHC::Commands::M_MAPPER_CATTLEFARM: - return 0xa; + return 10; case OpenSHC::Commands::M_MAPPER_UNDUGMOAT: case OpenSHC::Commands::M_MAPPER_DUGMOAT: case OpenSHC::Commands::M_MAPPER_MOAT: diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp index 0912b24d0c..86b6e66bab 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp @@ -28,7 +28,6 @@ namespace Map { this->buildingRotationRelatedValue = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][5]; } - return; } } diff --git a/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp b/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp index 6bb6c92213..e9316c268f 100644 --- a/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp +++ b/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp @@ -8,25 +8,25 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x00502950 - int TileMapState::getMaxWallHeightInBrushArea(int param_1, uint param_2) + int TileMapState::getMaxWallHeightInBrushArea(int tile, uint y) { - int baseTile = param_1; - uint baseY = param_2; + int baseTile = tile; + uint baseY = y; int maxWallHeight = 0; for (int index = 1; index < 5; index++) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( - 1, index, ¶m_1, (int*)¶m_2, baseTile, baseY); - if ((this->LogicLayer[param_1] & L_WALL_OR_GATEHOUSE) == 0) { + 1, index, &tile, (int*)&y, baseTile, baseY); + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { continue; } - if ((this->LogicLayer[param_1] & L_STOCKPILEUnk) != 0) { + if ((this->LogicLayer[tile] & L_STOCKPILEUnk) != 0) { continue; } - if ((this->LogicLayer[param_1] & L_CRENEL) != 0) { + if ((this->LogicLayer[tile] & L_CRENEL) != 0) { continue; } - if (this->HeightLayer[param_1] > maxWallHeight) { - maxWallHeight = this->HeightLayer[param_1]; + if (this->HeightLayer[tile] > maxWallHeight) { + maxWallHeight = this->HeightLayer[tile]; } } return maxWallHeight; diff --git a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp index 190058e1d2..7d7c5b5121 100644 --- a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp +++ b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp @@ -6,13 +6,13 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FA460 undefined4 TileMapState::getRubbleGraphicStageForDamageLevel(int rotation) { - /* the result lives in eax from the start (xor eax, eax), every comparison goes through ecx */ + // the result lives in eax from the start (xor eax, eax), every comparison goes through ecx int result = 0; int orientation = this->mapOrientation; if (orientation == 0) { - if (rotation == 0x50) { + if (rotation == 80) { result = 1; - } else if (rotation == 0x51) { + } else if (rotation == 81) { result = 0; } else if (rotation == 1) { result = 2; @@ -24,9 +24,9 @@ namespace Map { result = 4; } } else if (orientation == 4) { - if (rotation == 0x50) { + if (rotation == 80) { result = 1; - } else if (rotation == 0x51) { + } else if (rotation == 81) { result = 0; } else if (rotation == 1) { result = 4; @@ -38,9 +38,9 @@ namespace Map { result = 2; } } else if (orientation == 2) { - if (rotation == 0x50) { + if (rotation == 80) { result = 0; - } else if (rotation == 0x51) { + } else if (rotation == 81) { result = 1; } else if (rotation == 1) { result = 5; @@ -52,9 +52,9 @@ namespace Map { result = 3; } } else if (orientation == 6) { - if (rotation == 0x50) { + if (rotation == 80) { result = 0; - } else if (rotation == 0x51) { + } else if (rotation == 81) { result = 1; } else if (rotation == 1) { result = 3; diff --git a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp index a97d886cd7..e762019d4d 100644 --- a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp @@ -25,7 +25,7 @@ namespace Map { index = 0; } int brushStep = DAT_TerrainDefinedData::instance.field_0xc[index]; - if (brushStep == 0xf) { + if (brushStep == 15) { return; } if (brushStep < 8) { diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp index 1deea8175e..7df44d5dfd 100644 --- a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp @@ -27,7 +27,7 @@ namespace Map { for (int index = 0; index < 9; index++) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( 0, index, &tile, (int*)&y, baseTile, baseY); - /* a copy the height store cannot alias: the original pushes it without reloading tile */ + // a copy the height store cannot alias: the original pushes it without reloading tile int const brushTile = tile; if ((this->LogicLayer[tile] & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { continue; @@ -42,7 +42,7 @@ namespace Map { continue; } - if ((this->HeightLayer[tile] < 0x10 || this->DefaultHeightLayer[tile] < 0x10) + if ((this->HeightLayer[tile] < 16 || this->DefaultHeightLayer[tile] < 16) && (int)((uint)this->HeightLayer[tile] + increment) >= 0) { this->HeightLayer[tile] = this->HeightLayer[tile] + (char)increment; } diff --git a/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp b/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp index b780f960b1..acad647feb 100644 --- a/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp @@ -4,11 +4,11 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FC7C0 - BOOLEnum TileMapState::isCliffDropInDirection(int tileUnk, undefined4 param_2, int y) + BOOLEnum TileMapState::isCliffDropInDirection(int tileUnk, undefined4 unused, int y) { int direction = (this->screenSouthEastDirection + 4) % 8; return this->HeightLayer[tileUnk] - > this->HeightLayer[this->directionTranslationMatrix[y][direction] + tileUnk] + 0x14; + > this->HeightLayer[this->directionTranslationMatrix[y][direction] + tileUnk] + 20; } } diff --git a/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp b/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp index 0decdfcc1d..6868964b39 100644 --- a/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp +++ b/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp @@ -8,26 +8,23 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; - using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; // FUNCTION: STRONGHOLDCRUSADER 0x004F8840 - BOOLEnum TileMapState::isWallConnectionHeightValid(int tile, int y, int param_3) + BOOLEnum TileMapState::isWallConnectionHeightValid(int tile, int y, int direction) { int tileHeight = this->HeightLayer[tile]; int firstDirection = 0; int secondDirection = 0; - if (param_3 == 0) { + if (direction == 0) { secondDirection = 4; - } else if (param_3 == 2) { + } else if (direction == 2) { firstDirection = 2; secondDirection = 6; - } else if (param_3 == 4) { + } else if (direction == 4) { firstDirection = 0; - secondDirection = param_3; - } else if (param_3 == 6) { + secondDirection = direction; + } else if (direction == 6) { firstDirection = 2; secondDirection = 6; } @@ -39,7 +36,7 @@ namespace Map { if ((this->LogicLayer[first] & L_STOCKPILEUnk) != 0) { return FALSE; } - int minHeight = tileHeight - 0x10; + int minHeight = tileHeight - 16; if (this->HeightLayer[first] < minHeight && this->DamageLayer[first] == 0) { return FALSE; } diff --git a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp index 3d00eac4c9..7dc704306a 100644 --- a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp @@ -8,17 +8,20 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_PLAIN1_AND_FARM; // FUNCTION: STRONGHOLDCRUSADER 0x004FA9D0 - void TileMapState::markBuildingFootprintFlag(int param_1, int param_2, int param_3) + void TileMapState::markBuildingFootprintFlag(int x, int y, int buildingSize) { int buildingSizeTileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( - buildingSizeTileIndex, param_3); + buildingSizeTileIndex, buildingSize); buildingSizeTileIndex++; - int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + param_2].addXgetTile - + this->buildingX + param_1; + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; this->LogicLayer[tile] = this->LogicLayer[tile] | L_PLAIN1_AND_FARM; - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xfff3; + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0xc; } while (buildingSizeTileIndex < this->constructionTileCount); } diff --git a/src/OpenSHC/Map/TileMapState/noop1.cpp b/src/OpenSHC/Map/TileMapState/noop1.cpp index ea3d3f93c3..cc1385e676 100644 --- a/src/OpenSHC/Map/TileMapState/noop1.cpp +++ b/src/OpenSHC/Map/TileMapState/noop1.cpp @@ -4,7 +4,7 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F70D0 - void TileMapState::noop1(undefined4 param_1) { return; } + void TileMapState::noop1(undefined4 unused) {} } } diff --git a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp index 5739af1938..962493cc00 100644 --- a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp +++ b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp @@ -26,17 +26,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::Map::LogicHelpers::L_BOULDERS; - using OpenSHC::Map::LogicHelpers::L_CRENEL; - using OpenSHC::Map::LogicHelpers::L_CRENEL_VARIATIONUnk; - using OpenSHC::Map::LogicHelpers::L_IRON; - using OpenSHC::Map::LogicHelpers::L_PEBBLES; - using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; - using OpenSHC::Map::LogicHelpers::L_STAIRS; - using OpenSHC::Map::LogicHelpers::L_TREE; - using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; - using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::Commands::MappersEnum; using OpenSHC::WindowsHelper::Enums::BOOLEnum; @@ -53,13 +42,13 @@ namespace Map { this->DamageLayer[tile] = 0; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; if (command == OpenSHC::Commands::M_MAPPER_WALL) { - this->HeightLayer[tile] = this->DefaultHeightLayer[tile] + 0x5a; + this->HeightLayer[tile] = this->DefaultHeightLayer[tile] + 90; } else if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { - this->HeightLayer[tile] = this->DefaultHeightLayer[tile] + 0x3c; + this->HeightLayer[tile] = this->DefaultHeightLayer[tile] + 60; } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL; - this->HeightLayer[tile] = this->HeightLayer[tile] + 0x62; - /* a crenel on an odd tile of one axis carries the alternate variation */ + this->HeightLayer[tile] = this->HeightLayer[tile] + 98; + // a crenel on an odd tile of one axis carries the alternate variation if ((int)(x & 1) == 1 && (y & 1) == 0) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; } else if ((int)(x & 1) == 0 && (y & 1) == 1) { @@ -67,7 +56,7 @@ namespace Map { } } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL2) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL; - this->HeightLayer[tile] = this->HeightLayer[tile] + 0x44; + this->HeightLayer[tile] = this->HeightLayer[tile] + 68; if ((int)(x & 1) == 1 && (y & 1) == 0) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; } else if ((int)(x & 1) == 0 && (y & 1) == 1) { @@ -75,19 +64,19 @@ namespace Map { } } else if (command == OpenSHC::Commands::M_MAPPER_STAIR1) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 0x50; + this->HeightLayer[tile] = this->HeightLayer[tile] + 80; } else if (command == OpenSHC::Commands::M_MAPPER_STAIR2) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 0x40; + this->HeightLayer[tile] = this->HeightLayer[tile] + 64; } else if (command == OpenSHC::Commands::M_MAPPER_STAIR3) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 0x30; + this->HeightLayer[tile] = this->HeightLayer[tile] + 48; } else if (command == OpenSHC::Commands::M_MAPPER_STAIR4) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 0x20; + this->HeightLayer[tile] = this->HeightLayer[tile] + 32; } else if (command == OpenSHC::Commands::M_MAPPER_STAIR5) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 0x10; + this->HeightLayer[tile] = this->HeightLayer[tile] + 16; } this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_UNKNOWN_WALL_RELATED | L_BOULDERS | L_PEBBLES | L_IRON) @@ -105,7 +94,7 @@ namespace Map { if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_UNKNOWN_WALL_RELATED; } - this->WallOwnerLayer[tile] = this->WallOwnerLayer[tile] & 0xf8 | (char)playerID - 1U; + this->WallOwnerLayer[tile] = this->WallOwnerLayer[tile] & ~7 | (char)playerID - 1U; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)(y, tile); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoat, this)(tile); diff --git a/src/OpenSHC/Map/TileMapState/removeMoat.cpp b/src/OpenSHC/Map/TileMapState/removeMoat.cpp index 63d55eb057..c365b350a0 100644 --- a/src/OpenSHC/Map/TileMapState/removeMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/removeMoat.cpp @@ -15,7 +15,7 @@ namespace Map { using OpenSHC::WindowsHelper::Enums::BOOLEnum; // FUNCTION: STRONGHOLDCRUSADER 0x005113F0 - BOOLEnum TileMapState::removeMoat(uint moatID, int param_2) + BOOLEnum TileMapState::removeMoat(uint moatID, int unused) { this->moats[moatID].fillProgress = this->moats[moatID].fillProgress - 1; // nested form: the original keeps the FALSE return as the trailing block diff --git a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp index b0bc40a819..d6d3dafaca 100644 --- a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp +++ b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp @@ -1,7 +1,7 @@ #include "../TileMapState.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" @@ -23,10 +23,10 @@ namespace Map { this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_BORDER | L_BORDER_EDGE); } - /* the two outer diagonals of the diamond carry the border flags */ + // the two outer diagonals of the diamond carry the border flags int rowLength = 0; int tile = 0; - do { + for (; rowLength < MC_MAP_XY_LIMIT; rowLength = rowLength + 2) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_BORDER; tile++; if (rowLength > 0) { @@ -37,11 +37,10 @@ namespace Map { this->LogicLayer[tile - 1] = L_BORDER_EDGE; } this->LogicLayer[tile] = L_BORDER; - rowLength = rowLength + 2; tile++; - } while (rowLength < MC_MAP_XY_LIMIT); + } - for (rowLength = 398; rowLength >= 0; rowLength = rowLength - 2) { + for (rowLength = MC_MAP_XY_LIMIT - 2; rowLength >= 0; rowLength = rowLength - 2) { this->LogicLayer[tile] = L_BORDER; tile++; if (rowLength > 0) { @@ -55,7 +54,7 @@ namespace Map { tile++; } - /* and again inset by (400 - mapSize) / 2 for a map smaller than the full diamond */ + // and again inset by (400 - mapSize) / 2 for a map smaller than the full diamond int row = 0; tile = 0; for (int skipped = 0; skipped < inset; skipped++) { @@ -95,7 +94,7 @@ namespace Map { DAT_PathFindingState::ptr)(); } - /* every border tile ends up at the minimum height */ + // every border tile ends up at the minimum height for (int borderTile = 0; borderTile < MC_MAP_TILES_COUNT; borderTile++) { if ((this->LogicLayer[borderTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { this->HeightLayer[borderTile] = 8; diff --git a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp index 43aa6cd9eb..228a4a803d 100644 --- a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp @@ -53,7 +53,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)(x, y); this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_MOAT | L_MOAT_DUG_OR_PLANNED); } - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xfc3f; + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0x3c0; } } diff --git a/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp b/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp index 4d7aa9e32c..bb053e399e 100644 --- a/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp +++ b/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp @@ -16,15 +16,14 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004F81D0 - void TileMapState::resetTileToDefaultState(int param_1, uint param_2, uint param_3) + void TileMapState::resetTileToDefaultState(int tile, uint x, uint y) { - this->LogicLayer[param_1] = this->LogicLayer[param_1] + this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); - this->HeightLayer[param_1] = this->DefaultHeightLayer[param_1]; - MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)( - param_1); + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tile); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, - DAT_PathFindingState::ptr)(5, param_2, param_3); + DAT_PathFindingState::ptr)(5, x, y); } } diff --git a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp index bf4a5b4bc2..f4f32ac1d8 100644 --- a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp +++ b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp @@ -12,11 +12,9 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F8300 void TileMapState::rotateFearFactorBuildingVariations() { - /* - currentMapperCommand is reached through the global instance's absolute address, and the - switch below is the original's byte table at 0x004F847C into the jump table at 0x004F8454, - biased by M_MAPPER_GARDEN1. The "- 1 & 6" forms are the original's setcc/dec/and idiom. - */ + // currentMapperCommand is reached through the global instance's absolute address, and the + // switch below is the original's byte table at 0x004F847C into the jump table at 0x004F8454, + // biased by M_MAPPER_GARDEN1. The "- 1 & 6" forms are the original's setcc/dec/and idiom. DWORD now = timeGetTime(); if (this->editorRockType == 5) { if (this->rockOrientation == 0) { @@ -32,7 +30,7 @@ namespace Map { } this->lastTime = now; - this->gateOrientationVariant = (this->gateOrientationVariant == 0x50) + 0x50; + this->gateOrientationVariant = (this->gateOrientationVariant == 80) + 80; if (this->editorRockType == 0) { if (this->rockOrientation == 0) { this->rockOrientation = 2; @@ -63,7 +61,8 @@ namespace Map { case OpenSHC::Commands::M_MAPPER_SHRINE1: case OpenSHC::Commands::M_MAPPER_POND1: case OpenSHC::Commands::M_MAPPER_POND3_LARGE1: - DAT_TileMapState::instance.currentMapperCommand = (MappersEnum)(DAT_TileMapState::instance.currentMapperCommand + OpenSHC::Commands::M_MAPPER_AREA); + DAT_TileMapState::instance.currentMapperCommand + = (MappersEnum)(DAT_TileMapState::instance.currentMapperCommand + OpenSHC::Commands::M_MAPPER_AREA); return; case OpenSHC::Commands::M_MAPPER_GARDEN6: DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_GARDEN1; diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp index 1049b14fbb..6070370e52 100644 --- a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -12,6 +12,7 @@ #include "OpenSHC/Map/Units/UnitsState.func.hpp" #include "OpenSHC/Rendering/ViewportRenderState.func.hpp" #include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_AICState.hpp" @@ -57,8 +58,8 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupLogicalMapBorders, this)(); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateShowHiLayerOrResetChangedLayer, this)(); - /* the border tiles get their own graphic, everything else the plain one */ - for (int tile = 0; tile < 80400; tile += 6) { + // the border tiles get their own graphic, everything else the plain one + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile += 6) { for (int i = 0; i < 6; i++) { if (this->LogicLayer[tile + i] == L_BORDER) { this->GfxLayer[tile + i] = (ushort)GMFirstPictureIndex::instance[2]; @@ -71,14 +72,14 @@ namespace Map { } MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ShortValue, DAT_LowLevelMemory::ptr)( - 80400, 1, this->PillarGFXLayer); + MC_MAP_TILES_COUNT, 1, this->PillarGFXLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - 80400, '\b', this->HeightLayer); + sizeof(this->HeightLayer), '\b', this->HeightLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - 80400, '\b', this->DefaultHeightLayer); + sizeof(this->DefaultHeightLayer), '\b', this->DefaultHeightLayer); DAT_PathFindingState::instance.searchGeneration = 1; MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - 160800, '\0', DAT_TileMapState::instance.WalkLayer); + sizeof(DAT_TileMapState::instance.WalkLayer), '\0', DAT_TileMapState::instance.WalkLayer); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::setChangedLayerZeroBasedOn40x40Layer, DAT_PathFindingState::ptr)(0); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateLogicalTileMapRelatedSections, this)(); diff --git a/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp b/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp index f5dd47d0de..35ef2a57ab 100644 --- a/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp +++ b/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + namespace OpenSHC { namespace Map { @@ -11,7 +13,7 @@ namespace Map { { int rowWidth = 0; int index = 0; - for (; rowWidth < 400; rowWidth += 2) { + for (; rowWidth < MC_MAP_XY_LIMIT; rowWidth += 2) { this->LogicLayer[index] = L_BORDER; index++; if (rowWidth > 0) { @@ -24,7 +26,7 @@ namespace Map { this->LogicLayer[index] = L_BORDER; index++; } - for (rowWidth = 398;rowWidth >= 0; rowWidth -= 2) { + for (rowWidth = MC_MAP_XY_LIMIT - 2; rowWidth >= 0; rowWidth -= 2) { this->LogicLayer[index] = L_BORDER; index++; if (rowWidth > 0) { diff --git a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp index 6047a48d28..7d54b26763 100644 --- a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp @@ -1,8 +1,8 @@ #include "../TileMapState.func.hpp" #include "OpenSHC/IO/LowLevelMemory.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" #include "OpenSHC/Globals/SEC_RNG.hpp" diff --git a/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp b/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp index 0c718871c6..e8292afce8 100644 --- a/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp +++ b/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp @@ -23,11 +23,11 @@ namespace Map { using OpenSHC::Map::Entities::EntityType; // FUNCTION: STRONGHOLDCRUSADER 0x004F9F00 - void TileMapState::spawnEraserTileEffect(undefined4 param_1, int tile) + void TileMapState::spawnEraserTileEffect(undefined4 unused, int tile) { uint y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & 0xfbff; + this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0x400; if (this->UnitLayer[tile] != 0) { return; } @@ -45,7 +45,7 @@ namespace Map { int microY = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile] * 8; MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, 0, 0, microX, microY, DAT_TileMapState::instance.DefaultHeightLayer[tile], microX + 1, microY + 1, - DAT_TileMapState::instance.DefaultHeightLayer[tile], (EntityType)0x1e, 0); + DAT_TileMapState::instance.DefaultHeightLayer[tile], (EntityType)30, 0); // EntityType 30 has no name yet this->BuildingWasLayer[tile] = 0; this->DamageLayer[tile] = 0; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, diff --git a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp index 5cc0b11423..1b69ed42fd 100644 --- a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp +++ b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" namespace OpenSHC { @@ -10,21 +12,25 @@ namespace Map { { this->buildingMinHeight = 1000; this->buildingMaxHeight = 0; - if (x > 399 || y > 399) { + if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { return; } - if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { return; } int buildingSizeTileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingWidthAndHeight); uint footprintY = this->buildingY + y; uint footprintX = this->buildingX + x; - if (footprintX <= 399 && footprintY <= 399 - && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[footprintY * 400 + footprintX] != 0) { + if (footprintX <= MC_MAP_XY_LIMIT_INCLUSIVE && footprintY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[footprintY * MC_MAP_XY_LIMIT + footprintX] + != 0) { uint height = this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[footprintY].addXgetTile + this->buildingX + x]; diff --git a/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp index d94c0b2e1a..e5b859cfd0 100644 --- a/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp @@ -4,16 +4,16 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500790 - void TileMapState::swapMoatOwnership(int param_1, int param_2) + void TileMapState::swapMoatOwnership(int playerID, int otherPlayerID) { for (int moatID = 1; moatID < 16000; moatID++) { if (this->moats[moatID].owner == 0) { continue; } - if (this->moats[moatID].owner == param_1) { - this->moats[moatID].owner = (char)param_2; - } else if (this->moats[moatID].owner == param_2) { - this->moats[moatID].owner = (char)param_1; + if (this->moats[moatID].owner == playerID) { + this->moats[moatID].owner = (char)otherPlayerID; + } else if (this->moats[moatID].owner == otherPlayerID) { + this->moats[moatID].owner = (char)playerID; } } } diff --git a/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp index e53a5e4462..e20678f099 100644 --- a/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp @@ -4,16 +4,16 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500940 - void TileMapState::swapPitchOwnership(int param_1, int param_2) + void TileMapState::swapPitchOwnership(int playerID, int otherPlayerID) { for (int pitchDitchID = 1; pitchDitchID < 4000; pitchDitchID++) { if (this->pitchDitches[pitchDitchID].owner == 0) { continue; } - if (this->pitchDitches[pitchDitchID].owner == param_1) { - this->pitchDitches[pitchDitchID].owner = (short)param_2; - } else if (this->pitchDitches[pitchDitchID].owner == param_2) { - this->pitchDitches[pitchDitchID].owner = (short)param_1; + if (this->pitchDitches[pitchDitchID].owner == playerID) { + this->pitchDitches[pitchDitchID].owner = (short)otherPlayerID; + } else if (this->pitchDitches[pitchDitchID].owner == otherPlayerID) { + this->pitchDitches[pitchDitchID].owner = (short)playerID; } } } diff --git a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp index 42f9c13e46..682fdd6e22 100644 --- a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + namespace OpenSHC { namespace Map { @@ -8,47 +10,53 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F9220 void TileMapState::swapWallOwnership(int playerID, int otherPlayerID) { - for (int tileUnk = 0; tileUnk < 80400; tileUnk += 6) { + for (int tileUnk = 0; tileUnk < MC_MAP_TILES_COUNT; tileUnk += 6) { if ((this->LogicLayer[tileUnk + 0] & L_WALL_OR_GATEHOUSE) != 0) { if ((this->WallOwnerLayer[tileUnk + 0] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 0] = this->WallOwnerLayer[tileUnk + 0] & 0xf8 | (char)otherPlayerID - 1U; + this->WallOwnerLayer[tileUnk + 0] + = this->WallOwnerLayer[tileUnk + 0] & ~7 | (char)otherPlayerID - 1U; } else if ((this->WallOwnerLayer[tileUnk + 0] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 0] = this->WallOwnerLayer[tileUnk + 0] & 0xf8 | (char)playerID - 1U; + this->WallOwnerLayer[tileUnk + 0] = this->WallOwnerLayer[tileUnk + 0] & ~7 | (char)playerID - 1U; } } if ((this->LogicLayer[tileUnk + 1] & L_WALL_OR_GATEHOUSE) != 0) { if ((this->WallOwnerLayer[tileUnk + 1] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 1] = this->WallOwnerLayer[tileUnk + 1] & 0xf8 | (char)otherPlayerID - 1U; + this->WallOwnerLayer[tileUnk + 1] + = this->WallOwnerLayer[tileUnk + 1] & ~7 | (char)otherPlayerID - 1U; } else if ((this->WallOwnerLayer[tileUnk + 1] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 1] = this->WallOwnerLayer[tileUnk + 1] & 0xf8 | (char)playerID - 1U; + this->WallOwnerLayer[tileUnk + 1] = this->WallOwnerLayer[tileUnk + 1] & ~7 | (char)playerID - 1U; } } if ((this->LogicLayer[tileUnk + 2] & L_WALL_OR_GATEHOUSE) != 0) { if ((this->WallOwnerLayer[tileUnk + 2] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 2] = this->WallOwnerLayer[tileUnk + 2] & 0xf8 | (char)otherPlayerID - 1U; + this->WallOwnerLayer[tileUnk + 2] + = this->WallOwnerLayer[tileUnk + 2] & ~7 | (char)otherPlayerID - 1U; } else if ((this->WallOwnerLayer[tileUnk + 2] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 2] = this->WallOwnerLayer[tileUnk + 2] & 0xf8 | (char)playerID - 1U; + this->WallOwnerLayer[tileUnk + 2] = this->WallOwnerLayer[tileUnk + 2] & ~7 | (char)playerID - 1U; } } if ((this->LogicLayer[tileUnk + 3] & L_WALL_OR_GATEHOUSE) != 0) { if ((this->WallOwnerLayer[tileUnk + 3] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 3] = this->WallOwnerLayer[tileUnk + 3] & 0xf8 | (char)otherPlayerID - 1U; + this->WallOwnerLayer[tileUnk + 3] + = this->WallOwnerLayer[tileUnk + 3] & ~7 | (char)otherPlayerID - 1U; } else if ((this->WallOwnerLayer[tileUnk + 3] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 3] = this->WallOwnerLayer[tileUnk + 3] & 0xf8 | (char)playerID - 1U; + this->WallOwnerLayer[tileUnk + 3] = this->WallOwnerLayer[tileUnk + 3] & ~7 | (char)playerID - 1U; } } if ((this->LogicLayer[tileUnk + 4] & L_WALL_OR_GATEHOUSE) != 0) { if ((this->WallOwnerLayer[tileUnk + 4] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 4] = this->WallOwnerLayer[tileUnk + 4] & 0xf8 | (char)otherPlayerID - 1U; + this->WallOwnerLayer[tileUnk + 4] + = this->WallOwnerLayer[tileUnk + 4] & ~7 | (char)otherPlayerID - 1U; } else if ((this->WallOwnerLayer[tileUnk + 4] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 4] = this->WallOwnerLayer[tileUnk + 4] & 0xf8 | (char)playerID - 1U; + this->WallOwnerLayer[tileUnk + 4] = this->WallOwnerLayer[tileUnk + 4] & ~7 | (char)playerID - 1U; } } if ((this->LogicLayer[tileUnk + 5] & L_WALL_OR_GATEHOUSE) != 0) { if ((this->WallOwnerLayer[tileUnk + 5] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 5] = this->WallOwnerLayer[tileUnk + 5] & 0xf8 | (char)otherPlayerID - 1U; + this->WallOwnerLayer[tileUnk + 5] + = this->WallOwnerLayer[tileUnk + 5] & ~7 | (char)otherPlayerID - 1U; } else if ((this->WallOwnerLayer[tileUnk + 5] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 5] = this->WallOwnerLayer[tileUnk + 5] & 0xf8 | (char)playerID - 1U; + this->WallOwnerLayer[tileUnk + 5] = this->WallOwnerLayer[tileUnk + 5] & ~7 | (char)playerID - 1U; } } } diff --git a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp index 1180855365..6216277e9d 100644 --- a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp +++ b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp @@ -13,11 +13,11 @@ namespace Map { using OpenSHC::Map::Units::UnitType; // FUNCTION: STRONGHOLDCRUSADER 0x004F6FD0 - void TileMapState::triggerLoweredView(int param_1) + void TileMapState::triggerLoweredView(int requestedView) { int view = 2; if (this->flatViewToggleValue2 == 0) { - view = param_1; + view = requestedView; } if (this->refreshCertainTileMap_old == view) { return; diff --git a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp index f4994b2580..52eba288e2 100644 --- a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp @@ -8,15 +8,18 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_PLAIN1_AND_FARM; // FUNCTION: STRONGHOLDCRUSADER 0x004FAD20 - void TileMapState::unmarkBuildingFootprintFlag(int param_1, int param_2, int param_3) + void TileMapState::unmarkBuildingFootprintFlag(int x, int y, int buildingSize) { int buildingSizeTileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( - buildingSizeTileIndex, param_3); + buildingSizeTileIndex, buildingSize); buildingSizeTileIndex++; - int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + param_2].addXgetTile - + this->buildingX + param_1; + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; this->LogicLayer[tile] = this->LogicLayer[tile] & ~L_PLAIN1_AND_FARM; } while (buildingSizeTileIndex < this->constructionTileCount); } diff --git a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp index 6cb6e376a0..73847b9c67 100644 --- a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp +++ b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp @@ -15,6 +15,9 @@ namespace Map { int area = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findAccessibleAreaNearBuildingLocation, DAT_BuildingsState::ptr)(x, y, buildingSize); + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); diff --git a/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp b/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp index 905e51d09e..b0bc0f79b9 100644 --- a/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp +++ b/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp @@ -15,15 +15,15 @@ namespace Map { return; } - if (DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown == 0x28) { + if (DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown == 40) { this->field_0x554a10 = -1; } DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown - 1; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setSignpostDistanceForCampaignMission, this)(); - int signpostDistance = ((0x28 - DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown) + int signpostDistance = ((40 - DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown) * DAT_GameState::instance.mapAndTime.unk_signpostDistance) - / 0x28; + / 40; if (signpostDistance == this->field_0x554a10) { return; } diff --git a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp index a90edaa412..1857f62b69 100644 --- a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp @@ -16,15 +16,19 @@ namespace Map { void TileMapState::updatePathLinkagesForBuilding(int buildingID) { int buildingSizeTileIndex = 0; + // do-while, not a for loop: the bound is this->constructionTileCount, which the + // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first + // iteration would read the count of the previous footprint. do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); int tileUnk = DAT_ViewportRenderState::instance - .translationMatrix[DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY] - .addXgetTile + .translationMatrix[DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY] + .addXgetTile + DAT_BuildingsState::instance.buildings[buildingID].x + this->buildingX; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, - DAT_PathFindingState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY, tileUnk); + DAT_PathFindingState::ptr)( + DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY, tileUnk); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoat, this)(tileUnk); buildingSizeTileIndex++; } while (buildingSizeTileIndex < this->constructionTileCount); diff --git a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp index 3fde39dae9..1879f67d4c 100644 --- a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp @@ -32,7 +32,7 @@ namespace Map { if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) == 0 || this->pitchDitches[id].state == -1) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::destroyPitchDitch, this)(id); } else if (this->pitchDitches[id].state == 0) { - /* the original increments the state rather than storing the literal */ + // the original increments the state rather than storing the literal this->pitchDitches[id].state = this->pitchDitches[id].state + 1; this->pitchDitches[id].field_0x12 = 0; } else if (this->pitchDitches[id].state == 2) { @@ -41,7 +41,7 @@ namespace Map { this->pitchDitches[id].state = this->pitchDitches[id].state + 1; this->pitchDitches[id].field_0x12 = 0; uint height = DAT_TileMapState::instance.HeightLayer[tile]; - /* the fire spreads to the four adjacent ditches that are still unlit */ + // the fire spreads to the four adjacent ditches that are still unlit for (int i = 0; i < 4; i++) { int neighbour = DAT_ViewportRenderState::instance .translationMatrix[this->pitchDitches[id].y diff --git a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp index 404e028aa7..b3bab6cf44 100644 --- a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp @@ -19,7 +19,7 @@ namespace Map { this->refreshRelatedOne = 0; for (int row = 0; row < 256; row++) { int target = ((uint)row >> 2) + 1; - /* the pull-down eases towards the target in steps that shrink as it gets closer */ + // the pull-down eases towards the target in steps that shrink as it gets closer int step; if (this->refreshCertainTileMap == 3) { step = this->heightBasedScreenYOffset[row] - target; diff --git a/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp b/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp index 37848d246b..822be6a0c6 100644 --- a/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp @@ -1,7 +1,7 @@ #include "../TileMapState.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Map/Version.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" namespace OpenSHC { namespace Map { diff --git a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp index 49c6494d7f..fb3a999d3c 100644 --- a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp @@ -26,7 +26,7 @@ namespace Map { using OpenSHC::WindowsHelper::Enums::BOOLEnum; // FUNCTION: STRONGHOLDCRUSADER 0x004F94A0 - void TileMapState::validateWallPlacementAtTile(int playerID, uint x, uint y, short param_4) + void TileMapState::validateWallPlacementAtTile(int playerID, uint x, uint y, short mapperCommand) { this->illegalBuild = TRUE; int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; @@ -60,7 +60,8 @@ namespace Map { if (this->UnitLayer[tile] != 0 && (this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { int const unitID = (short)this->UnitLayer[tile]; - if (param_4 == OpenSHC::Commands::M_MAPPER_CRENAL || param_4 == OpenSHC::Commands::M_MAPPER_CRENAL2) { + if (mapperCommand == OpenSHC::Commands::M_MAPPER_CRENAL + || mapperCommand == OpenSHC::Commands::M_MAPPER_CRENAL2) { DAT_UnitsState::instance.units[unitID].logicalState = OpenSHC::Map::Units::ULS_REMOVE; } } From 5de5096a6056c6e3cce50e1a7cecc920304760ee Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 7 Nov 2026 20:06:55 +0100 Subject: [PATCH 08/28] style(TileMapState): write the footprint loops as while (true) with a break The twelve footprint loops test this->constructionTileCount, which the getBuildingSizeIndexMappingData call in the body sets, so the test has to stay at the end of the body. Writing that as while (true) with a trailing break instead of do-while is codegen-neutral: all 88 functions measure identical to the previous commit. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- .../TileMapState/applyRockGraphicsToFootprint.cpp | 12 +++++++----- .../clearBuildingDisplayFlagsAndEntities.cpp | 12 +++++++----- .../clearBuildingFootprintAndRemoveSiegeTower.cpp | 12 +++++++----- .../clearBuildingFootprintAndResetUnits.cpp | 12 +++++++----- .../clearBuildingFootprintWithEdgeRubble.cpp | 12 +++++++----- .../Map/TileMapState/clearDrawBridgeWater.cpp | 12 +++++++----- .../clearFixedSizeTwoBuildingFootprint.cpp | 12 +++++++----- .../Map/TileMapState/markBuildingFootprintFlag.cpp | 12 +++++++----- .../Map/TileMapState/storeMinAndMaxHeightOfArea.cpp | 12 +++++++----- .../Map/TileMapState/unmarkBuildingFootprintFlag.cpp | 12 +++++++----- .../TileMapState/updateAreaBasedOnSurrounding.cpp | 12 +++++++----- .../TileMapState/updatePathLinkagesForBuilding.cpp | 12 +++++++----- 12 files changed, 84 insertions(+), 60 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp index 7dc4cb9e63..3380a30fbc 100644 --- a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp @@ -25,10 +25,9 @@ namespace Map { int size = DAT_LandscapeState::instance.rocks[rockID].size; int surface = (orientation / 2) * size * size; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( index, DAT_LandscapeState::instance.rocks[rockID].size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + rockY].addXgetTile + rockX @@ -55,7 +54,10 @@ namespace Map { } } index++; - } while (index < this->constructionTileCount); + if (index >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp index 39da7bf574..879f4aecca 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp @@ -16,10 +16,9 @@ namespace Map { int buildingX = DAT_BuildingsState::instance.buildings[buildingID].x; int buildingY = DAT_BuildingsState::instance.buildings[buildingID].y; uint widthOrHeight = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, widthOrHeight); int tileUnk = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + buildingY].addXgetTile @@ -30,7 +29,10 @@ namespace Map { OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tileUnk); } buildingSizeTileIndex++; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp index 7296766a3d..b37f2c04b3 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp @@ -25,10 +25,9 @@ namespace Map { void TileMapState::clearBuildingFootprintAndRemoveSiegeTower(int x, int y, int size) { int tileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; @@ -45,7 +44,10 @@ namespace Map { DAT_UnitsState::instance.units[unitID].state.generic = OpenSHC::Map::Units::States::US_DISAPPEAR; } tileIndex++; - } while (tileIndex < this->constructionTileCount); + if (tileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp index ce93f3e713..801f2304e9 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp @@ -22,10 +22,9 @@ namespace Map { void TileMapState::clearBuildingFootprintAndResetUnits(int x, int y, int size) { int buildingSizeTileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile @@ -55,7 +54,10 @@ namespace Map { } buildingSizeTileIndex++; this->ChangedLayer[tile] = 2; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp index eb0dd6519c..a8396a0262 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp @@ -21,10 +21,9 @@ namespace Map { void TileMapState::clearBuildingFootprintWithEdgeRubble(int x, int y, int size) { int buildingSizeTileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile @@ -49,7 +48,10 @@ namespace Map { } buildingSizeTileIndex++; this->ChangedLayer[tile] = 2; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp index ae40619962..ccbb62a454 100644 --- a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp +++ b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp @@ -11,10 +11,9 @@ namespace Map { void TileMapState::clearDrawBridgeWater(int x, int y) { int buildingSizeTileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, 5); int targetedTile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile @@ -31,7 +30,10 @@ namespace Map { buildingSizeTileIndex++; this->BuildingWasLayer[targetedTile] = 0; this->ChangedLayer[targetedTile] = 2; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp index fd25d1bf63..2ad62bdffb 100644 --- a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp @@ -18,10 +18,9 @@ namespace Map { void TileMapState::clearFixedSizeTwoBuildingFootprint(int x, int y) { int buildingSizeTileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, 2); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile @@ -38,7 +37,10 @@ namespace Map { } buildingSizeTileIndex++; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp index 7dc704306a..d474904a26 100644 --- a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp @@ -11,10 +11,9 @@ namespace Map { void TileMapState::markBuildingFootprintFlag(int x, int y, int buildingSize) { int buildingSizeTileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); buildingSizeTileIndex++; @@ -22,7 +21,10 @@ namespace Map { + this->buildingX + x; this->LogicLayer[tile] = this->LogicLayer[tile] | L_PLAIN1_AND_FARM; this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0xc; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp index 1b69ed42fd..2cea0a2798 100644 --- a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp +++ b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp @@ -20,10 +20,9 @@ namespace Map { } int buildingSizeTileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingWidthAndHeight); uint footprintY = this->buildingY + y; @@ -42,7 +41,10 @@ namespace Map { } } buildingSizeTileIndex++; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp index 52eba288e2..e88ef93d58 100644 --- a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp @@ -11,17 +11,19 @@ namespace Map { void TileMapState::unmarkBuildingFootprintFlag(int x, int y, int buildingSize) { int buildingSizeTileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); buildingSizeTileIndex++; int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; this->LogicLayer[tile] = this->LogicLayer[tile] & ~L_PLAIN1_AND_FARM; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp index 73847b9c67..57eb546f36 100644 --- a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp +++ b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp @@ -15,10 +15,9 @@ namespace Map { int area = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findAccessibleAreaNearBuildingLocation, DAT_BuildingsState::ptr)(x, y, buildingSize); - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); int tileUnk = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile @@ -27,7 +26,10 @@ namespace Map { this->PathConnectionLayer[tileUnk] = (ushort)area; } buildingSizeTileIndex++; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } } } diff --git a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp index 1857f62b69..2db6cf76cc 100644 --- a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp @@ -16,10 +16,9 @@ namespace Map { void TileMapState::updatePathLinkagesForBuilding(int buildingID) { int buildingSizeTileIndex = 0; - // do-while, not a for loop: the bound is this->constructionTileCount, which the - // getBuildingSizeIndexMappingData call in the body sets. Testing it before the first - // iteration would read the count of the previous footprint. - do { + // the bound is set by the getBuildingSizeIndexMappingData call in the body, + // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); int tileUnk = DAT_ViewportRenderState::instance @@ -31,7 +30,10 @@ namespace Map { DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY, tileUnk); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoat, this)(tileUnk); buildingSizeTileIndex++; - } while (buildingSizeTileIndex < this->constructionTileCount); + if (buildingSizeTileIndex >= this->constructionTileCount) { + break; + } + } short buildingType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; if (buildingType == OpenSHC::Map::Buildings::BT_GATEHOUSELARGE) { From bb90ea0d15316858658519326e9e8feec9feba6f Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 8 Nov 2026 01:07:31 +0100 Subject: [PATCH 09/28] removed comments, return FALSE instead of 0 --- .../Map/TileMapState/advanceMoatDigProgress.cpp | 5 ++--- .../Map/TileMapState/applyRockGraphicsToFootprint.cpp | 2 -- .../clearBuildingDisplayFlagsAndEntities.cpp | 3 +-- .../clearBuildingFootprintAndRemoveSiegeTower.cpp | 3 +-- .../clearBuildingFootprintAndResetUnits.cpp | 3 +-- .../clearBuildingFootprintWithEdgeRubble.cpp | 3 +-- src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp | 3 +-- .../clearFixedSizeTwoBuildingFootprint.cpp | 3 +-- .../Map/TileMapState/computeClimbRampRotation.cpp | 2 -- .../TileMapState/computeWallCornerRenderRotation.cpp | 1 - .../TileMapState/findNearestValidDigTileNearTarget.cpp | 10 +++++----- .../getBuildingSizeForCommandBuildingType.cpp | 7 ------- .../getRubbleGraphicStageForDamageLevel.cpp | 1 - .../TileMapState/getWallFlagForOrientedDirection.cpp | 4 ++-- src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp | 10 +++++----- .../TileMapState/isWallCornerForDiagonalDirection.cpp | 6 +++--- .../Map/TileMapState/markBuildingFootprintFlag.cpp | 3 +-- .../Map/TileMapState/placeDefensiveStructureTile.cpp | 1 - .../Map/TileMapState/recountTotalOwnedMoats.cpp | 1 - src/OpenSHC/Map/TileMapState/removeMoat.cpp | 1 - .../Map/TileMapState/resetHeightAndMapBorders.cpp | 3 --- .../rotateFearFactorBuildingVariations.cpp | 3 --- .../Map/TileMapState/updateAreaBasedOnSurrounding.cpp | 3 +-- .../Map/TileMapState/updatePathLinkagesForBuilding.cpp | 3 +-- .../updateShowHiLayerOrResetChangedLayer.cpp | 2 -- 25 files changed, 26 insertions(+), 60 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp b/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp index c4237ebe31..cc347600fd 100644 --- a/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp +++ b/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp @@ -17,7 +17,6 @@ namespace Map { BOOLEnum TileMapState::advanceMoatDigProgress(int moatID) { this->moats[moatID].fillProgress = this->moats[moatID].fillProgress + 1; - // nested form: the original keeps the FALSE return as the trailing block if (this->moats[moatID].fillProgress >= 4) { int tile = this->moats[moatID].tile; this->moats[moatID].someCountDown = 0; @@ -36,9 +35,9 @@ namespace Map { DAT_PathFindingState::ptr)(this->moats[moatID].y, this->moats[moatID].tile); DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::triggerMinimapRedraw, DAT_MinimapViewState::ptr)(1); - return 1; + return TRUE; } - return 0; + return FALSE; } } diff --git a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp index 3380a30fbc..70bd01e47b 100644 --- a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp @@ -25,8 +25,6 @@ namespace Map { int size = DAT_LandscapeState::instance.rocks[rockID].size; int surface = (orientation / 2) * size * size; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( index, DAT_LandscapeState::instance.rocks[rockID].size); diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp index 879f4aecca..9b74d85ade 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp @@ -16,8 +16,7 @@ namespace Map { int buildingX = DAT_BuildingsState::instance.buildings[buildingID].x; int buildingY = DAT_BuildingsState::instance.buildings[buildingID].y; uint widthOrHeight = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, widthOrHeight); diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp index b37f2c04b3..7df5e8f67d 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp @@ -25,8 +25,7 @@ namespace Map { void TileMapState::clearBuildingFootprintAndRemoveSiegeTower(int x, int y, int size) { int tileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp index 801f2304e9..69c402cb34 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp @@ -22,8 +22,7 @@ namespace Map { void TileMapState::clearBuildingFootprintAndResetUnits(int x, int y, int size) { int buildingSizeTileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, size); diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp index a8396a0262..461467f29c 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp @@ -21,8 +21,7 @@ namespace Map { void TileMapState::clearBuildingFootprintWithEdgeRubble(int x, int y, int size) { int buildingSizeTileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, size); diff --git a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp index ccbb62a454..2de891aa9d 100644 --- a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp +++ b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp @@ -11,8 +11,7 @@ namespace Map { void TileMapState::clearDrawBridgeWater(int x, int y) { int buildingSizeTileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, 5); diff --git a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp index 2ad62bdffb..b128628ddc 100644 --- a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp @@ -18,8 +18,7 @@ namespace Map { void TileMapState::clearFixedSizeTwoBuildingFootprint(int x, int y) { int buildingSizeTileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, 2); diff --git a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp index 652ff7d91b..7a1f4b20f3 100644 --- a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp @@ -57,8 +57,6 @@ namespace Map { rotation = 2; } } else if (heightAt86 < 136 || heightAt85 < 136) { - // the original reaches this with a setcc/dec/and, which is how MSVC compiles the - // conditional below if (high > heightAt84 + 20) { rotation = 5; } else { diff --git a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp index 995fe2738b..7bbe76f0bd 100644 --- a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp @@ -74,7 +74,6 @@ namespace Map { } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( tileUnk, y, 4) != 0) { - // the other direction carries a wall too result = 63; } else { result = 33; diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp index eb14fa3e38..f16296f1b7 100644 --- a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -16,14 +16,14 @@ namespace Map { BOOLEnum TileMapState::findNearestValidDigTileNearTarget(uint x1, uint y1, uint x2, uint y2) { if (x1 > MC_MAP_XY_LIMIT_INCLUSIVE || y1 > MC_MAP_XY_LIMIT_INCLUSIVE) { - return 0; + return FALSE; } if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y1 * MC_MAP_XY_LIMIT + x1] == 0) { - return 0; + return FALSE; } if (x2 > MC_MAP_XY_LIMIT_INCLUSIVE || y2 > MC_MAP_XY_LIMIT_INCLUSIVE || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y2 * MC_MAP_XY_LIMIT + x2] == 0) { - return 0; + return FALSE; } int area = (short)this @@ -67,11 +67,11 @@ namespace Map { if (bestIndex <= -1) { this->field_0x5549a8 = x2; this->field_0x5549ac = y2; - return 0; + return FALSE; } this->field_0x5549a8 = DAT_TerrainDefinedData::instance.field_0x378c[bestIndex].x + x2; this->field_0x5549ac = DAT_TerrainDefinedData::instance.field_0x378c[bestIndex].y + y2; - return 1; + return TRUE; } } diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp index 3ee68ad635..76eab47543 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp @@ -12,13 +12,6 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FA550 int TileMapState::getBuildingSizeForCommandBuildingType(MappersEnum commandBuildingType) { - // The original dispatches through a byte index table at 0x004FA614 (0x147 entries, biased by - // M_MAPPER_UNDUGMOAT) into a jump table at 0x004FA5DC, which is what MSVC emits for a dense - // switch; Ghidra could not normalise it and rendered the dispatch as a read through an - // unnamed pointer array. The case groups below are that byte table, decoded. - // - // field159_0x5549b8 is written through the global instance, not through this, which is how - // the original addresses it. switch (commandBuildingType) { case OpenSHC::Commands::M_MAPPER_FLETCHER: case OpenSHC::Commands::M_MAPPER_HOVEL: diff --git a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp index 7d7c5b5121..b68118a8c0 100644 --- a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp +++ b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp @@ -6,7 +6,6 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FA460 undefined4 TileMapState::getRubbleGraphicStageForDamageLevel(int rotation) { - // the result lives in eax from the start (xor eax, eax), every comparison goes through ecx int result = 0; int orientation = this->mapOrientation; if (orientation == 0) { diff --git a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp index 219c252262..c6f5eb82e7 100644 --- a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp @@ -28,9 +28,9 @@ namespace Map { direction = 2; } } else { - return 0; + return FALSE; } - return (uint)this->LogicLayer[this->directionTranslationMatrix[y][direction] + tileUnk] >> 8 & 1; + return (uint)this->LogicLayer[this->directionTranslationMatrix[y][direction] + tileUnk] >> 8 & TRUE; } } diff --git a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp index 1a76d9936d..8d8453f1da 100644 --- a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp +++ b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp @@ -11,21 +11,21 @@ namespace Map { { int offset = this->directionTranslationMatrix[y][0] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { - return 1; + return TRUE; } offset = this->directionTranslationMatrix[y][4] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { - return 1; + return TRUE; } offset = this->directionTranslationMatrix[y][2] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { - return 1; + return TRUE; } offset = this->directionTranslationMatrix[y][6] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { - return 1; + return TRUE; } - return 0; + return FALSE; } } diff --git a/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp b/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp index 9102067b61..b1a8d907ba 100644 --- a/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp @@ -35,13 +35,13 @@ namespace Map { } if ((this->LogicLayer[this->directionTranslationMatrix[y][first] + tile] & L_CRENEL) == 0) { - return 0; + return FALSE; } if ((this->LogicLayer[this->directionTranslationMatrix[y][second] + tile] & L_CRENEL) == 0) { - return 0; + return FALSE; } if ((this->LogicLayer[this->directionTranslationMatrix[y][third] + tile] & L_CRENEL) != 0) { - return 0; + return FALSE; } return ~((uint)this->LogicLayer[this->directionTranslationMatrix[y][fourth] + tile] >> 9) & 1; } diff --git a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp index d474904a26..17c2189700 100644 --- a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp @@ -11,8 +11,7 @@ namespace Map { void TileMapState::markBuildingFootprintFlag(int x, int y, int buildingSize) { int buildingSizeTileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); diff --git a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp index 962493cc00..ede1082c6b 100644 --- a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp +++ b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp @@ -48,7 +48,6 @@ namespace Map { } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL; this->HeightLayer[tile] = this->HeightLayer[tile] + 98; - // a crenel on an odd tile of one axis carries the alternate variation if ((int)(x & 1) == 1 && (y & 1) == 0) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; } else if ((int)(x & 1) == 0 && (y & 1) == 1) { diff --git a/src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp b/src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp index a4bb5f1a70..e3ff1f18d6 100644 --- a/src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp +++ b/src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp @@ -9,7 +9,6 @@ namespace Map { this->currentMoatCount = 0; for (int i = 1; i < 16000; ++i) { if (this->moats[i].owner != 0) { - // not a count: one past the highest owned moat index, used as loop bound this->currentMoatCount = i + 1; } } diff --git a/src/OpenSHC/Map/TileMapState/removeMoat.cpp b/src/OpenSHC/Map/TileMapState/removeMoat.cpp index c365b350a0..14be1a08dd 100644 --- a/src/OpenSHC/Map/TileMapState/removeMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/removeMoat.cpp @@ -18,7 +18,6 @@ namespace Map { BOOLEnum TileMapState::removeMoat(uint moatID, int unused) { this->moats[moatID].fillProgress = this->moats[moatID].fillProgress - 1; - // nested form: the original keeps the FALSE return as the trailing block if (this->moats[moatID].fillProgress <= 0) { this->HeightLayer[this->moats[moatID].tile] = 8; this->LogicLayer[this->moats[moatID].tile] = this->LogicLayer[this->moats[moatID].tile] & ~L_MOAT; diff --git a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp index d6d3dafaca..b7da28c33f 100644 --- a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp +++ b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp @@ -23,7 +23,6 @@ namespace Map { this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_BORDER | L_BORDER_EDGE); } - // the two outer diagonals of the diamond carry the border flags int rowLength = 0; int tile = 0; for (; rowLength < MC_MAP_XY_LIMIT; rowLength = rowLength + 2) { @@ -54,7 +53,6 @@ namespace Map { tile++; } - // and again inset by (400 - mapSize) / 2 for a map smaller than the full diamond int row = 0; tile = 0; for (int skipped = 0; skipped < inset; skipped++) { @@ -94,7 +92,6 @@ namespace Map { DAT_PathFindingState::ptr)(); } - // every border tile ends up at the minimum height for (int borderTile = 0; borderTile < MC_MAP_TILES_COUNT; borderTile++) { if ((this->LogicLayer[borderTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { this->HeightLayer[borderTile] = 8; diff --git a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp index f4f32ac1d8..d66c92710f 100644 --- a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp +++ b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp @@ -12,9 +12,6 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F8300 void TileMapState::rotateFearFactorBuildingVariations() { - // currentMapperCommand is reached through the global instance's absolute address, and the - // switch below is the original's byte table at 0x004F847C into the jump table at 0x004F8454, - // biased by M_MAPPER_GARDEN1. The "- 1 & 6" forms are the original's setcc/dec/and idiom. DWORD now = timeGetTime(); if (this->editorRockType == 5) { if (this->rockOrientation == 0) { diff --git a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp index 57eb546f36..8f7548e976 100644 --- a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp +++ b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp @@ -15,8 +15,7 @@ namespace Map { int area = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findAccessibleAreaNearBuildingLocation, DAT_BuildingsState::ptr)(x, y, buildingSize); - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); diff --git a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp index 2db6cf76cc..99d906e848 100644 --- a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp @@ -16,8 +16,7 @@ namespace Map { void TileMapState::updatePathLinkagesForBuilding(int buildingID) { int buildingSizeTileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); diff --git a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp index b3bab6cf44..edfa123cf7 100644 --- a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp @@ -19,7 +19,6 @@ namespace Map { this->refreshRelatedOne = 0; for (int row = 0; row < 256; row++) { int target = ((uint)row >> 2) + 1; - // the pull-down eases towards the target in steps that shrink as it gets closer int step; if (this->refreshCertainTileMap == 3) { step = this->heightBasedScreenYOffset[row] - target; @@ -66,7 +65,6 @@ namespace Map { } this->refreshRelatedTwo = 1; - // nested form: the original keeps the rebuild tail call as the trailing block if (importHeight == 0) { if (this->refreshCertainTileMap == 4 || this->refreshCertainTileMap == 2) { this->refreshRelatedOne = 1; From c21cc0ca046f3af590206648769b9d5db3a4f5a8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 8 Nov 2026 01:30:39 +0100 Subject: [PATCH 10/28] style(TileMapState): swapWallOwnership as a plain per-tile loop The six hand-unrolled copies were MSVC's own unrolling of a one-tile loop body. Written as a plain loop it unrolls six-fold, as in the original, once the decompiler's (char)playerID - 1U cast is dropped from the writes; with the cast the body looks bigger to MSVC and it unrolls five-fold (0.905). Still 100%. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- .../Map/TileMapState/swapWallOwnership.cpp | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp index 682fdd6e22..4b89316f77 100644 --- a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp @@ -10,53 +10,14 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F9220 void TileMapState::swapWallOwnership(int playerID, int otherPlayerID) { - for (int tileUnk = 0; tileUnk < MC_MAP_TILES_COUNT; tileUnk += 6) { - if ((this->LogicLayer[tileUnk + 0] & L_WALL_OR_GATEHOUSE) != 0) { - if ((this->WallOwnerLayer[tileUnk + 0] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 0] - = this->WallOwnerLayer[tileUnk + 0] & ~7 | (char)otherPlayerID - 1U; - } else if ((this->WallOwnerLayer[tileUnk + 0] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 0] = this->WallOwnerLayer[tileUnk + 0] & ~7 | (char)playerID - 1U; - } - } - if ((this->LogicLayer[tileUnk + 1] & L_WALL_OR_GATEHOUSE) != 0) { - if ((this->WallOwnerLayer[tileUnk + 1] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 1] - = this->WallOwnerLayer[tileUnk + 1] & ~7 | (char)otherPlayerID - 1U; - } else if ((this->WallOwnerLayer[tileUnk + 1] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 1] = this->WallOwnerLayer[tileUnk + 1] & ~7 | (char)playerID - 1U; - } - } - if ((this->LogicLayer[tileUnk + 2] & L_WALL_OR_GATEHOUSE) != 0) { - if ((this->WallOwnerLayer[tileUnk + 2] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 2] - = this->WallOwnerLayer[tileUnk + 2] & ~7 | (char)otherPlayerID - 1U; - } else if ((this->WallOwnerLayer[tileUnk + 2] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 2] = this->WallOwnerLayer[tileUnk + 2] & ~7 | (char)playerID - 1U; - } - } - if ((this->LogicLayer[tileUnk + 3] & L_WALL_OR_GATEHOUSE) != 0) { - if ((this->WallOwnerLayer[tileUnk + 3] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 3] - = this->WallOwnerLayer[tileUnk + 3] & ~7 | (char)otherPlayerID - 1U; - } else if ((this->WallOwnerLayer[tileUnk + 3] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 3] = this->WallOwnerLayer[tileUnk + 3] & ~7 | (char)playerID - 1U; - } - } - if ((this->LogicLayer[tileUnk + 4] & L_WALL_OR_GATEHOUSE) != 0) { - if ((this->WallOwnerLayer[tileUnk + 4] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 4] - = this->WallOwnerLayer[tileUnk + 4] & ~7 | (char)otherPlayerID - 1U; - } else if ((this->WallOwnerLayer[tileUnk + 4] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 4] = this->WallOwnerLayer[tileUnk + 4] & ~7 | (char)playerID - 1U; - } - } - if ((this->LogicLayer[tileUnk + 5] & L_WALL_OR_GATEHOUSE) != 0) { - if ((this->WallOwnerLayer[tileUnk + 5] & 7) + 1 == playerID) { - this->WallOwnerLayer[tileUnk + 5] - = this->WallOwnerLayer[tileUnk + 5] & ~7 | (char)otherPlayerID - 1U; - } else if ((this->WallOwnerLayer[tileUnk + 5] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tileUnk + 5] = this->WallOwnerLayer[tileUnk + 5] & ~7 | (char)playerID - 1U; + // MSVC unrolls this loop six-fold, as in the original. The (char)playerID - 1U the decompiler + // shows makes the body look bigger to it, and it then unrolls five-fold instead. + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + if ((this->WallOwnerLayer[tile] & 7) + 1 == playerID) { + this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~7) | (otherPlayerID - 1); + } else if ((this->WallOwnerLayer[tile] & 7) + 1 == otherPlayerID) { + this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~7) | (playerID - 1); } } } From 0a5ba8299d4e35e7574f65ab5e9469dade6e38c7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 8 Nov 2026 19:42:31 +0100 Subject: [PATCH 11/28] style(TileMapState): let MSVC unroll the remaining tile loops Addresses the style-lint and cpp-linter reports on the PR: - setupAllMapSections: the border graphic loop is a plain per-tile loop; MSVC unrolls it six-fold by itself. - rebuildShowHiLayerFromHeights: a plain loop unrolls only six-fold where the original has eight, so the outer loop steps by 8 over an inner 0..7 loop instead of eight hand-written copies. - updatePathLinkagesForBuilding: trailing whitespace (clang-format). All 88 functions measure identical to before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- .../rebuildShowHiLayerFromHeights.cpp | 13 +++++-------- .../Map/TileMapState/setupAllMapSections.cpp | 16 +++++++--------- .../updatePathLinkagesForBuilding.cpp | 2 +- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp b/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp index a6d670a1bf..2c0d20906a 100644 --- a/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp +++ b/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp @@ -8,15 +8,12 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F79D0 void TileMapState::rebuildShowHiLayerFromHeights() { + // the original is unrolled eight-fold; a plain per-tile loop gets only six, so the outer + // loop steps by 8 and MSVC unrolls the inner one for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile += 8) { - this->ShowHiLayer[tile] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile]]; - this->ShowHiLayer[tile + 1] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 1]]; - this->ShowHiLayer[tile + 2] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 2]]; - this->ShowHiLayer[tile + 3] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 3]]; - this->ShowHiLayer[tile + 4] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 4]]; - this->ShowHiLayer[tile + 5] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 5]]; - this->ShowHiLayer[tile + 6] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 6]]; - this->ShowHiLayer[tile + 7] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + 7]]; + for (int i = 0; i < 8; i++) { + this->ShowHiLayer[tile + i] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + i]]; + } } } diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp index 6070370e52..f65f6da7a0 100644 --- a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -59,15 +59,13 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateShowHiLayerOrResetChangedLayer, this)(); // the border tiles get their own graphic, everything else the plain one - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile += 6) { - for (int i = 0; i < 6; i++) { - if (this->LogicLayer[tile + i] == L_BORDER) { - this->GfxLayer[tile + i] = (ushort)GMFirstPictureIndex::instance[2]; - } else if (this->LogicLayer[tile + i] == L_BORDER_EDGE) { - this->GfxLayer[tile + i] = (ushort)GMFirstPictureIndex::instance[2] + 1; - } else { - this->GfxLayer[tile + i] = (ushort)GMFirstPictureIndex::instance[2] + 2; - } + for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + if (this->LogicLayer[tile] == L_BORDER) { + this->GfxLayer[tile] = (ushort)GMFirstPictureIndex::instance[2]; + } else if (this->LogicLayer[tile] == L_BORDER_EDGE) { + this->GfxLayer[tile] = (ushort)GMFirstPictureIndex::instance[2] + 1; + } else { + this->GfxLayer[tile] = (ushort)GMFirstPictureIndex::instance[2] + 2; } } diff --git a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp index 99d906e848..c29cb865d3 100644 --- a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp @@ -16,7 +16,7 @@ namespace Map { void TileMapState::updatePathLinkagesForBuilding(int buildingID) { int buildingSizeTileIndex = 0; - + while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); From 4227c71802c0a8f259a8129e15e307b9b0971a23 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 8 Nov 2026 21:12:42 +0100 Subject: [PATCH 12/28] style(TileMapState): apply main's style guide to the remaining spots Drop the comments that explained deviations, test BOOLEnum results without != FALSE, remove casts to the destination's own type, name the climb-ramp heights, write the setcc idioms in rotateFearFactorBuildingVariations as if/else, make importHeight a BOOLEnum and let loops replace the copies in countMoatsOwnedByEachPlayer and getTileForBrush. All 88 functions measure unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XmXCmaNCgNNvTDAKE2qbZC --- .../clearBuildingFootprintAndResetUnits.cpp | 3 +- .../clearBuildingFootprintWithEdgeRubble.cpp | 3 +- .../clearBuildingTilesAndTrees.cpp | 2 +- .../TileMapState/computeClimbRampRotation.cpp | 38 +++++++++---------- .../computeWallCornerRenderRotation.cpp | 13 +++---- .../countMoatsOwnedByEachPlayer.cpp | 11 ++---- .../Map/TileMapState/createMoatData.cpp | 6 +-- .../Map/TileMapState/getTileForBrush.cpp | 25 +++++------- .../hasHigherNeighborWithStairs.cpp | 2 +- .../increaseHeightForTunnelSingleTile.cpp | 4 +- .../increaseHeightForTunnelWithBrush.cpp | 5 +-- .../placeDefensiveStructureTile.cpp | 4 +- .../rebuildShowHiLayerFromHeights.cpp | 4 +- .../TileMapState/resetHeightAndMapBorders.cpp | 10 ++--- .../rotateFearFactorBuildingVariations.cpp | 14 +++++-- .../Map/TileMapState/setupAllMapSections.cpp | 4 -- .../storeMinAndMaxHeightOfArea.cpp | 2 - .../Map/TileMapState/swapMoatOwnership.cpp | 4 +- .../Map/TileMapState/swapPitchOwnership.cpp | 4 +- .../Map/TileMapState/swapWallOwnership.cpp | 2 - .../Map/TileMapState/triggerLoweredView.cpp | 2 +- .../unmarkBuildingFootprintFlag.cpp | 2 - .../updateAreaBasedOnSurrounding.cpp | 2 +- .../Map/TileMapState/updatePitchDitches.cpp | 2 - .../updateShowHiLayerOrResetChangedLayer.cpp | 8 ++-- .../validateWallPlacementAtTile.cpp | 8 ++-- 26 files changed, 80 insertions(+), 104 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp index 69c402cb34..063041fbcf 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp @@ -40,8 +40,7 @@ namespace Map { if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { this->BuildingWasLayer[tile] = 0; } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isFootprintIndexOnEdge, this)( - buildingSizeTileIndex, size) - != FALSE) { + buildingSizeTileIndex, size)) { this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x2000; } else { this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x4000; diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp index 461467f29c..17a91640d6 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp @@ -39,8 +39,7 @@ namespace Map { if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { this->BuildingWasLayer[tile] = 0; } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isFootprintIndexOnEdge, this)( - buildingSizeTileIndex, size) - != FALSE) { + buildingSizeTileIndex, size)) { this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x2000; } else { this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x4000; diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp index 8287496ae6..11b47ac7cf 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp @@ -41,7 +41,7 @@ namespace Map { this->ChangedLayer[tileUnk] = 2; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)( - (int)DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tileUnk], tileUnk); + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tileUnk], tileUnk); } } diff --git a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp index 7a1f4b20f3..2a98490149 100644 --- a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp @@ -8,41 +8,41 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FC810 int TileMapState::computeClimbRampRotation(int tileUnk, uint x, uint y) { - int high; + int height; if ((this->LogicLayer[tileUnk] & L_WALL_OR_GATEHOUSE) != 0) { - high = this->DefaultHeightLayer[tileUnk]; + height = this->DefaultHeightLayer[tileUnk]; } else { - high = this->HeightLayer[tileUnk]; + height = this->HeightLayer[tileUnk]; } int neighbour = this->directionTranslationMatrix[y][this->screenSouthDirection] + tileUnk; - int heightAt86; + int southHeight; if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0) { - heightAt86 = this->DefaultHeightLayer[neighbour]; + southHeight = this->DefaultHeightLayer[neighbour]; } else { - heightAt86 = this->HeightLayer[neighbour]; + southHeight = this->HeightLayer[neighbour]; } neighbour = this->directionTranslationMatrix[y][this->screenEastDirection] + tileUnk; - int heightAt85; + int eastHeight; if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0) { - heightAt85 = this->DefaultHeightLayer[neighbour]; + eastHeight = this->DefaultHeightLayer[neighbour]; } else { - heightAt85 = this->HeightLayer[neighbour]; + eastHeight = this->HeightLayer[neighbour]; } neighbour = this->directionTranslationMatrix[y][this->screenSouthEastDirection] + tileUnk; - int heightAt84; + int southEastHeight; if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0) { - heightAt84 = this->DefaultHeightLayer[neighbour]; + southEastHeight = this->DefaultHeightLayer[neighbour]; } else { - heightAt84 = this->HeightLayer[neighbour]; + southEastHeight = this->HeightLayer[neighbour]; } uint rotation; - if (high > heightAt86 + 20 && heightAt86 < 136) { - if (high > heightAt85 + 20 && heightAt85 < 136) { - if (high > heightAt84 + 20 && heightAt84 < 136) { + if (height > southHeight + 20 && southHeight < 136) { + if (height > eastHeight + 20 && eastHeight < 136) { + if (height > southEastHeight + 20 && southEastHeight < 136) { rotation = 5; } else { rotation = 3; @@ -50,14 +50,14 @@ namespace Map { } else { rotation = 1; } - } else if (high > heightAt85 + 20 && heightAt85 < 136) { - if (high > heightAt86 + 20 && heightAt86 < 136) { + } else if (height > eastHeight + 20 && eastHeight < 136) { + if (height > southHeight + 20 && southHeight < 136) { rotation = 3; } else { rotation = 2; } - } else if (heightAt86 < 136 || heightAt85 < 136) { - if (high > heightAt84 + 20) { + } else if (southHeight < 136 || eastHeight < 136) { + if (height > southEastHeight + 20) { rotation = 5; } else { rotation = 0; diff --git a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp index 7bbe76f0bd..5bab4bfdd2 100644 --- a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp @@ -13,8 +13,7 @@ namespace Map { int tileUnk = this->DAT_SomeTile; int y = this->DAT_SomeY; int result = 0; - if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)(tileUnk, y, 2) - != FALSE) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)(tileUnk, y, 2)) { if (this->mapOrientation == 0) { if ((x & 0xf) == 0xf) { result = 2; @@ -40,8 +39,8 @@ namespace Map { result = 32 - (x & 0xf); } } - } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)(tileUnk, y, 0) - != FALSE) { + } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)( + tileUnk, y, 0)) { if (this->mapOrientation == 0) { if ((y & 0xf) == 0xf) { result = 1; @@ -68,12 +67,10 @@ namespace Map { } } } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( - tileUnk, y, 2) - != 0) { + tileUnk, y, 2)) { result = 48; } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( - tileUnk, y, 4) - != 0) { + tileUnk, y, 4)) { result = 63; } else { result = 33; diff --git a/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp b/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp index 94f3ca4c46..a25ad3169d 100644 --- a/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp +++ b/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp @@ -8,14 +8,9 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x005000E0 void TileMapState::countMoatsOwnedByEachPlayer() { - DAT_GameState::instance.playerDataArray[1].moatsOwned = 0; - DAT_GameState::instance.playerDataArray[2].moatsOwned = 0; - DAT_GameState::instance.playerDataArray[3].moatsOwned = 0; - DAT_GameState::instance.playerDataArray[4].moatsOwned = 0; - DAT_GameState::instance.playerDataArray[5].moatsOwned = 0; - DAT_GameState::instance.playerDataArray[6].moatsOwned = 0; - DAT_GameState::instance.playerDataArray[7].moatsOwned = 0; - DAT_GameState::instance.playerDataArray[8].moatsOwned = 0; + for (int playerID = 1; playerID < 9; playerID++) { + DAT_GameState::instance.playerDataArray[playerID].moatsOwned = 0; + } for (int moatID = 1; moatID < 16000; moatID++) { char const owner = this->moats[moatID].owner; if (owner != 0) { diff --git a/src/OpenSHC/Map/TileMapState/createMoatData.cpp b/src/OpenSHC/Map/TileMapState/createMoatData.cpp index afac27b36b..67ea338a89 100644 --- a/src/OpenSHC/Map/TileMapState/createMoatData.cpp +++ b/src/OpenSHC/Map/TileMapState/createMoatData.cpp @@ -43,9 +43,9 @@ namespace Map { if (moatID >= this->currentMoatCount) { this->currentMoatCount = moatID + 1; } - this->moats[moatID].owner = (char)playerID; - this->moats[moatID].x = (short)x; - this->moats[moatID].y = (short)y; + this->moats[moatID].owner = playerID; + this->moats[moatID].x = x; + this->moats[moatID].y = y; this->moats[moatID].tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; this->moats[moatID].zeroOrTwo = 2; if (filled != 0) { diff --git a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp index e762019d4d..5997c635d2 100644 --- a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp @@ -37,23 +37,18 @@ namespace Map { if (brushStep < 28) { brushStep = brushStep - 20; - *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; - *yPointer = *yPointer - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; - *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; - *yPointer = *yPointer - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + for (int i = 0; i < 2; i++) { + *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer = *yPointer + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + } } else if (brushStep < 48) { brushStep = brushStep - 40; - *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; - *yPointer = *yPointer - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; - *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; - *yPointer = *yPointer - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; - *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; - *yPointer = *yPointer - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + for (int i = 0; i < 3; i++) { + *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer = *yPointer + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + } } } diff --git a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp index 9c6392c669..0b3455463c 100644 --- a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp +++ b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp @@ -28,7 +28,7 @@ namespace Map { if (this->HeightLayer[neighbour] <= this->HeightLayer[tileUnk]) { return FALSE; } - return (uint)this->LogicLayer[neighbour] >> 0xb & TRUE; + return (uint)this->LogicLayer[neighbour] >> 11 & TRUE; } } diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp index 94a8ee8f8d..c78a0e4f66 100644 --- a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp @@ -35,8 +35,8 @@ namespace Map { } if ((this->HeightLayer[tile] < 16 || this->DefaultHeightLayer[tile] < 16) - && (int)((uint)this->HeightLayer[tile] + increment) >= 0) { - this->HeightLayer[tile] = this->HeightLayer[tile] + (char)increment; + && this->HeightLayer[tile] + increment >= 0) { + this->HeightLayer[tile] = this->HeightLayer[tile] + increment; } MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, DAT_PathFindingState::ptr)(4, x, y); diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp index 7df44d5dfd..e5a28d310e 100644 --- a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp @@ -27,7 +27,6 @@ namespace Map { for (int index = 0; index < 9; index++) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( 0, index, &tile, (int*)&y, baseTile, baseY); - // a copy the height store cannot alias: the original pushes it without reloading tile int const brushTile = tile; if ((this->LogicLayer[tile] & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { continue; @@ -43,8 +42,8 @@ namespace Map { } if ((this->HeightLayer[tile] < 16 || this->DefaultHeightLayer[tile] < 16) - && (int)((uint)this->HeightLayer[tile] + increment) >= 0) { - this->HeightLayer[tile] = this->HeightLayer[tile] + (char)increment; + && this->HeightLayer[tile] + increment >= 0) { + this->HeightLayer[tile] = this->HeightLayer[tile] + increment; } MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)(y, brushTile); diff --git a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp index ede1082c6b..8fb1271e3a 100644 --- a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp +++ b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp @@ -33,7 +33,7 @@ namespace Map { void TileMapState::placeDefensiveStructureTile(int playerID, uint x, uint y, MappersEnum mapper) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateWallPlacementAtTile, this)(playerID, x, y, mapper); - if (this->illegalBuild != FALSE) { + if (this->illegalBuild) { return; } @@ -93,7 +93,7 @@ namespace Map { if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_UNKNOWN_WALL_RELATED; } - this->WallOwnerLayer[tile] = this->WallOwnerLayer[tile] & ~7 | (char)playerID - 1U; + this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~7) | (playerID - 1); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)(y, tile); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoat, this)(tile); diff --git a/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp b/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp index 2c0d20906a..a1ec9632d0 100644 --- a/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp +++ b/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp @@ -8,11 +8,9 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F79D0 void TileMapState::rebuildShowHiLayerFromHeights() { - // the original is unrolled eight-fold; a plain per-tile loop gets only six, so the outer - // loop steps by 8 and MSVC unrolls the inner one for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile += 8) { for (int i = 0; i < 8; i++) { - this->ShowHiLayer[tile + i] = (uchar)this->heightBasedScreenYOffset[this->HeightLayer[tile + i]]; + this->ShowHiLayer[tile + i] = this->heightBasedScreenYOffset[this->HeightLayer[tile + i]]; } } } diff --git a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp index b7da28c33f..ac74995683 100644 --- a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp +++ b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp @@ -25,7 +25,7 @@ namespace Map { int rowLength = 0; int tile = 0; - for (; rowLength < MC_MAP_XY_LIMIT; rowLength = rowLength + 2) { + for (; rowLength < MC_MAP_XY_LIMIT; rowLength += 2) { this->LogicLayer[tile] = this->LogicLayer[tile] | L_BORDER; tile++; if (rowLength > 0) { @@ -39,7 +39,7 @@ namespace Map { tile++; } - for (rowLength = MC_MAP_XY_LIMIT - 2; rowLength >= 0; rowLength = rowLength - 2) { + for (rowLength = MC_MAP_XY_LIMIT - 2; rowLength >= 0; rowLength -= 2) { this->LogicLayer[tile] = L_BORDER; tile++; if (rowLength > 0) { @@ -57,10 +57,10 @@ namespace Map { tile = 0; for (int skipped = 0; skipped < inset; skipped++) { tile = tile + 2 + row; - row = row + 2; + row += 2; } int firstRow = row; - for (; row < MC_MAP_XY_LIMIT; row = row + 2) { + for (; row < MC_MAP_XY_LIMIT; row += 2) { this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER; tile++; if (row - inset > 0) { @@ -73,7 +73,7 @@ namespace Map { this->LogicLayer[tile - inset] = this->LogicLayer[tile - inset] | L_BORDER; tile++; } - for (row = 398; row >= firstRow; row = row - 2) { + for (row = MC_MAP_XY_LIMIT - 2; row >= firstRow; row -= 2) { this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER; tile++; if (row - inset > 0) { diff --git a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp index d66c92710f..f947c198c5 100644 --- a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp +++ b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp @@ -18,8 +18,10 @@ namespace Map { this->rockOrientation = 2; } else if (this->rockOrientation == 2) { this->rockOrientation = 4; + } else if (this->rockOrientation == 4) { + this->rockOrientation = 6; } else { - this->rockOrientation = (this->rockOrientation != 4) - 1 & 6; + this->rockOrientation = 0; } } if ((int)now < (int)(this->lastTime + 1000)) { @@ -27,14 +29,20 @@ namespace Map { } this->lastTime = now; - this->gateOrientationVariant = (this->gateOrientationVariant == 80) + 80; + if (this->gateOrientationVariant == 80) { + this->gateOrientationVariant = 81; + } else { + this->gateOrientationVariant = 80; + } if (this->editorRockType == 0) { if (this->rockOrientation == 0) { this->rockOrientation = 2; } else if (this->rockOrientation == 2) { this->rockOrientation = 4; + } else if (this->rockOrientation == 4) { + this->rockOrientation = 6; } else { - this->rockOrientation = (this->rockOrientation != 4) - 1 & 6; + this->rockOrientation = 0; } } diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp index f65f6da7a0..3f36379a38 100644 --- a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -58,7 +58,6 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupLogicalMapBorders, this)(); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateShowHiLayerOrResetChangedLayer, this)(); - // the border tiles get their own graphic, everything else the plain one for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { if (this->LogicLayer[tile] == L_BORDER) { this->GfxLayer[tile] = (ushort)GMFirstPictureIndex::instance[2]; @@ -91,9 +90,6 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::clearBuildings, DAT_BuildingsState::ptr)(); MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::clearRocksAndTrees, DAT_LandscapeState::ptr)(); MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::resetWind, DAT_LandscapeState::ptr)(); - // the original calls this empty function as a member (object in ecx), of UnitsState here and of UnitsState - // and LandscapeState below; the generated header has it as a global, so pass the object through a one-argument - // __fastcall pointer ((void(__fastcall*)(OpenSHC::Map::Units::UnitsState*))MACRO_CALL(OpenSHC::Global_Func::DoNothing))( DAT_UnitsState::ptr); MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::clearAllUnits, DAT_UnitsState::ptr)(); diff --git a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp index 2cea0a2798..9deaed27e5 100644 --- a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp +++ b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp @@ -20,8 +20,6 @@ namespace Map { } int buildingSizeTileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingWidthAndHeight); diff --git a/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp index e5b859cfd0..fb78abcc8a 100644 --- a/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp @@ -11,9 +11,9 @@ namespace Map { continue; } if (this->moats[moatID].owner == playerID) { - this->moats[moatID].owner = (char)otherPlayerID; + this->moats[moatID].owner = otherPlayerID; } else if (this->moats[moatID].owner == otherPlayerID) { - this->moats[moatID].owner = (char)playerID; + this->moats[moatID].owner = playerID; } } } diff --git a/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp index e20678f099..17f6bff83c 100644 --- a/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp @@ -11,9 +11,9 @@ namespace Map { continue; } if (this->pitchDitches[pitchDitchID].owner == playerID) { - this->pitchDitches[pitchDitchID].owner = (short)otherPlayerID; + this->pitchDitches[pitchDitchID].owner = otherPlayerID; } else if (this->pitchDitches[pitchDitchID].owner == otherPlayerID) { - this->pitchDitches[pitchDitchID].owner = (short)playerID; + this->pitchDitches[pitchDitchID].owner = playerID; } } } diff --git a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp index 4b89316f77..7294f09a86 100644 --- a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp @@ -10,8 +10,6 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F9220 void TileMapState::swapWallOwnership(int playerID, int otherPlayerID) { - // MSVC unrolls this loop six-fold, as in the original. The (char)playerID - 1U the decompiler - // shows makes the body look bigger to it, and it then unrolls five-fold instead. for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { if ((this->WallOwnerLayer[tile] & 7) + 1 == playerID) { diff --git a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp index 6216277e9d..57e979ca06 100644 --- a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp +++ b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp @@ -52,7 +52,7 @@ namespace Map { if (height > 14) { height = 14; } - DAT_UnitsState::instance.units[unitID].heightDiv10 = (char)height; + DAT_UnitsState::instance.units[unitID].heightDiv10 = height; DAT_UnitsState::instance.units[unitID].field_0x83 = 0; } } diff --git a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp index e88ef93d58..b9fd58a6e4 100644 --- a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp @@ -11,8 +11,6 @@ namespace Map { void TileMapState::unmarkBuildingFootprintFlag(int x, int y, int buildingSize) { int buildingSizeTileIndex = 0; - // the bound is set by the getBuildingSizeIndexMappingData call in the body, - // so it can only be tested at the end of it while (true) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); diff --git a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp index 8f7548e976..89f0acd200 100644 --- a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp +++ b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp @@ -22,7 +22,7 @@ namespace Map { int tileUnk = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; if (this->PathConnectionLayer[tileUnk] == 0) { - this->PathConnectionLayer[tileUnk] = (ushort)area; + this->PathConnectionLayer[tileUnk] = area; } buildingSizeTileIndex++; if (buildingSizeTileIndex >= this->constructionTileCount) { diff --git a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp index 1879f67d4c..899518761b 100644 --- a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp @@ -32,7 +32,6 @@ namespace Map { if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) == 0 || this->pitchDitches[id].state == -1) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::destroyPitchDitch, this)(id); } else if (this->pitchDitches[id].state == 0) { - // the original increments the state rather than storing the literal this->pitchDitches[id].state = this->pitchDitches[id].state + 1; this->pitchDitches[id].field_0x12 = 0; } else if (this->pitchDitches[id].state == 2) { @@ -41,7 +40,6 @@ namespace Map { this->pitchDitches[id].state = this->pitchDitches[id].state + 1; this->pitchDitches[id].field_0x12 = 0; uint height = DAT_TileMapState::instance.HeightLayer[tile]; - // the fire spreads to the four adjacent ditches that are still unlit for (int i = 0; i < 4; i++) { int neighbour = DAT_ViewportRenderState::instance .translationMatrix[this->pitchDitches[id].y diff --git a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp index edfa123cf7..80b9d23358 100644 --- a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp @@ -8,7 +8,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00501A20 void TileMapState::updateShowHiLayerOrResetChangedLayer() { - int importHeight = 0; + BOOLEnum importHeight = FALSE; this->refreshRelatedTwo = 0; if (this->refreshCertainTileMap == 0) { return; @@ -54,18 +54,18 @@ namespace Map { } else if (this->refreshCertainTileMap == 3) { this->heightBasedScreenYOffset[row] = this->heightBasedScreenYOffset[row] - step; if (this->heightBasedScreenYOffset[row] > target) { - importHeight = 1; + importHeight = TRUE; } } else if (this->refreshCertainTileMap == 4) { this->heightBasedScreenYOffset[row] = this->heightBasedScreenYOffset[row] + step; if (this->heightBasedScreenYOffset[row] != row) { - importHeight = 1; + importHeight = TRUE; } } } this->refreshRelatedTwo = 1; - if (importHeight == 0) { + if (!importHeight) { if (this->refreshCertainTileMap == 4 || this->refreshCertainTileMap == 2) { this->refreshRelatedOne = 1; } else { diff --git a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp index fb3a999d3c..068ae8629d 100644 --- a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp @@ -48,18 +48,16 @@ namespace Map { return; } if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, - DAT_PathFindingState::ptr)(playerID, x, y, 5) - != FALSE) { + DAT_PathFindingState::ptr)(playerID, x, y, 5)) { return; } if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::findSomeSuitableLocationUnk, - DAT_PathFindingState::ptr)(playerID, x, y, 2) - != 0) { + DAT_PathFindingState::ptr)(playerID, x, y, 2)) { return; } if (this->UnitLayer[tile] != 0 && (this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { - int const unitID = (short)this->UnitLayer[tile]; + int const unitID = this->UnitLayer[tile]; if (mapperCommand == OpenSHC::Commands::M_MAPPER_CRENAL || mapperCommand == OpenSHC::Commands::M_MAPPER_CRENAL2) { DAT_UnitsState::instance.units[unitID].logicalState = OpenSHC::Map::Units::ULS_REMOVE; From 0173f09bb4a11ebb98d873b202c7caf6724f63cb Mon Sep 17 00:00:00 2001 From: Gynt Date: Wed, 11 Nov 2026 12:07:55 +0100 Subject: [PATCH 13/28] style(TileMapState): use compound assignments, drop redundant usings `a = a op v` becomes `a op= v` (103 sites). Using-declarations that TileMapState.hpp already provides (BOOLEnum, MappersEnum, BuildingType), that other includes already make visible, or that were unused are removed. Codegen-neutral: every function's /FA output is identical. Co-Authored-By: Claude Opus 5.5 --- .../TileMapState/Constructor_TileMapState.cpp | 3 -- .../TileMapState/advanceMoatDigProgress.cpp | 10 ++--- .../applyRockGraphicsToFootprint.cpp | 2 +- ...arBuildingFootprintAndRemoveSiegeTower.cpp | 8 +--- .../clearBuildingFootprintAndResetUnits.cpp | 13 +++--- .../clearBuildingFootprintWithEdgeRubble.cpp | 13 +++--- .../TileMapState/clearBuildingFromTerrain.cpp | 3 -- .../clearBuildingTilesAndTrees.cpp | 6 +-- .../Map/TileMapState/clearDrawBridgeWater.cpp | 4 +- .../clearFixedSizeTwoBuildingFootprint.cpp | 7 ++- src/OpenSHC/Map/TileMapState/clearMoat.cpp | 2 +- .../Map/TileMapState/clearMoatDataAtTile.cpp | 2 +- .../collectCliffEdgeTilesForClimbData.cpp | 4 +- .../computeTileAlongAxisOffset.cpp | 4 +- .../computeWallCornerRenderRotation.cpp | 2 - .../Map/TileMapState/createMoatData.cpp | 4 +- .../Map/TileMapState/destroyPitchDitch.cpp | 9 ++-- .../Map/TileMapState/destroyWallsOfPlayer.cpp | 4 +- .../findNearestValidDigTileNearTarget.cpp | 8 ++-- ...TileInSameAreaAndNoTooHeightDifference.cpp | 2 - .../Map/TileMapState/getBuildingHurtSFXID.cpp | 2 - .../getBuildingSizeForCommandBuildingType.cpp | 2 - ...NonFarmFieldBuildingHealthAtTileOr1000.cpp | 2 - .../Map/TileMapState/getTileForBrush.cpp | 21 +++++---- .../Map/TileMapState/getTotalHeightAtTile.cpp | 2 - .../hasHigherNeighborWithStairs.cpp | 4 +- ...HigherPlainNeighborWithWallOrGatehouse.cpp | 4 +- .../hasOnlyTowerNeighborsNoWalls.cpp | 2 - .../increaseHeightForTunnelSingleTile.cpp | 2 +- .../increaseHeightForTunnelWithBrush.cpp | 2 +- .../TileMapState/isFootprintIndexOnEdge.cpp | 2 - .../isTileEnclosedByWallsOrGates.cpp | 2 - .../isWallConnectionHeightValid.cpp | 2 - .../isWallCornerForCardinalDirection.cpp | 2 - .../markBuildingFootprintFlag.cpp | 4 +- .../placeDefensiveStructureTile.cpp | 45 +++++++++---------- src/OpenSHC/Map/TileMapState/planMoat.cpp | 2 +- src/OpenSHC/Map/TileMapState/removeMoat.cpp | 6 +-- .../TileMapState/resetHeightAndMapBorders.cpp | 32 ++++++------- .../TileMapState/resetTileAndClearMoat.cpp | 9 ++-- .../TileMapState/resetTileToDefaultState.cpp | 4 +- .../rotateFearFactorBuildingVariations.cpp | 2 - .../setSignpostDistanceForCampaignMission.cpp | 2 - .../Map/TileMapState/setupAllMapSections.cpp | 2 - .../TileMapState/setupLogicalMapBorders.cpp | 4 +- .../TileMapState/spawnEraserTileEffect.cpp | 6 +-- .../Map/TileMapState/triggerLoweredView.cpp | 3 -- .../unmarkBuildingFootprintFlag.cpp | 2 +- .../TileMapState/updateGameRelatedValue.cpp | 3 +- .../updatePathLinkagesForBuilding.cpp | 2 - .../Map/TileMapState/updatePitchDitches.cpp | 8 ++-- .../updateShowHiLayerOrResetChangedLayer.cpp | 6 +-- .../validateBuildingPlacementAtTile.cpp | 3 -- .../validateWallPlacementAtTile.cpp | 3 -- 54 files changed, 116 insertions(+), 193 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp index 28becf90ab..03169c8e95 100644 --- a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp +++ b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp @@ -9,9 +9,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Commands::MappersEnum; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x00515F40 TileMapState* TileMapState::Constructor_TileMapState() { diff --git a/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp b/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp index cc347600fd..c99d9a9628 100644 --- a/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp +++ b/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp @@ -16,18 +16,16 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500500 BOOLEnum TileMapState::advanceMoatDigProgress(int moatID) { - this->moats[moatID].fillProgress = this->moats[moatID].fillProgress + 1; + this->moats[moatID].fillProgress += 1; if (this->moats[moatID].fillProgress >= 4) { int tile = this->moats[moatID].tile; this->moats[moatID].someCountDown = 0; this->moats[moatID].fillProgress = 4; this->moats[moatID].stage = 2; this->HeightLayer[tile] = 0; - this->LogicLayer[this->moats[moatID].tile] - = this->LogicLayer[this->moats[moatID].tile] & ~L_MOAT_DUG_OR_PLANNED; - this->LogicLayer[this->moats[moatID].tile] - = this->LogicLayer[this->moats[moatID].tile] & ~L_PLAIN2_AND_PITCH; - this->LogicLayer[this->moats[moatID].tile] = this->LogicLayer[this->moats[moatID].tile] | L_MOAT; + this->LogicLayer[this->moats[moatID].tile] &= ~L_MOAT_DUG_OR_PLANNED; + this->LogicLayer[this->moats[moatID].tile] &= ~L_PLAIN2_AND_PITCH; + this->LogicLayer[this->moats[moatID].tile] |= L_MOAT; this->Logic2Layer[this->moats[moatID].tile] = 0; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, DAT_PathFindingState::ptr)(2, this->moats[moatID].x, this->moats[moatID].y); diff --git a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp index 70bd01e47b..2bcbee2daf 100644 --- a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp @@ -20,7 +20,7 @@ namespace Map { int orientation = DAT_LandscapeState::instance.rocks[rockID].orientation + this->mapOrientation; int index = 0; if (orientation >= 8) { - orientation = orientation - 8; + orientation -= 8; } int size = DAT_LandscapeState::instance.rocks[rockID].size; int surface = (orientation / 2) * size * size; diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp index 7df5e8f67d..fe08fa07e7 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp @@ -18,9 +18,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STAIRS; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::Map::Units::UnitType; - using OpenSHC::Map::Units::States::UnitState; - // FUNCTION: STRONGHOLDCRUSADER 0x004FAC70 void TileMapState::clearBuildingFootprintAndRemoveSiegeTower(int x, int y, int size) { @@ -30,9 +27,8 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; - this->LogicLayer[tile] = this->LogicLayer[tile] - & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk - | L_KEEP_NON_MANOR_HOUSE); + this->LogicLayer[tile] &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk + | L_KEEP_NON_MANOR_HOUSE); this->BuildingLayer[tile] = 0; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp index 063041fbcf..b6390580b2 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp @@ -16,8 +16,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STAIRS; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004FAB70 void TileMapState::clearBuildingFootprintAndResetUnits(int x, int y, int size) { @@ -28,11 +26,10 @@ namespace Map { buildingSizeTileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; - this->LogicLayer[tile] = this->LogicLayer[tile] - & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk - | L_KEEP_NON_MANOR_HOUSE); + this->LogicLayer[tile] &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk + | L_KEEP_NON_MANOR_HOUSE); if ((this->MiscDisplayLayer[tile] & 0x20) != 0) { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0x20; + this->MiscDisplayLayer[tile] &= ~0x20; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; } int buildingID = this->BuildingLayer[tile]; @@ -41,9 +38,9 @@ namespace Map { this->BuildingWasLayer[tile] = 0; } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isFootprintIndexOnEdge, this)( buildingSizeTileIndex, size)) { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x2000; + this->MiscDisplayLayer[tile] |= 0x2000; } else { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x4000; + this->MiscDisplayLayer[tile] |= 0x4000; } for (int unitID = this->UnitLayer[tile]; unitID != 0; unitID = DAT_UnitsState::instance.units[unitID].nextUnitOnTheSameTile) { diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp index 17a91640d6..a286ccd944 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp @@ -15,8 +15,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STAIRS; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004FAD70 void TileMapState::clearBuildingFootprintWithEdgeRubble(int x, int y, int size) { @@ -27,11 +25,10 @@ namespace Map { buildingSizeTileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; - this->LogicLayer[tile] = this->LogicLayer[tile] - & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk - | L_KEEP_NON_MANOR_HOUSE); + this->LogicLayer[tile] &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk + | L_KEEP_NON_MANOR_HOUSE); if ((this->MiscDisplayLayer[tile] & 0x20) != 0) { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0x20; + this->MiscDisplayLayer[tile] &= ~0x20; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; } int buildingID = this->BuildingLayer[tile]; @@ -40,9 +37,9 @@ namespace Map { this->BuildingWasLayer[tile] = 0; } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isFootprintIndexOnEdge, this)( buildingSizeTileIndex, size)) { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x2000; + this->MiscDisplayLayer[tile] |= 0x2000; } else { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x4000; + this->MiscDisplayLayer[tile] |= 0x4000; } buildingSizeTileIndex++; this->ChangedLayer[tile] = 2; diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp index 5f820c714e..123555437f 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp @@ -13,9 +13,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Buildings::BuildingType; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x00515A20 void TileMapState::clearBuildingFromTerrain(int buildingID) { diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp index 11b47ac7cf..4e36506c5e 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp @@ -11,8 +11,6 @@ namespace OpenSHC { namespace Map { - using namespace OpenSHC::Map::LogicHelpers; // L_* flags - using OpenSHC::Map::Buildings::Building; using OpenSHC::Map::LogicHelpers::L_BUILDING; using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_APPLE; @@ -31,8 +29,8 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeTree, DAT_LandscapeState::ptr)(treeID); } } - this->LogicLayer[tileUnk] = this->LogicLayer[tileUnk] - & ~(L_BUILDING | L_FARM_FIELD_WHEAT | L_FARM_FIELD_HOP | L_FARM_FIELD_APPLE | L_FARM_FIELD_DAIRY); + this->LogicLayer[tileUnk] + &= ~(L_BUILDING | L_FARM_FIELD_WHEAT | L_FARM_FIELD_HOP | L_FARM_FIELD_APPLE | L_FARM_FIELD_DAIRY); this->DamageLayer[tileUnk] = 0; this->BuildingLayer[tileUnk] = 0; if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { diff --git a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp index 2de891aa9d..3ae98e608e 100644 --- a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp +++ b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp @@ -17,12 +17,12 @@ namespace Map { buildingSizeTileIndex, 5); int targetedTile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; - this->LogicLayer[targetedTile] = this->LogicLayer[targetedTile] & ~L_MOAT; + this->LogicLayer[targetedTile] &= ~L_MOAT; this->HeightLayer[targetedTile] = 8; uint moatID = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, this)(targetedTile); if (moatID != 0) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatData, this)(moatID); - this->LogicLayer[targetedTile] = this->LogicLayer[targetedTile] & ~L_MOAT; + this->LogicLayer[targetedTile] &= ~L_MOAT; this->BuildingWasLayer[targetedTile] = 0; } this->BuildingLayer[targetedTile] = 0; diff --git a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp index b128628ddc..c863ca6eac 100644 --- a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp @@ -24,15 +24,14 @@ namespace Map { buildingSizeTileIndex, 2); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; - this->LogicLayer[tile] = this->LogicLayer[tile] - & ~(L_STOCKPILEUnk | L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk - | L_KEEP_NON_MANOR_HOUSE); + this->LogicLayer[tile] &= ~(L_STOCKPILEUnk | L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS + | L_CRENEL_VARIATIONUnk | L_KEEP_NON_MANOR_HOUSE); int buildingID = this->BuildingLayer[tile]; this->BuildingLayer[tile] = 0; if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { this->BuildingWasLayer[tile] = 0; } else { - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] | 0x4000; + this->MiscDisplayLayer[tile] |= 0x4000; } buildingSizeTileIndex++; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; diff --git a/src/OpenSHC/Map/TileMapState/clearMoat.cpp b/src/OpenSHC/Map/TileMapState/clearMoat.cpp index e2d8ae0c07..f873e33228 100644 --- a/src/OpenSHC/Map/TileMapState/clearMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/clearMoat.cpp @@ -19,7 +19,7 @@ namespace Map { .translationMatrix[DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]] .addXgetTile, DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]); - this->LogicLayer[tile] = this->LogicLayer[tile] & ~L_MOAT_DUG_OR_PLANNED; + this->LogicLayer[tile] &= ~L_MOAT_DUG_OR_PLANNED; } } diff --git a/src/OpenSHC/Map/TileMapState/clearMoatDataAtTile.cpp b/src/OpenSHC/Map/TileMapState/clearMoatDataAtTile.cpp index 79c5839089..f06fe16930 100644 --- a/src/OpenSHC/Map/TileMapState/clearMoatDataAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/clearMoatDataAtTile.cpp @@ -14,7 +14,7 @@ namespace Map { if (this->moats[moatID].x == x && this->moats[moatID].y == y) { MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( sizeof(Moat), 0, &this->moats[moatID]); - this->moatTileCount = this->moatTileCount - 1; + this->moatTileCount -= 1; } } } diff --git a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp index 8e8979c092..e42c5c6a85 100644 --- a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp +++ b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp @@ -40,7 +40,7 @@ namespace Map { break; } } - this->temporaryTerrainTypeIndex = this->temporaryTerrainTypeIndex + 1; + this->temporaryTerrainTypeIndex += 1; if ((int)this->temporaryTerrainTypeIndex >= 1000) { return; } @@ -50,7 +50,7 @@ namespace Map { || ((this->LogicLayer[tile] & L_SEA) != 0 && (this->Logic2Layer[tile] & L2_PLATEAU_HIGH) != 0)) { this->temporaryTerrainTypeBinaryArray[this->temporaryTerrainTypeIndex] = 1; this->temporaryTerrainTypeArray[this->temporaryTerrainTypeIndex] = tile; - this->temporaryTerrainTypeIndex = this->temporaryTerrainTypeIndex + 1; + this->temporaryTerrainTypeIndex += 1; if ((int)this->temporaryTerrainTypeIndex >= 1000) { return; } diff --git a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp index d7e8f0a46e..b56fed3c49 100644 --- a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp +++ b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp @@ -18,8 +18,8 @@ namespace Map { int count = abs((int)offset); for (int i = 0; i < count; i++) { - tileUnk = tileUnk + this->directionTranslationMatrix[y][direction]; - y = y + yStep; + tileUnk += this->directionTranslationMatrix[y][direction]; + y += yStep; } return tileUnk + addend; } diff --git a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp index 5bab4bfdd2..0d4b929a58 100644 --- a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp @@ -5,8 +5,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004FC650 int TileMapState::computeWallCornerRenderRotation(uint x) { diff --git a/src/OpenSHC/Map/TileMapState/createMoatData.cpp b/src/OpenSHC/Map/TileMapState/createMoatData.cpp index 67ea338a89..44d79cdd6f 100644 --- a/src/OpenSHC/Map/TileMapState/createMoatData.cpp +++ b/src/OpenSHC/Map/TileMapState/createMoatData.cpp @@ -11,8 +11,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Game::GameMode2; - // FUNCTION: STRONGHOLDCRUSADER 0x005110B0 int TileMapState::createMoatData(undefined4 playerID, uint x, uint y, int filled) { @@ -55,7 +53,7 @@ namespace Map { this->moats[moatID].stage = 1; this->moats[moatID].fillProgress = 0; } - this->moatTileCount = this->moatTileCount + 1; + this->moatTileCount += 1; return moatID; } return 0; diff --git a/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp b/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp index d046dd4219..5834f9ed0f 100644 --- a/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp +++ b/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp @@ -15,12 +15,9 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500890 void TileMapState::destroyPitchDitch(int pitchDitchID) { - this->LogicLayer[this->pitchDitches[pitchDitchID].tile] - = this->LogicLayer[this->pitchDitches[pitchDitchID].tile] & ~L_PLAIN2_AND_PITCH; - this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] - = this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] & ~0x2000; - this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] - = this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] & ~0x4000; + this->LogicLayer[this->pitchDitches[pitchDitchID].tile] &= ~L_PLAIN2_AND_PITCH; + this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] &= ~0x2000; + this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] &= ~0x4000; if ((this->LogicLayer[this->pitchDitches[pitchDitchID].tile] & L_WALL_OR_GATEHOUSE) == 0 && this->BuildingLayer[this->pitchDitches[pitchDitchID].tile] == 0) { this->HeightLayer[this->pitchDitches[pitchDitchID].tile] diff --git a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp index 7af1f6dcff..90baeaaa67 100644 --- a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp +++ b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp @@ -31,8 +31,8 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)( tile); - this->LogicLayer[tile] = this->LogicLayer[tile] - & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); + this->LogicLayer[tile] + &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; this->DamageLayer[tile] = 0; uint y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp index f16296f1b7..50a6031180 100644 --- a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -34,8 +34,8 @@ namespace Map { uint targetHeight = this->HeightLayer[targetTile]; int targetBuildingID = this->BuildingLayer[targetTile]; if (targetBuildingID != 0) { - targetHeight = targetHeight - + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + targetHeight + += MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, DAT_BuildingsState::ptr)(targetBuildingID); } @@ -49,8 +49,8 @@ namespace Map { uint height = this->HeightLayer[tile]; int buildingID = this->BuildingLayer[tile]; if (buildingID != 0) { - height = height - + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + height + += MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, DAT_BuildingsState::ptr)(buildingID); } if ((int)height >= (int)(targetHeight + 16) || (int)height <= (int)(targetHeight - 16)) { diff --git a/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp b/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp index 1fb3dd439d..4e3a3e4b76 100644 --- a/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp +++ b/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp @@ -5,8 +5,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x00500370 BOOLEnum TileMapState::findTileInSameAreaAndNoTooHeightDifference(int area, int tile, int yUnk) { diff --git a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp index 54f714f1a4..c56a5f46ad 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp @@ -7,8 +7,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Buildings::BuildingLogicalState; - // FUNCTION: STRONGHOLDCRUSADER 0x004F8210 uint TileMapState::getBuildingHurtSFXID(int tileUnk) { diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp index 76eab47543..3d159aae88 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp @@ -7,8 +7,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Commands::MappersEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004FA550 int TileMapState::getBuildingSizeForCommandBuildingType(MappersEnum commandBuildingType) { diff --git a/src/OpenSHC/Map/TileMapState/getNonFarmFieldBuildingHealthAtTileOr1000.cpp b/src/OpenSHC/Map/TileMapState/getNonFarmFieldBuildingHealthAtTileOr1000.cpp index ea298623c1..73f072874a 100644 --- a/src/OpenSHC/Map/TileMapState/getNonFarmFieldBuildingHealthAtTileOr1000.cpp +++ b/src/OpenSHC/Map/TileMapState/getNonFarmFieldBuildingHealthAtTileOr1000.cpp @@ -13,8 +13,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_HOP; using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_WHEAT; - using OpenSHC::Map::Buildings::BuildingLogicalState; - // FUNCTION: STRONGHOLDCRUSADER 0x004F8160 int TileMapState::getNonFarmFieldBuildingHealthAtTileOr1000(int tile) { diff --git a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp index 5997c635d2..42f54932d4 100644 --- a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp @@ -29,25 +29,24 @@ namespace Map { return; } if (brushStep < 8) { - *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; - *yPointer = *yPointer - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + *tilePointer += this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer += DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; return; } if (brushStep < 28) { - brushStep = brushStep - 20; + brushStep -= 20; for (int i = 0; i < 2; i++) { - *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; - *yPointer = *yPointer - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + *tilePointer += this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer + += DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; } } else if (brushStep < 48) { - brushStep = brushStep - 40; + brushStep -= 40; for (int i = 0; i < 3; i++) { - *tilePointer = *tilePointer + this->directionTranslationMatrix[*yPointer][brushStep]; - *yPointer = *yPointer - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; + *tilePointer += this->directionTranslationMatrix[*yPointer][brushStep]; + *yPointer + += DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; } } } diff --git a/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp b/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp index 844faef35d..8703894f77 100644 --- a/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp @@ -8,8 +8,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Buildings::BuildingType; - // FUNCTION: STRONGHOLDCRUSADER 0x004FFB10 uint TileMapState::getTotalHeightAtTile(int tile) { diff --git a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp index 0b3455463c..922eea38d4 100644 --- a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp +++ b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp @@ -5,8 +5,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F8A40 BOOLEnum TileMapState::hasHigherNeighborWithStairs(int tileUnk, int y, int direction) { @@ -21,7 +19,7 @@ namespace Map { rotatedDirection = direction + 6; } if (rotatedDirection >= 8) { - rotatedDirection = rotatedDirection - 8; + rotatedDirection -= 8; } int neighbour = this->directionTranslationMatrix[y][rotatedDirection] + tileUnk; diff --git a/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp index 6e50555415..0f2cb8bf82 100644 --- a/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp @@ -8,8 +8,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_CRENEL; using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F8AC0 BOOLEnum TileMapState::hasHigherPlainNeighborWithWallOrGatehouse(int tile, int y, int direction) { @@ -24,7 +22,7 @@ namespace Map { rotatedDirection = direction + 6; } if (rotatedDirection >= 8) { - rotatedDirection = rotatedDirection - 8; + rotatedDirection -= 8; } int neighbour = this->directionTranslationMatrix[y][rotatedDirection] + tile; diff --git a/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp b/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp index fdaf81b454..2bbd14fdb2 100644 --- a/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp +++ b/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp @@ -8,8 +8,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F8900 BOOLEnum TileMapState::hasOnlyTowerNeighborsNoWalls(int tile, int y) { diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp index c78a0e4f66..2adee90853 100644 --- a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp @@ -36,7 +36,7 @@ namespace Map { if ((this->HeightLayer[tile] < 16 || this->DefaultHeightLayer[tile] < 16) && this->HeightLayer[tile] + increment >= 0) { - this->HeightLayer[tile] = this->HeightLayer[tile] + increment; + this->HeightLayer[tile] += increment; } MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, DAT_PathFindingState::ptr)(4, x, y); diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp index e5a28d310e..1ce47255f1 100644 --- a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp @@ -43,7 +43,7 @@ namespace Map { if ((this->HeightLayer[tile] < 16 || this->DefaultHeightLayer[tile] < 16) && this->HeightLayer[tile] + increment >= 0) { - this->HeightLayer[tile] = this->HeightLayer[tile] + increment; + this->HeightLayer[tile] += increment; } MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)(y, brushTile); diff --git a/src/OpenSHC/Map/TileMapState/isFootprintIndexOnEdge.cpp b/src/OpenSHC/Map/TileMapState/isFootprintIndexOnEdge.cpp index 70401976c2..132e9010cd 100644 --- a/src/OpenSHC/Map/TileMapState/isFootprintIndexOnEdge.cpp +++ b/src/OpenSHC/Map/TileMapState/isFootprintIndexOnEdge.cpp @@ -5,8 +5,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F9930 BOOLEnum TileMapState::isFootprintIndexOnEdge(int counter, int size) { diff --git a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp index dfb35c7c91..29277f6692 100644 --- a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp +++ b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp @@ -9,8 +9,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F85B0 BOOLEnum TileMapState::isTileEnclosedByWallsOrGates(int tile, int y) { diff --git a/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp b/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp index 6868964b39..4b1286ef95 100644 --- a/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp +++ b/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp @@ -8,8 +8,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F8840 BOOLEnum TileMapState::isWallConnectionHeightValid(int tile, int y, int direction) { diff --git a/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp b/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp index b7e008769d..9357e1d752 100644 --- a/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp @@ -7,8 +7,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_CRENEL; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F86D0 BOOLEnum TileMapState::isWallCornerForCardinalDirection(int tile, int y, int direction) { diff --git a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp index 17c2189700..9649ef7bf1 100644 --- a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp @@ -18,8 +18,8 @@ namespace Map { buildingSizeTileIndex++; int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; - this->LogicLayer[tile] = this->LogicLayer[tile] | L_PLAIN1_AND_FARM; - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0xc; + this->LogicLayer[tile] |= L_PLAIN1_AND_FARM; + this->MiscDisplayLayer[tile] &= ~0xc; if (buildingSizeTileIndex >= this->constructionTileCount) { break; } diff --git a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp index 8fb1271e3a..87b7e8b6ef 100644 --- a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp +++ b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp @@ -26,9 +26,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::Commands::MappersEnum; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x005034A0 void TileMapState::placeDefensiveStructureTile(int playerID, uint x, uint y, MappersEnum mapper) { @@ -46,43 +43,43 @@ namespace Map { } else if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { this->HeightLayer[tile] = this->DefaultHeightLayer[tile] + 60; } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL; - this->HeightLayer[tile] = this->HeightLayer[tile] + 98; + this->LogicLayer[tile] |= L_CRENEL; + this->HeightLayer[tile] += 98; if ((int)(x & 1) == 1 && (y & 1) == 0) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; + this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; } else if ((int)(x & 1) == 0 && (y & 1) == 1) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; + this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; } } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL2) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL; - this->HeightLayer[tile] = this->HeightLayer[tile] + 68; + this->LogicLayer[tile] |= L_CRENEL; + this->HeightLayer[tile] += 68; if ((int)(x & 1) == 1 && (y & 1) == 0) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; + this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; } else if ((int)(x & 1) == 0 && (y & 1) == 1) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_CRENEL_VARIATIONUnk; + this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; } } else if (command == OpenSHC::Commands::M_MAPPER_STAIR1) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 80; + this->LogicLayer[tile] |= L_STAIRS; + this->HeightLayer[tile] += 80; } else if (command == OpenSHC::Commands::M_MAPPER_STAIR2) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 64; + this->LogicLayer[tile] |= L_STAIRS; + this->HeightLayer[tile] += 64; } else if (command == OpenSHC::Commands::M_MAPPER_STAIR3) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 48; + this->LogicLayer[tile] |= L_STAIRS; + this->HeightLayer[tile] += 48; } else if (command == OpenSHC::Commands::M_MAPPER_STAIR4) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 32; + this->LogicLayer[tile] |= L_STAIRS; + this->HeightLayer[tile] += 32; } else if (command == OpenSHC::Commands::M_MAPPER_STAIR5) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_STAIRS; - this->HeightLayer[tile] = this->HeightLayer[tile] + 16; + this->LogicLayer[tile] |= L_STAIRS; + this->HeightLayer[tile] += 16; } this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_UNKNOWN_WALL_RELATED | L_BOULDERS | L_PEBBLES | L_IRON) | L_WALL_OR_GATEHOUSE; if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) != 0) { - this->LogicLayer[tile] = this->LogicLayer[tile] & ~L_PLAIN2_AND_PITCH; - this->HeightLayer[tile] = this->HeightLayer[tile] + 4; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->HeightLayer[tile] += 4; } if ((this->LogicLayer[tile] & L_TREE) != 0) { int organism = this->OrganismLayer[tile]; @@ -91,7 +88,7 @@ namespace Map { } } if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_UNKNOWN_WALL_RELATED; + this->LogicLayer[tile] |= L_UNKNOWN_WALL_RELATED; } this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~7) | (playerID - 1); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, diff --git a/src/OpenSHC/Map/TileMapState/planMoat.cpp b/src/OpenSHC/Map/TileMapState/planMoat.cpp index 6734ace63a..ec30ca6bb9 100644 --- a/src/OpenSHC/Map/TileMapState/planMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/planMoat.cpp @@ -51,7 +51,7 @@ namespace Map { if ((logic & (L_MOAT_DUG_OR_PLANNED | L_MOAT)) == 0 && this->HeightLayer[tile] <= 12) { if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::createMoatData, this)(playerID, moatX, tileY, 0) != 0) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_MOAT_DUG_OR_PLANNED; + this->LogicLayer[tile] |= L_MOAT_DUG_OR_PLANNED; } MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)(tileY, tile); diff --git a/src/OpenSHC/Map/TileMapState/removeMoat.cpp b/src/OpenSHC/Map/TileMapState/removeMoat.cpp index 14be1a08dd..fa3df6df54 100644 --- a/src/OpenSHC/Map/TileMapState/removeMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/removeMoat.cpp @@ -12,15 +12,13 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_MOAT; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x005113F0 BOOLEnum TileMapState::removeMoat(uint moatID, int unused) { - this->moats[moatID].fillProgress = this->moats[moatID].fillProgress - 1; + this->moats[moatID].fillProgress -= 1; if (this->moats[moatID].fillProgress <= 0) { this->HeightLayer[this->moats[moatID].tile] = 8; - this->LogicLayer[this->moats[moatID].tile] = this->LogicLayer[this->moats[moatID].tile] & ~L_MOAT; + this->LogicLayer[this->moats[moatID].tile] &= ~L_MOAT; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, DAT_PathFindingState::ptr)(2, this->moats[moatID].x, this->moats[moatID].y); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, diff --git a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp index ac74995683..77bdc379bd 100644 --- a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp +++ b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp @@ -20,18 +20,18 @@ namespace Map { if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; } - this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_BORDER | L_BORDER_EDGE); + this->LogicLayer[tile] &= ~(L_BORDER | L_BORDER_EDGE); } int rowLength = 0; int tile = 0; for (; rowLength < MC_MAP_XY_LIMIT; rowLength += 2) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_BORDER; + this->LogicLayer[tile] |= L_BORDER; tile++; if (rowLength > 0) { - this->LogicLayer[tile] = this->LogicLayer[tile] | L_BORDER_EDGE; + this->LogicLayer[tile] |= L_BORDER_EDGE; } - tile = tile + rowLength; + tile += rowLength; if (rowLength > 0 && (this->LogicLayer[tile - 1] & L_BORDER) == 0) { this->LogicLayer[tile - 1] = L_BORDER_EDGE; } @@ -45,7 +45,7 @@ namespace Map { if (rowLength > 0) { this->LogicLayer[tile] = L_BORDER_EDGE; } - tile = tile + rowLength; + tile += rowLength; if (rowLength > 0 && (this->LogicLayer[tile - 1] & L_BORDER) == 0) { this->LogicLayer[tile - 1] = L_BORDER_EDGE; } @@ -56,34 +56,34 @@ namespace Map { int row = 0; tile = 0; for (int skipped = 0; skipped < inset; skipped++) { - tile = tile + 2 + row; + tile += 2 + row; row += 2; } int firstRow = row; for (; row < MC_MAP_XY_LIMIT; row += 2) { - this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER; + this->LogicLayer[tile + inset] |= L_BORDER; tile++; if (row - inset > 0) { - this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER_EDGE; + this->LogicLayer[tile + inset] |= L_BORDER_EDGE; } - tile = tile + row; + tile += row; if (row - inset > 0 && (this->LogicLayer[tile - inset] & L_BORDER) == 0) { - this->LogicLayer[tile - inset - 1] = this->LogicLayer[tile - inset - 1] | L_BORDER_EDGE; + this->LogicLayer[tile - inset - 1] |= L_BORDER_EDGE; } - this->LogicLayer[tile - inset] = this->LogicLayer[tile - inset] | L_BORDER; + this->LogicLayer[tile - inset] |= L_BORDER; tile++; } for (row = MC_MAP_XY_LIMIT - 2; row >= firstRow; row -= 2) { - this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER; + this->LogicLayer[tile + inset] |= L_BORDER; tile++; if (row - inset > 0) { - this->LogicLayer[tile + inset] = this->LogicLayer[tile + inset] | L_BORDER_EDGE; + this->LogicLayer[tile + inset] |= L_BORDER_EDGE; } - tile = tile + row; + tile += row; if (row - inset > 0 && (this->LogicLayer[tile - inset] & L_BORDER) == 0) { - this->LogicLayer[tile - inset - 1] = this->LogicLayer[tile - inset - 1] | L_BORDER_EDGE; + this->LogicLayer[tile - inset - 1] |= L_BORDER_EDGE; } - this->LogicLayer[tile - inset] = this->LogicLayer[tile - inset] | L_BORDER; + this->LogicLayer[tile - inset] |= L_BORDER; tile++; } if (mapSize != MC_MAP_XY_LIMIT) { diff --git a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp index 228a4a803d..4333a1cb2b 100644 --- a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp @@ -22,9 +22,8 @@ namespace Map { { int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; - this->LogicLayer[tile] = this->LogicLayer[tile] - & ~(L_PLAIN2_AND_PITCH | L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED - | L_CRENEL_VARIATIONUnk); + this->LogicLayer[tile] &= ~(L_PLAIN2_AND_PITCH | L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS + | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); this->HeightLayer[tile] = DAT_TileMapState::instance.DefaultHeightLayer[tile]; this->DamageLayer[tile] = 0; if ((this->LogicLayer[tile] & L_TREE) != 0) { @@ -51,9 +50,9 @@ namespace Map { } if ((this->LogicLayer[tile] & (L_MOAT | L_MOAT_DUG_OR_PLANNED)) != 0) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)(x, y); - this->LogicLayer[tile] = this->LogicLayer[tile] & ~(L_MOAT | L_MOAT_DUG_OR_PLANNED); + this->LogicLayer[tile] &= ~(L_MOAT | L_MOAT_DUG_OR_PLANNED); } - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0x3c0; + this->MiscDisplayLayer[tile] &= ~0x3c0; } } diff --git a/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp b/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp index bb053e399e..f21491c8d6 100644 --- a/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp +++ b/src/OpenSHC/Map/TileMapState/resetTileToDefaultState.cpp @@ -18,8 +18,8 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F81D0 void TileMapState::resetTileToDefaultState(int tile, uint x, uint y) { - this->LogicLayer[tile] = this->LogicLayer[tile] - & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); + this->LogicLayer[tile] + &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tile); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, diff --git a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp index f947c198c5..c17758ca96 100644 --- a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp +++ b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp @@ -7,8 +7,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Commands::MappersEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F8300 void TileMapState::rotateFearFactorBuildingVariations() { diff --git a/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp b/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp index 6695af2132..5821a0c99c 100644 --- a/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp +++ b/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp @@ -9,8 +9,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Game::GameMode2; - // FUNCTION: STRONGHOLDCRUSADER 0x00500BB0 void TileMapState::setSignpostDistanceForCampaignMission() { diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp index 3f36379a38..370c2f4c7d 100644 --- a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -38,8 +38,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_BORDER; using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x00512100 void TileMapState::setupAllMapSections() { diff --git a/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp b/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp index 35ef2a57ab..2d1f303cba 100644 --- a/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp +++ b/src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp @@ -19,7 +19,7 @@ namespace Map { if (rowWidth > 0) { this->LogicLayer[index] = L_BORDER_EDGE; } - index = index + rowWidth; + index += rowWidth; if (rowWidth > 0) { this->LogicLayer[index - 1] = L_BORDER_EDGE; } @@ -32,7 +32,7 @@ namespace Map { if (rowWidth > 0) { this->LogicLayer[index] = L_BORDER_EDGE; } - index = index + rowWidth; + index += rowWidth; if (rowWidth > 0) { this->LogicLayer[index - 1] = L_BORDER_EDGE; } diff --git a/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp b/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp index e8292afce8..00379b41d9 100644 --- a/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp +++ b/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp @@ -27,15 +27,15 @@ namespace Map { { uint y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; - this->MiscDisplayLayer[tile] = this->MiscDisplayLayer[tile] & ~0x400; + this->MiscDisplayLayer[tile] &= ~0x400; if (this->UnitLayer[tile] != 0) { return; } this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tile); - this->LogicLayer[tile] = this->LogicLayer[tile] - & ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); + this->LogicLayer[tile] + &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); int microX = (tile - DAT_ViewportRenderState::instance diff --git a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp index 57e979ca06..101c896e44 100644 --- a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp +++ b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp @@ -9,9 +9,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Units::UnitLogicState; - using OpenSHC::Map::Units::UnitType; - // FUNCTION: STRONGHOLDCRUSADER 0x004F6FD0 void TileMapState::triggerLoweredView(int requestedView) { diff --git a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp index b9fd58a6e4..2aa71d72da 100644 --- a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp @@ -17,7 +17,7 @@ namespace Map { buildingSizeTileIndex++; int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; - this->LogicLayer[tile] = this->LogicLayer[tile] & ~L_PLAIN1_AND_FARM; + this->LogicLayer[tile] &= ~L_PLAIN1_AND_FARM; if (buildingSizeTileIndex >= this->constructionTileCount) { break; } diff --git a/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp b/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp index b0bc0f79b9..62afd7f731 100644 --- a/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp +++ b/src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp @@ -18,8 +18,7 @@ namespace Map { if (DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown == 40) { this->field_0x554a10 = -1; } - DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown - = DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown - 1; + DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown -= 1; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setSignpostDistanceForCampaignMission, this)(); int signpostDistance = ((40 - DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown) * DAT_GameState::instance.mapAndTime.unk_signpostDistance) diff --git a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp index c29cb865d3..7e925daf1c 100644 --- a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp @@ -10,8 +10,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Buildings::BuildingType; - // FUNCTION: STRONGHOLDCRUSADER 0x00506AD0 void TileMapState::updatePathLinkagesForBuilding(int buildingID) { diff --git a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp index 899518761b..f681e62d04 100644 --- a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp @@ -32,12 +32,12 @@ namespace Map { if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) == 0 || this->pitchDitches[id].state == -1) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::destroyPitchDitch, this)(id); } else if (this->pitchDitches[id].state == 0) { - this->pitchDitches[id].state = this->pitchDitches[id].state + 1; + this->pitchDitches[id].state += 1; this->pitchDitches[id].field_0x12 = 0; } else if (this->pitchDitches[id].state == 2) { - this->pitchDitches[id].field_0x12 = this->pitchDitches[id].field_0x12 + 1; + this->pitchDitches[id].field_0x12 += 1; if (this->pitchDitches[id].field_0x12 == 20) { - this->pitchDitches[id].state = this->pitchDitches[id].state + 1; + this->pitchDitches[id].state += 1; this->pitchDitches[id].field_0x12 = 0; uint height = DAT_TileMapState::instance.HeightLayer[tile]; for (int i = 0; i < 4; i++) { @@ -63,7 +63,7 @@ namespace Map { } } } else if (this->pitchDitches[id].state == 3) { - this->pitchDitches[id].field_0x12 = this->pitchDitches[id].field_0x12 + 1; + this->pitchDitches[id].field_0x12 += 1; if (this->pitchDitches[id].field_0x12 == 200) { DAT_TileMapState::instance.HeightLayer[tile] = DAT_TileMapState::instance.DefaultHeightLayer[tile]; this->pitchDitches[id].state = -1; diff --git a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp index 80b9d23358..7decaed7a0 100644 --- a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp @@ -14,7 +14,7 @@ namespace Map { return; } - this->counter1 = this->counter1 + 1; + this->counter1 += 1; this->refreshCertainTileMap_old = this->refreshCertainTileMap; this->refreshRelatedOne = 0; for (int row = 0; row < 256; row++) { @@ -52,12 +52,12 @@ namespace Map { } else if (this->refreshCertainTileMap == 2) { this->heightBasedScreenYOffset[row] = row; } else if (this->refreshCertainTileMap == 3) { - this->heightBasedScreenYOffset[row] = this->heightBasedScreenYOffset[row] - step; + this->heightBasedScreenYOffset[row] -= step; if (this->heightBasedScreenYOffset[row] > target) { importHeight = TRUE; } } else if (this->refreshCertainTileMap == 4) { - this->heightBasedScreenYOffset[row] = this->heightBasedScreenYOffset[row] + step; + this->heightBasedScreenYOffset[row] += step; if (this->heightBasedScreenYOffset[row] != row) { importHeight = TRUE; } diff --git a/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp b/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp index 6487cb5a87..30a91ecfe9 100644 --- a/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp @@ -13,9 +13,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::Map::Buildings::BuildingType; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F9DF0 void TileMapState::validateBuildingPlacementAtTile(int playerID, int x, int y) { diff --git a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp index 068ae8629d..061ff6a764 100644 --- a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp @@ -22,9 +22,6 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_SEA; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; - using OpenSHC::Map::Units::UnitLogicState; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F94A0 void TileMapState::validateWallPlacementAtTile(int playerID, uint x, uint y, short mapperCommand) { From a50bdcf15478ae499edffc876dee77fd85478ca6 Mon Sep 17 00:00:00 2001 From: Gynt Date: Wed, 11 Nov 2026 13:03:12 +0100 Subject: [PATCH 14/28] style(TileMapState): drop unnecessary casts, use countof() for array bounds Removes 50 casts whose removal leaves every function's /FA output and the compiler warnings unchanged; the four (int)(x & 1) casts in placeDefensiveStructureTile stay, since dropping all of them together splits a shared tail. Literal and MC_MAP_TILES_COUNT bounds that are the length of the array being indexed become countof(), and MapConstants.hpp is no longer included where nothing else used it. Codegen-neutral. Co-Authored-By: Claude Opus 5.5 --- .../applyRockGraphicsToFootprint.cpp | 16 +++++----- .../TileMapState/clearBuildingFromTerrain.cpp | 4 +-- .../clearBuildingTilesAndTrees.cpp | 2 +- .../collectCliffEdgeTilesForClimbData.cpp | 10 +++---- .../computeTileAlongAxisOffset.cpp | 2 +- .../countMoatsOwnedByEachPlayer.cpp | 4 +-- .../countUnfinishedMoatTilesForPlayer.cpp | 2 +- .../TileMapState/countUnownedPitchDitches.cpp | 2 +- .../Map/TileMapState/createMoatData.cpp | 2 +- .../Map/TileMapState/destroyWallsOfPlayer.cpp | 3 +- .../findNearestValidDigTileNearTarget.cpp | 2 +- ...TileInSameAreaAndNoTooHeightDifference.cpp | 2 +- .../getBuildingSizeForCommandBuildingType.cpp | 26 ++++++++-------- ...tOrientationThatIsWallTowerOrGatehouse.cpp | 2 +- .../placeDefensiveStructureTile.cpp | 4 +-- .../rebuildShowHiLayerFromHeights.cpp | 4 +-- .../TileMapState/recountTotalOwnedMoats.cpp | 2 +- .../resetAreaBasedOnLogicalLayer.cpp | 4 +-- .../TileMapState/resetHeightAndMapBorders.cpp | 4 +-- .../TileMapState/resetTileAndClearMoat.cpp | 30 +++++++++---------- .../setSignpostDistanceForCampaignMission.cpp | 2 +- .../Map/TileMapState/setupAllMapSections.cpp | 10 +++---- .../Map/TileMapState/setupTileMapSections.cpp | 3 +- .../Map/TileMapState/swapMoatOwnership.cpp | 2 +- .../Map/TileMapState/swapPitchOwnership.cpp | 2 +- .../Map/TileMapState/swapWallOwnership.cpp | 4 +-- .../Map/TileMapState/triggerLoweredView.cpp | 2 +- .../Map/TileMapState/updatePitchDitches.cpp | 6 ++-- .../updateShowHiLayerOrResetChangedLayer.cpp | 2 +- .../upgradeMapFormatLogicLayer.cpp | 12 ++++---- .../validateWallPlacementAtTile.cpp | 2 +- 31 files changed, 81 insertions(+), 93 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp index 2bcbee2daf..5f6cc7c211 100644 --- a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp @@ -33,21 +33,19 @@ namespace Map { if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { if (this->disableElevationRendering == 0) { this->GfxLayer[tile] - = ((short)GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] - + (short)DAT_LandscapeState::instance.rocks[rockID].gfx - + (short)this->buildingRotationRelatedValue + surface) + = GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] + + DAT_LandscapeState::instance.rocks[rockID].gfx + this->buildingRotationRelatedValue + surface - 1; } else if (DAT_LandscapeState::instance.rocks[rockID].size == 1) { this->GfxLayer[tile] - = ((short)GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] - + (short)DAT_LandscapeState::instance.rocks[rockID].gfx - + (short)this->buildingRotationRelatedValue + surface) + = GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] + + DAT_LandscapeState::instance.rocks[rockID].gfx + this->buildingRotationRelatedValue + surface - 1; } else { this->GfxLayer[tile] - = (short)MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::getRandomRockImageOffset, - DAT_LandscapeState::ptr)(((byte)DAT_TileMapState::instance.RandomLayer[tile] & 3) + 1) - + (short)GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] + = MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::getRandomRockImageOffset, + DAT_LandscapeState::ptr)((DAT_TileMapState::instance.RandomLayer[tile] & 3) + 1) + + GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] + surface - 1; } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp index 123555437f..85b7592e92 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFromTerrain.cpp @@ -16,8 +16,8 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00515A20 void TileMapState::clearBuildingFromTerrain(int buildingID) { - uint x = (short)DAT_BuildingsState::instance.buildings[buildingID].x; - uint y = (short)DAT_BuildingsState::instance.buildings[buildingID].y; + uint x = DAT_BuildingsState::instance.buildings[buildingID].x; + uint y = DAT_BuildingsState::instance.buildings[buildingID].y; uint size = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; if (DAT_BuildingsState::instance.buildings[buildingID].buildingType != OpenSHC::Map::Buildings::BT_KILLINGPIT) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateBuildingPlacementAtTile, this)( diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp index 4e36506c5e..9cfe8f2fc9 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingTilesAndTrees.cpp @@ -25,7 +25,7 @@ namespace Map { int tileUnk = DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i]; if ((this->LogicLayer[tileUnk] & L_FARM_FIELD_APPLE) != 0) { int treeID = this->OrganismLayer[tileUnk]; - if (treeID != 0 && treeID < 2000) { + if (treeID != 0 && treeID < countof(DAT_LandscapeState::instance.trees)) { MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeTree, DAT_LandscapeState::ptr)(treeID); } } diff --git a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp index e42c5c6a85..cdb1173db9 100644 --- a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp +++ b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp @@ -1,7 +1,5 @@ #include "../TileMapState.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" - #include "OpenSHC/Globals/DAT_ClimbLogicDefinedData.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" @@ -20,7 +18,7 @@ namespace Map { void TileMapState::collectCliffEdgeTilesForClimbData() { this->temporaryTerrainTypeIndex = 0; - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + for (int tile = 0; tile < countof(this->LogicLayer); tile++) { if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { continue; } @@ -31,7 +29,7 @@ namespace Map { this->temporaryTerrainTypeArray[this->temporaryTerrainTypeIndex] = tile; int const row = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; int const height = this->HeightLayer[tile]; - for (int index = 0; index < 8; index++) { + for (int index = 0; index < countof(DAT_ClimbLogicDefinedData::instance.field_0x2c); index++) { int neighbour = this->directionTranslationMatrix[row][DAT_ClimbLogicDefinedData::instance.field_0x2c[index]] + tile; @@ -41,7 +39,7 @@ namespace Map { } } this->temporaryTerrainTypeIndex += 1; - if ((int)this->temporaryTerrainTypeIndex >= 1000) { + if (this->temporaryTerrainTypeIndex >= countof(this->temporaryTerrainTypeArray)) { return; } } @@ -51,7 +49,7 @@ namespace Map { this->temporaryTerrainTypeBinaryArray[this->temporaryTerrainTypeIndex] = 1; this->temporaryTerrainTypeArray[this->temporaryTerrainTypeIndex] = tile; this->temporaryTerrainTypeIndex += 1; - if ((int)this->temporaryTerrainTypeIndex >= 1000) { + if (this->temporaryTerrainTypeIndex >= countof(this->temporaryTerrainTypeArray)) { return; } } diff --git a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp index b56fed3c49..f6e94c1d0d 100644 --- a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp +++ b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp @@ -16,7 +16,7 @@ namespace Map { direction = 0; } - int count = abs((int)offset); + int count = abs(offset); for (int i = 0; i < count; i++) { tileUnk += this->directionTranslationMatrix[y][direction]; y += yStep; diff --git a/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp b/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp index a25ad3169d..1cfd18f958 100644 --- a/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp +++ b/src/OpenSHC/Map/TileMapState/countMoatsOwnedByEachPlayer.cpp @@ -8,10 +8,10 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x005000E0 void TileMapState::countMoatsOwnedByEachPlayer() { - for (int playerID = 1; playerID < 9; playerID++) { + for (int playerID = 1; playerID < countof(DAT_GameState::instance.playerDataArray); playerID++) { DAT_GameState::instance.playerDataArray[playerID].moatsOwned = 0; } - for (int moatID = 1; moatID < 16000; moatID++) { + for (int moatID = 1; moatID < countof(this->moats); moatID++) { char const owner = this->moats[moatID].owner; if (owner != 0) { int const ownerIndex = owner; diff --git a/src/OpenSHC/Map/TileMapState/countUnfinishedMoatTilesForPlayer.cpp b/src/OpenSHC/Map/TileMapState/countUnfinishedMoatTilesForPlayer.cpp index 94d1f7836b..80daf39b88 100644 --- a/src/OpenSHC/Map/TileMapState/countUnfinishedMoatTilesForPlayer.cpp +++ b/src/OpenSHC/Map/TileMapState/countUnfinishedMoatTilesForPlayer.cpp @@ -9,7 +9,7 @@ namespace Map { int TileMapState::countUnfinishedMoatTilesForPlayer(int playerID) { int unfinishedMoatTiles = 0; - for (int moatID = 1; moatID < 16000; moatID++) { + for (int moatID = 1; moatID < countof(this->moats); moatID++) { if (this->moats[moatID].owner != 0 && this->moats[moatID].owner == playerID && (this->LogicLayer[this->moats[moatID].tile] & L_MOAT) == 0) { unfinishedMoatTiles++; diff --git a/src/OpenSHC/Map/TileMapState/countUnownedPitchDitches.cpp b/src/OpenSHC/Map/TileMapState/countUnownedPitchDitches.cpp index 018ebbd565..a9c81b01c5 100644 --- a/src/OpenSHC/Map/TileMapState/countUnownedPitchDitches.cpp +++ b/src/OpenSHC/Map/TileMapState/countUnownedPitchDitches.cpp @@ -7,7 +7,7 @@ namespace Map { int TileMapState::countUnownedPitchDitches() { int unownedPitchDitches = 0; - for (int pitchDitchID = 0; pitchDitchID < 4000; pitchDitchID++) { + for (int pitchDitchID = 0; pitchDitchID < countof(this->pitchDitches); pitchDitchID++) { if (this->pitchDitches[pitchDitchID].owner == 0) { unownedPitchDitches++; } diff --git a/src/OpenSHC/Map/TileMapState/createMoatData.cpp b/src/OpenSHC/Map/TileMapState/createMoatData.cpp index 44d79cdd6f..0155860a04 100644 --- a/src/OpenSHC/Map/TileMapState/createMoatData.cpp +++ b/src/OpenSHC/Map/TileMapState/createMoatData.cpp @@ -33,7 +33,7 @@ namespace Map { return 0; } - for (int moatID = 1; moatID < 16000; moatID++) { + for (int moatID = 1; moatID < countof(this->moats); moatID++) { if (this->moats[moatID].owner != 0) { continue; } diff --git a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp index 90baeaaa67..5b790a13c9 100644 --- a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp +++ b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp @@ -2,7 +2,6 @@ #include "OpenSHC/Map/Entities/EntityState.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Globals/DAT_EntityState.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" @@ -21,7 +20,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F93E0 void TileMapState::destroyWallsOfPlayer(int playerID) { - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + for (int tile = 0; tile < countof(this->LogicLayer); tile++) { if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { continue; } diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp index 50a6031180..a4b3a91573 100644 --- a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -39,7 +39,7 @@ namespace Map { DAT_BuildingsState::ptr)(targetBuildingID); } - for (int index = 0; index < 4; index++) { + for (int index = 0; index < countof(DAT_TerrainDefinedData::instance.field_0x378c); index++) { int fromXPosition = DAT_TerrainDefinedData::instance.field_0x378c[index].x + x2; int fromYPosition = DAT_TerrainDefinedData::instance.field_0x378c[index].y + y2; int tile = DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile + fromXPosition; diff --git a/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp b/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp index 4e3a3e4b76..3b5883ffd1 100644 --- a/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp +++ b/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp @@ -8,7 +8,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500370 BOOLEnum TileMapState::findTileInSameAreaAndNoTooHeightDifference(int area, int tile, int yUnk) { - for (int attempts = 0; attempts < 8; attempts++) { + for (int attempts = 0; attempts < countof(this->directionTranslationMatrix[yUnk]); attempts++) { int neighbour = this->directionTranslationMatrix[yUnk][attempts] + tile; if (this->HeightLayer[neighbour] > this->HeightLayer[tile] + 16) { continue; diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp index 3d159aae88..b5c0b64baa 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp @@ -28,9 +28,9 @@ namespace Map { case OpenSHC::Commands::M_MAPPER_GARDEN11: case OpenSHC::Commands::M_MAPPER_GARDEN12: case OpenSHC::Commands::M_MAPPER_OIL_SMELTER: - case (MappersEnum)258: - case (MappersEnum)259: - case (MappersEnum)260: + case 258: + case 259: + case 260: case OpenSHC::Commands::M_MAPPER_WATERPOT: return 4; case OpenSHC::Commands::M_MAPPER_STORES: @@ -102,10 +102,10 @@ namespace Map { case OpenSHC::Commands::M_MAPPER_CAMP_FIRE: case OpenSHC::Commands::M_MAPPER_KILLING_PIT: case OpenSHC::Commands::M_MAPPER_PITCH_DITCH: - case (MappersEnum)248: - case (MappersEnum)249: - case (MappersEnum)250: - case (MappersEnum)251: + case 248: + case 249: + case 250: + case 251: case OpenSHC::Commands::M_MAPPER_SHRINE5: return 1; case OpenSHC::Commands::M_MAPPER_KEEP3: @@ -135,12 +135,12 @@ namespace Map { case OpenSHC::Commands::M_MAPPER_GARDEN5: case OpenSHC::Commands::M_MAPPER_GARDEN6: case OpenSHC::Commands::M_MAPPER_GALLOWS: - case (MappersEnum)252: - case (MappersEnum)253: - case (MappersEnum)254: - case (MappersEnum)255: - case (MappersEnum)256: - case (MappersEnum)257: + case 252: + case 253: + case 254: + case 255: + case 256: + case 257: case OpenSHC::Commands::M_MAPPER_GIBBET: case OpenSHC::Commands::M_MAPPER_STATUE1: case OpenSHC::Commands::M_MAPPER_STATUE2: diff --git a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp index 2d8bff6973..4414b160e6 100644 --- a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp @@ -23,7 +23,7 @@ namespace Map { } int rowTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; - for (int index = 0; index < 8; index++) { + for (int index = 0; index < countof(DAT_TerrainDefinedData::instance.SomeOrientationOrderArray); index++) { int orientation = DAT_TerrainDefinedData::instance.SomeOrientationOrderArray[index]; int neighbour = this->directionTranslationMatrix[y][orientation] + rowTile; if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0 diff --git a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp index 87b7e8b6ef..d234ad9f1d 100644 --- a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp +++ b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp @@ -35,7 +35,7 @@ namespace Map { } int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; - short command = (short)mapper; + short command = mapper; this->DamageLayer[tile] = 0; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; if (command == OpenSHC::Commands::M_MAPPER_WALL) { @@ -83,7 +83,7 @@ namespace Map { } if ((this->LogicLayer[tile] & L_TREE) != 0) { int organism = this->OrganismLayer[tile]; - if (organism < 2000) { + if (organism < countof(DAT_LandscapeState::instance.trees)) { DAT_LandscapeState::instance.trees[organism].state = 3; } } diff --git a/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp b/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp index a1ec9632d0..2587837363 100644 --- a/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp +++ b/src/OpenSHC/Map/TileMapState/rebuildShowHiLayerFromHeights.cpp @@ -1,14 +1,12 @@ #include "../TileMapState.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" - namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F79D0 void TileMapState::rebuildShowHiLayerFromHeights() { - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile += 8) { + for (int tile = 0; tile < countof(this->ShowHiLayer); tile += 8) { for (int i = 0; i < 8; i++) { this->ShowHiLayer[tile + i] = this->heightBasedScreenYOffset[this->HeightLayer[tile + i]]; } diff --git a/src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp b/src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp index e3ff1f18d6..e199706384 100644 --- a/src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp +++ b/src/OpenSHC/Map/TileMapState/recountTotalOwnedMoats.cpp @@ -7,7 +7,7 @@ namespace Map { void TileMapState::recountTotalOwnedMoats() { this->currentMoatCount = 0; - for (int i = 1; i < 16000; ++i) { + for (int i = 1; i < countof(this->moats); ++i) { if (this->moats[i].owner != 0) { this->currentMoatCount = i + 1; } diff --git a/src/OpenSHC/Map/TileMapState/resetAreaBasedOnLogicalLayer.cpp b/src/OpenSHC/Map/TileMapState/resetAreaBasedOnLogicalLayer.cpp index 85a489bded..8001534aa3 100644 --- a/src/OpenSHC/Map/TileMapState/resetAreaBasedOnLogicalLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/resetAreaBasedOnLogicalLayer.cpp @@ -1,7 +1,5 @@ #include "../TileMapState.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" - #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" namespace OpenSHC { @@ -13,7 +11,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x005127B0 void TileMapState::resetAreaBasedOnLogicalLayer() { - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + for (int tile = 0; tile < countof(this->LogicLayer); tile++) { if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) == 0) { continue; } diff --git a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp index 77bdc379bd..2df49efedf 100644 --- a/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp +++ b/src/OpenSHC/Map/TileMapState/resetHeightAndMapBorders.cpp @@ -16,7 +16,7 @@ namespace Map { { int inset = (MC_MAP_XY_LIMIT - mapSize) / 2; this->mapSize = mapSize; - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + for (int tile = 0; tile < countof(this->LogicLayer); tile++) { if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; } @@ -92,7 +92,7 @@ namespace Map { DAT_PathFindingState::ptr)(); } - for (int borderTile = 0; borderTile < MC_MAP_TILES_COUNT; borderTile++) { + for (int borderTile = 0; borderTile < countof(this->LogicLayer); borderTile++) { if ((this->LogicLayer[borderTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { this->HeightLayer[borderTile] = 8; } diff --git a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp index 4333a1cb2b..892d7cf13f 100644 --- a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp @@ -28,22 +28,22 @@ namespace Map { this->DamageLayer[tile] = 0; if ((this->LogicLayer[tile] & L_TREE) != 0) { int treeID = this->OrganismLayer[tile]; - if (treeID < 2000) { + if (treeID < countof(DAT_LandscapeState::instance.trees)) { switch (DAT_LandscapeState::instance.trees[treeID].treeType) { - case (TreeType)5: - case (TreeType)6: - case (TreeType)7: - case (TreeType)8: - case (TreeType)9: - case (TreeType)10: - case (TreeType)11: - case (TreeType)12: - case (TreeType)13: - case (TreeType)14: - case (TreeType)16: - case (TreeType)17: - case (TreeType)18: - case (TreeType)19: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 16: + case 17: + case 18: + case 19: DAT_LandscapeState::instance.trees[treeID].state = 3; } } diff --git a/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp b/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp index 5821a0c99c..b0c9d7c527 100644 --- a/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp +++ b/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp @@ -30,7 +30,7 @@ namespace Map { if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_ECONOMIC_CAMPAIGN_SH1 || (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_BUILDERUnk - && (int)DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 >= 2)) { + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 >= 2)) { DAT_GameState::instance.mapAndTime.unk_signpostDistance = 7; } } diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp index 370c2f4c7d..19e31db5cc 100644 --- a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -56,13 +56,13 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupLogicalMapBorders, this)(); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateShowHiLayerOrResetChangedLayer, this)(); - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + for (int tile = 0; tile < countof(this->LogicLayer); tile++) { if (this->LogicLayer[tile] == L_BORDER) { - this->GfxLayer[tile] = (ushort)GMFirstPictureIndex::instance[2]; + this->GfxLayer[tile] = GMFirstPictureIndex::instance[2]; } else if (this->LogicLayer[tile] == L_BORDER_EDGE) { - this->GfxLayer[tile] = (ushort)GMFirstPictureIndex::instance[2] + 1; + this->GfxLayer[tile] = GMFirstPictureIndex::instance[2] + 1; } else { - this->GfxLayer[tile] = (ushort)GMFirstPictureIndex::instance[2] + 2; + this->GfxLayer[tile] = GMFirstPictureIndex::instance[2] + 2; } } @@ -103,7 +103,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::fillWith0xFF, DAT_GameState::ptr)(); MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::clearAnimalSpawnLocationsUnk, DAT_TribesState::ptr)(); - for (int tribe = 0; tribe < 1000; tribe++) { + for (int tribe = 0; tribe < countof(DAT_AICState::instance.tribeIDArray); tribe++) { DAT_AICState::instance.tribeIDArray[tribe] = 0; DAT_AICState::instance.tribeUIDArray[tribe] = 0; } diff --git a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp index 7d54b26763..14a78a006d 100644 --- a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp @@ -2,7 +2,6 @@ #include "OpenSHC/IO/LowLevelMemory.func.hpp" #include "OpenSHC/Random/RNG.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" #include "OpenSHC/Globals/SEC_RNG.hpp" @@ -72,7 +71,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( sizeof(this->SEC_PathfindingCostTileMap1105), '\0', this->SEC_PathfindingCostTileMap1105); - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + for (int tile = 0; tile < countof(this->RandomLayer); tile++) { MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); this->RandomLayer[tile] = SEC_RNG::instance.currentNumber2; } diff --git a/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp index fb78abcc8a..ae9cf6f89d 100644 --- a/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapMoatOwnership.cpp @@ -6,7 +6,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500790 void TileMapState::swapMoatOwnership(int playerID, int otherPlayerID) { - for (int moatID = 1; moatID < 16000; moatID++) { + for (int moatID = 1; moatID < countof(this->moats); moatID++) { if (this->moats[moatID].owner == 0) { continue; } diff --git a/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp index 17f6bff83c..82d2cc90cb 100644 --- a/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapPitchOwnership.cpp @@ -6,7 +6,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500940 void TileMapState::swapPitchOwnership(int playerID, int otherPlayerID) { - for (int pitchDitchID = 1; pitchDitchID < 4000; pitchDitchID++) { + for (int pitchDitchID = 1; pitchDitchID < countof(this->pitchDitches); pitchDitchID++) { if (this->pitchDitches[pitchDitchID].owner == 0) { continue; } diff --git a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp index 7294f09a86..ecfc451238 100644 --- a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp @@ -1,7 +1,5 @@ #include "../TileMapState.func.hpp" -#include "OpenSHC/Map/MapConstants.hpp" - namespace OpenSHC { namespace Map { @@ -10,7 +8,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F9220 void TileMapState::swapWallOwnership(int playerID, int otherPlayerID) { - for (int tile = 0; tile < MC_MAP_TILES_COUNT; tile++) { + for (int tile = 0; tile < countof(this->LogicLayer); tile++) { if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { if ((this->WallOwnerLayer[tile] & 7) + 1 == playerID) { this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~7) | (otherPlayerID - 1); diff --git a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp index 101c896e44..9efaba855d 100644 --- a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp +++ b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp @@ -28,7 +28,7 @@ namespace Map { return; } - for (int unitID = 1; unitID < (int)DAT_UnitsState::instance.maxUnitCount; unitID++) { + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; unitID++) { if (DAT_UnitsState::instance.units[unitID].logicalState == OpenSHC::Map::Units::ULS_INVISIBLE) { continue; } diff --git a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp index f681e62d04..d62135298c 100644 --- a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp @@ -17,7 +17,7 @@ namespace Map { { if (DAT_GameState::instance.gameTicksLoadBalancer % 10 == 3) { this->maxPitchDitchCount = 0; - for (int id = 1; id < 4000; id++) { + for (int id = 1; id < countof(this->pitchDitches); id++) { if (this->pitchDitches[id].owner != 0) { this->maxPitchDitchCount = id + 1; } @@ -40,7 +40,7 @@ namespace Map { this->pitchDitches[id].state += 1; this->pitchDitches[id].field_0x12 = 0; uint height = DAT_TileMapState::instance.HeightLayer[tile]; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.field_0x376c); i++) { int neighbour = DAT_ViewportRenderState::instance .translationMatrix[this->pitchDitches[id].y + DAT_TerrainDefinedData::instance.field_0x376c[i].y] @@ -54,7 +54,7 @@ namespace Map { if (other == 0 || this->pitchDitches[other].state != 1) { continue; } - if (abs((int)(height - DAT_TileMapState::instance.HeightLayer[neighbour])) < 25) { + if (abs(height - DAT_TileMapState::instance.HeightLayer[neighbour]) < 25) { MACRO_CALL(OpenSHC::Map::Entities_Func::SetPlaceOnFire)(this->pitchDitches[other].owner, this->pitchDitches[other].x * 8, this->pitchDitches[other].y * 8, DAT_TileMapState::instance.HeightLayer[this->pitchDitches[other].tile], 3); diff --git a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp index 7decaed7a0..5802b62c2e 100644 --- a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp @@ -17,7 +17,7 @@ namespace Map { this->counter1 += 1; this->refreshCertainTileMap_old = this->refreshCertainTileMap; this->refreshRelatedOne = 0; - for (int row = 0; row < 256; row++) { + for (int row = 0; row < countof(this->heightBasedScreenYOffset); row++) { int target = ((uint)row >> 2) + 1; int step; if (this->refreshCertainTileMap == 3) { diff --git a/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp b/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp index 822be6a0c6..ee74ccb5d0 100644 --- a/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/upgradeMapFormatLogicLayer.cpp @@ -20,22 +20,22 @@ namespace Map { return; } - if ((int)receivedMapVersion < 102) { + if (receivedMapVersion < 102) { MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_102)(); } - if ((int)receivedMapVersion < 120) { + if (receivedMapVersion < 120) { MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_120)(); } - if ((int)receivedMapVersion < 125) { + if (receivedMapVersion < 125) { MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_125)(); } - if ((int)receivedMapVersion < 128) { + if (receivedMapVersion < 128) { MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_128)(); } - if ((int)receivedMapVersion < 145) { + if (receivedMapVersion < 145) { MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_145)(); } - if ((int)receivedMapVersion < 147) { + if (receivedMapVersion < 147) { MACRO_CALL(OpenSHC::Map::Version_Func::UpgradeMapLogicToVersion_147)(); } } diff --git a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp index 061ff6a764..bdc2007eac 100644 --- a/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/validateWallPlacementAtTile.cpp @@ -29,7 +29,7 @@ namespace Map { int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; uint logic = this->LogicLayer[tile]; int const building = this->BuildingLayer[tile]; - if ((logic & L_WALL_OR_GATEHOUSE) != 0 && (char)this->DamageLayer[tile] < 12) { + if ((logic & L_WALL_OR_GATEHOUSE) != 0 && this->DamageLayer[tile] < 12) { return; } if ((logic & L_BUILDING) != 0) { From 6ad2a6cc1381e6ecf4b46deb196cdd41c96cf7b5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Wed, 11 Nov 2026 13:22:37 +0100 Subject: [PATCH 15/28] style(TileMapState): pass 0 instead of '\0' as the fill byte fillMemory_ByteValue takes a uchar, so the char literal only obscured a plain zero. Codegen-neutral. Co-Authored-By: Claude Opus 5.5 --- .../Map/TileMapState/setupAllMapSections.cpp | 2 +- .../Map/TileMapState/setupTileMapSections.cpp | 58 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp index 19e31db5cc..ed50a92faa 100644 --- a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -74,7 +74,7 @@ namespace Map { sizeof(this->DefaultHeightLayer), '\b', this->DefaultHeightLayer); DAT_PathFindingState::instance.searchGeneration = 1; MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(DAT_TileMapState::instance.WalkLayer), '\0', DAT_TileMapState::instance.WalkLayer); + sizeof(DAT_TileMapState::instance.WalkLayer), 0, DAT_TileMapState::instance.WalkLayer); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::setChangedLayerZeroBasedOn40x40Layer, DAT_PathFindingState::ptr)(0); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateLogicalTileMapRelatedSections, this)(); diff --git a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp index 14a78a006d..2c2330d65e 100644 --- a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp @@ -13,63 +13,63 @@ namespace Map { void TileMapState::setupTileMapSections() { MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->GfxLayer), '\0', this->GfxLayer); + sizeof(this->GfxLayer), 0, this->GfxLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->AlphaGFXLayer), '\0', this->AlphaGFXLayer); + sizeof(this->AlphaGFXLayer), 0, this->AlphaGFXLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->ConstructionGFXLayer), '\0', this->ConstructionGFXLayer); + sizeof(this->ConstructionGFXLayer), 0, this->ConstructionGFXLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->PillarGFXLayer), '\0', this->PillarGFXLayer); + sizeof(this->PillarGFXLayer), 0, this->PillarGFXLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->WallGFXLayer), '\0', this->WallGFXLayer); + sizeof(this->WallGFXLayer), 0, this->WallGFXLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->FloatingLayer), '\0', this->FloatingLayer); + sizeof(this->FloatingLayer), 0, this->FloatingLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->UnitLayer), '\0', this->UnitLayer); + sizeof(this->UnitLayer), 0, this->UnitLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->EntityLayer), '\0', this->EntityLayer); + sizeof(this->EntityLayer), 0, this->EntityLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->EntityLayerLT25), '\0', this->EntityLayerLT25); + sizeof(this->EntityLayerLT25), 0, this->EntityLayerLT25); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->BuildingLayer), '\0', this->BuildingLayer); + sizeof(this->BuildingLayer), 0, this->BuildingLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->LogicLayer), '\0', this->LogicLayer); + sizeof(this->LogicLayer), 0, this->LogicLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->Logic2Layer), '\0', this->Logic2Layer); + sizeof(this->Logic2Layer), 0, this->Logic2Layer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->ChangedLayer), '\0', this->ChangedLayer); + sizeof(this->ChangedLayer), 0, this->ChangedLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->OrganismLayer), '\0', this->OrganismLayer); + sizeof(this->OrganismLayer), 0, this->OrganismLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->DamageLayer), '\0', this->DamageLayer); + sizeof(this->DamageLayer), 0, this->DamageLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->MacroLayer), '\0', this->MacroLayer); + sizeof(this->MacroLayer), 0, this->MacroLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->HeightLayer), '\0', this->HeightLayer); + sizeof(this->HeightLayer), 0, this->HeightLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->DefaultHeightLayer), '\0', this->DefaultHeightLayer); + sizeof(this->DefaultHeightLayer), 0, this->DefaultHeightLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->ShowHiLayer), '\0', this->ShowHiLayer); + sizeof(this->ShowHiLayer), 0, this->ShowHiLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->MiscDisplayLayer), '\0', this->MiscDisplayLayer); + sizeof(this->MiscDisplayLayer), 0, this->MiscDisplayLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->LuminesenceLayer), '\0', this->LuminesenceLayer); + sizeof(this->LuminesenceLayer), 0, this->LuminesenceLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->WallOwnerLayer), '\0', this->WallOwnerLayer); + sizeof(this->WallOwnerLayer), 0, this->WallOwnerLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->BuildingWasLayer), '\0', this->BuildingWasLayer); + sizeof(this->BuildingWasLayer), 0, this->BuildingWasLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->OccupancyLayer), '\0', this->OccupancyLayer); + sizeof(this->OccupancyLayer), 0, this->OccupancyLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->AIZoneLayer), '\0', this->AIZoneLayer); + sizeof(this->AIZoneLayer), 0, this->AIZoneLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->AIInfoLayer), '\0', this->AIInfoLayer); + sizeof(this->AIInfoLayer), 0, this->AIInfoLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->unitDeathHeatMap), '\0', this->unitDeathHeatMap); + sizeof(this->unitDeathHeatMap), 0, this->unitDeathHeatMap); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->SEC_TileMap1104), '\0', this->SEC_TileMap1104); + sizeof(this->SEC_TileMap1104), 0, this->SEC_TileMap1104); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->SEC_PathfindingCostTileMap1105), '\0', this->SEC_PathfindingCostTileMap1105); + sizeof(this->SEC_PathfindingCostTileMap1105), 0, this->SEC_PathfindingCostTileMap1105); for (int tile = 0; tile < countof(this->RandomLayer); tile++) { MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); From 51479bdfbe24984bfb0028e659e12842c59be02d Mon Sep 17 00:00:00 2001 From: Gynt Date: Wed, 11 Nov 2026 13:41:22 +0100 Subject: [PATCH 16/28] style(TileMapState): use main's MapOrientation and BOOLEnum field types With main's headers, mapOrientation is a MapOrientationInt and the forceUpdate* flags are BOOLEnum: compare against MO_NORTH/EAST/SOUTH/WEST and assign TRUE/FALSE. PathConnectionLayer is now short, which makes the (short) read casts redundant. reccmp unchanged (87/88 at 100%). Co-Authored-By: Claude Opus 5.5 --- .../TileMapState/Constructor_TileMapState.cpp | 6 +++--- .../Map/TileMapState/changeMapOrientation.cpp | 8 ++++---- .../TileMapState/computeClimbRampRotation.cpp | 6 +++--- .../computeWallCornerRenderRotation.cpp | 16 ++++++++-------- .../findNearestValidDigTileNearTarget.cpp | 2 +- ...indTileInSameAreaAndNoTooHeightDifference.cpp | 2 +- .../Map/TileMapState/forceFullTileMapRedraw.cpp | 6 +++--- .../getBuildingSizeIndexMappingData.cpp | 8 ++++---- .../getWallFlagForOrientedDirection.cpp | 16 ++++++++-------- .../TileMapState/hasHigherNeighborWithStairs.cpp | 8 ++++---- ...hasHigherPlainNeighborWithWallOrGatehouse.cpp | 8 ++++---- .../Map/TileMapState/setupAllMapSections.cpp | 10 +++++----- .../Map/TileMapState/updateMacroLayer.cpp | 4 ++-- .../updateShowHiLayerOrResetChangedLayer.cpp | 2 +- 14 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp index 03169c8e95..6c35a93f4b 100644 --- a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp +++ b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp @@ -26,9 +26,9 @@ namespace Map { this->refreshRelatedOne = 1; this->disableElevationRendering = 0; this->refreshRelatedTwo = 0; - this->forceUpdateLogicalAndMiscDisplayLayers = 1; - this->forceUpdateTextureTilemap = 1; - this->forceUpdateGFXLayers = 1; + this->forceUpdateLogicalAndMiscDisplayLayers = TRUE; + this->forceUpdateTextureTilemap = TRUE; + this->forceUpdateGFXLayers = TRUE; this->refreshCertainTileMap_old = 4; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); this->moatTileCount = 0; diff --git a/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp b/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp index b80e8a4ab2..cbb56ddf2d 100644 --- a/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp +++ b/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp @@ -23,28 +23,28 @@ namespace Map { OpenSHC::Map::Buildings::BuildingsState_Func::refreshAllBuildingTileDisplays, DAT_BuildingsState::ptr)(); DAT_BuildingsState::instance.field_0x10 = 5; switch (this->mapOrientation) { - case 0: + case OpenSHC::Map::Enums::MO_NORTH: this->screenSouthEastDirection = 3; this->orientedRowStep = 1; this->screenEastDirection = 2; this->screenSouthDirection = 4; this->screenSouthWestDirection = 5; return; - case 2: + case OpenSHC::Map::Enums::MO_EAST: this->screenSouthEastDirection = 5; this->orientedRowStep = 1; this->screenEastDirection = 4; this->screenSouthDirection = 6; this->screenSouthWestDirection = 7; return; - case 4: + case OpenSHC::Map::Enums::MO_SOUTH: this->screenSouthEastDirection = 7; this->screenEastDirection = 6; this->screenSouthDirection = 0; this->screenSouthWestDirection = 1; this->orientedRowStep = -1; return; - case 6: + case OpenSHC::Map::Enums::MO_WEST: this->screenSouthEastDirection = 1; this->screenEastDirection = 0; this->screenSouthDirection = 2; diff --git a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp index 2a98490149..fa6835c971 100644 --- a/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeClimbRampRotation.cpp @@ -66,19 +66,19 @@ namespace Map { rotation = 4; } - if (this->mapOrientation == 0) { + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { if (rotation == 1) { this->wallCornerRotation = 32 - (x & 0x1f); } else { this->wallCornerRotation = 32 - (y & 0x1f); } - } else if (this->mapOrientation == 4) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { if (rotation == 1) { this->wallCornerRotation = (x & 0x1f) + 1; } else { this->wallCornerRotation = (y & 0x1f) + 1; } - } else if (this->mapOrientation == 2) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { this->wallCornerRotation = (y & 0x1f) + 1; } else { this->wallCornerRotation = 32 - (y & 0x1f); diff --git a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp index 0d4b929a58..2943d45bab 100644 --- a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp @@ -12,25 +12,25 @@ namespace Map { int y = this->DAT_SomeY; int result = 0; if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)(tileUnk, y, 2)) { - if (this->mapOrientation == 0) { + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { if ((x & 0xf) == 0xf) { result = 2; } else { result = 17 - (x & 0xf); } - } else if (this->mapOrientation == 4) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { if ((x & 0xf) == 0) { result = 2; } else { result = (x & 0xf) + 2; } - } else if (this->mapOrientation == 2) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { if ((x & 0xf) == 0) { result = 1; } else { result = (x & 0xf) + 17; } - } else if (this->mapOrientation == 6) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { if ((x & 0xf) == 0xf) { result = 1; } else { @@ -39,25 +39,25 @@ namespace Map { } } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)( tileUnk, y, 0)) { - if (this->mapOrientation == 0) { + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { if ((y & 0xf) == 0xf) { result = 1; } else { result = 32 - (y & 0xf); } - } else if (this->mapOrientation == 4) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { if ((y & 0xf) == 0) { result = 1; } else { result = (y & 0xf) + 17; } - } else if (this->mapOrientation == 6) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { if ((y & 0xf) == 0) { result = 2; } else { result = (y & 0xf) + 2; } - } else if (this->mapOrientation == 2) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { if ((y & 0xf) == 0xf) { result = 2; } else { diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp index a4b3a91573..99aefd72db 100644 --- a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -43,7 +43,7 @@ namespace Map { int fromXPosition = DAT_TerrainDefinedData::instance.field_0x378c[index].x + x2; int fromYPosition = DAT_TerrainDefinedData::instance.field_0x378c[index].y + y2; int tile = DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile + fromXPosition; - if ((short)this->PathConnectionLayer[tile] != area) { + if (this->PathConnectionLayer[tile] != area) { continue; } uint height = this->HeightLayer[tile]; diff --git a/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp b/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp index 3b5883ffd1..fb2a258513 100644 --- a/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp +++ b/src/OpenSHC/Map/TileMapState/findTileInSameAreaAndNoTooHeightDifference.cpp @@ -13,7 +13,7 @@ namespace Map { if (this->HeightLayer[neighbour] > this->HeightLayer[tile] + 16) { continue; } - if ((short)this->PathConnectionLayer[neighbour] != area) { + if (this->PathConnectionLayer[neighbour] != area) { continue; } return TRUE; diff --git a/src/OpenSHC/Map/TileMapState/forceFullTileMapRedraw.cpp b/src/OpenSHC/Map/TileMapState/forceFullTileMapRedraw.cpp index 50d530182b..01611f2753 100644 --- a/src/OpenSHC/Map/TileMapState/forceFullTileMapRedraw.cpp +++ b/src/OpenSHC/Map/TileMapState/forceFullTileMapRedraw.cpp @@ -6,9 +6,9 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x005017A0 void TileMapState::forceFullTileMapRedraw() { - this->forceUpdateLogicalAndMiscDisplayLayers = 1; - this->forceUpdateTextureTilemap = 1; - this->forceUpdateGFXLayers = 1; + this->forceUpdateLogicalAndMiscDisplayLayers = TRUE; + this->forceUpdateTextureTilemap = TRUE; + this->forceUpdateGFXLayers = TRUE; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); } diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp index 86b6e66bab..3bec836ac0 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp @@ -12,19 +12,19 @@ namespace Map { this->buildingX = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][0]; this->buildingY = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][1]; switch (this->mapOrientation) { - case 0: + case OpenSHC::Map::Enums::MO_NORTH: this->buildingRotationRelatedValue = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][2]; return; - case 2: + case OpenSHC::Map::Enums::MO_EAST: this->buildingRotationRelatedValue = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][3]; return; - case 4: + case OpenSHC::Map::Enums::MO_SOUTH: this->buildingRotationRelatedValue = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][4]; return; - case 6: + case OpenSHC::Map::Enums::MO_WEST: this->buildingRotationRelatedValue = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][5]; } diff --git a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp index c6f5eb82e7..be1afabcd3 100644 --- a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp @@ -8,23 +8,23 @@ namespace Map { { int direction = 0; if (twoOrFour == 2) { - if (this->mapOrientation == 0) { + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { direction = 2; - } else if (this->mapOrientation == 2) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { direction = 4; - } else if (this->mapOrientation == 4) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { direction = 6; - } else if (this->mapOrientation == 6) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { direction = 0; } } else if (twoOrFour == 4) { - if (this->mapOrientation == 0) { + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { direction = 4; - } else if (this->mapOrientation == 2) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { direction = 6; - } else if (this->mapOrientation == 4) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { direction = 0; - } else if (this->mapOrientation == 6) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { direction = 2; } } else { diff --git a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp index 922eea38d4..879cad2e2d 100644 --- a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp +++ b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp @@ -9,13 +9,13 @@ namespace Map { BOOLEnum TileMapState::hasHigherNeighborWithStairs(int tileUnk, int y, int direction) { int rotatedDirection = 0; - if (this->mapOrientation == 0) { + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { rotatedDirection = direction; - } else if (this->mapOrientation == 4) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { rotatedDirection = direction + 4; - } else if (this->mapOrientation == 2) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { rotatedDirection = direction + 2; - } else if (this->mapOrientation == 6) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { rotatedDirection = direction + 6; } if (rotatedDirection >= 8) { diff --git a/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp index 0f2cb8bf82..5403da05a0 100644 --- a/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp @@ -12,13 +12,13 @@ namespace Map { BOOLEnum TileMapState::hasHigherPlainNeighborWithWallOrGatehouse(int tile, int y, int direction) { int rotatedDirection = 0; - if (this->mapOrientation == 0) { + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { rotatedDirection = direction; - } else if (this->mapOrientation == 4) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { rotatedDirection = direction + 4; - } else if (this->mapOrientation == 2) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { rotatedDirection = direction + 2; - } else if (this->mapOrientation == 6) { + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { rotatedDirection = direction + 6; } if (rotatedDirection >= 8) { diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp index ed50a92faa..30a0d97cf4 100644 --- a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -114,17 +114,17 @@ namespace Map { MACRO_CALL_MEMBER( OpenSHC::Map::Entities::EntityState_Func::clearEntityArrayAndSeagullArray, DAT_EntityState::ptr)(); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); - this->forceUpdateLogicalAndMiscDisplayLayers = 1; - this->forceUpdateTextureTilemap = 1; - this->forceUpdateGFXLayers = 1; - this->forceUpdateMacroLayerFlag = 1; + this->forceUpdateLogicalAndMiscDisplayLayers = TRUE; + this->forceUpdateTextureTilemap = TRUE; + this->forceUpdateGFXLayers = TRUE; + this->forceUpdateMacroLayerFlag = TRUE; this->field_0x55487c = 200; MACRO_CALL_MEMBER( OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageLayerForEachBuildingAtEachTile, DAT_PathFindingState::ptr)(); MACRO_CALL_MEMBER( OpenSHC::Map::Navigation::PathFindingState_Func::updateSeparateAreaTileMap, DAT_PathFindingState::ptr)(1); - this->forceUpdateMacroLayerFlag = 1; + this->forceUpdateMacroLayerFlag = TRUE; this->field_0x55487c = 500; MACRO_CALL_MEMBER( OpenSHC::UI::MinimapViewState_Func::setTileColorsDependingOnMapSize, DAT_MinimapViewState::ptr)(0, 100); diff --git a/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp b/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp index c8bd742bc5..2bf49c3f9c 100644 --- a/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp @@ -20,7 +20,7 @@ namespace Map { return; } - this->forceUpdateMacroLayerFlag = 0; + this->forceUpdateMacroLayerFlag = FALSE; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)( L_DEFAULT_EARTH_OR_TEXTURE, L2_SCRUB, 0); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_MARSH, L_NONE, 0); @@ -31,7 +31,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_NONE, L2_PLATEAU_MEDIUM, 0); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_NONE, L2_PLATEAU_HIGH, 0); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated2, this)(); - this->forceUpdateTextureTilemap = 1; + this->forceUpdateTextureTilemap = TRUE; } } diff --git a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp index 5802b62c2e..676ff1662a 100644 --- a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp @@ -73,7 +73,7 @@ namespace Map { this->refreshRelatedTwo = 2; } this->refreshCertainTileMap = 0; - this->forceUpdateLogicalAndMiscDisplayLayers = 1; + this->forceUpdateLogicalAndMiscDisplayLayers = TRUE; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); this->counter1 = 0; DAT_RotateMapOrPullDownTerrain::instance = 1; From 7d1f8703a5bbfcac3e146bc77b0513fda10e2efe Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 12 Nov 2026 17:05:03 +0100 Subject: [PATCH 17/28] types: add the CardinalDirection enum Exported by hand from Ghidra's /_HoldStrong/Map/Enums/CardinalDirection (CD_NORTH = 0 ... CD_NORTHWEST = 7, CD_UPPER_LIMIT = 8), which had no header yet. It names the second index of directionTranslationMatrix. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Enums/CardinalDirection.hpp | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/OpenSHC/Map/Enums/CardinalDirection.hpp diff --git a/src/OpenSHC/Map/Enums/CardinalDirection.hpp b/src/OpenSHC/Map/Enums/CardinalDirection.hpp new file mode 100644 index 0000000000..d7c402f4f5 --- /dev/null +++ b/src/OpenSHC/Map/Enums/CardinalDirection.hpp @@ -0,0 +1,31 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Enums/CardinalDirection.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Enums { + typedef enum CardinalDirection { + + CD_NORTH = 0, // 0x00000000 + CD_NORTHEAST = 1, // 0x00000001 + CD_EAST = 2, // 0x00000002 + CD_SOUTHEAST = 3, // 0x00000003 + CD_SOUTH = 4, // 0x00000004 + CD_SOUTHWEST = 5, // 0x00000005 + CD_WEST = 6, // 0x00000006 + CD_NORTHWEST = 7, // 0x00000007 + CD_UPPER_LIMIT = 8 // 0x00000008 + + } CardinalDirection; + + static_assert_cpp98_obj(sizeof(CardinalDirection) == 4, CardinalDirection); + } // namespace Enums +} // namespace Map +} // namespace OpenSHC From 31a645faf4c3922ed80219da05114db511b08c0a Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 12 Nov 2026 17:05:04 +0100 Subject: [PATCH 18/28] types: getOrientationThatIsWallTowerOrGatehouse returns MapOrientation As Ghidra already types it. The "no wall" result is MO_NONE (15). The other results come from SomeOrientationOrderArray {0, 4, 2, 6, 1, 7, 3, 5}, so the diagonals are returned as well. Codegen unchanged. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/TileMapState.func.hpp | 2 +- src/OpenSHC/Map/TileMapState.hpp | 3 ++- .../getOrientationThatIsWallTowerOrGatehouse.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState.func.hpp b/src/OpenSHC/Map/TileMapState.func.hpp index 16e2e7fac6..d59f7d0b63 100644 --- a/src/OpenSHC/Map/TileMapState.func.hpp +++ b/src/OpenSHC/Map/TileMapState.func.hpp @@ -142,7 +142,7 @@ namespace Map { &TileMapState::hasHigherPlainNeighborWithWallOrGatehouse) hasHigherPlainNeighborWithWallOrGatehouse; - MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(uint, uint), false, Address::SHC_3BB0A8C1_0x004F8B50, + MACRO_FUNCTION_RESOLVER(MapOrientation (TileMapState::*)(uint, uint), false, Address::SHC_3BB0A8C1_0x004F8B50, &TileMapState::getOrientationThatIsWallTowerOrGatehouse) getOrientationThatIsWallTowerOrGatehouse; diff --git a/src/OpenSHC/Map/TileMapState.hpp b/src/OpenSHC/Map/TileMapState.hpp index 5c4ae6241b..b2e1a899d7 100644 --- a/src/OpenSHC/Map/TileMapState.hpp +++ b/src/OpenSHC/Map/TileMapState.hpp @@ -28,6 +28,7 @@ namespace Map { using OpenSHC::Map::PitchDitch; using OpenSHC::Map::Buildings::BuildingFailReasonEnumInt; using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::Map::Enums::MapOrientation; using OpenSHC::Map::Enums::MapOrientationInt; using OpenSHC::Map::LogicHelpers::Logic1; using OpenSHC::Map::LogicHelpers::Logic2; @@ -304,7 +305,7 @@ namespace Map { BOOLEnum hasHigherPlainNeighborWithWallOrGatehouse(int param_1, int param_2, int param_3); - int getOrientationThatIsWallTowerOrGatehouse(uint x, uint y); + MapOrientation getOrientationThatIsWallTowerOrGatehouse(uint x, uint y); void renderWallDragPreview(int playerID, uint x1, uint y1, uint x2, uint y2, short command); diff --git a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp index 4414b160e6..e2735beaf8 100644 --- a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp @@ -13,13 +13,13 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004F8B50 - int TileMapState::getOrientationThatIsWallTowerOrGatehouse(uint x, uint y) + MapOrientation TileMapState::getOrientationThatIsWallTowerOrGatehouse(uint x, uint y) { if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { - return 15; + return OpenSHC::Map::Enums::MO_NONE; } if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { - return 15; + return OpenSHC::Map::Enums::MO_NONE; } int rowTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; @@ -28,10 +28,10 @@ namespace Map { int neighbour = this->directionTranslationMatrix[y][orientation] + rowTile; if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[neighbour] & (L_STOCKPILEUnk | L_CRENEL_VARIATIONUnk)) == 0) { - return orientation; + return (MapOrientation)orientation; } } - return 15; + return OpenSHC::Map::Enums::MO_NONE; } } From 04a5f3e7e10f601b3d6ad897bf7c1ffbec4d49a0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 12 Nov 2026 17:05:12 +0100 Subject: [PATCH 19/28] style(TileMapState): enum names from review - countLogicPropertyInSurroundingTiles: CD_NORTH/EAST/SOUTH/WEST for the directionTranslationMatrix index - resetTileAndClearMoat: TreeType values for the tree-state switch - setupTileMapSections: changeMapOrientation(MO_NORTH) - getCastleBuildRangeForMapSize: MC_MAP_SIZE_* cases - getBuildingSizeForCommandBuildingType: M_MAPPER_UNKNOWN_248..260 from main Each function compiles to the same instructions as before. Co-Authored-By: Claude Opus 5.5 --- .../countLogicPropertyInSurroundingTiles.cpp | 14 ++++++--- .../getBuildingSizeForCommandBuildingType.cpp | 26 ++++++++-------- .../getCastleBuildRangeForMapSize.cpp | 8 ++--- .../TileMapState/resetTileAndClearMoat.cpp | 30 ++++++++++--------- .../Map/TileMapState/setupTileMapSections.cpp | 2 +- 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/countLogicPropertyInSurroundingTiles.cpp b/src/OpenSHC/Map/TileMapState/countLogicPropertyInSurroundingTiles.cpp index 95f8d15a0f..101c4c9ce9 100644 --- a/src/OpenSHC/Map/TileMapState/countLogicPropertyInSurroundingTiles.cpp +++ b/src/OpenSHC/Map/TileMapState/countLogicPropertyInSurroundingTiles.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" + namespace OpenSHC { namespace Map { @@ -7,16 +9,20 @@ namespace Map { void TileMapState::countLogicPropertyInSurroundingTiles(int tile, int y, uint logic1) { this->DAT_CardinalTilesAroundTile = 0; - if ((this->LogicLayer[this->directionTranslationMatrix[y][0] + tile] & logic1) != 0) { + if ((this->LogicLayer[this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_NORTH] + tile] & logic1) + != 0) { this->DAT_CardinalTilesAroundTile++; } - if ((this->LogicLayer[this->directionTranslationMatrix[y][2] + tile] & logic1) != 0) { + if ((this->LogicLayer[this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_EAST] + tile] & logic1) + != 0) { this->DAT_CardinalTilesAroundTile++; } - if ((this->LogicLayer[this->directionTranslationMatrix[y][4] + tile] & logic1) != 0) { + if ((this->LogicLayer[this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_SOUTH] + tile] & logic1) + != 0) { this->DAT_CardinalTilesAroundTile++; } - if ((this->LogicLayer[this->directionTranslationMatrix[y][6] + tile] & logic1) != 0) { + if ((this->LogicLayer[this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_WEST] + tile] & logic1) + != 0) { this->DAT_CardinalTilesAroundTile++; } } diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp index b5c0b64baa..1f3e1f74a7 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeForCommandBuildingType.cpp @@ -28,9 +28,9 @@ namespace Map { case OpenSHC::Commands::M_MAPPER_GARDEN11: case OpenSHC::Commands::M_MAPPER_GARDEN12: case OpenSHC::Commands::M_MAPPER_OIL_SMELTER: - case 258: - case 259: - case 260: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_258: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_259: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_260: case OpenSHC::Commands::M_MAPPER_WATERPOT: return 4; case OpenSHC::Commands::M_MAPPER_STORES: @@ -102,10 +102,10 @@ namespace Map { case OpenSHC::Commands::M_MAPPER_CAMP_FIRE: case OpenSHC::Commands::M_MAPPER_KILLING_PIT: case OpenSHC::Commands::M_MAPPER_PITCH_DITCH: - case 248: - case 249: - case 250: - case 251: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_248: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_249: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_250: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_251: case OpenSHC::Commands::M_MAPPER_SHRINE5: return 1; case OpenSHC::Commands::M_MAPPER_KEEP3: @@ -135,12 +135,12 @@ namespace Map { case OpenSHC::Commands::M_MAPPER_GARDEN5: case OpenSHC::Commands::M_MAPPER_GARDEN6: case OpenSHC::Commands::M_MAPPER_GALLOWS: - case 252: - case 253: - case 254: - case 255: - case 256: - case 257: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_252: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_253: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_254: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_255: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_256: + case OpenSHC::Commands::M_MAPPER_UNKNOWN_257: case OpenSHC::Commands::M_MAPPER_GIBBET: case OpenSHC::Commands::M_MAPPER_STATUE1: case OpenSHC::Commands::M_MAPPER_STATUE2: diff --git a/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp b/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp index 56763b7058..4061a2024b 100644 --- a/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp +++ b/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp @@ -9,13 +9,13 @@ namespace Map { undefined4 TileMapState::getCastleBuildRangeForMapSize() { switch (this->mapSize) { - case 160: + case MC_MAP_SIZE_160: return 45; - case 200: + case MC_MAP_SIZE_200: return 50; - case 300: + case MC_MAP_SIZE_300: return 60; - case MC_MAP_XY_LIMIT: + case MC_MAP_SIZE_400: return 70; } return 70; diff --git a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp index 892d7cf13f..ea1fefc88a 100644 --- a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Trees/TreeType.hpp" + #include "OpenSHC/Globals/DAT_LandscapeState.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" @@ -30,20 +32,20 @@ namespace Map { int treeID = this->OrganismLayer[tile]; if (treeID < countof(DAT_LandscapeState::instance.trees)) { switch (DAT_LandscapeState::instance.trees[treeID].treeType) { - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 16: - case 17: - case 18: - case 19: + case OpenSHC::Map::Trees::TT_UNKNOWN_5: + case OpenSHC::Map::Trees::TT_UNKNOWN_6: + case OpenSHC::Map::Trees::TT_UNKNOWN_7: + case OpenSHC::Map::Trees::TT_UNKNOWN_8: + case OpenSHC::Map::Trees::TT_UNKNOWN_9: + case OpenSHC::Map::Trees::TT_UNKNOWN_10: + case OpenSHC::Map::Trees::TT_UNKNOWN_11: + case OpenSHC::Map::Trees::TT_UNKNOWN_12: + case OpenSHC::Map::Trees::TT_UNKNOWN_13: + case OpenSHC::Map::Trees::TT_UNKNOWN_14: + case OpenSHC::Map::Trees::TT_UNKNOWN_16: + case OpenSHC::Map::Trees::TT_UNKNOWN_17: + case OpenSHC::Map::Trees::TT_UNKNOWN_18: + case OpenSHC::Map::Trees::TT_UNKNOWN_19: DAT_LandscapeState::instance.trees[treeID].state = 3; } } diff --git a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp index 2c2330d65e..e62bcf81a3 100644 --- a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp @@ -75,7 +75,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); this->RandomLayer[tile] = SEC_RNG::instance.currentNumber2; } - MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::changeMapOrientation, this)(0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::changeMapOrientation, this)(OpenSHC::Map::Enums::MO_NORTH); this->DAT_FutureMapOrientation = 8; } From 5c1e705c8898fa4dd78de81990a9508b41e09f7b Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 12 Nov 2026 17:35:26 +0100 Subject: [PATCH 20/28] reimplement(TileMapState): follow main's changeMapOrientation(MapOrientation) The upstream Ghidra export types the parameter as MapOrientation, so the definition takes one and processMapOrientationChange casts the pending orientation it passes. Codegen unchanged. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp | 2 +- src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp b/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp index cbb56ddf2d..b357b6ff74 100644 --- a/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp +++ b/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp @@ -11,7 +11,7 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00501B90 - void TileMapState::changeMapOrientation(int mapOrientation) + void TileMapState::changeMapOrientation(MapOrientation mapOrientation) { MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::saveFocusTileAndCenterPreview, DAT_ViewportRenderState::ptr)(); diff --git a/src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp b/src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp index 3c44508739..967bd96d43 100644 --- a/src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp +++ b/src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp @@ -8,7 +8,7 @@ namespace Map { { if ((int)this->DAT_FutureMapOrientation < 8) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::changeMapOrientation, this)( - this->DAT_FutureMapOrientation); + (MapOrientation)this->DAT_FutureMapOrientation); this->DAT_FutureMapOrientation = 8; } } From 9882188fc83ddd0c758ae467caff86dd44792420 Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 12 Nov 2026 17:35:26 +0100 Subject: [PATCH 21/28] types: getOrientationThatIsWallTowerOrGatehouse returns CardinalDirection The result is a neighbour direction taken from SomeOrientationOrderArray {0, 4, 2, 6, 1, 7, 3, 5}, so the diagonals are returned too, which MapOrientation has no names for. "Nothing found" stays 15 (MO_NONE); CardinalDirection has no value for it. Codegen unchanged. Ghidra still types the return as MapOrientation, so the next export will revert this unless the function signature is changed there as well. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/TileMapState.func.hpp | 4 +++- src/OpenSHC/Map/TileMapState.hpp | 4 +++- .../getOrientationThatIsWallTowerOrGatehouse.cpp | 10 +++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState.func.hpp b/src/OpenSHC/Map/TileMapState.func.hpp index f00d1234c2..ead5a21257 100644 --- a/src/OpenSHC/Map/TileMapState.func.hpp +++ b/src/OpenSHC/Map/TileMapState.func.hpp @@ -5,6 +5,7 @@ #include "OpenSHC/Commands/MappersEnum.hpp" #include "OpenSHC/IO/PackagedFileMagicNum.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/Map/Enums/MapOrientation.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" #include "OpenSHC/Map/LogicHelpers/Logic2.hpp" @@ -17,6 +18,7 @@ namespace Map { using OpenSHC::Commands::MappersEnum; using OpenSHC::IO::PackagedFileMagicNum; using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::Map::Enums::CardinalDirection; using OpenSHC::Map::Enums::MapOrientation; using OpenSHC::Map::LogicHelpers::Logic1; using OpenSHC::Map::LogicHelpers::Logic2; @@ -144,7 +146,7 @@ namespace Map { &TileMapState::hasHigherPlainNeighborWithWallOrGatehouse) hasHigherPlainNeighborWithWallOrGatehouse; - MACRO_FUNCTION_RESOLVER(MapOrientation (TileMapState::*)(uint, uint), false, Address::SHC_3BB0A8C1_0x004F8B50, + MACRO_FUNCTION_RESOLVER(CardinalDirection (TileMapState::*)(uint, uint), false, Address::SHC_3BB0A8C1_0x004F8B50, &TileMapState::getOrientationThatIsWallTowerOrGatehouse) getOrientationThatIsWallTowerOrGatehouse; diff --git a/src/OpenSHC/Map/TileMapState.hpp b/src/OpenSHC/Map/TileMapState.hpp index d4bce988a0..b41b11cb16 100644 --- a/src/OpenSHC/Map/TileMapState.hpp +++ b/src/OpenSHC/Map/TileMapState.hpp @@ -12,6 +12,7 @@ #include "OpenSHC/IO/PackagedFileMagicNum.hpp" #include "OpenSHC/Map/Buildings/BuildingFailReasonEnumInt.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/Map/Enums/MapOrientation.hpp" #include "OpenSHC/Map/Enums/MapOrientationInt.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" @@ -29,6 +30,7 @@ namespace Map { using OpenSHC::Map::PitchDitch; using OpenSHC::Map::Buildings::BuildingFailReasonEnumInt; using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::Map::Enums::CardinalDirection; using OpenSHC::Map::Enums::MapOrientation; using OpenSHC::Map::Enums::MapOrientationInt; using OpenSHC::Map::LogicHelpers::Logic1; @@ -306,7 +308,7 @@ namespace Map { BOOLEnum hasHigherPlainNeighborWithWallOrGatehouse(int param_1, int param_2, int param_3); - MapOrientation getOrientationThatIsWallTowerOrGatehouse(uint x, uint y); + CardinalDirection getOrientationThatIsWallTowerOrGatehouse(uint x, uint y); void renderWallDragPreview(int playerID, uint x1, uint y1, uint x2, uint y2, short command); diff --git a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp index e2735beaf8..630a1c7ed7 100644 --- a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp @@ -13,13 +13,13 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004F8B50 - MapOrientation TileMapState::getOrientationThatIsWallTowerOrGatehouse(uint x, uint y) + CardinalDirection TileMapState::getOrientationThatIsWallTowerOrGatehouse(uint x, uint y) { if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { - return OpenSHC::Map::Enums::MO_NONE; + return (CardinalDirection)OpenSHC::Map::Enums::MO_NONE; } if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { - return OpenSHC::Map::Enums::MO_NONE; + return (CardinalDirection)OpenSHC::Map::Enums::MO_NONE; } int rowTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; @@ -28,10 +28,10 @@ namespace Map { int neighbour = this->directionTranslationMatrix[y][orientation] + rowTile; if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[neighbour] & (L_STOCKPILEUnk | L_CRENEL_VARIATIONUnk)) == 0) { - return (MapOrientation)orientation; + return (CardinalDirection)orientation; } } - return OpenSHC::Map::Enums::MO_NONE; + return (CardinalDirection)OpenSHC::Map::Enums::MO_NONE; } } From 531e6e31286bc62d19f23521a4ed2552346b4009 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 15 Nov 2026 22:43:36 +0100 Subject: [PATCH 22/28] style(TileMapState): direction, orientation and view enums from review - CardinalDirection for directionTranslationMatrix columns and direction parameters; MapOrientation steps for the neighbour rotation; CD_UPPER_LIMIT for the wrap and the queued-orientation sentinel - if/else flag checks (L_WALL_OR_GATEHOUSE, L_STAIRS, L_CRENEL) instead of shift-and-mask - new LoweredViewTransition (refreshCertainTileMap) and EditorRockType enums - rotateFearFactorBuildingVariations: int timeGetTime() result, ERT_*/MO_* - setupAllMapSections: 8 instead of '\b'; getTileForBrush: countof bound Each function compiles to the same instructions as before. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH --- src/OpenSHC/Map/Enums/EditorRockType.hpp | 28 ++++++++++ .../Map/Enums/LoweredViewTransition.hpp | 27 +++++++++ .../TileMapState/Constructor_TileMapState.cpp | 10 ++-- .../Map/TileMapState/changeMapOrientation.cpp | 33 +++++------ .../computeWallCornerRenderRotation.cpp | 10 ++-- ...tOrientationThatIsWallTowerOrGatehouse.cpp | 5 +- .../Map/TileMapState/getTileForBrush.cpp | 5 +- .../getWallFlagForOrientedDirection.cpp | 32 +++++++---- .../hasHigherNeighborWithStairs.cpp | 20 ++++--- ...HigherPlainNeighborWithWallOrGatehouse.cpp | 19 ++++--- .../hasOnlyTowerNeighborsNoWalls.cpp | 9 +-- .../TileMapState/isCliffDropInDirection.cpp | 4 +- .../TileMapState/isTileEnclosedByWalls.cpp | 10 ++-- .../isTileEnclosedByWallsOrGates.cpp | 9 +-- .../isWallConnectionHeightValid.cpp | 27 ++++----- .../isWallCornerForCardinalDirection.cpp | 54 +++++++++--------- .../isWallCornerForDiagonalDirection.cpp | 55 ++++++++++--------- .../rotateFearFactorBuildingVariations.cpp | 37 +++++++------ .../Map/TileMapState/setupAllMapSections.cpp | 4 +- .../Map/TileMapState/setupTileMapSections.cpp | 3 +- .../Map/TileMapState/triggerLoweredView.cpp | 5 +- 21 files changed, 253 insertions(+), 153 deletions(-) create mode 100644 src/OpenSHC/Map/Enums/EditorRockType.hpp create mode 100644 src/OpenSHC/Map/Enums/LoweredViewTransition.hpp diff --git a/src/OpenSHC/Map/Enums/EditorRockType.hpp b/src/OpenSHC/Map/Enums/EditorRockType.hpp new file mode 100644 index 0000000000..16a6c2c97d --- /dev/null +++ b/src/OpenSHC/Map/Enums/EditorRockType.hpp @@ -0,0 +1,28 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Enums/EditorRockType.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Enums { + typedef enum EditorRockType { + + ERT_NONE = 0, // 0x00000000 + ERT_BIGROCK1 = 1, // 0x00000001 + ERT_BIGROCK2 = 2, // 0x00000002 + ERT_BIGROCK3 = 3, // 0x00000003 + ERT_BIGROCK4 = 4, // 0x00000004 + ERT_BIGROCK5 = 5 // 0x00000005 + + } EditorRockType; + + static_assert_cpp98_obj(sizeof(EditorRockType) == 4, EditorRockType); + } // namespace Enums +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Enums/LoweredViewTransition.hpp b/src/OpenSHC/Map/Enums/LoweredViewTransition.hpp new file mode 100644 index 0000000000..80ad719dc8 --- /dev/null +++ b/src/OpenSHC/Map/Enums/LoweredViewTransition.hpp @@ -0,0 +1,27 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Enums/LoweredViewTransition.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Enums { + typedef enum LoweredViewTransition { + + LVT_NONE = 0, // 0x00000000 + LVT_SET_LOWERED = 1, // 0x00000001 + LVT_SET_NORMAL = 2, // 0x00000002 + LVT_LOWER = 3, // 0x00000003 + LVT_RAISE = 4 // 0x00000004 + + } LoweredViewTransition; + + static_assert_cpp98_obj(sizeof(LoweredViewTransition) == 4, LoweredViewTransition); + } // namespace Enums +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp index 6c35a93f4b..00cb9f1107 100644 --- a/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp +++ b/src/OpenSHC/Map/TileMapState/Constructor_TileMapState.cpp @@ -1,6 +1,8 @@ #include "../TileMapState.func.hpp" #include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Map/Enums/EditorRockType.hpp" +#include "OpenSHC/Map/Enums/LoweredViewTransition.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" @@ -16,7 +18,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupBuildingSizeIndexMapping, this)(); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setupTileMapSections, this)(); this->editorActiveBrush = 7; - this->refreshCertainTileMap = 2; + this->refreshCertainTileMap = OpenSHC::Map::Enums::LVT_SET_NORMAL; this->counter1 = 0; this->mapperMax = FALSE; this->editorSnapToMode = 0; @@ -29,14 +31,14 @@ namespace Map { this->forceUpdateLogicalAndMiscDisplayLayers = TRUE; this->forceUpdateTextureTilemap = TRUE; this->forceUpdateGFXLayers = TRUE; - this->refreshCertainTileMap_old = 4; + this->refreshCertainTileMap_old = OpenSHC::Map::Enums::LVT_RAISE; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); this->moatTileCount = 0; this->skipPlacementCheck = 0; this->gateOrientationVariant = 80; this->lastTime = timeGetTime(); - this->rockOrientation = 0; - this->editorRockType = 0; + this->rockOrientation = OpenSHC::Map::Enums::MO_NORTH; + this->editorRockType = OpenSHC::Map::Enums::ERT_NONE; this->cursorAnimationTime = timeGetTime(); this->cursorOverlayAnimationFrame = 1; this->temporaryTerrainTypeIndex = 0; diff --git a/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp b/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp index b357b6ff74..7e6992e9b2 100644 --- a/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp +++ b/src/OpenSHC/Map/TileMapState/changeMapOrientation.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" #include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -24,31 +25,31 @@ namespace Map { DAT_BuildingsState::instance.field_0x10 = 5; switch (this->mapOrientation) { case OpenSHC::Map::Enums::MO_NORTH: - this->screenSouthEastDirection = 3; + this->screenSouthEastDirection = OpenSHC::Map::Enums::CD_SOUTHEAST; this->orientedRowStep = 1; - this->screenEastDirection = 2; - this->screenSouthDirection = 4; - this->screenSouthWestDirection = 5; + this->screenEastDirection = OpenSHC::Map::Enums::CD_EAST; + this->screenSouthDirection = OpenSHC::Map::Enums::CD_SOUTH; + this->screenSouthWestDirection = OpenSHC::Map::Enums::CD_SOUTHWEST; return; case OpenSHC::Map::Enums::MO_EAST: - this->screenSouthEastDirection = 5; + this->screenSouthEastDirection = OpenSHC::Map::Enums::CD_SOUTHWEST; this->orientedRowStep = 1; - this->screenEastDirection = 4; - this->screenSouthDirection = 6; - this->screenSouthWestDirection = 7; + this->screenEastDirection = OpenSHC::Map::Enums::CD_SOUTH; + this->screenSouthDirection = OpenSHC::Map::Enums::CD_WEST; + this->screenSouthWestDirection = OpenSHC::Map::Enums::CD_NORTHWEST; return; case OpenSHC::Map::Enums::MO_SOUTH: - this->screenSouthEastDirection = 7; - this->screenEastDirection = 6; - this->screenSouthDirection = 0; - this->screenSouthWestDirection = 1; + this->screenSouthEastDirection = OpenSHC::Map::Enums::CD_NORTHWEST; + this->screenEastDirection = OpenSHC::Map::Enums::CD_WEST; + this->screenSouthDirection = OpenSHC::Map::Enums::CD_NORTH; + this->screenSouthWestDirection = OpenSHC::Map::Enums::CD_NORTHEAST; this->orientedRowStep = -1; return; case OpenSHC::Map::Enums::MO_WEST: - this->screenSouthEastDirection = 1; - this->screenEastDirection = 0; - this->screenSouthDirection = 2; - this->screenSouthWestDirection = 3; + this->screenSouthEastDirection = OpenSHC::Map::Enums::CD_NORTHEAST; + this->screenEastDirection = OpenSHC::Map::Enums::CD_NORTH; + this->screenSouthDirection = OpenSHC::Map::Enums::CD_EAST; + this->screenSouthWestDirection = OpenSHC::Map::Enums::CD_SOUTHEAST; this->orientedRowStep = -1; } } diff --git a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp index 2943d45bab..af0ce9197c 100644 --- a/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp +++ b/src/OpenSHC/Map/TileMapState/computeWallCornerRenderRotation.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { @@ -11,7 +12,8 @@ namespace Map { int tileUnk = this->DAT_SomeTile; int y = this->DAT_SomeY; int result = 0; - if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)(tileUnk, y, 2)) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)( + tileUnk, y, OpenSHC::Map::Enums::CD_EAST)) { if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { if ((x & 0xf) == 0xf) { result = 2; @@ -38,7 +40,7 @@ namespace Map { } } } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isWallConnectionHeightValid, this)( - tileUnk, y, 0)) { + tileUnk, y, OpenSHC::Map::Enums::CD_NORTH)) { if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { if ((y & 0xf) == 0xf) { result = 1; @@ -65,10 +67,10 @@ namespace Map { } } } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( - tileUnk, y, 2)) { + tileUnk, y, OpenSHC::Map::Enums::CD_EAST)) { result = 48; } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getWallFlagForOrientedDirection, this)( - tileUnk, y, 4)) { + tileUnk, y, OpenSHC::Map::Enums::CD_SOUTH)) { result = 63; } else { result = 33; diff --git a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp index 630a1c7ed7..ad192ada9f 100644 --- a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp @@ -24,11 +24,12 @@ namespace Map { int rowTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; for (int index = 0; index < countof(DAT_TerrainDefinedData::instance.SomeOrientationOrderArray); index++) { - int orientation = DAT_TerrainDefinedData::instance.SomeOrientationOrderArray[index]; + CardinalDirection const orientation + = (CardinalDirection)DAT_TerrainDefinedData::instance.SomeOrientationOrderArray[index]; int neighbour = this->directionTranslationMatrix[y][orientation] + rowTile; if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[neighbour] & (L_STOCKPILEUnk | L_CRENEL_VARIATIONUnk)) == 0) { - return (CardinalDirection)orientation; + return orientation; } } return (CardinalDirection)OpenSHC::Map::Enums::MO_NONE; diff --git a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp index 42f54932d4..59f7f1c763 100644 --- a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp @@ -1,6 +1,7 @@ #include "../TileMapState.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" #include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" @@ -21,14 +22,14 @@ namespace Map { return; } - if (index >= 37) { + if (index >= countof(DAT_TerrainDefinedData::instance.field_0xc)) { index = 0; } int brushStep = DAT_TerrainDefinedData::instance.field_0xc[index]; if (brushStep == 15) { return; } - if (brushStep < 8) { + if (brushStep < OpenSHC::Map::Enums::CD_UPPER_LIMIT) { *tilePointer += this->directionTranslationMatrix[*yPointer][brushStep]; *yPointer += DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[brushStep].int_.yOffset; return; diff --git a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp index be1afabcd3..a56f59196d 100644 --- a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp @@ -1,36 +1,44 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + namespace OpenSHC { namespace Map { + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + // FUNCTION: STRONGHOLDCRUSADER 0x004F89C0 BOOLEnum TileMapState::getWallFlagForOrientedDirection(int tileUnk, int y, int twoOrFour) { - int direction = 0; - if (twoOrFour == 2) { + int direction = OpenSHC::Map::Enums::CD_NORTH; + if (twoOrFour == OpenSHC::Map::Enums::CD_EAST) { if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { - direction = 2; + direction = OpenSHC::Map::Enums::CD_EAST; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { - direction = 4; + direction = OpenSHC::Map::Enums::CD_SOUTH; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { - direction = 6; + direction = OpenSHC::Map::Enums::CD_WEST; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { - direction = 0; + direction = OpenSHC::Map::Enums::CD_NORTH; } - } else if (twoOrFour == 4) { + } else if (twoOrFour == OpenSHC::Map::Enums::CD_SOUTH) { if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { - direction = 4; + direction = OpenSHC::Map::Enums::CD_SOUTH; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { - direction = 6; + direction = OpenSHC::Map::Enums::CD_WEST; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { - direction = 0; + direction = OpenSHC::Map::Enums::CD_NORTH; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { - direction = 2; + direction = OpenSHC::Map::Enums::CD_EAST; } } else { return FALSE; } - return (uint)this->LogicLayer[this->directionTranslationMatrix[y][direction] + tileUnk] >> 8 & TRUE; + if ((this->LogicLayer[this->directionTranslationMatrix[y][direction] + tileUnk] & L_WALL_OR_GATEHOUSE) != 0) { + return TRUE; + } + return FALSE; } } diff --git a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp index 879cad2e2d..3f774191fb 100644 --- a/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp +++ b/src/OpenSHC/Map/TileMapState/hasHigherNeighborWithStairs.cpp @@ -1,32 +1,38 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { namespace Map { + using OpenSHC::Map::LogicHelpers::L_STAIRS; + // FUNCTION: STRONGHOLDCRUSADER 0x004F8A40 BOOLEnum TileMapState::hasHigherNeighborWithStairs(int tileUnk, int y, int direction) { - int rotatedDirection = 0; + int rotatedDirection = OpenSHC::Map::Enums::CD_NORTH; if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { rotatedDirection = direction; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { - rotatedDirection = direction + 4; + rotatedDirection = direction + OpenSHC::Map::Enums::MO_SOUTH; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { - rotatedDirection = direction + 2; + rotatedDirection = direction + OpenSHC::Map::Enums::MO_EAST; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { - rotatedDirection = direction + 6; + rotatedDirection = direction + OpenSHC::Map::Enums::MO_WEST; } - if (rotatedDirection >= 8) { - rotatedDirection -= 8; + if (rotatedDirection >= OpenSHC::Map::Enums::CD_UPPER_LIMIT) { + rotatedDirection -= OpenSHC::Map::Enums::CD_UPPER_LIMIT; } int neighbour = this->directionTranslationMatrix[y][rotatedDirection] + tileUnk; if (this->HeightLayer[neighbour] <= this->HeightLayer[tileUnk]) { return FALSE; } - return (uint)this->LogicLayer[neighbour] >> 11 & TRUE; + if ((this->LogicLayer[neighbour] & L_STAIRS) != 0) { + return TRUE; + } + return FALSE; } } diff --git a/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp index 5403da05a0..0695b08278 100644 --- a/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/hasHigherPlainNeighborWithWallOrGatehouse.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { @@ -7,22 +8,23 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_CRENEL; using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004F8AC0 BOOLEnum TileMapState::hasHigherPlainNeighborWithWallOrGatehouse(int tile, int y, int direction) { - int rotatedDirection = 0; + int rotatedDirection = OpenSHC::Map::Enums::CD_NORTH; if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { rotatedDirection = direction; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { - rotatedDirection = direction + 4; + rotatedDirection = direction + OpenSHC::Map::Enums::MO_SOUTH; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { - rotatedDirection = direction + 2; + rotatedDirection = direction + OpenSHC::Map::Enums::MO_EAST; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { - rotatedDirection = direction + 6; + rotatedDirection = direction + OpenSHC::Map::Enums::MO_WEST; } - if (rotatedDirection >= 8) { - rotatedDirection -= 8; + if (rotatedDirection >= OpenSHC::Map::Enums::CD_UPPER_LIMIT) { + rotatedDirection -= OpenSHC::Map::Enums::CD_UPPER_LIMIT; } int neighbour = this->directionTranslationMatrix[y][rotatedDirection] + tile; @@ -35,7 +37,10 @@ namespace Map { if ((this->LogicLayer[neighbour] & L_STOCKPILEUnk) != 0) { return FALSE; } - return (uint)this->LogicLayer[neighbour] >> 8 & TRUE; + if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0) { + return TRUE; + } + return FALSE; } } diff --git a/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp b/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp index 2bbd14fdb2..fdc777d85c 100644 --- a/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp +++ b/src/OpenSHC/Map/TileMapState/hasOnlyTowerNeighborsNoWalls.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { @@ -13,25 +14,25 @@ namespace Map { { int unknownWallRelated = 0; int wallOrGatehouse = 0; - int offset = this->directionTranslationMatrix[y][0] + tile; + int offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_NORTH] + tile; if ((this->LogicLayer[offset] & L_UNKNOWN_WALL_RELATED) != 0) { unknownWallRelated++; } else if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0) { wallOrGatehouse++; } - offset = this->directionTranslationMatrix[y][2] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_EAST] + tile; if ((this->LogicLayer[offset] & L_UNKNOWN_WALL_RELATED) != 0) { unknownWallRelated++; } else if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0) { wallOrGatehouse++; } - offset = this->directionTranslationMatrix[y][4] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_SOUTH] + tile; if ((this->LogicLayer[offset] & L_UNKNOWN_WALL_RELATED) != 0) { unknownWallRelated++; } else if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0) { wallOrGatehouse++; } - offset = this->directionTranslationMatrix[y][6] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_WEST] + tile; if ((this->LogicLayer[offset] & L_UNKNOWN_WALL_RELATED) != 0) { unknownWallRelated++; } else if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0) { diff --git a/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp b/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp index acad647feb..362b530099 100644 --- a/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/isCliffDropInDirection.cpp @@ -1,12 +1,14 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" + namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FC7C0 BOOLEnum TileMapState::isCliffDropInDirection(int tileUnk, undefined4 unused, int y) { - int direction = (this->screenSouthEastDirection + 4) % 8; + int direction = (this->screenSouthEastDirection + 4) % OpenSHC::Map::Enums::CD_UPPER_LIMIT; return this->HeightLayer[tileUnk] > this->HeightLayer[this->directionTranslationMatrix[y][direction] + tileUnk] + 20; } diff --git a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp index 8d8453f1da..c89e67f7a3 100644 --- a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp +++ b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" + namespace OpenSHC { namespace Map { @@ -9,19 +11,19 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F8640 BOOLEnum TileMapState::isTileEnclosedByWalls(int tile, int y) { - int offset = this->directionTranslationMatrix[y][0] + tile; + int offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_NORTH] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { return TRUE; } - offset = this->directionTranslationMatrix[y][4] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_SOUTH] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { return TRUE; } - offset = this->directionTranslationMatrix[y][2] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_EAST] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { return TRUE; } - offset = this->directionTranslationMatrix[y][6] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_WEST] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & L_STOCKPILEUnk) == 0) { return TRUE; } diff --git a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp index 29277f6692..328d6c80ee 100644 --- a/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp +++ b/src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { @@ -12,22 +13,22 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F85B0 BOOLEnum TileMapState::isTileEnclosedByWallsOrGates(int tile, int y) { - int offset = this->directionTranslationMatrix[y][0] + tile; + int offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_NORTH] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & (L_STOCKPILEUnk | L_CRENEL)) == 0) { return TRUE; } - offset = this->directionTranslationMatrix[y][4] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_SOUTH] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & (L_STOCKPILEUnk | L_CRENEL)) == 0) { return TRUE; } - offset = this->directionTranslationMatrix[y][2] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_EAST] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & (L_STOCKPILEUnk | L_CRENEL)) == 0) { return TRUE; } - offset = this->directionTranslationMatrix[y][6] + tile; + offset = this->directionTranslationMatrix[y][OpenSHC::Map::Enums::CD_WEST] + tile; if ((this->LogicLayer[offset] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[offset] & (L_STOCKPILEUnk | L_CRENEL)) == 0) { return TRUE; diff --git a/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp b/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp index 4b1286ef95..ddb60fc378 100644 --- a/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp +++ b/src/OpenSHC/Map/TileMapState/isWallConnectionHeightValid.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { @@ -12,19 +13,19 @@ namespace Map { BOOLEnum TileMapState::isWallConnectionHeightValid(int tile, int y, int direction) { int tileHeight = this->HeightLayer[tile]; - int firstDirection = 0; - int secondDirection = 0; - if (direction == 0) { - secondDirection = 4; - } else if (direction == 2) { - firstDirection = 2; - secondDirection = 6; - } else if (direction == 4) { - firstDirection = 0; - secondDirection = direction; - } else if (direction == 6) { - firstDirection = 2; - secondDirection = 6; + int firstDirection = OpenSHC::Map::Enums::CD_NORTH; + int secondDirection = OpenSHC::Map::Enums::CD_NORTH; + if (direction == OpenSHC::Map::Enums::CD_NORTH) { + secondDirection = OpenSHC::Map::Enums::CD_SOUTH; + } else if (direction == OpenSHC::Map::Enums::CD_EAST) { + firstDirection = OpenSHC::Map::Enums::CD_EAST; + secondDirection = OpenSHC::Map::Enums::CD_WEST; + } else if (direction == OpenSHC::Map::Enums::CD_SOUTH) { + firstDirection = OpenSHC::Map::Enums::CD_NORTH; + secondDirection = OpenSHC::Map::Enums::CD_SOUTH; + } else if (direction == OpenSHC::Map::Enums::CD_WEST) { + firstDirection = OpenSHC::Map::Enums::CD_EAST; + secondDirection = OpenSHC::Map::Enums::CD_WEST; } int first = this->directionTranslationMatrix[y][firstDirection] + tile; diff --git a/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp b/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp index 9357e1d752..00b0ff1dc0 100644 --- a/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/isWallCornerForCardinalDirection.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { @@ -10,30 +11,30 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F86D0 BOOLEnum TileMapState::isWallCornerForCardinalDirection(int tile, int y, int direction) { - int first = 0; - int second = 0; - int third = 0; - int fourth = 0; - if (direction == 0) { - first = 0; - second = 4; - third = 2; - fourth = 6; - } else if (direction == 2) { - first = 2; - second = 6; - third = 0; - fourth = 4; - } else if (direction == 4) { - first = 0; - second = 4; - third = 2; - fourth = 6; - } else if (direction == 6) { - first = 2; - second = 6; - third = 0; - fourth = 4; + int first = OpenSHC::Map::Enums::CD_NORTH; + int second = OpenSHC::Map::Enums::CD_NORTH; + int third = OpenSHC::Map::Enums::CD_NORTH; + int fourth = OpenSHC::Map::Enums::CD_NORTH; + if (direction == OpenSHC::Map::Enums::CD_NORTH) { + first = OpenSHC::Map::Enums::CD_NORTH; + second = OpenSHC::Map::Enums::CD_SOUTH; + third = OpenSHC::Map::Enums::CD_EAST; + fourth = OpenSHC::Map::Enums::CD_WEST; + } else if (direction == OpenSHC::Map::Enums::CD_EAST) { + first = OpenSHC::Map::Enums::CD_EAST; + second = OpenSHC::Map::Enums::CD_WEST; + third = OpenSHC::Map::Enums::CD_NORTH; + fourth = OpenSHC::Map::Enums::CD_SOUTH; + } else if (direction == OpenSHC::Map::Enums::CD_SOUTH) { + first = OpenSHC::Map::Enums::CD_NORTH; + second = OpenSHC::Map::Enums::CD_SOUTH; + third = OpenSHC::Map::Enums::CD_EAST; + fourth = OpenSHC::Map::Enums::CD_WEST; + } else if (direction == OpenSHC::Map::Enums::CD_WEST) { + first = OpenSHC::Map::Enums::CD_EAST; + second = OpenSHC::Map::Enums::CD_WEST; + third = OpenSHC::Map::Enums::CD_NORTH; + fourth = OpenSHC::Map::Enums::CD_SOUTH; } if ((this->LogicLayer[this->directionTranslationMatrix[y][first] + tile] & L_CRENEL) == 0) { @@ -45,7 +46,10 @@ namespace Map { if ((this->LogicLayer[this->directionTranslationMatrix[y][third] + tile] & L_CRENEL) != 0) { return FALSE; } - return ~((uint)this->LogicLayer[this->directionTranslationMatrix[y][fourth] + tile] >> 9) & TRUE; + if ((this->LogicLayer[this->directionTranslationMatrix[y][fourth] + tile] & L_CRENEL) != 0) { + return FALSE; + } + return TRUE; } } diff --git a/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp b/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp index b1a8d907ba..60ce06043f 100644 --- a/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" + namespace OpenSHC { namespace Map { @@ -8,30 +10,30 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F8780 uint TileMapState::isWallCornerForDiagonalDirection(int tile, int y, int direction) { - int first = 0; - int second = 0; - int third = 0; - int fourth = 0; - if (direction == 1) { - first = 4; - second = 6; - third = 0; - fourth = 2; - } else if (direction == 3) { - first = 0; - second = 6; - third = 4; - fourth = 2; - } else if (direction == 5) { - first = 0; - second = 2; - third = 4; - fourth = 6; - } else if (direction == 7) { - first = 4; - second = 2; - third = 0; - fourth = 6; + int first = OpenSHC::Map::Enums::CD_NORTH; + int second = OpenSHC::Map::Enums::CD_NORTH; + int third = OpenSHC::Map::Enums::CD_NORTH; + int fourth = OpenSHC::Map::Enums::CD_NORTH; + if (direction == OpenSHC::Map::Enums::CD_NORTHEAST) { + first = OpenSHC::Map::Enums::CD_SOUTH; + second = OpenSHC::Map::Enums::CD_WEST; + third = OpenSHC::Map::Enums::CD_NORTH; + fourth = OpenSHC::Map::Enums::CD_EAST; + } else if (direction == OpenSHC::Map::Enums::CD_SOUTHEAST) { + first = OpenSHC::Map::Enums::CD_NORTH; + second = OpenSHC::Map::Enums::CD_WEST; + third = OpenSHC::Map::Enums::CD_SOUTH; + fourth = OpenSHC::Map::Enums::CD_EAST; + } else if (direction == OpenSHC::Map::Enums::CD_SOUTHWEST) { + first = OpenSHC::Map::Enums::CD_NORTH; + second = OpenSHC::Map::Enums::CD_EAST; + third = OpenSHC::Map::Enums::CD_SOUTH; + fourth = OpenSHC::Map::Enums::CD_WEST; + } else if (direction == OpenSHC::Map::Enums::CD_NORTHWEST) { + first = OpenSHC::Map::Enums::CD_SOUTH; + second = OpenSHC::Map::Enums::CD_EAST; + third = OpenSHC::Map::Enums::CD_NORTH; + fourth = OpenSHC::Map::Enums::CD_WEST; } if ((this->LogicLayer[this->directionTranslationMatrix[y][first] + tile] & L_CRENEL) == 0) { @@ -43,7 +45,10 @@ namespace Map { if ((this->LogicLayer[this->directionTranslationMatrix[y][third] + tile] & L_CRENEL) != 0) { return FALSE; } - return ~((uint)this->LogicLayer[this->directionTranslationMatrix[y][fourth] + tile] >> 9) & 1; + if ((this->LogicLayer[this->directionTranslationMatrix[y][fourth] + tile] & L_CRENEL) != 0) { + return FALSE; + } + return TRUE; } } diff --git a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp index c17758ca96..cf1cf39116 100644 --- a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp +++ b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp @@ -1,6 +1,7 @@ #include "../TileMapState.func.hpp" #include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Map/Enums/EditorRockType.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -10,19 +11,19 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F8300 void TileMapState::rotateFearFactorBuildingVariations() { - DWORD now = timeGetTime(); - if (this->editorRockType == 5) { - if (this->rockOrientation == 0) { - this->rockOrientation = 2; - } else if (this->rockOrientation == 2) { - this->rockOrientation = 4; - } else if (this->rockOrientation == 4) { - this->rockOrientation = 6; + int now = timeGetTime(); + if (this->editorRockType == OpenSHC::Map::Enums::ERT_BIGROCK5) { + if (this->rockOrientation == OpenSHC::Map::Enums::MO_NORTH) { + this->rockOrientation = OpenSHC::Map::Enums::MO_EAST; + } else if (this->rockOrientation == OpenSHC::Map::Enums::MO_EAST) { + this->rockOrientation = OpenSHC::Map::Enums::MO_SOUTH; + } else if (this->rockOrientation == OpenSHC::Map::Enums::MO_SOUTH) { + this->rockOrientation = OpenSHC::Map::Enums::MO_WEST; } else { - this->rockOrientation = 0; + this->rockOrientation = OpenSHC::Map::Enums::MO_NORTH; } } - if ((int)now < (int)(this->lastTime + 1000)) { + if (now < (int)(this->lastTime + 1000)) { return; } @@ -32,15 +33,15 @@ namespace Map { } else { this->gateOrientationVariant = 80; } - if (this->editorRockType == 0) { - if (this->rockOrientation == 0) { - this->rockOrientation = 2; - } else if (this->rockOrientation == 2) { - this->rockOrientation = 4; - } else if (this->rockOrientation == 4) { - this->rockOrientation = 6; + if (this->editorRockType == OpenSHC::Map::Enums::ERT_NONE) { + if (this->rockOrientation == OpenSHC::Map::Enums::MO_NORTH) { + this->rockOrientation = OpenSHC::Map::Enums::MO_EAST; + } else if (this->rockOrientation == OpenSHC::Map::Enums::MO_EAST) { + this->rockOrientation = OpenSHC::Map::Enums::MO_SOUTH; + } else if (this->rockOrientation == OpenSHC::Map::Enums::MO_SOUTH) { + this->rockOrientation = OpenSHC::Map::Enums::MO_WEST; } else { - this->rockOrientation = 0; + this->rockOrientation = OpenSHC::Map::Enums::MO_NORTH; } } diff --git a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp index 30a0d97cf4..6ad8329258 100644 --- a/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp @@ -69,9 +69,9 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ShortValue, DAT_LowLevelMemory::ptr)( MC_MAP_TILES_COUNT, 1, this->PillarGFXLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->HeightLayer), '\b', this->HeightLayer); + sizeof(this->HeightLayer), 8, this->HeightLayer); MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( - sizeof(this->DefaultHeightLayer), '\b', this->DefaultHeightLayer); + sizeof(this->DefaultHeightLayer), 8, this->DefaultHeightLayer); DAT_PathFindingState::instance.searchGeneration = 1; MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( sizeof(DAT_TileMapState::instance.WalkLayer), 0, DAT_TileMapState::instance.WalkLayer); diff --git a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp index e62bcf81a3..0cf4893a9b 100644 --- a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/IO/LowLevelMemory.func.hpp" #include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" #include "OpenSHC/Globals/SEC_RNG.hpp" @@ -76,7 +77,7 @@ namespace Map { this->RandomLayer[tile] = SEC_RNG::instance.currentNumber2; } MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::changeMapOrientation, this)(OpenSHC::Map::Enums::MO_NORTH); - this->DAT_FutureMapOrientation = 8; + this->DAT_FutureMapOrientation = OpenSHC::Map::Enums::CD_UPPER_LIMIT; } } diff --git a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp index 9efaba855d..b92a0e69ab 100644 --- a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp +++ b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/LoweredViewTransition.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" @@ -12,7 +13,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F6FD0 void TileMapState::triggerLoweredView(int requestedView) { - int view = 2; + int view = OpenSHC::Map::Enums::LVT_SET_NORMAL; if (this->flatViewToggleValue2 == 0) { view = requestedView; } @@ -21,7 +22,7 @@ namespace Map { } this->refreshCertainTileMap = view; this->counter1 = 0; - if (view != 3) { + if (view != OpenSHC::Map::Enums::LVT_LOWER) { return; } if (DAT_GameCore::instance.gamePausedLogical != 0) { From bae202f0e6d7f8bffa675763bbb02877c1e3ec25 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 15 Nov 2026 22:43:52 +0100 Subject: [PATCH 23/28] style(TileMapState): do-while footprint loops and MiscDisplay flags from review - the construction-tile loops are do-while, testing constructionTileCount after the body as before (getBuildingSizeIndexMappingData sets it) - new MiscDisplay enum for the MiscDisplayLayer bits, used for the literals - storeMinAndMaxHeightOfArea: int height, casts dropped - updateShowHiLayerOrResetChangedLayer: row / 4 + 1 and LVT_* values Each function compiles to the same instructions as before. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH --- src/OpenSHC/Map/LogicHelpers/MiscDisplay.hpp | 40 +++++++++++++++++++ .../applyRockGraphicsToFootprint.cpp | 13 +++--- .../clearBuildingDisplayFlagsAndEntities.cpp | 12 +++--- ...arBuildingFootprintAndRemoveSiegeTower.cpp | 7 +--- .../clearBuildingFootprintAndResetUnits.cpp | 19 ++++----- .../clearBuildingFootprintWithEdgeRubble.cpp | 19 ++++----- .../Map/TileMapState/clearDrawBridgeWater.cpp | 7 +--- .../clearFixedSizeTwoBuildingFootprint.cpp | 12 +++--- .../Map/TileMapState/destroyPitchDitch.cpp | 7 +++- .../markBuildingFootprintFlag.cpp | 12 +++--- .../TileMapState/resetTileAndClearMoat.cpp | 4 +- .../TileMapState/spawnEraserTileEffect.cpp | 4 +- .../storeMinAndMaxHeightOfArea.cpp | 13 +++--- .../unmarkBuildingFootprintFlag.cpp | 7 +--- .../updateAreaBasedOnSurrounding.cpp | 7 +--- .../updatePathLinkagesForBuilding.cpp | 7 +--- .../updateShowHiLayerOrResetChangedLayer.cpp | 34 ++++++++++------ 17 files changed, 131 insertions(+), 93 deletions(-) create mode 100644 src/OpenSHC/Map/LogicHelpers/MiscDisplay.hpp diff --git a/src/OpenSHC/Map/LogicHelpers/MiscDisplay.hpp b/src/OpenSHC/Map/LogicHelpers/MiscDisplay.hpp new file mode 100644 index 0000000000..51a93ca131 --- /dev/null +++ b/src/OpenSHC/Map/LogicHelpers/MiscDisplay.hpp @@ -0,0 +1,40 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/LogicHelpers/MiscDisplay.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace LogicHelpers { + typedef enum MiscDisplay { + + MD_PILLAR_SOUTH_SIDEUnk = 1, // 0x00000001 + MD_PILLAR_EAST_SIDEUnk = 2, // 0x00000002 + MD_PILLAR_SIDESUnk = 3, // 0x00000003 + MD_BUILDING_MAIN_TILE = 4, // 0x00000004 + MD_BUILDING_SECOND_TILEUnk = 8, // 0x00000008 + MD_BUILDING_TILES = 12, // 0x0000000C + MD_BATCHED_SPRITES = 16, // 0x00000010 + MD_GATEHOUSE_RAISED = 32, // 0x00000020 + MD_SEA_CLIFF = 64, // 0x00000040 + MD_SEA_UNNAMED_0x80 = 128, // 0x00000080 + MD_SEA_SHORE = 256, // 0x00000100 + MD_SEA_SHORE_EDGE = 512, // 0x00000200 + MD_SEA_EDGES = 960, // 0x000003C0 + MD_DESTROY_PENDING = 1024, // 0x00000400 + MD_DECORATION_ENTITY = 4096, // 0x00001000 + MD_RUBBLE_EDGEUnk = 8192, // 0x00002000 + MD_RUBBLE_INNERUnk = 16384, // 0x00004000 + MD_PREVIEW_IGNORES_PLACEMENT_FAIL = 32768 // 0x00008000 + + } MiscDisplay; + + static_assert_cpp98_obj(sizeof(MiscDisplay) == 4, MiscDisplay); + } // namespace LogicHelpers +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp index 5f6cc7c211..c55b63b17d 100644 --- a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp @@ -1,6 +1,7 @@ #include "../TileMapState.func.hpp" #include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/Globals/DAT_LandscapeState.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -10,6 +11,7 @@ namespace OpenSHC { namespace Map { + using OpenSHC::Map::Enums::CD_UPPER_LIMIT; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004FB770 @@ -19,13 +21,13 @@ namespace Map { int rockY = DAT_LandscapeState::instance.rocks[rockID].y; int orientation = DAT_LandscapeState::instance.rocks[rockID].orientation + this->mapOrientation; int index = 0; - if (orientation >= 8) { - orientation -= 8; + if (orientation >= CD_UPPER_LIMIT) { + orientation -= CD_UPPER_LIMIT; } int size = DAT_LandscapeState::instance.rocks[rockID].size; int surface = (orientation / 2) * size * size; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( index, DAT_LandscapeState::instance.rocks[rockID].size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + rockY].addXgetTile + rockX @@ -50,10 +52,7 @@ namespace Map { } } index++; - if (index >= this->constructionTileCount) { - break; - } - } + } while (index < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp index 9b74d85ade..765f309fe3 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingDisplayFlagsAndEntities.cpp @@ -1,6 +1,7 @@ #include "../TileMapState.func.hpp" #include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_EntityState.hpp" @@ -9,6 +10,8 @@ namespace OpenSHC { namespace Map { + using OpenSHC::Map::LogicHelpers::MD_BUILDING_TILES; + // FUNCTION: STRONGHOLDCRUSADER 0x004FB360 void TileMapState::clearBuildingDisplayFlagsAndEntities(int buildingID, int destroyEntities) { @@ -17,21 +20,18 @@ namespace Map { int buildingY = DAT_BuildingsState::instance.buildings[buildingID].y; uint widthOrHeight = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, widthOrHeight); int tileUnk = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + buildingY].addXgetTile + this->buildingX + buildingX; - this->MiscDisplayLayer[tileUnk] &= ~0xc; + this->MiscDisplayLayer[tileUnk] &= ~MD_BUILDING_TILES; if (destroyEntities == 1) { MACRO_CALL_MEMBER( OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tileUnk); } buildingSizeTileIndex++; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp index fe08fa07e7..14a43193bf 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndRemoveSiegeTower.cpp @@ -23,7 +23,7 @@ namespace Map { { int tileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; @@ -39,10 +39,7 @@ namespace Map { DAT_UnitsState::instance.units[unitID].state.generic = OpenSHC::Map::Units::States::US_DISAPPEAR; } tileIndex++; - if (tileIndex >= this->constructionTileCount) { - break; - } - } + } while (tileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp index b6390580b2..daada49a3e 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintAndResetUnits.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" @@ -15,21 +16,24 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; using OpenSHC::Map::LogicHelpers::L_STAIRS; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_GATEHOUSE_RAISED; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_EDGEUnk; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_INNERUnk; // FUNCTION: STRONGHOLDCRUSADER 0x004FAB70 void TileMapState::clearBuildingFootprintAndResetUnits(int x, int y, int size) { int buildingSizeTileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; this->LogicLayer[tile] &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk | L_KEEP_NON_MANOR_HOUSE); - if ((this->MiscDisplayLayer[tile] & 0x20) != 0) { - this->MiscDisplayLayer[tile] &= ~0x20; + if ((this->MiscDisplayLayer[tile] & MD_GATEHOUSE_RAISED) != 0) { + this->MiscDisplayLayer[tile] &= ~MD_GATEHOUSE_RAISED; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; } int buildingID = this->BuildingLayer[tile]; @@ -38,9 +42,9 @@ namespace Map { this->BuildingWasLayer[tile] = 0; } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isFootprintIndexOnEdge, this)( buildingSizeTileIndex, size)) { - this->MiscDisplayLayer[tile] |= 0x2000; + this->MiscDisplayLayer[tile] |= MD_RUBBLE_EDGEUnk; } else { - this->MiscDisplayLayer[tile] |= 0x4000; + this->MiscDisplayLayer[tile] |= MD_RUBBLE_INNERUnk; } for (int unitID = this->UnitLayer[tile]; unitID != 0; unitID = DAT_UnitsState::instance.units[unitID].nextUnitOnTheSameTile) { @@ -49,10 +53,7 @@ namespace Map { } buildingSizeTileIndex++; this->ChangedLayer[tile] = 2; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp index a286ccd944..a0c0e390e3 100644 --- a/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp +++ b/src/OpenSHC/Map/TileMapState/clearBuildingFootprintWithEdgeRubble.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" @@ -14,21 +15,24 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; using OpenSHC::Map::LogicHelpers::L_STAIRS; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_GATEHOUSE_RAISED; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_EDGEUnk; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_INNERUnk; // FUNCTION: STRONGHOLDCRUSADER 0x004FAD70 void TileMapState::clearBuildingFootprintWithEdgeRubble(int x, int y, int size) { int buildingSizeTileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, size); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; this->LogicLayer[tile] &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_BUILDING | L_STAIRS | L_CRENEL_VARIATIONUnk | L_KEEP_NON_MANOR_HOUSE); - if ((this->MiscDisplayLayer[tile] & 0x20) != 0) { - this->MiscDisplayLayer[tile] &= ~0x20; + if ((this->MiscDisplayLayer[tile] & MD_GATEHOUSE_RAISED) != 0) { + this->MiscDisplayLayer[tile] &= ~MD_GATEHOUSE_RAISED; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; } int buildingID = this->BuildingLayer[tile]; @@ -37,16 +41,13 @@ namespace Map { this->BuildingWasLayer[tile] = 0; } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isFootprintIndexOnEdge, this)( buildingSizeTileIndex, size)) { - this->MiscDisplayLayer[tile] |= 0x2000; + this->MiscDisplayLayer[tile] |= MD_RUBBLE_EDGEUnk; } else { - this->MiscDisplayLayer[tile] |= 0x4000; + this->MiscDisplayLayer[tile] |= MD_RUBBLE_INNERUnk; } buildingSizeTileIndex++; this->ChangedLayer[tile] = 2; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp index 3ae98e608e..3544c9e857 100644 --- a/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp +++ b/src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp @@ -12,7 +12,7 @@ namespace Map { { int buildingSizeTileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, 5); int targetedTile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile @@ -29,10 +29,7 @@ namespace Map { buildingSizeTileIndex++; this->BuildingWasLayer[targetedTile] = 0; this->ChangedLayer[targetedTile] = 2; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp index c863ca6eac..59f30b309a 100644 --- a/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp @@ -1,5 +1,7 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" + #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" @@ -13,13 +15,14 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STAIRS; using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_INNERUnk; // FUNCTION: STRONGHOLDCRUSADER 0x004FAE50 void TileMapState::clearFixedSizeTwoBuildingFootprint(int x, int y) { int buildingSizeTileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, 2); int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile @@ -31,14 +34,11 @@ namespace Map { if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { this->BuildingWasLayer[tile] = 0; } else { - this->MiscDisplayLayer[tile] |= 0x4000; + this->MiscDisplayLayer[tile] |= MD_RUBBLE_INNERUnk; } buildingSizeTileIndex++; this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp b/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp index 5834f9ed0f..9d83313741 100644 --- a/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp +++ b/src/OpenSHC/Map/TileMapState/destroyPitchDitch.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/IO/LowLevelMemory.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" #include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" @@ -11,13 +12,15 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_EDGEUnk; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_INNERUnk; // FUNCTION: STRONGHOLDCRUSADER 0x00500890 void TileMapState::destroyPitchDitch(int pitchDitchID) { this->LogicLayer[this->pitchDitches[pitchDitchID].tile] &= ~L_PLAIN2_AND_PITCH; - this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] &= ~0x2000; - this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] &= ~0x4000; + this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] &= ~MD_RUBBLE_EDGEUnk; + this->MiscDisplayLayer[this->pitchDitches[pitchDitchID].tile] &= ~MD_RUBBLE_INNERUnk; if ((this->LogicLayer[this->pitchDitches[pitchDitchID].tile] & L_WALL_OR_GATEHOUSE) == 0 && this->BuildingLayer[this->pitchDitches[pitchDitchID].tile] == 0) { this->HeightLayer[this->pitchDitches[pitchDitchID].tile] diff --git a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp index 9649ef7bf1..882a70e418 100644 --- a/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp @@ -1,29 +1,29 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" + #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" namespace OpenSHC { namespace Map { using OpenSHC::Map::LogicHelpers::L_PLAIN1_AND_FARM; + using OpenSHC::Map::LogicHelpers::MD_BUILDING_TILES; // FUNCTION: STRONGHOLDCRUSADER 0x004FA9D0 void TileMapState::markBuildingFootprintFlag(int x, int y, int buildingSize) { int buildingSizeTileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); buildingSizeTileIndex++; int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; this->LogicLayer[tile] |= L_PLAIN1_AND_FARM; - this->MiscDisplayLayer[tile] &= ~0xc; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + this->MiscDisplayLayer[tile] &= ~MD_BUILDING_TILES; + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp index ea1fefc88a..58a4a87ec9 100644 --- a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp @@ -1,5 +1,6 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" #include "OpenSHC/Map/Trees/TreeType.hpp" #include "OpenSHC/Globals/DAT_LandscapeState.hpp" @@ -18,6 +19,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_TREE; using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_SEA_EDGES; // FUNCTION: STRONGHOLDCRUSADER 0x00507350 void TileMapState::resetTileAndClearMoat(int tile) @@ -54,7 +56,7 @@ namespace Map { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)(x, y); this->LogicLayer[tile] &= ~(L_MOAT | L_MOAT_DUG_OR_PLANNED); } - this->MiscDisplayLayer[tile] &= ~0x3c0; + this->MiscDisplayLayer[tile] &= ~MD_SEA_EDGES; } } diff --git a/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp b/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp index 00379b41d9..99d1a8f677 100644 --- a/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp +++ b/src/OpenSHC/Map/TileMapState/spawnEraserTileEffect.cpp @@ -4,6 +4,7 @@ #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/UI/MinimapViewState.func.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" #include "OpenSHC/Globals/DAT_EntityState.hpp" #include "OpenSHC/Globals/DAT_MinimapViewState.hpp" @@ -19,6 +20,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STAIRS; using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_DESTROY_PENDING; using OpenSHC::Map::Entities::EntityType; @@ -27,7 +29,7 @@ namespace Map { { uint y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; - this->MiscDisplayLayer[tile] &= ~0x400; + this->MiscDisplayLayer[tile] &= ~MD_DESTROY_PENDING; if (this->UnitLayer[tile] != 0) { return; } diff --git a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp index 9deaed27e5..b9ec740972 100644 --- a/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp +++ b/src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp @@ -20,7 +20,7 @@ namespace Map { } int buildingSizeTileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingWidthAndHeight); uint footprintY = this->buildingY + y; @@ -28,21 +28,18 @@ namespace Map { if (footprintX <= MC_MAP_XY_LIMIT_INCLUSIVE && footprintY <= MC_MAP_XY_LIMIT_INCLUSIVE && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[footprintY * MC_MAP_XY_LIMIT + footprintX] != 0) { - uint height + int const height = this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[footprintY].addXgetTile + this->buildingX + x]; - if ((int)height > this->buildingMaxHeight) { + if (height > this->buildingMaxHeight) { this->buildingMaxHeight = height; } - if ((int)height < this->buildingMinHeight) { + if (height < this->buildingMinHeight) { this->buildingMinHeight = height; } } buildingSizeTileIndex++; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp index 2aa71d72da..c6da6b3904 100644 --- a/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp +++ b/src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp @@ -11,17 +11,14 @@ namespace Map { void TileMapState::unmarkBuildingFootprintFlag(int x, int y, int buildingSize) { int buildingSizeTileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); buildingSizeTileIndex++; int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + x; this->LogicLayer[tile] &= ~L_PLAIN1_AND_FARM; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp index 89f0acd200..4948baadab 100644 --- a/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp +++ b/src/OpenSHC/Map/TileMapState/updateAreaBasedOnSurrounding.cpp @@ -16,7 +16,7 @@ namespace Map { = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findAccessibleAreaNearBuildingLocation, DAT_BuildingsState::ptr)(x, y, buildingSize); - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, buildingSize); int tileUnk = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile @@ -25,10 +25,7 @@ namespace Map { this->PathConnectionLayer[tileUnk] = area; } buildingSizeTileIndex++; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); } } diff --git a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp index 7e925daf1c..92caea6403 100644 --- a/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp @@ -15,7 +15,7 @@ namespace Map { { int buildingSizeTileIndex = 0; - while (true) { + do { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( buildingSizeTileIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); int tileUnk = DAT_ViewportRenderState::instance @@ -27,10 +27,7 @@ namespace Map { DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY, tileUnk); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoat, this)(tileUnk); buildingSizeTileIndex++; - if (buildingSizeTileIndex >= this->constructionTileCount) { - break; - } - } + } while (buildingSizeTileIndex < this->constructionTileCount); short buildingType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; if (buildingType == OpenSHC::Map::Buildings::BT_GATEHOUSELARGE) { diff --git a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp index 676ff1662a..1171cae30a 100644 --- a/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp @@ -1,16 +1,24 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/Enums/LoweredViewTransition.hpp" + #include "OpenSHC/Globals/DAT_RotateMapOrPullDownTerrain.hpp" namespace OpenSHC { namespace Map { + using OpenSHC::Map::Enums::LVT_LOWER; + using OpenSHC::Map::Enums::LVT_NONE; + using OpenSHC::Map::Enums::LVT_RAISE; + using OpenSHC::Map::Enums::LVT_SET_LOWERED; + using OpenSHC::Map::Enums::LVT_SET_NORMAL; + // FUNCTION: STRONGHOLDCRUSADER 0x00501A20 void TileMapState::updateShowHiLayerOrResetChangedLayer() { BOOLEnum importHeight = FALSE; this->refreshRelatedTwo = 0; - if (this->refreshCertainTileMap == 0) { + if (this->refreshCertainTileMap == LVT_NONE) { return; } @@ -18,11 +26,11 @@ namespace Map { this->refreshCertainTileMap_old = this->refreshCertainTileMap; this->refreshRelatedOne = 0; for (int row = 0; row < countof(this->heightBasedScreenYOffset); row++) { - int target = ((uint)row >> 2) + 1; + int const loweredOffset = row / 4 + 1; int step; - if (this->refreshCertainTileMap == 3) { - step = this->heightBasedScreenYOffset[row] - target; - } else if (this->refreshCertainTileMap == 4) { + if (this->refreshCertainTileMap == LVT_LOWER) { + step = this->heightBasedScreenYOffset[row] - loweredOffset; + } else if (this->refreshCertainTileMap == LVT_RAISE) { step = row - this->heightBasedScreenYOffset[row]; } else { step = 0; @@ -47,16 +55,16 @@ namespace Map { step = 0; } - if (this->refreshCertainTileMap == 1) { - this->heightBasedScreenYOffset[row] = target; - } else if (this->refreshCertainTileMap == 2) { + if (this->refreshCertainTileMap == LVT_SET_LOWERED) { + this->heightBasedScreenYOffset[row] = loweredOffset; + } else if (this->refreshCertainTileMap == LVT_SET_NORMAL) { this->heightBasedScreenYOffset[row] = row; - } else if (this->refreshCertainTileMap == 3) { + } else if (this->refreshCertainTileMap == LVT_LOWER) { this->heightBasedScreenYOffset[row] -= step; - if (this->heightBasedScreenYOffset[row] > target) { + if (this->heightBasedScreenYOffset[row] > loweredOffset) { importHeight = TRUE; } - } else if (this->refreshCertainTileMap == 4) { + } else if (this->refreshCertainTileMap == LVT_RAISE) { this->heightBasedScreenYOffset[row] += step; if (this->heightBasedScreenYOffset[row] != row) { importHeight = TRUE; @@ -66,13 +74,13 @@ namespace Map { this->refreshRelatedTwo = 1; if (!importHeight) { - if (this->refreshCertainTileMap == 4 || this->refreshCertainTileMap == 2) { + if (this->refreshCertainTileMap == LVT_RAISE || this->refreshCertainTileMap == LVT_SET_NORMAL) { this->refreshRelatedOne = 1; } else { this->refreshRelatedOne = 0; this->refreshRelatedTwo = 2; } - this->refreshCertainTileMap = 0; + this->refreshCertainTileMap = LVT_NONE; this->forceUpdateLogicalAndMiscDisplayLayers = TRUE; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); this->counter1 = 0; From ccb8650ccbee9d6fe68963a6c597ee95929ac986 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 15 Nov 2026 22:43:52 +0100 Subject: [PATCH 24/28] style(TileMapState): wall owner mask, types and flag checks from review - new WallOwner enum: WO_OWNER_MASK (owner = playerID - 1 in the low 3 bits) - getBuildingHurtSFXID: if/else on L_WALL_OR_GATEHOUSE instead of >> 7 & 2 - int locals where the original compares signed; redundant casts dropped - computeTileAlongAxisOffset and getRubbleGraphicStageForDamageLevel: CardinalDirection / MapOrientation names Each function compiles to the same instructions as before. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH --- src/OpenSHC/Map/LogicHelpers/WallOwner.hpp | 24 +++++++++ .../computeTileAlongAxisOffset.cpp | 7 ++- .../Map/TileMapState/destroyWallsOfPlayer.cpp | 6 ++- .../findNearestValidDigTileNearTarget.cpp | 9 ++-- .../Map/TileMapState/getBuildingHurtSFXID.cpp | 7 ++- .../getRubbleGraphicStageForDamageLevel.cpp | 49 +++++++++++-------- .../placeDefensiveStructureTile.cpp | 12 +++-- .../Map/TileMapState/swapWallOwnership.cpp | 11 +++-- .../Map/TileMapState/updatePitchDitches.cpp | 2 +- .../validateBuildingPlacementAtTile.cpp | 4 +- 10 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 src/OpenSHC/Map/LogicHelpers/WallOwner.hpp diff --git a/src/OpenSHC/Map/LogicHelpers/WallOwner.hpp b/src/OpenSHC/Map/LogicHelpers/WallOwner.hpp new file mode 100644 index 0000000000..540ed6cf70 --- /dev/null +++ b/src/OpenSHC/Map/LogicHelpers/WallOwner.hpp @@ -0,0 +1,24 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/LogicHelpers/WallOwner.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace LogicHelpers { + typedef enum WallOwner { + + WO_OWNER_MASK = 7, // 0x00000007 + WO_DAMAGED_WALL_GFXUnk = 8 // 0x00000008 + + } WallOwner; + + static_assert_cpp98_obj(sizeof(WallOwner) == 4, WallOwner); + } // namespace LogicHelpers +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp index f6e94c1d0d..573f54a943 100644 --- a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp +++ b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp @@ -5,15 +5,18 @@ namespace OpenSHC { namespace Map { + using OpenSHC::Map::Enums::CD_NORTH; + using OpenSHC::Map::Enums::CD_SOUTH; + // FUNCTION: STRONGHOLDCRUSADER 0x00500B50 int TileMapState::computeTileAlongAxisOffset(int tileUnk, int addend, uint offset) { int yStep = 1; - int direction = 4; + int direction = CD_SOUTH; int y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tileUnk]; if ((int)offset < 0) { yStep = -1; - direction = 0; + direction = CD_NORTH; } int count = abs(offset); diff --git a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp index 5b790a13c9..ad113f22d6 100644 --- a/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp +++ b/src/OpenSHC/Map/TileMapState/destroyWallsOfPlayer.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/Map/Entities/EntityState.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" #include "OpenSHC/Globals/DAT_EntityState.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" @@ -16,6 +17,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_STAIRS; using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; // FUNCTION: STRONGHOLDCRUSADER 0x004F93E0 void TileMapState::destroyWallsOfPlayer(int playerID) @@ -24,7 +26,7 @@ namespace Map { if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { continue; } - if ((this->WallOwnerLayer[tile] & 7) + 1 != playerID) { + if ((this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 != playerID) { continue; } @@ -34,7 +36,7 @@ namespace Map { &= ~(L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; this->DamageLayer[tile] = 0; - uint y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; DAT_TileMapState::instance.field_0x554a30 = 1; int x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp index 99aefd72db..3eebff4d71 100644 --- a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -26,12 +26,11 @@ namespace Map { return FALSE; } - int area = (short)this - ->PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[y1].addXgetTile + x1]; + int area = this->PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[y1].addXgetTile + x1]; int targetTile = DAT_ViewportRenderState::instance.translationMatrix[y2].addXgetTile + x2; int bestDistance = 10000; int bestIndex = -1; - uint targetHeight = this->HeightLayer[targetTile]; + int targetHeight = this->HeightLayer[targetTile]; int targetBuildingID = this->BuildingLayer[targetTile]; if (targetBuildingID != 0) { targetHeight @@ -46,14 +45,14 @@ namespace Map { if (this->PathConnectionLayer[tile] != area) { continue; } - uint height = this->HeightLayer[tile]; + int height = this->HeightLayer[tile]; int buildingID = this->BuildingLayer[tile]; if (buildingID != 0) { height += MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, DAT_BuildingsState::ptr)(buildingID); } - if ((int)height >= (int)(targetHeight + 16) || (int)height <= (int)(targetHeight - 16)) { + if (height >= targetHeight + 16 || height <= targetHeight - 16) { continue; } MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, diff --git a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp index c56a5f46ad..d13513e94a 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp @@ -7,6 +7,8 @@ namespace OpenSHC { namespace Map { + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + // FUNCTION: STRONGHOLDCRUSADER 0x004F8210 uint TileMapState::getBuildingHurtSFXID(int tileUnk) { @@ -49,7 +51,10 @@ namespace Map { return 1; } } - return (uint)this->LogicLayer[tileUnk] >> 7 & 2; + if ((this->LogicLayer[tileUnk] & L_WALL_OR_GATEHOUSE) != 0) { + return 2; + } + return 0; } } diff --git a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp index b68118a8c0..f5be7c28be 100644 --- a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp +++ b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp @@ -3,65 +3,74 @@ namespace OpenSHC { namespace Map { + using OpenSHC::Map::Enums::CD_NORTHEAST; + using OpenSHC::Map::Enums::CD_NORTHWEST; + using OpenSHC::Map::Enums::CD_SOUTHEAST; + using OpenSHC::Map::Enums::CD_SOUTHWEST; + using OpenSHC::Map::Enums::MO_EAST; + using OpenSHC::Map::Enums::MO_NORTH; + using OpenSHC::Map::Enums::MO_SOUTH; + using OpenSHC::Map::Enums::MO_WEST; + // FUNCTION: STRONGHOLDCRUSADER 0x004FA460 undefined4 TileMapState::getRubbleGraphicStageForDamageLevel(int rotation) { int result = 0; int orientation = this->mapOrientation; - if (orientation == 0) { + if (orientation == MO_NORTH) { if (rotation == 80) { result = 1; } else if (rotation == 81) { result = 0; - } else if (rotation == 1) { + } else if (rotation == CD_NORTHEAST) { result = 2; - } else if (rotation == 7) { + } else if (rotation == CD_NORTHWEST) { result = 5; - } else if (rotation == 3) { + } else if (rotation == CD_SOUTHEAST) { result = 3; - } else if (rotation == 5) { + } else if (rotation == CD_SOUTHWEST) { result = 4; } - } else if (orientation == 4) { + } else if (orientation == MO_SOUTH) { if (rotation == 80) { result = 1; } else if (rotation == 81) { result = 0; - } else if (rotation == 1) { + } else if (rotation == CD_NORTHEAST) { result = 4; - } else if (rotation == 7) { + } else if (rotation == CD_NORTHWEST) { result = 3; - } else if (rotation == 3) { + } else if (rotation == CD_SOUTHEAST) { result = 5; - } else if (rotation == 5) { + } else if (rotation == CD_SOUTHWEST) { result = 2; } - } else if (orientation == 2) { + } else if (orientation == MO_EAST) { if (rotation == 80) { result = 0; } else if (rotation == 81) { result = 1; - } else if (rotation == 1) { + } else if (rotation == CD_NORTHEAST) { result = 5; - } else if (rotation == 7) { + } else if (rotation == CD_NORTHWEST) { result = 4; - } else if (rotation == 3) { + } else if (rotation == CD_SOUTHEAST) { result = 2; - } else if (rotation == 5) { + } else if (rotation == CD_SOUTHWEST) { result = 3; } - } else if (orientation == 6) { + } else if (orientation == MO_WEST) { if (rotation == 80) { result = 0; } else if (rotation == 81) { result = 1; - } else if (rotation == 1) { + } else if (rotation == CD_NORTHEAST) { result = 3; - } else if (rotation == 7) { + } else if (rotation == CD_NORTHWEST) { result = 2; - } else if (rotation == 3) { + } else if (rotation == CD_SOUTHEAST) { result = 4; - } else if (rotation == 5) { + } else if (rotation == CD_SOUTHWEST) { result = 5; } } diff --git a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp index d234ad9f1d..bcc13f90c7 100644 --- a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp +++ b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp @@ -4,6 +4,7 @@ #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/UI/MinimapViewState.func.hpp" #include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" @@ -25,6 +26,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_TREE; using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; // FUNCTION: STRONGHOLDCRUSADER 0x005034A0 void TileMapState::placeDefensiveStructureTile(int playerID, uint x, uint y, MappersEnum mapper) @@ -45,17 +47,17 @@ namespace Map { } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL) { this->LogicLayer[tile] |= L_CRENEL; this->HeightLayer[tile] += 98; - if ((int)(x & 1) == 1 && (y & 1) == 0) { + if ((x & 1) == 1 && (y & 1) == 0) { this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; - } else if ((int)(x & 1) == 0 && (y & 1) == 1) { + } else if ((x & 1) == 0 && (y & 1) == 1) { this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; } } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL2) { this->LogicLayer[tile] |= L_CRENEL; this->HeightLayer[tile] += 68; - if ((int)(x & 1) == 1 && (y & 1) == 0) { + if ((x & 1) == 1 && (y & 1) == 0) { this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; - } else if ((int)(x & 1) == 0 && (y & 1) == 1) { + } else if ((x & 1) == 0 && (y & 1) == 1) { this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; } } else if (command == OpenSHC::Commands::M_MAPPER_STAIR1) { @@ -90,7 +92,7 @@ namespace Map { if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { this->LogicLayer[tile] |= L_UNKNOWN_WALL_RELATED; } - this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~7) | (playerID - 1); + this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~WO_OWNER_MASK) | (playerID - 1); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)(y, tile); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoat, this)(tile); diff --git a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp index ecfc451238..653768a000 100644 --- a/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp +++ b/src/OpenSHC/Map/TileMapState/swapWallOwnership.cpp @@ -1,19 +1,22 @@ #include "../TileMapState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" + namespace OpenSHC { namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; // FUNCTION: STRONGHOLDCRUSADER 0x004F9220 void TileMapState::swapWallOwnership(int playerID, int otherPlayerID) { for (int tile = 0; tile < countof(this->LogicLayer); tile++) { if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { - if ((this->WallOwnerLayer[tile] & 7) + 1 == playerID) { - this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~7) | (otherPlayerID - 1); - } else if ((this->WallOwnerLayer[tile] & 7) + 1 == otherPlayerID) { - this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~7) | (playerID - 1); + if ((this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 == playerID) { + this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~WO_OWNER_MASK) | (otherPlayerID - 1); + } else if ((this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 == otherPlayerID) { + this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~WO_OWNER_MASK) | (playerID - 1); } } } diff --git a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp index d62135298c..09f89f8270 100644 --- a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp @@ -39,7 +39,7 @@ namespace Map { if (this->pitchDitches[id].field_0x12 == 20) { this->pitchDitches[id].state += 1; this->pitchDitches[id].field_0x12 = 0; - uint height = DAT_TileMapState::instance.HeightLayer[tile]; + int height = DAT_TileMapState::instance.HeightLayer[tile]; for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.field_0x376c); i++) { int neighbour = DAT_ViewportRenderState::instance .translationMatrix[this->pitchDitches[id].y diff --git a/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp b/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp index 30a91ecfe9..07727e108c 100644 --- a/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/validateBuildingPlacementAtTile.cpp @@ -1,6 +1,7 @@ #include "../TileMapState.func.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" @@ -12,6 +13,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_BUILDING; using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; // FUNCTION: STRONGHOLDCRUSADER 0x004F9DF0 void TileMapState::validateBuildingPlacementAtTile(int playerID, int x, int y) @@ -24,7 +26,7 @@ namespace Map { this->buildingPlacementFail = TRUE; } if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0 && this->BuildingLayer[tile] == 0) { - if ((this->WallOwnerLayer[tile] & 7) + 1 != playerID) { + if ((this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 != playerID) { return; } this->buildingPlacementFail = FALSE; From 73f5100c67dc60baba9f803d3af4634f7ea1f750 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 15 Nov 2026 22:43:53 +0100 Subject: [PATCH 25/28] style(TileMapState): enum names in the remaining PR sources - setSignpostDistanceForCampaignMission: MT_ECONOMIC - updateMacroLayer: L2_NONE for the Logic2 mask argument - advanceMoatDigProgress: L2_NONE Each function compiles to the same instructions as before. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH --- src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp | 3 ++- .../Map/TileMapState/setSignpostDistanceForCampaignMission.cpp | 2 +- src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp b/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp index c99d9a9628..b9fb0b022f 100644 --- a/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp +++ b/src/OpenSHC/Map/TileMapState/advanceMoatDigProgress.cpp @@ -9,6 +9,7 @@ namespace OpenSHC { namespace Map { + using OpenSHC::Map::LogicHelpers::L2_NONE; using OpenSHC::Map::LogicHelpers::L_MOAT; using OpenSHC::Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; @@ -26,7 +27,7 @@ namespace Map { this->LogicLayer[this->moats[moatID].tile] &= ~L_MOAT_DUG_OR_PLANNED; this->LogicLayer[this->moats[moatID].tile] &= ~L_PLAIN2_AND_PITCH; this->LogicLayer[this->moats[moatID].tile] |= L_MOAT; - this->Logic2Layer[this->moats[moatID].tile] = 0; + this->Logic2Layer[this->moats[moatID].tile] = L2_NONE; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, DAT_PathFindingState::ptr)(2, this->moats[moatID].x, this->moats[moatID].y); MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, diff --git a/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp b/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp index b0c9d7c527..bbb367ee7e 100644 --- a/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp +++ b/src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp @@ -30,7 +30,7 @@ namespace Map { if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_ECONOMIC_CAMPAIGN_SH1 || (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_BUILDERUnk - && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 >= 2)) { + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 >= OpenSHC::Map::MT_ECONOMIC)) { DAT_GameState::instance.mapAndTime.unk_signpostDistance = 7; } } diff --git a/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp b/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp index 2bf49c3f9c..0ce6a927d5 100644 --- a/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp +++ b/src/OpenSHC/Map/TileMapState/updateMacroLayer.cpp @@ -5,6 +5,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L2_BEACH; using OpenSHC::Map::LogicHelpers::L2_EARTH_AND_STONES; + using OpenSHC::Map::LogicHelpers::L2_NONE; using OpenSHC::Map::LogicHelpers::L2_OASIS_GRASS; using OpenSHC::Map::LogicHelpers::L2_PLATEAU_HIGH; using OpenSHC::Map::LogicHelpers::L2_PLATEAU_MEDIUM; @@ -23,7 +24,7 @@ namespace Map { this->forceUpdateMacroLayerFlag = FALSE; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)( L_DEFAULT_EARTH_OR_TEXTURE, L2_SCRUB, 0); - MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_MARSH, L_NONE, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_MARSH, L2_NONE, 0); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)( L_NONE, L2_EARTH_AND_STONES, 0); MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateMacroLayerRelated, this)(L_NONE, L2_OASIS_GRASS, 0); From 233eaccd2c32e2f1f7bdd5700a4b7de862d983d7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 15 Nov 2026 22:53:04 +0100 Subject: [PATCH 26/28] types(TileMapState): signed coordinates and value types from review - int x/y parameters where the original compares signed or callers pass sign-extended shorts: computeTileAlongAxisOffset, findNearestValidDigTile- NearTarget (range checks written as x < 0 || x > 399, same cmp/ja), getMaxWallHeightInBrushArea, getTileForBrush, increaseHeightForTunnel- SingleTile/WithBrush, placeDefensiveStructureTile - int returns for getBuildingHurtSFXID, getCastleBuildRangeForMapSize, getRubbleGraphicStageForDamageLevel, getTotalHeightAtTile; BOOLEnum for isWallCornerForDiagonalDirection like its cardinal sibling - int moatTileCount, lastTime, field_0x554a10; LoweredViewTransition for refreshCertainTileMap(_old) and triggerLoweredView - getWallFlagForOrientedDirection: twoOrFour -> screenDirection - CardinalDirection.hpp synced from main for CD_UNSPECIFIED (15), used for the "nothing found" result and the empty brush step reccmp: every function equal or better; placeDefensiveStructureTile 90.2 -> 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH --- src/OpenSHC/Map/Enums/CardinalDirection.hpp | 3 +- src/OpenSHC/Map/TileMapState.func.hpp | 31 ++++++++------- src/OpenSHC/Map/TileMapState.hpp | 39 ++++++++++--------- .../computeTileAlongAxisOffset.cpp | 4 +- .../findNearestValidDigTileNearTarget.cpp | 6 +-- .../Map/TileMapState/getBuildingHurtSFXID.cpp | 2 +- .../getCastleBuildRangeForMapSize.cpp | 2 +- .../getMaxWallHeightInBrushArea.cpp | 6 +-- ...tOrientationThatIsWallTowerOrGatehouse.cpp | 6 +-- .../getRubbleGraphicStageForDamageLevel.cpp | 2 +- .../Map/TileMapState/getTileForBrush.cpp | 4 +- .../Map/TileMapState/getTotalHeightAtTile.cpp | 2 +- .../getWallFlagForOrientedDirection.cpp | 6 +-- .../increaseHeightForTunnelSingleTile.cpp | 2 +- .../increaseHeightForTunnelWithBrush.cpp | 6 +-- .../isWallCornerForDiagonalDirection.cpp | 2 +- .../placeDefensiveStructureTile.cpp | 2 +- .../rotateFearFactorBuildingVariations.cpp | 2 +- .../Map/TileMapState/triggerLoweredView.cpp | 4 +- 19 files changed, 67 insertions(+), 64 deletions(-) diff --git a/src/OpenSHC/Map/Enums/CardinalDirection.hpp b/src/OpenSHC/Map/Enums/CardinalDirection.hpp index d7c402f4f5..8f73960c59 100644 --- a/src/OpenSHC/Map/Enums/CardinalDirection.hpp +++ b/src/OpenSHC/Map/Enums/CardinalDirection.hpp @@ -21,7 +21,8 @@ namespace Map { CD_SOUTHWEST = 5, // 0x00000005 CD_WEST = 6, // 0x00000006 CD_NORTHWEST = 7, // 0x00000007 - CD_UPPER_LIMIT = 8 // 0x00000008 + CD_UPPER_LIMIT = 8, // 0x00000008 + CD_UNSPECIFIED = 15 // 0x0000000F } CardinalDirection; diff --git a/src/OpenSHC/Map/TileMapState.func.hpp b/src/OpenSHC/Map/TileMapState.func.hpp index 1eeea936eb..7c15174d9e 100644 --- a/src/OpenSHC/Map/TileMapState.func.hpp +++ b/src/OpenSHC/Map/TileMapState.func.hpp @@ -6,6 +6,7 @@ #include "OpenSHC/IO/PackagedFileMagicNum.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" #include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/Enums/LoweredViewTransition.hpp" #include "OpenSHC/Map/Enums/MapOrientation.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" #include "OpenSHC/Map/LogicHelpers/Logic2.hpp" @@ -58,8 +59,8 @@ namespace Map { void (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004F6F90, &TileMapState::setMapSize) setMapSize; - MACRO_FUNCTION_RESOLVER( - void (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004F6FD0, &TileMapState::triggerLoweredView) + MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(OpenSHC::Map::Enums::LoweredViewTransition), false, + Address::SHC_3BB0A8C1_0x004F6FD0, &TileMapState::triggerLoweredView) triggerLoweredView; MACRO_FUNCTION_RESOLVER( @@ -86,7 +87,7 @@ namespace Map { &TileMapState::computeTileLuminescence) computeTileLuminescence; - MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, uint, uint, int), false, Address::SHC_3BB0A8C1_0x004F80E0, + MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, int, int, int), false, Address::SHC_3BB0A8C1_0x004F80E0, &TileMapState::increaseHeightForTunnelSingleTile) increaseHeightForTunnelSingleTile; @@ -99,7 +100,7 @@ namespace Map { resetTileToDefaultState; MACRO_FUNCTION_RESOLVER( - uint (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004F8210, &TileMapState::getBuildingHurtSFXID) + int (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004F8210, &TileMapState::getBuildingHurtSFXID) getBuildingHurtSFXID; MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(), false, Address::SHC_3BB0A8C1_0x004F8300, @@ -122,7 +123,7 @@ namespace Map { &TileMapState::isWallCornerForCardinalDirection) isWallCornerForCardinalDirection; - MACRO_FUNCTION_RESOLVER(uint (TileMapState::*)(int, int, int), false, Address::SHC_3BB0A8C1_0x004F8780, + MACRO_FUNCTION_RESOLVER(BOOLEnum (TileMapState::*)(int, int, int), false, Address::SHC_3BB0A8C1_0x004F8780, &TileMapState::isWallCornerForDiagonalDirection) isWallCornerForDiagonalDirection; @@ -206,7 +207,7 @@ namespace Map { &TileMapState::checkDrawbridgePlacement) checkDrawbridgePlacement; - MACRO_FUNCTION_RESOLVER(undefined4 (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004FA460, + MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004FA460, &TileMapState::getRubbleGraphicStageForDamageLevel) getRubbleGraphicStageForDamageLevel; @@ -290,11 +291,11 @@ namespace Map { &TileMapState::renderWallPlacementPreview) renderWallPlacementPreview; - MACRO_FUNCTION_RESOLVER(undefined4 (TileMapState::*)(), false, Address::SHC_3BB0A8C1_0x004FBC30, + MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(), false, Address::SHC_3BB0A8C1_0x004FBC30, &TileMapState::getCastleBuildRangeForMapSize) getCastleBuildRangeForMapSize; - MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, int, int*, int*, int, uint), false, + MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, int, int*, int*, int, int), false, Address::SHC_3BB0A8C1_0x004FBD80, &TileMapState::getTileForBrush) getTileForBrush; @@ -351,7 +352,7 @@ namespace Map { returnSomeHeight; MACRO_FUNCTION_RESOLVER( - uint (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004FFB10, &TileMapState::getTotalHeightAtTile) + int (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004FFB10, &TileMapState::getTotalHeightAtTile) getTotalHeightAtTile; MACRO_FUNCTION_RESOLVER( @@ -454,11 +455,11 @@ namespace Map { &TileMapState::swapPitchOwnership) swapPitchOwnership; - MACRO_FUNCTION_RESOLVER(BOOLEnum (TileMapState::*)(uint, uint, uint, uint), false, - Address::SHC_3BB0A8C1_0x00500980, &TileMapState::findNearestValidDigTileNearTarget) + MACRO_FUNCTION_RESOLVER(BOOLEnum (TileMapState::*)(int, int, int, int), false, Address::SHC_3BB0A8C1_0x00500980, + &TileMapState::findNearestValidDigTileNearTarget) findNearestValidDigTileNearTarget; - MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(int, int, uint), false, Address::SHC_3BB0A8C1_0x00500B50, + MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(int, int, int), false, Address::SHC_3BB0A8C1_0x00500B50, &TileMapState::computeTileAlongAxisOffset) computeTileAlongAxisOffset; @@ -490,7 +491,7 @@ namespace Map { &TileMapState::changeMapOrientation) changeMapOrientation; - MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, uint, uint, int), false, Address::SHC_3BB0A8C1_0x00501CD0, + MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, int, int, int), false, Address::SHC_3BB0A8C1_0x00501CD0, &TileMapState::increaseHeightForTunnelWithBrush) increaseHeightForTunnelWithBrush; @@ -518,7 +519,7 @@ namespace Map { &TileMapState::useTerrainHeightBrush) useTerrainHeightBrush; - MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(int, uint), false, Address::SHC_3BB0A8C1_0x00502950, + MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(int, int), false, Address::SHC_3BB0A8C1_0x00502950, &TileMapState::getMaxWallHeightInBrushArea) getMaxWallHeightInBrushArea; @@ -530,7 +531,7 @@ namespace Map { Address::SHC_3BB0A8C1_0x00502F30, &TileMapState::placeWalls) placeWalls; - MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, uint, uint, MappersEnum), false, + MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, int, int, MappersEnum), false, Address::SHC_3BB0A8C1_0x005034A0, &TileMapState::placeDefensiveStructureTile) placeDefensiveStructureTile; diff --git a/src/OpenSHC/Map/TileMapState.hpp b/src/OpenSHC/Map/TileMapState.hpp index b41b11cb16..fa879c46db 100644 --- a/src/OpenSHC/Map/TileMapState.hpp +++ b/src/OpenSHC/Map/TileMapState.hpp @@ -13,6 +13,7 @@ #include "OpenSHC/Map/Buildings/BuildingFailReasonEnumInt.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" #include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/Enums/LoweredViewTransition.hpp" #include "OpenSHC/Map/Enums/MapOrientation.hpp" #include "OpenSHC/Map/Enums/MapOrientationInt.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" @@ -89,7 +90,7 @@ namespace Map { char mapping40x40[40][40]; // 0x00500230 length: 1600 Moat moats[16000]; // 0x00500870 length: 256000 int currentMoatCount; // 0x0053F070 length: 4 - undefined4 moatTileCount; // 0x0053F074 length: 4 + int moatTileCount; // 0x0053F074 length: 4 undefined4 ALG_MoatXResult; // 0x0053F078 length: 4 undefined4 ALG_MoatYResult; // 0x0053F07C length: 4 int someMoatTile; // 0x0053F080 length: 4 @@ -113,7 +114,7 @@ namespace Map { undefined4 gateOrientationVariant; // 0x0055488C length: 4 undefined4 rockOrientation; // 0x00554890 length: 4 undefined4 editorRockType; // 0x00554894 length: 4 - undefined4 lastTime; // 0x00554898 length: 4 + int lastTime; // 0x00554898 length: 4 MapOrientationInt mapOrientation; // 0x0055489C length: 4 undefined4 DAT_FutureMapOrientation; // 0x005548A0 length: 4 int screenSouthEastDirection; // 0x005548A4 length: 4 @@ -121,8 +122,8 @@ namespace Map { int screenSouthDirection; // 0x005548AC length: 4 int screenSouthWestDirection; // 0x005548B0 length: 4 int orientedRowStep; // 0x005548B4 length: 4 - undefined4 refreshCertainTileMap; // 0x005548B8 length: 4 - undefined4 refreshCertainTileMap_old; // 0x005548BC length: 4 + OpenSHC::Map::Enums::LoweredViewTransition refreshCertainTileMap; // 0x005548B8 length: 4 + OpenSHC::Map::Enums::LoweredViewTransition refreshCertainTileMap_old; // 0x005548BC length: 4 undefined4 counter1; // 0x005548C0 length: 4 undefined4 refreshRelatedOne; // 0x005548C4 length: 4 undefined4 disableElevationRendering; // 0x005548C8 length: 4 @@ -206,7 +207,7 @@ namespace Map { undefined4 field_0x554a04; // 0x00554A04 length: 4 undefined4 field_0x554a08; // 0x00554A08 length: 4 int mapSize; // 0x00554A0C length: 4 - undefined4 field_0x554a10; // 0x00554A10 length: 4 + int field_0x554a10; // 0x00554A10 length: 4 undefined4 skipPlacementFailChecks; // 0x00554A14 length: 4 undefined1 padding_0x554a18[4]; // 0x00554A18 length: 4 undefined4 decorationVariantIndex; // 0x00554A1C length: 4 @@ -264,7 +265,7 @@ namespace Map { void setMapSize(int size); - void triggerLoweredView(int param_1); + void triggerLoweredView(OpenSHC::Map::Enums::LoweredViewTransition param_1); void toggleFlatView(int param_1); @@ -278,13 +279,13 @@ namespace Map { void computeTileLuminescence(int tile, int param_2); - void increaseHeightForTunnelSingleTile(int tile, uint x, uint y, int increment); + void increaseHeightForTunnelSingleTile(int tile, int x, int y, int increment); int getNonFarmFieldBuildingHealthAtTileOr1000(int tile); void resetTileToDefaultState(int param_1, uint param_2, uint param_3); - uint getBuildingHurtSFXID(int buildingID); + int getBuildingHurtSFXID(int buildingID); void rotateFearFactorBuildingVariations(); @@ -296,13 +297,13 @@ namespace Map { BOOLEnum isWallCornerForCardinalDirection(int param_1, int param_2, int param_3); - uint isWallCornerForDiagonalDirection(int param_1, int param_2, int param_3); + BOOLEnum isWallCornerForDiagonalDirection(int param_1, int param_2, int param_3); BOOLEnum isWallConnectionHeightValid(int tile, int y, int param_3); BOOLEnum hasOnlyTowerNeighborsNoWalls(int tile, int y); - BOOLEnum getWallFlagForOrientedDirection(int tile, int y, int twoOrFour); + BOOLEnum getWallFlagForOrientedDirection(int tile, int y, int screenDirection); BOOLEnum hasHigherNeighborWithStairs(int tile, int y, int direction); @@ -338,7 +339,7 @@ namespace Map { void checkDrawbridgePlacement(int x, int y); - undefined4 getRubbleGraphicStageForDamageLevel(int param_1); + int getRubbleGraphicStageForDamageLevel(int param_1); int getBuildingSizeForCommandBuildingType(MappersEnum commandBuildingType); @@ -381,9 +382,9 @@ namespace Map { void renderWallPlacementPreview(uint x, uint y, short param_3); - undefined4 getCastleBuildRangeForMapSize(); + int getCastleBuildRangeForMapSize(); - void getTileForBrush(int square, int index, int* tilePointer, int* yPointer, int baseTile, uint y); + void getTileForBrush(int square, int index, int* tilePointer, int* yPointer, int baseTile, int y); BOOLEnum isTileSuitableForBrushPlacement(int tile, uint x, uint y); @@ -411,7 +412,7 @@ namespace Map { uint returnSomeHeight(int tile, int param_2); - uint getTotalHeightAtTile(int tile); + int getTotalHeightAtTile(int tile); int getTotalHeightAt(int tile, int playerID); @@ -463,9 +464,9 @@ namespace Map { void swapPitchOwnership(int param_1, int param_2); - BOOLEnum findNearestValidDigTileNearTarget(uint x1, uint y1, uint x2, uint y2); + BOOLEnum findNearestValidDigTileNearTarget(int x1, int y1, int x2, int y2); - int computeTileAlongAxisOffset(int param_1, int param_2, uint param_3); + int computeTileAlongAxisOffset(int param_1, int param_2, int param_3); void setSignpostDistanceForCampaignMission(); @@ -481,7 +482,7 @@ namespace Map { void changeMapOrientation(MapOrientation mapOrientation); - void increaseHeightForTunnelWithBrush(int tile, uint x, uint y, int increment); + void increaseHeightForTunnelWithBrush(int tile, int x, int y, int increment); void raiseLand(int tile, uint y, uint brush, int change); @@ -495,13 +496,13 @@ namespace Map { void useTerrainHeightBrush(int param_1, uint param_2, uint param_3, short param_4); - int getMaxWallHeightInBrushArea(int param_1, uint param_2); + int getMaxWallHeightInBrushArea(int param_1, int param_2); void validateWallBuildPath(int playerID, uint x1, uint y1, uint x2, uint y2, short command); void placeWalls(int playerID, uint x1, uint y1, uint x2, uint y2, MappersEnum wallType, int tileCountUnk); - void placeDefensiveStructureTile(int playerID, uint x, uint y, MappersEnum param_4); + void placeDefensiveStructureTile(int playerID, int x, int y, MappersEnum param_4); void setupBuildingSizeIndexMapping(); diff --git a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp index 573f54a943..d237fdbed0 100644 --- a/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp +++ b/src/OpenSHC/Map/TileMapState/computeTileAlongAxisOffset.cpp @@ -9,12 +9,12 @@ namespace Map { using OpenSHC::Map::Enums::CD_SOUTH; // FUNCTION: STRONGHOLDCRUSADER 0x00500B50 - int TileMapState::computeTileAlongAxisOffset(int tileUnk, int addend, uint offset) + int TileMapState::computeTileAlongAxisOffset(int tileUnk, int addend, int offset) { int yStep = 1; int direction = CD_SOUTH; int y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tileUnk]; - if ((int)offset < 0) { + if (offset < 0) { yStep = -1; direction = CD_NORTH; } diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp index 3eebff4d71..a107ded787 100644 --- a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -13,15 +13,15 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00500980 - BOOLEnum TileMapState::findNearestValidDigTileNearTarget(uint x1, uint y1, uint x2, uint y2) + BOOLEnum TileMapState::findNearestValidDigTileNearTarget(int x1, int y1, int x2, int y2) { - if (x1 > MC_MAP_XY_LIMIT_INCLUSIVE || y1 > MC_MAP_XY_LIMIT_INCLUSIVE) { + if (x1 < 0 || x1 > MC_MAP_XY_LIMIT_INCLUSIVE || y1 < 0 || y1 > MC_MAP_XY_LIMIT_INCLUSIVE) { return FALSE; } if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y1 * MC_MAP_XY_LIMIT + x1] == 0) { return FALSE; } - if (x2 > MC_MAP_XY_LIMIT_INCLUSIVE || y2 > MC_MAP_XY_LIMIT_INCLUSIVE + if (x2 < 0 || x2 > MC_MAP_XY_LIMIT_INCLUSIVE || y2 < 0 || y2 > MC_MAP_XY_LIMIT_INCLUSIVE || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y2 * MC_MAP_XY_LIMIT + x2] == 0) { return FALSE; } diff --git a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp index d13513e94a..454bcbf173 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp @@ -10,7 +10,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004F8210 - uint TileMapState::getBuildingHurtSFXID(int tileUnk) + int TileMapState::getBuildingHurtSFXID(int tileUnk) { short buildingID = this->BuildingLayer[tileUnk]; if (buildingID != 0) { diff --git a/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp b/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp index 4061a2024b..db73420a98 100644 --- a/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp +++ b/src/OpenSHC/Map/TileMapState/getCastleBuildRangeForMapSize.cpp @@ -6,7 +6,7 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FBC30 - undefined4 TileMapState::getCastleBuildRangeForMapSize() + int TileMapState::getCastleBuildRangeForMapSize() { switch (this->mapSize) { case MC_MAP_SIZE_160: diff --git a/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp b/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp index e9316c268f..3cbd94fdd0 100644 --- a/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp +++ b/src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp @@ -8,14 +8,14 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x00502950 - int TileMapState::getMaxWallHeightInBrushArea(int tile, uint y) + int TileMapState::getMaxWallHeightInBrushArea(int tile, int y) { int baseTile = tile; - uint baseY = y; + int baseY = y; int maxWallHeight = 0; for (int index = 1; index < 5; index++) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( - 1, index, &tile, (int*)&y, baseTile, baseY); + 1, index, &tile, &y, baseTile, baseY); if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { continue; } diff --git a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp index ad192ada9f..a9640fca94 100644 --- a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp @@ -16,10 +16,10 @@ namespace Map { CardinalDirection TileMapState::getOrientationThatIsWallTowerOrGatehouse(uint x, uint y) { if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { - return (CardinalDirection)OpenSHC::Map::Enums::MO_NONE; + return OpenSHC::Map::Enums::CD_UNSPECIFIED; } if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { - return (CardinalDirection)OpenSHC::Map::Enums::MO_NONE; + return OpenSHC::Map::Enums::CD_UNSPECIFIED; } int rowTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; @@ -32,7 +32,7 @@ namespace Map { return orientation; } } - return (CardinalDirection)OpenSHC::Map::Enums::MO_NONE; + return OpenSHC::Map::Enums::CD_UNSPECIFIED; } } diff --git a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp index f5be7c28be..d1e6045690 100644 --- a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp +++ b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp @@ -13,7 +13,7 @@ namespace Map { using OpenSHC::Map::Enums::MO_WEST; // FUNCTION: STRONGHOLDCRUSADER 0x004FA460 - undefined4 TileMapState::getRubbleGraphicStageForDamageLevel(int rotation) + int TileMapState::getRubbleGraphicStageForDamageLevel(int rotation) { int result = 0; int orientation = this->mapOrientation; diff --git a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp index 59f7f1c763..8dbd3f0a7d 100644 --- a/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/getTileForBrush.cpp @@ -11,7 +11,7 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FBD80 - void TileMapState::getTileForBrush(int square, int index, int* tilePointer, int* yPointer, int baseTile, uint y) + void TileMapState::getTileForBrush(int square, int index, int* tilePointer, int* yPointer, int baseTile, int y) { if (square != 0) { MACRO_CALL_MEMBER( @@ -26,7 +26,7 @@ namespace Map { index = 0; } int brushStep = DAT_TerrainDefinedData::instance.field_0xc[index]; - if (brushStep == 15) { + if (brushStep == OpenSHC::Map::Enums::CD_UNSPECIFIED) { return; } if (brushStep < OpenSHC::Map::Enums::CD_UPPER_LIMIT) { diff --git a/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp b/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp index 8703894f77..07da7bc445 100644 --- a/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp +++ b/src/OpenSHC/Map/TileMapState/getTotalHeightAtTile.cpp @@ -9,7 +9,7 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004FFB10 - uint TileMapState::getTotalHeightAtTile(int tile) + int TileMapState::getTotalHeightAtTile(int tile) { int buildingID = this->BuildingLayer[tile]; if (buildingID != 0) { diff --git a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp index a56f59196d..8aeeef0108 100644 --- a/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/getWallFlagForOrientedDirection.cpp @@ -9,10 +9,10 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004F89C0 - BOOLEnum TileMapState::getWallFlagForOrientedDirection(int tileUnk, int y, int twoOrFour) + BOOLEnum TileMapState::getWallFlagForOrientedDirection(int tileUnk, int y, int screenDirection) { int direction = OpenSHC::Map::Enums::CD_NORTH; - if (twoOrFour == OpenSHC::Map::Enums::CD_EAST) { + if (screenDirection == OpenSHC::Map::Enums::CD_EAST) { if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { direction = OpenSHC::Map::Enums::CD_EAST; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { @@ -22,7 +22,7 @@ namespace Map { } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { direction = OpenSHC::Map::Enums::CD_NORTH; } - } else if (twoOrFour == OpenSHC::Map::Enums::CD_SOUTH) { + } else if (screenDirection == OpenSHC::Map::Enums::CD_SOUTH) { if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { direction = OpenSHC::Map::Enums::CD_SOUTH; } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp index 2adee90853..ab69728a85 100644 --- a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelSingleTile.cpp @@ -20,7 +20,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004F80E0 - void TileMapState::increaseHeightForTunnelSingleTile(int tile, uint x, uint y, int increment) + void TileMapState::increaseHeightForTunnelSingleTile(int tile, int x, int y, int increment) { if ((this->LogicLayer[tile] & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_RIVER | L_FORD | L_KEEP_NON_MANOR_HOUSE | L_MARSH | L_MOAT)) diff --git a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp index 1ce47255f1..2d47e44cb4 100644 --- a/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp +++ b/src/OpenSHC/Map/TileMapState/increaseHeightForTunnelWithBrush.cpp @@ -20,13 +20,13 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x00501CD0 - void TileMapState::increaseHeightForTunnelWithBrush(int tile, uint x, uint y, int increment) + void TileMapState::increaseHeightForTunnelWithBrush(int tile, int x, int y, int increment) { int baseTile = tile; - uint baseY = y; + int baseY = y; for (int index = 0; index < 9; index++) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( - 0, index, &tile, (int*)&y, baseTile, baseY); + 0, index, &tile, &y, baseTile, baseY); int const brushTile = tile; if ((this->LogicLayer[tile] & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { continue; diff --git a/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp b/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp index 60ce06043f..8ee0b685b6 100644 --- a/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp +++ b/src/OpenSHC/Map/TileMapState/isWallCornerForDiagonalDirection.cpp @@ -8,7 +8,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::L_CRENEL; // FUNCTION: STRONGHOLDCRUSADER 0x004F8780 - uint TileMapState::isWallCornerForDiagonalDirection(int tile, int y, int direction) + BOOLEnum TileMapState::isWallCornerForDiagonalDirection(int tile, int y, int direction) { int first = OpenSHC::Map::Enums::CD_NORTH; int second = OpenSHC::Map::Enums::CD_NORTH; diff --git a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp index bcc13f90c7..6df9fa22a2 100644 --- a/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp +++ b/src/OpenSHC/Map/TileMapState/placeDefensiveStructureTile.cpp @@ -29,7 +29,7 @@ namespace Map { using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; // FUNCTION: STRONGHOLDCRUSADER 0x005034A0 - void TileMapState::placeDefensiveStructureTile(int playerID, uint x, uint y, MappersEnum mapper) + void TileMapState::placeDefensiveStructureTile(int playerID, int x, int y, MappersEnum mapper) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateWallPlacementAtTile, this)(playerID, x, y, mapper); if (this->illegalBuild) { diff --git a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp index cf1cf39116..529bebba65 100644 --- a/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp +++ b/src/OpenSHC/Map/TileMapState/rotateFearFactorBuildingVariations.cpp @@ -23,7 +23,7 @@ namespace Map { this->rockOrientation = OpenSHC::Map::Enums::MO_NORTH; } } - if (now < (int)(this->lastTime + 1000)) { + if (now < this->lastTime + 1000) { return; } diff --git a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp index b92a0e69ab..b84c836cd2 100644 --- a/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp +++ b/src/OpenSHC/Map/TileMapState/triggerLoweredView.cpp @@ -11,9 +11,9 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F6FD0 - void TileMapState::triggerLoweredView(int requestedView) + void TileMapState::triggerLoweredView(OpenSHC::Map::Enums::LoweredViewTransition requestedView) { - int view = OpenSHC::Map::Enums::LVT_SET_NORMAL; + OpenSHC::Map::Enums::LoweredViewTransition view = OpenSHC::Map::Enums::LVT_SET_NORMAL; if (this->flatViewToggleValue2 == 0) { view = requestedView; } From e4efe7a9f5c493b6a640baf5a32466226e77200e Mon Sep 17 00:00:00 2001 From: Gynt Date: Mon, 16 Nov 2026 07:35:04 +0100 Subject: [PATCH 27/28] types(TileMapState): enums, struct and names proposed in the review New headers (generated format, to be added to Ghidra): - PitchDitchState (+ PitchDitchStateShort): PDS_REMOVE -1, PDS_PLACED 0, PDS_READY 1, PDS_BURNING 2, PDS_BURNT_OUT 3; PitchDitch.state uses it and field_0x12 becomes burnTimer (20 ticks burning, 200 burnt out) - HitSoundMaterial: HSM_NONE 0, HSM_WOOD 1, HSM_STONE 2, the return of getBuildingHurtSFXID (callers pick FX_ATTACK_WOOD / FX_ATTACK_STONE); its parameter is a tile, not a building id - BuildingSizeIndexMapping { x, y, orientedPartIndex[4] } for the global that was int[14][169][6]; buildingRotationRelatedValue becomes buildingOrientedPartIndex - MapOrientation gets MO_UPPER_LIMIT (8), the "no change queued" value of DAT_FutureMapOrientation Field types and names: - rockOrientation: MapOrientation, editorRockType: EditorRockType (the map editor big-rock buttons now use ERT_BIGROCK1..5 and MO_*) - TerrainDefinedData.SomeOrientationOrderArray and ClimbLogicDefinedData.field_0x2c (-> neighbourSearchOrder): CardinalDirection[8] - TerrainDefinedData.field_0x378c -> twoTileAxisOffsets, field_0x5549a8/ac -> int destinationNearTargetX/Y - getRubbleGraphicStageForDamageLevel parameter -> fencePiece reccmp: every function unchanged, MenuItemActionHandler_MapEditorLandscaping_ GeneralButtons 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH --- .../Globals/DAT_BuildingSizeIndexMapping.hpp | 9 +++- .../Buildings/BuildingSizeIndexMapping.hpp | 29 +++++++++++ src/OpenSHC/Map/Enums/HitSoundMaterial.hpp | 25 ++++++++++ src/OpenSHC/Map/Enums/MapOrientation.hpp | 1 + src/OpenSHC/Map/PitchDitch.hpp | 6 ++- src/OpenSHC/Map/PitchDitchState.hpp | 25 ++++++++++ src/OpenSHC/Map/PitchDitchStateShort.hpp | 19 +++++++ src/OpenSHC/Map/TerrainDefinedData.hpp | 6 ++- src/OpenSHC/Map/TileMapState.func.hpp | 5 +- src/OpenSHC/Map/TileMapState.hpp | 16 +++--- .../applyRockGraphicsToFootprint.cpp | 4 +- .../collectCliffEdgeTilesForClimbData.cpp | 7 +-- .../findNearestValidDigTileNearTarget.cpp | 14 +++--- .../Map/TileMapState/getBuildingHurtSFXID.cpp | 23 +++++---- .../getBuildingSizeIndexMappingData.cpp | 24 +++++---- ...tOrientationThatIsWallTowerOrGatehouse.cpp | 3 +- .../getRubbleGraphicStageForDamageLevel.cpp | 50 +++++++++---------- .../processMapOrientationChange.cpp | 4 +- .../Map/TileMapState/setupTileMapSections.cpp | 2 +- .../Map/TileMapState/updatePitchDitches.cpp | 26 +++++----- .../Units/Climbing/ClimbLogicDefinedData.hpp | 4 +- ...er_MapEditorLandscaping_GeneralButtons.cpp | 20 ++++---- 22 files changed, 221 insertions(+), 101 deletions(-) create mode 100644 src/OpenSHC/Map/Buildings/BuildingSizeIndexMapping.hpp create mode 100644 src/OpenSHC/Map/Enums/HitSoundMaterial.hpp create mode 100644 src/OpenSHC/Map/PitchDitchState.hpp create mode 100644 src/OpenSHC/Map/PitchDitchStateShort.hpp diff --git a/src/OpenSHC/Globals/DAT_BuildingSizeIndexMapping.hpp b/src/OpenSHC/Globals/DAT_BuildingSizeIndexMapping.hpp index 8925aa8ed6..bcd06fb019 100644 --- a/src/OpenSHC/Globals/DAT_BuildingSizeIndexMapping.hpp +++ b/src/OpenSHC/Globals/DAT_BuildingSizeIndexMapping.hpp @@ -8,12 +8,17 @@ #pragma once +#include "OpenSHC/Map/Buildings/BuildingSizeIndexMapping.hpp" + // GLOBAL: STRONGHOLDCRUSADER 0x00ED31E0 -// StructResolver::Instance::instance +// StructResolver::Instance::instance namespace OpenSHC { -MACRO_STRUCT_RESOLVER(int[14][169][6], false, Address::SHC_3BB0A8C1_0x00ED31E0) DAT_BuildingSizeIndexMapping; +using OpenSHC::Map::Buildings::BuildingSizeIndexMapping; + +MACRO_STRUCT_RESOLVER(BuildingSizeIndexMapping[14][169], false, Address::SHC_3BB0A8C1_0x00ED31E0) +DAT_BuildingSizeIndexMapping; } // namespace OpenSHC MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00ED31E0); diff --git a/src/OpenSHC/Map/Buildings/BuildingSizeIndexMapping.hpp b/src/OpenSHC/Map/Buildings/BuildingSizeIndexMapping.hpp new file mode 100644 index 0000000000..f677459ecb --- /dev/null +++ b/src/OpenSHC/Map/Buildings/BuildingSizeIndexMapping.hpp @@ -0,0 +1,29 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Buildings/BuildingSizeIndexMapping.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Buildings { + +#pragma pack(push, 1) + // SIZE: 0x00000018 + typedef struct BuildingSizeIndexMapping { + + int x; // 0x00000000 length: 4 + int y; // 0x00000004 length: 4 + int orientedPartIndex[4]; // 0x00000008 length: 16 + + } BuildingSizeIndexMapping; +#pragma pack(pop) + + static_assert_cpp98_obj(sizeof(BuildingSizeIndexMapping) == 24, BuildingSizeIndexMapping); + } // namespace Buildings +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Enums/HitSoundMaterial.hpp b/src/OpenSHC/Map/Enums/HitSoundMaterial.hpp new file mode 100644 index 0000000000..7237bd7aee --- /dev/null +++ b/src/OpenSHC/Map/Enums/HitSoundMaterial.hpp @@ -0,0 +1,25 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Enums/HitSoundMaterial.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Enums { + typedef enum HitSoundMaterial { + + HSM_NONE = 0, // 0x00000000 + HSM_WOOD = 1, // 0x00000001 + HSM_STONE = 2 // 0x00000002 + + } HitSoundMaterial; + + static_assert_cpp98_obj(sizeof(HitSoundMaterial) == 4, HitSoundMaterial); + } // namespace Enums +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Enums/MapOrientation.hpp b/src/OpenSHC/Map/Enums/MapOrientation.hpp index 6b74d6a484..d92497417a 100644 --- a/src/OpenSHC/Map/Enums/MapOrientation.hpp +++ b/src/OpenSHC/Map/Enums/MapOrientation.hpp @@ -17,6 +17,7 @@ namespace Map { MO_EAST = 2, // 0x00000002 MO_SOUTH = 4, // 0x00000004 MO_WEST = 6, // 0x00000006 + MO_UPPER_LIMIT = 8, // 0x00000008 MO_NONE = 15 // 0x0000000F } MapOrientation; diff --git a/src/OpenSHC/Map/PitchDitch.hpp b/src/OpenSHC/Map/PitchDitch.hpp index 3e0f54666b..5ac6f36a67 100644 --- a/src/OpenSHC/Map/PitchDitch.hpp +++ b/src/OpenSHC/Map/PitchDitch.hpp @@ -8,6 +8,8 @@ #pragma once +#include "OpenSHC/Map/PitchDitchStateShort.hpp" + namespace OpenSHC { namespace Map { @@ -21,8 +23,8 @@ namespace Map { short x; // 0x0000000A length: 2 short y; // 0x0000000C length: 2 short rng; // 0x0000000E length: 2 - short state; // 0x00000010 length: 2 - short field_0x12; // 0x00000012 length: 2 + PitchDitchStateShort state; // 0x00000010 length: 2 + short burnTimer; // 0x00000012 length: 2 } PitchDitch; #pragma pack(pop) diff --git a/src/OpenSHC/Map/PitchDitchState.hpp b/src/OpenSHC/Map/PitchDitchState.hpp new file mode 100644 index 0000000000..dbe5b1aeec --- /dev/null +++ b/src/OpenSHC/Map/PitchDitchState.hpp @@ -0,0 +1,25 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/PitchDitchState.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + typedef enum PitchDitchState { + + PDS_REMOVE = -1, // 0xFFFFFFFF + PDS_PLACED = 0, // 0x00000000 + PDS_READY = 1, // 0x00000001 + PDS_BURNING = 2, // 0x00000002 + PDS_BURNT_OUT = 3 // 0x00000003 + + } PitchDitchState; + + static_assert_cpp98_obj(sizeof(PitchDitchState) == 4, PitchDitchState); +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/PitchDitchStateShort.hpp b/src/OpenSHC/Map/PitchDitchStateShort.hpp new file mode 100644 index 0000000000..a8cbc4ef06 --- /dev/null +++ b/src/OpenSHC/Map/PitchDitchStateShort.hpp @@ -0,0 +1,19 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/PitchDitchStateShort.hpp' +*/ + +#pragma once + +#include "OpenSHC/Map/PitchDitchState.hpp" + +namespace OpenSHC { +namespace Map { + typedef short PitchDitchStateShort; + + static_assert_cpp98_obj(sizeof(PitchDitchStateShort) == 2, PitchDitchStateShort); +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/TerrainDefinedData.hpp b/src/OpenSHC/Map/TerrainDefinedData.hpp index 193ea89556..9e577037b6 100644 --- a/src/OpenSHC/Map/TerrainDefinedData.hpp +++ b/src/OpenSHC/Map/TerrainDefinedData.hpp @@ -9,6 +9,7 @@ #pragma once #include "OpenSHC/Map/Buildings/WheatFarm/WheatFarmFieldSpec.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/Map/GFX/UnkBytePair.hpp" #include "OpenSHC/Map/Location/GateTowerPlacement.hpp" #include "OpenSHC/Map/Location/Point8.hpp" @@ -19,6 +20,7 @@ namespace OpenSHC { namespace Map { using OpenSHC::Map::Buildings::WheatFarm::WheatFarmFieldSpec; + using OpenSHC::Map::Enums::CardinalDirection; using OpenSHC::Map::GFX::UnkBytePair; using OpenSHC::Map::Location::GateTowerPlacement; using OpenSHC::Map::Location::Point8; @@ -74,7 +76,7 @@ namespace Map { UnkBytePair TerrainFlagGraphicLookup[8]; // 0x00001D64 length: 16 int MapSizes[5]; // 0x00001D74 length: 20 undefined1 padding_0x1d88[164]; // 0x00001D88 length: 164 - int SomeOrientationOrderArray[8]; // 0x00001E2C length: 32 + CardinalDirection SomeOrientationOrderArray[8]; // 0x00001E2C length: 32 int field_0x1e4c[32]; // 0x00001E4C length: 128 XYPair drawBridgeOffsets[4][9]; // 0x00001ECC length: 288 int field_0x1fec[4][25]; // 0x00001FEC length: 400 @@ -88,7 +90,7 @@ namespace Map { int field_0x370c[8]; // 0x0000370C length: 32 XYPair field_0x372c[8]; // 0x0000372C length: 64 XYPair field_0x376c[4]; // 0x0000376C length: 32 - XYPair field_0x378c[4]; // 0x0000378C length: 32 + XYPair twoTileAxisOffsets[4]; // 0x0000378C length: 32 } TerrainDefinedData; #pragma pack(pop) diff --git a/src/OpenSHC/Map/TileMapState.func.hpp b/src/OpenSHC/Map/TileMapState.func.hpp index 7c15174d9e..208dcd26c3 100644 --- a/src/OpenSHC/Map/TileMapState.func.hpp +++ b/src/OpenSHC/Map/TileMapState.func.hpp @@ -6,6 +6,7 @@ #include "OpenSHC/IO/PackagedFileMagicNum.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" #include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/Enums/HitSoundMaterial.hpp" #include "OpenSHC/Map/Enums/LoweredViewTransition.hpp" #include "OpenSHC/Map/Enums/MapOrientation.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" @@ -99,8 +100,8 @@ namespace Map { &TileMapState::resetTileToDefaultState) resetTileToDefaultState; - MACRO_FUNCTION_RESOLVER( - int (TileMapState::*)(int), false, Address::SHC_3BB0A8C1_0x004F8210, &TileMapState::getBuildingHurtSFXID) + MACRO_FUNCTION_RESOLVER(OpenSHC::Map::Enums::HitSoundMaterial (TileMapState::*)(int), false, + Address::SHC_3BB0A8C1_0x004F8210, &TileMapState::getBuildingHurtSFXID) getBuildingHurtSFXID; MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(), false, Address::SHC_3BB0A8C1_0x004F8300, diff --git a/src/OpenSHC/Map/TileMapState.hpp b/src/OpenSHC/Map/TileMapState.hpp index fa879c46db..490aee6f2a 100644 --- a/src/OpenSHC/Map/TileMapState.hpp +++ b/src/OpenSHC/Map/TileMapState.hpp @@ -13,6 +13,8 @@ #include "OpenSHC/Map/Buildings/BuildingFailReasonEnumInt.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" #include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/Enums/EditorRockType.hpp" +#include "OpenSHC/Map/Enums/HitSoundMaterial.hpp" #include "OpenSHC/Map/Enums/LoweredViewTransition.hpp" #include "OpenSHC/Map/Enums/MapOrientation.hpp" #include "OpenSHC/Map/Enums/MapOrientationInt.hpp" @@ -112,8 +114,8 @@ namespace Map { undefined1 padding_0x554880[8]; // 0x00554880 length: 8 undefined4 placedBuildingID; // 0x00554888 length: 4 undefined4 gateOrientationVariant; // 0x0055488C length: 4 - undefined4 rockOrientation; // 0x00554890 length: 4 - undefined4 editorRockType; // 0x00554894 length: 4 + OpenSHC::Map::Enums::MapOrientation rockOrientation; // 0x00554890 length: 4 + OpenSHC::Map::Enums::EditorRockType editorRockType; // 0x00554894 length: 4 int lastTime; // 0x00554898 length: 4 MapOrientationInt mapOrientation; // 0x0055489C length: 4 undefined4 DAT_FutureMapOrientation; // 0x005548A0 length: 4 @@ -177,13 +179,13 @@ namespace Map { int DAT_WallTileCountCurrentDrag; // 0x00554988 length: 4 undefined4 buildingX; // 0x0055498C length: 4 undefined4 buildingY; // 0x00554990 length: 4 - undefined4 buildingRotationRelatedValue; // 0x00554994 length: 4 + undefined4 buildingOrientedPartIndex; // 0x00554994 length: 4 undefined4 placementOnWall; // 0x00554998 length: 4 undefined4 placementOnMoat; // 0x0055499C length: 4 undefined4 savedCursorTile; // 0x005549A0 length: 4 int showNoRubbleWhenDestroyingBuilding; // 0x005549A4 length: 4 - undefined4 field_0x5549a8; // 0x005549A8 length: 4 - undefined4 field_0x5549ac; // 0x005549AC length: 4 + int destinationNearTargetX; // 0x005549A8 length: 4 + int destinationNearTargetY; // 0x005549AC length: 4 int wallPlacementCost; // 0x005549B0 length: 4 int DAT_TempBuildingRotation; // 0x005549B4 length: 4 int field_0x5549b8; // 0x005549B8 length: 4 @@ -285,7 +287,7 @@ namespace Map { void resetTileToDefaultState(int param_1, uint param_2, uint param_3); - int getBuildingHurtSFXID(int buildingID); + OpenSHC::Map::Enums::HitSoundMaterial getBuildingHurtSFXID(int tile); void rotateFearFactorBuildingVariations(); @@ -339,7 +341,7 @@ namespace Map { void checkDrawbridgePlacement(int x, int y); - int getRubbleGraphicStageForDamageLevel(int param_1); + int getRubbleGraphicStageForDamageLevel(int fencePiece); int getBuildingSizeForCommandBuildingType(MappersEnum commandBuildingType); diff --git a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp index c55b63b17d..d4590824e7 100644 --- a/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp +++ b/src/OpenSHC/Map/TileMapState/applyRockGraphicsToFootprint.cpp @@ -36,12 +36,12 @@ namespace Map { if (this->disableElevationRendering == 0) { this->GfxLayer[tile] = GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] - + DAT_LandscapeState::instance.rocks[rockID].gfx + this->buildingRotationRelatedValue + surface + + DAT_LandscapeState::instance.rocks[rockID].gfx + this->buildingOrientedPartIndex + surface - 1; } else if (DAT_LandscapeState::instance.rocks[rockID].size == 1) { this->GfxLayer[tile] = GMFirstPictureIndex::instance[DAT_LandscapeState::instance.rocks[rockID].unknownGMID] - + DAT_LandscapeState::instance.rocks[rockID].gfx + this->buildingRotationRelatedValue + surface + + DAT_LandscapeState::instance.rocks[rockID].gfx + this->buildingOrientedPartIndex + surface - 1; } else { this->GfxLayer[tile] diff --git a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp index cdb1173db9..10cb7ac7cb 100644 --- a/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp +++ b/src/OpenSHC/Map/TileMapState/collectCliffEdgeTilesForClimbData.cpp @@ -29,9 +29,10 @@ namespace Map { this->temporaryTerrainTypeArray[this->temporaryTerrainTypeIndex] = tile; int const row = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; int const height = this->HeightLayer[tile]; - for (int index = 0; index < countof(DAT_ClimbLogicDefinedData::instance.field_0x2c); index++) { - int neighbour - = this->directionTranslationMatrix[row][DAT_ClimbLogicDefinedData::instance.field_0x2c[index]] + for (int index = 0; index < countof(DAT_ClimbLogicDefinedData::instance.neighbourSearchOrder); + index++) { + int neighbour = this->directionTranslationMatrix[row][DAT_ClimbLogicDefinedData::instance + .neighbourSearchOrder[index]] + tile; if ((this->LogicLayer[neighbour] & L_RIVER) != 0 && this->HeightLayer[neighbour] > height + 80) { this->temporaryTerrainTypeBinaryArray[this->temporaryTerrainTypeIndex] = 0; diff --git a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp index a107ded787..e3fef9ccb4 100644 --- a/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp +++ b/src/OpenSHC/Map/TileMapState/findNearestValidDigTileNearTarget.cpp @@ -38,9 +38,9 @@ namespace Map { DAT_BuildingsState::ptr)(targetBuildingID); } - for (int index = 0; index < countof(DAT_TerrainDefinedData::instance.field_0x378c); index++) { - int fromXPosition = DAT_TerrainDefinedData::instance.field_0x378c[index].x + x2; - int fromYPosition = DAT_TerrainDefinedData::instance.field_0x378c[index].y + y2; + for (int index = 0; index < countof(DAT_TerrainDefinedData::instance.twoTileAxisOffsets); index++) { + int fromXPosition = DAT_TerrainDefinedData::instance.twoTileAxisOffsets[index].x + x2; + int fromYPosition = DAT_TerrainDefinedData::instance.twoTileAxisOffsets[index].y + y2; int tile = DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile + fromXPosition; if (this->PathConnectionLayer[tile] != area) { continue; @@ -64,12 +64,12 @@ namespace Map { } if (bestIndex <= -1) { - this->field_0x5549a8 = x2; - this->field_0x5549ac = y2; + this->destinationNearTargetX = x2; + this->destinationNearTargetY = y2; return FALSE; } - this->field_0x5549a8 = DAT_TerrainDefinedData::instance.field_0x378c[bestIndex].x + x2; - this->field_0x5549ac = DAT_TerrainDefinedData::instance.field_0x378c[bestIndex].y + y2; + this->destinationNearTargetX = DAT_TerrainDefinedData::instance.twoTileAxisOffsets[bestIndex].x + x2; + this->destinationNearTargetY = DAT_TerrainDefinedData::instance.twoTileAxisOffsets[bestIndex].y + y2; return TRUE; } diff --git a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp index 454bcbf173..33e110af0e 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingHurtSFXID.cpp @@ -7,22 +7,25 @@ namespace OpenSHC { namespace Map { + using OpenSHC::Map::Enums::HSM_NONE; + using OpenSHC::Map::Enums::HSM_STONE; + using OpenSHC::Map::Enums::HSM_WOOD; using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; // FUNCTION: STRONGHOLDCRUSADER 0x004F8210 - int TileMapState::getBuildingHurtSFXID(int tileUnk) + OpenSHC::Map::Enums::HitSoundMaterial TileMapState::getBuildingHurtSFXID(int tile) { - short buildingID = this->BuildingLayer[tileUnk]; + short buildingID = this->BuildingLayer[tile]; if (buildingID != 0) { if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == 0) { - return 0; + return HSM_NONE; } if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == OpenSHC::Map::Buildings::BLS_REMOVE) { - return 0; + return HSM_NONE; } if (DAT_BuildingsState::instance.buildings[buildingID].currentHealth == 0) { - return 0; + return HSM_NONE; } switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { @@ -46,15 +49,15 @@ namespace Map { case OpenSHC::Map::Buildings::BT_TOWER4: case OpenSHC::Map::Buildings::BT_TOWER5: case OpenSHC::Map::Buildings::BT_OUTPOST_EUROPEAN: - return 2; + return HSM_STONE; default: - return 1; + return HSM_WOOD; } } - if ((this->LogicLayer[tileUnk] & L_WALL_OR_GATEHOUSE) != 0) { - return 2; + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + return HSM_STONE; } - return 0; + return HSM_NONE; } } diff --git a/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp b/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp index 3bec836ac0..f5256b9b9b 100644 --- a/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp +++ b/src/OpenSHC/Map/TileMapState/getBuildingSizeIndexMappingData.cpp @@ -9,24 +9,28 @@ namespace Map { void TileMapState::getBuildingSizeIndexMappingData(int buildingSizeTileIndex, int buildingWidthOrHeight) { this->constructionTileCount = buildingWidthOrHeight * buildingWidthOrHeight; - this->buildingX = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][0]; - this->buildingY = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][1]; + this->buildingX = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex].x; + this->buildingY = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex].y; switch (this->mapOrientation) { case OpenSHC::Map::Enums::MO_NORTH: - this->buildingRotationRelatedValue - = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][2]; + this->buildingOrientedPartIndex + = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex] + .orientedPartIndex[0]; return; case OpenSHC::Map::Enums::MO_EAST: - this->buildingRotationRelatedValue - = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][3]; + this->buildingOrientedPartIndex + = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex] + .orientedPartIndex[1]; return; case OpenSHC::Map::Enums::MO_SOUTH: - this->buildingRotationRelatedValue - = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][4]; + this->buildingOrientedPartIndex + = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex] + .orientedPartIndex[2]; return; case OpenSHC::Map::Enums::MO_WEST: - this->buildingRotationRelatedValue - = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex][5]; + this->buildingOrientedPartIndex + = DAT_BuildingSizeIndexMapping::instance[buildingWidthOrHeight][buildingSizeTileIndex] + .orientedPartIndex[3]; } } diff --git a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp index a9640fca94..e4170f3bf3 100644 --- a/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp +++ b/src/OpenSHC/Map/TileMapState/getOrientationThatIsWallTowerOrGatehouse.cpp @@ -24,8 +24,7 @@ namespace Map { int rowTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; for (int index = 0; index < countof(DAT_TerrainDefinedData::instance.SomeOrientationOrderArray); index++) { - CardinalDirection const orientation - = (CardinalDirection)DAT_TerrainDefinedData::instance.SomeOrientationOrderArray[index]; + CardinalDirection const orientation = DAT_TerrainDefinedData::instance.SomeOrientationOrderArray[index]; int neighbour = this->directionTranslationMatrix[y][orientation] + rowTile; if ((this->LogicLayer[neighbour] & L_WALL_OR_GATEHOUSE) != 0 && (this->LogicLayer[neighbour] & (L_STOCKPILEUnk | L_CRENEL_VARIATIONUnk)) == 0) { diff --git a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp index d1e6045690..1790a0c806 100644 --- a/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp +++ b/src/OpenSHC/Map/TileMapState/getRubbleGraphicStageForDamageLevel.cpp @@ -13,64 +13,64 @@ namespace Map { using OpenSHC::Map::Enums::MO_WEST; // FUNCTION: STRONGHOLDCRUSADER 0x004FA460 - int TileMapState::getRubbleGraphicStageForDamageLevel(int rotation) + int TileMapState::getRubbleGraphicStageForDamageLevel(int fencePiece) { int result = 0; int orientation = this->mapOrientation; if (orientation == MO_NORTH) { - if (rotation == 80) { + if (fencePiece == 80) { result = 1; - } else if (rotation == 81) { + } else if (fencePiece == 81) { result = 0; - } else if (rotation == CD_NORTHEAST) { + } else if (fencePiece == CD_NORTHEAST) { result = 2; - } else if (rotation == CD_NORTHWEST) { + } else if (fencePiece == CD_NORTHWEST) { result = 5; - } else if (rotation == CD_SOUTHEAST) { + } else if (fencePiece == CD_SOUTHEAST) { result = 3; - } else if (rotation == CD_SOUTHWEST) { + } else if (fencePiece == CD_SOUTHWEST) { result = 4; } } else if (orientation == MO_SOUTH) { - if (rotation == 80) { + if (fencePiece == 80) { result = 1; - } else if (rotation == 81) { + } else if (fencePiece == 81) { result = 0; - } else if (rotation == CD_NORTHEAST) { + } else if (fencePiece == CD_NORTHEAST) { result = 4; - } else if (rotation == CD_NORTHWEST) { + } else if (fencePiece == CD_NORTHWEST) { result = 3; - } else if (rotation == CD_SOUTHEAST) { + } else if (fencePiece == CD_SOUTHEAST) { result = 5; - } else if (rotation == CD_SOUTHWEST) { + } else if (fencePiece == CD_SOUTHWEST) { result = 2; } } else if (orientation == MO_EAST) { - if (rotation == 80) { + if (fencePiece == 80) { result = 0; - } else if (rotation == 81) { + } else if (fencePiece == 81) { result = 1; - } else if (rotation == CD_NORTHEAST) { + } else if (fencePiece == CD_NORTHEAST) { result = 5; - } else if (rotation == CD_NORTHWEST) { + } else if (fencePiece == CD_NORTHWEST) { result = 4; - } else if (rotation == CD_SOUTHEAST) { + } else if (fencePiece == CD_SOUTHEAST) { result = 2; - } else if (rotation == CD_SOUTHWEST) { + } else if (fencePiece == CD_SOUTHWEST) { result = 3; } } else if (orientation == MO_WEST) { - if (rotation == 80) { + if (fencePiece == 80) { result = 0; - } else if (rotation == 81) { + } else if (fencePiece == 81) { result = 1; - } else if (rotation == CD_NORTHEAST) { + } else if (fencePiece == CD_NORTHEAST) { result = 3; - } else if (rotation == CD_NORTHWEST) { + } else if (fencePiece == CD_NORTHWEST) { result = 2; - } else if (rotation == CD_SOUTHEAST) { + } else if (fencePiece == CD_SOUTHEAST) { result = 4; - } else if (rotation == CD_SOUTHWEST) { + } else if (fencePiece == CD_SOUTHWEST) { result = 5; } } diff --git a/src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp b/src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp index b1afd2b135..1189846f3b 100644 --- a/src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp +++ b/src/OpenSHC/Map/TileMapState/processMapOrientationChange.cpp @@ -6,10 +6,10 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00512920 void TileMapState::processMapOrientationChange() { - if ((int)this->DAT_FutureMapOrientation < 8) { + if ((int)this->DAT_FutureMapOrientation < OpenSHC::Map::Enums::MO_UPPER_LIMIT) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::changeMapOrientation, this)( (MapOrientation)this->DAT_FutureMapOrientation); - this->DAT_FutureMapOrientation = 8; + this->DAT_FutureMapOrientation = OpenSHC::Map::Enums::MO_UPPER_LIMIT; } } diff --git a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp index 0cf4893a9b..30099d5573 100644 --- a/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp +++ b/src/OpenSHC/Map/TileMapState/setupTileMapSections.cpp @@ -77,7 +77,7 @@ namespace Map { this->RandomLayer[tile] = SEC_RNG::instance.currentNumber2; } MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::changeMapOrientation, this)(OpenSHC::Map::Enums::MO_NORTH); - this->DAT_FutureMapOrientation = OpenSHC::Map::Enums::CD_UPPER_LIMIT; + this->DAT_FutureMapOrientation = OpenSHC::Map::Enums::MO_UPPER_LIMIT; } } diff --git a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp index 09f89f8270..22b2ad26a1 100644 --- a/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp +++ b/src/OpenSHC/Map/TileMapState/updatePitchDitches.cpp @@ -29,16 +29,16 @@ namespace Map { continue; } int tile = this->pitchDitches[id].tile; - if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) == 0 || this->pitchDitches[id].state == -1) { + if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) == 0 || this->pitchDitches[id].state == PDS_REMOVE) { MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::destroyPitchDitch, this)(id); - } else if (this->pitchDitches[id].state == 0) { + } else if (this->pitchDitches[id].state == PDS_PLACED) { this->pitchDitches[id].state += 1; - this->pitchDitches[id].field_0x12 = 0; - } else if (this->pitchDitches[id].state == 2) { - this->pitchDitches[id].field_0x12 += 1; - if (this->pitchDitches[id].field_0x12 == 20) { + this->pitchDitches[id].burnTimer = 0; + } else if (this->pitchDitches[id].state == PDS_BURNING) { + this->pitchDitches[id].burnTimer += 1; + if (this->pitchDitches[id].burnTimer == 20) { this->pitchDitches[id].state += 1; - this->pitchDitches[id].field_0x12 = 0; + this->pitchDitches[id].burnTimer = 0; int height = DAT_TileMapState::instance.HeightLayer[tile]; for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.field_0x376c); i++) { int neighbour = DAT_ViewportRenderState::instance @@ -51,22 +51,22 @@ namespace Map { } int other = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getPitchDitchIDForTile, this)( neighbour); - if (other == 0 || this->pitchDitches[other].state != 1) { + if (other == 0 || this->pitchDitches[other].state != PDS_READY) { continue; } if (abs(height - DAT_TileMapState::instance.HeightLayer[neighbour]) < 25) { MACRO_CALL(OpenSHC::Map::Entities_Func::SetPlaceOnFire)(this->pitchDitches[other].owner, this->pitchDitches[other].x * 8, this->pitchDitches[other].y * 8, DAT_TileMapState::instance.HeightLayer[this->pitchDitches[other].tile], 3); - this->pitchDitches[other].state = 2; + this->pitchDitches[other].state = PDS_BURNING; } } } - } else if (this->pitchDitches[id].state == 3) { - this->pitchDitches[id].field_0x12 += 1; - if (this->pitchDitches[id].field_0x12 == 200) { + } else if (this->pitchDitches[id].state == PDS_BURNT_OUT) { + this->pitchDitches[id].burnTimer += 1; + if (this->pitchDitches[id].burnTimer == 200) { DAT_TileMapState::instance.HeightLayer[tile] = DAT_TileMapState::instance.DefaultHeightLayer[tile]; - this->pitchDitches[id].state = -1; + this->pitchDitches[id].state = PDS_REMOVE; } } } diff --git a/src/OpenSHC/Map/Units/Climbing/ClimbLogicDefinedData.hpp b/src/OpenSHC/Map/Units/Climbing/ClimbLogicDefinedData.hpp index 60b6bbe8d5..d3ce53163f 100644 --- a/src/OpenSHC/Map/Units/Climbing/ClimbLogicDefinedData.hpp +++ b/src/OpenSHC/Map/Units/Climbing/ClimbLogicDefinedData.hpp @@ -8,6 +8,7 @@ #pragma once +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" #include "OpenSHC/Map/Navigation/Algorithms/XYPair.hpp" #include "OpenSHC/Util/FunctionTypes/NoArgCallback.hpp" @@ -16,6 +17,7 @@ namespace Map { namespace Units { namespace Climbing { + using OpenSHC::Map::Enums::CardinalDirection; using OpenSHC::Map::Navigation::Algorithms::XYPair; using OpenSHC::Util::FunctionTypes::NoArgCallback; @@ -25,7 +27,7 @@ namespace Map { NoArgCallback* updateFunctions[10]; // 0x00000000 length: 40 undefined1 padding_0x28[4]; // 0x00000028 length: 4 - int field_0x2c[8]; // 0x0000002C length: 32 + CardinalDirection neighbourSearchOrder[8]; // 0x0000002C length: 32 int field_0x4c[55]; // 0x0000004C length: 220 undefined1 field_0x128; // 0x00000128 length: 1 undefined1 field_0x129; // 0x00000129 length: 1 diff --git a/src/OpenSHC/UI/MenuItems/MapEditorLandscaping/MenuItemActionHandler_MapEditorLandscaping_GeneralButtons.cpp b/src/OpenSHC/UI/MenuItems/MapEditorLandscaping/MenuItemActionHandler_MapEditorLandscaping_GeneralButtons.cpp index 4882016c87..c363bcd409 100644 --- a/src/OpenSHC/UI/MenuItems/MapEditorLandscaping/MenuItemActionHandler_MapEditorLandscaping_GeneralButtons.cpp +++ b/src/OpenSHC/UI/MenuItems/MapEditorLandscaping/MenuItemActionHandler_MapEditorLandscaping_GeneralButtons.cpp @@ -79,8 +79,8 @@ namespace UI { return; // each rock steps the brush up to the next odd size; one shared round-up for the five loses the match case OpenSHC::Commands::M_MAPPER_BIGROCK1: - DAT_TileMapState::instance.editorRockType = 1; - DAT_TileMapState::instance.rockOrientation = 0; + DAT_TileMapState::instance.editorRockType = OpenSHC::Map::Enums::ERT_BIGROCK1; + DAT_TileMapState::instance.rockOrientation = OpenSHC::Map::Enums::MO_NORTH; DAT_TileMapState::instance.currentMapperCommand = command; if (DAT_TileMapState::instance.editorActiveBrush == 2) { DAT_TileMapState::instance.editorActiveBrush = 3; @@ -91,8 +91,8 @@ namespace UI { } return; case OpenSHC::Commands::M_MAPPER_BIGROCK2: - DAT_TileMapState::instance.editorRockType = 2; - DAT_TileMapState::instance.rockOrientation = 2; + DAT_TileMapState::instance.editorRockType = OpenSHC::Map::Enums::ERT_BIGROCK2; + DAT_TileMapState::instance.rockOrientation = OpenSHC::Map::Enums::MO_EAST; DAT_TileMapState::instance.currentMapperCommand = command; if (DAT_TileMapState::instance.editorActiveBrush == 2) { DAT_TileMapState::instance.editorActiveBrush = 3; @@ -103,8 +103,8 @@ namespace UI { } return; case OpenSHC::Commands::M_MAPPER_BIGROCK3: - DAT_TileMapState::instance.editorRockType = 3; - DAT_TileMapState::instance.rockOrientation = 4; + DAT_TileMapState::instance.editorRockType = OpenSHC::Map::Enums::ERT_BIGROCK3; + DAT_TileMapState::instance.rockOrientation = OpenSHC::Map::Enums::MO_SOUTH; DAT_TileMapState::instance.currentMapperCommand = command; if (DAT_TileMapState::instance.editorActiveBrush == 2) { DAT_TileMapState::instance.editorActiveBrush = 3; @@ -115,8 +115,8 @@ namespace UI { } return; case OpenSHC::Commands::M_MAPPER_BIGROCK4: - DAT_TileMapState::instance.editorRockType = 4; - DAT_TileMapState::instance.rockOrientation = 6; + DAT_TileMapState::instance.editorRockType = OpenSHC::Map::Enums::ERT_BIGROCK4; + DAT_TileMapState::instance.rockOrientation = OpenSHC::Map::Enums::MO_WEST; DAT_TileMapState::instance.currentMapperCommand = command; if (DAT_TileMapState::instance.editorActiveBrush == 2) { DAT_TileMapState::instance.editorActiveBrush = 3; @@ -127,8 +127,8 @@ namespace UI { } return; case OpenSHC::Commands::M_MAPPER_BIGROCK5: - DAT_TileMapState::instance.editorRockType = 5; - DAT_TileMapState::instance.rockOrientation = 0; + DAT_TileMapState::instance.editorRockType = OpenSHC::Map::Enums::ERT_BIGROCK5; + DAT_TileMapState::instance.rockOrientation = OpenSHC::Map::Enums::MO_NORTH; DAT_TileMapState::instance.currentMapperCommand = command; if (DAT_TileMapState::instance.editorActiveBrush == 2) { DAT_TileMapState::instance.editorActiveBrush = 3; From e3f146cbcb8d603b7692e5135c7f857d794011e4 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 07:53:38 +0100 Subject: [PATCH 28/28] docs(compiler-internals): the TU symbol count decides some register choices c2's GrgImmedTupleHash buckets resolver-global address constants by their TU-wide symbol number & 0x3f, which permutes the global register candidates' numbers. FoldTooCheapDefs and SpillObvious act greedily in number order, so a header edit above a function can change its code with no source change (placeDefensiveStructureTile 100 -> 96.3% after a main merge). shift_sweep.py measures a function over the 64 possible offsets (or screens the whole tree); color_probe.py dumps every candidate at each stage of Color and compares two runs. Screen of all 2469 functions: 6 vary. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmaL4CQf53VmKTVHqhH --- tools/compiler-internals/color_probe.py | 231 +++++++++++++++++++++++ tools/compiler-internals/msvc-backend.md | 134 +++++++++++++ tools/compiler-internals/shift_sweep.py | 173 +++++++++++++++++ 3 files changed, 538 insertions(+) create mode 100644 tools/compiler-internals/color_probe.py create mode 100644 tools/compiler-internals/shift_sweep.py diff --git a/tools/compiler-internals/color_probe.py b/tools/compiler-internals/color_probe.py new file mode 100644 index 0000000000..88c4bf2b17 --- /dev/null +++ b/tools/compiler-internals/color_probe.py @@ -0,0 +1,231 @@ +"""Dump every global register candidate at each stage of c2's `Color`, for one function. + +usage: color_probe.py FILE.cpp --name FUNC [--shift N] [--watch ID] + color_probe.py --compare A.txt B.txt + +Built to explain why one function compiles differently when only the TU's symbol count changes +(msvc-backend.md, "The TU symbol count decides some register choices"): run it on the committed +file and again with `--shift N` (N dummy `typedef short` lines prepended to a temporary copy, the +same thing shift_sweep.py does), then `--compare` the two outputs. Candidates are matched by +symbol id and name, so the comparison shows which fields differ, not just that the numbers moved. + +Output lines (saved to the probe folder as color---.txt and printed): + + CK cls= checkpoint; every candidate follows as a G line + G num id key c24 c28 c2c c40 c38 f4 L.. N=name + num +0x1c candidate number (the order the greedy passes walk) + id +0x44 symbol id (the colouring tie-break) + key +0x0c colouring key, c40 +0x40 spill benefit, c24 +0x24 + reference count, f4 +0x04 flags (byte +5 bit 4 = never fold) + FV num id f5 .. FoldTooCheapDefs looks at a candidate (number order) + FK1 / FK2 its two veto tests (ComponentKilled, the def check) + FOLD num id ...and folds it into its uses (DoFoldDef) + SPILL num id c24 c40 N=name SpillObvious spills it (number order) + SUBST num id N=name ...and substitutes its def + SERVE / SOD / HCU num id key c40 colouring pops it / SpillOrDefer / HandleCurrUncolorable + CPR id legal=.. ChoosePhysReg is asked for it + CPRDONE id reg=.. w=.. ...and chose that register (1 eax .. 8 edi) with these weights + WATCH / FLAGW with --watch ID: who writes that candidate's flag byte +5 + +Stages: 0 before SubsumeGlobregs, 1 after it, 2 after FoldTooCheapDefs, 3 after +InitialSplitPoints, 4 after Spillcosts, 5 after SpillObvious, 6 after OrderGlobregs, 7/8 the +re-split round (before Spillcosts / after SpillObvious), 9 class done. +""" + +import collections +import os +import re +import sys + +import c2base +from slot_probe import EQ, NL, GLOBAL_REG_ALLOC, COLOR_ENTRY, run, name_test, out + +GLOBREG_HASH = '0x10d15090' # _GlobregHash: 0x400 chains, bucket = number & 0x3ff, next at +0x30 +STAGES = [ + ('0x10b0d0a5', 0), # before SubsumeGlobregs + ('0x10b0d0aa', 1), # after SubsumeGlobregs + ('0x10b0d0bf', 2), # after FoldTooCheapDefs + CreateBlockBvs + ('0x10b0d149', 3), # after InitialSplitPoints + ('0x10b0d15a', 4), # after Spillcosts + ('0x10b0d169', 5), # after SpillObvious + ('0x10b0d22f', 6), # after OrderGlobregs + ('0x10b0d2ab', 7), # re-split round: before Spillcosts + ('0x10b0d2bf', 8), # re-split round: after SpillObvious + ('0x10b0d497', 9), # class done +] + +# one candidate per G line; run with $$>< so the whole walk is one command. $t9 = stage number +DUMP = (r'r $t1=0' '\n' + r'.while (@$t1 < 0x400) { r $t2=poi(' + GLOBREG_HASH + r'+@$t1*4); .while (@$t2 != 0) { ' + r'.printf "G %x num=%x id=%x key=%d c24=%x c28=%x c2c=%x c40=%d c38=%x f4=%x ", @$t9, poi(@$t2+0x1c), ' + r'poi(@$t2+0x44), poi(@$t2+0xc), poi(@$t2+0x24), poi(@$t2+0x28), poi(@$t2+0x2c), poi(@$t2+0x40), ' + r'poi(@$t2+0x38), poi(@$t2+4); .if (poi(@$t2+0x20) != 0) { r $t3=poi(poi(@$t2+0x20)); .while (@$t3 != 0) ' + r'{ .printf "L%x:%x:%x ", poi(@$t3), poi(@$t3+4), poi(@$t3+8); r $t3=poi(@$t3+0xc) } }; r $t4=poi(@$t2); ' + r'.if (@$t4 != 0) { .if (poi(@$t4) != 0) { .if (poi(poi(@$t4)+4) != 0) { .printf "N=%ma", ' + r'poi(poi(@$t4)+4)+1 } } }; .printf "\n"; r $t2=poi(@$t2+0x30) }; r $t1=@$t1+1 }' '\n') + +# the symbol name of the candidate in $t2, for the one-line breakpoints +NAME = ('r $t4=poi(@$t2); .if (@$t4 != 0) { .if (poi(@$t4) != 0) { .if (poi(poi(@$t4)+4) != 0) { .printf ' + + EQ + 'N=%ma' + EQ + ', poi(poi(@$t4)+4)+1 } } }; .printf ' + EQ + NL + EQ) + + +def one(label, reg): + return ('"r $t2=' + reg + '; .printf ' + EQ + label + ' num=%x id=%x key=%d c40=%d' + NL + EQ + + ', poi(@$t2+0x1c), poi(@$t2+0x44), poi(@$t2+0xc), poi(@$t2+0x40); gc"') + + +def breakpoints(dump_path, watch): + dp = str(dump_path).replace('\\', '/') + bps = [(a, '"r $t9=0n%d; .printf ' % n + EQ + 'CK %d cls=%%x' % n + NL + EQ + ', @ebx; $$><' + dp + '; gc"') + for a, n in STAGES] + bps += [ + ('0x10b0d350', one('SERVE', '@ebp')), + ('0x10b0d37e', one('SOD', '@ebp')), + ('0x10b0d3c5', one('HCU', '@ebp')), + ('0x10b0d471', '"r $t2=@ebp; .printf ' + EQ + 'CPR id=%x legal=%x/%x/%x' + NL + EQ + + ', poi(@$t2+0x44), poi(poi(poi(@$t2+0x20))), poi(poi(poi(@$t2+0x20))+4), poi(poi(poi(@$t2+0x20))+8); gc"'), + ('0x10b0d476', '"r $t2=@ebp; .printf ' + EQ + 'CPRDONE id=%x reg=%x w=%d,%d,%d,%d,%d,%d,%d,%d' + NL + EQ + + ', poi(@$t2+0x44), (poi(@$t2+0x10)-0x10d09f70)/0x60, poi(0x10d14f14), poi(0x10d14f18), poi(0x10d14f1c), poi(0x10d14f20), ' + 'poi(0x10d14f24), poi(0x10d14f28), poi(0x10d14f2c), poi(0x10d14f30); gc"'), + # FoldTooCheapDefs phase 2 walks _GlobregHash in number order; esi = candidate + ('0x10b0dd20', '"r $t2=@esi; .printf ' + EQ + 'FV num=%x id=%x f5=%x u14=%x def=%x defop=%x c34=%x' + NL + + EQ + ', poi(@$t2+0x1c), poi(@$t2+0x44), by(@$t2+5), poi(@$t2+0x14), poi(@$t2+0x3c), ' + '(poi(@$t2+0x3c)!=0)*poi(poi(@$t2+0x3c)+4), by(@$t2+0x34); gc"'), + ('0x10b0ddc5', '".printf ' + EQ + 'FK1 %x' + NL + EQ + ', @eax; gc"'), + ('0x10b0dde4', '".printf ' + EQ + 'FK2 %x' + NL + EQ + ', @eax; gc"'), + ('0x10b0de18', '"r $t2=@esi; .printf ' + EQ + 'FOLD num=%x id=%x' + NL + EQ + + ', poi(@$t2+0x1c), poi(@$t2+0x44); gc"'), + # SpillObvious: eax = the candidate at the Spill call and at the CmdSubstDef call + ('0x10b115d6', '"r $t2=@eax; .printf ' + EQ + 'SPILL num=%x id=%x c24=%x c40=%d ' + EQ + + ', poi(@$t2+0x1c), poi(@$t2+0x44), poi(@$t2+0x24), poi(@$t2+0x40); ' + NAME + '; gc"'), + ('0x10b11630', '"r $t2=@eax; .printf ' + EQ + 'SUBST num=%x id=%x ' + EQ + + ', poi(@$t2+0x1c), poi(@$t2+0x44); ' + NAME + '; gc"'), + ] + if watch is not None: + # after SubsumeGlobregs: find the candidate with that symbol id, hardware-watch its flag byte + bps.append(('0x10b0d0b0', '"r $t5=0; r $t1=0; .while (@$t1 < 0x400) { r $t2=poi(' + GLOBREG_HASH + + '+@$t1*4); .while (@$t2 != 0) { .if (poi(@$t2+0x44) == ' + watch + ') { r $t5=@$t2 }; ' + 'r $t2=poi(@$t2+0x30) }; r $t1=@$t1+1 }; .printf ' + EQ + 'WATCH %x f5=%x' + NL + EQ + + ', @$t5, by(@$t5+5); ba30 w1 @$t5+5 ' + EQ + '.echo FLAGW; ? by(@$t5+5); r eip; k 8; gc' + + EQ + '; gc"')) + return bps + + +KEEP = re.compile(r'^(FOUND|CK|G |SERVE|SOD|CPR|HCU|COLORENTRY|FV|FK|FOLD|SPILL|SUBST|WATCH|FLAGW|Evaluate|eip=|' + r'[0-9a-f]{8} [0-9a-f]{8} )') + + +def probe(src, name, shift, watch): + tag = 'color-%s-%s-%d' % (os.path.basename(src)[:-4], name, shift) + dump = out / (tag + '.dump') + dump.write_text(c2base.rebase(DUMP)) + bps = breakpoints(dump, watch) + n = len(bps) + gate = ('r $t7=poi(poi(@eax)+4); ' + name_test(name) + '; .if (@$t6 != 0) { .printf ' + EQ + 'FOUND' + NL + + EQ + '; be 1-%d } .else { bd 1-%d }' % (n, n)) + lines = ['sxe ld:c2', 'g'] + lines += ['bp%d %s %s' % (i, a, c) for i, (a, c) in enumerate(bps, 1)] + # Color runs again for the stack colouring (COLOR_ENTRY): stop logging there + lines += ['bp%d %s ".printf ' % (n + 1, COLOR_ENTRY) + EQ + 'COLORENTRY' + NL + EQ + '; bd 1-%d; gc"' % n, + 'bd 1-%d' % n, + 'bp0 ' + GLOBAL_REG_ALLOC + ' "' + gate + '; gc"', + 'g', 'q', ''] + target = src + if shift: + # beside the original, so its relative #includes still resolve + target = src[:-4] + '__colorpad%d.cpp' % shift + pad = ''.join('typedef short ShiftPad%d;\n' % i for i in range(shift)).encode() + open(target, 'wb').write(pad + open(src, 'rb').read()) + try: + txt = run(lines, target, tag) + finally: + if shift: + os.remove(target) + if 'Malformed' in txt or 'Syntax error' in txt: + sys.exit('cdb rejected a command - see ' + str(out / (tag + '.log'))) + if 'FOUND' not in txt: + sys.exit('GlobalRegAlloc never ran for ?%s@ - check --name' % name) + result = '\n'.join(l.rstrip() for l in txt.splitlines() if KEEP.match(l)) + '\n' + (out / (tag + '.txt')).write_text(result) + return result, out / (tag + '.txt') + + +REGS = dict(enumerate(['-', 'eax', 'ecx', 'edx', 'ebx', 'esp', 'ebp', 'esi', 'edi'])) +EVENTS = ('FOLD', 'SPILL', 'SUBST', 'SERVE', 'CPRDONE') + + +def load(path): + """-> ({(stage, occurrence): [candidate dicts]}, {event kind: [event dicts]}, num -> (id, name))""" + stages, events, seen, cur = {}, collections.defaultdict(list), collections.Counter(), None + for line in open(path): + line = line.rstrip() + if line.startswith('CK '): + stage = int(line.split()[1]) + cur = stages.setdefault((stage, seen[stage]), []) + seen[stage] += 1 + elif line.startswith('G ') and cur is not None: + cur.append(dict(re.findall(r'(\w+)=(\S+)', line))) + elif line.split(' ', 1)[0] in EVENTS: + events[line.split(' ', 1)[0]].append(dict(re.findall(r'(\w+)=(\S+)', line))) + return stages, events + + +def compare(pa, pb): + """Per checkpoint, the candidates whose fields differ other than by their number; per kind of + event, the sequence of symbols in both runs up to and past the first divergence.""" + (sa, ea), (sb, eb) = load(pa), load(pb) + names = {} + for stages in (sa, sb): + for gs in stages.values(): + for d in gs: + if d.get('N'): + names[d['id']] = d['N'] + + def label(d): + if 'num' not in d: # CPRDONE carries the register instead + r = int(d.get('reg', '0'), 16) + return '%s%s=%s' % (d['id'], '(' + names[d['id']] + ')' if d['id'] in names else '', REGS.get(r, hex(r))) + tail = '#' + d['num'] + return '%s%s%s' % (d['id'], '(' + names[d['id']] + ')' if d['id'] in names else '', tail) + + def by_symbol(gs): + m = collections.defaultdict(list) + for d in gs: + m[d['id']].append((d['key'], d['c24'], d['c40'], d['f4'], int(d['num'], 16))) + return {k: sorted(v) for k, v in m.items()} + + print('candidates per checkpoint, compared by symbol id (fields: key c24 c40 f4 #num)') + for k in sorted(set(sa) | set(sb)): + x, y = by_symbol(sa.get(k, [])), by_symbol(sb.get(k, [])) + diffs = [i for i in sorted(set(x) | set(y)) if [t[:4] for t in x.get(i, [])] != [t[:4] for t in y.get(i, [])]] + print('CK %d.%d candidates %d/%d differing %d' % (k[0], k[1], len(sa.get(k, [])), len(sb.get(k, [])), + len(diffs))) + for i in diffs[:12]: + print(' id=%s %s\n A %s\n B %s' % (i, names.get(i, ''), x.get(i), y.get(i))) + print('\nevent order, as symbol id(name)#number') + for kind in EVENTS: + la, lb = [label(d) for d in ea.get(kind, [])], [label(d) for d in eb.get(kind, [])] + if [s.split('#')[0] for s in la] == [s.split('#')[0] for s in lb]: + print('%-7s same order (%d)' % (kind, len(la))) + continue + print('%-7s A: %s\n B: %s' % (kind, ' '.join(la), ' '.join(lb))) + + +def main(): + if '--compare' in sys.argv: + i = sys.argv.index('--compare') + compare(sys.argv[i + 1], sys.argv[i + 2]) + return + if '--name' not in sys.argv: + sys.exit(__doc__) + src = os.path.abspath(sys.argv[1]) + name = sys.argv[sys.argv.index('--name') + 1] + shift = int(sys.argv[sys.argv.index('--shift') + 1]) if '--shift' in sys.argv else 0 + watch = sys.argv[sys.argv.index('--watch') + 1] if '--watch' in sys.argv else None + txt, path = probe(src, name, shift, watch) + print(txt) + print('saved to ' + str(path)) + + +if __name__ == '__main__': + main() diff --git a/tools/compiler-internals/msvc-backend.md b/tools/compiler-internals/msvc-backend.md index c38bc6e8a5..1db83c70b6 100644 --- a/tools/compiler-internals/msvc-backend.md +++ b/tools/compiler-internals/msvc-backend.md @@ -3041,3 +3041,137 @@ Two more `quick_diff.py` artefacts came out of this batch and are fixed: a `swit (`$LN38@f[edi]`, `jmp dword ptr [ecx*4 + 0x41c9d0]`) were not collapsed to `G` on either side, which alone held `lightUpBuilding` at 0.8988 where it is 0.9312; and the original's indirect jumps were skipping normalisation entirely. + +## The TU symbol count decides some register choices (`shift_sweep.py`, `color_probe.py`) + +`placeDefensiveStructureTile` (TileMapState, PR #366) was 100% before a merge of `main` and 96.3% after it, with +the `.cpp` byte-identical and the IL identical up to `regalloc`. The merge had only added three enums to headers +the file includes. None of them is used by the function; what they changed is **how many symbols the front end +had numbered before the function**, and that number reaches the register allocator through a hash. + +### The chain, in c2.dll + +1. **`GrgImmedTupleHash`** (0x10b5c050) files every constant operand into the 64-bucket `_ImmedHashTable` + (0x10d12170). An address constant (tuple kind 3, the `&Instance<...>::instance` of a resolver global) hashes + by `[[[tuple+0x18]+8]]+0x28 & 0x3f` - a symbol number counted over the whole translation unit. Measured: an + `enum` with one enumerator adds 2 to it, a `typedef` 1, a `#define` 0, and only declarations *before* the + function count (four dummy enums after the last `#include` moved the result; the same four after the body + did not). +2. **`CreateGlobregs`** (0x10b5abe0) walks that table bucket by bucket and frees every immediate candidate that + turned out worthless (`ColRemoveGlobregFromHashTable`, 0x10b18790, called from 0x10b5ac39). The bucket + decides where each one lands in the free order. +3. **`GrgNewGlobreg`** (0x10b5b7b0) reuses `_FreeGlobs` last-in-first-out and **keeps the freed record's number** + (`+0x1c`). The same `CreateGlobregs` call then creates the candidates for the real symbols (`this`, `tile`, + `x`, temporaries), so they receive a permutation of the freed numbers. +4. What the number does **not** change: the colouring key `+0x0c`, the benefit `+0x40`, the symbol id `+0x44`, + and therefore `InsertInList`'s serve order, whose tie-break is the id. `color_probe.py --compare` on a bad + and a good shift shows all of them equal right up to the pass that diverges. +5. What it does change: any **greedy** pass that visits candidates in number order - walking `_GlobregHash` + (0x10d15090, bucket `number & 0x3ff`, chained through `+0x30`) or `bsf` over a bitset of numbers - where + acting on one candidate changes what the pass can do with a later one. Two were caught doing it. + +### Pass 1: `FoldTooCheapDefs` (0x10b0da80) - `placeDefensiveStructureTile` + +Phase 2 of `FoldTooCheapDefs` walks `_GlobregHash` and folds each cheap single-definition candidate back into its +uses (`ComponentKilled` 0x10b19fe0 as the veto, then `DoFoldDef` 0x10b195e0 -> `CmdDoFoldDef`). This function +has two such candidates, one built on the other (`tuple_dump.py` at `FoldTooCheapDefs` entry; the `t` numbers +are the candidate numbers): + +``` +shift 0 (bad) shift 46 (good) +lea t8, dword ptr [this + tile] lea t11, dword ptr [this + tile] +mov byte ptr [t8 + 3313824], t1 mov byte ptr [t11 + 3313824], t1 +lea t21, dword ptr [t8 + 2751024] lea t8, dword ptr [t11 + 2751024] ; &HeightLayer[tile] +mov t3, byte ptr [t8 + 2831424] mov t21, byte ptr [t11 + 2831424] +mov byte ptr [t21], t3 mov byte ptr [t8], t21 ; ... and ~16 more uses +``` + +With the inner `lea` (A) numbered lower, it is folded first: every `[A + d]` becomes `[this + tile + d]`, which +turns the outer `lea` (B) from a based address (`0x27c`) into an indexed one (`0x27d`). `CmdDoFoldDef`'s end +block notices and sets B's never-fold bit (byte `+5 |= 4`, the write at 0x10c248f5, caught with `--watch 0x1b`), +so B is skipped when the walk reaches it. With B numbered lower, B folds first (into `[A + 2751024]`) and A +after it, and both disappear: + +``` +color_probe.py ... --compare (A = shift 0, B = shift 46) +FOLD A: 46#2 34#6 1d#8 5c#f 62#17 75#1a 68#1e 6d#25 56#26 + B: 56#2 34#3 46#6 1b#8 1d#b 5c#f 62#17 6d#1a 68#1e 75#23 +CK 4.0 id=1e tile A [key 385, refs 0x26, benefit 76] B [key 451, refs 0x38, benefit 112] + id=e this A [key 311, refs 0x25, benefit 74] B [key 383, refs 0x37, benefit 110] +``` + +The surviving B is gone again before colouring proper, but it is still there when `Spillcosts` counts +references, so 18 uses each of `tile` and `this` are booked against B instead. The lower keys reorder the tail +of the serve list, the `x & 1` temporaries tie with `x` and take `eax` instead of `ecx` (`CPRDONE` in the same +comparison), a `mov eax, ecx` copy survives, and `FgDoCommonTailMerge` can no longer merge the two crenel arms' +identical tails - seven instructions more: + +``` +shift 0 (ours, 96.3%) shift 46 (= original) +add byte ptr [esi+edi+2751024], 98 add byte ptr [esi+edi+2751024], 98 +mov eax, ecx $LN54: +and eax, 1 and ecx, 1 +je $LN18 je $LN18 +test bl, 1 test bl, 1 +jne $LN18 jne $LN18 +or dword ptr [edi+esi*4+1462624], 0x400000 or dword ptr [edi+esi*4+1462624], 0x400000 +jmp $LN52 jmp $LN52 +... ... +add byte ptr [esi+edi+2751024], 68 add byte ptr [esi+edi+2751024], 68 +mov eax, ecx jmp $LN54 ; the second arm reuses the first's tail +and eax, 1 +... (the whole tail again) +``` + +### Pass 2: `SpillObvious` (0x10b11560) - the sliders and `DisplayMapDescriptionAndAllocatePlayersToSlots` + +`SpillObvious` spills every candidate with fewer than two references (`+0x24 < 2`) in `bsf` order (the `Spill` +call at 0x10b115d6, `CmdSubstDef` at 0x10b11630; `eax` is the candidate at both). Each spill inserts its reload +right before the use, so the spill order is the order of the loads. In +`MenuItemRenderFunction_GameplayOptions_SpeedSlider`, `thumbX = thumbXPos + DAT_ButtonX::instance`: + +``` +SPILL A: 7(thumbXPos)#3 29(thumbWidth)#6 8(DAT_ButtonX)#7 ... shift 0 (= original) + B: 29(thumbWidth)#6 8(DAT_ButtonX)#7 7(thumbXPos)#8 ... shift 30 + +shift 0 shift 30 +mov ecx, dword ptr [DAT_ButtonX] mov ecx, dword ptr [thumbXPos] +mov eax, dword ptr [thumbXPos] mov eax, dword ptr [DAT_ButtonX] +add eax, ecx add eax, ecx +``` + +Serve order, `ChoosePhysReg` costs and chosen registers are identical in both runs; only the load order flips, +so the two operands trade registers. + +### Periodic in 64, and how many functions it reaches + +Because the only path is `number & 0x3f`, the outcome repeats every 64 symbols - predicted and confirmed for +nine combinations of dummy enums and typedefs on `placeDefensiveStructureTile`, including 32 enums = 64 +typedefs = 128 typedefs = no change. `shift_sweep.py --all` screened all 2469 marked functions at shifts +0/17/34/51 (no compile errors), then swept the six that varied over the full period: + +| function | shift 0 | best | shifts at best (of 64) | +|---|---|---|---| +| `placeDefensiveStructureTile` | 0.9630 | **1.0000** | 39: 13-23, 25-52 | +| `MenuItemRenderFunction_GameplayOptions_SpeedSlider` | 1.0000 | 1.0000 | 21: 0-14, 16-19, 62-63 | +| `MenuItemRenderFunction_SoundOptions_VolumeSlider` | 1.0000 | 1.0000 | 21: 0-10, 12-15, 58-63 | +| `MenuItemActionHandler_UnusedChooseAvailableKeeps_Main` | 1.0000 | 1.0000 | 50: 0-48, 63 | +| `DisplayMapDescriptionAndAllocatePlayersToSlots` | 0.9507 | 0.9686 | 45 | +| `UpdateFireBallistaBuilding` | 0.9936 | 0.9936 | 55 | + +About 0.25% of functions, and only one is held below a reachable 100% today; three sit at 100% by luck and an +unrelated header edit can knock them down (the two sliders hardest). A function whose sensitive window is +narrower than 17 shifts can slip between the screen's four points, so six is a lower bound. + +### What to do with it + +- A header-only change that moves one function's match is a candidate for this. Check with + `shift_sweep.py OUT.jsonl FILE.cpp --name FUNC` (0-63 by default, about 30 s at `-j 12`). +- If any shift reaches 1.0, the source is right: record the function as "matches modulo TU symbol count" in the + commit remark, like "only call targets differ". Do **not** pad the translation unit with dummy declarations + or steer the enum/typedef count by hand - the next header edit anywhere above the function moves it again. + Converting enums to `#define`s does not fix it either; it only removes symbols, which helps or hurts by luck. +- To see which pass decides it for a new case: `color_probe.py FILE.cpp --name FUNC` and again with + `--shift N` for a good N, then `color_probe.py --compare A.txt B.txt`. The first checkpoint where a + candidate differs by more than its number, and the first event list that differs, name the pass. `--watch ID` + puts a hardware breakpoint on that candidate's flag byte and prints the stack of every write. diff --git a/tools/compiler-internals/shift_sweep.py b/tools/compiler-internals/shift_sweep.py new file mode 100644 index 0000000000..82c6e1acd8 --- /dev/null +++ b/tools/compiler-internals/shift_sweep.py @@ -0,0 +1,173 @@ +"""Does a function's match depend on how many symbols its translation unit declares before it? + +c2.dll numbers its global register candidates through a 64-bucket hash keyed on each global's +TU-wide symbol number (msvc-backend.md, "The TU symbol count decides some register choices"), so +a header edit anywhere above a function can move its match with no change to its source. This +tool compiles copies of a .cpp with N dummy `typedef short` lines prepended - each one shifts every +later symbol number by 1 - and records quick_diff's ratio per N. + +usage: shift_sweep.py OUT.jsonl FILE.cpp [--name FUNC] [--shifts 0-63] [-j 14] + shift_sweep.py OUT.jsonl --all [--shifts 0,17,34,51] [-j 14] every // FUNCTION: in src/OpenSHC + shift_sweep.py OUT.jsonl --only LIST.txt [--shifts ...] LIST.txt lines: pathname + shift_sweep.py OUT.jsonl --report functions whose ratio varies + +--shifts takes a comma list and/or ranges (`0-63`, `0,17,34,51`). OUT.jsonl is appended to and +resumable: (file, name, shift) triples already in it are skipped. The default for one file is the +whole period 0-63, for --all the 4-point screen 0,17,34,51 (cheap, but a function whose sensitive +window is narrower than 17 can slip through it). + +Reading the report: `now` is shift 0 (the TU as committed), `best` the highest ratio over the +shifts measured and `at best` how many shifts reach it. A function whose best is 1.0 has the right +source - record it as "matches modulo TU symbol count" rather than padding the TU, because the +next header edit moves the count again. A function at 1.0 now with few shifts at best is fragile: +an unrelated header change can drop it. +""" + +import json +import os +import re +import subprocess +import sys +import threading +from concurrent.futures import ThreadPoolExecutor + +ROOT = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')) +QD = os.path.join(ROOT, 'tools', 'reimplementation-helper', 'batch', 'quick_diff.py') +MARK = re.compile(r'FUNCTION: STRONGHOLDCRUSADER (0x[0-9A-Fa-f]+)[^\n]*\n[^\n(]*?(?:(\w+)::)?(\w+)\(') +PAD = '__shiftpad' + + +def arg(flag, default=None): + return sys.argv[sys.argv.index(flag) + 1] if flag in sys.argv else default + + +def parse_shifts(text): + out = [] + for part in text.split(','): + a, _, b = part.partition('-') + out += range(int(a), int(b) + 1) if b else [int(a)] + return out + + +def functions_in(path): + src = open(os.path.join(ROOT, path), encoding='utf-8', errors='replace').read() + return [m.group(3) for m in MARK.finditer(src)] + + +def targets(): + if '--only' in sys.argv: + for line in open(arg('--only'), encoding='utf-8'): + if line.strip(): + p, n = line.rstrip('\n').split('\t') + yield p, n + return + if '--all' in sys.argv: + for d, _, fs in os.walk(os.path.join(ROOT, 'src', 'OpenSHC')): + for f in sorted(fs): + if f.endswith('.cpp') and PAD not in f: + p = os.path.relpath(os.path.join(d, f), ROOT).replace('\\', '/') + for n in functions_in(p): + yield p, n + return + p = os.path.relpath(os.path.abspath(sys.argv[2]), ROOT).replace('\\', '/') + names = functions_in(p) + want = arg('--name') + for n in names: + if want is None or n == want: + yield p, n + if want is None: + return + + +def report(out_path): + runs = {} + for line in open(out_path, encoding='utf-8'): + r = json.loads(line) + if 'ratio' in r: + runs.setdefault((r['file'], r['name']), {})[r['shift']] = r['ratio'] + rows = [] + for (f, n), by in runs.items(): + vals = set(by.values()) + if len(vals) > 1: + best = max(vals) + rows.append((n, by.get(0), best, sum(v == best for v in by.values()), len(by), + [s for s in sorted(by) if by[s] == best])) + print('%d functions measured, %d vary with the symbol count' % (len(runs), len(rows))) + for n, now, best, k, total, good in sorted(rows, key=lambda r: (r[1] or 0) - r[2]): + print('%-60s now %s best %.4f at %d/%d %s' % ( + n, '%.4f' % now if now is not None else ' - ', best, k, total, spans(good))) + + +def spans(xs): + out, start = [], None + for i, x in enumerate(xs): + if start is None: + start = x + if i + 1 == len(xs) or xs[i + 1] != x + 1: + out.append(str(start) if start == x else '%d-%d' % (start, x)) + start = None + return ','.join(out) + + +def main(): + out_path = os.path.abspath(sys.argv[1]) + if '--report' in sys.argv: + report(out_path) + return + default = '0,17,34,51' if ('--all' in sys.argv or '--only' in sys.argv) else '0-63' + shifts = parse_shifts(arg('--shifts', default)) + jobs = int(arg('-j', '14')) + + done = set() + if os.path.exists(out_path): + for line in open(out_path, encoding='utf-8'): + r = json.loads(line) + done.add((r['file'], r['name'], r['shift'])) + lock = threading.Lock() + slots = list(range(jobs)) + slot_lock = threading.Lock() + + def run(task): + path, name, n, multi = task + with slot_lock: + slot = slots.pop() + try: + full = os.path.join(ROOT, path) + src = open(full, 'rb').read() + # beside the original, so its relative #includes still resolve + tmp = full[:-4] + '%s%d_%d.cpp' % (PAD, n, slot) + pad = ''.join('typedef short ShiftPad%d;\n' % i for i in range(n)).encode() + open(tmp, 'wb').write(pad + src) + try: + cmd = [sys.executable, QD, tmp, '-q'] + (['--name', name] if multi else []) + env = dict(os.environ, QD_OUT='shift%d' % slot) + r = subprocess.run(cmd, cwd=ROOT, capture_output=True, text=True, env=env, timeout=600) + o = r.stdout + r.stderr + finally: + os.remove(tmp) + m = re.search(r'ratio (\S+)\s+orig (\d+) ours (\d+)', o) + rec = {'file': path, 'name': name, 'shift': n} + if m: + rec.update(ratio=float(m.group(1)), orig=int(m.group(2)), ours=int(m.group(3))) + else: + rec['error'] = o.strip()[-300:] + with lock: + with open(out_path, 'a', encoding='utf-8') as fh: + fh.write(json.dumps(rec) + '\n') + finally: + with slot_lock: + slots.append(slot) + + tl = list(targets()) + count = {} + for p, n in tl: + count[p] = len(functions_in(p)) + tasks = [(p, n, s, count[p] > 1) for p, n in tl for s in shifts if (p, n, s) not in done] + print('%d functions, %d compiles to do' % (len(tl), len(tasks)), flush=True) + with ThreadPoolExecutor(jobs) as ex: + list(ex.map(run, tasks)) + report(out_path) + + +if __name__ == '__main__': + main()